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 2005/08/16 22:11:20 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/util/sequence AbstractSequenceManager.java package.html SequenceManager.java SequenceManagerHelper.java SequenceManagerHighLowImpl.java SequenceManagerInMemoryImpl.java SequenceManagerNextValImpl.java
arminw 2005/08/16 13:11:20
Modified: src/doc/forrest/src/documentation/content/xdocs/docu/guides
Tag: OJB_1_0_RELEASE repository.xml
sequencemanager.xml
src/doc/forrest/src/documentation/content/xdocs Tag:
OJB_1_0_RELEASE site.xml
src/java/org/apache/ojb/broker/platforms Tag:
OJB_1_0_RELEASE Platform.java PlatformDb2Impl.java
PlatformDefaultImpl.java PlatformOracleImpl.java
PlatformPostgreSQLImpl.java PlatformSapdbImpl.java
src/java/org/apache/ojb/broker/util/sequence Tag:
OJB_1_0_RELEASE AbstractSequenceManager.java
package.html SequenceManager.java
SequenceManagerHelper.java
SequenceManagerHighLowImpl.java
SequenceManagerInMemoryImpl.java
SequenceManagerNextValImpl.java
Log:
add new improvement OJB-66. Now it is possible to add additional properties used for database sequence creation.
Revision Changes Path
No revision
No revision
1.1.2.10 +2 -1 db-ojb/src/doc/forrest/src/documentation/content/xdocs/docu/guides/repository.xml
Index: repository.xml
===================================================================
RCS file: /home/cvs/db-ojb/src/doc/forrest/src/documentation/content/xdocs/docu/guides/repository.xml,v
retrieving revision 1.1.2.9
retrieving revision 1.1.2.10
diff -u -r1.1.2.9 -r1.1.2.10
--- repository.xml 8 Aug 2005 17:06:29 -0000 1.1.2.9
+++ repository.xml 16 Aug 2005 20:11:19 -0000 1.1.2.10
@@ -727,6 +727,7 @@
</section>
</section>
+ <anchor id="sequence-manager"/>
<section>
<title>sequence-manager</title>
<p>
1.1.2.4 +171 -34 db-ojb/src/doc/forrest/src/documentation/content/xdocs/docu/guides/sequencemanager.xml
Index: sequencemanager.xml
===================================================================
RCS file: /home/cvs/db-ojb/src/doc/forrest/src/documentation/content/xdocs/docu/guides/sequencemanager.xml,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- sequencemanager.xml 9 Mar 2005 15:23:05 -0000 1.1.2.3
+++ sequencemanager.xml 16 Aug 2005 20:11:19 -0000 1.1.2.4
@@ -159,9 +159,8 @@
/>
<sequence-manager className="org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl">
- <attribute attribute-name="grabSize" attribute-value="5"/>
- <attribute attribute-name="globalSequenceId" attribute-value="false"/>
- <attribute attribute-name="globalSequenceStart" attribute-value="10000"/>
+ <attribute attribute-name="seq.start" attribute-value="10000"/>
+ <attribute attribute-name="grabSize" attribute-value="20"/>
</sequence-manager>
</jdbc-connection-descriptor>]]></source>
<p>
@@ -209,21 +208,37 @@
<em>global mode</em>, generate global unique id's.
</p>
<p>
- This implementation needs an internal database table and object mapping declaration
- to persist the used sequences (see
- <link href="site:repository/introduction">OJB internal mapping</link> for more info).
+ This implementation <strong>needs an internal database table and object mapping declaration</strong>
+ to persist the used sequences. The table structure can be found in
+ <link href="site:platform/internal-tables">in platform guide</link> the object metadata mapping
+ can be found in <link href="ext:repository_internal.xml">OJB internal mapping file
+ (called <em>repository_internal.xml</em>)</link>.
+ </p>
+ <p>
+ To declare this <em>sequence manager</em> implementation specify a <code>sequence-manager</code>
+ element within the
+ <link href="site:repository/jdbc-connection-descriptor">jdbc-connection-descriptor</link>:
</p>
<source><![CDATA[
<sequence-manager className=
"org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl">
+ <attribute attribute-name="seq.start" attribute-value="5000"/>
<attribute attribute-name="grabSize" attribute-value="20"/>
- <attribute attribute-name="sequenceStart" attribute-value="0"/>
- <attribute attribute-name="globalSequenceId" attribute-value="false"/>
- <attribute attribute-name="globalSequenceStart" attribute-value="10000"/>
<attribute attribute-name="autoNaming" attribute-value="true"/>
+ <attribute attribute-name="globalSequenceId" attribute-value="false"/>
+ <!-- deprecated settings -->
+ <attribute attribute-name="sequenceStart" attribute-value="5000"/>
</sequence-manager>]]></source>
<p>
+ The property
+ <code>seq.start</code> (or deprecated <code>sequenceStart</code>) define
+ the start value of the
+ id generation (default was '1'). It's recommended to use start values
+ greater than '0' to avoid problems with primitive primary key fields when
+ used as foreign key in references.
+ </p>
+ <p>
With property
<code>grabSize</code> you set the size of the assigned ID's kept
in memory for each <em>autoincrement</em> field. If the assigned ID's
@@ -233,23 +248,15 @@
If OJB was shutdown/redeployed all unused assigned ID's are lost.
</p>
<p>
- The attribute
- <code>sequenceStart</code> define the start value of the
- id generation (default was '1'). It's recommended to use start values
- greater than '0' to avoid problems with primitive primary key fields.
- </p>
- <p>
If property
<code>globalSequenceId</code> was set
<code>true</code> you will
get global unique ID's over all persistent objects. Default was
<code>false</code>.
- </p>
- <p>
- The attribute
- <code>globalSequenceStart</code> define the start value of the
- global id generation (default was 10000). <em>This property is deprecated, please use
- property 'sequenceStart' instead</em>.
+ <br/>
+ NOTE: If the database is already populated or the global sequence name
+ in <em>OJB_HL_SEQ</em> database table was removed (by accident), the <em>seq.start</em>
+ value must be greater than the biggest PK value in database.
</p>
<p>
This sequence manager implementation supports <em>user defined
@@ -292,16 +299,23 @@
<link href="site:advanced-technique/extents"><em>extents</em></link>,
using the same mechanism as the High/Low sequence manager implementation.
</p>
+ <p>
+ To declare this <em>sequence manager</em> implementation specify a <code>sequence-manager</code>
+ element within the
+ <link href="site:repository/jdbc-connection-descriptor">jdbc-connection-descriptor</link>:
+ </p>
<source><![CDATA[
<sequence-manager className="org.apache.ojb.broker.util.sequence.SequenceManagerInMemoryImpl">
- <attribute attribute-name="sequenceStart" attribute-value="0"/>
+ <attribute attribute-name="seq.start" attribute-value="0"/>
<attribute attribute-name="autoNaming" attribute-value="true"/>
</sequence-manager>]]></source>
<p>
- The attribute
- <code>sequenceStart</code> define the start value of the
+ The property
+ <code>seq.start</code> (or deprecated <code>sequenceStart</code>) define
+ the start value of the
id generation (default was '1'). It's recommended to use start values
- greater than '0' to avoid problems with primitive primary key fields.
+ greater than '0' to avoid problems with primitive primary key fields when
+ used as foreign key in references.
</p>
<p>
This sequence manager implementation supports <em>user defined
@@ -314,11 +328,21 @@
More info about <link href="#auto-naming">autoNaming</link>.
</p>
<p>
+ The specified sequences will only be used <em>in memory</em>. First time a sequence was used
+ OJB does a <code>select max</code>-query to find the latest/greatest value for the
+ autoincrement field and use this as starting point for further <em>in-memory</em> key generation.
+ </p>
+ <p>
This is the fastest standard sequence manager implementation and should work
- with all databases without any specific preparation, but has some Limitations:
+ with all databases without any specific preparation, but has some Limitations.
+ </p>
+ <p>
+ Limitations:
<br/>- do not use in clustered environments
<br/>- superfluously to mention, do not use (or handle with care) if other non-OJB
applications insert objects too
+ <br/>- only declare "number" fields as <em>autoincrement</em> fields (because e.g. "select max ...
+ does not work with CHAR columns in the used manner)
</p>
</section>
@@ -331,10 +355,6 @@
you can use the <code>SequenceManagerNextValImpl</code> implementation to force generation
of the sequence keys by your database.
</p>
- <source><![CDATA[
-<sequence-manager className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl">
- <attribute attribute-name="autoNaming" attribute-value="true"/>
-</sequence-manager>]]></source>
<p>
Database based sequences (sequence objects, sequence generators) are special
(single-row) tables in the database created with an specific statement,
@@ -346,6 +366,24 @@
in the <link href="site:repository/field-descriptor">field-descriptor</link>
</p>
<p>
+ To declare this <em>sequence manager</em> implementation specify a <code>sequence-manager</code>
+ element within the
+ <link href="site:repository/jdbc-connection-descriptor">jdbc-connection-descriptor</link>:
+ </p>
+ <source><![CDATA[
+<sequence-manager className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl">
+ <attribute attribute-name="seq.start" attribute-value="200000"/>
+ <attribute attribute-name="autoNaming" attribute-value="true"/>
+
+ <!-- optional attributes supported by Oracle, PostgreSQL, MaxDB/SapDB, DB2 -->
+ <!-- attribute attribute-name="seq.incrementBy" attribute-value="1"/ -->
+ <!-- attribute attribute-name="seq.maxValue" attribute-value="999999999999999999999999999"/ -->
+ <!-- attribute attribute-name="seq.minValue" attribute-value="1"/ -->
+ <!-- attribute attribute-name="seq.cycle" attribute-value="false"/ -->
+ <!-- attribute attribute-name="seq.cache" attribute-value="20"/ -->
+ <!-- attribute attribute-name="seq.order" attribute-value="false"/ -->
+</sequence-manager>]]></source>
+ <p>
Attribute
<code>autoNaming</code>, default setting is <em>true</em>. If set <em>true</em> OJB will
try to auto-generate a sequence name if none was found in
@@ -362,6 +400,102 @@
for a given sequence name (specified in <em>field-descriptor</em>) no database sequence
can be found.
</p>
+ <p>
+ The table below show additional <em>sequence properties</em>. To specifiy the properties
+ use <link href="site:repository/custom-attribute">custom-attributes</link>
+ within the <link href="site:repository/sequence-manager">sequence-manager</link> element.
+ <br/>
+ The database sequence specific properties are generally speaking, see database user guide
+ for detailed description.
+ </p>
+ <table>
+ <tr>
+ <th>Name</th>
+ <th>Value</th>
+ <th>Description</th>
+ <th>Supported By</th>
+ </tr>
+ <tr>
+ <td>seq.start</td>
+ <td>1 ... max INTEGER</td>
+ <td>
+ Database sequence specific property.<br/>
+ Specifies the first sequence number to be
+ generated. Allowed: <em>1</em> or greater.
+ </td>
+ <td>Oracle, PostgreSQL, MaxDB/SapDB, DB2</td>
+ </tr>
+ <tr>
+ <td>seq.incrementBy</td>
+ <td>>=1</td>
+ <td>
+ Database sequence specific property.<br/>
+ Specifies the interval between sequence numbers.
+ This value can be any positive or negative
+ integer, but it cannot be 0.
+ <br/>
+ <em>Decrement sequences are currently not supported</em>
+ </td>
+ <td>Oracle, PostgreSQL, MaxDB/SapDB, DB2</td>
+ </tr>
+ <tr>
+ <td>seq.maxValue</td>
+ <td>1 ... max INTEGER</td>
+ <td>
+ Database sequence specific property.<br/>
+ Set max value for sequence numbers.
+ </td>
+ <td>Oracle, PostgreSQL, MaxDB/SapDB, DB2</td>
+ </tr>
+ <tr>
+ <td>seq.minValue</td>
+ <td>min INTEGER</td>
+ <td>
+ Database sequence specific property.<br/>
+ Set min value for sequence numbers.
+ <br/>
+ <em>Negative sequences are not tested as yet.</em>
+ </td>
+ <td>Oracle, PostgreSQL, MaxDB/SapDB, DB2</td>
+ </tr>
+ <tr>
+ <td>seq.cycle</td>
+ <td>true/false</td>
+ <td>
+ Database sequence specific property.<br/>
+ If <em>true</em>, specifies that the sequence continues to generate
+ values after reaching either its maximum or minimum value.
+ <br/>
+ If <em>false</em>, specifies that the sequence cannot generate more values after
+ reaching its maximum or minimum value.
+ </td>
+ <td>Oracle, PostgreSQL, MaxDB/SapDB, DB2</td>
+ </tr>
+ <tr>
+ <td>seq.cache</td>
+ <td>>= 2</td>
+ <td>
+ Database sequence specific property.<br/>
+ Specifies how many values of the sequence Oracle
+ preallocates and keeps in memory for faster access.
+ Allowed values: <em>2</em> or greater. If set <em>0</em>,
+ an explicite <em>nocache</em> expression will be set.
+ </td>
+ <td>Oracle, PostgreSQL, MaxDB/SapDB, DB2</td>
+ </tr>
+ <tr>
+ <td>seq.order</td>
+ <td>true/false</td>
+ <td>
+ Database sequence specific property.<br/>
+ If set <em>true</em>, guarantees that sequence numbers
+ are generated in order of request.
+ <br/>
+ If <em>false</em>, a <em>no order</em> expression will be set.
+ </td>
+ <td>Oracle, MaxDB/SapDB, DB2</td>
+ </tr>
+ </table>
<source><![CDATA[
<class-descriptor
class="org.greatest.software.Person"
@@ -816,7 +950,7 @@
<em>extent aware</em> mean?
</title>
<p>
- Say we have a abstract base class
+ Say we have an abstract base class
<code>Animal</code> and two classes
<code>Dog</code> and
<code>Cat</code>
@@ -826,9 +960,12 @@
<link href="site:advanced-technique/polymorphism">declare the inheritance</link> in OJB.
<br/>
Now it is possible to do a query like
- <em>give me all animals</em>. To make this working in OJB
+ <em>give me all animals</em> and OJB will return all <code>Cat</code> and <code>Dog</code>
+ objects. To make this working in OJB
the ID's of <code>Dog</code> and <code>Cat</code> objects must be unique across the
- tables of both classes or else you may not get a vaild query result.
+ tables of both classes or else you may not get a vaild query result (e.g. you can't
+ query for the <code>Animal</code> with <em>id=23</em>, because in both tables such an id
+ can exist).
<br/>
The reason for this behaviour is the
<link href="ext:identity"><code>org.apache.ojb.broker.Identity</code></link>
No revision
No revision
1.3.2.18 +2 -1 db-ojb/src/doc/forrest/src/documentation/content/xdocs/site.xml
Index: site.xml
===================================================================
RCS file: /home/cvs/db-ojb/src/doc/forrest/src/documentation/content/xdocs/site.xml,v
retrieving revision 1.3.2.17
retrieving revision 1.3.2.18
diff -u -r1.3.2.17 -r1.3.2.18
--- site.xml 2 Jul 2005 00:58:16 -0000 1.3.2.17
+++ site.xml 16 Aug 2005 20:11:19 -0000 1.3.2.18
@@ -131,6 +131,7 @@
<custom-attribute href="#custom-attribute"/>
<collection-descriptor href="#collection-descriptor"/>
<reference-descriptor href="#reference-descriptor"/>
+ <sequence-manager href="#sequence-manager"/>
<query-customizer href="#query-customizer"/>
</repository>
<basic-technique label="Basic mapping" href="basic-technique.html">
No revision
No revision
1.24.2.4 +18 -7 db-ojb/src/java/org/apache/ojb/broker/platforms/Platform.java
Index: Platform.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/Platform.java,v
retrieving revision 1.24.2.3
retrieving revision 1.24.2.4
diff -u -r1.24.2.3 -r1.24.2.4
--- Platform.java 4 Jun 2005 14:13:43 -0000 1.24.2.3
+++ Platform.java 16 Aug 2005 20:11:19 -0000 1.24.2.4
@@ -24,6 +24,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import java.util.Properties;
/**
* This interface provides callbacks that allow to perform
@@ -141,7 +142,17 @@
/**
* Returns a query to create a sequence entry.
+ *
+ * @param sequenceName
+ * @param prop
+ * @return a sql string to create a sequence
+ */
+ String createSequenceQuery(String sequenceName, Properties prop);
+
+ /**
+ * Returns a query to create a sequence entry.
* @return a sql string to create a sequence
+ * @deprecated use {@link #createSequenceQuery(String)} instead.
*/
String createSequenceQuery(String sequenceName);
@@ -184,23 +195,23 @@
/**
* Answer true if LIMIT or equivalent is supported
* <b> SQL-Paging is not yet supported </b>
- * @return
+ * @return
*/
boolean supportsPaging();
-
+
/**
* Add the LIMIT or equivalent to the SQL
* <b> SQL-Paging is not yet supported </b>
*/
void addPagingSql(StringBuffer anSqlString);
-
+
/**
* Answer true if the LIMIT parameters are bound before the query parameters
* <b> SQL-Paging is not yet supported </b>
* @return
*/
boolean bindPagingParametersFirst();
-
+
/**
* Bind the Paging Parameters
* <b> SQL-Paging is not yet supported </b>
@@ -211,7 +222,7 @@
* @return
*/
int bindPagingParameters(PreparedStatement ps, int index, int startAt, int endAt) throws SQLException;
-
+
/**
* Concatenate the columns </br>
* ie: col1 || col2 || col3 (ANSI)</br>
@@ -222,7 +233,7 @@
* @return the concatenated String
*/
String concatenate(String[] theColumns);
-
+
/**
* Answer the Clause used Escape wildcards in LIKE
* @param aCriteria
1.10.2.1 +156 -10 db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformDb2Impl.java
Index: PlatformDb2Impl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformDb2Impl.java,v
retrieving revision 1.10
retrieving revision 1.10.2.1
diff -u -r1.10 -r1.10.2.1
--- PlatformDb2Impl.java 4 Apr 2004 23:53:35 -0000 1.10
+++ PlatformDb2Impl.java 16 Aug 2005 20:11:19 -0000 1.10.2.1
@@ -18,11 +18,102 @@
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
+import java.util.Properties;
+
+import org.apache.ojb.broker.util.sequence.SequenceManagerHelper;
/**
* This class extends <code>PlatformDefaultImpl</code> and defines specific
* behavior for the DB2 platform.
*
+ * <p/>
+ * Many of the database sequence specific properties can be specified using
+ * <em>custom attributes</em> within the <em>sequence-manager</em> element.
+ * <br/>
+ * The database sequence specific properties are generally speaking, see database user guide
+ * for detailed description.
+ *
+ * <p>
+ * Implementation configuration properties:
+ * </p>
+ *
+ * <table cellspacing="2" cellpadding="2" border="3" frame="box">
+ * <tr>
+ * <td><strong>Property Key</strong></td>
+ * <td><strong>Property Values</strong></td>
+ * </tr>
+ * <tr>
+ * <td>sequenceStart</td>
+ * <td>
+ * DEPRECATED. Database sequence specific property.<br/>
+ * Specifies the first sequence number to be
+ * generated. Allowed: <em>1</em> or greater.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.start</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Specifies the first sequence number to be
+ * generated. Allowed: <em>1</em> or greater.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.incrementBy</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Specifies the interval between sequence numbers.
+ * This value can be any positive or negative
+ * integer, but it cannot be 0.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.maxValue</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Set max value for sequence numbers.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.minValue</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Set min value for sequence numbers.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.cycle</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * If <em>true</em>, specifies that the sequence continues to generate
+ * values after reaching either its maximum or minimum value.
+ * <br/>
+ * If <em>false</em>, specifies that the sequence cannot generate more values after
+ * reaching its maximum or minimum value.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.cache</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Specifies how many values of the sequence Oracle
+ * preallocates and keeps in memory for faster access.
+ * Allowed values: <em>2</em> or greater. If set <em>0</em>,
+ * an explicite <em>nocache</em> expression will be set.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.order</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * If set <em>true</em>, guarantees that sequence numbers
+ * are generated in order of request.
+ * <br/>
+ * If <em>false</em>, a <em>no order</em> expression will be set.
+ * </td>
+ * </tr>
+ * </table>
+ *
* @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
* @version $Id$
*/
@@ -50,6 +141,61 @@
return "create sequence " + sequenceName;
}
+ public String createSequenceQuery(String sequenceName, Properties prop)
+ {
+ StringBuffer query = new StringBuffer(createSequenceQuery(sequenceName));
+ if(prop != null)
+ {
+ Boolean b;
+ Long value;
+
+ value = SequenceManagerHelper.getSeqIncrementBy(prop);
+ if(value != null)
+ {
+ query.append(" INCREMENT BY ").append(value.longValue());
+ }
+
+ value = SequenceManagerHelper.getSeqStart(prop);
+ if(value != null)
+ {
+ query.append(" START WITH ").append(value.longValue());
+ }
+
+ value = SequenceManagerHelper.getSeqMaxValue(prop);
+ if(value != null)
+ {
+ query.append(" MAXVALUE ").append(value.longValue());
+ }
+
+ value = SequenceManagerHelper.getSeqMinValue(prop);
+ if(value != null)
+ {
+ query.append(" MINVALUE ").append(value.longValue());
+ }
+
+ b = SequenceManagerHelper.getSeqCycleValue(prop);
+ if(b != null)
+ {
+ if(b.booleanValue()) query.append(" CYCLE");
+ else query.append(" NO CYCLE");
+ }
+
+ value = SequenceManagerHelper.getSeqCacheValue(prop);
+ if(value != null)
+ {
+ query.append(" CACHE ").append(value.longValue());
+ }
+
+ b = SequenceManagerHelper.getSeqOrderValue(prop);
+ if(b != null)
+ {
+ if(b.booleanValue()) query.append(" ORDER");
+ else query.append(" NO ORDER");
+ }
+ }
+ return query.toString();
+ }
+
public String nextSequenceQuery(String sequenceName)
{
return "values nextval for "+ sequenceName;
@@ -59,13 +205,13 @@
{
return "drop sequence " + sequenceName;
}
-
- public String getLastInsertIdentityQuery(String tableName)
- {
- // matthias.roth@impart.ch
- // the function is used by the org.apache.ojb.broker.util.sequence.SequenceManagerNativeImpl
- // this call must be made before commit the insert cammand, so you
- // must turn off autocommit by seting the useAutoCommit="2"
- return "select IDENTITY_VAL_LOCAL() from sysibm.sysdummy1";
- }
+
+ public String getLastInsertIdentityQuery(String tableName)
+ {
+ // matthias.roth@impart.ch
+ // the function is used by the org.apache.ojb.broker.util.sequence.SequenceManagerNativeImpl
+ // this call must be made before commit the insert cammand, so you
+ // must turn off autocommit by seting the useAutoCommit="2"
+ return "select IDENTITY_VAL_LOCAL() from sysibm.sysdummy1";
+ }
}
1.27.2.5 +9 -4 db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java
Index: PlatformDefaultImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java,v
retrieving revision 1.27.2.4
retrieving revision 1.27.2.5
diff -u -r1.27.2.4 -r1.27.2.5
--- PlatformDefaultImpl.java 24 Jul 2005 23:39:42 -0000 1.27.2.4
+++ PlatformDefaultImpl.java 16 Aug 2005 20:11:19 -0000 1.27.2.5
@@ -24,6 +24,7 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
+import java.util.Properties;
import org.apache.ojb.broker.PersistenceBrokerException;
import org.apache.ojb.broker.accesslayer.JoinSyntaxTypes;
@@ -66,7 +67,7 @@
{
if (!m_batchUpdatesChecked)
{
- DatabaseMetaData meta = null;
+ DatabaseMetaData meta;
try
{
meta = conn.getMetaData();
@@ -297,6 +298,11 @@
return false;
}
+ public String createSequenceQuery(String sequenceName, Properties prop)
+ {
+ return createSequenceQuery(sequenceName);
+ }
+
/**
* Override this method to enable database based sequence generation
*/
@@ -398,7 +404,7 @@
{
if (i > 0)
{
- buf.append(" " + concatChar + " ");
+ buf.append(" ").append(concatChar).append(" ");
}
buf.append(theColumns[i]);
}
@@ -432,5 +438,4 @@
{
stmt.registerOutParameter(position, Types.OTHER);
}
-
}
1.20.2.4 +161 -6 db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformOracleImpl.java
Index: PlatformOracleImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformOracleImpl.java,v
retrieving revision 1.20.2.3
retrieving revision 1.20.2.4
diff -u -r1.20.2.3 -r1.20.2.4
--- PlatformOracleImpl.java 6 Apr 2005 13:29:33 -0000 1.20.2.3
+++ PlatformOracleImpl.java 16 Aug 2005 20:11:19 -0000 1.20.2.4
@@ -18,6 +18,7 @@
import org.apache.ojb.broker.util.logging.Logger;
import org.apache.ojb.broker.util.logging.LoggerFactory;
import org.apache.ojb.broker.util.ClassHelper;
+import org.apache.ojb.broker.util.sequence.SequenceManagerHelper;
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
@@ -33,11 +34,100 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
+import java.util.Properties;
/**
* This class is a concrete implementation of <code>Platform</code>. Provides an implementation
- * that works around some issues with Oracle in general and Oracle's Thin driver in particular..
- *
+ * that works around some issues with Oracle in general and Oracle's Thin driver in particular.
+ *
+ * <p/>
+ * Many of the database sequence specific properties can be specified using
+ * <em>custom attributes</em> within the <em>sequence-manager</em> element.
+ * <br/>
+ * The database sequence specific properties are generally speaking, see database user guide
+ * for detailed description.
+ *
+ * <p>
+ * Implementation configuration properties:
+ * </p>
+ *
+ * <table cellspacing="2" cellpadding="2" border="3" frame="box">
+ * <tr>
+ * <td><strong>Property Key</strong></td>
+ * <td><strong>Property Values</strong></td>
+ * </tr>
+ * <tr>
+ * <td>sequenceStart</td>
+ * <td>
+ * DEPRECATED. Database sequence specific property.<br/>
+ * Specifies the first sequence number to be
+ * generated. Allowed: <em>1</em> or greater.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.start</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Specifies the first sequence number to be
+ * generated. Allowed: <em>1</em> or greater.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.incrementBy</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Specifies the interval between sequence numbers.
+ * This value can be any positive or negative
+ * integer, but it cannot be 0.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.maxValue</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Set max value for sequence numbers.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.minValue</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Set min value for sequence numbers.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.cycle</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * If <em>true</em>, specifies that the sequence continues to generate
+ * values after reaching either its maximum or minimum value.
+ * <br/>
+ * If <em>false</em>, specifies that the sequence cannot generate more values after
+ * reaching its maximum or minimum value.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.cache</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Specifies how many values of the sequence Oracle
+ * preallocates and keeps in memory for faster access.
+ * Allowed values: <em>2</em> or greater. If set <em>0</em>,
+ * an explicite <em>nocache</em> expression will be set.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.order</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * If set <em>true</em>, guarantees that sequence numbers
+ * are generated in order of request.
+ * <br/>
+ * If <em>false</em>, a <em>no order</em> expression will be set.
+ * </td>
+ * </tr>
+ * </table>
+ *
* @author <a href="mailto:thma@apache.org">Thomas Mahler <a>
* @version $Id$
*/
@@ -149,8 +239,8 @@
}
else if (sqlType == Types.CLOB && (value instanceof String || value instanceof byte[]))
{
- Reader reader = null;
- int length = 0;
+ Reader reader;
+ int length;
if (value instanceof String)
{
String stringValue = (String) value;
@@ -226,7 +316,72 @@
public String createSequenceQuery(String sequenceName)
{
- return "create sequence " + sequenceName;
+ return "CREATE SEQUENCE " + sequenceName;
+ }
+
+ public String createSequenceQuery(String sequenceName, Properties prop)
+ {
+ /*
+ CREATE SEQUENCE [schema.]sequence
+ [INCREMENT BY integer]
+ [START WITH integer]
+ [MAXVALUE integer | NOMAXVALUE]
+ [MINVALUE integer | NOMINVALUE]
+ [CYCLE | NOCYCLE]
+ [CACHE integer | NOCACHE]
+ [ORDER | NOORDER]
+ */
+ StringBuffer query = new StringBuffer(createSequenceQuery(sequenceName));
+ if(prop != null)
+ {
+ Boolean b;
+ Long value;
+
+ value = SequenceManagerHelper.getSeqIncrementBy(prop);
+ if(value != null)
+ {
+ query.append(" INCREMENT BY ").append(value.longValue());
+ }
+
+ value = SequenceManagerHelper.getSeqStart(prop);
+ if(value != null)
+ {
+ query.append(" START WITH ").append(value.longValue());
+ }
+
+ value = SequenceManagerHelper.getSeqMaxValue(prop);
+ if(value != null)
+ {
+ query.append(" MAXVALUE ").append(value.longValue());
+ }
+
+ value = SequenceManagerHelper.getSeqMinValue(prop);
+ if(value != null)
+ {
+ query.append(" MINVALUE ").append(value.longValue());
+ }
+
+ b = SequenceManagerHelper.getSeqCycleValue(prop);
+ if(b != null)
+ {
+ if(b.booleanValue()) query.append(" CYCLE");
+ else query.append(" NOCYCLE");
+ }
+
+ value = SequenceManagerHelper.getSeqCacheValue(prop);
+ if(value != null)
+ {
+ query.append(" CACHE ").append(value.longValue());
+ }
+
+ b = SequenceManagerHelper.getSeqOrderValue(prop);
+ if(b != null)
+ {
+ if(b.booleanValue()) query.append(" ORDER");
+ else query.append(" NOORDER");
+ }
+ }
+ return query.toString();
}
public String nextSequenceQuery(String sequenceName)
1.10.2.1 +151 -9 db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformPostgreSQLImpl.java
Index: PlatformPostgreSQLImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformPostgreSQLImpl.java,v
retrieving revision 1.10
retrieving revision 1.10.2.1
diff -u -r1.10 -r1.10.2.1
--- PlatformPostgreSQLImpl.java 25 Jun 2004 13:11:35 -0000 1.10
+++ PlatformPostgreSQLImpl.java 16 Aug 2005 20:11:19 -0000 1.10.2.1
@@ -18,13 +18,103 @@
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
+import java.util.Properties;
import org.apache.ojb.broker.query.LikeCriteria;
+import org.apache.ojb.broker.util.sequence.SequenceManagerHelper;
/**
* This class extends <code>PlatformDefaultImpl</code> and defines specific
* behavior for the PostgreSQL platform.
*
+ * <p/>
+ * Many of the database sequence specific properties can be specified using
+ * <em>custom attributes</em> within the <em>sequence-manager</em> element.
+ * <br/>
+ * The database sequence specific properties are generally speaking, see database user guide
+ * for detailed description.
+ *
+ * <p>
+ * Implementation configuration properties:
+ * </p>
+ *
+ * <table cellspacing="2" cellpadding="2" border="3" frame="box">
+ * <tr>
+ * <td><strong>Property Key</strong></td>
+ * <td><strong>Property Values</strong></td>
+ * </tr>
+ * <tr>
+ * <td>sequenceStart</td>
+ * <td>
+ * DEPRECATED. Database sequence specific property.<br/>
+ * Specifies the first sequence number to be
+ * generated. Allowed: <em>1</em> or greater.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.start</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Specifies the first sequence number to be
+ * generated. Allowed: <em>1</em> or greater.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.incrementBy</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Specifies the interval between sequence numbers.
+ * This value can be any positive or negative
+ * integer, but it cannot be 0.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.maxValue</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Set max value for sequence numbers.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.minValue</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Set min value for sequence numbers.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.cycle</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * If <em>true</em>, specifies that the sequence continues to generate
+ * values after reaching either its maximum or minimum value.
+ * <br/>
+ * If <em>false</em>, specifies that the sequence cannot generate more values after
+ * reaching its maximum or minimum value.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.cache</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Specifies how many values of the sequence Oracle
+ * preallocates and keeps in memory for faster access.
+ * Allowed values: <em>2</em> or greater. If set <em>0</em>,
+ * an explicite <em>nocache</em> expression will be set.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.order</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * If set <em>true</em>, guarantees that sequence numbers
+ * are generated in order of request.
+ * <br/>
+ * If <em>false</em>, a <em>no order</em> expression will be set.
+ * </td>
+ * </tr>
+ * </table>
+ *
* @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
* @version $Id$
*/
@@ -48,6 +138,58 @@
return "create sequence " + sequenceName;
}
+ public String createSequenceQuery(String sequenceName, Properties prop)
+ {
+ /*
+ CREATE [ TEMPORARY | TEMP ] SEQUENCE seqname [ INCREMENT increment ]
+ [ MINVALUE minvalue ] [ MAXVALUE maxvalue ]
+ [ START start ] [ CACHE cache ] [ CYCLE ]
+ */
+ StringBuffer query = new StringBuffer(createSequenceQuery(sequenceName));
+ if(prop != null)
+ {
+ Boolean b;
+ Long value;
+
+ value = SequenceManagerHelper.getSeqIncrementBy(prop);
+ if(value != null)
+ {
+ query.append(" INCREMENT ").append(value.longValue());
+ }
+
+ value = SequenceManagerHelper.getSeqMinValue(prop);
+ if(value != null)
+ {
+ query.append(" MINVALUE ").append(value.longValue());
+ }
+
+ value = SequenceManagerHelper.getSeqMaxValue(prop);
+ if(value != null)
+ {
+ query.append(" MAXVALUE ").append(value.longValue());
+ }
+
+ value = SequenceManagerHelper.getSeqStart(prop);
+ if(value != null)
+ {
+ query.append(" START ").append(value.longValue());
+ }
+
+ value = SequenceManagerHelper.getSeqCacheValue(prop);
+ if(value != null)
+ {
+ query.append(" CACHE ").append(value.longValue());
+ }
+
+ b = SequenceManagerHelper.getSeqCycleValue(prop);
+ if(b != null)
+ {
+ if(b.booleanValue()) query.append(" CYCLE");
+ }
+ }
+ return query.toString();
+ }
+
public String nextSequenceQuery(String sequenceName)
{
return "select nextval('" + sequenceName + "')";
@@ -57,18 +199,18 @@
{
return "drop sequence " + sequenceName;
}
-
+
/* (non-Javadoc)
- * @see org.apache.ojb.broker.platforms.Platform#addPagingSql(java.lang.StringBuffer)
- */
+ * @see org.apache.ojb.broker.platforms.Platform#addPagingSql(java.lang.StringBuffer)
+ */
public void addPagingSql(StringBuffer anSqlString)
{
anSqlString.append(" LIMIT ? OFFSET ?");
}
-
+
/* (non-Javadoc)
- * @see org.apache.ojb.broker.platforms.Platform#supportsPaging()
- */
+ * @see org.apache.ojb.broker.platforms.Platform#supportsPaging()
+ */
public boolean supportsPaging()
{
return true;
@@ -91,7 +233,7 @@
*/
public String getEscapeClause(LikeCriteria aCriteria)
{
- if (LikeCriteria.getEscapeCharacter() != LikeCriteria.DEFAULT_ESCPAPE_CHARACTER)
+ if (LikeCriteria.getEscapeCharacter() != LikeCriteria.DEFAULT_ESCPAPE_CHARACTER)
{
// the default escape character is \, so there's no need for an escape clause
return super.getEscapeClause(aCriteria);
@@ -100,5 +242,5 @@
{
return "";
}
- }
+ }
}
1.10.2.2 +174 -55 db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformSapdbImpl.java
Index: PlatformSapdbImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformSapdbImpl.java,v
retrieving revision 1.10.2.1
retrieving revision 1.10.2.2
diff -u -r1.10.2.1 -r1.10.2.2
--- PlatformSapdbImpl.java 4 Jun 2005 14:13:43 -0000 1.10.2.1
+++ PlatformSapdbImpl.java 16 Aug 2005 20:11:19 -0000 1.10.2.2
@@ -18,54 +18,107 @@
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
+import java.util.Properties;
+
+import org.apache.ojb.broker.util.sequence.SequenceManagerHelper;
/**
- * SapDB specific Platform implementation
- * @author Justin A. Stanczak
- * @author Matthew Baird (mattb
+ * SapDB specific Platform implementation.
+ *
+ * <p/>
+ * Many of the database sequence specific properties can be specified using
+ * <em>custom attributes</em> within the <em>sequence-manager</em> element.
+ * <br/>
+ * The database sequence specific properties are generally speaking, see database user guide
+ * for detailed description.
+ *
+ * <p>
+ * Implementation configuration properties:
+ * </p>
+ *
+ * <table cellspacing="2" cellpadding="2" border="3" frame="box">
+ * <tr>
+ * <td><strong>Property Key</strong></td>
+ * <td><strong>Property Values</strong></td>
+ * </tr>
+ * <tr>
+ * <td>sequenceStart</td>
+ * <td>
+ * DEPRECATED. Database sequence specific property.<br/>
+ * Specifies the first sequence number to be
+ * generated. Allowed: <em>1</em> or greater.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.start</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Specifies the first sequence number to be
+ * generated. Allowed: <em>1</em> or greater.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.incrementBy</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Specifies the interval between sequence numbers.
+ * This value can be any positive or negative
+ * integer, but it cannot be 0.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.maxValue</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Set max value for sequence numbers.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.minValue</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Set min value for sequence numbers.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.cycle</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * If <em>true</em>, specifies that the sequence continues to generate
+ * values after reaching either its maximum or minimum value.
+ * <br/>
+ * If <em>false</em>, specifies that the sequence cannot generate more values after
+ * reaching its maximum or minimum value.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.cache</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Specifies how many values of the sequence Oracle
+ * preallocates and keeps in memory for faster access.
+ * Allowed values: <em>2</em> or greater. If set <em>0</em>,
+ * an explicite <em>nocache</em> expression will be set.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>seq.order</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * If set <em>true</em>, guarantees that sequence numbers
+ * are generated in order of request.
+ * <br/>
+ * If <em>false</em>, a <em>no order</em> expression will be set.
+ * </td>
+ * </tr>
+ * </table>
+ *
+ * @author Justin A. Stanczak
+ * @author Matthew Baird (mattb
* @version $Id$
*/
public class PlatformSapdbImpl extends PlatformDefaultImpl
{
-// arminw: Check is not necessary any longer
-// final String msgCallableStatement = "Can't check maxDB/sapDB driver for CallableStatement, will return false";
-// static final String SAP_FIELD_NAME_1 = "parseinfo";
-// static final String SAP_FIELD_NAME_2 = "isDBProc";
-//
-// public boolean isCallableStatement(PreparedStatement stmt)
-// {
-// if(super.isCallableStatement(stmt))
-// {
-// /*
-// arminw: TODO: this is a really bad hook into the maxDB-driver
-// to detect CallableStatement. It's based on two non-public driver-class fields!!
-// Thus we can't guarantee that it will work with next/older driver version (7.6.00.00.3360).
-// If a security manager is used this hook could cause problems.
-// Recommend to do a redesign of StatementManager interface to avoid this check
-// on Platform class.
-// */
-// try
-// {
-// Field fld = stmt.getClass().getDeclaredField(SAP_FIELD_NAME_1);
-// fld.setAccessible(true);
-// Object parseInfo = fld.get(stmt);
-// fld = parseInfo.getClass().getDeclaredField(SAP_FIELD_NAME_2);
-// fld.setAccessible(true);
-// Boolean result = (Boolean) fld.get(parseInfo);
-// return result.booleanValue();
-// }
-// catch(Exception e)
-// {
-// if(log.isEnabledFor(Logger.WARN)) log.warn(msgCallableStatement, e);
-// return false;
-// }
-// }
-// else
-// {
-// return false;
-// }
-// }
-
public void setObjectForStatement(
PreparedStatement ps,
int index,
@@ -73,7 +126,7 @@
int sqlType)
throws SQLException
{
- if (((sqlType == Types.VARBINARY) || (sqlType == Types.LONGVARBINARY))
+ if(((sqlType == Types.VARBINARY) || (sqlType == Types.LONGVARBINARY))
&& (value instanceof byte[]))
{
byte buf[] = (byte[]) value;
@@ -85,7 +138,8 @@
}
}
- /** Get join syntax type for this RDBMS - one on of the constants from JoinSyntaxType interface
+ /**
+ * Get join syntax type for this RDBMS - one on of the constants from JoinSyntaxType interface
*/
public byte getJoinSyntaxType()
{
@@ -104,7 +158,72 @@
public String createSequenceQuery(String sequenceName)
{
- return "create sequence " + sequenceName;
+ return "CREATE SEQUENCE " + sequenceName;
+ }
+
+ public String createSequenceQuery(String sequenceName, Properties prop)
+ {
+ /*
+ CREATE SEQUENCE [<schema_name>.]<sequence_name>
+ [INCREMENT BY <integer>]
+ [START WITH <integer>]
+ [MAXVALUE <integer> | NOMAXVALUE]
+ [MINVALUE <integer> | NOMINVALUE]
+ [CYCLE | NOCYCLE]
+ [CACHE <unsigned_integer> | NOCACHE]
+ [ORDER|NOORDER]
+ */
+ StringBuffer query = new StringBuffer(createSequenceQuery(sequenceName));
+ if(prop != null)
+ {
+ Boolean b;
+ Long value;
+
+ value = SequenceManagerHelper.getSeqIncrementBy(prop);
+ if(value != null)
+ {
+ query.append(" INCREMENT BY ").append(value.longValue());
+ }
+
+ value = SequenceManagerHelper.getSeqStart(prop);
+ if(value != null)
+ {
+ query.append(" START WITH ").append(value.longValue());
+ }
+
+ value = SequenceManagerHelper.getSeqMaxValue(prop);
+ if(value != null)
+ {
+ query.append(" MAXVALUE ").append(value.longValue());
+ }
+
+ value = SequenceManagerHelper.getSeqMinValue(prop);
+ if(value != null)
+ {
+ query.append(" MINVALUE ").append(value.longValue());
+ }
+
+ b = SequenceManagerHelper.getSeqCycleValue(prop);
+ if(b != null)
+ {
+ if(b.booleanValue()) query.append(" CYCLE");
+ else query.append(" NOCYCLE");
+ }
+
+ value = SequenceManagerHelper.getSeqCacheValue(prop);
+ if(value != null)
+ {
+ query.append(" CACHE ").append(value.longValue());
+ }
+
+ b = SequenceManagerHelper.getSeqOrderValue(prop);
+ if(b != null)
+ {
+ if(b.booleanValue()) query.append(" ORDER");
+ else query.append(" NOORDER");
+ }
+ }
+ return query.toString();
}
public String nextSequenceQuery(String sequenceName)
@@ -116,10 +235,10 @@
{
return "drop sequence " + sequenceName;
}
-
+
/* (non-Javadoc)
- * @see org.apache.ojb.broker.platforms.Platform#addPagingSql(java.lang.StringBuffer)
- */
+ * @see org.apache.ojb.broker.platforms.Platform#addPagingSql(java.lang.StringBuffer)
+ */
public void addPagingSql(StringBuffer anSqlString)
{
anSqlString.append(" ROWNO <= ? ");
@@ -130,17 +249,17 @@
*/
public int bindPagingParameters(PreparedStatement ps, int index, int startAt, int endAt) throws SQLException
{
-
+
ps.setInt(index, endAt - 1); // IGNORE startAt !!
index++;
return index;
- }
-
+ }
+
/* (non-Javadoc)
- * @see org.apache.ojb.broker.platforms.Platform#supportsPaging()
- */
+ * @see org.apache.ojb.broker.platforms.Platform#supportsPaging()
+ */
public boolean supportsPaging()
{
return true;
- }
+ }
}
No revision
No revision
1.17.2.2 +2 -1 db-ojb/src/java/org/apache/ojb/broker/util/sequence/AbstractSequenceManager.java
Index: AbstractSequenceManager.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/AbstractSequenceManager.java,v
retrieving revision 1.17.2.1
retrieving revision 1.17.2.2
diff -u -r1.17.2.1 -r1.17.2.2
--- AbstractSequenceManager.java 27 Jul 2004 00:33:11 -0000 1.17.2.1
+++ AbstractSequenceManager.java 16 Aug 2005 20:11:19 -0000 1.17.2.2
@@ -38,6 +38,7 @@
{
// private Logger log = LoggerFactory.getLogger(AbstractSequenceManager.class);
public static final String PROPERTY_AUTO_NAMING = "autoNaming";
+ protected static final String GLOBAL_SEQUENCE_NAME = "ojb.global.sequence";
private PersistenceBroker brokerForClass;
private Platform platform;
1.1.1.1.4.1 +1 -9 db-ojb/src/java/org/apache/ojb/broker/util/sequence/package.html
Index: package.html
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/package.html,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.4.1
diff -u -r1.1.1.1 -r1.1.1.1.4.1
--- package.html 17 Jun 2002 18:16:48 -0000 1.1.1.1
+++ package.html 16 Aug 2005 20:11:19 -0000 1.1.1.1.4.1
@@ -5,14 +5,6 @@
</head>
<body bgcolor="#FFFFFF">
-This package contains classes that provide the OJB sequence numering.
-<P>
-no class documentation yet.
-<P>
-Patterns applied:
-Configurable Factory
-
-<P>
-Todo:
+This package contains classes that provide the OJB sequence numering.
</body>
</html>
1.10.2.4 +36 -1 db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManager.java
Index: SequenceManager.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManager.java,v
retrieving revision 1.10.2.3
retrieving revision 1.10.2.4
diff -u -r1.10.2.3 -r1.10.2.4
--- SequenceManager.java 14 May 2005 11:36:02 -0000 1.10.2.3
+++ SequenceManager.java 16 Aug 2005 20:11:19 -0000 1.10.2.4
@@ -40,6 +40,41 @@
public interface SequenceManager
{
/**
+ * Property name used to configure sequence manager implementations.
+ * @deprecated use {@link #PROP_SEQ_START} instead.
+ */
+ public static final String PROP_SEQ_START_OLD = "sequenceStart";
+ /**
+ * Property name used to configure sequence manager implementations.
+ */
+ public static final String PROP_SEQ_START = "seq.start";
+ /**
+ * Property name used to configure sequence manager implementations.
+ */
+ public static final String PROP_SEQ_INCREMENT_BY = "seq.incrementBy";
+ /**
+ * Property name used to configure sequence manager implementations.
+ */
+ public static final String PROP_SEQ_MAX_VALUE = "seq.maxValue";
+ /**
+ * Property name used to configure sequence manager implementations.
+ */
+ public static final String PROP_SEQ_MIN_VALUE = "seq.minValue";
+ /**
+ * Property name used to configure sequence manager implementations.
+ */
+ public static final String PROP_SEQ_CYCLE = "seq.cycle";
+ /**
+ * Property name used to configure sequence manager implementations.
+ */
+ public static final String PROP_SEQ_CACHE = "seq.cache";
+ /**
+ * Property name used to configure sequence manager implementations.
+ */
+ public static final String PROP_SEQ_ORDER = "seq.order";
+
+
+ /**
* This method is called to get an unique value <strong>before</strong> the object
* is written to persistent storage.
* <br/>
1.17.2.4 +153 -1 db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHelper.java
Index: SequenceManagerHelper.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHelper.java,v
retrieving revision 1.17.2.3
retrieving revision 1.17.2.4
diff -u -r1.17.2.3 -r1.17.2.4
--- SequenceManagerHelper.java 14 Aug 2005 15:48:32 -0000 1.17.2.3
+++ SequenceManagerHelper.java 16 Aug 2005 20:11:19 -0000 1.17.2.4
@@ -29,6 +29,7 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;
+import java.util.Properties;
/**
* Helper class for SequenceManager implementations.
@@ -334,4 +335,155 @@
}
return result;
}
+
+ /**
+ * Database sequence properties helper method.
+ * Return sequence <em>start value</em> or <em>null</em>
+ * if not set.
+ *
+ * @param prop The {@link java.util.Properties} instance to use.
+ * @return The found expression or <em>null</em>.
+ */
+ public static Long getSeqStart(Properties prop)
+ {
+ String result = prop.getProperty(SequenceManager.PROP_SEQ_START, null);
+ if(result == null)
+ {
+ result = prop.getProperty(SequenceManager.PROP_SEQ_START_OLD, null);
+ }
+ if(result != null)
+ {
+ return new Long(Long.parseLong(result));
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Database sequence properties helper method.
+ * Return sequence <em>increment by value</em> or <em>null</em>
+ * if not set.
+ *
+ * @param prop The {@link java.util.Properties} instance to use.
+ * @return The found expression or <em>null</em>.
+ */
+ public static Long getSeqIncrementBy(Properties prop)
+ {
+ String result = prop.getProperty(SequenceManager.PROP_SEQ_INCREMENT_BY, null);
+ if(result != null)
+ {
+ return new Long(Long.parseLong(result));
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Database sequence properties helper method.
+ * Return sequence <em>max value</em> or <em>null</em>
+ * if not set.
+ *
+ * @param prop The {@link java.util.Properties} instance to use.
+ * @return The found expression or <em>null</em>.
+ */
+ public static Long getSeqMaxValue(Properties prop)
+ {
+ String result = prop.getProperty(SequenceManager.PROP_SEQ_MAX_VALUE, null);
+ if(result != null)
+ {
+ return new Long(Long.parseLong(result));
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Database sequence properties helper method.
+ * Return sequence <em>min value</em> or <em>null</em>
+ * if not set.
+ *
+ * @param prop The {@link java.util.Properties} instance to use.
+ * @return The found expression or <em>null</em>.
+ */
+ public static Long getSeqMinValue(Properties prop)
+ {
+ String result = prop.getProperty(SequenceManager.PROP_SEQ_MIN_VALUE, null);
+ if(result != null)
+ {
+ return new Long(Long.parseLong(result));
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Database sequence properties helper method.
+ * Return sequence <em>cache value</em> or <em>null</em>
+ * if not set.
+ *
+ * @param prop The {@link java.util.Properties} instance to use.
+ * @return The found expression or <em>null</em>.
+ */
+ public static Long getSeqCacheValue(Properties prop)
+ {
+ String result = prop.getProperty(SequenceManager.PROP_SEQ_CACHE, null);
+ if(result != null)
+ {
+ return new Long(Long.parseLong(result));
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Database sequence properties helper method.
+ * Return sequence <em>cycle</em> Booelan or <em>null</em>
+ * if not set.
+ *
+ * @param prop The {@link java.util.Properties} instance to use.
+ * @return The found expression or <em>null</em>.
+ */
+ public static Boolean getSeqCycleValue(Properties prop)
+ {
+ String result = prop.getProperty(SequenceManager.PROP_SEQ_CYCLE, null);
+ if(result != null)
+ {
+ return Boolean.getBoolean(result) ? Boolean.TRUE : Boolean.FALSE;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Database sequence properties helper method.
+ * Return sequence <em>order</em> Booelan or <em>null</em>
+ * if not set.
+ *
+ * @param prop The {@link java.util.Properties} instance to use.
+ * @return The found expression or <em>null</em>.
+ */
+ public static Boolean getSeqOrderValue(Properties prop)
+ {
+ String result = prop.getProperty(SequenceManager.PROP_SEQ_ORDER, null);
+ if(result != null)
+ {
+ return Boolean.getBoolean(result) ? Boolean.TRUE : Boolean.FALSE;
+ }
+ else
+ {
+ return null;
+ }
+ }
}
1.29.2.3 +30 -24 db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHighLowImpl.java
Index: SequenceManagerHighLowImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHighLowImpl.java,v
retrieving revision 1.29.2.2
retrieving revision 1.29.2.3
diff -u -r1.29.2.2 -r1.29.2.3
--- SequenceManagerHighLowImpl.java 22 Apr 2005 16:44:14 -0000 1.29.2.2
+++ SequenceManagerHighLowImpl.java 16 Aug 2005 20:11:19 -0000 1.29.2.3
@@ -43,6 +43,13 @@
* <td><strong>Property Values</strong></td>
* </tr>
* <tr>
+ * <td>seq.start</td>
+ * <td>
+ * Set the start index of used sequences (e.g. set 100000, id generation starts with 100001).
+ * Default start index is <em>1</em>.
+ * </td>
+ * </tr>
+ * <tr>
* <td>grabSize</td>
* <td>
* Integer entry determines the
@@ -52,34 +59,34 @@
* </td>
* </tr>
* <tr>
+ * <td>autoNaming</td>
+ * <td>
+ * Default was 'true'. If set 'true' OJB try to build a
+ * sequence name automatic if none found in field-descriptor
+ * and set this generated name as <code>sequence-name</code>
+ * in field-descriptor. If set 'false' OJB throws an exception
+ * if none sequence name was found in field-descriptor.
+ * </td>
+ * </tr>
+ * <tr>
* <td>globalSequenceId</td>
* <td>
- * If set 'true' implementation use global unique
+ * Deprecated! If set 'true' implementation use global unique
* id's for all fields. Default was 'false'.
* </td>
* </tr>
* <tr>
* <td>globalSequenceStart</td>
* <td>
- * <em>Deprecated, use property 'sequenceStart'.</em> Set the start index of used global id
+ * <em>Deprecated, use property 'seq.start'.</em> Set the start index of used global id
* generation (e.g. set 100000, id generation starts with 100001)
* </td>
* </tr>
* <tr>
* <td>sequenceStart</td>
* <td>
- * Set the start index of used sequences (e.g. set 100000, id generation starts with 100001).
- * Default start index is <em>0</em>.
- * </td>
- * </tr>
- * <tr>
- * <td>autoNaming</td>
- * <td>
- * Default was 'true'. If set 'true' OJB try to build a
- * sequence name automatic if none found in field-descriptor
- * and set this generated name as <code>sequence-name</code>
- * in field-descriptor. If set 'false' OJB throws an exception
- * if none sequence name was found in field-descriptor.
+ * <em>Deprecated, use property 'seq.start'.</em> Set the start index of used
+ * sequences (e.g. set 100000, id generation starts with 100001). Default start index is <em>1</em>.
* </td>
* </tr>
* </table>
@@ -116,7 +123,6 @@
public static final String PROPERTY_GRAB_SIZE = "grabSize";
public static final String PROPERTY_GLOBAL_SEQUENCE_ID = "globalSequenceId";
public static final String PROPERTY_GLOBAL_SEQUENCE_START = "globalSequenceStart";
- public static final String PROPERTY_SEQUENCE_START = "sequenceStart";
protected static Map sequencesDBMap = new HashMap();
@@ -128,12 +134,12 @@
public SequenceManagerHighLowImpl(PersistenceBroker broker)
{
super(broker);
+ Long start = SequenceManagerHelper.getSeqStart(getConfigurationProperties());
+ sequenceStart = start != null ? start.longValue() : 1;
grabSize = Integer.parseInt(getConfigurationProperty(PROPERTY_GRAB_SIZE, "20"));
- useGlobalSequenceIdentities =
- Boolean.valueOf(getConfigurationProperty(PROPERTY_GLOBAL_SEQUENCE_ID, "false")).booleanValue();
- long globalSequenceStart = Long.parseLong(getConfigurationProperty(PROPERTY_GLOBAL_SEQUENCE_START, "10000"));
- sequenceStart = Long.parseLong(getConfigurationProperty(PROPERTY_SEQUENCE_START, "0"));
- // support for deprecated property
+ useGlobalSequenceIdentities = Boolean.getBoolean(getConfigurationProperty(PROPERTY_GLOBAL_SEQUENCE_ID, "false"));
+ // support for deprecated properties
+ long globalSequenceStart = Long.parseLong(getConfigurationProperty(PROPERTY_GLOBAL_SEQUENCE_START, "1"));
if(useGlobalSequenceIdentities && globalSequenceStart > sequenceStart)
{
sequenceStart = globalSequenceStart;
@@ -282,7 +288,7 @@
protected HighLowSequence lookupStoreSequence(PersistenceBroker broker, FieldDescriptor field, String seqName)
{
- HighLowSequence newSequence = null;
+ HighLowSequence newSequence;
boolean needsInsert = false;
Identity oid = broker.serviceIdentity().buildIdentity(HighLowSequence.class, seqName);
@@ -351,7 +357,7 @@
protected long getMaxKeyForSequence(PersistenceBroker broker,
FieldDescriptor field)
{
- long maxKey = 0;
+ long maxKey;
if (useGlobalSequenceIdentities)
{
maxKey = sequenceStart;
@@ -370,7 +376,7 @@
private String buildSequenceName(FieldDescriptor field) throws SequenceManagerException
{
- String seqName = null;
+ String seqName;
if (useGlobalSequenceIdentities)
{
seqName = GLOBAL_SEQUENCE_NAME;
1.14.2.2 +13 -5 db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerInMemoryImpl.java
Index: SequenceManagerInMemoryImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerInMemoryImpl.java,v
retrieving revision 1.14.2.1
retrieving revision 1.14.2.2
diff -u -r1.14.2.1 -r1.14.2.2
--- SequenceManagerInMemoryImpl.java 4 Oct 2004 15:00:13 -0000 1.14.2.1
+++ SequenceManagerInMemoryImpl.java 16 Aug 2005 20:11:19 -0000 1.14.2.2
@@ -46,6 +46,13 @@
* <td><strong>Property Values</strong></td>
* </tr>
* <tr>
+ * <td>seq.start</td>
+ * <td>
+ * Set the start index of used sequences (e.g. set 100000, id generation starts with 100001).
+ * Default start index is <em>1</em>.
+ * </td>
+ * </tr>
+ * <tr>
* <td>autoNaming</td>
* <td>
* Default was 'true'. If set 'true' OJB try to build a
@@ -58,8 +65,9 @@
* <tr>
* <td>sequenceStart</td>
* <td>
- * Set the start index of used sequences (e.g. set 100000, id generation starts with 100001).
- * Default start index is <em>0</em>.
+ * <em>Deprecated, use property 'seq.start'.</em> Set the start index
+ * of used sequences (e.g. set 100000, id generation starts with 100001).
+ * Default start index is <em>1</em>.
* </td>
* </tr>
* </table>
@@ -78,14 +86,14 @@
*/
public class SequenceManagerInMemoryImpl extends AbstractSequenceManager
{
- public static final String PROPERTY_SEQUENCE_START = "sequenceStart";
protected static Map sequencesDBMap = new HashMap();
private long sequenceStart;
public SequenceManagerInMemoryImpl(PersistenceBroker broker)
{
super(broker);
- sequenceStart = Long.parseLong(getConfigurationProperty(PROPERTY_SEQUENCE_START, "0"));
+ Long start = SequenceManagerHelper.getSeqStart(getConfigurationProperties());
+ sequenceStart = start != null ? start.longValue() : 1;
}
protected long getUniqueLong(FieldDescriptor field) throws SequenceManagerException
1.17.2.1 +6 -4 db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerNextValImpl.java
Index: SequenceManagerNextValImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerNextValImpl.java,v
retrieving revision 1.17
retrieving revision 1.17.2.1
diff -u -r1.17 -r1.17.2.1
--- SequenceManagerNextValImpl.java 9 Jun 2004 09:27:37 -0000 1.17
+++ SequenceManagerNextValImpl.java 16 Aug 2005 20:11:19 -0000 1.17.2.1
@@ -17,6 +17,7 @@
import java.sql.ResultSet;
import java.sql.Statement;
+import java.util.Properties;
import org.apache.commons.lang.SystemUtils;
import org.apache.ojb.broker.PersistenceBroker;
@@ -91,6 +92,7 @@
public class SequenceManagerNextValImpl extends AbstractSequenceManager
{
private Logger log = LoggerFactory.getLogger(SequenceManagerNextValImpl.class);
+
/**
*
*/
@@ -202,7 +204,7 @@
try
{
stmt = stmtMan.getGenericStatement(cld, Query.NOT_SCROLLABLE);
- stmt.execute(getPlatform().createSequenceQuery(sequenceName));
+ stmt.execute(getPlatform().createSequenceQuery(sequenceName, getConfigurationProperties()));
}
finally
{
@@ -210,9 +212,9 @@
{
stmtMan.closeResources(stmt, null);
}
- catch (Exception ignore)
+ catch (Exception e)
{
- // ignore it
+ e.printStackTrace();
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org