/** * @deprecated */ public Exception getLinkedException() { return (Exception) getCause(); }
public Connection getConnection() throws SQLException { try { return (Connection) cm.allocateConnection(mcf, containerRequestInfo); } catch (ResourceException e) { if (e.getCause() instanceof SQLException) { throw (SQLException) e.getCause(); } else { throw (SQLException) new SQLException().initCause(e); } } }
import java.sql.SQLException; import javax.resource.ResourceException; public class Linking { public static void main(String[] args) { SQLException resW = new SQLException("blubb"); ResourceException resX = new ResourceException("a message", resW); SQLException sqlExc = null; Throwable linkedExc = resX.getCause(); // if linkedExc exception is a SQL Exception, assign it to sqlExc if (linkedExc instanceof SQLException) { sqlExc = (SQLException) linkedExc; } if (sqlExc != null) sqlExc.printStackTrace(); } }
public Connection getConnection(String user, String password) throws SQLException { try { UserPasswordHandleFactoryRequestInfo cri = new UserPasswordHandleFactoryRequestInfo<Connection, ConnectionHandle>(handleFactory, user, password); return (Connection) cm.allocateConnection(mcf, cri); } catch (ResourceException e) { if (e.getCause() instanceof SQLException) { throw (SQLException) e.getCause(); } else { throw (SQLException) new SQLException().initCause(e); } } }
protected ManagedConnectionHandle<Connection, ConnectionHandle> getManagedConnection() throws SQLException { if (closed) { throw new SQLException("Connection has been closed"); } if (mc == null && cm != null) { try { cm.associateConnection(this, mcf, cri); } catch (ResourceException e) { if (e.getCause() instanceof SQLException) { throw (SQLException) e.getCause(); } else { throw (SQLException) new SQLException("Failed lazy association with ManagedConnection").initCause(e); } } if (mc == null) { throw new SQLException("Failed lazy association with ManagedConnection"); } } assert mc != null; return mc; }
public void rollback() throws SQLException { ManagedConnectionHandle<Connection, ConnectionHandle> mc = getManagedConnection(); Connection c = mc.getPhysicalConnection(); if (c.getAutoCommit()) { return; } try { LocalTransaction tx = mc.getClientLocalTransaction(); tx.rollback(); tx.begin(); } catch (ResourceException e) { if (e.getCause() instanceof SQLException) { throw (SQLException) e.getCause(); } else { throw (SQLException) new SQLException().initCause(e); } } }
public void commit() throws SQLException { ManagedConnectionHandle<Connection, ConnectionHandle> mc = getManagedConnection(); Connection c = mc.getPhysicalConnection(); if (c.getAutoCommit()) { return; } try { LocalTransaction tx = mc.getClientLocalTransaction(); tx.commit(); tx.begin(); } catch (ResourceException e) { if (e.getCause() instanceof SQLException) { throw (SQLException) e.getCause(); } else { throw (SQLException) new SQLException().initCause(e); } } }
public void setAutoCommit(boolean autoCommit) throws SQLException { ManagedConnectionHandle<Connection, ConnectionHandle> mc = getManagedConnection(); Connection c = mc.getPhysicalConnection(); if (autoCommit == c.getAutoCommit()) { // nothing to do return; } try { LocalTransaction tx = mc.getClientLocalTransaction(); if (autoCommit) { // reenabling autoCommit - JDBC spec says current transaction is committed tx.commit(); } else { // disabling autoCommit tx.begin(); } } catch (ResourceException e) { if (e.getCause() instanceof SQLException) { throw (SQLException) e.getCause(); } else { throw (SQLException) new SQLException().initCause(e); } } }
/** * <p>Attempt to establish a database connection. * * @return a Connection to the database * @throws SQLException * if a database-access error occurs. */ @SuppressWarnings("deprecation") public Connection getConnection() throws SQLException { try { return (Connection) cm.allocateConnection(mcf, mcf.getDefaultConnectionRequestInfo()); } catch (ResourceException re) { if (re.getCause() instanceof SQLException) { throw (SQLException) re.getCause(); } if (re.getLinkedException() instanceof SQLException) { throw (SQLException) re.getLinkedException(); } throw new FBSQLException(re); } }
/** * <p>Attempt to establish a database connection. * * @return a Connection to the database * @throws SQLException * if a database-access error occurs. */ @SuppressWarnings("deprecation") public Connection getConnection() throws SQLException { try { return (Connection) cm.allocateConnection(mcf, mcf.getDefaultConnectionRequestInfo()); } catch (ResourceException re) { if (re.getCause() instanceof SQLException) { throw (SQLException) re.getCause(); } if (re.getLinkedException() instanceof SQLException) { throw (SQLException) re.getLinkedException(); } throw new FBSQLException(re); } }
/** * <p>Attempt to establish a database connection. * * @param username * the database user on whose behalf the Connection is * being made * @param password * the user's password * @return a Connection to the database * @throws SQLException * if a database-access error occurs. */ @SuppressWarnings("deprecation") public Connection getConnection(String username, String password) throws SQLException { try { //mcf makes a copy for us. FBConnectionRequestInfo subjectCri = mcf.getDefaultConnectionRequestInfo(); subjectCri.setUserName(username); subjectCri.setPassword(password); return (Connection) cm.allocateConnection(mcf, subjectCri); } catch (ResourceException re) { if (re.getCause() instanceof SQLException) { throw (SQLException) re.getCause(); } if (re.getLinkedException() instanceof SQLException) { throw (SQLException) re.getLinkedException(); } throw new FBSQLException(re); } }
/** * <p>Attempt to establish a database connection. * * @param username * the database user on whose behalf the Connection is * being made * @param password * the user's password * @return a Connection to the database * @throws SQLException * if a database-access error occurs. */ @SuppressWarnings("deprecation") public Connection getConnection(String username, String password) throws SQLException { try { //mcf makes a copy for us. FBConnectionRequestInfo subjectCri = mcf.getDefaultConnectionRequestInfo(); subjectCri.setUserName(username); subjectCri.setPassword(password); return (Connection) cm.allocateConnection(mcf, subjectCri); } catch (ResourceException re) { if (re.getCause() instanceof SQLException) { throw (SQLException) re.getCause(); } if (re.getLinkedException() instanceof SQLException) { throw (SQLException) re.getLinkedException(); } throw new FBSQLException(re); } }
/** * Creates a new session. */ @SuppressWarnings("deprecation") public Session login(Credentials creds, String workspace) throws RepositoryException { try { return (Session) cm.allocateConnection( mcf, new JCAConnectionRequestInfo(creds, workspace)); } catch (ResourceException e) { Throwable cause = e.getCause(); if (cause == null) { cause = e.getLinkedException(); } if (cause instanceof LoginException) { throw (LoginException) cause; } else if (cause instanceof NoSuchWorkspaceException) { throw (NoSuchWorkspaceException) cause; } else if (cause instanceof RepositoryException) { throw (RepositoryException) cause; } else if (cause != null) { throw new RepositoryException(cause); } else { throw new RepositoryException(e); } } }
@SuppressWarnings( "deprecation" ) @Override public Session login( Credentials c, String workspace ) throws LoginException, NoSuchWorkspaceException, RepositoryException { try { return (Session)cm.allocateConnection(mcf, new JcrConnectionRequestInfo(c, workspace)); } catch (ResourceException e) { Throwable cause = e.getCause(); if (cause == null) { cause = e.getLinkedException(); } if (cause instanceof LoginException) { throw (LoginException)cause; } else if (cause instanceof NoSuchWorkspaceException) { throw (NoSuchWorkspaceException)cause; } else if (cause instanceof RepositoryException) { throw (RepositoryException)cause; } else if (cause != null) { throw new RepositoryException(cause); } else { throw new RepositoryException(e); } } }
/** * Creates a new session. */ @SuppressWarnings("deprecation") public Session login(Credentials creds, String workspace) throws RepositoryException { try { return (Session) cm.allocateConnection( mcf, new JCAConnectionRequestInfo(creds, workspace)); } catch (ResourceException e) { Throwable cause = e.getCause(); if (cause == null) { cause = e.getLinkedException(); } if (cause instanceof LoginException) { throw (LoginException) cause; } else if (cause instanceof NoSuchWorkspaceException) { throw (NoSuchWorkspaceException) cause; } else if (cause instanceof RepositoryException) { throw (RepositoryException) cause; } else if (cause != null) { throw new RepositoryException(cause); } else { throw new RepositoryException(e); } } }
if(this.createParentDirectory && e.getCause() instanceof ClientCommandCdException)