Java 类org.hibernate.ogm.model.key.spi.AssociationKeyMetadata 实例源码

项目:hibernate-ogm-ignite    文件:IgniteDatastoreProvider.java   
public Object createAssociationKeyObject( RowKey rowKey, AssociationKeyMetadata keyMetadata ) {
    Object result = null;
    if ( IgniteAssociationSnapshot.isThirdTableAssociation( keyMetadata ) ) {
        result = UUID.randomUUID().toString();
    }
    else {
        String associationKeyColumns[] = keyMetadata.getAssociatedEntityKeyMetadata().getAssociationKeyColumns();
        if ( associationKeyColumns.length == 1 ) {
            result = rowKey.getColumnValue( associationKeyColumns[0] );
        }
        else {
            BinaryObjectBuilder builder = createBinaryObjectBuilder( findKeyType( keyMetadata.getAssociatedEntityKeyMetadata().getEntityKeyMetadata() ) );
            for ( int i = 0; i < associationKeyColumns.length; i++ ) {
                builder.setField( StringHelper.stringAfterPoint( associationKeyColumns[i] ), rowKey.getColumnValue( associationKeyColumns[i] ) );
            }
            result = builder.build();
        }
    }
    return result;
}
项目:hibernate-ogm-ignite    文件:IgniteCacheInitializer.java   
private CacheConfiguration<?,?> createEntityCacheConfiguration(EntityKeyMetadata entityKeyMetadata, SchemaDefinitionContext context) {
    CacheConfiguration<?,?> cacheConfiguration = new CacheConfiguration<>();
    cacheConfiguration.setStoreKeepBinary( true );
    cacheConfiguration.setSqlSchema( QueryUtils.DFLT_SCHEMA );
    cacheConfiguration.setBackups( 1 );
    cacheConfiguration.setName( StringHelper.stringBeforePoint( entityKeyMetadata.getTable() ) );
    cacheConfiguration.setAtomicityMode( CacheAtomicityMode.TRANSACTIONAL );

    QueryEntity queryEntity = new QueryEntity();
    queryEntity.setTableName( entityKeyMetadata.getTable() );
    queryEntity.setKeyType( getEntityIdClassName( entityKeyMetadata.getTable(), context ).getSimpleName() );
    queryEntity.setValueType( StringHelper.stringAfterPoint( entityKeyMetadata.getTable() ) );

    addTableInfo( queryEntity, context, entityKeyMetadata.getTable() );
    for ( AssociationKeyMetadata associationKeyMetadata : context.getAllAssociationKeyMetadata() ) {
        if ( associationKeyMetadata.getAssociationKind() != AssociationKind.EMBEDDED_COLLECTION
                && associationKeyMetadata.getTable().equals( entityKeyMetadata.getTable() )
                && !IgniteAssociationSnapshot.isThirdTableAssociation( associationKeyMetadata ) ) {
            appendIndex( queryEntity, associationKeyMetadata, context );
        }
    }
    log.debugf( "queryEntity: %s", queryEntity );
    cacheConfiguration.setQueryEntities( Arrays.asList( queryEntity ) );
    return cacheConfiguration;
}
项目:hibernate-ogm-ignite    文件:IgniteDialect.java   
/**
     * @param associationMetadata
     * @return index column name for indexed embedded collections or null for collections without index
     */
    private String findIndexColumnName(AssociationKeyMetadata associationMetadata) {
        String indexColumnName = null;
        if ( associationMetadata.getAssociationType() == AssociationType.SET
                || associationMetadata.getAssociationType() == AssociationType.BAG ) {
//          String cols[] =  associationMetadata.getColumnsWithoutKeyColumns(
//                                  Arrays.asList( associationMetadata.getRowKeyColumnNames() )
//                          );
        }
        else {
            if ( associationMetadata.getRowKeyIndexColumnNames().length > 1 ) {
                throw new UnsupportedOperationException( "Multiple index columns not implemented yet" );
            }
            indexColumnName = associationMetadata.getRowKeyIndexColumnNames()[0];
        }

        return indexColumnName;
    }
