T - public abstract class QueryableDatatype<T> extends Object implements Serializable, DBExpression
Support DBvolution at Patreon
| Modifier and Type | Field and Description |
|---|---|
static Boolean |
SORT_ASCENDING
Used to indicate the the QDT should be sorted so that the values run from
A->Z or 0->9 when using the
setSortOrder(java.lang.Boolean)
method. |
static Boolean |
SORT_DESCENDING
Used to indicate the the QDT should be sorted so that the values run from
Z->A or 9->0 when using the
setSortOrder(java.lang.Boolean)
method. |
| Modifier | Constructor and Description |
|---|---|
protected |
QueryableDatatype()
Default Constructor
|
protected |
QueryableDatatype(DBExpression columnExpression)
Create a QDT with a permanent column expression.
|
protected |
QueryableDatatype(DBExpression[] columnExpression)
Create a QDT with a permanent column expression.
|
protected |
QueryableDatatype(T obj)
Create a QueryableDatatype with the exact value provided.
|
| Modifier and Type | Method and Description |
|---|---|
QueryableDatatype<T> |
clear()
Remove the conditions, criteria, and operators applied to this QDT.
|
QueryableDatatype<T> |
copy()
Copies a QueryableDatatype and returns the copy.
|
String |
createSQLForFromClause(DBDatabase database) |
boolean |
equals(Object otherObject) |
String |
formatColumnForSQLStatement(DBDefinition db,
String formattedColumnName)
Returns the column of the object formatted for the database.
|
protected abstract String |
formatValueForSQLStatement(DBDefinition db)
Returns the value of the object formatted for the database
This should be overridden in each subclass
This method is called by toSQLString after checking for NULLs and should
return a string representation of the object formatted for use within a SQL
select, insert, update, or delete statement.
|
abstract ColumnProvider |
getColumn(RowDefinition row)
Creates a Column Provider suitable to this QDT.
|
DBExpression[] |
getColumnExpression()
Returns the expression underlying this QDT or null.
|
protected abstract T |
getFromResultSet(DBDefinition database,
ResultSet resultSet,
String fullColumnName)
Returns the correct object from the ResultSet for the QueryableDatatype to
handle.
|
protected T |
getLiteralValue()
Support DBvolution at Patreon |
DBOperator |
getOperator()
Support DBvolution at Patreon |
String |
getPreviousSQLValue(DBDefinition db)
Returns the previous value of this field as an SQL formatted String.
|
protected QueryableDatatype<T> |
getPreviousValue()
Used internally.
|
protected PropertyWrapperDefinition |
getPropertyWrapperDefinition()
Used internally.
|
QueryableDatatype<T> |
getQueryableDatatypeForExpressionValue()
Provides a blank instance of the
QueryableDatatype used by this
expression. |
static <S> QueryableDatatype<S> |
getQueryableDatatypeForObject(S o)
Returns an appropriate QueryableDatatype for the provided object.
|
static <T extends QueryableDatatype<?>> |
getQueryableDatatypeInstance(Class<T> requiredQueryableDatatype)
Factory method that creates a new QDT instance with the same class as the
provided example.
|
Boolean |
getSortOrder()
Return the order in which this QDT will be sorted.
|
abstract String |
getSQLDatatype()
Provides the SQL datatype used by default for this type of object.
|
Set<DBRow> |
getTablesInvolved()
Returns a Set of the DBRow instances involved in this expression.
|
Object |
getValue()
Gets the current literal value of this queryable data type.
|
boolean |
hasBeenSet()
Support DBvolution at Patreon |
boolean |
hasChanged()
Indicates that the value of this QDT has been changed from its defined
value.
|
boolean |
hasColumnExpression()
Tests for the expression underlying this QDT or returns FALSE.
|
int |
hashCode() |
void |
includingNulls()
Causes the underlying operator to explicitly include NULL values in it's
processing.
|
boolean |
isComplexExpression() |
boolean |
isDefined()
Support DBvolution at Patreon |
boolean |
isNotNull()
Indicates whether object is NULL within the database
|
boolean |
isNull()
Indicates whether object is NULL within the database
|
boolean |
isPurelyFunctional()
Indicates whether or not the expression includes table columns.
|
void |
negateOperator()
Negate the meaning of the comparison associated with this object.
|
QueryableDatatype<T> |
removeConstraints()
Remove the conditions, criteria, and operators applied to this QDT.
|
protected void |
setChanged(boolean hasChanged)
Used internally.
|
protected void |
setColumnExpression(DBExpression... columnExpression)
Used Internally.
|
protected void |
setDefined(boolean defined) |
void |
setFromResultSet(DBDefinition defn,
ResultSet resultSet,
String resultSetColumnName)
Used internally to set the QDT to the value returned from the database.
|
protected void |
setLiteralValue(T newLiteralValue)
Sets the literal value of this queryable data type.
|
void |
setOperator(DBOperator operator) |
protected void |
setPreviousValue(QueryableDatatype<T> queryableDatatype)
Used internally.
|
QueryableDatatype<T> |
setSortOrderAscending()
Used to switch the direction of the column's sort order
Support DBvolution at Patreon |
QueryableDatatype<T> |
setSortOrderDescending()
Used to switch the direction of the column's sort order
Support DBvolution at Patreon |
protected DBOperator |
setToNull()
Sets the value of this column to DBNull Also changes the operator to
DBIsNullOperator for comparisons
Support DBvolution at Patreon |
protected DBOperator |
setToNull(DBDefinition database)
Used during setFromResultSet to set the QDT to a database NULL value.
|
void |
setUnchanged()
Clear the changes to this QDT and remove the previous value as though this
QDT had never had any value other than the current value.
|
protected abstract void |
setValueFromStandardStringEncoding(String encodedValue)
Set the value of this QDT to the value provided from the standard string
encoding of this datatype
|
void |
setValueToNull()
Convenient synonym for setValue(null).
|
String |
stringValue()
Returns the raw value as a String
|
String |
toSQLString(DBDefinition defn)
Formats the literal value for use within an SQL statement.
|
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitisAggregatorpublic static final Boolean SORT_ASCENDING
setSortOrder(java.lang.Boolean)
method.public static final Boolean SORT_DESCENDING
setSortOrder(java.lang.Boolean)
method.protected QueryableDatatype()
protected QueryableDatatype(T obj)
Equivalent to new QueryableDatatype().setValue(obj);
obj - the literal value of the QDT.protected QueryableDatatype(DBExpression[] columnExpression)
Use this method within a DBRow sub-class to create a column that uses an expression to create the value at query time.
This is particularly useful for trimming strings or converting between types but also allows for complex arithmetic and transformations.
columnExpression - columnExpressionprotected QueryableDatatype(DBExpression columnExpression)
Use this method within a DBRow sub-class to create a column that uses an expression to create the value at query time.
This is particularly useful for trimming strings or converting between types but also allows for complex arithmetic and transformations.
columnExpression - columnExpressionpublic static <T extends QueryableDatatype<?>> T getQueryableDatatypeInstance(Class<T> requiredQueryableDatatype)
This method only provides a new blank instance. To copy the QDT and its
fields, use copy().
T - the QDT typerequiredQueryableDatatype - requiredQueryableDatatype
Support DBvolution at Patreon
public static <S> QueryableDatatype<S> getQueryableDatatypeForObject(S o)
Provides the base QDTs for Integer, Number, String, Date, Byte[], Boolean, NumberResult, StringResult, DateResult, LargeObjectResult, BooleanResult and defaults everything else to DBJavaObject.
S - the base datatype returned by the QDTo - the object to be encapsulated in the QDT
Support DBvolution at Patreon
public QueryableDatatype<T> copy()
Support DBvolution at Patreon
copy in interface DBExpressionpublic String stringValue()
A database NULL is treated as an empty string, use isNull() to
handle NULLs separately.
Support DBvolution at Patreon
public QueryableDatatype<T> removeConstraints()
After calling this method, this object will not cause a where clause to be generated in any subsequent queries.
Support DBvolution at Patreon
public void negateOperator()
For instance, given thisQDT.permittedValue(1), thisQDT.negateOperator() will cause the operator to return everything other than 1.
If this object has an operator defined for it, this method will invert the
meaning of the operator by calling the operator's DBOperator.invertOperator(java.lang.Boolean) with "true".
public Object getValue()
This method will return NULL if the QDT represents a database NULL OR the
field is undefined. Use isNull() and isDefined() to
differentiate the 2 states.
Undefined QDTs represents a QDT that is not a field from the database.
Undefined QDTs are similar to undefined DBRows
Support DBvolution at Patreon
protected abstract void setValueFromStandardStringEncoding(String encodedValue)
Subclass writers should ensure that the method handles nulls correctly and throws an exception if an inappropriate value is supplied.
encodedValue - the value of the QDT in the appropriate encodingprotected void setLiteralValue(T newLiteralValue)
equals operator on the given value.newLiteralValue - the literalValue to setpublic void setUnchanged()
protected DBOperator setToNull()
Support DBvolution at Patreon
public void includingNulls()
For instance: normally thisQDT.permittedValue(1) will only return fields with the value 1. Calling thisQDT.includingNulls() as well will cause the operator to return fields with value 1 and those with value NULL.
public abstract String getSQLDatatype()
This should be overridden in each subclass
Example return value: "VARCHAR(1000)"
Database specific datatypes are provided by the DBDefinition in the method
DBDefinition.getDatabaseDataTypeOfQueryableDatatype(nz.co.gregs.dbvolution.datatypes.QueryableDatatype<?>)
Support DBvolution at Patreon
public final String toSQLString(DBDefinition defn)
This is used internally to transform the Java object in to SQL format. You won't need to use it.
Support DBvolution at Patreon
toSQLString in interface DBExpressiondefn - protected abstract String formatValueForSQLStatement(DBDefinition db)
db - db
Support DBvolution at Patreon
public DBOperator getOperator()
Support DBvolution at Patreon
public void setOperator(DBOperator operator)
operator - the operator to setpublic boolean hasChanged()
Support DBvolution at Patreon
public void setFromResultSet(DBDefinition defn, ResultSet resultSet, String resultSetColumnName) throws SQLException
If you create a new QDT you should override this method. The default
implementation in QueryableDatatype processes the ResultSet column
as a String. You should follow the basic pattern but change
ResultSet.getString(String)
to the required ResultSet method and add any required post-processing.
Note that most of the method is dedicated to detecting NULL values. This is
very important as are the calls to setUnchanged() and setDefined(boolean)
defn - databaseresultSet - resultSetresultSetColumnName - resultSetColumnNameSQLException - Database exceptions may be thrownprotected abstract T getFromResultSet(DBDefinition database, ResultSet resultSet, String fullColumnName) throws SQLException
database - databaseresultSet - resultSetfullColumnName - fullColumnName
Support DBvolution at Patreon
SQLException - java.sql.SQLExceptionpublic boolean isNull()
Databases and Java both use the term NULL but for slightly different meanings.
This method indicates whether the field represented by this object is NULL in the database sense.
Support DBvolution at Patreon
public boolean isNotNull()
Databases and Java both use the term NULL but for slightly different meanings.
This method indicates whether the field represented by this object is NULL in the database sense.
Support DBvolution at Patreon
public String getPreviousSQLValue(DBDefinition db)
Used by DBActionList to generate
revert action lists.
db - db
Support DBvolution at Patreon
public QueryableDatatype<T> setSortOrderAscending()
Support DBvolution at Patreon
public QueryableDatatype<T> setSortOrderDescending()
Support DBvolution at Patreon
public Boolean getSortOrder()
Support DBvolution at Patreon
SORT_ASCENDING if the column is to be sorted ascending,
SORT_DESCENDING otherwise.public QueryableDatatype<T> clear()
After calling this method, this object will not cause a where clause to be generated in any subsequent queries.
Synonym for removeConstraints().
Support DBvolution at Patreon
public boolean isDefined()
Support DBvolution at Patreon
protected void setDefined(boolean defined)
defined - the undefined to setpublic QueryableDatatype<T> getQueryableDatatypeForExpressionValue()
DBExpressionQueryableDatatype used by this
expression.
You are probably looking for ExpressionColumn.asExpressionColumn().
Note that this method is not good for use in everyday DBvolution code and should probably be reserved for meta-programming.
Support DBvolution at Patreon
getQueryableDatatypeForExpressionValue in interface DBExpressionpublic final DBExpression[] getColumnExpression()
When the QDT is created using an expression , this method makes the expression accessible.
Support DBvolution at Patreon
public final boolean hasColumnExpression()
When the QDT is created using an expression , this method makes the expression accessible.
Support DBvolution at Patreon
public Set<DBRow> getTablesInvolved()
DBExpressionUsed by QueryGraph to plot the connections between tables and avoid cartesian joins.
Support DBvolution at Patreon
getTablesInvolved in interface DBExpressionpublic boolean hasBeenSet()
Support DBvolution at Patreon
protected T getLiteralValue()
Support DBvolution at Patreon
protected DBOperator setToNull(DBDefinition database)
DBDatabase is supplied so that database-specific processing, such as Oracle empty strings, can be performed.
Sets the value of this column to DBNull Also changes the operator to DBIsNullOperator for comparisons.
The default implementation just calls setToNull()
database - database
Support DBvolution at Patreon
protected void setChanged(boolean hasChanged)
hasChanged - hasChangedprotected QueryableDatatype<T> getPreviousValue()
Support DBvolution at Patreon
protected void setPreviousValue(QueryableDatatype<T> queryableDatatype)
queryableDatatype - queryableDatatypeprotected PropertyWrapperDefinition getPropertyWrapperDefinition()
Support DBvolution at Patreon
protected final void setColumnExpression(DBExpression... columnExpression)
columnExpression - the columnExpression to setpublic void setValueToNull()
public boolean isPurelyFunctional()
DBExpressionPurely functional expressions use only in-built functions or literal values to produce results and do not require data from tables.
Some databases, notably MS SQLServer, can not group purely functional expressions.
Support DBvolution at Patreon
isPurelyFunctional in interface DBExpressionpublic String formatColumnForSQLStatement(DBDefinition db, String formattedColumnName)
This method provides a route to transforming all calls to a column prior to use in SQL.
See
the implementation in DBStringTrimmed
for an example.
db - dbformattedColumnName - the name of the database column or similar
expression ready to be used in an SQL excerpt
Support DBvolution at Patreon
public abstract ColumnProvider getColumn(RowDefinition row) throws IncorrectRowProviderInstanceSuppliedException
Creates a ColumnProvider object of the correct type for this QueryableDatatype, using this object and the provided row.
Used internally to maintain the relationship between QDTs and their ColumnProvider equivalents.
row - IncorrectRowProviderInstanceSuppliedException - if this object is not
a field in the row.public final String createSQLForFromClause(DBDatabase database)
createSQLForFromClause in interface DBExpressionpublic final boolean isComplexExpression()
isComplexExpression in interface DBExpressionCopyright © 2018. All Rights Reserved.