Package com.dieselpoint.norm
Class Query
java.lang.Object
com.dieselpoint.norm.Query
Holds all of the information in a query. Create a query using
Database.someQueryCreationMethod(), populate it using a builder pattern, and
execute it using either .execute() (to update the database) or .results() (to
get the results of a query.)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateTable(Class<?> clazz) Deprecated.delete()Delete multiple rows in a table.Delete a row in a table.execute()Execute a sql command that does not return a result set.<T> TReturns the first row in a query in a pojo, or null if the query returns no results.generatedKeyReceiver(Object generatedKeyReceiver, String... generatedKeyNames) Specify the object and its fields that should receive any column values that the database server generates during an insert or update.longintFor queries that affect the database in some way, this method returns the number of rows affected.getTable()getWhere()Insert a row into a table.maxLatency(long millis) sets the maximum acceptable latency for this query.Add an "orderBy" clause to a query.<T> List<T>Execute a "select" query and return a list of results where each row is an instance of clazz.Create a query using straight SQL.Create a query using straight SQL.Specify the table to operate on.transaction(Transaction trans) Specify that this query should be a part of the specified transaction.Update a row in a table.Upsert a row into a table.Add a where clause and some parameters to a query.
-
Constructor Details
-
Query
-
-
Method Details
-
where
Add a where clause and some parameters to a query. Has no effect if the .sql() method is used.- Parameters:
where- Example: "name=?"args- The parameter values to use in the where, example: "Bob"
-
sql
Create a query using straight SQL. Overrides any other methods like .where(), .orderBy(), etc.- Parameters:
sql- The SQL string to use, may include ? parameters.args- The parameter values to use in the query.
-
sql
Create a query using straight SQL. Overrides any other methods like .where(), .orderBy(), etc.- Parameters:
sql- The SQL string to use, may include ? parameters.args- The parameter values to use in the query.
-
orderBy
Add an "orderBy" clause to a query. -
first
Returns the first row in a query in a pojo, or null if the query returns no results. Will return it in a Map if a class that implements Map is specified. -
results
Execute a "select" query and return a list of results where each row is an instance of clazz. Returns an empty list if there are no results. -
insert
Insert a row into a table. The row pojo can have a @Table annotation to specify the table, or you can specify the table with the .table() method. -
upsert
Upsert a row into a table. See http://en.wikipedia.org/wiki/Merge_%28SQL%29 -
update
Update a row in a table. It will match an existing row based on the primary key. -
execute
Execute a sql command that does not return a result set. The sql should previously have been set with the sql(String) method. Returns this Query object. To see how the command did, call .rowsAffected(). -
generatedKeyReceiver
Specify the object and its fields that should receive any column values that the database server generates during an insert or update. If a column is marked as "AUTO INCREMENT" (MySql) or has datatype "SERIAL" (Postgres) then the database will generate a value for that column. Databases can also generate a last-updated timestamp for a column, or just fill in a column with a default value. To get those values, you can specify generatedKeyReceiver as a Map or as a pojo. It can be the pojo you just inserted or updated. Specify also the field/column names that should be filled in. -
createTable
Deprecated.Simple, primitive method for creating a table based on a pojo. -
delete
Delete a row in a table. This method looks for an @Id annotation to find the row to delete by primary key, and looks for a @Table annotation to figure out which table to hit. -
delete
Delete multiple rows in a table. Be sure to specify the table with the .table() method and limit the rows to delete using the .where() method. -
table
Specify the table to operate on. -
getRowsAffected
public int getRowsAffected()For queries that affect the database in some way, this method returns the number of rows affected. Call it after you call .execute(), .update(), .delete(), etc.: .table("foo").where("bar=bah").delete().rowsAffected(); -
transaction
Specify that this query should be a part of the specified transaction. -
getOrderBy
-
getWhere
-
getTable
-
getResultSetMetaData
-
getMaxLatencyMillis
public long getMaxLatencyMillis() -
maxLatency
sets the maximum acceptable latency for this query. Must be called before terminal operators such asexecute()orfirst(Class).
If latency of the query exceeds the threshold then theLatencyAlerterthat have been added to theDatabasewill be called in order- Parameters:
millis- maximum number of milliseconds that a query can take to execute before an alert will be generated- Returns:
- this, to enable maxLatency to be chained, a la
db.sql( "select count(*) from Thing" ).maxLatency(50).first( Long.class )
-
getDatabase
-