Java Code Examples for javax.persistence.ManyToOne

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project b3log-latke, under directory /latke/src/main/java/org/b3log/latke/repository/jpa/.

Source file: MetaEntity.java

  19 
vote

/** 
 * Constructs a meta entity with the specified entity class.
 * @param entityClass the specified entity class
 */
public MetaEntity(final Class<?> entityClass){
  LOGGER.log(Level.FINER,"Analysing an entity scheme....");
  if (!EntityClassCheckers.isValid(entityClass)) {
    throw new IllegalArgumentException("The specified class is not a valid entity class");
  }
  this.entityClass=entityClass;
  final String entityClassName=entityClass.getSimpleName();
  repositoryName=entityClassName.substring(0,1).toLowerCase() + entityClassName.substring(1);
  LOGGER.log(Level.FINER,"Entity[classSimpleName={0}] to repository[name={1}]",new Object[]{entityClass.getSimpleName(),repositoryName});
  final Field[] allFields=entityClass.getDeclaredFields();
  for (int i=0; i < allFields.length; i++) {
    final Field field=allFields[i];
    final Class<?> fieldClass=field.getType();
    if (field.isAnnotationPresent(Id.class)) {
      fields.put(Keys.OBJECT_ID,field);
      continue;
    }
    if (fieldClass.isPrimitive() || String.class.equals(fieldClass)) {
      fields.put(field.getName(),field);
      continue;
    }
    if (field.isAnnotationPresent(OneToOne.class) || field.isAnnotationPresent(ManyToOne.class)) {
      fields.put(field.getName() + "Id",field);
      continue;
    }
    if (field.isAnnotationPresent(ManyToMany.class)) {
      final String many2ManyReposName=fieldClass.getSimpleName() + '_' + entityClass.getSimpleName();
      Relationships.addManyToManyRepositoryName(many2ManyReposName);
    }
  }
  Entities.addMetaEntity(this);
}
 

Example 2

From project Core_2, under directory /javaee-impl/src/main/java/org/jboss/forge/spec/javaee/jpa/.

Source file: FieldPlugin.java

  19 
vote

@Command(value="oneToMany",help="Add a one-to-many relationship field (java.lang.Set<?>) to an existing @Entity class") public void newOneToManyRelationship(@Option(name="named",required=true,description="The field name",type=PromptType.JAVA_VARIABLE_NAME) final String fieldName,@Option(name="fieldType",required=true,description="The @Entity representing the 'many' side of the relationship.",type=PromptType.JAVA_CLASS) final String fieldType,@Option(name="inverseFieldName",required=false,description="Create an bi-directional relationship, using this value as the name of the inverse field.",type=PromptType.JAVA_VARIABLE_NAME) final String inverseFieldName){
  JavaSourceFacet java=project.getFacet(JavaSourceFacet.class);
  try {
    JavaClass one=getJavaClass();
    JavaClass many=findEntity(fieldType);
    one.addImport(Set.class);
    one.addImport(HashSet.class);
    one.addImport(many.getQualifiedName());
    Field<JavaClass> oneField=one.addField("private Set<" + many.getName() + "> "+ fieldName+ "= new HashSet<"+ many.getName()+ ">();");
    Annotation<JavaClass> annotation=oneField.addAnnotation(OneToMany.class);
    Refactory.createGetterAndSetter(one,oneField);
    if ((inverseFieldName != null) && !inverseFieldName.isEmpty()) {
      annotation.setStringValue("mappedBy",inverseFieldName);
      annotation.setLiteralValue("cascade","CascadeType.ALL");
      annotation.getOrigin().addImport(CascadeType.class);
      annotation.setLiteralValue("orphanRemoval","true");
      many.addImport(one);
      Field<JavaClass> manyField=many.addField("private " + one.getName() + " "+ inverseFieldName+ ";");
      manyField.addAnnotation(ManyToOne.class);
      Refactory.createGetterAndSetter(many,manyField);
      java.saveJavaSource(many);
    }
    java.saveJavaSource(one);
  }
 catch (  FileNotFoundException e) {
    shell.println("Could not locate the @Entity requested. No update was made.");
  }
}
 

