Fixed toString() method of insert-builder. Fixes #134
authorKasper Sørensen <i.am.kasper.sorensen@gmail.com>
Thu, 27 Oct 2016 04:07:13 +0000 (21:07 -0700)
committerKasper Sørensen <i.am.kasper.sorensen@gmail.com>
Thu, 27 Oct 2016 04:07:13 +0000 (21:07 -0700)
.gitattributes [new file with mode: 0644]
core/src/main/java/org/apache/metamodel/insert/AbstractRowInsertionBuilder.java
core/src/test/java/org/apache/metamodel/insert/AbstractRowInsertionBuilderTest.java [new file with mode: 0644]
pom.xml

diff --git a/.gitattributes b/.gitattributes
new file mode 100644 (file)
index 0000000..4cab1f4
--- /dev/null
@@ -0,0 +1,2 @@
+# Set the default behavior, in case people don't have core.autocrlf set.
+* text=auto
index d688059..bc09f98 100644 (file)
@@ -84,7 +84,10 @@ public abstract class AbstractRowInsertionBuilder<U extends UpdateCallback> exte
         sb.append(") VALUES (");
         Object[] values = getValues();
         for (int i = 0; i < values.length; i++) {
-            Object value = values[i];
+            if (i != 0) {
+                sb.append(',');
+            }
+            final Object value = values[i];
             final String stringValue;
             if (value == null) {
                 stringValue = "NULL";
diff --git a/core/src/test/java/org/apache/metamodel/insert/AbstractRowInsertionBuilderTest.java b/core/src/test/java/org/apache/metamodel/insert/AbstractRowInsertionBuilderTest.java
new file mode 100644 (file)
index 0000000..fc9f6bd
--- /dev/null
@@ -0,0 +1,49 @@
+/**\r
+ * Licensed to the Apache Software Foundation (ASF) under one\r
+ * or more contributor license agreements.  See the NOTICE file\r
+ * distributed with this work for additional information\r
+ * regarding copyright ownership.  The ASF licenses this file\r
+ * to you under the Apache License, Version 2.0 (the\r
+ * "License"); you may not use this file except in compliance\r
+ * with the License.  You may obtain a copy of the License at\r
+ *\r
+ *   http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing,\r
+ * software distributed under the License is distributed on an\r
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
+ * KIND, either express or implied.  See the License for the\r
+ * specific language governing permissions and limitations\r
+ * under the License.\r
+ */\r
+package org.apache.metamodel.insert;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+\r
+import org.apache.metamodel.MetaModelException;\r
+import org.apache.metamodel.UpdateCallback;\r
+import org.apache.metamodel.schema.MutableColumn;\r
+import org.apache.metamodel.schema.MutableTable;\r
+import org.junit.Test;\r
+\r
+public class AbstractRowInsertionBuilderTest {\r
+\r
+    @Test\r
+    public void testToString() {\r
+        final MutableTable table = new MutableTable("tbl");\r
+        final MutableColumn col1 = new MutableColumn("col1").setTable(table);\r
+        final MutableColumn col2 = new MutableColumn("col2").setTable(table);\r
+        table.addColumn(col1).addColumn(col2);\r
+\r
+        final AbstractRowInsertionBuilder<UpdateCallback> builder = new AbstractRowInsertionBuilder<UpdateCallback>(\r
+                null, table) {\r
+            @Override\r
+            public void execute() throws MetaModelException {\r
+                throw new UnsupportedOperationException();\r
+            }\r
+        };\r
+\r
+        builder.value(col1, "value1").value(col2, "value2");\r
+        assertEquals("INSERT INTO tbl(col1,col2) VALUES (\"value1\",\"value2\")", builder.toString());\r
+    }\r
+}\r
diff --git a/pom.xml b/pom.xml
index 25209d8..b7b71c9 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -376,6 +376,8 @@ under the License.
                                                        <exclude>**/src/assembly/metamodel-packaged-assembly-descriptor.xml</exclude>
                                                        <exclude>**/.gitignore/**</exclude>
                                                        <exclude>.git/**</exclude>
+                                                       <exclude>.gitattributes</exclude>
+                                                       <exclude>**/.toDelete</exclude>
                                                        <exclude>**/src/main/resources/META-INF/services/**</exclude>
                                                        <exclude>**/src/test/resources/**</exclude>
                                                        <exclude>**/src/site/**</exclude>