public class DBMigration<M extends DBRow> extends RowDefinition
| Constructor and Description |
|---|
DBMigration(DBDatabase db,
M migrationMapper) |
| Modifier and Type | Method and Description |
|---|---|
void |
addAsOptionalTables(DBRow... examples)
Add the rows as optional tables in the query.
|
Long |
count(DBDatabase database,
DBRow... rows)
Count the rows on the database without retrieving the rows.
|
List<M> |
getAllRows()
Gets all the migrated rows using only conditions supplied within the
supplied DBMigration.
|
List<M> |
getAllRows(DBRow... extraExamples)
Gets all the migrated rows using conditions in the DBMigration and the
supplied examples.
|
List<M> |
getRows(DBDatabase database,
DBRow... rows)
Gets all the report rows of the migration limited by the supplied example
rows.
|
List<M> |
getRowsHaving(DBDatabase database,
DBRow[] rows,
BooleanExpression... conditions)
Gets all the report rows of this DBMigration limited by the supplied
example rows but reduce the result to only those that match the conditions.
|
protected ColumnProvider[] |
getSortColumns()
Returns the list of sort columns
Support DBvolution at Patreon |
String |
getSQLForCount(DBDatabase database,
DBRow... rows)
Returns the SQL query that will used to count the rows returned for the
supplied DBReport
|
String |
getSQLForInsert(DBDatabase database,
DBRow... rows)
Generates and returns the actual SQL to be used by this DBQueryInsert to
insert the queried rows.
|
String |
getSQLForQuery(DBDatabase database,
DBRow... rows)
Generates and returns the actual SQL to be used by this DBQueryInsert to
select the rows to insert.
|
void |
insertAllRows(DBRow... extraExamples) |
DBMigration<M> |
setBlankQueryAllowed(Boolean setting)
Change the Default Setting of Disallowing Blank Queries
|
DBMigration<M> |
setCartesianJoinAllowed(Boolean setting)
Suppresses Cartesian join error protection.
|
DBMigration<M> |
setSortOrder(ColumnProvider... columns)
Sets the sort order of DBReport (field and/or method) by the given column
providers.
|
DBMigration<M> |
setSortOrder(QueryableDatatype<?>... columns)
Sets the sort order of DBReport (field and/or method) by the given column
providers.
|
String |
toString() |
DBMigrationValidation.Results |
validateAllRows(DBRow... extraExamples) |
column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, column, getAutoFillingPropertyWrappers, getColumnPropertyWrapperDefinitions, getColumnPropertyWrappers, getDBExpression, getFieldNames, getFieldValues, getPropertyWrapperOf, getReturnColumns, getWrapper, setReturnColumnspublic DBMigration(DBDatabase db, M migrationMapper)
public List<M> getAllRows() throws SQLException
Use this method to retrieve all rows when the criteria have been supplied as part of the DBMigration subclass.
If you require extra criteria to be add to the DBMigration, limiting the
results to a subset, use the
other getAllRows method.
Support DBvolution at Patreon
SQLException - java.sql.SQLExceptionpublic List<M> getAllRows(DBRow... extraExamples) throws SQLException
extraExamples - extra rows defining additional criteria
Support DBvolution at Patreon
SQLException - java.sql.SQLExceptionpublic String toString()
toString in class RowDefinitionpublic List<M> getRows(DBDatabase database, DBRow... rows) throws SQLException
All supplied rows should be from a DBRow subclass that is included in the report.
Builtin report limitation will be used, the example rows supply further details for constraining the report.
This method allows you to create generic reports and apply dynamic limitations such as date ranges, department name, and other highly variable parameters.
database - databaserows - rows
Support DBvolution at Patreon
SQLException - java.sql.SQLExceptionpublic List<M> getRowsHaving(DBDatabase database, DBRow[] rows, BooleanExpression... conditions) throws SQLException
All conditions should only reference the fields/column of the DBMigration.
All supplied rows should be from a DBRow subclass that is included in the report.
Built-in report limitation will be used, the example rows supply further details for constraining the report.
This method allows you to create generic reports and apply dynamic limitations such as date ranges, department name, and other highly variable parameters.
database - databaserows - rows example rows that provide extra criteriaconditions - the conditions that will be supplied to the WHERE or
HAVING clause of the query
Support DBvolution at Patreon
SQLException - Database exceptions may be thrownpublic String getSQLForQuery(DBDatabase database, DBRow... rows)
Good for debugging and great for DBAs, this is how you find out what DBvolution is really doing.
Generates the SQL query for retrieving the objects but does not execute the
SQL. Use
the getAllRows method
to retrieve the rows.
See also
#getSQLForCount(nz.co.gregs.dbvolution.DBDatabase, nz.co.gregs.dbvolution.DBRow...)
database - the database the SQL will be run against.rows - additional conditions to apply to the report.
Support DBvolution at Patreon
public String getSQLForInsert(DBDatabase database, DBRow... rows)
Good for debugging and great for DBAs, this is how you find out what DBvolution is really doing.
Generates the SQL query for retrieving the objects but does not execute the
SQL. Use
the getAllRows method
to retrieve the rows.
See also
#getSQLForCount(nz.co.gregs.dbvolution.DBDatabase, nz.co.gregs.dbvolution.DBRow...)
database - the database the SQL will be run against.rows - additional conditions to apply to the report.
Support DBvolution at Patreon
public String getSQLForCount(DBDatabase database, DBRow... rows) throws SQLException
Use this method to check the SQL that will be executed during
the count method
database - the database to format the query for.rows - additional conditions to be applied.
Support DBvolution at Patreon
SQLException - java.sql.SQLExceptionpublic Long count(DBDatabase database, DBRow... rows) throws SQLException
Creates a
count query
for the report and conditions and retrieves the number of rows that would
have been returned had
getAllRows method
been called.
database - the database to format the query for.rows - additional conditions for the query.
Support DBvolution at Patreon
SQLException - java.sql.SQLExceptionpublic DBMigration<M> setSortOrder(ColumnProvider... columns)
For example the following code snippet will sort by just the name column:
CustomerReport customers = ...; customers.setSortOrder(customers.column(customers.name));
columns - a list of columns to sort the query by.
Support DBvolution at Patreon
public DBMigration<M> setSortOrder(QueryableDatatype<?>... columns)
ONLY USE FIELDS FROM THE SAME INSTANCE.
For example the following code snippet will sort by the name and accountNumber columns:
CustomerReport customers = ...; customers.setSortOrder(customers.name, customers.accountNumber);
columns - a list of columns to sort the query by.
Support DBvolution at Patreon
public void addAsOptionalTables(DBRow... examples)
examples - protected ColumnProvider[] getSortColumns()
Support DBvolution at Patreon
public DBMigration<M> setCartesianJoinAllowed(Boolean setting)
DBvolution protects you from accidental Cartesian joins but use this function if a Cartesian is required.
Cartesian joins occur when there is no connection between 2 (or more) tables. Normally all tables are connect by a chain of relationships, usually primary key to foreign key.
Sometimes a connection is missed: for instance 2 unrelated tables are being
compared by price, but the price relating expression has not been added. In
this case DBvolution will throw an AccidentalCartesianJoinException
and abort the query. This exception avoids creating a probably massive
dataset that will reduce database and network performance
significantly.
However there are valid cases for a Cartesian join: finding all possible combinations of cake and coffee for instance.
If you are sure you need a Cartesian join, use this method to avoid the
error-checking and the AccidentalCartesianJoinException
setting - True if you need a Cartesian join in this DBQueryInsert.
Support DBvolution at Patreon
public DBMigration<M> setBlankQueryAllowed(Boolean setting)
A common mistake is creating a query without supplying criteria and accidently retrieving a huge number of rows.
DBvolution detects this situation and, by default, throws a
AccidentalBlankQueryException
when it happens.
To change this behaviour, and allow blank queries, call
setBlankQueriesAllowed(true).
setting - - TRUE to allow blank queries, FALSE to return it to the
default setting.
Support DBvolution at Patreon
public void insertAllRows(DBRow... extraExamples) throws SQLException
SQLExceptionpublic DBMigrationValidation.Results validateAllRows(DBRow... extraExamples) throws SQLException
SQLExceptionCopyright © 2017. All Rights Reserved.