Java Code Examples for org.hibernate.internal.util.StringHelper#qualify()

The following examples show how to use org.hibernate.internal.util.StringHelper#qualify() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardIndexExporter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String[] getSqlDropStrings(Index index, Metadata metadata) {
	if ( !dialect.dropConstraints() ) {
		return NO_COMMANDS;
	}

	final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();
	final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
			index.getTable().getQualifiedTableName(),
			dialect
	);

	final String indexNameForCreation;
	if ( dialect.qualifyIndexName() ) {
		indexNameForCreation = StringHelper.qualify( tableName, index.getName() );
	}
	else {
		indexNameForCreation = index.getName();
	}

	return new String[] { "drop index " + indexNameForCreation };
}
 
Example 2
Source File: PropertyBinder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the value generation strategy for the given property, if any.
 */
private ValueGeneration getValueGenerationFromAnnotations(XProperty property) {
	AnnotationValueGeneration<?> valueGeneration = null;

	for ( Annotation annotation : property.getAnnotations() ) {
		AnnotationValueGeneration<?> candidate = getValueGenerationFromAnnotation( property, annotation );

		if ( candidate != null ) {
			if ( valueGeneration != null ) {
				throw new AnnotationException(
						"Only one generator annotation is allowed:" + StringHelper.qualify(
								holder.getPath(),
								name
						)
				);
			}
			else {
				valueGeneration = candidate;
			}
		}
	}

	return valueGeneration;
}
 
Example 3
Source File: AbstractEntityPersister.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: ElementPropertyMapping.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public String[] toColumns(String alias, String propertyName) throws QueryException {
	if (propertyName==null || "id".equals(propertyName) ) {
		return StringHelper.qualify( alias, elementColumns );
	}
	else {
		throw new QueryException("cannot dereference scalar collection element: " + propertyName);
	}
}
 
Example 5
Source File: TableGenerator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "WeakerAccess"})
protected String buildSelectQuery(Dialect dialect) {
	final String alias = "tbl";
	final String query = "select " + StringHelper.qualify( alias, valueColumnName ) +
			" from " + renderedTableName + ' ' + alias +
			" where " + StringHelper.qualify( alias, segmentColumnName ) + "=?";
	final LockOptions lockOptions = new LockOptions( LockMode.PESSIMISTIC_WRITE );
	lockOptions.setAliasSpecificLockMode( alias, LockMode.PESSIMISTIC_WRITE );
	final Map updateTargetColumnsMap = Collections.singletonMap( alias, new String[] { valueColumnName } );
	return dialect.applyLocksToSql( query, lockOptions, updateTargetColumnsMap );
}
 
Example 6
Source File: AbstractPropertyHolder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get column overriding, property first, then parent, then holder
 * replace the placeholder 'collection&&element' with nothing
 *
 * These rules are here to support both JPA 2 and legacy overriding rules.
 */
@Override
public JoinTable getJoinTable(XProperty property) {
	final String propertyName = StringHelper.qualify( getPath(), property.getName() );
	JoinTable result = getOverriddenJoinTable( propertyName );
	if (result == null) {
		result = property.getAnnotation( JoinTable.class );
	}
	return result;
}
 
Example 7
Source File: SubselectFetch.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public String toSubselectString(String ukname) {
	String[] joinColumns = ukname == null
			? StringHelper.qualify( alias, loadable.getIdentifierColumnNames() )
			: ( (PropertyMapping) loadable ).toColumns( alias, ukname );

	return "select " + String.join( ", ", joinColumns ) + queryString;
}
 
Example 8
Source File: CollectionBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private String getCondition(String cond, String name) {
	if ( BinderHelper.isEmptyAnnotationValue( cond ) ) {
		cond = buildingContext.getMetadataCollector().getFilterDefinition( name ).getDefaultFilterCondition();
		if ( StringHelper.isEmpty( cond ) ) {
			throw new AnnotationException(
					"no filter condition found for filter " + name + " in "
							+ StringHelper.qualify( propertyHolder.getPath(), propertyName )
			);
		}
	}
	return cond;
}
 
