();
+
+ /**
+ * Get access-context on thread.
+ *
+ * @return Access-context. (Nullable)
+ */
+ public static AccessContext getAccessContextOnThread() {
+ return (AccessContext) threadLocal.get();
+ }
+
+ /**
+ * Set access-context on thread.
+ *
+ * @param accessContext Access-context. (NotNull)
+ */
+ public static void setAccessContextOnThread(AccessContext accessContext) {
+ if (accessContext == null) {
+ String msg = "The argument[accessContext] must not be null.";
+ throw new IllegalArgumentException(msg);
+ }
+ threadLocal.set(accessContext);
+ }
+
+ /**
+ * Is existing access-context on thread?
+ *
+ * @return Determination.
+ */
+ public static boolean isExistAccessContextOnThread() {
+ return (threadLocal.get() != null);
+ }
+
+ /**
+ * Clear access-context on thread.
+ */
+ public static void clearAccessContextOnThread() {
+ threadLocal.set(null);
+ }
+
+ // ===================================================================================
+ // Access Information
+ // ==================
+ /**
+ * Get access user on thread.
+ *
+ * If it can't get access user from access-context,
+ * returns 'Anonymous' as default value!
+ *
+ * @return Access user. (NotNull)
+ */
+ public static String getAccessUserOnThread() {
+ if (isExistAccessContextOnThread()) {
+ final AccessContext userContextOnThread = getAccessContextOnThread();
+ final String accessUser = userContextOnThread.getAccessUser();
+ if (accessUser != null) {
+ return accessUser;
+ }
+ }
+ return "Anonymous";// as Default
+ }
+
+ /**
+ * Get access module on thread.
+ *
+ * If it can't get access module from access-context,
+ * returns 'Anonymous' as default value!
+ *
+ * @return Access module. (NotNull)
+ */
+ public static String getAccessModuleOnThread() {
+ if (isExistAccessContextOnThread()) {
+ final AccessContext userContextOnThread = getAccessContextOnThread();
+ final String accessModule = userContextOnThread.getAccessModule();
+ if (accessModule != null) {
+ return accessModule;
+ }
+ }
+ return "Anonymous";// as Default
+ }
+
+ /**
+ * Get access timestamp on thread.
+ *
+ * If it can't get access timestamp from access-context,
+ * returns application current time as default value!
+ *
+ * @return Access timestamp. (NotNull)
+ */
+ public static java.sql.Timestamp getAccessTimestampOnThread() {
+ if (isExistAccessContextOnThread()) {
+ final AccessContext userContextOnThread = getAccessContextOnThread();
+ final java.sql.Timestamp accessTimestamp = userContextOnThread.getAccessTimestamp();
+ if (accessTimestamp != null) {
+ return accessTimestamp;
+ }
+ }
+ return new java.sql.Timestamp(System.currentTimeMillis());// as Default
+ }
+
+ // ===================================================================================
+ // Attribute
+ // =========
+ protected String accessUser;
+
+ protected String accessModule;
+
+ protected java.sql.Timestamp accessTimestamp;
+
+ // ===================================================================================
+ // Accessor
+ // ========
+ public String getAccessUser() {
+ return accessUser;
+ }
+
+ public void setAccessUser(String accessUser) {
+ this.accessUser = accessUser;
+ }
+
+ public String getAccessModule() {
+ return accessModule;
+ }
+
+ public void setAccessModule(String accessModule) {
+ this.accessModule = accessModule;
+ }
+
+ public java.sql.Timestamp getAccessTimestamp() {
+ return accessTimestamp;
+ }
+
+ public void setAccessTimestamp(java.sql.Timestamp accessTimestamp) {
+ this.accessTimestamp = accessTimestamp;
+ }
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/CacheDaoSelector.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/CacheDaoSelector.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/CacheDaoSelector.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,287 @@
+package jp.sf.pal.pompei.allcommon;
+
+import jp.sf.pal.pompei.allcommon.bhv.BehaviorReadable;
+import jp.sf.pal.pompei.allcommon.bhv.BehaviorWritable;
+
+import jp.sf.pal.pompei.allcommon.dbmeta.DBMetaInstanceHandler;
+import jp.sf.pal.pompei.allcommon.dbmeta.DBMeta;
+
+import org.seasar.framework.container.S2Container;
+
+/**
+ * The implementation of dao-selector.
+ *
+ * Long long ago this object have cache of dao and bhv.
+ * But the cache cause wrong performance when this is initialized.
+ * So now this object don't have cache.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public class CacheDaoSelector implements DaoSelector {
+
+ protected S2Container _container;
+
+ public void setContainer(S2Container container) {
+ this._container = container;
+ }
+
+ /**
+ * Get dao.
+ *
+ * @param daoType Dao type. (NotNull)
+ * @return Dao. (NotNull)
+ */
+ public DAO_TYPE getDao(Class daoType) {
+ return (DAO_TYPE)_container.getComponent(daoType);
+ }
+
+ /**
+ * Get dao-readable.
+ *
+ * @param tableMultiName Table multi-name. (NotNull)
+ * @return Dao-readable. (NotNull)
+ */
+ public DaoReadable byNameAsDaoReadable(String tableMultiName) {
+ assertStringNotNullAndNotTrimmedEmpty("tableMultiName", tableMultiName);
+ final DBMeta dbmeta = DBMetaInstanceHandler.getInstanceByTableMultiName(tableMultiName);
+ return getDao(getDaoType(dbmeta));
+ }
+
+ /**
+ * Get behavior.
+ *
+ * @param behaviorType Behavior type. (NotNull)
+ * @return Behavior. (NotNull)
+ */
+ public BEHAVIOR_TYPE getBehavior(Class behaviorType) {
+ return (BEHAVIOR_TYPE)_container.getComponent(behaviorType);
+ }
+
+ /**
+ * Get behavior-readable.
+ *
+ * @param tableMultiName Table multi-name. (NotNull)
+ * @return Behavior-readable. (NotNull)
+ */
+ public BehaviorReadable byNameAsBehaviorReadable(String tableMultiName) {
+ assertStringNotNullAndNotTrimmedEmpty("tableMultiName", tableMultiName);
+ final DBMeta dbmeta = DBMetaInstanceHandler.getInstanceByTableMultiName(tableMultiName);
+ return getBehavior(getBehaviorType(dbmeta));
+ }
+
+ /**
+ * Get dao-readable by dao type.
+ *
+ * @param daoType Dao type. (NotNull)
+ * @return Dao-readable. (NotNull)
+ */
+ public DaoReadable getRDao(Class daoType) {
+ assertObjectNotNull("daoType", daoType);
+ return (DaoReadable)_container.getComponent(daoType);
+ }
+
+ /**
+ * Get dao-readable by entity.
+ *
+ * @param entity Entity. (NotNull)
+ * @return Dao-readable. (NotNull)
+ */
+ public DaoReadable getRDao(Entity entity) {
+ assertObjectNotNull("entity", entity);
+ return getRDao(getDaoType(entity.getDBMeta()));
+ }
+
+ /**
+ * Get dao-readable by table multi-name.
+ *
+ * @param tableMultiName Table multi-name. (NotNull)
+ * @return Dao-readable. (NotNull)
+ */
+ public DaoReadable getRDao(String tableMultiName) {
+ assertStringNotNullAndNotTrimmedEmpty("tableMultiName", tableMultiName);
+ final DBMeta dbmeta = DBMetaInstanceHandler.getInstanceByTableMultiName(tableMultiName);
+ return getRDao(getDaoType(dbmeta));
+ }
+
+ /**
+ * Get dao-writable by dao type.
+ *
+ * @param daoType Dao type. (NotNull)
+ * @return Dao-writable. (NotNull)
+ */
+ public DaoWritable getWDao(Class daoType) {
+ assertObjectNotNull("daoType", daoType);
+ return (DaoWritable)getRDao(daoType);
+ }
+
+ /**
+ * Get dao-writable by entity.
+ *
+ * @param entity Entity. (NotNull)
+ * @return Dao-writable. (NotNull)
+ */
+ public DaoWritable getWDao(Entity entity) {
+ assertObjectNotNull("entity", entity);
+ return (DaoWritable)getRDao(entity);
+ }
+
+ /**
+ * Get dao-writable by table multi-name.
+ *
+ * @param tableMultiName Table multi-name. (NotNull)
+ * @return Dao-writable. (NotNull)
+ */
+ public DaoWritable getWDao(String tableMultiName) {
+ assertStringNotNullAndNotTrimmedEmpty("tableMultiName", tableMultiName);
+ return (DaoWritable)getRDao(tableMultiName);
+ }
+
+ /**
+ * Get bhv-readable by bhv type.
+ *
+ * @param bhvType Bhv type. (NotNull)
+ * @return Bhv-readable. (NotNull)
+ */
+ public BehaviorReadable getRBhv(Class bhvType) {
+ assertObjectNotNull("bhvType", bhvType);
+ return (BehaviorReadable)_container.getComponent(bhvType);
+ }
+
+ /**
+ * Get bhv-readable by entity.
+ *
+ * @param entity Entity. (NotNull)
+ * @return Bhv-readable. (NotNull)
+ */
+ public BehaviorReadable getRBhv(Entity entity) {
+ assertObjectNotNull("entity", entity);
+ return getRBhv(getBehaviorType(entity.getDBMeta()));
+ }
+
+ /**
+ * Get bhv-readable by table multi-name.
+ *
+ * @param tableMultiName Table multi-name. (NotNull)
+ * @return Bhv-readable. (NotNull)
+ */
+ public BehaviorReadable getRBhv(String tableMultiName) {
+ assertStringNotNullAndNotTrimmedEmpty("tableMultiName", tableMultiName);
+ final DBMeta dbmeta = DBMetaInstanceHandler.getInstanceByTableMultiName(tableMultiName);
+ return getRBhv(getBehaviorType(dbmeta));
+ }
+
+ /**
+ * Get bhv-writable by bhv type.
+ *
+ * @param bhvType Bhv type. (NotNull)
+ * @return Bhv-writable. (NotNull)
+ */
+ public BehaviorWritable getWBhv(Class bhvType) {
+ assertObjectNotNull("bhvType", bhvType);
+ return (BehaviorWritable)getRBhv(bhvType);
+ }
+
+ /**
+ * Get bhv-writable by entity.
+ *
+ * @param entity Entity. (NotNull)
+ * @return Bhv-writable. (NotNull)
+ */
+ public BehaviorWritable getWBhv(Entity entity) {
+ assertObjectNotNull("entity", entity);
+ return (BehaviorWritable)getRBhv(entity);
+ }
+
+ /**
+ * Get bhv-writable by table multi-name.
+ *
+ * @param tableMultiName Table multi-name. (NotNull)
+ * @return Bhv-writable. (NotNull)
+ */
+ public BehaviorWritable getWBhv(String tableMultiName) {
+ assertStringNotNullAndNotTrimmedEmpty("tableMultiName", tableMultiName);
+ return (BehaviorWritable)getRBhv(tableMultiName);
+ }
+
+ /**
+ * Get behavior-type by dbmeta.
+ *
+ * @param dbmeta Dbmeta. (NotNull)
+ * @return Behavior-type. (NotNull)
+ */
+ protected Class getBehaviorType(DBMeta dbmeta) {
+ final String behaviorTypeName = dbmeta.getBehaviorTypeName();
+ if (behaviorTypeName == null) {
+ String msg = "The dbmeta.getBehaviorTypeName() should not return null: dbmeta=" + dbmeta;
+ throw new IllegalStateException(msg);
+ }
+ final Class behaviorType;
+ try {
+ behaviorType = Class.forName(behaviorTypeName);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("The class does not exist: " + behaviorTypeName, e);
+ }
+ return behaviorType;
+ }
+
+ protected Class getDaoType(DBMeta dbmeta) {
+ final String daoTypeName = dbmeta.getDaoTypeName();
+ if (daoTypeName == null) {
+ String msg = "The dbmeta.getDaoTypeName() should not return null: dbmeta=" + dbmeta;
+ throw new IllegalStateException(msg);
+ }
+ final Class daoType;
+ try {
+ daoType = Class.forName(daoTypeName);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("The class does not exist: " + daoTypeName, e);
+ }
+ return daoType;
+ }
+
+ // =====================================================================================
+ // Destroy
+ // =======
+ public void destroy() {
+ _container = null;
+ }
+
+ // ----------------------------------------------------------------
+ // Assert Object
+ // -------------
+ /**
+ * Assert that the object is not null.
+ *
+ * @param variableName Variable name. (NotNull)
+ * @param value Value. (NotNull)
+ * @exception IllegalArgumentException
+ */
+ protected void assertObjectNotNull(String variableName, Object value) {
+ if (variableName == null) {
+ String msg = "The value should not be null: variableName=" + variableName + " value=" + value;
+ throw new IllegalArgumentException(msg);
+ }
+ if (value == null) {
+ String msg = "The value should not be null: variableName=" + variableName;
+ throw new IllegalArgumentException(msg);
+ }
+ }
+
+ // ----------------------------------------------------------------
+ // Assert String
+ // -------------
+ /**
+ * Assert that the entity is not null and not trimmed empty.
+ *
+ * @param variableName Variable name. (NotNull)
+ * @param value Value. (NotNull)
+ */
+ protected void assertStringNotNullAndNotTrimmedEmpty(String variableName, String value) {
+ assertObjectNotNull("variableName", variableName);
+ assertObjectNotNull("value", value);
+ if (value.trim().length() ==0) {
+ String msg = "The value should not be empty: variableName=" + variableName + " value=" + value;
+ throw new IllegalArgumentException(msg);
+ }
+ }
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/DaoReadable.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/DaoReadable.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/DaoReadable.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,12 @@
+package jp.sf.pal.pompei.allcommon;
+
+/**
+ * The interface of dao-readable.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public interface DaoReadable {
+ // [Developer's comment] (2006/06/08)
+ // It cannot be done for the convenience of s2dao though I want to define methods for condition-bean here.
+ // DTO argument as Interface is not accepted.
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/DaoSelector.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/DaoSelector.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/DaoSelector.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,152 @@
+package jp.sf.pal.pompei.allcommon;
+
+import jp.sf.pal.pompei.allcommon.bhv.BehaviorReadable;
+import jp.sf.pal.pompei.allcommon.bhv.BehaviorWritable;
+
+/**
+ * The interface of dao-selector.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public interface DaoSelector {
+
+ /**
+ * Get dao.
+ *
+ * @param daoType Dao type. (NotNull)
+ * @return Dao. (NotNull)
+ */
+ public DAO_TYPE getDao(Class daoType);
+
+ /**
+ * Get dao-readable.
+ *
+ * @param tableMultiName Table multi-name. (NotNull)
+ * @return Dao-readable. (NotNull)
+ */
+ public DaoReadable byNameAsDaoReadable(String tableMultiName);
+
+ /**
+ * Get behavior.
+ *
+ * @param behaviorType Behavior type. (NotNull)
+ * @return Behavior. (NotNull)
+ */
+ public BEHAVIOR_TYPE getBehavior(Class behaviorType);
+
+ /**
+ * Get behavior-readable.
+ *
+ * @param tableMultiName Table multi-name. (NotNull)
+ * @return Behavior-readable. (NotNull)
+ */
+ public BehaviorReadable byNameAsBehaviorReadable(String tableMultiName);
+
+ /**
+ * Get dao-readable by dao type.
+ *
+ * @param daoType Dao type. (NotNull)
+ * @return Dao-readable. (NotNull)
+ * @deprecated
+ */
+ public DaoReadable getRDao(Class daoType);
+
+ /**
+ * Get dao-readable by entity.
+ *
+ * @param entity Entity. (NotNull)
+ * @return Dao-readable. (NotNull)
+ * @deprecated
+ */
+ public DaoReadable getRDao(Entity entity);
+
+ /**
+ * Get dao-readable by table multi-name.
+ *
+ * @param tableMultiName Table multi-name. (NotNull)
+ * @return Dao-readable. (NotNull)
+ * @deprecated
+ */
+ public DaoReadable getRDao(String tableMultiName);
+
+ /**
+ * Get dao-writable by dao type.
+ *
+ * @param daoType Dao type. (NotNull)
+ * @return Dao-writable. (NotNull)
+ * @deprecated
+ */
+ public DaoWritable getWDao(Class daoType);
+
+ /**
+ * Get dao-writable by entity.
+ *
+ * @param entity Entity. (NotNull)
+ * @return Dao-writable. (NotNull)
+ * @deprecated
+ */
+ public DaoWritable getWDao(Entity entity);
+
+ /**
+ * Get dao-writable by table multi-name.
+ *
+ * @param tableMultiName Table multi-name. (NotNull)
+ * @return Dao-writable. (NotNull)]
+ * @deprecated
+ */
+ public DaoWritable getWDao(String tableMultiName);
+
+ /**
+ * Get bhv-readable by bhv type.
+ *
+ * @param bhvType Bhv type. (NotNull)
+ * @return Bhv-readable. (NotNull)
+ * @deprecated
+ */
+ public BehaviorReadable getRBhv(Class bhvType);
+
+ /**
+ * Get bhv-readable by entity.
+ *
+ * @param entity Entity. (NotNull)
+ * @return Bhv-readable. (NotNull)
+ * @deprecated
+ */
+ public BehaviorReadable getRBhv(Entity entity);
+
+ /**
+ * Get bhv-readable by table multi-name.
+ *
+ * @param tableMultiName Table multi-name. (NotNull)
+ * @return Bhv-readable. (NotNull)
+ * @deprecated
+ */
+ public BehaviorReadable getRBhv(String tableMultiName);
+
+ /**
+ * Get bhv-writable by bhv type.
+ *
+ * @param bhvType Bhv type. (NotNull)
+ * @return Bhv-writable. (NotNull)
+ * @deprecated
+ */
+ public BehaviorWritable getWBhv(Class bhvType);
+
+ /**
+ * Get bhv-writable by entity.
+ *
+ * @param entity Entity. (NotNull)
+ * @return Bhv-writable. (NotNull)
+ * @deprecated
+ */
+ public BehaviorWritable getWBhv(Entity entity);
+
+ /**
+ * Get bhv-writable by table multi-name.
+ *
+ * @param tableMultiName Table multi-name. (NotNull)
+ * @return Bhv-writable. (NotNull)
+ * @deprecated
+ */
+ public BehaviorWritable getWBhv(String tableMultiName);
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/DaoWritable.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/DaoWritable.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/DaoWritable.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,67 @@
+package jp.sf.pal.pompei.allcommon;
+
+import jp.sf.pal.pompei.allcommon.Entity;
+
+/**
+ * The interface of dao-writable.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public interface DaoWritable extends DaoReadable {
+
+ /**
+ * Insert one entity that the type is entity-interface.
+ *
+ * @param entity Entity that the type is entity-interface. (NotNull)
+ * @return Inserted count.
+ */
+ public int create(Entity entity);
+
+ /**
+ * Update one entity that the type is entity-interface.
+ *
+ * @param entity Entity that the type is entity-interface. (NotNull)
+ * @return Updated count.
+ */
+ public int modify(Entity entity);
+
+ /**
+ * Update one entity that the type is entity-interface. (modified only)
+ *
+ * @param entity Entity that the type is entity-interface. (NotNull)
+ * @return Updated count.
+ */
+ public int modifyModifiedOnly(Entity entity);
+
+ /**
+ * Delete one entity that the type is entity-interface.
+ *
+ * @param entity Entity that the type is entity-interface. (NotNull)
+ * @return Deleted count.
+ */
+ public int remove(Entity entity);
+
+ /**
+ * Insert several entities that the type is entity-interface.
+ *
+ * @param entityList Entity-list that the type is entity-interface. (NotNull)
+ * @return Inserted count.
+ */
+ public int createList(java.util.List entityList);
+
+ /**
+ * Update several entities that the type is entity-interface.
+ *
+ * @param entityList Entity-list that the type is entity-interface. (NotNull)
+ * @return Updated count.
+ */
+ public int modifyList(java.util.List entityList);
+
+ /**
+ * Delete several entities that the type is entity-interface.
+ *
+ * @param entityList Entity-list that the type is entity-interface. (NotNull)
+ * @return Deleted count.
+ */
+ public int removeList(java.util.List entityList);
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/Entity.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/Entity.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/Entity.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,224 @@
+package jp.sf.pal.pompei.allcommon;
+
+import jp.sf.pal.pompei.allcommon.dbmeta.DBMeta;
+import jp.sf.pal.pompei.allcommon.helper.MapListString;
+import jp.sf.pal.pompei.allcommon.helper.MapListStringImpl;
+
+/**
+ * The interface of entity.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public interface Entity {
+
+ // ===================================================================================
+ // Definition
+ // ==========
+ /** Map-string map-mark. */
+ public static final String MAP_STRING_MAP_MARK = "map:";
+
+ /** Map-string list-mark. */
+ public static final String MAP_STRING_LIST_MARK = "list:";
+
+ /** Map-string start-brace. */
+ public static final String MAP_STRING_START_BRACE = "@{";
+
+ /** Map-string end-brace. */
+ public static final String MAP_STRING_END_BRACE = "@}";
+
+ /** Map-string delimiter. */
+ public static final String MAP_STRING_DELIMITER = "@;";
+
+ /** Map-string equal. */
+ public static final String MAP_STRING_EQUAL = "@=";
+
+ // ===================================================================================
+ // DBMeta
+ // ======
+ /**
+ * Get dbmeta.
+ *
+ * @return DBMeta. (NotNull)
+ */
+ public DBMeta getDBMeta();
+
+ // ===================================================================================
+ // Table Name
+ // ==========
+ /**
+ * Get table db-name.
+ *
+ * @return Table db-name. (NotNull)
+ */
+ public String getTableDbName();
+
+ /**
+ * Get table cap-prop-name.
+ *
+ * @return Table cap-prop-name. (NotNull)
+ */
+ public String getTableCapPropName();
+
+ /**
+ * Get table uncap-prop-name.
+ *
+ * @return Table uncap-prop-name. (NotNull)
+ */
+ public String getTableUncapPropName();
+
+ // ===================================================================================
+ // Accept
+ // ======
+ /**
+ * Accept primary-key map.
+ *
+ * @param primaryKeyMap Primary-key map. (NotNull and NotEmpty)
+ * @deprecated Please use DBMeta#acceptPrimaryKeyMap(entity, primaryKeyMap);
+ */
+ public void acceptPrimaryKeyMap(java.util.Map primaryKeyMap);
+
+ /**
+ * Accept primary-key map-string.
+ *
+ * @param primaryKeyMapString Primary-key map-string. (NotNull)
+ * @deprecated Please use DBMeta#acceptPrimaryKeyMapString(entity, primaryKeyMap);
+ */
+ public void acceptPrimaryKeyMapString(String primaryKeyMapString);
+
+ /**
+ * Accept column-value map.
+ *
+ * @param columnValueMap Column-value map. (NotNull and NotEmpty)
+ * @deprecated Please use DBMeta#acceptColumnValueMap(entity, columnValueMap);
+ */
+ public void acceptColumnValueMap(java.util.Map columnValueMap);
+
+ /**
+ * Accept column-value map-string.
+ *
+ * @param columnValueMapString Column-value map-string. (NotNull)
+ * @deprecated Please use DBMeta#acceptColumnValueMapString(entity, columnValueMapString);
+ */
+ public void acceptColumnValueMapString(String columnValueMapString);
+
+ // ===================================================================================
+ // Extract
+ // =======
+ /**
+ * Extract primary-key map-string. Delimiter is at-mark and semicolon.
+ *
+ *
+ * ex) Uses that this method have.
+ * final String primaryKeyMapString = entity.extractPrimaryKeyMapString();
+ * final LdBook entity = dao.selectEntity(new LdBookCB().acceptPrimaryKeyMapString(primaryKeyMapString));
+ * ... // as primary key for condition.
+ *
+ *
+ * @return Primary-key map-string. (NotNull)
+ * @deprecated Please use DBMeta#extractPrimaryKeyMapString(entity);
+ */
+ public String extractPrimaryKeyMapString();
+
+ /**
+ * Extract primary-key map-string.
+ *
+ * @param startBrace Start-brace. (NotNull)
+ * @param endBrace End-brace. (NotNull)
+ * @param delimiter Delimiter. (NotNull)
+ * @param equal Equal. (NotNull)
+ * @return Primary-key map-string. (NotNull)
+ * @deprecated Please use DBMeta#extractPrimaryKeyMapString(entity, startBrace, endBrace, delimiter, equal);
+ */
+ public String extractPrimaryKeyMapString(String startBrace, String endBrace, String delimiter, String equal);
+
+ /**
+ * Extract column-value map-string. Delimiter is at-mark and semicolon.
+ *
+ * @return Column-value map-string. (NotNull)
+ * @deprecated Please use DBMeta#extractColumnValueMapString(entity);
+ */
+ public String extractColumnValueMapString();
+
+ /**
+ * Extract column-value map-string.
+ *
+ * @param startBrace Start-brace. (NotNull)
+ * @param endBrace End-brace. (NotNull)
+ * @param delimiter Delimiter. (NotNull)
+ * @param equal Equal. (NotNull)
+ * @return Column-value map-string. (NotNull)
+ * @deprecated Please use DBMeta#extractColumnValueMapString(entity, startBrace, endBrace, delimiter, equal);
+ */
+ public String extractColumnValueMapString(String startBrace, String endBrace, String delimiter, String equal);
+
+ // ===================================================================================
+ // Determination
+ // =============
+ /**
+ * Has primary-key value?
+ *
+ * @return Determination.
+ */
+ public boolean hasPrimaryKeyValue();
+
+ // ===================================================================================
+ // Modified Properties
+ // ===================
+ /**
+ * Get modified property names. (JavaBeansRule)
+ *
+ * @return Modified property names. (NotNull)
+ */
+ public java.util.Set getModifiedPropertyNames();
+
+ /**
+ * Clear modified property names.
+ */
+ public void clearModifiedPropertyNames();
+
+ /**
+ * Entity modified properties.
+ */
+ public static class EntityModifiedProperties implements java.io.Serializable {
+
+ /** Serial version UID. (Default) */
+ private static final long serialVersionUID = 1L;
+
+ /** Set of properties. */
+ protected java.util.Set _propertiesSet = new java.util.LinkedHashSet();
+
+ /**
+ * Add property name. (JavaBeansRule)
+ *
+ * @param propertyName Property name. (Nullable)
+ */
+ public void addPropertyName(String propertyName) {
+ _propertiesSet.add(propertyName);
+ }
+
+ /**
+ * Get the set of properties.
+ *
+ * @return The set of properties. (NotNull)
+ */
+ public java.util.Set getPropertyNames() {
+ return _propertiesSet;
+ }
+
+ /**
+ * Clear the set of properties.
+ */
+ public void clear() {
+ _propertiesSet.clear();
+ }
+
+ /**
+ * Remove property name from the set. (JavaBeansRule)
+ *
+ * @param propertyName Property name. (Nullable)
+ */
+ public void remove(String propertyName) {
+ _propertiesSet.remove(propertyName);
+ }
+ }
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/EntityDefinedCommonColumn.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/EntityDefinedCommonColumn.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/EntityDefinedCommonColumn.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,17 @@
+package jp.sf.pal.pompei.allcommon;
+
+/**
+ * The interface of entity defined common column.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public interface EntityDefinedCommonColumn extends Entity {
+
+ /**
+ * Extract common-column-value map-string.
+ *
+ * @return Common-column-value map-string. (NotNull)
+ * @deprecated Please use DBMeta#extractCommonColumnValueMapString(entity);
+ */
+ public String extractCommonColumnValueMapString();
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/GenMetaData.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/GenMetaData.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/GenMetaData.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,409 @@
+package jp.sf.pal.pompei.allcommon;
+
+
+/**
+ * The sigleton class that has generate-meta-data(GenMetaData).
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public class GenMetaData {
+
+ /** Singleton instance. */
+ private static final GenMetaData _instance = new GenMetaData();
+
+ /**
+ * Constructor.
+ */
+ private GenMetaData() {
+ }
+
+ /**
+ * Get instance.
+ *
+ * @return Singleton instance.
+ */
+ public static GenMetaData getInstance() {
+ return _instance;
+ }
+
+ // =========================================================================================
+ // Generated method name
+ // =====================
+ /**
+ * Get the method name of 'getCountAll'.
+ *
+ * @return The method name of 'getCountAll'. (NotNull)
+ */
+ public String getMethodNameOfGetCountAll() {
+ return "getCountAll";
+ }
+
+ /**
+ * Get the method name of 'getListAll'.
+ *
+ * @return The method name of 'getListAll'. (NotNull)
+ */
+ public String getMethodNameOfGetListAll() {
+ return "getListAll";
+ }
+
+ /**
+ * Get the method name of 'getEntity'.
+ *
+ * @return The method name of 'getEntity'. (NotNull)
+ */
+ public String getMethodNameOfGetEntity() {
+ return "getEntity";
+ }
+
+ /**
+ * Get the method name of 'selectCountIgnoreFetchNarrowing'.
+ *
+ * @return The method name of 'selectCountIgnoreFetchNarrowing'. (NotNull)
+ */
+ public String getMethodNameOfSelectCountIgnoreFetchScope() {
+ return "selectCountIgnoreFetchScope";
+ }
+
+ /**
+ * Get the method name of 'selectEntity'.
+ *
+ * @return The method name of 'selectEntity'. (NotNull)
+ */
+ public String getMethodNameOfSelectEntity() {
+ return "selectEntity";
+ }
+
+ /**
+ * Get the method name of 'selectList'.
+ *
+ * @return The method name of 'selectList'. (NotNull)
+ */
+ public String getMethodNameOfSelectList() {
+ return "selectList";
+ }
+
+ // =========================================================================================
+ // Only when having generated, the effective one
+ // =============================================
+ // -------------------------------------------------------------------------------
+ // Basic
+ // -----
+ /**
+ * Get the property-value of targetLanguage.
+ *
+ * @return The property-value.
+ */
+ public String getTargetLanguage() {
+ return "java";
+ }
+
+ /**
+ * Get the property-value of templateFileExtension.
+ *
+ * @return The property-value.
+ */
+ public String getTemplateFileExtension() {
+ return "vm";
+ }
+
+ /**
+ * Get the property-value of classFileExtension.
+ *
+ * @return The property-value.
+ */
+ public String getClassFileExtension() {
+ return "java";
+ }
+
+ /**
+ * Get the property-value of templateFileEncoding.
+ *
+ * @return The property-value.
+ */
+ public String getTemplateEncoding() {
+ return "UTF-8";
+ }
+
+ /**
+ * Get the property-value of classAuthor.
+ *
+ * @return The property-value.
+ */
+ public String getClassAuthor() {
+ return "DBFlute(AutoGenerator)";
+ }
+
+ // -------------------------------------------------------------------------------
+ // Available
+ // ---------
+ /**
+ * Is java name of table same as db name? Answer is false!
+ *
+ * @return The property-value.
+ */
+ public boolean isJavaNameOfTableSameAsDbName() {
+ return false;
+ }
+
+ /**
+ * Is java name of column same as db name? Answer is false!
+ *
+ * @return The property-value.
+ */
+ public boolean isJavaNameOfColumnSameAsDbName() {
+ return false;
+ }
+
+ /**
+ * Is available behavior generation? Answer is true!
+ *
+ * @return The property-value.
+ */
+ public boolean isAvailableBehaviorGeneration() {
+ return true;
+ }
+
+ /**
+ * Is available common-column-setup interceptor to behavior? Answer is false!
+ *
+ * @return The property-value.
+ */
+ public boolean isAvailableCommonColumnSetupInterceptorToBehavior() {
+ return false;
+ }
+
+ /**
+ * Is available common-column-setup interceptor to dao? Answer is false!
+ *
+ * @return The property-value.
+ */
+ public boolean isAvailableCommonColumnSetupInterceptorToDao() {
+ return false;
+ }
+
+ /**
+ * Is available generics? Answer is true!
+ *
+ * @return The property-value.
+ */
+ public boolean isAvailableGenerics() {
+ return true;
+ }
+
+ // -------------------------------------------------------------------------------
+ // Prefix
+ // ------
+ /**
+ * Get the property-value of projectPrefix.
+ *
+ * @return The property-value.
+ */
+ public String getProjectPrefix() {
+ return "";
+ }
+
+ /**
+ * Get the property-value of basePrefix.
+ *
+ * @return The property-value.
+ */
+ public String getBasePrefix() {
+ return "Bs";
+ }
+
+ // -------------------------------------------------------------------------------
+ // DaoDicon
+ // --------
+ /**
+ * Get the property-value of daoDiconNamespace.
+ *
+ * @return The property-value.
+ */
+ public String getDaoDiconNamespace() {
+ return "dbflute";
+ }
+
+ /**
+ * Get the property-value of daoDiconPackageName.
+ *
+ * @return The property-value.
+ */
+ public String getDaoDiconPackageName() {
+ return "";
+ }
+
+ /**
+ * Get the property-value of daoDiconFileName.
+ *
+ * @return The property-value.
+ */
+ public String getDaoDiconFileName() {
+ return "dbflute.dicon";
+ }
+
+ /**
+ * Get the property-value of jdbcDiconResourceName.
+ *
+ * @return The property-value.
+ */
+ public String getJdbcDiconResourceName() {
+ return "j2ee.dicon";
+ }
+
+ /**
+ * Get the property-value of requiredTxComponentName.
+ *
+ * @return The property-value.
+ */
+ public String getRequiredTxComponentName() {
+ return "requiredTx";
+ }
+
+ // -------------------------------------------------------------------------------
+ // Package
+ // -------
+ /**
+ * Get the property-value of baseCommonPackage.
+ *
+ * @return The property-value.
+ */
+ public String getBaseCommonPackage() {
+ return "jp.sf.pal.pompei.allcommon";
+ }
+
+ /**
+ * Get the property-value of baseBehaviorPackage.
+ *
+ * @return The property-value.
+ */
+ public String getBaseBehaviorPackage() {
+ return "jp.sf.pal.pompei.bsbhv";
+ }
+
+ /**
+ * Get the property-value of baseDaoPackage.
+ *
+ * @return The property-value.
+ */
+ public String getBaseDaoPackage() {
+ return "jp.sf.pal.pompei.bsdao";
+ }
+
+ /**
+ * Get the property-value of baseEntityPackage.
+ *
+ * @return The property-value.
+ */
+ public String getBaseEntityPackage() {
+ return "jp.sf.pal.pompei.bsentity";
+ }
+
+ /**
+ * Get the property-value of conditionBeanPackage.
+ *
+ * @return The property-value.
+ */
+ public String getConditionBeanPackage() {
+ return "jp.sf.pal.pompei.cbean";
+ }
+
+ /**
+ * Get the property-value of extendedDaoPackage.
+ *
+ * @return The property-value.
+ */
+ public String getExtendedDaoPackage() {
+ return "jp.sf.pal.pompei.exdao";
+ }
+
+ /**
+ * Get the property-value of extendedBehaviorPackage.
+ *
+ * @return The property-value.
+ */
+ public String getExtendedBehaviorPackage() {
+ return "jp.sf.pal.pompei.exbhv";
+ }
+
+ /**
+ * Get the property-value of extendedEntityPackage.
+ *
+ * @return The property-value.
+ */
+ public String getExtendedEntityPackage() {
+ return "jp.sf.pal.pompei.exentity";
+ }
+
+ // -------------------------------------------------------------------------------
+ // Optimistic Lock
+ // ---------------
+ /**
+ * Get the property-value of updateDateFieldName.
+ *
+ * @return The property-value.
+ */
+ public String getUpdateDateFieldName() {
+ return "";
+ }
+
+ /**
+ * Get the property-value of versionNoFieldName.
+ *
+ * @return The property-value.
+ */
+ public String getVersionNoFieldName() {
+ return "";
+ }
+
+ // -------------------------------------------------------------------------------
+ // Select Param
+ // ------------
+ /**
+ * Get the property-value of selectQueryTimeout.
+ *
+ * @return The property-value.
+ */
+ public int getSelectQueryTimeout() {
+ return -1;
+ }
+
+ // -------------------------------------------------------------------------------
+ // Extract
+ // -------
+ /**
+ * Get the value of 'extractAcceptStartBrace'.
+ *
+ * @return The property-value. (NotNull)
+ */
+ public String getExtractAcceptStartBrace() {
+ return "@{";
+ }
+
+ /**
+ * Get the value of 'extractAcceptEndBrace'.
+ *
+ * @return The property-value. (NotNull)
+ */
+ public String getExtractAcceptEndBrace() {
+ return "@}";
+ }
+
+ /**
+ * Get the value of 'extractAcceptDelimiter'.
+ *
+ * @return The property-value. (NotNull)
+ */
+ public String getExtractAcceptDelimiter() {
+ return "@;";
+ }
+
+ /**
+ * Get the value of 'extractAcceptEqual'.
+ *
+ * @return The property-value. (NotNull)
+ */
+ public String getExtractAcceptEqual() {
+ return "@=";
+ }
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/annotation/OutsideSql.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/annotation/OutsideSql.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/annotation/OutsideSql.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,13 @@
+package jp.sf.pal.pompei.allcommon.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+ △ Inherited
+ △ Retention(RetentionPolicy.RUNTIME)
+ △ Target(ElementType.METHOD)
+public @interface OutsideSql {
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/AbstractBehaviorReadable.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/AbstractBehaviorReadable.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/AbstractBehaviorReadable.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,516 @@
+
+package jp.sf.pal.pompei.allcommon.bhv;
+
+import jp.sf.pal.pompei.allcommon.DaoSelector;
+import jp.sf.pal.pompei.allcommon.Entity;
+import jp.sf.pal.pompei.allcommon.bhv.setup.ValueLabelSetupper;
+import jp.sf.pal.pompei.allcommon.bhv.setup.ValueLabelBox;
+import jp.sf.pal.pompei.allcommon.cbean.ConditionBean;
+import jp.sf.pal.pompei.allcommon.cbean.ListResultBean;
+import jp.sf.pal.pompei.allcommon.cbean.PagingBean;
+import jp.sf.pal.pompei.allcommon.cbean.PagingResultBean;
+
+import jp.sf.pal.pompei.allcommon.bhv.batch.TokenFileOutputOption;
+import jp.sf.pal.pompei.allcommon.bhv.batch.TokenFileOutputResult;
+
+import jp.sf.pal.pompei.allcommon.helper.token.file.FileMakingOption;
+import jp.sf.pal.pompei.allcommon.helper.token.file.FileMakingHeaderInfo;
+import jp.sf.pal.pompei.allcommon.helper.token.file.FileMakingSimpleFacade;
+import jp.sf.pal.pompei.allcommon.helper.token.file.impl.FileMakingSimpleFacadeImpl;
+
+/**
+ * The abstract class of behavior-readable.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public abstract class AbstractBehaviorReadable implements BehaviorReadable {
+
+ // ===================================================================================
+ // Attribute
+ // =========
+ /** Dao-selector instance. */
+ protected DaoSelector _daoSelector;
+
+ // ===================================================================================
+ // Constructor
+ // ===========
+ /**
+ * Constructor.
+ */
+ public AbstractBehaviorReadable() {
+ }
+
+ // ===================================================================================
+ // Dao Accessor
+ // ============
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @return Dao-selector.
+ */
+ public DaoSelector getDaoSelector() {
+ return _daoSelector;
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @param value Dao-selector.
+ */
+ public void setDaoSelector(DaoSelector value) {
+ _daoSelector = value;
+ }
+
+ // ===================================================================================
+ // Delegate Method
+ // ===============
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @return All count.
+ */
+ public int callGetCountAll() {
+ final java.lang.reflect.Method mtd = getMethod(getDaoReadable().getClass(), "getCountAll", new Class[]{});
+ final Object result = invoke(mtd, getDaoReadable(), new Object[]{});
+ return ((Integer)result).intValue();
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @return All list. (NotNull)
+ */
+ public java.util.List callGetListAll() {
+ final java.lang.reflect.Method mtd = getMethod(getDaoReadable().getClass(), "getListAll", new Class[]{});
+ final Object result = invoke(mtd, getDaoReadable(), new Object[]{});
+ return (java.util.List)result;
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @param cb Condition-bean that the type is condition-bean-interface. (NotNull)
+ * @return Read count. (NotNull)
+ */
+ public int callReadCount(ConditionBean cb) {
+ assertConditionBeanNotNull(cb);
+ final Class[] types = new Class[]{cb.getClass()};
+ final java.lang.reflect.Method mtd = getMethod(getDaoReadable().getClass(), "selectCount", types);
+ final Object result = invoke(mtd, getDaoReadable(), new Object[]{cb});
+ return ((Integer)result).intValue();
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @param cb Condition-bean that the type is condition-bean-interface. (NotNull)
+ * @return Read entity. If the select result is zero, it returns null. (Nullable)
+ */
+ public Entity callReadEntity(ConditionBean cb) {
+ assertConditionBeanNotNull(cb);
+ final Class[] types = new Class[]{cb.getClass()};
+ final java.lang.reflect.Method mtd = getMethod(getDaoReadable().getClass(), "selectEntity", types);
+ final Object result = invoke(mtd, getDaoReadable(), new Object[]{cb});
+ return (Entity)result;
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @param cb Condition-bean that the type is condition-bean-interface. (NotNull)
+ * @return Read list. If the select result is zero, it returns empty list. (NotNull)
+ */
+ public java.util.List callReadList(ConditionBean cb) {
+ assertConditionBeanNotNull(cb);
+ final Class[] types = new Class[]{cb.getClass()};
+ final java.lang.reflect.Method mtd = getMethod(getDaoReadable().getClass(), "selectList", types);
+ final Object result = invoke(mtd, getDaoReadable(), new Object[]{cb});
+ return (java.util.List)result;
+ }
+
+ private java.lang.reflect.Method getMethod(Class clazz, String methodName, Class[] argTypes) {
+ try {
+ return clazz.getMethod(methodName, argTypes);
+ } catch (NoSuchMethodException ex) {
+ String msg = "class=" + clazz + " method=" + methodName + "-" + java.util.Arrays.asList(argTypes);
+ throw new RuntimeException(msg, ex);
+ }
+ }
+
+ private Object invoke(java.lang.reflect.Method method, Object target, Object[] args) {
+ try {
+ return method.invoke(target, args);
+ } catch (java.lang.reflect.InvocationTargetException ex) {
+ Throwable t = ex.getCause();
+ if (t instanceof RuntimeException) {
+ throw (RuntimeException) t;
+ }
+ if (t instanceof Error) {
+ throw (Error) t;
+ }
+ String msg = "target=" + target + " method=" + method + "-" + java.util.Arrays.asList(args);
+ throw new RuntimeException(msg, ex);
+ } catch (IllegalAccessException ex) {
+ String msg = "target=" + target + " method=" + method + "-" + java.util.Arrays.asList(args);
+ throw new RuntimeException(msg, ex);
+ }
+ }
+
+ // =====================================================================================
+ // Basic Get All
+ // =============
+ /**
+ * Get count all.
+ *
+ * @return Count all.
+ */
+ public int getCountAll() {
+ return callGetCountAll();
+ }
+
+ // =====================================================================================
+ // Basic Read Count
+ // ================
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @param cb Condition-bean. This condition-bean should not be set up about fetch-scope. (NotNull)
+ * @return Read count. (NotNull)
+ */
+ public int readCount(ConditionBean cb) {
+ assertConditionBeanNotNull(cb);
+ return callReadCount(cb);
+ }
+
+ // =====================================================================================
+ // Basic Read Entity
+ // =================
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @param cb Condition-bean. (NotNull)
+ * @return Read entity. (Nullalble)
+ * @exception jp.sf.pal.pompei.allcommon.exception.RecordHasOverlappedException
+ */
+ public Entity readEntity(ConditionBean cb) {
+ assertConditionBeanNotNull(cb);
+ final java.util.List ls = readList(cb);
+ if (ls.isEmpty()) {
+ return null;
+ }
+ assertRecordHasBeenSelectedAsOne(ls, cb);
+ return (Entity)ls.get(0);
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @param cb Condition-bean. (NotNull)
+ * @return Read entity. (NotNull)
+ * @exception jp.sf.pal.pompei.allcommon.exception.RecordHasAlreadyBeenDeletedException
+ * @exception jp.sf.pal.pompei.allcommon.exception.RecordHasOverlappedException
+ */
+ public Entity readEntityWithDeletedCheck(ConditionBean cb) {
+ assertConditionBeanNotNull(cb);
+ final java.util.List ls = readList(cb);
+ assertRecordHasNotBeenDeleted(ls, cb);
+ assertRecordHasBeenSelectedAsOne(ls, cb);
+ return (Entity)ls.get(0);
+ }
+
+ // =====================================================================================
+ // Basic Read List
+ // ===============
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @param cb Condition-bean.
+ * @return List-result-bean. If the select result is zero, it returns empty list. (NotNull)
+ */
+ public ListResultBean readList(ConditionBean cb) {
+ assertConditionBeanNotNull(cb);
+ return new ResultBeanBuilder(this).buildListResultBean(cb, callReadList(cb));
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @param cb Condition-bean. (NotNull)
+ * @return Read page. (NotNull)
+ */
+ public PagingResultBean readPage(final ConditionBean cb) {
+ assertConditionBeanNotNull(cb);
+ return readPage(cb, new SelectPageSimpleInvoker(this));
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @param cb Condition-bean. (NotNull)
+ * @param invoker Select-page-invoker (NotNull)
+ * @return Read page. (NotNull)
+ */
+ public PagingResultBean readPage(final ConditionBean cb, SelectPageInvoker invoker) {
+ assertConditionBeanNotNull(cb);
+ final SelectPageCallback pageCallback = new SelectPageCallback() {
+ public PagingBean getPagingBean() { return cb; }
+ public int selectCountIgnoreFetchScope() {
+ return readCount(cb);
+ }
+ public java.util.List selectListWithFetchScope() {
+ return readList(cb);
+ }
+ };
+ return invoker.invokeSelectPage(pageCallback);
+ }
+
+ /**
+ * Assert that record has not been deleted.
+ *
+ * @param entity Selected entity.
+ * @param searchKey4log Search-key for Logging.
+ * @exception jp.sf.pal.pompei.allcommon.exception.RecordHasAlreadyBeenDeletedException
+ */
+ protected void assertRecordHasNotBeenDeleted(jp.sf.pal.pompei.allcommon.Entity entity, Object searchKey4log) {
+ if (entity == null) {
+ String msg = "The record has already been deleted by other thread: searchKey=" + searchKey4log;
+ throw new jp.sf.pal.pompei.allcommon.exception.RecordHasAlreadyBeenDeletedException(msg);
+ }
+ }
+
+ /**
+ * Assert that record has not been deleted.
+ *
+ * @param ls Selected list.
+ * @param searchKey4log Search-key for Logging.
+ * @exception jp.sf.pal.pompei.allcommon.exception.RecordHasAlreadyBeenDeletedException
+ */
+ protected void assertRecordHasNotBeenDeleted(java.util.List ls, Object searchKey4log) {
+ if (ls == null || ls.isEmpty()) {
+ String msg = "The record has already been deleted by other thread: searchKey=" + searchKey4log;
+ throw new jp.sf.pal.pompei.allcommon.exception.RecordHasAlreadyBeenDeletedException(msg);
+ }
+ }
+
+ /**
+ * Assert that record has been selected as one.
+ *
+ * @param ls Selected list.
+ * @param searchKey4log Search-key for Logging.
+ * @exception jp.sf.pal.pompei.allcommon.exception.RecordHasAlreadyBeenDeletedException
+ * @exception jp.sf.pal.pompei.allcommon.exception.RecordHasOverlappedException
+ */
+ protected void assertRecordHasBeenSelectedAsOne(java.util.List ls, Object searchKey4log) {
+ if (ls == null || ls.isEmpty()) {
+ String msg = "The record has already been deleted by other thread: searchKey=" + searchKey4log;
+ throw new jp.sf.pal.pompei.allcommon.exception.RecordHasAlreadyBeenDeletedException(msg);
+ }
+ if (ls.size() != 1) {
+ String msg = "This selected contents should be only one: searchKey=" + searchKey4log;
+ msg = msg + " resultCount=" + ls.size();
+ throw new jp.sf.pal.pompei.allcommon.exception.RecordHasOverlappedException(msg);
+ }
+ }
+
+ /**
+ * Assert that selected count has not exceeded max count.
+ *
+ * @param selectedCount Selected count.
+ * @param maxCount Max count.
+ * @param clauseObject Clause object for exception message.
+ * @exception jp.sf.pal.pompei.allcommon.exception.SelectedCountExceedMaxCountException
+ */
+ protected void assertSelectedCountHasNotExceededMaxCount(int selectedCount, int maxCount, Object clauseObject) {
+ if (selectedCount > maxCount) {
+ String msg = "Selected count[" + selectedCount + "] has exceeded max count[" + maxCount + "]: clauseObject=" + clauseObject;
+ throw new jp.sf.pal.pompei.allcommon.exception.SelectedCountExceedMaxCountException(msg, selectedCount, maxCount);
+ }
+ }
+
+ // ===================================================================================
+ // Various Select
+ // ==============
+ /**
+ * Select value-label list.
+ *
+ * @param cb Condition-bean. (NotNull)
+ * @param valueLabelSetupper Value-label-setupper. (NotNull)
+ * @return Value-label list. (NotNull)
+ */
+ protected java.util.List> createValueLabelList(ListResultBean ls, ValueLabelSetupper valueLabelSetupper) {
+ final java.util.List> valueLabelList = new java.util.ArrayList>();
+ final ValueLabelBox box = new ValueLabelBox();
+ for (E entity : ls) {
+ final java.util.Map valueLabel = new java.util.HashMap();
+ valueLabelSetupper.setup(box, entity);
+ valueLabel.put("value", box.getValue());
+ valueLabel.put("label", box.getLabel());
+ valueLabelList.add(valueLabel);
+ }
+ return valueLabelList;
+ }
+
+ // ===================================================================================
+ // Token File
+ // ==========
+ /**
+ * Output token-file from this table records.
+ *
+ * @param cb Condition-bean. (NotNull)
+ * @param filename Name of the file. (NotNull and NotEmpty)
+ * @param tokenFileOutputOption token-file-output-option. (NotNull and Required{delimiter and encoding})
+ * @return Token-file-output-result. (NotNull)
+ * @throws java.io.FileNotFoundException
+ * @throws java.io.IOException
+ */
+ public TokenFileOutputResult outputTokenFile(ConditionBean cb, String filename, TokenFileOutputOption tokenFileOutputOption) throws java.io.FileNotFoundException, java.io.IOException {
+ assertConditionBeanNotNull(cb);
+ assertStringNotNullAndNotTrimmedEmpty("filename", filename);
+ assertObjectNotNull("tokenFileOutputOption", tokenFileOutputOption);
+
+ final java.util.List ls = readList(cb);
+ java.util.List> rowList = new java.util.ArrayList>();
+ for (java.util.Iterator ite = ls.iterator(); ite.hasNext(); ) {
+ final Entity entity = (Entity)ite.next();
+ final java.util.List valueList = getDBMeta().convertToColumnStringValueList(entity);
+ rowList.add(valueList);
+ }
+ final FileMakingSimpleFacade fileMakingSimpleFacade = new FileMakingSimpleFacadeImpl();
+ final FileMakingOption fileMakingOption = tokenFileOutputOption.getFileMakingOption();
+ final FileMakingHeaderInfo fileMakingHeaderInfo = new FileMakingHeaderInfo();
+ fileMakingHeaderInfo.setColumnNameList(getDBMeta().getColumnDbNameList());
+ fileMakingOption.setFileMakingHeaderInfo(fileMakingHeaderInfo);
+ fileMakingSimpleFacade.makeFromRowList(filename, rowList, fileMakingOption);
+ final TokenFileOutputResult tokeFileOutputResult = new TokenFileOutputResult();
+ tokeFileOutputResult.setSelectedList(ls);
+ return tokeFileOutputResult;
+ }
+
+ // ===================================================================================
+ // Helper
+ // ======
+ /**
+ * To lower case if the type is String.
+ *
+ * @param obj Object. (Nullable)
+ * @return Lower object. (Nullable)
+ */
+ protected Object toLowerCaseIfString(Object obj) {
+ if (obj != null && obj instanceof String) {
+ return ((String)obj).toLowerCase();
+ }
+ return obj;
+ }
+
+ // ----------------------------------------------------------------
+ // Assert Object
+ // -------------
+ /**
+ * Assert that the object is not null.
+ *
+ * @param variableName Variable name. (NotNull)
+ * @param value Value. (NotNull)
+ * @exception IllegalArgumentException
+ */
+ protected void assertObjectNotNull(String variableName, Object value) {
+ if (variableName == null) {
+ String msg = "The value should not be null: variableName=" + variableName + " value=" + value;
+ throw new IllegalArgumentException(msg);
+ }
+ if (value == null) {
+ String msg = "The value should not be null: variableName=" + variableName;
+ throw new IllegalArgumentException(msg);
+ }
+ }
+
+ /**
+ * Assert that the entity is not null.
+ *
+ * @param entity Entity. (NotNull)
+ */
+ protected void assertEntityNotNull(Entity entity) {
+ assertObjectNotNull("entity", entity);
+ }
+
+ /**
+ * Assert that the condition-bean is not null.
+ *
+ * @param cb Condition-bean. (NotNull)
+ */
+ protected void assertConditionBeanNotNull(jp.sf.pal.pompei.allcommon.cbean.ConditionBean cb) {
+ assertObjectNotNull("cb", cb);
+ }
+
+ /**
+ * Assert that the entity has primary-key value.
+ *
+ * @param entity Entity. (NotNull)
+ */
+ protected void assertEntityNotNullAndHasPrimaryKeyValue(Entity entity) {
+ assertEntityNotNull(entity);
+ if (!entity.hasPrimaryKeyValue()) {
+ String msg = "The entity must should primary-key: entity=" + entity;
+ throw new IllegalArgumentException(msg + entity);
+ }
+ }
+
+ // ----------------------------------------------------------------
+ // Assert String
+ // -------------
+ /**
+ * Assert that the entity is not null and not trimmed empty.
+ *
+ * @param variableName Variable name. (NotNull)
+ * @param value Value. (NotNull)
+ */
+ protected void assertStringNotNullAndNotTrimmedEmpty(String variableName, String value) {
+ assertObjectNotNull("variableName", variableName);
+ assertObjectNotNull(variableName, value);
+ if (value.trim().length() ==0) {
+ String msg = "The value should not be empty: variableName=" + variableName + " value=" + value;
+ throw new IllegalArgumentException(msg);
+ }
+ }
+
+ // ----------------------------------------------------------------
+ // Assert List
+ // -----------
+ /**
+ * Assert that the list is empty.
+ *
+ * @param ls List. (NotNull)
+ */
+ protected void assertListNotNullAndEmpty(java.util.List ls) {
+ assertObjectNotNull("ls", ls);
+ if (!ls.isEmpty()) {
+ String msg = "The list should be empty: ls=" + ls.toString();
+ throw new IllegalArgumentException(msg);
+ }
+ }
+
+ /**
+ * Assert that the list is not empty.
+ *
+ * @param ls List. (NotNull)
+ */
+ protected void assertListNotNullAndNotEmpty(java.util.List ls) {
+ assertObjectNotNull("ls", ls);
+ if (ls.isEmpty()) {
+ String msg = "The list should not be empty: ls=" + ls.toString();
+ throw new IllegalArgumentException(msg);
+ }
+ }
+
+ /**
+ * Assert that the list having only one.
+ *
+ * @param ls List. (NotNull)
+ */
+ protected void assertListNotNullAndHasOnlyOne(java.util.List ls) {
+ assertObjectNotNull("ls", ls);
+ if (ls.size() != 1) {
+ String msg = "The list should contain only one object: ls=" + ls.toString();
+ throw new IllegalArgumentException(msg);
+ }
+ }
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/AbstractBehaviorWritable.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/AbstractBehaviorWritable.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/AbstractBehaviorWritable.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,570 @@
+
+package jp.sf.pal.pompei.allcommon.bhv;
+
+import jp.sf.pal.pompei.allcommon.Entity;
+import jp.sf.pal.pompei.allcommon.helper.MapStringBuilder;
+import jp.sf.pal.pompei.allcommon.helper.MapStringBuilderImpl;
+
+import jp.sf.pal.pompei.allcommon.bhv.batch.TokenFileReflectionOption;
+import jp.sf.pal.pompei.allcommon.bhv.batch.TokenFileReflectionResult;
+import jp.sf.pal.pompei.allcommon.bhv.batch.TokenFileReflectionFailure;
+
+import jp.sf.pal.pompei.allcommon.helper.token.file.FileToken;
+import jp.sf.pal.pompei.allcommon.helper.token.file.FileTokenizingCallback;
+import jp.sf.pal.pompei.allcommon.helper.token.file.FileTokenizingRowResource;
+import jp.sf.pal.pompei.allcommon.helper.token.file.FileTokenizingHeaderInfo;
+import jp.sf.pal.pompei.allcommon.helper.token.file.FileTokenizingOption;
+import jp.sf.pal.pompei.allcommon.helper.token.file.impl.FileTokenImpl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * The abstract class of behavior-writable.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public abstract class AbstractBehaviorWritable extends AbstractBehaviorReadable implements BehaviorWritable {
+
+ /** Log-instance. */
+ private static final Log _log = LogFactory.getLog(AbstractBehaviorWritable.class);
+
+ // =====================================================================================
+ // Constructor
+ // ===========
+ /**
+ * Constructor.
+ */
+ public AbstractBehaviorWritable() {
+ }
+
+ // =====================================================================================
+ // Delegate Method
+ // ===============
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @param entity Entity that the type is entity-interface. (NotNull)
+ * @return Inserted count.
+ */
+ public int callCreate(Entity entity) {
+ assertEntityNotNull(entity);// If this table use identity, the entity does not have primary-key.
+ filterEntityOfInsert(entity);
+ assertEntityOfInsert(entity);
+ return getDaoWritable().create(entity);
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ * {modified only}
+ *
+ * @param entity Entity that the type is entity-interface. (NotNull)
+ * @return Updated count.
+ */
+ public int callModify(Entity entity) {
+ assertEntityNotNullAndHasPrimaryKeyValue(entity);
+ filterEntityOfUpdate(entity);
+ assertEntityOfUpdate(entity);
+ return getDaoWritable().modifyModifiedOnly(entity);
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @param entity Entity that the type is entity-interface. (NotNull)
+ * @return Deleted count.
+ */
+ public int callRemove(Entity entity) {
+ assertEntityNotNullAndHasPrimaryKeyValue(entity);
+ filterEntityOfDelete(entity);
+ assertEntityOfDelete(entity);
+ return getDaoWritable().remove(entity);
+ }
+
+ /**
+ * Filter the entity of insert.
+ *
+ * @param entity Entity that the type is entity-interface. (NotNull)
+ */
+ protected void filterEntityOfInsert(Entity entity) {
+ }
+
+ /**
+ * Assert the entity of insert.
+ *
+ * @param entity Entity that the type is entity-interface. (NotNull)
+ */
+ protected void assertEntityOfInsert(Entity entity) {
+ }
+
+ /**
+ * Filter the entity of update.
+ *
+ * @param entity Entity that the type is entity-interface. (NotNull)
+ */
+ protected void filterEntityOfUpdate(Entity entity) {
+ }
+
+ /**
+ * Assert the entity of update.
+ *
+ * @param entity Entity that the type is entity-interface. (NotNull)
+ */
+ protected void assertEntityOfUpdate(Entity entity) {
+ }
+
+
+ /**
+ * Filter the entity of delete.
+ *
+ * @param entity Entity that the type is entity-interface. (NotNull)
+ */
+ protected void filterEntityOfDelete(Entity entity) {
+ }
+
+ /**
+ * Assert the entity of delete
+ *
+ * @param entity Entity that the type is entity-interface. (NotNull)
+ */
+ protected void assertEntityOfDelete(Entity entity) {
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @param entityList Entity-list that the type is entity-interface. (NotNull)
+ * @return Inserted count.
+ */
+ public int callCreateList(java.util.List entityList) {
+ assertListNotNullAndNotEmpty(entityList);
+ for (final java.util.Iterator ite = entityList.iterator(); ite.hasNext(); ) {
+ final Entity entity = (Entity)ite.next();
+ filterEntityOfInsert(entity);
+ assertEntityOfInsert(entity);
+ }
+ return getDaoWritable().createList(entityList);
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @param entityList Entity-list that the type is entity-interface. (NotNull)
+ * @return Updated count.
+ */
+ public int callModifyList(java.util.List entityList) {
+ assertListNotNullAndNotEmpty(entityList);
+ for (final java.util.Iterator ite = entityList.iterator(); ite.hasNext(); ) {
+ final Entity entity = (Entity)ite.next();
+ filterEntityOfUpdate(entity);
+ assertEntityOfUpdate(entity);
+ }
+ return getDaoWritable().modifyList(entityList);
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @param entityList Entity-list that the type is entity-interface. (NotNull)
+ * @return Deleted count.
+ */
+ public int callRemoveList(java.util.List entityList) {
+ assertListNotNullAndNotEmpty(entityList);
+ for (final java.util.Iterator ite = entityList.iterator(); ite.hasNext(); ) {
+ final Entity entity = (Entity)ite.next();
+ filterEntityOfDelete(entity);
+ assertEntityOfDelete(entity);
+ }
+ return getDaoWritable().removeList(entityList);
+ }
+
+ // =====================================================================================
+ // Basic Entity Update
+ // ===================
+ /**
+ * Create.
+ *
+ * @param entity Entity. (NotNull)
+ */
+ public void create(Entity entity) {
+ doCreate(entity);
+ }
+
+ abstract protected void doCreate(Entity entity);
+
+ /**
+ * Modify.
+ *
+ * @param entity Entity. (NotNull)
+ * @exception jp.sf.pal.pompei.allcommon.exception.RecordHasAlreadyBeenDeletedException
+ * @exception jp.sf.pal.pompei.allcommon.exception.RecordHasOverlappedException
+ */
+ public void modify(Entity entity) {
+ doModify(entity);
+ }
+
+ abstract protected void doModify(Entity entity);
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @param entity Entity having primary-key value. (NotNull)
+ * @exception jp.sf.pal.pompei.allcommon.exception.RecordHasAlreadyBeenDeletedException
+ */
+ public void modifyAfterSelect(Entity entity) {
+ doModifyAfterSelect(entity);
+ }
+
+ abstract protected void doModifyAfterSelect(Entity entity);
+
+ /**
+ * Create or modify after select.
+ * {modify: modified only}
+ *
+ * @param entity Entity. This must contain primary-key value at least(Except use identity). (NotNull)
+ */
+ public void createOrModifyAfterSelect(jp.sf.pal.pompei.allcommon.Entity entity) {
+ assertEntityNotNull(entity);
+ doCreateOrModifyAfterSelect(entity);
+ }
+
+ abstract protected void doCreateOrModifyAfterSelect(Entity entity);
+
+ /**
+ * Merge entity.
+ * Copy the column data of sourceEntity that the setter has been invoked to destinationEntity.
+ *
+ * @param sourceEntity Source entity. (NotNull)
+ * @param destinationEntity Destination entity. (NotNull)
+ */
+ abstract protected void mergeEntity(Entity sourceEntity, Entity destinationEntity);
+
+ /**
+ * Remove.
+ *
+ * @param entity Entity. (NotNull)
+ * @exception jp.sf.pal.pompei.allcommon.exception.RecordHasAlreadyBeenDeletedException
+ * @exception jp.sf.pal.pompei.allcommon.exception.RecordHasOverlappedException
+ */
+ public void remove(jp.sf.pal.pompei.allcommon.Entity entity) {
+ assertEntityNotNull(entity);
+ callRemove(entity);
+ }
+
+ abstract protected void doRemove(Entity entity);
+
+ /**
+ * Remove after select.
+ *
+ * @param entity Entity. This must contain primary-key value at least. (NotNull)
+ * @exception jp.sf.pal.pompei.allcommon.exception.RecordHasAlreadyBeenDeletedException
+ */
+ public void removeAfterSelect(Entity entity) {
+ assertEntityNotNullAndHasPrimaryKeyValue(entity);
+ doRemoveAfterSelect(entity);
+ }
+
+ abstract protected void doRemoveAfterSelect(Entity entity);
+
+ // =====================================================================================
+ // Basic Batch Update
+ // ==================
+ /**
+ * Create list.
+ *
+ * @param entityList Entity-list. (NotNull and NotEmpty)
+ * @return Created count.
+ */
+ public int createList(java.util.List entityList) {
+ assertListNotNullAndNotEmpty(entityList);
+ return callCreateList(entityList);
+ }
+
+ /**
+ * Modify list.
+ *
+ * @param entityList Entity-list. (NotNull and NotEmpty)
+ * @return Modified count.
+ */
+ public int modifyList(java.util.List entityList) {
+ assertListNotNullAndNotEmpty(entityList);
+ return callModifyList(entityList);
+ }
+
+ /**
+ * Remove list.
+ *
+ * @param entityList Entity-list. (NotNull and NotEmpty)
+ * @return Removed count.
+ */
+ public int removeList(java.util.List entityList) {
+ assertListNotNullAndNotEmpty(entityList);
+ return callRemoveList(entityList);
+ }
+
+ // =====================================================================================
+ // Token File
+ // ==========
+ /**
+ * Reflect(insert or update) token-file to this table.
+ *
+ * @param filename Name of the file. (NotNull and NotEmpty)
+ * @param tokenFileReflectionOption token-file-reflection-option. (NotNull and Required{delimiter and encoding})
+ * @return Token-file-reflection-result. (NotNull)
+ * @throws java.io.FileNotFoundException
+ * @throws java.io.IOException
+ */
+ public TokenFileReflectionResult reflectTokenFile(String filename, TokenFileReflectionOption tokenFileReflectionOption) throws java.io.FileNotFoundException, java.io.IOException {
+ assertStringNotNullAndNotTrimmedEmpty("filename", filename);
+ assertFileTokenReflectionOption(tokenFileReflectionOption);
+
+ final TokenFileReflectionResult result = buildTokenFileReflectionResult();
+ final FileTokenizingCallback fileTokenizingCallback = buildFileTokenReflectionFileTokenizingCallback(tokenFileReflectionOption, result);
+ final FileTokenizingOption fileTokenizingOption = buildFileTokenReflectionFileTokenizingOption(tokenFileReflectionOption);
+ final FileToken fileToken = new FileTokenImpl();
+ fileToken.tokenize(filename, fileTokenizingCallback, fileTokenizingOption);
+ return result;
+ }
+
+ /**
+ * Reflect(insert or update) token-file to this table.
+ *
+ * @param inputStream Input stream. (NotNull and NotClosed)
+ * @param tokenFileReflectionOption token-file-reflection-option. (NotNull and Required{delimiter and encoding})
+ * @return Token-file-reflection-result. (NotNull)
+ * @throws java.io.FileNotFoundException
+ * @throws java.io.IOException
+ */
+ public TokenFileReflectionResult reflectTokenFile(java.io.InputStream inputStream, TokenFileReflectionOption tokenFileReflectionOption) throws java.io.FileNotFoundException, java.io.IOException {
+ assertObjectNotNull("inputStream", inputStream);
+ assertFileTokenReflectionOption(tokenFileReflectionOption);
+
+ final TokenFileReflectionResult result = buildTokenFileReflectionResult();
+ final FileTokenizingCallback fileTokenizingCallback = buildFileTokenReflectionFileTokenizingCallback(tokenFileReflectionOption, result);
+ final FileTokenizingOption fileTokenizingOption = buildFileTokenReflectionFileTokenizingOption(tokenFileReflectionOption);
+ final FileToken fileToken = new FileTokenImpl();
+ fileToken.tokenize(inputStream, fileTokenizingCallback, fileTokenizingOption);
+ return result;
+ }
+
+ protected void assertFileTokenReflectionOption(TokenFileReflectionOption tokenFileReflectionOption) {
+ assertObjectNotNull("tokenFileReflectionOption", tokenFileReflectionOption);
+
+ final String encoding = tokenFileReflectionOption.getEncoding();
+ final String delimiter = tokenFileReflectionOption.getDelimiter();
+ assertStringNotNullAndNotTrimmedEmpty("encoding", encoding);
+ assertObjectNotNull("delimiter", delimiter);
+ }
+
+ protected TokenFileReflectionResult buildTokenFileReflectionResult() {
+ final TokenFileReflectionResult result = new TokenFileReflectionResult();
+ final java.util.List failureList = new java.util.ArrayList();
+ result.setFailureList(failureList);
+ return result;
+ }
+
+ protected FileTokenizingCallback buildFileTokenReflectionFileTokenizingCallback(TokenFileReflectionOption tokenFileReflectionOption, final TokenFileReflectionResult result) throws java.io.FileNotFoundException, java.io.IOException {
+ assertObjectNotNull("tokenFileReflectionOption", tokenFileReflectionOption);
+
+ final String encoding = tokenFileReflectionOption.getEncoding();
+ final String delimiter = tokenFileReflectionOption.getDelimiter();
+ final boolean interruptIfError = tokenFileReflectionOption.isInterruptIfError();
+ assertStringNotNullAndNotTrimmedEmpty("encoding", encoding);
+ assertObjectNotNull("delimiter", delimiter);
+ final java.util.List failureList = result.getFailureList();
+ assertObjectNotNull("failureList", failureList);
+
+ final FileTokenizingCallback fileTokenizingCallback = new FileTokenizingCallback() {
+ public void handleRowResource(FileTokenizingRowResource fileTokenizingRowResource) {
+ final FileTokenizingHeaderInfo fileTokenizingHeaderInfo = fileTokenizingRowResource.getFileTokenizingHeaderInfo();
+ final java.util.List columnNameList = fileTokenizingHeaderInfo.getColumnNameList();
+ final java.util.List valueList = fileTokenizingRowResource.getValueList();
+
+ // Set up columnNameList of result object.
+ if (result.getColumnNameList() == null) {
+ result.setColumnNameList(columnNameList);
+ }
+
+ Entity entity = null;
+ try {
+ // Create entity by the list of value composed of String.
+ entity = createEntityByStringValueList(columnNameList, valueList);
+
+ // Create or modify as non-strict.
+ doCreateOrUpdateNonstrict(entity);
+
+ // Increment successCount of result object.
+ result.incrementSuccessCount();
+ } catch (RuntimeException e) {
+ if (interruptIfError) {
+ throw e;
+ }
+ final TokenFileReflectionFailure failure = new TokenFileReflectionFailure();
+ failure.setColumnNameList(columnNameList);
+ failure.setValueList(valueList);
+ failure.setRowString(fileTokenizingRowResource.getRowString());
+ failure.setRowNumber(fileTokenizingRowResource.getRowNumber());
+ failure.setLineNumber(fileTokenizingRowResource.getLineNumber());
+ if (entity != null) {
+ failure.setEntity(entity);
+ }
+ failure.setException(e);
+ failureList.add(failure);
+ }
+ }
+ };
+ return fileTokenizingCallback;
+ }
+
+ protected Entity createEntityByStringValueList(java.util.List columnNameList, java.util.List valueList) {
+ final MapStringBuilder builder = new MapStringBuilderImpl();
+ builder.setMsMapMark(MAP_STRING_MAP_MARK);
+ builder.setMsStartBrace(MAP_STRING_START_BRACE);
+ builder.setMsEndBrace(MAP_STRING_END_BRACE);
+ builder.setMsDelimiter(MAP_STRING_DELIMITER);
+ builder.setMsEqual(MAP_STRING_EQUAL);
+ builder.setColumnNameList(columnNameList);
+ final String mapString = builder.buildFromList(valueList);
+
+ final Entity entity = getDBMeta().newEntity();
+ getDBMeta().acceptColumnValueMapString(entity, mapString);
+ return entity;
+ }
+
+ protected FileTokenizingOption buildFileTokenReflectionFileTokenizingOption(TokenFileReflectionOption tokenFileReflectionOption) throws java.io.FileNotFoundException, java.io.IOException {
+ assertObjectNotNull("tokenFileReflectionOption", tokenFileReflectionOption);
+
+ final String encoding = tokenFileReflectionOption.getEncoding();
+ final String delimiter = tokenFileReflectionOption.getDelimiter();
+ assertStringNotNullAndNotTrimmedEmpty("encoding", encoding);
+ assertObjectNotNull("delimiter", delimiter);
+
+ final FileTokenizingOption fileTokenizingOption = new FileTokenizingOption();
+ fileTokenizingOption.setEncoding(encoding);
+ fileTokenizingOption.setDelimiter(delimiter);
+ if (tokenFileReflectionOption.isHandleEmptyAsNull()) {
+ fileTokenizingOption.handleEmptyAsNull();
+ }
+ return fileTokenizingOption;
+ }
+
+ abstract protected void doCreateOrUpdateNonstrict(Entity entity);
+
+ /**
+ * Reflect(insert or update) from separated-file.
+ *
+ * @param filename Name of the file. (NotNull and NotEmpty)
+ * @param encoding Encoding of the file. (NotNull and NotEmpty)
+ * @param delimiter Delimiter of the file. (NotNull and NotEmpty)
+ * @param batchCount Batch-count for transaction. If this value is 0, all records are done in one transaction.
+ * @param isErrorContinue If true, this method continue in spite of throwing the exception.
+ * @return The list of OneEntityExceptionResult. (NotNull)
+ * @throws java.io.FileNotFoundException
+ * @throws java.io.IOException
+ * @deprecated Please use reflectTokenFile()
+ */
+ public java.util.List reflectFromSeparatedFile(
+ String filename, String encoding,
+ String delimiter, int batchCount, boolean isErrorContinue
+ ) throws java.io.FileNotFoundException, java.io.IOException {
+ assertStringNotNullAndNotTrimmedEmpty("filename", filename);
+ assertStringNotNullAndNotTrimmedEmpty("encoding", encoding);
+ assertObjectNotNull("delimiter", delimiter);
+ final java.util.List exceptionList = new java.util.ArrayList();
+
+ java.io.FileInputStream fis = null;
+ java.io.InputStreamReader ir = null;
+ java.io.BufferedReader br = null;
+ try {
+ fis = new java.io.FileInputStream(filename);
+ ir = new java.io.InputStreamReader(fis, encoding);
+ br = new java.io.BufferedReader(ir);
+
+ final MapStringBuilder builder = new MapStringBuilderImpl();
+ builder.setMsMapMark(MAP_STRING_MAP_MARK);
+ builder.setMsStartBrace(MAP_STRING_START_BRACE);
+ builder.setMsEndBrace(MAP_STRING_END_BRACE);
+ builder.setMsDelimiter(MAP_STRING_DELIMITER);
+ builder.setMsEqual(MAP_STRING_EQUAL);
+ final java.util.List entityList = new java.util.ArrayList();
+ int count = 0;
+ while (true) {
+ ++count;
+
+ final String lineString = br.readLine();
+ if (lineString == null) {
+ if (entityList.size() > 0) {
+ final java.util.List tmpList = reflectAfterSelectNewTx(entityList, isErrorContinue);
+ exceptionList.addAll(tmpList);
+ entityList.clear();
+ }
+ break;
+ }
+ if (count == 1) {
+ builder.setColumnNames(lineString.split(delimiter));
+ continue;
+ }
+
+ final String mapString = builder.buildByDelimiter(lineString, delimiter);
+ final Entity entity = getDBMeta().newEntity();
+ entity.acceptColumnValueMapString(mapString);
+ entityList.add(entity);
+
+ if (entityList.size() == batchCount) {
+ final java.util.List tmpList = reflectAfterSelectNewTx(entityList, isErrorContinue);
+ exceptionList.addAll(tmpList);
+ entityList.clear();
+ }
+ }
+ } catch (java.io.FileNotFoundException e) {
+ throw e;
+ } catch (java.io.IOException e) {
+ throw e;
+ } finally {
+ try {
+ if (fis != null) {
+ fis.close();
+ }
+ if (ir != null) {
+ ir.close();
+ }
+ if (br != null) {
+ br.close();
+ }
+ } catch (java.io.IOException ignored) {
+ _log.warn("File-close threw the exception: ", ignored);
+ }
+ }
+ return exceptionList;
+ }
+
+ /**
+ * Reflect(insert or update) from separated-file.
+ *
+ * @param entityList The list of entity that is reflection target. (NotNull)
+ * @param isErrorContinue If true, this method continue in spite of throwing the exception.
+ * @return The list of InsertOrUpdateExceptionResult. (NotNull)
+ * @deprecated Please use reflectTokenFile()
+ */
+ public java.util.List reflectAfterSelectNewTx(java.util.List entityList,
+ boolean isErrorContinue) {
+ final java.util.List exceptionList = new java.util.ArrayList();
+ for (final java.util.Iterator ite = entityList.iterator(); ite.hasNext(); ) {
+ final Entity entity = (Entity)ite.next();
+ try {
+ createOrModifyAfterSelect(entity);
+ } catch (RuntimeException e) {
+ if (isErrorContinue) {
+ final OneEntityExceptionResult result = new OneEntityExceptionResult();
+ result.setPrimaryKeyMapString(entity.extractPrimaryKeyMapString());
+ result.setEntity(entity);
+ result.setException(e);
+ exceptionList.add(result);
+ continue;
+ }
+ throw e;
+ }
+ }
+ return exceptionList;
+ }
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/BehaviorReadable.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/BehaviorReadable.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/BehaviorReadable.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,374 @@
+package jp.sf.pal.pompei.allcommon.bhv;
+
+import jp.sf.pal.pompei.allcommon.DaoSelector;
+import jp.sf.pal.pompei.allcommon.DaoReadable;
+import jp.sf.pal.pompei.allcommon.Entity;
+import jp.sf.pal.pompei.allcommon.cbean.ConditionBean;
+import jp.sf.pal.pompei.allcommon.cbean.ListResultBean;
+import jp.sf.pal.pompei.allcommon.cbean.OrderByBean;
+import jp.sf.pal.pompei.allcommon.cbean.PagingBean;
+import jp.sf.pal.pompei.allcommon.cbean.PagingResultBean;
+import jp.sf.pal.pompei.allcommon.dbmeta.DBMeta;
+
+import jp.sf.pal.pompei.allcommon.bhv.batch.TokenFileOutputOption;
+import jp.sf.pal.pompei.allcommon.bhv.batch.TokenFileOutputResult;
+
+/**
+ * The interface of behavior-readable.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public interface BehaviorReadable {
+
+ // =====================================================================================
+ // Definition
+ // ==========
+ /** Map-string map-mark. */
+ public static final String MAP_STRING_MAP_MARK = "map:";
+
+ /** Map-string list-mark. */
+ public static final String MAP_STRING_LIST_MARK = "list:";
+
+ /** Map-string start-brace. */
+ public static final String MAP_STRING_START_BRACE = "@{";
+
+ /** Map-string end-brace. */
+ public static final String MAP_STRING_END_BRACE = "@}";
+
+ /** Map-string delimiter. */
+ public static final String MAP_STRING_DELIMITER = "@;";
+
+ /** Map-string equal. */
+ public static final String MAP_STRING_EQUAL = "@=";
+
+ // =====================================================================================
+ // Table name
+ // ==========
+ /**
+ * Get table db-name.
+ *
+ * @return Table db-name. (NotNull)
+ */
+ public String getTableDbName();
+
+ // =====================================================================================
+ // DBMeta
+ // ======
+ /**
+ * Get dbmeta.
+ *
+ * @return DBMeta. (NotNull)
+ */
+ public DBMeta getDBMeta();
+
+ // =====================================================================================
+ // Dao Accessor
+ // ============
+ /**
+ * Get dao-readable.
+ *
+ * @return Dao-readable. (NotNull)
+ */
+ public DaoReadable getDaoReadable();
+
+ /**
+ * Get dao-selector.
+ *
+ * @return Dao-selector.
+ */
+ public DaoSelector getDaoSelector();
+
+ /**
+ * Set dao-selector.
+ *
+ * @param value Dao-selector.
+ */
+ public void setDaoSelector(DaoSelector value);
+
+ // =====================================================================================
+ // New Instance
+ // ============
+ /**
+ * New entity.
+ *
+ * @return Entity. (NotNull)
+ */
+ public Entity newEntity();
+
+ /**
+ * New condition-bean.
+ *
+ * @return Condition-bean. (NotNull)
+ */
+ public ConditionBean newConditionBean();
+
+ // =====================================================================================
+ // Delegate Method
+ // ===============
+ /**
+ * Read count as all. (Delegate-Method)
+ *
+ * @return All count. (NotNull)
+ */
+ public int callGetCountAll();
+
+ /**
+ * Read list as all. (Delegate-Method)
+ *
+ * @return All list. (NotNull)
+ */
+ public java.util.List callGetListAll();
+
+ /**
+ * Read count by condition-bean. (Delegate-Method)
+ * If the condition-bean is invoked fetchFirst() and fetchScope() and fetchPage(), throw exception.
+ *
+ * @param cb Condition-bean. (NotNull)
+ * @return Read count. (NotNull)
+ */
+ public int callReadCount(ConditionBean cb);
+
+ /**
+ * Read entity by condition-bean. (Delegate-Method)
+ *
+ * @param cb Condition-bean. (NotNull)
+ * @return Read entity. If the select result is zero, it returns null. (Nullable)
+ */
+ public Entity callReadEntity(ConditionBean cb);
+
+ /**
+ * Read list by condition-bean. (Delegate-Method)
+ *
+ * @param cb Condition-bean. (NotNull)
+ * @return Read list. If the select result is zero, it returns empty list. (NotNull)
+ */
+ public java.util.List callReadList(ConditionBean cb);
+
+ // =====================================================================================
+ // Basic Get All
+ // =============
+ /**
+ * Get count all.
+ *
+ * @return Count all.
+ */
+ public int getCountAll();
+
+ // =====================================================================================
+ // Basic Read Count
+ // ================
+ /**
+ * Read count by condition-bean.
+ *
+ * If the argument 'condition-bean' is effective about fetch-scope,
+ * this method invoke select count ignoring the fetch-scope.
+ *
+ * @param cb Condition-bean. This condition-bean should not be set up about fetch-scope. (NotNull)
+ * @return Read count. (NotNull)
+ */
+ public int readCount(ConditionBean cb);
+
+ // =====================================================================================
+ // Basic Read Entity
+ // =================
+ /**
+ * Read entity by condition-bean.
+ *
+ * @param cb Condition-bean. (NotNull)
+ * @return Read entity. (Nullalble)
+ * @exception jp.sf.pal.pompei.allcommon.exception.RecordHasOverlappedException
+ */
+ public Entity readEntity(ConditionBean cb);
+
+ /**
+ * Read simple entity by condition-bean with deleted check.
+ *
+ * @param cb Condition-bean. (NotNull)
+ * @return Read entity. (NotNull)
+ * @exception jp.sf.pal.pompei.allcommon.exception.RecordHasAlreadyBeenDeletedException
+ */
+ public Entity readEntityWithDeletedCheck(ConditionBean cb);
+
+ // =====================================================================================
+ // Basic Read List
+ // ===============
+ /**
+ * Read list as result-bean.
+ *
+ * @param cb Condition-bean. (NotNull)
+ * @return List-result-bean. If the select result is zero, it returns empty list. (NotNull)
+ */
+ public ListResultBean readList(ConditionBean cb);
+
+ /**
+ * Read page as result-bean.
+ *
+ * @param cb Condition-bean. (NotNull)
+ * @return Read page. (NotNull)
+ */
+ public PagingResultBean readPage(final ConditionBean cb);
+
+ /**
+ * Read page as result-bean.
+ *
+ * @param cb Condition-bean. (NotNull)
+ * @param invoker Select-page-invoker (NotNull)
+ * @return Read page. (NotNull)
+ */
+ public PagingResultBean readPage(final ConditionBean cb, SelectPageInvoker invoker);
+
+ // =====================================================================================
+ // Token File
+ // ==========
+ /**
+ * Output token-file from this table records.
+ *
+ * @param cb Condition-bean. (NotNull)
+ * @param filename Name of the file. (NotNull and NotEmpty)
+ * @param tokenFileOutputOption token-file-output-option. (NotNull and Required{delimiter and encoding})
+ * @return Token-file-output-result. (NotNull)
+ * @throws java.io.FileNotFoundException
+ * @throws java.io.IOException
+ */
+ public TokenFileOutputResult outputTokenFile(ConditionBean cb, String filename, TokenFileOutputOption tokenFileOutputOption) throws java.io.FileNotFoundException, java.io.IOException;
+
+ /**
+ * The interface of select-page callback.
+ *
+ * @param The generic template for 'selectedList'.
+ */
+ public static interface SelectPageCallback {
+ public PagingBean getPagingBean();
+ public int selectCountIgnoreFetchScope();
+ public java.util.List selectListWithFetchScope();
+ }
+
+ /**
+ * The object of result-bean builder.
+ *
+ * @param The generic template for 'resultBean'.
+ */
+ public static class ResultBeanBuilder {
+ protected BehaviorReadable _bhv;
+ public ResultBeanBuilder(BehaviorReadable bhv) {
+ _bhv = bhv;
+ }
+ /**
+ * Build list-reuslt-bean.
+ *
+ * @param ob Order-by-bean. (NotNull)
+ * @param selectedList Selected list. (NotNull)
+ * @return List-result-bean. (NotNull)
+ */
+ public ListResultBean buildListResultBean(OrderByBean ob, java.util.List selectedList) {
+ ListResultBean rb = new ListResultBean();
+ rb.setTableDbName(_bhv.getTableDbName());
+ rb.setAllRecordCount(selectedList.size());
+ rb.setSelectedList(selectedList);
+ rb.setOrderByClause(ob.getSqlComponentOfOrderByClause());
+ return rb;
+ }
+ /**
+ * Build paging-reuslt-bean.
+ *
+ * @param pb Paging-bean. (NotNull)
+ * @param allRecordCount All-record-count.
+ * @param selectedList Selected list. (NotNull)
+ * @return Paging-result-bean. (NotNull)
+ */
+ public PagingResultBean buildPagingResultBean(PagingBean pb, int allRecordCount, java.util.List selectedList) {
+ PagingResultBean rb = new PagingResultBean();
+ rb.setTableDbName(_bhv.getTableDbName());
+ rb.setAllRecordCount(allRecordCount);
+ rb.setSelectedList(selectedList);
+ rb.setPageSize(pb.getFetchSize());
+ rb.setCurrentPageNumber(pb.getFetchPageNumber());
+ rb.setOrderByClause(pb.getSqlComponentOfOrderByClause());
+ return rb;
+ }
+ }
+
+ public static interface SelectPageInvoker {
+ /**
+ * Invoke select-page by callback.
+ *
+ * @param callback Callback. (NotNull)
+ * @return Paging-result-bean. (NotNull)
+ */
+ public PagingResultBean invokeSelectPage(SelectPageCallback callback);
+ }
+
+ /**
+ * The object of result-bean builder.
+ *
+ * @param The generic template for 'resultBean'.
+ */
+ public static class SelectPageSimpleInvoker implements SelectPageInvoker {
+ protected BehaviorReadable _bhv;
+ public SelectPageSimpleInvoker(BehaviorReadable bhv) {
+ _bhv = bhv;
+ }
+
+ /**
+ * Invoke select-page by callback.
+ *
+ * @param callback Callback. (NotNull)
+ * @return Paging-result-bean. (NotNull)
+ */
+ public PagingResultBean invokeSelectPage(SelectPageCallback callback) {
+ assertObjectNotNull("callback", callback);
+ assertObjectNotNull("callback.getPagingBean()", callback.getPagingBean());
+ if (!callback.getPagingBean().isFetchScopeEffective()) {
+ String msg = "The paging bean is not effective about fetch-scope!";
+ msg = msg + " When you select page, you should set up fetch-scope of paging bean(Should invoke fetchFirst() and fetchPage()!).";
+ msg = msg + " The paging bean is: " + callback.getPagingBean();
+ throw new IllegalStateException(msg);
+ }
+ final int allRecordCount = callback.selectCountIgnoreFetchScope();
+ final java.util.List selectedList = callback.selectListWithFetchScope();
+ final PagingResultBean rb = new ResultBeanBuilder(_bhv).buildPagingResultBean(callback.getPagingBean(), allRecordCount, selectedList);
+ if (isNecessaryToReadPageAgain(rb)) {
+ callback.getPagingBean().fetchPage(rb.getAllPageCount());
+ final int reAllRecordCount = callback.selectCountIgnoreFetchScope();
+ final java.util.List reSelectedList = callback.selectListWithFetchScope();
+ return new ResultBeanBuilder(_bhv).buildPagingResultBean(callback.getPagingBean(), reAllRecordCount, reSelectedList);
+ } else {
+ return rb;
+ }
+ }
+
+ /**
+ * Is it necessary to read page again?
+ *
+ * @param rb Paging-result-bean. (NotNull)
+ * @return Determination.
+ */
+ protected boolean isNecessaryToReadPageAgain(PagingResultBean rb) {
+ return rb.getAllRecordCount() > 0 && rb.getSelectedList().isEmpty();
+ }
+
+ /**
+ * Assert that the object is not null.
+ *
+ * @param variableName Variable name. (NotNull)
+ * @param value Value. (NotNull)
+ * @exception IllegalArgumentException
+ */
+ protected void assertObjectNotNull(String variableName, Object value) {
+ if (variableName == null) {
+ String msg = "The value should not be null: variableName=" + variableName + " value=" + value;
+ throw new IllegalArgumentException(msg);
+ }
+ if (value == null) {
+ String msg = "The value should not be null: variableName=" + variableName;
+ throw new IllegalArgumentException(msg);
+ }
+ }
+ }
+
+ /**
+ * The marker interface of simple condition-bean setupper.
+ */
+ public static interface SimpleCBSetupper {
+ }
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/BehaviorWritable.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/BehaviorWritable.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/BehaviorWritable.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,208 @@
+package jp.sf.pal.pompei.allcommon.bhv;
+
+import jp.sf.pal.pompei.allcommon.DaoWritable;
+import jp.sf.pal.pompei.allcommon.Entity;
+import jp.sf.pal.pompei.allcommon.bhv.batch.TokenFileReflectionOption;
+import jp.sf.pal.pompei.allcommon.bhv.batch.TokenFileReflectionResult;
+
+/**
+ * The interface of behavior-writable.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public interface BehaviorWritable extends BehaviorReadable {
+
+ /**
+ * Get dao-writable.
+ *
+ * @return Dao-writable. (NotNull)
+ */
+ public DaoWritable getDaoWritable();
+
+ /**
+ * Create entity. (Delegate-Method)
+ *
+ * @param entity Entity that the type is entity-interface. (NotNull)
+ * @return Inserted count.
+ */
+ public int callCreate(Entity entity);
+
+ /**
+ * Modify entity. (Delegate-Method)
+ * {modified only}
+ *
+ * @param entity Entity that the type is entity-interface. (NotNull)
+ * @return Updated count.
+ */
+ public int callModify(Entity entity);
+
+ /**
+ * Remove entity. (Delegate-Method)
+ *
+ * @param entity Entity that the type is entity-interface. (NotNull)
+ * @return Deleted count.
+ */
+ public int callRemove(Entity entity);
+
+ /**
+ * Create several entity-list. (Delegate-Method)
+ *
+ * @param entityList Entity-list that the type is entity-interface. (NotNull)
+ * @return Inserted count.
+ */
+ public int callCreateList(java.util.List entityList);
+
+ /**
+ * Modify several entity-list. (Delegate-Method)
+ *
+ * @param entityList Entity-list that the type is entity-interface. (NotNull)
+ * @return Updated count.
+ */
+ public int callModifyList(java.util.List entityList);
+
+ /**
+ * Remove several entity-list. (Delegate-Method)
+ *
+ * @param entityList Entity-list that the type is entity-interface. (NotNull)
+ * @return Deleted count.
+ */
+ public int callRemoveList(java.util.List entityList);
+
+ // =====================================================================================
+ // Basic Entity Update
+ // ===================
+ /**
+ * Create.
+ *
+ * @param entity Entity. (NotNull)
+ */
+ public void create(jp.sf.pal.pompei.allcommon.Entity entity);
+
+ /**
+ * Modify.
+ *
+ * @param entity Entity. (NotNull)
+ */
+ public void modify(jp.sf.pal.pompei.allcommon.Entity entity);
+
+ /**
+ * Modify after select.
+ *
+ * @param entity Entity.
+ * @exception jp.sf.pal.pompei.allcommon.exception.RecordHasAlreadyBeenDeletedException
+ */
+ public void modifyAfterSelect(jp.sf.pal.pompei.allcommon.Entity entity);
+
+ /**
+ * Create or modify after select.
+ *
+ * @param entity Entity. This must contain primary-key value at least(Except use identity). (NotNull)
+ */
+ public void createOrModifyAfterSelect(jp.sf.pal.pompei.allcommon.Entity entity);
+
+ /**
+ * Remove.
+ *
+ * @param entity Entity. (NotNull)
+ */
+ public void remove(jp.sf.pal.pompei.allcommon.Entity entity);
+
+ // =====================================================================================
+ // Basic Batch Update
+ // ==================
+ /**
+ * Create list.
+ *
+ * @param entityList Entity-list. (NotNull and NotEmpty)
+ * @return Created count.
+ */
+ public int createList(java.util.List entityList);
+
+ /**
+ * Modify list.
+ *
+ * @param entityList Entity-list. (NotNull and NotEmpty)
+ * @return Modified count.
+ */
+ public int modifyList(java.util.List entityList);
+
+ /**
+ * Remove list.
+ *
+ * @param entityList Entity-list. (NotNull and NotEmpty)
+ * @return Removed count.
+ */
+ public int removeList(java.util.List entityList);
+
+ // =====================================================================================
+ // Token File
+ // ==========
+ /**
+ * Reflect(insert or update) token-file to this table.
+ *
+ * @param filename Name of the file. (NotNull and NotEmpty)
+ * @param tokenFileReflectionOption token-file-reflection-option. (NotNull and Required{delimiter and encoding})
+ * @return Token-file-reflection-result. (NotNull)
+ * @throws java.io.FileNotFoundException
+ * @throws java.io.IOException
+ */
+ public TokenFileReflectionResult reflectTokenFile(String filename, TokenFileReflectionOption tokenFileReflectionOption) throws java.io.FileNotFoundException, java.io.IOException;
+
+ /**
+ * Reflect(insert or update) token-file to this table.
+ *
+ * @param inputStream Input stream. (NotNull and NotClosed)
+ * @param tokenFileReflectionOption token-file-reflection-option. (NotNull and Required{delimiter and encoding})
+ * @return Token-file-reflection-result. (NotNull)
+ * @throws java.io.FileNotFoundException
+ * @throws java.io.IOException
+ */
+ public TokenFileReflectionResult reflectTokenFile(java.io.InputStream inputStream, TokenFileReflectionOption tokenFileReflectionOption) throws java.io.FileNotFoundException, java.io.IOException;
+
+ /**
+ * Reflect(insert or update) from separated-file.
+ *
+ * @param filename Name of the file. (NotNull and NotEmpty)
+ * @param encoding Encoding of the file. (NotNull and NotEmpty)
+ * @param delimiter Delimiter of the file. (NotNull and NotEmpty)
+ * @param batchCount Batch-count for transaction.
+ * @param isErrorContinue If true, this method continue in spite of throwing the exception.
+ * @return The list of InsertOrUpdateExceptionResult. (NotNull)
+ * @throws java.io.FileNotFoundException
+ * @throws java.io.IOException
+ * @deprecated Please use reflectTokenFile()
+ */
+ public java.util.List reflectFromSeparatedFile(
+ String filename, String encoding,
+ String delimiter, int batchCount, boolean isErrorContinue
+ ) throws java.io.FileNotFoundException, java.io.IOException;
+
+ /**
+ * Exception result for one entity.
+ * @deprecated Please use BatchTransactionFailureResult
+ */
+ public static class OneEntityExceptionResult {
+ protected String _primaryKeyMapString;
+ protected Entity _entity;
+ protected Exception _exception;
+
+ public String getPrimaryKeyMapString() {
+ return _primaryKeyMapString;
+ }
+ public void setPrimaryKeyMapString(String value) {
+ _primaryKeyMapString = value;
+ }
+ public Entity getEntity() {
+ return _entity;
+ }
+ public void setEntity(Entity value) {
+ _entity = value;
+ }
+ public Exception getException() {
+ return _exception;
+ }
+ public void setException(Exception value) {
+ _exception = value;
+ }
+ }
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/batch/TokenFileOutputOption.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/batch/TokenFileOutputOption.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/batch/TokenFileOutputOption.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,87 @@
+package jp.sf.pal.pompei.allcommon.bhv.batch;
+
+import jp.sf.pal.pompei.allcommon.helper.token.file.FileMakingOption;
+
+/**
+ * @author DBFlute(AutoGenerator)
+ */
+public class TokenFileOutputOption {
+
+ // =====================================================================================
+ // Attribute
+ // =========
+ protected FileMakingOption _fileMakingOption = new FileMakingOption();
+
+ // =====================================================================================
+ // Easy-to-Use
+ // ===========
+ public TokenFileOutputOption delimitateByComma() {
+ _fileMakingOption.delimitateByComma();
+ return this;
+ }
+
+ public TokenFileOutputOption delimitateByTab() {
+ _fileMakingOption.delimitateByTab();
+ return this;
+ }
+
+ public TokenFileOutputOption encodeAsUTF8() {
+ _fileMakingOption.encodeAsUTF8();
+ return this;
+ }
+
+ public TokenFileOutputOption encodeAsWindows31J() {
+ _fileMakingOption.encodeAsWindows31J();
+ return this;
+ }
+
+ public TokenFileOutputOption separateCrLf() {
+ _fileMakingOption.separateCrLf();
+ return this;
+ }
+
+ public TokenFileOutputOption separateLf() {
+ _fileMakingOption.separateLf();
+ return this;
+ }
+
+ public TokenFileOutputOption goodByeDoubleQuotation() {
+ _fileMakingOption.goodByeDoubleQuotation();
+ return this;
+ }
+
+ // =====================================================================================
+ // Accessor
+ // ========
+ public String getEncoding() {
+ return _fileMakingOption.getEncoding();
+ }
+
+ public void setEncoding(String encoding) {
+ _fileMakingOption.setDelimiter(encoding);
+ }
+
+ public String getDelimiter() {
+ return _fileMakingOption.getDelimiter();
+ }
+
+ public void setDelimiter(String delimiter) {
+ _fileMakingOption.setDelimiter(delimiter);
+ }
+
+ public String getLineSeparator() {
+ return _fileMakingOption.getLineSeparator();
+ }
+
+ public void setLineSeparator(String lineSeparator) {
+ _fileMakingOption.setLineSeparator(lineSeparator);
+ }
+
+ public boolean isGoodByeDoubleQuotation() {
+ return _fileMakingOption.isGoodByeDoubleQuotation();
+ }
+
+ public FileMakingOption getFileMakingOption() {
+ return _fileMakingOption;
+ }
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/batch/TokenFileOutputResult.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/batch/TokenFileOutputResult.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/batch/TokenFileOutputResult.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,25 @@
+package jp.sf.pal.pompei.allcommon.bhv.batch;
+
+import jp.sf.pal.pompei.allcommon.Entity;
+
+/**
+ * @author DBFlute(AutoGenerator)
+ */
+public class TokenFileOutputResult {
+
+ // =====================================================================================
+ // Attribute
+ // =========
+ protected java.util.List _selectedList;
+
+ // =====================================================================================
+ // Accessor
+ // ========
+ public java.util.List getSelectedList() {
+ return _selectedList;
+ }
+
+ public void setSelectedList(java.util.List selectedList) {
+ _selectedList = selectedList;
+ }
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/batch/TokenFileReflectionFailure.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/batch/TokenFileReflectionFailure.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/batch/TokenFileReflectionFailure.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,85 @@
+package jp.sf.pal.pompei.allcommon.bhv.batch;
+
+import jp.sf.pal.pompei.allcommon.Entity;
+
+/**
+ * @author DBFlute(AutoGenerator)
+ */
+public class TokenFileReflectionFailure {
+
+ // =====================================================================================
+ // Attribute
+ // =========
+ protected java.util.List _columnNameList;
+ protected java.util.List _valueList;
+
+ protected String rowString;
+
+ /** The row number. */
+ protected int _rowNumber;
+
+ /** The line number. */
+ protected int _lineNumber;
+
+ protected Entity _entity;
+ protected Exception _exception;
+
+ // =====================================================================================
+ // Accessor
+ // ========
+ public java.util.List getColumnNameList() {
+ return _columnNameList;
+ }
+
+ public void setColumnNameList(java.util.List columnNameList) {
+ this._columnNameList = columnNameList;
+ }
+
+ public java.util.List getValueList() {
+ return _valueList;
+ }
+
+ public void setValueList(java.util.List valueList) {
+ this._valueList = valueList;
+ }
+
+ public String getRowString() {
+ return rowString;
+ }
+
+ public void setRowString(String rowString) {
+ this.rowString = rowString;
+ }
+
+ public int getRowNumber() {
+ return _rowNumber;
+ }
+
+ public void setRowNumber(int rowNumber) {
+ _rowNumber = rowNumber;
+ }
+
+ public int getLineNumber() {
+ return _lineNumber;
+ }
+
+ public void setLineNumber(int lineNumber) {
+ _lineNumber = lineNumber;
+ }
+
+ public Entity getEntity() {
+ return _entity;
+ }
+
+ public void setEntity(Entity value) {
+ _entity = value;
+ }
+
+ public Exception getException() {
+ return _exception;
+ }
+
+ public void setException(Exception value) {
+ _exception = value;
+ }
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/batch/TokenFileReflectionOption.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/batch/TokenFileReflectionOption.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/batch/TokenFileReflectionOption.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,76 @@
+package jp.sf.pal.pompei.allcommon.bhv.batch;
+
+import jp.sf.pal.pompei.allcommon.helper.token.file.FileTokenizingOption;
+
+/**
+ * @author DBFlute(AutoGenerator)
+ */
+public class TokenFileReflectionOption {
+
+ // =====================================================================================
+ // Attribute
+ // =========
+ protected boolean _interruptIfError;
+
+ protected FileTokenizingOption _fileTokenizingOption = new FileTokenizingOption();
+
+ // =====================================================================================
+ // Easy-to-Use
+ // ===========
+ public TokenFileReflectionOption delimitateByComma() {
+ _fileTokenizingOption.delimitateByComma();
+ return this;
+ }
+
+ public TokenFileReflectionOption delimitateByTab() {
+ _fileTokenizingOption.delimitateByTab();
+ return this;
+ }
+
+ public TokenFileReflectionOption encodeAsUTF8() {
+ _fileTokenizingOption.encodeAsUTF8();
+ return this;
+ }
+
+ public TokenFileReflectionOption encodeAsWindows31J() {
+ _fileTokenizingOption.encodeAsWindows31J();
+ return this;
+ }
+
+ public TokenFileReflectionOption handleEmptyAsNull() {
+ _fileTokenizingOption.handleEmptyAsNull();
+ return this;
+ }
+
+ public TokenFileReflectionOption interruptIfError() {
+ _interruptIfError = true;
+ return this;
+ }
+
+ // =====================================================================================
+ // Accessor
+ // ========
+ public String getDelimiter() {
+ return _fileTokenizingOption.getDelimiter();
+ }
+
+ public void setDelimiter(String delimiter) {
+ _fileTokenizingOption.setDelimiter(delimiter);
+ }
+
+ public String getEncoding() {
+ return _fileTokenizingOption.getEncoding();
+ }
+
+ public void setEncoding(String encoding) {
+ _fileTokenizingOption.setDelimiter(encoding);
+ }
+
+ public boolean isHandleEmptyAsNull() {
+ return _fileTokenizingOption.isHandleEmptyAsNull();
+ }
+
+ public boolean isInterruptIfError() {
+ return _interruptIfError;
+ }
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/batch/TokenFileReflectionResult.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/batch/TokenFileReflectionResult.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/batch/TokenFileReflectionResult.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,48 @@
+package jp.sf.pal.pompei.allcommon.bhv.batch;
+
+/**
+ * @author DBFlute(AutoGenerator)
+ */
+public class TokenFileReflectionResult {
+
+ // =====================================================================================
+ // Attribute
+ // =========
+ protected java.util.List _columnNameList;
+ protected int _successCount;
+ protected java.util.List _failureList;
+
+ // =====================================================================================
+ // Easy-to-Use
+ // ===========
+ public void incrementSuccessCount() {
+ ++_successCount;
+ }
+
+ // =====================================================================================
+ // Accessor
+ // ========
+ public java.util.List getColumnNameList() {
+ return _columnNameList;
+ }
+
+ public void setColumnNameList(java.util.List columnNameList) {
+ this._columnNameList = columnNameList;
+ }
+
+ public int getSuccessCount() {
+ return _successCount;
+ }
+
+ public void setSuccessCount(int successCount) {
+ _successCount = successCount;
+ }
+
+ public java.util.List getFailureList() {
+ return _failureList;
+ }
+
+ public void setFailureList(java.util.List failureList) {
+ this._failureList = failureList;
+ }
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/load/LoadRefererOption.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/load/LoadRefererOption.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/load/LoadRefererOption.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,120 @@
+package jp.sf.pal.pompei.allcommon.bhv.load;
+
+import jp.sf.pal.pompei.allcommon.Entity;
+import jp.sf.pal.pompei.allcommon.bhv.setup.ConditionBeanSetupper;
+import jp.sf.pal.pompei.allcommon.bhv.setup.EntityListSetupper;
+import jp.sf.pal.pompei.allcommon.cbean.ConditionBean;
+
+/**
+ * The class of load referer option.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public class LoadRefererOption {
+
+ // ===================================================================================
+ // Attribute
+ // =========
+ protected ConditionBeanSetupper _conditionBeanSetupper;
+
+ protected EntityListSetupper _entityListSetupper;
+
+ protected REFERER_CONDITION_BEAN _reffererConditionBean;
+
+ protected boolean _toLastKeyCondtion;
+
+ protected boolean _stopOrderByKey;
+
+ // ===================================================================================
+ // Constructor
+ // ===========
+ public LoadRefererOption() {
+ }
+
+ public LoadRefererOption(ConditionBeanSetupper conditionBeanSetupper) {
+ this._conditionBeanSetupper = conditionBeanSetupper;
+ }
+
+ public LoadRefererOption(ConditionBeanSetupper conditionBeanSetupper, EntityListSetupper entityListSetupper) {
+ this._conditionBeanSetupper = conditionBeanSetupper;
+ this._entityListSetupper = entityListSetupper;
+ }
+
+ // ===================================================================================
+ // Easy-to-Use
+ // ===========
+ /**
+ * Specify that the key condition is added as last condition.
+ * This method is valid only after you use reffererConditionBean and add your original condition to it.
+ *
+ * @return this. (NotNull)
+ */
+ public LoadRefererOption toLastKeyCondtion() {
+ _toLastKeyCondtion = true;
+ return this;
+ }
+
+ /**
+ * Specify that it stops adding order-by of the key.
+ * This method is valid only after you use reffererConditionBean and add your original order-by to it.
+ *
+ * @return this. (NotNull)
+ */
+ public LoadRefererOption stopOrderByKey() {
+ _stopOrderByKey = true;
+ return this;
+ }
+
+ public void delegateKeyConditionExchangingFirstWhereClauseForLastOne(REFERER_CONDITION_BEAN cb) {// Internal
+ if (!_toLastKeyCondtion) {
+ cb.getSqlClause().exchangeFirstWhereClauseForLastOne();
+ }
+ }
+
+ public void delegateConditionBeanSettingUp(REFERER_CONDITION_BEAN cb) {// Internal
+ if (_conditionBeanSetupper != null) {
+ _conditionBeanSetupper.setup(cb);
+ }
+ }
+
+ public void delegateEntitySettingUp(java.util.List entityList) {// Internal
+ if (_entityListSetupper != null) {
+ _entityListSetupper.setup(entityList);
+ }
+ }
+
+ // ===================================================================================
+ // Accessor
+ // ========
+ public ConditionBeanSetupper getConditionBeanSetupper() {
+ return _conditionBeanSetupper;
+ }
+
+ public void setConditionBeanSetupper(ConditionBeanSetupper conditionBeanSetupper) {
+ this._conditionBeanSetupper = conditionBeanSetupper;
+ }
+
+ public EntityListSetupper getEntityListSetupper() {
+ return _entityListSetupper;
+ }
+
+ public void setEntityListSetupper(EntityListSetupper entityListSetupper) {
+ this._entityListSetupper = entityListSetupper;
+ }
+
+ public REFERER_CONDITION_BEAN getReffererConditionBean() {
+ return _reffererConditionBean;
+ }
+
+ public void setReffererConditionBean(REFERER_CONDITION_BEAN reffererConditionBean) {
+ this._reffererConditionBean = reffererConditionBean;
+ }
+
+ public boolean isToLastKeyCondtion() {
+ return _toLastKeyCondtion;
+ }
+
+ public boolean isStopOrderByKey() {
+ return _stopOrderByKey;
+ }
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/setup/ConditionBeanSetupper.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/setup/ConditionBeanSetupper.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/setup/ConditionBeanSetupper.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,18 @@
+package jp.sf.pal.pompei.allcommon.bhv.setup;
+
+import jp.sf.pal.pompei.allcommon.cbean.ConditionBean;
+
+/**
+ * The interface of condition-bean setupper.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public interface ConditionBeanSetupper {
+
+ /**
+ * Set up condition.
+ *
+ * @param cb Condition-bean. (NotNull)
+ */
+ public void setup(CONDITION_BEAN cb);
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/setup/EntityListSetupper.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/setup/EntityListSetupper.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/setup/EntityListSetupper.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,18 @@
+package jp.sf.pal.pompei.allcommon.bhv.setup;
+
+import jp.sf.pal.pompei.allcommon.Entity;
+
+/**
+ * The interface of entity list setupper.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public interface EntityListSetupper {
+
+ /**
+ * Set up entity list.
+ *
+ * @param entityList Entity list. (NotNull)
+ */
+ public void setup(java.util.List entityList);
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/setup/ValueLabelBox.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/setup/ValueLabelBox.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/setup/ValueLabelBox.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,26 @@
+package jp.sf.pal.pompei.allcommon.bhv.setup;
+
+/**
+ * The class of Value-Label Box.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public class ValueLabelBox {
+
+ protected Object _value;
+
+ protected String _label;
+
+ public void setValueLabel(Object value, String label) {
+ this._value = value;
+ this._label = label;
+ }
+
+ public Object getValue() {
+ return _value;
+ }
+
+ public String getLabel() {
+ return _label;
+ }
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/setup/ValueLabelSetupper.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/setup/ValueLabelSetupper.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/bhv/setup/ValueLabelSetupper.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,17 @@
+package jp.sf.pal.pompei.allcommon.bhv.setup;
+
+/**
+ * The interface of Value-Label Setupper.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public interface ValueLabelSetupper {
+
+ /**
+ * Set up value-label.
+ *
+ * @param box Value-label box. (NotNull)
+ * @param entity Entity. (NotNull)
+ */
+ public void setup(ValueLabelBox box, T entity);
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/AbstractConditionBean.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/AbstractConditionBean.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/AbstractConditionBean.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,548 @@
+package jp.sf.pal.pompei.allcommon.cbean;
+
+
+import jp.sf.pal.pompei.allcommon.cbean.ConditionBeanContext;
+import jp.sf.pal.pompei.allcommon.dbmeta.DBMeta;
+import jp.sf.pal.pompei.allcommon.dbmeta.DBMetaInstanceHandler;
+import jp.sf.pal.pompei.allcommon.helper.MapListString;
+import jp.sf.pal.pompei.allcommon.helper.MapListStringImpl;
+import jp.sf.pal.pompei.allcommon.cbean.sqlclause.OrderByClause;
+import jp.sf.pal.pompei.allcommon.cbean.sqlclause.SqlClause;
+
+/**
+ * The condition-bean as abstract.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public abstract class AbstractConditionBean implements ConditionBean {
+
+ // =====================================================================================
+ // Attribute
+ // =========
+ /** SQL clause instance. */
+ protected final SqlClause _sqlClause;
+ {
+ _sqlClause = ConditionBeanContext.createSqlClause(this);
+ }
+
+ // =====================================================================================
+ // Sql-Clause
+ // ==========
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @return Sql clause. (NotNull)
+ */
+ public SqlClause getSqlClause() {
+ return _sqlClause;
+ }
+
+ // =====================================================================================
+ // Condition-Query
+ // ===============
+ /**
+ * Get condition query as interface.
+ *
+ * @return Instance of query as interface. (NotNull)
+ */
+ abstract public ConditionQuery getConditionQueryAsInterface();
+
+ // =====================================================================================
+ // Accept Primary-Key
+ // ==================
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @param primaryKeyMapString Primary-key map. (NotNull and NotEmpty)
+ */
+ public void acceptPrimaryKeyMapString(String primaryKeyMapString) {
+ if (primaryKeyMapString == null) {
+ String msg = "The argument[primaryKeyMapString] must not be null.";
+ throw new IllegalArgumentException(msg);
+ }
+ final String prefix = MAP_STRING_MAP_MARK + MAP_STRING_START_BRACE;
+ final String suffix = MAP_STRING_END_BRACE;
+ if (!primaryKeyMapString.trim().startsWith(prefix)) {
+ primaryKeyMapString = prefix + primaryKeyMapString;
+ }
+ if (!primaryKeyMapString.trim().endsWith(suffix)) {
+ primaryKeyMapString = primaryKeyMapString + suffix;
+ }
+ MapListString mapListString = new MapListStringImpl();
+ mapListString.setMapMark(MAP_STRING_MAP_MARK);
+ mapListString.setListMark(MAP_STRING_LIST_MARK);
+ mapListString.setDelimiter(MAP_STRING_DELIMITER);
+ mapListString.setStartBrace(MAP_STRING_START_BRACE);
+ mapListString.setEndBrace(MAP_STRING_END_BRACE);
+ mapListString.setEqual(MAP_STRING_EQUAL);
+ acceptPrimaryKeyMap(mapListString.generateMap(primaryKeyMapString));
+ }
+
+ protected void checkTypeString(Object value, String propertyName, String typeName) {
+ if (value == null) {
+ throw new IllegalArgumentException("The value should not be null: " + propertyName);
+ }
+ if (!(value instanceof String)) {
+ String msg = "The value of " + propertyName + " should be " + typeName + " or String: ";
+ msg = msg + "valueType=" + value.getClass() + " value=" + value;
+ throw new IllegalArgumentException(msg);
+ }
+ }
+
+ protected long parseDateString(Object value, String propertyName, String typeName) {
+ checkTypeString(value, propertyName, typeName);
+ try {
+ return getDateFormat().parse((String)value).getTime();
+ } catch (java.text.ParseException e) {
+ String msg = "The value of " + propertyName + " should be " + typeName + ". but: " + value;
+ throw new RuntimeException(msg + " threw the exception: value=[" + value + "]", e);
+ } catch (RuntimeException e) {
+ String msg = "The value of " + propertyName + " should be " + typeName + ". but: " + value;
+ throw new RuntimeException(msg + " threw the exception: value=[" + value + "]", e);
+ }
+ }
+
+ protected java.text.DateFormat getDateFormat() {
+ return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+ }
+
+ // =====================================================================================
+ // Fetch-Narrowing
+ // ===============
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @return Fetch start index.
+ */
+ public int getFetchNarrowingSkipStartIndex() {
+ return getSqlClause().getFetchNarrowingSkipStartIndex();
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @return Fetch size.
+ */
+ public int getFetchNarrowingLoopCount() {
+ return getSqlClause().getFetchNarrowingLoopCount();
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @return Determination.
+ */
+ public boolean isFetchNarrowingSkipStartIndexEffective() {
+ return !getSqlClause().isFetchStartIndexSupported();
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @return Determination.
+ */
+ public boolean isFetchNarrowingLoopCountEffective() {
+ return !getSqlClause().isFetchSizeSupported();
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @return Determiantion.
+ */
+ public boolean isFetchNarrowingEffective() {
+ return getSqlClause().isFetchNarrowingEffective();
+ }
+
+ // =====================================================================================
+ // Paging
+ // ======
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @param fetchSize Fetch-size. (NotMinus & NotZero)
+ * @return this. (NotNUll)
+ */
+ public PagingBean fetchFirst(int fetchSize) {
+ getSqlClause().fetchFirst(fetchSize);
+ return this;
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @param fetchStartIndex Fetch-start-index. 0 origin. (NotMinus)
+ * @param fetchSize Fetch-size. (NotMinus & NotZero)
+ * @return this. (NotNUll)
+ */
+ public PagingBean fetchScope(int fetchStartIndex, int fetchSize) {
+ getSqlClause().fetchScope(fetchStartIndex, fetchSize);
+ return this;
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @param fetchPageNumber Fetch-page-number. 1 origin. (NotMinus & NotZero)
+ * @return this. (NotNull)
+ */
+ public PagingBean fetchPage(int fetchPageNumber) {
+ getSqlClause().fetchPage(fetchPageNumber);
+ return this;
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @return Fetch-start-index.
+ */
+ public int getFetchStartIndex() {
+ return getSqlClause().getFetchStartIndex();
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @return Fetch-size.
+ */
+ public int getFetchSize() {
+ return getSqlClause().getFetchSize();
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @return Fetch-page-number.
+ */
+ public int getFetchPageNumber() {
+ return getSqlClause().getFetchPageNumber();
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @return Page start index. 0 origin. (NotMinus)
+ */
+ public int getPageStartIndex() {
+ return getSqlClause().getPageStartIndex();
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @return Page end index. 0 origin. (NotMinus)
+ */
+ public int getPageEndIndex() {
+ return getSqlClause().getPageEndIndex();
+ }
+
+ /**
+ * Is fetch scope effective?
+ *
+ * @return Determiantion.
+ */
+ public boolean isFetchScopeEffective() {
+ return getSqlClause().isFetchScopeEffective();
+ }
+
+ // =====================================================================================
+ // Order-By
+ // ========
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @return Sql component of order-by clause. (NotNull)
+ */
+ public OrderByClause getSqlComponentOfOrderByClause() {
+ return getSqlClause().getSqlComponentOfOrderByClause();
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @return Order-by clause. (NotNull)
+ */
+ public String getOrderByClause() {
+ return _sqlClause.getOrderByClause();
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @return this. (NotNull)
+ */
+ public OrderByBean clearOrderBy() {
+ getSqlClause().clearOrderBy();
+ return this;
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @return this. (NotNull)
+ */
+ public OrderByBean ignoreOrderBy() {
+ getSqlClause().ignoreOrderBy();
+ return this;
+ }
+
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @return this. (NotNull)
+ */
+ public OrderByBean makeOrderByEffective() {
+ getSqlClause().makeOrderByEffective();
+ return this;
+ }
+
+ /**
+ * Register order-by-asc.
+ *
+ * @param orderByProperty Order-by-property. 'aliasName.columnName/aliasName.columnName/...' (NotNull)
+ * @return this. (NotNull)
+ */
+ public OrderByBean registerOrderByAsc(String orderByProperty) {
+ getSqlClause().registerOrderBy(filterOrderByProperty(orderByProperty), orderByProperty, true);
+ return this;
+ }
+
+ /**
+ * Register order-by-desc.
+ *
+ * @param orderByProperty Order-by-property. 'aliasName.columnName/aliasName.columnName/...' (NotNull)
+ * @return this. (NotNull)
+ */
+ public OrderByBean registerOrderByDesc(String orderByProperty) {
+ getSqlClause().registerOrderBy(filterOrderByProperty(orderByProperty), orderByProperty, false);
+ return this;
+ }
+
+ /**
+ * Reverse order-by or Override order-by asc.
+ *
+ * @param orderByProperty Order-by-property. 'aliasName.columnName/aliasName.columnName/...' (NotNull)
+ * @return this. (NotNull)
+ */
+ public OrderByBean reverseOrderBy_Or_OverrideOrderByAsc(String orderByProperty) {
+ getSqlClause().reverseOrderBy_Or_OverrideOrderBy(filterOrderByProperty(orderByProperty), orderByProperty, true);
+ return this;
+ }
+
+ /**
+ * Reverse order-by or Override order-by desc.
+ *
+ * @param orderByProperty Order-by-property. 'aliasName.columnName/aliasName.columnName/...' (NotNull)
+ * @return this. (NotNull)
+ */
+ public OrderByBean reverseOrderBy_Or_OverrideOrderByDesc(String orderByProperty) {
+ getSqlClause().reverseOrderBy_Or_OverrideOrderBy(filterOrderByProperty(orderByProperty), orderByProperty, false);
+ return this;
+ }
+
+ protected String filterOrderByProperty(String orderByProperty) {
+ final java.util.List orderBySlashList = new java.util.ArrayList();
+ {
+ final java.util.StringTokenizer st = new java.util.StringTokenizer(orderByProperty, "/");
+ while (st.hasMoreElements()) {
+ orderBySlashList.add(st.nextToken());
+ }
+ }
+
+ final StringBuffer sb = new StringBuffer();
+ DBMeta dbmeta = DBMetaInstanceHandler.getInstanceByTableDbName(getTableDbName());
+ ConditionQuery query = this.getConditionQueryAsInterface();
+ for (final java.util.Iterator ite = orderBySlashList.iterator(); ite.hasNext(); ) {
+ final String orderBySlashElement = (String)ite.next();
+ final java.util.List orderByDotList = new java.util.ArrayList();
+ {
+ final java.util.StringTokenizer st = new java.util.StringTokenizer(orderBySlashElement, "/");
+ while (st.hasMoreElements()) {
+ orderByDotList.add(st.nextToken());
+ }
+ }
+
+ if (orderByDotList.size() == 1) {
+ if (dbmeta.isExistMultiName(orderBySlashElement)) {
+ sb.append("/").append(query.getRealColumnName(dbmeta.getDbNameByMultiName(orderBySlashElement)));
+ } else {
+ sb.append("/").append(orderBySlashElement);
+ }
+ } else {
+ DBMeta foreignDBMeta = dbmeta;
+ ConditionQuery foreignQuery = query;
+ int count = 0;
+ for (final java.util.Iterator ite2 = orderByDotList.iterator(); ite2.hasNext(); ) {
+ String orderByDotElement = (String)ite2.next();
+ count++;
+
+ if (orderByDotList.size() == count) {// Last Loop!
+ if (!foreignDBMeta.isExistMultiName(orderByDotElement)) {
+ String msg = "The name for order-by is not existing: name=" + orderByDotElement;
+ msg = msg + " orderBySlashElement=" + orderBySlashElement + " orderByProperty=" + orderByProperty;
+ throw new IllegalStateException(msg);
+ }
+ sb.append("/").append(foreignQuery.getRealColumnName(foreignDBMeta.getDbNameByMultiName(orderByDotElement)));
+ break;
+ }
+
+ foreignDBMeta = foreignDBMeta.getForeignDBMeta(orderByDotElement);
+ foreignQuery = foreignQuery.getForeignConditionQuery(orderByDotElement);
+ }
+ }
+ }
+ sb.delete(0, "/".length());
+ return sb.toString();
+ }
+
+ // =====================================================================================
+ // Limit-Select
+ // ============
+ /** Is limit-select PK only? */
+ protected boolean _isLimitSelectPKOnly;
+
+ /**
+ * Is limit-select PK only?
+ *
+ * @return Determination.
+ */
+ public boolean isLimitSelect_PKOnly() {
+ return _isLimitSelectPKOnly;
+ }
+
+ /**
+ * Limit select PK only.
+ *
+ * @return this. (NotNull)
+ */
+ public ConditionBean limitSelect_PKOnly() {
+ _isLimitSelectPKOnly = true;
+ return this;
+ }
+
+ /**
+ * Limit select off.
+ *
+ * @return this. (NotNull)
+ */
+ public ConditionBean limitSelect_Off() {
+ _isLimitSelectPKOnly = false;
+ return this;
+ }
+
+ // =====================================================================================
+ // Advance
+ // =======
+ /**
+ * This method implements the method that is declared at super.
+ *
+ * @return this. (NotNull)
+ */
+ public ConditionBean lockForUpdate() {
+ getSqlClause().lockForUpdate();
+ return this;
+ }
+
+ // =====================================================================================
+ // For SqlComment
+ // ==============
+ /**
+ * Get select-hint. {select [select-hint] * from table...}
+ *
+ * @return select-hint. (NotNull)
+ */
+ public String getSelectHint() {
+ return getSqlClause().getSelectHint();
+ }
+
+ /**
+ * Get from-base-table-hint. {select * from table [from-base-table-hint] where ...}
+ *
+ * @return from-base-table-hint. (NotNull)
+ */
+ public String getFromBaseTableHint() {
+ return getSqlClause().getFromBaseTableHint();
+ }
+
+ /**
+ * Get from-hint. {select * from table left outer join ... on ... [from-hint] where ...}
+ *
+ * @return from-hint. (NotNull)
+ */
+ public String getFromHint() {
+ return getSqlClause().getFromHint();
+ }
+
+ /**
+ * Get where clause.
+ *
+ * @return Where clause. (NotNull)
+ */
+ public String getWhereClause() {
+ return getSqlClause().getWhereClause();
+ }
+
+ /**
+ * Get sql-suffix. {select * from table where ... order by ... [sql-suffix]}
+ *
+ * @return Sql-suffix. (NotNull)
+ */
+ public String getSqlSuffix() {
+ return getSqlClause().getSqlSuffix();
+ }
+
+ // ------------------------------
+ // for Internal
+ // ------------
+ /**
+ * Set up various things for select-count-ignore-fetch-scope. {Internal}
+ * This method is for INTERNAL. Don't invoke this!
+ *
+ * @return this. (NotNull)
+ */
+ public ConditionBean xsetupSelectCountIgnoreFetchScope() {
+ _isSelectCountIgnoreFetchScope = true;
+
+ // If the query uses union query, it needs included-select-column.
+ if (!hasUnionQueryOrUnionAllQuery()) {
+ getSqlClause().ignoreIncludedSelectColumn();
+ }
+
+ getSqlClause().ignoreOrderBy();
+ getSqlClause().ignoreFetchScope();
+ return this;
+ }
+
+ /**
+ * Do after-care for select-count-ignore-fetch-scope. {Internal}
+ * This method is for INTERNAL. Don't invoke this!
+ *
+ * @return this. (NotNull)
+ */
+ public ConditionBean xafterCareSelectCountIgnoreFetchScope() {
+ _isSelectCountIgnoreFetchScope = false;
+
+ // If the query uses union query, it needs included-select-column.
+ if (!hasUnionQueryOrUnionAllQuery()) {
+ getSqlClause().makeIncludedSelectColumnEffective();
+ }
+
+ getSqlClause().makeOrderByEffective();
+ getSqlClause().makeFetchScopeEffective();
+ return this;
+ }
+
+ /** Is set up various things for select-count-ignore-fetch-scope? */
+ protected boolean _isSelectCountIgnoreFetchScope;
+
+ /**
+ * Is set up various things for select-count-ignore-fetch-scope?
+ * This method is for INTERNAL. Don't invoke this!
+ *
+ * @return Determination.
+ */
+ public boolean isSelectCountIgnoreFetchScope() {
+ return _isSelectCountIgnoreFetchScope;
+ }
+
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/AbstractConditionQuery.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/AbstractConditionQuery.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/AbstractConditionQuery.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,765 @@
+package jp.sf.pal.pompei.allcommon.cbean;
+
+
+import jp.sf.pal.pompei.allcommon.cbean.ckey.ConditionKey;
+import jp.sf.pal.pompei.allcommon.cbean.coption.ConditionOption;
+import jp.sf.pal.pompei.allcommon.cbean.coption.FromToOption;
+import jp.sf.pal.pompei.allcommon.cbean.coption.LikeSearchOption;
+import jp.sf.pal.pompei.allcommon.cbean.coption.InScopeOption;
+import jp.sf.pal.pompei.allcommon.cbean.cvalue.ConditionValue;
+import jp.sf.pal.pompei.allcommon.dbmeta.DBMeta;
+import jp.sf.pal.pompei.allcommon.dbmeta.DBMetaInstanceHandler;
+import jp.sf.pal.pompei.allcommon.cbean.sqlclause.SqlClause;
+
+/**
+ * The abstract class of condition-query.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public abstract class AbstractConditionQuery implements ConditionQuery {
+
+ // =====================================================================================
+ // Attribute
+ // =========
+ /** Condition value for DUMMY. */
+ protected static final ConditionValue DUMMY_CONDITION_VALUE = new ConditionValue();
+
+ /** Object for DUMMY. */
+ protected static final Object DUMMY_OBJECT = new Object();
+
+ /** SQL clause. */
+ protected final SqlClause _sqlClause;
+
+ /** My alias name. */
+ protected final String _aliasName;
+
+ /** Nest level. */
+ protected final int _nestLevel;
+
+ /** Child query. */
+ protected final ConditionQuery _childQuery;
+
+ // =====================================================================================
+ // Constructor
+ // ===========
+ /**
+ * Constructor.
+ *
+ * @param childQuery Child query. (Nullable: If null, this is base instance.)
+ * @param sqlClause SQL clause instance. (NotNull)
+ * @param aliasName My alias name. (NotNull)
+ * @param nestLevel Nest level.
+ */
+ public AbstractConditionQuery(ConditionQuery childQuery, SqlClause sqlClause, String aliasName, int nestLevel) {
+ _childQuery = childQuery;
+ _sqlClause = sqlClause;
+ _aliasName = aliasName;
+ _nestLevel = nestLevel;
+ }
+
+ // =====================================================================================
+ // Accessor
+ // ========
+ /**
+ * Get child query.
+ *
+ * @return Child query. (Nullable)
+ */
+ public ConditionQuery getChildQuery() {
+ return _childQuery;
+ }
+
+ /**
+ * Get sql clause.
+ *
+ * @return Sql clause. (NotNull)
+ */
+ public SqlClause getSqlClause() {
+ return _sqlClause;
+ }
+
+ /**
+ * Get alias name.
+ *
+ * @return Alias name. (NotNull)
+ */
+ public String getAliasName() {
+ return _aliasName;
+ }
+
+ /**
+ * Get nest level.
+ *
+ * @return Nest level.
+ */
+ public int getNestLevel() {
+ return _nestLevel;
+ }
+
+ /**
+ * Get next nest level.
+ *
+ * @return Next nest level.
+ */
+ public int getNextNestLevel() {
+ return _nestLevel+1;
+ }
+
+ /**
+ * Is base query?
+ *
+ * @param query Condition query. (NotNull)
+ * @return Determination.
+ */
+ public boolean isBaseQuery(ConditionQuery query) {
+ return (query.getChildQuery() == null);
+ }
+
+ // =====================================================================================
+ // Real Name
+ // =========
+ /**
+ * Get real alias name(that has nest level mark).
+ *
+ * @return Real alias name.
+ */
+ public String getRealAliasName() {
+ if (getNestLevel() > 1) {
+ return getAliasName() + "_n" + getNestLevel();
+ } else {
+ return getAliasName();
+ }
+ }
+
+ /**
+ * Get real column name(with real alias name).
+ *
+ * @param columnName Column name without alias name. This should not contain comma. (NotNull)
+ * @return Real column name.
+ */
+ public String getRealColumnName(String columnName) {
+ assertColumnName(columnName);
+ return getRealAliasName() + "." + columnName;
+ }
+
+ // =====================================================================================
+ // Location
+ // ========
+ /**
+ * Get location.
+ *
+ * @param columnPropertyName Column property name.
+ * @param key Condition key.
+ * @return Next nest level.
+ */
+ protected String getLocation(String columnPropertyName, ConditionKey key) {
+ return getLocationBase(columnPropertyName) + "." + key.getConditionKey();
+ }
+
+ protected String getLocationBase() {
+ final StringBuffer sb = new StringBuffer();
+ ConditionQuery query = this;
+ while (true) {
+ if (query.isBaseQuery(query)) {
+ sb.insert(0, "conditionQuery.");
+ break;
+ } else {
+ sb.insert(0, "conditionQuery" + query.getAliasName() + ".");
+ }
+ query = query.getChildQuery();
+ }
+ return sb.toString();
+ }
+
+ protected String getLocationBase(String columnPropertyName) {
+ return getLocationBase() + columnPropertyName;
+ }
+
+ // =====================================================================================
+ // Union-Query
+ // ===========
+ protected java.util.Map _unionQueryMap = new java.util.LinkedHashMap();
+
+ public java.util.Map getUnionQueryMap() {// for Internal
+ return _unionQueryMap;
+ }
+
+ /**
+ * Set union query. {Internal}
+ *
+ * Add union query to condition bean.
+ *
+ * @param unionQuery Union query. (NotNull)
+ */
+ public void xsetUnionQuery(ConditionQuery unionQuery) {
+ xsetupUnion(unionQuery, false, _unionQueryMap);
+ }
+
+ protected java.util.Map _unionAllQueryMap = new java.util.LinkedHashMap();
+
+ public java.util.Map getUnionAllQueryMap() {// for Internal
+ return _unionAllQueryMap;
+ }
+
+ /**
+ * Set union all query. {Internal}
+ *
+ * Add union all query to condition bean.
+ *
+ * @param unionAllQuery Union all query. (NotNull)
+ */
+ public void xsetUnionAllQuery(ConditionQuery unionAllQuery) {
+ xsetupUnion(unionAllQuery, true, _unionAllQueryMap);
+ }
+
+ protected void xsetupUnion(ConditionQuery unionQuery, boolean unionAll, java.util.Map unionQueryMap) {
+ if (unionQuery == null) {
+ String msg = "The argument[unionQuery] should not be null.";
+ throw new IllegalArgumentException(msg);
+ }
+ reflectRelationOnUnionQuery(this, unionQuery);// Reflect Relation!
+ getSqlClause().copyIncludedSelectColumn(unionQuery.getSqlClause());// Reflect IncludedSelectColumn!
+ final String key = (unionAll ? "unionAllQuery" : "unionQuery") + unionQueryMap.size();
+ unionQueryMap.put(key, unionQuery);
+ registerUnionQuery(unionQuery, unionAll, (unionAll ? "unionAllQueryMap" : "unionQueryMap") + "." + key);
+ }
+
+ abstract protected void reflectRelationOnUnionQuery(ConditionQuery baseQueryAsSuper, ConditionQuery unionQueryAsSuper);
+
+ public boolean hasUnionQueryOrUnionAllQuery() {
+ return !_unionQueryMap.isEmpty() || !_unionAllQueryMap.isEmpty();
+ }
+
+ public java.util.List getUnionQueryList() {
+ return new java.util.ArrayList(_unionQueryMap.values());
+ }
+
+ public java.util.List getUnionAllQueryList() {
+ return new java.util.ArrayList(_unionAllQueryMap.values());
+ }
+
+ // =====================================================================================
+ // Include-As-Mine
+ // ===============
+ /**
+ * Register included-select-column.
+ *
+ * @param aliasName Alias name. This should not contain comma. (NotNull)
+ * @param realColumnName Real column name. This should not contain comma. (NotNull)
+ */
+ protected void registerIncludedSelectColumn(String aliasName, String realColumnName) {
+ assertAliasName(aliasName);
+ assertColumnName(realColumnName);
+ getSqlClause().registerIncludedSelectColumn(aliasName, realColumnName);
+ }
+
+ // =====================================================================================
+ // Register
+ // ========
+ // ----------------------------------------
+ // Normal
+ // ------
+ protected void registerQuery(ConditionKey key, Object value, ConditionValue cvalue
+ , String colName, String capPropName, String uncapPropName) {
+ if (key.isValidRegistration(cvalue, value, key.getConditionKey() + " of " + getRealAliasName() + "." + uncapPropName)) {
+ setupConditionValueAndRegisterWhereClause(key, value, cvalue, colName, capPropName, uncapPropName);
+ }
+ }
+
+ protected void registerQuery(ConditionKey key, Object value, ConditionValue cvalue
+ , String colName, String capPropName, String uncapPropName, ConditionOption option) {
+ if (key.isValidRegistration(cvalue, value, key.getConditionKey() + " of " + getRealAliasName() + "." + uncapPropName)) {
+ setupConditionValueAndRegisterWhereClause(key, value, cvalue, colName, capPropName, uncapPropName, option);
+ }
+ }
+
+ // ----------------------------------------
+ // FromTo
+ // ------
+ protected void registerFromToQuery(java.util.Date fromDate, java.util.Date toDate, ConditionValue cvalue
+ , String colName, String capPropName, String uncapPropName, FromToOption option) {
+ {
+ final java.util.Date filteredFromDate = option.filterFromDate(fromDate);
+ final ConditionKey fromKey = option.getFromDateConditionKey();
+ if (fromKey.isValidRegistration(cvalue, filteredFromDate, fromKey.getConditionKey() + " of " + getRealAliasName() + "." + uncapPropName)) {
+ setupConditionValueAndRegisterWhereClause(fromKey, filteredFromDate, cvalue, colName, capPropName, uncapPropName);
+ }
+ }
+ {
+ final java.util.Date filteredToDate = option.filterToDate(toDate);
+ final ConditionKey toKey = option.getToDateConditionKey();
+ if (toKey.isValidRegistration(cvalue, filteredToDate, toKey.getConditionKey() + " of " + getRealAliasName() + "." + uncapPropName)) {
+ setupConditionValueAndRegisterWhereClause(toKey, filteredToDate, cvalue, colName, capPropName, uncapPropName);
+ }
+ }
+ }
+
+ // ----------------------------------------
+ // LikeSearch
+ // ----------
+ protected void registerLikeSearchQuery(ConditionKey key, String value, ConditionValue cvalue
+ , String colName, String capPropName, String uncapPropName, LikeSearchOption option) {
+ if (key.isValidRegistration(cvalue, value, key.getConditionKey() + " of " + getRealAliasName() + "." + uncapPropName)) {
+ if (value != null && option.isSplit()) {
+ final String[] strArray = option.generateSplitValueArray(value);
+ for (int i=0; i < strArray.length; i++) {
+ final String currentValue = strArray[i];
+ setupConditionValueAndRegisterWhereClause(key, currentValue, cvalue, colName, capPropName, uncapPropName, option);
+
+ // Callback for LikeAsOr!
+ final java.util.List callbackList = option.getLikeAsOrCallbackList();
+ if (!callbackList.isEmpty()) {
+ getSqlClause().makeAdditionalConditionAsOrEffective();
+ for (java.util.Iterator ite = callbackList.iterator(); ite.hasNext(); ) {
+ final LikeSearchOption.LikeAsOrCallback likeAsOrCallback = (LikeSearchOption.LikeAsOrCallback)ite.next();
+ final String additionalTargetPropertyName = likeAsOrCallback.getAdditionalTargetPropertyName();
+ final String filteredValue = likeAsOrCallback.filterValue(currentValue);
+ final LikeSearchOption optionDeepCopy = (LikeSearchOption)option.createDeepCopy();
+ optionDeepCopy.clearLikeAsOrCallback();
+ final LikeSearchOption filteredOption = likeAsOrCallback.filterOption(optionDeepCopy);
+ invokeSetterLikeSearch(additionalTargetPropertyName, filteredValue, filteredOption);
+ }
+ getSqlClause().ignoreAdditionalConditionAsOr();
+ }
+ }
+ } else {
+ setupConditionValueAndRegisterWhereClause(key, value, cvalue, colName, capPropName, uncapPropName, option);
+ }
+ }
+ }
+
+ // ----------------------------------------
+ // InScope
+ // -------
+ protected void registerInScopeQuery(ConditionKey key, String value, ConditionValue cvalue
+ , String colName, String capPropName, String uncapPropName, InScopeOption option) {
+ if (key.isValidRegistration(cvalue, value, key.getConditionKey() + " of " + getRealAliasName() + "." + uncapPropName)) {
+ if (value != null && option.isSplit()) {
+ final String[] strArray = option.generateSplitValueArray(value);
+ final java.util.List realValueList = new java.util.ArrayList();
+ for (int i=0; i < strArray.length; i++) {
+ final String currentValue = strArray[i];
+ realValueList.add(currentValue);
+ }
+ setupConditionValueAndRegisterWhereClause(key, realValueList, cvalue, colName, capPropName, uncapPropName, option);
+ } else {
+ setupConditionValueAndRegisterWhereClause(key, value, cvalue, colName, capPropName, uncapPropName, option);
+ }
+ }
+ }
+
+ protected void setupConditionValueAndRegisterWhereClause(ConditionKey key, Object value, ConditionValue cvalue
+ , String colName, String capPropName, String uncapPropName) {
+ key.setupConditionValue(cvalue, value, getLocation(uncapPropName, key));// If Java, UncapProp!
+ getSqlClause().registerWhereClause(getRealColumnName(colName), key, cvalue);
+ }
+
+ protected void setupConditionValueAndRegisterWhereClause(ConditionKey key, Object value, ConditionValue cvalue
+ , String colName, String capPropName, String uncapPropName, ConditionOption option) {
+ key.setupConditionValue(cvalue, value, getLocation(uncapPropName, key), option);// If Java, UncapProp!
+ getSqlClause().registerWhereClause(getRealColumnName(colName), key, cvalue, option);
+ }
+
+ // ----------------------------------------
+ // Inline
+ // ------
+ protected void registerInlineQuery(ConditionKey key, Object value, ConditionValue cvalue
+ , String colName, String capPropName, String uncapPropName) {
+ if (key.isValidRegistration(cvalue, value, key.getConditionKey() + " of " + getRealAliasName() + "." + uncapPropName)) {
+ key.setupConditionValue(cvalue, value, getLocation(uncapPropName, key));// If Java, UncapProp!
+ if (isBaseQuery(this)) {
+ getSqlClause().registerBaseTableInlineWhereClause(colName, key, cvalue);
+ } else {
+ getSqlClause().registerOuterJoinInlineWhereClause(getRealAliasName(), colName, key, cvalue);
+ }
+ }
+ }
+
+ protected void registerInlineQuery(ConditionKey key, Object value, ConditionValue cvalue
+ , String colName, String capPropName, String uncapPropName, ConditionOption option) {
+ if (key.isValidRegistration(cvalue, value, key.getConditionKey() + " of " + getRealAliasName() + "." + uncapPropName)) {
+ key.setupConditionValue(cvalue, value, getLocation(uncapPropName, key), option);// If Java, UncapProp!
+ if (isBaseQuery(this)) {
+ getSqlClause().registerBaseTableInlineWhereClause(colName, key, cvalue, option);
+ } else {
+ getSqlClause().registerOuterJoinInlineWhereClause(getRealAliasName(), colName, key, cvalue, option);
+ }
+ }
+ }
+
+ // ----------------------------------------
+ // InScopeSubQuery
+ // ---------------
+ protected void registerInScopeSubQuery(ConditionQuery subQuery
+ , String columnName, String relatedColumnName, String propertyName) {
+ final String realColumnName = getRealColumnName(columnName);
+ final String subQueryClause = getInScopeSubQuerySql(subQuery, relatedColumnName, propertyName);
+ registerWhereClause(realColumnName + " in (" + subQueryClause + ")");
+ }
+
+ protected String getInScopeSubQuerySql(ConditionQuery subQuery
+ , String relatedColumnName, String propertyName) {
+ final String selectClause = "select " + subQuery.getAliasName() + "." + relatedColumnName;
+ String clause = subQuery.getSqlClause().getClauseWithoutIncludedOrderBySqlSuffix();
+ clause = replaceString(clause, ".conditionQuery.", "." + getLocationBase(propertyName) + ".");// Very Important!
+ return replaceString(clause, SqlClause.INCLUDE_SELECT_CLAUSE_MARK, selectClause);
+ }
+
+ // ----------------------------------------
+ // ExistsSubQuery
+ // --------------
+ protected void registerExistsSubQuery(ConditionQuery subQuery
+ , String columnName, String relatedColumnName, String propertyName) {
+ final String realColumnName = getRealColumnName(columnName);
+ final String subQueryClause = getExistsSubQuerySql(subQuery, realColumnName, relatedColumnName, propertyName);
+ registerWhereClause("exists (" + subQueryClause + ")");
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ // *Unsupport ExistsSubQuery as inline because it's so dangerous.
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+ protected String getExistsSubQuerySql(ConditionQuery subQuery
+ , String realColumnName, String relatedColumnName, String propertyName) {
+ final String selectClause = "select " + subQuery.getAliasName() + "." + relatedColumnName;
+ String clause = subQuery.getSqlClause().getClauseWithoutIncludedOrderBySqlSuffix();
+ clause = replaceString(clause, ".conditionQuery.", "." + getLocationBase(propertyName) + ".");// Very Important!
+ final String parentCondition;
+ if (clause.contains("where")) {
+ parentCondition = " and " + relatedColumnName + " = " + realColumnName;
+ } else {
+ parentCondition = " where " + relatedColumnName + " = " + realColumnName;
+ }
+ return replaceString(clause + parentCondition, SqlClause.INCLUDE_SELECT_CLAUSE_MARK, selectClause);
+ }
+
+ protected void registerWhereClause(String whereClause) {
+ getSqlClause().registerWhereClause(whereClause);
+ }
+
+ protected void registerInlineWhereClause(String whereClause) {
+ if (isBaseQuery(this)) {
+ getSqlClause().registerBaseTableInlineWhereClause(whereClause);
+ } else {
+ getSqlClause().registerOuterJoinInlineWhereClause(getRealAliasName(), whereClause);
+ }
+ }
+
+ // ----------------------------------------
+ // UnionQuery
+ // ----------
+ public void registerUnionQuery(ConditionQuery unionQuery, boolean unionAll, String unionQueryPropertyName) {
+ final String unionQueryClause = getUnionQuerySql(unionQuery, unionQueryPropertyName);
+ getSqlClause().registerUnionQuery(unionQueryClause, unionAll);
+ }
+
+ protected String getUnionQuerySql(ConditionQuery unionQuery, String unionQueryPropertyName) {
+ final String selectClause = unionQuery.getSqlClause().getIncludedSelectColumnClause();
+ final String queryClause = unionQuery.getSqlClause().getFromClause() + " " + unionQuery.getSqlClause().getWhereClause();
+ final String oldStr = ".conditionQuery.";
+ final String newStr = ".conditionQuery." + unionQueryPropertyName + ".";
+ final String replacedClause = replaceString(queryClause, oldStr, newStr);// Very Important!
+ return selectClause + " " + replacedClause;
+ }
+
+ // =====================================================================================
+ // Invoke
+ // ======
+ public ConditionValue invokeGetter(String columnMultiName) {
+ final DBMeta dbmeta = DBMetaInstanceHandler.getInstanceByTableDbName(getTableDbName());
+ final String columnCapPropName = dbmeta.getCapPropNameByMultiName(columnMultiName);
+ String methodName = "get" + columnCapPropName;
+ java.lang.reflect.Method method = null;
+ try {
+ method = this.getClass().getMethod(methodName, new Class[]{});
+ } catch (NoSuchMethodException e) {
+ String msg = "The columnMultiName is not existing in this table: columnMultiName=" + columnMultiName;
+ msg = msg + " tableName=" + getTableDbName() + " methodName=" + methodName;
+ throw new RuntimeException(msg, e);
+ }
+ try {
+ final Object result = method.invoke(this, new Object[]{});
+ return (ConditionValue)result;
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (java.lang.reflect.InvocationTargetException e) {
+ throw new RuntimeException(e.getCause());
+ }
+ }
+
+ public void invokeSetterEqual(String columnMultiName, Object value) {
+ invokeSetter(columnMultiName, value, "equal");
+ }
+
+ public void invokeSetterNotEqual(String columnMultiName, Object value) {
+ invokeSetter(columnMultiName, value, "notEqual");
+ }
+
+ public void invokeSetterGreaterThan(String columnMultiName, Object value) {
+ invokeSetter(columnMultiName, value, "greaterThan");
+ }
+
+ public void invokeSetterLessThan(String columnMultiName, Object value) {
+ invokeSetter(columnMultiName, value, "lessThan");
+ }
+
+ public void invokeSetterGreaterEqual(String columnMultiName, Object value) {
+ invokeSetter(columnMultiName, value, "greaterEqual");
+ }
+
+ public void invokeSetterLessEqual(String columnMultiName, Object value) {
+ invokeSetter(columnMultiName, value, "lessEqual");
+ }
+
+ protected void invokeSetter(String columnMultiName, Object value, String conditionKeyName) {
+ if (value == null) {
+ return;
+ }
+ final DBMeta dbmeta = DBMetaInstanceHandler.getInstanceByTableDbName(getTableDbName());
+ final String columnCapPropName = dbmeta.getCapPropNameByMultiName(columnMultiName);
+ String methodName = "set" + columnCapPropName + "_" + conditionKeyName.substring(0, 1).toUpperCase() + conditionKeyName.substring(1);
+ java.lang.reflect.Method method = null;
+ try {
+ method = this.getClass().getMethod(methodName, new Class[]{value.getClass()});
+ } catch (NoSuchMethodException e) {
+ String msg = "The columnMultiName is not existing in this table: columnMultiName=" + columnMultiName;
+ msg = msg + " tableName=" + getTableDbName() + " methodName=" + methodName;
+ throw new RuntimeException(msg, e);
+ }
+ try {
+ method.invoke(this, new Object[]{value});
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (java.lang.reflect.InvocationTargetException e) {
+ throw new RuntimeException(e.getCause());
+ }
+ }
+
+ protected void invokeSetterLikeSearch(String columnMultiName, Object value, LikeSearchOption option) {
+ if (value == null) {
+ return;
+ }
+ final DBMeta dbmeta = DBMetaInstanceHandler.getInstanceByTableDbName(getTableDbName());
+ final String columnCapPropName = dbmeta.getCapPropNameByMultiName(columnMultiName);
+ String methodName = "set" + columnCapPropName + "_" + "likeSearch".substring(0, 1).toUpperCase() + "likeSearch".substring(1);
+ java.lang.reflect.Method method = null;
+ try {
+ method = this.getClass().getMethod(methodName, new Class[]{value.getClass(), LikeSearchOption.class});
+ } catch (NoSuchMethodException e) {
+ String msg = "The columnMultiName is not existing in this table: columnMultiName=" + columnMultiName;
+ msg = msg + " tableName=" + getTableDbName() + " methodName=" + methodName;
+ throw new RuntimeException(msg, e);
+ }
+ try {
+ method.invoke(this, new Object[]{value, option});
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (java.lang.reflect.InvocationTargetException e) {
+ throw new RuntimeException(e.getCause());
+ }
+ }
+
+ public void invokeAddOrderByAsc(String columnMultiName) {
+ invokeOrderBy(columnMultiName, true);
+ }
+
+ public void invokeAddOrderByDesc(String columnMultiName) {
+ invokeOrderBy(columnMultiName, false);
+ }
+
+ protected void invokeOrderBy(String columnMultiName, boolean isAsc) {
+ String ascDesc = null;
+ if (isAsc) {
+ ascDesc = "Asc";
+ } else {
+ ascDesc = "Desc";
+ }
+ final DBMeta dbmeta = DBMetaInstanceHandler.getInstanceByTableDbName(getTableDbName());
+ final String methodName = "addOrderBy_" + dbmeta.getCapPropNameByMultiName(columnMultiName) + "_" + ascDesc;
+
+ java.lang.reflect.Method method = null;
+ try {
+ method = this.getClass().getMethod(methodName, new Class[]{});
+ } catch (NoSuchMethodException e) {
+ String msg = "The columnMultiName is not existing in this table: columnMultiName=" + columnMultiName;
+ msg = msg + " tableName=" + getTableDbName() + " methodName=" + methodName;
+ throw new RuntimeException(msg, e);
+ }
+ try {
+ method.invoke(this, new Object[]{});
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (java.lang.reflect.InvocationTargetException e) {
+ throw new RuntimeException(e.getCause());
+ }
+ }
+
+ // =====================================================================================
+ // Foreign Query
+ // =============
+ ///
+ /// This method implements the method that is declared at super.
+ ///
+ /// Foreign-property-name(Both OK - InitCap or not). (NotNull)
+ /// Foreign condition-query as interface.
+ public ConditionQuery getForeignConditionQuery(String foreignPropertyName) {
+ final String methodName = "query" + foreignPropertyName.substring(0, 1) + foreignPropertyName.substring(1);
+ java.lang.reflect.Method method = null;
+ try {
+ method = this.getClass().getMethod(methodName, new Class[]{});
+ } catch (NoSuchMethodException e) {
+ String msg = "The foreignPropertyName is not existing in this table: foreignPropertyName=" + foreignPropertyName;
+ msg = msg + " tableName=" + getTableDbName() + " methodName=" + methodName;
+ throw new RuntimeException(msg, e);
+ }
+ try {
+ return (ConditionQuery)method.invoke(this, new Object[]{});
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (java.lang.reflect.InvocationTargetException e) {
+ throw new RuntimeException(e.getCause());
+ }
+ }
+
+ // =====================================================================================
+ // Helper
+ // ======
+
+ protected final String replaceString(String text, String fromText, String toText) {
+ if(text == null || fromText == null || toText == null)
+ return null;
+ StringBuffer buf = new StringBuffer(100);
+ int pos = 0;
+ int pos2 = 0;
+ do {
+ pos = text.indexOf(fromText, pos2);
+ if(pos == 0) {
+ buf.append(toText);
+ pos2 = fromText.length();
+ } else
+ if(pos > 0) {
+ buf.append(text.substring(pos2, pos));
+ buf.append(toText);
+ pos2 = pos + fromText.length();
+ } else {
+ buf.append(text.substring(pos2));
+ return buf.toString();
+ }
+ } while(true);
+ }
+
+ /**
+ * Filter removing empty-string.
+ * If the value is null or empty-string, returns null.
+ *
+ * @param value Query-value-string. (Nullable)
+ * @return Filtered value. (Nullable)
+ */
+ protected String filterRemoveEmptyString(String value) {
+ return ((value != null && !"".equals(value)) ? value : null);
+ }
+
+ /**
+ * Filter removing empty-string from the list.
+ * If the list is null or empty-string, returns null.
+ *
+ * @param ls List. (Nullable)
+ * @return Filtered list. (Nullable)
+ */
+ protected java.util.List filterRemoveEmptyStringFromList(java.util.List ls) {
+ if (ls == null) {
+ return null;
+ }
+ java.util.List newList = new java.util.ArrayList();
+ for (final java.util.Iterator ite = ls.iterator(); ite.hasNext(); ) {
+ final String str = (String)ite.next();
+ if ("".equals(str)) {
+ continue;
+ }
+ newList.add(str);
+ }
+ return newList;
+ }
+
+ // ----------------------------------------------------------------
+ // Assert Object
+ // -------------
+ /**
+ * Assert that the object is not null.
+ *
+ * @param variableName Variable name. (NotNull)
+ * @param value Value. (NotNull)
+ * @exception IllegalArgumentException
+ */
+ protected void assertObjectNotNull(String variableName, Object value) {
+ if (variableName == null) {
+ String msg = "The value should not be null: variableName=" + variableName + " value=" + value;
+ throw new IllegalArgumentException(msg);
+ }
+ if (value == null) {
+ String msg = "The value should not be null: variableName=" + variableName;
+ throw new IllegalArgumentException(msg);
+ }
+ }
+
+ /**
+ * Assert that the column-name is not null and is not emtpy and does not contain comma.
+ *
+ * @param columnName Column-name. (NotNull)
+ * @exception IllegalArgumentException
+ */
+ protected void assertColumnName(String columnName) {
+ if (columnName == null) {
+ String msg = "The columnName should not be null.";
+ throw new IllegalArgumentException(msg);
+ }
+ if (columnName.trim().length() == 0) {
+ String msg = "The columnName should not be empty-string.";
+ throw new IllegalArgumentException(msg);
+ }
+ if (columnName.indexOf(",") >= 0) {
+ String msg = "The columnName should not contain comma ',': " + columnName;
+ throw new IllegalArgumentException(msg);
+ }
+ }
+
+ /**
+ * Assert that the alias-name is not null and is not emtpy and does not contain comma.
+ *
+ * @param aliasName Alias-name. (NotNull)
+ * @exception IllegalArgumentException
+ */
+ protected void assertAliasName(String aliasName) {
+ if (aliasName == null) {
+ String msg = "The aliasName should not be null.";
+ throw new IllegalArgumentException(msg);
+ }
+ if (aliasName.trim().length() == 0) {
+ String msg = "The aliasName should not be empty-string.";
+ throw new IllegalArgumentException(msg);
+ }
+ if (aliasName.indexOf(",") >= 0) {
+ String msg = "The aliasName should not contain comma ',': " + aliasName;
+ throw new IllegalArgumentException(msg);
+ }
+ }
+
+
+ // ----------------------------------------------------------------
+ // Assert String
+ // -------------
+ /**
+ * Assert that the entity is not null and not trimmed empty.
+ *
+ * @param variableName Variable name. (NotNull)
+ * @param value Value. (NotNull)
+ */
+ protected void assertStringNotNullAndNotTrimmedEmpty(String variableName, String value) {
+ assertObjectNotNull("variableName", variableName);
+ assertObjectNotNull("value", value);
+ if (value.trim().length() ==0) {
+ String msg = "The value should not be empty: variableName=" + variableName + " value=" + value;
+ throw new IllegalArgumentException(msg);
+ }
+ }
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/ConditionBean.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/ConditionBean.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/ConditionBean.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,165 @@
+package jp.sf.pal.pompei.allcommon.cbean;
+
+import jp.sf.pal.pompei.allcommon.cbean.sqlclause.SqlClause;
+
+/**
+ * The interface of condition-bean.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public interface ConditionBean extends PagingBean {
+
+ // =====================================================================================
+ // Definition
+ // ==========
+ /** Map-string map-mark. */
+ public static final String MAP_STRING_MAP_MARK = "map:";
+
+ /** Map-string list-mark. */
+ public static final String MAP_STRING_LIST_MARK = "list:";
+
+ /** Map-string start-brace. */
+ public static final String MAP_STRING_START_BRACE = "@{";
+
+ /** Map-string end-brace. */
+ public static final String MAP_STRING_END_BRACE = "@}";
+
+ /** Map-string delimiter. */
+ public static final String MAP_STRING_DELIMITER = "@;";
+
+ /** Map-string equal. */
+ public static final String MAP_STRING_EQUAL = "@=";
+
+ // =====================================================================================
+ // Table Name
+ // ==========
+ /**
+ * Get table db-name.
+ *
+ * @return Table db-name. (NotNull)
+ */
+ public String getTableDbName();
+
+ // =====================================================================================
+ // Sql-Clause
+ // ==========
+ /**
+ * Get sql-clause instance.
+ *
+ * @return Sql-clause. (NotNull)
+ */
+ public SqlClause getSqlClause();
+
+ // =====================================================================================
+ // Primary-Key
+ // ===========
+ /**
+ * Accept primary-key map-string.
+ *
+ * @param primaryKeyMap Primary-key map. (NotNull and NotEmpty)
+ */
+ public void acceptPrimaryKeyMap(java.util.Map primaryKeyMap);
+
+ /**
+ * Accept primary-key map-string. Delimiter is at-mark and semicolon.
+ *
+ * @param primaryKeyMapString Primary-key map. (NotNull and NotEmpty)
+ */
+ public void acceptPrimaryKeyMapString(String primaryKeyMapString);
+
+ // =====================================================================================
+ // Order-By
+ // ========
+ /**
+ * Add order-by PrimaryKey asc. {order by primaryKey1 asc, primaryKey2 asc...}
+ *
+ * @return this. (NotNull)
+ */
+ public ConditionBean addOrderBy_PK_Asc();
+
+ /**
+ * Add order-by PrimaryKey desc. {order by primaryKey1 desc, primaryKey2 desc...}
+ *
+ * @return this. (NotNull)
+ */
+ public ConditionBean addOrderBy_PK_Desc();
+
+ // =====================================================================================
+ // Query
+ // =====
+ /**
+ * Get condition-query as interface.
+ *
+ * @return Instance of query as interface. (NotNull)
+ */
+ public ConditionQuery getConditionQueryAsInterface();
+
+ // =====================================================================================
+ // Union-Query
+ // ===========
+ public boolean hasUnionQueryOrUnionAllQuery();
+
+ // =====================================================================================
+ // Limit-Select
+ // ============
+ /**
+ * Limit select PK only.
+ *
+ * @return this. (NotNull)
+ */
+ public ConditionBean limitSelect_PKOnly();
+
+ /**
+ * Limit select off.
+ *
+ * @return this. (NotNull)
+ */
+ public ConditionBean limitSelect_Off();
+
+ /**
+ * Is limit-select PK only?
+ *
+ * @return Determination.
+ */
+ public boolean isLimitSelect_PKOnly();
+
+ // =====================================================================================
+ // Advance
+ // =======
+ /**
+ * Lock for update.
+ *
+ * If you invoke this, your SQL lock target records for update.
+ * It depends whether this method supports this on the database type.
+ *
+ * @return this. (NotNull)
+ */
+ public ConditionBean lockForUpdate();
+
+ // ------------------------------
+ // for Internal
+ // ------------
+ /**
+ * Set up various things for select-count-ignore-fetch-scope. {Internal}
+ * This method is for INTERNAL. Don't invoke this!
+ *
+ * @return this. (NotNull)
+ */
+ public ConditionBean xsetupSelectCountIgnoreFetchScope();
+
+ /**
+ * Do after-care for select-count-ignore-fetch-scope. {Internal}
+ * This method is for INTERNAL. Don't invoke this!
+ *
+ * @return this. (NotNull)
+ */
+ public ConditionBean xafterCareSelectCountIgnoreFetchScope();
+
+ /**
+ * Is set up various things for select-count-ignore-fetch-scope? {Internal}
+ * This method is for INTERNAL. Don't invoke this!
+ *
+ * @return Determination.
+ */
+ public boolean isSelectCountIgnoreFetchScope();
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/ConditionBeanContext.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/ConditionBeanContext.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/ConditionBeanContext.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,195 @@
+package jp.sf.pal.pompei.allcommon.cbean;
+
+import jp.sf.pal.pompei.allcommon.cbean.sqlclause.*;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Condition-Bean context. (referring to s2pager)
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public class ConditionBeanContext {
+
+ /** Log-instance. */
+ private static final Log _log = LogFactory.getLog(ConditionBeanContext.class);
+
+ // =====================================================================================
+ // Thread Local
+ // ============
+ /** The thread-local for this. */
+ private static final ThreadLocal _threadLocal = new ThreadLocal();
+
+ /**
+ * Get condition-bean on thread.
+ *
+ * @return Condition-bean context. (Nullable)
+ */
+ public static ConditionBean getConditionBeanOnThread() {
+ return (ConditionBean)_threadLocal.get();
+ }
+
+ /**
+ * Set condition-bean on thread.
+ *
+ * @param cb Condition-bean. (NotNull)
+ */
+ public static void setConditionBeanOnThread(ConditionBean cb) {
+ if (cb == null) {
+ String msg = "The argument[cb] must not be null.";
+ throw new IllegalArgumentException(msg);
+ }
+ _threadLocal.set(cb);
+ }
+
+ /**
+ * Is existing condition-bean on thread?
+ *
+ * @return Determination.
+ */
+ public static boolean isExistConditionBeanOnThread() {
+ return (_threadLocal.get() != null);
+ }
+
+ /**
+ * Clear condition-bean on thread.
+ */
+ public static void clearConditionBeanOnThread() {
+ _threadLocal.set(null);
+ }
+
+ // =====================================================================================
+ // Initialize against LinkageError
+ // ===============================
+ public static void initialize() {
+ // Stop the LinkageError!
+ {
+ final Class clazz = jp.sf.pal.pompei.allcommon.cbean.SimplePagingBean.class;
+ _log.debug("Loading class of " + clazz.getName() + ": " + clazz.getClassLoader());
+ }
+ {
+ final Class clazz = jp.sf.pal.pompei.allcommon.cbean.coption.FromToOption.class;
+ _log.debug("Loading class of " + clazz.getName() + ": " + clazz.getClassLoader());
+ }
+ {
+ final Class clazz = jp.sf.pal.pompei.allcommon.cbean.coption.LikeSearchOption.class;
+ _log.debug("Loading class of " + clazz.getName() + ": " + clazz.getClassLoader());
+ }
+ {
+ final Class clazz = jp.sf.pal.pompei.allcommon.cbean.coption.InScopeOption.class;
+ _log.debug("Loading class of " + clazz.getName() + ": " + clazz.getClassLoader());
+ }
+ }
+
+ // =====================================================================================
+ // Type Judgement
+ // ==============
+ /**
+ * Is the argument condition-bean?
+ *
+ * @param dtoInstance Dto instance.
+ * @return Determination.
+ */
+ public static boolean isTheArgumentConditionBean(final Object dtoInstance) {
+ if (dtoInstance instanceof ConditionBean) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Is the type condition-bean?
+ *
+ * @param dtoClass DtoClass.
+ * @return Determination.
+ */
+ public static boolean isTheTypeConditionBean(final Class dtoClass) {
+ if (ConditionBean.class.isAssignableFrom(dtoClass)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ // =====================================================================================
+ // Product Name
+ // ============
+ /** The database product name. */
+ private static String _databaseProductName;
+
+ /**
+ * Get database product name.
+ *
+ * @return Database product name.
+ */
+ public static String getDatabaseProductName() {
+ return _databaseProductName;
+ }
+
+ /**
+ * Set database product name.
+ *
+ * @param name Database product name. (NotNull)
+ */
+ public static void setDatabaseProductName(String name) {
+ if (_databaseProductName != null) {
+ String msg = "Already set up: current=" + _databaseProductName + " your=" + name;
+ throw new IllegalStateException(msg);
+ }
+ _databaseProductName = name;
+ }
+
+ // =====================================================================================
+ // Column Alias
+ // ============
+ public static final java.util.Map> _selectClauseColumnAliasContainerMap = new java.util.HashMap>();
+
+ public static void addColumnAliasInfo(Class conditionBeanClass, String columnFullName, String columnAliasName) {
+ if (_selectClauseColumnAliasContainerMap.containsKey(conditionBeanClass)) {
+ final java.util.Map selectClauseColumnAliasMap = (java.util.Map)_selectClauseColumnAliasContainerMap.get(conditionBeanClass);
+ selectClauseColumnAliasMap.put(columnFullName, columnAliasName);
+ } else {
+ final java.util.Map selectClauseColumnAliasMap = new java.util.HashMap();
+ _selectClauseColumnAliasContainerMap.put(conditionBeanClass, selectClauseColumnAliasMap);
+ selectClauseColumnAliasMap.put(columnFullName, columnAliasName);
+ }
+ }
+
+ public static java.util.Map getSelectClauseColumnAliasMap(Class conditionBeanClass) {
+ return (java.util.Map)_selectClauseColumnAliasContainerMap.get(conditionBeanClass);
+ }
+
+ // =====================================================================================
+ // Creator
+ // =======
+ public static SqlClause createSqlClause(ConditionBean cb) {
+ final String tableDbName = cb.getTableDbName();
+ return createSqlClause(tableDbName);
+ }
+
+ public static SqlClause createSqlClause(String tableDbName) {
+ final String databaseProductName = getDatabaseProductName();
+ if (databaseProductName == null) {
+ return new SqlClauseDerby(tableDbName);
+ }
+ final String name = databaseProductName.toLowerCase();
+ if (name.startsWith("derby")) {
+ return new SqlClauseDerby(tableDbName);
+ } else if (name.startsWith("oracle")) {
+ return new SqlClauseOracle(tableDbName);
+ } else if (name.startsWith("firebird")) {
+ return new SqlClauseFirebird(tableDbName);
+ } else if (name.startsWith("mysql")) {
+ return new SqlClauseMySql(tableDbName);
+ } else if (name.startsWith("postgre")) {
+ return new SqlClausePostgreSql(tableDbName);
+ } else if (name.startsWith("mssql")) {
+ return new SqlClauseSqlServer(tableDbName);
+ } else if (name.startsWith("db2")) {
+ return new SqlClauseDb2(tableDbName);
+ } else {
+ return new SqlClauseDerby(tableDbName);
+ }
+ }
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/ConditionQuery.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/ConditionQuery.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/ConditionQuery.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,105 @@
+package jp.sf.pal.pompei.allcommon.cbean;
+
+import jp.sf.pal.pompei.allcommon.cbean.cvalue.ConditionValue;
+import jp.sf.pal.pompei.allcommon.cbean.sqlclause.SqlClause;
+
+/**
+ * The condition-query as interface.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public interface ConditionQuery {
+
+ // =====================================================================================
+ // Accessor
+ // ========
+ /**
+ * Get table db-name.
+ *
+ * @return Table db-name. (NotNull)
+ */
+ public String getTableDbName();
+
+ /**
+ * Get real alias name(that has nest level mark).
+ *
+ * @return Real alias name.
+ */
+ public String getRealAliasName();
+
+ /**
+ * Get real column name(with real alias name).
+ *
+ * @param columnName Column name without alias name.
+ * @return Real column name.
+ */
+ public String getRealColumnName(String columnName);
+
+ /**
+ * Get child query.
+ *
+ * @return Child query. (Nullable)
+ */
+ public ConditionQuery getChildQuery();
+
+ /**
+ * Get sql clause.
+ *
+ * @return Sql clause. (NotNull)
+ */
+ public SqlClause getSqlClause();
+
+ /**
+ * Get alias name.
+ *
+ * @return Alias name. (NotNull)
+ */
+ public String getAliasName();
+
+ /**
+ * Get nest level.
+ *
+ * @return Nest level.
+ */
+ public int getNestLevel();
+
+ /**
+ * Get next nest level.
+ *
+ * @return Next nest level.
+ */
+ public int getNextNestLevel();
+
+ /**
+ * Is base query?
+ *
+ * @param query Condition query. (NotNull)
+ * @return Determination.
+ */
+ public boolean isBaseQuery(ConditionQuery query);
+
+ // =====================================================================================
+ // Invoke
+ // ======
+ public ConditionValue invokeGetter(String columnMultiName);
+
+ public void invokeSetterEqual(String columnMultiName, Object value);
+ public void invokeSetterNotEqual(String columnMultiName, Object value);
+ public void invokeSetterGreaterThan(String columnMultiName, Object value);
+ public void invokeSetterLessThan(String columnMultiName, Object value);
+ public void invokeSetterGreaterEqual(String columnMultiName, Object value);
+ public void invokeSetterLessEqual(String columnMultiName, Object value);
+
+ public void invokeAddOrderByAsc(String columnMultiName);
+ public void invokeAddOrderByDesc(String columnMultiName);
+
+ // =====================================================================================
+ // Foregin-Query
+ // =============
+ ///
+ /// Get foreign condition-query.
+ ///
+ /// Foreign-property-name(Both OK - InitCap or not). (NotNull)
+ /// Foreign condition-query as interface.
+ public ConditionQuery getForeignConditionQuery(String foreignPropertyName);
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/FetchNarrowingBean.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/FetchNarrowingBean.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/FetchNarrowingBean.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,44 @@
+package jp.sf.pal.pompei.allcommon.cbean;
+
+/**
+ * The condition-bean as interface.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public interface FetchNarrowingBean {
+
+ /**
+ * Get fetch start index.
+ *
+ * @return Fetch start index.
+ */
+ public int getFetchNarrowingSkipStartIndex();
+
+ /**
+ * Get fetch size.
+ *
+ * @return Fetch size.
+ */
+ public int getFetchNarrowingLoopCount();
+
+ /**
+ * Is fetch start index supported?
+ *
+ * @return Determination.
+ */
+ public boolean isFetchNarrowingSkipStartIndexEffective();
+
+ /**
+ * Is fetch size supported?
+ *
+ * @return Determination.
+ */
+ public boolean isFetchNarrowingLoopCountEffective();
+
+ /**
+ * Is fetch-narrowing effective?
+ *
+ * @return Determiantion.
+ */
+ public boolean isFetchNarrowingEffective();
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/FetchNarrowingBeanContext.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/FetchNarrowingBeanContext.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/FetchNarrowingBeanContext.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,78 @@
+package jp.sf.pal.pompei.allcommon.cbean;
+
+/**
+ * Fetch-Narrowing-Bean context. (referring to s2pager)
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public class FetchNarrowingBeanContext {
+
+ /** The thread-local for this. */
+ private static ThreadLocal _threadLocal = new ThreadLocal();
+
+ /**
+ * Get fetch-narrowing-bean on thread.
+ *
+ * @return Condition-bean context. (Nullable)
+ */
+ public static FetchNarrowingBean getFetchNarrowingBeanOnThread() {
+ return (FetchNarrowingBean)_threadLocal.get();
+ }
+
+ /**
+ * Set fetch-narrowing-bean on thread.
+ *
+ * @param cb Condition-bean. (NotNull)
+ */
+ public static void setFetchNarrowingBeanOnThread(FetchNarrowingBean cb) {
+ if (cb == null) {
+ String msg = "The argument[cb] must not be null.";
+ throw new IllegalArgumentException(msg);
+ }
+ _threadLocal.set(cb);
+ }
+
+ /**
+ * Is existing fetch-narrowing-bean on thread?
+ *
+ * @return Determination.
+ */
+ public static boolean isExistFetchNarrowingBeanOnThread() {
+ return (_threadLocal.get() != null);
+ }
+
+ /**
+ * Clear fetch-narrowing-bean on thread.
+ */
+ public static void clearFetchNarrowingBeanOnThread() {
+ _threadLocal.set(null);
+ }
+
+ /**
+ * Is the argument fetch-narrowing-bean?
+ *
+ * @param dtoInstance Dto instance.
+ * @return Determination.
+ */
+ public static boolean isTheArgumentFetchNarrowingBean(final Object dtoInstance) {
+ if (dtoInstance instanceof FetchNarrowingBean) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Is the type fetch-narrowing-bean?
+ *
+ * @param dtoClass DtoClass.
+ * @return Determination.
+ */
+ public static boolean isTheTypeFetchNarrowingBean(final Class dtoClass) {
+ if (FetchNarrowingBean.class.isAssignableFrom(dtoClass)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/ListResultBean.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/ListResultBean.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/ListResultBean.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,318 @@
+package jp.sf.pal.pompei.allcommon.cbean;
+
+import jp.sf.pal.pompei.allcommon.cbean.mapping.EntityDtoMapper;
+import jp.sf.pal.pompei.allcommon.cbean.grouping.GroupingOption;
+import jp.sf.pal.pompei.allcommon.cbean.grouping.GroupingRowEndDeterminer;
+import jp.sf.pal.pompei.allcommon.cbean.grouping.GroupingRowResource;
+import jp.sf.pal.pompei.allcommon.cbean.grouping.GroupingRowSetupper;
+import jp.sf.pal.pompei.allcommon.cbean.sqlclause.OrderByClause;
+
+/**
+ * The list-result-bean for ListResultBean.
+ *
+ * @param The generic template for 'selectedList'.
+ * @author DBFlute(AutoGenerator)
+ */
+public class ListResultBean implements java.util.List, java.io.Serializable {
+
+ /** Serial version UID. (Default) */
+ private static final long serialVersionUID = 1L;
+
+ // =====================================================================================
+ // Attribute
+ // =========
+ /** The value of table db-name. */
+ protected String _tableDbName;
+
+ /** The value of all record count. */
+ protected int _allRecordCount;
+
+ /** Selected list. */
+ protected java.util.List _selectedList = new java.util.ArrayList();
+
+ /** Order-by clause. */
+ protected OrderByClause _orderByClause = new OrderByClause();
+
+ // =====================================================================================
+ // Constructor
+ // ===========
+ /**
+ * Constructor.
+ */
+ public ListResultBean() {
+ }
+
+ // =====================================================================================
+ // Getter Setter
+ // =============
+ /**
+ * Get the value of tableDbName.
+ *
+ * @return The value of tableDbName.
+ */
+ public String getTableDbName() {
+ return _tableDbName;
+ }
+
+ /**
+ * Set the value of tableDbName.
+ *
+ * @param tableDbName The value of tableDbName.
+ */
+ public void setTableDbName(String tableDbName) {
+ _tableDbName = tableDbName;
+ }
+
+ /**
+ * Get the value of allRecordCount.
+ *
+ * @return The value of allRecordCount.
+ */
+ public int getAllRecordCount() {
+ return _allRecordCount;
+ }
+
+ /**
+ * Set the value of allRecordCount.
+ *
+ * @param allRecordCount The value of allRecordCount.
+ */
+ public void setAllRecordCount(int allRecordCount) {
+ _allRecordCount = allRecordCount;
+ }
+
+ /**
+ * Get the value of selectedList.
+ *
+ * @return Selected list. (NotNull)
+ */
+ public java.util.List getSelectedList() {
+ return _selectedList;
+ }
+
+ /**
+ * Set the value of selectedList.
+ *
+ * @param selectedList Selected list. (NotNull)
+ */
+ public void setSelectedList(java.util.List selectedList) {
+ _selectedList = selectedList;
+ }
+
+ /**
+ * Get the value of orderByClause.
+ *
+ * @return The value of orderByClause. (NotNull)
+ */
+ public OrderByClause getOrderByClause() {
+ return _orderByClause;
+ }
+
+ /**
+ * Set the value of orderByClause.
+ *
+ * @param orderByClause The value of orderByClause. (NotNull)
+ */
+ public void setOrderByClause(OrderByClause orderByClause) {
+ _orderByClause = orderByClause;
+ }
+
+ // =====================================================================================
+ // Grouping
+ // ========
+ public java.util.List groupingList(GroupingRowSetupper groupingRowSetupper, GroupingOption groupingOption) {
+ final java.util.List groupingList = new java.util.ArrayList();
+ GroupingRowEndDeterminer rowEndDeterminer = groupingOption.getGroupingRowEndDeterminer();
+ if (rowEndDeterminer == null) {
+ rowEndDeterminer = new GroupingRowEndDeterminer() {
+ public boolean determine(int columnIndex, int columnCount, GroupingRowResource rowResource, ENTITY nextEntity) {
+ return columnIndex == (columnCount-1);
+ }
+ };// as Default
+ }
+ GroupingRowResource rowResource = new GroupingRowResource();
+ int columnCount = groupingOption.getColumnCount();
+ int columnIndex = 0;
+ int rowIndex = 0;
+ for (ENTITY entity : _selectedList) {
+ // Set up row resource.
+ rowResource.addGroupingRowList(entity);
+
+ if (_selectedList.size() == (rowIndex + 1)) {// Last Loop!
+ // Callback!
+ final ROW groupingRowObject = groupingRowSetupper.setup(rowResource);
+
+ // Register!
+ groupingList.add(groupingRowObject);
+ break;
+ }
+
+ ENTITY nextElement = null;
+ if (_selectedList.size() > (rowIndex + 1)) {;
+ nextElement = _selectedList.get(rowIndex);
+ }
+
+ // Do at row end.
+ if (rowEndDeterminer.determine(columnIndex, columnCount, rowResource, nextElement)) {
+ // Callback!
+ final ROW groupingRowObject = groupingRowSetupper.setup(rowResource);
+
+ // Register!
+ groupingList.add(groupingRowObject);
+
+ // Initialize!
+ rowResource = new GroupingRowResource();
+ columnIndex = 0;
+ ++rowIndex;
+ continue;
+ }
+ ++columnIndex;
+ ++rowIndex;
+ }
+ return groupingList;
+ }
+
+ // =====================================================================================
+ // Mapping
+ // =======
+ public ListResultBean mappingList(EntityDtoMapper entityDtoMapper) {
+ final ListResultBean mappingList = new ListResultBean();
+ for (ENTITY entity : _selectedList) {
+ mappingList.add(entityDtoMapper.map(entity));
+ }
+ mappingList.setTableDbName(getTableDbName());
+ mappingList.setAllRecordCount(getAllRecordCount());
+ mappingList.setOrderByClause(getOrderByClause());
+ return mappingList;
+ }
+
+ // =====================================================================================
+ // Determination
+ // =============
+ /**
+ * Has this result selected?
+ *
+ * If isSetterInvokedSelectedList is true, returns true.
+ *
+ *
+ * @return Determination.
+ */
+ public boolean isSelectedResult() {
+ return _tableDbName != null;
+ }
+
+ // =====================================================================================
+ // Basic Override
+ // ==============
+ /**
+ * This method overrides the method that is declared at super.
+ *
+ * @return View-string of all-columns value.
+ */
+ public String toString() {
+ final StringBuffer sb = new StringBuffer();
+
+ sb.append(" tableDbName=").append(_tableDbName);
+ sb.append(" allRecordCount=").append(_tableDbName);
+ sb.append(" selectedList.size()=").append(_selectedList.size());
+ sb.append(" orderByClause=").append(_orderByClause);
+
+ return sb.toString();
+ }
+
+ // =====================================================================================
+ // List Elements
+ // =============
+ public boolean add(ENTITY o) {
+ return _selectedList.add(o);
+ }
+
+ public boolean addAll(java.util.Collection extends ENTITY> c) {
+ return _selectedList.addAll(c);
+ }
+
+ public void clear() {
+ _selectedList.clear();
+ }
+
+ public boolean contains(Object o) {
+ return _selectedList.contains(o);
+ }
+
+ public boolean containsAll(java.util.Collection> c) {
+ return _selectedList.containsAll(c);
+ }
+
+ public boolean isEmpty() {
+ return _selectedList.isEmpty();
+ }
+
+ public java.util.Iterator iterator() {
+ return _selectedList.iterator();
+ }
+
+ public boolean remove(Object o) {
+ return _selectedList.remove(o);
+ }
+
+ public boolean removeAll(java.util.Collection> c) {
+ return _selectedList.removeAll(c);
+ }
+
+ public boolean retainAll(java.util.Collection> c) {
+ return _selectedList.retainAll(c);
+ }
+
+ public int size() {
+ return _selectedList.size();
+ }
+
+ public Object[] toArray() {
+ return _selectedList.toArray();
+ }
+
+ public TYPE[] toArray(TYPE[] a) {
+ return _selectedList.toArray(a);
+ }
+
+ public void add(int index, ENTITY element) {
+ _selectedList.add(index, element);
+ }
+
+ public boolean addAll(int index, java.util.Collection extends ENTITY> c) {
+ return _selectedList.addAll(index, c);
+ }
+
+ public ENTITY get(int index) {
+ return _selectedList.get(index);
+ }
+
+ public int indexOf(Object o) {
+ return _selectedList.indexOf(o);
+ }
+
+ public int lastIndexOf(Object o) {
+ return _selectedList.lastIndexOf(o);
+ }
+
+ public java.util.ListIterator listIterator() {
+ return _selectedList.listIterator();
+ }
+
+ public java.util.ListIterator listIterator(int index) {
+ return _selectedList.listIterator(index);
+ }
+
+ public ENTITY remove(int index) {
+ return _selectedList.remove(index);
+ }
+
+ public ENTITY set(int index, ENTITY element) {
+ return _selectedList.set(index, element);
+ }
+
+ public java.util.List subList(int fromIndex, int toIndex) {
+ return _selectedList.subList(fromIndex, toIndex);
+ }
+
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/OrderByBean.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/OrderByBean.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/OrderByBean.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,78 @@
+package jp.sf.pal.pompei.allcommon.cbean;
+
+import jp.sf.pal.pompei.allcommon.cbean.sqlclause.OrderByClause;
+
+/**
+ * The order-by-bean as interface.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public interface OrderByBean extends SelectResource {
+
+ /**
+ * Get sql component of order-by clause.
+ *
+ * @return Sql component of order-by clause. (NotNull)
+ */
+ public OrderByClause getSqlComponentOfOrderByClause();
+
+ /**
+ * Get order-by clause.
+ *
+ * @return Order-by clause. (NotNull)
+ */
+ public String getOrderByClause();
+
+ /**
+ * Clear order-by.
+ *
+ * @return this. (NotNull)
+ */
+ public OrderByBean clearOrderBy();
+
+ /**
+ * Ignore order-by.
+ *
+ * @return this. (NotNull)
+ */
+ public OrderByBean ignoreOrderBy();
+
+ /**
+ * Make order-by effective.
+ *
+ * @return this. (NotNull)
+ */
+ public OrderByBean makeOrderByEffective();
+
+ /**
+ * Register order-by-asc.
+ *
+ * @param orderByProperty Order-by-property. 'aliasName.columnName/aliasName.columnName/...' (NotNull)
+ * @return this. (NotNull)
+ */
+ public OrderByBean registerOrderByAsc(String orderByProperty);
+
+ /**
+ * Register order-by-desc.
+ *
+ * @param orderByProperty Order-by-property. 'aliasName.columnName/aliasName.columnName/...' (NotNull)
+ * @return this. (NotNull)
+ */
+ public OrderByBean registerOrderByDesc(String orderByProperty);
+
+ /**
+ * Reverse order-by or Override order-by asc.
+ *
+ * @param orderByProperty Order-by-property. 'aliasName.columnName/aliasName.columnName/...' (NotNull)
+ * @return this. (NotNull)
+ */
+ public OrderByBean reverseOrderBy_Or_OverrideOrderByAsc(String orderByProperty);
+
+ /**
+ * Reverse order-by or Override order-by desc.
+ *
+ * @param orderByProperty Order-by-property. 'aliasName.columnName/aliasName.columnName/...' (NotNull)
+ * @return this. (NotNull)
+ */
+ public OrderByBean reverseOrderBy_Or_OverrideOrderByDesc(String orderByProperty);
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/PagingBean.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/PagingBean.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/PagingBean.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,108 @@
+package jp.sf.pal.pompei.allcommon.cbean;
+
+/**
+ * The interface of paging-bean.
+ *
+ * @author DBFlute(AutoGenerator)
+ */
+public interface PagingBean extends FetchNarrowingBean, OrderByBean {
+
+ /**
+ * Fetch first.
+ *
+ * If you invoke this, your SQL returns [fetch-size] records from first.
+ *
+ * @param fetchSize Fetch-size. (NotMinus & NotZero)
+ * @return this. (NotNUll)
+ */
+ public PagingBean fetchFirst(int fetchSize);
+
+ /**
+ * Fetch scope.
+ *
+ * If you invoke this, your SQL returns [fetch-size] records from [fetch-start-index].
+ *
+ * @param fetchStartIndex Fetch-start-index. 0 origin. (NotMinus)
+ * @param fetchSize Fetch-size. (NotMinus & NotZero)
+ * @return this. (NotNUll)
+ */
+ public PagingBean fetchScope(int fetchStartIndex, int fetchSize);
+
+ /**
+ * Fetch page.
+ *
+ * When you invoke this, it is normally necessary to invoke 'fetchFirst()' or 'fetchScope()' ahead of that.
+ * But you also can use default-fetch-size without invoking 'fetchFirst()' or 'fetchScope()'.
+ * If you invoke this, your SQL returns [fetch-size] records from [fetch-start-index] calculated by [fetch-page-number].
+ *
+ * @param fetchPageNumber Fetch-page-number. 1 origin. (NotMinus & NotZero)
+ * @return this. (NotNull)
+ */
+ public PagingBean fetchPage(int fetchPageNumber);
+
+ /**
+ * Get fetch-start-index.
+ *
+ * @return Fetch-start-index.
+ */
+ public int getFetchStartIndex();
+
+ /**
+ * Get fetch-size.
+ *
+ * @return Fetch-size.
+ */
+ public int getFetchSize();
+
+ /**
+ * Get fetch-page-number.
+ *
+ * @return Fetch-page-number.
+ */
+ public int getFetchPageNumber();
+
+ /**
+ * Get page start index.
+ *
+ * @return Page start index. 0 origin. (NotMinus)
+ */
+ public int getPageStartIndex();
+
+ /**
+ * Get page end index.
+ *
+ * @return Page end index. 0 origin. (NotMinus)
+ */
+ public int getPageEndIndex();
+
+ /**
+ * Is fetch scope effective?
+ *
+ * @return Determiantion.
+ */
+ public boolean isFetchScopeEffective();
+
+ // =====================================================================================
+ // For SqlComment
+ // ==============
+ /**
+ * Get select-hint. {select [select-hint] * from table...}
+ *
+ * @return Select-hint. (NotNull)
+ */
+ public String getSelectHint();
+
+ /**
+ * Get from-hint. {select * from table [from-hint] where ...}
+ *
+ * @return From-hint. (NotNull)
+ */
+ public String getFromHint();
+
+ /**
+ * Get sql-suffix. {select * from table where ... order by ... [sql-suffix]}
+ *
+ * @return Sql-suffix. (NotNull)
+ */
+ public String getSqlSuffix();
+}
Added: pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/PagingResultBean.java
===================================================================
--- pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/PagingResultBean.java 2007-07-10 08:51:31 UTC (rev 213)
+++ pompei/trunk/src/main/java/jp/sf/pal/pompei/allcommon/cbean/PagingResultBean.java 2007-07-10 09:09:05 UTC (rev 214)
@@ -0,0 +1,521 @@
+package jp.sf.pal.pompei.allcommon.cbean;
+
+import jp.sf.pal.pompei.allcommon.cbean.mapping.EntityDtoMapper;
+/**
+ * The paging-result-bean for PagingResultBean.
+ *
+ * @param The generic template for 'selectedList'.
+ * @author DBFlute(AutoGenerator)
+ */
+public class PagingResultBean extends ListResultBean {
+
+ /** Serial version UID. (Default) */
+ private static final long serialVersionUID = 1L;
+
+ // =====================================================================================
+ // Attribute
+ // =========
+ /** The value of current page number. */
+ protected int _pageSize;
+
+ /** The value of current page number. */
+ protected int _currentPageNumber;
+
+ // -----------------------------------------
+ // Page Range
+ // ----------
+ /** The value of page-range option. */
+ protected PageRangeOption _pageRangeOption;
+
+ // -----------------------------------------
+ // Page Group
+ // ----------
+ /** The value of page-group option. */
+ protected PageGroupOption _pageGroupOption;
+
+ // =====================================================================================
+ // Constructor
+ // ===========
+ /**
+ * Constructor.
+ */
+ public PagingResultBean() {
+ }
+
+ // =====================================================================================
+ // Accessor
+ // ========
+ /**
+ * Get the value of pageSize.
+ *
+ * @return The value of pageSize.
+ */
+ public int getPageSize() {
+ return _pageSize;
+ }
+
+ /**
+ * Set the value of pageSize.
+ *
+ * @param pageSize The value of pageSize.
+ */
+ public void setPageSize(int pageSize) {
+ _pageSize = pageSize;
+ }
+
+ /**
+ * Get the value of currentPageNumber.
+ *
+ * @return The value of currentPageNumber.
+ */
+ public int getCurrentPageNumber() {
+ return _currentPageNumber;
+ }
+
+ /**
+ * Set the value of currentPageNumber.
+ *
+ * @param currentPageNumber The value of currentPageNumber.
+ */
+ public void setCurrentPageNumber(int currentPageNumber) {
+ _currentPageNumber = currentPageNumber;
+ }
+
+ /**
+ * Get the value of allPageCount.
+ *
+ * @return The value of allPageCount.
+ */
+ public int getAllPageCount() {
+ return calculateAllPageCount(_allRecordCount, _pageSize);
+ }
+
+ /**
+ * Get the value of currentStartRecordNumber.
+ *
+ * @return The value of currentStartRecordNumber.
+ */
+ public int getCurrentStartRecordNumber() {
+ return calculateCurrentStartRecordNumber(_currentPageNumber, _pageSize);
+ }
+
+ /**
+ * Get the value of currentEndRecordNumber.
+ *
+ * @return The value of currentEndRecordNumber.
+ */
+ public int getCurrentEndRecordNumber() {
+ return calculateCurrentEndRecordNumber(_currentPageNumber, _pageSize);
+ }
+
+ // -----------------------------------------
+ // Page Range
+ // ----------
+ /**
+ * Get the value of pageRangeSize.
+ *
+ * @return The value of pageRangeSize.
+ */
+ public int getPageRangeSize() {
+ return _pageRangeOption != null ? _pageRangeOption.getPageRangeSize() : 0;
+ }
+
+ /**
+ * Set the value of pageRangeSize.
+ *
+ * @param pageRangeSize The value of pageRangeSize.
+ */
+ public void setPageRangeSize(int pageRangeSize) {
+ final PageRangeOption option = new PageRangeOption();
+ option.setPageRangeSize(pageRangeSize);
+ setPageRangeOption(option);
+ }
+
+ /**
+ * Set the value of pageRangeOption.
+ *
+ * @param pageRangeOption The value of pageRangeOption.
+ */
+ public void setPageRangeOption(PageRangeOption pageRangeOption) {
+ _pageRangeOption = pageRangeOption;
+ }
+
+ public static class PageRangeOption {
+ protected int _pageRangeSize;
+
+ protected boolean _fillLimit;
+
+ public int getPageRangeSize() {
+ return _pageRangeSize;
+ }
+
+ public void setPageRangeSize(int pageRangeSize) {
+ _pageRangeSize = pageRangeSize;
+ }
+
+ public boolean isFillLimit() {
+ return _fillLimit;
+ }
+
+ public void setFillLimit(boolean fillLimit) {
+ _fillLimit = fillLimit;
+ }
+ }
+
+ // -----------------------------------------
+ // Page Group
+ // ----------
+ /**
+ * Get the value of pageGroupSize.
+ *
+ * @return The value of pageGroupSize.
+ */
+ public int getPageGroupSize() {
+ return _pageGroupOption != null ? _pageGroupOption.getPageGroupSize() : 0;
+ }
+
+ /**
+ * Set the value of pageGroupSize.
+ *
+ * @param value The value of pageGroupSize.
+ */
+ public void setPageGroupSize(int pageGroupSize) {
+ final PageGroupOption option = new PageGroupOption();
+ option.setPageGroupSize(pageGroupSize);
+ setPageGroupOption(option);
+ }
+
+ /**
+ * Set the value of pageGroupOption.
+ *
+ * @param pageGroupOption The value of pageGroupOption.
+ */
+ public void setPageGroupOption(PageGroupOption pageGroupOption) {
+ _pageGroupOption = pageGroupOption;
+ }
+
+ public static class PageGroupOption {
+ protected int _pageGroupSize;
+
+ public int getPageGroupSize() {
+ return _pageGroupSize;
+ }
+
+ public void setPageGroupSize(int pageGroupSize) {
+ _pageGroupSize = pageGroupSize;
+ }
+ }
+
+ // =====================================================================================
+ // Mapping
+ // =======
+ public PagingResultBean mappingList(EntityDtoMapper entityDtoMapper) {
+ final ListResultBean ls = super.mappingList(entityDtoMapper);
+ final PagingResultBean mappingList = new PagingResultBean();
+ mappingList.setSelectedList(ls.getSelectedList());
+ mappingList.setTableDbName(getTableDbName());
+ mappingList.setAllRecordCount(getAllRecordCount());
+ mappingList.setOrderByClause(getOrderByClause());
+ mappingList.setPageSize(getPageSize());
+ mappingList.setCurrentPageNumber(getCurrentPageNumber());
+ mappingList.setPageRangeOption(_pageRangeOption);
+ mappingList.setPageGroupOption(_pageGroupOption);
+ return mappingList;
+ }
+
+ // =====================================================================================
+ // Calculate
+ // =========
+ // -------------------------------------------
+ // Page
+ // ----
+ /**
+ * Calculate all page count.
+ *
+ * @param allRecordCount All record count.
+ * @param pageSize Fetch-size.
+ * @return All page count.
+ */
+ protected int calculateAllPageCount(int allRecordCount, int pageSize) {
+ if (allRecordCount == 0) {
+ return 1;
+ }
+ int pageCountBase = (allRecordCount / pageSize);
+ if (allRecordCount % pageSize > 0) {
+ pageCountBase++;
+ }
+ return pageCountBase;
+ }
+
+ protected int calculateCurrentStartRecordNumber(int currentPageNumber, int pageSize) {
+ return ((currentPageNumber - 1) * pageSize) + 1;
+ }
+
+ protected int calculateCurrentEndRecordNumber(int currentPageNumber, int pageSize) {
+ return calculateCurrentStartRecordNumber(currentPageNumber, pageSize) + _selectedList.size() - 1;
+ }
+
+ /**
+ * Is existing previous page?
+ * Using values are currentPageNumber.
+ *
+ * @return Determination.
+ */
+ public boolean isExistPrePage() {
+ return (_allRecordCount > 0 && _currentPageNumber > 1);
+ }
+
+ /**
+ * Is existing next page?
+ * Using values are currentPageNumber and allPageCount.
+ *
+ * @return Determination.
+ */
+ public boolean isExistNextPage() {
+ return (_allRecordCount > 0 && _currentPageNumber < getAllPageCount());
+ }
+
+ // -------------------------------------------
+ // Page Range
+ // ----------
+ /**
+ * Get current page-range page-number-list.
+ * Using values are pageRangeOption and currentPageNumber and allPageCount.
+ *
+ * @return Current page-range page-number-list. (NotNull)
+ */
+ public java.util.List getCurrentPageRangePageNumberList() {
+ assertPageRangeValid();
+ final int pageRangeSize = _pageRangeOption.getPageRangeSize();
+ final int allPageCount = this.getAllPageCount();
+ final int currentPageNumber = _currentPageNumber;
+
+ final java.util.List resultList = new java.util.ArrayList();
+ for (int i = currentPageNumber - pageRangeSize; i < currentPageNumber; i++) {
+ if (i < 1) {
+ continue;
+ }
+ resultList.add(new Integer(i));
+ }
+
+ resultList.add(new Integer(currentPageNumber));
+
+ final int endPageNumber = (currentPageNumber + pageRangeSize);
+ for (int i = currentPageNumber + 1 ; i <= endPageNumber && i <= allPageCount; i++) {
+ resultList.add(new Integer(i));
+ }
+
+ final boolean fillLimit = _pageRangeOption.isFillLimit();
+ final int limitSize = (pageRangeSize * 2) + 1;
+ if (fillLimit && !resultList.isEmpty() && resultList.size() < limitSize) {
+ final Integer firstElements = (Integer)resultList.get(0);
+ final Integer lastElements = (Integer)resultList.get(resultList.size() - 1);
+ if (firstElements.intValue() > 1) {
+ for (int i = firstElements.intValue() - 1 ; resultList.size() < limitSize && i > 0; i--) {
+ resultList.add(0, new Integer(i));
+ }
+ }
+ for (int i = lastElements.intValue() + 1 ; resultList.size() < limitSize && i <= allPageCount; i++) {
+ resultList.add(new Integer(i));
+ }
+ }
+ return resultList;
+ }
+
+ /**
+ * Get current page-range page-number-array.
+ * Using values are pageRangeOption and currentPageNumber and allPageCount.
+ *
+ * @return Current page-range page-number-array.
+ */
+ public int[] getCurrentPageRangePageNumberArray() {
+ assertPageRangeValid();
+ return convertListToIntArray(getCurrentPageRangePageNumberList());
+ }
+
+ protected int[] convertListToIntArray(java.util.List