Methods Summary |
---|
protected void | appendElementColumns(org.hibernate.sql.SelectFragment frag, java.lang.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(org.hibernate.sql.SelectFragment frag, java.lang.String alias)
if ( hasIdentifier ) {
frag.addColumn( alias, identifierColumnName, identifierColumnAlias );
}
|
protected void | appendIndexColumns(org.hibernate.sql.SelectFragment frag, java.lang.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] );
}
}
}
|
protected abstract org.hibernate.loader.collection.CollectionInitializer | createCollectionInitializer(java.util.Map enabledFilters)
|
protected abstract org.hibernate.loader.collection.CollectionInitializer | createSubselectInitializer(org.hibernate.engine.SubselectFetch subselect, org.hibernate.engine.SessionImplementor session)
|
protected java.lang.Object | decrementIndexByBase(java.lang.Object index)
if (baseIndex!=0) {
index = new Integer( ( (Integer) index ).intValue() - baseIndex );
}
return index;
|
public void | deleteRows(org.hibernate.collection.PersistentCollection collection, java.io.Serializable id, org.hibernate.engine.SessionImplementor session)
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()
);
}
}
|
protected abstract int | doUpdateRows(java.io.Serializable key, org.hibernate.collection.PersistentCollection collection, org.hibernate.engine.SessionImplementor session)
|
public boolean | elementExists(java.io.Serializable key, java.lang.Object element, org.hibernate.engine.SessionImplementor session)
return exists(key, element, getElementType(), sqlDetectRowByElementString, session);
|
private boolean | exists(java.io.Serializable key, java.lang.Object indexOrElement, org.hibernate.type.Type indexOrElementType, java.lang.String sql, org.hibernate.engine.SessionImplementor session)
try {
PreparedStatement st = session.getBatcher().prepareSelectStatement(sql);
try {
getKeyType().nullSafeSet(st, key, 1, session);
indexOrElementType.nullSafeSet( st, indexOrElement, keyColumnNames.length + 1, session );
ResultSet rs = st.executeQuery();
try {
return rs.next();
}
finally {
rs.close();
}
}
catch( TransientObjectException e ) {
return false;
}
finally {
session.getBatcher().closeStatement( st );
}
}
catch (SQLException sqle) {
throw JDBCExceptionHelper.convert(
getFactory().getSQLExceptionConverter(),
sqle,
"could not check row existence: " +
MessageHelper.collectionInfoString( this, key, getFactory() ),
sqlSelectSizeString
);
}
|
protected java.lang.String | filterFragment(java.lang.String alias)
return hasWhere() ? " and " + getSQLWhereString( alias ) : "";
|
public java.lang.String | filterFragment(java.lang.String alias, java.util.Map enabledFilters)
StringBuffer sessionFilterFragment = new StringBuffer();
filterHelper.render( sessionFilterFragment, alias, enabledFilters );
return sessionFilterFragment.append( filterFragment( alias ) ).toString();
|
protected abstract java.lang.String | generateDeleteRowString()
|
protected abstract java.lang.String | generateDeleteString()
|
protected java.lang.String | generateDetectRowByElementString()
return new SimpleSelect(dialect)
.setTableName( getTableName() )
.addCondition( getKeyColumnNames(), "=?" )
.addCondition( getElementColumnNames(), "=?" )
.addCondition( elementFormulas, "=?" )
.addColumn("1")
.toStatementString();
|
protected java.lang.String | generateDetectRowByIndexString()
if ( !hasIndex() ) {
return null;
}
return new SimpleSelect(dialect)
.setTableName( getTableName() )
.addCondition( getKeyColumnNames(), "=?" )
.addCondition( getIndexColumnNames(), "=?" )
.addCondition( indexFormulas, "=?" )
.addColumn("1")
.toStatementString();
|
protected abstract java.lang.String | generateInsertRowString()
|
protected org.hibernate.sql.SelectFragment | generateSelectFragment(java.lang.String alias, java.lang.String columnSuffix)
return new SelectFragment()
.setSuffix( columnSuffix )
.addColumns( alias, keyColumnNames, keyColumnAliases );
|
protected java.lang.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 java.lang.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();
|
protected abstract java.lang.String | generateUpdateRowString()
|
protected org.hibernate.loader.collection.CollectionInitializer | getAppropriateInitializer(java.io.Serializable key, org.hibernate.engine.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 org.hibernate.cache.CacheConcurrencyStrategy | getCache()
return cache;
|
public org.hibernate.cache.entry.CacheEntryStructure | getCacheEntryStructure()
return cacheEntryStructure;
|
public org.hibernate.metadata.CollectionMetadata | getCollectionMetadata()
return this;
|
public java.lang.String[] | getCollectionPropertyColumnAliases(java.lang.String propertyName, java.lang.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 java.io.Serializable[] | getCollectionSpaces()
return spaces;
|
public org.hibernate.type.CollectionType | getCollectionType()
return collectionType;
|
protected org.hibernate.engine.ExecuteUpdateResultCheckStyle | getDeleteAllCheckStyle()
return deleteAllCheckStyle;
|
protected org.hibernate.engine.ExecuteUpdateResultCheckStyle | getDeleteCheckStyle()
return deleteCheckStyle;
|
protected org.hibernate.dialect.Dialect | getDialect()
return dialect;
|
public java.lang.Object | getElementByIndex(java.io.Serializable key, java.lang.Object index, org.hibernate.engine.SessionImplementor session, java.lang.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 java.lang.Class | getElementClass()Return the element class of an array, or null otherwise //needed by arrays
return elementClass;
|
public java.lang.String[] | getElementColumnAliases(java.lang.String suffix)
return new Alias( suffix ).toAliasStrings( elementColumnAliases );
|
public java.lang.String[] | getElementColumnNames(java.lang.String alias)
return qualify(alias, elementColumnNames, elementFormulaTemplates);
|
public java.lang.String[] | getElementColumnNames()
return elementColumnNames; //TODO: something with formulas...
|
public java.lang.String | getElementNodeName()
return elementNodeName;
|
public org.hibernate.persister.entity.EntityPersister | getElementPersister()
if ( elementPersister == null ) {
throw new AssertionFailure( "not an association" );
}
return ( Loadable ) elementPersister;
|
public org.hibernate.type.Type | getElementType()
return elementType;
|
public org.hibernate.engine.SessionFactoryImplementor | getFactory()
return factory;
|
public org.hibernate.FetchMode | getFetchMode()
return fetchMode;
|
public java.lang.String | getIdentifierColumnAlias(java.lang.String suffix)
if ( hasIdentifier ) {
return new Alias( suffix ).toAliasString( identifierColumnAlias );
}
else {
return null;
}
|
public java.lang.String | getIdentifierColumnName()
if ( hasIdentifier ) {
return identifierColumnName;
} else {
return null;
}
|
public org.hibernate.id.IdentifierGenerator | getIdentifierGenerator()
return identifierGenerator;
|
public org.hibernate.type.Type | getIdentifierType()
return identifierType;
|
public java.lang.String[] | getIndexColumnAliases(java.lang.String suffix)
if ( hasIndex ) {
return new Alias( suffix ).toAliasStrings( indexColumnAliases );
}
else {
return null;
}
|
public java.lang.String[] | getIndexColumnNames()
return indexColumnNames;
|
public java.lang.String[] | getIndexColumnNames(java.lang.String alias)
return qualify(alias, indexColumnNames, indexFormulaTemplates);
|
public java.lang.String[] | getIndexFormulas()
return indexFormulas;
|
public java.lang.String | getIndexNodeName()
return indexNodeName;
|
public org.hibernate.type.Type | getIndexType()
return indexType;
|
protected org.hibernate.engine.ExecuteUpdateResultCheckStyle | getInsertCheckStyle()
return insertCheckStyle;
|
public java.lang.String[] | getKeyColumnAliases(java.lang.String suffix)
return new Alias( suffix ).toAliasStrings( keyColumnAliases );
|
public java.lang.String[] | getKeyColumnNames()
return keyColumnNames;
|
public org.hibernate.type.Type | getKeyType()
return keyType;
|
public java.lang.String | getManyToManyFilterFragment(java.lang.String alias, java.util.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 java.lang.String | getManyToManyOrderByString(java.lang.String alias)
if ( isManyToMany() && manyToManyOrderByString != null ) {
return StringHelper.replace( manyToManyOrderByTemplate, Template.TEMPLATE, alias );
}
else {
return "";
}
|
public java.lang.String | getName()
return getRole();
|
public java.lang.String | getNodeName()
return nodeName;
|
public java.lang.String | getOwnerEntityName()
return entityName;
|
public org.hibernate.persister.entity.EntityPersister | getOwnerEntityPersister()
return ownerPersister;
|
public java.lang.String | getRole()
return role;
|
protected java.lang.String | getSQLDeleteRowString()
return sqlDeleteRowString;
|
protected java.lang.String | getSQLDeleteString()
return sqlDeleteString;
|
protected org.hibernate.exception.SQLExceptionConverter | getSQLExceptionConverter()
return sqlExceptionConverter;
|
protected java.lang.String | getSQLInsertRowString()
return sqlInsertRowString;
|
public java.lang.String | getSQLOrderByString(java.lang.String alias)
return hasOrdering() ?
StringHelper.replace( sqlOrderByStringTemplate, Template.TEMPLATE, alias ) : "";
|
protected java.lang.String | getSQLUpdateRowString()
return sqlUpdateRowString;
|
protected java.lang.String | getSQLWhereString(java.lang.String alias)
return StringHelper.replace( sqlWhereStringTemplate, Template.TEMPLATE, alias );
|
public int | getSize(java.io.Serializable key, org.hibernate.engine.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
);
}
|
private org.hibernate.loader.collection.CollectionInitializer | getSubselectInitializer(java.io.Serializable key, org.hibernate.engine.SessionImplementor session)
if ( !isSubselectLoadable() ) {
return null;
}
final PersistenceContext persistenceContext = session.getPersistenceContext();
SubselectFetch subselect = persistenceContext.getBatchFetchQueue()
.getSubselect( new EntityKey( key, getOwnerEntityPersister(), session.getEntityMode() ) );
if (subselect == null) {
return null;
}
else {
// Take care of any entities that might have
// been evicted!
Iterator iter = subselect.getResult().iterator();
while ( iter.hasNext() ) {
if ( !persistenceContext.containsEntity( (EntityKey) iter.next() ) ) {
iter.remove();
}
}
// Run a subquery loader
return createSubselectInitializer( subselect, session );
}
|
public java.lang.String | getTableName()
return qualifiedTableName;
|
public org.hibernate.type.Type | getType()
return elementPropertyMapping.getType(); //==elementType ??
|
protected org.hibernate.engine.ExecuteUpdateResultCheckStyle | getUpdateCheckStyle()
return updateCheckStyle;
|
public boolean | hasCache()
return cache != 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 java.lang.Object | incrementIndexByBase(java.lang.Object index)
if (baseIndex!=0) {
index = new Integer( ( (Integer) index ).intValue() + baseIndex );
}
return index;
|
public boolean | indexExists(java.io.Serializable key, java.lang.Object index, org.hibernate.engine.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 }
);
}
|
private void | initCollectionPropertyMap(java.lang.String aliasName, org.hibernate.type.Type type, java.lang.String[] columnAliases, java.lang.String[] columnNames)
collectionPropertyColumnAliases.put(aliasName, columnAliases);
collectionPropertyColumnNames.put(aliasName, columnNames);
if( type.isComponentType() ) {
AbstractComponentType ct = (AbstractComponentType) type;
String[] propertyNames = ct.getPropertyNames();
for (int i = 0; i < propertyNames.length; i++) {
String name = propertyNames[i];
collectionPropertyColumnAliases.put( aliasName + "." + name, columnAliases[i] );
collectionPropertyColumnNames.put( aliasName + "." + name, columnNames[i] );
}
}
|
public void | initialize(java.io.Serializable key, org.hibernate.engine.SessionImplementor session)
getAppropriateInitializer( key, session ).initialize( key, session );
|
public void | insertRows(org.hibernate.collection.PersistentCollection collection, java.io.Serializable id, org.hibernate.engine.SessionImplementor session)
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(org.hibernate.engine.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;
|
public abstract 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 java.lang.String | oneToManyFilterFragment(java.lang.String alias)
return "";
|
public void | postInstantiate()
initializer = queryLoaderName == null ?
createCollectionInitializer( CollectionHelper.EMPTY_MAP ) :
new NamedQueryCollectionInitializer( queryLoaderName, this );
|
private static java.lang.String[] | qualify(java.lang.String alias, java.lang.String[] columnNames, java.lang.String[] formulaTemplates)
int span = columnNames.length;
String[] result = new String[span];
for (int i=0; i<span; i++) {
if ( columnNames[i]==null ) {
result[i] = StringHelper.replace( formulaTemplates[i], Template.TEMPLATE, alias );
}
else {
result[i] = StringHelper.qualify( alias, columnNames[i] );
}
}
return result;
|
public java.lang.Object | readElement(java.sql.ResultSet rs, java.lang.Object owner, java.lang.String[] aliases, org.hibernate.engine.SessionImplementor session)
return getElementType().nullSafeGet( rs, aliases, session, owner );
|
public java.lang.Object | readIdentifier(java.sql.ResultSet rs, java.lang.String alias, org.hibernate.engine.SessionImplementor session)
Object id = getIdentifierType().nullSafeGet( rs, alias, session, null );
if ( id == null ) {
throw new HibernateException( "null identifier column for collection: " + role );
}
return id;
|
public java.lang.Object | readIndex(java.sql.ResultSet rs, java.lang.String[] aliases, org.hibernate.engine.SessionImplementor session)
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 java.lang.Object | readKey(java.sql.ResultSet rs, java.lang.String[] aliases, org.hibernate.engine.SessionImplementor session)
return getKeyType().nullSafeGet( rs, aliases, session, null );
|
public void | recreate(org.hibernate.collection.PersistentCollection collection, java.io.Serializable id, org.hibernate.engine.SessionImplementor session)
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(java.io.Serializable id, org.hibernate.engine.SessionImplementor session)
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 java.lang.String | selectFragment(java.lang.String alias, java.lang.String columnSuffix)Generate a list of collection index, key and element columns
SelectFragment frag = generateSelectFragment( alias, columnSuffix );
appendElementColumns( frag, alias );
appendIndexColumns( frag, alias );
appendIdentifierColumns( frag, alias );
return frag.toFragmentString()
.substring( 2 ); //strip leading ','
|
public java.lang.String[] | toColumns(java.lang.String alias, java.lang.String propertyName)
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 java.lang.String[] | toColumns(java.lang.String propertyName)
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 java.lang.String | toString()
return StringHelper.unqualify( getClass().getName() ) + '(" + role + ')";
|
public org.hibernate.type.Type | toType(java.lang.String propertyName)
if ( "index".equals( propertyName ) ) {
return indexType;
}
return elementPropertyMapping.toType( propertyName );
|
public void | updateRows(org.hibernate.collection.PersistentCollection collection, java.io.Serializable id, org.hibernate.engine.SessionImplementor session)
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(java.sql.PreparedStatement st, java.lang.Object elt, int i, org.hibernate.engine.SessionImplementor session)Write the element to a JDBC PreparedStatement
getElementType().nullSafeSet(st, elt, i, elementColumnIsSettable, session);
return i + ArrayHelper.countTrue(elementColumnIsSettable);
|
protected int | writeElementToWhere(java.sql.PreparedStatement st, java.lang.Object elt, int i, org.hibernate.engine.SessionImplementor session)Write the element to a JDBC PreparedStatement
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;
|
public int | writeIdentifier(java.sql.PreparedStatement st, java.lang.Object id, int i, org.hibernate.engine.SessionImplementor session)Write the identifier to a JDBC PreparedStatement
getIdentifierType().nullSafeSet( st, id, i, session );
return i + 1;
|
protected int | writeIndex(java.sql.PreparedStatement st, java.lang.Object index, int i, org.hibernate.engine.SessionImplementor session)Write the index to a JDBC PreparedStatement
getIndexType().nullSafeSet( st, incrementIndexByBase(index), i, indexColumnIsSettable, session );
return i + ArrayHelper.countTrue(indexColumnIsSettable);
|
protected int | writeIndexToWhere(java.sql.PreparedStatement st, java.lang.Object index, int i, org.hibernate.engine.SessionImplementor session)Write the index to a JDBC PreparedStatement
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;
|
protected int | writeKey(java.sql.PreparedStatement st, java.io.Serializable key, int i, org.hibernate.engine.SessionImplementor session)Write the key to a JDBC PreparedStatement
if ( key == null ) {
throw new NullPointerException( "null key for collection: " + role ); //an assertion
}
getKeyType().nullSafeSet( st, key, i, session );
return i + keyColumnAliases.length;
|