public Type getType() throws MappingException { return value.getType(); }
/** * Checks if the collection element is of {@link ComponentType} type. */ private boolean isEmbeddableElementType() { return propertyValue.getElement().getType() instanceof ComponentType; }
/** * Returns whether we believe the map element should be included as part of the middle table's primary key. * * @return {@code true} if the element should be included as part of the key, otherwise {@code false}. */ private boolean isMapElementInPrimaryKey() { if ( propertyValue instanceof IndexedCollection ) { final Value index = ( (IndexedCollection) propertyValue ).getIndex(); return !index.getType().isEntityType(); } return true; } }
public CascadeStyle getCascadeStyle() throws MappingException { Type type = value.getType(); if ( type.isComponentType() ) { return getCompositeCascadeStyle( (CompositeType) type, cascade ); } else if ( type.isCollectionType() ) { return getCollectionCascadeStyle( ( (Collection) value ).getElement().getType(), cascade ); } else { return getCascadeStyle( cascade ); } }
/** * Returns whether the collection is a map-type and that the map element is defined as a Clob/NClob type. * * @return {@code true} if the element is a Clob/NClob type, otherwise {@code false}. */ private boolean isLobMapElementType() { if ( propertyValue instanceof org.hibernate.mapping.Map ) { final Type type = propertyValue.getElement().getType(); // we're only interested in basic types if ( !type.isComponentType() && !type.isAssociationType() ) { return ( type instanceof MaterializedClobType ) || ( type instanceof MaterializedNClobType ); } } return false; }
boolean addBasic( Element parent, PropertyAuditingData propertyAuditingData, Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) { if ( value.getType() instanceof BasicType ) { if ( parent != null ) { final Element propMapping = buildProperty( parent, propertyAuditingData, value, insertable, key ); if ( isAddNestedType( value ) ) { applyNestedType( (SimpleValue) value, propMapping ); } } // A null mapper means that we only want to add xml mappings if ( mapper != null ) { final PropertyData propertyData = propertyAuditingData.resolvePropertyData( value.getType() ); mapper.add( propertyData ); } return true; } return false; }
public void bindDiscriminatorValue() { if ( StringHelper.isEmpty( discriminatorValue ) ) { Value discriminator = persistentClass.getDiscriminator(); if ( discriminator == null ) { persistentClass.setDiscriminatorValue( name ); } else if ( "character".equals( discriminator.getType().getName() ) ) { throw new AnnotationException( "Using default @DiscriminatorValue for a discriminator of type CHAR is not safe" ); } else if ( "integer".equals( discriminator.getType().getName() ) ) { persistentClass.setDiscriminatorValue( String.valueOf( name.hashCode() ) ); } else { persistentClass.setDiscriminatorValue( name ); //Spec compliant } } else { //persistentClass.getDiscriminator() persistentClass.setDiscriminatorValue( discriminatorValue ); } }
public int getSqlTypeCode(Mapping mapping) throws MappingException { org.hibernate.type.Type type = getValue().getType(); try { int sqlTypeCode = type.sqlTypes( mapping )[getTypeIndex()]; if ( getSqlTypeCode() != null && getSqlTypeCode() != sqlTypeCode ) { throw new MappingException( "SQLType code's does not match. mapped as " + sqlTypeCode + " but is " + getSqlTypeCode() ); } return sqlTypeCode; } catch (Exception e) { throw new MappingException( "Could not determine type for column " + name + " of type " + type.getClass().getName() + ": " + e.getClass().getName(), e ); } }
private Type getMapKeyType(Property prop) { Value value = prop.getValue(); assertEquals( Map.class, value.getClass() ); Map map = (Map) value; return map.getIndex().getType(); }
private Element buildProperty( Element parent, PropertyAuditingData propertyAuditingData, Value value, boolean insertable, boolean key) { final Element propMapping = MetadataTools.addProperty( parent, propertyAuditingData.getName(), isAddNestedType( value ) ? null : getBasicTypeName( value.getType() ), propertyAuditingData.isForceInsertable() || insertable, key ); MetadataTools.addColumns( propMapping, value.getColumnIterator() ); return propMapping; }
public void validate(Mapping mapping) throws MappingException { super.validate( mapping ); assert getElement() != null : "IndexedCollection index not bound : " + getRole(); if ( !getIndex().isValid(mapping) ) { throw new MappingException( "collection index mapping has wrong number of columns: " + getRole() + " type: " + getIndex().getType().getName() ); } }
private Class determineElementClass(XClass elementXClass) { if ( elementXClass != null ) { try { return getContext().getBootstrapContext().getReflectionManager().toClass( elementXClass ); } catch (Exception e) { log.debugf( "Unable to resolve XClass [%s] to Class for collection elements [%s]", elementXClass.getName(), collection.getRole() ); } } if ( collection.getElement() != null ) { if ( collection.getElement().getType() != null ) { return collection.getElement().getType().getReturnedClass(); } } // currently this is called from paths where the element type really should be known, // so log the fact that we could not resolve the collection element info log.debugf( "Unable to resolve element information for collection [%s]", collection.getRole() ); return null; }
private Class determineKeyClass(XClass keyXClass) { if ( keyXClass != null ) { try { return getContext().getBootstrapContext().getReflectionManager().toClass( keyXClass ); } catch (Exception e) { log.debugf( "Unable to resolve XClass [%s] to Class for collection key [%s]", keyXClass.getName(), collection.getRole() ); } } final IndexedCollection indexedCollection = (IndexedCollection) collection; if ( indexedCollection.getIndex() != null ) { if ( indexedCollection.getIndex().getType() != null ) { return indexedCollection.getIndex().getType().getReturnedClass(); } } // currently this is called from paths where the element type really should be known, // so log the fact that we could not resolve the collection element info log.debugf( "Unable to resolve key information for collection [%s]", collection.getRole() ); return null; } }
boolean insertable, boolean processModifiedFlag) { final Type type = value.getType(); final boolean isBasic = basicMetadataGenerator.addBasic( parent,
@SuppressWarnings({"unchecked"}) boolean addManyToOne( Element parent, PropertyAuditingData propertyAuditingData, Value value, SimpleMapperBuilder mapper) { final Type type = value.getType(); // A null mapper occurs when adding to composite-id element final Element manyToOneElement = parent.addElement( mapper != null ? "many-to-one" : "key-many-to-one" ); manyToOneElement.addAttribute( "name", propertyAuditingData.getName() ); manyToOneElement.addAttribute( "class", type.getName() ); // HHH-11107 // Use FK hbm magic value 'none' to skip making foreign key constraints between the Envers // schema and the base table schema when a @ManyToOne is present in an identifier. if ( mapper == null ) { manyToOneElement.addAttribute( "foreign-key", "none" ); } MetadataTools.addColumns( manyToOneElement, value.getColumnIterator() ); return true; }
public Class getElementClass() throws MappingException { if ( elementClassName == null ) { org.hibernate.type.Type elementType = getElement().getType(); return isPrimitiveArray() ? ( (PrimitiveType) elementType ).getPrimitiveClass() : elementType.getReturnedClass(); } else { try { return getMetadata().getMetadataBuildingOptions() .getServiceRegistry() .getService( ClassLoaderService.class ) .classForName( elementClassName ); } catch (ClassLoadingException e) { throw new MappingException( e ); } } }
/** * @deprecated See mainly {@link #buildEntityBasedAttribute} */ @Deprecated public static StandardProperty buildStandardProperty(Property property, boolean lazyAvailable) { final Type type = property.getValue().getType(); // we need to dirty check collections, since they can cause an owner // version number increment // we need to dirty check many-to-ones with not-found="ignore" in order // to update the cache (not the database), since in this case a null // entity reference can lose information boolean alwaysDirtyCheck = type.isAssociationType() && ( (AssociationType) type ).isAlwaysDirtyChecked(); return new StandardProperty( property.getName(), type, lazyAvailable && property.isLazy(), property.isInsertable(), property.isUpdateable(), property.getValueGenerationStrategy(), property.isOptional(), alwaysDirtyCheck || property.isUpdateable(), property.isOptimisticLocked(), property.getCascadeStyle(), property.getValue().getFetchMode() ); }
public void validate(Mapping mapping) throws MappingException { assert getKey() != null : "Collection key not bound : " + getRole(); assert getElement() != null : "Collection element not bound : " + getRole(); if ( !getKey().isValid( mapping ) ) { throw new MappingException( "collection foreign key mapping has wrong number of columns: " + getRole() + " type: " + getKey().getType().getName() ); } if ( !getElement().isValid( mapping ) ) { throw new MappingException( "collection element mapping has wrong number of columns: " + getRole() + " type: " + getElement().getType().getName() ); } checkColumnDuplication(); }
@SuppressWarnings({"unchecked"}) private Triple<Element, ExtendedPropertyMapper, String> generateMappingData( PersistentClass pc, EntityXmlMappingData xmlMappingData, AuditTableData auditTableData, IdMappingData idMapper) { final Element classMapping = MetadataTools.createEntity( xmlMappingData.getMainXmlMapping(), auditTableData, pc.getDiscriminatorValue(), pc.isAbstract() ); final ExtendedPropertyMapper propertyMapper = new MultiPropertyMapper(); // Checking if there is a discriminator column if ( pc.getDiscriminator() != null ) { final Element discriminatorElement = classMapping.addElement( "discriminator" ); // Database column or SQL formula allowed to distinguish entity types MetadataTools.addColumnsOrFormulas( discriminatorElement, pc.getDiscriminator().getColumnIterator() ); discriminatorElement.addAttribute( "type", pc.getDiscriminator().getType().getName() ); } // Adding the id mapping classMapping.add( (Element) idMapper.getXmlMapping().clone() ); // Adding the "revision type" property addRevisionType( classMapping, classMapping ); addAdditionalColumns( classMapping ); return Triple.make( classMapping, propertyMapper, null ); }
attributeNumber, property.getName(), property.getValue().getType(), new BaselineAttributeInformation.Builder() .setLazy( lazy )