Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* * Copyright 2012 Impetus Infotech.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
******************************************************************************/
package com.impetus.kundera.persistence;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.impetus.kundera.PersistenceProperties;
import com.impetus.kundera.client.Client;
import com.impetus.kundera.client.EnhanceEntity;
import com.impetus.kundera.index.IndexManager;
import com.impetus.kundera.metadata.KunderaMetadataManager;
import com.impetus.kundera.metadata.MetadataUtils;
import com.impetus.kundera.metadata.model.EntityMetadata;
import com.impetus.kundera.metadata.model.JoinTableMetadata;
import com.impetus.kundera.metadata.model.Relation;
import com.impetus.kundera.metadata.model.Relation.ForeignKey;
import com.impetus.kundera.persistence.EntityManagerFactoryImpl.KunderaMetadata;
import com.impetus.kundera.persistence.context.PersistenceCacheManager;
import com.impetus.kundera.property.PropertyAccessException;
import com.impetus.kundera.property.PropertyAccessorHelper;
import com.impetus.kundera.proxy.KunderaProxy;
import com.impetus.kundera.proxy.ProxyHelper;
import com.impetus.kundera.proxy.collection.ProxyCollection;
import com.impetus.kundera.proxy.collection.ProxyList;
import com.impetus.kundera.proxy.collection.ProxyMap;
import com.impetus.kundera.proxy.collection.ProxySet;
import com.impetus.kundera.utils.ObjectUtils;
/**
* This class is responsible for building association for given entities.
*
* @author vivek.mishra
*/
public final class AssociationBuilder
{
private static Logger log = LoggerFactory.getLogger(AssociationBuilder.class);
/**
* Retrieves associated entities from secondary index. There are two
* alternatives here:
*
* 1. Via running Lucene query into Lucene powered secondary index. 2.
* Searching into a secondary index by custom secondary index class provided
* by user.
*
* @see PersistenceProperties#KUNDERA_INDEX_HOME_DIR
* @see PersistenceProperties#KUNDERA_INDEXER_CLASS
*
* TODO: Which secondary index to use should be transparent. All we
* should bother about is indexer.index(), indexer.search() etc.
*/
List getAssociatedEntitiesFromIndex(Class owningClazz, Object entityId, Class> childClass, Client childClient)
{
List associatedEntities;
IndexManager indexManager = childClient.getIndexManager();
Map results = indexManager != null ? indexManager.search(owningClazz, childClass, entityId)
: new HashMap();
Set rsSet = results != null ? new HashSet(results.values()) : new HashSet();
if (childClass.equals(owningClazz))
{
associatedEntities = (List