protected UniqueEntityLoader createEntityLoader( LockOptions lockOptions, LoadQueryInfluencers loadQueryInfluencers) throws MappingException { //TODO: disable batch loading if lockMode > READ? return BatchingEntityLoaderBuilder.getBuilder( getFactory() ) .buildLoader( this, batchSize, lockOptions, getFactory(), loadQueryInfluencers ); }
protected UniqueEntityLoader createEntityLoader( LockMode lockMode, LoadQueryInfluencers loadQueryInfluencers) throws MappingException { //TODO: disable batch loading if lockMode > READ? return BatchingEntityLoaderBuilder.getBuilder( getFactory() ) .buildLoader( this, batchSize, lockMode, getFactory(), loadQueryInfluencers ); }
private String substituteBrackets(String sql) { return new SubstituteBracketSQLQueryParser( sql, getFactory() ).process(); }
protected boolean useGetGeneratedKeys() { return getFactory().getSessionFactoryOptions().isGetGeneratedKeysEnabled(); }
protected void createLoaders() { // We load the entity loaders for the most common lock modes. noneLockLoader = createEntityLoader( LockMode.NONE ); readLockLoader = createEntityLoader( LockMode.READ ); // The loaders for the other lock modes are lazily loaded and will later be stored in this map, // unless this setting is disabled if ( ! factory.getSessionFactoryOptions().isDelayBatchFetchLoaderCreationsEnabled() ) { for ( LockMode lockMode : EnumSet.complementOf( EnumSet.of( LockMode.NONE, LockMode.READ, LockMode.WRITE ) ) ) { loaders.put( lockMode, createEntityLoader( lockMode ) ); } } // And finally, create the internal merge and refresh load plans loaders.put( "merge", new CascadeEntityLoader( this, CascadingActions.MERGE, getFactory() ) ); loaders.put( "refresh", new CascadeEntityLoader( this, CascadingActions.REFRESH, getFactory() ) ); }
public String getIdentitySelectString() { //TODO: cache this in an instvar return getFactory().getDialect().getIdentityColumnSupport() .getIdentitySelectString( getTableName( 0 ), getKeyColumns( 0 )[0], getIdentifierType().sqlTypes( getFactory() )[0] ); }
private EntityLoader createUniqueKeyLoader( Type uniqueKeyType, String[] columns, LoadQueryInfluencers loadQueryInfluencers) { if ( uniqueKeyType.isEntityType() ) { String className = ( (EntityType) uniqueKeyType ).getAssociatedEntityName(); uniqueKeyType = getFactory().getMetamodel().entityPersister( className ).getIdentifierType(); } return new EntityLoader( this, columns, uniqueKeyType, 1, LockMode.NONE, getFactory(), loadQueryInfluencers ); }
public String[][] getPolymorphicJoinColumns(String lhsTableAlias, String propertyPath) { Set<String> subclassEntityNames = getEntityMetamodel().getSubclassEntityNames(); // We will collect all the join columns from the LHS subtypes here List<String[]> polymorphicJoinColumns = new ArrayList<>( subclassEntityNames.size() ); String[] joinColumns; OUTER: for ( String subclassEntityName : subclassEntityNames ) { AbstractEntityPersister subclassPersister = (AbstractEntityPersister) getFactory() .getMetamodel() .entityPersister( subclassEntityName ); joinColumns = subclassPersister.toColumns( lhsTableAlias, propertyPath ); if ( joinColumns.length == 0 ) { // The subtype does not have a "concrete" mapping for the property path continue; } // Check for duplicates like this since we will mostly have just a few candidates for ( String[] existingColumns : polymorphicJoinColumns ) { if ( Arrays.deepEquals( existingColumns, joinColumns ) ) { continue OUTER; } } polymorphicJoinColumns.add( joinColumns ); } return ArrayHelper.to2DStringArray( polymorphicJoinColumns ); }
protected boolean useInsertSelectIdentity() { return !useGetGeneratedKeys() && getFactory().getDialect().getIdentityColumnSupport().supportsInsertSelectIdentity(); }
/** * Load an instance using either the <tt>forUpdateLoader</tt> or the outer joining <tt>loader</tt>, * depending upon the value of the <tt>lock</tt> parameter */ public Object load(Serializable id, Object optionalObject, LockOptions lockOptions, SharedSessionContractImplementor session) throws HibernateException { if ( LOG.isTraceEnabled() ) { LOG.tracev( "Fetching entity: {0}", MessageHelper.infoString( this, id, getFactory() ) ); } final UniqueEntityLoader loader = getAppropriateLoader( lockOptions, session ); return loader.load( id, optionalObject, session, lockOptions ); }
public boolean isBatchable() { return optimisticLockStyle() == OptimisticLockStyle.NONE || ( !isVersioned() && optimisticLockStyle() == OptimisticLockStyle.VERSION ) || getFactory().getSessionFactoryOptions().isJdbcBatchVersionedData(); }
private void internalInitSubclassPropertyAliasesMap(String path, Iterator propertyIterator) { while ( propertyIterator.hasNext() ) { Property prop = (Property) propertyIterator.next(); String propname = path == null ? prop.getName() : path + "." + prop.getName(); if ( prop.isComposite() ) { Component component = (Component) prop.getValue(); Iterator compProps = component.getPropertyIterator(); internalInitSubclassPropertyAliasesMap( propname, compProps ); } else { String[] aliases = new String[prop.getColumnSpan()]; String[] cols = new String[prop.getColumnSpan()]; Iterator colIter = prop.getColumnIterator(); int l = 0; while ( colIter.hasNext() ) { Selectable thing = (Selectable) colIter.next(); aliases[l] = thing.getAlias( getFactory().getDialect(), prop.getValue().getTable() ); cols[l] = thing.getText( getFactory().getDialect() ); // TODO: skip formulas? l++; } subclassPropertyAliases.put( propname, aliases ); subclassPropertyColumnNames.put( propname, cols ); } } }
private void initDiscriminatorPropertyPath(Mapping mapping) throws MappingException { propertyMapping.initPropertyPaths( ENTITY_CLASS, getDiscriminatorType(), new String[] {getDiscriminatorColumnName()}, new String[] {getDiscriminatorColumnReaders()}, new String[] {getDiscriminatorColumnReaderTemplate()}, new String[] {getDiscriminatorFormulaTemplate()}, getFactory() ); }
private String generateVersionIncrementUpdateString() { Update update = new Update( getFactory().getDialect() ); update.setTableName( getTableName( 0 ) ); if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { update.setComment( "forced version increment" ); } update.addColumn( getVersionColumnName() ); update.addPrimaryKeyColumns( rootTableKeyColumnNames ); update.setVersionColumnName( getVersionColumnName() ); return update.toStatementString(); }
/** * Generate the SQL that selects the version number by id */ protected String generateSelectVersionString() { SimpleSelect select = new SimpleSelect( getFactory().getDialect() ) .setTableName( getVersionedTableName() ); if ( isVersioned() ) { select.addColumn( versionColumnName ); } else { select.addColumns( rootTableKeyColumnNames ); } if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { select.setComment( "get version " + getEntityName() ); } return select.addCondition( rootTableKeyColumnNames, "=?" ).toStatementString(); }
public String getSelectByUniqueKeyString(String propertyName) { return new SimpleSelect( getFactory().getDialect() ) .setTableName( getTableName( 0 ) ) .addColumns( getKeyColumns( 0 ) ) .addCondition( getPropertyColumnNames( propertyName ), "=?" ) .toStatementString(); }
protected String renderSelect( final int[] tableNumbers, final int[] columnNumbers, final int[] formulaNumbers) { Arrays.sort( tableNumbers ); //get 'em in the right order (not that it really matters) //render the where and from parts int drivingTable = tableNumbers[0]; final String drivingAlias = generateTableAlias( getRootAlias(), drivingTable ); //we *could* regerate this inside each called method! final String where = createWhereByKey( drivingTable, drivingAlias ); final String from = createFrom( drivingTable, drivingAlias ); //now render the joins JoinFragment jf = createJoin( tableNumbers, drivingAlias ); //now render the select clause SelectFragment selectFragment = createSelect( columnNumbers, formulaNumbers ); //now tie it all together Select select = new Select( getFactory().getDialect() ); select.setSelectClause( selectFragment.toFragmentString().substring( 2 ) ); select.setFromClause( from ); select.setWhereClause( where ); select.setOuterJoins( jf.toFromFragmentString(), jf.toWhereFragmentString() ); if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { select.setComment( "sequential select " + getEntityName() ); } return select.toStatementString(); }
protected JoinFragment createJoin(int[] tableNumbers, String drivingAlias) { final String[] keyCols = StringHelper.qualify( drivingAlias, getSubclassTableKeyColumns( tableNumbers[0] ) ); final JoinFragment jf = getFactory().getDialect().createOuterJoinFragment(); // IMPL NOTE : notice that we skip the first table; it is the driving table! for ( int i = 1; i < tableNumbers.length; i++ ) { final int j = tableNumbers[i]; jf.addJoin( getSubclassTableName( j ), generateTableAlias( getRootAlias(), j ), keyCols, getSubclassTableKeyColumns( j ), isInverseSubclassTable( j ) || isNullableSubclassTable( j ) ? JoinType.LEFT_OUTER_JOIN : JoinType.INNER_JOIN ); } return jf; }
/** * Generate the SQL that deletes a row by id (and version) */ protected String generateDeleteString(int j) { final Delete delete = new Delete() .setTableName( getTableName( j ) ) .addPrimaryKeyColumns( getKeyColumns( j ) ); if ( j == 0 ) { delete.setVersionColumnName( getVersionColumnName() ); } if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { delete.setComment( "delete " + getEntityName() ); } return delete.toStatementString(); }
protected interface InclusionChecker { boolean includeProperty(int propertyNumber); }