Java 类org.neo4j.graphdb.TransactionFailureException 实例源码

项目:neo4j-mobile-android    文件:IndexManagerImpl.java   
private Map<String, String> getOrCreateIndexConfig( Class<? extends PropertyContainer> cls,
        String indexName, Map<String, String> suppliedConfig )
{
    Pair<Map<String, String>, Boolean> result = findIndexConfig( cls,
            indexName, suppliedConfig, graphDbImpl.getConfig().getParams() );
    if ( result.other() )
    {
        IndexCreatorThread creator = new IndexCreatorThread( cls, indexName, result.first() );
        creator.start();
        try
        {
            creator.join();
            if ( creator.exception != null )
            {
                throw new TransactionFailureException( "Index creation failed for " + indexName +
                        ", " + result.first(), creator.exception );
            }
        }
        catch ( InterruptedException e )
        {
            Thread.interrupted();
        }
    }
    return result.first();
}
项目:neo4j-mobile-android    文件:XaTransaction.java   
/**
 * Adds the command to transaction. First writes the command to the logical
 * log then calls {@link #doAddCommand}. Also check
 * {@link XaConnectionHelpImpl} class documentation example.
 * 
 * @param command
 *            The command to add to transaction
 * @throws RuntimeException
 *             If problem writing command to logical log or this transaction
 *             is committed or rolled back
 */
public final void addCommand( XaCommand command )
{
    if ( committed )
    {
        throw new TransactionFailureException(
            "Cannot add command to committed transaction" );
    }
    if ( rolledback )
    {
        throw new TransactionFailureException(
            "Cannot add command to rolled back transaction" );
    }
    doAddCommand( command );
    try
    {
        log.writeCommand( command, identifier );
    }
    catch ( IOException e )
    {
        throw new TransactionFailureException(
            "Unable to write command to logical log.", e );
    }
}
项目:neo4j-mobile-android    文件:TxModule.java   
/**
 * Use this method to add data source that can participate in transactions
 * if you don't want a data source configuration file.
 *
 * @param name
 *            The data source name
 * @param className
 *            The (full) class name of class
 * @param resourceId
 *            The resource id identifying datasource
 * @param params
 *            The configuration map for the datasource
 * @throws LifecycleException
 */
public XaDataSource registerDataSource( String dsName, String className,
    byte resourceId[], Map<?,?> params )
{
    XaDataSourceManager xaDsMgr = xaDsManager;
    String name = dsName.toLowerCase();
    if ( xaDsMgr.hasDataSource( name ) )
    {
        throw new TransactionFailureException( "Data source[" + name
            + "] has already been registered" );
    }
    try
    {
        XaDataSource dataSource = xaDsMgr.create( className, params );
        xaDsMgr.registerDataSource( name, dataSource, resourceId );
        return dataSource;
    }
    catch ( Exception e )
    {
        throw new TransactionFailureException(
            "Could not create data source [" + name
            + "], see nested exception for cause of error", e.getCause() );
    }
}
项目:neo4j-mobile-android    文件:TxModule.java   
public XaDataSource registerDataSource( String dsName, String className,
    byte resourceId[], Map<?,?> params, boolean useExisting )
{
    XaDataSourceManager xaDsMgr = xaDsManager;
    String name = dsName.toLowerCase();
    if ( xaDsMgr.hasDataSource( name ) )
    {
        if ( useExisting )
        {
            return xaDsMgr.getXaDataSource( name );
        }
        throw new TransactionFailureException( "Data source[" + name
            + "] has already been registered" );
    }
    try
    {
        XaDataSource dataSource = xaDsMgr.create( className, params );
        xaDsMgr.registerDataSource( name, dataSource, resourceId );
        return dataSource;
    }
    catch ( Exception e )
    {
        throw new TransactionFailureException(
            "Could not create data source " + name + "[" + name + "]", e );
    }
}
项目:neo4j-mobile-android    文件:PersistenceManager.java   
void delistResourcesForTransaction() throws NotInTransactionException
{
    Transaction tx = this.getCurrentTransaction();
    if ( tx == null )
    {
        throw new NotInTransactionException();
    }
    NeoStoreTransaction con = txConnectionMap.get( tx );
    if ( con != null )
    {
        try
        {
            tx.delistResource( con.getXAResource(), XAResource.TMSUCCESS );
        }
        catch ( SystemException e )
        {
            throw new TransactionFailureException(
                "Failed to delist resource '" + con +
                "' from current transaction.", e );
        }
    }
}
项目:neo4j-mobile-android    文件:EmbeddedGraphDbImpl.java   
/**
 * @throws TransactionFailureException if unable to start transaction
 */
