use of javax.resource.ResourceException in project teiid by teiid.
the class CoherenceUpdateExecution method executeDelete.
private void executeDelete() throws TranslatorException {
DeleteVisitor visitor = new DeleteVisitor(metadata);
visitor.visitNode((Delete) command);
if (visitor.getException() != null) {
throw visitor.getException();
}
if (visitor.getKeys() == null || visitor.getKeys().isEmpty()) {
// $NON-NLS-1$
final String msg = CoherencePlugin.Util.getString("CoherenceUpdateExecution.objectNotDeleted", new Object[] { visitor.getTableName() });
throw new TranslatorException(msg);
}
for (java.util.Iterator it = visitor.getKeys().iterator(); it.hasNext(); ) {
Object key = it.next();
try {
this.connection.remove(key);
} catch (ResourceException e) {
throw new TranslatorException(e);
}
}
}
use of javax.resource.ResourceException in project teiid by teiid.
the class CoherenceConnectionImpl method update.
public void update(Object key, Object object) throws ResourceException {
NamedCache sourceCache = getCache();
if (!sourceCache.containsKey(key)) {
throw new ResourceException("Unable to update object for key: " + key + " to cache " + this.cacheName + ", because it already exist");
}
TransactionMap tmap = CacheFactory.getLocalTransaction(sourceCache);
tmap.setTransactionIsolation(TransactionMap.TRANSACTION_REPEATABLE_GET);
tmap.setConcurrency(TransactionMap.CONCUR_PESSIMISTIC);
tmap.begin();
try {
tmap.put(key, object);
tmap.prepare();
tmap.commit();
} catch (Exception e) {
throw new ResourceException(e);
}
sourceCache = getCache();
if (!sourceCache.containsKey(key)) {
throw new ResourceException("Problem updating object for key: " + key + " to the cache " + this.cacheName + ", object not found after add");
}
}
use of javax.resource.ResourceException in project jaybird by FirebirdSQL.
the class FBXADataSource method initialize.
private void initialize() throws SQLException {
synchronized (lock) {
if (internalDs != null) {
return;
}
try {
GDSType gdsType = GDSType.getType(getType());
if (gdsType == null) {
gdsType = GDSFactory.getDefaultGDSType();
}
FBManagedConnectionFactory mcf = new FBManagedConnectionFactory(gdsType, getConnectionProperties());
mcf.setDefaultConnectionManager(new XAConnectionManager());
internalDs = (FBDataSource) mcf.createConnectionFactory();
internalDs.setLogWriter(getLogWriter());
} catch (ResourceException e) {
throw new FBSQLException(e);
}
}
}
use of javax.resource.ResourceException in project jaybird by FirebirdSQL.
the class FBManagedConnection method findSingleXid.
/**
* Obtain a single prepared transaction branch from a resource manager, based on a Xid
*
* @param externalXid
* The Xid to find
* @return The Xid if found, otherwise null.
* @throws XAException
* An error has occurred. Possible values are XAER_RMERR,
* XAER_RMFAIL, XAER_INVAL, and XAER_PROTO.
*/
protected Xid findSingleXid(Xid externalXid) throws javax.transaction.xa.XAException {
try {
FbTransaction trHandle2 = database.startTransaction(tpb.getTransactionParameterBuffer());
FbStatement stmtHandle2 = database.createStatement(trHandle2);
GDSHelper gdsHelper2 = new GDSHelper(database);
gdsHelper2.setCurrentTransaction(trHandle2);
stmtHandle2.prepare(RECOVERY_QUERY_PARAMETRIZED);
DataProvider dataProvider0 = new DataProvider(0);
stmtHandle2.addStatementListener(dataProvider0);
DataProvider dataProvider1 = new DataProvider(1);
stmtHandle2.addStatementListener(dataProvider1);
final RowValue parameters = stmtHandle2.getParameterDescriptor().createDefaultFieldValues();
FBXid tempXid = new FBXid(externalXid);
parameters.getFieldValue(0).setFieldData(tempXid.toBytes());
stmtHandle2.execute(parameters);
stmtHandle2.fetchRows(1);
FBField field0 = FBField.createField(stmtHandle2.getFieldDescriptor().getFieldDescriptor(0), dataProvider0, gdsHelper2, false);
FBField field1 = FBField.createField(stmtHandle2.getFieldDescriptor().getFieldDescriptor(1), dataProvider1, gdsHelper2, false);
FBXid xid = null;
if (dataProvider0.getRowCount() > 0) {
dataProvider0.setRow(0);
dataProvider1.setRow(0);
long inLimboTxId = field0.getLong();
byte[] inLimboMessage = field1.getBytes();
try {
xid = new FBXid(new ByteArrayInputStream(inLimboMessage), inLimboTxId);
} catch (FBIncorrectXidException ex) {
log.warn("ignoring XID stored with invalid format in RDB$TRANSACTIONS for RDB$TRANSACTION_ID=" + inLimboTxId);
}
}
stmtHandle2.close();
trHandle2.commit();
return xid;
} catch (SQLException | ResourceException e) {
throw new FBXAException("can't perform query to fetch xids", XAException.XAER_RMFAIL, e);
}
}
use of javax.resource.ResourceException in project jaybird by FirebirdSQL.
the class FBManagedConnection method forget.
/**
* Indicates that no further action will be taken on behalf of this
* transaction (after a heuristic failure). It is assumed this will be
* called after a failed commit or rollback.
*
* @throws XAException
* Occurs when the state was not correct (end never called), or
* the transaction ID is wrong.
*/
public void forget(Xid id) throws XAException {
long inLimboId = -1;
try {
// find XID
// TODO: Is there a reason why this piece of code can't use the JDBC Statement class?
FbTransaction trHandle2 = database.startTransaction(tpb.getTransactionParameterBuffer());
FbStatement stmtHandle2 = database.createStatement(trHandle2);
GDSHelper gdsHelper2 = new GDSHelper(database);
gdsHelper2.setCurrentTransaction(trHandle2);
stmtHandle2.prepare(FORGET_FIND_QUERY);
DataProvider dataProvider0 = new DataProvider(0);
stmtHandle2.addStatementListener(dataProvider0);
DataProvider dataProvider1 = new DataProvider(1);
stmtHandle2.addStatementListener(dataProvider1);
stmtHandle2.execute(RowValue.EMPTY_ROW_VALUE);
stmtHandle2.fetchRows(10);
FBField field0 = FBField.createField(stmtHandle2.getFieldDescriptor().getFieldDescriptor(0), dataProvider0, gdsHelper2, false);
FBField field1 = FBField.createField(stmtHandle2.getFieldDescriptor().getFieldDescriptor(1), dataProvider1, gdsHelper2, false);
int row = 0;
while (row < dataProvider0.getRowCount()) {
dataProvider0.setRow(row);
dataProvider1.setRow(row);
long inLimboTxId = field0.getLong();
byte[] inLimboMessage = field1.getBytes();
try {
FBXid xid = new FBXid(new ByteArrayInputStream(inLimboMessage), inLimboTxId);
boolean gtridEquals = Arrays.equals(xid.getGlobalTransactionId(), id.getGlobalTransactionId());
boolean bqualEquals = Arrays.equals(xid.getBranchQualifier(), id.getBranchQualifier());
if (gtridEquals && bqualEquals) {
inLimboId = inLimboTxId;
break;
}
} catch (FBIncorrectXidException ex) {
log.warn("incorrect XID format in RDB$TRANSACTIONS where RDB$TRANSACTION_ID=" + inLimboTxId, ex);
}
row++;
}
stmtHandle2.close();
trHandle2.commit();
} catch (SQLException | ResourceException ex) {
log.debug("can't perform query to fetch xids", ex);
throw new FBXAException(XAException.XAER_RMFAIL, ex);
}
if (inLimboId == -1)
// TODO: is XAER_NOTA the proper error code ?
throw new FBXAException("XID not found", XAException.XAER_NOTA);
try {
// delete XID
FbTransaction trHandle2 = database.startTransaction(tpb.getTransactionParameterBuffer());
FbStatement stmtHandle2 = database.createStatement(trHandle2);
GDSHelper gdsHelper2 = new GDSHelper(database);
gdsHelper2.setCurrentTransaction(trHandle2);
stmtHandle2.prepare(FORGET_DELETE_QUERY + inLimboId);
stmtHandle2.execute(RowValue.EMPTY_ROW_VALUE);
stmtHandle2.close();
trHandle2.commit();
} catch (SQLException ex) {
throw new FBXAException("can't perform query to fetch xids", XAException.XAER_RMFAIL, ex);
}
}
Aggregations