Example 9
Source File: ForeignKeys.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
private CompletionStage<Void> nullifyTransientReferences(String propertyName, Object[] values, Type[] types, String[] names) {
	CompletionStage<Void> nullifiers = null;
	for ( int i = 0; i < values.length; i++ ) {
		int ii = i;
		String name = propertyName==null ? names[ii] : StringHelper.qualify( propertyName, names[ii] );
		CompletionStage<Object> nullifier = nullifyTransientReferences( values[ii], name, types[ii] );
		if ( nullifier != null ) {
			nullifiers = ( nullifiers == null ? nullifier : nullifiers.thenCompose( v-> nullifier ) )
					.thenAccept( replacement -> values[ii] = replacement );
		}
	}
	return nullifiers;
}
 
Example 10
Source File: AbstractEntityPersister.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public String[] toColumns(String name, final int i) {
	final String alias = generateTableAlias( name, getSubclassPropertyTableNumber( i ) );
	String[] cols = getSubclassPropertyColumnNames( i );
	String[] templates = getSubclassPropertyFormulaTemplateClosure()[i];
	String[] result = new String[cols.length];
	for ( int j = 0; j < cols.length; j++ ) {
		if ( cols[j] == null ) {
			result[j] = StringHelper.replace( templates[j], Template.TEMPLATE, alias );
		}
		else {
			result[j] = StringHelper.qualify( alias, cols[j] );
		}
	}
	return result;
}
 
Example 11
Source File: CriteriaQueryTranslator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String[] getIdentifierColumns(Criteria criteria) {
	String[] idcols =
			( ( Loadable ) getPropertyMapping( getEntityName( criteria ) ) ).getIdentifierColumnNames();
	return StringHelper.qualify( getSQLAlias( criteria ), idcols );
}
 
Example 12
Source File: GrailsHibernateUtil.java    From gorm-hibernate5 with Apache License 2.0 4 votes vote down vote up
public static String qualify(final String prefix, final String name) {
    return StringHelper.qualify(prefix, name);
}
 
Example 13
Source File: ForeignKey.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String getExportIdentifier() {
	// NOt sure name is always set.  Might need some implicit naming
	return StringHelper.qualify( getTable().getName(), "FK-" + getName() );
}
 
Example 14
Source File: PropertyAccessException.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String getMessage() {
	return originalMessage()
			+ ( wasSetter ? " setter of " : " getter of " )
			+ StringHelper.qualify( persistentClass.getName(), propertyName );
}
 
Example 15
Source File: Index.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static String buildSqlDropIndexString(
		String name,
		String tableName) {
	return "drop index " + StringHelper.qualify( tableName, name );
}
 
Example 16
Source File: AbstractPropertyMapping.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private static String extendPath(String path, String property) {
	return StringHelper.isEmpty( path ) ? property : StringHelper.qualify( path, property );
}
 
Example 17
Source File: PropertyBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public Property makeProperty() {
	validateMake();
	LOG.debugf( "Building property %s", name );
	Property prop = new Property();
	prop.setName( name );
	prop.setValue( value );
	prop.setLazy( lazy );
	prop.setLazyGroup( lazyGroup );
	prop.setCascade( cascade );
	prop.setPropertyAccessorName( accessType.getType() );

	if ( property != null ) {
		prop.setValueGenerationStrategy( determineValueGenerationStrategy( property ) );

		if ( property.isAnnotationPresent( AttributeAccessor.class ) ) {
			final AttributeAccessor accessor = property.getAnnotation( AttributeAccessor.class );
			prop.setPropertyAccessorName( accessor.value() );
		}
	}

	NaturalId naturalId = property != null ? property.getAnnotation( NaturalId.class ) : null;
	if ( naturalId != null ) {
		if ( ! entityBinder.isRootEntity() ) {
			throw new AnnotationException( "@NaturalId only valid on root entity (or its @MappedSuperclasses)" );
		}
		if ( ! naturalId.mutable() ) {
			updatable = false;
		}
		prop.setNaturalIdentifier( true );
	}

	// HHH-4635 -- needed for dialect-specific property ordering
	Lob lob = property != null ? property.getAnnotation( Lob.class ) : null;
	prop.setLob( lob != null );

	prop.setInsertable( insertable );
	prop.setUpdateable( updatable );

	// this is already handled for collections in CollectionBinder...
	if ( Collection.class.isInstance( value ) ) {
		prop.setOptimisticLocked( ( (Collection) value ).isOptimisticLocked() );
	}
	else {
		final OptimisticLock lockAnn = property != null
				? property.getAnnotation( OptimisticLock.class )
				: null;
		if ( lockAnn != null ) {
			//TODO this should go to the core as a mapping validation checking
			if ( lockAnn.excluded() && (
					property.isAnnotationPresent( javax.persistence.Version.class )
							|| property.isAnnotationPresent( Id.class )
							|| property.isAnnotationPresent( EmbeddedId.class ) ) ) {
				throw new AnnotationException(
						"@OptimisticLock.exclude=true incompatible with @Id, @EmbeddedId and @Version: "
								+ StringHelper.qualify( holder.getPath(), name )
				);
			}
		}
		final boolean isOwnedValue = !isToOneValue( value ) || insertable; // && updatable as well???
		final boolean includeInOptimisticLockChecks = ( lockAnn != null )
				? ! lockAnn.excluded()
				: isOwnedValue;
		prop.setOptimisticLocked( includeInOptimisticLockChecks );
	}

	LOG.tracev( "Cascading {0} with {1}", name, cascade );
	this.mappingProperty = prop;
	return prop;
}
 