Example 3

From project Core_2, under directory /javaee-impl/src/main/java/org/jboss/forge/spec/javaee/jpa/.

Source file: FieldPlugin.java

  19 
vote

@Command(value="manyToOne",help="Add a many-to-one relationship field to an existing @Entity class") public void newManyToOneRelationship(@Option(name="named",required=true,description="The field name",type=PromptType.JAVA_VARIABLE_NAME) final String fieldName,@Option(name="fieldType",required=true,description="The @Entity representing the 'one' side of the relationship.",type=PromptType.JAVA_CLASS) final String fieldType,@Option(name="inverseFieldName",required=false,description="Create an bi-directional relationship, using this value as the name of the inverse field.",type=PromptType.JAVA_VARIABLE_NAME) final String inverseFieldName){
  JavaSourceFacet java=project.getFacet(JavaSourceFacet.class);
  try {
    JavaClass many=getJavaClass();
    JavaClass one=findEntity(fieldType);
    many.addImport(one);
    Field<JavaClass> manyField=many.addField("private " + one.getName() + " "+ fieldName+ ";");
    manyField.addAnnotation(ManyToOne.class);
    Refactory.createGetterAndSetter(many,manyField);
    if ((inverseFieldName != null) && !inverseFieldName.isEmpty()) {
      one.addImport(Set.class);
      one.addImport(HashSet.class);
      one.addImport(many.getQualifiedName());
      Field<JavaClass> oneField=one.addField("private Set<" + many.getName() + "> "+ inverseFieldName+ "= new HashSet<"+ many.getName()+ ">();");
      Annotation<JavaClass> oneAnnotation=oneField.addAnnotation(OneToMany.class).setStringValue("mappedBy",fieldName);
      oneAnnotation.setLiteralValue("cascade","CascadeType.ALL");
      oneAnnotation.getOrigin().addImport(CascadeType.class);
      Refactory.createGetterAndSetter(one,oneField);
      java.saveJavaSource(one);
    }
    java.saveJavaSource(many);
  }
 catch (  FileNotFoundException e) {
    shell.println("Could not locate the @Entity requested. No update was made.");
  }
}
 

Example 4

From project Core_2, under directory /javaee-impl/src/test/java/org/jboss/forge/spec/jpa/.

Source file: NewFieldPluginTest.java

  19 
vote

@Test public void testNewOneToManyRelationshipInverse() throws Exception {
  Project project=getProject();
  JavaClass rightEntity=generateEntity(project);
  JavaClass leftEntity=generateEntity(project);
  getShell().execute(ConstraintInspector.getName(FieldPlugin.class) + " oneToMany --named right --fieldType ~." + PersistenceFacetImpl.DEFAULT_ENTITY_PACKAGE+ "."+ rightEntity.getName()+ " --inverseFieldName left");
  leftEntity=(JavaClass)project.getFacet(JavaSourceFacet.class).getJavaResource(leftEntity).getJavaSource();
  assertTrue(leftEntity.hasAnnotation(Entity.class));
  assertTrue(leftEntity.hasField("right"));
  assertEquals("Set",leftEntity.getField("right").getType());
  assertEquals(rightEntity.getQualifiedName(),leftEntity.getField("right").getTypeInspector().getTypeArguments().get(0).getQualifiedName());
  assertTrue(leftEntity.getField("right").hasAnnotation(OneToMany.class));
  assertEquals("left",leftEntity.getField("right").getAnnotation(OneToMany.class).getStringValue("mappedBy"));
  assertEquals("CascadeType.ALL",leftEntity.getField("right").getAnnotation(OneToMany.class).getLiteralValue("cascade"));
  assertTrue(leftEntity.hasImport(rightEntity.getQualifiedName()));
  assertTrue(leftEntity.hasImport(OneToMany.class));
  assertFalse(leftEntity.hasSyntaxErrors());
  rightEntity=(JavaClass)project.getFacet(JavaSourceFacet.class).getJavaResource(rightEntity).getJavaSource();
  assertTrue(rightEntity.hasField("left"));
  assertEquals(leftEntity.getName(),rightEntity.getField("left").getType());
  assertTrue(rightEntity.getField("left").hasAnnotation(ManyToOne.class));
  assertNull(rightEntity.getField("left").getAnnotation(ManyToOne.class).getStringValue("mappedBy"));
  assertTrue(rightEntity.hasImport(leftEntity.getQualifiedName()));
  assertTrue(rightEntity.hasImport(ManyToOne.class));
  assertFalse(rightEntity.hasSyntaxErrors());
}
 

