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));
}
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);
}
}
}
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);
}
}
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);
}
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()]);
}
Aggregations