Java 类org.hibernate.annotations.common.AssertionFailure 实例源码

项目:lams    文件:ClassPropertyHolder.java   
private void addPropertyToPersistentClass(Property prop, XClass declaringClass) {
    if ( declaringClass != null ) {
        final InheritanceState inheritanceState = inheritanceStatePerClass.get( declaringClass );
        if ( inheritanceState == null ) {
            throw new AssertionFailure(
                    "Declaring class is not found in the inheritance state hierarchy: " + declaringClass
            );
        }
        if ( inheritanceState.isEmbeddableSuperclass() ) {
            persistentClass.addMappedsuperclassProperty(prop);
            addPropertyToMappedSuperclass( prop, declaringClass );
        }
        else {
            persistentClass.addProperty( prop );
        }
    }
    else {
        persistentClass.addProperty( prop );
    }
}
项目:lams    文件:ClassPropertyHolder.java   
private void addPropertyToJoin(Property prop, XClass declaringClass, Join join) {
    if ( declaringClass != null ) {
        final InheritanceState inheritanceState = inheritanceStatePerClass.get( declaringClass );
        if ( inheritanceState == null ) {
            throw new AssertionFailure(
                    "Declaring class is not found in the inheritance state hierarchy: " + declaringClass
            );
        }
        if ( inheritanceState.isEmbeddableSuperclass() ) {
            join.addMappedsuperclassProperty(prop);
            addPropertyToMappedSuperclass( prop, declaringClass );
        }
        else {
            join.addProperty( prop );
        }
    }
    else {
        join.addProperty( prop );
    }
}
项目:lams    文件:HibernateTraversableResolver.java   
private String getStringBasedPath(Path.Node traversableProperty, Path pathToTraversableObject) {
    StringBuilder path = new StringBuilder( );
    for ( Path.Node node : pathToTraversableObject ) {
        if (node.getName() != null) {
            path.append( node.getName() ).append( "." );
        }
    }
    if ( traversableProperty.getName() == null ) {
        throw new AssertionFailure(
                "TraversableResolver being passed a traversableProperty with null name. pathToTraversableObject: "
                        + path.toString() );
    }
    path.append( traversableProperty.getName() );

    return path.toString();
}
项目:lams    文件:PropertyBinder.java   
private void validateBind() {
    if ( property.isAnnotationPresent( Immutable.class ) ) {
        throw new AnnotationException(
                "@Immutable on property not allowed. " +
                        "Only allowed on entity level or on a collection."
        );
    }
    if ( !declaringClassSet ) {
        throw new AssertionFailure( "declaringClass has not been set before a bind" );
    }
}
项目:lams    文件:CollectionBinder.java   
private void defineFetchingStrategy() {
    LazyCollection lazy = property.getAnnotation( LazyCollection.class );
    Fetch fetch = property.getAnnotation( Fetch.class );
    OneToMany oneToMany = property.getAnnotation( OneToMany.class );
    ManyToMany manyToMany = property.getAnnotation( ManyToMany.class );
    ElementCollection elementCollection = property.getAnnotation( ElementCollection.class ); //jpa 2
    ManyToAny manyToAny = property.getAnnotation( ManyToAny.class );
    FetchType fetchType;
    if ( oneToMany != null ) {
        fetchType = oneToMany.fetch();
    }
    else if ( manyToMany != null ) {
        fetchType = manyToMany.fetch();
    }
    else if ( elementCollection != null ) {
        fetchType = elementCollection.fetch();
    }
    else if ( manyToAny != null ) {
        fetchType = FetchType.LAZY;
    }
    else {
        throw new AssertionFailure(
                "Define fetch strategy on a property not annotated with @ManyToOne nor @OneToMany nor @CollectionOfElements"
        );
    }
    if ( lazy != null ) {
        collection.setLazy( !( lazy.value() == LazyCollectionOption.FALSE ) );
        collection.setExtraLazy( lazy.value() == LazyCollectionOption.EXTRA );
    }
    else {
        collection.setLazy( fetchType == FetchType.LAZY );
        collection.setExtraLazy( false );
    }
    if ( fetch != null ) {
        if ( fetch.value() == org.hibernate.annotations.FetchMode.JOIN ) {
            collection.setFetchMode( FetchMode.JOIN );
            collection.setLazy( false );
        }
        else if ( fetch.value() == org.hibernate.annotations.FetchMode.SELECT ) {
            collection.setFetchMode( FetchMode.SELECT );
        }
        else if ( fetch.value() == org.hibernate.annotations.FetchMode.SUBSELECT ) {
            collection.setFetchMode( FetchMode.SELECT );
            collection.setSubselectLoadable( true );
            collection.getOwner().setSubselectLoadableCollections( true );
        }
        else {
            throw new AssertionFailure( "Unknown FetchMode: " + fetch.value() );
        }
    }
    else {
        collection.setFetchMode( AnnotationBinder.getFetchMode( fetchType ) );
    }
}
项目:lams    文件:CollectionBinder.java   
protected void bindOneToManySecondPass(
        Collection collection,
        Map persistentClasses,
        Ejb3JoinColumn[] fkJoinColumns,
        XClass collectionType,
        boolean cascadeDeleteEnabled,
        boolean ignoreNotFound,
        Mappings mappings,
        Map<XClass, InheritanceState> inheritanceStatePerClass) {

    final boolean debugEnabled = LOG.isDebugEnabled();
    if ( debugEnabled ) {
        LOG.debugf( "Binding a OneToMany: %s.%s through a foreign key", propertyHolder.getEntityName(), propertyName );
    }
    org.hibernate.mapping.OneToMany oneToMany = new org.hibernate.mapping.OneToMany( mappings, collection.getOwner() );
    collection.setElement( oneToMany );
    oneToMany.setReferencedEntityName( collectionType.getName() );
    oneToMany.setIgnoreNotFound( ignoreNotFound );

    String assocClass = oneToMany.getReferencedEntityName();
    PersistentClass associatedClass = (PersistentClass) persistentClasses.get( assocClass );
    if ( jpaOrderBy != null ) {
        final String orderByFragment = buildOrderByClauseFromHql(
                jpaOrderBy.value(),
                associatedClass,
                collection.getRole()
        );
        if ( StringHelper.isNotEmpty( orderByFragment ) ) {
            collection.setOrderBy( orderByFragment );
        }
    }

    if ( mappings == null ) {
        throw new AssertionFailure(
                "CollectionSecondPass for oneToMany should not be called with null mappings"
        );
    }
    Map<String, Join> joins = mappings.getJoins( assocClass );
    if ( associatedClass == null ) {
        throw new MappingException(
                "Association references unmapped class: " + assocClass
        );
    }
    oneToMany.setAssociatedClass( associatedClass );
    for (Ejb3JoinColumn column : fkJoinColumns) {
        column.setPersistentClass( associatedClass, joins, inheritanceStatePerClass );
        column.setJoins( joins );
        collection.setCollectionTable( column.getTable() );
    }
    if ( debugEnabled ) {
        LOG.debugf( "Mapping collection: %s -> %s", collection.getRole(), collection.getCollectionTable().getName() );
    }
    bindFilters( false );
    bindCollectionSecondPass( collection, null, fkJoinColumns, cascadeDeleteEnabled, property, mappings );
    if ( !collection.isInverse()
            && !collection.getKey().isNullable() ) {
        // for non-inverse one-to-many, with a not-null fk, add a backref!
        String entityName = oneToMany.getReferencedEntityName();
        PersistentClass referenced = mappings.getClass( entityName );
        Backref prop = new Backref();
        prop.setName( '_' + fkJoinColumns[0].getPropertyName() + '_' + fkJoinColumns[0].getLogicalColumnName() + "Backref" );
        prop.setUpdateable( false );
        prop.setSelectable( false );
        prop.setCollectionRole( collection.getRole() );
        prop.setEntityName( collection.getOwner().getEntityName() );
        prop.setValue( collection.getKey() );
        referenced.addProperty( prop );
    }
}