Example #1
0
 public void setValue(RecT rec, ValueT value) throws SQLException {
   doSetValue(rec, value);
   Flow<ValueT> f = rec.getFlow(this);
   if (f != null) {
     f.setValue(value);
   }
 }
Example #2
0
  public void genDirtyFieldDescriptions(RecT rec, Set<String> out) throws SQLException {
    for (Col<RecT, ?> c : cols()) {
      if (c.isVisible() && c.field().isDirty(rec)) {
        String n = String.format("%s.%s", name(), c.name());
        out.add(
            String.format(
                "%s: %s (%s)", rec.cx().t8(n), c.formatValue(rec), c.formatStoredValue(rec)));
      }
    }

    for (Table<RecT>.Ref<?> r : refs()) {
      CoreTable<?> t = (CoreTable<?>) r.refTable();
      if (!t.createEvents(rec.cx())) {
        ((Ref<?>) r).genDirtyFieldDescriptions(rec, out);
      }
    }
  }
Example #3
0
  public Flow<ValueT> valueFlow(final RecT rec) {
    Flow<ValueT> f = rec.getFlow(this);

    if (f == null) {
      f =
          new Flow<ValueT>() {
            @Override
            public void setValue(ValueT value, Set<Node> blacklist) {
              try {
                Map<Col<RecT, ?>, Object> valueMap = new HashMap<>();
                for (Col<RecT, ?> c : table.cols()) {
                  if (c != Col.this) {
                    valueMap.put(c, c.getValue(rec));
                  }
                }

                Col.this.setValue(rec, value);

                for (Map.Entry<Col<RecT, ?>, Object> e : valueMap.entrySet()) {
                  Col<RecT, ?> c = e.getKey();
                  Flow<?> f = rec.getFlow(c);
                  if (f != null && !c.equalObjects(valueMap.get(c), c.getValue(rec))) {
                    f.pushValue();
                  }
                }
              } catch (SQLException e) {
                throw new RuntimeException(e);
              }
            }

            @Override
            public ValueT value() {

              try {
                return getValue(rec);
              } catch (SQLException e) {
                throw new RuntimeException(e);
              }
            }
          };
      rec.addFlow(this, f);
    }

    return f;
  }
Example #4
0
  public String genStoreEventDescription(RecT rec) throws SQLException {
    boolean isStored = recIsStored(rec);
    StringBuilder res = new StringBuilder();
    res.append(
        String.format(
            "%s %s.", rec.caption(), isStored ? rec.cx().t8(updated()) : rec.cx().t8(created())));
    if (isStored) {
      Set<String> fieldDescriptions = new TreeSet<>();
      genDirtyFieldDescriptions(rec, fieldDescriptions);

      if (fieldDescriptions.isEmpty()) {
        return null;
      }

      res.append(' ');
      String sep = "";
      for (String s : fieldDescriptions) {
        res.append(sep).append(s);
        sep = ", ";
      }
      res.append('.');
    }
    return res.toString();
  }
Example #5
0
  @Override
  public void deleteRec(final RecT rec) throws SQLException {
    if (createEvents(rec.cx())) {
      rec.cx()
          .execEvent(
              new Event.Procedure<Object>(rec.cx()) {
                @Override
                protected Object onExec() throws SQLException {
                  description = genDeleteEventDescription(rec);
                  doDeleteRec(rec);
                  return null;
                }

                @Override
                protected String getDescription() throws SQLException {
                  return description;
                }

                private String description;
              });
    } else {
      doDeleteRec(rec);
    }
  }
Example #6
0
  @Override
  public RecT storeRec(final RecT rec) throws SQLException {
    if (!rec.isStoring()) {
      rec.setStoring(true);
      try {
        if (createEvents(rec.cx())) {
          rec.cx()
              .execEvent(
                  new Event.Procedure<Object>(rec.cx()) {
                    @Override
                    protected Object onExec() throws SQLException {
                      description = genStoreEventDescription(rec);
                      doStoreRec(rec);
                      return null;
                    }

                    @Override
                    protected String getDescription() throws SQLException {
                      return description;
                    }

                    @Override
                    protected boolean storeEvent() {
                      return description != null;
                    }

                    private String description;
                  });
        } else {
          doStoreRec(rec);
        }
      } finally {
        rec.setStoring(false);
      }
    }
    return rec;
  }
Example #7
0
 public void updateValueFlow(RecT rec) {
   Flow<ValueT> f = rec.getFlow(this);
   if (f != null) {
     f.pushValue();
   }
 }
Example #8
0
 public void loadValue(RecT rec, Query.Result result) throws SQLException {
   field.setValue(rec, loadValue(rec.cx(), result));
 }
Example #9
0
 public void initRec(RecT rec) {
   field.initRec(rec, defaultValue(rec.cx()));
 }
Example #10
0
 public String formatValue(RecT rec) throws SQLException {
   return formatValue(rec.cx(), getValue(rec));
 }
Example #11
0
 public String genDeleteEventDescription(RecT rec, String deleted) throws SQLException {
   return String.format("%s %s.", rec.caption(), rec.cx().t8(deleted));
 }