From: Hirzel P. <ph...@us...> - 2008-04-18 18:23:10
|
Update of /cvsroot/jomm/JOMM/src/ch/softenvironment/jomm In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv6032/src/ch/softenvironment/jomm Modified Files: DbMapper.java DbObjectServer.java Log Message: Minor refactoring and commenting Index: DbMapper.java =================================================================== RCS file: /cvsroot/jomm/JOMM/src/ch/softenvironment/jomm/DbMapper.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DbMapper.java 6 May 2007 20:46:04 -0000 1.4 --- DbMapper.java 18 Apr 2008 18:22:54 -0000 1.5 *************** *** 49,195 **** // DbFieldType Attribute public static final String ATTRIBUTE_MAP_VALUE = "T_Value"; ! /** ! * Usually each Target-System uses its own Error-Codes thrown ! * as an Exception in case of illegal interaction. ! * Therefore a User might be interested in a more understandable ! * (say less technical) verbose explanation of the exception. ! * @return String User-like error-explanation ! */ ! String describeTargetException(Exception exception); ! /** ! * Return an Id for a given Key (also referred as Sequence sometimes). ! * @param objectServer ! * @param transaction ! * @param key ! */ ! Long getNewId(javax.jdo.PersistenceManager objectServer, javax.jdo.Transaction transaction, final String key); ! /** ! * Return whether the given collection has a next element. ! */ ! boolean hasNext(Object collection); ! /** ! * Map <i>Collection of Objects</i>: <b>Target-System => Java</b>. ! * Maps values of given collection to given DbObject's Properties. ! * ! * <b>Only Properties of the given Descriptor are considered</b>, therefore ! * the correct Object hierarchy must be managed by the caller. ! * ! * @param object ! * @param descriptor ! * @param collection (Query Results -> only plain attributes, such as fields and foreign key ID's) ! */ ! void mapFromTarget(DbObject instance, DbDescriptor descriptor, Object collection) throws Throwable; ! /** ! * @see #mapFromTargetString(..) ! */ ! java.math.BigDecimal mapFromTargetBigDecimal(Object collection, String attribute); ! /** ! * Map <i>Type</i>: <b>Target-System => Java</b>. ! * Assumes Textdb-Field with 'T' for true and 'F' for false. ! * @see #mapFromTargetString(..) ! */ ! Boolean mapFromTargetBoolean(Object collection, String attribute); ! /** ! * @see #mapFromTargetString(..) ! */ ! java.util.Date mapFromTargetDate(Object collection, String attribute, final int type); ! /** ! * Map special types. ! */ ! DbFieldType mapFromTargetDbFieldType(Object collection, String attribute); ! /** ! * @see #mapFromTargetString(..) ! */ ! Double mapFromTargetDouble(Object collection, String attribute); ! /** ! * @see #mapFromTargetString(..) ! */ ! Integer mapFromTargetInteger(Object collection, String attribute); ! /** ! * @see #mapFromTargetString(..) ! */ ! Long mapFromTargetLong(Object collection, String attribute); ! /** ! * @see mapFromTargetBoolean() ! * @deprecated ! */ ! boolean mapFromTargetNativeBoolean(Object collection, String attribute); ! /** ! * @see mapFromTargetInteger() ! * @deprecated ! */ ! int mapFromTargetNativeInt(Object collection, String attribute); ! /** ! * Maps from <b>Target-System => Java</b>. ! * @param collection ResultSet from a query ! * @param attribute expected Attribute in collection ! */ ! String mapFromTargetString(Object collection, String attribute); ! /** ! * Map <i>Type</i>: <b>Java => Target-System</b>. ! * @param value Application value of a Model ! * @return String given value as an SQL-Query argument ! */ ! Object mapToTarget(DbFieldType value); ! /** ! * Map <i>Type</i>: <b>Java => Target-System</b>. ! * Only the Reference-Type of the given value will be mapped. ! * @param value Aggregated Object as Application value of a Model ! * @return String given value as an SQL-Query argument ! */ ! Object mapToTarget(DbObject value); ! /** ! * Map <i>Type</i>: <b>Java => Target-System</b>. ! * The value of given change will be mapped here. ! * @deprecated should be done in DbQueryBuilder ! */ ! Object mapToTarget(DbPropertyChange change); ! /** ! * Map <i>Type</i>: <b>Java => Target-System</b>. ! * Tri-State (TRUE, FALSE or NULL). ! * ! * @param value Application value of a Model ! * @return String given value as an SQL-Query argument ! */ ! Object mapToTarget(Boolean value); ! /** ! * Map <i>Type</i>: <b>Java => Target-System</b>. ! * @param value Application value of a Model ! * @return String given value as an SQL-Query argument ! */ ! Object mapToTarget(Number value); ! /** ! * Map <i>Type</i>: <b>Java => Target-System</b>. ! * @param value Application value of a Model ! * @return String given value as an SQL-Query argument ! */ ! Object mapToTarget(String value); ! /** ! * Map <i>Type</i>: <b>Java => Target-System</b>. ! * @param value Application value of a Model ! * @param type see DbDateFieldDescriptor ! * @return String given value as an SQL-Query argument ! */ ! Object mapToTarget(java.util.Date value, final int type); ! /** ! * Return a qualified attribute-name on Target-System. ! */ ! String mapToTargetQualified(String qualifier, String attribute); ! /** ! * Return the technical name of the "Identity" property. ! * @return ! */ ! String getTargetIdName(); ! /** ! * Return the name where NLS-String's are managed. ! * @return ! * @see #getTargetNlsTranslationName() ! */ ! String getTargetNlsName(); ! /** ! * Return the name where NLS-Translations's are managed. ! * @return ! * @see #getTargetNlsName() ! */ ! String getTargetNlsTranslationName(); } --- 49,202 ---- // DbFieldType Attribute public static final String ATTRIBUTE_MAP_VALUE = "T_Value"; ! ! /** ! * Usually each Target-System uses its own Error-Codes thrown ! * as an Exception in case of illegal interaction. ! * Therefore a User might be interested in a more understandable ! * (say less technical) verbose explanation of the exception. ! * @return String User-like error-explanation ! */ ! String describeTargetException(Exception exception); ! /** ! * Return an Id for a given Key (also referred as Sequence sometimes). ! * @param objectServer ! * @param transaction ! * @param key ! */ ! Long getNewId(javax.jdo.PersistenceManager objectServer, javax.jdo.Transaction transaction, final String key); ! /** ! * Return whether the given collection has a next element. ! */ ! boolean hasNext(Object collection); ! /** ! * Map <i>Collection of Objects</i>: <b>Target-System => Java</b>. ! * Maps values of given collection to given DbObject's Properties. ! * ! * <b>Only Properties of the given Descriptor are considered</b>, therefore ! * the correct Object hierarchy must be managed by the caller. ! * ! * @param object ! * @param descriptor ! * @param collection (Query Results -> only plain attributes, such as fields and foreign key ID's) ! */ ! void mapFromTarget(DbObject instance, DbDescriptor descriptor, Object collection) throws Throwable; ! /** ! * @see #mapFromTargetString(..) ! */ ! java.math.BigDecimal mapFromTargetBigDecimal(Object collection, String attribute); ! /** ! * Map <i>Type</i>: <b>Target-System => Java</b>. ! * Assumes Textdb-Field with 'T' for true and 'F' for false. ! * @see #mapFromTargetString(..) ! */ ! Boolean mapFromTargetBoolean(Object collection, String attribute); ! /** ! * @see #mapFromTargetString(..) ! */ ! java.util.Date mapFromTargetDate(Object collection, String attribute, final int type); ! /** ! * Map special types. ! */ ! DbFieldType mapFromTargetDbFieldType(Object collection, String attribute); ! /** ! * @see #mapFromTargetString(..) ! */ ! Double mapFromTargetDouble(Object collection, String attribute); ! /** ! * @see #mapFromTargetString(..) ! */ ! Integer mapFromTargetInteger(Object collection, String attribute); ! /** ! * @see #mapFromTargetString(..) ! */ ! Long mapFromTargetLong(Object collection, String attribute); ! /** ! * @see mapFromTargetBoolean() ! * @deprecated ! */ ! boolean mapFromTargetNativeBoolean(Object collection, String attribute); ! /** ! * @see mapFromTargetInteger() ! * @deprecated ! */ ! int mapFromTargetNativeInt(Object collection, String attribute); ! /** ! * Maps from <b>Target-System => Java</b>. ! * @param collection ResultSet from a query ! * @param attribute expected Attribute in collection ! */ ! String mapFromTargetString(Object collection, String attribute); ! /** ! * Map <i>Type</i>: <b>Java => Target-System</b>. ! * @param value Application value of a Model ! * @return String given value as an SQL-Query argument ! */ ! Object mapToTarget(DbFieldType value); ! /** ! * Map <i>Type</i>: <b>Java => Target-System</b>. ! * Only the Reference-Type of the given value will be mapped. ! * @param value Aggregated Object as Application value of a Model ! * @return String given value as an SQL-Query argument ! */ ! Object mapToTarget(DbObject value); ! /** ! * Map <i>Type</i>: <b>Java => Target-System</b>. ! * The value of given change will be mapped here. ! * @deprecated should be done in DbQueryBuilder ! */ ! Object mapToTarget(DbPropertyChange change); ! /** ! * Map <i>Type</i>: <b>Java => Target-System</b>. ! * Tri-State (TRUE, FALSE or NULL). ! * ! * @param value Application value of a Model ! * @return String given value as an SQL-Query argument ! */ ! Object mapToTarget(Boolean value); ! /** ! * Map <i>Type</i>: <b>Java => Target-System</b>. ! * @param value Application value of a Model ! * @return String given value as an SQL-Query argument ! */ ! Object mapToTarget(Number value); ! /** ! * Map <i>Type</i>: <b>Java => Target-System</b>. ! * @param value Application value of a Model ! * @return String given value as an SQL-Query argument ! */ ! Object mapToTarget(String value); ! /** ! * Map <i>Type</i>: <b>Java => Target-System</b>. ! * @param value Application value of a Model ! * @param type see DbDateFieldDescriptor ! * @return String given value as an SQL-Query argument ! */ ! Object mapToTarget(java.util.Date value, final int type); ! /** ! * Return a qualified attribute-name on Target-System. ! */ ! String mapToTargetQualified(String qualifier, String attribute); ! /** ! * Return the technical name of the "Identity" property. ! * @return ! */ ! String getTargetIdName(); ! /** ! * Return the name where NLS-String's are managed. ! * @return ! * @see #getTargetNlsTranslationName() ! */ ! String getTargetNlsName(); ! /** ! * Return the name where NLS-Translations's are managed. ! * @return ! * @see #getTargetNlsName() ! */ ! String getTargetNlsTranslationName(); ! /** ! * Return the name where removed objects are historized. ! * @return ! * @see #getTargetNlsTranslationName() ! */ ! String getTargetRemoveHistoryName(); } Index: DbObjectServer.java =================================================================== RCS file: /cvsroot/jomm/JOMM/src/ch/softenvironment/jomm/DbObjectServer.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** DbObjectServer.java 20 Feb 2007 13:27:03 -0000 1.17 --- DbObjectServer.java 18 Apr 2008 18:22:54 -0000 1.18 *************** *** 269,276 **** //TODO NYI: evtl. keep new transient DbObject's in mind setUniqueId(object, getTemporaryNewId()); ! if (dbClass.equals(DbCodeType.class)) { } } return object; --- 269,277 ---- //TODO NYI: evtl. keep new transient DbObject's in mind setUniqueId(object, getTemporaryNewId()); ! /* if (dbClass.equals(DbCodeType.class)) { } + */ } return object; *************** *** 357,361 **** // if (!object.jdoIsTransactional()) { ! if (pc instanceof DbCodeType) { // uncache all codes of this type codeCache.uncache(object.getClass()); --- 358,365 ---- // if (!object.jdoIsTransactional()) { ! if (pc instanceof DbEnumeration) { ! Tracer.getInstance().developerWarning("Cannot uncache DbEnumeration=>needs a restart to change"); ! return; ! } else if (pc instanceof DbCode /*Type*/) { // uncache all codes of this type codeCache.uncache(object.getClass()); *************** *** 697,761 **** } } ! /** This method locates a persistent instance in the cache of instances ! * managed by this <code>PersistenceManager</code>. ! * The <code>getObjectById</code> method attempts ! * to find an instance in the cache with the specified JDO identity. ! * The <code>oid</code> parameter object might have been returned by an earlier call ! * to <code>getObjectId</code> or <code>getTransactionalObjectId</code>, ! * or might have been constructed by the application. ! * <P>If the <code>PersistenceManager</code> is unable to resolve the <code>oid</code> parameter ! * to an ObjectId instance, then it throws a <code>JDOUserException</code>. ! * <P>If the <code>validate</code> flag is <code>false</code>, and there is already an instance in the ! * cache with the same JDO identity as the <code>oid</code> parameter, then this method ! * returns it. There is no change made to the state of the returned ! * instance. ! * <P>If there is not an instance already in the cache with the same JDO ! * identity as the <code>oid</code> parameter, then this method creates an instance ! * with the specified JDO identity and returns it. If there is no ! * transaction in progress, the returned instance will be hollow or ! * persistent-nontransactional, at the choice of the implementation. ! * <P>If there is a transaction in progress, the returned instance will ! * be hollow, persistent-nontransactional, or persistent-clean, at the ! * choice of the implementation. ! * <P>It is an implementation decision whether to access the data store, ! * if required to determine the exact class. This will be the case of ! * inheritance, where multiple <code>PersistenceCapable</code> classes share the ! * same ObjectId class. ! * <P>If the validate flag is <code>false</code>, and the instance does not exist in ! * the data store, then this method might not fail. It is an ! * implementation choice whether to fail immediately with a ! * <code>JDODataStoreException</code>. But a subsequent access of the fields of the ! * instance will throw a <code>JDODataStoreException</code> if the instance does not ! * exist at that time. Further, if a relationship is established to this ! * instance, then the transaction in which the association was made will ! * fail. ! * <P>If the <code>validate</code> flag is <code>true</code>, and there is already a transactional ! * instance in the cache with the same JDO identity as the <code>oid</code> parameter, ! * then this method returns it. There is no change made to the state of ! * the returned instance. ! * <P>If there is an instance already in the cache with the same JDO ! * identity as the <code>oid</code> parameter, but the instance is not transactional, ! * then it must be verified in the data store. If the instance does not ! * exist in the datastore, then a <code>JDODataStoreException</code> is thrown. ! * <P>If there is not an instance already in the cache with the same JDO ! * identity as the <code>oid</code> parameter, then this method creates an instance ! * with the specified JDO identity, verifies that it exists in the data ! * store, and returns it. If there is no transaction in progress, the ! * returned instance will be hollow or persistent-nontransactional, ! * at the choice of the implementation. ! * <P>If there is a data store transaction in progress, the returned ! * instance will be persistent-clean. ! * If there is an optimistic transaction in progress, the returned ! * instance will be persistent-nontransactional. ! * ! * For e.g. ! * DbCodeType code = getObjectById(new DbObjectId(MyCodeType.class, new Long(15)), false) ! * @see #getObjectId(Object pc) ! * @see #getTransactionalObjectId(Object pc) ! * @return the <code>PersistenceCapable</code> instance with the specified ObjectId ! * @param oid an ObjectId ! * @param validate if the existence of the instance is to be validated ! * @see javax.jdo.PersistenceManager ! */ public java.lang.Object getObjectById(java.lang.Object oid, boolean validate) { return getObjectById(oid, validate, false); --- 701,768 ---- } } ! /** ! * This method locates a persistent instance in the cache of instances ! * managed by this <code>PersistenceManager</code>. ! * The <code>getObjectById</code> method attempts ! * to find an instance in the cache with the specified JDO identity. ! * The <code>oid</code> parameter object might have been returned by an earlier call ! * to <code>getObjectId</code> or <code>getTransactionalObjectId</code>, ! * or might have been constructed by the application. ! * <P>If the <code>PersistenceManager</code> is unable to resolve the <code>oid</code> parameter ! * to an ObjectId instance, then it throws a <code>JDOUserException</code>. ! * <P>If the <code>validate</code> flag is <code>false</code>, and there is already an instance in the ! * cache with the same JDO identity as the <code>oid</code> parameter, then this method ! * returns it. There is no change made to the state of the returned ! * instance. ! * <P>If there is not an instance already in the cache with the same JDO ! * identity as the <code>oid</code> parameter, then this method creates an instance ! * with the specified JDO identity and returns it. If there is no ! * transaction in progress, the returned instance will be hollow or ! * persistent-nontransactional, at the choice of the implementation. ! * <P>If there is a transaction in progress, the returned instance will ! * be hollow, persistent-nontransactional, or persistent-clean, at the ! * choice of the implementation. ! * <P>It is an implementation decision whether to access the data store, ! * if required to determine the exact class. This will be the case of ! * inheritance, where multiple <code>PersistenceCapable</code> classes share the ! * same ObjectId class. ! * <P>If the validate flag is <code>false</code>, and the instance does not exist in ! * the data store, then this method might not fail. It is an ! * implementation choice whether to fail immediately with a ! * <code>JDODataStoreException</code>. But a subsequent access of the fields of the ! * instance will throw a <code>JDODataStoreException</code> if the instance does not ! * exist at that time. Further, if a relationship is established to this ! * instance, then the transaction in which the association was made will ! * fail. ! * <P>If the <code>validate</code> flag is <code>true</code>, and there is already a transactional ! * instance in the cache with the same JDO identity as the <code>oid</code> parameter, ! * then this method returns it. There is no change made to the state of ! * the returned instance. ! * <P>If there is an instance already in the cache with the same JDO ! * identity as the <code>oid</code> parameter, but the instance is not transactional, ! * then it must be verified in the data store. If the instance does not ! * exist in the datastore, then a <code>JDODataStoreException</code> is thrown. ! * <P>If there is not an instance already in the cache with the same JDO ! * identity as the <code>oid</code> parameter, then this method creates an instance ! * with the specified JDO identity, verifies that it exists in the data ! * store, and returns it. If there is no transaction in progress, the ! * returned instance will be hollow or persistent-nontransactional, ! * at the choice of the implementation. ! * <P>If there is a data store transaction in progress, the returned ! * instance will be persistent-clean. ! * If there is an optimistic transaction in progress, the returned ! * instance will be persistent-nontransactional. ! * ! * For e.g. ! * DbCodeType code = getObjectById(new DbObjectId(MyCodeType.class, new Long(15)), false); ! * MyConcreteClass mc = (MyConcreteClass)getObjectById(new DbObjectId(MyAbstract.class, new Long(15)), false); // returns real inherited instance ! * ! * @see #getObjectId(Object pc) ! * @see #getTransactionalObjectId(Object pc) ! * @return the <code>PersistenceCapable</code> instance with the specified ObjectId ! * @param oid an ObjectId ! * @param validate if the existence of the instance is to be validated ! * @see javax.jdo.PersistenceManager ! */ public java.lang.Object getObjectById(java.lang.Object oid, boolean validate) { return getObjectById(oid, validate, false); |