Example usage for javax.persistence.metamodel EmbeddableType getJavaType

List of usage examples for javax.persistence.metamodel EmbeddableType getJavaType

Introduction

In this page you can find the example usage for javax.persistence.metamodel EmbeddableType getJavaType.

Prototype

Class<X> getJavaType();

Source Link

Document

Return the represented Java type.

Usage

From source file:com.impetus.client.cassandra.schemamanager.CassandraSchemaManager.java

/**
 * Creates the typefor embeddables./* w  w w .  j ava 2s  .c  o m*/
 * 
 */
private void createTypeforEmbeddables() {
    if (!createdPuEmbeddables.contains(puMetadata.getPersistenceUnitName())) {
        CQLTranslator translator = new CQLTranslator();

        Map<String, String> embNametoUDTQuery = new HashMap<String, String>();
        Map<String, List<String>> embNametoDependentList = new HashMap<String, List<String>>();

        MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata()
                .getMetamodel(puMetadata.getPersistenceUnitName());

        Iterator iter = metaModel.getEmbeddables().iterator();
        while (iter.hasNext()) {
            List<String> childEmb = new ArrayList<String>();

            String typeQuery = CQLTranslator.CREATE_TYPE;
            EmbeddableType embeddedColumn = (EmbeddableType) iter.next();
            if (!embeddedColumn.getPersistenceType().equals(PersistenceType.EMBEDDABLE)) {
                continue;
            }

            typeQuery = StringUtils.replace(typeQuery, CQLTranslator.TYPE, translator
                    .ensureCase(new StringBuilder(), embeddedColumn.getJavaType().getSimpleName(), false)
                    .toString());

            StringBuilder typeQueryBuilder = new StringBuilder();

            for (Object column : embeddedColumn.getAttributes()) {

                Attribute columnAttribute = (Attribute) column;
                Field f = (Field) columnAttribute.getJavaMember();

                if (columnAttribute.getJavaType().isAnnotationPresent(Embeddable.class)) {
                    // handle embeddable
                    String cqlType = CQLTranslator.FROZEN + Constants.STR_LT + Constants.ESCAPE_QUOTE
                            + columnAttribute.getJavaType().getSimpleName() + Constants.ESCAPE_QUOTE
                            + Constants.STR_GT;
                    translator.appendColumnName(typeQueryBuilder, columnAttribute.getName(), cqlType);
                    typeQueryBuilder.append(Constants.SPACE_COMMA);
                    childEmb.add(columnAttribute.getJavaType().getSimpleName());
                } else if (columnAttribute.isCollection()) {
                    // handle element collection with embeddables
                    handleElementCollectionAttribute(translator, columnAttribute, typeQueryBuilder);
                    if (!MetadataUtils.isBasicElementCollectionField((Field) columnAttribute.getJavaMember())) {
                        childEmb.add(
                                ((AbstractAttribute) columnAttribute).getBindableJavaType().getSimpleName());
                    }

                } else {
                    String cqlType = null;
                    String dataType = CassandraValidationClassMapper.getValidationClass(f.getType(), true);
                    cqlType = translator.getCQLType(dataType);
                    // check for JPA names
                    translator.appendColumnName(typeQueryBuilder,
                            ((AbstractAttribute) columnAttribute).getJPAColumnName(), cqlType);
                    typeQueryBuilder.append(Constants.SPACE_COMMA);

                }

            }
            typeQueryBuilder = replaceColumnsAndStripLastChar(typeQuery, typeQueryBuilder);
            typeQueryBuilder.append(CQLTranslator.CLOSE_BRACKET);
            embNametoUDTQuery.put(embeddedColumn.getJavaType().getSimpleName(), typeQueryBuilder.toString());
            embNametoDependentList.put(embeddedColumn.getJavaType().getSimpleName(), childEmb);
            // run query final

        }
        postProcessEmbedded(embNametoUDTQuery, embNametoDependentList);
        createdPuEmbeddables.add(puMetadata.getPersistenceUnitName());
    }
}

From source file:utilities.internal.CopyOfDatabaseUtil.java

private Configuration buildConfiguration() {
    Configuration result;/*from   www  .  j a  v  a2 s  . c  o m*/
    Metamodel metamodel;
    Collection<EntityType<?>> entities;
    Collection<EmbeddableType<?>> embeddables;

    result = new Configuration();
    metamodel = entityManagerFactory.getMetamodel();

    entities = metamodel.getEntities();
    for (EntityType<?> entity : entities)
        result.addAnnotatedClass(entity.getJavaType());

    embeddables = metamodel.getEmbeddables();
    for (EmbeddableType<?> embeddable : embeddables)
        result.addAnnotatedClass(embeddable.getJavaType());

    return result;
}