[cvs]
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj
DBObjectDef.java
JCorporate Ltd
jcorp at jcorp2.servlets.net
Mon Sep 20 13:13:45 PDT 2004
Update of /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj
In directory jcorp2.servlets.net:/tmp/cvs-serv5387
Modified Files:
DBObjectDef.java
Log Message:
<Aucun commentaire entré>
Index: DBObjectDef.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/DBObjectDef.java,v
retrieving revision 1.43
retrieving revision 1.44
diff -C2 -d -r1.43 -r1.44
*** DBObjectDef.java 20 Sep 2004 19:20:15 -0000 1.43
--- DBObjectDef.java 20 Sep 2004 20:13:43 -0000 1.44
***************
*** 71,74 ****
--- 71,75 ----
import com.jcorporate.expresso.core.dataobjects.DataFieldMetaData;
import com.jcorporate.expresso.core.dataobjects.jdbc.JDBCObjectMetaData;
+ import com.jcorporate.expresso.core.db.config.JDBCConfig;
import com.jcorporate.expresso.core.db.DBException;
import com.jcorporate.expresso.core.i18n.Messages;
***************
*** 76,79 ****
--- 77,81 ----
import com.jcorporate.expresso.core.misc.StringUtil;
import com.jcorporate.expresso.core.security.filters.FilterManager;
+ import com.jcorporate.expresso.core.misc.ConfigurationException;
import org.apache.log4j.Logger;
import org.apache.oro.text.regex.MalformedPatternException;
***************
*** 111,114 ****
--- 113,120 ----
private static final String OBJECT_NAME_NOT_ASSIGNED = "NOT ASSIGNED";
+ private static final String TABLE_OBJECT_TYPE = "TABLE";
+
+ private static final String STORE_PROCEDURE_OBJECT_TYPE = "SPL";
+
/* the log */
transient private static Logger log = Logger.getLogger(DBObjectDef.class);
***************
*** 141,144 ****
--- 147,160 ----
private String objectDescription = "";
+ /** Vector containing the field names in the order they were added for
+ * INPUT and OUTPUT parameters for store procedure
+ * @author Yves Henri AMAIZO
+ */
+ private Map allInParameters = new ConcurrentReaderHashMap();
+ private ArrayList inParamList = new ArrayList();
+ private Map allOutParameters = new ConcurrentReaderHashMap();
+ private ArrayList outParamList = new ArrayList();
+
+
/**
* The detailObjsLocal local and detailObjsForeign hashtables holds one or more references to other
***************
*** 168,171 ****
--- 184,211 ----
private String tableName = "";
+ /**
+ * Store Procedure name of the "primary" table that this DB object refers to
+ */
+ private String storeProcedureName = ("");
+
+ /**
+ * Store Procedure name of the "primary" table that this DB object refers to
+ */
+ private String objectType = "NONE";
+
+ private boolean returningValue = false;
+
+
+ /**
+ * Database schema name of the "primary" table that this DB object refers to
+ */
+ private String dbSchemaName = ("");
+
+ /**
+ * Database catalogue name of the "primary" table that this DB object refers to
+ */
+ private String dbCatalogName = ("");
+
+
/**
* A default characterset to filter on.
***************
*** 234,237 ****
--- 274,291 ----
fieldPrecision, allowNull, fieldDescription));
+ /**
+ * If we're dealing with integer datatypes, lets be helpful and make sure
+ * that the field is a valid integer format. Add the mask automatically
+ */
+ if (fieldType.equalsIgnoreCase(DBField.INTEGER_TYPE) ||
+ fieldType.equalsIgnoreCase(DBField.INT_TYPE)) {
+
+ setMask(fieldName, DBObject.INT_MASK);
+ setAttribute(fieldName, DBObject.ATTRIBUTE_ERROR_MESSAGE,
+ "You must enter a valid integer for field: "
+ + fieldDescription);
+ }
+
+
fieldNamesInOrder.add(fieldName);
} /* addField(String, String, int, int, boolean, String) */
***************
*** 357,360 ****
--- 411,429 ----
fieldNamesInOrder.add(fieldName);
+
+
+ /**
+ * If we're dealing with integer datatypes, lets be helpful and make sure
+ * that the field is a valid integer format. Add the mask automatically
+ */
+ if (fieldType.equalsIgnoreCase(DBField.INTEGER_TYPE) ||
+ fieldType.equalsIgnoreCase(DBField.INT_TYPE)) {
+
+ setMask(fieldName, DBObject.INT_MASK);
+ setAttribute(fieldName, DBObject.ATTRIBUTE_ERROR_MESSAGE,
+ "You must enter a valid integer for field: "
+ + fieldDescription);
+ }
+
} /* addField(String, String, int, boolean, String) */
***************
*** 1146,1149 ****
--- 1215,1241 ----
} /* getTargetTable() */
+ /**
+ * Return the Schema Name of the current database object.
+ *
+ * @return String: Schema name of the target table of this database object
+ * @throws DataException upon error
+ *
+ * author Yves Henri AMAIZO <amy_amaizo at compuserve.com>
+ */
+ public String getTargetDbSchema() {
+ return dbSchemaName;
+ } /* getTargetDbSchema() */
+
+ /**
+ * Return the Schema Name of the current database object.
+ *
+ * @return String: Schema name of the target table of this database object
+ * @throws DataException upon error
+ *
+ * author Yves Henri AMAIZO <amy_amaizo at compuserve.com>
+ */
+ public String getTargetDbCatalog() {
+ return dbCatalogName;
+ }
/**
***************
*** 1443,1449 ****
--- 1535,1591 ----
tableName = theTable;
+ objectType = TABLE_OBJECT_TYPE;
} /* setTargetTable(String) */
+ /**
+ * Set the target database schema for this DBObject.
+ *
+ * @param theSchema database schema for this object
+ * @throws DBException
+ *
+ * author Yves Henri AMAIZO <amy_amaizo at compuserve.com>
+ */
+ synchronized public void setTargetDbSchema(String theSchema)
+ throws DBException {
+ if (theSchema.length() > 18) {
+ log.warn("Schema name is over 18 characters");
+ }
+ if (ConfigManager.isReservedWord(theSchema)) {
+ throw new DBException("You cannot have a Schema name of " +
+ theSchema +
+ ". It is a database reserved word. Check " +
+ "com.jcorporate.expresso.core.misc.ReservedWords for a full list" +
+ " of reservered words");
+ }
+
+ dbSchemaName = theSchema;
+ } /* setTargetSchema(String) */
+
+ /**
+ * Set the target database schema for this DBObject.
+ *
+ * @param theSchema database schema for this object
+ * @throws DBException
+ *
+ * author Yves Henri AMAIZO <amy_amaizo at compuserve.com>
+ */
+ synchronized public void setTargetDbCatalog(String theCatalog)
+ throws DBException {
+ if (theCatalog.length() > 18) {
+ log.warn("Schema name is over 18 characters");
+ }
+ if (ConfigManager.isReservedWord(theCatalog)) {
+ throw new DBException("You cannot have a Catalog name of " +
+ theCatalog +
+ ". It is a database reserved word. Check " +
+ "com.jcorporate.expresso.core.misc.ReservedWords for a full list" +
+ " of reservered words");
+ }
+
+ dbCatalogName = theCatalog;
+ } /* setTargetDbCatalog(String) */
+
+
/**
*
***************
*** 1551,1554 ****
--- 1693,1952 ----
return oneField.getAllAttributes();
}
+
+
+ /**
+ * Return the Store procedure Name of the current database object. Keep in mind
+ * that a database object could update or affect other tables as well.
+ *
+ * @return String: Store procedure name of the target table of this database object
+ * @throws DataException upon error
+ *
+ * @author Yves Henri AMAIZO
+ * @version $Revision$ on $Date$
+ */
+ public String getTargetStoreProcedure()
+ throws DataException {
+ if (storeProcedureName == null) {
+ throw new DataException("No store procedure name supplied");
+ }
+
+ return storeProcedureName;
+ } /* getTargetTable() */
+
+
+ /**
+ * Set the target store procedure for this DBObject.
+ *
+ * @param theStoreProcedure Store procedure for this object
+ * @throws DBException
+ *
+ * @author Yves Henri AMAIZO
+ * @version $Revision$ on $Date$
+ */
+ synchronized public void setTargetStoreProcedure(String theStoreProcedure)
+ throws DBException {
+ if (theStoreProcedure.length() > 18) {
+ log.warn("Strore procedure name is over 18 characters");
+ }
+ if (ConfigManager.isReservedWord(theStoreProcedure)) {
+ throw new DBException("You cannot have a store procedure name of " +
+ theStoreProcedure +
+ ". It is a database reserved word. Check " +
+ "com.jcorporate.expresso.core.misc.ReservedWords for a full list" +
+ " of reservered words");
+ }
+
+ storeProcedureName = theStoreProcedure;
+ tableName = theStoreProcedure;
+ objectType = STORE_PROCEDURE_OBJECT_TYPE;
+ } /* setTargetStoreProcedure(String) */
+
+
+ /**
+ * Add a new field to the list of fields that are part of this
+ * object's list of input parameters. Called after all of the "addField" calls in the setupFields()
+ * method to specify which fields make up the parameter fields of this object.
+ *
+ * @param inFieldName The name of the field to add as part of the input parameter
+ * @throws DBException if the field name is not valid or the field
+ * allows nulls
+ *
+ * @author Yves Henri AMAIZO
+ * @version $Revision$ on $Date$
+ */
+ synchronized public void addInParam(String inFieldName)
+ throws DBException {
+ DBField oneField = (DBField) allFields.get(inFieldName);
+
+ if (oneField == null) {
+ throw new DBException("(" + getName() + ") Field " + inFieldName +
+ " is not defined as a field in this DBObject - cannot add " +
+ "to input list parameter");
+ }
+ if (oneField.allowsNull()) {
+ throw new DBException("(" + getName() + ") Field " + inFieldName +
+ " allows null - not suitable for inclusion " +
+ "in key");
+ }
+ if (oneField.isVirtual()) {
+ throw new DBException("(" + getName() + ") Field " + inFieldName +
+ " is a virtual field - not suitable for " +
+ "inclusion in input list parameter");
+ }
+
+ if (oneField.isLongObjectType()) {
+ throw new DBException("(" + getName() + ") Field " + inFieldName +
+ " allows arbitrarily long length, either text or binary - not suitable for inclusion " +
+ "in the input list parameter");
+ }
+
+ allInParameters.put(inFieldName, oneField);
+
+ /* We must keep keys in order, so we add to keyList as well */
+ inParamList.add(inFieldName);
+ } /* addInParam(String) */
+
+
+ /**
+ * Add a new field to the list of fields that are part of this
+ * object's list of output parameter. Called after all of the "addField" calls in the setupFields()
+ * method to specify which fields make up the parameter fields of this object.
+ *
+ * @param outFieldName The name of the field to add as part of the output parameter
+ * @throws DBException if the field name is not valid or the field
+ * allows nulls
+ *
+ * @author Yves Henri AMAIZO
+ * @version $Revision$ on $Date$
+ */
+ synchronized public void addOutParam(String outFieldName)
+ throws DBException {
+ DBField oneField = (DBField) allFields.get(outFieldName);
+
+ if (oneField == null) {
+ throw new DBException("(" + getName() + ") Field " + outFieldName +
+ " is not defined as a field in this DBObject - cannot add " +
+ "to the output list parameter");
+ }
+ if (oneField.allowsNull()) {
+ throw new DBException("(" + getName() + ") Field " + outFieldName +
+ " allows null - not suitable for inclusion " +
+ "in the output list parameter");
+ }
+ if (oneField.isVirtual()) {
+ throw new DBException("(" + getName() + ") Field " + outFieldName +
+ " is a virtual field - not suitable for " +
+ "inclusion in the output list parameter");
+ }
+
+ if (oneField.isLongObjectType()) {
+ throw new DBException("(" + getName() + ") Field " + outFieldName +
+ " allows arbitrarily long length, either text or binary - not suitable for inclusion " +
+ "in the output list parameter");
+ }
+
+ allOutParameters.put(outFieldName, oneField);
+
+ /* We must keep keys in order, so we add to keyList as well */
+ outParamList.add(outFieldName);
+ } /* addOutParam(String) */
+
+
+ public boolean isReturningValue() {
+ return returningValue;
+ }
+
+ /**
+ *
+ * @param value returning value to be set
+ *
+ * @author Yves Henri AMAIZO
+ * @version $Revision$ on $Date$
+ */
+ public void setReturningValue(boolean value) {
+ returningValue = value;
+ }
+
+ /**
+ * Check if a certain name is a INPUT field parameter(of any kind) in this DBOBject
+ * @param fieldName the name of the field to check
+ * @return true if the field name exists
+ */
+ public boolean isOutField(String fieldName) {
+ return allOutParameters.get(fieldName) != null;
+ }
+
+ /**
+ * Check if a certain name is a OUTPUT field parameter(of any kind) in this DBOBject
+ * @param fieldName the name of the field to check
+ * @return true if the field name exists
+ */
+ public boolean isInField(String fieldName) {
+ return allInParameters.get(fieldName) != null;
+ }
+
+ /**
+ * Return the Table Name of the current database object. Keep in mind
+ * that a database object could update or affect other tables as well.
+ *
+ * @return String: Table name of the target table of this database object
+ * @throws DataException upon error
+ *
+ * author Yves Henri AMAIZO <amy_amaizo at compuserve.com>
+ */
+ public String getTargetSQLTable(String dataContext)
+ throws DataException {
+ String sqlTableName = getTargetTable();
+ try {
+ if (getTargetDbSchema() != null && !"".equals(getTargetDbSchema())) {
+ sqlTableName = getTargetDbSchema() + "." + getTargetTable();
+ } else {
+ JDBCConfig myConfig = ConfigManager.getJdbcRequired(dataContext);
+ if (myConfig.getDbSchema() != null && !"".equals(myConfig.getDbSchema())) {
+ sqlTableName = myConfig.getDbSchema() + "." + getTargetTable();
+ }
+ }
+ } catch (ConfigurationException ce) {
+ throw new DataException(ce);
+ }
+ return sqlTableName;
+ } /* getTargetSQLTable() */
+
+
+ /**
+ * Get a list of all of the names of the IN param fields in this object
+ *
+ * @return An ArrayList of all of the names of the IN param fields
+ */
+ public ArrayList getInParamListArray() {
+ return inParamList;
+ }
+
+ /**
+ * Get a list of all of the names of the OUT param fields in this object
+ *
+ * @return An ArrayList of all of the names of the OUT param fields
+ */
+ public ArrayList getOutParamListArray() {
+ return outParamList;
+ }
+
+
+ /**
+ * Retrieve an interator of IN param fields
+ * @return Iterator of IN param fields. [MetaData]
+ */
+ public Iterator getInParamFieldListIterator() {
+ return inParamList.iterator();
+ }
+
+
+ /**
+ * Retrieve an interator of IN param fields
+ * @return Iterator of IN param fields. [MetaData]
+ */
+ public Iterator getOutParamFieldListIterator() {
+ return outParamList.iterator();
+ }
+
+ /**
+ * This convenience method counts
+ * <code>DBFields</code> belonging to this
+ * <code>DBObject</code> that are set to <b>retrieve</b>.
+ * author Yves Henri Amaizo <amy_amaizo at compuserve.com>
+ *
+ * @return int number of retrieve fields.
+ *
+ * @throws DBException
+ */
+ public synchronized int getOutParamFieldsCount()
+ throws DBException {
+ if (outParamList == null) {
+ return 0;
+ } else {
+ return outParamList.size();
+ }
+ } /* getFieldsToRetrieveCount() */
+
}
More information about the cvs
mailing list