Example 5

From project Core_2, under directory /javaee-impl/src/test/java/org/jboss/forge/spec/jpa/.

Source file: NewFieldPluginTest.java

  19 
vote

@Test public void testNewManyToOneRelationshipInverse() throws Exception {
  Project project=getProject();
  JavaClass rightEntity=generateEntity(project);
  JavaClass leftEntity=generateEntity(project);
  getShell().execute(ConstraintInspector.getName(FieldPlugin.class) + " manyToOne --named right --fieldType ~." + PersistenceFacetImpl.DEFAULT_ENTITY_PACKAGE+ "."+ rightEntity.getName()+ " --inverseFieldName left");
  leftEntity=(JavaClass)project.getFacet(JavaSourceFacet.class).getJavaResource(leftEntity).getJavaSource();
  assertTrue(leftEntity.hasAnnotation(Entity.class));
  assertTrue(leftEntity.hasField("right"));
  assertEquals(rightEntity.getName(),leftEntity.getField("right").getType());
  assertTrue(leftEntity.getField("right").hasAnnotation(ManyToOne.class));
  assertNull(leftEntity.getField("right").getAnnotation(ManyToOne.class).getStringValue("mappedBy"));
  assertTrue(leftEntity.hasImport(rightEntity.getQualifiedName()));
  assertTrue(leftEntity.hasImport(ManyToOne.class));
  assertFalse(leftEntity.hasSyntaxErrors());
  rightEntity=(JavaClass)project.getFacet(JavaSourceFacet.class).getJavaResource(rightEntity).getJavaSource();
  assertTrue(rightEntity.hasField("left"));
  assertEquals("Set",rightEntity.getField("left").getType());
  assertEquals(leftEntity.getQualifiedName(),rightEntity.getField("left").getTypeInspector().getTypeArguments().get(0).getQualifiedName());
  assertTrue(rightEntity.getField("left").hasAnnotation(OneToMany.class));
  assertEquals("right",rightEntity.getField("left").getAnnotation(OneToMany.class).getStringValue("mappedBy"));
  assertEquals("CascadeType.ALL",rightEntity.getField("left").getAnnotation(OneToMany.class).getLiteralValue("cascade"));
  assertTrue(rightEntity.hasImport(leftEntity.getQualifiedName()));
  assertTrue(rightEntity.hasImport(OneToMany.class));
  assertFalse(rightEntity.hasSyntaxErrors());
}
 

Example 6

From project Core_2, under directory /scaffold-faces/src/main/java/org/jboss/forge/scaffold/faces/metawidget/inspector/.

Source file: ForgeInspector.java

  19 
vote

