Moving to root below branch label

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2005 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2005-12-08 07:13:07 +00:00
commit e1e6508fec
1095 changed files with 230566 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2005 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.search.transaction;
import java.util.HashMap;
import java.util.concurrent.locks.ReentrantLock;
import org.alfresco.service.cmr.repository.StoreRef;
public class LuceneIndexLock
{
private HashMap<StoreRef, ReentrantLock> locks = new HashMap<StoreRef, ReentrantLock> ();
public LuceneIndexLock()
{
super();
}
public void getReadLock(StoreRef ref)
{
return;
}
public void releaseReadLock(StoreRef ref)
{
return;
}
public void getWriteLock(StoreRef ref)
{
ReentrantLock lock;
synchronized(locks)
{
lock = locks.get(ref);
if(lock == null)
{
lock = new ReentrantLock(true);
locks.put(ref, lock);
}
}
lock.lock();
}
public void releaseWriteLock(StoreRef ref)
{
ReentrantLock lock;
synchronized(locks)
{
lock = locks.get(ref);
}
if(lock != null)
{
lock.unlock();
}
}
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright (C) 2005 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.search.transaction;
import org.springframework.transaction.TransactionException;
/**
* @author Andy Hind
*/
public class LuceneTransactionException extends TransactionException
{
private static final long serialVersionUID = 3978985453464335925L;
public LuceneTransactionException(String arg0)
{
super(arg0);
}
public LuceneTransactionException(String arg0, Throwable arg1)
{
super(arg0, arg1);
}
}

View File

@@ -0,0 +1,205 @@
/*
* Copyright (C) 2005 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.search.transaction;
import java.io.UnsupportedEncodingException;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import javax.transaction.xa.XAResource;
import org.alfresco.util.GUID;
public class SimpleTransaction implements XidTransaction
{
private static final int DEFAULT_TIMEOUT = 600;
private boolean isRollBackOnly;
private int timeout;
public static final int FORMAT_ID = 12321;
private static final String CHAR_SET = "UTF-8";
private byte[] globalTransactionId;
private byte[] branchQualifier;
// This is the transactoin id
private String guid;
private static ThreadLocal<SimpleTransaction> transaction = new ThreadLocal<SimpleTransaction>();
private SimpleTransaction(int timeout)
{
super();
this.timeout = timeout;
guid = GUID.generate();
try
{
globalTransactionId = guid.getBytes(CHAR_SET);
}
catch (UnsupportedEncodingException e)
{
throw new XidException(e);
}
branchQualifier = new byte[0];
}
private SimpleTransaction()
{
this(DEFAULT_TIMEOUT);
}
public static SimpleTransaction getTransaction()
{
return (SimpleTransaction) transaction.get();
}
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
SecurityException, SystemException
{
try
{
if (isRollBackOnly)
{
throw new RollbackException("Commit failed: Transaction marked for rollback");
}
}
finally
{
transaction.set(null);
}
}
public boolean delistResource(XAResource arg0, int arg1) throws IllegalStateException, SystemException
{
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
}
public boolean enlistResource(XAResource arg0) throws RollbackException, IllegalStateException, SystemException
{
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
}
public int getStatus() throws SystemException
{
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
}
public void registerSynchronization(Synchronization arg0) throws RollbackException, IllegalStateException,
SystemException
{
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
}
public void rollback() throws IllegalStateException, SystemException
{
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
}
public void setRollbackOnly() throws IllegalStateException, SystemException
{
isRollBackOnly = true;
}
/*
* Support for suspend, resume and begin.
*/
/* package */static SimpleTransaction suspend()
{
SimpleTransaction tx = getTransaction();
transaction.set(null);
return tx;
}
/* package */static void begin() throws NotSupportedException
{
if (getTransaction() != null)
{
throw new NotSupportedException("Nested transactions are not supported");
}
transaction.set(new SimpleTransaction());
}
/* package */static void resume(SimpleTransaction tx)
{
if (getTransaction() != null)
{
throw new IllegalStateException("A transaction is already associated with the thread");
}
transaction.set((SimpleTransaction) tx);
}
public String getGUID()
{
return guid;
}
public boolean equals(Object o)
{
if (this == o)
{
return true;
}
if (!(o instanceof SimpleTransaction))
{
return false;
}
SimpleTransaction other = (SimpleTransaction) o;
return this.getGUID().equals(other.getGUID());
}
public int hashCode()
{
return getGUID().hashCode();
}
public String toString()
{
StringBuffer buffer = new StringBuffer(128);
buffer.append("Simple Transaction GUID = " + getGUID());
return buffer.toString();
}
public int getFormatId()
{
return FORMAT_ID;
}
public byte[] getGlobalTransactionId()
{
return globalTransactionId;
}
public byte[] getBranchQualifier()
{
return branchQualifier;
}
}

View File

@@ -0,0 +1,109 @@
/*
* Copyright (C) 2005 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.search.transaction;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.InvalidTransactionException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
public class SimpleTransactionManager implements TransactionManager
{
private static SimpleTransactionManager manager = new SimpleTransactionManager();
private int timeout;
private SimpleTransactionManager()
{
super();
}
public static SimpleTransactionManager getInstance()
{
return manager;
}
public void begin() throws NotSupportedException, SystemException
{
SimpleTransaction.begin();
}
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
SecurityException, IllegalStateException, SystemException
{
SimpleTransaction transaction = getTransactionChecked();
transaction.commit();
}
public int getStatus() throws SystemException
{
SimpleTransaction transaction = getTransactionChecked();
return transaction.getStatus();
}
public SimpleTransaction getTransaction() throws SystemException
{
return SimpleTransaction.getTransaction();
}
private SimpleTransaction getTransactionChecked() throws SystemException, IllegalStateException
{
SimpleTransaction tx = SimpleTransaction.getTransaction();
if (tx == null)
{
throw new IllegalStateException("The thread is not bound to a transaction.");
}
return tx;
}
public void resume(Transaction tx) throws InvalidTransactionException, IllegalStateException, SystemException
{
if (!(tx instanceof SimpleTransaction))
{
throw new IllegalStateException("Transaction must be a SimpleTransaction to resume");
}
SimpleTransaction.resume((SimpleTransaction) tx);
}
public void rollback() throws IllegalStateException, SecurityException, SystemException
{
SimpleTransaction transaction = getTransactionChecked();
transaction.rollback();
}
public void setRollbackOnly() throws IllegalStateException, SystemException
{
SimpleTransaction transaction = getTransactionChecked();
transaction.setRollbackOnly();
}
public void setTransactionTimeout(int timeout) throws SystemException
{
this.timeout = timeout;
}
public SimpleTransaction suspend() throws SystemException
{
return SimpleTransaction.suspend();
}
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright (C) 2005 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.search.transaction;
public class XidException extends RuntimeException
{
/**
*
*/
private static final long serialVersionUID = 3257847696969840185L;
public XidException()
{
super();
}
public XidException(String message)
{
super(message);
}
public XidException(String message, Throwable cause)
{
super(message, cause);
}
public XidException(Throwable cause)
{
super(cause);
}
}

View File

@@ -0,0 +1,25 @@
/*
* Copyright (C) 2005 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.search.transaction;
import javax.transaction.Transaction;
import javax.transaction.xa.Xid;
public interface XidTransaction extends Xid, Transaction
{
}