List of usage examples for javax.persistence.metamodel Attribute equals
public boolean equals(Object obj)
From source file:com.impetus.client.oraclenosql.OracleNoSQLClient.java
/** * Iterate and store attributes.//from www . ja v a 2 s. c o m * * @param entity * JPA entity. * @param metamodel * JPA meta model. * @param row * kv row. * @param attributes * JPA attributes. * @param schemaTable * the schema table * @param metadata * the metadata */ private void process(Object entity, MetamodelImpl metamodel, Row row, Set<Attribute> attributes, Table schemaTable, EntityMetadata metadata) { for (Attribute attribute : attributes) { // by pass association. if (!attribute.isAssociation()) { // in case of embeddable id. if (attribute.equals(metadata.getIdAttribute()) && metamodel.isEmbeddable(((AbstractAttribute) attribute).getBindableJavaType())) { processEmbeddableAttribute(entity, metamodel, row, schemaTable, metadata, attribute); } else { if (metamodel.isEmbeddable(((AbstractAttribute) attribute).getBindableJavaType())) { processEmbeddableAttribute(entity, metamodel, row, schemaTable, metadata, attribute); } else { setField(row, schemaTable, entity, attribute); } } } } }
From source file:com.impetus.client.cassandra.thrift.CQLTranslator.java
/** * On translation.//from w w w . j ava2s . c o m * * @param record * the record * @param m * the m * @param type * the type * @param metaModel * the meta model * @param entityClazz * the entity clazz * @param entityType * the entity type * @param builders * the builders * @param columnBuilders * the column builders * @param externalProperties * the external properties * @param kunderaMetadata * the kundera metadata */ private void onTranslation(final Object record, final EntityMetadata m, TranslationType type, MetamodelImpl metaModel, Class entityClazz, EntityType entityType, Map<String, StringBuilder> builders, Map<String, StringBuilder> columnBuilders, Map<String, Object> externalProperties, final KunderaMetadata kunderaMetadata) { Set<Attribute> attributes = entityType.getAttributes(); Iterator<Attribute> iterator = attributes.iterator(); while (iterator.hasNext()) { Attribute attribute = iterator.next(); // Populating table name. String tableName = ((AbstractAttribute) attribute).getTableName() != null ? ((AbstractAttribute) attribute).getTableName() : m.getTableName(); StringBuilder columnBuilder = columnBuilders.get(tableName); if (columnBuilder == null) { columnBuilder = new StringBuilder(); columnBuilders.put(tableName, columnBuilder); } StringBuilder builder = builders.get(tableName); if (builder == null) { builder = new StringBuilder(); builders.put(tableName, builder); } Field field = (Field) attribute.getJavaMember(); if (!attribute.equals(m.getIdAttribute()) && !((AbstractAttribute) attribute).getJPAColumnName() .equals(((AbstractAttribute) m.getIdAttribute()).getJPAColumnName())) { if (metaModel.isEmbeddable(((AbstractAttribute) attribute).getBindableJavaType())) { // create embedded entity persisting format if (field.isAnnotationPresent(ElementCollection.class)) { // handle embeddable collection // check list, map, set // build embedded value StringBuilder elementCollectionValue = buildElementCollectionValue(field, record, metaModel, attribute); columnBuilder.append(Constants.ESCAPE_QUOTE); columnBuilder.append(((AbstractAttribute) attribute).getJPAColumnName()); columnBuilder.append(Constants.ESCAPE_QUOTE); columnBuilder.append(Constants.COMMA); builder.append(elementCollectionValue); builder.append(Constants.COMMA); } else { EmbeddableType embeddableKey = metaModel.embeddable(field.getType()); Object embeddableKeyObj = PropertyAccessorHelper.getObject(record, field); if (embeddableKeyObj != null) { StringBuilder embeddedValueBuilder = new StringBuilder(Constants.OPEN_CURLY_BRACKET); for (Field embeddableColumn : field.getType().getDeclaredFields()) { if (!ReflectUtils.isTransientOrStatic(embeddableColumn)) { AbstractAttribute subAttribute = (AbstractAttribute) embeddableKey .getAttribute(embeddableColumn.getName()); if (metaModel.isEmbeddable(subAttribute.getBindableJavaType())) { // construct map; recursive // send attribute if (embeddableColumn.isAnnotationPresent(ElementCollection.class)) { // build element collection value StringBuilder elementCollectionValue = buildElementCollectionValue( embeddableColumn, embeddableKeyObj, metaModel, (Attribute) subAttribute); appendColumnName(embeddedValueBuilder, ((AbstractAttribute) (embeddableKey .getAttribute(embeddableColumn.getName()))) .getJPAColumnName()); embeddedValueBuilder.append(Constants.COLON); embeddedValueBuilder.append(elementCollectionValue); } else { buildEmbeddedValue(embeddableKeyObj, metaModel, embeddedValueBuilder, (SingularAttribute) subAttribute); } } else { // append key value appendColumnName(embeddedValueBuilder, ((AbstractAttribute) (embeddableKey .getAttribute(embeddableColumn.getName()))) .getJPAColumnName()); embeddedValueBuilder.append(Constants.COLON); appendColumnValue(embeddedValueBuilder, embeddableKeyObj, embeddableColumn); } embeddedValueBuilder.append(Constants.COMMA); } } // strip last char and append '}' embeddedValueBuilder.deleteCharAt(embeddedValueBuilder.length() - 1); embeddedValueBuilder.append(Constants.CLOSE_CURLY_BRACKET); // add to columnbuilder and builder columnBuilder.append(Constants.ESCAPE_QUOTE); columnBuilder.append(((AbstractAttribute) attribute).getJPAColumnName()); columnBuilder.append(Constants.ESCAPE_QUOTE); columnBuilder.append(Constants.COMMA); builder.append(embeddedValueBuilder); builder.append(Constants.COMMA); // end if } } } else if (!ReflectUtils.isTransientOrStatic(field) && !attribute.isAssociation()) { onTranslation(type, builder, columnBuilder, ((AbstractAttribute) attribute).getJPAColumnName(), record, field); } } } for (String tableName : columnBuilders.keySet()) { translateCompositeId(record, m, type, metaModel, builders, columnBuilders, externalProperties, kunderaMetadata, tableName, m.getIdAttribute()); } // on inherited columns. onDiscriminatorColumn(builders.get(m.getTableName()), columnBuilders.get(m.getTableName()), entityType); }