You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by oz...@apache.org on 2004/05/11 12:41:10 UTC
cvs commit: jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms AbstractRDBMSStore.java
ozeigermann 2004/05/11 03:41:10
Modified: src/stores/org/apache/slide/store/impl/rdbms
AbstractRDBMSStore.java
Log:
Added SequenceStore support to RDBMS store
Revision Changes Path
1.4 +144 -6 jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/AbstractRDBMSStore.java
Index: AbstractRDBMSStore.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/AbstractRDBMSStore.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AbstractRDBMSStore.java 11 Feb 2004 11:30:21 -0000 1.3
+++ AbstractRDBMSStore.java 11 May 2004 10:41:10 -0000 1.4
@@ -59,6 +59,7 @@
import org.apache.slide.store.RevisionDescriptorStore;
import org.apache.slide.store.RevisionDescriptorsStore;
import org.apache.slide.store.SecurityStore;
+import org.apache.slide.store.SequenceStore;
import org.apache.slide.structure.ObjectAlreadyExistsException;
import org.apache.slide.structure.ObjectNode;
import org.apache.slide.structure.ObjectNotFoundException;
@@ -76,7 +77,14 @@
*/
public abstract class AbstractRDBMSStore
extends AbstractXAService
- implements LockStore, NodeStore, RevisionDescriptorsStore, RevisionDescriptorStore, SecurityStore, ContentStore {
+ implements
+ LockStore,
+ NodeStore,
+ RevisionDescriptorsStore,
+ RevisionDescriptorStore,
+ SecurityStore,
+ ContentStore,
+ SequenceStore {
protected String LOG_CHANNEL = this.getClass().getName();
@@ -91,6 +99,8 @@
protected RDBMSAdapter adapter;
protected boolean alreadyInitialized = false;
+
+ protected int isSequenceSupported = 0;
/**
* Indicates whether the transaction manager will commit / rollback
@@ -418,6 +428,135 @@
}
}
+ // ----------------------------------------------- SequenceStore Implementation
+
+ /**
+ * @see org.apache.slide.store.SequenceStore#createSequence(java.lang.String)
+ */
+ public boolean createSequence(String sequenceName) throws ServiceAccessException {
+ if (!isSequenceSupported()) {
+ throw new ServiceAccessException(this, "Sequences not supported");
+ }
+ Connection connection = null;
+ try {
+ connection = getNewConnection();
+ return ((SequenceAdapter) adapter).createSequence(connection, sequenceName);
+ } catch (SQLException e) {
+ throw new ServiceAccessException(this, e);
+ } finally {
+ if (connection != null) {
+ try {
+ if (!tmCommits) {
+ connection.commit();
+ }
+ } catch (SQLException e) {
+ throw new ServiceAccessException(this, e);
+ } finally {
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ getLogger().log(e, LOG_CHANNEL, Logger.WARNING);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * @see org.apache.slide.store.SequenceStore#isSequenceSupported()
+ */
+ public boolean isSequenceSupported() {
+ // cache it for better performance as support of an adapter will
+ // not change will running, it is either yes or no all the time
+ if (isSequenceSupported > 0)
+ return true;
+ if (isSequenceSupported > 0)
+ return false;
+ Connection connection = null;
+ try {
+ connection = getNewConnection();
+ if (adapter instanceof SequenceAdapter && ((SequenceAdapter) adapter).isSequenceSupported(connection)) {
+ isSequenceSupported = 1;
+ return true;
+ } else {
+ isSequenceSupported = -1;
+ return false;
+ }
+ } catch (SQLException e) {
+ getLogger().log(
+ "Error while trying to check for sequence support. Assuming false",
+ e,
+ LOG_CHANNEL,
+ Logger.ERROR);
+ isSequenceSupported = -1;
+ return false;
+ } finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ getLogger().log(e, LOG_CHANNEL, Logger.WARNING);
+ }
+ }
+ }
+ }
+
+ /**
+ * @see org.apache.slide.store.SequenceStore#nextSequenceValue(java.lang.String)
+ */
+ public long nextSequenceValue(String sequenceName) throws ServiceAccessException {
+ if (!isSequenceSupported()) {
+ throw new ServiceAccessException(this, "Sequences not supported");
+ }
+ Connection connection = null;
+ try {
+ connection = getNewConnection();
+ return ((SequenceAdapter) adapter).nextSequenceValue(connection, sequenceName);
+ } catch (SQLException e) {
+ throw new ServiceAccessException(this, e);
+ } finally {
+ if (connection != null) {
+ try {
+ if (!tmCommits) {
+ connection.commit();
+ }
+ } catch (SQLException e) {
+ throw new ServiceAccessException(this, e);
+ } finally {
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ getLogger().log(e, LOG_CHANNEL, Logger.WARNING);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * @see org.apache.slide.store.SequenceStore#sequenceExists(java.lang.String)
+ */
+ public boolean sequenceExists(String sequenceName) throws ServiceAccessException {
+ if (!isSequenceSupported()) {
+ throw new ServiceAccessException(this, "Sequences not supported");
+ }
+ Connection connection = null;
+ try {
+ connection = getNewConnection();
+ return ((SequenceAdapter) adapter).sequenceExists(connection, sequenceName);
+ } catch (SQLException e) {
+ throw new ServiceAccessException(this, e);
+ } finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ getLogger().log(e, LOG_CHANNEL, Logger.WARNING);
+ }
+ }
+ }
+ }
+
// ----------------------------------------------- NodeStore Implementation
/**
@@ -890,5 +1029,4 @@
}
}
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org