/** * On family type. * * @param entityMetadata * the entity metadata * @param clazz * the clazz * @param f * the f */ private void onFamilyType(EntityMetadata entityMetadata, final Class clazz, Field f) { if (entityMetadata.getType() == null || !entityMetadata.getType().equals(Type.SUPER_COLUMN_FAMILY)) { if ((f.isAnnotationPresent(Embedded.class) && f.getType().getAnnotation(Embeddable.class) != null)) { entityMetadata.setType(Type.SUPER_COLUMN_FAMILY); } else if (f.isAnnotationPresent(ElementCollection.class) && !MetadataUtils.isBasicElementCollectionField(f)) { entityMetadata.setType(Type.SUPER_COLUMN_FAMILY); } else { entityMetadata.setType(Type.COLUMN_FAMILY); } } }
/** * * @param metadata * @param clazz * @param metaModelBuilder */ private <X, T> void validateandSetEntityType(EntityMetadata metadata, Class<X> clazz, MetaModelBuilder<X, T> metaModelBuilder) { if (metadata.getType() == null && clazz != null && !clazz.equals(Object.class) && clazz.isAnnotationPresent(javax.persistence.Entity.class)) { EntityType entityType = (EntityType) metaModelBuilder.getManagedTypes().get(clazz); if (entityType.getSupertype() != null) { Set<Attribute> attributes = ((AbstractIdentifiableType) entityType.getSupertype()).getAttributes(); Iterator<Attribute> iter = attributes.iterator(); while (iter.hasNext()) { Attribute attribute = iter.next(); Field f = (Field) ((Field) attribute.getJavaMember()); onFamilyType(metadata, clazz, f); } } validateandSetEntityType(metadata, (Class<X>) clazz.getSuperclass(), metaModelBuilder); } }
/** * Checks whether Inverted indexing is applicable for a given entity whose * metadata is passed as parameter * * @param m * @return */ public static boolean isInvertedIndexingApplicable(EntityMetadata m, boolean useSecondryIndex) { boolean invertedIndexingApplicable = useSecondryIndex && CassandraPropertyReader.csmd.isInvertedIndexingEnabled(m.getSchema()) && m.getType().isSuperColumnFamilyMetadata() && !m.isCounterColumnType(); return invertedIndexingApplicable; }
List<Object> entities; if (m.getType().isSuperColumnFamilyMetadata()) { if (log.isInfoEnabled()) { log.info("On counter column for super column family of entity {}.", m.getEntityClazz());
boolean isRelational, List<String> relationNames, CassandraDataHandler dataHandler) if (m.getType().isSuperColumnFamilyMetadata())
if (m.getType().isSuperColumnFamilyMetadata())
/** * Sets the id. * * @param m * the m * @param entity * the entity * @param columnValue * the column value * @param isCql3Enabled * the is cql3 enabled */ private void setId(EntityMetadata m, Object entity, Object columnValue, boolean isCql3Enabled) { if (isCql3Enabled && !m.getType().equals(Type.SUPER_COLUMN_FAMILY)) { setFieldValueViaCQL(entity, columnValue, m.getIdAttribute()); } else { setFieldValue(entity, columnValue, m.getIdAttribute()); } }
/** * Returns true in case of, composite Id and if cql3 opted and not a embedded entity. * * @param metadata * the metadata * @return true, if is cql3 enabled */ public boolean isCql3Enabled(EntityMetadata metadata) { if (metadata != null) { MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(metadata.getPersistenceUnit()); if (metaModel.isEmbeddable(metadata.getIdAttribute().getBindableJavaType())) { return true; } // added for embeddables support on cql3 AbstractManagedType managedType = (AbstractManagedType) metaModel.entity(metadata.getEntityClazz()); if (managedType.hasEmbeddableAttribute()) { return getCqlVersion().equalsIgnoreCase(CassandraConstants.CQL_VERSION_3_0); } if (getCqlVersion().equalsIgnoreCase(CassandraConstants.CQL_VERSION_3_0) && metadata.getType().equals(Type.SUPER_COLUMN_FAMILY)) { log.warn( "Super Columns not supported by cql, Any operation on supercolumn family will be executed using thrift, returning false."); return false; } return getCqlVersion().equalsIgnoreCase(CassandraConstants.CQL_VERSION_3_0); } return getCqlVersion().equalsIgnoreCase(CassandraConstants.CQL_VERSION_3_0); }
/** * Populate entity from slice. * * @param m the m * @param relationNames the relation names * @param isWrapReq the is wrap req * @param e the e * @param columnOrSuperColumnsFromRow the column or super columns from row * @return the object * @throws CharacterCodingException the character coding exception */ private Object populateEntityFromSlice(EntityMetadata m, List<String> relationNames, boolean isWrapReq, Object e, Map<ByteBuffer, List<ColumnOrSuperColumn>> columnOrSuperColumnsFromRow) throws CharacterCodingException { ThriftDataResultHelper dataGenerator = new ThriftDataResultHelper(); for (ByteBuffer key : columnOrSuperColumnsFromRow.keySet()) { Object id = PropertyAccessorHelper.getObject(m.getIdAttribute().getJavaType(), key.array()); ThriftRow tr = new ThriftRow(); tr.setColumnFamilyName(m.getTableName()); tr.setId(id); tr = dataGenerator.translateToThriftRow(columnOrSuperColumnsFromRow, m.isCounterColumnType(), m.getType(), tr); e = populateEntity(tr, m, e, relationNames, isWrapReq); } return e; } }
tr.setId(id); tr.setColumnFamilyName(m.getTableName()); tr = dataGenerator.translateToThriftRow(data, m.isCounterColumnType(), m.getType(), tr);
m.getType(), tr);
Type type = entityMetadata.getType(); Class idClassName = entityMetadata.getIdAttribute() != null ? entityMetadata.getIdAttribute().getJavaType() : null;
if (metadata.getType().equals(EntityMetadata.Type.SUPER_COLUMN_FAMILY))
slicePredicate, keyRange, getConsistencyLevel()); if (m.getType().isSuperColumnFamilyMetadata())
if (m.getType().isSuperColumnFamilyMetadata())
if (m.getType().equals(Type.SUPER_COLUMN_FAMILY))
if (!m.getType().equals(Type.SUPER_COLUMN_FAMILY))
@Test public void testEmbeddedCollection() { EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata( ((EntityManagerFactoryImpl) emf).getKunderaMetadataInstance(), KunderaUser.class); Assert.assertNotNull(entityMetadata); Assert.assertTrue(entityMetadata.getIndexProperties().isEmpty()); Assert.assertEquals(EntityMetadata.Type.SUPER_COLUMN_FAMILY, entityMetadata.getType()); Assert.assertNotNull(entityMetadata.toString()); entityMetadata.setCounterColumnType(false); Assert.assertFalse(entityMetadata.isCounterColumnType()); }
Type targetEntityType = targetEntityMetadata.getType(); Class idClass = targetEntityMetadata.getIdAttribute().getJavaType(); String idName = ((AbstractAttribute) targetEntityMetadata.getIdAttribute()).getJPAColumnName();
((AbstractAttribute) attribute).getBindableJavaType()); Object value; if (isCql3Enabled && !m.getType().equals(Type.SUPER_COLUMN_FAMILY))