/** * Returns default DbOom instance. If multiple DbOoms are in use, * an exception is thrown. */ public static DbOom get() { if (defaultDbOom == null) { throw new DbSqlException( "No default DbOom available. Use DbOom to create one.\n" + "If more then one DbOom is in use, there is no default instance."); } return defaultDbOom; }
/** * Checks if query is initialized and throws an exception if it is not. */ protected void checkInitialized() { if (queryState != INITIALIZED) { final String message = (queryState == CREATED ? "Query is created but not yet initialized." : "Query is closed."); throw new DbSqlException(this, message + " Operation may be performed only on initialized queries."); } }
/** * Checks if query is created (and not yet initialized or closed) and throws an exception if it is not. */ protected void checkCreated() { if (queryState != CREATED) { final String message = (queryState == INITIALIZED ? "Query is already initialized." : "Query is closed."); throw new DbSqlException(this, message + " Operation may be performed only on created queries."); } }
protected void assertSessionIsOpen() { if (queries == null) { throw new DbSqlException("Session is closed"); } }
/** * Checks if query is not closed and throws an exception if it is. */ protected void checkNotClosed() { if (queryState == CLOSED) { throw new DbSqlException(this, "Query is closed. Operation may be performed only on active queries."); } }
private DbSqlException newGetParamError(final String param, final Exception ex) { return new DbSqlException("Invalid SQL parameter with name: " + param, ex); } private DbSqlException newGetParamError(final String param) {
private void throwSetParamError(final int index, final Exception ex) { throw new DbSqlException(this, "Invalid SQL parameter with index: " + index, ex); }
private DbSqlException newGetParamError(final int index, final Exception ex) { return new DbSqlException("Invalid SQL parameter with index: " + index, ex); } private DbSqlException newGetParamError(final String param, final Exception ex) {
private DbSqlException newGetParamError(final String param) { return new DbSqlException("Invalid number of parameter with name: " + param); }
private void throwSetParamError(final String param, final Exception ex) { throw new DbSqlException(this, "Invalid SQL parameter with name: " + param, ex); }
/** * Closes current transaction. */ protected void closeTx() { txActive = false; try { connection.setAutoCommit(true); } catch (SQLException sex) { throw new DbSqlException("Close TX failed", sex); } }
@Override public synchronized void init() { try { Class.forName(driverClass); } catch (ClassNotFoundException cnfex) { throw new DbSqlException("JDBC driver not found: " + driverClass, cnfex); } }
/** * Returns the query string from loggable wrapped statement. */ public String getQueryString(final T statement) { try { return (String) getQueryStringMethod.invoke(statement); } catch (Exception ex) { throw new DbSqlException(ex); } }
public DataSourceConnectionProvider(final String jndiName, final String user, final String pass) { try { InitialContext initialContext = new InitialContext(); this.dataSource = (DataSource) initialContext.lookup(jndiName); } catch (NamingException nex) { throw new DbSqlException("Invalid JNDI datasource name: " + jndiName, nex); } this.username = user; this.password = pass; }
@Override public Connection getConnection() { try { if (username != null || password != null) { return dataSource.getConnection(username, password); } else { return dataSource.getConnection(); } } catch (SQLException sex) { throw new DbSqlException("Invalid datasource connection", sex); } }
int[] getNamedParameterIndices(final String name) { final DbQueryNamedParameter p = lookupNamedParameter(name); if (p == null) { throw new DbSqlException("Named parameter not found: " + name + "\nQuery: " + sql); } return p.indices; }
protected void assertTxIsActive() { assertSessionIsOpen(); if (!txActive) { throw new DbSqlException("TX not available for this session"); } } }
private void initPrepared() { init(); if (preparedStatement == null) { throw new DbSqlException("Prepared statement not initialized."); } } private void initCallable() {
private void initCallable() { init(); if (callableStatement == null) { throw new DbSqlException("Callable statement not initialized."); } }
protected void assertTxIsClosed() { assertSessionIsOpen(); if (txActive) { throw new DbSqlException("TX already started for this session"); } }