METAMODEL-228: Fixed
authorKasper Sørensen <i.am.kasper.sorensen@gmail.com>
Tue, 9 Feb 2016 12:39:15 +0000 (13:39 +0100)
committerKasper Sørensen <i.am.kasper.sorensen@gmail.com>
Tue, 9 Feb 2016 12:39:15 +0000 (13:39 +0100)
CHANGES.md
core/src/main/java/org/apache/metamodel/schema/ColumnTypeImpl.java
core/src/test/java/org/apache/metamodel/schema/ColumnTypeImplTest.java [moved from core/src/test/java/org/apache/metamodel/schema/ColumnTypeTest.java with 93% similarity]
couchdb/src/test/java/org/apache/metamodel/couchdb/CouchDbDataContextTest.java
mongodb/mongo2/src/test/java/org/apache/metamodel/mongodb/mongo2/MongoDbDataContextTest.java
mongodb/mongo3/src/test/java/org/apache/metamodel/mongodb/mongo3/MongoDbDataContextTest.java
pojo/src/test/java/org/apache/metamodel/pojo/ObjectTableDataProviderTest.java

index 13f1694..39aa75e 100644 (file)
@@ -3,6 +3,7 @@
  * [METAMODEL-227] - Fix for respecting CSV escape character also when no quote character is set.
  * [METAMODEL-183] - MongoDB module split into three: common, Mongo2 and Mongo3 to allow use of either old or new MongoDB API.
  * [METAMODEL-231] - Fixed a bug causing the Neo4j to represent the same table multiple times within a schema.
+ * [METAMODEL-228] - Fixed a bug causing Number.class to not be converted to ColumnType.NUMBER.
 
 ### Apache MetaModel 4.5.0
 
