Return-Path: Delivered-To: apmail-db-torque-dev-archive@www.apache.org Received: (qmail 11776 invoked from network); 17 May 2004 13:29:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 17 May 2004 13:29:22 -0000 Received: (qmail 63783 invoked by uid 500); 17 May 2004 13:29:27 -0000 Delivered-To: apmail-db-torque-dev-archive@db.apache.org Received: (qmail 63734 invoked by uid 500); 17 May 2004 13:29:27 -0000 Mailing-List: contact torque-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Apache Torque Developers List" Reply-To: "Apache Torque Developers List" Delivered-To: mailing list torque-dev@db.apache.org Received: (qmail 63705 invoked by uid 500); 17 May 2004 13:29:26 -0000 Received: (qmail 63679 invoked by uid 98); 17 May 2004 13:29:26 -0000 Received: from henning@apache.org by hermes.apache.org by uid 82 with qmail-scanner-1.20 (clamuko: 0.70. Clear:RC:0(209.237.227.194):. Processed in 0.081969 secs); 17 May 2004 13:29:26 -0000 X-Qmail-Scanner-Mail-From: henning@apache.org via hermes.apache.org X-Qmail-Scanner: 1.20 (Clear:RC:0(209.237.227.194):. Processed in 0.081969 secs) Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by hermes.apache.org with SMTP; 17 May 2004 13:29:26 -0000 Received: (qmail 11743 invoked by uid 1332); 17 May 2004 13:29:19 -0000 Date: 17 May 2004 13:29:19 -0000 Message-ID: <20040517132919.11742.qmail@minotaur.apache.org> From: henning@apache.org To: db-torque-cvs@apache.org Subject: cvs commit: db-torque/xdocs release-changes.xml X-Spam-Rating: hermes.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N henning 2004/05/17 06:29:19 Modified: src/generator/src/templates/om Tag: TORQUE_3_1_HENNING Object.vm Peer.vm src/java/org/apache/torque/om Tag: TORQUE_3_1_HENNING Persistent.java src/java/org/apache/torque/util Tag: TORQUE_3_1_HENNING BasePeer.java xdocs Tag: TORQUE_3_1_HENNING release-changes.xml Removed: proposals/henning/skipidbroker Tag: TORQUE_3_1_HENNING README skipidbroker.patch Log: Added the skipidbroker proposal to the TORQUE_3_1_HENNING branch. Revision Changes Path No revision No revision 1.7.2.2.2.1 +56 -6 db-torque/src/generator/src/templates/om/Object.vm Index: Object.vm =================================================================== RCS file: /home/cvs/db-torque/src/generator/src/templates/om/Object.vm,v retrieving revision 1.7.2.2 retrieving revision 1.7.2.2.2.1 diff -u -r1.7.2.2 -r1.7.2.2.2.1 --- Object.vm 22 Jan 2004 01:06:50 -0000 1.7.2.2 +++ Object.vm 17 May 2004 13:29:19 -0000 1.7.2.2.2.1 @@ -1022,15 +1022,28 @@ */ public void save() throws $saveException { + save(false); + } + + /** + * Stores the object in the database. If the object is new, + * it inserts it; otherwise an update is performed. + * + * @param skipIdBroker If this is true, the criteria already contains + * a value for the PK and the ID Broker should not be used + * @throws $saveException + */ + public void save(boolean skipIdBroker) throws $saveException + { #if ($complexObjectModel) save(${table.JavaName}Peer.getMapBuilder() - .getDatabaseMap().getName()); + .getDatabaseMap().getName(), skipIdBroker); #else if (isModified()) { if (isNew()) { - ${table.JavaName}Peer.doInsert(($table.JavaName) this); + ${table.JavaName}Peer.doInsert(($table.JavaName) this, skipIdBroker); setNew(false); } else @@ -1055,12 +1068,31 @@ */ public void save(String dbName) throws TorqueException { + save(dbName, false); + } + + /** + * Stores the object in the database. If the object is new, + * it inserts it; otherwise an update is performed. + #if ($complexObjectModel) + * Note: this code is here because the method body is + * auto-generated conditionally and therefore needs to be + * in this file instead of in the super class, BaseObject. + #end + * + * @param dbName + * @param skipIdBroker If this is true, the criteria already contains + * a value for the PK and the ID Broker should not be used + * @throws TorqueException + */ + public void save(String dbName, boolean skipIdBroker) throws TorqueException + { Connection con = null; #if ($complexObjectModel) try { con = Transaction.begin(dbName); - save(con); + save(con, skipIdBroker); Transaction.commit(con); } catch(TorqueException e) @@ -1077,7 +1109,7 @@ if (isNew()) { ${table.JavaName}Peer - .doInsert(($table.JavaName) this, con); + .doInsert(($table.JavaName) this, con, skipIdBroker); setNew(false); } else @@ -1099,6 +1131,7 @@ by another object which falls in this transaction. */ private boolean alreadyInSave = false; #end + /** * Stores the object in the database. If the object is new, * it inserts it; otherwise an update is performed. This method @@ -1111,6 +1144,23 @@ */ public void save(Connection con) throws TorqueException { + save(con, false); + } + + /** + * Stores the object in the database. If the object is new, + * it inserts it; otherwise an update is performed. This method + * is meant to be used as part of a transaction, otherwise use + * the save() method and the connection details will be handled + * internally + * + * @param con + * @param skipIdBroker If this is true, the criteria already contains + * a value for the PK and the ID Broker should not be used + * @throws TorqueException + */ + public void save(Connection con, boolean skipIdBroker) throws TorqueException + { #if ($complexObjectModel) if (!alreadyInSave) { @@ -1132,7 +1182,7 @@ #set($i = $velocityCount - 1) if ($aVarName != null) { - ${aVarName}.save(con); + ${aVarName}.save(con, skipIdBroker); set$pVars.get($i)($aVarName); } #end @@ -1145,7 +1195,7 @@ { if (isNew()) { - ${table.JavaName}Peer.doInsert(($table.JavaName) this, con); + ${table.JavaName}Peer.doInsert(($table.JavaName) this, con, skipIdBroker); setNew(false); } else 1.5.2.3.2.1 +92 -8 db-torque/src/generator/src/templates/om/Peer.vm Index: Peer.vm =================================================================== RCS file: /home/cvs/db-torque/src/generator/src/templates/om/Peer.vm,v retrieving revision 1.5.2.3 retrieving revision 1.5.2.3.2.1 diff -u -r1.5.2.3 -r1.5.2.3.2.1 --- Peer.vm 6 Apr 2004 12:49:46 -0000 1.5.2.3 +++ Peer.vm 17 May 2004 13:29:19 -0000 1.5.2.3.2.1 @@ -229,8 +229,23 @@ public static ObjectKey doInsert(Criteria criteria) throws TorqueException { + return doInsert(criteria, false); + } + + /** + * Method to do inserts. + * + * @param criteria object used to create the INSERT statement. + * @param skipIdBroker If this is true, the criteria already contains + * a value for the PK and the ID Broker should not be used + * @throws TorqueException Any exceptions caught during processing will be + * rethrown wrapped into a TorqueException. + */ + public static ObjectKey doInsert(Criteria criteria, boolean skipIdBroker) + throws TorqueException + { return $basePrefix${table.JavaName}Peer - .doInsert(criteria, (Connection) null); + .doInsert(criteria, (Connection) null, skipIdBroker); } /** @@ -246,6 +261,24 @@ public static ObjectKey doInsert(Criteria criteria, Connection con) throws TorqueException { + return doInsert(criteria, con, false); + } + + /** + * Method to do inserts. This method is to be used during a transaction, + * otherwise use the doInsert(Criteria) method. It will take care of + * the connection details internally. + * + * @param criteria object used to create the INSERT statement. + * @param con the connection to use + * @param skipIdBroker If this is true, the criteria already contains + * a value for the PK and the ID Broker should not be used + * @throws TorqueException Any exceptions caught during processing will be + * rethrown wrapped into a TorqueException. + */ + public static ObjectKey doInsert(Criteria criteria, Connection con, boolean skipIdBroker) + throws TorqueException + { #foreach ($col in $table.Columns) #set ( $cup=$col.Name.toUpperCase() ) #if($col.isBooleanInt()) @@ -294,11 +327,11 @@ } if (con == null) { - return BasePeer.doInsert(criteria); + return BasePeer.doInsert(criteria, skipIdBroker); } else { - return BasePeer.doInsert(criteria, con); + return BasePeer.doInsert(criteria, con, skipIdBroker); } } @@ -790,10 +823,30 @@ */ public static void doInsert($table.JavaName obj) throws TorqueException { + doInsert(obj, false); + } + + /** + * Method to do inserts + * + * @param skipIdBroker If this is true, the criteria already contains + * a value for the PK and the ID Broker should not be used + * @throws TorqueException Any exceptions caught during processing will be + * rethrown wrapped into a TorqueException. + */ + public static void doInsert($table.JavaName obj, boolean skipIdBroker) throws TorqueException + { #if ($table.IdMethod.equals("none") || $table.PrimaryKey.size() == 0) - doInsert(buildCriteria(obj)); + doInsert(buildCriteria(obj, skipIdBroker), skipIdBroker); #else - obj.setPrimaryKey(doInsert(buildCriteria(obj))); + if (skipIdBroker) + { + doInsert(buildCriteria(obj, skipIdBroker), skipIdBroker); + } + else + { + obj.setPrimaryKey(doInsert(buildCriteria(obj, skipIdBroker), skipIdBroker)); + } #end obj.setNew(false); obj.setModified(false); @@ -833,10 +886,35 @@ public static void doInsert($table.JavaName obj, Connection con) throws TorqueException { + doInsert(obj, con, false); + } + + /** + * Method to do inserts. This method is to be used during a transaction, + * otherwise use the doInsert($table.JavaName) method. It will take + * care of the connection details internally. + * + * @param obj the data object to insert into the database. + * @param con the connection to use + * @param skipIdBroker If this is true, the criteria already contains + * a value for the PK and the ID Broker should not be used + * @throws TorqueException Any exceptions caught during processing will be + * rethrown wrapped into a TorqueException. + */ + public static void doInsert($table.JavaName obj, Connection con, boolean skipIdBroker) + throws TorqueException + { #if ($table.IdMethod.equals("none") || $table.PrimaryKey.size() == 0) - doInsert(buildCriteria(obj), con); + doInsert(buildCriteria(obj, skipIdBroker), con, skipIdBroker); #else - obj.setPrimaryKey(doInsert(buildCriteria(obj), con)); + if (skipIdBroker) + { + doInsert(buildCriteria(obj, skipIdBroker), con, skipIdBroker); + } + else + { + obj.setPrimaryKey(doInsert(buildCriteria(obj, skipIdBroker), con, skipIdBroker)); + } #end obj.setNew(false); obj.setModified(false); @@ -925,12 +1003,18 @@ /** Build a Criteria object from the data object for this peer */ public static Criteria buildCriteria( $table.JavaName obj ) { + return buildCriteria(obj, false); + } + + /** Build a Criteria object from the data object for this peer */ + public static Criteria buildCriteria( $table.JavaName obj, boolean includePk ) + { Criteria criteria = new Criteria(DATABASE_NAME); #foreach ($col in $table.Columns) #set ( $cfc=$col.JavaName ) #set ( $cup=$col.Name.toUpperCase() ) #if ($col.isPrimaryKey() && !$table.IdMethod.equals("none")) - if (!obj.isNew()) + if (includePk || !obj.isNew()) #end criteria.add($cup, obj.get${cfc}()); #end No revision No revision 1.11.2.1.2.1 +35 -1 db-torque/src/java/org/apache/torque/om/Persistent.java Index: Persistent.java =================================================================== RCS file: /home/cvs/db-torque/src/java/org/apache/torque/om/Persistent.java,v retrieving revision 1.11.2.1 retrieving revision 1.11.2.1.2.1 diff -u -r1.11.2.1 -r1.11.2.1.2.1 --- Persistent.java 29 Feb 2004 23:14:11 -0000 1.11.2.1 +++ Persistent.java 17 May 2004 13:29:19 -0000 1.11.2.1.2.1 @@ -108,4 +108,38 @@ * @throws Exception This method might throw an exception */ void save(Connection con) throws Exception; + + /** + * Saves the object. + * + * @param skipIdBroker If this is true, the criteria already contains + * a value for the PK and the ID Broker should not be used + * @throws Exception This method might throw an exception + */ + void save(boolean skipIdBroker) throws Exception; + + /** + * Stores the object in the database. If the object is new, + * it inserts it; otherwise an update is performed. + * + * @param dbName the name of the database + * @param skipIdBroker If this is true, the criteria already contains + * a value for the PK and the ID Broker should not be used + * @throws Exception This method might throw an exception + */ + void save(String dbName, boolean skipIdBroker) throws Exception; + + /** + * Stores the object in the database. If the object is new, + * it inserts it; otherwise an update is performed. This method + * is meant to be used as part of a transaction, otherwise use + * the save() method and the connection details will be handled + * internally + * + * @param con the Connection used to store the object + * @param skipIdBroker If this is true, the criteria already contains + * a value for the PK and the ID Broker should not be used + * @throws Exception This method might throw an exception + */ + void save(Connection con, boolean skipIdBroker) throws Exception; } No revision No revision 1.76.2.1.2.1 +73 -2 db-torque/src/java/org/apache/torque/util/BasePeer.java Index: BasePeer.java =================================================================== RCS file: /home/cvs/db-torque/src/java/org/apache/torque/util/BasePeer.java,v retrieving revision 1.76.2.1 retrieving revision 1.76.2.1.2.1 diff -u -r1.76.2.1 -r1.76.2.1.2.1 --- BasePeer.java 29 Feb 2004 23:19:09 -0000 1.76.2.1 +++ BasePeer.java 17 May 2004 13:29:19 -0000 1.76.2.1.2.1 @@ -585,6 +585,38 @@ */ public static ObjectKey doInsert(Criteria criteria) throws TorqueException { + return doInsert(criteria, false); + } + + /** + * Method to perform inserts based on values and keys in a + * Criteria. + *

+ * If the primary key is auto incremented the data in Criteria + * will be inserted and the auto increment value will be returned. + *

+ * If the primary key is included in Criteria then that value will + * be used to insert the row. + *

+ * If no primary key is included in Criteria then we will try to + * figure out the primary key from the database map and insert the + * row with the next available id using util.db.IDBroker. + *

+ * If no primary key is defined for the table the values will be + * inserted as specified in Criteria and -1 will be returned. + * + * @param criteria Object containing values to insert. + * @param skipIdBroker If this is true, the criteria already contains + * a value for the PK and the ID Broker should not be used + * @return An Object which is the id of the row that was inserted + * (if the table has a primary key) or null (if the table does not + * have a primary key). + * @throws TorqueException Any exceptions caught during processing will be + * rethrown wrapped into a TorqueException. + */ + public static ObjectKey doInsert(Criteria criteria, boolean skipIdBroker) + throws TorqueException + { Connection con = null; ObjectKey id = null; @@ -593,7 +625,7 @@ con = Transaction.beginOptional( criteria.getDbName(), criteria.isUseTransaction()); - id = doInsert(criteria, con); + id = doInsert(criteria, con, skipIdBroker); Transaction.commit(con); } catch (TorqueException e) @@ -633,6 +665,39 @@ public static ObjectKey doInsert(Criteria criteria, Connection con) throws TorqueException { + return doInsert(criteria, con, false); + } + + /** + * Method to perform inserts based on values and keys in a + * Criteria. + *

+ * If the primary key is auto incremented the data in Criteria + * will be inserted and the auto increment value will be returned. + *

+ * If the primary key is included in Criteria then that value will + * be used to insert the row. + *

+ * If no primary key is included in Criteria then we will try to + * figure out the primary key from the database map and insert the + * row with the next available id using util.db.IDBroker. + *

+ * If no primary key is defined for the table the values will be + * inserted as specified in Criteria and null will be returned. + * + * @param criteria Object containing values to insert. + * @param con A Connection. + * @param skipIdBroker If this is true, the criteria already contains + * a value for the PK and the ID Broker should not be used + * @return An Object which is the id of the row that was inserted + * (if the table has a primary key) or null (if the table does not + * have a primary key). + * @throws TorqueException Any exceptions caught during processing will be + * rethrown wrapped into a TorqueException. + */ + public static ObjectKey doInsert(Criteria criteria, Connection con, boolean skipIdBroker) + throws TorqueException + { SimpleKey id = null; // Get the table name and method for determining the primary @@ -656,6 +721,8 @@ ColumnMap pk = getPrimaryKey(criteria); + if (!skipIdBroker) + { // pk will be null if there is no primary key defined for the table // we're inserting into. if (pk != null && !criteria.containsKey(pk.getFullyQualifiedName())) @@ -689,6 +756,7 @@ criteria.add(pk.getFullyQualifiedName(), id); } } + } // Use Village to perform the insert. TableDataSet tds = null; @@ -717,6 +785,8 @@ } } + if (!skipIdBroker) + { // If the primary key column is auto-incremented, get the id // now. if (pk != null && keyGen != null && keyGen.isPostInsert()) @@ -736,6 +806,7 @@ { throwTorqueException(e); } + } } return id; No revision No revision 1.3.2.5.2.7 +19 -1 db-torque/xdocs/release-changes.xml Index: release-changes.xml =================================================================== RCS file: /home/cvs/db-torque/xdocs/release-changes.xml,v retrieving revision 1.3.2.5.2.6 retrieving revision 1.3.2.5.2.7 diff -u -r1.3.2.5.2.6 -r1.3.2.5.2.7 --- release-changes.xml 17 May 2004 13:23:01 -0000 1.3.2.5.2.6 +++ release-changes.xml 17 May 2004 13:29:19 -0000 1.3.2.5.2.7 @@ -115,6 +115,24 @@ ]]>

+ + +

+If an application wants to read a save file back into a Torque +database, every object will get a new primary key value, even if the +values of the primary keys were saved, too. This is fatal for all +kinds of foreign key relations and even more fatal if save file +integrity is an issue to an application.
+ +This patch allows a restore program to use Persistent.save(true) +and friends to skip the idbroker call. All other methods continue to work as +before.
+ +As Torque copies these methods into the generated OM classes, it is necessary to +rebuild the OM scheme.
+

+
+
--------------------------------------------------------------------- To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org For additional commands, e-mail: torque-dev-help@db.apache.org