@Override protected Map<String,String> inspectProperty(Property property) throws Exception {
  Map<String,String> attributes=CollectionUtils.newHashMap();
  if (property.isAnnotationPresent(OneToOne.class) || property.isAnnotationPresent(Embedded.class)) {
    attributes.put(ONE_TO_ONE,TRUE);
  }
  if (property.isAnnotationPresent(ManyToOne.class)) {
    attributes.put(FACES_LOOKUP,StaticFacesUtils.wrapExpression(StringUtils.decapitalize(ClassUtils.getSimpleName(property.getType())) + "Bean.all"));
    attributes.put(FACES_CONVERTER_ID,StaticFacesUtils.wrapExpression(StringUtils.decapitalize(ClassUtils.getSimpleName(property.getType())) + "Bean.converter"));
    for (    Property reverseProperty : getProperties(property.getType()).values()) {
      if (reverseProperty.isAnnotationPresent(Id.class)) {
        attributes.put(REVERSE_PRIMARY_KEY,reverseProperty.getName());
        break;
      }
    }
  }
  if (property.isAnnotationPresent(OneToMany.class) || property.isAnnotationPresent(ManyToMany.class)) {
    attributes.put(N_TO_MANY,TRUE);
  }
  if (property instanceof ForgeProperty) {
    List<EnumConstant<JavaEnum>> enumConstants=((ForgeProperty)property).getEnumConstants();
    if (enumConstants != null) {
      List<String> lookup=CollectionUtils.newArrayList();
      for (      EnumConstant<JavaEnum> anEnum : enumConstants) {
        lookup.add(anEnum.getName());
      }
      attributes.put(LOOKUP,CollectionUtils.toString(lookup));
    }
  }
  if (property.isAnnotationPresent(Id.class)) {
    attributes.put(PRIMARY_KEY,TRUE);
  }
  return attributes;
}
 

Example 7

From project Core_2, under directory /scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/.

Source file: PrimaryKeyFacesScaffoldTest.java

  19 
vote

@SuppressWarnings("unchecked") private void generateLegacyEntities(Project project) throws FileNotFoundException {
  JavaSourceFacet java=project.getFacet(JavaSourceFacet.class);
  JavaClass javaClass=JavaParser.create(JavaClass.class).setPackage("com.test.model").setName("State").setPublic().addAnnotation(Entity.class).getOrigin().addInterface(Serializable.class);
  String idName="stateId";
  Field<JavaClass> id=javaClass.addField("private String " + idName + " = null;");
  id.addAnnotation(Id.class);
  id.addAnnotation(GeneratedValue.class).setEnumValue("strategy",GenerationType.AUTO);
  Refactory.createGetterAndSetter(javaClass,id);
  Refactory.createToStringFromFields(javaClass,id);
  Refactory.createHashCodeAndEquals(javaClass);
  java.saveJavaSource(javaClass);
  javaClass=JavaParser.create(JavaClass.class).setPackage("com.test.model").setName("Parent").setPublic().addAnnotation(Entity.class).getOrigin().addInterface(Serializable.class);
  idName="parentId";
  id=javaClass.addField("private String " + idName + " = null;");
  id.addAnnotation(Id.class);
  id.addAnnotation(GeneratedValue.class).setEnumValue("strategy",GenerationType.AUTO);
  id.addAnnotation(Column.class).setStringValue("name",idName).setLiteralValue("updatable","false").setLiteralValue("nullable","false");
  Refactory.createGetterAndSetter(javaClass,id);
  Field<JavaClass> name=javaClass.addField("private String name = null;");
  name.addAnnotation(Column.class).setLiteralValue("nullable","false");
  Refactory.createGetterAndSetter(javaClass,name);
  Field<JavaClass> state=javaClass.addField("private State state = null;");
  state.addAnnotation(ManyToOne.class).setLiteralValue("optional","false");
  Refactory.createGetterAndSetter(javaClass,state);
  Refactory.createToStringFromFields(javaClass,id);
  Refactory.createHashCodeAndEquals(javaClass);
  java.saveJavaSource(javaClass);
}
 

Example 8

From project Empire, under directory /core/src/com/clarkparsia/empire/util/.

Source file: BeanReflectUtil.java

  19 
vote

