You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/02/14 14:49:39 UTC

[1/2] camel git commit: Add a type converter for java.sql.Timestamp

Repository: camel
Updated Branches:
  refs/heads/master c126376ba -> 25f4be9e3


Add a type converter for java.sql.Timestamp


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

Branch: refs/heads/master
Commit: a560d012c6d55a59db50ae87eb525e342a1bd1e9
Parents: c126376
Author: Daniel Pocock <da...@pocock.pro>
Authored: Fri Nov 28 08:59:49 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Feb 14 14:42:45 2015 +0100

----------------------------------------------------------------------
 .../apache/camel/converter/SQLConverter.java    | 44 ++++++++++++++++++++
 1 file changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a560d012/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
new file mode 100644
index 0000000..3dbbed3
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/converter/SQLConverter.java
@@ -0,0 +1,44 @@
+/**
+ * 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.Converter;
+
+/**
+ * Date and time related converters.
+ */
+@Converter
+public final class SQLConverter {
+
+    /**
+     * Utility classes should not have a public constructor.
+     */
+    private SQLConverter() {
+    }
+
+    @Converter
+    public static Timestamp toTimestamp(Long l) {
+        return l != null ? new Timestamp(l) : null;
+    }
+    
+    @Converter
+    public static Long toLong(Timestamp ts) {
+        return ts != null ? ts.getTime() : null;
+    }
+}


[2/2] camel git commit: More work on sql type converter

Posted by da...@apache.org.
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 <da...@apache.org>
Authored: Sat Feb 14 14:49:34 2015 +0100
Committer: Claus Ibsen <da...@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);
+    }
+}