001/** 002 * Copyright 2005-2015 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.devtools.jpa.eclipselink.conv.parser.helper.resolver; 017 018import japa.parser.ast.comments.BlockComment; 019import japa.parser.ast.comments.Comment; 020import japa.parser.ast.ImportDeclaration; 021import japa.parser.ast.expr.AnnotationExpr; 022import japa.parser.ast.expr.ArrayInitializerExpr; 023import japa.parser.ast.expr.Expression; 024import japa.parser.ast.expr.NameExpr; 025import japa.parser.ast.expr.QualifiedNameExpr; 026import japa.parser.ast.expr.SingleMemberAnnotationExpr; 027import org.apache.commons.logging.Log; 028import org.apache.commons.logging.LogFactory; 029import org.apache.ojb.broker.metadata.DescriptorRepository; 030import org.kuali.rice.devtools.jpa.eclipselink.conv.parser.helper.NodeData; 031 032import java.util.Collection; 033import java.util.Collections; 034import java.util.List; 035 036/** 037 * this only does mappings for OneToOne at the field level for compound fks. 038 */ 039public class PrimaryKeyJoinColumnsResolver extends AbstractPrimaryKeyJoinColumnResolver { 040 private static final Log LOG = LogFactory.getLog(PrimaryKeyJoinColumnsResolver.class); 041 042 public static final String PACKAGE = "javax.persistence"; 043 public static final String SIMPLE_NAME = "PrimaryKeyJoinColumns"; 044 045 public PrimaryKeyJoinColumnsResolver(Collection<DescriptorRepository> descriptorRepositories) { 046 super(descriptorRepositories); 047 } 048 @Override 049 public String getFullyQualifiedName() { 050 return PACKAGE + "." + SIMPLE_NAME; 051 } 052 053 @Override 054 protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) { 055 final List<Expression> joinColumns = getJoinColumns(enclosingClass, fieldName, mappedClass); 056 if (joinColumns != null && joinColumns.size() > 1) { 057 final Comment fixme = new BlockComment("\nFIXME: JPA_CONVERSION\n" 058 + "For compound primary keys, make sure the join columns are in the correct order.\n"); 059 AnnotationExpr annotation = new SingleMemberAnnotationExpr(new NameExpr(SIMPLE_NAME), new ArrayInitializerExpr(joinColumns)); 060 annotation.setComment(fixme); 061 return new NodeData(annotation, 062 new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false), 063 Collections.singletonList(new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), "PrimaryKeyJoinColumn"), false, false))); 064 } 065 066 return null; 067 } 068}