项目:hibernate-ogm-ignite    文件:IgniteTestHelper.java   
@Override
public long getNumberOfAssociations(SessionFactory sessionFactory) {
    int associationCount = 0;
    IgniteDatastoreProvider datastoreProvider = getProvider( sessionFactory );
    for ( CollectionPersister collectionPersister : ( (SessionFactoryImplementor) sessionFactory ).getCollectionPersisters().values() ) {
        AssociationKeyMetadata associationKeyMetadata = ( (OgmCollectionPersister) collectionPersister ).getAssociationKeyMetadata();
        if ( associationKeyMetadata.getAssociationKind() == AssociationKind.ASSOCIATION ) {
            IgniteCache<Object, BinaryObject> associationCache = getAssociationCache( sessionFactory, associationKeyMetadata );
            StringBuilder query = new StringBuilder( "SELECT " )
                                        .append( StringHelper.realColumnName( associationKeyMetadata.getColumnNames()[0] ) )
                                        .append( " FROM " ).append( associationKeyMetadata.getTable() );
            SqlFieldsQuery sqlQuery = datastoreProvider.createSqlFieldsQueryWithLog( query.toString(), null );
            Iterable<List<?>> queryResult = associationCache.query( sqlQuery );
            Set<Object> uniqs = new HashSet<>();
            for ( List<?> row : queryResult ) {
                Object value = row.get( 0 );
                if ( value != null ) {
                    uniqs.add( value );
                }
            }
            associationCount += uniqs.size();
        }
    }
    return associationCount;
}
项目:hibernate-ogm-ignite    文件:IgniteTestHelper.java   
@Override
public long getNumberOfAssociations(SessionFactory sessionFactory, AssociationStorageType type) {
    int asscociationCount = 0;
    Set<IgniteCache<Object, BinaryObject>> processedCaches = Collections.newSetFromMap( new IdentityHashMap<IgniteCache<Object, BinaryObject>, Boolean>() );

    for ( CollectionPersister collectionPersister : ( (SessionFactoryImplementor) sessionFactory ).getCollectionPersisters().values() ) {
        AssociationKeyMetadata associationKeyMetadata = ( (OgmCollectionPersister) collectionPersister ).getAssociationKeyMetadata();
        IgniteCache<Object, BinaryObject> associationCache = getAssociationCache( sessionFactory, associationKeyMetadata );
        if ( !processedCaches.contains( associationCache ) ) {
            asscociationCount += associationCache.size();
            processedCaches.add( associationCache );
        }
    }

    return asscociationCount;
}
项目:hibernate-ogm-redis    文件:RedisJsonDialect.java   
@Override
public boolean isStoredInEntityStructure(
        AssociationKeyMetadata keyMetadata,
        AssociationTypeContext associationTypeContext) {

    AssociationStorageType associationStorage = getAssociationStorageType( associationTypeContext );

    if ( keyMetadata.getAssociationType() == AssociationType.ONE_TO_ONE || keyMetadata.getAssociationKind() == AssociationKind.EMBEDDED_COLLECTION || associationStorage == AssociationStorageType.IN_ENTITY ) {
        return true;
    }

    return false;
}
项目:hibernate-ogm-redis    文件:RedisHashDialect.java   
@Override
public boolean isStoredInEntityStructure(
        AssociationKeyMetadata keyMetadata, AssociationTypeContext associationTypeContext) {
    if ( keyMetadata.getAssociationType() == AssociationType.ONE_TO_ONE ) {
        return true;
    }
    return false;
}
项目:hibernate-ogm-ignite    文件:IgniteAssociationRowSnapshot.java   
public IgniteAssociationRowSnapshot(Object id, BinaryObject binaryObject, AssociationKeyMetadata associationMetadata) {
    this.id = id;
    this.binaryObject = binaryObject;
    this.associationMetadata = associationMetadata;
    this.thirdTableLink = IgniteAssociationSnapshot.isThirdTableAssociation( associationMetadata );
    if ( this.thirdTableLink ) {
        Set<String> cn = new HashSet<>();
        Collections.addAll( cn, associationMetadata.getRowKeyColumnNames() );
        Collections.addAll( cn, associationMetadata.getAssociatedEntityKeyMetadata().getAssociationKeyColumns() );
        this.columnNames = Collections.unmodifiableSet( cn );
        this.isSimpleId = true; //vk: not used in this case
    }
    else {
        Set<String> idColumnNames = new HashSet<>();
        EntityKeyMetadata entityKeyMetadata = associationMetadata.getAssociatedEntityKeyMetadata().getEntityKeyMetadata();
        for ( String columnName : entityKeyMetadata.getColumnNames() ) {
            if ( entityKeyMetadata.isKeyColumn( columnName ) ) {
                idColumnNames.add( columnName );
            }
        }
        if ( idColumnNames.isEmpty() ) {
            throw new UnsupportedOperationException( "There is no id column in entity " + entityKeyMetadata.getTable() + ". Hmm..." );
        }
        this.columnNames = CollectionHelper.asSet( entityKeyMetadata.getColumnNames() );
        this.isSimpleId = idColumnNames.size() == 1;
    }
}
项目:hibernate-ogm-ignite    文件:IgniteCacheInitializer.java   
private CacheConfiguration createCacheConfiguration(AssociationKeyMetadata associationKeyMetadata, SchemaDefinitionContext context) {
    QueryEntity queryEntity = new QueryEntity();
    queryEntity.setTableName( associationKeyMetadata.getTable() );
    queryEntity.setValueType( StringHelper.stringAfterPoint( associationKeyMetadata.getTable() ) );
    appendIndex( queryEntity, associationKeyMetadata, context );

    CacheConfiguration result = new CacheConfiguration();
    result.setName( StringHelper.stringBeforePoint( associationKeyMetadata.getTable() ) );
    result.setQueryEntities( Arrays.asList( queryEntity ) );
    return result;
}
项目:hibernate-ogm-redis    文件:HashEmbeddedAssociation.java   
public HashEmbeddedAssociation(TuplePointer tuplePointer, AssociationKeyMetadata associationKeyMetadata) {
    this.associationKeyMetadata = associationKeyMetadata;
    this.tuplePointer = tuplePointer;
}
项目:hibernate-ogm-redis    文件:EmbeddedAssociation.java   
public EmbeddedAssociation(TuplePointer tuplePointer, AssociationKeyMetadata associationKeyMetadata) {
    this.tuplePointer = tuplePointer;
    this.associationKeyMetadata = associationKeyMetadata;
}
项目:hibernate-ogm-ignite    文件:IgniteDatastoreProvider.java   
public IgniteCache<Object, BinaryObject> getAssociationCache(AssociationKeyMetadata keyMetadata) {
    return keyMetadata.getAssociationKind() == AssociationKind.EMBEDDED_COLLECTION
                ? getEntityCache( keyMetadata.getEntityKeyMetadata() )
                : getEntityCache( keyMetadata.getTable() );
}
项目:hibernate-ogm-ignite    文件:IgniteAssociationSnapshot.java   
/**
 * @param associationMetadata
 * @return true - is association through third table
 */
