diff --git a/config/alfresco/bootstrap-context.xml b/config/alfresco/bootstrap-context.xml index 53c7e94a20..12c0ca21a0 100644 --- a/config/alfresco/bootstrap-context.xml +++ b/config/alfresco/bootstrap-context.xml @@ -97,7 +97,7 @@ - + diff --git a/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.Dialect/AlfrescoSchemaUpdate-Person.sql b/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.Dialect/AlfrescoSchemaUpdate-Person.sql index 4e81768fc4..6d0e659ece 100644 --- a/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.Dialect/AlfrescoSchemaUpdate-Person.sql +++ b/config/alfresco/dbscripts/upgrade/2.2/org.hibernate.dialect.Dialect/AlfrescoSchemaUpdate-Person.sql @@ -57,11 +57,11 @@ UPDATE -- -- Record script finish -- -DELETE FROM alf_applied_patch WHERE id = 'patch.db-V2.2-Person-2'; +DELETE FROM alf_applied_patch WHERE id = 'patch.db-V2.2-Person-3'; INSERT INTO alf_applied_patch (id, description, fixes_from_schema, fixes_to_schema, applied_to_schema, target_schema, applied_on_date, applied_to_server, was_executed, succeeded, report) VALUES ( - 'patch.db-V2.2-Person-2', 'Manually executed script upgrade V2.2: Person user name also in the association qname', - 0, 2005, -1, 2006, null, 'UNKOWN', 1, 1, 'Script completed' + 'patch.db-V2.2-Person-3', 'Manually executed script upgrade V2.2: Person user name also in the association qname', + 0, 3002, -1, 3003, null, 'UNKOWN', 1, 1, 'Script completed' ); diff --git a/config/alfresco/patch/patch-services-context.xml b/config/alfresco/patch/patch-services-context.xml index fcb207298b..d994b882b8 100644 --- a/config/alfresco/patch/patch-services-context.xml +++ b/config/alfresco/patch/patch-services-context.xml @@ -1633,12 +1633,12 @@ - - patch.db-V2.2-Person-2 + + patch.db-V2.2-Person-3 patch.schemaUpgradeScript.description 0 - 2005 - 2006 + 3002 + 3003 classpath:alfresco/dbscripts/upgrade/2.2/${db.script.dialect}/AlfrescoSchemaUpdate-Person.sql diff --git a/config/alfresco/version.properties b/config/alfresco/version.properties index 640cf8e2d7..490ed48683 100644 --- a/config/alfresco/version.properties +++ b/config/alfresco/version.properties @@ -19,4 +19,4 @@ version.build=@build-number@ # Schema number -version.schema=3002 +version.schema=3003 diff --git a/source/java/org/alfresco/repo/search/impl/lucene/AbstractLuceneIndexerAndSearcherFactory.java b/source/java/org/alfresco/repo/search/impl/lucene/AbstractLuceneIndexerAndSearcherFactory.java index b5b81e1e78..457bf74581 100644 --- a/source/java/org/alfresco/repo/search/impl/lucene/AbstractLuceneIndexerAndSearcherFactory.java +++ b/source/java/org/alfresco/repo/search/impl/lucene/AbstractLuceneIndexerAndSearcherFactory.java @@ -77,6 +77,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.transaction.support.TransactionSynchronizationManager; /** * This class is resource manager LuceneIndexers and LuceneSearchers. It supports two phase commit inside XA @@ -110,13 +111,12 @@ public abstract class AbstractLuceneIndexerAndSearcherFactory implements LuceneI private Map> suspendedIndexersInGlobalTx = new HashMap>(); /** - * Thread local indexers - used outside a global transaction + * The key under which this instance's map of indexers is stored in a (non-global) transaction */ - - private ThreadLocal> threadLocalIndexers = new ThreadLocal>(); + private final String indexersKey = "AbstractLuceneIndexerAndSearcherFactory." + GUID.generate(); /** - * The dafault timeout for transactions TODO: Respect this + * The default timeout for transactions TODO: Respect this */ private int timeout = DEFAULT_TIMEOUT; @@ -393,13 +393,14 @@ public abstract class AbstractLuceneIndexerAndSearcherFactory implements LuceneI } + @SuppressWarnings("unchecked") private LuceneIndexer getThreadLocalIndexer(StoreRef storeRef) { - Map indexers = threadLocalIndexers.get(); + Map indexers = (Map) AlfrescoTransactionSupport.getResource(indexersKey); if (indexers == null) { indexers = new HashMap(); - threadLocalIndexers.set(indexers); + AlfrescoTransactionSupport.bindResource(indexersKey, indexers); } LuceneIndexer indexer = indexers.get(storeRef); if (indexer == null) @@ -411,11 +412,12 @@ public abstract class AbstractLuceneIndexerAndSearcherFactory implements LuceneI } /** - * Get the transaction identifier uised to store it in the transaction map. + * Get the transaction identifier used to store it in the transaction map. * * @param tx * @return - the transaction id */ + @SuppressWarnings("unchecked") private String getTransactionId(Transaction tx, StoreRef storeRef) { if (tx instanceof SimpleTransaction) @@ -423,9 +425,10 @@ public abstract class AbstractLuceneIndexerAndSearcherFactory implements LuceneI SimpleTransaction simpleTx = (SimpleTransaction) tx; return simpleTx.getGUID(); } - else + else if (TransactionSynchronizationManager.isSynchronizationActive()) { - Map indexers = threadLocalIndexers.get(); + Map indexers = (Map) AlfrescoTransactionSupport + .getResource(indexersKey); if (indexers != null) { LuceneIndexer indexer = indexers.get(storeRef); @@ -434,8 +437,8 @@ public abstract class AbstractLuceneIndexerAndSearcherFactory implements LuceneI return indexer.getDeltaId(); } } - return null; } + return null; } /** @@ -741,11 +744,13 @@ public abstract class AbstractLuceneIndexerAndSearcherFactory implements LuceneI * Commit the transaction */ + @SuppressWarnings("unchecked") public void commit() throws IndexerException { + Map indexers = null; try { - Map indexers = threadLocalIndexers.get(); + indexers = (Map) AlfrescoTransactionSupport.getResource(indexersKey); if (indexers != null) { for (LuceneIndexer indexer : indexers.values()) @@ -764,10 +769,10 @@ public abstract class AbstractLuceneIndexerAndSearcherFactory implements LuceneI } finally { - if (threadLocalIndexers.get() != null) + if (indexers != null) { - threadLocalIndexers.get().clear(); - threadLocalIndexers.set(null); + indexers.clear(); + AlfrescoTransactionSupport.unbindResource(indexersKey); } } } @@ -777,11 +782,12 @@ public abstract class AbstractLuceneIndexerAndSearcherFactory implements LuceneI * * @return - the tx code */ + @SuppressWarnings("unchecked") public int prepare() throws IndexerException { boolean isPrepared = true; boolean isModified = false; - Map indexers = threadLocalIndexers.get(); + Map indexers = (Map) AlfrescoTransactionSupport.getResource(indexersKey); if (indexers != null) { for (LuceneIndexer indexer : indexers.values()) @@ -818,9 +824,10 @@ public abstract class AbstractLuceneIndexerAndSearcherFactory implements LuceneI /** * Roll back the transaction */ + @SuppressWarnings("unchecked") public void rollback() { - Map indexers = threadLocalIndexers.get(); + Map indexers = (Map) AlfrescoTransactionSupport.getResource(indexersKey); if (indexers != null) { @@ -835,20 +842,16 @@ public abstract class AbstractLuceneIndexerAndSearcherFactory implements LuceneI } } + indexers.clear(); + AlfrescoTransactionSupport.unbindResource(indexersKey); } - - if (threadLocalIndexers.get() != null) - { - threadLocalIndexers.get().clear(); - threadLocalIndexers.set(null); - } - } + @SuppressWarnings("unchecked") public void flush() { // TODO: Needs fixing if we expose the indexer in JTA - Map indexers = threadLocalIndexers.get(); + Map indexers = (Map) AlfrescoTransactionSupport.getResource(indexersKey); if (indexers != null) {