You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2009/11/16 22:09:34 UTC
svn commit: r880957 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity:
jdbc/SqlJdbcUtil.java model/ModelFieldType.java
Author: adrianc
Date: Mon Nov 16 21:09:34 2009
New Revision: 880957
URL: http://svn.apache.org/viewvc?rev=880957&view=rev
Log:
Small performance enhancement to the entity engine converter code. If a SQL->Java converter is needed, keep a reference to it in ModelFieldType.
Modified:
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelFieldType.java
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java?rev=880957&r1=880956&r2=880957&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java Mon Nov 16 21:09:34 2009
@@ -511,16 +511,30 @@
}
Class<?> targetClass = mft.getJavaClass();
if (targetClass != null) {
- if (targetClass.equals(sourceObject.getClass())) {
+ Class<?> sourceClass = sourceObject.getClass();
+ if (targetClass.equals(sourceClass)) {
entity.dangerousSetNoCheckButFast(curField, sourceObject);
return;
}
- try {
- Converter<Object, Object> converter = (Converter<Object, Object>) Converters.getConverter(sourceObject.getClass(), targetClass);
- entity.dangerousSetNoCheckButFast(curField, converter.convert(sourceObject));
- return;
- } catch (Exception e) {
- Debug.logError(e, module);
+ Converter<Object, Object> converter = (Converter<Object, Object>) mft.getSqlToJavaConverter();
+ if (converter == null) {
+ if (mft.getSqlClass() == null) {
+ mft.setSqlClass(sourceClass);
+ }
+ try {
+ converter = (Converter<Object, Object>) Converters.getConverter(sourceClass, targetClass);
+ mft.setSqlToJavaConverter(converter);
+ } catch (Exception e) {
+ Debug.logError(e, module);
+ }
+ }
+ if (converter != null) {
+ try {
+ entity.dangerousSetNoCheckButFast(curField, converter.convert(sourceObject));
+ return;
+ } catch (Exception e) {
+ Debug.logError(e, module);
+ }
}
Debug.logInfo("Unable to convert, falling back on switch statement", module);
}
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelFieldType.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelFieldType.java?rev=880957&r1=880956&r2=880957&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelFieldType.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelFieldType.java Mon Nov 16 21:09:34 2009
@@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.List;
+import org.ofbiz.base.conversion.Converter;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.UtilXml;
@@ -56,6 +57,8 @@
/** The sql-type-alias of the Field, this is optional */
protected String sqlTypeAlias = null;
+
+ protected Converter<?, ?> sqlToJavaConverter = null;
/** validators to be called when an update is done */
protected List<ModelFieldValidator> validators = new ArrayList<ModelFieldValidator>();
@@ -104,11 +107,6 @@
return this.javaClass;
}
- /** The sql-type of the Field */
- public String getSqlType() {
- return this.sqlType;
- }
-
/** Returns the SQL <code>Class</code> of the Field. The returned value might
* be <code>null</code>. The SQL class is unknown until a connection is made
* to the database. */
@@ -116,6 +114,18 @@
return this.sqlClass;
}
+ /** Returns the SQL-object-type to Java-object-type <code>Converter</code> for
+ * the Field. The returned value might be <code>null</code>. The converter
+ * type is unknown until a connection is made to the database. */
+ public Converter<?, ?> getSqlToJavaConverter() {
+ return this.sqlToJavaConverter;
+ }
+
+ /** The sql-type of the Field */
+ public String getSqlType() {
+ return this.sqlType;
+ }
+
/** The sql-type-alias of the Field */
public String getSqlTypeAlias() {
return this.sqlTypeAlias;
@@ -134,6 +144,13 @@
this.sqlClass = sqlClass;
}
+ /** Sets the SQL-object-type to Java-object-type <code>Converter</code> for
+ * the Field.
+ */
+ public synchronized void setSqlToJavaConverter(Converter<?, ?> converter) {
+ this.sqlToJavaConverter = converter;
+ }
+
/** A simple function to derive the max length of a String created from the field value, based on the sql-type
* @return max length of a String representing the Field value
*/