public final class DBUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAX_INDEX_SIZE
The default maximum permitted size for all combined fields of an index.
|
private static java.util.logging.Logger |
LOG
Logger
|
private static java.util.Map<java.lang.Class<?>,java.util.Set<java.lang.String>> |
notNullPropSets
Sets of non-nullable DMO properties, mapped by DMO implementation class
|
static int |
TABLE_ID_FIELD_SIZE
The size of the id primary synthetic field (DatabaseManager.PRIMARY_KEY) added to tables,
used by non-unique indexes.
|
private static java.util.Map<java.lang.Class<?>,org.hibernate.type.Type> |
types
Mapping of wrapper data types to Hibernate
Type s |
Constructor and Description |
---|
DBUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
composePropertyName(boolean isCharacter,
boolean ignoreCase,
java.lang.String computedColumnPrefix,
java.lang.String alias,
java.lang.String name,
java.lang.StringBuilder buf,
P2JDialect dialect)
Compose a DMO property name within the given string buffer.
|
(package private) static void |
composePropertyName(RecordBuffer buffer,
java.lang.String name,
java.lang.StringBuilder buf)
Compose a DMO property name within the given string buffer.
|
(package private) static void |
composePropertyName(RecordBuffer buffer,
java.lang.String name,
java.lang.StringBuilder buf,
Database.Type type)
Compose a DMO property name within the given string buffer.
|
static java.lang.Class<?> |
dmoClassForEntity(java.lang.String entityName)
Get the DMO implementation class for the given DMO entity name.
|
static java.lang.String |
entityForDMOInterface(java.lang.Class<?> dmoIface)
Generate the DMO implementation class name (the entity name), given a
DMO interface.
|
static java.lang.String |
extractIndexName(java.lang.String indexName)
Extracts index name from index name optionally containing prefix "idx__" and backticks.
|
(package private) static java.lang.reflect.Method |
findDMOGetterMethod(java.lang.Class<?> dmoClass,
java.lang.String propName,
java.lang.Class<?>[] parmTypes)
Look up the getter method associated with the given property.
|
static java.lang.String |
formatWithEscapedParameter(java.lang.String format,
java.lang.String parameter)
Returns a formatted string using the specified format string and parameter optionally
containing backticks.
|
static java.lang.String |
formatWithEscapedParameter(java.lang.String format,
java.lang.String parameter,
java.lang.Long index)
Returns a formatted string using the specified format string and arguments optionally
containing backticks.
|
static java.lang.String |
formatWithEscapedParameters(java.lang.String format,
java.lang.String table,
java.lang.String... params)
Returns a formatted string using the specified format string and arguments optionally
containing backticks.
|
static java.lang.Class<?> |
getDMOPropertyType(java.lang.Class<?> dmoIface,
java.lang.String property)
Report the data type of a DMO property.
|
static FieldReference[] |
getFieldForAddLikeColumn(P2JQuery query,
character fieldExpression)
Get field reference(s) for ADD-LIKE-COLUMN.
|
static FieldReference[] |
getFieldForAddLikeColumn(P2JQuery query,
handle fieldHandle)
Get field reference(s) for ADD-LIKE-COLUMN.
|
(package private) static java.lang.Class<?> |
getGetterSetterType(java.lang.reflect.Method method)
This method returns return type or parameter type depending on getter/setter method name
prefix.
|
static java.util.Map<java.lang.Class<?>,org.hibernate.type.Type> |
getHibernateTypeMap()
Get the mapping of Java class to Hibernate data type used by P2J.
|
static java.lang.String |
getPrefixedParameter(java.lang.String parameter,
java.lang.String prefix)
Returns prefixed parameter optionally containing backticks.
|
static void |
handleException(Database database,
java.lang.Exception exc)
Handle an
InterruptedException , which may be wrapped in an
exception causal chain, by throwing StopConditionException . |
(package private) static boolean |
isMandatoryProperty(Database database,
java.lang.Class<?> dmoClass,
java.lang.String property)
Determine whether the given property in the context of the given DMO class represents a
mandatory (i.e., non-nullable) database column.
|
static org.hibernate.type.Type[] |
makeTypeArray(java.lang.Object[] args)
Convenience method to create an array of Hibernate
Type
objects to match the given array of substitution parameters. |
static org.hibernate.type.Type[] |
makeTypeArray(java.lang.Object[] args,
org.hibernate.type.Type[] types)
Convenience method to populate an array of Hibernate
Type
objects to match the given array of substitution parameters. |
(package private) static java.io.Serializable[] |
trimToTableCount(java.io.Serializable[] array,
P2JQuery query)
Right-trim array according to the query's table count.
|
public static final int DEFAULT_MAX_INDEX_SIZE
public static final int TABLE_ID_FIELD_SIZE
private static final java.util.logging.Logger LOG
private static final java.util.Map<java.lang.Class<?>,org.hibernate.type.Type> types
Type
sprivate static final java.util.Map<java.lang.Class<?>,java.util.Set<java.lang.String>> notNullPropSets
public static java.util.Map<java.lang.Class<?>,org.hibernate.type.Type> getHibernateTypeMap()
public static org.hibernate.type.Type[] makeTypeArray(java.lang.Object[] args)
Type
objects to match the given array of substitution parameters. It is
assumed that neither args
nor any of its elements are
null
.args
- Array of HQL query substitution parameters.Type
instances.java.lang.IllegalArgumentException
- if args
contains a parameter of unknown type.public static org.hibernate.type.Type[] makeTypeArray(java.lang.Object[] args, org.hibernate.type.Type[] types)
Type
objects to match the given array of substitution parameters. It is
assumed that neither args
nor any of its elements are
null
.
This implementation handles both resolved (BaseDataType
)
and unresolved (Resolvable
) arguments. The latter is
possible because we only care about the data type, not the actual value,
of the parameters.
If any element in the types
array is non-null
,
it is skipped.
args
- Array of HQL query substitution parameters.types
- Array of the same size as args
; some elements
may be pre-populated.Type
instances.java.lang.IllegalArgumentException
- if args
contains a parameter of unknown type.public static java.lang.Class<?> getDMOPropertyType(java.lang.Class<?> dmoIface, java.lang.String property) throws PersistenceException
dmoIface
- DMO interface.property
- Unqualified DMO property name.PersistenceException
- if the property doesn't exist, or if there is some error determining its data type.public static void composePropertyName(boolean isCharacter, boolean ignoreCase, java.lang.String computedColumnPrefix, java.lang.String alias, java.lang.String name, java.lang.StringBuilder buf, P2JDialect dialect)
foo.bar
, the
end result would be:
upper(rtrim(foo.bar))For a non-text property
foo.bar
, foo.bar
is emitted.isCharacter
- true
for text properties; false
for
non-text properties.ignoreCase
- true
if the name expression must be wrapped in an
uppercasing function; false
for case-sensitive
text properties, as well as for non-text properties.computedColumnPrefix
- If a computed column is needed instead of embedding the DMO
property name within a function, this parameter should be the
non-null prefix to be prepended before the property name.
If null
, it is assumed function use is acceptable.alias
- Optional alias used to qualify name
. Ignored if null
.name
- Unqualified DMO property name.buf
- String buffer into which results are emitted.dialect
- The dialect used for rtrim
sql function. If isCharacter
is false
this parameter is ignored.public static java.lang.Class<?> dmoClassForEntity(java.lang.String entityName)
entityName
- DMO entity name.java.lang.IllegalArgumentException
- if entityName
does not represent a loaded class,
or if there is any other error loading the class.public static java.lang.String entityForDMOInterface(java.lang.Class<?> dmoIface)
dmoIface
- DMO interface.public static java.lang.String extractIndexName(java.lang.String indexName)
indexName
- Index name.public static java.lang.String formatWithEscapedParameter(java.lang.String format, java.lang.String parameter)
format
- Format string.parameter
- String parameter optionally containing backticks..public static java.lang.String formatWithEscapedParameter(java.lang.String format, java.lang.String parameter, java.lang.Long index)
format
- Format string.parameter
- String parameter optionally containing backticks..index
- Nullable value.public static java.lang.String getPrefixedParameter(java.lang.String parameter, java.lang.String prefix)
parameter
- Parameter optionally containing backticks.prefix
- Prefix.public static java.lang.String formatWithEscapedParameters(java.lang.String format, java.lang.String table, java.lang.String... params)
format
- Format string.table
- String parameter optionally containing backticks.params
- String parameters optionally containing backticks.public static void handleException(Database database, java.lang.Exception exc)
InterruptedException
, which may be wrapped in an
exception causal chain, by throwing StopConditionException
.
Alternatively, if the error represents a database connection problem,
DatabaseConnectionException
is thrown. Determination of
the latter type of problem is dialect-specific.
If neither of these conditions is found to be the cause of the error, this method returns normally.
database
- The database in use when the exception was thrown. May be
null
if no database is used.exc
- An exception to inspect.StopConditionException
- if exc
or any exception in its causal chain is an
instance of InterruptException
.DatabaseConnectionException
- if exc
or any exception in its causal chain is
determined to be a database connection error.public static FieldReference[] getFieldForAddLikeColumn(P2JQuery query, handle fieldHandle)
query
- The query which backs the browse ADD-LIKE-COLUMN was called for.fieldHandle
- Handle to the target field.fieldHandle
is valid and
references a buffer which participates in the query, null
otherwise.
If fieldHandle
references an extent field, multiple field references
for each extent element are returned.public static FieldReference[] getFieldForAddLikeColumn(P2JQuery query, character fieldExpression)
query
- The query which backs the browse ADD-LIKE-COLUMN was called for.fieldExpression
- Expression which specifies the target field. Has format [database
name.]{legacy table name|legacy buffer name}.legacy field name
.null
otherwise.
If the field expression references an extent field, multiple field references
for each extent element are returned.static java.lang.Class<?> getGetterSetterType(java.lang.reflect.Method method)
method
- Method.static java.lang.reflect.Method findDMOGetterMethod(java.lang.Class<?> dmoClass, java.lang.String propName, java.lang.Class<?>[] parmTypes) throws PersistenceException
get
and is
variants.dmoClass
- DMO implementation class.propName
- Unqualified DMO property name.parmTypes
- Array of data types which are expected by the getter method.
This will generally be null
(or an empty array),
or an array with one element of type Integer.TYPE
(representing the index value passed to an indexed getter
method).PersistenceException
- if propName
does not represent a property of
dmoClass
.static void composePropertyName(RecordBuffer buffer, java.lang.String name, java.lang.StringBuilder buf) throws PersistenceException
foo.bar
, the
end result would be:
upper(rtrim(foo.bar))
For a non-text property foo.bar
, foo.bar
is
emitted.
buffer
- Record buffer which holds information about the DMO's alias,
interface, and implementation class.name
- Unqualified DMO property name.buf
- String buffer into which results are emitted.PersistenceException
- if any errors occur looking up metadata regarding the property.static void composePropertyName(RecordBuffer buffer, java.lang.String name, java.lang.StringBuilder buf, Database.Type type) throws PersistenceException
foo.bar
, the
end result would be:
upper(rtrim(foo.bar))
In cases where a special computed column name is required instead of the enclosing function syntax noted above, such a name is generated instead.
For a non-text property foo.bar
, foo.bar
is
emitted.
buffer
- Record buffer which holds information about the DMO's alias,
interface, and implementation class.name
- Unqualified DMO property name.buf
- String buffer into which results are emitted.type
- Database type, which drives the dialect to use to compose the name.PersistenceException
- if any errors occur looking up metadata regarding the property.static boolean isMandatoryProperty(Database database, java.lang.Class<?> dmoClass, java.lang.String property)
database
- Database containing table represented by DMO class.dmoClass
- DMO implementation class.property
- Property name.true
if the property is mandatory, else false
.static java.io.Serializable[] trimToTableCount(java.io.Serializable[] array, P2JQuery query)
array
- Array to trim.query
- Target query.