ClassFile ccFile = cc.getClassFile();
ConstPool constpool = ccFile.getConstPool();
// 1.2.1] Create an annotation for the class
AnnotationsAttribute attrClass = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag);
// 1.2.1.1] Entity
Annotation annotEntity = new Annotation("javax.persistence.Entity", constpool);
attrClass.addAnnotation(annotEntity);
// 1.2.1.2] Table info
Annotation annotTable = new Annotation("javax.persistence.Table", constpool);
annotTable.addMemberValue("name", new StringMemberValue("TEST_CLASS", ccFile.getConstPool()));
annotTable.addMemberValue("schema", new StringMemberValue("KunderaTest@mongoPU", ccFile.getConstPool()));
attrClass.addAnnotation(annotTable);
// 1.2.1.3] Attach the annotation to the class
ccFile.addAttribute(attrClass);
// 1.2.2] Create an annotation for the field
// 1.2.2.1] Annotation Id
AnnotationsAttribute attrIdField = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag);
Annotation annotId = new Annotation("javax.persistence.Id", constpool);
attrIdField.addAnnotation(annotId);
idField.getFieldInfo().addAttribute(attrIdField);
// 1.2.2.2] Annotation Column (name="testField")
AnnotationsAttribute attrTestField = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag);
Annotation annotCol = new Annotation("javax.persistence.Column", constpool);
annotCol.addMemberValue("name", new StringMemberValue("TEST_FIELD", ccFile.getConstPool()));
attrTestField.addAnnotation(annotCol);
testField.getFieldInfo().addAttribute(attrTestField);
if (null != testField2) {
AnnotationsAttribute attrTestField2 = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag);
Annotation annotCol2 = new Annotation("javax.persistence.Column", constpool);
annotCol.addMemberValue("name", new StringMemberValue("TEST_FIELD2", ccFile.getConstPool()));
attrTestField2.addAnnotation(annotCol2);
testField2.getFieldInfo().addAttribute(attrTestField2);
}
// 1.3] Add methods