Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/* Copyright 1999 Vince Via [email protected]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.viaoa.object;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.viaoa.hub.Hub;
import com.viaoa.hub.HubEventDelegate;
public class OAObjectSaveDelegate {
private static Logger LOG = Logger.getLogger(OAObjectSaveDelegate.class.getName());
protected static void save(OAObject oaObj, int iCascadeRule) {
if (oaObj == null) {
return;
}
if (OAObjectCSDelegate.isWorkstation(oaObj)) {
OAObjectCSDelegate.save(oaObj, iCascadeRule);
return;
}
OACascade cascade = new OACascade();
save(oaObj, iCascadeRule, cascade, true, true);
}
public static void save(OAObject oaObj, int iCascadeRule, OACascade cascade) {
save(oaObj, iCascadeRule, cascade, false, true);
}
private static void save(OAObject oaObj, int iCascadeRule, OACascade cascade, boolean bIsFirst, boolean bCheckDepth) {
if (bCheckDepth && cascade.getDepth() > 50) {
if (!cascade.wasCascaded(oaObj, false)) {
cascade.addToOverflow(oaObj); // add to overflow, (tail recursion)
}
return;
}
if (OAThreadLocalDelegate.isDeleting(oaObj)) {
return;
}
if (cascade.wasCascaded(oaObj, true)) {
return;
}
cascade.depthAdd();
boolean b = (oaObj.newFlag || oaObj.changedFlag || bIsFirst);
OAObjectSaveDelegate._save(oaObj, true, iCascadeRule, cascade); // "ONE" relationships
// cascadeSave() will check hash to see if object has already been checked
if (b) {
Hub[] hubs = OAObjectHubDelegate.getHubReferences(oaObj);
if (hubs != null) {
for (Hub h : hubs) {
if (h != null) {
HubEventDelegate.fireBeforeSaveEvent(h, oaObj);
}
}
}
for (int i = 0; i < 4; i++) {
try {
if (OAObjectSaveDelegate.onSave(oaObj)) {
if (i > 0) {
String msg = "Retry save successful, class=" + oaObj.getClass().getSimpleName() + ", key="
+ oaObj.getObjectKey() + ", try=" + (i + 1);
LOG.log(Level.WARNING, msg);
}
break;
}
} catch (Exception e) {
String msg = "error saving, class=" + oaObj.getClass().getSimpleName() + ", key=" + oaObj.getObjectKey() + ", isNew="
+ oaObj.isNew() + ", try=" + (i + 1) + " of 4";
if (i == 3) {
msg += " ALERT: possible data loss";
}
LOG.log(Level.WARNING, msg, e);
oaObj.setChanged(true);
OAObjectSaveDelegate._save(oaObj, true, iCascadeRule, cascade); // "ONE" relationships
continue;
}
// try again, object might have been changed in the process
String msg = "onSave returned false, class=" + oaObj.getClass().getSimpleName() + ", key=" + oaObj.getObjectKey()
+ ", isNew=" + oaObj.isNew() + ", will try again the next time save is called";
LOG.warning(msg);
break;
}
if (hubs != null) {
for (Hub h : hubs) {
if (h != null) {
HubEventDelegate.fireAfterSaveEvent(h, oaObj);
}
}
}
}
OAObjectSaveDelegate._save(oaObj, false, iCascadeRule, cascade); // "MANY" relationships
cascade.depthSubtract();
if (cascade.getDepth() < 1) {
ArrayList