Search in sources :

Example 76 with ResourceException

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);
        }
    }
}
Also used : TranslatorException(org.teiid.translator.TranslatorException) ResourceException(javax.resource.ResourceException) DeleteVisitor(org.teiid.translator.coherence.visitor.DeleteVisitor)

Example 77 with ResourceException

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");
    }
}
Also used : ResourceException(javax.resource.ResourceException) TransactionMap(com.tangosol.util.TransactionMap) ResourceException(javax.resource.ResourceException) NamedCache(com.tangosol.net.NamedCache)

Example 78 with ResourceException

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);
        }
    }
}
Also used : FBManagedConnectionFactory(org.firebirdsql.jca.FBManagedConnectionFactory) ResourceException(javax.resource.ResourceException) FBSQLException(org.firebirdsql.jdbc.FBSQLException) GDSType(org.firebirdsql.gds.impl.GDSType)

Example 79 with ResourceException

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);
    }
}
Also used : FBField(org.firebirdsql.jdbc.field.FBField) SQLException(java.sql.SQLException) GDSHelper(org.firebirdsql.gds.impl.GDSHelper) FieldDataProvider(org.firebirdsql.jdbc.field.FieldDataProvider) ByteArrayInputStream(java.io.ByteArrayInputStream) RowValue(org.firebirdsql.gds.ng.fields.RowValue) ResourceException(javax.resource.ResourceException)

Example 80 with ResourceException

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);
    }
}
Also used : FBField(org.firebirdsql.jdbc.field.FBField) SQLException(java.sql.SQLException) GDSHelper(org.firebirdsql.gds.impl.GDSHelper) FieldDataProvider(org.firebirdsql.jdbc.field.FieldDataProvider) ByteArrayInputStream(java.io.ByteArrayInputStream) ResourceException(javax.resource.ResourceException)

Aggregations

ResourceException (javax.resource.ResourceException)163 TranslatorException (org.teiid.translator.TranslatorException)26 SQLException (java.sql.SQLException)18 IOException (java.io.IOException)17 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)14 ManagedConnection (javax.resource.spi.ManagedConnection)13 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)13 NamingException (javax.naming.NamingException)11 InvocationTargetException (java.lang.reflect.InvocationTargetException)10 SObject (com.sforce.soap.partner.sobject.SObject)9 ConnectionException (com.sforce.ws.ConnectionException)9 UnexpectedErrorFault (com.sforce.soap.partner.fault.UnexpectedErrorFault)8 ArrayList (java.util.ArrayList)8 ResourceHandle (com.sun.enterprise.resource.ResourceHandle)7 InvalidSObjectFault (com.sforce.soap.partner.fault.InvalidSObjectFault)6 ResourcePrincipal (com.sun.enterprise.deployment.ResourcePrincipal)6 Set (java.util.Set)6 MessageEndpoint (javax.resource.spi.endpoint.MessageEndpoint)6 XAResource (javax.transaction.xa.XAResource)6 InvalidFieldFault (com.sforce.soap.partner.fault.InvalidFieldFault)5