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

项目:lams    文件:ToOneFkSecondPass.java   
@Override
   public boolean isInPrimaryKey() {
    if ( entityClassName == null ) return false;
    final PersistentClass persistentClass = mappings.getClass( entityClassName );
    Property property = persistentClass.getIdentifierProperty();
    if ( path == null ) {
        return false;
    }
    else if ( property != null) {
        //try explicit identifier property
        return path.startsWith( property.getName() + "." );
    }
    else {
        //try the embedded property
        //embedded property starts their path with 'id.' See PropertyPreloadedData( ) use when idClass != null in AnnotationSourceProcessor
        if ( path.startsWith( "id." ) ) {
            KeyValue valueIdentifier = persistentClass.getIdentifier();
            String localPath = path.substring( 3 );
            if ( valueIdentifier instanceof Component ) {
                Iterator it = ( (Component) valueIdentifier ).getPropertyIterator();
                while ( it.hasNext() ) {
                    Property idProperty = (Property) it.next();
                    if ( localPath.startsWith( idProperty.getName() ) ) return true;
                }

            }
        }
    }
    return false;
}
项目:lams    文件:PropertyFactory.java   
/**
 * Generates a VersionProperty representation for an entity mapping given its
 * version mapping Property.
 *
 * @param property The version mapping Property.
 * @param lazyAvailable Is property lazy loading currently available.
 * @return The appropriate VersionProperty definition.
 */
public static VersionProperty buildVersionProperty(
        EntityPersister persister,
        SessionFactoryImplementor sessionFactory,
        int attributeNumber,
        Property property,
        boolean lazyAvailable) {
    String mappedUnsavedValue = ( (KeyValue) property.getValue() ).getNullValue();

    VersionValue unsavedValue = UnsavedValueFactory.getUnsavedVersionValue(
            mappedUnsavedValue,
            getGetter( property ),
            (VersionType) property.getType(),
            getConstructor( property.getPersistentClass() )
    );

    boolean lazy = lazyAvailable && property.isLazy();

    return new VersionProperty(
            persister,
            sessionFactory,
            attributeNumber,
            property.getName(),
            property.getValue().getType(),
            new BaselineAttributeInformation.Builder()
                    .setLazy( lazy )
                    .setInsertable( property.isInsertable() )
                    .setUpdateable( property.isUpdateable() )
                    .setValueGenerationStrategy( property.getValueGenerationStrategy() )
                    .setNullable( property.isOptional() )
                    .setDirtyCheckable( property.isUpdateable() && !lazy )
                    .setVersionable( property.isOptimisticLocked() )
                    .setCascadeStyle( property.getCascadeStyle() )
                    .createInformation(),
            unsavedValue
        );
}
项目:cacheonix-core    文件:PropertyFactory.java   
/**
 * Generates a VersionProperty representation for an entity mapping given its
 * version mapping Property.
 *
 * @param property The version mapping Property.
 * @param lazyAvailable Is property lazy loading currently available.
 * @return The appropriate VersionProperty definition.
 */
