use of com.sun.jdo.spi.persistence.utility.generator.JavaClassWriter in project Payara by payara.
the class Main method writeOidClass.
private void writeOidClass(final String className, final String oidClassName, final boolean enclosedOid) throws IOException {
final String[] comments = new String[] { dotLine, "Key Class:", dotLine };
final String superOidClassName = ImplHelper.normalizeClassName(meta.getSuperKeyClass(className));
JavaClassWriter oidWriter = new IOJavaClassWriter();
oidWriter.setClassDeclaration((enclosedOid ? Modifier.PUBLIC | Modifier.STATIC : 0), oidClassName, ImplHelper.COMMENT_NOT_ENHANCER_ADDED);
oidWriter.setSuperclass(superOidClassName);
oidWriter.addInterface(Serializable.class.getName());
final boolean isPCRoot = meta.isPersistenceCapableRootClass(className);
final String[] pknames = meta.getKeyFields(className);
final String[] pktypes = meta.getFieldType(className, pknames);
// write the PK-fields
for (int i = 0; i < pknames.length; i++) {
oidWriter.addField(pknames[i], Modifier.PUBLIC, ImplHelper.normalizeClassName(pktypes[i]), null, null);
}
// write default constructor
oidWriter.addConstructor(oidClassName, Modifier.PUBLIC, null, null, null, ImplHelper.getDefaultConstructorImpl(), ImplHelper.COMMENT_NOT_ENHANCER_ADDED);
// hashCode
oidWriter.addMethod("hashCode", Modifier.PUBLIC, "int", null, null, null, ImplHelper.getOidHashCodeImpl(pknames, pktypes, isPCRoot), ImplHelper.COMMENT_NOT_ENHANCER_ADDED);
// equals
oidWriter.addMethod("equals", Modifier.PUBLIC, JavaClassWriterHelper.boolean_, new String[] { "pk" }, new String[] { Object.class.getName() }, null, ImplHelper.getOidEqualsImpl(oidClassName, pknames, pktypes, "pk", isPCRoot), ImplHelper.COMMENT_NOT_ENHANCER_ADDED);
if (enclosedOid) {
writer.addClass(oidWriter);
} else {
fWriter.addClass(oidWriter);
}
}
Aggregations