org.hibernate.loader.custom.ScalarReturn Java Examples

The following examples show how to use org.hibernate.loader.custom.ScalarReturn. 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: IgniteQueryRenderer.java    From hibernate-ogm-ignite with GNU Lesser General Public License v2.1 6 votes vote down vote up
public IgniteQueryParsingResult getResult() {
	StringBuilder queryBuilder = new StringBuilder();
	List<ScalarReturn> selections = select( queryBuilder );
	from( queryBuilder );
	if ( !StringHelper.isEmpty( from ) ) {
		queryBuilder.append( ' ' ).append( from );
	}
	if ( !StringHelper.isEmpty( where ) ) {
		queryBuilder.append( " WHERE " ).append( where );
	}
	if ( !StringHelper.isEmpty( orderBy ) ) {
		queryBuilder.append( " ORDER BY " ).append( orderBy );
	}

	IgniteQueryDescriptor queryDescriptor = new IgniteQueryDescriptor(
		queryBuilder.toString(), indexedParameters, !selections.isEmpty(),
		propertyHelper.getKeyMetaData( propertyHelper.getRootEntity() ), selections );

	List<String> selectionAliases = selections.isEmpty()
		? ENTITY_COLUMN_NAMES
		: selections.stream().map( ScalarReturn::getColumnAlias ).collect( toList() );

	return new IgniteQueryParsingResult( queryDescriptor, selectionAliases );
}
 
Example #2
Source File: IgniteQueryDescriptor.java    From hibernate-ogm-ignite with GNU Lesser General Public License v2.1 5 votes vote down vote up
public IgniteQueryDescriptor(String sql, List<Object> indexedParameters,
		boolean hasScalar, EntityKeyMetadata rootKeyMetadata,
		List<ScalarReturn> queryReturns) {
	this.sql = sql;
	this.indexedParameters = indexedParameters;
	this.hasScalar = hasScalar;
	this.rootKeyMetadata = rootKeyMetadata;
	this.queryReturns = queryReturns;
}
 
Example #3
Source File: IgniteQueryDescriptor.java    From hibernate-ogm-ignite with GNU Lesser General Public License v2.1 4 votes vote down vote up
public List<ScalarReturn> getQueryReturns() {
	return queryReturns;
}
 
Example #4
Source File: IgniteQueryRenderer.java    From hibernate-ogm-ignite with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Appends SELECT clause in query builder and returns either
 * list of selections if a query is a projection query, or empty
 * list if a single entity query
 */
private List<ScalarReturn> select(StringBuilder queryBuilder) {
	queryBuilder.append( "SELECT " );
	String rootAlias = propertyHelper.findAliasForType( propertyHelper.getRootEntity() );

	// is selected unqualified root entity (e.g. "from Hypothesis"),
	// or a single entity defined by alias (e.g. "select h from Hypothesis h")
	if ( propertyHelper.getSelections().isEmpty()
		|| ( propertyHelper.getSelections().size() == 1
		&& propertyHelper.getSelections().get( 0 ).getNodeNamesWithoutAlias().isEmpty() ) ) {
		String selectionAlias = propertyHelper.getSelections().isEmpty()
			? rootAlias
			: propertyHelper.getSelections().get( 0 ).getFirstNode().getName();
		queryBuilder
			.append( selectionAlias ).append( "._KEY, " )
			.append( selectionAlias ).append( "._VAL" );
		return Collections.emptyList();
	}

	// else, treat as projection selection
	List<ScalarReturn> selections = new ArrayList<>();
	int columnNumber = 0;
	Iterator<PropertyPath> i = propertyHelper.getSelections().iterator();
	while ( i.hasNext() ) {
		PropertyPath path = i.next();
		String alias = path.getFirstNode().isAlias()
			? path.getFirstNode().getName() : rootAlias;

		String columnName;
		List<String> propertyPath = path.getNodeNamesWithoutAlias();
		String entityType = propertyHelper.getEntityNameByAlias( alias );
		Type type = propertyHelper.getPropertyType( entityType, propertyPath );
		if ( type.isEntityType() ) {
			// though it may be better to load both key and value
			// in one query, OgmQueryLoader requires only key
			columnName = "_KEY";
		}
		else if ( type.isComponentType() ) {
			throw new NotYetImplementedException( "Embeddables in projection selection" );
		}
		else {
			columnName = propertyHelper.getColumnName( entityType, propertyPath );
			EntityKeyMetadata entityKey = propertyHelper.getKeyMetaData( entityType );
			if ( entityKey.getColumnNames().length == 1
				&& entityKey.getColumnNames()[0].equals( columnName ) ) {
				columnName = "_KEY";
			}
		}
		String columnAlias = "col_" + ( columnNumber++ );
		queryBuilder
			.append( alias ).append( '.' ).append( columnName )
			.append( " as " ).append( columnAlias );
		selections.add( new ScalarReturn( type, columnAlias ) );

		if ( i.hasNext() ) {
			queryBuilder.append( ',' ).append( ' ' );
		}
	}
	return selections;
}
 
Example #5
Source File: IgniteDialect.java    From hibernate-ogm-ignite with GNU Lesser General Public License v2.1 4 votes vote down vote up
ProjectionResultCursor(Iterable<List<?>> resultCursor, List<ScalarReturn> queryReturns, RowSelection rowSelection) {
	super( resultCursor, rowSelection );
	this.queryReturns = queryReturns;
}