Search in sources :

Example 11 with XaDataSource

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

the class OnlineBackup method slaveContextOf.

@SuppressWarnings("unchecked")
private SlaveContext slaveContextOf(GraphDatabaseService graphDb) {
    XaDataSourceManager dsManager = ((AbstractGraphDatabase) graphDb).getConfig().getTxModule().getXaDataSourceManager();
    List<Pair<String, Long>> txs = new ArrayList<Pair<String, Long>>();
    for (XaDataSource ds : dsManager.getAllRegisteredDataSources()) {
        txs.add(Pair.of(ds.getName(), ds.getLastCommittedTxId()));
    }
    return new SlaveContext(0, 0, txs.toArray(new Pair[0]));
}
Also used : SlaveContext(org.neo4j.com.SlaveContext) XaDataSourceManager(org.neo4j.kernel.impl.transaction.XaDataSourceManager) ArrayList(java.util.ArrayList) AbstractGraphDatabase(org.neo4j.kernel.AbstractGraphDatabase) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource) Pair(org.neo4j.helpers.Pair)

Example 12 with XaDataSource

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

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 13 with XaDataSource

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

the class TxModule method registerDataSource.

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

Example 14 with XaDataSource

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

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 15 with XaDataSource

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

the class TestNeo4j method testKeepLogsConfig.

@Test
public void testKeepLogsConfig() {
    Map<String, String> config = new HashMap<String, String>();
    config.put(Config.KEEP_LOGICAL_LOGS, "nioneodb");
    String storeDir = "target/configdb";
    deleteFileOrDirectory(storeDir);
    EmbeddedGraphDatabase db = new EmbeddedGraphDatabase(storeDir, config);
    XaDataSourceManager xaDsMgr = db.getConfig().getTxModule().getXaDataSourceManager();
    XaDataSource xaDs = xaDsMgr.getXaDataSource("nioneodb");
    assertTrue(xaDs.isLogicalLogKept());
    db.shutdown();
    config.remove(Config.KEEP_LOGICAL_LOGS);
    db = new EmbeddedGraphDatabase(storeDir, config);
    xaDsMgr = db.getConfig().getTxModule().getXaDataSourceManager();
    xaDs = xaDsMgr.getXaDataSource("nioneodb");
    assertTrue(!xaDs.isLogicalLogKept());
    db.shutdown();
    config.put(Config.KEEP_LOGICAL_LOGS, "true");
    db = new EmbeddedGraphDatabase(storeDir, config);
    xaDsMgr = db.getConfig().getTxModule().getXaDataSourceManager();
    xaDs = xaDsMgr.getXaDataSource("nioneodb");
    assertTrue(xaDs.isLogicalLogKept());
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) XaDataSourceManager(org.neo4j.kernel.impl.transaction.XaDataSourceManager) HashMap(java.util.HashMap) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource) Test(org.junit.Test)

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