diff --git a/src/main/java/jp/oiyokan/OiyokanCsdlEntitySet.java b/src/main/java/jp/oiyokan/OiyokanCsdlEntitySet.java index 62fa9ab..de9cbe1 100755 --- a/src/main/java/jp/oiyokan/OiyokanCsdlEntitySet.java +++ b/src/main/java/jp/oiyokan/OiyokanCsdlEntitySet.java @@ -22,7 +22,6 @@ import org.apache.olingo.commons.api.edm.provider.CsdlEntityType; import org.apache.olingo.server.api.ODataApplicationException; -import jp.oiyokan.OiyokanConstants.DatabaseType; import jp.oiyokan.common.OiyoInfo; import jp.oiyokan.common.OiyoInfoUtil; import jp.oiyokan.dto.OiyoSettingsDatabase; @@ -45,39 +44,17 @@ public class OiyokanCsdlEntitySet extends CsdlEntitySet { */ private OiyoSettingsEntitySet settingsEntitySet = null; - /** - * この EntitySet が接続する先のデータベースタイプを記憶. - */ - private DatabaseType databaseType = DatabaseType.h2; - /** * この EntitySet から導出された EntityType. */ private CsdlEntityType entityType = null; - /** - * EntitySet設定情報を取得. - * - * @return EntitySet設定情報. - */ - public OiyoSettingsEntitySet getSettingsEntitySet() { - return settingsEntitySet; - } - - /** - * データベース型を取得. - * - * @return データベースの型. - */ - public DatabaseType getDatabaseType() { - return databaseType; - } - /** * Database設定情報を取得. * * @return Database設定情報. * @throws ODataApplicationException ODataアプリ例外. + * @deprecated */ public OiyoSettingsDatabase getSettingsDatabase(OiyoInfo oiyoInfo) throws ODataApplicationException { return OiyoInfoUtil.getOiyoDatabaseByName(oiyoInfo, settingsEntitySet.getDbSettingName()); @@ -96,6 +73,7 @@ public void setEntityType(CsdlEntityType entityType) { * CsdlEntityType を取得。 * * @return CsdlEntityTypeインスタンス. + * @deprecated */ public CsdlEntityType getEntityType() { return entityType; @@ -107,6 +85,7 @@ public CsdlEntityType getEntityType() { * @param entityContainer コンテナ情報. * @param settingsEntitySet EntitySetの設定. * @throws ODataApplicationException ODataアプリ例外が発生した場合. + * @deprecated */ public OiyokanCsdlEntitySet(OiyoInfo oiyoInfo, OiyokanCsdlEntityContainer entityContainer, OiyoSettingsEntitySet settingsEntitySet) throws ODataApplicationException { @@ -116,7 +95,7 @@ public OiyokanCsdlEntitySet(OiyoInfo oiyoInfo, OiyokanCsdlEntityContainer entity try { // 指定のデータベース名の文字列が妥当かどうかチェックして値として設定。 - databaseType = OiyokanConstants.DatabaseType.valueOf(getSettingsDatabase(oiyoInfo).getType()); + OiyokanConstants.DatabaseType.valueOf(getSettingsDatabase(oiyoInfo).getType()); } catch (IllegalArgumentException ex) { // [M002] UNEXPECTED: Illegal data type in database settings System.err.println(OiyokanMessages.M002 + ": dbname:" + getSettingsDatabase(oiyoInfo).getName() // @@ -134,6 +113,7 @@ public OiyokanCsdlEntitySet(OiyoInfo oiyoInfo, OiyokanCsdlEntityContainer entity * エンティティ名. ODataTest1 相当. * * @return エンティティ名. ODataTest1 相当. + * @deprecated */ public String getEntityNameIyo() { return settingsEntitySet.getEntityType().getName(); @@ -144,17 +124,9 @@ public String getEntityNameIyo() { * * @return エンティティのFQN(完全修飾名). * @throws ODataApplicationException ODataアプリ例外が発生した場合. + * @deprecated */ public FullQualifiedName getEntityNameFqnIyo() throws ODataApplicationException { return new FullQualifiedName(csdlEntityContainer.getNamespaceIyo(), getEntityNameIyo()); } - - /** - * ターゲット上のテーブル名. - * - * @return ターゲットのDBテーブル名. - */ - public String getDbTableNameTargetIyo() { - return settingsEntitySet.getEntityType().getDbName(); - } } diff --git a/src/main/java/jp/oiyokan/OiyokanEntityCollectionProcessor.java b/src/main/java/jp/oiyokan/OiyokanEntityCollectionProcessor.java index 941e263..93d086b 100755 --- a/src/main/java/jp/oiyokan/OiyokanEntityCollectionProcessor.java +++ b/src/main/java/jp/oiyokan/OiyokanEntityCollectionProcessor.java @@ -43,6 +43,7 @@ import jp.oiyokan.basic.OiyoBasicJdbcEntityCollectionBuilder; import jp.oiyokan.common.OiyoInfo; +import jp.oiyokan.common.OiyoInfoUtil; /** * Oiyokan による EntityCollectionProcessor 実装. @@ -157,7 +158,10 @@ private static final OiyokanEntityCollectionBuilderInterface getEntityCollection } } - switch (entitySet.getDatabaseType()) { + final OiyokanConstants.DatabaseType databaseType = OiyoInfoUtil.getOiyoDatabaseTypeByEntitySetName(oiyoInfo, + edmEntitySet.getName()); + + switch (databaseType) { case h2: case postgres: case MySQL: diff --git a/src/main/java/jp/oiyokan/basic/OiyoBasicJdbcEntityOneBuilder.java b/src/main/java/jp/oiyokan/basic/OiyoBasicJdbcEntityOneBuilder.java index df3e6a2..6106c94 100644 --- a/src/main/java/jp/oiyokan/basic/OiyoBasicJdbcEntityOneBuilder.java +++ b/src/main/java/jp/oiyokan/basic/OiyoBasicJdbcEntityOneBuilder.java @@ -181,6 +181,8 @@ public Entity createEntityData(UriInfo uriInfo, EdmEntitySet edmEntitySet, Entit final OiyoSettingsDatabase database = OiyoInfoUtil.getOiyoDatabaseByEntitySetName(oiyoInfo, entitySet.getName()); + final OiyokanConstants.DatabaseType databaseType = OiyoInfoUtil.getOiyoDatabaseTypeByEntitySetName(oiyoInfo, + entitySet.getName()); // データベースに接続. boolean isTranSuccessed = false; @@ -191,7 +193,7 @@ public Entity createEntityData(UriInfo uriInfo, EdmEntitySet edmEntitySet, Entit final List generatedKeys = OiyoBasicJdbcUtil.executeDml(connTargetDb, sqlInfo, true); // 生成されたキーをその後の処理に反映。 final List keyPredicates = new ArrayList<>(); - if (DatabaseType.ORACLE == DatabaseType.valueOf(database.getType())) { + if (DatabaseType.ORACLE == databaseType) { // ORACLEの特殊ルール。ROWIDが戻るので決め打ちで検索. final UriParameterImpl newParam = new UriParameterImpl(); newParam.setName("ROWID"); diff --git a/src/main/java/jp/oiyokan/basic/OiyoBasicJdbcUtil.java b/src/main/java/jp/oiyokan/basic/OiyoBasicJdbcUtil.java index 73e9d14..a323382 100755 --- a/src/main/java/jp/oiyokan/basic/OiyoBasicJdbcUtil.java +++ b/src/main/java/jp/oiyokan/basic/OiyoBasicJdbcUtil.java @@ -725,10 +725,10 @@ public static String unescapeKakkoFieldName(String escapedFieldName) { * @throws ODataApplicationException ODataアプリ例外が発生した場合. */ public static String escapeKakkoFieldName(OiyoSqlInfo sqlInfo, String fieldName) throws ODataApplicationException { - final OiyoSettingsDatabase database = OiyoInfoUtil.getOiyoDatabaseByEntitySetName(sqlInfo.getOiyoInfo(), - sqlInfo.getEntitySetName()); + final OiyokanConstants.DatabaseType databaseType = OiyoInfoUtil + .getOiyoDatabaseTypeByEntitySetName(sqlInfo.getOiyoInfo(), sqlInfo.getEntitySetName()); - return escapeKakkoFieldName(OiyokanConstants.DatabaseType.valueOf(database.getType()), fieldName); + return escapeKakkoFieldName(databaseType, fieldName); } public static String escapeKakkoFieldName(OiyokanConstants.DatabaseType databaseType, String fieldName) diff --git a/src/main/java/jp/oiyokan/basic/sql/OiyoSqlQueryListBuilder.java b/src/main/java/jp/oiyokan/basic/sql/OiyoSqlQueryListBuilder.java index d03b010..1138363 100755 --- a/src/main/java/jp/oiyokan/basic/sql/OiyoSqlQueryListBuilder.java +++ b/src/main/java/jp/oiyokan/basic/sql/OiyoSqlQueryListBuilder.java @@ -32,7 +32,6 @@ import jp.oiyokan.common.OiyoInfo; import jp.oiyokan.common.OiyoInfoUtil; import jp.oiyokan.common.OiyoSqlInfo; -import jp.oiyokan.dto.OiyoSettingsDatabase; import jp.oiyokan.dto.OiyoSettingsEntitySet; import jp.oiyokan.dto.OiyoSettingsProperty; @@ -92,8 +91,6 @@ public void buildSelectCountQuery(UriInfo uriInfo) throws ODataApplicationExcept * @throws ODataApplicationException ODataアプリ例外が発生した場合. */ public void buildSelectQuery(UriInfo uriInfo) throws ODataApplicationException { - final OiyoSettingsEntitySet entitySet = OiyoInfoUtil.getOiyoEntitySet(oiyoInfo, entitySetName); - sqlInfo.getSqlBuilder().append("SELECT "); expandSelect(uriInfo); @@ -104,9 +101,8 @@ public void buildSelectQuery(UriInfo uriInfo) throws ODataApplicationException { // 現状の実装では指定があろうがなかろうが件数はカウントする実装となっている. // TODO FIXME 現状でも常にカウントしているかどうか確認すること。 - final OiyoSettingsDatabase database = OiyoInfoUtil.getOiyoDatabaseByEntitySetName(sqlInfo.getOiyoInfo(), - sqlInfo.getEntitySetName()); - final OiyokanConstants.DatabaseType databaseType = OiyokanConstants.DatabaseType.valueOf(database.getType()); + final OiyokanConstants.DatabaseType databaseType = OiyoInfoUtil + .getOiyoDatabaseTypeByEntitySetName(sqlInfo.getOiyoInfo(), sqlInfo.getEntitySetName()); if (OiyokanConstants.DatabaseType.MSSQL2008 == databaseType // || OiyokanConstants.DatabaseType.ORACLE == databaseType) { @@ -216,9 +212,8 @@ private void expandSelectEach(UriInfo uriInfo) throws ODataApplicationException private void expandFrom(UriInfo uriInfo) throws ODataApplicationException { final OiyoSettingsEntitySet entitySet = OiyoInfoUtil.getOiyoEntitySet(oiyoInfo, sqlInfo.getEntitySetName()); - final OiyoSettingsDatabase database = OiyoInfoUtil.getOiyoDatabaseByEntitySetName(sqlInfo.getOiyoInfo(), - sqlInfo.getEntitySetName()); - final OiyokanConstants.DatabaseType databaseType = OiyokanConstants.DatabaseType.valueOf(database.getType()); + final OiyokanConstants.DatabaseType databaseType = OiyoInfoUtil + .getOiyoDatabaseTypeByEntitySetName(sqlInfo.getOiyoInfo(), sqlInfo.getEntitySetName()); // 取得元のテーブル. switch (databaseType) { @@ -318,9 +313,8 @@ private void expandOrderByWithPrimary() throws ODataApplicationException { } private void expandTopSkip(UriInfo uriInfo) throws ODataApplicationException { - final OiyoSettingsDatabase database = OiyoInfoUtil.getOiyoDatabaseByEntitySetName(sqlInfo.getOiyoInfo(), - sqlInfo.getEntitySetName()); - final OiyokanConstants.DatabaseType databaseType = OiyokanConstants.DatabaseType.valueOf(database.getType()); + final OiyokanConstants.DatabaseType databaseType = OiyoInfoUtil + .getOiyoDatabaseTypeByEntitySetName(sqlInfo.getOiyoInfo(), sqlInfo.getEntitySetName()); if (OiyokanConstants.DatabaseType.MSSQL2008 != databaseType // && OiyokanConstants.DatabaseType.ORACLE != databaseType) { diff --git a/src/main/java/jp/oiyokan/basic/sql/OiyoSqlQueryListExpr.java b/src/main/java/jp/oiyokan/basic/sql/OiyoSqlQueryListExpr.java index 932974f..e5c9c69 100755 --- a/src/main/java/jp/oiyokan/basic/sql/OiyoSqlQueryListExpr.java +++ b/src/main/java/jp/oiyokan/basic/sql/OiyoSqlQueryListExpr.java @@ -38,7 +38,6 @@ import jp.oiyokan.common.OiyoInfo; import jp.oiyokan.common.OiyoInfoUtil; import jp.oiyokan.common.OiyoSqlInfo; -import jp.oiyokan.dto.OiyoSettingsDatabase; import jp.oiyokan.dto.OiyoSettingsEntitySet; /** @@ -280,9 +279,8 @@ private void expandMember(MemberImpl impl) throws ODataApplicationException { * @throws ODataApplicationException ODataアプリ例外が発生. */ private void expandMethod(MethodImpl impl) throws ODataApplicationException { - final OiyoSettingsDatabase database = OiyoInfoUtil.getOiyoDatabaseByEntitySetName(sqlInfo.getOiyoInfo(), - sqlInfo.getEntitySetName()); - final OiyokanConstants.DatabaseType databaseType = OiyokanConstants.DatabaseType.valueOf(database.getType()); + final OiyokanConstants.DatabaseType databaseType = OiyoInfoUtil + .getOiyoDatabaseTypeByEntitySetName(sqlInfo.getOiyoInfo(), sqlInfo.getEntitySetName()); // CONTAINS if (impl.getMethod() == MethodKind.CONTAINS) { diff --git a/src/main/java/jp/oiyokan/basic/sql/OiyoSqlQueryOneBuilder.java b/src/main/java/jp/oiyokan/basic/sql/OiyoSqlQueryOneBuilder.java index 53a0a4e..aa82553 100644 --- a/src/main/java/jp/oiyokan/basic/sql/OiyoSqlQueryOneBuilder.java +++ b/src/main/java/jp/oiyokan/basic/sql/OiyoSqlQueryOneBuilder.java @@ -26,7 +26,6 @@ import jp.oiyokan.common.OiyoInfo; import jp.oiyokan.common.OiyoInfoUtil; import jp.oiyokan.common.OiyoSqlInfo; -import jp.oiyokan.dto.OiyoSettingsDatabase; import jp.oiyokan.dto.OiyoSettingsEntitySet; import jp.oiyokan.dto.OiyoSettingsProperty; @@ -69,9 +68,8 @@ public void buildSelectOneQuery(EdmEntitySet edmEntitySet, List ke throws ODataApplicationException { final OiyoSettingsEntitySet entitySet = OiyoInfoUtil.getOiyoEntitySet(oiyoInfo, edmEntitySet.getName()); - final OiyoSettingsDatabase database = OiyoInfoUtil.getOiyoDatabaseByEntitySetName(sqlInfo.getOiyoInfo(), - sqlInfo.getEntitySetName()); - final OiyokanConstants.DatabaseType databaseType = OiyokanConstants.DatabaseType.valueOf(database.getType()); + final OiyokanConstants.DatabaseType databaseType = OiyoInfoUtil + .getOiyoDatabaseTypeByEntitySetName(sqlInfo.getOiyoInfo(), sqlInfo.getEntitySetName()); sqlInfo.getSqlBuilder().append("SELECT "); diff --git a/src/main/java/jp/oiyokan/common/OiyoInfoUtil.java b/src/main/java/jp/oiyokan/common/OiyoInfoUtil.java index 3c6f12b..70e93dc 100644 --- a/src/main/java/jp/oiyokan/common/OiyoInfoUtil.java +++ b/src/main/java/jp/oiyokan/common/OiyoInfoUtil.java @@ -97,6 +97,16 @@ public static OiyoSettingsDatabase getOiyoDatabaseByEntitySetName(OiyoInfo oiyoI return getOiyoDatabaseByName(oiyoInfo, entitySet.getDbSettingName()); } + public static OiyokanConstants.DatabaseType getOiyoDatabaseTypeByEntitySetName(OiyoInfo oiyoInfo, + String entitySetName) throws ODataApplicationException { + final OiyoSettingsEntitySet entitySet = getOiyoEntitySet(oiyoInfo, entitySetName); + + // TODO FIXME エラーメッセージ処理。 + OiyoSettingsDatabase database = getOiyoDatabaseByName(oiyoInfo, entitySet.getDbSettingName()); + + return OiyokanConstants.DatabaseType.valueOf(database.getType()); + } + public static OiyoSettingsEntitySet getOiyoEntitySet(OiyoInfo oiyoInfo, String entitySetName) throws ODataApplicationException { if (entitySetName == null) { @@ -129,7 +139,7 @@ public static OiyoSettingsProperty getOiyoEntityProperty(OiyoInfo oiyoInfo, Stri } new Exception("ここはどこ").printStackTrace(); - + // [M040] UNEXPECTED: EntitySet Property settings NOT found. System.err.println(OiyokanMessages.M040 + ": entitySet:" + entitySetName + ", property:" + propertyName); throw new ODataApplicationException(