public Transaction beginTx()
{
    if ( graphDbInstance.transactionRunning() )
    {
        if ( placeboTransaction == null )
        {
            placeboTransaction = new PlaceboTransaction(
                    graphDbInstance.getTransactionManager() );
        }
        return placeboTransaction;
    }
    TransactionManager txManager = graphDbInstance.getTransactionManager();
    Transaction result = null;
    try
    {
        txManager.begin();
        result = new TopLevelTransaction( txManager, txManager.getTransaction() );
    }
    catch ( Exception e )
    {
        throw new TransactionFailureException(
            "Unable to begin transaction", e );
    }
    return result;
}
项目:SciGraph    文件:Neo4jModuleTest.java   
@Test(expected = TransactionFailureException.class)
public void graphDbReadOnlyWithApi() {
  GraphDatabaseService graphDb = injectorReadOnly.getInstance(GraphDatabaseService.class);
  Transaction tx = graphDb.beginTx();
  try {
    graphDb.createNode(Label.label("test"));
  } finally {
    tx.close();
  }
}
项目:SciGraph    文件:Neo4jModuleTest.java   
@Test(expected = TransactionFailureException.class)
public void graphDbReadOnlyWithCypher() {
  GraphDatabaseService graphDb = injectorReadOnly.getInstance(GraphDatabaseService.class);
  Transaction tx = graphDb.beginTx();
  try {
    graphDb.execute("CREATE (n: test)");
  } finally {
    tx.close();
  }
}
项目:neo4j-mobile-android    文件:GraphDbInstance.java   
public boolean transactionRunning()
{
    try
    {
        return config.getTxModule().getTxManager().getTransaction() != null;
    }
    catch ( Exception e )
    {
        throw new TransactionFailureException(
                "Unable to get transaction.", e );
    }
}
项目:neo4j-mobile-android    文件:TopLevelTransaction.java   
public void failure()
{
    transactionOutcome.failed();
    try
    {
        transactionManager.getTransaction().setRollbackOnly();
    }
    catch ( Exception e )
    {
        throw new TransactionFailureException(
            "Failed to mark transaction as rollback only.", e );
    }
}
项目:neo4j-mobile-android    文件:PlaceboTransaction.java   
public void failure()
{
    try
    {
        transactionManager.getTransaction().setRollbackOnly();
    }
    catch ( Exception e )
    {
        throw new TransactionFailureException(
            "Failed to mark transaction as rollback only.", e );
    }
}
项目:neo4j-mobile-android    文件:TxManager.java   
private XaDataSource xaResourceToDataSource( XAResource participant )
{
    byte[] participantBranchId = xaDsManager.getBranchId( participant );
    for ( XaDataSource dataSource : xaDsManager.getAllRegisteredDataSources() )
    {
        if ( Arrays.equals( participantBranchId, dataSource.getBranchId() ) )
        {
            return dataSource;
        }
    }
    throw logAndReturn("TM recovery data source not found",
            new TransactionFailureException("Data source for recovery participant " + participant +
                    ", " + Arrays.toString(participantBranchId) + " couldn't be found"));
}
项目:neo4j-mobile-android    文件:RagManager.java   
Transaction getCurrentTransaction()
{
    try
    {
        return tm.getTransaction();
    }
    catch ( SystemException e )
    {
        throw new TransactionFailureException(
            "Could not get current transaction.", e );
    }
}
项目:neo4j-mobile-android    文件:XaDataSourceManager.java   
synchronized byte[] getBranchId( XAResource xaResource )
{
    if ( xaResource instanceof XaResource )
    {
        byte branchId[] = ((XaResource) xaResource).getBranchId();
        if ( branchId != null )
        {
            return branchId;
        }
    }
    Iterator<Map.Entry<String,XaDataSource>> itr = 
        dataSources.entrySet().iterator();
    while ( itr.hasNext() )
    {
        Map.Entry<String,XaDataSource> entry = itr.next();
        XaDataSource dataSource = entry.getValue();
        XAResource resource = dataSource.getXaConnection().getXaResource();
        try
        {
            if ( resource.isSameRM( xaResource ) )
            {
                String name = entry.getKey();
                return sourceIdMapping.get( name );
            }
        }
        catch ( XAException e )
        {
            throw new TransactionFailureException( 
                "Unable to check is same resource", e );
        }
    }
    throw new TransactionFailureException( 
        "Unable to find mapping for XAResource[" + xaResource + "]" );
}
项目:neo4j-mobile-android    文件:XaDataSourceManager.java   
synchronized XAResource getXaResource( byte branchId[] )
{
    XaDataSource dataSource = branchIdMapping.get( UTF8.decode( branchId ) );
    if ( dataSource == null )
    {
        throw new TransactionFailureException( 
            "No mapping found for branchId[0x" +
            UTF8.decode( branchId ) + "]" );
    }
    return dataSource.getXaConnection().getXaResource();
}
项目:neo4j-mobile-android    文件:PersistenceManager.java   
private Transaction getCurrentTransaction()
    throws NotInTransactionException
{
    try
    {
        return transactionManager.getTransaction();
    }
    catch ( SystemException se )
    {
        throw new TransactionFailureException( "Error fetching transaction "
            + "for current thread", se );
    }
}
项目:neo4j-mobile-android    文件:NeoStoreXaConnection.java   
public WriteTransaction getWriteTransaction()
{
    // Is only called once per write transaction so no need
    // to cache the transaction here.
    try
    {
        return (WriteTransaction) getTransaction();
    }
    catch ( XAException e )
    {
        throw new TransactionFailureException( 
            "Unable to get transaction.", e );
    }
}
项目:neo4j-mobile-android    文件:PropertyIndexManager.java   
private Transaction getTransaction()
{
    try
    {
        return transactionManager.getTransaction();
    }
    catch ( Exception e )
    {
        throw new TransactionFailureException( 
            "Unable to get transaction.", e );
    }
}
项目:neo4j-mobile-android    文件:DefaultRelationshipTypeCreator.java   
public int getOrCreate( TransactionManager txManager, EntityIdGenerator idGenerator,
        PersistenceManager persistence, RelationshipTypeHolder relTypeHolder, String name )
{
    RelTypeCreater createrThread = new RelTypeCreater( name, txManager, idGenerator,
            persistence );
    synchronized ( createrThread )
    {
        createrThread.start();
        while ( createrThread.isAlive() )
        {
            try
            {
                createrThread.wait( 50 );
            }
            catch ( InterruptedException e )
            {
                Thread.interrupted();
            }
        }
    }
    if ( createrThread.succeded() )
    {
        int id = createrThread.getRelTypeId();
        relTypeHolder.addRawRelationshipType( new RelationshipTypeData( id, name ) );
        return id;
    }
    throw new TransactionFailureException(
            "Unable to create relationship type " + name );
}
项目:neo4j-mobile-android    文件:LockReleaser.java   
private Transaction getTransaction()
{
    try
    {
        return transactionManager.getTransaction();
    }
    catch ( SystemException e )
    {
        throw new TransactionFailureException(
            "Failed to get current transaction.", e );
    }
}
项目:obelix    文件:ObelixCache.java   
public final void buildCacheFromCacheQueue() {
    List<String> allUsers = this.graphDb.getAllUserIds();
    List<String> usersHandledAlready = new ArrayList<>();

    int imported = 0;
    while (true) {
        ObelixQueueElement user = redisQueueManager.pop();

        if (user == null) {
            break;
        }

        String userID = (String) user.getData().get("user_id");

        if (userID.equals("") || userID.equals("0")) {
            break;
        }

        // We only create the cache for unique users every 50 entry imported.
        if (usersHandledAlready.contains(userID)) {
            LOGGER.info("Skipping creation of recommendations for " + user);
            continue;
        }

        if (allUsers.contains(userID)) {
            imported += 1;
            try {
                buildCacheForUser(userID);
                usersHandledAlready.add(userID);
            } catch (TransactionFailureException e) {
                LOGGER.error("Pushing user [" + userID + "]back on the queue because: "
                        + e.getMessage());

                usersHandledAlready.remove(userID);
                redisQueueManager.push(user);
            }
        }

        if (imported >= LIMIT_CACHE_BUILDS_BEFORE_SLEEP) {
            break;
        }
    }

    if (imported > 0) {
        LOGGER.debug("Built " + imported + " recommendation caches!");
    }
}
项目:neo4j-mobile-android    文件:TxManager.java   
private void buildRecoveryInfo( List<NonCompletedTransaction> commitList,
    List<Xid> rollbackList, Map<Resource,XAResource> resourceMap,
    Iterator<List<TxLog.Record>> danglingRecordList )
{
    while ( danglingRecordList.hasNext() )
    {
        Iterator<TxLog.Record> dListItr =
            danglingRecordList.next().iterator();
        TxLog.Record startRecord = dListItr.next();
        if ( startRecord.getType() != TxLog.TX_START )
        {
            throw logAndReturn("TM error building recovery info",
                    new TransactionFailureException(
                "First record not a start record, type="
                    + startRecord.getType() ));
        }
        // get branches & commit status
        HashSet<Resource> branchSet = new HashSet<Resource>();
        int markedCommit = -1;
        while ( dListItr.hasNext() )
        {
            TxLog.Record record = dListItr.next();
            if ( record.getType() == TxLog.BRANCH_ADD )
            {
                if ( markedCommit != -1 )
                {

                    throw logAndReturn("TM error building recovery info", new TransactionFailureException(
                        "Already marked commit " + startRecord ));
                }
                branchSet.add( new Resource( record.getBranchId() ) );
            }
            else if ( record.getType() == TxLog.MARK_COMMIT )
            {
                if ( markedCommit != -1 )
                {
                    throw logAndReturn("TM error building recovery info",new TransactionFailureException(
                        "Already marked commit " + startRecord ));
                }
                markedCommit = record.getSequenceNumber();
            }
            else
            {
                throw logAndReturn("TM error building recovery info",new TransactionFailureException(
                    "Illegal record type[" + record.getType() + "]" ));
            }
        }
        Iterator<Resource> resourceItr = branchSet.iterator();
        List<Xid> xids = new LinkedList<Xid>();
        while ( resourceItr.hasNext() )
        {
            Resource resource = resourceItr.next();
            if ( !resourceMap.containsKey( resource ) )
            {
                resourceMap.put( resource, getXaResource(
                    resource.getResourceId() ) );
            }
            xids.add( new XidImpl( startRecord.getGlobalId(),
                resource.getResourceId() ) );
        }
        if ( markedCommit != -1 ) // this xid needs to be committed
        {
            commitList.add(
                new NonCompletedTransaction( markedCommit, xids ) );
        }
        else
        {
            rollbackList.addAll( xids );
        }
    }
}
项目:neo4j-mobile-android    文件:LockReleaser.java   
/**
 * Invoking this method with no transaction running will cause the lock to
 * be released right away.
 *
 * @param resource
 *            the resource on which the lock is taken
 * @param type
 *            type of lock (READ or WRITE)
 * @throws NotInTransactionException
 */
public void addLockToTransaction( Object resource, LockType type )
    throws NotInTransactionException
{
    Transaction tx = getTransaction();
    List<LockElement> lockElements = lockMap.get( tx );
    if ( lockElements != null )
    {
        lockElements.add( new LockElement( resource, type ) );
    }
    else
    {
        if ( tx == null )
        {
            // no transaction we release lock right away
            if ( type == LockType.WRITE )
            {
                lockManager.releaseWriteLock( resource, null );
            }
            else if ( type == LockType.READ )
            {
                lockManager.releaseReadLock( resource, null );
            }
            return;
        }
        lockElements = new ArrayList<LockElement>();
        lockMap.put( tx, lockElements );
        lockElements.add( new LockElement( resource, type ) );
        // we have to have a synchronization hook for read only transaction,
        // write locks can be taken in read only transactions (ex:
        // transactions that perform write operations that cancel each other
        // out). This sync hook will only release locks if they exist and
        // tx was read only
        try
        {
            tx.registerSynchronization( new ReadOnlyTxReleaser( tx ) );
        }
        catch ( Exception e )
        {
            throw new TransactionFailureException(
                "Failed to register lock release synchronization hook", e );
        }
    }
}