Package com.impetus.kundera.metadata.model

Examples of com.impetus.kundera.metadata.model.MetamodelImpl


     * @param relationshipEntity
     */
    public Map<String, Object> createRelationshipProperties(EntityMetadata entityMetadata,
            EntityMetadata targetEntityMetadata, Object relationshipEntity)
    {
        MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                entityMetadata.getPersistenceUnit());
        EntityType entityType = metaModel.entity(relationshipEntity.getClass());
        Map<String, Object> relationshipProperties = new HashMap<String, Object>();

        Set<Attribute> attributes = entityType.getSingularAttributes();
        for (Attribute attribute : attributes)
        {
View Full Code Here


     */
    private Node getOrCreateNodeWithUniqueFactory(final Object entity, final Object id, final EntityMetadata m,
            GraphDatabaseService graphDb)
    {
        final String idColumnName = ((AbstractAttribute) m.getIdAttribute()).getJPAColumnName();
        final MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                m.getPersistenceUnit());
        final String idUniqueValue = serializeIdAttributeValue(m, metaModel, id);

        UniqueFactory<Node> factory = new UniqueFactory.UniqueNodeFactory(graphDb, m.getIndexName())
        {
            /**
             * Initialize ID attribute
             */
            @Override
            protected void initialize(Node created, Map<String, Object> properties)
            {
                // Set Embeddable ID attribute
                if (metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType()))
                {
                    // Populate embedded field value in serialized format
                    created.setProperty(idColumnName, idUniqueValue);

                    // Populated all other attributes of embedded into this node
                    Set<Attribute> embeddableAttributes = metaModel
                            .embeddable(m.getIdAttribute().getBindableJavaType()).getSingularAttributes();
                    for (Attribute attribute : embeddableAttributes)
                    {
                        String columnName = ((AbstractAttribute) attribute).getJPAColumnName();
                        if (columnName == null)
                            columnName = attribute.getName();
                        Object value = PropertyAccessorHelper.getObject(id, (Field) attribute.getJavaMember());

                        if (value != null)
                            created.setProperty(columnName, value);
                    }
                }
                else
                {
                    created.setProperty(idColumnName, properties.get(idColumnName));
                }

            }
        };

        if (metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType()))
        {
            return factory.getOrCreate(idColumnName, idUniqueValue);
        }
        else
        {
View Full Code Here

    public Node searchNode(Object key, EntityMetadata m, GraphDatabaseService graphDb, boolean skipProxy)
    {
        Node node = null;
        String idColumnName = ((AbstractAttribute) m.getIdAttribute()).getJPAColumnName();

        final MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                m.getPersistenceUnit());
        if (metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType()))
        {
            key = serializeIdAttributeValue(m, metaModel, key);
        }

        if (indexer.isNodeAutoIndexingEnabled(graphDb))
View Full Code Here

     * @param entityClassName
     * @param em
     * @return
     */
    public static AbstractManagedType getEntityManagedType(String entityClassName, EntityManager em) {
        MetamodelImpl metamodel = (MetamodelImpl) em.getEntityManagerFactory().getMetamodel();
        Class<?> entityClass = metamodel.getEntityClass(entityClassName);
        EntityMetadata entityMetadata = metamodel.getEntityMetadata(entityClass);
        AbstractManagedType managedType = (AbstractManagedType) metamodel.entity(entityMetadata.getEntityClazz());
        return managedType;
    }
View Full Code Here

     * @param entityClassName
     * @param em
     * @return
     */
    public static Class<?> getEntityClass(String entityClassName, EntityManager em) {
        MetamodelImpl metamodel = (MetamodelImpl) em.getEntityManagerFactory().getMetamodel();
        Class<?> entityClass = metamodel.getEntityClass(entityClassName);
        return entityClass;
    }
View Full Code Here

     * @param entityClassName
     * @param em
     * @return
     */
    public static EntityMetadata getEntityMetaData(String entityClassName, EntityManager em) {
        MetamodelImpl metamodel = (MetamodelImpl) em.getEntityManagerFactory().getMetamodel();
        Class<?> entityClass = metamodel.getEntityClass(entityClassName);

        return metamodel.getEntityMetadata(entityClass);
    }
