テリー、アーキテクチャを再訪する必要があります。更新が送信時に処理されている場合、ティムがうまく指摘したように、なぜそれらをサーバーに個別に送信することを気にするのですか。私がすること:
- 2つのJavaクラスを作成する:1つの「Order」1つの「LineItem」
- 注文クラスにマップインターフェイスマップを実装します
- リピートコントロールには注文クラスを使用します(各ラインタイムのキーが繰り返し変数として表示されます)
- リピート内のフィールドをバインドして[Repeatkey] .FieldNameを注文します
- オブジェクトデータソースで注文を使用します
- Orderクラスに保存メソッドを実装し、オブジェクトデータソースの保存メソッドに呼び出します
非常に際立っているアウトライン、あなたが私に詳しく説明する必要があるかどうか教えてください。 Javaコレクションフレームワークはあなたの友達です。
見た目よりも簡単です:
public class LineItem {
private String unid;
private String partno;
private int quantity;
private long unitprice;
/**
* Constructor for new items
*/
public LineItem() {
this.unid = null;
}
/**
* Constructor for existing items
*/
public LineItem(Document doc) {
this.unid = doc.getUniversalId();
// more here
}
/**
* @return the unid
*/
public String getUnid() {
return this.unid;
}
/**
* @return the partno
*/
public String getPartno() {
return this.partno;
}
/**
* @param partno the partno to set
*/
public void setPartno(String partno) {
this.partno = partno;
}
/**
* @return the quantity
*/
public int getQuantity() {
return this.quantity;
}
/**
* @param quantity the quantity to set
*/
public void setQuantity(int quantity) {
this.quantity = quantity;
}
/**
* @return the unitprice
*/
public long getUnitprice() {
return this.unitprice;
}
/**
* @param unitprice the unitprice to set
*/
public void setUnitprice(long unitprice) {
this.unitprice = unitprice;
}
public void save(Database db) {
Document doc = null;
if (this.unid == null) {
doc = db.createDocument();
doc.replaceItem("Form", "LineItem");
}
doc.replaceItem("PartNo", this.partno);
// More here
doc.save();
}
}
そして、注文のために - ドキュメントコレクションからロードすると仮定します。
public class Order implements Map<String, LineItem> {
// You might want to have a stack here to keep order
private final Map<String, LineItem> backingMap = new LinkedHashMap<String, LineItem>();
private final Set<String> deletedItemKeys = new HashSet<String>();
// The key we use for new items when unid is null
private int lastNewItemNumber = 0;
@Override
public int size() {
return this.backingMap.size();
}
@Override
public boolean isEmpty() {
return this.backingMap.isEmpty();
}
@Override
public boolean containsKey(Object key) {
return this.backingMap.containsKey(key);
}
@Override
public boolean containsValue(Object value) {
return this.backingMap.containsValue(value);
}
@Override
public LineItem get(Object key) {
return this.backingMap.get(key);
}
@Override
public LineItem put(String key, LineItem value) {
// Here it gets a little special
// We need to prevent null keys
if (key == null) {
key = String.valueOf(this.lastNewItemNumber);
lastNewItemNumber++;
}
this.deletedItemKeys.remove(key);
return this.backingMap.put(key, value);
}
@Override
public LineItem remove(Object key) {
this.deletedItemKeys.add(key.toString());
return this.backingMap.remove(key);
}
@Override
public void putAll(Map<? extends String, ? extends LineItem> m) {
for (Map.Entry<? extends String, ? extends LineItem> me : m.entrySet()) {
this.put(me.getKey(), me.getValue());
}
}
@Override
public void clear() {
this.deletedItemKeys.addAll(this.backingMap.keySet());
this.backingMap.clear();
}
@Override
public Set<String> keySet() {
return this.backingMap.keySet();
}
@Override
public Collection<LineItem> values() {
return this.backingMap.values();
}
@Override
public Set<java.util.Map.Entry<String, LineItem>> entrySet() {
return this.backingMap.entrySet();
}
public void load(NotesDocumentCollection dc) throws NotesException {
Document doc = dc.getFirstDocument();
Document nextDoc;
while (doc != null) {
nextDoc = dc.getNextDocument(doc);
LineItem li = new LineItem(doc);
this.put(doc.getUniversalId(), li);
doc.recycle();
doc = nextDoc;
}
doc.recyle();
}
public void save(Database db) {
for (LineItem item : this.backingMap.values()) {
item.save(db);
}
// Now kill the left overs - needs error handling
for (String morituri : this.deletedItemKeys) {
Document delDoc = db.getDocumentByUnid(morituri);
if (delDoc != null) {
delDoc.remove(true);
}
}
}
}