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

The following examples show how to use org.hibernate.internal.util.StringHelper#replace() . 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: FilterHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private String render(FilterAliasGenerator aliasGenerator, int filterIndex) {
	Map<String, String> aliasTableMap = filterAliasTableMaps[filterIndex];
	String condition = filterConditions[filterIndex];
	if ( filterAutoAliasFlags[filterIndex] ) {
		return StringHelper.replace(
				condition,
				FilterImpl.MARKER,
				aliasGenerator.getAlias( aliasTableMap.get( null ) )
		);
	}
	else if ( isTableFromPersistentClass( aliasTableMap ) ) {
		return condition.replace( "{alias}", aliasGenerator.getAlias( aliasTableMap.get( null ) ) );
	}
	else {
		for ( Map.Entry<String, String> entry : aliasTableMap.entrySet() ) {
			condition = condition.replace(
					"{" + entry.getKey() + "}",
					aliasGenerator.getAlias( entry.getValue() )
			);
		}
		return condition;
	}
}
 
Example 2
Source File: AbstractPropertyMapping.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public String[] toColumns(String alias, String propertyName) throws QueryException {
	//TODO: *two* hashmap lookups here is one too many...
	String[] columns = columnsByPropertyPath.get( propertyName );
	if ( columns == null ) {
		throw propertyException( propertyName );
	}
	String[] formulaTemplates = formulaTemplatesByPropertyPath.get( propertyName );
	String[] columnReaderTemplates = columnReaderTemplatesByPropertyPath.get( propertyName );
	String[] result = new String[columns.length];
	for ( int i = 0; i < columns.length; i++ ) {
		if ( columnReaderTemplates[i] == null ) {
			result[i] = StringHelper.replace( formulaTemplates[i], Template.TEMPLATE, alias );
		}
		else {
			result[i] = StringHelper.replace( columnReaderTemplates[i], Template.TEMPLATE, alias );
		}
	}
	return result;
}
 
Example 3
Source File: AbstractPropertyMapping.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public String[] toColumns(String propertyName) throws QueryException {
	String[] columns = columnsByPropertyPath.get( propertyName );
	if ( columns == null ) {
		throw propertyException( propertyName );
	}
	String[] formulaTemplates = formulaTemplatesByPropertyPath.get( propertyName );
	String[] columnReaders = columnReadersByPropertyPath.get( propertyName );
	String[] result = new String[columns.length];
	for ( int i = 0; i < columns.length; i++ ) {
		if ( columnReaders[i] == null ) {
			result[i] = StringHelper.replace( formulaTemplates[i], Template.TEMPLATE, "" );
		}
		else {
			result[i] = columnReaders[i];
		}
	}
	return result;
}
 
Example 4
Source File: ReactiveDynamicBatchingEntityLoader.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
static String expandBatchIdPlaceholder(
		String sql,
		Serializable[] ids,
		String alias,
		String[] keyColumnNames,
		Dialect dialect) {
	if ( keyColumnNames.length == 1 ) {
		// non-composite
		return StringHelper.replace( sql, StringHelper.BATCH_ID_PLACEHOLDER, StringHelper.repeat( "?", ids.length, "," ) );
	}
	else {
		// composite
		if ( dialect.supportsRowValueConstructorSyntaxInInList() ) {
			final String tuple = '(' + StringHelper.repeat( "?", keyColumnNames.length, "," ) + ')';
			return StringHelper.replace( sql, StringHelper.BATCH_ID_PLACEHOLDER, StringHelper.repeat( tuple, ids.length, "," ) );
		}
		else {
			final String keyCheck = '(' + StringHelper.joinWithQualifierAndSuffix(
					keyColumnNames,
					alias,
					" = ?",
					" and "
			) + ')';
			return StringHelper.replace( sql, StringHelper.BATCH_ID_PLACEHOLDER, StringHelper.repeat( keyCheck, ids.length, " or " ) );
		}
	}
}
 
Example 5
Source File: FilterHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The map of defined filters.  This is expected to be in format
 * where the filter names are the map keys, and the defined
 * conditions are the values.
 *
 * @param filters The map of defined filters.
 * @param factory The session factory
 */
public FilterHelper(List<FilterConfiguration> filters, SessionFactoryImplementor factory) {
	int filterCount = filters.size();
	filterNames = new String[filterCount];
	filterConditions = new String[filterCount];
	filterAutoAliasFlags = new boolean[filterCount];
	filterAliasTableMaps = new Map[filterCount];
	filterCount = 0;
	for ( final FilterConfiguration filter : filters ) {
		filterAutoAliasFlags[filterCount] = false;
		filterNames[filterCount] = filter.getName();
		filterConditions[filterCount] = filter.getCondition();
		filterAliasTableMaps[filterCount] = filter.getAliasTableMap( factory );
		if ( ( filterAliasTableMaps[filterCount].isEmpty() || isTableFromPersistentClass( filterAliasTableMaps[filterCount] ) ) && filter
				.useAutoAliasInjection() ) {
			filterConditions[filterCount] = Template.renderWhereStringTemplate(
					filter.getCondition(),
					FilterImpl.MARKER,
					factory.getDialect(),
					factory.getSqlFunctionRegistry()
			);
			filterAutoAliasFlags[filterCount] = true;
		}
		filterConditions[filterCount] = StringHelper.replace(
				filterConditions[filterCount],
				":",
				":" + filterNames[filterCount] + "."
		);
		filterCount++;
	}
}
 
