use of org.hibernate.Criteria in project hibernate-orm by hibernate.
the class CriteriaJoinWalker method generateTableAlias.
@Override
protected String generateTableAlias(int n, PropertyPath path, Joinable joinable) {
// TODO: deal with side-effects (changes to includeInResultRowList, userAliasList, resultTypeList)!!!
// for collection-of-entity, we are called twice for given "path"
// once for the collection Joinable, once for the entity Joinable.
// the second call will/must "consume" the alias + perform side effects according to consumesEntityAlias()
// for collection-of-other, however, there is only one call
// it must "consume" the alias + perform side effects, despite what consumeEntityAlias() return says
//
// note: the logic for adding to the userAliasList is still strictly based on consumesEntityAlias return value
boolean checkForSqlAlias = joinable.consumesEntityAlias();
if (!checkForSqlAlias && joinable.isCollection()) {
// is it a collection-of-other (component or value) ?
CollectionPersister collectionPersister = (CollectionPersister) joinable;
Type elementType = collectionPersister.getElementType();
if (elementType.isComponentType() || !elementType.isEntityType()) {
checkForSqlAlias = true;
}
}
String sqlAlias = null;
if (checkForSqlAlias) {
final Criteria subcriteria = translator.getCriteria(path.getFullPath());
sqlAlias = subcriteria == null ? null : translator.getSQLAlias(subcriteria);
if (joinable.consumesEntityAlias() && !translator.hasProjection()) {
includeInResultRowList.add(subcriteria != null && subcriteria.getAlias() != null);
if (sqlAlias != null) {
if (subcriteria.getAlias() != null) {
userAliasList.add(subcriteria.getAlias());
resultTypeList.add(translator.getResultType(subcriteria));
}
}
}
}
if (sqlAlias == null) {
sqlAlias = super.generateTableAlias(n + translator.getSQLAliasCount(), path, joinable);
}
return sqlAlias;
}
use of org.hibernate.Criteria in project hibernate-orm by hibernate.
the class CriteriaQueryTranslator method createCriteriaEntityNameMap.
private void createCriteriaEntityNameMap() {
// initialize the rootProvider first
final CriteriaInfoProvider rootProvider = new EntityCriteriaInfoProvider((Queryable) sessionFactory.getEntityPersister(rootEntityName));
criteriaInfoMap.put(rootCriteria, rootProvider);
nameCriteriaInfoMap.put(rootProvider.getName(), rootProvider);
for (final String key : associationPathCriteriaMap.keySet()) {
final Criteria value = associationPathCriteriaMap.get(key);
final CriteriaInfoProvider info = getPathInfo(key);
criteriaInfoMap.put(value, info);
nameCriteriaInfoMap.put(info.getName(), info);
}
}
use of org.hibernate.Criteria in project hibernate-orm by hibernate.
the class CriteriaQueryTranslator method getEntityName.
//TODO: use these in methods above
@Override
public String getEntityName(Criteria subcriteria, String propertyName) {
if (propertyName.indexOf('.') > 0) {
final String root = StringHelper.root(propertyName);
final Criteria crit = getAliasedCriteria(root);
if (crit != null) {
return getEntityName(crit);
}
}
return getEntityName(subcriteria);
}
use of org.hibernate.Criteria in project hibernate-orm by hibernate.
the class CriteriaQueryTranslator method getWholeAssociationPath.
private String getWholeAssociationPath(CriteriaImpl.Subcriteria subcriteria) {
String path = subcriteria.getPath();
// some messy, complex stuff here, since createCriteria() can take an
// aliased path, or a path rooted at the creating criteria instance
Criteria parent = null;
if (path.indexOf('.') > 0) {
// if it is a compound path
String testAlias = StringHelper.root(path);
if (!testAlias.equals(subcriteria.getAlias())) {
// and the qualifier is not the alias of this criteria
// -> check to see if we belong to some criteria other
// than the one that created us
parent = aliasCriteriaMap.get(testAlias);
}
}
if (parent == null) {
// otherwise assume the parent is the the criteria that created us
parent = subcriteria.getParent();
} else {
path = StringHelper.unroot(path);
}
if (parent.equals(rootCriteria)) {
// if its the root criteria, we are done
return path;
} else {
// otherwise, recurse
return getWholeAssociationPath((CriteriaImpl.Subcriteria) parent) + '.' + path;
}
}
use of org.hibernate.Criteria in project hibernate-orm by hibernate.
the class NaturalIdInvalidationTest method getCitizenWithCriteria.
private void getCitizenWithCriteria(SessionFactory sf) throws Exception {
withTxSession(sf, s -> {
State france = getState(s, "Ile de France");
Criteria criteria = s.createCriteria(Citizen.class);
criteria.add(Restrictions.naturalId().set("ssn", "1234").set("state", france));
criteria.setCacheable(true);
criteria.list();
});
}
Aggregations