Basic functionality for persisting an entity via JDBC
through either generated or custom SQL
addDiscriminatorToInsert
protected void addDiscriminatorToInsert(Insert insert)
addDiscriminatorToSelect
protected void addDiscriminatorToSelect(SelectFragment select,
String name,
String suffix)
canExtractIdOutOfEntity
public boolean canExtractIdOutOfEntity()
Determine whether detahced instances of this entity carry their own
identifier value.
The other option is the deperecated feature where users could supply
the id during session calls.
- canExtractIdOutOfEntity in interface EntityPersister
check
protected boolean check(int rows,
Serializable id,
int tableNumber,
Expectation expectation,
PreparedStatement statement)
throws HibernateException
concretePropertySelectFragment
protected String concretePropertySelectFragment(String alias,
boolean[] includeProperty)
concretePropertySelectFragment
protected String concretePropertySelectFragment(String alias,
ValueInclusion[] inclusions)
concretePropertySelectFragmentSansLeadingComma
protected String concretePropertySelectFragmentSansLeadingComma(String alias,
boolean[] include)
consumesCollectionAlias
public boolean consumesCollectionAlias()
Very, very, very ugly...
- consumesCollectionAlias in interface Joinable
- Does this persister "consume" collection column aliases in the result
set?
consumesEntityAlias
public boolean consumesEntityAlias()
Very, very, very ugly...
- consumesEntityAlias in interface Joinable
- Does this persister "consume" entity column aliases in the result
set?
createFrom
protected String createFrom(int tableNumber,
String alias)
createJoin
protected JoinFragment createJoin(String name,
boolean innerJoin,
boolean includeSubclasses)
createJoin
protected JoinFragment createJoin(int[] tableNumbers,
String drivingAlias)
createQueryLoader
protected void createQueryLoader()
createSelect
protected SelectFragment createSelect(int[] subclassColumnNumbers,
int[] subclassFormulaNumbers)
createUniqueKeyLoaders
protected void createUniqueKeyLoaders()
throws MappingException
createWhereByKey
protected String createWhereByKey(int tableNumber,
String alias)
dehydrate
protected int dehydrate(Serializable id,
Object[] fields,
Object rowId,
boolean[] includeProperty,
boolean[][] includeColumns,
int j,
PreparedStatement ps,
SessionImplementor session,
int index)
throws SQLException,
HibernateException
Marshall the fields of a persistent instance to a prepared statement
dehydrate
protected int dehydrate(Serializable id,
Object[] fields,
boolean[] includeProperty,
boolean[][] includeColumns,
int j,
PreparedStatement st,
SessionImplementor session)
throws HibernateException,
SQLException
delete
protected void delete(Serializable id,
Object version,
int j,
Object object,
String sql,
SessionImplementor session,
Object[] loadedState)
throws HibernateException
Perform an SQL DELETE
filterFragment
protected abstract String filterFragment(String alias)
throws MappingException
filterFragment
public String filterFragment(String alias,
Map enabledFilters)
throws MappingException
Get the where clause filter, given a query alias and considering enabled session filters
- filterFragment in interface Joinable
findDirty
public int[] findDirty(Object[] currentState,
Object[] previousState,
Object entity,
SessionImplementor session)
throws HibernateException
Locate the property-indices of all properties considered to be dirty.
- findDirty in interface EntityPersister
currentState
- The current state of the entity (the state to be checked).previousState
- The previous state of the entity (the state to be checked against).entity
- The entity for which we are checking state dirtiness.session
- The session in which the check is ccurring.
- null or the indices of the dirty properties
findModified
public int[] findModified(Object[] old,
Object[] current,
Object entity,
SessionImplementor session)
throws HibernateException
Locate the property-indices of all properties considered to be dirty.
- findModified in interface EntityPersister
old
- The old state of the entity.current
- The current state of the entity.entity
- The entity for which we are checking state modification.session
- The session in which the check is ccurring.
- null or the indices of the modified properties
fromJoinFragment
public String fromJoinFragment(String alias,
boolean innerJoin,
boolean includeSubclasses)
Get the from clause part of any joins
(optional operation)
- fromJoinFragment in interface Joinable
generateDeleteString
protected String generateDeleteString(int j)
Generate the SQL that deletes a row by id (and version)
generateFilterConditionAlias
public String generateFilterConditionAlias(String rootAlias)
The alias used for any filter conditions (mapped where-fragments or
enabled-filters).
This may or may not be different from the root alias depending upon the
inheritence mapping strategy.
- generateFilterConditionAlias in interface Queryable
rootAlias
- The root alias
- The alias used for "filter conditions" within the where clause.
generateIdentityInsertString
protected String generateIdentityInsertString(boolean[] includeProperty)
Used to generate an insery statement against the root table in the
case of identifier generation strategies where the insert statement
executions actually generates the identifier value.
includeProperty
- indices of the properties to include in the
insert statement.
- The insert SQL statement string
generateInsertGeneratedValuesSelectString
protected String generateInsertGeneratedValuesSelectString()
generateInsertString
protected String generateInsertString(boolean identityInsert,
boolean[] includeProperty)
generateInsertString
protected String generateInsertString(boolean identityInsert,
boolean[] includeProperty,
int j)
Generate the SQL that inserts a row
generateInsertString
protected String generateInsertString(boolean[] includeProperty,
int j)
generateLazySelectString
protected String generateLazySelectString()
generateSelectVersionString
protected String generateSelectVersionString()
Generate the SQL that selects the version number by id
generateSnapshotSelectString
protected String generateSnapshotSelectString()
generateTableAlias
protected String generateTableAlias(String rootAlias,
int tableNumber)
generateUpdateGeneratedValuesSelectString
protected String generateUpdateGeneratedValuesSelectString()
generateUpdateString
protected String generateUpdateString(boolean[] includeProperty,
int j,
Object[] oldFields,
boolean useRowId)
Generate the SQL that updates a row by id (and version)
generateUpdateString
protected String generateUpdateString(boolean[] includeProperty,
int j,
boolean useRowId)
getDiscriminatorAlias
protected String getDiscriminatorAlias()
getDiscriminatorFormulaTemplate
protected String getDiscriminatorFormulaTemplate()
getIdentifierAliases
protected String[] getIdentifierAliases()
getIdentifierColumnSpan
protected int getIdentifierColumnSpan()
getKeyColumns
protected abstract String[] getKeyColumns(int j)
getLazyProperties
protected Set getLazyProperties()
getMappedSuperclass
public String getMappedSuperclass()
Get the class that this class is mapped as a subclass of -
not necessarily the direct superclass
- getMappedSuperclass in interface Queryable
getName
public String getName()
An identifying name; a class name or collection role name.
- getName in interface Joinable
getNaturalIdentifierSnapshot
public Object[] getNaturalIdentifierSnapshot(Serializable id,
SessionImplementor session)
throws HibernateException
Retrieve the current state of the natural-id properties from the database.
- getNaturalIdentifierSnapshot in interface EntityPersister
id
- The identifier of the entity for which to retrieve the naturak-id values.session
- The session from which the request originated.
getNonLazyPropertyUpdateability
public boolean[] getNonLazyPropertyUpdateability()
getPropertiesToInsert
protected boolean[] getPropertiesToInsert(Object[] fields)
Transform the array of property indexes to an array of booleans,
true when the property is insertable and non-null
getPropertiesToUpdate
protected final boolean[] getPropertiesToUpdate(int[] dirtyProperties,
boolean hasDirtyCollection)
Transform the array of property indexes to an array of booleans,
true when the property is dirty
getPropertyCheckability
public boolean[] getPropertyCheckability()
Get the "checkability" of the properties of this class
(is the property dirty checked, does the cache need
to be updated)
- getPropertyCheckability in interface EntityPersister
getPropertyColumnSpan
protected int getPropertyColumnSpan(int i)
getPropertyInsertability
public boolean[] getPropertyInsertability()
Get the "insertability" of the properties of this class
(does the property appear in an SQL INSERT)
- getPropertyInsertability in interface EntityPersister
getPropertySpan
protected int getPropertySpan()
getPropertySubclassNames
protected String[] getPropertySubclassNames()
getPropertyTableNumbers
protected abstract int[] getPropertyTableNumbers()
getPropertyTableNumbersInSelect
protected abstract int[] getPropertyTableNumbersInSelect()
getPropertyUpdateability
public boolean[] getPropertyUpdateability()
Get the "updateability" of the properties of this class
(does the property appear in an SQL UPDATE)
- getPropertyUpdateability in interface EntityPersister
getPropertyUpdateability
protected boolean[] getPropertyUpdateability(Object entity,
EntityMode entityMode)
Which properties appear in the SQL update?
(Initialized, updateable ones!)
getPropertyVersionability
public boolean[] getPropertyVersionability()
Get the "versionability" of the properties of this class
(is the property optimistic-locked)
- getPropertyVersionability in interface EntityPersister
getQuerySpaces
public Serializable[] getQuerySpaces()
Returns an array of objects that identify spaces in which properties of
this entity are persisted, for instances of this class and its subclasses.
Much like
EntityPersister.getPropertySpaces()
, except that here we include subclass
entity spaces.
- getQuerySpaces in interface EntityPersister
getRootEntityName
public String getRootEntityName()
Returns an object that identifies the space in which identifiers of
this entity hierarchy are unique. Might be a table name, a JNDI URL, etc.
- getRootEntityName in interface EntityPersister
getRootTableAlias
public String getRootTableAlias(String drivingAlias)
Get the SQL alias this persister would use for the root table
given the passed driving alias.
- getRootTableAlias in interface Lockable
drivingAlias
- The driving alias; or the alias for the table
mapped by this persister in the hierarchy.
getRootTableIdentifierColumnNames
public String[] getRootTableIdentifierColumnNames()
Get the names of columns on the root table used to persist the identifier.
- getRootTableIdentifierColumnNames in interface Lockable
- The root table identifier column names.
getRootTableName
public String getRootTableName()
Locks are always applied to the "root table".
- getRootTableName in interface Lockable
getSQLDeleteStrings
protected String[] getSQLDeleteStrings()
getSQLIdentityInsertString
protected String getSQLIdentityInsertString()
The query that inserts a row, letting the database generate an id
- The IDENTITY-based insertion query.
getSQLInsertStrings
protected String[] getSQLInsertStrings()
getSQLLazySelectString
protected String getSQLLazySelectString()
getSQLLazyUpdateByRowIdStrings
protected String[] getSQLLazyUpdateByRowIdStrings()
getSQLLazyUpdateStrings
protected String[] getSQLLazyUpdateStrings()
getSQLSnapshotSelectString
protected String getSQLSnapshotSelectString()
getSQLUpdateByRowIdStrings
protected String[] getSQLUpdateByRowIdStrings()
getSQLUpdateStrings
protected String[] getSQLUpdateStrings()
getSQLWhereString
protected String getSQLWhereString(String alias)
getSelectByUniqueKeyString
public String getSelectByUniqueKeyString(String propertyName)
Get a SQL select string that performs a select based on a unique
key determined by the given property name).
- getSelectByUniqueKeyString in interface PostInsertIdentityPersister
propertyName
- The name of the property which maps to the
column(s) to use in the select statement restriction.
getSequentialSelect
protected String getSequentialSelect(String entityName)
getSubclassColumnAliasClosure
protected String[] getSubclassColumnAliasClosure()
getSubclassColumnClosure
protected String[] getSubclassColumnClosure()
getSubclassColumnLazyiness
protected boolean[] getSubclassColumnLazyiness()
getSubclassColumnTableNumberClosure
protected abstract int[] getSubclassColumnTableNumberClosure()
getSubclassFormulaAliasClosure
protected String[] getSubclassFormulaAliasClosure()
getSubclassFormulaClosure
protected String[] getSubclassFormulaClosure()
getSubclassFormulaLazyiness
protected boolean[] getSubclassFormulaLazyiness()
getSubclassFormulaTableNumberClosure
protected abstract int[] getSubclassFormulaTableNumberClosure()
getSubclassFormulaTemplateClosure
protected String[] getSubclassFormulaTemplateClosure()
getSubclassPropertyColumnAliases
public String[] getSubclassPropertyColumnAliases(String propertyName,
String suffix)
Return the column alias names used to persist/query the named property of the class or a subclass (optional operation).
- getSubclassPropertyColumnAliases in interface SQLLoadable
getSubclassPropertyColumnNameClosure
protected String[][] getSubclassPropertyColumnNameClosure()
getSubclassPropertyColumnNames
public String[] getSubclassPropertyColumnNames(String propertyName)
Return the column names used to persist/query the named property of the class or a subclass (optional operation).
- getSubclassPropertyColumnNames in interface SQLLoadable
getSubclassPropertyDeclarer
public Declarer getSubclassPropertyDeclarer(String propertyPath)
Determine whether the given property is declared by our
mapped class, our super class, or one of our subclasses...
Note: the method is called 'subclass property...' simply
for consistency sake (e.g.
Queryable.getSubclassPropertyTableNumber(String)
- getSubclassPropertyDeclarer in interface Queryable
propertyPath
- The property name.
getSubclassPropertyFormulaTemplateClosure
protected String[][] getSubclassPropertyFormulaTemplateClosure()
getSubclassPropertyNameClosure
protected String[] getSubclassPropertyNameClosure()
getSubclassPropertySubclassNameClosure
protected String[] getSubclassPropertySubclassNameClosure()
getSubclassPropertyTableNumber
public int getSubclassPropertyTableNumber(String propertyPath)
Warning:
When there are duplicated property names in the subclasses
of the class, this method may return the wrong table
number for the duplicated subclass property (note that
SingleTableEntityPersister defines an overloaded form
which takes the entity name.
- getSubclassPropertyTableNumber in interface Queryable
getSubclassPropertyTableNumber
protected abstract int getSubclassPropertyTableNumber(int i)
getSubclassPropertyTypeClosure
protected Type[] getSubclassPropertyTypeClosure()
getSubclassTableKeyColumns
protected abstract String[] getSubclassTableKeyColumns(int j)
getSubclassTableName
public abstract String getSubclassTableName(int j)
Get the name of the table with the given index from the internal
array.
- getSubclassTableName in interface Queryable
getSubclassTableSpan
protected abstract int getSubclassTableSpan()
getTableName
protected abstract String getTableName(int j)
getTableSpan
protected abstract int getTableSpan()
getTableUpdateNeeded
protected boolean[] getTableUpdateNeeded(int[] dirtyProperties,
boolean hasDirtyCollection)
Decide which tables need to be updated.
The return here is an array of boolean values with each index corresponding
to a given table in the scope of this persister.
dirtyProperties
- The indices of all the entity properties considered dirty.hasDirtyCollection
- Whether any collections owned by the entity which were considered dirty.
- Array of booleans indicating which table require updating.
getTemporaryIdTableDDL
public String getTemporaryIdTableDDL()
Get the appropriate DDL command for generating the temporary table to
be used to (potentially) store id values when performing bulk update/deletes.
- getTemporaryIdTableDDL in interface Queryable
- The appropriate temporary table creation command.
getTemporaryIdTableName
public String getTemporaryIdTableName()
Get the name of the temporary table to be used to (potentially) store id values
when performing bulk update/deletes.
- getTemporaryIdTableName in interface Queryable
- The appropriate temporary table name.
getVersionColumnName
public String getVersionColumnName()
For versioned entities, get the name of the column (again, expected on the
root table) used to store the version values.
- getVersionColumnName in interface Lockable
getVersionSelectString
protected String getVersionSelectString()
getVersionedTableName
protected String getVersionedTableName()
hasCascades
public boolean hasCascades()
Determine whether this entity has any non-none cascading.
- hasCascades in interface EntityPersister
- True if the entity has any properties with a cscade other than NONE;
false otherwise (aka, no cascading).
hasCollections
public boolean hasCollections()
Determine whether this entity contains references to persistent collections.
- hasCollections in interface EntityPersister
- True if the entity does contain persistent collections; false otherwise.
hasEmbeddedCompositeIdentifier
protected boolean hasEmbeddedCompositeIdentifier()
hasFormulaProperties
protected boolean hasFormulaProperties()
hasInsertGeneratedProperties
public boolean hasInsertGeneratedProperties()
Does this entity define any properties as being database generated on insert?
- hasInsertGeneratedProperties in interface EntityPersister
- True if this entity contains at least one property defined
as generated (including version property, but not identifier).
hasLazyProperties
public boolean hasLazyProperties()
Determine whether this entity defines any lazy properties (ala
bytecode instrumentation).
- hasLazyProperties in interface EntityPersister
- True if the entity has properties mapped as lazy; false otherwise.
hasMutableProperties
public boolean hasMutableProperties()
Determine whether any properties of this entity are considered mutable.
- hasMutableProperties in interface EntityPersister
- True if any properties of the entity are mutable; false otherwise (meaning none are).
hasSequentialSelect
public boolean hasSequentialSelect()
hasSubselectLoadableCollections
public boolean hasSubselectLoadableCollections()
Determine whether this entity contains references to persistent collections
which are fetchable by subselect?
- hasSubselectLoadableCollections in interface EntityPersister
- True if the entity contains collections fetchable by subselect; false otherwise.
hasUpdateGeneratedProperties
public boolean hasUpdateGeneratedProperties()
Does this entity define any properties as being database generated on update?
- hasUpdateGeneratedProperties in interface EntityPersister
- True if this entity contains at least one property defined
as generated (including version property, but not identifier).
hasWhere
protected boolean hasWhere()
hydrate
public Object[] hydrate(ResultSet rs,
Serializable id,
Object object,
Loadable rootLoadable,
String[][] suffixedPropertyColumns,
boolean allProperties,
SessionImplementor session)
throws SQLException,
HibernateException
Unmarshall the fields of a persistent instance from a result set,
without resolving associations or collections. Question: should
this really be here, or should it be sent back to Loader?
- hydrate in interface Loadable
identifierSelectFragment
public String identifierSelectFragment(String name,
String suffix)
Given a query alias and an identifying suffix, render the intentifier select fragment.
- identifierSelectFragment in interface Queryable
initLockers
protected void initLockers()
initSubclassPropertyAliasesMap
protected void initSubclassPropertyAliasesMap(PersistentClass model)
throws MappingException
Must be called by subclasses, at the end of their constructors
insert
protected Serializable insert(Object[] fields,
boolean[] notNull,
String sql,
Object object,
SessionImplementor session)
throws HibernateException
Perform an SQL INSERT, and then retrieve a generated identifier.
This form is used for PostInsertIdentifierGenerator-style ids (IDENTITY,
select, etc).
insert
protected void insert(Serializable id,
Object[] fields,
boolean[] notNull,
int j,
String sql,
Object object,
SessionImplementor session)
throws HibernateException
Perform an SQL INSERT.
This for is used for all non-root tables as well as the root table
in cases where the identifier value is known before the insert occurs.
isBatchable
public boolean isBatchable()
isCacheInvalidationRequired
public boolean isCacheInvalidationRequired()
We can't immediately add to the cache if we have formulas
which must be evaluated, or if we have the possibility of
two concurrent updates to the same item being merged on
the database. This can happen if (a) the item is not
versioned and either (b) we have dynamic update enabled
or (c) we have multiple tables holding the state of the
item.
- isCacheInvalidationRequired in interface EntityPersister
isClassOrSuperclassTable
protected abstract boolean isClassOrSuperclassTable(int j)
isCollection
public boolean isCollection()
Is this instance actually a CollectionPersister?
- isCollection in interface Joinable
isDeleteCallable
protected boolean isDeleteCallable(int j)
isIdentifierAssignedByInsert
public boolean isIdentifierAssignedByInsert()
Are identifiers of this entity assigned known before the insert execution?
Or, are they generated (in the database) by the insert execution.
- isIdentifierAssignedByInsert in interface EntityPersister
- True if identifiers for this entity are generated by the insert
execution.
isInsertCallable
protected boolean isInsertCallable(int j)
isInverseSubclassTable
protected boolean isInverseSubclassTable(int j)
isInverseTable
protected boolean isInverseTable(int j)
isMultiTable
public boolean isMultiTable()
Is the inheritence hierarchy described by this persister contained across
multiple tables?
- isMultiTable in interface Queryable
- True if the inheritence hierarchy is spread across multiple tables; false otherwise.
isNullableSubclassTable
protected boolean isNullableSubclassTable(int j)
isNullableTable
protected boolean isNullableTable(int j)
isPolymorphic
public boolean isPolymorphic()
isPropertyOfTable
protected abstract boolean isPropertyOfTable(int property,
int j)
isSubclassEntityName
public boolean isSubclassEntityName(String entityName)
Determine whether the given name represents a subclass entity
(or this entity itself) of the entity mapped by this persister.
- isSubclassEntityName in interface EntityPersister
entityName
- The entity name to be checked.
- True if the given entity name represents either the entity
mapped by this persister or one of its subclass entities; false
otherwise.
isSubclassPropertyDeferred
protected boolean isSubclassPropertyDeferred(String propertyName,
String entityName)
isSubclassTableLazy
protected boolean isSubclassTableLazy(int j)
isSubclassTableSequentialSelect
protected boolean isSubclassTableSequentialSelect(int j)
isTableCascadeDeleteEnabled
protected abstract boolean isTableCascadeDeleteEnabled(int j)
isUpdateCallable
protected boolean isUpdateCallable(int j)
isVersionPropertyGenerated
public boolean isVersionPropertyGenerated()
Does this entity contain a version property that is defined
to be database generated?
- isVersionPropertyGenerated in interface EntityPersister
- true if this entity contains a version property and that
property has been marked as generated.
logStaticSQL
protected void logStaticSQL()
optimisticLockMode
protected final int optimisticLockMode()
processInsertGeneratedProperties
public void processInsertGeneratedProperties(Serializable id,
Object entity,
Object[] state,
SessionImplementor session)
Perform a select to retrieve the values of any generated properties
back from the database, injecting these generated values into the
given entity as well as writing this state to the
PersistenceContext
.
Note, that because we update the PersistenceContext here, callers
need to take care that they have already written the initial snapshot
to the PersistenceContext before calling this method.
- processInsertGeneratedProperties in interface EntityPersister
id
- The entity's id value.entity
- The entity for which to get the state.state
- session
- The session
processUpdateGeneratedProperties
public void processUpdateGeneratedProperties(Serializable id,
Object entity,
Object[] state,
SessionImplementor session)
Perform a select to retrieve the values of any generated properties
back from the database, injecting these generated values into the
given entity as well as writing this state to the
PersistenceContext
.
Note, that because we update the PersistenceContext here, callers
need to take care that they have already written the initial snapshot
to the PersistenceContext before calling this method.
- processUpdateGeneratedProperties in interface EntityPersister
id
- The entity's id value.entity
- The entity for which to get the state.state
- session
- The session
propertySelectFragment
public String propertySelectFragment(String name,
String suffix,
boolean allProperties)
Given a query alias and an identifying suffix, render the property select fragment.
- propertySelectFragment in interface Queryable
renderSelect
protected String renderSelect(int[] tableNumbers,
int[] columnNumbers,
int[] formulaNumbers)
resetIdentifier
public void resetIdentifier(Object entity,
Serializable currentId,
Object currentVersion,
EntityMode entityMode)
Set the identifier and version of the given instance back
to its "unsaved" value, returning the id
- resetIdentifier in interface EntityPersister
currentId
- TODOcurrentVersion
- TODO
selectFragment
public final String selectFragment(Joinable rhs,
String rhsAlias,
String lhsAlias,
String entitySuffix,
String collectionSuffix,
boolean includeCollectionColumns)
All columns to select, when loading.
- selectFragment in interface Joinable
toColumns
public String[] toColumns(String alias,
String propertyName)
throws QueryException
Given a query alias and a property path, return the qualified
column name
- toColumns in interface PropertyMapping
toString
public String toString()
update
protected boolean update(Serializable id,
Object[] fields,
Object[] oldFields,
Object rowId,
boolean[] includeProperty,
int j,
Object oldVersion,
Object object,
String sql,
SessionImplementor session)
throws HibernateException
updateOrInsert
protected void updateOrInsert(Serializable id,
Object[] fields,
Object[] oldFields,
Object rowId,
boolean[] includeProperty,
int j,
Object oldVersion,
Object object,
String sql,
SessionImplementor session)
throws HibernateException
Perform an SQL UPDATE or SQL INSERT
useDynamicInsert
protected boolean useDynamicInsert()
useDynamicUpdate
protected boolean useDynamicUpdate()
useGetGeneratedKeys
protected boolean useGetGeneratedKeys()
useInsertSelectIdentity
protected boolean useInsertSelectIdentity()
whereJoinFragment
public String whereJoinFragment(String alias,
boolean innerJoin,
boolean includeSubclasses)
Get the where clause part of any joins
(optional operation)
- whereJoinFragment in interface Joinable