Skip to content

Commit

Permalink
OGM-469 Changing GridDialect#isStoredInEntityStructure() to accept ke…
Browse files Browse the repository at this point in the history
…y and context specific to the association family only rather than specific to association instances
  • Loading branch information
gunnarmorling committed Oct 29, 2014
1 parent adfbace commit fedf0e6
Show file tree
Hide file tree
Showing 22 changed files with 252 additions and 135 deletions.
Expand Up @@ -15,11 +15,13 @@
import org.hibernate.dialect.lock.OptimisticLockingStrategy;
import org.hibernate.dialect.lock.PessimisticForceIncrementLockingStrategy;
import org.hibernate.ogm.dialect.spi.AssociationContext;
import org.hibernate.ogm.dialect.spi.AssociationTypeContext;
import org.hibernate.ogm.dialect.spi.BaseGridDialect;
import org.hibernate.ogm.dialect.spi.ModelConsumer;
import org.hibernate.ogm.dialect.spi.NextValueRequest;
import org.hibernate.ogm.dialect.spi.TupleContext;
import org.hibernate.ogm.model.key.spi.AssociationKey;
import org.hibernate.ogm.model.key.spi.AssociationKeyMetadata;
import org.hibernate.ogm.model.key.spi.EntityKey;
import org.hibernate.ogm.model.key.spi.EntityKeyMetadata;
import org.hibernate.ogm.model.key.spi.RowKey;
Expand Down Expand Up @@ -114,7 +116,7 @@ public void removeAssociation(AssociationKey key, AssociationContext association
}

