[
http://opensource.atlassian.com/projects/hibernate/browse/HSHARDS-9?page=...
]
Nathan Silberman commented on HSHARDS-9:
----------------------------------------
Thanks for clarifying the virtual/physical shard association. I previously misunderstood
that. Allow me to briefly explain my motivation, and perhaps this will help you better
assess whether or not you consider this feature to be worthwhile.
I have a project that currently uses Hibernate for the persistance layer that is bound to
a single data source. My intention was to be able to add Shards to enable data retrieval
from multiple data sources, without having to alter much, if any, code. I imagine this
scenario is common.
One of the features we hope to add, was the ability to provide reporting on different data
structures per data source. Hence the Shard or Source-aware concept.
The addition of Shards neccessitated (1) the addition of code to configure the Shards from
a generic hibernate base class and (2) the actual shard configuration files. These simple
steps immedietely enabled me to retrieve objects from multiple databases.
The final step could be done in one of two ways (or perhaps more that I cannot currently
imagine): Either add helper methods inside my Hibernate Base class that called
ShardedSession.getShardIdForObject() and set this 'source' property on each object
or have Shards perform this action.
One could argue that it is an odd coupling. However, it is that much more enticing that
the adoption of Shards would not require an addition code change on the adopter's
side. The required changes will only be minimized further in the future once it is
possible to completely configure Shards from Spring/Guice etc
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira