本文整理了Java中org.hibernate.ogm.model.spi.Association.isEmpty()
方法的一些代码示例,展示了Association.isEmpty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Association.isEmpty()
方法的具体详情如下:
包路径:org.hibernate.ogm.model.spi.Association
类名称:Association
方法名:isEmpty
[英]Whether this association contains no rows.
[中]此关联是否不包含行。
代码示例来源:origin: hibernate/hibernate-ogm
/**
* Whether the rows of the given association should be stored in a hash using the single row key column as key or
* not.
*/
public static boolean organizeAssociationMapByRowKey(
org.hibernate.ogm.model.spi.Association association,
AssociationKey key,
AssociationContext associationContext) {
if ( association.isEmpty() ) {
return false;
}
if ( key.getMetadata().getRowKeyIndexColumnNames().length != 1 ) {
return false;
}
Object valueOfFirstRow = association.get( association.getKeys().iterator().next() )
.get( key.getMetadata().getRowKeyIndexColumnNames()[0] );
if ( !( valueOfFirstRow instanceof String ) ) {
return false;
}
// The list style may be explicitly enforced for compatibility reasons
return getMapStorage( associationContext ) == MapStorageType.BY_KEY;
}
代码示例来源:origin: hibernate/hibernate-ogm
@Override
public Association createAssociation(AssociationKey key, AssociationContext associationContext) {
AssociationStorageStrategy storageStrategy = getAssociationStorageStrategy( key, associationContext );
Document document = storageStrategy == AssociationStorageStrategy.IN_ENTITY
? getEmbeddingEntity( key, associationContext )
: associationKeyToObject( key, storageStrategy );
Association association = new Association( new MongoDBAssociationSnapshot( document, key, storageStrategy ) );
// in the case of an association stored in the entity structure, we might end up with rows present in the
// current snapshot of the entity while we want an empty association here. So, in this case, we clear the
// snapshot to be sure the association created is empty.
if ( !association.isEmpty() ) {
association.clear();
}
return association;
}
代码示例来源:origin: org.hibernate.ogm/hibernate-ogm-mongodb
@Override
public Association createAssociation(AssociationKey key, AssociationContext associationContext) {
AssociationStorageStrategy storageStrategy = getAssociationStorageStrategy( key, associationContext );
Document document = storageStrategy == AssociationStorageStrategy.IN_ENTITY
? getEmbeddingEntity( key, associationContext )
: associationKeyToObject( key, storageStrategy );
Association association = new Association( new MongoDBAssociationSnapshot( document, key, storageStrategy ) );
// in the case of an association stored in the entity structure, we might end up with rows present in the
// current snapshot of the entity while we want an empty association here. So, in this case, we clear the
// snapshot to be sure the association created is empty.
if ( !association.isEmpty() ) {
association.clear();
}
return association;
}
代码示例来源:origin: hibernate/hibernate-ogm
private void removeNavigationalInformationFromInverseSide(int propertyIndex, AssociationKeyMetadata associationKeyMetadata, Object[] oldColumnValue) {
// If the association involves entities deleted by a previous operation of the current batch,
// it does not make sense trying to update association itself
EntityKey entityKey = new EntityKey( associationKeyMetadata.getEntityKeyMetadata(), oldColumnValue );
if ( gridDialect instanceof BatchOperationsDelegator && ( (BatchOperationsDelegator) gridDialect ).isMarkedForRemoval( entityKey ) ) {
return;
}
AssociationPersister associationPersister = createInverseAssociationPersister( propertyIndex, associationKeyMetadata, oldColumnValue );
Association association = associationPersister.getAssociationOrNull();
// The association might be empty if the navigation information have already been removed.
// This typically happens when the entity owning the inverse association has already been deleted prior to
// deleting the entity owning the association and a {@code @NotFound(action = NotFoundAction.IGNORE)} is
// involved.
if ( association != null && !association.isEmpty() ) {
RowKey rowKey = getInverseRowKey( associationKeyMetadata, oldColumnValue );
association.remove( rowKey );
associationPersister.flushToDatastore();
}
}
代码示例来源:origin: hibernate/hibernate-ogm
/**
* Writes out the changes gathered in the {@link Association} managed by this persister to the datastore.
*/
public void flushToDatastore() {
if ( getAssociation().isEmpty() ) {
gridDialect.removeAssociation( getAssociationKey(), getAssociationContext() );
association = null;
OgmEntityEntryState.getStateFor( session, hostingEntity ).setAssociation( associationKeyMetadata.getCollectionRole(), null );
}
else if ( !getAssociation().getOperations().isEmpty() ) {
gridDialect.insertOrUpdateAssociation( getAssociationKey(), getAssociation(), getAssociationContext() );
}
updateHostingEntityIfRequired();
}
代码示例来源:origin: hibernate/hibernate-ogm
private void removeNavigationInformation(Serializable id, Object entity, SharedSessionContractImplementor session) {
for ( int propertyIndex = 0; propertyIndex < getEntityMetamodel().getPropertySpan(); propertyIndex++ ) {
if ( propertyMightHaveNavigationalInformation[propertyIndex] ) {
CollectionType collectionType = (CollectionType) getPropertyTypes()[propertyIndex];
OgmCollectionPersister collectionPersister = (OgmCollectionPersister) getFactory()
.getMetamodel().collectionPersister( collectionType.getRole() );
AssociationPersister associationPersister = new AssociationPersister.Builder( collectionPersister.getOwnerEntityPersister().getMappedClass() )
.hostingEntity( entity )
.gridDialect( gridDialect )
.key( id, collectionPersister.getKeyGridType() )
.associationKeyMetadata( collectionPersister.getAssociationKeyMetadata() )
.associationTypeContext( collectionPersister.getAssociationTypeContext() )
.session( session )
.build();
Association association = associationPersister.getAssociationOrNull();
if ( association != null && !association.isEmpty() ) {
association.clear();
associationPersister.flushToDatastore();
}
}
}
}
代码示例来源:origin: org.hibernate.ogm/hibernate-ogm-couchdb
@Override
public Association createAssociation(AssociationKey key, AssociationContext associationContext) {
CouchDBAssociation couchDBAssociation = null;
if ( isStoredInEntityStructure( key.getMetadata(), associationContext.getAssociationTypeContext() ) ) {
TuplePointer tuplePointer = getEmbeddingEntityTuplePointer( key, associationContext );
EntityDocument owningEntity = getEntityFromTuple( tuplePointer.getTuple() );
if ( owningEntity == null ) {
owningEntity = (EntityDocument) getDataStore().saveDocument( new EntityDocument( key.getEntityKey() ) );
tuplePointer.setTuple( new Tuple( new CouchDBTupleSnapshot( owningEntity ), SnapshotType.UPDATE ) );
}
couchDBAssociation = CouchDBAssociation.fromEmbeddedAssociation( tuplePointer, key.getMetadata() );
}
else {
AssociationDocument association = new AssociationDocument( Identifier.createAssociationId( key ) );
couchDBAssociation = CouchDBAssociation.fromAssociationDocument( association );
}
Association association = new Association( new CouchDBAssociationSnapshot( couchDBAssociation, key ) );
// in the case of an association stored in the entity structure, we might end up with rows present in the current snapshot of the entity
// while we want an empty association here. So, in this case, we clear the snapshot to be sure the association created is empty.
if ( !association.isEmpty() ) {
association.clear();
}
return association;
}
内容来源于网络,如有侵权,请联系作者删除!