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:
@@ -2,9 +2,72 @@
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN//EN"
|
||||
"http://www.springframework.org/dtd/spring-beans.dtd">
|
||||
<beans>
|
||||
<bean id="hibernateHelper" class="org.alfresco.repo.avm.hibernate.HibernateHelper"
|
||||
destroy-method="shutdown">
|
||||
|
||||
<!-- Use substitution values in this config. -->
|
||||
<bean id="configurationProperties"
|
||||
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="locations">
|
||||
<list>
|
||||
<value>config/alfresco/avm-console.properties</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- Datasource -->
|
||||
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
|
||||
<property name="driverClass">
|
||||
<value>${db.driver}</value>
|
||||
</property>
|
||||
<property name="jdbcUrl">
|
||||
<value>${db.url}</value>
|
||||
</property>
|
||||
<property name="user">
|
||||
<value>${db.username}</value>
|
||||
</property>
|
||||
<property name="password">
|
||||
<value>${db.password}</value>
|
||||
</property>
|
||||
<property name="initialPoolSize" >
|
||||
<value>${db.pool.initial}</value>
|
||||
</property>
|
||||
<property name="maxPoolSize" >
|
||||
<value>${db.pool.max}</value>
|
||||
</property>
|
||||
<property name="numHelperThreads" >
|
||||
<value>1</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- The SessionFactory for hibernate. -->
|
||||
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
|
||||
<property name="dataSource">
|
||||
<ref bean="dataSource"/>
|
||||
</property>
|
||||
<property name="hibernateProperties">
|
||||
<props>
|
||||
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
|
||||
<prop key="hibernate.current_session_context_class">${hibernate.current_session_context_class}</prop>
|
||||
<prop key="hibernate.connection.isolation">${hibernate.connection.isolation}</prop>
|
||||
<prop key="hibernate.default_batch_fetch_size">${hibernate.default_batch_fetch_size}</prop>
|
||||
<prop key="hibernate.jdbc.batch_versioned_data">${hibernate.jdbc.batch_versioned_data}</prop>
|
||||
<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
|
||||
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
|
||||
</props>
|
||||
</property>
|
||||
<property name="mappingResources">
|
||||
<list>
|
||||
<value>org/alfresco/repo/avm/hibernate/AVM.hbm.xml</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- The Hibernate Transaction wrapper. -->
|
||||
<bean id="hibernateTxn" class="org.alfresco.repo.avm.hibernate.HibernateTxn">
|
||||
<property name="sessionFactory">
|
||||
<ref bean="sessionFactory"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="orphanReaper" class="org.alfresco.repo.avm.OrphanReaper"
|
||||
init-method="init" destroy-method="shutDown" depends-on="avmService">
|
||||
<property name="inactiveBaseSleep">
|
||||
@@ -16,27 +79,30 @@
|
||||
<property name="batchSize">
|
||||
<value>50</value>
|
||||
</property>
|
||||
<property name="hibernateHelper">
|
||||
<ref bean="hibernateHelper"/>
|
||||
<property name="hibernateTxn">
|
||||
<ref bean="hibernateTxn"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="bulkLoader" class="org.alfresco.repo.avm.util.BulkLoader">
|
||||
<property name="avmService">
|
||||
<ref bean="avmService"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="avmService" class="org.alfresco.repo.avm.AVMServiceImpl"
|
||||
init-method="init">
|
||||
<property name="storage">
|
||||
<value>build/test-results/storage</value>
|
||||
</property>
|
||||
<property name="createTables">
|
||||
<value>false</value>
|
||||
<property name="initialize">
|
||||
<value>${avm.initialize}</value>
|
||||
</property>
|
||||
<property name="hibernateHelper">
|
||||
<ref bean="hibernateHelper"/>
|
||||
<property name="hibernateTxn">
|
||||
<ref bean="hibernateTxn"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="interactiveConsole" class="org.alfresco.repo.avm.AVMInterpreter">
|
||||
<property name="avmService">
|
||||
<ref bean="avmService"/>
|
||||
@@ -45,4 +111,5 @@
|
||||
<ref bean="bulkLoader"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
17
config/alfresco/avm-console.properties
Normal file
17
config/alfresco/avm-console.properties
Normal file
@@ -0,0 +1,17 @@
|
||||
# Database specifics.
|
||||
db.driver=com.mysql.jdbc.Driver
|
||||
db.url=jdbc:mysql://127.0.0.1/avm
|
||||
db.username=root
|
||||
db.password=
|
||||
db.pool.initial=4
|
||||
db.pool.max=32
|
||||
# Hibernate properties
|
||||
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
|
||||
hibernate.current_session_context_class=thread
|
||||
hibernate.connection.isolation=2
|
||||
hibernate.default_batch_fetch_size=16
|
||||
hibernate.jdbc.batch_versioned_data=true
|
||||
hibernate.cache.use_second_level_cache=true
|
||||
hibernate.hbm2ddl.auto=update
|
||||
# AVM specific properties.
|
||||
avm.initialize=false
|
@@ -2,9 +2,72 @@
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN//EN"
|
||||
"http://www.springframework.org/dtd/spring-beans.dtd">
|
||||
<beans>
|
||||
<bean id="hibernateHelper" class="org.alfresco.repo.avm.hibernate.HibernateHelper"
|
||||
destroy-method="shutdown">
|
||||
|
||||
<!-- Use substitution values in this config. -->
|
||||
<bean id="configurationProperties"
|
||||
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="locations">
|
||||
<list>
|
||||
<value>config/alfresco/avm-test.properties</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- Datasource -->
|
||||
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
|
||||
<property name="driverClass">
|
||||
<value>${db.driver}</value>
|
||||
</property>
|
||||
<property name="jdbcUrl">
|
||||
<value>${db.url}</value>
|
||||
</property>
|
||||
<property name="user">
|
||||
<value>${db.username}</value>
|
||||
</property>
|
||||
<property name="password">
|
||||
<value>${db.password}</value>
|
||||
</property>
|
||||
<property name="initialPoolSize">
|
||||
<value>${db.pool.initial}</value>
|
||||
</property>
|
||||
<property name="maxPoolSize" >
|
||||
<value>${db.pool.max}</value>
|
||||
</property>
|
||||
<property name="numHelperThreads">
|
||||
<value>1</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- The SessionFactory for hibernate. -->
|
||||
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
|
||||
<property name="dataSource">
|
||||
<ref bean="dataSource"/>
|
||||
</property>
|
||||
<property name="hibernateProperties">
|
||||
<props>
|
||||
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
|
||||
<prop key="hibernate.current_session_context_class">${hibernate.current_session_context_class}</prop>
|
||||
<prop key="hibernate.connection.isolation">${hibernate.connection.isolation}</prop>
|
||||
<prop key="hibernate.default_batch_fetch_size">${hibernate.default_batch_fetch_size}</prop>
|
||||
<prop key="hibernate.jdbc.batch_versioned_data">${hibernate.jdbc.batch_versioned_data}</prop>
|
||||
<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
|
||||
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
|
||||
</props>
|
||||
</property>
|
||||
<property name="mappingResources">
|
||||
<list>
|
||||
<value>org/alfresco/repo/avm/hibernate/AVM.hbm.xml</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- The Hibernate Transaction wrapper. -->
|
||||
<bean id="hibernateTxn" class="org.alfresco.repo.avm.hibernate.HibernateTxn">
|
||||
<property name="sessionFactory">
|
||||
<ref bean="sessionFactory"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="orphanReaper" class="org.alfresco.repo.avm.OrphanReaper"
|
||||
init-method="init" destroy-method="shutDown" depends-on="avmService">
|
||||
<property name="inactiveBaseSleep">
|
||||
@@ -16,20 +79,21 @@
|
||||
<property name="batchSize">
|
||||
<value>50</value>
|
||||
</property>
|
||||
<property name="hibernateHelper">
|
||||
<ref bean="hibernateHelper"/>
|
||||
<property name="hibernateTxn">
|
||||
<ref bean="hibernateTxn"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="avmService" class="org.alfresco.repo.avm.AVMServiceImpl"
|
||||
init-method="init">
|
||||
<property name="storage">
|
||||
<value>build/test-results/storage</value>
|
||||
</property>
|
||||
<property name="createTables">
|
||||
<value>true</value>
|
||||
<property name="initialize">
|
||||
<value>${avm.initialize}</value>
|
||||
</property>
|
||||
<property name="hibernateHelper">
|
||||
<ref bean="hibernateHelper"/>
|
||||
<property name="hibernateTxn">
|
||||
<ref bean="hibernateTxn"/>
|
||||
</property>
|
||||
</bean>
|
||||
</beans>
|
17
config/alfresco/avm-test.properties
Normal file
17
config/alfresco/avm-test.properties
Normal file
@@ -0,0 +1,17 @@
|
||||
# Database specifics.
|
||||
db.driver=com.mysql.jdbc.Driver
|
||||
db.url=jdbc:mysql://127.0.0.1/avm
|
||||
db.username=root
|
||||
db.password=
|
||||
db.pool.initial=4
|
||||
db.pool.max=32
|
||||
# Hibernate properties
|
||||
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
|
||||
hibernate.current_session_context_class=thread
|
||||
hibernate.connection.isolation=2
|
||||
hibernate.default_batch_fetch_size=16
|
||||
hibernate.jdbc.batch_versioned_data=true
|
||||
hibernate.cache.use_second_level_cache=true
|
||||
hibernate.hbm2ddl.auto=create
|
||||
# AVM specific properties.
|
||||
avm.initialize=true
|
@@ -35,7 +35,7 @@ public class AVMCrawlTest extends AVMServiceTestBase
|
||||
*/
|
||||
public void testCrawl()
|
||||
{
|
||||
int n = 4; // Number of Threads.
|
||||
int n = 8; // Number of Threads.
|
||||
int m = 16; // How many multiples of content to start with.
|
||||
long runTime = 1200000; // Ten minutes
|
||||
fService.purgeRepository("main");
|
||||
|
@@ -28,12 +28,10 @@ import java.util.List;
|
||||
import java.util.SortedMap;
|
||||
|
||||
import org.alfresco.repo.avm.SuperRepository;
|
||||
import org.alfresco.repo.avm.hibernate.HibernateHelper;
|
||||
import org.alfresco.repo.avm.hibernate.HibernateTxn;
|
||||
import org.alfresco.repo.avm.hibernate.HibernateTxnCallback;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||
|
||||
/**
|
||||
* Implements the AVMService. Stub.
|
||||
@@ -74,12 +72,7 @@ public class AVMServiceImpl implements AVMService
|
||||
/**
|
||||
* Whether the tables should be dropped and created.
|
||||
*/
|
||||
private boolean fCreateTables;
|
||||
|
||||
/**
|
||||
* The HibernateHelper.
|
||||
*/
|
||||
private HibernateHelper fHibernateHelper;
|
||||
private boolean fInitialize;
|
||||
|
||||
/**
|
||||
* Basic constructor for the service.
|
||||
@@ -94,61 +87,47 @@ public class AVMServiceImpl implements AVMService
|
||||
*/
|
||||
public void init()
|
||||
{
|
||||
fTransaction = new HibernateTxn(fHibernateHelper.getSessionFactory());
|
||||
if (fCreateTables)
|
||||
try
|
||||
{
|
||||
SchemaExport se = new SchemaExport(fHibernateHelper.getConfiguration());
|
||||
se.drop(false, true);
|
||||
se.create(false, true);
|
||||
File storage = new File(fStorage);
|
||||
storage.mkdirs();
|
||||
fNodeIssuer = new Issuer(0L);
|
||||
fContentIssuer = new Issuer(0L);
|
||||
fLayerIssuer = new Issuer(0L);
|
||||
fTransaction.perform(
|
||||
new HibernateTxnCallback()
|
||||
{
|
||||
public void perform(Session sess)
|
||||
{
|
||||
Query query = sess.createQuery("select max(an.id) from AVMNodeImpl an");
|
||||
Long val = (Long)query.uniqueResult();
|
||||
fNodeIssuer = new Issuer(val == null ? 0L : val + 1L);
|
||||
query = sess.createQuery("select max(fc.id) from FileContentImpl fc");
|
||||
val = (Long)query.uniqueResult();
|
||||
fContentIssuer = new Issuer(val == null ? 0L : val + 1L);
|
||||
query = sess.createQuery("select max(an.layerID) from AVMNodeImpl an");
|
||||
val = (Long)query.uniqueResult();
|
||||
fLayerIssuer = new Issuer(val == null ? 0L : val + 1L);
|
||||
}
|
||||
}, false);
|
||||
fSuperRepository = new SuperRepository(fNodeIssuer,
|
||||
fContentIssuer,
|
||||
fLayerIssuer,
|
||||
fStorage);
|
||||
try
|
||||
{
|
||||
createRepository("main");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// TODO Log this and abort in some useful way.
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (Exception e)
|
||||
{
|
||||
try
|
||||
{
|
||||
fTransaction.perform(
|
||||
new HibernateTxnCallback()
|
||||
{
|
||||
public void perform(Session sess)
|
||||
{
|
||||
Query query = sess.createQuery("select max(an.id) from AVMNodeImpl an");
|
||||
Long val = (Long)query.uniqueResult();
|
||||
fNodeIssuer = new Issuer(val == null ? 0L : val + 1L);
|
||||
query = sess.createQuery("select max(fc.id) from FileContentImpl fc");
|
||||
val = (Long)query.uniqueResult();
|
||||
fContentIssuer = new Issuer(val == null ? 0L : val + 1L);
|
||||
query = sess.createQuery("select max(an.layerID) from AVMNodeImpl an");
|
||||
val = (Long)query.uniqueResult();
|
||||
fLayerIssuer = new Issuer(val == null ? 0L : val + 1L);
|
||||
}
|
||||
}, false);
|
||||
fSuperRepository = new SuperRepository(fNodeIssuer,
|
||||
fContentIssuer,
|
||||
fLayerIssuer,
|
||||
fStorage);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace(System.err);
|
||||
// TODO Log this and abort in some useful way.
|
||||
}
|
||||
e.printStackTrace(System.err);
|
||||
// TODO Log this and abort in some useful way.
|
||||
}
|
||||
if (fInitialize)
|
||||
{
|
||||
createRepository("main");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Hibernate Transaction wrapper.
|
||||
* @param txn
|
||||
*/
|
||||
public void setHibernateTxn(HibernateTxn txn)
|
||||
{
|
||||
fTransaction = txn;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,21 +140,12 @@ public class AVMServiceImpl implements AVMService
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether we should drop and create tables.
|
||||
* @param createTables
|
||||
* Set whether we should create an initial repository.
|
||||
* @param initialize
|
||||
*/
|
||||
public void setCreateTables(boolean createTables)
|
||||
public void setInitialize(boolean initialize)
|
||||
{
|
||||
fCreateTables = createTables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the HibernateHelper.
|
||||
* @param helper
|
||||
*/
|
||||
public void setHibernateHelper(HibernateHelper helper)
|
||||
{
|
||||
fHibernateHelper = helper;
|
||||
fInitialize = initialize;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -23,7 +23,6 @@ import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.alfresco.repo.avm.hibernate.HibernateHelper;
|
||||
import org.hibernate.stat.Statistics;
|
||||
import org.springframework.context.support.FileSystemXmlApplicationContext;
|
||||
|
||||
|
@@ -56,6 +56,7 @@ abstract class DirectoryNodeImpl extends AVMNodeImpl implements DirectoryNode
|
||||
@SuppressWarnings("unchecked")
|
||||
protected ChildEntry getChild(String name, boolean write)
|
||||
{
|
||||
// TODO This may be very Dangerous!
|
||||
Session sess = SuperRepository.GetInstance().getSession();
|
||||
ChildEntry entry = (ChildEntry)sess.get(ChildEntryImpl.class, new ChildEntryImpl(name, this, null),
|
||||
(write && getIsNew()) ? LockMode.UPGRADE : LockMode.READ);
|
||||
|
@@ -19,7 +19,6 @@ package org.alfresco.repo.avm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.avm.hibernate.HibernateHelper;
|
||||
import org.alfresco.repo.avm.hibernate.HibernateTxn;
|
||||
import org.alfresco.repo.avm.hibernate.HibernateTxnCallback;
|
||||
import org.hibernate.Query;
|
||||
@@ -68,11 +67,6 @@ public class OrphanReaper implements Runnable
|
||||
*/
|
||||
private Thread fThread;
|
||||
|
||||
/**
|
||||
* The Hibernate helper to use.
|
||||
*/
|
||||
private HibernateHelper fHibernateHelper;
|
||||
|
||||
/**
|
||||
* Create one with default parameters.
|
||||
*/
|
||||
@@ -115,12 +109,12 @@ public class OrphanReaper implements Runnable
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the HibernateHelper to use.
|
||||
* @param helper The helper to use.
|
||||
* Set the Hibernate Transaction Wrapper.
|
||||
* @param transaction
|
||||
*/
|
||||
public void setHibernateHelper(HibernateHelper helper)
|
||||
public void setHibernateTxn(HibernateTxn transaction)
|
||||
{
|
||||
fHibernateHelper = helper;
|
||||
fTransaction = transaction;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,7 +122,6 @@ public class OrphanReaper implements Runnable
|
||||
*/
|
||||
public void init()
|
||||
{
|
||||
fTransaction = new HibernateTxn(fHibernateHelper.getSessionFactory());
|
||||
fThread = new Thread(this);
|
||||
fThread.start();
|
||||
}
|
||||
|
@@ -43,7 +43,7 @@ public class SimultaneousLoadTest extends AVMServiceTestBase
|
||||
Thread [] threads = new Thread[n];
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
Loader loader = new Loader("source", "main:/d" + i, m);
|
||||
Loader loader = new Loader("/Users/britt/stuff/" + i, "main:/d" + i, m);
|
||||
threads[i] = new Thread(loader);
|
||||
threads[i].start();
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -25,8 +25,6 @@ import java.io.OutputStream;
|
||||
|
||||
import org.alfresco.repo.avm.AVMException;
|
||||
import org.alfresco.repo.avm.AVMService;
|
||||
import org.alfresco.repo.avm.AVMServiceImpl;
|
||||
import org.alfresco.repo.avm.hibernate.HibernateHelper;
|
||||
|
||||
/**
|
||||
* This takes a filesystem directory path and a repository path and name
|
||||
|
Reference in New Issue
Block a user