@Override public DbRow primaryKeyQuery(String tableName, Object primaryKeyValue) throws JuDbException { String selectQry = "SELECT * FROM " + tableName + " WHERE " + this.dbConnection.getPrimaryColumnName(tableName) + "=?"; DbRows dbRows = this.query(selectQry, primaryKeyValue); if (dbRows.getRowCount() > 1) { throw new JuDbException("PrimaryKeyQuery for " + tableName + " with key=" + primaryKeyValue + ". Expected exactly 1 row, but got " + dbRows.getRowCount()); } return dbRows.getRowCount() == 0 ? null : dbRows.getRow(0); }
/** * Gets a list of all sequence names of the DB. Sequences names are returned the * way the DB driver returns them, which is usually upper case. * @return List of Sequences names * @throws JuDbException If the list cannot be evaluated */ public List<String> getSequenceNames() throws JuDbException { // There doesn't seem to be a generic way to retrieve sequences using JDBC meta data, so // we have to use native queries. The queries are stored in the DB specific handlers. return this.getDbType().getDbSpecificHandler(this.asConnUtil()).getSequenceNames(); }
/** * Resets identity generation of all tables or sequences to allow for predictable * and repeatable entity generation. * <p> * The exact behaviour of identity generation may vary from DB to DB. * @param val Value for the next primary key */ public void resetIdentityGenerationOrSequences(int val) { this.getDbType().getDbSpecificHandler(this.asConnUtil()).resetIdentityGenerationOrSequences(val); }
public Long getNextValueFromSequence(String sequenceName) throws JuDbException { return this.getDbType().getDbSpecificHandler(this.asConnUtil()).getNextValueFromSequence(sequenceName); }
public void setConnectionInfo(ConnectionInfo connectionInfo) { this.setUrl(connectionInfo.getConnectionString()); this.setUsername(connectionInfo.getUserName()); this.setPassword(connectionInfo.getPassword()); this.connectionInfo = connectionInfo; }
@Override public void dropSchema(SchemaInfo schemaInfo, String... users) { throw new JuDbException("Schema Dropping not yet implemented for " + this.connUtil.getDbType()); } }
@Override public DbRowsImpl query(String query, Object... params) throws JuDbException { try { QueryRunner qr = new QueryRunner(); return qr.query(this.getConnection(), query, new DbRowResultSetHandler(), this.processParams(params)); } catch (SQLException ex) { throw new JuDbException("Couldn't execute query: " + query, ex); } }
@Override public String getSchema() { return this.getConnectionInfo().getSchema(); }
@Override public String getName() { return this.getConnectionInfo().getName(); }
/** * Executes a select * query on the specified table that returns no rows. Can be used * to obtain an empty DbRows instance. * @param tableName Table name * @return DbRows instance with no rows * @throws JuDbException If the query fails */ @Override public DbRow emptyRowQuery(String tableName) throws JuDbException { String selectQry = "SELECT * FROM " + tableName + " WHERE 1=0"; return this.query(selectQry).getBaseRow(); }
@Override public DbHandler getDbHandler() { return this.getDbType().getDbSpecificHandler(this); } }
/** * Executes a select * query on the specified table that returns no rows. Can be used * to obtain an empty DbRows instance. * @param tableName Table name * @return DbRows instance with no rows * @throws JuDbException If the query fails */ protected static DbRows emptyRowsQuery(DbConnection dbConn, String tableName) throws JuDbException { String selectQry = "SELECT * FROM " + tableName + " WHERE 1=0"; return dbConn.getQueryRunner(). query(selectQry); } }
@Override public Image getImage() { return this.getConnectionInfo().getImage(); }
@Override public String getUserName() { return this.getConnectionInfo().getUserName(); }
@Override public Icon getIcon() { return this.getConnectionInfo().getIcon(); }
@Override public DbType getDbType() { if (this.dbType == null) { String productName = this.extractDatabaseMetaData(new DatabaseMetaDataCallback<String>() { @Override public String processMetaData(DatabaseMetaData dbmd) throws SQLException { return dbmd.getDatabaseProductName(); } }); this.dbType = DbType.evaluateDbType(productName); } return this.dbType; }
@Override public String getConnectionString() { return this.getConnectionInfo().getConnectionString(); }
@Override public String getPassword() { return this.getConnectionInfo().getPassword(); }
@Override public void createSchema(DbSchemaBuilder builder) { throw new JuDbException("Schema Creation not yet implemented for " + this.connUtil.getDbType()); }
@Override public List<String> getSequenceNames() { throw new JuDbException("Sequences not supported by " + this.connUtil.getDbType()); }