Skip to content

Commit

Permalink
refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
igapyon committed Apr 17, 2021
1 parent aad0055 commit eda0af1
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 60 deletions.
40 changes: 6 additions & 34 deletions src/main/java/jp/oiyokan/OiyokanCsdlEntitySet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -96,6 +73,7 @@ public void setEntityType(CsdlEntityType entityType) {
* CsdlEntityType を取得。
*
* @return CsdlEntityTypeインスタンス.
* @deprecated
*/
public CsdlEntityType getEntityType() {
return entityType;
Expand All @@ -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 {
Expand All @@ -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() //
Expand All @@ -134,6 +113,7 @@ public OiyokanCsdlEntitySet(OiyoInfo oiyoInfo, OiyokanCsdlEntityContainer entity
* エンティティ名. ODataTest1 相当.
*
* @return エンティティ名. ODataTest1 相当.
* @deprecated
*/
public String getEntityNameIyo() {
return settingsEntitySet.getEntityType().getName();
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import jp.oiyokan.basic.OiyoBasicJdbcEntityCollectionBuilder;
import jp.oiyokan.common.OiyoInfo;
import jp.oiyokan.common.OiyoInfoUtil;

/**
* Oiyokan による EntityCollectionProcessor 実装.
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -191,7 +193,7 @@ public Entity createEntityData(UriInfo uriInfo, EdmEntitySet edmEntitySet, Entit
final List<String> generatedKeys = OiyoBasicJdbcUtil.executeDml(connTargetDb, sqlInfo, true);
// 生成されたキーをその後の処理に反映。
final List<UriParameter> keyPredicates = new ArrayList<>();
if (DatabaseType.ORACLE == DatabaseType.valueOf(database.getType())) {
if (DatabaseType.ORACLE == databaseType) {
// ORACLEの特殊ルール。ROWIDが戻るので決め打ちで検索.
final UriParameterImpl newParam = new UriParameterImpl();
newParam.setName("ROWID");
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/jp/oiyokan/basic/OiyoBasicJdbcUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 6 additions & 12 deletions src/main/java/jp/oiyokan/basic/sql/OiyoSqlQueryListBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/jp/oiyokan/basic/sql/OiyoSqlQueryListExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -69,9 +68,8 @@ public void buildSelectOneQuery(EdmEntitySet edmEntitySet, List<UriParameter> 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 ");

Expand Down
12 changes: 11 additions & 1 deletion src/main/java/jp/oiyokan/common/OiyoInfoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit eda0af1

Please sign in to comment.