/** * Generate and write the application identity code. */ private ApplicationIdTool newApplicationIdTool(ClassMapping mapping) { ApplicationIdTool tool; if (mapping.getIdentityType() == ClassMapping.ID_APPLICATION && !mapping.isOpenJPAIdentity() && mapping.getPCSuperclass() == null) { tool = new ApplicationIdTool(_conf, mapping.getDescribedType(), mapping); tool.setDirectory(_dir); tool.setCodeFormat(_format); if (!tool.run()) return null; return tool; } return null; }
/** * Return the necessary imports for the class. */ private String getImports() { Set pkgs = getImportPackages(); CodeFormat imports = newCodeFormat(); String base = ClassUtil.getPackageName(_meta.getObjectIdType()); String pkg; for (Iterator itr = pkgs.iterator(); itr.hasNext();) { pkg = (String) itr.next(); if (pkg.length() > 0 && !"java.lang".equals(pkg) && !base.equals(pkg)) { if (imports.length() > 0) imports.endl(); imports.append("import ").append(pkg).append(".*;"); } } return imports.toString(); }
public ReverseCodeGenerator(ClassMapping mapping, ApplicationIdTool aid) { super(mapping); super.setDirectory(_dir); super.setCodeFormat(_format); _mapping = mapping; if (aid != null && aid.isInnerClass()) _appid = aid; else _appid = null; }
String className = getClassName(); String packageName = ClassUtil.getPackageName(oidClass); String packageDec = ""; String imports = getImports(); String fieldDecs = getFieldDeclarations(); String constructor = getConstructor(superOidClass != null); String properties = getProperties(); String fromStringCode = getFromStringCode(superOidClass != null); String toStringCode = getToStringCode(superOidClass != null); String equalsCode = getEqualsCode(superOidClass != null); String hashCodeCode = getHashCodeCode(superOidClass != null); CodeFormat code = newCodeFormat(); if (!isInnerClass() && packageDec.length() > 0) code.append(packageDec).afterSection(); if (!isInnerClass() && imports.length() > 0) code.append(imports).afterSection(); append(" */").endl(); code.append("public "); if (isInnerClass()) code.append("static "); code.append("class ").append(className); code.afterSection().append(getToBytesByteArrayCode()); code.afterSection().append(getToStringByteArrayCode()); code.afterSection().append(getEqualsByteArrayCode());
MetaDataRepository repos = conf.newMetaDataRepositoryInstance(); repos.setValidate(repos.VALIDATE_NONE, true); loadObjectIds(repos, flags.name == null && flags.suffix == null); setObjectIdType(meta, flags, bc); tool = new ApplicationIdTool(conf, cls, meta); tool.setDirectory(flags.directory); tool.setIgnoreErrors(flags.ignoreErrors); tool.setToken(flags.token); tool.setCodeFormat(flags.format); if (tool.run()) { log.info(_loc.get("appid-output", tool.getFile())); tool.record(); } else log.info(_loc.get("appid-norun"));
gen.writeCode(); written.add(gen.getFile()); if (aid != null && !aid.isInnerClass()) aid.record(); } else { StringWriter writer = new StringWriter(); output.put(mappings[i].getDescribedType(), writer.toString()); if (aid != null && !aid.isInnerClass()) { writer = new StringWriter(); aid.setWriter(writer); aid.record(); output.put(mappings[i].getObjectIdType(), writer.toString());
if (hasConcreteSuperclass() || (hasSuperclass && _fields.length == 0)) return ""; CodeFormat code = newCodeFormat(); code.tab().append("public int hashCode").parens(). openBrace(2).endl(); else if (_fields.length == 1 && !hasSuperclass) { code.tab(2).append("return "); appendHashCodeCode(_fields[0], code); code.append(";").endl(); } else { appendHashCodeCode(_fields[i], code); code.append(";").endl();
if (hasConcreteSuperclass() || (hasSuperclass && _fields.length == 0)) return ""; CodeFormat code = newCodeFormat(); code.tab().append("public boolean equals").openParen(true). append("Object obj").closeParen().openBrace(2).endl(); String className = getClassName(); if (hasSuperclass) { code.tab(2).append("if").openParen(true).
public boolean run(Options opts) throws ClassNotFoundException, IOException { OpenJPAConfiguration conf = new OpenJPAConfigurationImpl(); try { return ApplicationIdTool.run(conf, arguments, opts); } finally { conf.close(); } } });
/** * Return the string constructor code. */ private String getConstructor(boolean hasSuperclass) { CodeFormat code = newCodeFormat(); code.tab().append("public "); code.append(getClassName()); code.openParen(true).append("String str").closeParen(); code.openBrace(2).endl(); if (_fields.length != 0 || (hasSuperclass && _meta.getPrimaryKeyFields().length > 0)) { code.tab(2).append("fromString").openParen(true). append("str").closeParen().append(";").endl(); } code.closeBrace(2); return code.toString(); }
/** * Add the list of imports for any inner app id classes * * @return */ public Set getImportPackages() { Set pkgs = super.getImportPackages(); if (_appid != null) pkgs.addAll(_appid.getImportPackages()); return pkgs; }
/** * If there is an inner application identity class, then * add it to the bottom of the class code. */ protected void closeClassBrace(CodeFormat code) { if (_appid != null) { code.afterSection(); code.append(_appid.getCode()); code.endl(); } super.closeClassBrace(code); }
String className = getClassName(); String packageName = ClassUtil.getPackageName(oidClass); String packageDec = ""; String imports = getImports(); String fieldDecs = getFieldDeclarations(); String constructor = getConstructor(superOidClass != null); String properties = getProperties(); String fromStringCode = getFromStringCode(superOidClass != null); String toStringCode = getToStringCode(superOidClass != null); String equalsCode = getEqualsCode(superOidClass != null); String hashCodeCode = getHashCodeCode(superOidClass != null); CodeFormat code = newCodeFormat(); if (!isInnerClass() && packageDec.length() > 0) code.append(packageDec).afterSection(); if (!isInnerClass() && imports.length() > 0) code.append(imports).afterSection(); append(" */").endl(); code.append("public "); if (isInnerClass()) code.append("static "); code.append("class ").append(className); code.afterSection().append(getToBytesByteArrayCode()); code.afterSection().append(getToStringByteArrayCode()); code.afterSection().append(getEqualsByteArrayCode());
MetaDataRepository repos = conf.newMetaDataRepositoryInstance(); repos.setValidate(repos.VALIDATE_NONE, true); loadObjectIds(repos, flags.name == null && flags.suffix == null); setObjectIdType(meta, flags, bc); tool = new ApplicationIdTool(conf, cls, meta); tool.setDirectory(flags.directory); tool.setIgnoreErrors(flags.ignoreErrors); tool.setToken(flags.token); tool.setCodeFormat(flags.format); if (tool.run()) { log.info(_loc.get("appid-output", tool.getFile())); tool.record(); } else log.info(_loc.get("appid-norun"));
gen.writeCode(); written.add(gen.getFile()); if (aid != null && !aid.isInnerClass()) aid.record(); } else { StringWriter writer = new StringWriter(); output.put(mappings[i].getDescribedType(), writer.toString()); if (aid != null && !aid.isInnerClass()) { writer = new StringWriter(); aid.setWriter(writer); aid.record(); output.put(mappings[i].getObjectIdType(), writer.toString());
if (hasConcreteSuperclass() || (hasSuperclass && _fields.length == 0)) return ""; CodeFormat code = newCodeFormat(); code.tab().append("public int hashCode").parens(). openBrace(2).endl(); else if (_fields.length == 1 && !hasSuperclass) { code.tab(2).append("return "); appendHashCodeCode(_fields[0], code); code.append(";").endl(); } else { appendHashCodeCode(_fields[i], code); code.append(";").endl();
if (hasConcreteSuperclass() || (hasSuperclass && _fields.length == 0)) return ""; CodeFormat code = newCodeFormat(); code.tab().append("public boolean equals").openParen(true). append("Object obj").closeParen().openBrace(2).endl(); String className = getClassName(); if (hasSuperclass) { code.tab(2).append("if").openParen(true).
public boolean run(Options opts) throws ClassNotFoundException, IOException { OpenJPAConfiguration conf = new OpenJPAConfigurationImpl(); try { return ApplicationIdTool.run(conf, arguments, opts); } finally { conf.close(); } } });
/** * Return the string constructor code. */ private String getConstructor(boolean hasSuperclass) { CodeFormat code = newCodeFormat(); code.tab().append("public "); code.append(getClassName()); code.openParen(true).append("String str").closeParen(); code.openBrace(2).endl(); if (_fields.length != 0 || (hasSuperclass && _meta.getPrimaryKeyFields().length > 0)) { code.tab(2).append("fromString").openParen(true). append("str").closeParen().append(";").endl(); } code.closeBrace(2); return code.toString(); }
/** * Add the list of imports for any inner app id classes * * @return */ public Set getImportPackages() { Set pkgs = super.getImportPackages(); if (_appid != null) pkgs.addAll(_appid.getImportPackages()); return pkgs; }