index 856321e..dbca861 100644 (file)
@@ -198,7 +198,7 @@ public class ColumnTypeImpl implements ColumnType {
 
         final ColumnType type;
         if (cls == String.class) {
-            type = ColumnType.VARCHAR;
+            type = ColumnType.STRING;
         } else if (cls == Boolean.class || cls == boolean.class) {
             type = ColumnType.BOOLEAN;
         } else if (cls == Character.class || cls == char.class || cls == Character[].class || cls == char[].class) {
@@ -217,6 +217,8 @@ public class ColumnTypeImpl implements ColumnType {
             type = ColumnType.DOUBLE;
         } else if (cls == BigDecimal.class) {
             type = ColumnType.DECIMAL;
+        } else if (Number.class.isAssignableFrom(cls)) {
+            type = ColumnType.NUMBER;
         } else if (Map.class.isAssignableFrom(cls)) {
             type = ColumnType.MAP;
         } else if (List.class.isAssignableFrom(cls)) {
@@ -31,7 +31,7 @@ import java.util.TreeMap;
 
 import junit.framework.TestCase;
 
-public class ColumnTypeTest extends TestCase {
+public class ColumnTypeImplTest extends TestCase {
 
        public void testConvertColumnTypeFromJdbcTypes() throws Exception {
                ColumnType type = ColumnTypeImpl.convertColumnType(Types.VARCHAR);
@@ -55,7 +55,10 @@ public class ColumnTypeTest extends TestCase {
        
        public void testConvertColumnTypeFromJavaClass() throws Exception {
                ColumnType type = ColumnTypeImpl.convertColumnType(String.class);
-               assertEquals(ColumnType.VARCHAR, type);
+               assertEquals(ColumnType.STRING, type);
+
+        type = ColumnTypeImpl.convertColumnType(Number.class);
+        assertEquals(ColumnType.NUMBER, type);
 
                type = ColumnTypeImpl.convertColumnType(Time.class);
                assertEquals(ColumnType.TIME, type);
index dd637fd..9e1f5fe 100644 (file)
@@ -65,7 +65,7 @@ public class CouchDbDataContextTest extends CouchDbTestCase {
             connector = couchDbInstance.createConnector(databaseName, true);
 
             final String[] columnNames = new String[] { "name", "gender", "age" };
-            final ColumnType[] columnTypes = new ColumnType[] { ColumnType.VARCHAR, ColumnType.CHAR, ColumnType.INTEGER };
+            final ColumnType[] columnTypes = new ColumnType[] { ColumnType.STRING, ColumnType.CHAR, ColumnType.INTEGER };
             predefinedTableDef = new SimpleTableDef(databaseName, columnNames, columnTypes);
         }
 
@@ -160,11 +160,11 @@ public class CouchDbDataContextTest extends CouchDbTestCase {
         final CouchDbDataContext dc = new CouchDbDataContext(couchDbInstance);
         Table table = dc.getDefaultSchema().getTableByName(databaseName);
         assertNotNull(table);
-        assertEquals("[Column[name=_id,columnNumber=0,type=VARCHAR,nullable=false,nativeType=null,columnSize=null], "
-                + "Column[name=_rev,columnNumber=1,type=VARCHAR,nullable=false,nativeType=null,columnSize=null], "
-                + "Column[name=bar,columnNumber=2,type=VARCHAR,nullable=null,nativeType=null,columnSize=null], "
+        assertEquals("[Column[name=_id,columnNumber=0,type=STRING,nullable=false,nativeType=null,columnSize=null], "
+                + "Column[name=_rev,columnNumber=1,type=STRING,nullable=false,nativeType=null,columnSize=null], "
+                + "Column[name=bar,columnNumber=2,type=STRING,nullable=null,nativeType=null,columnSize=null], "
                 + "Column[name=baz,columnNumber=3,type=INTEGER,nullable=null,nativeType=null,columnSize=null], "
-                + "Column[name=foo,columnNumber=4,type=VARCHAR,nullable=null,nativeType=null,columnSize=null]]",
+                + "Column[name=foo,columnNumber=4,type=STRING,nullable=null,nativeType=null,columnSize=null]]",
                 Arrays.toString(table.getColumns()));
 
         // first delete the manually created database!
@@ -182,7 +182,7 @@ public class CouchDbDataContextTest extends CouchDbTestCase {
             @Override
             public void run(UpdateCallback callback) {
                 Table table = callback.createTable(dc.getDefaultSchema(), databaseName).withColumn("foo")
-                        .ofType(ColumnType.VARCHAR).withColumn("greeting").ofType(ColumnType.VARCHAR).execute();
+                        .ofType(ColumnType.STRING).withColumn("greeting").ofType(ColumnType.STRING).execute();
                 assertEquals("[_id, _rev, foo, greeting]", Arrays.toString(table.getColumnNames()));
             }
         });
@@ -260,11 +260,11 @@ public class CouchDbDataContextTest extends CouchDbTestCase {
         assertEquals("[_id, _rev, age, gender, name]",
                 Arrays.toString(schema.getTableByName(getDatabaseName()).getColumnNames()));
         Column idColumn = schema.getTableByName(getDatabaseName()).getColumnByName("_id");
-        assertEquals("Column[name=_id,columnNumber=0,type=VARCHAR,nullable=false,nativeType=null,columnSize=null]",
+        assertEquals("Column[name=_id,columnNumber=0,type=STRING,nullable=false,nativeType=null,columnSize=null]",
                 idColumn.toString());
         assertTrue(idColumn.isPrimaryKey());
 
-        assertEquals("Column[name=_rev,columnNumber=1,type=VARCHAR,nullable=false,nativeType=null,columnSize=null]",
+        assertEquals("Column[name=_rev,columnNumber=1,type=STRING,nullable=false,nativeType=null,columnSize=null]",
                 schema.getTableByName(getDatabaseName()).getColumnByName("_rev").toString());
 
         DataSet ds;
index d777e5e..a03585a 100644 (file)
@@ -283,7 +283,7 @@ public class MongoDbDataContextTest extends MongoDbTestCase {
         assertEquals("[_id, baz, foo, id, list, name]", Arrays.toString(table.getColumnNames()));
 
         assertEquals(ColumnType.MAP, table.getColumnByName("baz").getType());
-        assertEquals(ColumnType.VARCHAR, table.getColumnByName("foo").getType());
+        assertEquals(ColumnType.STRING, table.getColumnByName("foo").getType());
         assertEquals(ColumnType.LIST, table.getColumnByName("list").getType());
         assertEquals(ColumnType.INTEGER, table.getColumnByName("id").getType());
         assertEquals(ColumnType.ROWID, table.getColumnByName("_id").getType());
index 1952640..d16e47c 100644 (file)
@@ -266,7 +266,7 @@ public class MongoDbDataContextTest extends MongoDbTestCase {
         assertEquals("[_id, baz, foo, id, list, name]", Arrays.toString(table.getColumnNames()));
 
         assertEquals(ColumnType.MAP, table.getColumnByName("baz").getType());
-        assertEquals(ColumnType.VARCHAR, table.getColumnByName("foo").getType());
+        assertEquals(ColumnType.STRING, table.getColumnByName("foo").getType());
         assertEquals(ColumnType.LIST, table.getColumnByName("list").getType());
         assertEquals(ColumnType.INTEGER, table.getColumnByName("id").getType());
         assertEquals(ColumnType.ROWID, table.getColumnByName("_id").getType());
index bdffc2a..ecf89fb 100644 (file)
@@ -30,7 +30,7 @@ public class ObjectTableDataProviderTest extends TestCase {
 
         SimpleTableDef tableDef = tableDataProvider.getTableDef();
         assertEquals(
-                "SimpleTableDef[name=FoobarBean,columnNames=[col1, col2, col3],columnTypes=[VARCHAR, INTEGER, BOOLEAN]]",
+                "SimpleTableDef[name=FoobarBean,columnNames=[col1, col2, col3],columnTypes=[STRING, INTEGER, BOOLEAN]]",
                 tableDef.toString());
     }
 }