camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] camel git commit: More work on sql type converter
Date Sat, 14 Feb 2015 13:49:40 GMT
More work on sql type converter


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/25f4be9e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/25f4be9e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/25f4be9e

Branch: refs/heads/master
Commit: 25f4be9e3382b2ef739c5fb9e17d230692e9ce6a
Parents: a560d01
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Feb 14 14:49:34 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Feb 14 14:49:34 2015 +0100

----------------------------------------------------------------------
 .../apache/camel/converter/SQLConverter.java    |  6 ++--
 .../converter/CorePackageScanClassResolver.java |  2 ++
 .../camel/converter/SqlConverterTest.java       | 38 ++++++++++++++++++++
 3 files changed, 43 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/25f4be9e/camel-core/src/main/java/org/apache/camel/converter/SQLConverter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/converter/SQLConverter.java b/camel-core/src/main/java/org/apache/camel/converter/SQLConverter.java
index 3dbbed3..7ddc9ad 100644
--- a/camel-core/src/main/java/org/apache/camel/converter/SQLConverter.java
+++ b/camel-core/src/main/java/org/apache/camel/converter/SQLConverter.java
@@ -21,7 +21,7 @@ import java.sql.Timestamp;
 import org.apache.camel.Converter;
 
 /**
- * Date and time related converters.
+ * SQL Date and time related converters.
  */
 @Converter
 public final class SQLConverter {
@@ -34,11 +34,11 @@ public final class SQLConverter {
 
     @Converter
     public static Timestamp toTimestamp(Long l) {
-        return l != null ? new Timestamp(l) : null;
+        return new Timestamp(l);
     }
     
     @Converter
     public static Long toLong(Timestamp ts) {
-        return ts != null ? ts.getTime() : null;
+        return ts.getTime();
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/25f4be9e/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java
b/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java
index c75d673..d6af4dd 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java
@@ -29,6 +29,7 @@ import org.apache.camel.converter.DateTimeConverter;
 import org.apache.camel.converter.IOConverter;
 import org.apache.camel.converter.NIOConverter;
 import org.apache.camel.converter.ObjectConverter;
+import org.apache.camel.converter.SQLConverter;
 import org.apache.camel.converter.TimePatternConverter;
 import org.apache.camel.converter.jaxp.DomConverter;
 import org.apache.camel.converter.jaxp.StaxConverter;
@@ -59,6 +60,7 @@ public class CorePackageScanClassResolver implements PackageScanClassResolver
{
         converters.add(ObjectConverter.class);
         converters.add(CollectionConverter.class);
         converters.add(DateTimeConverter.class);
+        converters.add(SQLConverter.class);
         converters.add(IOConverter.class);
         converters.add(NIOConverter.class);
         converters.add(StaxConverter.class);

http://git-wip-us.apache.org/repos/asf/camel/blob/25f4be9e/camel-core/src/test/java/org/apache/camel/converter/SqlConverterTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/converter/SqlConverterTest.java b/camel-core/src/test/java/org/apache/camel/converter/SqlConverterTest.java
new file mode 100644
index 0000000..b480de7
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/converter/SqlConverterTest.java
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.converter;
+
+import java.sql.Timestamp;
+
+import org.apache.camel.ContextTestSupport;
+
+public class SQLConverterTest extends ContextTestSupport {
+
+    public void testTimestamp() {
+        long value = System.currentTimeMillis();
+        Timestamp ts = context.getTypeConverter().convertTo(Timestamp.class, value);
+        Timestamp expected = new Timestamp(value);
+        assertEquals(expected, ts);
+    }
+
+    public void testToLong() {
+        long value = System.currentTimeMillis();
+        Timestamp ts = new Timestamp(value);
+        long l = context.getTypeConverter().convertTo(Long.class, ts);
+        assertEquals(value, l);
+    }
+}


Mime
View raw message