Example 6
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 7
Source File: AbstractCollectionPersister.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static String[] qualify(String alias, String[] columnNames, 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;
}
 
Example 8
Source File: SyntheticAndFactory.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void addDiscriminatorWhereFragment(
		RestrictableStatement statement,
		Queryable persister,
		Map enabledFilters,
		String alias) {
	String whereFragment = persister.filterFragment( alias, enabledFilters ).trim();
	if ( "".equals( whereFragment ) ) {
		return;
	}
	if ( whereFragment.startsWith( "and" ) ) {
		whereFragment = whereFragment.substring( 4 );
	}

	// Need to parse off the column qualifiers; this is assuming (which is true as of now)
	// that this is only used from update and delete HQL statement parsing
	whereFragment = StringHelper.replace(
			whereFragment,
			persister.generateFilterConditionAlias( alias ) + ".",
			""
	);

	// Note: this simply constructs a "raw" SQL_TOKEN representing the
	// where fragment and injects this into the tree.  This "works";
	// however it is probably not the best long-term solution.
	//
	// At some point we probably want to apply an additional grammar to
	// properly tokenize this where fragment into constituent parts
	// focused on the operators embedded within the fragment.
	SqlFragment discrimNode = (SqlFragment) create( SQL_TOKEN, whereFragment );

	JoinProcessor.processDynamicFilterParameters(
			whereFragment,
			discrimNode,
			hqlSqlWalker
	);

	if ( statement.getWhereClause().getNumberOfChildren() == 0 ) {
		statement.getWhereClause().setFirstChild( discrimNode );
	}
	else {
		AST and = create( AND, "{and}" );
		AST currentFirstChild = statement.getWhereClause().getFirstChild();
		and.setFirstChild( discrimNode );
		and.addChild( currentFirstChild );
		statement.getWhereClause().setFirstChild( and );
	}
}
 
Example 9
Source File: SimpleAuxiliaryDatabaseObject.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private String injectCatalogAndSchema(String ddlString) {
	String rtn = StringHelper.replace( ddlString, CATALOG_NAME_PLACEHOLDER, catalogName == null ? "" : catalogName );
	rtn = StringHelper.replace( rtn, SCHEMA_NAME_PLACEHOLDER, schemaName == null ? "" : schemaName );
	return rtn;
}
 
Example 10
Source File: InFragment.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public InFragment setFormula(String alias, String formulaTemplate) {
	this.columnName = StringHelper.replace( formulaTemplate, Template.TEMPLATE, alias );
	return setColumn( this.columnName );
}
 
Example 11
Source File: AbstractCollectionPersister.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected String getSQLWhereString(String alias) {
	return StringHelper.replace( sqlWhereStringTemplate, Template.TEMPLATE, alias );
}
 
Example 12
Source File: AbstractEntityPersister.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected String getSQLWhereString(String alias) {
	return StringHelper.replace( sqlWhereStringTemplate, Template.TEMPLATE, alias );
}
 
Example 13
Source File: AbstractEntityPersister.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
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 selectFragment = new SelectFragment();
	selectFragment.addColumns( rooAlias, getIdentifierColumnNames(), getIdentifierAliases() );
	select.setSelectClause( selectFragment );

	StringBuilder whereClauseBuffer = new StringBuilder();
	final int uniquePropertyIndex = getSubclassPropertyIndex( uniquePropertyName );
	final String uniquePropertyTableAlias = generateTableAlias(
			rooAlias,
			getSubclassPropertyTableNumber( uniquePropertyIndex )
	);
	String sep = "";
	for ( String columnTemplate : getSubclassPropertyColumnReaderTemplateClosure()[uniquePropertyIndex] ) {
		if ( columnTemplate == null ) {
			continue;
		}
		final String columnReference = StringHelper.replace(
				columnTemplate,
				Template.TEMPLATE,
				uniquePropertyTableAlias
		);
		whereClauseBuffer.append( sep ).append( columnReference ).append( "=?" );
		sep = " and ";
	}
	for ( String formulaTemplate : getSubclassPropertyFormulaTemplateClosure()[uniquePropertyIndex] ) {
		if ( formulaTemplate == null ) {
			continue;
		}
		final String formulaReference = StringHelper.replace(
				formulaTemplate,
				Template.TEMPLATE,
				uniquePropertyTableAlias
		);
		whereClauseBuffer.append( sep ).append( formulaReference ).append( "=?" );
		sep = " and ";
	}
	whereClauseBuffer.append( whereJoinFragment( rooAlias, true, false ) );

	select.setWhereClause( whereClauseBuffer.toString() );

	return select.setOuterJoins( "", "" ).toStatementString();
}
 
Example 14
Source File: SQLCriterion.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
	return StringHelper.replace( sql, "{alias}", criteriaQuery.getSQLAlias( criteria ) );
}
 
Example 15
Source File: SQLProjection.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String toGroupSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
	return StringHelper.replace( groupBy, "{alias}", criteriaQuery.getSQLAlias( criteria ) );
}
 
Example 16
Source File: SQLProjection.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery) {
	return StringHelper.replace( sql, "{alias}", criteriaQuery.getSQLAlias( criteria ) );
}
 
Example 17
Source File: Formula.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String getTemplate(Dialect dialect, SQLFunctionRegistry functionRegistry) {
	String template = Template.renderWhereStringTemplate(formula, dialect, functionRegistry);
	return StringHelper.replace( template, "{alias}", Template.TEMPLATE );
}