![JAR search and dependency download from the Maven repository](/logo.png)
com.viaoa.object.OAObjectSaveDelegate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of oa-core Show documentation
Show all versions of oa-core Show documentation
Object Automation library
/* 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.*;
import java.util.logging.*;
import com.viaoa.hub.*;
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.add(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
© 2015 - 2025 Weber Informatics LLC | Privacy Policy