Java Code Examples for javax.persistence.FetchType

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 Empire, under directory /core/src/com/clarkparsia/empire/util/.

Source file: BeanReflectUtil.java

  21 
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 2

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

Source file: NativeEntryEntityPersister.java

  19 
vote

private boolean isLazyAssociation(PropertyMapping<Property> associationPropertyMapping){
  if (associationPropertyMapping == null) {
    return true;
  }
  Property kv=associationPropertyMapping.getMappedForm();
  return kv.getFetchStrategy() == FetchType.LAZY;
}
 

Example 3

From project jBilling, under directory /src/java/com/sapienter/jbilling/server/user/contact/db/.

Source file: ContactDTO.java

  19 
vote

@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY,mappedBy="contact") public Set<ContactFieldDTO> getFields(){
  if (fields == null) {
    fields=new HashSet<ContactFieldDTO>(0);
  }
  return this.fields;
}
 

Example 4

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 5

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 6

From project SeavusJB3, under directory /src/java/com/sapienter/jbilling/server/user/contact/db/.

Source file: ContactDTO.java

  19 
vote

@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY,mappedBy="contact") public Set<ContactFieldDTO> getFields(){
  if (fields == null) {
    fields=new HashSet<ContactFieldDTO>(0);
  }
  return this.fields;
}
 

Example 7

From project zanata, under directory /zanata-model/src/main/java/org/zanata/model/.

Source file: HPerson.java

  19 
vote

@ManyToMany(fetch=FetchType.EAGER,mappedBy="maintainers",cascade=CascadeType.ALL) public Set<HProject> getMaintainerProjects(){
  if (maintainerProjects == null) {
    maintainerProjects=new HashSet<HProject>();
  }
  return maintainerProjects;
}
 

Example 8

From project zanata, under directory /zanata-model/src/main/java/org/zanata/model/.

Source file: HPerson.java

  19 
vote

@ManyToMany(fetch=FetchType.EAGER,mappedBy="maintainers",cascade=CascadeType.ALL) public Set<HIterationGroup> getMaintainerVersionGroups(){
  if (maintainerVersionGroups == null) {
    maintainerVersionGroups=new HashSet<HIterationGroup>();
  }
  return maintainerVersionGroups;
}
 

Example 9

From project zanata, under directory /zanata-model/src/main/java/org/zanata/model/.

Source file: HTextFlow.java

  19 
vote

@Override @NotEmpty @Type(type="text") @AccessType("field") @CollectionOfElements(fetch=FetchType.EAGER) @JoinTable(name="HTextFlowContent",[email protected](name="text_flow_id")) @IndexColumn(name="pos",nullable=false) @Column(name="content",nullable=false) public List<String> getContents(){
  copyLazyLoadedRelationsToHistory();
  if (contents == null) {
    contents=new ArrayList<String>();
  }
  return contents;
}
 

Example 10

From project zanata, under directory /zanata-model/src/main/java/org/zanata/model/.

Source file: HTextFlowTarget.java

  19 
vote

@Override @Type(type="text") @AccessType("field") @CollectionOfElements(fetch=FetchType.EAGER) @JoinTable(name="HTextFlowTargetContent",[email protected](name="text_flow_target_id")) @IndexColumn(name="pos",nullable=false) @Column(name="content",nullable=false) @Field(name=IndexFieldLabels.CONTENT,index=Index.TOKENIZED,[email protected](impl=StringListBridge.class,params={@Parameter(name="case",value="fold"),@Parameter(name="ngrams",value="multisize")})) @AnalyzerDiscriminator(impl=TextContainerAnalyzerDiscriminator.class) public List<String> getContents(){
  copyLazyLoadedRelationsToHistory();
  if (contents == null) {
    contents=new ArrayList<String>();
  }
  return contents;
}