use of org.hibernate.type.EntityType in project hibernate-orm by hibernate.
the class QueryLoader method initialize.
private void initialize(SelectClause selectClause) {
List fromElementList = selectClause.getFromElementsForLoad();
hasScalars = selectClause.isScalarSelect();
scalarColumnNames = selectClause.getColumnNames();
//sqlResultTypes = selectClause.getSqlResultTypes();
queryReturnTypes = selectClause.getQueryReturnTypes();
aggregatedSelectExpression = selectClause.getAggregatedSelectExpression();
queryReturnAliases = selectClause.getQueryReturnAliases();
List collectionFromElements = selectClause.getCollectionFromElements();
if (collectionFromElements != null && collectionFromElements.size() != 0) {
int length = collectionFromElements.size();
collectionPersisters = new QueryableCollection[length];
collectionOwners = new int[length];
collectionSuffixes = new String[length];
for (int i = 0; i < length; i++) {
FromElement collectionFromElement = (FromElement) collectionFromElements.get(i);
collectionPersisters[i] = collectionFromElement.getQueryableCollection();
collectionOwners[i] = fromElementList.indexOf(collectionFromElement.getOrigin());
// collectionSuffixes[i] = collectionFromElement.getColumnAliasSuffix();
// collectionSuffixes[i] = Integer.toString( i ) + "_";
collectionSuffixes[i] = collectionFromElement.getCollectionSuffix();
}
}
int size = fromElementList.size();
entityPersisters = new Queryable[size];
entityEagerPropertyFetches = new boolean[size];
entityAliases = new String[size];
sqlAliases = new String[size];
sqlAliasSuffixes = new String[size];
includeInSelect = new boolean[size];
owners = new int[size];
ownerAssociationTypes = new EntityType[size];
for (int i = 0; i < size; i++) {
final FromElement element = (FromElement) fromElementList.get(i);
entityPersisters[i] = (Queryable) element.getEntityPersister();
if (entityPersisters[i] == null) {
throw new IllegalStateException("No entity persister for " + element.toString());
}
entityEagerPropertyFetches[i] = element.isAllPropertyFetch();
sqlAliases[i] = element.getTableAlias();
entityAliases[i] = element.getClassAlias();
sqlAliasByEntityAlias.put(entityAliases[i], sqlAliases[i]);
// TODO should we just collect these like with the collections above?
sqlAliasSuffixes[i] = (size == 1) ? "" : Integer.toString(i) + "_";
// sqlAliasSuffixes[i] = element.getColumnAliasSuffix();
includeInSelect[i] = !element.isFetch();
if (includeInSelect[i]) {
selectLength++;
}
//by default
owners[i] = -1;
if (element.isFetch()) {
//noinspection StatementWithEmptyBody
if (element.isCollectionJoin() || element.getQueryableCollection() != null) {
// This is now handled earlier in this method.
} else if (element.getDataType().isEntityType()) {
EntityType entityType = (EntityType) element.getDataType();
if (entityType.isOneToOne()) {
owners[i] = fromElementList.indexOf(element.getOrigin());
}
ownerAssociationTypes[i] = entityType;
}
}
}
//NONE, because its the requested lock mode, not the actual!
defaultLockModes = ArrayHelper.fillArray(LockMode.NONE, size);
}
use of org.hibernate.type.EntityType in project hibernate-orm by hibernate.
the class ForeignKeys method collectNonNullableTransientEntities.
private static void collectNonNullableTransientEntities(Nullifier nullifier, Object value, String propertyName, Type type, boolean isNullable, SharedSessionContractImplementor session, NonNullableTransientDependencies nonNullableTransientEntities) {
if (value == null) {
return;
}
if (type.isEntityType()) {
final EntityType entityType = (EntityType) type;
if (!isNullable && !entityType.isOneToOne() && nullifier.isNullifiable(entityType.getAssociatedEntityName(), value)) {
nonNullableTransientEntities.add(propertyName, value);
}
} else if (type.isAnyType()) {
if (!isNullable && nullifier.isNullifiable(null, value)) {
nonNullableTransientEntities.add(propertyName, value);
}
} else if (type.isComponentType()) {
final CompositeType actype = (CompositeType) type;
final boolean[] subValueNullability = actype.getPropertyNullability();
if (subValueNullability != null) {
final String[] subPropertyNames = actype.getPropertyNames();
final Object[] subvalues = actype.getPropertyValues(value, session);
final Type[] subtypes = actype.getSubtypes();
for (int j = 0; j < subvalues.length; j++) {
collectNonNullableTransientEntities(nullifier, subvalues[j], subPropertyNames[j], subtypes[j], subValueNullability[j], session, nonNullableTransientEntities);
}
}
}
}
use of org.hibernate.type.EntityType in project hibernate-orm by hibernate.
the class AbstractPropertyMapping method initPropertyPaths.
/*protected void initPropertyPaths(
final String path,
final Type type,
final String[] columns,
final String[] formulaTemplates,
final Mapping factory)
throws MappingException {
//addFormulaPropertyPath(path, type, formulaTemplates);
initPropertyPaths(path, type, columns, formulaTemplates, factory);
}*/
protected void initPropertyPaths(final String path, final Type type, String[] columns, String[] columnReaders, String[] columnReaderTemplates, final String[] formulaTemplates, final Mapping factory) throws MappingException {
assert columns != null : "Incoming columns should not be null : " + path;
assert type != null : "Incoming type should not be null : " + path;
if (columns.length != type.getColumnSpan(factory)) {
throw new MappingException("broken column mapping for: " + path + " of: " + getEntityName());
}
if (type.isAssociationType()) {
AssociationType actype = (AssociationType) type;
if (actype.useLHSPrimaryKey()) {
columns = getIdentifierColumnNames();
columnReaders = getIdentifierColumnReaders();
columnReaderTemplates = getIdentifierColumnReaderTemplates();
} else {
String foreignKeyProperty = actype.getLHSPropertyName();
if (foreignKeyProperty != null && !path.equals(foreignKeyProperty)) {
//TODO: this requires that the collection is defined afterQuery the
// referenced property in the mapping file (ok?)
columns = columnsByPropertyPath.get(foreignKeyProperty);
if (columns == null) {
//get em on the second pass!
return;
}
columnReaders = columnReadersByPropertyPath.get(foreignKeyProperty);
columnReaderTemplates = columnReaderTemplatesByPropertyPath.get(foreignKeyProperty);
}
}
}
if (path != null) {
addPropertyPath(path, type, columns, columnReaders, columnReaderTemplates, formulaTemplates);
}
if (type.isComponentType()) {
CompositeType actype = (CompositeType) type;
initComponentPropertyPaths(path, actype, columns, columnReaders, columnReaderTemplates, formulaTemplates, factory);
if (actype.isEmbedded()) {
initComponentPropertyPaths(path == null ? null : StringHelper.qualifier(path), actype, columns, columnReaders, columnReaderTemplates, formulaTemplates, factory);
}
} else if (type.isEntityType()) {
initIdentifierPropertyPaths(path, (EntityType) type, columns, columnReaders, columnReaderTemplates, factory);
}
}
Aggregations