/** 
 * Return whether or not the accessor is marked with a  {@link FetchType#LAZY} annotation.  If there is no{@link OneToOne},  {@link OneToMany},  {@link ManyToOne},  {@link OneToOne}, or  {@link ManyToMany} annotation,or they do not specify a fetch type, the default value is assumed to be  {@link FetchType#EAGER}.  If the provided accessor is not a Field or Method, the FetchType is also assumed to be EAGER.
 * @param theAccessor the accessor
 * @return true if the accessor is marked with {@link FetchType#LAZY}, false otherwise.
 */
public static boolean isFetchTypeLazy(Object theAccessor){
  FetchType aFetchType=null;
  if (theAccessor instanceof AccessibleObject) {
    AccessibleObject aObject=(AccessibleObject)theAccessor;
    if (aObject.getAnnotation(OneToMany.class) != null) {
      aFetchType=aObject.getAnnotation(OneToMany.class).fetch();
    }
 else     if (aObject.getAnnotation(OneToOne.class) != null) {
      aFetchType=aObject.getAnnotation(OneToOne.class).fetch();
    }
 else     if (aObject.getAnnotation(ManyToOne.class) != null) {
      aFetchType=aObject.getAnnotation(ManyToOne.class).fetch();
    }
 else     if (aObject.getAnnotation(ManyToMany.class) != null) {
      aFetchType=aObject.getAnnotation(ManyToMany.class).fetch();
    }
  }
  if (aFetchType == null) {
    aFetchType=FetchType.EAGER;
  }
  return aFetchType.equals(FetchType.LAZY);
}
 

Example 9

From project Empire, under directory /core/src/com/clarkparsia/empire/util/.

Source file: BeanReflectUtil.java

  19 
vote

/** 
 * Return the value of the targetEntity for the accessor if it has a  {@link OneToOne},  {@link OneToMany}, {@link ManyToOne},  {@link OneToOne}, or  {@link ManyToMany} annotation.  This will return null if the accessoris not an  {@link AccessibleObject} or if it does not have one of the aforementioned annotations, or if thetargetEntity is not set for the annotation
 * @param theAccessor the accessor
 * @return the targetEntity for the accessor, or null if not specified.
 */
public static Class<?> getTargetEntity(Object theAccessor){
  Class<?> aClass=null;
  if (theAccessor instanceof AccessibleObject) {
    AccessibleObject aObject=(AccessibleObject)theAccessor;
    if (aObject.getAnnotation(OneToMany.class) != null) {
      aClass=aObject.getAnnotation(OneToMany.class).targetEntity();
    }
 else     if (aObject.getAnnotation(OneToOne.class) != null) {
      aClass=aObject.getAnnotation(OneToOne.class).targetEntity();
    }
 else     if (aObject.getAnnotation(ManyToOne.class) != null) {
      aClass=aObject.getAnnotation(ManyToOne.class).targetEntity();
    }
 else     if (aObject.getAnnotation(ManyToMany.class) != null) {
      aClass=aObject.getAnnotation(ManyToMany.class).targetEntity();
    }
  }
  return aClass;
}
 

Example 10

From project Empire, under directory /core/src/com/clarkparsia/empire/util/.

Source file: BeanReflectUtil.java

  19 
vote

/** 
 * Return all  {@link CascadeType CascadeTypes} specified for the provided accessor.  If the access is not a Fieldor Method, or if it does not have any of the value multiplicity annotations ( {@link OneToOne},  {@link OneToMany}, {@link ManyToOne},  {@link OneToOne}, or  {@link ManyToMany}) this will return false, otherwise it will collect the values of the casade property of any of the aforementioned annotations used on the accessor.
 * @param theAccessor the accessor to inspect
 * @return the collection of CascadeTypes specified, or an empty list if none is specified.
 */
