public final class RecordMeta
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
(package private) java.util.BitSet |
allIndexedProps
Bit set which marks the position of each property participating in an index
|
(package private) java.lang.String[] |
deleteSql
SQL delete statement(s) which delete a single DMO's data from the database
|
private DmoMeta |
dmoMeta
The
DmoMeta structure which contains the legacy meta information. |
private java.util.Map<java.lang.String,java.lang.Integer> |
indexIdByName
Map of index name to index UID (positive for unique indices, negative for non-unique indices)
|
(package private) java.lang.Object[] |
initialData
Values to which a newly created record should be set
|
(package private) java.lang.String[] |
insertSql
SQL insert statement(s) which insert a single DMO's data into the database
|
java.lang.String |
legacyName
The legacy name of the parent table.
|
(package private) java.lang.String[] |
loadSql
SQL query statement(s) to access data needed to load a single DMO instance
|
private static java.lang.ThreadLocal<org.apache.commons.lang3.tuple.Pair<java.lang.Class<? extends DataModelObject>,RecordMeta>> |
local
Thread-local, temporary association of a
DataModelObject interface to its
RecordMeta . |
private static java.util.logging.Logger |
log
Logger
|
(package private) java.util.BitSet |
nonNullableProps
Bit set which marks the position of each non-null column in the backing table
|
(package private) java.util.BitSet[] |
nonuniqueIndices
Bit sets which mark the positions of the component columns of non-unique indices
|
private java.lang.String[] |
nonuniqueIndicesLegacyNames
The array of legacy names for non-unique indices, with positional correspondents in
nonuniqueIndices list. |
private java.lang.String[] |
nonuniqueIndicesNames
The array of names for non-unique indices, with positional correspondents in
nonuniqueIndices
list. |
private int |
primaryIndex
UID of primary index, if any.
|
private PropertyMeta[] |
props
Property metadata, ordered scalar properties first, then the extent properties grouped by
their extent size.
|
private java.lang.String[] |
replaceCleanupSql
The set of DELETE SQL statements used to remove existing records that conflict with a record ready to be
inserted.
|
private Dialect |
replaceCleanupSqlDialect
The
Dialect which was used for creating the replaceCleanupSql statements. |
private java.util.Map<java.lang.String,java.lang.Integer> |
reversedIndexProperties |
java.lang.String[] |
tables
Names of the backing database tables
|
private boolean |
temporary
Does this object represent metadata for a temporary table?
|
(package private) java.util.BitSet[] |
uniqueIndices
Bit sets which mark the positions of the component columns of unique indices
|
private java.lang.String[] |
uniqueIndicesLegacyNames
The array of legacy names for unique indices, with positional correspondents in
uniqueIndices list. |
private java.lang.String[] |
uniqueIndicesNames
Array of names of unique indices, with positional correspondents in
uniqueIndices list |
private java.lang.String[] |
uniqueSql
The SQL statements used to test the uniqueness of the record against each unique index.
|
private Dialect |
uniqueSqlDialect
The
Dialect which was used for creating the uniqueSql statements. |
(package private) java.util.BitSet |
validatable
Bit set which marks the position of each property that can be validated
|
Constructor and Description |
---|
RecordMeta(java.lang.Class<? extends DataModelObject> dmoIface,
DmoMeta dmoMeta)
Initialize the record's metadata.
|
Modifier and Type | Method and Description |
---|---|
private static java.lang.String |
backTickify(java.lang.String name)
Enclose a name in back ticks quotes.
|
private java.lang.String[] |
composeReplaceCleanupSQLs(java.lang.String sqlTableName,
Dialect d)
Composes a set of SQL query statements that delete conflicting records from the temp-table.
|
private java.lang.String[] |
composeValidationSQLs(java.lang.String sqlTableName,
Dialect d)
Composes a set of SQL query statements that verify if a record can be safely saved to database so there
are no conflicts with unique indexes.
|
static RecordMeta |
get(java.lang.Class<? extends DataModelObject> key)
Get the last created
RecordMeta . |
java.util.BitSet |
getAllIndexedProperties()
Get a bit set representing all DMO properties which participate in indices in the backing
table.
|
DmoMeta |
getDmoMeta()
Obtain the
DmoMeta structure which contains the legacy meta information. |
int |
getIndexIdByName(java.lang.String name)
Obtain the id of an index using its name.
|
java.lang.String |
getIndexLegacyName(int pos,
boolean unique)
Obtain the legacy name of an index, by its order in the list of unique or non-unique lists.
|
int |
getIndexOfProperty(java.lang.String propName)
Obtain the index of a property in the
data array based on its name. |
java.lang.String |
getLegacyName()
Obtain the legacy name of the parent table.
|
java.lang.String[] |
getNonuniqueIndexNames()
Obtain the array of names of unique indices, if any.
|
java.util.BitSet[] |
getNonuniqueIndices()
Get an array of bit sets, each of which describes the components of a non-unique index.
|
int |
getPrimaryIndexId() |
PropertyMeta[] |
getPropertyMeta(boolean nativeOrder)
Get the array of
property metadata objects which describe how the core
data of this record is organized. |
java.lang.String[] |
getReplaceCleanupSQLs(Dialect d)
Get an array of DELETE SQL statements used to remove existing records which conflict (from the point of
view of unique indexes) with a record that is about to be inserted.
|
java.lang.String[] |
getUniqueIndexNames()
Obtain the array of names of unique indices, if any.
|
java.util.BitSet[] |
getUniqueIndices()
Get an array of bit sets, each of which describes the components of an unique index.
|
java.lang.String[] |
getUniqueIndicesValidationSQLs(Dialect d)
Get an array of SQL statements, each of which the tests the uniqueness of a record against an unique
index.
|
java.util.BitSet |
getValidatableProperties()
Get a bit set representing all DMO properties which must be validated when a record is created or
updated.
|
boolean |
isTemporary()
Indicate whether this object represents metadata for a temporary table.
|
private static java.util.BitSet |
readIndices(java.lang.Class<?> dmoIface,
PropertyMeta[] props,
java.lang.String[] primary,
java.util.BitSet validatable,
java.util.List<java.util.BitSet> unique,
java.util.List<java.lang.String> uniqueNames,
java.util.List<java.lang.String> uniqueLegacyNames,
java.util.List<java.util.BitSet> nonUnique,
java.util.List<java.lang.String> nonUniqueNames,
java.util.List<java.lang.String> nonUniqueLegacyNames)
Read the DMO interface's index annotations, if any.
|
(package private) static PropertyMeta[] |
readPropertyMeta(DmoMeta dmoMeta)
Read the getter method annotations from the DMO interface and generate property metadata
from them.
|
private static java.lang.String |
stripBackTicks(java.lang.String name,
java.lang.String dmoName)
Strip back tick quotes from a name, if it is enclosed in them.
|
private static java.lang.String[] |
tableNames(DmoMeta dmoMeta,
PropertyMeta[] props)
Get the array of table names associated with this DMO.
|
private static final java.util.logging.Logger log
private final boolean temporary
private final PropertyMeta[] props
public final java.lang.String[] tables
public final java.lang.String legacyName
final java.lang.Object[] initialData
final java.util.BitSet nonNullableProps
final java.util.BitSet allIndexedProps
final java.util.BitSet validatable
final java.util.BitSet[] uniqueIndices
private final java.lang.String[] uniqueIndicesNames
uniqueIndices
listprivate final java.lang.String[] uniqueIndicesLegacyNames
uniqueIndices
list.final java.util.BitSet[] nonuniqueIndices
private final java.lang.String[] nonuniqueIndicesNames
nonuniqueIndices
list.private final java.lang.String[] nonuniqueIndicesLegacyNames
nonuniqueIndices
list.final java.lang.String[] loadSql
final java.lang.String[] insertSql
final java.lang.String[] deleteSql
private final DmoMeta dmoMeta
DmoMeta
structure which contains the legacy meta information.private java.lang.String[] uniqueSql
private java.lang.String[] replaceCleanupSql
private Dialect uniqueSqlDialect
Dialect
which was used for creating the uniqueSql
statements.private Dialect replaceCleanupSqlDialect
Dialect
which was used for creating the replaceCleanupSql
statements.
Normally this should be H2 as this is the only dialect supported for temp-tables, as the
replaceCleanupSql
will be used only on _temp database.
private static final java.lang.ThreadLocal<org.apache.commons.lang3.tuple.Pair<java.lang.Class<? extends DataModelObject>,RecordMeta>> local
DataModelObject
interface to its
RecordMeta
. They are the last DataModelObject
processed and the obtained
crtRecordMeta
. We do a double check to be sure the initialization of the static
field _metadata
is correct (and the DMO interface is the right one).
This pair of values is kept until get(java.lang.Class<? extends com.goldencode.p2j.persist.DataModelObject>)
is called and is reset after the first valid
access this static method.private final java.util.Map<java.lang.String,java.lang.Integer> reversedIndexProperties
private final java.util.Map<java.lang.String,java.lang.Integer> indexIdByName
private final int primaryIndex
0
indicates no primary index existsRecordMeta(java.lang.Class<? extends DataModelObject> dmoIface, DmoMeta dmoMeta)
dmoIface
- DMO interface; the public API to business logic. Annotations on the getter
methods of this interface are used to define the concrete subclass.dmoMeta
- The DmoMeta
structure which contains the legacy meta information. May have not been
fully filled yet.public static RecordMeta get(java.lang.Class<? extends DataModelObject> key)
RecordMeta
. After the first access the value is reset.
To avoid processing the readPropertyMeta(com.goldencode.p2j.persist.orm.DmoMeta)
twice (one before creating the DMO
implementation class and one after, when its _metadata
is statically initialized at
first access, we store the last created RecordMeta
) we store the latest created
object in a static member and return it at first call. The RecordMeta
is called
in a synchronized block so that nobody else will get/reset the result. The key
parameter makes sure the new metadata goes to the right class.
key
- The DMO interface that was previously processed. It must be the interface that the
DMO implementation ask for meta data.RecordMeta
that corresponds to key
DMO
interface. If the method is called multiple time, null
is retuned for
subsequent invocation.static PropertyMeta[] readPropertyMeta(DmoMeta dmoMeta)
Loader
class description. This order is critical to all CRUD operations performed by the loader
and persister, and reflects the order of the data stored in the record's core data array.dmoMeta
- DMO metadata.private java.lang.String[] composeValidationSQLs(java.lang.String sqlTableName, Dialect d)
uniqueIndices
array, as in:
select 0 where recid != ? and column1 = ? and column2 = ?for the "0th" index.
Multiple such statements can then be concatenated with the union all
operator and the result
set will have a row corresponding with each unique index which failed validation, or no rows if
validation passed.
sqlTableName
- The name of the SQL table.d
- The dialect to be used when creating the queries.private java.lang.String[] composeReplaceCleanupSQLs(java.lang.String sqlTableName, Dialect d)
sqlTableName
- The name of the SQL table.d
- The dialect to be used when creating the queries.private static java.util.BitSet readIndices(java.lang.Class<?> dmoIface, PropertyMeta[] props, java.lang.String[] primary, java.util.BitSet validatable, java.util.List<java.util.BitSet> unique, java.util.List<java.lang.String> uniqueNames, java.util.List<java.lang.String> uniqueLegacyNames, java.util.List<java.util.BitSet> nonUnique, java.util.List<java.lang.String> nonUniqueNames, java.util.List<java.lang.String> nonUniqueLegacyNames)
BitSet
object which describes the components of each index. Add each such
object to the appropriate list of unique or non-unique index descriptors.
In addition, create and return an BitSet
object which describes all indexed
properties of the DMO.
dmoIface
- DMO interface.props
- Array of metadata objects which describe each property in the DMO. The position
of each element of this array will correspond with a set bit in an BitSet
object which describes an index containing that property.primary
- Single-element string array output parameter, to be filled with the name of the primary
index, if any.validatable
- Bit set of property positions in the record's data
array of those properties which
either are mandatory or which participate in a unique index.unique
- List of BitSet
objects for unique indices, if any. Should be empty
when this method is invoked; may be empty upon return.uniqueNames
- List of names for unique indices, if any, with positional correspondents in unique
list.uniqueLegacyNames
- List of legacy names for unique indices, if any, with positional correspondents in
unique
list.nonUnique
- List of BitSet
objects for non-unique indices, if any. Should be
empty when this method is invoked; may be empty upon return.nonUniqueNames
- List of legacy names for non-unique indices, if any, with positional correspondents
in nonUnique
list.nonUniqueLegacyNames
- List of legacy names for non-unique indices, if any, with positional correspondents in
nonUnique
list.BitSet
object which describes all properties which participate in
any index of the table represented by the DMO.java.lang.IllegalStateException
- if the name of an index component stored in an IndexComponent
annotation
does not match the name of any property in the DMO.private static java.lang.String[] tableNames(DmoMeta dmoMeta, PropertyMeta[] props)
dmoMeta
- The DmoMeta
structure which contains the legacy meta information.props
- Array of property metadata, ordered as described in the Loader
class description.private static java.lang.String stripBackTicks(java.lang.String name, java.lang.String dmoName)
name
parameter.name
- Name from which to strip back ticks.dmoName
- DMO interface name (for error reporting only).java.lang.IllegalArgumentException
- if a back tick leads or trails the name, but not both (i.e., unbalanced back tick quotes).private static java.lang.String backTickify(java.lang.String name)
name
- Name to enclose.public DmoMeta getDmoMeta()
DmoMeta
structure which contains the legacy meta information.DmoMeta
structure which contains the legacy meta informationpublic boolean isTemporary()
true
if backing, primary, table is a temporary table, else false
.public PropertyMeta[] getPropertyMeta(boolean nativeOrder)
property metadata
objects which describe how the core
data of this record is organized.nativeOrder
- If true
the returned array of properties will be sorted by their
id
-s. This is the 'native' order, in which the records are found in
exported (.d dump) files. This view of the properties is only needed when the
import process is run.public java.util.BitSet getAllIndexedProperties()
public java.util.BitSet getValidatableProperties()
public java.util.BitSet[] getUniqueIndices()
public java.lang.String[] getUniqueIndicesValidationSQLs(Dialect d)
public java.lang.String[] getReplaceCleanupSQLs(Dialect d)
Only used for FILL operations in REPLACE mode.
public java.util.BitSet[] getNonuniqueIndices()
public java.lang.String getIndexLegacyName(int pos, boolean unique)
pos
- The position in the list of unique or non-unique list of indices.unique
- If true
, the name of the pos
unique index is returned, otherwise
the non-unique list is used.null
if the index is invalid.public java.lang.String[] getUniqueIndexNames()
getUniqueIndices()
and getIndexLegacyName()
.public java.lang.String[] getNonuniqueIndexNames()
getNonuniqueIndices()
and getIndexLegacyName()
.public java.lang.String getLegacyName()
public int getIndexOfProperty(java.lang.String propName)
data
array based on its name.
NOTE:
Use this method only in non-time-critical code. It uses map access and usage is not recommended.
propName
- The name of the property.public int getIndexIdByName(java.lang.String name)
name
- The name of the index.public int getPrimaryIndexId()