Example usage for javax.resource ResourceException ResourceException

List of usage examples for javax.resource ResourceException ResourceException

Introduction

In this page you can find the example usage for javax.resource ResourceException ResourceException.

Prototype

public ResourceException(Throwable cause) 

Source Link

Document

Constructs a new throwable with the specified cause.

Usage

From source file:com.googlecode.cassandra.jca.managed.connection.CassandraManagedConnection.java

public CassandraManagedConnection(CassandraProperties properties) throws ResourceException {

    try {//from w  ww .j ava 2 s  .co m
        transport = new TFramedTransport(
                new TSocket(properties.getServer(), properties.getPort(), properties.getTimeout()));

        TProtocol framedProtocol = new TBinaryProtocol(transport);

        iface = new Cassandra.Client(framedProtocol);

        transport.open();

        if (StringUtils.isNotBlank(properties.getUsername())
                && StringUtils.isNotBlank(properties.getPassword())) {

            Map<String, String> credentials = new HashMap<String, String>();
            //TODO
            AuthenticationRequest request = new AuthenticationRequest(credentials);
            request.validate();
            iface.login(request);
        }

        if (StringUtils.isNotBlank(properties.getKeyspace())) {
            iface.set_keyspace(properties.getKeyspace());
        }
    } catch (Exception ex) {
        throw new ResourceException(ex);
    }
}

From source file:eu.luminis.httpjca.HttpManagedConnection.java

/**
 * Used by the container to change the association of an 
 * application-level connection handle with a ManagedConneciton instance.
 *
 * @param connection Application-level connection handle
 * @throws ResourceException generic exception if operation fails
 *///from  ww  w  .  ja  va  2 s .c  o  m
public void associateConnection(Object connection) throws ResourceException {
    log.finest("associateConnection()");

    if (connection == null)
        throw new ResourceException("Null connection handle");

    if (!(connection instanceof HttpConnectionImpl))
        throw new ResourceException("Wrong connection handle");

    this.connection = (HttpConnectionImpl) connection;
}

From source file:eu.luminis.httpjca.HttpManagedConnection.java

/**
 * Application server calls this method to force any cleanup on the ManagedConnection instance.
 *
 * @throws ResourceException generic exception if operation fails
 */// w  w  w.j a  v  a 2  s.  c  o  m
public void cleanup() throws ResourceException {
    log.finest("cleanup()");
    if (connection != null) {
        try {
            connection.flush();
        } catch (IOException e) {
            throw new ResourceException(e);
        }
    }
}

From source file:me.jtalk.socketconnector.SocketResourceAdapter.java

@Override
public void endpointActivation(MessageEndpointFactory endpointFactory, ActivationSpec spec)
        throws ResourceException {
    log.info("Endpoint activation request received for class {0}",
            endpointFactory.getEndpointClass().getCanonicalName());
    if (!this.running.get()) {
        throw new ResourceException("This resource adapter is stopped");
    }//from  w w w .ja  v a  2  s .co m
    if (!(spec instanceof TCPActivationSpec)) {
        throw new NotSupportedException(
                "Activation spec supplied has unsupported type " + spec.getClass().getCanonicalName());
    } else {
        log.info("Endpoint activation for class {0}", endpointFactory.getEndpointClass().getCanonicalName());
        this.activateTCP(endpointFactory, (TCPActivationSpec) spec);
        log.info("Endpoint activated for class {0}", endpointFactory.getEndpointClass().getCanonicalName());
    }
}

From source file:eu.devexpert.orient.jca.OrientDBGraphImpl.java

public List<ODocument> getNodesByFields(Object obj, String... constraints) throws ResourceException {
    try {/*from   ww w  . ja  v  a  2 s.  com*/
        Object[] values = new Object[constraints.length];
        StringBuffer query = new StringBuffer("select * from ");
        query.append(obj.getClass().getName());
        query.append(" where ");
        int counter = 0;
        for (String attributeName : constraints) {
            values[counter] = BeanUtils.getObjectAttribute(obj, attributeName);
            query.append(attributeName);
            query.append(" = ? ");
            if (++counter < constraints.length) {
                query.append("and ");
            }
        }

        return (List<ODocument>) graphDatabase.command(new OSQLSynchQuery<ODocument>(query.toString()))
                .execute(values);
    } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ie) {
        throw new ResourceException(ie.getMessage());
    }
}

From source file:eu.devexpert.orient.jca.OrientDBGraphImpl.java

@Override
public void saveOrUpdateNode(Object obj, String... constraints) throws ResourceException {
    try {//from   www .  j a  va2 s  .com
        List<ODocument> existingNodes = getNodesByFields(obj, constraints);
        if (existingNodes.size() == 0) {
            saveNode(obj);
        } else if (existingNodes.size() == 1) {
            ODocument node = existingNodes.get(0);
            String jsonStr = mapper.writeValueAsString(obj);
            node.fromJSON(jsonStr).save();
        } else {
            throw new ResourceException(
                    "You have to pass unique fields, otherwise it is not possible to update the node, now we have found more nodes with your criteria : "
                            + existingNodes.size());
        }
    } catch (IOException iox) {
        throw new ResourceException(iox.getMessage());
    }
}

From source file:org.apache.webdav.connector.WebDAVManagedConnection.java

/**
 * @see ManagedConnection#destroy()//from   w  ww  . jav  a 2 s .c  o m
 */
public void destroy() throws ResourceException {

    if (connection != null) {
        connection.invalidate();
        connection = null;
    }

    listeners = null;
    name = null;
    xares = null;
    tx = null;
    try {
        webdavResource.close();
    } catch (IOException e) {
        throw new ResourceException(e);
    }
}

From source file:org.apache.webdav.connector.WebDAVManagedConnection.java

/**
 * @see ManagedConnection#cleanup()/*from   ww  w. java 2s .com*/
 */
public void cleanup() throws ResourceException {
    // XXX We should only reset internal state to put our
    // physical connection back to the pool. As I have
    // no idea how to recycle a WebdavResource a have to
    // fully destroy it (Olli Z.)

    if (connection != null) {
        connection.invalidate();
        connection = null;
    }

    name = null;
    xares = null;
    tx = null;
    try {
        webdavResource.close();
    } catch (IOException e) {
        throw new ResourceException(e);
    }
}

From source file:org.apache.webdav.connector.WebDAVManagedConnection.java

/**
 * @see ManagedConnection#associateConnection(Object)
 *///from   w  w w.  j av  a2  s . co m
public void associateConnection(Object connection) throws ResourceException {
    if (!(connection instanceof WebDAVConnection)) {
        throw new ResourceException("Connection is not of type WebDAVConnection");
    }

    this.connection = (WebDAVConnection) connection;
    try {
        open(this.connection.mc.webDAVConnectionSpec);
    } catch (URIException e) {
        throw new ResourceException("Could not associate connection", e);
    } catch (IOException e) {
        throw new ResourceException("Could not associate connection", e);
    }
    this.connection.mc = this;
}

From source file:org.eclipse.ecr.core.storage.sql.SessionImpl.java

@Override
public void close() throws ResourceException {
    try {/*from   www.  j a v  a2  s . co m*/
        closeSession();
    } catch (StorageException e) {
        throw new ResourceException(e);
    }
    repository.closeSession(this);
}