View Full Code Here

     * @param q
     * @param em
     */
    public static void setObjectQueryParameters(String queryString, String parameterString, Query q, EntityManager em,
        String mediaType) {
        MetamodelImpl metamodel = (MetamodelImpl) em.getEntityManagerFactory().getMetamodel();

        if (parameterString == null || parameterString.isEmpty()) {
            return;
        }

        Map<String, String> paramsMap = new HashMap<String, String>();
        ObjectMapper mapper = new ObjectMapper();

        try {
            paramsMap = mapper.readValue(parameterString, new TypeReference<HashMap<String, String>>() {
            });
            KunderaQuery kq = ((QueryImpl) q).getKunderaQuery();
            Set<Parameter<?>> parameters = kq.getParameters();
            for (String paramName : paramsMap.keySet()) {
                String value = paramsMap.get(paramName);

                if (paramName.equalsIgnoreCase("firstResult")) {
                    q.setFirstResult(Integer.parseInt(value));

                } else if (paramName.equalsIgnoreCase("maxResult")) {
                    q.setMaxResults(Integer.parseInt(value));

                } else if (StringUtils.isNumeric(paramName)) {
                    for (Parameter param : parameters) {
                        if (param.getPosition() == Integer.parseInt(paramName)) {

                            Class<?> paramClass = param.getParameterType();
                            Object paramValue = null;
                            if (metamodel.isEmbeddable(paramClass)) {
                                paramValue =
                                    JAXBUtils.toObject(StreamUtils.toInputStream(value), paramClass, mediaType);

                            } else {
                                PropertyAccessor accessor = PropertyAccessorFactory.getPropertyAccessor(paramClass);
                                paramValue = accessor.fromString(paramClass, value);
                            }

                            q.setParameter(Integer.parseInt(paramName), paramValue);
                            break;
                        }
                    }
                } else {
                    for (Parameter param : parameters) {
                        if (param.getName().equals(paramName)) {

                            Class<?> paramClass = param.getParameterType();
                            Object paramValue = null;

                            if (metamodel.isEmbeddable(paramClass)) {
                                paramValue =
                                    JAXBUtils.toObject(StreamUtils.toInputStream(value), paramClass, mediaType);

                            } else {
                                PropertyAccessor accessor = PropertyAccessorFactory.getPropertyAccessor(paramClass);
View Full Code Here

     */
    private List<Object> findUsingLucene(EntityMetadata m, Client client, Object[] primaryKeys)
    {
        String idField = m.getIdAttribute().getName();
        String equals = "=";
        MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                m.getPersistenceUnit());
        EntityType entityType = metaModel.entity(m.getEntityClazz());
        String columnName = ((AbstractAttribute) entityType.getAttribute(idField)).getJPAColumnName();
        List<Object> result = new ArrayList<Object>();
        Queue queue = getKunderaQuery().getFilterClauseQueue();
        KunderaQuery kunderaQuery = getKunderaQuery();

View Full Code Here

     */
    protected List<Object> populateUsingLucene(EntityMetadata m, Client client, List<Object> result,
            String[] columnsToSelect)
    {

        MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                m.getPersistenceUnit());
        String luceneQ = KunderaCoreUtils.getLuceneQueryFromJPAQuery(kunderaQuery, kunderaMetadata);

        Map<String, Object> searchFilter = client.getIndexManager().search(m.getEntityClazz(), luceneQ,
                Constants.INVALID, Constants.INVALID);
        boolean isEmbeddedId = metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType());

        if (isEmbeddedId)
        {
            return populateEmbeddedIdUsingLucene(m, client, result, searchFilter, columnsToSelect);
        }
View Full Code Here

    protected String[] getColumns(final String[] columns, final EntityMetadata m)
    {
        List<String> columnAsList = new ArrayList<String>();
        if (columns != null && columns.length > 0)
        {
            MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                    m.getPersistenceUnit());
            EntityType entity = metaModel.entity(m.getEntityClazz());
            for (int i = 1; i < columns.length; i++)
            {
                if (columns[i] != null)
                {
                    Attribute col = entity.getAttribute(columns[i]);
View Full Code Here

TOP

Related Classes of com.impetus.kundera.metadata.model.MetamodelImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.