private String manyToManySelectFragment( Joinable rhs, String rhsAlias, String lhsAlias, 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 ',' }
@Override protected CollectionInitializer createSubselectInitializer(SubselectFetch subselect, SharedSessionContractImplementor session) { return new SubselectCollectionLoader( this, subselect.toSubselectString( getCollectionType().getLHSPropertyName() ), subselect.getResult(), subselect.getQueryParameters(), subselect.getNamedParameterLocMap(), session.getFactory(), session.getLoadQueryInfluencers() ); }
public String selectFragment( Joinable rhs, String rhsAlias, String lhsAlias, String entitySuffix, 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 ) : ""; }
@SuppressWarnings({"unchecked", "UnusedParameters"}) protected Serializable snapshot(BasicCollectionPersister persister, EntityMode entityMode) throws HibernateException { final TreeMap clonedSet = new TreeMap( comparator ); for ( Object setElement : set ) { final Object copy = persister.getElementType().deepCopy( setElement, persister.getFactory() ); clonedSet.put( copy, copy ); } return clonedSet; }
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; if ( updateBatchKey == null ) { updateBatchKey = new BasicBatchKey( getRole() + "#UPDATE", expectation ); int loc = writeElement( st, collection.getElement( entry ), offset, session ); if ( hasIdentifier ) { writeIdentifier( st, collection.getIdentifier( entry, i ), loc, session ); loc = writeKey( st, id, loc, session ); if ( hasIndex && !indexContainsFormula ) { writeIndexToWhere( st, collection.getIndex( entry, i, this ), loc, session ); writeElementToWhere( st, collection.getSnapshotElement( entry, i ), loc, session ); throw getSQLExceptionHelper().convert( sqle, "could not update collection rows: " + MessageHelper.collectionInfoString( this, id, getFactory() ), getSQLUpdateRowString() );
boolean callable = isUpdateCallable(); Iterator entries = collection.entries(this); try { if ( callable ) { CallableStatement callstatement = session.getBatcher() .prepareBatchCallableStatement( getSQLUpdateRowString() ); st = session.getBatcher().prepareBatchStatement( getSQLUpdateRowString() ); int loc = writeElement(st, collection.getElement(entry), offset, session ); if ( hasIdentifier ) { loc = writeIdentifier(st, collection.getIdentifier(entry, i), loc, session); loc = writeKey( st, id, loc, session ); if ( hasIndex && !indexIsFormula ) { loc = writeIndexToWhere( st, collection.getIndex(entry, i, this), loc, session ); loc = writeElementToWhere( st, collection.getSnapshotElement(entry, i), loc, session ); getSQLExceptionConverter(), sqle, "could not update collection rows: " + MessageHelper.collectionInfoString( this, id, getFactory() ), getSQLUpdateRowString() );
/** * Generate the SQL INSERT that creates a new row */ @Override protected String generateInsertRowString() { final Insert insert = new Insert( getDialect() ) .setTableName( qualifiedTableName ) .addColumns( keyColumnNames ); if ( hasIdentifier ) { insert.addColumn( identifierColumnName ); } if ( hasIndex /*&& !indexIsFormula*/ ) { insert.addColumns( indexColumnNames, indexColumnIsSettable ); } if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { insert.setComment( "insert collection row " + getRole() ); } //if ( !elementIsFormula ) { insert.addColumns( elementColumnNames, elementColumnIsSettable, elementColumnWriters ); //} return insert.toStatementString(); }
if ( updateBatchKey == null ) { updateBatchKey = new BasicBatchKey( getRole() + "#UPDATE", expectation ); int loc = writeElement( st, collection.getElement( entry ), offset, session ); if ( hasIdentifier ) { writeIdentifier( st, collection.getIdentifier( entry, i ), loc, session ); loc = writeKey( st, id, loc, session ); if ( hasIndex && !indexContainsFormula ) { writeIndexToWhere( st, collection.getIndex( entry, i, this ), loc, session ); writeElementToWhere( st, collection.getSnapshotElement( entry, i ), loc, session );
/** * Generate the SQL DELETE that deletes all rows */ @Override protected String generateDeleteString() { final Delete delete = new Delete() .setTableName( qualifiedTableName ) .addPrimaryKeyColumns( keyColumnNames ); if ( hasWhere ) { delete.setWhere( sqlWhereString ); } if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { delete.setComment( "delete collection " + getRole() ); } return delete.toStatementString(); }
final Expectation expectation = Expectations.appropriateExpectation( getUpdateCheckStyle() ); final boolean callable = isUpdateCallable(); final int jdbcBatchSizeToUse = session.getConfiguredJdbcBatchSize(); boolean useBatch = expectation.canBeBatched() && jdbcBatchSizeToUse > 1; final String sql = getSQLUpdateRowString(); int count = 0; if ( collection.isElementRemoved() ) { count = doUpdateRow( id, collection, count = doUpdateRow( id, collection, session ), getSQLUpdateRowString() );
/** * Create the <tt>CollectionLoader</tt> * * @see org.hibernate.loader.collection.BasicCollectionLoader */ @Override protected CollectionInitializer createCollectionInitializer(LoadQueryInfluencers loadQueryInfluencers) throws MappingException { return BatchingCollectionInitializerBuilder.getBuilder( getFactory() ) .createBatchingCollectionInitializer( this, batchSize, getFactory(), loadQueryInfluencers ); }
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; if ( updateBatchKey == null ) { updateBatchKey = new BasicBatchKey( getRole() + "#UPDATE", expectation ); int loc = writeElement( st, collection.getElement( entry ), offset, session ); if ( hasIdentifier ) { writeIdentifier( st, collection.getIdentifier( entry, i ), loc, session ); loc = writeKey( st, id, loc, session ); if ( hasIndex && !indexContainsFormula ) { writeIndexToWhere( st, collection.getIndex( entry, i, this ), loc, session ); writeElementToWhere( st, collection.getSnapshotElement( entry, i ), loc, session ); throw getSQLExceptionHelper().convert( sqle, "could not update collection rows: " + MessageHelper.collectionInfoString( this, id, getFactory() ), getSQLUpdateRowString() );
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; int loc = writeElement( st, collection.getElement( entry ), offset, session ); if ( hasIdentifier ) { writeIdentifier( st, collection.getIdentifier( entry, i ), loc, session ); loc = writeKey( st, id, loc, session ); if ( hasIndex && !indexContainsFormula ) { writeIndexToWhere( st, collection.getIndex( entry, i, this ), loc, session ); writeElementToWhere( st, collection.getSnapshotElement( entry, i ), loc, session ); getSQLExceptionConverter(), sqle, "could not update collection rows: " + MessageHelper.collectionInfoString( this, id, getFactory() ), getSQLUpdateRowString() );
/** * Generate the SQL UPDATE that updates a row */ @Override protected String generateUpdateRowString() { final Update update = new Update( getDialect() ) .setTableName( qualifiedTableName ); //if ( !elementIsFormula ) { update.addColumns( elementColumnNames, elementColumnIsSettable, elementColumnWriters ); //} if ( hasIdentifier ) { update.addPrimaryKeyColumns( new String[] {identifierColumnName} ); } else if ( hasIndex && !indexContainsFormula ) { update.addPrimaryKeyColumns( ArrayHelper.join( keyColumnNames, indexColumnNames ) ); } else { update.addPrimaryKeyColumns( keyColumnNames ); update.addPrimaryKeyColumns( elementColumnNames, elementColumnIsInPrimaryKey, elementColumnWriters ); } if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { update.setComment( "update collection row " + getRole() ); } return update.toStatementString(); }
/** * Generate the SQL DELETE that deletes a particular row */ @Override protected String generateDeleteRowString() { final Delete delete = new Delete().setTableName( qualifiedTableName ); if ( hasIdentifier ) { delete.addPrimaryKeyColumns( new String[] {identifierColumnName} ); } else if ( hasIndex && !indexContainsFormula ) { delete.addPrimaryKeyColumns( ArrayHelper.join( keyColumnNames, indexColumnNames ) ); } else { delete.addPrimaryKeyColumns( keyColumnNames ); delete.addPrimaryKeyColumns( elementColumnNames, elementColumnIsInPrimaryKey, elementColumnWriters ); } if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { delete.setComment( "delete collection row " + getRole() ); } return delete.toStatementString(); }
@SuppressWarnings({"unchecked", "UnusedParameters"}) protected Serializable snapshot(BasicCollectionPersister persister, EntityMode entityMode) throws HibernateException { final TreeMap clonedMap = new TreeMap( comparator ); for ( Object o : map.entrySet() ) { final Entry e = (Entry) o; clonedMap.put( e.getKey(), persister.getElementType().deepCopy( e.getValue(), persister.getFactory() ) ); } return clonedMap; }
/** * Create the <tt>CollectionLoader</tt> * * @see org.hibernate.loader.collection.BasicCollectionLoader */ @Override protected CollectionInitializer createCollectionInitializer(LoadQueryInfluencers loadQueryInfluencers) throws MappingException { return BatchingCollectionInitializer.createBatchingCollectionInitializer( this, batchSize, getFactory(), loadQueryInfluencers ); }
public String selectFragment( Joinable rhs, String rhsAlias, String lhsAlias, String entitySuffix, 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 ) : ""; }
/** * Generate the SQL INSERT that creates a new row */ @Override protected String generateInsertRowString() { 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, elementColumnWriters ); //} return insert.toStatementString(); }
/** * Generate the SQL DELETE that deletes all rows */ protected String generateDeleteString() { 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(); }