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.metadata;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import javax.persistence.PersistenceException;
import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.EmbeddableType;
import javax.persistence.metamodel.EntityType;
import javax.persistence.metamodel.Metamodel;
import com.impetus.kundera.Constants;
import com.impetus.kundera.metadata.model.ClientMetadata;
import com.impetus.kundera.metadata.model.EntityMetadata;
import com.impetus.kundera.metadata.model.KunderaMetadata;
import com.impetus.kundera.metadata.model.MetamodelImpl;
import com.impetus.kundera.metadata.model.Relation;
import com.impetus.kundera.metadata.model.Relation.ForeignKey;
import com.impetus.kundera.metadata.model.attributes.AbstractAttribute;
import com.impetus.kundera.metadata.validator.InvalidEntityDefinitionException;
import com.impetus.kundera.property.PropertyAccessorHelper;
/**
* Utility class for entity metadata related funcntionality.
*
* @author amresh.singh
*/
public class MetadataUtils
{
/**
* Populate column and super column maps.
*
* @param m
* the m
* @param columnNameToFieldMap
* the column name to field map
* @param superColumnNameToFieldMap
* the super column name to field map
*/
public static void populateColumnAndSuperColumnMaps(EntityMetadata m, Map columnNameToFieldMap,
Map superColumnNameToFieldMap)
{
getEmbeddableType(m, columnNameToFieldMap, superColumnNameToFieldMap);
}
/**
* Creates the columns field map.
*
* @param m
* the m
* @param superColumn
* the super column
* @return the map
*/
public static Map createColumnsFieldMap(EntityMetadata m, EmbeddableType superColumn)
{
Map columnNameToFieldMap = new HashMap();
Set attributes = superColumn.getAttributes();
for (Attribute column : attributes)
{
columnNameToFieldMap.put(((AbstractAttribute) column).getJPAColumnName(), (Field) column.getJavaMember());
}
return columnNameToFieldMap;
}
/**
* Creates the super columns field map.
*
* @param m
* the m
* @return the map
*/
public static Map createSuperColumnsFieldMap(EntityMetadata m)
{
Map superColumnNameToFieldMap = new HashMap();
getEmbeddableType(m, null, superColumnNameToFieldMap);
// for (Map.Entry entry :
// m.getEmbeddedColumnsMap().entrySet())
// {
// EmbeddedColumn scMetadata = entry.getValue();
// superColumnNameToFieldMap.put(scMetadata.getName(),
// scMetadata.getField());
//
// }
return superColumnNameToFieldMap;
}
/**
* Gets the embedded collection instance.
*
* @param embeddedCollectionField
* the embedded collection field
* @return the embedded collection instance
*/
public static Collection getEmbeddedCollectionInstance(Field embeddedCollectionField)
{
Collection embeddedCollection = null;
Class embeddedCollectionFieldClass = embeddedCollectionField.getType();
if (embeddedCollection == null || embeddedCollection.isEmpty())
{
if (embeddedCollectionFieldClass.equals(List.class))
{
embeddedCollection = new ArrayList