Refine search
protected interface InclusionChecker { boolean includeProperty(int propertyNumber); }
private String generateEntityIdByNaturalIdSql(boolean[] valueNullness) { EntityPersister rootPersister = getFactory().getEntityPersister( getRootEntityName() ); if ( rootPersister != this ) { if ( rootPersister instanceof AbstractEntityPersister ) { return ( (AbstractEntityPersister) rootPersister ).generateEntityIdByNaturalIdSql( valueNullness ); Select select = new Select( getFactory().getDialect() ); if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { select.setComment( "get current natural-id->entity-id state " + getEntityName() ); final String rootAlias = getRootAlias(); select.setSelectClause( identifierSelectFragment( rootAlias, "" ) ); select.setFromClause( fromTableFragment( rootAlias ) + fromJoinFragment( rootAlias, true, false ) ); final int[] propertyTableNumbers = getPropertyTableNumbers(); final int[] naturalIdPropertyIndexes = this.getNaturalIdentifierProperties(); int valuesIndex = -1; for ( int propIdx = 0; propIdx < naturalIdPropertyIndexes.length; propIdx++ ) { final String tableAlias = generateTableAlias( rootAlias, propertyTableNumbers[naturalIdIdx] ); final String[] propertyColumnNames = getPropertyColumnNames( naturalIdIdx ); final String[] aliasedPropertyColumns = StringHelper.qualify( tableAlias, propertyColumnNames ); whereClause.append( whereJoinFragment( getRootAlias(), true, false ) );
protected void createUniqueKeyLoaders() throws MappingException { Type[] propertyTypes = getPropertyTypes(); String[] propertyNames = getPropertyNames(); for ( int i = 0; i < entityMetamodel.getPropertySpan(); i++ ) { if ( propertyUniqueness[i] ) { //don't need filters for the static loaders uniqueKeyLoaders.put( propertyNames[i], createUniqueKeyLoader( propertyTypes[i], getPropertyColumnNames( i ), LoadQueryInfluencers.NONE ) ); //TODO: create uk loaders for component properties } } }
ClassMetadata hibernateMetadata = sessionFactory.getClassMetadata(pClassName); if (hibernateMetadata == null) { return; } if (hibernateMetadata instanceof AbstractEntityPersister) { AbstractEntityPersister persister = (AbstractEntityPersister) hibernateMetadata; String tableName = persister.getTableName(); String[] columnNames = persister.getKeyColumnNames(); }
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() ); }
public String getIdentitySelectString() { //TODO: cache this in an instvar return getFactory().getDialect().getIdentityColumnSupport() .getIdentitySelectString( getTableName( 0 ), getKeyColumns( 0 )[0], getIdentifierType().sqlTypes( getFactory() )[0] ); }
public Object[] getNaturalIdentifierSnapshot(Serializable id, SharedSessionContractImplementor session) throws HibernateException { if ( !hasNaturalIdentifier() ) { throw new MappingException( "persistent class did not define a natural-id : " + MessageHelper.infoString( LOG.tracev( "Getting current natural-id snapshot state for: {0}", MessageHelper.infoString( this, id, getFactory() ) ); int[] naturalIdPropertyIndexes = getNaturalIdentifierProperties(); int naturalIdPropertyCount = naturalIdPropertyIndexes.length; boolean[] naturalIdMarkers = new boolean[getPropertySpan()]; Type[] extractionTypes = new Type[naturalIdPropertyCount]; for ( int i = 0; i < naturalIdPropertyCount; i++ ) { extractionTypes[i] = getPropertyTypes()[naturalIdPropertyIndexes[i]]; naturalIdMarkers[naturalIdPropertyIndexes[i]] = true; Select select = new Select( getFactory().getDialect() ); if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { select.setComment( "get current natural-id state " + getEntityName() ); select.setSelectClause( concretePropertySelectFragmentSansLeadingComma( getRootAlias(), naturalIdMarkers ) ); select.setFromClause( fromTableFragment( getRootAlias() ) + fromJoinFragment( getRootAlias(), true, false ) ); String[] aliasedIdColumns = StringHelper.qualify( getRootAlias(), getIdentifierColumnNames() ); String whereClause = new StringBuilder() .append(
Update update = new Update( getFactory().getDialect() ).setTableName( getTableName( j ) ); update.addPrimaryKeyColumns( getKeyColumns( j ) ); if ( includeProperty[i] && isPropertyOfTable( i, j ) && !lobProperties.contains( i ) ) { getPropertyColumnNames( i ), propertyColumnUpdateable[i], propertyColumnWriters[i] ); hasColumns = hasColumns || getPropertyColumnSpan( i ) > 0; if ( includeProperty[i] && isPropertyOfTable( i, j ) ) { getPropertyColumnNames( i ), propertyColumnUpdateable[i], propertyColumnWriters[i] ); if ( j == 0 && isVersioned() && entityMetamodel.getOptimisticLockStyle() == OptimisticLockStyle.VERSION ) { if ( checkVersion( includeProperty ) ) { update.setVersionColumnName( getVersionColumnName() ); hasColumns = true; else if ( isAllOrDirtyOptLocking() && oldFields != null ) { getPropertyUpdateability() boolean[] versionability = getPropertyVersionability();
Select select = new Select( getFactory().getDialect() ); if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { select.setComment( "get current state " + getEntityName() ); String[] aliasedIdColumns = StringHelper.qualify( getRootAlias(), getIdentifierColumnNames() ); String selectClause = String.join( ", ", aliasedIdColumns ) + concretePropertySelectFragment( getRootAlias(), getPropertyUpdateability() ); String fromClause = fromTableFragment( getRootAlias() ) + fromJoinFragment( getRootAlias(), true, false ); .append( whereJoinFragment( getRootAlias(), true, false ) ) .toString();
internalInitSubclassPropertyAliasesMap( null, model.getSubclassPropertyClosureIterator() ); subclassPropertyAliases.put( ENTITY_ID, getIdentifierAliases() ); subclassPropertyColumnNames.put( ENTITY_ID, getIdentifierColumnNames() ); if ( hasIdentifierProperty() ) { subclassPropertyAliases.put( getIdentifierPropertyName(), getIdentifierAliases() ); subclassPropertyColumnNames.put( getIdentifierPropertyName(), getIdentifierColumnNames() ); if ( getIdentifierType().isComponentType() ) { CompositeType componentId = (CompositeType) getIdentifierType(); String[] idPropertyNames = componentId.getPropertyNames(); String[] idAliases = getIdentifierAliases(); String[] idColumnNames = getIdentifierColumnNames(); ); subclassPropertyColumnNames.put( ENTITY_ID + "." + getIdentifierPropertyName() + "." + idPropertyNames[i], new String[] {idColumnNames[i]} ); if ( hasIdentifierProperty() ) { subclassPropertyAliases.put( getIdentifierPropertyName() + "." + idPropertyNames[i], new String[] {idAliases[i]} ); subclassPropertyColumnNames.put( getIdentifierPropertyName() + "." + idPropertyNames[i],
protected String generateIdByUniqueKeySelectString(String uniquePropertyName) { Select select = new Select( getFactory().getDialect() ); if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { select.setComment( "resolve id by unique property [" + getEntityName() + "." + uniquePropertyName + "]" ); final String rooAlias = getRootAlias(); select.setFromClause( fromTableFragment( rooAlias ) + fromJoinFragment( rooAlias, true, false ) ); selectFragment.addColumns( rooAlias, getIdentifierColumnNames(), getIdentifierAliases() ); select.setSelectClause( selectFragment ); final int uniquePropertyIndex = getSubclassPropertyIndex( uniquePropertyName ); final String uniquePropertyTableAlias = generateTableAlias( rooAlias, getSubclassPropertyTableNumber( uniquePropertyIndex ) ); String sep = ""; for ( String columnTemplate : getSubclassPropertyColumnReaderTemplateClosure()[uniquePropertyIndex] ) { if ( columnTemplate == null ) { continue; for ( String formulaTemplate : getSubclassPropertyFormulaTemplateClosure()[uniquePropertyIndex] ) { if ( formulaTemplate == null ) { continue; whereClauseBuffer.append( whereJoinFragment( rooAlias, true, false ) );
public String getSelectByUniqueKeyString(String propertyName) { return new SimpleSelect( getFactory().getDialect() ) .setTableName( getTableName( 0 ) ) .addColumns( getKeyColumns( 0 ) ) .addCondition( getPropertyColumnNames( propertyName ), "=?" ) .toStatementString(); }
Insert insert = new Insert( getFactory().getDialect() ) .setTableName( getTableName( j ) ); if ( isPropertyOfTable( i, j ) ) { if ( !lobProperties.contains( i ) ) { final InDatabaseValueGenerationStrategy generationStrategy = entityMetamodel.getInDatabaseValueGenerationStrategies()[i]; insert.addColumns( getPropertyColumnNames( i ), propertyColumnInsertable[i], values ); getPropertyColumnNames( i ), propertyColumnInsertable[i], propertyColumnWriters[i] addDiscriminatorToInsert( insert ); insert.addIdentityColumn( getKeyColumns( 0 )[0] ); insert.addColumns( getKeyColumns( j ) ); if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { insert.setComment( "insert " + getEntityName() ); if ( includeProperty[i] && isPropertyOfTable( i, j ) ) { getPropertyColumnNames( i ), propertyColumnInsertable[i], propertyColumnWriters[i] if ( j == 0 && identityInsert && useInsertSelectIdentity() ) { //TODO: suck into Insert
private String generateVersionIncrementUpdateString() { Update update = new Update( getFactory().getDialect() ); update.setTableName( getTableName( 0 ) ); if ( getFactory().getSettings().isCommentsEnabled() ) { update.setComment( "forced version increment" ); } update.addColumn( getVersionColumnName() ); update.addPrimaryKeyColumns( getIdentifierColumnNames() ); update.setVersionColumnName( getVersionColumnName() ); return update.toStatementString(); }
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(); }
private String[] generateSQLDeletStrings(Object[] loadedState) { int span = getTableSpan(); String[] deleteStrings = new String[span]; for ( int j = span - 1; j >= 0; j-- ) { Delete delete = new Delete() .setTableName( getTableName( j ) ) .addPrimaryKeyColumns( getKeyColumns( j ) ); if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { delete.setComment( "delete " + getEntityName() + " [" + j + "]" ); boolean[] versionability = getPropertyVersionability(); Type[] types = getPropertyTypes(); for ( int i = 0; i < entityMetamodel.getPropertySpan(); i++ ) { if ( isPropertyOfTable( i, j ) && versionability[i] ) { String[] propertyColumnNames = getPropertyColumnNames( i ); boolean[] propertyNullness = types[i].toColumnNullness( loadedState[i], getFactory() ); for ( int k = 0; k < propertyNullness.length; k++ ) { if ( propertyNullness[k] ) {
private TableInfoDTO getTableInfo(AbstractEntityPersister persister) { TableInfoDTO tableInfoDTO = new TableInfoDTO(); String[] name = SqlUtil.replaceSingularSchemaName(persister.getTableName()).split("\\."); tableInfoDTO.setSchema(name[0]); tableInfoDTO.setTableName(name[1]); List<String> columns = new ArrayList<>(); String[] propertyNames = persister.getPropertyNames(); Arrays.asList(propertyNames).forEach(propertyName -> columns.add(persister.getPropertyColumnNames(propertyName)[0])); Arrays.asList(persister.getIdentifierColumnNames()).forEach(chave -> { if (!columns.contains(chave)) { columns.add(chave); } }); List<ColumnInfoDTO> columnsType = new ArrayList<>(); columns.forEach(col -> columnsType.add(new ColumnInfoDTO(col, true))); tableInfoDTO.setColumnsInfo(columnsType); return tableInfoDTO; }
protected JoinFragment createJoin( String name, boolean innerJoin, boolean includeSubclasses, Set<String> treatAsDeclarations) { // IMPL NOTE : all joins join to the pk of the driving table final String[] idCols = StringHelper.qualify( name, getIdentifierColumnNames() ); final JoinFragment join = getFactory().getDialect().createOuterJoinFragment(); final int tableSpan = getSubclassTableSpan(); // IMPL NOTE : notice that we skip the first table; it is the driving table! for ( int j = 1; j < tableSpan; j++ ) { final JoinType joinType = determineSubclassTableJoinType( j, innerJoin, includeSubclasses, treatAsDeclarations ); if ( joinType != null && joinType != JoinType.NONE ) { join.addJoin( getSubclassTableName( j ), generateTableAlias( name, j ), idCols, getSubclassTableKeyColumns( j ), joinType ); } } return join; }
insert.setTableName( getTableName( 0 ) ); if ( isPropertyOfTable( i, 0 ) && !lobProperties.contains( i ) ) { final InDatabaseValueGenerationStrategy generationStrategy = entityMetamodel.getInDatabaseValueGenerationStrategies()[i]; getPropertyColumnNames( i ), propertyColumnInsertable[i], propertyColumnWriters[i] getPropertyColumnNames( i ), propertyColumnInsertable[i], values if ( includeProperty[i] && isPropertyOfTable( i, 0 ) ) { insert.addColumns( getPropertyColumnNames( i ), propertyColumnInsertable[i], propertyColumnWriters[i] ); addDiscriminatorToInsert( insert ); if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { insert.setComment( "insert " + getEntityName() );
/** * 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(); }