Java 类org.hibernate.engine.Mapping 实例源码

项目:Equella    文件:ExtendedOracle10gDialect.java   
@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 + ")";
}
项目:Equella    文件:ExtendedPostgresDialect.java   
@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();
}
项目:Equella    文件:HibernateFactory.java   
public synchronized Mapping getMapping()
{
    if( mapping == null )
    {
        ClassLoader oldLoader = oldLoader();
        try
        {
            setContextLoader(classLoader);
            mapping = getConfiguration().buildMapping();
        }
        finally
        {
            setContextLoader(oldLoader);
        }
    }
    return mapping;
}
项目:cacheonix-core    文件:Table.java   
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 )
                );
            }
        }
    }

}
项目:cacheonix-core    文件:Table.java   
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();
}
项目:cacheonix-core    文件:PersistentClass.java   
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();
}
项目:cacheonix-core    文件:Column.java   
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
            );
    }
}
项目:cacheonix-core    文件:AbstractPropertyMapping.java   
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);
    }
}
项目:cacheonix-core    文件:PersisterFactory.java   
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);
    }
}
项目:cacheonix-core    文件:ClassicAvgFunction.java   
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;
    }
}
项目:Equella    文件:SQLServerDialect.java   
@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;
}
项目:Equella    文件:SQLServerDialect.java   
@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";
}
项目:cacheonix-core    文件:Constraint.java   
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;
    }
}
项目:cacheonix-core    文件:JoinedSubclass.java   
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()
            );
    }
}
项目:cacheonix-core    文件:Collection.java   
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 );
    }
}
项目:cacheonix-core    文件:IndexedCollection.java   
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 );
    }
}
项目:cacheonix-core    文件:RootClass.java   
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();
}
项目:cacheonix-core    文件:IdentifierCollection.java   
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()
        );
    }
}
项目:cacheonix-core    文件:Index.java   
public String sqlCreateString(Dialect dialect, Mapping mapping, String defaultCatalog, String defaultSchema)
        throws HibernateException {
    return buildSqlCreateIndexString(
            dialect,
            getName(),
            getTable(),
            getColumnIterator(),
            false,
            defaultCatalog,
            defaultSchema
    );
}
项目:cacheonix-core    文件:UnionSubclass.java   
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()
        );
    }
}
项目:cacheonix-core    文件:SimpleAuxiliaryDatabaseObject.java   
public String sqlCreateString(
        Dialect dialect,
        Mapping p,
        String defaultCatalog,
        String defaultSchema) throws HibernateException {
    return injectCatalogAndSchema( sqlCreateString, defaultCatalog, defaultSchema );
}
项目:cacheonix-core    文件:Set.java   
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() );*/
}
项目:cacheonix-core    文件:PersistentClass.java   
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 );
    }
}
项目:cacheonix-core    文件:UniqueKey.java   
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 );
    }
}
项目:cacheonix-core    文件:AbstractEntityPersister.java   
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 );
    }
}
项目:cacheonix-core    文件:AbstractEntityPersister.java   
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 );
    }
}
项目:cacheonix-core    文件:CustomPersister.java   
public CustomPersister(
        PersistentClass model,
        CacheConcurrencyStrategy cache,
        SessionFactoryImplementor factory,
        Mapping mapping) {
    this.factory = factory;
}
项目:cacheonix-core    文件:AbstractEntityPersister.java   
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 );
    }
}
项目:cacheonix-core    文件:AbstractPropertyMapping.java   
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;
    }
}
项目:cacheonix-core    文件:CompositeElementPropertyMapping.java   
public CompositeElementPropertyMapping(
        String[] elementColumns, 
        String[] elementFormulaTemplates, 
        AbstractComponentType compositeType, 
        Mapping factory)
throws MappingException {

    this.compositeType = compositeType;

    initComponentPropertyPaths(null, compositeType, elementColumns, elementFormulaTemplates, factory);

}
项目:cacheonix-core    文件:Dialect.java   
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;
}
项目:cacheonix-core    文件:Dialect.java   
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;
    }
}
项目:cacheonix-core    文件:ComponentType.java   
public int getColumnSpan(Mapping mapping) throws MappingException {
    int span = 0;
    for ( int i = 0; i < propertySpan; i++ ) {
        span += propertyTypes[i].getColumnSpan( mapping );
    }
    return span;
}
项目:cacheonix-core    文件:EntityType.java   
/**
 * 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;
    }
}
项目:cacheonix-core    文件:ManyToOneType.java   
public boolean[] toColumnNullness(Object value, Mapping mapping) {
    boolean[] result = new boolean[ getColumnSpan( mapping ) ];
    if ( value != null ) {
        Arrays.fill( result, true );
    }
    return result;
}
项目:webdsl    文件:SingleTableEntityPersister.java   
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();
    }
}
项目:cacheonix-core    文件:CompositeCustomType.java   
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;
}
项目:cacheonix-core    文件:CompositeCustomType.java   
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;
}
项目:cacheonix-core    文件:EntityType.java   
/**
 * 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;
    }
}
项目:Equella    文件:ExtendedOracle10gDialect.java   
@Override
public String getAddNotNullSql(Mapping mapping, Column column)
{
    String columnName = column.getQuotedName(this);
    return "MODIFY (" + columnName + " NOT NULL)";
}