Java 类org.hibernate.mapping.Value 实例源码

项目:lams    文件:EntityBinder.java   
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 );
    }
}
项目:lams    文件:TableBinder.java   
public static void createUniqueConstraint(Value value) {
    Iterator iter = value.getColumnIterator();
    ArrayList cols = new ArrayList();
    while ( iter.hasNext() ) {
        cols.add( iter.next() );
    }
    value.getTable().createUniqueKey( cols );
}
项目:hibernate-semantic-query    文件:CollectionPersisterImpl.java   
public CollectionPersisterImpl(
            Collection collectionBinding,
            ManagedTypeImplementor source,
            String localName,
            CollectionRegionAccessStrategy collectionCaching,
            PersisterCreationContext creationContext) {
        super( source, localName, PropertyAccess.DUMMY );
        this.source = source;
        this.localName = localName;
        this.role = source.getNavigableName() + '.' + this.localName;
        this.collectionClassification = PersisterHelper.interpretCollectionClassification( collectionBinding );
        this.foreignKeyDescriptor = new CollectionKey( this );

        this.typeConfiguration = creationContext.getTypeConfiguration();

        this.collectionType = new CollectionTypeImpl(
                role,
                resolveCollectionJtd( creationContext, collectionClassification ),
                null,
                null
        );

        if ( collectionBinding instanceof IndexedCollection ) {
            final Value indexValueMapping = ( (IndexedCollection) collectionBinding ).getIndex();
            if ( indexValueMapping instanceof SimpleValue ) {
                final SimpleValue simpleIndexValueMapping = (SimpleValue) indexValueMapping;
//              indexAttributeConverter = simpleIndexValueMapping.getAttributeConverterDescriptor().getAttributeConverter();
            }
        }

        final Value elementValueMapping = collectionBinding.getElement();
        if ( elementValueMapping instanceof SimpleValue ) {
            final SimpleValue simpleElementValueMapping = (SimpleValue) elementValueMapping;
//          elementAttributeConverter = simpleElementValueMapping.getAttributeConverterDescriptor().getAttributeConverter();
        }
    }
项目:hibernate-semantic-query    文件:PersisterHelper.java   
public OrmAttribute buildAttribute(
        PersisterCreationContext creationContext,
        OrmNavigableSource source,
        Value value,
        String propertyName,
        Type propertyType,
        List<Column> columns) {
    if ( propertyType instanceof org.hibernate.orm.type.spi.CollectionType ) {
        assert columns == null || columns.isEmpty();

        return buildPluralAttribute(
                creationContext,
                (Collection) value,
                source,
                propertyName
        );
    }
    else {
        return buildSingularAttribute(
                creationContext,
                source,
                value,
                propertyName,
                propertyType,
                columns
        );
    }
}
项目:hibernate-semantic-query    文件:OrmTypeHelper.java   
public static <T> Type convert(
        PersisterCreationContext creationContext,
        ManagedTypeImplementor source,
        String navigableName,
        Value valueBinding,
        TypeConfiguration typeConfiguration) {
    if ( valueBinding.getType() == null ) {
        return null;
    }

    if ( valueBinding.getType() instanceof org.hibernate.type.BasicType ) {
        return convertBasic( (BasicType) valueBinding.getType(), typeConfiguration );
    }

    if ( valueBinding.getType() instanceof org.hibernate.type.CompositeType ) {
        return convertEmbedded( creationContext, source, navigableName, (Component) valueBinding, typeConfiguration );
    }

    if ( valueBinding.getType() instanceof org.hibernate.type.CollectionType ) {
        return convertCollection( creationContext, source, navigableName, (Collection) valueBinding, typeConfiguration );
    }

    if ( valueBinding.getType() instanceof org.hibernate.type.ManyToOneType ) {
        return convertEntity( creationContext, source, navigableName, (ToOne) valueBinding, typeConfiguration );
    }

    throw new NotYetImplementedException( "Converting " + valueBinding.getType().getClass().getName() + " -> org.hibernate.orm.type.spi.Type" );
}
项目:cagrid-core    文件:HibernateConfigTypesInformationResolver.java   
public String getEndName(String parentClassname, String childClassname) throws TypesInformationException {
    LOG.debug("Getting the association end name for " + parentClassname + " to " + childClassname);
    String identifier = getAssociationIdentifier(parentClassname, childClassname);
    String roleName = roleNames.get(identifier);
    if (roleName == null) {
        PersistentClass clazz = findPersistentClass(parentClassname);
        Iterator<?> propertyIter = clazz.getPropertyIterator();
        while (propertyIter.hasNext()) {
            Property prop = (Property) propertyIter.next();
            Value value = prop.getValue();
            String referencedEntity = null;
            if (value instanceof Collection) {
                Value element = ((Collection) value).getElement();
                if (element instanceof OneToMany) {
                    referencedEntity = ((OneToMany) element).getReferencedEntityName();
                } else if (element instanceof ToOne) {
                    referencedEntity = ((ToOne) element).getReferencedEntityName();
                }
            } else if (value instanceof ToOne) {
                referencedEntity = ((ToOne) value).getReferencedEntityName();
            }
            if (childClassname.equals(referencedEntity)) {
                if (roleName != null) {
                    // already found one association, so this is ambiguous
                    throw new TypesInformationException("Association from " + parentClassname + " to " 
                        + childClassname + " is ambiguous.  Please specify a valid role name");
                }
                roleName = prop.getName();
            }
        }
    }
    return roleName;
}
项目:lams    文件:FkSecondPass.java   
public Value getValue() {
    return value;
}
项目:lams    文件:PropertyBinder.java   
public void setValue(Value value) {
    this.value = value;
}
项目:lams    文件:PropertyBinder.java   
private boolean isToOneValue(Value value) {
    return ToOne.class.isInstance( value );
}
项目:lams    文件:PropertyBinder.java   
public Value getValue() {
    return value;
}
项目:hibernate-semantic-query    文件:EntityHierarchyImpl.java   
private static List<Column> resolveColumns(
            Table table,
            Value value,
            PersisterCreationContext creationContext) {
        final String[] columnNames = new String[value.getColumnSpan()];
        final String[] formulas = value.hasFormula() ? new String[value.getColumnSpan()] : null;
        //final SqlTypeDescriptor[] sqlTypeDescriptors = new SqlTypeDescriptor[value.getColumnSpan()];
        final int[] jdbcTypeCodes = new int[value.getColumnSpan()];

        final Iterator<Selectable> itr = value.getColumnIterator();
        int i = 0;
        while ( itr.hasNext() ) {
            final Selectable selectable = itr.next();
            if ( selectable instanceof org.hibernate.mapping.Column ) {
//              columnNames[i] = ( (org.hibernate.mapping.Column) selectable ).getQuotedName(
//                      creationContext.getSessionFactory().getJdbcServices().getJdbcEnvironment().getDialect()
//              );
                columnNames[i] = '`' + ( (org.hibernate.mapping.Column) selectable ).getName() + '`';
            }
            else {
                if ( formulas == null ) {
                    throw new HibernateException(
                            "Value indicated it does not have formulas, but a formula was encountered : " + selectable );
                }
                formulas[i] = ( (Formula) selectable ).getFormula();
            }

            // todo : need access to the TypeConfiguration...
            //sqlTypeDescriptors[i] = creationContext.getSessionFactory()
            jdbcTypeCodes[i] = value.getType().sqlTypes( null )[i];

            // todo : keep track of readers/writers... how exactly?
            // something like this vv ?
            //      Column#applyReadExpression( col.getReadExpr( dialect ) )
            //      Column#applyWriteExpression( col.getWriteExpr() )

            i++;
        }

        // makeColumns(
        //      creationContext,
        //      tableSelector,
        //      columnNames,
        //      formulas,
        //      sqlTypeDescriptors (or just JDBC type codes?)
        // )
        return PersisterHelper.makeValues(
                creationContext,
                // todo : a Table "selector"...
                table,
                columnNames,
                formulas,
                jdbcTypeCodes
        );
    }
项目:hibernate-semantic-query    文件:PersisterHelper.java   
public AbstractOrmAttribute buildSingularAttribute(
            PersisterCreationContext creationContext,
            OrmNavigableSource source,
            Value value,
            String attributeName,
            Type attributeType,
            List<Column> columns) {
        final SingularAttributeClassification classification = interpretSingularAttributeClassification( attributeType );
        if ( classification == SingularAttributeClassification.ANY ) {
            throw new NotYetImplementedException();
        }
        else if ( classification == SingularAttributeClassification.EMBEDDED ) {
            return new SingularAttributeEmbedded(
                    (ManagedTypeImplementor) source,
                    attributeName,
                    PropertyAccess.DUMMY,
                    SingularAttribute.Disposition.NORMAL,
                    buildEmbeddablePersister(
                            creationContext,
                            (EmbeddableContainer) source,
                            attributeName,
                            (Component) value,
                            columns
                    )
            );
        }
        else if ( classification == SingularAttributeClassification.BASIC ) {
            // todo : need to be able to locate the AttributeConverter (if one) associated with this singular basic attribute
//          final AttributeConverter attributeConverter = ( (SimpleValue) value ).getAttributeConverterDescriptor().getAttributeConverter();
            final AttributeConverter attributeConverter = null;
            return new SingularAttributeBasic(
                    (ManagedTypeImplementor) source,
                    attributeName,
                    PropertyAccess.DUMMY,
                    (BasicType) attributeType,
                    SingularAttribute.Disposition.NORMAL,
                    attributeConverter,
                    columns
            );
        }
        else {
            final EntityType ormEntityType = (EntityType) attributeType;
            return new SingularAttributeEntity(
                    (ManagedTypeImplementor) source,
                    attributeName,
                    PropertyAccess.DUMMY,
                    SingularAttribute.Disposition.NORMAL,
                    classification,
                    ormEntityType,
                    columns
            );
        }
    }
项目:cagrid-core    文件:HibernateConfigTypesInformationResolver.java   
public String getRoleName(String parentClassname, String childClassname) throws TypesInformationException {
    String identifier = getAssociationIdentifier(parentClassname, childClassname);
    String roleName = roleNames.get(identifier);
    if (roleName == null) {
        PersistentClass clazz = configuration.getClassMapping(parentClassname);
        Iterator<?> propertyIter = clazz.getPropertyIterator();
        while (propertyIter.hasNext()) {
            Property prop = (Property) propertyIter.next();
            Value value = prop.getValue();
            String referencedEntity = null;
            if (value instanceof Collection) {
                Value element = ((Collection) value).getElement();
                if (element instanceof OneToMany) {
                    referencedEntity = ((OneToMany) element).getReferencedEntityName();
                } else if (element instanceof ToOne) {
                    referencedEntity = ((ToOne) element).getReferencedEntityName();
                }
            } else if (value instanceof ToOne) {
                referencedEntity = ((ToOne) value).getReferencedEntityName();
            }
            if (childClassname.equals(referencedEntity)) {
                if (roleName != null) {
                    // already found one association, so this is ambiguous
                    throw new TypesInformationException("Association from " + parentClassname + " to " 
                        + childClassname + " is ambiguous.  Please specify a valid role name");
                }
                roleName = prop.getName();
            }
        }
        if (roleName == null && reflectionFallback) {
            LOG.debug("No role name found for " + identifier + " using hibernate configuration, trying reflection");
            Class<?> parentClass = null;
            try {
                parentClass = Class.forName(parentClassname);
            } catch (ClassNotFoundException ex) {
                LOG.error("Could not load parent class: " + ex.getMessage());
                throw new TypesInformationException("Could not load parent class: " + ex.getMessage());
            }
            Field[] fields = parentClass.getDeclaredFields();
            for (Field f : fields) {
                // if collection, inspect the collection for type
                Class<?> fieldType = f.getType();
                if (java.util.Collection.class.isAssignableFrom(fieldType)) {
                    Type generic = f.getGenericType();
                    if (generic instanceof ParameterizedType) {
                        Type contents = ((ParameterizedType) generic).getActualTypeArguments()[0];
                        if (contents instanceof Class 
                            && childClassname.equals(((Class<?>) contents).getName())) {
                            roleName = f.getName();
                        }
                    }
                } else if (fieldType.getName().equals(childClassname)) {
                    if (roleName != null) {
                        // already found one association, so this is ambiguous
                        throw new TypesInformationException("Association from " + parentClassname + " to " 
                            + childClassname + " is ambiguous.  Please specify a valid role name");
                    }
                    roleName = f.getName();
                }
            }
        }
    }
    return roleName;
}
项目:cagrid-core    文件:HibernateConfigTypesInformationResolver.java   
public String getRoleName(String parentClassname, String childClassname) throws TypesInformationException {
    String identifier = getAssociationIdentifier(parentClassname, childClassname);
    String roleName = roleNames.get(identifier);
    if (roleName == null) {
        PersistentClass clazz = configuration.getClassMapping(parentClassname);
        Iterator<?> propertyIter = clazz.getPropertyIterator();
        while (propertyIter.hasNext()) {
            Property prop = (Property) propertyIter.next();
            Value value = prop.getValue();
            String referencedEntity = null;
            if (value instanceof Collection) {
                Value element = ((Collection) value).getElement();
                if (element instanceof OneToMany) {
                    referencedEntity = ((OneToMany) element).getReferencedEntityName();
                } else if (element instanceof ToOne) {
                    referencedEntity = ((ToOne) element).getReferencedEntityName();
                }
            } else if (value instanceof ToOne) {
                referencedEntity = ((ToOne) value).getReferencedEntityName();
            }
            if (childClassname.equals(referencedEntity)) {
                if (roleName != null) {
                    // already found one association, so this is ambiguous
                    throw new TypesInformationException("Association from " + parentClassname + " to " 
                        + childClassname + " is ambiguous.  Please specify a valid role name");
                }
                roleName = prop.getName();
            }
        }
        if (roleName == null && reflectionFallback) {
            LOG.debug("No role name found for " + identifier + " using hibernate configuration, trying reflection");
            Class<?> parentClass = null;
            try {
                parentClass = Class.forName(parentClassname);
            } catch (ClassNotFoundException ex) {
                LOG.error("Could not load parent class: " + ex.getMessage());
                throw new TypesInformationException("Could not load parent class: " + ex.getMessage());
            }
            Field[] fields = parentClass.getDeclaredFields();
            for (Field f : fields) {
                // if collection, inspect the collection for type
                Class<?> fieldType = f.getType();
                if (java.util.Collection.class.isAssignableFrom(fieldType)) {
                    Type generic = f.getGenericType();
                    if (generic instanceof ParameterizedType) {
                        Type contents = ((ParameterizedType) generic).getActualTypeArguments()[0];
                        if (contents instanceof Class 
                            && childClassname.equals(((Class) contents).getName())) {
                            roleName = f.getName();
                        }
                    }
                } else if (fieldType.getName().equals(childClassname)) {
                    if (roleName != null) {
                        // already found one association, so this is ambiguous
                        throw new TypesInformationException("Association from " + parentClassname + " to " 
                            + childClassname + " is ambiguous.  Please specify a valid role name");
                    }
                    roleName = f.getName();
                }
            }
        }
    }
    return roleName;
}