]
Max Ross resolved HSHARDS-9.
----------------------------
Resolution: Fixed
Fix Version/s: 3.0.0
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
Fix For: 3.0.0
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: