[hibernate-issues] [Hibernate-JIRA] Commented: (HSHARDS-9) Add ShardAware interface and related exit strategy logic
Max Ross (JIRA)
noreply at atlassian.com
Tue Apr 17 01:02:04 EDT 2007
[ http://opensource.atlassian.com/projects/hibernate/browse/HSHARDS-9?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_26741 ]
Max Ross commented on HSHARDS-9:
--------------------------------
Interesting idea Nathan, thanks for writing it up. If your goal is to be able to determine the shard with which an object is associated there's already a facility for it:: ShardedSession.getShardIdForObject(). Is this what you're after or is there something else I'm not seeing?
Also, I noticed you're trying to associate a set of virtual shard ids with a given object. An object will only be associated with 1 virtual shard and 1 physical shard. Looking at the implementation of getShardIdForObject() it looks like it will only return physical shard ids. It seems worthwhile to expose a similar facility for determining virtual shard, but I confess I think I prefer a mechanism that doesn't involve the decoration of model objects. Let me investigate a bit more.
Thanks,
Max
> Add ShardAware interface and related exit strategy logic
> --------------------------------------------------------
>
> Key: HSHARDS-9
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HSHARDS-9
> Project: Hibernate Shards
> Issue Type: New Feature
> Components: strategy
> Affects Versions: 3.0.0.Beta1
> Environment: Hibernate 3.2, Database: DB2
> Reporter: Nathan Silberman
> Assignee: Max Ross
> Original Estimate: 2 days
> Remaining Estimate: 2 days
>
> Domain model awareness of its host Shard. Any domain model that implemented a 'ShardAware' interface would contain a Set<ShardId> that could be injected by the relevant ExitStrategy.
> This could be solved by adding the following interface:
> -------------------------------------------------------
> package org.hibernate.shards;
> import org.hibernate.shards.ShardId;
> import java.util.Set;
> /**
> * Interface for persistent objects that are aware of the virtual shardIds
> * that host them.
> */
> public interface ShardAware {
>
> /**
> * Sets the virtual ShardIds that host the implementing
> * persistant object
> *
> * @param shardid
> * a non-null, non-empty Set of ShardIds
> * @throws IllegalArgumentException
> * if <tt>shardIds</tt> is null or empty
> */
> void setShardIds( Set<ShardId> shardids );
> }
> ---------------------------------------------------
> An simple exit strategy that could be used, for example, would set the ShardIds for each resulting ShardAware domain model:
> ------------------------------------------------------
> package org.hibernate.shards.strategy.exit;
> import java.util.List;
> import org.hibernate.shards.Shard;
> import org.hibernate.shards.ShardAware;
> /**
> * ShardAwareConcatenateListsExistStrategy sets the ShardIds on each of the given
> * objects returned by each Shard.
> *
> * One should be aware that usage of this class adds O(n) overhead to each retrieval
> * as the setting of each ShardIds Set is invoked by iterating over the entire resultSet.
> */
> public class ShardAwareConcatenateListsExistStrategy extends ConcatenateListsExitStrategy {
> @Override
> public synchronized boolean addResult(List<Object> oneResult, Shard shard ) {
>
> if ( oneResult != null && ! oneResult.isEmpty()
> && oneResult.get( 0 ) instanceof ShardAware ) {
>
> for( Object object : oneResult ) {
> ((ShardAware)object).setShardIds( shard.getShardIds() );
> }
> }
>
> return super.addResult( oneResult, shard );
> }
> }
> ---------------------------------------
> This change might require changes wherever ShardAccessStrategy.apply() could be invoked.
> I have made the changes including a small alteration to the ShardedCriteriaImpl, to use ShardAwareConcatenateListsExistStrategy instead of ConcatenateListsExitStrategy, with success.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list