Author: jleroux
Date: Fri Jan 26 15:13:42 2018
New Revision: 1822310
URL: http://svn.apache.org/viewvc?rev=1822310&view=rev
Log:
Fixed: EntitySaxReader mostly-insert (store after create-error) Fix
(OFBIZ-1032)
Karl:
Avoids rollback on create error to be able to store the entity instead
(previous mostly-inserts feature).
Matin:
I think, the data load with "mostly inserts" activated should fail on a
create-failure (what it does indeed already), so I see no need for a working
solution of a fallback store attempt. Consistently the Feature should be
renamed
in the frontend from "mostly inserts" to "only inserts".
Kyra:
Additional trivial refactoring in the patch: I reduced the full qualified
classname of org.xml.sax.SAXException in method signatures to the simple name.
This incorperates the changes that Martin has mentioned above.
The unnecessary call to store() is removed, simplifying the process of creating
and deleting entities. (These changes were already in Martins old patch but had
the wrong format.) This means that the flag "mostly Inserts?" is not accurately
worded since as long as there is only create fail, all operations are rolled
back. So the second patch renames the flag and all appropriate parameters to
"onlyInserts".
jleroux: I made few no functional changes, apart not swallowing an exception
Thanks: Thanks Karl for the 1st patch, Martin to get further, and Kyra to
complete the whole with a final touch and help to quickly test
Modified:
ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java
ofbiz/ofbiz-framework/trunk/framework/webtools/config/WebtoolsUiLabels.xml
ofbiz/ofbiz-framework/trunk/framework/webtools/servicedef/services.xml
ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/WebToolsServices.java
ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImport.ftl
ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportDir.ftl
ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportReaders.ftl
Modified:
ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java?rev=1822310&r1=1822309&r2=1822310&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java
Fri Jan 26 15:13:42 2018
@@ -231,11 +231,11 @@ public class EntitySaxReader extends Def
try {
parser.parse(is, this);
// make sure all of the values to write got written...
- if (! valuesToWrite.isEmpty()) {
+ if (!valuesToWrite.isEmpty()) {
writeValues(valuesToWrite);
valuesToWrite.clear();
}
- if (! valuesToDelete.isEmpty()) {
+ if (!valuesToDelete.isEmpty()) {
delegator.removeAll(valuesToDelete);
valuesToDelete.clear();
}
@@ -269,14 +269,14 @@ public class EntitySaxReader extends Def
private void countValue(boolean skip, boolean exist) {
if (skip) numberSkipped++;
else if (Action.DELETE == currentAction) numberDeleted++;
- else if (Action.CREATE == currentAction || ! exist) numberCreated++;
+ else if (Action.CREATE == currentAction || !exist) numberCreated++;
else if (Action.CREATE_REPLACE == currentAction) numberReplaced++;
else numberUpdated++;
}
// ======== ContentHandler interface implementation ========
- public void characters(char[] values, int offset, int count) throws
org.xml.sax.SAXException {
+ public void characters(char[] values, int offset, int count) throws
SAXException {
if (isParseForTemplate) {
// if null, don't worry about it
if (this.currentNodeForTemplate != null) {
@@ -301,7 +301,7 @@ public class EntitySaxReader extends Def
}
}
- public void endElement(String namespaceURI, String localName, String
fullNameString) throws org.xml.sax.SAXException {
+ public void endElement(String namespaceURI, String localName, String
fullNameString) throws SAXException {
if (Debug.verboseOn()) Debug.logVerbose("endElement: localName=" +
localName + ", fullName=" + fullNameString + ", numberRead=" + numberRead,
module);
if ("entity-engine-xml".equals(fullNameString)) {
return;
@@ -343,13 +343,11 @@ public class EntitySaxReader extends Def
try {
reader.setTransactionTimeout(this.transactionTimeout);
} catch (GenericTransactionException e1) {
- // couldn't set tx timeout, shouldn't be a big deal
+ Debug.logWarning("couldn't set tx timeout, hopefully
shouldn't be a big deal", module);
}
numberRead += reader.parse(s);
- } catch (TemplateException e) {
- throw new SAXException("Error storing value", e);
- } catch (IOException e) {
+ } catch (TemplateException | IOException e) {
throw new SAXException("Error storing value", e);
}
}
@@ -403,7 +401,7 @@ public class EntitySaxReader extends Def
boolean exist = true;
boolean skip = false;
//if verbose on, check if entity exist on database for
count each action
- //It's necessary to check also for specific action CREATE
and DELETE to ensure it's ok
+ //It's necessary to check also for specific action CREATE
and DELETE to ensure it's OK
if (Action.CREATE == currentAction || Action.DELETE ==
currentAction || Debug.verboseOn()) {
GenericHelper helper =
delegator.getEntityHelper(currentValue.getEntityName());
if (currentValue.containsPrimaryKey()) {
@@ -412,27 +410,14 @@ public class EntitySaxReader extends Def
} catch (GenericEntityNotFoundException e) {exist
= false;}
}
if (Action.CREATE == currentAction && exist) { skip =
true; }
- else if (Action.DELETE == currentAction && ! exist) {
skip = true; }
+ else if (Action.DELETE == currentAction && !exist) {
skip = true; }
}
- if (! skip) {
+ if (!skip) {
if (this.useTryInsertMethod && !this.checkDataOnly) {
- if (Action.CREATE == currentAction) {
currentValue.create(); }
- else if (Action.DELETE == currentAction) {
- try {
- currentValue.remove();
- } catch (GenericEntityException e1) {
- String errMsg = "Error deleting value";
- Debug.logError(e1, errMsg, module);
- throw new SAXException(errMsg, e1);
- }
+ if (Action.DELETE == currentAction) {
+ currentValue.remove();
} else {
- // this technique is faster for data sets
where most, if not all, values do not already exist in the database
- try {
- currentValue.create();
- } catch (GenericEntityException e1) {
- // create failed, try a store, if that
fails too we have a real error and the catch outside of this should handle it
- currentValue.store();
- }
+ currentValue.create();
}
} else {
if (Action.DELETE == currentAction) {
@@ -457,7 +442,7 @@ public class EntitySaxReader extends Def
}
currentValue = null;
} catch (GenericEntityException e) {
- String errMsg = "Error storing value";
+ String errMsg = "Error performing action " + currentAction;
Debug.logError(e, errMsg, module);
throw new SAXException(errMsg, e);
}
@@ -469,7 +454,7 @@ public class EntitySaxReader extends Def
this.locator = locator;
}
- public void startElement(String namepsaceURI, String localName, String
fullNameString, Attributes attributes) throws org.xml.sax.SAXException {
+ public void startElement(String namepsaceURI, String localName, String
fullNameString, Attributes attributes) throws SAXException {
if (Debug.verboseOn()) Debug.logVerbose("startElement: localName=" +
localName + ", fullName=" + fullNameString + ", attributes=" + attributes,
module);
if ("entity-engine-xml".equals(fullNameString)) {
// check the maintain-timestamp flag
@@ -548,9 +533,6 @@ public class EntitySaxReader extends Def
try {
currentValue = delegator.makeValue(entityName);
- // TODO: do we really want this? it makes it so none of the
values imported have create/update timestamps set
- // DEJ 10/16/04 I think they should all be stamped, so
commenting this out
- // JAZ 12/10/04 I think it should be specified when creating
the reader
if (this.maintainTxStamps) {
currentValue.setIsFromEntitySync(true);
}
@@ -608,16 +590,16 @@ public class EntitySaxReader extends Def
// ======== ErrorHandler interface implementation ========
- public void error(org.xml.sax.SAXParseException exception) throws
org.xml.sax.SAXException {
+ public void error(org.xml.sax.SAXParseException exception) throws
SAXException {
Debug.logWarning(exception, "Error reading XML on line " +
exception.getLineNumber() + ", column " + exception.getColumnNumber(), module);
}
- public void fatalError(org.xml.sax.SAXParseException exception) throws
org.xml.sax.SAXException {
+ public void fatalError(org.xml.sax.SAXParseException exception) throws
SAXException {
Debug.logError(exception, "Fatal Error reading XML on line " +
exception.getLineNumber() + ", column " + exception.getColumnNumber(), module);
throw new SAXException("Fatal Error reading XML on line " +
exception.getLineNumber() + ", column " + exception.getColumnNumber(),
exception);
}
- public void warning(org.xml.sax.SAXParseException exception) throws
org.xml.sax.SAXException {
+ public void warning(org.xml.sax.SAXParseException exception) throws
SAXException {
Debug.logWarning(exception, "Warning reading XML on line " +
exception.getLineNumber() + ", column " + exception.getColumnNumber(), module);
}
}
Modified:
ofbiz/ofbiz-framework/trunk/framework/webtools/config/WebtoolsUiLabels.xml
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/config/WebtoolsUiLabels.xml?rev=1822310&r1=1822309&r2=1822310&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/webtools/config/WebtoolsUiLabels.xml
(original)
+++ ofbiz/ofbiz-framework/trunk/framework/webtools/config/WebtoolsUiLabels.xml
Fri Jan 26 15:13:42 2018
@@ -3656,6 +3656,11 @@
<value xml:lang="zh">大é¨åæ¯æå
¥ï¼</value>
<value xml:lang="zh-TW">大é¨åæ¯æå
¥ï¼</value>
</property>
+ <property key="WebtoolsOnlyInserts">
+ <value xml:lang="de">Nur Einfügungen?</value>
+ <value xml:lang="en">Only Inserts?</value>
+ <value xml:lang="fr">Seulement des insertions ?</value>
+ </property>
<property key="WebtoolsMyCertificates">
<value xml:lang="de">Meine Zertifikate</value>
<value xml:lang="en">My Certificates</value>
Modified: ofbiz/ofbiz-framework/trunk/framework/webtools/servicedef/services.xml
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/servicedef/services.xml?rev=1822310&r1=1822309&r2=1822310&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/webtools/servicedef/services.xml
(original)
+++ ofbiz/ofbiz-framework/trunk/framework/webtools/servicedef/services.xml Fri
Jan 26 15:13:42 2018
@@ -32,7 +32,7 @@ under the License.
<permission-service service-name="entityMaintPermCheck"
main-action="VIEW"/>
<attribute name="url" type="java.net.URL" mode="IN" optional="true"/>
<attribute name="xmltext" type="String" mode="IN" optional="true"
allow-html="any"/>
- <attribute name="mostlyInserts" type="String" mode="IN"
optional="true"/>
+ <attribute name="onlyInserts" type="String" mode="IN" optional="true"/>
<attribute name="maintainTimeStamps" type="String" mode="IN"
optional="true"/>
<attribute name="txTimeout" type="Integer" mode="IN" optional="true"/>
<attribute name="createDummyFks" type="String" mode="IN"
optional="true"/>
@@ -48,7 +48,7 @@ under the License.
<attribute name="fmfilename" type="String" mode="IN" optional="true"
allow-html="any"/>
<attribute name="fulltext" type="String" mode="IN" optional="true"
allow-html="any"/>
<attribute name="isUrl" type="String" mode="IN" optional="true"/>
- <attribute name="mostlyInserts" type="String" mode="IN"
optional="true"/>
+ <attribute name="onlyInserts" type="String" mode="IN" optional="true"/>
<attribute name="maintainTimeStamps" type="String" mode="IN"
optional="true"/>
<attribute name="createDummyFks" type="String" mode="IN"
optional="true"/>
<attribute name="checkDataOnly" type="String" mode="IN"
optional="true"/>
@@ -61,7 +61,7 @@ under the License.
<description>Imports all entity xml files contained in a
directory</description>
<permission-service service-name="entityMaintPermCheck"
main-action="VIEW"/>
<attribute name="path" type="String" mode="IN" optional="true"/>
- <attribute name="mostlyInserts" type="String" mode="IN"
optional="true"/>
+ <attribute name="onlyInserts" type="String" mode="IN" optional="true"/>
<attribute name="maintainTimeStamps" type="String" mode="IN"
optional="true"/>
<attribute name="createDummyFks" type="String" mode="IN"
optional="true"/>
<attribute name="checkDataOnly" type="String" mode="IN"
optional="true"/>
@@ -78,7 +78,7 @@ under the License.
<attribute name="readers" type="String" mode="IN" optional="true"/>
<attribute name="overrideDelegator" type="String" mode="IN"
optional="true"/>
<attribute name="overrideGroup" type="String" mode="IN"
optional="true"/>
- <attribute name="mostlyInserts" type="String" mode="IN"
optional="true"/>
+ <attribute name="onlyInserts" type="String" mode="IN" optional="true"/>
<attribute name="maintainTimeStamps" type="String" mode="IN"
optional="true"/>
<attribute name="createDummyFks" type="String" mode="IN"
optional="true"/>
<attribute name="checkDataOnly" type="String" mode="IN"
optional="true"/>
Modified:
ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/WebToolsServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/WebToolsServices.java?rev=1822310&r1=1822309&r2=1822310&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/WebToolsServices.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/WebToolsServices.java
Fri Jan 26 15:13:42 2018
@@ -114,7 +114,7 @@ public class WebToolsServices {
String fmfilename = (String)context.get("fmfilename");
String fulltext = (String)context.get("fulltext");
boolean isUrl = (String)context.get("isUrl") != null;
- String mostlyInserts = (String)context.get("mostlyInserts");
+ String onlyInserts = (String)context.get("onlyInserts");
String maintainTimeStamps = (String)context.get("maintainTimeStamps");
String createDummyFks = (String)context.get("createDummyFks");
String checkDataOnly = (String) context.get("checkDataOnly");
@@ -176,7 +176,7 @@ public class WebToolsServices {
// #############################
if (fulltext != null || url != null) {
try {
- Map<String, Object> inputMap = UtilMisc.toMap("mostlyInserts",
mostlyInserts,
+ Map<String, Object> inputMap = UtilMisc.toMap("onlyInserts",
onlyInserts,
"createDummyFks", createDummyFks,
"checkDataOnly", checkDataOnly,
"maintainTimeStamps",
maintainTimeStamps,
@@ -216,7 +216,7 @@ public class WebToolsServices {
List<String> messages = new LinkedList<String>();
String path = (String) context.get("path");
- String mostlyInserts = (String) context.get("mostlyInserts");
+ String onlyInserts = (String) context.get("onlyInserts");
String maintainTimeStamps = (String) context.get("maintainTimeStamps");
String createDummyFks = (String) context.get("createDummyFks");
boolean deleteFiles = (String) context.get("deleteFiles") != null;
@@ -255,7 +255,7 @@ public class WebToolsServices {
lastUnprocessedFilesCount = files.size();
unprocessedFiles = new LinkedList<File>();
for (File f: files) {
- Map<String, Object> parseEntityXmlFileArgs =
UtilMisc.toMap("mostlyInserts", mostlyInserts,
+ Map<String, Object> parseEntityXmlFileArgs =
UtilMisc.toMap("onlyInserts", onlyInserts,
"createDummyFks", createDummyFks,
"checkDataOnly", checkDataOnly,
"maintainTimeStamps", maintainTimeStamps,
@@ -318,7 +318,7 @@ public class WebToolsServices {
String overrideGroup = (String) context.get("overrideGroup");
boolean useDummyFks = "true".equals(context.get("createDummyFks"));
boolean maintainTxs = "true".equals(context.get("maintainTimeStamps"));
- boolean tryInserts = "true".equals(context.get("mostlyInserts"));
+ boolean tryInserts = "true".equals(context.get("onlyInserts"));
boolean checkDataOnly = "true".equals(context.get("checkDataOnly"));
Locale locale = (Locale) context.get("locale");
Integer txTimeoutInt = (Integer) context.get("txTimeout");
@@ -432,7 +432,7 @@ public class WebToolsServices {
if (url == null && xmltext == null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource,
"EntityImportNoXmlFileOrTextSpecified", locale));
}
- boolean mostlyInserts = (String) context.get("mostlyInserts") != null;
+ boolean onlyInserts = (String) context.get("onlyInserts") != null;
boolean maintainTimeStamps = (String)
context.get("maintainTimeStamps") != null;
boolean createDummyFks = (String) context.get("createDummyFks") !=
null;
boolean checkDataOnly = (String) context.get("checkDataOnly") != null;
@@ -446,7 +446,7 @@ public class WebToolsServices {
long rowProcessed = 0;
try {
EntitySaxReader reader = new EntitySaxReader(delegator);
- reader.setUseTryInsertMethod(mostlyInserts);
+ reader.setUseTryInsertMethod(onlyInserts);
reader.setMaintainTxStamps(maintainTimeStamps);
reader.setTransactionTimeout(txTimeout.intValue());
reader.setCreateDummyFks(createDummyFks);
Modified:
ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImport.ftl
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImport.ftl?rev=1822310&r1=1822309&r2=1822310&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImport.ftl
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImport.ftl
Fri Jan 26 15:13:42 2018
@@ -27,7 +27,7 @@ under the License.
${uiLabelMap.WebtoolsAbsoluteFTLFilename}:<br />
<input type="text" size="40" name="fmfilename" value="${fmfilename!}"/><br
/>
<label><input type="checkbox" name="isUrl" <#if
isUrl??>checked="checked"</#if>/>${uiLabelMap.WebtoolsIsURL}</label><br />
- <label><input type="checkbox" name="mostlyInserts" <#if
mostlyInserts??>checked="checked"</#if>/>${uiLabelMap.WebtoolsMostlyInserts}</label><br
/>
+ <label><input type="checkbox" name="onlyInserts" <#if
onlyInserts??>checked="checked"</#if>/>${uiLabelMap.WebtoolsOnlyInserts}</label><br
/>
<label><input type="checkbox" name="maintainTimeStamps" <#if
keepStamps??>checked="checked"</#if>/>${uiLabelMap.WebtoolsMaintainTimestamps}</label><br
/>
<label><input type="checkbox" name="createDummyFks" <#if
createDummyFks??>checked="checked"</#if>/>${uiLabelMap.WebtoolsCreateDummyFks}</label><br
/>
<label><input type="checkbox" name="checkDataOnly" <#if
checkDataOnly??>checked="checked"</#if>/>${uiLabelMap.WebtoolsCheckDataOnly}</label><br
/>
Modified:
ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportDir.ftl
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportDir.ftl?rev=1822310&r1=1822309&r2=1822310&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportDir.ftl
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportDir.ftl
Fri Jan 26 15:13:42 2018
@@ -24,7 +24,7 @@ under the License.
<form method="post" action="<@ofbizUrl>entityImportDir</@ofbizUrl>">
${uiLabelMap.WebtoolsAbsolutePath}:<br />
<input type="text" size="60" name="path" value="${path!}"/><br />
- <label><input type="checkbox" name="mostlyInserts" <#if
mostlyInserts??>checked="checked"</#if>/>${uiLabelMap.WebtoolsMostlyInserts}</label><br
/>
+ <label><input type="checkbox" name="onlyInserts" <#if
onlyInserts??>checked="checked"</#if>/>${uiLabelMap.WebtoolsOnlyInserts}</label><br
/>
<label><input type="checkbox" name="maintainTimeStamps" <#if
keepStamps??>checked="checked"</#if>/>${uiLabelMap.WebtoolsMaintainTimestamps}</label><br
/>
<label><input type="checkbox" name="createDummyFks" <#if
createDummyFks??>checked="checked"</#if>/>${uiLabelMap.WebtoolsCreateDummyFks}</label><br
/>
<label><input type="checkbox" name="deleteFiles" <#if
(deleteFiles??)>checked="checked"</#if>/>${uiLabelMap.WebtoolsDeleteFiles}</label><br
/>
Modified:
ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportReaders.ftl
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportReaders.ftl?rev=1822310&r1=1822309&r2=1822310&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportReaders.ftl
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportReaders.ftl
Fri Jan 26 15:13:42 2018
@@ -23,7 +23,7 @@ under the License.
<form method="post" action="<@ofbizUrl>entityImportReaders</@ofbizUrl>">
Enter Readers (comma separated, no spaces; from entityengine.xml and
ofbiz-component.xml files; common ones include seed,ext,demo):<br />
<input type="text" size="60" name="readers"
value="${readers?default("seed")}"/><br />
- <label><input type="checkbox" name="mostlyInserts" <#if
mostlyInserts??>checked="checked"</#if>
value="true"/>${uiLabelMap.WebtoolsMostlyInserts}</label><br />
+ <label><input type="checkbox" name="onlyInserts" <#if
onlyInserts??>checked="checked"</#if>
value="true"/>${uiLabelMap.WebtoolsOnlyInserts}</label><br />
<label><input type="checkbox" name="maintainTimeStamps" <#if
keepStamps??>checked="checked"</#if>
value="true"/>${uiLabelMap.WebtoolsMaintainTimestamps}</label><br />
<label><input type="checkbox" name="createDummyFks" <#if
createDummyFks??>checked="checked"</#if>
value="true"/>${uiLabelMap.WebtoolsCreateDummyFks}</label><br />
<label><input type="checkbox" name="checkDataOnly" <#if
checkDataOnly??>checked="checked"</#if>
value="true"/>${uiLabelMap.WebtoolsCheckDataOnly}</label>R<br />