public static VersionProperty buildVersionProperty(Property property, boolean lazyAvailable) {
    String mappedUnsavedValue = ( (KeyValue) property.getValue() ).getNullValue();

    VersionValue unsavedValue = UnsavedValueFactory.getUnsavedVersionValue(
            mappedUnsavedValue, 
            getGetter( property ),
            (VersionType) property.getType(),
            getConstructor( property.getPersistentClass() )
        );

    boolean lazy = lazyAvailable && property.isLazy();

    return new VersionProperty(
            property.getName(),
            property.getNodeName(),
            property.getValue().getType(),
            lazy,
            property.isInsertable(),
            property.isUpdateable(),
            property.getGeneration() == PropertyGeneration.INSERT || property.getGeneration() == PropertyGeneration.ALWAYS,
            property.getGeneration() == PropertyGeneration.ALWAYS,
            property.isOptional(),
            property.isUpdateable() && !lazy,
            property.isOptimisticLocked(),
            property.getCascadeStyle(),
            unsavedValue
        );
}
项目:lams    文件:ClassPropertyHolder.java   
public KeyValue getIdentifier() {
    return persistentClass.getIdentifier();
}
项目:lams    文件:CollectionPropertyHolder.java   
public KeyValue getIdentifier() {
    throw new AssertionFailure( "Identifier collection not yet managed" );
}
项目:lams    文件:ComponentPropertyHolder.java   
public KeyValue getIdentifier() {
    return component.getOwner().getIdentifier();
}
项目:lams    文件:AnnotationBinder.java   
private static void bindOneToOne(
        String cascadeStrategy,
        Ejb3JoinColumn[] joinColumns,
        boolean optional,
        FetchMode fetchMode,
        boolean ignoreNotFound,
        boolean cascadeOnDelete,
        XClass targetEntity,
        PropertyHolder propertyHolder,
        PropertyData inferredData,
        String mappedBy,
        boolean trueOneToOne,
        boolean isIdentifierMapper,
        boolean inSecondPass,
        PropertyBinder propertyBinder,
        Mappings mappings) {
    //column.getTable() => persistentClass.getTable()
    final String propertyName = inferredData.getPropertyName();
    LOG.tracev( "Fetching {0} with {1}", propertyName, fetchMode );
    boolean mapToPK = true;
    if ( !trueOneToOne ) {
        //try to find a hidden true one to one (FK == PK columns)
        KeyValue identifier = propertyHolder.getIdentifier();
        if ( identifier == null ) {
            //this is a @OneToOne in a @EmbeddedId (the persistentClass.identifier is not set yet, it's being built)
            //by definition the PK cannot refers to itself so it cannot map to itself
            mapToPK = false;
        }
        else {
            Iterator idColumns = identifier.getColumnIterator();
            List<String> idColumnNames = new ArrayList<String>();
            org.hibernate.mapping.Column currentColumn;
            if ( identifier.getColumnSpan() != joinColumns.length ) {
                mapToPK = false;
            }
            else {
                while ( idColumns.hasNext() ) {
                    currentColumn = ( org.hibernate.mapping.Column ) idColumns.next();
                    idColumnNames.add( currentColumn.getName() );
                }
                for ( Ejb3JoinColumn col : joinColumns ) {
                    if ( !idColumnNames.contains( col.getMappingColumn().getName() ) ) {
                        mapToPK = false;
                        break;
                    }
                }
            }
        }
    }
    if ( trueOneToOne || mapToPK || !BinderHelper.isEmptyAnnotationValue( mappedBy ) ) {
        //is a true one-to-one
        //FIXME referencedColumnName ignored => ordering may fail.
        OneToOneSecondPass secondPass = new OneToOneSecondPass(
                mappedBy,
                propertyHolder.getEntityName(),
                propertyName,
                propertyHolder, inferredData, targetEntity, ignoreNotFound, cascadeOnDelete,
                optional, cascadeStrategy, joinColumns, mappings
        );
        if ( inSecondPass ) {
            secondPass.doSecondPass( mappings.getClasses() );
        }
        else {
            mappings.addSecondPass(
                    secondPass, BinderHelper.isEmptyAnnotationValue( mappedBy )
            );
        }
    }
    else {
        //has a FK on the table
        bindManyToOne(
                cascadeStrategy, joinColumns, optional, ignoreNotFound, cascadeOnDelete,
                targetEntity,
                propertyHolder, inferredData, true, isIdentifierMapper, inSecondPass,
                propertyBinder, mappings
        );
    }
}
项目:lams    文件:CollectionBinder.java   
/**
 * bind the inverse FK of a ManyToMany
 * If we are in a mappedBy case, read the columns from the associated
 * collection element
 * Otherwise delegates to the usual algorithm
 */
