net.aditsu.depeche
public class Provider extends Object implements Serializable
Constructor and Description |
---|
Provider(ConnSource cs)
Constructs a provider that uses a given connection source
|
Modifier and Type | Method and Description |
---|---|
void |
addColumn(String table,
Column col)
Adds a column to a table
|
void |
addColumn(String table,
Column col,
Conn conn)
Adds a column to a table using a given connection
|
void |
addFKey(FKey fk)
Adds a foreign key constraint
|
void |
addFKey(FKey fk,
Conn conn)
Adds a foreign key constraint, using a given connection
|
void |
addUnique(UniqueConstraint c)
Adds a unique constraint
|
void |
addUnique(UniqueConstraint c,
Conn conn)
Adds a unique constraint, using a given connection
|
void |
batchInsert(Conn conn,
String table,
List<Record> records)
Inserts a list of records into a table, in a single batch, using a given connection
|
void |
batchInsert(String table,
List<Record> records)
Inserts a list of records into a table, in a single batch, using a new connection
|
void |
clearTable(String name)
Removes the cached information (if any) for the given table
|
void |
close()
Releases resources used by this provider
|
void |
createTable(TableInfo tinfo)
Creates a table given its information, with no constraints other than primary key
|
void |
createTable(TableInfo tinfo,
Conn conn)
Creates a table given its information, using a given connection, with no constraints other than primary key
|
void |
createView(String name,
String def)
Creates a view given its name and definition
|
void |
createView(String name,
String def,
Conn conn)
Creates a view given its name and definition, using a given connection
|
void |
dropColumn(String table,
Column col)
Drops a column from a table
|
void |
dropColumn(String table,
Column col,
Conn conn)
Drops a column from a table using a given connection
|
void |
dropFKey(FKey fk)
Drops a foreign key constraint
|
void |
dropFKey(FKey fk,
Conn conn)
Drops a foreign key constraint, using a given connection
|
void |
dropTable(String name)
Drops a table given its name
|
void |
dropTable(String name,
Conn conn)
Drops a table given its name, using a given connection
|
void |
dropView(String name)
Drops a view given its name
|
void |
dropView(String name,
Conn conn)
Drops a view given its name, using a given connection
|
int |
execute(String sql)
Runs the given query directly as an UPDATE and returns the number of rows affected
|
int |
execute(String sql,
Conn conn)
Runs the given query directly as an UPDATE, using the given connection and returns the number of rows affected
|
SQLCondition |
filter(KeyInfo keyInfo,
Key key)
Creates a condition to match a list of columns with a list of values (using "=" or "IS NULL" accordingly)
|
SQLCondition |
filter(String name,
Serializable value)
Creates a condition representing "name = value";
null values are handled separately using "IS NULL"
|
SQLCondition |
filter(String name,
String op,
Serializable value)
Creates a condition representing "name op value"
|
SQLCondition |
filterIn(String name,
Collection<? extends Serializable> values)
Creates a condition representing "name IN (values)"
|
String |
getAddColumnSQL(String table,
Column col)
Returns an SQL command for adding a column to a table
|
String |
getAddFKeySQL(FKey fk)
Returns an SQL command for adding a foreign key constraint
|
String |
getAddUniqueSQL(UniqueConstraint c)
Returns an SQL command for adding a unique constraint
|
List<Table> |
getAllTables()
Returns a list of all the actual tables in this database
|
List<Table> |
getAllViews()
Returns a list of all the views in this database
|
RawQuery |
getColumnCommentQuery(String table,
String column,
String value)
Returns a query for setting a comment on a table column
|
String |
getColumnDesc(Column col) |
String |
getCreateTableSQL(TableInfo tinfo)
Returns an SQL command for creating a table given its information, with no constraints other than primary key
|
String |
getCreateViewSQL(String name,
String def)
Returns an SQL command for creating a view given its name and definition
|
String |
getDropColumnSQL(String table,
Column col)
Returns an SQL command for dropping a column from a table
|
String |
getDropFKeySQL(FKey fk)
Returns an SQL command for dropping a foreign key constraint
|
String |
getDropTableSQL(String name)
Returns an SQL command for dropping a table given its name
|
String |
getDropViewSQL(String name)
Returns an SQL command for dropping a view given its name
|
List<String> |
getEnumValues(Column c)
Returns the list of values for a column with an enumerated type
|
List<Record> |
getGenericTableDetails(String catalog,
String schemaPattern,
String tableNamePattern,
String... types)
Returns a detailed list of table-like objects in this provider's database, matching the given criteria
|
List<Table> |
getGenericTables(String catalog,
String schemaPattern,
String namePattern,
String... types)
Returns a list of table-like objects in this provider's database, matching the given criteria
|
int |
getLastId(Conn conn)
Returns the last generated auto-increment value in a given connection as an int value
|
long |
getLongLastId(Conn conn)
Returns the last generated auto-increment value in a given connection as a long value
|
String |
getName()
Returns this provider's name
|
ProviderRef |
getProviderRef()
Returns the provider reference used in queries and records
|
Record |
getRecord(String table,
Conn conn,
List<Serializable> values)
Returns a single record (or null if not found) given its table and primary key values,
using a given connection
|
Record |
getRecord(String table,
Conn conn,
Serializable... values)
Returns a single record (or null if not found) given its table and primary key values,
using a given connection
|
Record |
getRecord(String table,
List<Serializable> values)
Returns a single record (or null if not found) given its table and primary key values
|
Record |
getRecord(String table,
Serializable... values)
Returns a single record (or null if not found) given its table and primary key values
|
Record |
getRecord(Table table,
List<Serializable> values)
Deprecated.
|
Record |
getRecord(Table table,
Serializable... values)
Deprecated.
|
TableInfo |
getTableInfo(String table)
Returns the table information for a given table
|
TableInfo |
getTableInfo(String table,
Conn conn)
Returns the table information for a given table,
using the given connection if needed
|
TableInfo |
getTableInfo(Table t)
Returns the table information for a given table
|
TableInfo |
getTableInfo(Table t,
Conn conn)
Returns the table information for a given table,
using the given connection if needed
|
List<Table> |
getTables(String catalog,
String schemaPattern,
String namePattern)
Returns a list of actual tables in this database, matching the given criteria
|
List<String> |
getTableTypes()
Returns the list of table types supported by this provider's database
|
List<UniqueConstraint> |
getUniqueConstraints(Table t)
Returns a list of all the unique constraints on the given table (not including the primary key)
|
String |
getViewDefinition(Table view)
Returns the definition of the given view
|
List<Table> |
getViews(String catalog,
String schemaPattern,
String namePattern)
Returns a list of views in this database, matching the given criteria
|
boolean |
hasFlag(Flag flag)
Checks whether the given flag is set for this provider
|
SQLCondition |
joinCondition(String table1,
KeyInfo kinfo1,
String table2,
KeyInfo kinfo2)
Creates a join condition matching the given keys between two tables, quoting the fields
|
SQLCondition |
joinCondition(String fld1,
String fld2)
Creates a join condition "fld1 = fld2", quoting the fields
|
SQLCondition |
joinCondition(String table1,
String fld1,
String table2,
String fld2)
Creates a join condition "table1.fld1 = table2.fld2", quoting the fields
|
Record |
newRecord(ColumnInfo colInfo)
Creates a new record using given column information
|
Record |
newRecord(String table)
Creates a new record for a given table
|
Record |
newRecord(String table,
Conn conn)
Creates a new record for a given table, using the given connection if needed
|
Query |
query()
Creates a new query without a table specified
|
Query |
query(Record rec)
Creates a new query that matches a given record
|
Query |
query(SQLQuery q,
String alias)
Creates a new query that uses a given query as a subquery
|
Query |
query(String table)
Creates a new query for a given table
|
Query |
query(Table table)
Creates a new query for a given table
|
String |
quote(String s)
Quotes an identifier, separating different parts by dots; doesn't quote a single "*"
|
RawQuery |
rawQuery(String sql,
List<Serializable> params)
Creates a raw SQL query
|
RawQuery |
rawQuery(String sql,
Serializable... params)
Creates a raw SQL query
|
String |
rawQuote(String s)
Quotes an identifier, treating dots as part of the identifier name
|
Table |
resolveTable(String table)
Resolves a table given as a string to its proper definition
|
Table |
resolveTable(String table,
Conn conn)
Resolves a table given as a string to its proper definition,
using the given connection if needed
|
<T> T |
run(DBTask<T> task)
Gets a new connection and runs the given task
|
void |
setColumnComment(String table,
String column,
String value)
Sets a comment on a table column
|
void |
setColumnComment(String table,
String column,
String value,
Conn conn)
Sets a comment on a table column, using a given connection
|
void |
setName(String name)
Sets this provider's name
|
void |
setProviderRef(ProviderRef pRef)
Sets the provider reference to be used in queries and records
|
<T> T |
transaction(DBTask<T> task)
Gets a new connection and runs the given task in a transaction
|
public Provider(ConnSource cs)
public void setProviderRef(ProviderRef pRef)
public ProviderRef getProviderRef()
public <T> T run(DBTask<T> task)
public <T> T transaction(DBTask<T> task)
public Table resolveTable(String table)
public Table resolveTable(String table, Conn conn)
public TableInfo getTableInfo(String table)
public TableInfo getTableInfo(String table, Conn conn)
public TableInfo getTableInfo(Table t, Conn conn)
public Query query()
public Query query(SQLQuery q, String alias)
public Record newRecord(String table, Conn conn)
public Record newRecord(ColumnInfo colInfo)
public RawQuery rawQuery(String sql, List<Serializable> params)
public RawQuery rawQuery(String sql, Serializable... params)
public long getLongLastId(Conn conn)
public int getLastId(Conn conn)
public String quote(String s)
public String rawQuote(String s)
public Record getRecord(String table, Serializable... values)
public Record getRecord(String table, Conn conn, Serializable... values)
@Deprecated public Record getRecord(Table table, Serializable... values)
public Record getRecord(String table, List<Serializable> values)
public Record getRecord(String table, Conn conn, List<Serializable> values)
@Deprecated public Record getRecord(Table table, List<Serializable> values)
public SQLCondition filter(String name, String op, Serializable value)
name
- field nameop
- operatorvalue
- right hand side valuepublic SQLCondition filter(String name, Serializable value)
name
- field namevalue
- right hand side valuepublic SQLCondition filter(KeyInfo keyInfo, Key key)
public SQLCondition filterIn(String name, Collection<? extends Serializable> values)
name
- field namevalues
- collection of valuespublic int execute(String sql)
public int execute(String sql, Conn conn)
public String getCreateTableSQL(TableInfo tinfo)
public void createTable(TableInfo tinfo)
public void createTable(TableInfo tinfo, Conn conn)
public void clearTable(String name)
public String getDropTableSQL(String name)
public void dropTable(String name)
public void dropTable(String name, Conn conn)
public String getAddColumnSQL(String table, Column col)
public void addColumn(String table, Column col, Conn conn)
public String getDropColumnSQL(String table, Column col)
public void dropColumn(String table, Column col, Conn conn)
public String getAddFKeySQL(FKey fk)
public void addFKey(FKey fk)
public void addFKey(FKey fk, Conn conn)
public String getDropFKeySQL(FKey fk)
public void dropFKey(FKey fk)
public void dropFKey(FKey fk, Conn conn)
public List<UniqueConstraint> getUniqueConstraints(Table t)
public String getAddUniqueSQL(UniqueConstraint c)
public void addUnique(UniqueConstraint c)
public void addUnique(UniqueConstraint c, Conn conn)
public boolean hasFlag(Flag flag)
public List<Table> getGenericTables(String catalog, String schemaPattern, String namePattern, String... types)
public List<Table> getTables(String catalog, String schemaPattern, String namePattern)
public List<Table> getAllTables()
public List<Table> getViews(String catalog, String schemaPattern, String namePattern)
public List<Record> getGenericTableDetails(String catalog, String schemaPattern, String tableNamePattern, String... types)
public List<String> getTableTypes()
public String getViewDefinition(Table view)
public String getCreateViewSQL(String name, String def)
public void createView(String name, String def)
public void createView(String name, String def, Conn conn)
public String getDropViewSQL(String name)
public void dropView(String name)
public void dropView(String name, Conn conn)
public RawQuery getColumnCommentQuery(String table, String column, String value)
public void setColumnComment(String table, String column, String value)
public void setColumnComment(String table, String column, String value, Conn conn)
public void batchInsert(Conn conn, String table, List<Record> records)
public void batchInsert(String table, List<Record> records)
public SQLCondition joinCondition(String fld1, String fld2)
public SQLCondition joinCondition(String table1, String fld1, String table2, String fld2)
public SQLCondition joinCondition(String table1, KeyInfo kinfo1, String table2, KeyInfo kinfo2)
public List<String> getEnumValues(Column c)
public String getName()
public void setName(String name)
public void close()