Fixed toString() method of insert-builder. Fixes #134

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

Branch: refs/heads/5.x
Commit: c32a2bb447863bda17fc75a5c7681c2d60af8590
Parents: a3ecbab
Author: Kasper Sørensen <[email protected]>
Authored: Wed Oct 26 21:07:13 2016 -0700
Committer: Kasper Sørensen <[email protected]>
Committed: Wed Oct 26 21:07:13 2016 -0700

----------------------------------------------------------------------
 .gitattributes                                  |  2 +
 .../insert/AbstractRowInsertionBuilder.java     |  5 +-
 .../insert/AbstractRowInsertionBuilderTest.java | 49 ++++++++++++++++++++
 pom.xml                                         |  2 +
 4 files changed, 57 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/metamodel/blob/c32a2bb4/.gitattributes
----------------------------------------------------------------------
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..4cab1f4
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+# Set the default behavior, in case people don't have core.autocrlf set.
+* text=auto

http://git-wip-us.apache.org/repos/asf/metamodel/blob/c32a2bb4/core/src/main/java/org/apache/metamodel/insert/AbstractRowInsertionBuilder.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/insert/AbstractRowInsertionBuilder.java
 
b/core/src/main/java/org/apache/metamodel/insert/AbstractRowInsertionBuilder.java
index d688059..bc09f98 100644
--- 
a/core/src/main/java/org/apache/metamodel/insert/AbstractRowInsertionBuilder.java
+++ 
b/core/src/main/java/org/apache/metamodel/insert/AbstractRowInsertionBuilder.java
@@ -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";

http://git-wip-us.apache.org/repos/asf/metamodel/blob/c32a2bb4/core/src/test/java/org/apache/metamodel/insert/AbstractRowInsertionBuilderTest.java
----------------------------------------------------------------------
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
index 0000000..fc9f6bd
--- /dev/null
+++ 
b/core/src/test/java/org/apache/metamodel/insert/AbstractRowInsertionBuilderTest.java
@@ -0,0 +1,49 @@
+/**
+ * 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.metamodel.insert;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableTable;
+import org.junit.Test;
+
+public class AbstractRowInsertionBuilderTest {
+
+    @Test
+    public void testToString() {
+        final MutableTable table = new MutableTable("tbl");
+        final MutableColumn col1 = new MutableColumn("col1").setTable(table);
+        final MutableColumn col2 = new MutableColumn("col2").setTable(table);
+        table.addColumn(col1).addColumn(col2);
+
+        final AbstractRowInsertionBuilder<UpdateCallback> builder = new 
AbstractRowInsertionBuilder<UpdateCallback>(
+                null, table) {
+            @Override
+            public void execute() throws MetaModelException {
+                throw new UnsupportedOperationException();
+            }
+        };
+
+        builder.value(col1, "value1").value(col2, "value2");
+        assertEquals("INSERT INTO tbl(col1,col2) VALUES 
(\"value1\",\"value2\")", builder.toString());
+    }
+}

http://git-wip-us.apache.org/repos/asf/metamodel/blob/c32a2bb4/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 25209d8..b7b71c9 100644
--- 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>

Reply via email to