private static Collection<CascadeType> getCascadeTypes(Object theAccessor){
  Collection<CascadeType> aCascade=new HashSet<CascadeType>();
  if (theAccessor instanceof AccessibleObject) {
    AccessibleObject aObject=(AccessibleObject)theAccessor;
    if (aObject.getAnnotation(OneToMany.class) != null) {
      aCascade.addAll(Arrays.asList(aObject.getAnnotation(OneToMany.class).cascade()));
    }
 else     if (aObject.getAnnotation(OneToOne.class) != null) {
      aCascade.addAll(Arrays.asList(aObject.getAnnotation(OneToOne.class).cascade()));
    }
 else     if (aObject.getAnnotation(ManyToOne.class) != null) {
      aCascade.addAll(Arrays.asList(aObject.getAnnotation(ManyToOne.class).cascade()));
    }
 else     if (aObject.getAnnotation(ManyToMany.class) != null) {
      aCascade.addAll(Arrays.asList(aObject.getAnnotation(ManyToMany.class).cascade()));
    }
  }
  return aCascade;
}
 

Example 11

From project grails-data-mapping, under directory /grails-datastore-gorm-jpa/src/main/groovy/org/grails/datastore/gorm/jpa/.

Source file: GormToJpaTransform.java

  19 
vote

static void handleToOne(ClassNode classNode,Map<String,ClassNode> belongsToMap,String propertyName){
  ClassNode associatedClass=belongsToMap.get(propertyName);
  final Map<String,ClassNode> inverseHasManyMap=lookupStringToClassNodeMap(associatedClass,GrailsDomainClassProperty.HAS_MANY);
  final Map<String,ClassNode> inverseHasOneMap=lookupStringToClassNodeMap(associatedClass,GrailsDomainClassProperty.HAS_ONE);
  if (inverseHasManyMap.containsValue(classNode)) {
    for (    String inversePropertyName : inverseHasManyMap.keySet()) {
      if (classNode.equals(inverseHasManyMap.get(inversePropertyName))) {
        final AnnotationNode manyToOneAnnotation=new AnnotationNode(new ClassNode(ManyToOne.class));
        manyToOneAnnotation.addMember("cascade",EXPR_CASCADE_PERSIST);
        annotateProperty(classNode,propertyName,manyToOneAnnotation);
      }
    }
  }
 else   if (inverseHasOneMap.containsValue(classNode)) {
    for (    String inversePropertyName : inverseHasOneMap.keySet()) {
      if (classNode.equals(inverseHasOneMap.get(inversePropertyName))) {
        final AnnotationNode oneToOneAnnotation=new AnnotationNode(new ClassNode(OneToOne.class));
        oneToOneAnnotation.addMember("mappedBy",new ConstantExpression(inversePropertyName));
        annotateProperty(classNode,propertyName,oneToOneAnnotation);
      }
    }
  }
 else {
    AnnotationNode annotationNode=new AnnotationNode(new ClassNode(ManyToOne.class));
    annotationNode.addMember("cascade",EXPR_CASCADE_ALL);
    annotateProperty(classNode,propertyName,annotationNode);
  }
}
 

Example 12

From project mob, under directory /com.netappsid.mob/src/com/netappsid/mob/ejb3/tools/.

Source file: JPAHelper.java

  19 
vote

/** 
 * @param toInspect
 * @param entitiesClass
 * @throws IntrospectionException
 */
