List of usage examples for org.hibernate.type ComponentType getSubtypes
@Override
public Type[] getSubtypes()
From source file:com.blazebit.persistence.integration.hibernate.base.HibernateJpa21Provider.java
License:Apache License
@Override public boolean isOrphanRemoval(ManagedType<?> ownerType, String elementCollectionPath, String attributeName) { Type elementType = getCollectionPersister(ownerType, elementCollectionPath).getElementType(); if (!(elementType instanceof ComponentType)) { // This can only happen for collection/join table target attributes, where it is irrelevant return false; }//from w ww.ja va 2 s . c om ComponentType componentType = (ComponentType) elementType; String subAttribute = attributeName.substring(elementCollectionPath.length() + 1); // Component types only store direct properties, so we have to go deeper String[] propertyParts = subAttribute.split("\\."); int propertyIndex = 0; for (; propertyIndex < propertyParts.length - 1; propertyIndex++) { int index = componentType.getPropertyIndex(propertyParts[propertyIndex]); Type propertyType = componentType.getSubtypes()[index]; if (propertyType instanceof ComponentType) { componentType = (ComponentType) propertyType; } else { // The association property is just as good as the id property of the association for our purposes // So we stop here and query the association property instead break; } } try { return (boolean) HAS_ORPHAN_DELETE_METHOD.invoke(componentType.getCascadeStyle(propertyIndex)); } catch (Exception ex) { throw new RuntimeException( "Could not access orphan removal information. Please report your version of hibernate so we can provide support for it!", ex); } }
From source file:com.blazebit.persistence.integration.hibernate.base.HibernateJpa21Provider.java
License:Apache License
@Override public boolean isDeleteCascaded(ManagedType<?> ownerType, String elementCollectionPath, String attributeName) { Type elementType = getCollectionPersister(ownerType, elementCollectionPath).getElementType(); if (!(elementType instanceof ComponentType)) { // This can only happen for collection/join table target attributes, where it is irrelevant return false; }/*from www.ja va 2 s . c om*/ ComponentType componentType = (ComponentType) elementType; String subAttribute = attributeName.substring(elementCollectionPath.length() + 1); // Component types only store direct properties, so we have to go deeper String[] propertyParts = subAttribute.split("\\."); int propertyIndex = 0; for (; propertyIndex < propertyParts.length - 1; propertyIndex++) { int index = componentType.getPropertyIndex(propertyParts[propertyIndex]); Type propertyType = componentType.getSubtypes()[index]; if (propertyType instanceof ComponentType) { componentType = (ComponentType) propertyType; } else { // The association property is just as good as the id property of the association for our purposes // So we stop here and query the association property instead break; } } try { return (boolean) DO_CASCADE_METHOD.invoke(componentType.getCascadeStyle(propertyIndex), DELETE_CASCADE); } catch (Exception ex) { throw new RuntimeException( "Could not access orphan removal information. Please report your version of hibernate so we can provide support for it!", ex); } }
From source file:com.blazebit.persistence.integration.hibernate.base.HibernateJpaProvider.java
License:Apache License
@Override public String[] getColumnNames(EntityType<?> ownerType, String elementCollectionPath, String attributeName) { QueryableCollection persister = getCollectionPersister(ownerType, elementCollectionPath); String subAttributeName = attributeName.substring(elementCollectionPath.length() + 1); if (persister.getElementType() instanceof ComponentType) { ComponentType elementType = (ComponentType) persister.getElementType(); String[] propertyNames = elementType.getPropertyNames(); Type[] subtypes = elementType.getSubtypes(); String[] propertyParts = subAttributeName.split("\\."); int offset = 0; for (int j = 0; j < propertyParts.length - 1; j++) { String propertyName = propertyParts[j]; for (int i = 0; i < propertyNames.length; i++) { int span = subtypes[i].getColumnSpan(persister.getFactory()); if (propertyName.equals(propertyNames[i])) { if (subtypes[i] instanceof ComponentType) { elementType = (ComponentType) subtypes[i]; propertyNames = elementType.getPropertyNames(); subtypes = elementType.getSubtypes(); break; } else { String[] columnNames = new String[span]; String[] elementColumnNames = persister.getElementColumnNames(); System.arraycopy(elementColumnNames, offset, columnNames, 0, span); return columnNames; }/* w ww. j a va 2s .c o m*/ } else { offset += span; } } } String propertyName = propertyParts[propertyParts.length - 1]; for (int i = 0; i < propertyNames.length; i++) { int span = subtypes[i].getColumnSpan(persister.getFactory()); if (propertyName.equals(propertyNames[i])) { String[] columnNames = new String[span]; String[] elementColumnNames = persister.getElementColumnNames(); System.arraycopy(elementColumnNames, offset, columnNames, 0, span); return columnNames; } else { offset += span; } } } else if (persister.getElementType() instanceof org.hibernate.type.EntityType) { AbstractEntityPersister elementPersister = (AbstractEntityPersister) entityPersisters .get(((org.hibernate.type.EntityType) persister.getElementType()).getAssociatedEntityName()); Type identifierType = ((org.hibernate.type.EntityType) persister.getElementType()) .getIdentifierOrUniqueKeyType(persister.getFactory()); String identifierOrUniqueKeyPropertyName = ((org.hibernate.type.EntityType) persister.getElementType()) .getIdentifierOrUniqueKeyPropertyName(persister.getFactory()); String prefix; if (identifierType instanceof EmbeddedComponentType) { String[] propertyNames = ((EmbeddedComponentType) identifierType).getPropertyNames(); String[] columnNames = columnNamesByPropertyName(elementPersister, propertyNames, subAttributeName, "", persister.getElementColumnNames(), persister.getFactory()); if (columnNames != null) { return columnNames; } } else if (subAttributeName.equals(identifierOrUniqueKeyPropertyName)) { return persister.getElementColumnNames(); } else if (identifierType instanceof ComponentType && subAttributeName.startsWith(prefix = identifierOrUniqueKeyPropertyName + ".")) { String[] propertyNames = ((ComponentType) identifierType).getPropertyNames(); String[] columnNames = columnNamesByPropertyName(elementPersister, propertyNames, subAttributeName.substring(identifierOrUniqueKeyPropertyName.length() + 1), prefix, persister.getElementColumnNames(), persister.getFactory()); if (columnNames != null) { return columnNames; } } } throw new IllegalArgumentException( "Couldn't find column names for " + getTypeName(ownerType) + "#" + attributeName); }
From source file:com.blazebit.persistence.integration.hibernate.base.HibernateJpaProvider.java
License:Apache License
@Override public String[] getColumnTypes(EntityType<?> ownerType, String elementCollectionPath, String attributeName) { QueryableCollection persister = getCollectionPersister(ownerType, elementCollectionPath); SessionFactoryImplementor sfi = persister.getFactory(); String[] columnNames = null;//from w w w . j a v a 2 s .co m Type propertyType = null; String subAttributeName = attributeName.substring(elementCollectionPath.length() + 1); if (persister.getElementType() instanceof ComponentType) { ComponentType elementType = (ComponentType) persister.getElementType(); String[] propertyNames = elementType.getPropertyNames(); Type[] subtypes = elementType.getSubtypes(); String[] propertyParts = subAttributeName.split("\\."); int offset = 0; for (int j = 0; j < propertyParts.length - 1; j++) { String propertyName = propertyParts[j]; for (int i = 0; i < propertyNames.length; i++) { int span = subtypes[i].getColumnSpan(persister.getFactory()); if (propertyName.equals(propertyNames[i])) { if (subtypes[i] instanceof ComponentType) { elementType = (ComponentType) subtypes[i]; propertyNames = elementType.getPropertyNames(); subtypes = elementType.getSubtypes(); break; } else { columnNames = new String[span]; String[] elementColumnNames = persister.getElementColumnNames(); System.arraycopy(elementColumnNames, offset, columnNames, 0, span); break; } } else { offset += span; } } } if (columnNames == null) { String propertyName = propertyParts[propertyParts.length - 1]; for (int i = 0; i < propertyNames.length; i++) { int span = subtypes[i].getColumnSpan(persister.getFactory()); if (propertyName.equals(propertyNames[i])) { columnNames = new String[span]; String[] elementColumnNames = persister.getElementColumnNames(); System.arraycopy(elementColumnNames, offset, columnNames, 0, span); break; } else { offset += span; } } } } else if (persister.getElementType() instanceof org.hibernate.type.EntityType) { Type identifierType = ((org.hibernate.type.EntityType) persister.getElementType()) .getIdentifierOrUniqueKeyType(persister.getFactory()); String identifierOrUniqueKeyPropertyName = ((org.hibernate.type.EntityType) persister.getElementType()) .getIdentifierOrUniqueKeyPropertyName(persister.getFactory()); String prefix; if (identifierType instanceof EmbeddedComponentType) { String[] propertyNames = ((EmbeddedComponentType) identifierType).getPropertyNames(); Type[] subtypes = ((EmbeddedComponentType) identifierType).getSubtypes(); int offset = 0; for (int i = 0; i < propertyNames.length; i++) { String propertyName = propertyNames[i]; int span = subtypes[i].getColumnSpan(persister.getFactory()); if (subAttributeName.equals(propertyName)) { columnNames = new String[span]; String[] elementColumnNames = persister.getElementColumnNames(); System.arraycopy(elementColumnNames, offset, columnNames, 0, span); propertyType = subtypes[i]; break; } else { offset += span; } } } else if (subAttributeName.equals(identifierOrUniqueKeyPropertyName)) { columnNames = persister.getElementColumnNames(); propertyType = identifierType; } else if (identifierType instanceof ComponentType && subAttributeName.startsWith(prefix = identifierOrUniqueKeyPropertyName + ".")) { String[] propertyNames = ((ComponentType) identifierType).getPropertyNames(); Type[] subtypes = ((ComponentType) identifierType).getSubtypes(); String subPropertyName = subAttributeName.substring(prefix.length()); int offset = 0; for (int i = 0; i < propertyNames.length; i++) { String propertyName = propertyNames[i]; int span = subtypes[i].getColumnSpan(persister.getFactory()); if (subPropertyName.equals(propertyName)) { columnNames = new String[span]; String[] elementColumnNames = persister.getElementColumnNames(); System.arraycopy(elementColumnNames, offset, columnNames, 0, span); propertyType = subtypes[i]; break; } else { offset += span; } } } } if (columnNames == null) { throw new IllegalArgumentException( "Couldn't find column names for " + getTypeName(ownerType) + "#" + attributeName); } boolean isFormula = columnNames.length == 1 && columnNames[0] == null; if (isFormula) { return getColumnTypeForPropertyType(ownerType, attributeName, sfi, propertyType); } Database database = sfi.getServiceRegistry().locateServiceBinding(Database.class).getService(); Table[] tables = new Table[] { database.getTable(unquote(persister.getTableName())) }; return getColumnTypesForColumnNames(ownerType, columnNames, tables); }
From source file:com.blazebit.persistence.integration.hibernate.base.HibernateJpaProvider.java
License:Apache License
@Override public boolean isOrphanRemoval(ManagedType<?> ownerType, String elementCollectionPath, String attributeName) { Type elementType = getCollectionPersister(ownerType, elementCollectionPath).getElementType(); if (!(elementType instanceof ComponentType)) { // This can only happen for collection/join table target attributes, where it is irrelevant return false; }// w w w.j a v a2 s . c o m ComponentType componentType = (ComponentType) elementType; String subAttribute = attributeName.substring(elementCollectionPath.length() + 1); // Component types only store direct properties, so we have to go deeper String[] propertyParts = subAttribute.split("\\."); int propertyIndex = 0; for (; propertyIndex < propertyParts.length - 1; propertyIndex++) { int index = componentType.getPropertyIndex(propertyParts[propertyIndex]); Type propertyType = componentType.getSubtypes()[index]; if (propertyType instanceof ComponentType) { componentType = (ComponentType) propertyType; } else { // The association property is just as good as the id property of the association for our purposes // So we stop here and query the association property instead break; } } return componentType.getCascadeStyle(propertyIndex).hasOrphanDelete(); }
From source file:com.blazebit.persistence.integration.hibernate.base.HibernateJpaProvider.java
License:Apache License
@Override public boolean isDeleteCascaded(ManagedType<?> ownerType, String elementCollectionPath, String attributeName) { Type elementType = getCollectionPersister(ownerType, elementCollectionPath).getElementType(); if (!(elementType instanceof ComponentType)) { // This can only happen for collection/join table target attributes, where it is irrelevant return false; }/*w ww . java2s.c o m*/ ComponentType componentType = (ComponentType) elementType; String subAttribute = attributeName.substring(elementCollectionPath.length() + 1); // Component types only store direct properties, so we have to go deeper String[] propertyParts = subAttribute.split("\\."); int propertyIndex = 0; for (; propertyIndex < propertyParts.length - 1; propertyIndex++) { int index = componentType.getPropertyIndex(propertyParts[propertyIndex]); Type propertyType = componentType.getSubtypes()[index]; if (propertyType instanceof ComponentType) { componentType = (ComponentType) propertyType; } else { // The association property is just as good as the id property of the association for our purposes // So we stop here and query the association property instead break; } } return componentType.getCascadeStyle(propertyIndex).doCascade(CascadingAction.DELETE); }
From source file:com.blazebit.persistence.integration.hibernate.base.HibernateJpaProvider.java
License:Apache License
@Override public List<String> getIdentifierOrUniqueKeyEmbeddedPropertyNames(EntityType<?> owner, String elementCollectionPath, String attributeName) { QueryableCollection persister = getCollectionPersister(owner, elementCollectionPath); ComponentType componentType = (ComponentType) persister.getElementType(); String subAttribute = attributeName.substring(elementCollectionPath.length() + 1); // Component types only store direct properties, so we have to go deeper String[] propertyParts = subAttribute.split("\\."); Type propertyType;/*from w w w . j a v a 2s . c o m*/ for (int i = 0; i < propertyParts.length - 1; i++) { int index = componentType.getPropertyIndex(propertyParts[i]); propertyType = componentType.getSubtypes()[index]; if (propertyType instanceof ComponentType) { componentType = (ComponentType) propertyType; } else { // A path expression shouldn't navigate over an association.. throw new IllegalStateException("Can't get the id properties for: " + attributeName); } } propertyType = componentType.getSubtypes()[componentType .getPropertyIndex(propertyParts[propertyParts.length - 1])]; List<String> identifierOrUniqueKeyPropertyNames = new ArrayList<>(); collectPropertyNames(identifierOrUniqueKeyPropertyNames, null, propertyType, persister.getFactory()); return identifierOrUniqueKeyPropertyNames; }
From source file:com.blazebit.persistence.integration.hibernate.base.HibernateJpaProvider.java
License:Apache License
private void collectPropertyNames(Collection<String> propertyNames, String prefix, Type propertyType, Mapping factory) {/* ww w .ja va2s. com*/ if (propertyType instanceof ComponentType) { ComponentType componentType = (ComponentType) propertyType; for (String propertyName : componentType.getPropertyNames()) { Type subtype = componentType.getSubtypes()[componentType.getPropertyIndex(propertyName)]; collectPropertyNames(propertyNames, prefix == null ? propertyName : prefix + "." + propertyName, subtype, factory); } } else if (propertyType instanceof org.hibernate.type.EntityType) { org.hibernate.type.EntityType entityType = (org.hibernate.type.EntityType) propertyType; Type identifierOrUniqueKeyType = entityType.getIdentifierOrUniqueKeyType(factory); if (identifierOrUniqueKeyType instanceof EmbeddedComponentType) { EmbeddedComponentType embeddedComponentType = (EmbeddedComponentType) identifierOrUniqueKeyType; for (String propertyName : embeddedComponentType.getPropertyNames()) { propertyNames.add(prefix == null ? propertyName : prefix + "." + propertyName); } } else { String identifierOrUniqueKeyPropertyName = entityType.getIdentifierOrUniqueKeyPropertyName(factory); propertyNames.add(prefix == null ? identifierOrUniqueKeyPropertyName : prefix + "." + identifierOrUniqueKeyPropertyName); } } else if (!(propertyType instanceof CollectionType) && prefix != null) { propertyNames.add(prefix); } }
From source file:com.evolveum.midpoint.repo.sql.util.MidpointPersisterUtil.java
License:Apache License
private static void killUnwantedAssociationValues(String[] propertyNames, Type[] propertyTypes, Object[] values, int depth) { if (values == null) { return;//from w ww. ja va 2s . com } for (int i = 0; i < propertyTypes.length; i++) { String name = propertyNames[i]; Type type = propertyTypes[i]; Object value = values[i]; if (LOGGER.isTraceEnabled()) { LOGGER.trace("{}- killUnwantedAssociationValues processing #{}: {} (type={}, value={})", StringUtils.repeat(" ", depth), i, name, type, value); } if (type instanceof ComponentType) { ComponentType componentType = (ComponentType) type; killUnwantedAssociationValues(componentType.getPropertyNames(), componentType.getSubtypes(), (Object[]) value, depth + 1); } else if (type instanceof ManyToOneType) { if (ASSOCIATION_TO_REMOVE.equals(name)) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("{}- killUnwantedAssociationValues KILLED #{}: {} (type={}, value={})", StringUtils.repeat(" ", depth), i, name, type, value); } values[i] = null; } } } }
From source file:cz.jirutka.rsql.visitor.hibernate.HibernateCriterionVisitor.java
License:Apache License
private Type getPropertyType(ComponentType componentType, String property) { property = propertyResolver.getPropertyName(componentType.getReturnedClass(), property); int propertyIndex = componentType.getPropertyIndex(property); return componentType.getSubtypes()[propertyIndex]; }