Search in sources :

Example 1 with XaDataSource

use of org.neo4j.kernel.impl.transaction.xaframework.XaDataSource in project neo4j-mobile-android by neo4j-contrib.

the class TxModule method registerDataSource.

/**
 * 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());
    }
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException)

Example 2 with XaDataSource

use of org.neo4j.kernel.impl.transaction.xaframework.XaDataSource in project neo4j-mobile-android by neo4j-contrib.

the class XaDataSourceManager method getBranchId.

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 + "]");
}
Also used : XAResource(javax.transaction.xa.XAResource) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) XAException(javax.transaction.xa.XAException) XaResource(org.neo4j.kernel.impl.transaction.xaframework.XaResource) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with XaDataSource

use of org.neo4j.kernel.impl.transaction.xaframework.XaDataSource in project neo4j-mobile-android by neo4j-contrib.

the class XaDataSourceManager method unregisterAllDataSources.

synchronized void unregisterAllDataSources() {
    branchIdMapping.clear();
    sourceIdMapping.clear();
    Iterator<XaDataSource> itr = dataSources.values().iterator();
    while (itr.hasNext()) {
        XaDataSource dataSource = itr.next();
        dataSource.close();
    }
    dataSources.clear();
}
Also used : XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource)

Example 4 with XaDataSource

use of org.neo4j.kernel.impl.transaction.xaframework.XaDataSource in project graphdb by neo4j-attic.

the class MasterUtil method packResponseWithoutTransactionStream.

public static <T> Response<T> packResponseWithoutTransactionStream(GraphDatabaseService graphDb, SlaveContext context, T response) {
    XaDataSource ds = ((AbstractGraphDatabase) graphDb).getConfig().getTxModule().getXaDataSourceManager().getXaDataSource(Config.DEFAULT_DATA_SOURCE_NAME);
    StoreId storeId = ((NeoStoreXaDataSource) ds).getStoreId();
    return new Response<T>(response, storeId, TransactionStream.EMPTY);
}
Also used : StoreId(org.neo4j.kernel.impl.nioneo.store.StoreId) NeoStoreXaDataSource(org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource) NeoStoreXaDataSource(org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource)

Example 5 with XaDataSource

use of org.neo4j.kernel.impl.transaction.xaframework.XaDataSource in project graphdb by neo4j-attic.

the class Client method getMyStoreId.

protected StoreId getMyStoreId() {
    if (myStoreId == null) {
        XaDataSource ds = ((AbstractGraphDatabase) graphDb).getConfig().getTxModule().getXaDataSourceManager().getXaDataSource(Config.DEFAULT_DATA_SOURCE_NAME);
        myStoreId = ((NeoStoreXaDataSource) ds).getStoreId();
    }
    return myStoreId;
}
Also used : NeoStoreXaDataSource(org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource)

Aggregations

XaDataSource (org.neo4j.kernel.impl.transaction.xaframework.XaDataSource)22 NeoStoreXaDataSource (org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource)7 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)6 XaDataSourceManager (org.neo4j.kernel.impl.transaction.XaDataSourceManager)6 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Pair (org.neo4j.helpers.Pair)4 AbstractGraphDatabase (org.neo4j.kernel.AbstractGraphDatabase)4 ArrayList (java.util.ArrayList)3 XAException (javax.transaction.xa.XAException)3 SlaveContext (org.neo4j.com.SlaveContext)3 File (java.io.File)2 Map (java.util.Map)2 XAResource (javax.transaction.xa.XAResource)2 Test (org.junit.Test)2 StoreId (org.neo4j.kernel.impl.nioneo.store.StoreId)2 XaResource (org.neo4j.kernel.impl.transaction.xaframework.XaResource)2 FileInputStream (java.io.FileInputStream)1 FilenameFilter (java.io.FilenameFilter)1 ByteBuffer (java.nio.ByteBuffer)1