mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Some more modification to make things more Spring friendly. Updated
Spring configurations to match. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3278 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2006 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.avm.hibernate;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
/**
|
||||
* Like 83.7 gazillion others, a HibernateHelper. This will go away.
|
||||
* @author britt
|
||||
*/
|
||||
public class HibernateHelper
|
||||
{
|
||||
/**
|
||||
* The single instance of this.
|
||||
*/
|
||||
private static HibernateHelper fgInstance = null;
|
||||
|
||||
/**
|
||||
* The Hibernate Configuration object.
|
||||
*/
|
||||
private Configuration fCfg;
|
||||
|
||||
/**
|
||||
* The Hibernate SessionFactory;
|
||||
*/
|
||||
private SessionFactory fFactory;
|
||||
|
||||
public HibernateHelper()
|
||||
{
|
||||
fCfg = null;
|
||||
fFactory = null;
|
||||
setup();
|
||||
fgInstance = this;
|
||||
}
|
||||
|
||||
public SessionFactory getSessionFactory()
|
||||
{
|
||||
return fFactory;
|
||||
}
|
||||
|
||||
public Configuration getConfiguration()
|
||||
{
|
||||
return fCfg;
|
||||
}
|
||||
|
||||
public void setup()
|
||||
{
|
||||
try
|
||||
{
|
||||
fCfg = new Configuration();
|
||||
fCfg.configure();
|
||||
fFactory = fCfg.buildSessionFactory();
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
t.printStackTrace(System.err);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown()
|
||||
{
|
||||
fFactory.close();
|
||||
}
|
||||
|
||||
public static HibernateHelper GetInstance()
|
||||
{
|
||||
return fgInstance;
|
||||
}
|
||||
}
|
@@ -18,11 +18,11 @@ package org.alfresco.repo.avm.hibernate;
|
||||
*/
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import org.alfresco.repo.avm.AVMException;
|
||||
import org.hibernate.FlushMode;
|
||||
import org.alfresco.repo.avm.AVMNotFoundException;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.ObjectNotFoundException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.StaleStateException;
|
||||
@@ -46,20 +46,22 @@ public class HibernateTxn
|
||||
*/
|
||||
private Random fRandom;
|
||||
|
||||
/**
|
||||
* The BFL.
|
||||
*/
|
||||
private ReentrantReadWriteLock fLock;
|
||||
|
||||
/**
|
||||
* Make one up.
|
||||
* @param sessionFactory The SessionFactory.
|
||||
*/
|
||||
public HibernateTxn(SessionFactory sessionFactory)
|
||||
public HibernateTxn()
|
||||
{
|
||||
fSessionFactory = sessionFactory;
|
||||
fRandom = new Random();
|
||||
fLock = new ReentrantReadWriteLock(true); // Make the lock fair.
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Hibernate Session factory.
|
||||
* @param factory
|
||||
*/
|
||||
public void setSessionFactory(SessionFactory factory)
|
||||
{
|
||||
fSessionFactory = factory;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,18 +78,7 @@ public class HibernateTxn
|
||||
{
|
||||
try
|
||||
{
|
||||
/*
|
||||
if (write)
|
||||
{
|
||||
fLock.writeLock().lock();
|
||||
}
|
||||
else
|
||||
{
|
||||
fLock.readLock().lock();
|
||||
}
|
||||
*/
|
||||
sess = fSessionFactory.openSession();
|
||||
// sess.setFlushMode(FlushMode.ALWAYS);
|
||||
txn = sess.beginTransaction();
|
||||
callback.perform(sess);
|
||||
txn.commit();
|
||||
@@ -113,23 +104,23 @@ public class HibernateTxn
|
||||
{
|
||||
if (t instanceof StaleStateException)
|
||||
{
|
||||
System.err.println("Lost Race");
|
||||
StackTraceElement [] stack = t.getStackTrace();
|
||||
long threadID = Thread.currentThread().getId();
|
||||
for (StackTraceElement frame : stack)
|
||||
{
|
||||
System.err.println(threadID + " " + frame);
|
||||
}
|
||||
// System.err.println("Lost Race");
|
||||
// StackTraceElement [] stack = t.getStackTrace();
|
||||
// long threadID = Thread.currentThread().getId();
|
||||
// for (StackTraceElement frame : stack)
|
||||
// {
|
||||
// System.err.println(threadID + " " + frame);
|
||||
// }
|
||||
}
|
||||
else
|
||||
{
|
||||
System.err.println("Deadlock");
|
||||
StackTraceElement [] stack = t.getStackTrace();
|
||||
long threadID = Thread.currentThread().getId();
|
||||
for (StackTraceElement frame : stack)
|
||||
{
|
||||
System.err.println(threadID + " " + frame);
|
||||
}
|
||||
// System.err.println("Deadlock");
|
||||
// StackTraceElement [] stack = t.getStackTrace();
|
||||
// long threadID = Thread.currentThread().getId();
|
||||
// for (StackTraceElement frame : stack)
|
||||
// {
|
||||
// System.err.println(threadID + " " + frame);
|
||||
// }
|
||||
try
|
||||
{
|
||||
long interval;
|
||||
@@ -154,20 +145,14 @@ public class HibernateTxn
|
||||
}
|
||||
// TODO Crack t into more useful exception types.
|
||||
// Otherwise nothing we can do except throw.
|
||||
throw new AVMException("Unrecoverable error", t);
|
||||
if (t instanceof ObjectNotFoundException)
|
||||
{
|
||||
throw new AVMNotFoundException("Object not found.", t);
|
||||
}
|
||||
throw new AVMException("Unrecoverable error.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
/*
|
||||
if (write)
|
||||
{
|
||||
fLock.writeLock().unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
fLock.readLock().unlock();
|
||||
}
|
||||
*/
|
||||
if (sess != null)
|
||||
{
|
||||
try
|
||||
|
Reference in New Issue
Block a user