📄 domainobjectfactory.java
字号:
}else if (fieldClassName.equals("short")){ convertedValue = new Short[1]; short shortValue = 0; shortValue = rs.getShort(columnName); if (rs.wasNull()){ short s = 0; convertedValue[0] = new Short(s); }else{ value = new Short(shortValue); convertedValue[0] = value; } }else if (fieldClassName.equals("java.lang.Boolean")){ convertedValue = new Boolean[1]; boolean booleanValue = false; booleanValue = rs.getBoolean(columnName); if (rs.wasNull()){ convertedValue[0] = new Boolean(false); }else{ value = new Boolean(booleanValue); convertedValue[0] = value; } }else if (fieldClassName.equals("java.lang.Character")){ convertedValue = new Character[1]; String stringValue = null; stringValue = rs.getString(columnName); if (rs.wasNull()){ char emptyChar = '\u0000'; convertedValue[0] = new Character(emptyChar); }else{ value = new Character(stringValue.charAt(0)); convertedValue[0] = value; } }else{ convertedValue = new Object[1]; value = rs.getObject(columnName); convertedValue[0] = value; } if (!isReadOnly()){ originalValues.setFieldNameAndValue(columnIndex, fieldName, value); } if (!isLazyLoading()){ this.metaData.getWriteMethod(columnIndex).invoke(obj, convertedValue); } } } if (!isReadOnly()){ ((DomainObject) obj).setOriginalValues(originalValues); } if (!isLazyLoading()){ ((DomainObject) obj).setLoading(false); ((DomainObject) obj).setLoaded(true); } if (isSynchronizedAccess()){ ((DomainObject) obj).setObjectId(this.getSyncNextObjectId()); }else{ ((DomainObject) obj).setObjectId(this.getNextObjectId()); } ((DomainObject) obj).setSqlStatus(DomainObject.ORIGINAL); this.objectList.add(obj); } }catch (Exception e){ e.printStackTrace(); }finally{ //if (rs != null) rs.close(); } return this.objectList.size(); } /** Getter for property mapping. * @return Value of property mapping. * */ public Map getMapping() { return mapping; } /** Setter for property mapping. * @param mapping New value of property mapping. * */ public void setMapping(Map mapping) { this.mapping = mapping; } /** Getter for property requestor. * @return Value of property requestor. * */ public java.lang.Class getRequestor() { return requestor; } /** Setter for property requestor. * @param requestor New value of property requestor. * */ public void setRequestor(java.lang.Class requestor) { this.requestor = requestor; } public List getPrimaryKey(String catalog, String schema, String table) { return PKCache.getInstance().getPrimaryKey(catalog, schema, table); } public void setPrimaryKey(String catalog, String schema, String table, List pk) { PKCache.getInstance().setPrimaryKey(catalog, schema, table, pk); } public int setObject(DomainObject domainObj){ int idx = -1; int id = domainObj.getObjectId(); if (id == 0){ // new object if (isSynchronizedAccess()){ id = this.getSyncNextObjectId(); domainObj.setObjectId(id); }else{ id = this.getNextObjectId(); domainObj.setObjectId(id); } this.objectList.add(domainObj); idx = this.objectList.size() + 1; }else{ idx = findIdxByObjectId(id); // replace object with new one this.objectList.set(idx - 1, domainObj); } return idx; } public DomainObject findObjectByObjectId(int objectId){ int idx = findIdxByObjectId(objectId); return (DomainObject) this.objectList.get(idx - 1); } /* This is NOT zero based index: idx of the first object is 1, the second is 2, ...*/ public int findIdxByObjectId(int objectId){ int id = 0; int idx = 0; Iterator it = this.objectList.iterator(); while (it.hasNext()){ idx ++; DomainObject domainObject = (DomainObject) it.next(); id = domainObject.getObjectId(); if (objectId == id){ break; } } return idx; } protected synchronized int getSyncNextObjectId() { this.objectId ++; return this.objectId; } protected int getNextObjectId() { this.objectId ++; return this.objectId; } /** Getter for property objectList. * @return Value of property objectList. * */ public List getObjectList() { return objectList; } /** Setter for property objectList. * @param objectList New value of property objectList. * */ public void setObjectList(List objectList) { this.objectList = objectList; } /* Does not delete from DB, just from Object list */ public boolean discard(DomainObject domainObject) { int idx = findIdxByObjectId(domainObject.getObjectId()); if (idx > 0){ this.objectList.remove(idx); return true; } return false; } public boolean remove(DomainObject domainObject) { boolean success = false; int removedIdx = -1; int idx = findIdxByObjectId(domainObject.getObjectId()); if (!beforeRemove(domainObject)){ return false; } if (idx > 0){ if (domainObject.remove()){ this.removedObjects.add(domainObject); removedIdx = this.removedObjects.size() + 1; this.objectList.remove(idx - 1); success = true; } } if (!afterRemove(removedIdx)){ return false; } return success; } public boolean beforeRemove(DomainObject domainObject) { return true; } public boolean afterRemove(int idx){ return true; } public boolean store(DomainObject domainObject) { boolean success = false; int idx = findIdxByObjectId(domainObject.getObjectId()); if (!beforeStore(domainObject, idx)){ return false; } if (idx > 0){ if (domainObject.store()){ this.objectList.set(idx - 1, domainObject); success = true; } } if (!afterStore(idx)){ return false; } return success; } public boolean beforeStore(DomainObject domainObject, int idx){ return true; } public boolean afterStore(int idx){ return true; } public boolean create(DomainObject domainObject) { int idx = -1; boolean success = false; if (!beforeCreate(domainObject)){ return false; } if (domainObject.create()){ idx = this.setObject(domainObject); success = true; } if (!afterCreate(idx)){ return false; } return success; } public boolean beforeCreate(DomainObject domainObject){ return true; } public boolean afterCreate(int idx){ return true; } /** Getter for property removedObjects. * @return Value of property removedObjects. * */ public List getRemovedObjects() { return removedObjects; } /** Setter for property removedObjects. * @param removedObjects New value of property removedObjects. * */ public void setRemovedObjects(List removedObjects) { this.removedObjects = removedObjects; } /** Indexed getter for property dataModificationSequence. * @param index Index of the property. * @return Value of the property at <CODE>index</CODE>. * */ public char getDataModificationSequence(int index) { return this.dataModificationSequence[index]; } /** Getter for property dataModificationSequence. * @return Value of property dataModificationSequence. * */ public char[] getDataModificationSequence() { return this.dataModificationSequence; } /** Setter for property dataModificationSequence. * @param dataModificationSequence New value of property dataModificationSequence. * */ public void setDataModificationSequence(char[] dataModificationSequence) { this.dataModificationSequence = dataModificationSequence; } /** Getter for property discardUnmodifiedObjects. * @return Value of property discardUnmodifiedObjects. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -