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

项目:lams    文件:HbmBinder.java   
private static void initLaziness(
        Element node,
        ToOne fetchable,
        Mappings mappings,
        boolean defaultLazy
) {
    if ( "no-proxy".equals( node.attributeValue( "lazy" ) ) ) {
        fetchable.setUnwrapProxy(true);
        fetchable.setLazy( true );
        //TODO: better to degrade to lazy="false" if uninstrumented
    }
    else {
        initLaziness( node, fetchable, mappings, "proxy", defaultLazy );
    }
}
项目:lams    文件:ToOneFkSecondPass.java   
public ToOneFkSecondPass(
        ToOne value,
        Ejb3JoinColumn[] columns,
        boolean unique,
        String entityClassName,
        String path,
        Mappings mappings) {
    super( value, columns );
    this.mappings = mappings;
    this.unique = unique;
    this.entityClassName = entityClassName;
    this.path = entityClassName != null ? path.substring( entityClassName.length() + 1 ) : path;
}
项目:cacheonix-core    文件:HbmBinder.java   
private static void initLaziness(
        Element node,
        ToOne fetchable,
        Mappings mappings,
        boolean defaultLazy
) {
    if ( "no-proxy".equals( node.attributeValue( "lazy" ) ) ) {
        fetchable.setUnwrapProxy(true);
        fetchable.setLazy(true);
        //TODO: better to degrade to lazy="false" if uninstrumented
    }
    else {
        initLaziness(node, fetchable, mappings, "proxy", defaultLazy);
    }
}
项目: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" );
}
项目:hibernate-semantic-query    文件:OrmTypeHelper.java   
public static EntityType convertEntity(
        PersisterCreationContext creationContext,
        ManagedTypeImplementor source,
        String navigableName,
        ToOne entityValue,
        TypeConfiguration typeConfiguration) {
    final String entityName = entityValue.getReferencedEntityName();
    final EntityPersister persister = typeConfiguration.findEntityPersister( entityName );
    if ( persister == null ) {
        throw new IllegalStateException( "Could not resolve EntityPersister : " + entityName );
    }
    return new EntityTypeImpl( null, persister.getJavaTypeDescriptor(), creationContext.getTypeConfiguration() );
}
项目: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    文件:ToOneFkSecondPass.java   
@Override
   public String getReferencedEntityName() {
    return ( (ToOne) value ).getReferencedEntityName();
}
项目:lams    文件:AnnotationBinder.java   
protected static void defineFetchingStrategy(ToOne toOne, XProperty property) {
    LazyToOne lazy = property.getAnnotation( LazyToOne.class );
    Fetch fetch = property.getAnnotation( Fetch.class );
    ManyToOne manyToOne = property.getAnnotation( ManyToOne.class );
    OneToOne oneToOne = property.getAnnotation( OneToOne.class );
    FetchType fetchType;
    if ( manyToOne != null ) {
        fetchType = manyToOne.fetch();
    }
    else if ( oneToOne != null ) {
        fetchType = oneToOne.fetch();
    }
    else {
        throw new AssertionFailure(
                "Define fetch strategy on a property not annotated with @OneToMany nor @OneToOne"
        );
    }
    if ( lazy != null ) {
        toOne.setLazy( !( lazy.value() == LazyToOneOption.FALSE ) );
        toOne.setUnwrapProxy( ( lazy.value() == LazyToOneOption.NO_PROXY ) );
    }
    else {
        toOne.setLazy( fetchType == FetchType.LAZY );
        toOne.setUnwrapProxy( false );
    }
    if ( fetch != null ) {
        if ( fetch.value() == org.hibernate.annotations.FetchMode.JOIN ) {
            toOne.setFetchMode( FetchMode.JOIN );
            toOne.setLazy( false );
            toOne.setUnwrapProxy( false );
        }
        else if ( fetch.value() == org.hibernate.annotations.FetchMode.SELECT ) {
            toOne.setFetchMode( FetchMode.SELECT );
        }
        else if ( fetch.value() == org.hibernate.annotations.FetchMode.SUBSELECT ) {
            throw new AnnotationException( "Use of FetchMode.SUBSELECT not allowed on ToOne associations" );
        }
        else {
            throw new AssertionFailure( "Unknown FetchMode: " + fetch.value() );
        }
    }
    else {
        toOne.setFetchMode( getFetchMode( fetchType ) );
    }
}
项目:lams    文件:PropertyBinder.java   
private boolean isToOneValue(Value value) {
    return ToOne.class.isInstance( value );
}
项目: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;
}