| Method from org.hibernate.persister.collection.AbstractCollectionPersister Detail: |
protected void appendElementColumns(SelectFragment frag,
String elemAlias) {
for ( int i=0; i< elementColumnIsSettable.length; i++ ) {
if ( elementColumnIsSettable[i] ) {
frag.addColumn( elemAlias, elementColumnNames[i], elementColumnAliases[i] );
}
else {
frag.addFormula( elemAlias, elementFormulaTemplates[i], elementColumnAliases[i] );
}
}
}
|
protected void appendIdentifierColumns(SelectFragment frag,
String alias) {
if ( hasIdentifier ) {
frag.addColumn( alias, identifierColumnName, identifierColumnAlias );
}
}
|
protected void appendIndexColumns(SelectFragment frag,
String alias) {
if ( hasIndex ) {
for ( int i=0; i< indexColumnIsSettable.length; i++ ) {
if ( indexColumnIsSettable[i] ) {
frag.addColumn( alias, indexColumnNames[i], indexColumnAliases[i] );
}
else {
frag.addFormula( alias, indexFormulaTemplates[i], indexColumnAliases[i] );
}
}
}
}
|
abstract protected CollectionInitializer createCollectionInitializer(Map enabledFilters) throws MappingException
|
abstract protected CollectionInitializer createSubselectInitializer(SubselectFetch subselect,
SessionImplementor session)
|
protected Object decrementIndexByBase(Object index) {
if (baseIndex!=0) {
index = new Integer( ( (Integer) index ).intValue() - baseIndex );
}
return index;
}
|
public void deleteRows(PersistentCollection collection,
Serializable id,
SessionImplementor session) throws HibernateException {
if ( !isInverse && isRowDeleteEnabled() ) {
if ( log.isDebugEnabled() ) {
log.debug(
"Deleting rows of collection: " +
MessageHelper.collectionInfoString( this, id, getFactory() )
);
}
boolean deleteByIndex = !isOneToMany() && hasIndex && !indexContainsFormula;
try {
//delete all the deleted entries
Iterator deletes = collection.getDeletes( this, !deleteByIndex );
if ( deletes.hasNext() ) {
int offset = 1;
int count = 0;
while ( deletes.hasNext() ) {
PreparedStatement st = null;
Expectation expectation = Expectations.appropriateExpectation( getDeleteCheckStyle() );
boolean callable = isDeleteCallable();
boolean useBatch = expectation.canBeBatched();
String sql = getSQLDeleteRowString();
if ( useBatch ) {
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 {
expectation.prepare( st );
Object entry = deletes.next();
int loc = offset;
if ( hasIdentifier ) {
writeIdentifier( st, entry, loc, session );
}
else {
loc = writeKey( st, id, loc, session );
if ( deleteByIndex ) {
writeIndexToWhere( st, entry, loc, session );
}
else {
writeElementToWhere( st, entry, loc, session );
}
}
if ( useBatch ) {
session.getBatcher().addToBatch( expectation );
}
else {
expectation.verifyOutcome( st.executeUpdate(), st, -1 );
}
count++;
}
catch ( SQLException sqle ) {
if ( useBatch ) {
session.getBatcher().abortBatch( sqle );
}
throw sqle;
}
finally {
if ( !useBatch ) {
session.getBatcher().closeStatement( st );
}
}
if ( log.isDebugEnabled() ) {
log.debug( "done deleting collection rows: " + count + " deleted" );
}
}
}
else {
if ( log.isDebugEnabled() ) {
log.debug( "no rows to delete" );
}
}
}
catch ( SQLException sqle ) {
throw JDBCExceptionHelper.convert(
sqlExceptionConverter,
sqle,
"could not delete collection rows: " +
MessageHelper.collectionInfoString( this, id, getFactory() ),
getSQLDeleteRowString()
);
}
}
}
|
abstract protected int doUpdateRows(Serializable key,
PersistentCollection collection,
SessionImplementor session) throws HibernateException
|
public boolean elementExists(Serializable key,
Object element,
SessionImplementor session) {
return exists(key, element, getElementType(), sqlDetectRowByElementString, session);
}
|
protected String filterFragment(String alias) throws MappingException {
return hasWhere() ? " and " + getSQLWhereString( alias ) : "";
}
|
public String filterFragment(String alias,
Map enabledFilters) throws MappingException {
StringBuffer sessionFilterFragment = new StringBuffer();
filterHelper.render( sessionFilterFragment, alias, enabledFilters );
return sessionFilterFragment.append( filterFragment( alias ) ).toString();
}
|
abstract protected String generateDeleteRowString()
|
abstract protected String generateDeleteString()
|
protected String generateDetectRowByElementString() {
return new SimpleSelect(dialect)
.setTableName( getTableName() )
.addCondition( getKeyColumnNames(), "=?" )
.addCondition( getElementColumnNames(), "=?" )
.addCondition( elementFormulas, "=?" )
.addColumn("1")
.toStatementString();
}
|
protected String generateDetectRowByIndexString() {
if ( !hasIndex() ) {
return null;
}
return new SimpleSelect(dialect)
.setTableName( getTableName() )
.addCondition( getKeyColumnNames(), "=?" )
.addCondition( getIndexColumnNames(), "=?" )
.addCondition( indexFormulas, "=?" )
.addColumn("1")
.toStatementString();
}
|
abstract protected String generateInsertRowString()
|
protected SelectFragment generateSelectFragment(String alias,
String columnSuffix) {
return new SelectFragment()
.setSuffix( columnSuffix )
.addColumns( alias, keyColumnNames, keyColumnAliases );
}
|
protected String generateSelectRowByIndexString() {
if ( !hasIndex() ) {
return null;
}
return new SimpleSelect(dialect)
.setTableName( getTableName() )
.addCondition( getKeyColumnNames(), "=?" )
.addCondition( getIndexColumnNames(), "=?" )
.addCondition( indexFormulas, "=?" )
.addColumns( getElementColumnNames(), elementColumnAliases )
.addColumns( indexFormulas, indexColumnAliases )
.toStatementString();
}
|
protected String generateSelectSizeString(boolean isIntegerIndexed) {
String selectValue = isIntegerIndexed ?
"max(" + getIndexColumnNames()[0] + ") + 1": //lists, arrays
"count(" + getElementColumnNames()[0] + ")"; //sets, maps, bags
return new SimpleSelect(dialect)
.setTableName( getTableName() )
.addCondition( getKeyColumnNames(), "=?" )
.addColumn(selectValue)
.toStatementString();
}
|
abstract protected String generateUpdateRowString()
|
protected CollectionInitializer getAppropriateInitializer(Serializable key,
SessionImplementor session) {
if ( queryLoaderName != null ) {
//if there is a user-specified loader, return that
//TODO: filters!?
return initializer;
}
CollectionInitializer subselectInitializer = getSubselectInitializer( key, session );
if ( subselectInitializer != null ) {
return subselectInitializer;
}
else if ( session.getEnabledFilters().isEmpty() ) {
return initializer;
}
else {
return createCollectionInitializer( session.getEnabledFilters() );
}
}
|
public CollectionRegionAccessStrategy getCacheAccessStrategy() {
return cacheAccessStrategy;
}
|
public CacheEntryStructure getCacheEntryStructure() {
return cacheEntryStructure;
}
|
public CollectionMetadata getCollectionMetadata() {
return this;
}
|
public String[] getCollectionPropertyColumnAliases(String propertyName,
String suffix) {
String rawAliases[] = (String[]) collectionPropertyColumnAliases.get(propertyName);
if ( rawAliases == null ) {
return null;
}
String result[] = new String[rawAliases.length];
for ( int i=0; i< rawAliases.length; i++ ) {
result[i] = new Alias(suffix).toUnquotedAliasString( rawAliases[i] );
}
return result;
}
|
public Serializable[] getCollectionSpaces() {
return spaces;
}
|
public CollectionType getCollectionType() {
return collectionType;
}
|
protected ExecuteUpdateResultCheckStyle getDeleteAllCheckStyle() {
return deleteAllCheckStyle;
}
|
protected ExecuteUpdateResultCheckStyle getDeleteCheckStyle() {
return deleteCheckStyle;
}
|
protected Dialect getDialect() {
return dialect;
}
|
public Object getElementByIndex(Serializable key,
Object index,
SessionImplementor session,
Object owner) {
try {
PreparedStatement st = session.getBatcher().prepareSelectStatement(sqlSelectRowByIndexString);
try {
getKeyType().nullSafeSet(st, key, 1, session);
getIndexType().nullSafeSet( st, incrementIndexByBase(index), keyColumnNames.length + 1, session );
ResultSet rs = st.executeQuery();
try {
if ( rs.next() ) {
return getElementType().nullSafeGet(rs, elementColumnAliases, session, owner);
}
else {
return null;
}
}
finally {
rs.close();
}
}
finally {
session.getBatcher().closeStatement( st );
}
}
catch (SQLException sqle) {
throw JDBCExceptionHelper.convert(
getFactory().getSQLExceptionConverter(),
sqle,
"could not read row: " +
MessageHelper.collectionInfoString( this, key, getFactory() ),
sqlSelectSizeString
);
}
}
|
public Class getElementClass() {
//needed by arrays
return elementClass;
}
Return the element class of an array, or null otherwise |
public String[] getElementColumnAliases(String suffix) {
return new Alias( suffix ).toAliasStrings( elementColumnAliases );
}
|
public String[] getElementColumnNames() {
return elementColumnNames; //TODO: something with formulas...
}
|
public String[] getElementColumnNames(String alias) {
return qualify(alias, elementColumnNames, elementFormulaTemplates);
}
|
public String getElementNodeName() {
return elementNodeName;
}
|
public EntityPersister getElementPersister() {
if ( elementPersister == null ) {
throw new AssertionFailure( "not an association" );
}
return ( Loadable ) elementPersister;
}
|
public Type getElementType() {
return elementType;
}
|
public SessionFactoryImplementor getFactory() {
return factory;
}
|
public FetchMode getFetchMode() {
return fetchMode;
}
|
public String getIdentifierColumnAlias(String suffix) {
if ( hasIdentifier ) {
return new Alias( suffix ).toAliasString( identifierColumnAlias );
}
else {
return null;
}
}
|
public String getIdentifierColumnName() {
if ( hasIdentifier ) {
return identifierColumnName;
} else {
return null;
}
}
|
public IdentifierGenerator getIdentifierGenerator() {
return identifierGenerator;
}
|
public Type getIdentifierType() {
return identifierType;
}
|
public String[] getIndexColumnAliases(String suffix) {
if ( hasIndex ) {
return new Alias( suffix ).toAliasStrings( indexColumnAliases );
}
else {
return null;
}
}
|
public String[] getIndexColumnNames() {
return indexColumnNames;
}
|
public String[] getIndexColumnNames(String alias) {
return qualify(alias, indexColumnNames, indexFormulaTemplates);
}
|
public String[] getIndexFormulas() {
return indexFormulas;
}
|
public String getIndexNodeName() {
return indexNodeName;
}
|
public Type getIndexType() {
return indexType;
}
|
protected ExecuteUpdateResultCheckStyle getInsertCheckStyle() {
return insertCheckStyle;
}
|
public String[] getKeyColumnAliases(String suffix) {
return new Alias( suffix ).toAliasStrings( keyColumnAliases );
}
|
public String[] getKeyColumnNames() {
return keyColumnNames;
}
|
public Type getKeyType() {
return keyType;
}
|
public String getManyToManyFilterFragment(String alias,
Map enabledFilters) {
StringBuffer buffer = new StringBuffer();
manyToManyFilterHelper.render( buffer, alias, enabledFilters );
if ( manyToManyWhereString != null ) {
buffer.append( " and " )
.append( StringHelper.replace( manyToManyWhereTemplate, Template.TEMPLATE, alias ) );
}
return buffer.toString();
}
|
public String getManyToManyOrderByString(String alias) {
if ( isManyToMany() && manyToManyOrderByString != null ) {
return StringHelper.replace( manyToManyOrderByTemplate, Template.TEMPLATE, alias );
}
else {
return "";
}
}
|
public String getName() {
return getRole();
}
|
public String getNodeName() {
return nodeName;
}
|
public String getOwnerEntityName() {
return entityName;
}
|
public EntityPersister getOwnerEntityPersister() {
return ownerPersister;
}
|
public String getRole() {
return role;
}
|
protected String getSQLDeleteRowString() {
return sqlDeleteRowString;
}
|
protected String getSQLDeleteString() {
return sqlDeleteString;
}
|
protected SQLExceptionConverter getSQLExceptionConverter() {
return sqlExceptionConverter;
}
|
protected String getSQLInsertRowString() {
return sqlInsertRowString;
}
|
public String getSQLOrderByString(String alias) {
return hasOrdering() ?
StringHelper.replace( sqlOrderByStringTemplate, Template.TEMPLATE, alias ) : "";
}
|
protected String getSQLUpdateRowString() {
return sqlUpdateRowString;
}
|
protected String getSQLWhereString(String alias) {
return StringHelper.replace( sqlWhereStringTemplate, Template.TEMPLATE, alias );
}
|
public int getSize(Serializable key,
SessionImplementor session) {
try {
PreparedStatement st = session.getBatcher().prepareSelectStatement(sqlSelectSizeString);
try {
getKeyType().nullSafeSet(st, key, 1, session);
ResultSet rs = st.executeQuery();
try {
return rs.next() ? rs.getInt(1) - baseIndex : 0;
}
finally {
rs.close();
}
}
finally {
session.getBatcher().closeStatement( st );
}
}
catch (SQLException sqle) {
throw JDBCExceptionHelper.convert(
getFactory().getSQLExceptionConverter(),
sqle,
"could not retrieve collection size: " +
MessageHelper.collectionInfoString( this, key, getFactory() ),
sqlSelectSizeString
);
}
}
|
public String getTableName() {
return qualifiedTableName;
}
|
public Type getType() {
return elementPropertyMapping.getType(); //==elementType ??
}
|
protected ExecuteUpdateResultCheckStyle getUpdateCheckStyle() {
return updateCheckStyle;
}
|
public boolean hasCache() {
return cacheAccessStrategy != null;
}
|
public boolean hasIndex() {
return hasIndex;
}
|
public boolean hasManyToManyOrdering() {
return isManyToMany() && manyToManyOrderByTemplate != null;
}
|
public boolean hasOrdering() {
return hasOrder;
}
|
public boolean hasOrphanDelete() {
return hasOrphanDelete;
}
|
public boolean hasWhere() {
return hasWhere;
}
|
protected Object incrementIndexByBase(Object index) {
if (baseIndex!=0) {
index = new Integer( ( (Integer) index ).intValue() + baseIndex );
}
return index;
}
|
public boolean indexExists(Serializable key,
Object index,
SessionImplementor session) {
return exists(key, incrementIndexByBase(index), getIndexType(), sqlDetectRowByIndexString, session);
}
|
public void initCollectionPropertyMap() {
initCollectionPropertyMap( "key", keyType, keyColumnAliases, keyColumnNames );
initCollectionPropertyMap( "element", elementType, elementColumnAliases, elementColumnNames );
if (hasIndex) {
initCollectionPropertyMap( "index", indexType, indexColumnAliases, indexColumnNames );
}
if (hasIdentifier) {
initCollectionPropertyMap(
"id",
identifierType,
new String[] { identifierColumnAlias },
new String[] { identifierColumnName }
);
}
}
|
public void initialize(Serializable key,
SessionImplementor session) throws HibernateException {
getAppropriateInitializer( key, session ).initialize( key, session );
}
|
public void insertRows(PersistentCollection collection,
Serializable id,
SessionImplementor session) throws HibernateException {
if ( !isInverse && isRowInsertEnabled() ) {
if ( log.isDebugEnabled() ) {
log.debug(
"Inserting rows of collection: " +
MessageHelper.collectionInfoString( this, id, getFactory() )
);
}
try {
//insert all the new entries
collection.preInsert( this );
Iterator entries = collection.entries( this );
Expectation expectation = Expectations.appropriateExpectation( getInsertCheckStyle() );
boolean callable = isInsertCallable();
boolean useBatch = expectation.canBeBatched();
String sql = getSQLInsertRowString();
int i = 0;
int count = 0;
while ( entries.hasNext() ) {
int offset = 1;
Object entry = entries.next();
PreparedStatement st = null;
if ( collection.needsInserting( entry, i, elementType ) ) {
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 );
//TODO: copy/paste from recreate()
offset = writeKey( st, id, offset, session );
if ( hasIdentifier ) {
offset = writeIdentifier( st, collection.getIdentifier(entry, i), offset, session );
}
if ( hasIndex /*&& !indexIsFormula*/ ) {
offset = writeIndex( st, collection.getIndex(entry, i, this), offset, session );
}
writeElement(st, collection.getElement(entry), offset, session );
if ( useBatch ) {
session.getBatcher().addToBatch( expectation );
}
else {
expectation.verifyOutcome( st.executeUpdate(), st, -1 );
}
collection.afterRowInsert( this, entry, i );
count++;
}
catch ( SQLException sqle ) {
if ( useBatch ) {
session.getBatcher().abortBatch( sqle );
}
throw sqle;
}
finally {
if ( !useBatch ) {
session.getBatcher().closeStatement( st );
}
}
}
i++;
}
if ( log.isDebugEnabled() ) {
log.debug( "done inserting rows: " + count + " inserted" );
}
}
catch ( SQLException sqle ) {
throw JDBCExceptionHelper.convert(
sqlExceptionConverter,
sqle,
"could not insert collection rows: " +
MessageHelper.collectionInfoString( this, id, getFactory() ),
getSQLInsertRowString()
);
}
}
}
|
public boolean isAffectedByEnabledFilters(SessionImplementor session) {
return filterHelper.isAffectedBy( session.getEnabledFilters() ) ||
( isManyToMany() && manyToManyFilterHelper.isAffectedBy( session.getEnabledFilters() ) );
}
|
public boolean isArray() {
return isArray;
}
|
public boolean isCollection() {
return true;
}
|
protected boolean isDeleteAllCallable() {
return deleteAllCallable;
}
|
protected boolean isDeleteCallable() {
return deleteCallable;
}
|
public boolean isExtraLazy() {
return isExtraLazy;
}
|
protected boolean isInsertCallable() {
return insertCallable;
}
|
public boolean isInverse() {
return isInverse;
}
|
public boolean isLazy() {
return isLazy;
}
|
abstract public boolean isManyToMany()
|
public boolean isMutable() {
return isMutable;
}
|
public boolean isPrimitiveArray() {
return isPrimitiveArray;
}
|
protected boolean isRowDeleteEnabled() {
return true;
}
|
protected boolean isRowInsertEnabled() {
return true;
}
|
public boolean isSubselectLoadable() {
return subselectLoadable;
}
|
protected boolean isUpdateCallable() {
return updateCallable;
}
|
public boolean isVersioned() {
return isVersioned && getOwnerEntityPersister().isVersioned();
}
|
protected void logStaticSQL() {
if ( log.isDebugEnabled() ) {
log.debug( "Static SQL for collection: " + getRole() );
if ( getSQLInsertRowString() != null ) {
log.debug( " Row insert: " + getSQLInsertRowString() );
}
if ( getSQLUpdateRowString() != null ) {
log.debug( " Row update: " + getSQLUpdateRowString() );
}
if ( getSQLDeleteRowString() != null ) {
log.debug( " Row delete: " + getSQLDeleteRowString() );
}
if ( getSQLDeleteString() != null ) {
log.debug( " One-shot delete: " + getSQLDeleteString() );
}
}
}
|
public String oneToManyFilterFragment(String alias) throws MappingException {
return "";
}
|
public void postInstantiate() throws MappingException {
initializer = queryLoaderName == null ?
createCollectionInitializer( CollectionHelper.EMPTY_MAP ) :
new NamedQueryCollectionInitializer( queryLoaderName, this );
}
|
public Object readElement(ResultSet rs,
Object owner,
String[] aliases,
SessionImplementor session) throws HibernateException, SQLException {
return getElementType().nullSafeGet( rs, aliases, session, owner );
}
|
public Object readIdentifier(ResultSet rs,
String alias,
SessionImplementor session) throws HibernateException, SQLException {
Object id = getIdentifierType().nullSafeGet( rs, alias, session, null );
if ( id == null ) {
throw new HibernateException( "null identifier column for collection: " + role );
}
return id;
}
|
public Object readIndex(ResultSet rs,
String[] aliases,
SessionImplementor session) throws HibernateException, SQLException {
Object index = getIndexType().nullSafeGet( rs, aliases, session, null );
if ( index == null ) {
throw new HibernateException( "null index column for collection: " + role );
}
index = decrementIndexByBase( index );
return index;
}
|
public Object readKey(ResultSet rs,
String[] aliases,
SessionImplementor session) throws HibernateException, SQLException {
return getKeyType().nullSafeGet( rs, aliases, session, null );
}
|
public void recreate(PersistentCollection collection,
Serializable id,
SessionImplementor session) throws HibernateException {
if ( !isInverse && isRowInsertEnabled() ) {
if ( log.isDebugEnabled() ) {
log.debug(
"Inserting collection: " +
MessageHelper.collectionInfoString( this, id, getFactory() )
);
}
try {
//create all the new entries
Iterator entries = collection.entries(this);
if ( entries.hasNext() ) {
collection.preInsert( this );
int i = 0;
int count = 0;
while ( entries.hasNext() ) {
final Object entry = entries.next();
if ( collection.entryExists( entry, i ) ) {
int offset = 1;
PreparedStatement st = null;
Expectation expectation = Expectations.appropriateExpectation( getInsertCheckStyle() );
boolean callable = isInsertCallable();
boolean useBatch = expectation.canBeBatched();
String sql = getSQLInsertRowString();
if ( useBatch ) {
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 );
//TODO: copy/paste from insertRows()
int loc = writeKey( st, id, offset, session );
if ( hasIdentifier ) {
loc = writeIdentifier( st, collection.getIdentifier(entry, i), loc, session );
}
if ( hasIndex /*&& !indexIsFormula*/ ) {
loc = writeIndex( st, collection.getIndex(entry, i, this), loc, session );
}
loc = writeElement(st, collection.getElement(entry), loc, session );
if ( useBatch ) {
session.getBatcher().addToBatch( expectation );
}
else {
expectation.verifyOutcome( st.executeUpdate(), st, -1 );
}
collection.afterRowInsert( this, entry, i );
count++;
}
catch ( SQLException sqle ) {
if ( useBatch ) {
session.getBatcher().abortBatch( sqle );
}
throw sqle;
}
finally {
if ( !useBatch ) {
session.getBatcher().closeStatement( st );
}
}
}
i++;
}
if ( log.isDebugEnabled() ) {
log.debug( "done inserting collection: " + count + " rows inserted" );
}
}
else {
if ( log.isDebugEnabled() ) {
log.debug( "collection was empty" );
}
}
}
catch ( SQLException sqle ) {
throw JDBCExceptionHelper.convert(
sqlExceptionConverter,
sqle,
"could not insert collection: " +
MessageHelper.collectionInfoString( this, id, getFactory() ),
getSQLInsertRowString()
);
}
}
}
|
public void remove(Serializable id,
SessionImplementor session) throws HibernateException {
if ( !isInverse && isRowDeleteEnabled() ) {
if ( log.isDebugEnabled() ) {
log.debug(
"Deleting collection: " +
MessageHelper.collectionInfoString( this, id, getFactory() )
);
}
// Remove all the old entries
try {
int offset = 1;
PreparedStatement st = null;
Expectation expectation = Expectations.appropriateExpectation( getDeleteAllCheckStyle() );
boolean callable = isDeleteAllCallable();
boolean useBatch = expectation.canBeBatched();
String sql = getSQLDeleteString();
if ( useBatch ) {
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 );
writeKey( st, id, offset, 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 );
}
}
if ( log.isDebugEnabled() ) {
log.debug( "done deleting collection" );
}
}
catch ( SQLException sqle ) {
throw JDBCExceptionHelper.convert(
sqlExceptionConverter,
sqle,
"could not delete collection: " +
MessageHelper.collectionInfoString( this, id, getFactory() ),
getSQLDeleteString()
);
}
}
}
|
public String selectFragment(String alias,
String columnSuffix) {
SelectFragment frag = generateSelectFragment( alias, columnSuffix );
appendElementColumns( frag, alias );
appendIndexColumns( frag, alias );
appendIdentifierColumns( frag, alias );
return frag.toFragmentString()
.substring( 2 ); //strip leading ','
}
Generate a list of collection index, key and element columns |
public String[] toColumns(String propertyName) throws QueryException {
if ( "index".equals( propertyName ) ) {
if ( isManyToMany() ) {
throw new QueryException( "index() function not supported for many-to-many association" );
}
return indexColumnNames;
}
return elementPropertyMapping.toColumns( propertyName );
}
|
public String[] toColumns(String alias,
String propertyName) throws QueryException {
if ( "index".equals( propertyName ) ) {
if ( isManyToMany() ) {
throw new QueryException( "index() function not supported for many-to-many association" );
}
return StringHelper.qualify( alias, indexColumnNames );
}
return elementPropertyMapping.toColumns( alias, propertyName );
}
|
public String toString() {
return StringHelper.unqualify( getClass().getName() ) + '(' + role + ')';
}
|
public Type toType(String propertyName) throws QueryException {
if ( "index".equals( propertyName ) ) {
return indexType;
}
return elementPropertyMapping.toType( propertyName );
}
|
public void updateRows(PersistentCollection collection,
Serializable id,
SessionImplementor session) throws HibernateException {
if ( !isInverse && collection.isRowUpdatePossible() ) {
if ( log.isDebugEnabled() ) {
log.debug( "Updating rows of collection: " + role + "#" + id );
}
//update all the modified entries
int count = doUpdateRows( id, collection, session );
if ( log.isDebugEnabled() ) {
log.debug( "done updating rows: " + count + " updated" );
}
}
}
|
protected int writeElement(PreparedStatement st,
Object elt,
int i,
SessionImplementor session) throws HibernateException, SQLException {
getElementType().nullSafeSet(st, elt, i, elementColumnIsSettable, session);
return i + ArrayHelper.countTrue(elementColumnIsSettable);
}
Write the element to a JDBC PreparedStatement |
protected int writeElementToWhere(PreparedStatement st,
Object elt,
int i,
SessionImplementor session) throws HibernateException, SQLException {
if (elementIsPureFormula) {
throw new AssertionFailure("cannot use a formula-based element in the where condition");
}
getElementType().nullSafeSet(st, elt, i, elementColumnIsInPrimaryKey, session);
return i + elementColumnAliases.length;
}
Write the element to a JDBC PreparedStatement |
public int writeIdentifier(PreparedStatement st,
Object id,
int i,
SessionImplementor session) throws HibernateException, SQLException {
getIdentifierType().nullSafeSet( st, id, i, session );
return i + 1;
}
Write the identifier to a JDBC PreparedStatement |
protected int writeIndex(PreparedStatement st,
Object index,
int i,
SessionImplementor session) throws HibernateException, SQLException {
getIndexType().nullSafeSet( st, incrementIndexByBase(index), i, indexColumnIsSettable, session );
return i + ArrayHelper.countTrue(indexColumnIsSettable);
}
Write the index to a JDBC PreparedStatement |
protected int writeIndexToWhere(PreparedStatement st,
Object index,
int i,
SessionImplementor session) throws HibernateException, SQLException {
if (indexContainsFormula) {
throw new AssertionFailure("cannot use a formula-based index in the where condition");
}
getIndexType().nullSafeSet( st, incrementIndexByBase(index), i, session );
return i + indexColumnAliases.length;
}
Write the index to a JDBC PreparedStatement |
protected int writeKey(PreparedStatement st,
Serializable key,
int i,
SessionImplementor session) throws HibernateException, SQLException {
if ( key == null ) {
throw new NullPointerException( "null key for collection: " + role ); //an assertion
}
getKeyType().nullSafeSet( st, key, i, session );
return i + keyColumnAliases.length;
}
Write the key to a JDBC PreparedStatement |