private static void visitProperties(Class<?> toInspect,Set<Class<?>> entitiesClass) throws IntrospectionException {
  BeanInfo beanInfo=Introspector.getBeanInfo(toInspect);
  PropertyDescriptor[] propertyDescriptors=beanInfo.getPropertyDescriptors();
  for (  PropertyDescriptor propertyDescriptor : propertyDescriptors) {
    Method readMethod=propertyDescriptor.getReadMethod();
    if (readMethod == null) {
      continue;
    }
    if (readMethod.isAnnotationPresent(OneToMany.class) || readMethod.isAnnotationPresent(OneToOne.class) || readMethod.isAnnotationPresent(ManyToMany.class)|| readMethod.isAnnotationPresent(ManyToOne.class)) {
      Class<?> propertyType=propertyDescriptor.getPropertyType();
      if (propertyType.isAnnotationPresent(Entity.class) && !entitiesClass.contains(propertyType)) {
        entitiesClass.add(propertyType);
        recurseSuperClass(propertyType,entitiesClass);
        visitProperties(propertyType,entitiesClass);
      }
 else       if (Collection.class.isAssignableFrom(propertyType)) {
        Class<?> entity=(Class<?>)((ParameterizedType)propertyDescriptor.getReadMethod().getGenericReturnType()).getActualTypeArguments()[0];
        if (entity.isAnnotationPresent(Entity.class) && !entitiesClass.contains(entity)) {
          entitiesClass.add(entity);
          recurseSuperClass(entity,entitiesClass);
          visitProperties(entity,entitiesClass);
        }
      }
 else       if (Map.class.isAssignableFrom(propertyType)) {
        Class<?> entity=(Class<?>)((ParameterizedType)propertyDescriptor.getReadMethod().getGenericReturnType()).getActualTypeArguments()[1];
        if (entity.isAnnotationPresent(Entity.class) && !entitiesClass.contains(entity)) {
          entitiesClass.add(entity);
          recurseSuperClass(entity,entitiesClass);
          visitProperties(entity,entitiesClass);
        }
      }
    }
  }
}
 

Example 13

From project plugin-spring-mvc, under directory /src/main/java/org/jboss/forge/scaffold/spring/metawidget/inspector/.

Source file: ForgeInspector.java

  19 
vote

@Override protected Map<String,String> inspectProperty(Property property) throws Exception {
  Map<String,String> attributes=CollectionUtils.newHashMap();
  if (property.isAnnotationPresent(OneToOne.class) || property.isAnnotationPresent(Embedded.class)) {
    attributes.put(ONE_TO_ONE,TRUE);
  }
  if (property.isAnnotationPresent(ManyToOne.class)) {
    attributes.put(SPRING_LOOKUP,StaticFacesUtils.wrapExpression(StringUtils.decapitalize(ClassUtils.getSimpleName(property.getType()))));
    for (    Property reverseProperty : getProperties(property.getType()).values()) {
      if (reverseProperty.isAnnotationPresent(Id.class)) {
        attributes.put(REVERSE_PRIMARY_KEY,reverseProperty.getName());
        break;
      }
    }
  }
  if (property.isAnnotationPresent(OneToMany.class) || property.isAnnotationPresent(ManyToMany.class)) {
    attributes.put(N_TO_MANY,TRUE);
  }
  if (property instanceof ForgeProperty) {
    List<EnumConstant<JavaEnum>> enumConstants=((ForgeProperty)property).getEnumConstants();
    if (enumConstants != null) {
      List<String> lookup=CollectionUtils.newArrayList();
      for (      EnumConstant<JavaEnum> anEnum : enumConstants) {
        lookup.add(anEnum.getName());
      }
      attributes.put(LOOKUP,CollectionUtils.toString(lookup));
    }
  }
  if (property.isAnnotationPresent(Id.class)) {
    attributes.put(PRIMARY_KEY,TRUE);
  }
  return attributes;
}
 

Example 14

From project plugin-spring-mvc, under directory /src/main/java/org/jboss/forge/scaffold/spring/.

Source file: SpringScaffold.java

  19 
vote

