Search in sources :

Example 11 with Queryable

use of org.hibernate.persister.entity.Queryable in project hibernate-orm by hibernate.

the class PersistentTableBulkIdStrategy method buildUpdateHandler.

@Override
public UpdateHandler buildUpdateHandler(SessionFactoryImplementor factory, HqlSqlWalker walker) {
    final UpdateStatement updateStatement = (UpdateStatement) walker.getAST();
    final FromElement fromElement = updateStatement.getFromClause().getFromElement();
    final Queryable targetedPersister = fromElement.getQueryable();
    return new UpdateHandlerImpl(factory, walker, getIdTableInfo(targetedPersister));
}
Also used : UpdateStatement(org.hibernate.hql.internal.ast.tree.UpdateStatement) FromElement(org.hibernate.hql.internal.ast.tree.FromElement) Queryable(org.hibernate.persister.entity.Queryable)

Example 12 with Queryable

use of org.hibernate.persister.entity.Queryable in project hibernate-orm by hibernate.

the class LiteralProcessor method processConstant.

public void processConstant(AST constant, boolean resolveIdent) throws SemanticException {
    // If the constant is an IDENT, figure out what it means...
    boolean isIdent = (constant.getType() == IDENT || constant.getType() == WEIRD_IDENT);
    if (resolveIdent && isIdent && isAlias(constant.getText())) {
        // IDENT is a class alias in the FROM.
        IdentNode ident = (IdentNode) constant;
        // Resolve to an identity column.
        ident.resolve(false, true);
    } else {
        // IDENT might be the name of a class.
        Queryable queryable = walker.getSessionFactoryHelper().findQueryableUsingImports(constant.getText());
        if (isIdent && queryable != null) {
            constant.setText(queryable.getDiscriminatorSQLValue());
        } else // Otherwise, it's a literal.
        {
            processLiteral(constant);
        }
    }
}
Also used : Queryable(org.hibernate.persister.entity.Queryable) IdentNode(org.hibernate.hql.internal.ast.tree.IdentNode)

Example 13 with Queryable

use of org.hibernate.persister.entity.Queryable in project hibernate-orm by hibernate.

the class LiteralProcessor method lookupConstant.

public void lookupConstant(DotNode node) throws SemanticException {
    String text = ASTUtil.getPathText(node);
    Queryable persister = walker.getSessionFactoryHelper().findQueryableUsingImports(text);
    if (persister != null) {
        // the name of an entity class
        final String discrim = persister.getDiscriminatorSQLValue();
        node.setDataType(persister.getDiscriminatorType());
        if (InFragment.NULL.equals(discrim) || InFragment.NOT_NULL.equals(discrim)) {
            throw new InvalidPathException("subclass test not allowed for null or not null discriminator: '" + text + "'");
        }
        // the class discriminator value
        setSQLValue(node, text, discrim);
    } else {
        Object value = ReflectHelper.getConstantValue(text, walker.getSessionFactoryHelper().getFactory());
        if (value == null) {
            throw new InvalidPathException("Invalid path: '" + text + "'");
        }
        setConstantValue(node, text, value);
    }
}
Also used : Queryable(org.hibernate.persister.entity.Queryable) InvalidPathException(org.hibernate.hql.internal.ast.InvalidPathException)

Example 14 with Queryable

use of org.hibernate.persister.entity.Queryable in project hibernate-orm by hibernate.

the class CriteriaQueryTranslator method getTypedValue.

/**
	 * Get the a typed value for the given property value.
	 */
@Override
public TypedValue getTypedValue(Criteria subcriteria, String propertyName, Object value) throws HibernateException {
    // Detect discriminator values...
    if (value instanceof Class) {
        final Class entityClass = (Class) value;
        final Queryable q = SessionFactoryHelper.findQueryableUsingImports(sessionFactory, entityClass.getName());
        if (q != null) {
            final Type type = q.getDiscriminatorType();
            String stringValue = q.getDiscriminatorSQLValue();
            if (stringValue != null && stringValue.length() > 2 && stringValue.startsWith("'") && stringValue.endsWith("'")) {
                // remove the single quotes
                stringValue = stringValue.substring(1, stringValue.length() - 1);
            }
            // Convert the string value into the proper type.
            if (type instanceof StringRepresentableType) {
                final StringRepresentableType nullableType = (StringRepresentableType) type;
                value = nullableType.fromStringValue(stringValue);
            } else {
                throw new QueryException("Unsupported discriminator type " + type);
            }
            return new TypedValue(type, value);
        }
    }
    // Otherwise, this is an ordinary value.
    return new TypedValue(getTypeUsingProjection(subcriteria, propertyName), value);
}
Also used : StringRepresentableType(org.hibernate.type.StringRepresentableType) CollectionType(org.hibernate.type.CollectionType) JoinType(org.hibernate.sql.JoinType) AssociationType(org.hibernate.type.AssociationType) Type(org.hibernate.type.Type) QueryException(org.hibernate.QueryException) StringRepresentableType(org.hibernate.type.StringRepresentableType) Queryable(org.hibernate.persister.entity.Queryable) TypedValue(org.hibernate.engine.spi.TypedValue)

