@@ -0,0 +1,1131 @@
+package foam.dao;%0A%0Aimport foam.core.FObject;%0Aimport foam.core.Property;%0Aimport foam.core.X;%0A%0A/**%0A * A ProxyDAO that injects a new ID for any item that doesn't already have one.%0A *%0A * TODO(braden): Support arbitrary sequence numbering. In practice it's ID 99%25 of the time.%0A * TODO(braden): Also assumes that the ID is an int.%0A */%0Apublic class SeqNoDAO extends ProxyDAO %7B%0A  private int nextID = -1;%0A%0A  public SeqNoDAO(DAO delegate) %7B%0A    super(delegate);%0A  %7D%0A%0A  private void findMax(X x) throws DAOInternalException, DAOException %7B%0A    MLang.MaxSink sink = (MLang.MaxSink) getDelegate().select(x, MLang.MAX(getModel().getID()));%0A    if (sink != null) %7B%0A      Integer max = (Integer) sink.getMax();%0A      nextID = max == null ? 1 : max.intValue() + 1;%0A    %7D%0A  %7D%0A%0A  public Object put(X x, Object o) throws DAOInternalException, DAOException %7B%0A    // Check if the object has an ID value.%0A    Property%3CInteger%3E ID = getModel().getID();%0A    int id = ID.get(o);%0A    if (id == 0) %7B%0A      if (nextID %3C 0) findMax(x);%0A      o = ((FObject) o).fclone();%0A      ID.set(o, nextID);%0A      nextID++;%0A    %7D%0A%0A    return getDelegate().put(x, o);%0A  %7D%0A%7D%0A

Add SeqNoDAO. Basic so far, always ID, always int.