@Override protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) { final FieldDescriptor fd = OjbUtil.findFieldDescriptor(mappedClass, fieldName, descriptorRepositories); if (fd != null) { final boolean autoInc = fd.isAutoIncrement(); final String seqName = fd.getSequenceName(); if (autoInc && StringUtils.isBlank(seqName)) { LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has autoincrement set to true but sequenceName is blank."); } if (!autoInc && StringUtils.isNotBlank(seqName)) { LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has autoincrement set to false but sequenceName is " + seqName + "."); } if (autoInc || StringUtils.isNotBlank(seqName)) { return new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), Collections.singletonList(new MemberValuePair("name", new StringLiteralExpr(upperCaseTableName ? seqName.toUpperCase() : seqName)))), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false)); } } return null; } }
private AnnotationExpr createJoinColumn(FieldDescriptor thisField, FieldDescriptor itemField) { final List<MemberValuePair> pairs = new ArrayList<MemberValuePair>(); pairs.add(new MemberValuePair("name", new StringLiteralExpr(thisField.getColumnName()))); pairs.add(new MemberValuePair("referencedColumnName", new StringLiteralExpr(itemField.getColumnName()))); if (!isAnonymousFk(thisField)) { pairs.add(new MemberValuePair("insertable", new BooleanLiteralExpr(false))); pairs.add(new MemberValuePair("updatable", new BooleanLiteralExpr(false))); } // Per this page: https://forums.oracle.com/message/3923913 // the nullable attribute is a hint to the DDL generation, especially on fields like this. // Commenting this flag out for now as it's just "noise" in the annotation definitions // if (!isNullableFk(thisField)) { // pairs.add(new MemberValuePair("nullable", new BooleanLiteralExpr(false))); // } return new NormalAnnotationExpr(new NameExpr("JoinColumn"), pairs); }
pairs.add(new MemberValuePair("name", new StringLiteralExpr(pfds[i].getColumnName()))); pairs.add(new MemberValuePair("referencedColumnName", new StringLiteralExpr(ipfds[i].getColumnName()))); joinColumns.add(new NormalAnnotationExpr(new NameExpr("PrimaryKeyJoinColumn"), pairs));
@Override protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) { final FieldDescriptor fd = OjbUtil.findFieldDescriptor(mappedClass, fieldName, descriptorRepositories); if (fd != null) { final boolean autoInc = fd.isAutoIncrement(); final String seqName = fd.getSequenceName(); if (autoInc && StringUtils.isBlank(seqName)) { LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has autoincrement set to true but sequenceName is blank."); } if (!autoInc && StringUtils.isNotBlank(seqName)) { LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has autoincrement set to false but sequenceName is " + seqName + "."); } if (autoInc || StringUtils.isNotBlank(seqName)) { return new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), Collections.singletonList(new MemberValuePair("generator", new StringLiteralExpr(upperCaseTableName ? seqName.toUpperCase() : seqName)))), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false)); } } return null; } }
final public NormalAnnotationExpr NormalAnnotation() throws ParseException { NameExpr name; List pairs = null; int line; int column; jj_consume_token(AT); line=token.beginLine; column=token.beginColumn; name = Name(); jj_consume_token(LPAREN); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case IDENTIFIER: pairs = MemberValuePairs(); break; default: jj_la1[127] = jj_gen; ; } jj_consume_token(RPAREN); NormalAnnotationExpr tmp = new NormalAnnotationExpr(line, column, token.endLine, token.endColumn,name, pairs); {if (true) return tmp;} throw new Error("Missing return statement in function"); }
final public NormalAnnotationExpr NormalAnnotation() throws ParseException { NameExpr name; List pairs = null; int line; int column; jj_consume_token(AT); line=token.beginLine; column=token.beginColumn; name = Name(); jj_consume_token(LPAREN); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case IDENTIFIER: pairs = MemberValuePairs(); break; default: jj_la1[125] = jj_gen; ; } jj_consume_token(RPAREN); {if (true) return new NormalAnnotationExpr(line, column, token.endLine, token.endColumn,name, pairs);} throw new Error("Missing return statement in function"); }
LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has a converter " + fc.getClass().getName() + " but a replacement converter was not configured, unable to set Convert class"); return new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), Collections.singletonList(new MemberValuePair("converter", new NameExpr(null)))), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false)); } else if ( StringUtils.isBlank(jpaConverter) ) { final String shortClassName = ClassUtils.getShortClassName(jpaConverter); final String packageName = ClassUtils.getPackageName(jpaConverter); return new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), Collections.singletonList(new MemberValuePair("converter", new NameExpr(shortClassName + ".class")))), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false), Collections.singletonList(new ImportDeclaration(new QualifiedNameExpr(new NameExpr(packageName), shortClassName), false, false)));
LOG.debug(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field scale is not set keeping @Column attribute (scale) at default"); return new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), pairs), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false));
final Collection<String> pks = OjbUtil.getPrimaryKeyNames(itemClassName, descriptorRepositories); joinColumnsPairs.add(new MemberValuePair("referencedColumnName", new StringLiteralExpr(getPksAsString(pks)))); joinColumns.add(new NormalAnnotationExpr(new NameExpr("JoinColumn"), joinColumnsPairs)); invJoinColumnsPairs.add(new MemberValuePair("referencedColumnName", new StringLiteralExpr( getPksAsString(pks)))); invJoinColumns.add(new NormalAnnotationExpr(new NameExpr("JoinColumn"), invJoinColumnsPairs)); return new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), pairs), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false), additionalImports);
return new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), pairs), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false), additionalImports);
@Override public Node visit(NormalAnnotationExpr _n, Object _arg) { NameExpr name = cloneNodes(_n.getName(), _arg); List<MemberValuePair> pairs = visit(_n.getPairs(), _arg); Comment comment = cloneNodes(_n.getComment(), _arg); NormalAnnotationExpr r = new NormalAnnotationExpr( _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), name, pairs ); r.setComment(comment); return r; }
@Override public NodeData resolve(Node node, String mappedClass) { if (!(node instanceof ClassOrInterfaceDeclaration)) { throw new IllegalArgumentException("this annotation belongs only on ClassOrInterfaceDeclaration"); } final TypeDeclaration dclr = (TypeDeclaration) node; if (!(dclr.getParentNode() instanceof CompilationUnit)) { //handling nested classes return null; } final String name = dclr.getName(); final String pckg = ((CompilationUnit) dclr.getParentNode()).getPackage().getName().toString(); final String enclosingClass = pckg + "." + name; final ClassDescriptor cd = OjbUtil.findClassDescriptor(enclosingClass, descriptorRepositories); if (cd != null) { final String tableName = getMappedTable(enclosingClass); if (tableName == null) { LOG.error(ResolverUtil.logMsgForClass(enclosingClass, mappedClass) + " table could not be found"); return null; } return new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), Collections.singletonList(new MemberValuePair("name", new StringLiteralExpr(upperCaseTableName ? tableName.toUpperCase() : tableName)))), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false)); } return null; }
+ "Even in the absence of a foreign key, one side must be the owning side.\n" + "If this is not the owning side, the required annotation should be:\n@OneToOne(mappedBy=\"" + mappedBy + "\")\n"); final NormalAnnotationExpr annotation = new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), pairs); annotation.setComment(fixme); nodeData = new NodeData(annotation, nodeData = new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), pairs), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false), additionalImports);
@Override protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) { final FieldDescriptor fd = OjbUtil.findFieldDescriptor(mappedClass, fieldName, descriptorRepositories); if (fd != null) { final Class<?> fc = ResolverUtil.getType(enclosingClass, fieldName); if (isEnum(fc)) { final Comment fixme = new BlockComment("\nFIXME:\n" + "Enums must be annotated with the @Enumerated annotation.\n " + "The @Enumerated annotation should set the EnumType.\n" + "If the EnumType is not set, then the Enumerated annotation is defaulted to EnumType.ORDINAL.\n" + "This conversion program cannot tell whether EnumType.ORDINAL is the appropriate EnumType."); AnnotationExpr enumerated = new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), Collections.singletonList(new MemberValuePair("value", new NameExpr("EnumType.")))); enumerated.setComment(fixme); return new NodeData(enumerated, new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false), Collections.singletonList(new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), "TemporalType"), false, false))); } } return null; }
ClassOrInterfaceDeclaration a = file.assertDeclaration(); MethodDeclaration show = new MethodDeclaration(Modifier.PUBLIC, ASTHelper.VOID_TYPE, "show"); show.setAnnotations(Collections.<AnnotationExpr>singletonList(new NormalAnnotationExpr(ASTHelper.createNameExpr(View.class.getName()), Collections.<MemberValuePair>emptyList()))); show.setBody(new BlockStmt()); a.getMembers().add(show);
MethodDeclaration index = new MethodDeclaration(Modifier.PUBLIC, ASTHelper.VOID_TYPE, "index"); ASTHelper.addParameter(index, ASTHelper.createParameter(new ClassOrInterfaceType(String.class.getName()), "s")); index.setAnnotations(Collections.<AnnotationExpr>singletonList(new NormalAnnotationExpr(ASTHelper.createNameExpr(View.class.getName()), Collections.<MemberValuePair>emptyList()))); index.setBody(new BlockStmt()); a.getMembers().add(index);
MethodDeclaration index = new MethodDeclaration(Modifier.PUBLIC, ASTHelper.VOID_TYPE, "index"); ASTHelper.addParameter(index, ASTHelper.createParameter(new ClassOrInterfaceType(String.class.getName()), "s")); index.setAnnotations(Collections.<AnnotationExpr>singletonList(new NormalAnnotationExpr(ASTHelper.createNameExpr(View.class.getName()), Collections.<MemberValuePair>emptyList()))); index.setBody(new BlockStmt()); a.getMembers().add(index);
PackageDeclaration pkg = pkgFile.assertPackage(); pkg.getAnnotations().clear(); List<AnnotationExpr> a = Collections.<AnnotationExpr>singletonList(new NormalAnnotationExpr(ASTHelper.createNameExpr( Application.class.getName()), Collections.<MemberValuePair>singletonList(new MemberValuePair(
PackageDeclaration pkg = pkgFile.assertPackage(); pkg.getAnnotations().clear(); List<AnnotationExpr> a = Collections.<AnnotationExpr>singletonList(new NormalAnnotationExpr(ASTHelper.createNameExpr( Application.class.getName()), Collections.<MemberValuePair>singletonList(new MemberValuePair(
ClassOrInterfaceDeclaration a = file.assertDeclaration(); MethodDeclaration show = new MethodDeclaration(Modifier.PUBLIC, ASTHelper.VOID_TYPE, "show"); show.setAnnotations(Collections.<AnnotationExpr>singletonList(new NormalAnnotationExpr(ASTHelper.createNameExpr(View.class.getName()), Collections.<MemberValuePair>emptyList()))); show.setBody(new BlockStmt()); a.getMembers().add(show);