/** * Adds the discriminator. * * @param values * the values * @param entityType * the entity type */ private void addDiscriminator(Map<String, Object> values, EntityType entityType) { String discrColumn = ((AbstractManagedType) entityType).getDiscriminatorColumn(); String discrValue = ((AbstractManagedType) entityType).getDiscriminatorValue(); // No need to check for empty or blank, as considering it as valid name // for nosql! if (discrColumn != null && discrValue != null) { values.put(discrColumn, discrValue); } }
m.getPersistenceUnit()); EntityType entityType = metaModel.entity(m.getEntityClazz()); List<AbstractManagedType> subManagedTypes = ((AbstractManagedType) entityType).getSubManagedType(); Map<String, Class> discrValueToEntityClazz = new HashMap<String, Class>(); String discrColumn = null; discrColumn = ((AbstractManagedType) subEntity).getDiscriminatorColumn(); discrValueToEntityClazz.put(subEntity.getDiscriminatorValue(), subEntity.getJavaType());
@Override public void validateFieldAnnotation(Annotation annotation, Field field, ManagedType managedType) { List<String> tables = ((DefaultEntityAnnotationProcessor) ((AbstractManagedType) managedType) .getEntityAnnotation()).getSecondaryTablesName(); Annotation primaryTableannotation = ((AbstractManagedType) managedType).getEntityAnnotation().getAnnotation( Table.class.getName()); String primaryTableName = ""; if (primaryTableannotation != null) { primaryTableName = ((Table) primaryTableannotation).name(); } String tableNameOfColumn = getTableNameOfColumn(); if (tableNameOfColumn != null && !tables.contains(tableNameOfColumn) && !primaryTableName.isEmpty() && !primaryTableName.equals(tableNameOfColumn)) { throw new InvalidEntityDefinitionException("Inavalid table " + tableNameOfColumn + " for field " + field); } }
/** * Adds the discriminator clause. * * @param clauses * the clauses * @param entityType * the entity type */ private void addDiscriminatorClause(List<String> clauses, EntityType entityType) { if (((AbstractManagedType) entityType).isInherited()) { String discrColumn = ((AbstractManagedType) entityType).getDiscriminatorColumn(); String discrValue = ((AbstractManagedType) entityType).getDiscriminatorValue(); if (discrColumn != null && discrValue != null) { if (clauses != null && !clauses.isEmpty()) { filtersQueue.add("AND"); } FilterClause filterClause = new FilterClause(discrColumn, "=", discrValue, discrColumn); filtersQueue.add(filterClause); } } }
/** * Bind type annotations. */ private void bindTypeAnnotations() { // TODO:: need to check @Embeddable attributes as well! // TODO:: need to Handle association override in // RelationMetadataProcessor. for (Class<? extends Annotation> ann : validJPAAnnotations) { if (getJavaType().isAnnotationPresent(ann)) { checkForValid(); Annotation annotation = getJavaType().getAnnotation(ann); if (ann.isAssignableFrom(AttributeOverride.class)) { bindAttribute(annotation); } else if (ann.isAssignableFrom(AttributeOverrides.class)) { AttributeOverride[] attribAnns = ((AttributeOverrides) annotation).value(); for (AttributeOverride attribOverann : attribAnns) { bindAttribute(attribOverann); } } } } }
List<AbstractManagedType> subManagedType = ((AbstractManagedType) entityType).getSubManagedType(); for (AbstractManagedType subEntity : subManagedType) { EntityMetadata subEntityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, subEntity.getJavaType());
/** * Checks if is string property. * * @param m * the m * @param fieldName * the field name * @return true, if is string property */ private boolean isStringProperty(EntityType entityType, Attribute attribute) { String discriminatorColumn = ((AbstractManagedType) entityType).getDiscriminatorColumn(); if (attribute.getName().equals(discriminatorColumn)) { return true; } return attribute != null ? ((AbstractAttribute) attribute).getBindableJavaType().isAssignableFrom(String.class) || ((AbstractAttribute) attribute).getBindableJavaType().isAssignableFrom(Character.class) || ((AbstractAttribute) attribute).getBindableJavaType().isAssignableFrom(char.class) || ((AbstractAttribute) attribute).getBindableJavaType().isAssignableFrom(Date.class) || ((AbstractAttribute) attribute).getBindableJavaType().isAssignableFrom(java.util.Date.class) : false; } }
/** * Adds the sub managed type. * * @param inheritedType * the inherited type */ private void addSubManagedType(ManagedType inheritedType) { if (Modifier.isAbstract(this.getJavaType().getModifiers())) { subManagedTypes.add(inheritedType); } }
.getAttributes().size()); Assert.assertEquals(KunderaCoreUtils.countNonSyntheticFields(OToOOwnerEntity.class), managedType .getDeclaredAttributes().size()); .getAttribute("association"); Assert.assertNotNull(associationAttribute); Assert.assertEquals(PersistentAttributeType.ONE_TO_ONE, associationAttribute.getPersistentAttributeType()); .getAttributes().size()); Assert.assertEquals(AssociationEntity.class, managedType.getJavaType()); Assert.assertEquals(KunderaCoreUtils.countNonSyntheticFields(AssociationEntity.class), managedType .getDeclaredAttributes().size()); assertOnIdAttribute(managedType, "assoRowKey", String.class);
/** * Gets the sub managed type. * * @param entityClass * the entity class * @param entityMetadata * the entity metadata * @return the sub managed type */ private List<AbstractManagedType> getSubManagedType(Class entityClass, EntityMetadata entityMetadata) { MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel( entityMetadata.getPersistenceUnit()); EntityType entityType = metaModel.entity(entityClass); List<AbstractManagedType> subManagedType = ((AbstractManagedType) entityType).getSubManagedType(); return subManagedType; }
if (managedType.hasLobAttribute()) String discriminatorColumn = ((AbstractManagedType) entity).getDiscriminatorColumn();
Assert.assertEquals(clazz, managedType.getJavaType()); SingularAttribute<? super X, String> rowId = (SingularAttribute<? super X, String>) managedType .getDeclaredSingularAttribute(id); Assert.assertNotNull(rowId); Assert.assertTrue(rowId.isId()); .getDeclaredAttribute(otherAttribute); Assert.assertNotNull(byteAttribute); Assert.assertFalse(byteAttribute.isId());
if (managedType.hasLobAttribute()) List<String> secondaryTables = ((DefaultEntityAnnotationProcessor) managedType.getEntityAnnotation()) .getSecondaryTablesName(); secondaryTables.add(entityMetadata.getTableName());
.getAttributes().size()); Assert.assertEquals(KunderaCoreUtils.countNonSyntheticFields(OToMOwnerEntity.class), managedType .getDeclaredAttributes().size()); .getCollection("association", AssociationEntity.class); Assert.assertNotNull(collectionAttribute); .getDeclaredCollection("association", AssociationEntity.class); Assert.assertNotNull(declaredCollectionAttribute); .getDeclaredCollection("association"); Assert.assertNotNull(declaredCollectionAttributeParam); collectionAttribute = (CollectionAttribute<? super X, ?>) managedType.getCollection("association", AssociationBiEntity.class); Assert.fail(); collectionAttribute = (CollectionAttribute<? super X, ?>) managedType.getCollection("associationInvalid"); Assert.fail(); .getAttribute("association"); Assert.assertNotNull(associationAttribute); Assert.assertEquals(PersistentAttributeType.ONE_TO_MANY, associationAttribute.getPersistentAttributeType());
Assert.assertEquals(5, managedType.getAttributes().size()); Assert.assertNotNull(managedType.getAttribute("mappedInt")); Assert.assertNotNull(managedType.getSingularAttribute("mappedInt", int.class)); Assert.assertEquals(5, managedType.getAttributes().size()); Assert.assertNotNull(managedType.getAttribute("mappedInt")); Assert.assertNotNull(managedType.getSingularAttribute("mappedInt", int.class));
AbstractManagedType managedType = managedTypes.get(clazz); Assert.assertNotNull(managedType); Assert.assertEquals(2, managedType.getAttributes().size()); Attribute idAttribute = managedType.getAttribute("id");
m.getPersistenceUnit()); EntityType entityType = metaModel.entity(m.getEntityClazz()); Set<Attribute> attributes = ((AbstractManagedType) entityType).getAttributes();
entityMetadata.getPersistenceUnit()); EntityType entityType = metaModel.entity(entityClass); List<AbstractManagedType> subManagedType = ((AbstractManagedType) entityType).getSubManagedType(); try subEntity.getJavaType()); results = handler.readAll(subEntityMetadata.getSchema(), subEntityMetadata.getEntityClazz(), subEntityMetadata, Arrays.asList(rowIds), subEntityMetadata.getRelationNames());
/** * Gets the filter for discr column. * * @param m * the m * @return the filter for discr column */ private Filter getFilterForDiscrColumn(EntityMetadata m) { MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata() .getMetamodel(m.getPersistenceUnit()); AbstractManagedType entity = (AbstractManagedType) metaModel.entity(m.getEntityClazz()); if (entity.isInherited()) { return new SingleColumnValueFilter(Bytes.toBytes(m.getTableName()), Bytes.toBytes(entity.getDiscriminatorColumn()), CompareOp.EQUAL, Bytes.toBytes(entity.getDiscriminatorValue())); } return null; }
String discriminatorColumn = ((AbstractManagedType) entity).getDiscriminatorColumn();