Search in sources :

Example 16 with FieldMetadata

use of javax.jdo.metadata.FieldMetadata in project motech by motech.

the class EntityMetadataBuilderImpl method addIdField.

private void addIdField(ClassMetadata cmd, String className, Class<?> definition) {
    boolean containsID;
    boolean isBaseClass;
    try {
        CtClass ctClass = MotechClassPool.getDefault().getOrNull(className);
        containsID = null != ctClass && null != ctClass.getField(ID_FIELD_NAME);
        isBaseClass = null != ctClass && (null == ctClass.getSuperclass() || Object.class.getName().equalsIgnoreCase(ctClass.getSuperclass().getName()));
    } catch (NotFoundException e) {
        containsID = false;
        isBaseClass = false;
    }
    if (containsID && isBaseClass) {
        FieldMetadata metadata = cmd.newFieldMetadata(ID_FIELD_NAME);
        metadata.setValueStrategy(getIdGeneratorStrategy(metadata, definition));
        metadata.setPrimaryKey(true);
    }
}
Also used : CtClass(javassist.CtClass) FieldMetadata(javax.jdo.metadata.FieldMetadata) NotFoundException(javassist.NotFoundException)

Aggregations

FieldMetadata (javax.jdo.metadata.FieldMetadata)16 Test (org.junit.Test)6 FieldDto (org.motechproject.mds.dto.FieldDto)6 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 ForeignKeyMetadata (javax.jdo.metadata.ForeignKeyMetadata)3 MetadataDto (org.motechproject.mds.dto.MetadataDto)3 CtClass (javassist.CtClass)2 IndexMetadata (javax.jdo.metadata.IndexMetadata)2 JoinMetadata (javax.jdo.metadata.JoinMetadata)2 Matchers.anyString (org.mockito.Matchers.anyString)2 AnotherSample (org.motechproject.mds.annotations.internal.samples.AnotherSample)2 Sample (org.motechproject.mds.builder.Sample)2 LookupDto (org.motechproject.mds.dto.LookupDto)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 CtField (javassist.CtField)1 NotFoundException (javassist.NotFoundException)1 ClassMetadata (javax.jdo.metadata.ClassMetadata)1 CollectionMetadata (javax.jdo.metadata.CollectionMetadata)1