Example 15 with Queryable

use of org.hibernate.persister.entity.Queryable in project hibernate-orm by hibernate.

the class MetamodelImpl method getImplementors.

/**
	 * Given the name of an entity class, determine all the class and interface names by which it can be
	 * referenced in an HQL query.
	 *
	 * @param className The name of the entity class
	 *
	 * @return the names of all persistent (mapped) classes that extend or implement the
	 *     given class or interface, accounting for implicit/explicit polymorphism settings
	 *     and excluding mapped subclasses/joined-subclasses of other classes in the result.
	 * @throws MappingException
	 */
public String[] getImplementors(String className) throws MappingException {
    final Class clazz;
    try {
        clazz = getSessionFactory().getServiceRegistry().getService(ClassLoaderService.class).classForName(className);
    } catch (ClassLoadingException e) {
        //for a dynamic-class
        return new String[] { className };
    }
    ArrayList<String> results = new ArrayList<>();
    for (EntityPersister checkPersister : entityPersisters().values()) {
        if (!Queryable.class.isInstance(checkPersister)) {
            continue;
        }
        final Queryable checkQueryable = Queryable.class.cast(checkPersister);
        final String checkQueryableEntityName = checkQueryable.getEntityName();
        final boolean isMappedClass = className.equals(checkQueryableEntityName);
        if (checkQueryable.isExplicitPolymorphism()) {
            if (isMappedClass) {
                //NOTE EARLY EXIT
                return new String[] { className };
            }
        } else {
            if (isMappedClass) {
                results.add(checkQueryableEntityName);
            } else {
                final Class mappedClass = checkQueryable.getMappedClass();
                if (mappedClass != null && clazz.isAssignableFrom(mappedClass)) {
                    final boolean assignableSuperclass;
                    if (checkQueryable.isInherited()) {
                        Class mappedSuperclass = entityPersister(checkQueryable.getMappedSuperclass()).getMappedClass();
                        assignableSuperclass = clazz.isAssignableFrom(mappedSuperclass);
                    } else {
                        assignableSuperclass = false;
                    }
                    if (!assignableSuperclass) {
                        results.add(checkQueryableEntityName);
                    }
                }
            }
        }
    }
    return results.toArray(new String[results.size()]);
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) Queryable(org.hibernate.persister.entity.Queryable) ArrayList(java.util.ArrayList) PersistentClass(org.hibernate.mapping.PersistentClass)

Aggregations

Queryable (org.hibernate.persister.entity.Queryable)34 QueryException (org.hibernate.QueryException)10 FromElement (org.hibernate.hql.internal.ast.tree.FromElement)8 Type (org.hibernate.type.Type)7 CollectionType (org.hibernate.type.CollectionType)5 EntityType (org.hibernate.type.EntityType)5 SharedSessionContractImplementor (org.hibernate.engine.spi.SharedSessionContractImplementor)4 UpdateStatement (org.hibernate.hql.internal.ast.tree.UpdateStatement)4 DeleteStatement (org.hibernate.hql.internal.ast.tree.DeleteStatement)3 QueryableCollection (org.hibernate.persister.collection.QueryableCollection)3 EntityPersister (org.hibernate.persister.entity.EntityPersister)3 JoinType (org.hibernate.sql.JoinType)3 AST (antlr.collections.AST)2 InsertStatement (org.hibernate.hql.internal.ast.tree.InsertStatement)2 ParameterNode (org.hibernate.hql.internal.ast.tree.ParameterNode)2 TableBasedDeleteHandlerImpl (org.hibernate.hql.spi.id.TableBasedDeleteHandlerImpl)2 TableBasedUpdateHandlerImpl (org.hibernate.hql.spi.id.TableBasedUpdateHandlerImpl)2 CollectionFilterKeyParameterSpecification (org.hibernate.param.CollectionFilterKeyParameterSpecification)2 NamedParameterSpecification (org.hibernate.param.NamedParameterSpecification)2 ParameterSpecification (org.hibernate.param.ParameterSpecification)2