테리, 건축을 다시 방문해야합니다. 제출시 업데이트가 처리되면 Tim이 지적한 것처럼 왜 서버로 개별적으로 보내는가? 내가 할 일 :
- 2 개의 Java 클래스 만들기 : 하나의 "주문"One "Lineitem"
- 주문 클래스가 맵 인터페이스 맵을 구현하도록하십시오
- 반복 제어를 위해 주문 클래스를 사용하십시오 (각 lineitem의 키를 반복 변수로 제공합니다).
- 반복 내부의 필드를 주문하기 위해 묶음 [반복 키] .FieldName
- 객체 데이터 소스에서 순서를 사용하십시오
- 주문 클래스에서 저장 메소드를 구현하고 객체 데이터 소스의 저장 메소드에서 호출하십시오.
매우 정교한 개요, 내가 정교하게 해야하는지 알려주세요. Java Collections 프레임 워크는 친구입니다.
보이는 것보다 쉽습니다.
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);
}
}
}
}