Example 18
Source File: AbstractEntityPersister.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private String generateGeneratedValuesSelectString(final GenerationTiming generationTimingToMatch) {
	Select select = new Select( getFactory().getDialect() );

	if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) {
		select.setComment( "get generated state " + getEntityName() );
	}

	String[] aliasedIdColumns = StringHelper.qualify( getRootAlias(), getIdentifierColumnNames() );

	// Here we render the select column list based on the properties defined as being generated.
	// For partial component generation, we currently just re-select the whole component
	// rather than trying to handle the individual generated portions.
	String selectClause = concretePropertySelectFragment(
			getRootAlias(),
			new InclusionChecker() {
				@Override
				public boolean includeProperty(int propertyNumber) {
					final InDatabaseValueGenerationStrategy generationStrategy
							= entityMetamodel.getInDatabaseValueGenerationStrategies()[propertyNumber];
					return generationStrategy != null
							&& timingsMatch( generationStrategy.getGenerationTiming(), generationTimingToMatch );
				}
			}
	);
	selectClause = selectClause.substring( 2 );

	String fromClause = fromTableFragment( getRootAlias() ) +
			fromJoinFragment( getRootAlias(), true, false );

	String whereClause = new StringBuilder()
			.append( String.join( "=? and ", aliasedIdColumns ) )
			.append( "=?" )
			.append( whereJoinFragment( getRootAlias(), true, false ) )
			.toString();

	return select.setSelectClause( selectClause )
			.setFromClause( fromClause )
			.setOuterJoins( "", "" )
			.setWhereClause( whereClause )
			.toStatementString();
}
 
Example 19
Source File: AbstractEntityPersister.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
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 StringBuilder whereClause = new StringBuilder();
	final int[] propertyTableNumbers = getPropertyTableNumbers();
	final int[] naturalIdPropertyIndexes = this.getNaturalIdentifierProperties();
	int valuesIndex = -1;
	for ( int propIdx = 0; propIdx < naturalIdPropertyIndexes.length; propIdx++ ) {
		valuesIndex++;
		if ( propIdx > 0 ) {
			whereClause.append( " and " );
		}

		final int naturalIdIdx = naturalIdPropertyIndexes[propIdx];
		final String tableAlias = generateTableAlias( rootAlias, propertyTableNumbers[naturalIdIdx] );
		final String[] propertyColumnNames = getPropertyColumnNames( naturalIdIdx );
		final String[] aliasedPropertyColumns = StringHelper.qualify( tableAlias, propertyColumnNames );

		if ( valueNullness != null && valueNullness[valuesIndex] ) {
			whereClause.append( String.join( " is null and ", aliasedPropertyColumns ) ).append( " is null" );
		}
		else {
			whereClause.append( String.join( "=? and ", aliasedPropertyColumns ) ).append( "=?" );
		}
	}

	whereClause.append( whereJoinFragment( getRootAlias(), true, false ) );

	return select.setOuterJoins( "", "" ).setWhereClause( whereClause.toString() ).toStatementString();
}
 
Example 20
Source File: PrimaryKey.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String getExportIdentifier() {
	return StringHelper.qualify( getTable().getName(), "PK-" + getName() );
}