Update of /var/cvs/src/org/mmbase/storage
In directory james.mmbase.org:/tmp/cvs-serv18372
Modified Files:
StorageManagerFactory.java
Log Message:
MMB-1782, MMB-1781
See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/storage
See also: http://www.mmbase.org/jira/browse/MMB-1782
See also: http://www.mmbase.org/jira/browse/MMB-1781
Index: StorageManagerFactory.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/storage/StorageManagerFactory.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -b -r1.36 -r1.37
--- StorageManagerFactory.java 19 Aug 2008 21:29:43 -0000 1.36
+++ StorageManagerFactory.java 30 Jan 2009 22:02:14 -0000 1.37
@@ -38,10 +38,18 @@
*
* @author Pierre van Rooden
* @since MMBase-1.7
- * @version $Id: StorageManagerFactory.java,v 1.36 2008/08/19 21:29:43 michiel
Exp $
+ * @version $Id: StorageManagerFactory.java,v 1.37 2009/01/30 22:02:14 michiel
Exp $
*/
public abstract class StorageManagerFactory<SM extends StorageManager> {
+ /**
+ * Transaction of the current thread, or <code>null</code> if it is not
currently in a
+ * transaction.
+ * @since MMBase-1.9.1
+ */
+ private final ThreadLocal<SM> transaction = new ThreadLocal<SM>();
+
+
private static final Object NULL = new Object();
private static final Logger log =
Logging.getLoggerInstance(StorageManagerFactory.class);
@@ -152,6 +160,7 @@
return newInstance(MMBase.getMMBase());
}
+
/**
* Initialize the StorageManagerFactory.
* This method should be called after instantiation of the factory class.
@@ -166,13 +175,32 @@
typeMappings = new CopyOnWriteArrayList<TypeMapping>();
storeBinaryAsFileObjects = Collections.synchronizedList(new
ArrayList<String>());
changeManager = new ChangeManager();
+
+ int loadTries = 0;
+
+
+ while(true) {
try {
log.debug("loading Storage Manager factory " +
this.getClass().getName());
+ loadTries++;
load();
+ break;
} catch (StorageException se) {
// pass exceptions as a StorageError to signal a serious
(unrecoverable) error condition
- log.fatal(se.getMessage() + Logging.stackTrace(se));
- throw new StorageError(se);
+ if (loadTries == 1) {
+ log.fatal(se.getMessage(), se);
+ } else if (loadTries < 3) {
+ log.fatal(se.getMessage());
+ } else {
+ log.fatal(se.getClass().getName());
+ }
+ try {
+ Thread.sleep(10000);
+ log.info("Retrying (" + loadTries + ")");
+ } catch (InterruptedException ie) {
+ throw se;
+ }
+ }
}
}
@@ -305,14 +333,11 @@
}
}
+
/**
- * Obtains a StorageManager from the factory.
- * The instance represents a temporary connection to the datasource -
- * do not store the result of this call as a static or long-term member of
a class.
- * @return a StorageManager instance
- * @throws StorageException when the storagemanager cannot be created
+ * @since MMBase-1.9.1
*/
- public SM getStorageManager() throws StorageException {
+ protected SM createStorageManager() throws StorageException {
try {
SM storageManager = storageManagerClass.newInstance();
storageManager.init(this);
@@ -324,6 +349,24 @@
}
}
+ /**
+ * Obtains a StorageManager from the factory.
+ * The instance represents a temporary connection to the datasource -
+ * do not store the result of this call as a static or long-term member of
a class.
+ * @return a StorageManager instance
+ * @throws StorageException when the storagemanager cannot be created
+ */
+ public SM getStorageManager() throws StorageException {
+ SM sm = transaction.get();
+ if (sm != null) {
+ return sm;
+ } else {
+ return createStorageManager();
+ }
+
+
+ }
+
// javadoc inherited
/**
* Obtains a SearchQueryHandler from the factory.
@@ -671,6 +714,41 @@
}
+ /**
+ * Puts the current thread in a database transaction
+ * @throws IllegalStateException if the current thread already in
transaction
+ * @since MMBase-1.9.1
+ */
+ public void beginTransaction() throws StorageException {
+ if (transaction.get() != null) throw new
IllegalStateException("Transaction already started");
+ SM sm = createStorageManager();
+ sm.beginTransaction();
+ transaction.set(sm);
+ }
+
+ /**
+ * Commits the current thread's database transaction
+ * @throws IllegalStateException if the current thread not in a transaction
+ * @since MMBase-1.9.1
+ */
+ public void commit() throws StorageException {
+ SM sm = transaction.get();
+ if (sm == null) throw new IllegalStateException("No transaction
started to commit");
+ transaction.set(null);
+ sm.commit();
+ }
+
+ /**
+ * Rolls back the current thread's database transaction
+ * @throws IllegalStateException if the current thread not in a transaction
+ * @since MMBase-1.9.1
+ */
+ public boolean rollback() throws StorageException {
+ SM sm = transaction.get();
+ if (sm == null) throw new IllegalStateException("No transaction
started to rollback");
+ transaction.set(null);
+ return sm.rollback();
+ }
}
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs