You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2003/06/05 20:30:47 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/util/sequence SequenceManagerNativeImpl.java
arminw 2003/06/05 11:30:47
Modified: src/test/org/apache/ojb/broker/sequence
NativeIdentifierTest.java
src/java/org/apache/ojb/broker/util/sequence
SequenceManagerNativeImpl.java
Log:
return always the same pseudo id
Revision Changes Path
1.3 +11 -3 db-ojb/src/test/org/apache/ojb/broker/sequence/NativeIdentifierTest.java
Index: NativeIdentifierTest.java
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/sequence/NativeIdentifierTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- NativeIdentifierTest.java 10 May 2003 18:21:19 -0000 1.2
+++ NativeIdentifierTest.java 5 Jun 2003 18:30:46 -0000 1.3
@@ -181,7 +181,7 @@
public void testSimpleInsert() throws Exception
{
- long timestamp = System.currentTimeMillis();
+ long timestamp = (long) (System.currentTimeMillis() * Math.random());
String name = "testSimpleInsert_" + timestamp;
if (skipTest()) return;
@@ -207,10 +207,18 @@
assertNotNull(obj_1.getIdentifier());
}
+ public void testAllInOne() throws Exception
+ {
+ testSimpleInsert();
+ testSimpleInsert();
+ testReferenceInsert();
+ testReferenceInsert();
+ }
+
public void testReferenceInsert() throws Exception
{
if (skipTest()) return;
- long timestamp = System.currentTimeMillis();
+ long timestamp = (long) (System.currentTimeMillis() * Math.random());
String name = "testReferenceInsert_main_" + timestamp;
String nameRef = "testReferenceInsert_reference_" + timestamp;
1.4 +16 -12 db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerNativeImpl.java
Index: SequenceManagerNativeImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerNativeImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SequenceManagerNativeImpl.java 15 May 2003 11:58:16 -0000 1.3
+++ SequenceManagerNativeImpl.java 5 Jun 2003 18:30:46 -0000 1.4
@@ -1,4 +1,5 @@
package org.apache.ojb.broker.util.sequence;
+
/* ====================================================================
* The Apache Software License, Version 1.1
*
@@ -52,6 +53,7 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ojb.broker.PersistenceBroker;
@@ -64,12 +66,12 @@
import java.math.BigDecimal;
import java.sql.Date;
+import java.sql.ResultSet;
import java.sql.SQLException;
+import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
-import java.sql.Statement;
-import java.sql.ResultSet;
import java.util.Iterator;
import java.util.Vector;
@@ -80,7 +82,7 @@
* <p>
* <b>Note:</b>
* The database identity column must not start with value '0' or
- * use negative values. So make sure oid generation starts with '1'
+ * use '-1' as identiy value. So make sure oid generation starts with '1'
* or higher.
* </p>
* <p>
@@ -119,15 +121,18 @@
{
private Log log = LogFactory.getLog(SequenceManagerNativeImpl.class);
/*
- TODO: find a better solution for this problem
+ TODO:
+ Find a better solution for this problem
We need this dummy field to return a negative long value
on getUniqueLong(...) call. If we return always the same
value, the resulting Identity object was found on cache.
+ arminw:
+ seems to work when always -1 was returned
Second problem is that generated oid (by Identity column)
must not begin with 0.
*/
- private static long idDummy;
+// private static long idDummy;
public SequenceManagerNativeImpl(PersistenceBroker broker)
{
@@ -142,7 +147,6 @@
}
-
public void setReferenceFKs(Object obj, ClassDescriptor cld) throws SequenceManagerException
{
Vector objectReferenceDescriptors = cld.getObjectReferenceDescriptors();
@@ -214,7 +218,7 @@
{
try
{
- if(stmt != null) stmt.close();
+ if (stmt != null) stmt.close();
}
catch (SQLException e)
{
@@ -224,14 +228,13 @@
else
{
throw new SequenceManagerException(
- "Field does not support autoincrement, please check repository: "+fd);
+ "Field does not support autoincrement, please check repository: " + fd);
}
return newId;
}
/*
- * query for the last insert id. Depends on the used database,
- * thus we sould move this to Platform classes in further versions
+ * query for the last insert id.
*/
protected String lastInsertSelect(String tableName)
{
@@ -362,6 +365,7 @@
*/
protected long getUniqueLong(FieldDescriptor field) throws SequenceManagerException
{
- return --idDummy;
+ // return --idDummy;
+ return -1;
}
}