Author: arminw
Date: Fri Oct 13 12:10:59 2006
New Revision: 463783
URL: http://svn.apache.org/viewvc?view=rev&rev=463783
Log:
add support for database sequences
Modified:
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformHsqldbImpl.java
Modified:
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformHsqldbImpl.java
URL:
http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformHsqldbImpl.java?view=diff&rev=463783&r1=463782&r2=463783
==============================================================================
---
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformHsqldbImpl.java
(original)
+++
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformHsqldbImpl.java
Fri Oct 13 12:10:59 2006
@@ -15,12 +15,51 @@
* limitations under the License.
*/
+import java.util.Properties;
+
+import org.apache.ojb.broker.util.sequence.SequenceManagerHelper;
/**
* This class extends <code>PlatformDefaultImpl</code> and defines specific
* behavior for the Hsqldb platform.
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Thomas Mahler<a>
+ * <p>
+ * Supported properties on sequence creation:
+ * </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>seq.as</td>
+ * <td>
+ * Database sequence specific property.<br/>
+ * Specifies the datatype used for the sequence.
+ * Allowed: <em>INTEGER</em> or <em>BIGINT</em>.
+ * </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>
+ * </table>
+ * <br/>
+ *
* @version $Id$
*/
public class PlatformHsqldbImpl extends PlatformDefaultImpl
@@ -35,6 +74,9 @@
return SQL92_NOPAREN_JOIN_SYNTAX;
}
+ /**
+ * @see
org.apache.ojb.broker.platforms.Platform#getLastInsertIdentityQuery(java.lang.String)
+ */
public String getLastInsertIdentityQuery(String tableName)
{
return LAST_INSERT;
@@ -69,15 +111,58 @@
return false;
}
-// arminw: Check is not necessary any longer
-// /**
-// * HSQLDB does not implement CallableStatement.
-// *
-// * @see
org.apache.ojb.broker.platforms.Platform#isCallableStatement(java.sql.PreparedStatement)
-// */
-// public boolean isCallableStatement(PreparedStatement stmt)
-// {
-// return false;
-// }
+ public String createSequenceQuery(String sequenceName, Properties prop)
+ {
+ // CREATE SEQUENCE <sequencename> [AS {INTEGER | BIGINT}]
+ // [START WITH <startvalue>] [INCREMENT BY <incrementvalue>];
+ StringBuffer query = new
StringBuffer(createSequenceQuery(sequenceName));
+ if(prop != null)
+ {
+ Long value;
+ String str;
+
+ str = SequenceManagerHelper.getSeqAsValue(prop);
+ if(str != null)
+ {
+ query.append(" AS ").append(str);
+ }
+
+ value = SequenceManagerHelper.getSeqStart(prop);
+ if(value != null)
+ {
+ query.append(" START WITH ").append(value.longValue());
+ }
+
+ value = SequenceManagerHelper.getSeqIncrementBy(prop);
+ if(value != null)
+ {
+ query.append(" INCREMENT BY ").append(value.longValue());
+ }
+ }
+ return query.toString();
+ }
+ /**
+ * @see
org.apache.ojb.broker.platforms.Platform#createSequenceQuery(java.lang.String)
+ */
+ public String createSequenceQuery(String sequenceName)
+ {
+ return "CREATE SEQUENCE " + sequenceName;
+ }
+
+ /**
+ * @see
org.apache.ojb.broker.platforms.Platform#nextSequenceQuery(java.lang.String)
+ */
+ public String nextSequenceQuery(String sequenceName)
+ {
+ return "CALL NEXT VALUE FOR " + sequenceName;
+ }
+
+ /**
+ * @see
org.apache.ojb.broker.platforms.Platform#dropSequenceQuery(java.lang.String)
+ */
+ public String dropSequenceQuery(String sequenceName)
+ {
+ return "DROP SEQUENCE " + sequenceName;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]