protected Map<Object,Object> findEntityRelationships(JavaClass entity,Map<Object,Object> context) throws FileNotFoundException {
  List<String> entityNames=new ArrayList<String>();
  List<String> entityClasses=new ArrayList<String>();
  List<String> ccEntityClasses=new ArrayList<String>();
  List<String> nToMany=new ArrayList<String>();
  for (  Field<?> field : entity.getFields()) {
    if (field.hasAnnotation(OneToOne.class) || field.hasAnnotation(OneToMany.class) || field.hasAnnotation(ManyToOne.class)|| field.hasAnnotation(ManyToMany.class)) {
      String name=field.getName();
      entityNames.add(name);
      String clazz=new String();
      if (field.hasAnnotation(OneToMany.class) || field.hasAnnotation(ManyToMany.class)) {
        clazz=field.getStringInitializer();
        int firstIndexOf=clazz.indexOf("<");
        int lastIndexOf=clazz.indexOf(">");
        clazz=clazz.substring(firstIndexOf + 1,lastIndexOf);
        String domainPackage=findDomainPackage(clazz,entity);
        nToMany.add(clazz);
        createConverter(clazz,domainPackage);
      }
 else {
        clazz=field.getType();
      }
      entityClasses.add(clazz);
      String ccEntity=StringUtils.camelCase(clazz);
      ccEntityClasses.add(ccEntity);
    }
  }
  context.put("entityNames",entityNames);
  context.put("entityClasses",entityClasses);
  context.put("ccEntityClasses",ccEntityClasses);
  if (!nToMany.isEmpty()) {
    context.put("nToMany",nToMany);
    addConverters(context);
    addConversionService();
  }
  return context;
}
 

Example 15

From project riot, under directory /content/src/org/riotfamily/components/model/.

Source file: ContentContainer.java

  19 
vote

@ManyToOne(fetch=FetchType.LAZY,cascade=CascadeType.ALL) @JoinColumn(name="preview_version") public Content getPreviewVersion(){
  if (previewVersion == null) {
    previewVersion=new Content(this);
  }
  return previewVersion;
}
 

Example 16

From project riot, under directory /content/src/org/riotfamily/components/model/.

Source file: ContentEntity.java

  19 
vote

@ManyToOne(cascade=CascadeType.ALL) public ContentContainer getContentContainer(){
  if (contentContainer == null) {
    contentContainer=new ContentContainer(this);
  }
  return contentContainer;
}
 

Example 17

From project riot, under directory /content/src/org/riotfamily/pages/model/.

Source file: Site.java

  19 
vote

@ManyToOne(fetch=FetchType.LAZY,cascade=CascadeType.ALL) public Content getProperties(){
  if (properties == null) {
    properties=new Content();
  }
  return properties;
}
 

Example 18

From project scaffold-aerogear, under directory /src/main/java/org/jboss/forge/scaffold/aerogear/metawidget/inspector/.

Source file: ForgeInspector.java

  19 
vote

@Override protected Map<String,String> inspectProperty(Property property) throws Exception {
  Map<String,String> attributes=CollectionUtils.newHashMap();
  if (property.isAnnotationPresent(OneToOne.class) || property.isAnnotationPresent(Embedded.class)) {
    attributes.put(ONE_TO_ONE,TRUE);
  }
  if (property.isAnnotationPresent(ManyToOne.class)) {
    attributes.put(MANY_TO_ONE,TRUE);
  }
  if (property.isAnnotationPresent(OneToMany.class) || property.isAnnotationPresent(ManyToMany.class)) {
    attributes.put(N_TO_MANY,TRUE);
  }
  return attributes;
}
 

Example 19

From project ServiceFramework, under directory /src/net/csdn/jpa/enhancer/.

Source file: ModelClass.java

  19 
vote

private void autoNotMapping(CtClass ctClass,List<String> skipFields){
  CtField[] fields=ctClass.getDeclaredFields();
  for (  CtField ctField : fields) {
    guessNotMappingName(ctField,ManyToOne.class,skipFields);
    guessNotMappingName(ctField,OneToOne.class,skipFields);
  }
}
 

Example 20

From project ticket2rock, under directory /src/main/java/de/ejb3buch/ticket2rock/entity/.

Source file: Konzert.java

  19 
vote

@ManyToOne public Interpret getInterpret(){
  if (interpret == null && tournee != null) {
    return tournee.getInterpret();
  }
 else {
    return interpret;
  }
}