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]));
}
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());
}
}
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);
}
}
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 + "]");
}
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());
}
Aggregations