/**
  * Retrieves the fetch mode for the specified instance; otherwise returns the default FetchMode.
  *
  * @param object The object, converted to a string
  * @return The FetchMode
  */
 public static FetchMode getFetchMode(Object object) {
   String name = object != null ? object.toString() : "default";
   if (name.equalsIgnoreCase(FetchMode.JOIN.toString()) || name.equalsIgnoreCase("eager")) {
     return FetchMode.JOIN;
   }
   if (name.equalsIgnoreCase(FetchMode.SELECT.toString()) || name.equalsIgnoreCase("lazy")) {
     return FetchMode.SELECT;
   }
   return FetchMode.DEFAULT;
 }
예제 #2
0
  private Property makeCollectionProperty(
      String propertyName,
      boolean mutable,
      Table table,
      ForeignKey fk,
      Collection value,
      boolean inverseProperty) {
    AssociationInfo fkei =
        inverseProperty
            ? revengStrategy.foreignKeyToInverseAssociationInfo(fk)
            : revengStrategy.foreignKeyToAssociationInfo(fk);

    String fetchMode = null;
    String cascade = null;
    boolean update = mutable;
    boolean insert = mutable;

    if (fkei != null) {
      cascade = fkei.getCascade();
      if (cascade == null)
        cascade =
            "all"; // To ensure collections cascade to be compatible with Seam-gen and previous
                   // behavior.
      if (fkei.getUpdate() != null) {
        update = fkei.getUpdate().booleanValue();
      }
      if (fkei.getInsert() != null) {
        insert = fkei.getInsert().booleanValue();
      }

      fetchMode = fkei.getFetch();
    }

    if (FetchMode.JOIN.toString().equalsIgnoreCase(fetchMode)) {
      value.setFetchMode(FetchMode.JOIN);
    } else if (FetchMode.SELECT.toString().equalsIgnoreCase(fetchMode)) {
      value.setFetchMode(FetchMode.SELECT);
    } else {
      value.setFetchMode(FetchMode.SELECT);
    }

    return makeProperty(
        TableIdentifier.create(table),
        propertyName,
        value,
        insert,
        update,
        value.getFetchMode() != FetchMode.JOIN,
        cascade,
        null);
  }
예제 #3
0
  private Property makeEntityProperty(
      String propertyName,
      boolean mutable,
      Table table,
      ForeignKey fk,
      ToOne value,
      boolean inverseProperty) {
    AssociationInfo fkei =
        inverseProperty
            ? revengStrategy.foreignKeyToInverseAssociationInfo(fk)
            : revengStrategy.foreignKeyToAssociationInfo(fk);

    String fetchMode = null;
    String cascade = null;
    boolean update = mutable;
    boolean insert = mutable;

    if (fkei != null) {
      cascade = fkei.getCascade();
      if (fkei.getUpdate() != null) {
        update = fkei.getUpdate().booleanValue();
      }
      if (fkei.getInsert() != null) {
        insert = fkei.getInsert().booleanValue();
      }

      fetchMode = fkei.getFetch();
    }

    if (FetchMode.JOIN.toString().equalsIgnoreCase(fetchMode)) {
      value.setFetchMode(FetchMode.JOIN);
    } else if (FetchMode.SELECT.toString().equalsIgnoreCase(fetchMode)) {
      value.setFetchMode(FetchMode.SELECT);
    } else {
      value.setFetchMode(FetchMode.SELECT);
    }

    return makeProperty(
        TableIdentifier.create(table),
        propertyName,
        value,
        insert,
        update,
        value.getFetchMode() != FetchMode.JOIN,
        cascade,
        null);
  }