summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntje Fuhrmann2012-11-12 03:22:38 (EST)
committerSven Rottstock2012-11-12 03:22:38 (EST)
commitf260aca277776793a411d0912f6e30215e3655b9 (patch)
tree5ec1a5bb1a5c180be8202577764a69af8c27dedf
parent4629f28a35f83a4307b45d92793c5d33fc71c26a (diff)
downloadorg.eclipse.stardust.engine-f260aca277776793a411d0912f6e30215e3655b9.zip
org.eclipse.stardust.engine-f260aca277776793a411d0912f6e30215e3655b9.tar.gz
org.eclipse.stardust.engine-f260aca277776793a411d0912f6e30215e3655b9.tar.bz2
Jira-ID: CRNT-26771
Data type error occurred after starting a process git-svn-id: http://emeafrazerg/svn/ipp/product/trunk/stardust/engine@60749 8100b5e0-4d52-466c-ae9c-bdeccbdeaf6b
-rw-r--r--stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/persistence/jdbc/DBDescriptor.java6
-rw-r--r--stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/persistence/jdbc/DmlManager.java27
-rw-r--r--stardust-engine-core/src/test/java/org/eclipse/stardust/engine/core/persistence/jdbc/DmlManagerTest.java71
3 files changed, 104 insertions, 0 deletions
diff --git a/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/persistence/jdbc/DBDescriptor.java b/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/persistence/jdbc/DBDescriptor.java
index 58f5986..5cac26f 100644
--- a/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/persistence/jdbc/DBDescriptor.java
+++ b/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/persistence/jdbc/DBDescriptor.java
@@ -43,6 +43,7 @@ public abstract class DBDescriptor
// Float.MIN_VALUE is NOT negative, use negative MAX_VALUE as lower border
private static final Pair FLOAT_VALUE_RANGE = new Pair(-Float.MAX_VALUE, Float.MAX_VALUE);
private static final Pair DOUBLE_VALUE_RANGE = new Pair( -1.0e+125, 1.0e+125);
+ private static final Pair EPSILON_DOUBLE_VALUE_RANGE = new Pair(-2.225E-307, 2.225E-307);
private static final String DBDESCRIPTOR_PREFIX = "org.eclipse.stardust.engine.core.persistence.jdbc.dbdescriptor.";
@@ -354,6 +355,11 @@ public abstract class DBDescriptor
* Maps Java field types to valid SQL column types.
*/
public abstract String getSQLType(Class type, long length);
+
+ public <E> Pair<E, E> getNumericSQLTypeEpsilonBorders(Class<E> type)
+ {
+ return EPSILON_DOUBLE_VALUE_RANGE;
+ }
//public static <E> TreeSet<E> copySet(TreeSet<? extends E> rhs)
public <E> Pair< E, E> getNumericSQLTypeValueBorders(
diff --git a/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/persistence/jdbc/DmlManager.java b/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/persistence/jdbc/DmlManager.java
index 048e37e..80d8b97 100644
--- a/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/persistence/jdbc/DmlManager.java
+++ b/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/persistence/jdbc/DmlManager.java
@@ -154,6 +154,19 @@ public class DmlManager
{
doubleValue = valueBorders.getSecond();
}
+ else
+ {
+ Pair<Double, Double> valueEpsilonBorders = dbDescriptor
+ .getNumericSQLTypeEpsilonBorders(Double.class);
+ if (doubleValue > valueEpsilonBorders.getFirst() && doubleValue < 0)
+ {
+ doubleValue = 0.0;
+ }
+ else if (doubleValue < valueEpsilonBorders.getSecond() && doubleValue > 0)
+ {
+ doubleValue = 0.0;
+ }
+ }
return doubleValue.toString();
}
@@ -286,6 +299,20 @@ public class DmlManager
{
doubleValue = valueBorders.getSecond();
}
+ else
+ {
+ Pair<Double, Double> valueEpsilonBorders = dbDescriptor
+ .getNumericSQLTypeEpsilonBorders(Double.class);
+ if (doubleValue > valueEpsilonBorders.getFirst() && doubleValue < 0)
+ {
+ doubleValue = 0.0;
+ }
+ else if (doubleValue < valueEpsilonBorders.getSecond()
+ && doubleValue > 0)
+ {
+ doubleValue = 0.0;
+ }
+ }
statement.setDouble(index, doubleValue);
}
}
diff --git a/stardust-engine-core/src/test/java/org/eclipse/stardust/engine/core/persistence/jdbc/DmlManagerTest.java b/stardust-engine-core/src/test/java/org/eclipse/stardust/engine/core/persistence/jdbc/DmlManagerTest.java
new file mode 100644
index 0000000..53d6c7a
--- /dev/null
+++ b/stardust-engine-core/src/test/java/org/eclipse/stardust/engine/core/persistence/jdbc/DmlManagerTest.java
@@ -0,0 +1,71 @@
+package org.eclipse.stardust.engine.core.persistence.jdbc;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+
+public class DmlManagerTest
+{
+ private DBDescriptor dbDescriptor;
+
+ @Mock
+ PreparedStatement statement;
+
+ @Before
+ public void setup()
+ {
+ dbDescriptor = new DerbyDbDescriptor();
+ }
+
+ @Test
+ public void testGetDoubleSQLValue()
+ {
+ assertEquals(new String("-2.225E-307"), getSQLValue(-2.225E-307));
+ assertEquals(new String("2.225E-307"), getSQLValue(2.225E-307));
+ assertEquals(new String("0.0"), getSQLValue(-439E-324));
+ assertEquals(new String("0.0"), getSQLValue(439E-324));
+ assertEquals(new String("-2.225E-300"), getSQLValue(-2.225E-300));
+ assertEquals(new String("2.225E-300"), getSQLValue(2.225E-300));
+ assertEquals(new String("-0.4567"), getSQLValue(-0.4567));
+ assertEquals(new String("0.4567"), getSQLValue(0.4567));
+ assertEquals(new String("25.123"), getSQLValue(25.123));
+ assertEquals(new String("-25.123"), getSQLValue(-25.123));
+ }
+
+ private String getSQLValue(Object value)
+ {
+ return DmlManager.getSQLValue(Double.class, value, dbDescriptor);
+ }
+
+ @Test
+ public void testSetSQLValuePreparedStatement() throws SQLException
+ {
+ assertSetSQLValue(-2.225E-307, -2.225E-307);
+ assertSetSQLValue(2.225E-307, 2.225E-307);
+ assertSetSQLValue(-2.225E-308, 0.0);
+ assertSetSQLValue(2.225E-308, 0.0);
+ assertSetSQLValue(-439E-324, 0.0);
+ assertSetSQLValue(439E-324, 0.0);
+ assertSetSQLValue(-2.225E-300, -2.225E-300);
+ assertSetSQLValue(2.225E-300, 2.225E-300);
+ assertSetSQLValue(-0.4567, -0.4567);
+ assertSetSQLValue(0.4567, 0.4567);
+ assertSetSQLValue(25.123, 25.123);
+ assertSetSQLValue(-25.123, -25.123);
+ }
+
+ private void assertSetSQLValue(Double value, Double expected) throws SQLException
+ {
+ statement = mock(PreparedStatement.class);
+ DmlManager.setSQLValue(statement, 1, Double.class, value, dbDescriptor);
+ verify(statement).setDouble(1, expected);
+ }
+
+}