use of org.hibernate.type.CollectionType in project hibernate-orm by hibernate.
the class DotNode method resolveIndex.
public void resolveIndex(AST parent) throws SemanticException {
if (isResolved()) {
return;
}
// Prepare the left hand side and get the data type.
Type propertyType = prepareLhs();
dereferenceCollection((CollectionType) propertyType, true, true, null, parent);
}
use of org.hibernate.type.CollectionType in project hibernate-orm by hibernate.
the class PathExpressionParser method token.
public void token(String token, QueryTranslatorImpl q) throws QueryException {
if (token != null) {
path.append(token);
}
String alias = q.getPathAlias(path.toString());
if (alias != null) {
//reset the dotcount (but not the path)
reset(q);
//afterQuery reset!
currentName = alias;
currentPropertyMapping = q.getPropertyMapping(currentName);
if (!ignoreInitialJoin) {
JoinSequence ojf = q.getPathJoin(path.toString());
try {
//afterQuery reset!
joinSequence.addCondition(ojf.toJoinFragment(q.getEnabledFilters(), true).toWhereFragmentString());
} catch (MappingException me) {
throw new QueryException(me);
}
// we don't need to worry about any condition in the ON clause
// here (toFromFragmentString), since anything in the ON condition
// is already applied to the whole query
}
} else if (".".equals(token)) {
dotcount++;
} else {
if (dotcount == 0) {
if (!continuation) {
if (!q.isName(token)) {
throw new QueryException("undefined alias: " + token);
}
currentName = token;
currentPropertyMapping = q.getPropertyMapping(currentName);
}
} else if (dotcount == 1) {
if (currentName != null) {
currentProperty = token;
} else if (collectionName != null) {
//processCollectionProperty(token, q.getCollectionPersister(collectionRole), collectionName);
continuation = false;
} else {
throw new QueryException("unexpected");
}
} else {
// dotcount>=2
// Do the corresponding RHS
Type propertyType = getPropertyType();
if (propertyType == null) {
throw new QueryException("unresolved property: " + path);
}
if (propertyType.isComponentType()) {
dereferenceComponent(token);
} else if (propertyType.isEntityType()) {
if (!isCollectionValued()) {
dereferenceEntity(token, (EntityType) propertyType, q);
}
} else if (propertyType.isCollectionType()) {
dereferenceCollection(token, ((CollectionType) propertyType).getRole(), q);
} else {
if (token != null) {
throw new QueryException("dereferenced: " + path);
}
}
}
}
}
use of org.hibernate.type.CollectionType in project hibernate-orm by hibernate.
the class PathExpressionParser method end.
public void end(QueryTranslatorImpl q) throws QueryException {
ignoreInitialJoin = false;
Type propertyType = getPropertyType();
if (propertyType != null && propertyType.isCollectionType()) {
collectionRole = ((CollectionType) propertyType).getRole();
collectionName = q.createNameForCollection(collectionRole);
prepareForIndex(q);
} else {
columns = currentColumns();
setType();
}
//important!!
continuation = false;
}
use of org.hibernate.type.CollectionType in project hibernate-orm by hibernate.
the class AbstractInlineIdsDeleteHandlerImpl method execute.
@Override
public int execute(SharedSessionContractImplementor session, QueryParameters queryParameters) {
IdsClauseBuilder values = prepareInlineStatement(session, queryParameters);
if (!values.getIds().isEmpty()) {
final String idSubselect = values.toStatement();
for (Type type : getTargetedQueryable().getPropertyTypes()) {
if (type.isCollectionType()) {
CollectionType cType = (CollectionType) type;
AbstractCollectionPersister cPersister = (AbstractCollectionPersister) factory().getMetamodel().collectionPersister(cType.getRole());
if (cPersister.isManyToMany()) {
deletes.add(generateDelete(cPersister.getTableName(), cPersister.getKeyColumnNames(), idSubselect, "bulk delete - m2m join table cleanup").toStatementString());
}
}
}
String[] tableNames = getTargetedQueryable().getConstraintOrderedTableNameClosure();
String[][] columnNames = getTargetedQueryable().getContraintOrderedTableKeyColumnClosure();
for (int i = 0; i < tableNames.length; i++) {
// TODO : an optimization here would be to consider cascade deletes and not gen those delete statements;
// the difficulty is the ordering of the tables here vs the cascade attributes on the persisters ->
// the table info gotten here should really be self-contained (i.e., a class representation
// defining all the needed attributes), then we could then get an array of those
deletes.add(generateDelete(tableNames[i], columnNames[i], idSubselect, "bulk delete").toStatementString());
}
// Start performing the deletes
for (String delete : deletes) {
if (delete == null) {
continue;
}
try {
try (PreparedStatement ps = session.getJdbcCoordinator().getStatementPreparer().prepareStatement(delete, false)) {
session.getJdbcCoordinator().getResultSetReturn().executeUpdate(ps);
}
} catch (SQLException e) {
throw convert(e, "error performing bulk delete", delete);
}
}
}
return values.getIds().size();
}
use of org.hibernate.type.CollectionType in project hibernate-orm by hibernate.
the class QuerySpaceHelper method makeCollectionQuerySpace.
public ExpandingCollectionQuerySpace makeCollectionQuerySpace(ExpandingQuerySpace lhsQuerySpace, AssociationAttributeDefinition attributeDefinition, String querySpaceUid, FetchStrategy fetchStrategy) {
final CollectionType fetchedType = (CollectionType) attributeDefinition.getType();
final CollectionPersister fetchedPersister = attributeDefinition.toCollectionDefinition().getCollectionPersister();
if (fetchedPersister == null) {
throw new WalkingException(String.format("Unable to locate CollectionPersister [%s] for fetch [%s]", fetchedType.getRole(), attributeDefinition.getName()));
}
final boolean required = lhsQuerySpace.canJoinsBeRequired() && !attributeDefinition.isNullable();
final ExpandingCollectionQuerySpace rhs = lhsQuerySpace.getExpandingQuerySpaces().makeCollectionQuerySpace(querySpaceUid, fetchedPersister, required);
if (shouldIncludeJoin(fetchStrategy)) {
final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createCollectionJoin(lhsQuerySpace, attributeDefinition.getName(), rhs, required, (CollectionType) attributeDefinition.getType(), fetchedPersister.getFactory());
lhsQuerySpace.addJoin(join);
}
return rhs;
}
Aggregations