public static boolean isThirdTableAssociation(AssociationKeyMetadata associationMetadata) {
    return !associationMetadata.getTable().equals(
                    associationMetadata.getAssociatedEntityKeyMetadata().getEntityKeyMetadata().getTable()
            );
}
项目:hibernate-ogm-ignite    文件:IgniteCacheInitializer.java   
private void appendIndex(QueryEntity queryEntity, AssociationKeyMetadata associationKeyMetadata, SchemaDefinitionContext context) {
    for ( String idFieldName : associationKeyMetadata.getRowKeyColumnNames() ) {
        queryEntity.addQueryField( generateIndexName( idFieldName ), STRING_CLASS_NAME, null );
        queryEntity.setIndexes( Arrays.asList( new QueryIndex( generateIndexName( idFieldName ), QueryIndexType.SORTED  ) ) );
    }
}
项目:hibernate-ogm-ignite    文件:IgniteDialect.java   
@Override
public boolean isStoredInEntityStructure(AssociationKeyMetadata associationKeyMetadata, AssociationTypeContext associationTypeContext) {
    return false;
}
项目:hibernate-ogm-ignite    文件:IgniteTestHelper.java   
public static IgniteCache<Object, BinaryObject> getAssociationCache(SessionFactory sessionFactory, AssociationKeyMetadata associationKeyMetadata) {
    IgniteDatastoreProvider castProvider = getProvider( sessionFactory );
    return castProvider.getAssociationCache( associationKeyMetadata );
}
项目:lightblue-hibernate-ogm    文件:LightblueDialect.java   
@Override
public boolean isStoredInEntityStructure(AssociationKeyMetadata associationKeyMetadata, AssociationTypeContext associationTypeContext) {
    return true;
    // TODO figure out
}
项目:hibernate-ogm-redis    文件:RedisAssociation.java   
/**
 * Creates a {@link RedisAssociation} from the given {@link TuplePointer} and association name.
 *
 * @param tuplePointer a pointer to the owner of the association
 * @param associationKeyMetadata association key meta-data
 *
 * @return a {@link RedisAssociation} representing the association
 */
public static RedisAssociation fromEmbeddedAssociation(
        TuplePointer tuplePointer,
        AssociationKeyMetadata associationKeyMetadata) {
    return new EmbeddedAssociation( tuplePointer, associationKeyMetadata );
}
项目:hibernate-ogm-redis    文件:RedisAssociation.java   
/**
 * Creates a {@link RedisAssociation} from the given {@link java.util.Map} and association name.
 *
 * @param tuplePointer a pointer to the owner of the association
 * @param associationKeyMetadata association key meta-data
 *
 * @return a {@link RedisAssociation} representing the association
 */
public static RedisAssociation fromHashEmbeddedAssociation(
        TuplePointer tuplePointer,
        AssociationKeyMetadata associationKeyMetadata) {
    return new HashEmbeddedAssociation( tuplePointer, associationKeyMetadata );
}