BasicCollectionPersisterpublic class BasicCollectionPersister extends AbstractCollectionPersister Collection persister for collections of values and many-to-many associations. |
Methods Summary |
---|
public boolean | consumesCollectionAlias()
// return !isOneToMany();
return true;
| public boolean | consumesEntityAlias()
return false;
| protected org.hibernate.loader.collection.CollectionInitializer | createCollectionInitializer(java.util.Map enabledFilters)Create the CollectionLoader
return BatchingCollectionInitializer.createBatchingCollectionInitializer( this, batchSize, getFactory(), enabledFilters );
| protected org.hibernate.loader.collection.CollectionInitializer | createSubselectInitializer(org.hibernate.engine.SubselectFetch subselect, org.hibernate.engine.SessionImplementor session)
return new SubselectCollectionLoader(
this,
subselect.toSubselectString( getCollectionType().getLHSPropertyName() ),
subselect.getResult(),
subselect.getQueryParameters(),
subselect.getNamedParameterLocMap(),
session.getFactory(),
session.getEnabledFilters()
);
| protected int | doUpdateRows(java.io.Serializable id, org.hibernate.collection.PersistentCollection collection, org.hibernate.engine.SessionImplementor session)
if ( ArrayHelper.isAllFalse(elementColumnIsSettable) ) return 0;
try {
PreparedStatement st = null;
Expectation expectation = Expectations.appropriateExpectation( getUpdateCheckStyle() );
boolean callable = isUpdateCallable();
boolean useBatch = expectation.canBeBatched();
Iterator entries = collection.entries( this );
String sql = getSQLUpdateRowString();
int i = 0;
int count = 0;
while ( entries.hasNext() ) {
Object entry = entries.next();
if ( collection.needsUpdating( entry, i, elementType ) ) {
int offset = 1;
if ( useBatch ) {
if ( st == null ) {
if ( callable ) {
st = session.getBatcher().prepareBatchCallableStatement( sql );
}
else {
st = session.getBatcher().prepareBatchStatement( sql );
}
}
}
else {
if ( callable ) {
st = session.getBatcher().prepareCallableStatement( sql );
}
else {
st = session.getBatcher().prepareStatement( sql );
}
}
try {
offset+= expectation.prepare( st );
int loc = writeElement( st, collection.getElement( entry ), offset, session );
if ( hasIdentifier ) {
writeIdentifier( st, collection.getIdentifier( entry, i ), loc, session );
}
else {
loc = writeKey( st, id, loc, session );
if ( hasIndex && !indexContainsFormula ) {
writeIndexToWhere( st, collection.getIndex( entry, i, this ), loc, session );
}
else {
writeElementToWhere( st, collection.getSnapshotElement( entry, i ), loc, session );
}
}
if ( useBatch ) {
session.getBatcher().addToBatch( expectation );
}
else {
expectation.verifyOutcome( st.executeUpdate(), st, -1 );
}
}
catch ( SQLException sqle ) {
if ( useBatch ) {
session.getBatcher().abortBatch( sqle );
}
throw sqle;
}
finally {
if ( !useBatch ) {
session.getBatcher().closeStatement( st );
}
}
count++;
}
i++;
}
return count;
}
catch ( SQLException sqle ) {
throw JDBCExceptionHelper.convert(
getSQLExceptionConverter(),
sqle,
"could not update collection rows: " + MessageHelper.collectionInfoString( this, id, getFactory() ),
getSQLUpdateRowString()
);
}
| public java.lang.String | fromJoinFragment(java.lang.String alias, boolean innerJoin, boolean includeSubclasses)
return "";
| protected java.lang.String | generateDeleteRowString()Generate the SQL DELETE that deletes a particular row
Delete delete = new Delete()
.setTableName( qualifiedTableName );
if ( hasIdentifier ) {
delete.setPrimaryKeyColumnNames( new String[]{ identifierColumnName } );
}
else if ( hasIndex && !indexContainsFormula ) {
delete.setPrimaryKeyColumnNames( ArrayHelper.join( keyColumnNames, indexColumnNames ) );
}
else {
delete.setPrimaryKeyColumnNames( ArrayHelper.join( keyColumnNames, elementColumnNames, elementColumnIsInPrimaryKey ) );
}
if ( getFactory().getSettings().isCommentsEnabled() ) {
delete.setComment( "delete collection row " + getRole() );
}
return delete.toStatementString();
| protected java.lang.String | generateDeleteString()Generate the SQL DELETE that deletes all rows
Delete delete = new Delete()
.setTableName( qualifiedTableName )
.setPrimaryKeyColumnNames( keyColumnNames );
if ( hasWhere ) delete.setWhere( sqlWhereString );
if ( getFactory().getSettings().isCommentsEnabled() ) {
delete.setComment( "delete collection " + getRole() );
}
return delete.toStatementString();
| protected java.lang.String | generateInsertRowString()Generate the SQL INSERT that creates a new row
Insert insert = new Insert( getDialect() )
.setTableName( qualifiedTableName )
.addColumns( keyColumnNames );
if ( hasIdentifier) insert.addColumn( identifierColumnName );
if ( hasIndex /*&& !indexIsFormula*/ ) {
insert.addColumns( indexColumnNames, indexColumnIsSettable );
}
if ( getFactory().getSettings().isCommentsEnabled() ) {
insert.setComment( "insert collection row " + getRole() );
}
//if ( !elementIsFormula ) {
insert.addColumns( elementColumnNames, elementColumnIsSettable );
//}
return insert.toStatementString();
| protected java.lang.String | generateUpdateRowString()Generate the SQL UPDATE that updates a row
Update update = new Update( getDialect() )
.setTableName( qualifiedTableName );
//if ( !elementIsFormula ) {
update.addColumns( elementColumnNames, elementColumnIsSettable );
//}
if ( hasIdentifier ) {
update.setPrimaryKeyColumnNames( new String[]{ identifierColumnName } );
}
else if ( hasIndex && !indexContainsFormula ) {
update.setPrimaryKeyColumnNames( ArrayHelper.join( keyColumnNames, indexColumnNames ) );
}
else {
update.setPrimaryKeyColumnNames( ArrayHelper.join( keyColumnNames, elementColumnNames, elementColumnIsInPrimaryKey ) );
}
if ( getFactory().getSettings().isCommentsEnabled() ) {
update.setComment( "update collection row " + getRole() );
}
return update.toStatementString();
| public boolean | isCascadeDeleteEnabled()
return false;
| public boolean | isManyToMany()
return elementType.isEntityType(); //instanceof AssociationType;
| public boolean | isOneToMany()
return false;
| private java.lang.String | manyToManySelectFragment(org.hibernate.persister.entity.Joinable rhs, java.lang.String rhsAlias, java.lang.String lhsAlias, java.lang.String collectionSuffix)
SelectFragment frag = generateSelectFragment( lhsAlias, collectionSuffix );
String[] elementColumnNames = rhs.getKeyColumnNames();
frag.addColumns( rhsAlias, elementColumnNames, elementColumnAliases );
appendIndexColumns( frag, lhsAlias );
appendIdentifierColumns( frag, lhsAlias );
return frag.toFragmentString()
.substring( 2 ); //strip leading ','
| public java.lang.String | selectFragment(org.hibernate.persister.entity.Joinable rhs, java.lang.String rhsAlias, java.lang.String lhsAlias, java.lang.String entitySuffix, java.lang.String collectionSuffix, boolean includeCollectionColumns)
// we need to determine the best way to know that two joinables
// represent a single many-to-many...
if ( rhs != null && isManyToMany() && !rhs.isCollection() ) {
AssociationType elementType = ( ( AssociationType ) getElementType() );
if ( rhs.equals( elementType.getAssociatedJoinable( getFactory() ) ) ) {
return manyToManySelectFragment( rhs, rhsAlias, lhsAlias, collectionSuffix );
}
}
return includeCollectionColumns ? selectFragment( lhsAlias, collectionSuffix ) : "";
| public java.lang.String | whereJoinFragment(java.lang.String alias, boolean innerJoin, boolean includeSubclasses)
return "";
|
|