public void validate(Mapping mapping) throws MappingException { Iterator iter = getPropertyIterator(); while ( iter.hasNext() ) { Property prop = (Property) iter.next(); if ( !prop.isValid(mapping) ) { throw new MappingException( "property mapping has wrong number of columns: " + StringHelper.qualify( getEntityName(), prop.getName() ) + " type: " + prop.getType().getName() ); } } checkPropertyDuplication(); checkColumnDuplication(); }
public UnionSubclassEntityPersister( final EntityBinding entityBinding, final EntityRegionAccessStrategy cacheAccessStrategy, final NaturalIdRegionAccessStrategy naturalIdRegionAccessStrategy, final SessionFactoryImplementor factory, final Mapping mapping) throws HibernateException { super(entityBinding, cacheAccessStrategy, naturalIdRegionAccessStrategy, factory ); // TODO: implement!!! initializing final fields to null to make compiler happy. subquery = null; tableName = null; subclassClosure = null; spaces = null; subclassSpaces = null; discriminatorValue = null; discriminatorSQLValue = null; constraintOrderedTableNames = null; constraintOrderedKeyColumnNames = null; }
/** * Get the qualified (prefixed by alias) names of the columns of the owning entity which are to be used in the join * * @param associationType The association type for the association that represents the join * @param columnQualifier The left-hand side table alias * @param propertyIndex The index of the property that represents the association/join * @param begin The index for any nested (composites) attributes * @param lhsPersister The persister for the left-hand side of the association/join * @param mapping The mapping (typically the SessionFactory). * * @return The qualified column names. */ public static String[] getAliasedLHSColumnNames( AssociationType associationType, String columnQualifier, int propertyIndex, int begin, OuterJoinLoadable lhsPersister, Mapping mapping) { if ( associationType.useLHSPrimaryKey() ) { return StringHelper.qualify( columnQualifier, lhsPersister.getIdentifierColumnNames() ); } else { final String propertyName = associationType.getLHSPropertyName(); if ( propertyName == null ) { return ArrayHelper.slice( toColumns( lhsPersister, columnQualifier, propertyIndex ), begin, associationType.getColumnSpan( mapping ) ); } else { //bad cast return ( (PropertyMapping) lhsPersister ).toColumns( columnQualifier, propertyName ); } } }
public void validate(Mapping mapping) throws MappingException { super.validate(mapping); if ( key!=null && !key.isValid(mapping) ) { throw new MappingException( "subclass key mapping has wrong number of columns: " + getEntityName() + " type: " + key.getType().getName() ); } }
@Override public void validate(Mapping mapping) throws MappingException { super.validate(mapping); if ( !getIdentifier().isValid(mapping) ) { throw new MappingException( "identifier mapping has wrong number of columns: " + getEntityName() + " type: " + getIdentifier().getType().getName() ); } checkCompositeIdentifier(); }
public String sqlCreateString(Dialect dialect, Mapping mapping, String defaultCatalog, String defaultSchema) throws HibernateException { return buildSqlCreateIndexString( dialect, getName(), getTable(), getColumnIterator(), columnOrderMap, false, defaultCatalog, defaultSchema ); }
public void validateColumns(Dialect dialect, Mapping mapping, TableMetadata tableInfo) { Iterator iter = getColumnIterator(); while ( iter.hasNext() ) { Column col = (Column) iter.next(); ColumnMetadata columnInfo = tableInfo.getColumnMetadata( col.getName() ); if ( columnInfo == null ) { throw new HibernateException( "Missing column: " + col.getName() + " in " + Table.qualify( tableInfo.getCatalog(), tableInfo.getSchema(), tableInfo.getName())); } else { final boolean typesMatch = col.getSqlType( dialect, mapping ).toLowerCase() .startsWith( columnInfo.getTypeName().toLowerCase() ) || columnInfo.getTypeCode() == col.getSqlTypeCode( mapping ); if ( !typesMatch ) { throw new HibernateException( "Wrong column type in " + Table.qualify( tableInfo.getCatalog(), tableInfo.getSchema(), tableInfo.getName()) + " for column " + col.getName() + ". Found: " + columnInfo.getTypeName().toLowerCase() + ", expected: " + col.getSqlType( dialect, mapping ) ); } } } }
public void prepareTemporaryTables(Mapping mapping, Dialect dialect) { temporaryIdTableName = dialect.generateTemporaryTableName( getTable().getName() ); if ( dialect.supportsTemporaryTables() ) { Table table = new Table(); table.setName( temporaryIdTableName ); Iterator itr = getTable().getPrimaryKey().getColumnIterator(); while( itr.hasNext() ) { Column column = (Column) itr.next(); table.addColumn( column.clone() ); } temporaryIdTableDDL = table.sqlTemporaryTableCreateString( dialect, mapping ); } }
@Override public String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog, String defaultSchema) { return dialect.getUniqueDelegate().getAlterTableToAddUniqueKeyCommand( this, defaultCatalog, defaultSchema ); }
public int getColumnSpan(Mapping mapping) throws MappingException { Type[] types = userType.getPropertyTypes(); int n=0; for ( Type type : types ) { n += type.getColumnSpan( mapping ); } return n; }
private void initIdentifierPropertyPaths(Mapping mapping) throws MappingException { String idProp = getIdentifierPropertyName(); if ( idProp != null ) { propertyMapping.initPropertyPaths( idProp, getIdentifierType(), getIdentifierColumnNames(), getIdentifierColumnReaders(), getIdentifierColumnReaderTemplates(), null, mapping ); } if ( entityMetamodel.getIdentifierProperty().isEmbedded() ) { propertyMapping.initPropertyPaths( null, getIdentifierType(), getIdentifierColumnNames(), getIdentifierColumnReaders(), getIdentifierColumnReaderTemplates(), null, mapping ); } if ( ! entityMetamodel.hasNonIdentifierPropertyNamedId() ) { propertyMapping.initPropertyPaths( ENTITY_ID, getIdentifierType(), getIdentifierColumnNames(), getIdentifierColumnReaders(), getIdentifierColumnReaderTemplates(), null, mapping ); } }
private void initDiscriminatorPropertyPath(Mapping mapping) throws MappingException { propertyMapping.initPropertyPaths( ENTITY_CLASS, getDiscriminatorType(), new String[]{getDiscriminatorColumnName()}, new String[]{getDiscriminatorColumnReaders()}, new String[]{getDiscriminatorColumnReaderTemplate()}, new String[]{getDiscriminatorFormulaTemplate()}, getFactory() ); }
/** * The name of the property on the associated entity to which our FK * refers * * @param factory The mappings... * @return The appropriate property name. * @throws MappingException Generally, if unable to resolve the associated entity name */ public final String getIdentifierOrUniqueKeyPropertyName(Mapping factory) throws MappingException { if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) { return factory.getIdentifierPropertyName( getAssociatedEntityName() ); } else { return uniqueKeyPropertyName; } }
@Override @SuppressWarnings( {"unchecked"}) public EntityPersister createEntityPersister( PersistentClass metadata, EntityRegionAccessStrategy cacheAccessStrategy, NaturalIdRegionAccessStrategy naturalIdRegionAccessStrategy, SessionFactoryImplementor factory, Mapping cfg) { Class<? extends EntityPersister> persisterClass = metadata.getEntityPersisterClass(); if ( persisterClass == null ) { persisterClass = serviceRegistry.getService( PersisterClassResolver.class ).getEntityPersisterClass( metadata ); } return create( persisterClass, ENTITY_PERSISTER_CONSTRUCTOR_ARGS, metadata, cacheAccessStrategy, naturalIdRegionAccessStrategy, factory, cfg ); }
public CompositeElementPropertyMapping( String[] elementColumns, String[] elementColumnReaders, String[] elementColumnReaderTemplates, String[] elementFormulaTemplates, CompositeType compositeType, Mapping factory) throws MappingException { this.compositeType = compositeType; initComponentPropertyPaths(null, compositeType, elementColumns, elementColumnReaders, elementColumnReaderTemplates, elementFormulaTemplates, factory); }
/** * Get the columns of the owning entity which are to be used in the join * * @param type The type representing the join * @param property The property index for the association type * @param begin ? * @param lhsPersister The persister for the left-hand-side of the join * @param mapping The mapping object (typically the SessionFactory) * * @return The columns for the left-hand-side of the join */ public static String[] getLHSColumnNames( AssociationType type, int property, int begin, OuterJoinLoadable lhsPersister, Mapping mapping) { if ( type.useLHSPrimaryKey() ) { //return lhsPersister.getSubclassPropertyColumnNames(property); return lhsPersister.getIdentifierColumnNames(); } else { final String propertyName = type.getLHSPropertyName(); if ( propertyName == null ) { //slice, to get the columns for this component //property return ArrayHelper.slice( property < 0 ? lhsPersister.getIdentifierColumnNames() : lhsPersister.getSubclassPropertyColumnNames( property ), begin, type.getColumnSpan( mapping ) ); } else { //property-refs for associations defined on a //component are not supported, so no need to slice return lhsPersister.getPropertyColumnNames( propertyName ); } } }
protected final int determineJdbcTypeCode(Type type, Mapping mapping) throws QueryException { try { final int[] jdbcTypeCodes = type.sqlTypes( mapping ); if ( jdbcTypeCodes.length != 1 ) { throw new QueryException( "multiple-column type in sum()" ); } return jdbcTypeCodes[0]; } catch ( MappingException me ) { throw new QueryException( me ); } }
/** * Determine the type of either (1) the identifier if we reference the * associated entity's PK or (2) the unique key to which we refer (i.e. * the property-ref). * * @param factory The mappings... * @return The appropriate type. * @throws MappingException Generally, if unable to resolve the associated entity name * or unique key property name. */ public final Type getIdentifierOrUniqueKeyType(Mapping factory) throws MappingException { if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) { return getIdentifierType(factory); } else { Type type = factory.getReferencedPropertyType( getAssociatedEntityName(), uniqueKeyPropertyName ); if ( type.isEntityType() ) { type = ( ( EntityType ) type).getIdentifierOrUniqueKeyType( factory ); } return type; } }
public boolean[] toColumnNullness(Object value, Mapping mapping) { boolean[] result = new boolean[ getColumnSpan( mapping ) ]; if ( value != null ) { Arrays.fill( result, true ); } return result; }
@Override public Object fromXMLNode(Node xml, Mapping factory) throws HibernateException { if ( !isEmbeddedInXML ) { return getIdentifierType(factory).fromXMLNode(xml, factory); } else { return xml; } }
@Override public int getColumnSpan(Mapping mapping) throws MappingException { int span = 0; for ( int i = 0; i < propertySpan; i++ ) { span += propertyTypes[i].getColumnSpan( mapping ); } return span; }
@Override public Size[] dictatedSizes(Mapping mapping) throws MappingException { //Not called at runtime so doesn't matter if its slow :) final Size[] sizes = new Size[ getColumnSpan( mapping ) ]; int soFar = 0; for ( Type propertyType : propertyTypes ) { final Size[] propertySizes = propertyType.dictatedSizes( mapping ); System.arraycopy( propertySizes, 0, sizes, soFar, propertySizes.length ); soFar += propertySizes.length; } return sizes; }
@Override public Size[] defaultSizes(Mapping mapping) throws MappingException { //Not called at runtime so doesn't matter if its slow :) final Size[] sizes = new Size[ getColumnSpan( mapping ) ]; int soFar = 0; for ( Type propertyType : propertyTypes ) { final Size[] propertySizes = propertyType.defaultSizes( mapping ); System.arraycopy( propertySizes, 0, sizes, soFar, propertySizes.length ); soFar += propertySizes.length; } return sizes; }
@Override public boolean[] toColumnNullness(Object value, Mapping mapping) { boolean[] result = new boolean[ getColumnSpan( mapping ) ]; if ( value == null ) { return result; } Object[] values = getPropertyValues( value, EntityMode.POJO ); //TODO!!!!!!! int loc = 0; for ( int i = 0; i < propertyTypes.length; i++ ) { boolean[] propertyNullness = propertyTypes[i].toColumnNullness( values[i], mapping ); System.arraycopy( propertyNullness, 0, result, loc, propertyNullness.length ); loc += propertyNullness.length; } return result; }
public int[] sqlTypes(Mapping mapping) throws MappingException { int[] result = new int[ getColumnSpan(mapping) ]; int n=0; for ( Type type : userType.getPropertyTypes() ) { for ( int sqlType : type.sqlTypes( mapping ) ) { result[n++] = sqlType; } } return result; }
@Override public Object fromXMLNode(Node xml, Mapping factory) throws HibernateException { throw new UnsupportedOperationException(); }
@Override public int getColumnSpan(Mapping mapping) throws MappingException { return 1; }
@Override public int[] sqlTypes(Mapping mapping) throws MappingException { return ArrayHelper.join( discriminatorType.sqlTypes( mapping ), identifierType.sqlTypes( mapping ) ); }
@Override public Size[] defaultSizes(Mapping mapping) throws MappingException { return new Size[] { LEGACY_DEFAULT_SIZE }; }
public boolean isValid(Mapping mapping) throws MappingException { if (referencedEntityName==null) { throw new MappingException("association must specify the referenced entity"); } return super.isValid( mapping ); }
public int[] sqlTypes(Mapping mapping) throws MappingException { return baseType.sqlTypes(mapping); }
public boolean isValid(Mapping mapping) throws MappingException { return true; }
public boolean[] toColumnNullness(Object value, Mapping mapping) { throw new UnsupportedOperationException(); }
public void validate(Mapping mapping) throws MappingException { if(getDiscriminator()==null) { throw new MappingException("No discriminator found for " + getEntityName() + ". Discriminator is needed when 'single-table-per-hierarchy' is used and a class has subclasses"); } super.validate(mapping); }
public T fromXMLString(String xml, Mapping factory) throws HibernateException { return StringHelper.isEmpty( xml ) ? null : fromStringValue( xml ); }
public boolean isValid(Mapping mapping) throws MappingException { return getValue().isValid(mapping); }
public boolean isValid(Mapping mapping) throws MappingException { if (referencedEntityName==null) { throw new MappingException("one to many association must specify the referenced entity"); } return true; }