@Override public String getModifyColumnSql(Mapping mapping, Column column, boolean changeNotNull, boolean changeType) { String columnName = column.getQuotedName(this); String nullStr = ""; if( changeNotNull ) { nullStr = column.isNullable() ? " NULL" : " NOT NULL"; } String typeStr = ""; if( changeType ) { typeStr = ' ' + column.getSqlType(this, mapping); } return "MODIFY (" + columnName + typeStr + nullStr + ")"; }
@Override public String getModifyColumnSql(Mapping mapping, Column column, boolean changeNotNull, boolean changeType) { StringBuilder sbuf = new StringBuilder(); String columnName = column.getQuotedName(this); if( changeNotNull ) { sbuf.append("ALTER COLUMN "); sbuf.append(columnName).append(' '); sbuf.append(column.isNullable() ? "DROP" : "SET"); sbuf.append(" NOT NULL"); } if( changeType ) { if( changeNotNull ) { sbuf.append(", "); } sbuf.append("ALTER COLUMN "); sbuf.append(columnName).append(" TYPE ").append(column.getSqlType(this, mapping)); } return sbuf.toString(); }
public synchronized Mapping getMapping() { if( mapping == null ) { ClassLoader oldLoader = oldLoader(); try { setContextLoader(classLoader); mapping = getConfiguration().buildMapping(); } finally { setContextLoader(oldLoader); } } return mapping; }
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 ) .startsWith( columnInfo.getTypeName().toLowerCase() ) || columnInfo.getTypeCode() == col.getSqlTypeCode( mapping ); if ( !typesMatch ) { throw new HibernateException( "Wrong column type: " + col.getName() + ", expected: " + col.getSqlType( dialect, mapping ) ); } } } }
public String sqlTemporaryTableCreateString(Dialect dialect, Mapping mapping) throws HibernateException { StringBuffer buffer = new StringBuffer( dialect.getCreateTemporaryTableString() ) .append( ' ' ) .append( name ) .append( " (" ); Iterator itr = getColumnIterator(); while ( itr.hasNext() ) { final Column column = (Column) itr.next(); buffer.append( column.getQuotedName( dialect ) ).append( ' ' ); buffer.append( column.getSqlType( dialect, mapping ) ); if ( column.isNullable() ) { buffer.append( dialect.getNullColumnString() ); } else { buffer.append( " not null" ); } if ( itr.hasNext() ) { buffer.append( ", " ); } } buffer.append( ") " ); buffer.append( dialect.getCreateTemporaryTablePostfix() ); return buffer.toString(); }
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 int getSqlTypeCode(Mapping mapping) throws MappingException { org.hibernate.type.Type type = getValue().getType(); try { int sqlTypeCode = type.sqlTypes(mapping)[ getTypeIndex() ]; if(getSqlTypeCode()!=null && getSqlTypeCode().intValue()!=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 ); } }
protected void initIdentifierPropertyPaths( final String path, final EntityType etype, final String[] columns, final Mapping factory) throws MappingException { Type idtype = etype.getIdentifierOrUniqueKeyType( factory ); String idPropName = etype.getIdentifierOrUniqueKeyPropertyName(factory); boolean hasNonIdentifierPropertyNamedId = hasNonIdentifierPropertyNamedId( etype, factory ); if ( etype.isReferenceToPrimaryKey() ) { if ( !hasNonIdentifierPropertyNamedId ) { String idpath1 = extendPath(path, EntityPersister.ENTITY_ID); addPropertyPath(idpath1, idtype, columns, null); initPropertyPaths(idpath1, idtype, columns, null, factory); } } if (idPropName!=null) { String idpath2 = extendPath(path, idPropName); addPropertyPath(idpath2, idtype, columns, null); initPropertyPaths(idpath2, idtype, columns, null, factory); } }
public static EntityPersister createClassPersister( PersistentClass model, CacheConcurrencyStrategy cache, SessionFactoryImplementor factory, Mapping cfg) throws HibernateException { Class persisterClass = model.getEntityPersisterClass(); if (persisterClass==null || persisterClass==SingleTableEntityPersister.class) { return new SingleTableEntityPersister(model, cache, factory, cfg); } else if (persisterClass==JoinedSubclassEntityPersister.class) { return new JoinedSubclassEntityPersister(model, cache, factory, cfg); } else if (persisterClass==UnionSubclassEntityPersister.class) { return new UnionSubclassEntityPersister(model, cache, factory, cfg); } else { return create(persisterClass, model, cache, factory, cfg); } }
public Type getReturnType(Type columnType, Mapping mapping) throws QueryException { int[] sqlTypes; try { sqlTypes = columnType.sqlTypes( mapping ); } catch ( MappingException me ) { throw new QueryException( me ); } if ( sqlTypes.length != 1 ) throw new QueryException( "multi-column type in avg()" ); int sqlType = sqlTypes[0]; if ( sqlType == Types.INTEGER || sqlType == Types.BIGINT || sqlType == Types.TINYINT ) { return Hibernate.FLOAT; } else { return columnType; } }
@Override public String getModifyColumnSql(Mapping mapping, Column column, boolean changeNotNull, boolean changeType) { String columnName = column.getQuotedName(this); String nullStr = column.isNullable() ? " NULL" : " NOT NULL"; String typeStr = ' ' + column.getSqlType(this, mapping); return "ALTER COLUMN " + columnName + typeStr + nullStr; }
@Override public String getAddNotNullSql(Mapping mapping, Column column) { String columnName = column.getQuotedName(this); String typeStr = ' ' + column.getSqlType(this, mapping); return "ALTER COLUMN " + columnName + typeStr + " NOT NULL"; }
public String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog, String defaultSchema) { if ( isGenerated( dialect ) ) { String constraintString = sqlConstraintString( dialect, getName(), defaultCatalog, defaultSchema ); StringBuffer buf = new StringBuffer( "alter table " ) .append( getTable().getQualifiedName( dialect, defaultCatalog, defaultSchema ) ) .append( constraintString ); return buf.toString(); } else { return null; } }
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() ); } }
public void validate(Mapping mapping) throws MappingException { if ( getKey().isCascadeDeleteEnabled() && ( !isInverse() || !isOneToMany() ) ) { throw new MappingException( "only inverse one-to-many associations may use on-delete=\"cascade\": " + 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(); if ( elementNodeName!=null && elementNodeName.startsWith("@") ) { throw new MappingException("element node must not be an attribute: " + elementNodeName ); } if ( elementNodeName!=null && elementNodeName.equals(".") ) { throw new MappingException("element node must not be the parent: " + elementNodeName ); } if ( nodeName!=null && nodeName.indexOf('@')>-1 ) { throw new MappingException("collection node must not be an attribute: " + elementNodeName ); } }
public void validate(Mapping mapping) throws MappingException { super.validate(mapping); if ( !getIndex().isValid(mapping) ) { throw new MappingException( "collection index mapping has wrong number of columns: " + getRole() + " type: " + getIndex().getType().getName() ); } if ( indexNodeName!=null && !indexNodeName.startsWith("@") ) { throw new MappingException("index node must be an attribute: " + indexNodeName ); } }
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 void validate(Mapping mapping) throws MappingException { super.validate(mapping); if ( !getIdentifier().isValid(mapping) ) { throw new MappingException( "collection id mapping has wrong number of columns: " + getRole() + " type: " + getIdentifier().getType().getName() ); } }
public String sqlCreateString(Dialect dialect, Mapping mapping, String defaultCatalog, String defaultSchema) throws HibernateException { return buildSqlCreateIndexString( dialect, getName(), getTable(), getColumnIterator(), false, defaultCatalog, defaultSchema ); }
public String sqlCreateString( Dialect dialect, Mapping p, String defaultCatalog, String defaultSchema) throws HibernateException { return injectCatalogAndSchema( sqlCreateString, defaultCatalog, defaultSchema ); }
public void validate(Mapping mapping) throws MappingException { super.validate( mapping ); //for backward compatibility, disable this: /*Iterator iter = getElement().getColumnIterator(); while ( iter.hasNext() ) { Column col = (Column) iter.next(); if ( !col.isNullable() ) { return; } } throw new MappingException("set element mappings must have at least one non-nullable column: " + getRole() );*/ }
public void prepareTemporaryTables(Mapping mapping, Dialect dialect) { if ( dialect.supportsTemporaryTables() ) { temporaryIdTableName = dialect.generateTemporaryTableName( getTable().getName() ); Table table = new Table(); table.setName( temporaryIdTableName ); Iterator itr = getTable().getPrimaryKey().getColumnIterator(); while( itr.hasNext() ) { Column column = (Column) itr.next(); table.addColumn( (Column) column.clone() ); } temporaryIdTableDDL = table.sqlTemporaryTableCreateString( dialect, mapping ); } }
public String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog, String defaultSchema) { if ( dialect.supportsUniqueConstraintInCreateAlterTable() ) { return super.sqlCreateString( dialect, p, defaultCatalog, defaultSchema ); } else { return Index.buildSqlCreateIndexString( dialect, getName(), getTable(), getColumnIterator(), true, defaultCatalog, defaultSchema ); } }
private void initOrdinaryPropertyPaths(Mapping mapping) throws MappingException { for ( int i = 0; i < getSubclassPropertyNameClosure().length; i++ ) { propertyMapping.initPropertyPaths( getSubclassPropertyNameClosure()[i], getSubclassPropertyTypeClosure()[i], getSubclassPropertyColumnNameClosure()[i], getSubclassPropertyFormulaTemplateClosure()[i], mapping ); } }
private void initIdentifierPropertyPaths(Mapping mapping) throws MappingException { String idProp = getIdentifierPropertyName(); if ( idProp != null ) { propertyMapping.initPropertyPaths( idProp, getIdentifierType(), getIdentifierColumnNames(), null, mapping ); } if ( entityMetamodel.getIdentifierProperty().isEmbedded() ) { propertyMapping.initPropertyPaths( null, getIdentifierType(), getIdentifierColumnNames(), null, mapping ); } if ( ! entityMetamodel.hasNonIdentifierPropertyNamedId() ) { propertyMapping.initPropertyPaths( ENTITY_ID, getIdentifierType(), getIdentifierColumnNames(), null, mapping ); } }
public CustomPersister( PersistentClass model, CacheConcurrencyStrategy cache, SessionFactoryImplementor factory, Mapping mapping) { this.factory = factory; }
protected void initPropertyPaths(Mapping mapping) throws MappingException { initOrdinaryPropertyPaths(mapping); initOrdinaryPropertyPaths(mapping); //do two passes, for collection property-ref! initIdentifierPropertyPaths(mapping); if ( entityMetamodel.isPolymorphic() ) { initDiscriminatorPropertyPath( mapping ); } }
private boolean hasNonIdentifierPropertyNamedId(final EntityType entityType, final Mapping factory) { // TODO : would be great to have a Mapping#hasNonIdentifierPropertyNamedId method // I don't believe that Mapping#getReferencedPropertyType accounts for the identifier property; so // if it returns for a property named 'id', then we should have a non-id field named id try { return factory.getReferencedPropertyType( entityType.getAssociatedEntityName(), EntityPersister.ENTITY_ID ) != null; } catch( MappingException e ) { return false; } }
public CompositeElementPropertyMapping( String[] elementColumns, String[] elementFormulaTemplates, AbstractComponentType compositeType, Mapping factory) throws MappingException { this.compositeType = compositeType; initComponentPropertyPaths(null, compositeType, elementColumns, elementFormulaTemplates, factory); }
public Type getReturnType(Type columnType, Mapping mapping) throws QueryException { int[] sqlTypes; try { sqlTypes = columnType.sqlTypes( mapping ); } catch ( MappingException me ) { throw new QueryException( me ); } if ( sqlTypes.length != 1 ) throw new QueryException( "multi-column type in avg()" ); return Hibernate.DOUBLE; }
public Type getReturnType(Type columnType, Mapping mapping) { //pre H3.2 behavior: super.getReturnType(ct, m); int[] sqlTypes; try { sqlTypes = columnType.sqlTypes( mapping ); } catch ( MappingException me ) { throw new QueryException( me ); } if ( sqlTypes.length != 1 ) throw new QueryException( "multi-column type in sum()" ); int sqlType = sqlTypes[0]; // First allow the actual type to control the return value. (the actual underlying sqltype could actually be different) if ( columnType == Hibernate.BIG_INTEGER ) { return Hibernate.BIG_INTEGER; } else if ( columnType == Hibernate.BIG_DECIMAL ) { return Hibernate.BIG_DECIMAL; } else if ( columnType == Hibernate.LONG || columnType == Hibernate.SHORT || columnType == Hibernate.INTEGER) { return Hibernate.LONG; } else if ( columnType == Hibernate.FLOAT || columnType == Hibernate.DOUBLE) { return Hibernate.DOUBLE; } // finally use the sqltype if == on Hibernate types did not find a match. if ( sqlType == Types.NUMERIC ) { return columnType; //because numeric can be anything } else if ( sqlType == Types.FLOAT || sqlType == Types.DOUBLE || sqlType == Types.DECIMAL || sqlType == Types.REAL) { return Hibernate.DOUBLE; } else if ( sqlType == Types.BIGINT || sqlType == Types.INTEGER || sqlType == Types.SMALLINT || sqlType == Types.TINYINT ) { return Hibernate.LONG; } else { return columnType; } }
public int getColumnSpan(Mapping mapping) throws MappingException { int span = 0; for ( int i = 0; i < propertySpan; i++ ) { span += propertyTypes[i].getColumnSpan( mapping ); } return span; }
/** * 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() ) { 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; }
public SingleTableEntityPersister(PersistentClass persistentClass, EntityRegionAccessStrategy cacheAccessStrategy, SessionFactoryImplementor factory, Mapping mapping) throws HibernateException { super(persistentClass, cacheAccessStrategy, factory, mapping); this.hasSubselectLoadableCollections = persistentClass.hasSubselectLoadableCollections(); java.util.Iterator i = persistentClass.getSubclassIterator(); while(!this.hasSubselectLoadableCollections && i.hasNext()) { this.hasSubselectLoadableCollections = ((org.hibernate.mapping.PersistentClass) i.next()).hasSubselectLoadableCollections(); } }
public int getColumnSpan(Mapping mapping) throws MappingException { Type[] types = userType.getPropertyTypes(); int n=0; for (int i=0; i<types.length; i++) { n+=types[i].getColumnSpan(mapping); } return n; }
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; Type[] propertyTypes = getSubtypes(); 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; }
/** * 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() ) { return factory.getIdentifierPropertyName( getAssociatedEntityName() ); } else { return uniqueKeyPropertyName; } }
@Override public String getAddNotNullSql(Mapping mapping, Column column) { String columnName = column.getQuotedName(this); return "MODIFY (" + columnName + " NOT NULL)"; }