/** * Creating sharded subcriteria is tricky. We need to give the client a reference to a * ShardedSubcriteriaImpl (which to the client just looks like a Criteria object). Then, for each * shard where the Criteria has already been established we need to create the actual subcriteria, * and for each shard where the Criteria has not yet been established we need to register an event * that will create the Subcriteria when the Criteria is established. * * @param factory the factory to use to create the subcriteria * @param associationPath the association path to the property on which we're creating a * subcriteria * @return a new ShardedSubcriteriaImpl */ private ShardedSubcriteriaImpl createSubcriteria( final SubcriteriaFactory factory, final String associationPath) { final ShardedSubcriteriaImpl subcriteria = new ShardedSubcriteriaImpl(shards, this, criteriaCollector, associationPath); for (final Shard shard : shards) { final Criteria criteria = shard.getCriteriaById(criteriaId); if (criteria != null) { factory.createSubcriteria(criteria, NO_CRITERIA_EVENTS); } else { final CreateSubcriteriaEvent event = new CreateSubcriteriaEvent(factory, subcriteria.getSubcriteriaRegistrar(shard)); shard.addCriteriaEvent(criteriaId, event); } } return subcriteria; }
private ShardedSubcriteriaImpl createSubcriteria(SubcriteriaFactory factory) { // first build our sharded subcrit ShardedSubcriteriaImpl subcrit = new ShardedSubcriteriaImpl(shards, parent); for (Shard shard : shards) { // see if we already have a concreate Criteria object for each shard if (shardToCriteriaMap.get(shard) != null) { // we already have a concreate Criteria for this shard, so create // a subcrit for it using the provided factory factory.createSubcriteria(this, shardToEventListMap.get(shard)); } else { // we do not yet have a concrete Criteria object for this shard // so register an event that will create a proper subcrit when we do CreateSubcriteriaEvent event = new CreateSubcriteriaEvent(factory, subcrit.getSubcriteriaRegistrar(shard)); shardToEventListMap.get(shard).add(event); } } return subcrit; }