Return-Path: Mailing-List: contact ojb-dev-help@db.apache.org; run by ezmlm Delivered-To: mailing list ojb-dev@db.apache.org Received: (qmail 48618 invoked from network); 2 Apr 2003 02:40:41 -0000 Received: from rack3.sundayta.com (HELO pluto.sundayta.net) (213.239.45.132) by daedalus.apache.org with SMTP; 2 Apr 2003 02:40:41 -0000 Received: from [217.206.34.202] (helo=sundayta.com) by pluto.sundayta.net with esmtp (Exim 3.35 #1 (Debian)) id 190XzR-00081A-00 for ; Wed, 02 Apr 2003 03:28:38 +0100 Message-ID: <3E8A5B27.7000904@sundayta.com> Date: Wed, 02 Apr 2003 03:38:15 +0000 From: David Warnock User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: OJB Developers List Subject: Re: Optimistic Locking change References: In-Reply-To: Content-Type: multipart/mixed; boundary="------------020700030805010008090204" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N --------------020700030805010008090204 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Thomas wrote: > Hi David, > > As you may have noticed, I did not manage to add your Optimistic locking > extension to the RC2 release. > I did not manage to get rid of the junit failures. > > But I still want to get your stuff integrated! > Could you please write your changes against the latest rc2 release and post > the patch file again. Here is the patch, it works with all the tests on my system (after I checked again and got the old patch to fail). This is a patch to the cvs HEAD. Dave -- David Warnock, Sundayta Ltd. http://www.sundayta.com iDocSys for Document Management. VisibleResults for Fundraising. Development and Hosting of Web Applications and Sites. --------------020700030805010008090204 Content-Type: text/plain; name="patchfile.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patchfile.txt" Index: src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java =================================================================== RCS file: /home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java,v retrieving revision 1.51 diff -u -r1.51 ClassDescriptor.java --- src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java 26 Mar 2003 10:37:55 -0000 1.51 +++ src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java 2 Apr 2003 02:37:25 -0000 @@ -727,6 +727,7 @@ /** * updates the values for locking fields , BRJ * handles int, long, Timestamp + * respects updateLock so locking field are only updated when updateLock is true * @throws PersistenceBrokerException if there is an erros accessing obj field values */ public void updateLockingValues(Object obj) throws PersistenceBrokerException @@ -735,40 +736,43 @@ for (int i = 0; i < fields.length; i++) { FieldDescriptor fmd = fields[i]; - PersistentField f = fmd.getPersistentField(); - Object cv = null; - cv = f.get(obj); - - // int - if ((f.getType() == int.class) || (f.getType() == Integer.class)) - + if (fmd.isUpdateLock()) { - int newCv = 0; - if (cv != null) + PersistentField f = fmd.getPersistentField(); + Object cv = null; + cv = f.get(obj); + + // int + if ((f.getType() == int.class) || (f.getType() == Integer.class)) + { - newCv = ((Number) cv).intValue(); + int newCv = 0; + if (cv != null) + { + newCv = ((Number) cv).intValue(); + } + newCv++; + f.set(obj, new Integer(newCv)); } - newCv++; - f.set(obj, new Integer(newCv)); - } - // long - else if ((f.getType() == long.class) || (f.getType() == Long.class)) - - { - long newCv = 0; - if (cv != null) + // long + else if ((f.getType() == long.class) || (f.getType() == Long.class)) + { - newCv = ((Number) cv).longValue(); + long newCv = 0; + if (cv != null) + { + newCv = ((Number) cv).longValue(); + } + newCv++; + f.set(obj, new Long(newCv)); + } + // Timestamp + else if (f.getType() == Timestamp.class) + + { + long newCv = (new Date()).getTime(); + f.set(obj, new Timestamp(newCv)); } - newCv++; - f.set(obj, new Long(newCv)); - } - // Timestamp - else if (f.getType() == Timestamp.class) - - { - long newCv = (new Date()).getTime(); - f.set(obj, new Timestamp(newCv)); } } } Index: src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java =================================================================== RCS file: /home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java,v retrieving revision 1.17 diff -u -r1.17 FieldDescriptor.java --- src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java 26 Mar 2003 10:37:56 -0000 1.17 +++ src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java 2 Apr 2003 02:37:36 -0000 @@ -95,6 +95,11 @@ private FieldConversion fieldConversion = null; // true if field is used for optimistic locking BRJ private boolean locking = false; + // if locking is true and updateLock is true then + // on save lock columns will be updated. + // if false then it is the responsibility of the + // dbms to update all lock columns eg using triggers + private boolean updateLock = true; /** * returns a comparator that allows to sort a Vector of FieldMappingDecriptors @@ -385,6 +390,32 @@ this.locking = locking; } + /** + * Gets the updateLock + * updateLock controls whether the lock fields should be + * updated by OJB when a row is saved + * If false then the dbms needs to update the lock fields. + * The default is true + * @return Returns a boolean + */ + public boolean isUpdateLock() + { + return updateLock; + } + + /** + * Sets the updateLock + * updateLock controls whether the lock fields should be + * updated by OJB when a row is saved. + * If false then the dbms needs to update the lock fields. + * The default is true + * @param updateLock The updateLock to set + */ + public void setUpdateLock(boolean updateLock) + { + this.updateLock = updateLock; + } + public void setLength(int length) { this.length = length; @@ -505,6 +536,13 @@ if (this.isLocking()) { result += " " + tags.getAttribute(LOCKING, "true") + eol; + } + + // updateLock + // default is true so only write if false + if (!this.isUpdateLock()) + { + result += " " + tags.getAttribute(UPDATE_LOCK, "false") + eol; } // default-fetch not yet implemented Index: src/java/org/apache/ojb/broker/metadata/RepositoryElements.java =================================================================== RCS file: /home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryElements.java,v retrieving revision 1.22 diff -u -r1.22 RepositoryElements.java --- src/java/org/apache/ojb/broker/metadata/RepositoryElements.java 30 Mar 2003 15:01:09 -0000 1.22 +++ src/java/org/apache/ojb/broker/metadata/RepositoryElements.java 2 Apr 2003 02:37:48 -0000 @@ -112,6 +112,7 @@ public static final int DATASOURCE_NAME = 44; public static final int JDBC_LEVEL = 45; public static final int LOCKING = 46; + public static final int UPDATE_LOCK = 95; public static final int REFRESH_REFERENCE = 47; public static final int PROXY_REFERENCE = 48; public static final int ISOLATION_LEVEL = 34; @@ -158,7 +159,7 @@ public static final int INITIALIZATION_METHOD = 93; // maintain a next id to keep track where we are - static final int _NEXT = 95; + static final int _NEXT = 96; public static final String TAG_ACCESS_ANONYMOUS = "anonymous"; public static final String TAG_ACCESS_READONLY = "readonly"; Index: src/java/org/apache/ojb/broker/metadata/RepositoryTags.java =================================================================== RCS file: /home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryTags.java,v retrieving revision 1.24 diff -u -r1.24 RepositoryTags.java --- src/java/org/apache/ojb/broker/metadata/RepositoryTags.java 30 Mar 2003 15:01:09 -0000 1.24 +++ src/java/org/apache/ojb/broker/metadata/RepositoryTags.java 2 Apr 2003 02:37:56 -0000 @@ -151,6 +151,7 @@ table.put("jndi-datasource-name", new Integer(DATASOURCE_NAME)); table.put("jdbc-level", new Integer(JDBC_LEVEL)); table.put("locking", new Integer(LOCKING)); + table.put("update-lock", new Integer(UPDATE_LOCK)); table.put("refresh", new Integer(REFRESH_REFERENCE)); table.put("proxy", new Integer(PROXY_REFERENCE)); table.put("sort", new Integer(SORT)); Index: src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java =================================================================== RCS file: /home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java,v retrieving revision 1.36 diff -u -r1.36 RepositoryXmlHandler.java --- src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java 30 Mar 2003 15:01:09 -0000 1.36 +++ src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java 2 Apr 2003 02:38:07 -0000 @@ -410,6 +410,11 @@ b = (new Boolean(locking)).booleanValue(); m_CurrentFLD.setLocking(b); + String updateLock = atts.getValue(tags.getTagById(UPDATE_LOCK)); + if (isDebug) logger.debug(" " + tags.getTagById(UPDATE_LOCK) + ": " + updateLock); + b = (new Boolean(updateLock)).booleanValue(); + m_CurrentFLD.setUpdateLock(b); + String fieldConversion = atts.getValue(tags.getTagById(FIELD_CONVERSION)); if (isDebug) logger.debug(" " + tags.getTagById(FIELD_CONVERSION) + ": " + fieldConversion); if (fieldConversion != null) Index: src/test/org/apache/ojb/repository.dtd =================================================================== RCS file: /home/cvspublic/db-ojb/src/test/org/apache/ojb/repository.dtd,v retrieving revision 1.38 diff -u -r1.38 repository.dtd --- src/test/org/apache/ojb/repository.dtd 1 Apr 2003 14:06:11 -0000 1.38 +++ src/test/org/apache/ojb/repository.dtd 2 Apr 2003 02:38:31 -0000 @@ -397,6 +397,12 @@ used for optimistic locking. can only be set for TIMESTAMP and INTEGER columns. + The updatelock attribute is set to false if the persistent attribute is + used for optimistic locking AND the dbms should update the lock column + itself. The default is true which means that when locking is true then + OJB will update the locking fields. Can only be set for TIMESTAMP and INTEGER + columns. + The default-fetch attribute specifies whether the persistent attribute belongs to the JDO default fetch group. @@ -439,6 +445,7 @@ autoincrement (true | false) "false" sequence-name CDATA #IMPLIED locking (true | false) "false" + update-lock (true | false) "true" default-fetch (true | false) "false" conversion CDATA #IMPLIED length CDATA #IMPLIED --------------020700030805010008090204--