/** * 一対多の関連を処理します。 * * @param propertyMeta プロパティメタデータ * @param field フィールド * @param entityMeta エンティティメタデータ * @param oneToMany 一対多関連 */ protected void doOneToMany( PropertyMeta propertyMeta, Field field, EntityMeta entityMeta, OneToMany oneToMany) { propertyMeta.setRelationshipType(RelationshipType.ONE_TO_MANY); if (!List.class.isAssignableFrom(field.getType())) { throw new OneToManyNotListRuntimeException(entityMeta.getName(), propertyMeta.getName()); } Class<?> relationshipClass = ReflectionUtil.getElementTypeOfList(field.getGenericType()); if (relationshipClass == null) { throw new OneToManyNotGenericsRuntimeException(entityMeta.getName(), propertyMeta.getName()); } if (relationshipClass.getAnnotation(Entity.class) == null) { throw new RelationshipNotEntityRuntimeException( entityMeta.getName(), propertyMeta.getName(), relationshipClass); } propertyMeta.setRelationshipClass(relationshipClass); String mappedBy = oneToMany.mappedBy(); if (!StringUtil.isEmpty(mappedBy)) { if (propertyMeta.getJoinColumnMetaList().size() > 0) { throw new BothMappedByAndJoinColumnRuntimeException( entityMeta.getName(), propertyMeta.getName()); } propertyMeta.setMappedBy(mappedBy); } else { throw new MappedByMandatoryRuntimeException(entityMeta.getName(), propertyMeta.getName()); } }
@Execute(validator = false) public String index() { if (StringUtil.isEmpty(page)) { throw new IllegalArgumentException("page is null."); } return page + ".ftl"; }
/** * 例外チェーンをたどって原因となった{@link SQLException#getSQLState() SQLステート}を返します。 * * <p>例外チェーンに{@link SQLException SQL例外}が存在しない場合や、SQLステートが設定されていない場合は <code>null</code>を返します。 * * @param t 例外 * @return 原因となった{@link SQLException#getSQLState() SQLステート} */ protected String getSQLState(Throwable t) { SQLException cause = getCauseSQLException(t); if (cause != null && !StringUtil.isEmpty(cause.getSQLState())) { return cause.getSQLState(); } return null; }
/** * {@link #ignoreWhitespace()}が呼び出された場合でパラメータ値が空文字列または空白のみの文字列なら <code>null</code>を、 * それ以外なら元の値をそのまま返します。 * * @param value パラメータ値 * @return {@link #ignoreWhitespace()}が呼び出された場合でパラメータ値が空文字列または空白のみの文字列なら <code>null</code>、 * それ以外なら元の値 */ protected Object normalize(final Object value) { if (excludesWhitespace && value instanceof String) { if (StringUtil.isEmpty(String.class.cast(value).trim())) { return null; } } return value; }
/** * シーケンスの名前を返します。 * * @param entityMeta エンティティメタデータ * @param propertyMeta プロパティメタデータ * @param sequenceGenerator シーケンスジェネレータ * @return シーケンスの名前 */ protected String getSequenceName( EntityMeta entityMeta, PropertyMeta propertyMeta, SequenceGenerator sequenceGenerator) { String sequenceName = sequenceGenerator.sequenceName(); if (!StringUtil.isEmpty(sequenceName)) { return sequenceName; } return entityMeta.getTableMeta().getName() + "_" + propertyMeta.getColumnMeta().getName(); }
/** * @see * org.seasar.framework.xml.sax.handler.TagHandler#end(org.seasar.framework.xml.sax.handler.TagHandlerContext, * java.lang.String) */ public void end(TagHandlerContext context, String body) { AspectDef aspectDef = (AspectDef) context.pop(); if (!StringUtil.isEmpty(body)) { aspectDef.setExpression(body); } ComponentDef componentDef = (ComponentDef) context.peek(); componentDef.addAspectDef(aspectDef); }
/** * 名前を処理します。 * * @param entityMeta エンティティメタデータ * @param tableDesc テーブル記述 * @param generator テーブルジェネレータ */ protected void doName(EntityMeta entityMeta, TableDesc tableDesc, TableGenerator generator) { String catalog = generator.catalog(); if (StringUtil.isEmpty(catalog)) { catalog = entityMeta.getTableMeta().getCatalog(); } String schema = generator.schema(); if (StringUtil.isEmpty(schema)) { schema = entityMeta.getTableMeta().getSchema(); } String name = generator.table(); if (StringUtil.isEmpty(name)) { name = TableIdGenerator.DEFAULT_TABLE; } tableDesc.setCatalogName(catalog); tableDesc.setSchemaName(schema); tableDesc.setName(name); tableDesc.setCanonicalName(buildCanonicalName(catalog, schema, name)); }
public String getSqlBySqlFile(Class daoClass, Method method, String suffix) { String base = daoClass.getName().replace('.', '/') + "_" + method.getName(); String dbmsPath = base + (StringUtil.isEmpty(suffix) ? "" : "_" + suffix) + DaoConstants.SQL_EXTENSION; String standardPath = base + DaoConstants.SQL_EXTENSION; if (ResourceUtil.isExist(dbmsPath)) { return TextUtil.readUTF8(dbmsPath); } else if (ResourceUtil.isExist(standardPath)) { return TextUtil.readUTF8(standardPath); } return null; }
protected String getOriginalPath(HttpServletRequest req) { String path = StringUtil.isEmpty(requestUriHeader) ? req.getRequestURI() : req.getHeader(requestUriHeader); if (path == null) return ""; int len = path.length(); int i = 0; for (; i < len; i++) if (path.charAt(i) == '?' || path.charAt(i) == ';') break; if (i != len) path = path.substring(0, i); return path; }
/** * カラム記述を処理します。 * * @param entityMeta エンティティメタデータ * @param propertyMetaList プロパティメタデータのリスト * @param tableDesc テーブル記述 * @param generator テーブルジェネレータ */ protected void doValueColumn( EntityMeta entityMeta, TableDesc tableDesc, TableGenerator generator) { String valueColumnName = generator.valueColumnName(); if (StringUtil.isEmpty(valueColumnName)) { valueColumnName = TableIdGenerator.DEFAULT_VALUE_COLUMN_NAME; } ColumnDesc columnDesc = new ColumnDesc(); columnDesc.setName(valueColumnName); SqlType sqlType = dialect.getSqlType(Types.BIGINT); columnDesc.setSqlType(sqlType); Column column = AnnotationUtil.getDefaultColumn(); columnDesc.setDefinition(sqlType.getDataType(0, column.precision(), 0, false)); columnDesc.setNullable(false); tableDesc.addColumnDesc(columnDesc); }
// ----------------------------------------------------- // Reset Method // ------------ protected void doSetupResetMethod( S2ExecuteConfig executeConfig, S2ActionMapping actionMapping, Execute execute) { final String reset = execute.reset(); if (!StringUtil.isEmpty(reset)) { Method resetMethod = null; if ("reset".equals(reset)) { resetMethod = actionMapping.getActionFormBeanDesc().getMethodNoException(reset); } else { resetMethod = actionMapping.getActionFormBeanDesc().getMethod(reset); } if (resetMethod != null) { executeConfig.setResetMethod(resetMethod); } } }
/** * 一対一の関連を処理します。 * * @param propertyMeta プロパティメタデータ * @param field フィールド * @param entityMeta エンティティメタデータ * @param oneToOne 一対一関連 */ protected void doOneToOne( PropertyMeta propertyMeta, Field field, EntityMeta entityMeta, OneToOne oneToOne) { propertyMeta.setRelationshipType(RelationshipType.ONE_TO_ONE); Class<?> relationshipClass = field.getType(); if (relationshipClass.getAnnotation(Entity.class) == null) { throw new RelationshipNotEntityRuntimeException( entityMeta.getName(), propertyMeta.getName(), relationshipClass); } propertyMeta.setRelationshipClass(relationshipClass); String mappedBy = oneToOne.mappedBy(); if (!StringUtil.isEmpty(mappedBy)) { if (propertyMeta.getJoinColumnMetaList().size() > 0) { throw new BothMappedByAndJoinColumnRuntimeException( entityMeta.getName(), propertyMeta.getName()); } propertyMeta.setMappedBy(mappedBy); } }
/** * 主キー記述を処理します。 * * @param entityMeta エンティティメタデータ * @param propertyMeta プロパティメタデータ * @param tableDesc テーブル記述 * @param generator テーブルジェネレータ */ protected void doPrimaryKeyColumn( EntityMeta entityMeta, TableDesc tableDesc, TableGenerator generator) { String pkColumnName = generator.pkColumnName(); if (StringUtil.isEmpty(pkColumnName)) { pkColumnName = TableIdGenerator.DEFAULT_PK_COLUMN_NAME; } PrimaryKeyDesc primaryKeyDesc = new PrimaryKeyDesc(); primaryKeyDesc.addColumnName(pkColumnName); tableDesc.setPrimaryKeyDesc(primaryKeyDesc); ColumnDesc columnDesc = new ColumnDesc(); columnDesc.setName(pkColumnName); SqlType sqlType = dialect.getSqlType(Types.VARCHAR); columnDesc.setSqlType(sqlType); Column column = AnnotationUtil.getDefaultColumn(); columnDesc.setDefinition(sqlType.getDataType(column.length(), 0, 0, false)); tableDesc.addColumnDesc(columnDesc); }
// =================================================================================== // ExecuteConfig // ============= protected void setupExecuteConfig( S2ExecuteConfig executeConfig, S2ActionMapping actionMapping, Class<?> actionClass, Method method) { final Execute execute = method.getAnnotation(Execute.class); final String input = !StringUtil.isEmpty(execute.input()) ? execute.input() : null; executeConfig.setMethod(method); executeConfig.setSaveErrors(execute.saveErrors()); executeConfig.setInput(input); doSetupValidationConfig(executeConfig, actionMapping, actionClass, method, execute, input); executeConfig.setUrlPattern(execute.urlPattern()); doSetupRole(executeConfig, execute); executeConfig.setStopOnValidationError(execute.stopOnValidationError()); executeConfig.setRemoveActionForm(execute.removeActionForm()); doSetupResetMethod(executeConfig, actionMapping, execute); executeConfig.setRedirect(execute.redirect()); }
/** * {@link GenerationType#TABLE}方式で識別子の値を自動生成するIDジェネレータを処理します。 * * @param propertyMeta プロパティメタデータ * @param generatedValue 識別子に付けられた{@link GeneratedValue}アノテーション * @param entityMeta エンティティのメタデータ * @return {@link GenerationType#TABLE}方式で識別子の値を自動生成するIDジェネレータが存在した場合に <code>true</code> */ protected boolean doTableIdGenerator( PropertyMeta propertyMeta, GeneratedValue generatedValue, EntityMeta entityMeta) { String name = generatedValue.generator(); TableGenerator tableGenerator; if (StringUtil.isEmpty(name)) { tableGenerator = DEFAULT_TABLE_GENERATOR; } else { tableGenerator = propertyMeta.getField().getAnnotation(TableGenerator.class); if (tableGenerator == null || !name.equals(tableGenerator.name())) { tableGenerator = entityMeta.getEntityClass().getAnnotation(TableGenerator.class); if (tableGenerator == null || !name.equals(tableGenerator.name())) { return false; } } } propertyMeta.setTableIdGenerator( new TableIdGenerator(entityMeta, propertyMeta, tableGenerator)); return true; }
/** * {@link GenerationType#SEQUENCE}方式で識別子の値を自動生成するIDジェネレータを処理します。 * * @param propertyMeta プロパティメタデータ * @param generatedValue 識別子に付けられた{@link GeneratedValue}アノテーション * @param entityMeta エンティティのメタデータ * @return {@link GenerationType#SEQUENCE}方式で識別子の値を自動生成するIDジェネレータが存在した場合に <code>true</code> */ protected boolean doSequenceIdGenerator( PropertyMeta propertyMeta, GeneratedValue generatedValue, EntityMeta entityMeta) { String name = generatedValue.generator(); SequenceGenerator sequenceGenerator; if (StringUtil.isEmpty(name)) { sequenceGenerator = DEFAULT_SEQUENCE_GENERATOR; } else { sequenceGenerator = propertyMeta.getField().getAnnotation(SequenceGenerator.class); if (sequenceGenerator == null || !name.equals(sequenceGenerator.name())) { sequenceGenerator = entityMeta.getEntityClass().getAnnotation(SequenceGenerator.class); if (sequenceGenerator == null || !name.equals(sequenceGenerator.name())) { return false; } } } propertyMeta.setSequenceIdGenerator( new SequenceIdGenerator(entityMeta, propertyMeta, sequenceGenerator)); return true; }
/** * テーブルジェネレータを返します。 * * @param entityMeta エンティティメタデータ * @param propertyMeta プロパティメタデータ * @return テーブルジェネレータ */ protected TableGenerator getTableGenerator(EntityMeta entityMeta, PropertyMeta propertyMeta) { Field field = propertyMeta.getField(); GeneratedValue generatedValue = field.getAnnotation(GeneratedValue.class); if (generatedValue == null) { throw new IllegalStateException("@GeneratedValue not found."); } String name = generatedValue.generator(); if (StringUtil.isEmpty(name)) { return AnnotationUtil.getDefaultTableGenerator(); } TableGenerator tableGenerator = field.getAnnotation(TableGenerator.class); if (tableGenerator != null && name.equals(tableGenerator.name())) { return tableGenerator; } tableGenerator = entityMeta.getEntityClass().getAnnotation(TableGenerator.class); if (tableGenerator != null && name.equals(tableGenerator.name())) { return tableGenerator; } throw new IllegalStateException("@TableGenerator not found."); }
// ----------------------------------------------------- // Validation // ---------- protected void doSetupValidationConfig( S2ExecuteConfig executeConfig, S2ActionMapping actionMapping, Class<?> actionClass, Method method, Execute execute, String input) { final List<S2ValidationConfig> validationConfigs = new ArrayList<S2ValidationConfig>(); final String validate = execute.validate(); boolean validator = false; if (!StringUtil.isEmpty(validate)) { final BeanDesc actionBeanDesc = actionMapping.getActionBeanDesc(); final BeanDesc actionFormBeanDesc = actionMapping.getActionFormBeanDesc(); for (String name : StringUtil.split(validate, ", ")) { if (VALIDATOR.equals(name)) { if (!execute.validator()) { throw new UnmatchValidatorAndValidateRuntimeException(actionClass, method.getName()); } validationConfigs.add(createValidationConfig()); validator = true; } else if (actionFormBeanDesc.hasMethod(name)) { final Method validateMethod = actionFormBeanDesc.getMethod(name); checkValidateMethod(actionClass, validateMethod); validationConfigs.add(createValidationConfig(validateMethod)); } else { final Method validateMethod = actionBeanDesc.getMethod(name); checkValidateMethod(actionClass, validateMethod); validationConfigs.add(createValidationConfig(validateMethod)); } } } if (!validator && execute.validator()) { validationConfigs.add(0, createValidationConfig()); } if (!validationConfigs.isEmpty() && input == null) { throw new IllegalValidatorOfExecuteMethodRuntimeException(actionClass, method.getName()); } executeConfig.setValidationConfigs(validationConfigs); }
/** * パラメータが空でないことを表明します。 * * @param parameter * @param name */ protected void assertParameterIsNotEmpty(String parameter, String name) { if (StringUtil.isEmpty(parameter)) { throw new IllegalArgumentException(name); } }
// ----------------------------------------------------- // Role // ---- protected void doSetupRole(S2ExecuteConfig executeConfig, Execute execute) { final String roles = execute.roles().trim(); if (!StringUtil.isEmpty(roles)) { executeConfig.setRoles(StringUtil.split(roles, ", ")); } }