@Override
public boolean isStoredInEntityStructure(AssociationKey associationKey, AssociationContext associationContext) {
public boolean isStoredInEntityStructure(AssociationKeyMetadata associationKeyMetadata, AssociationTypeContext associationTypeContext) {
return false;
}

Expand Down
Expand Up @@ -8,10 +8,9 @@

import org.hibernate.ogm.dialect.batch.spi.OperationsQueue;
import org.hibernate.ogm.dialect.spi.AssociationContext;
import org.hibernate.ogm.dialect.spi.AssociationTypeContext;
import org.hibernate.ogm.dialect.spi.GridDialect;
import org.hibernate.ogm.model.key.spi.AssociatedEntityKeyMetadata;
import org.hibernate.ogm.model.spi.Association;
import org.hibernate.ogm.options.spi.OptionsContext;

/**
* Provides context information to {@link GridDialect}s when accessing {@link Association}s.
Expand All @@ -21,61 +20,34 @@
*/
public class AssociationContextImpl implements AssociationContext {

private final OptionsContext optionsContext;
private final AssociationTypeContext associationTypeContext;
private final OperationsQueue operationsQueue;
private final AssociatedEntityKeyMetadata associatedEntityKeyMetadata;
private final String roleOnMainSide;

public AssociationContextImpl(OptionsContext optionsContext, AssociatedEntityKeyMetadata associatedEntityKeyMetadata, String roleOnMainSide) {
this( optionsContext, associatedEntityKeyMetadata, roleOnMainSide, null );
public AssociationContextImpl(AssociationTypeContext associationTypeContext) {
this(associationTypeContext, null );
}

public AssociationContextImpl(AssociationContextImpl original, OperationsQueue operationsQueue) {
this( original.optionsContext, original.associatedEntityKeyMetadata, original.roleOnMainSide, operationsQueue );
this( original.associationTypeContext, operationsQueue );
}

private AssociationContextImpl(OptionsContext optionsContext, AssociatedEntityKeyMetadata associatedEntityKeyMetadata, String roleOnMainSide, OperationsQueue operationsQueue) {
this.optionsContext = optionsContext;
this.associatedEntityKeyMetadata = associatedEntityKeyMetadata;
this.roleOnMainSide = roleOnMainSide;
private AssociationContextImpl(AssociationTypeContext associationTypeContext, OperationsQueue operationsQueue) {
this.associationTypeContext = associationTypeContext;
this.operationsQueue = operationsQueue;
}

@Override
public OperationsQueue getOperationsQueue() {
return operationsQueue;
}

@Override
public OptionsContext getOptionsContext() {
return optionsContext;
public AssociationTypeContext getAssociationTypeContext() {
return associationTypeContext;
}

/**
* Provides meta-data about the entity key on the other side of this association.
*
* @return A meta-data object providing information about the entity key on the other side of this information.
*/
@Override
public AssociatedEntityKeyMetadata getAssociatedEntityKeyMetadata() {
return associatedEntityKeyMetadata;
}

/**
* Provides the role of the represented association on the main side in case the current operation is invoked for
* the inverse side of a bi-directional association.
*
* @return The role of the represented association on the main side. The association's own role will be returned in
* case this operation is invoked for an uni-directional association or the main-side of a bi-directional
* association.
*/
@Override
public String getRoleOnMainSide() {
return roleOnMainSide;
public OperationsQueue getOperationsQueue() {
return operationsQueue;
}

@Override
public String toString() {
return "AssociationContext [optionsContext=" + optionsContext + "]";
return "AssociationContextImpl [associationTypeContext=" + associationTypeContext + ", operationsQueue=" + operationsQueue + "]";
}
}
@@ -0,0 +1,65 @@
/*
* Hibernate OGM, Domain model persistence for NoSQL datastores
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.ogm.dialect.impl;

import org.hibernate.ogm.dialect.spi.AssociationTypeContext;
import org.hibernate.ogm.dialect.spi.GridDialect;
import org.hibernate.ogm.model.key.spi.AssociatedEntityKeyMetadata;
import org.hibernate.ogm.model.spi.Association;
import org.hibernate.ogm.options.spi.OptionsContext;

/**
* Provides context information to {@link GridDialect}s when accessing {@link Association}s.
*
* @author Guillaume Scheibel &lt;guillaume.scheibel@gmail.com&gt;
* @author Gunnar Morling
*/
public class AssociationTypeContextImpl implements AssociationTypeContext {

private final OptionsContext optionsContext;
private final AssociatedEntityKeyMetadata associatedEntityKeyMetadata;
private final String roleOnMainSide;

public AssociationTypeContextImpl(OptionsContext optionsContext, AssociatedEntityKeyMetadata associatedEntityKeyMetadata, String roleOnMainSide) {
this.optionsContext = optionsContext;
this.associatedEntityKeyMetadata = associatedEntityKeyMetadata;
this.roleOnMainSide = roleOnMainSide;
}

@Override
public OptionsContext getOptionsContext() {
return optionsContext;
}

/**
* Provides meta-data about the entity key on the other side of this association.
*
* @return A meta-data object providing information about the entity key on the other side of this information.
*/
@Override
public AssociatedEntityKeyMetadata getAssociatedEntityKeyMetadata() {
return associatedEntityKeyMetadata;
}

/**
* Provides the role of the represented association on the main side in case the current operation is invoked for
* the inverse side of a bi-directional association.
*
* @return The role of the represented association on the main side. The association's own role will be returned in
* case this operation is invoked for an uni-directional association or the main-side of a bi-directional
* association.
*/
@Override
public String getRoleOnMainSide() {
return roleOnMainSide;
}

@Override
public String toString() {
return "AssociationContext [optionsContext=" + optionsContext + "]";
}
}
Expand Up @@ -22,12 +22,14 @@
import org.hibernate.ogm.dialect.query.spi.ParameterMetadataBuilder;
import org.hibernate.ogm.dialect.query.spi.QueryableGridDialect;
import org.hibernate.ogm.dialect.spi.AssociationContext;
import org.hibernate.ogm.dialect.spi.AssociationTypeContext;
import org.hibernate.ogm.dialect.spi.GridDialect;
import org.hibernate.ogm.dialect.spi.ModelConsumer;
import org.hibernate.ogm.dialect.spi.NextValueRequest;
import org.hibernate.ogm.dialect.spi.SessionFactoryLifecycleAwareDialect;
import org.hibernate.ogm.dialect.spi.TupleContext;
import org.hibernate.ogm.model.key.spi.AssociationKey;
import org.hibernate.ogm.model.key.spi.AssociationKeyMetadata;
import org.hibernate.ogm.model.key.spi.EntityKey;
import org.hibernate.ogm.model.key.spi.EntityKeyMetadata;
import org.hibernate.ogm.model.spi.Association;
Expand Down Expand Up @@ -129,8 +131,8 @@ public void removeAssociation(AssociationKey key, AssociationContext association
}

@Override
public boolean isStoredInEntityStructure(AssociationKey associationKey, AssociationContext associationContext) {
return gridDialect.isStoredInEntityStructure( associationKey, associationContext );
public boolean isStoredInEntityStructure(AssociationKeyMetadata associationKeyMetadata, AssociationTypeContext associationTypeContext) {
return gridDialect.isStoredInEntityStructure( associationKeyMetadata, associationTypeContext );
}

@Override
Expand Down
Expand Up @@ -13,10 +13,12 @@
import org.hibernate.ogm.dialect.query.spi.BackendQuery;
import org.hibernate.ogm.dialect.query.spi.ClosableIterator;
import org.hibernate.ogm.dialect.spi.AssociationContext;
import org.hibernate.ogm.dialect.spi.AssociationTypeContext;
import org.hibernate.ogm.dialect.spi.GridDialect;
import org.hibernate.ogm.dialect.spi.NextValueRequest;
import org.hibernate.ogm.dialect.spi.TupleContext;
import org.hibernate.ogm.model.key.spi.AssociationKey;
import org.hibernate.ogm.model.key.spi.AssociationKeyMetadata;
import org.hibernate.ogm.model.key.spi.EntityKey;
import org.hibernate.ogm.model.spi.Association;
import org.hibernate.ogm.model.spi.Tuple;
Expand Down Expand Up @@ -115,9 +117,9 @@ public Number nextValue(NextValueRequest request) {
}

@Override
public boolean isStoredInEntityStructure(AssociationKey associationKey, AssociationContext associationContext) {
log.tracef( "Determining whether assocication %1$s is stored in an entity structure", associationKey );
return super.isStoredInEntityStructure( associationKey, associationContext );
public boolean isStoredInEntityStructure(AssociationKeyMetadata associationKeyMetadata, AssociationTypeContext associationTypeContext) {
log.tracef( "Determining whether association %1$s is stored in an entity structure", associationKeyMetadata );
return super.isStoredInEntityStructure( associationKeyMetadata, associationTypeContext );
}

@Override
Expand Down
Expand Up @@ -7,7 +7,6 @@
package org.hibernate.ogm.dialect.spi;

import org.hibernate.ogm.dialect.batch.spi.OperationsQueue;
import org.hibernate.ogm.model.key.spi.AssociatedEntityKeyMetadata;
import org.hibernate.ogm.model.spi.Association;

/**
Expand All @@ -16,24 +15,9 @@
* @author Guillaume Scheibel &lt;guillaume.scheibel@gmail.com&gt;
* @author Gunnar Morling
*/
public interface AssociationContext extends GridDialectOperationContext {
public interface AssociationContext {

OperationsQueue getOperationsQueue();

/**
* Provides meta-data about the entity key on the other side of this association.
*
* @return A meta-data object providing information about the entity key on the other side of this information.
*/
AssociatedEntityKeyMetadata getAssociatedEntityKeyMetadata();

/**
* Provides the role of the represented association on the main side in case the current operation is invoked for
* the inverse side of a bi-directional association.
*
* @return The role of the represented association on the main side. The association's own role will be returned in
* case this operation is invoked for an uni-directional association or the main-side of a bi-directional
* association.
*/
String getRoleOnMainSide();
AssociationTypeContext getAssociationTypeContext();
}
@@ -0,0 +1,42 @@
/*
* Hibernate OGM, Domain model persistence for NoSQL datastores
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.ogm.dialect.spi;

import org.hibernate.ogm.model.key.spi.AssociatedEntityKeyMetadata;
import org.hibernate.ogm.model.spi.Association;
import org.hibernate.ogm.options.spi.OptionsContext;

/**
* Provides context information to {@link GridDialect}s when accessing {@link Association}s.
*
* @author Guillaume Scheibel &lt;guillaume.scheibel@gmail.com&gt;
* @author Gunnar Morling
*/
public interface AssociationTypeContext {

/**
* Returns a context object providing access to the options effectively applying for a given entity or property.
*/
OptionsContext getOptionsContext();

/**
* Provides meta-data about the entity key on the other side of this association.
*
* @return A meta-data object providing information about the entity key on the other side of this information.
*/
AssociatedEntityKeyMetadata getAssociatedEntityKeyMetadata();

/**
* Provides the role of the represented association on the main side in case the current operation is invoked for
* the inverse side of a bi-directional association.
*
* @return The role of the represented association on the main side. The association's own role will be returned in
* case this operation is invoked for an uni-directional association or the main-side of a bi-directional
* association.
*/
String getRoleOnMainSide();
}
Expand Up @@ -9,6 +9,7 @@
import org.hibernate.LockMode;
import org.hibernate.dialect.lock.LockingStrategy;
import org.hibernate.ogm.model.key.spi.AssociationKey;
import org.hibernate.ogm.model.key.spi.AssociationKeyMetadata;
import org.hibernate.ogm.model.key.spi.EntityKey;
import org.hibernate.ogm.model.key.spi.EntityKeyMetadata;
import org.hibernate.ogm.model.spi.Association;
Expand Down Expand Up @@ -87,14 +88,16 @@ public interface GridDialect extends Service {
void removeAssociation(AssociationKey key, AssociationContext associationContext);

/**
* Whether the given association is stored within an entity structure or not. E.g. dialects for document stores may
* support storing associations within entity documents and would have to return {@code true} if this is the case
* for a given association.
* Whether the specified association is stored within an entity structure or not. E.g. dialects for document stores
* may support storing associations within entity documents and would have to return {@code true} if this is the
* case for a given association.
*
* @param associationKey identifies the association of interest
* @param associationKeyMetadata identifies the association of interest
* @param associationTypeContext provides additional contextual information about the represented association type,
* such as the options effectively applying for it
* @return {@code true} if the specified association is stored within an entity structure, {@code false} otherwise.
*/
boolean isStoredInEntityStructure(AssociationKey associationKey, AssociationContext associationContext);
boolean isStoredInEntityStructure(AssociationKeyMetadata associationKeyMetadata, AssociationTypeContext associationTypeContext);

/**
* Returns the next value from the specified id generator with the specified increment.
Expand Down

This file was deleted.

Expand Up @@ -11,14 +11,20 @@

import org.hibernate.ogm.dialect.batch.spi.OperationsQueue;
import org.hibernate.ogm.model.key.spi.AssociatedEntityKeyMetadata;
import org.hibernate.ogm.options.spi.OptionsContext;

/**
* Represents all information used to load an entity with some specific characteristics like a projection
*
* @author Guillaume Scheibel &lt;guillaume.scheibel@gmail.com&gt;
* @author Gunnar Morling
*/
public interface TupleContext extends GridDialectOperationContext {
public interface TupleContext {

/**
* Returns a context object providing access to the options effectively applying for a given entity or property.
*/
OptionsContext getOptionsContext();

/**
* Returns the mapped columns of the given entity. May be used by a dialect to only load those columns instead of
Expand Down

0 comments on commit fedf0e6

Please sign in to comment.