public static void bindManytoManyInverseFk(
        PersistentClass referencedEntity,
        Ejb3JoinColumn[] columns,
        SimpleValue value,
        boolean unique,
        Mappings mappings) {
    final String mappedBy = columns[0].getMappedBy();
    if ( StringHelper.isNotEmpty( mappedBy ) ) {
        final Property property = referencedEntity.getRecursiveProperty( mappedBy );
        Iterator mappedByColumns;
        if ( property.getValue() instanceof Collection ) {
            mappedByColumns = ( (Collection) property.getValue() ).getKey().getColumnIterator();
        }
        else {
            //find the appropriate reference key, can be in a join
            Iterator joinsIt = referencedEntity.getJoinIterator();
            KeyValue key = null;
            while ( joinsIt.hasNext() ) {
                Join join = (Join) joinsIt.next();
                if ( join.containsProperty( property ) ) {
                    key = join.getKey();
                    break;
                }
            }
            if ( key == null ) key = property.getPersistentClass().getIdentifier();
            mappedByColumns = key.getColumnIterator();
        }
        while ( mappedByColumns.hasNext() ) {
            Column column = (Column) mappedByColumns.next();
            columns[0].linkValueUsingAColumnCopy( column, value );
        }
        String referencedPropertyName =
                mappings.getPropertyReferencedAssociation(
                        "inverse__" + referencedEntity.getEntityName(), mappedBy
                );
        if ( referencedPropertyName != null ) {
            //TODO always a many to one?
            ( (ManyToOne) value ).setReferencedPropertyName( referencedPropertyName );
            mappings.addUniquePropertyReference( referencedEntity.getEntityName(), referencedPropertyName );
        }
        ( (ManyToOne) value ).setReferenceToPrimaryKey( referencedPropertyName == null );
        value.createForeignKey();
    }
    else {
        BinderHelper.createSyntheticPropertyReference( columns, referencedEntity, null, value, true, mappings );
        TableBinder.bindFk( referencedEntity, null, columns, value, unique, mappings );
    }
}
项目:lams    文件:PropertyBinder.java   
private Property bind(Property prop) {
    if (isId) {
        final RootClass rootClass = ( RootClass ) holder.getPersistentClass();
        //if an xToMany, it as to be wrapped today.
        //FIXME this pose a problem as the PK is the class instead of the associated class which is not really compliant with the spec
        if ( isXToMany || entityBinder.wrapIdsInEmbeddedComponents() ) {
            Component identifier = (Component) rootClass.getIdentifier();
            if (identifier == null) {
                identifier = AnnotationBinder.createComponent( holder, new PropertyPreloadedData(null, null, null), true, false, mappings );
                rootClass.setIdentifier( identifier );
                identifier.setNullValue( "undefined" );
                rootClass.setEmbeddedIdentifier( true );
                rootClass.setIdentifierMapper( identifier );
            }
            //FIXME is it good enough?
            identifier.addProperty( prop );
        }
        else {
            rootClass.setIdentifier( ( KeyValue ) getValue() );
            if (embedded) {
                rootClass.setEmbeddedIdentifier( true );
            }
            else {
                rootClass.setIdentifierProperty( prop );
                final org.hibernate.mapping.MappedSuperclass superclass = BinderHelper.getMappedSuperclassOrNull(
                        declaringClass,
                        inheritanceStatePerClass,
                        mappings
                );
                if (superclass != null) {
                    superclass.setDeclaredIdentifierProperty(prop);
                }
                else {
                    //we know the property is on the actual entity
                    rootClass.setDeclaredIdentifierProperty( prop );
                }
            }
        }
    }
    else {
        holder.addProperty( prop, columns, declaringClass );
    }
    return prop;
}
项目:hibernate-semantic-query    文件:EntityHierarchyImpl.java   
private static IdentifierDescriptor interpretIdentifierDescriptor(
            EntityHierarchyImpl hierarchy,
            EntityPersister rootEntityPersister,
            PersisterCreationContext creationContext,
            RootClass rootEntityBinding,
            Table identifierTable) {
        final KeyValue identifierValueMapping = rootEntityBinding.getIdentifier();

        final List<Column> idColumns = resolveColumns( identifierTable, identifierValueMapping, creationContext );

        if ( identifierValueMapping.getType() instanceof org.hibernate.type.BasicType ) {
            return new IdentifierDescriptorSimpleImpl(
                    hierarchy.getRootEntityPersister(),
                    rootEntityBinding.getIdentifierProperty().getName(),
                    OrmTypeHelper.convertBasic(
                            (org.hibernate.type.BasicType) identifierValueMapping.getType(),
                            creationContext.getTypeConfiguration()
                    ),
                    idColumns
            );
        }
        else {
            final CompositeType cidType = (CompositeType) identifierValueMapping.getType();
            // todo : need to pass along that any built sub attributes are part of the id
            if ( rootEntityBinding.hasIdentifierProperty() ) {
                return new IdentifierDescriptorAggregatedEmbeddedImpl(
                        (SingularAttributeEmbedded) PersisterHelper.INSTANCE.buildSingularAttribute(
                                creationContext,
                                // the declaring type...
                                ///     for now we use the root entity
                                hierarchy.getRootEntityPersister(),
                                // value?
                                null,
                                rootEntityBinding.getIdentifierProperty().getName(),
                                OrmTypeHelper.convertComposite(
                                        creationContext,
                                        rootEntityBinding.getIdentifierProperty().getName(),
                                        (Component) identifierValueMapping,
                                        hierarchy.getRootEntityPersister(),
                                        creationContext.getTypeConfiguration()
                                ),
                                idColumns
                        )
                );
            }
            else {
                // todo : pass info about ther IdClass
                return new IdentifierDescriptorNonAggregatedEmbeddedImpl(
                        rootEntityPersister,
                        OrmTypeHelper.convertComposite(
                                creationContext,
                                "<id>",
                                (Component) identifierValueMapping,
                                hierarchy.getRootEntityPersister(),
                                creationContext.getTypeConfiguration()
                        ),
                        OrmTypeHelper.convertComposite(
                                creationContext,
                                "<IdClass>",
                                rootEntityBinding.getIdentifierMapper(),
                                hierarchy.getRootEntityPersister(),
                                creationContext.getTypeConfiguration()
                        )
                );

//                      PersisterHelper.INSTANCE.buildEmbeddablePersister(
//                              creationContext,
//                              hierarchy.getRootEntityPersister(),
//                              rootEntityBinding.getEntityName() + ".id",
//                              cidType,
//                              idColumns
//                      )
            }
        }
    }
项目:lams    文件:PropertyHolder.java   
KeyValue getIdentifier();