@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); }
/** * 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(); }