use of org.neo4j.graphdb.TransactionFailureException in project graphdb by neo4j-attic.
the class DefaultRelationshipTypeCreator method getOrCreate.
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);
}
use of org.neo4j.graphdb.TransactionFailureException in project graphdb by neo4j-attic.
the class EmbeddedGraphDbImpl method beginTx.
/**
* @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);
} catch (Exception e) {
throw new TransactionFailureException("Unable to begin transaction", e);
}
return result;
}
use of org.neo4j.graphdb.TransactionFailureException in project graphdb by neo4j-attic.
the class TxManager method init.
public void init(XaDataSourceManager xaDsManagerToUse) {
this.xaDsManager = xaDsManagerToUse;
txThreadMap = new ArrayMap<Thread, TransactionImpl>(5, true, true);
logSwitcherFileName = txLogDir + separator + "active_tx_log";
txLog1FileName = "tm_tx_log.1";
txLog2FileName = "tm_tx_log.2";
try {
if (new File(logSwitcherFileName).exists()) {
FileChannel fc = new RandomAccessFile(logSwitcherFileName, "rw").getChannel();
byte[] fileName = new byte[256];
ByteBuffer buf = ByteBuffer.wrap(fileName);
fc.read(buf);
fc.close();
String currentTxLog = txLogDir + separator + UTF8.decode(fileName).trim();
if (!new File(currentTxLog).exists()) {
throw new TransactionFailureException("Unable to start TM, " + "active tx log file[" + currentTxLog + "] not found.");
}
txLog = new TxLog(currentTxLog);
msgLog.logMessage("TM opening log: " + currentTxLog, true);
} else {
if (new File(txLogDir + separator + txLog1FileName).exists() || new File(txLogDir + separator + txLog2FileName).exists()) {
throw new TransactionFailureException("Unable to start TM, " + "no active tx log file found but found either " + txLog1FileName + " or " + txLog2FileName + " file, please set one of them as active or " + "remove them.");
}
ByteBuffer buf = ByteBuffer.wrap(txLog1FileName.getBytes("UTF-8"));
FileChannel fc = new RandomAccessFile(logSwitcherFileName, "rw").getChannel();
fc.write(buf);
txLog = new TxLog(txLogDir + separator + txLog1FileName);
msgLog.logMessage("TM new log: " + txLog1FileName, true);
fc.force(true);
fc.close();
}
Iterator<List<TxLog.Record>> danglingRecordList = txLog.getDanglingRecords();
if (danglingRecordList.hasNext()) {
log.info("Unresolved transactions found, " + "recovery started ...");
recover(danglingRecordList);
log.info("Recovery completed, all transactions have been " + "resolved to a consistent state.");
msgLog.logMessage("Recovery completed, all transactions have been " + "resolved to a consistent state.");
}
getTxLog().truncate();
tmOk = true;
} catch (IOException e) {
log.severe("Unable to start TM");
throw new TransactionFailureException("Unable to start TM", e);
}
}
use of org.neo4j.graphdb.TransactionFailureException 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.graphdb.TransactionFailureException 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);
}
}
Aggregations