now all compiling
authorJörg Unbehauen <joerg@unbehauen.net>
Thu, 27 Jul 2017 16:05:40 +0000 (18:05 +0200)
committerJörg Unbehauen <joerg@unbehauen.net>
Thu, 27 Jul 2017 16:05:40 +0000 (18:05 +0200)
113 files changed:
cassandra/src/main/java/org/apache/metamodel/cassandra/CassandraDataContext.java
cassandra/src/main/java/org/apache/metamodel/cassandra/CassandraDataSet.java
cassandra/src/test/java/org/apache/metamodel/cassandra/CassandraDataContextTest.java
core/src/main/java/org/apache/metamodel/data/AbstractDataSet.java
core/src/main/java/org/apache/metamodel/data/EmptyDataSet.java
core/src/main/java/org/apache/metamodel/data/SimpleDataSetHeader.java
core/src/main/java/org/apache/metamodel/intercept/InterceptableDataContext.java
core/src/main/java/org/apache/metamodel/schema/MutableRelationship.java
core/src/main/java/org/apache/metamodel/schema/MutableSchema.java
core/src/test/java/org/apache/metamodel/create/AbstractCreateTableBuilderTest.java
couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataContext.java
couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataSet.java
couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbSimpleTableDefSchemaBuilder.java
couchdb/src/test/java/org/apache/metamodel/couchdb/CouchDbDataContextTest.java
csv/src/main/java/org/apache/metamodel/csv/CsvCreateTableBuilder.java
csv/src/main/java/org/apache/metamodel/csv/CsvDataContext.java
csv/src/main/java/org/apache/metamodel/csv/CsvDataSet.java
csv/src/main/java/org/apache/metamodel/csv/CsvSchema.java
csv/src/main/java/org/apache/metamodel/csv/CsvTable.java
csv/src/main/java/org/apache/metamodel/csv/SingleLineCsvDataSet.java
csv/src/test/java/org/apache/metamodel/csv/CsvBigFileMemoryTest.java
csv/src/test/java/org/apache/metamodel/csv/CsvDataContextTest.java
csv/src/test/java/org/apache/metamodel/csv/SingleLineCsvRowTest.java
csv/src/test/java/org/apache/metamodel/intercept/InterceptionCsvIntegrationTest.java
dynamodb/src/main/java/org/apache/metamodel/dynamodb/DynamoDbDataContext.java
dynamodb/src/main/java/org/apache/metamodel/dynamodb/DynamoDbDataSet.java
dynamodb/src/main/java/org/apache/metamodel/dynamodb/DynamoDbTableCreationBuilder.java
dynamodb/src/test/java/org/apache/metamodel/dynamodb/DynamoDbDataContextIntegrationTest.java
elasticsearch/native/src/main/java/org/apache/metamodel/elasticsearch/nativeclient/ElasticSearchDataContext.java
elasticsearch/native/src/main/java/org/apache/metamodel/elasticsearch/nativeclient/ElasticSearchDataSet.java
elasticsearch/native/src/test/java/org/apache/metamodel/elasticsearch/nativeclient/ElasticSearchDataContextTest.java
elasticsearch/rest/src/main/java/org/apache/metamodel/elasticsearch/rest/ElasticSearchRestDataContext.java
elasticsearch/rest/src/main/java/org/apache/metamodel/elasticsearch/rest/JestElasticSearchDataSet.java
elasticsearch/rest/src/test/java/org/apache/metamodel/elasticsearch/rest/JestElasticSearchDataContextTest.java
elasticsearch/rest/src/test/java/org/apache/metamodel/elasticsearch/rest/JestElasticSearchUtilsTest.java
excel/src/main/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegate.java
excel/src/main/java/org/apache/metamodel/excel/ExcelDataContext.java
excel/src/main/java/org/apache/metamodel/excel/ExcelDeleteBuilder.java
excel/src/main/java/org/apache/metamodel/excel/ExcelTableCreationBuilder.java
excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java
excel/src/main/java/org/apache/metamodel/excel/SpreadsheetReaderDelegate.java
excel/src/main/java/org/apache/metamodel/excel/XlsDataSet.java
excel/src/main/java/org/apache/metamodel/excel/XlsxRowPublisherAction.java
excel/src/main/java/org/apache/metamodel/excel/XlsxSpreadsheetReaderDelegate.java
excel/src/test/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegateTest.java
excel/src/test/java/org/apache/metamodel/excel/ExcelDataContextTest.java
excel/src/test/java/org/apache/metamodel/excel/ExcelUpdateCallbackTest.java
fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataContext.java
fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataSet.java
fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthConfigurationReaderTest.java
fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthDataContextTest.java
hbase/src/main/java/org/apache/metamodel/hbase/HBaseDataContext.java
hbase/src/main/java/org/apache/metamodel/hbase/HBaseDataSet.java
hbase/src/test/java/org/apache/metamodel/hbase/HBaseDataContextTest.java
jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCreateTableBuilder.java
jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataContext.java
jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcMetadataLoader.java
jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSchema.java
jdbc/src/main/java/org/apache/metamodel/jdbc/QuerySplitter.java
jdbc/src/test/java/org/apache/metamodel/jdbc/DerbyTest.java
jdbc/src/test/java/org/apache/metamodel/jdbc/H2databaseTest.java
jdbc/src/test/java/org/apache/metamodel/jdbc/HsqldbTest.java
jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcDataContextTest.java
jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcDeleteBuilderTest.java
jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcInsertBuilderTest.java
jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcSchemaTest.java
jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcTestTemplates.java
jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcUpdateBuilderTest.java
jdbc/src/test/java/org/apache/metamodel/jdbc/QuerySplitterTest.java
jdbc/src/test/java/org/apache/metamodel/jdbc/SqliteTest.java
jdbc/src/test/java/org/apache/metamodel/jdbc/integrationtests/DB2Test.java
jdbc/src/test/java/org/apache/metamodel/jdbc/integrationtests/FirebirdTest.java
jdbc/src/test/java/org/apache/metamodel/jdbc/integrationtests/MysqlTest.java
jdbc/src/test/java/org/apache/metamodel/jdbc/integrationtests/OracleTest.java
jdbc/src/test/java/org/apache/metamodel/jdbc/integrationtests/PostgresqlTest.java
jdbc/src/test/java/org/apache/metamodel/jdbc/integrationtests/SQLServerJtdsDriverTest.java
jdbc/src/test/java/org/apache/metamodel/jdbc/integrationtests/SQLServerMicrosoftDriverTest.java
json/src/main/java/org/apache/metamodel/json/JsonDataContext.java
json/src/test/java/org/apache/metamodel/json/JsonDataContextTest.java
mongodb/mongo2/src/main/java/org/apache/metamodel/mongodb/mongo2/MongoDbDataContext.java
mongodb/mongo2/src/main/java/org/apache/metamodel/mongodb/mongo2/MongoDbDataSet.java
mongodb/mongo2/src/test/java/org/apache/metamodel/mongodb/mongo2/MongoDbDataContextTest.java
mongodb/mongo2/src/test/java/org/apache/metamodel/mongodb/mongo2/MongoDbDataCopyer.java
mongodb/mongo3/src/main/java/org/apache/metamodel/mongodb/mongo3/MongoDbDataContext.java
mongodb/mongo3/src/main/java/org/apache/metamodel/mongodb/mongo3/MongoDbDataSet.java
mongodb/mongo3/src/test/java/org/apache/metamodel/mongodb/mongo3/MongoDbDataContextTest.java
mongodb/mongo3/src/test/java/org/apache/metamodel/mongodb/mongo3/MongoDbDataCopyer.java
neo4j/src/main/java/org/apache/metamodel/neo4j/Neo4jCypherQueryBuilder.java
neo4j/src/main/java/org/apache/metamodel/neo4j/Neo4jDataContext.java
neo4j/src/main/java/org/apache/metamodel/neo4j/Neo4jDataSet.java
neo4j/src/test/java/org/apache/metamodel/neo4j/Neo4jDataContextTest.java
openoffice/src/main/java/org/apache/metamodel/openoffice/OpenOfficeDataContext.java
openoffice/src/test/java/org/apache/metamodel/openoffice/OpenOfficeDataContextTest.java
pojo/src/main/java/org/apache/metamodel/pojo/PojoDataContext.java
pojo/src/main/java/org/apache/metamodel/pojo/PojoDataSet.java
pojo/src/test/java/org/apache/metamodel/pojo/PojoDataContextTest.java
salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataContext.java
salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataSet.java
salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceSchema.java
salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceTable.java
salesforce/src/test/java/org/apache/metamodel/salesforce/SalesforceDataContextTest.java
salesforce/src/test/java/org/apache/metamodel/salesforce/SalesforceDataSetTest.java
spring/src/test/java/org/apache/metamodel/spring/CsvDefaultConfigurationFromResourceTest.java
spring/src/test/java/org/apache/metamodel/spring/CsvSpecifiedConfigurationFromFilenameTest.java
spring/src/test/java/org/apache/metamodel/spring/ExcelSpecifiedConfigurationFromFilenameTest.java
spring/src/test/java/org/apache/metamodel/spring/PojoDataContextFactoryBeanDelegateTest.java
sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmDataContext.java
sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmDataSet.java
sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmSchema.java
sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmTable.java
sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmXmlHelper.java
sugarcrm/src/test/java/org/apache/metamodel/sugarcrm/SugarCrmDataContextTest.java
xml/src/main/java/org/apache/metamodel/xml/XmlDomDataContext.java

index 3a1684e..08d3fd9 100644 (file)
@@ -69,7 +69,6 @@ import com.datastax.driver.core.querybuilder.Select.Selection;
 public class CassandraDataContext extends QueryPostprocessDataContext implements DataContext {
 
     private static final Logger logger = LoggerFactory.getLogger(CassandraDataContext.class);
-
     private final Cluster cassandraCluster;
     private final SimpleTableDef[] tableDefs;
     private final String keySpaceName;
@@ -188,7 +187,7 @@ public class CassandraDataContext extends QueryPostprocessDataContext implements
     }
 
     @Override
-    protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+    protected DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) {
         final Select query = QueryBuilder.select().all().from(keySpaceName, table.getName());
         if (limitMaxRowsIsSet(maxRows)) {
             query.limit(maxRows);
index ea02176..ff222a1 100644 (file)
 package org.apache.metamodel.cassandra;
 
 import java.util.Iterator;
+import java.util.List;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.data.AbstractDataSet;
 import org.apache.metamodel.data.DataSet;
 import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.SelectItem;
 import org.apache.metamodel.schema.Column;
 
 /**
@@ -36,8 +39,8 @@ final class CassandraDataSet extends AbstractDataSet {
 
     private volatile com.datastax.driver.core.Row _dbObject;
 
-    public CassandraDataSet(Iterator<com.datastax.driver.core.Row> cursor, Column[] columns) {
-        super(columns);
+    public CassandraDataSet(Iterator<com.datastax.driver.core.Row> cursor, List<Column> columns) {
+        super(columns.stream().map(SelectItem::new).collect(Collectors.toList()));
         _cursor = cursor;
     }
 
index a9d9605..575bb5f 100644 (file)
@@ -83,7 +83,7 @@ public class CassandraDataContextTest {
 
     @Test
     public void testSchemaAndSimpleQuery() throws Exception {
-        String existingTables = Arrays.toString(dc.getDefaultSchema().getTableNames());
+        String existingTables = Arrays.toString(dc.getDefaultSchema().getTableNames().toArray());
         assertTrue(existingTables.contains(testTableName));
         assertTrue(existingTables.contains(testCounterTableName));
 
index 6e64446..17699b5 100644 (file)
@@ -64,9 +64,6 @@ public abstract class AbstractDataSet extends BaseObject implements DataSet {
         _header = Objects.requireNonNull(header);
     }
 
-    public AbstractDataSet(Column[] columns) {
-        this(MetaModelHelper.createSelectItems(columns));
-    }
 
     /**
      * {@inheritDoc}
index fd71be3..89d5d35 100644 (file)
@@ -19,6 +19,7 @@
 package org.apache.metamodel.data;
 
 import java.util.List;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.query.SelectItem;
 import org.apache.metamodel.schema.Column;
@@ -36,6 +37,10 @@ public final class EmptyDataSet extends AbstractDataSet {
        this(new SimpleDataSetHeader(selectItems));
     }
 
+    public static EmptyDataSet fromColumns(List<Column> cols){
+        return new EmptyDataSet(cols.stream().map(SelectItem::new).collect(Collectors.toList()));
+    }
+
     @Override
     public boolean next() {
         return false;
index afc6226..71703d5 100644 (file)
@@ -49,6 +49,11 @@ public class SimpleDataSetHeader implements DataSetHeader {
     }
 
 
+    public static SimpleDataSetHeader fromColumns(List<Column> cols){
+        return new SimpleDataSetHeader(cols.stream().map(SelectItem::new).collect(Collectors.toList()));
+    }
+
+
     @Override
     public final List<SelectItem> getSelectItems() {
         return Collections.unmodifiableList(_items);
index 1811e78..3076ca8 100644 (file)
@@ -194,17 +194,15 @@ public class InterceptableDataContext implements UpdateableDataContext {
 
     @Override
     public List<Schema> getSchemas() throws MetaModelException {
-        List<Schema> schemas = _delegate.getSchemas();
-        List<Schema> result = new ArrayList<>(schemas.size());
-        if (!_schemaInterceptors.isEmpty()) {
-            for (int i = 0; i < schemas.size(); i++) {
-                schemas.set(i, _schemaInterceptors.interceptAll(schemas.get(i)));
-            }
-        }else {
-            result = schemas;
-        }
-        return result;
-
+        return _delegate.getSchemas().stream()
+                .map(schema -> {
+                    if(_schemaInterceptors.isEmpty()){
+                        return schema;
+                    }else{
+                        return _schemaInterceptors.interceptAll(schema);
+                    }
+
+                }).collect(Collectors.toList());
     }
 
     @Override
index 466244c..3ea624c 100644 (file)
@@ -110,7 +110,7 @@ public class MutableRelationship extends AbstractRelationship implements
                List<Column> pcols = new ArrayList<>();
                pcols.add(primaryColumn);
                List<Column> fcols = new ArrayList<>();
-               pcols.add(foreignColumn);
+               fcols.add(foreignColumn);
 
 
                return createRelationship(pcols, fcols);
index 29d361b..f01b5c0 100644 (file)
@@ -68,6 +68,11 @@ public class MutableSchema extends AbstractSchema implements Serializable,
                return Collections.unmodifiableList(_tables);
        }
 
+       public List<MutableTable> getMutableTables() {
+               return Collections.unmodifiableList(_tables);
+       }
+
+
        public MutableSchema setTables(Collection<? extends MutableTable> tables) {
            clearTables();
                for (MutableTable table : tables) {
index f5e7356..e108277 100644 (file)
@@ -102,6 +102,6 @@ public class AbstractCreateTableBuilderTest extends TestCase {
         assertEquals("Column[name=bar,columnNumber=1,type=null,nullable=null,nativeType=null,columnSize=null]",
                 table.getColumn(1).toString());
         assertEquals("Column[name=baz,columnNumber=2,type=null,nullable=null,nativeType=null,columnSize=null]",
-                table.getColumn(1).toString());
+                table.getColumn(2).toString());
     }
 }
index f98fa81..bc0a19d 100644 (file)
@@ -19,6 +19,7 @@
 package org.apache.metamodel.couchdb;
 
 import java.util.List;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.MetaModelException;
 import org.apache.metamodel.MetaModelHelper;
@@ -111,7 +112,7 @@ public class CouchDbDataContext extends QueryPostprocessDataContext implements U
     }
 
     @Override
-    protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int firstRow, int maxRows) {
+    protected DataSet materializeMainSchemaTable(Table table, List<Column> columns, int firstRow, int maxRows) {
         // the connector represents a handle to the the couchdb "database".
         final String databaseName = table.getName();
         final CouchDbConnector connector = _couchDbInstance.createConnector(databaseName, false);
@@ -128,12 +129,12 @@ public class CouchDbDataContext extends QueryPostprocessDataContext implements U
 
         final StreamingViewResult streamingView = connector.queryForStreamingView(query);
 
-        final SelectItem[] selectItems = MetaModelHelper.createSelectItems(columns);
+        final List<SelectItem> selectItems = columns.stream().map(SelectItem::new).collect(Collectors.toList());
         return new CouchDbDataSet(selectItems, streamingView);
     }
 
     @Override
-    protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+    protected DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) {
         return materializeMainSchemaTable(table, columns, 1, maxRows);
     }
 
index 47b0ac9..fef648e 100644 (file)
@@ -19,6 +19,7 @@
 package org.apache.metamodel.couchdb;
 
 import java.util.Iterator;
+import java.util.List;
 
 import org.apache.metamodel.data.AbstractDataSet;
 import org.apache.metamodel.data.DataSetHeader;
@@ -37,7 +38,7 @@ final class CouchDbDataSet extends AbstractDataSet {
     private final StreamingViewResult _streamingViewResult;
     private Row _row;
 
-    public CouchDbDataSet(SelectItem[] selectItems, StreamingViewResult streamingViewResult) {
+    public CouchDbDataSet(List<SelectItem> selectItems, StreamingViewResult streamingViewResult) {
         super(selectItems);
         _streamingViewResult = streamingViewResult;
 
index 308d8f2..97e0f8b 100644 (file)
@@ -40,8 +40,7 @@ public class CouchDbSimpleTableDefSchemaBuilder extends SimpleTableDefSchemaBuil
     @Override
     public MutableSchema build() {
         MutableSchema schema = super.build();
-        MutableTable[] tables = schema.getTables();
-        for (MutableTable table : tables) {
+        for (MutableTable table : schema.getMutableTables()) {
             CouchDbTableCreationBuilder.addMandatoryColumns(table);
         }
         return schema;
index c2ec998..508f3f1 100644 (file)
@@ -166,7 +166,7 @@ public class CouchDbDataContextTest extends CouchDbTestCase {
                 + "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=STRING,nullable=null,nativeType=null,columnSize=null]]",
-                Arrays.toString(table.getColumns()));
+                Arrays.toString(table.getColumns().toArray()));
 
         // first delete the manually created database!
         dc.executeUpdate(new UpdateScript() {
@@ -184,7 +184,7 @@ public class CouchDbDataContextTest extends CouchDbTestCase {
             public void run(UpdateCallback callback) {
                 Table table = callback.createTable(dc.getDefaultSchema(), databaseName).withColumn("foo")
                         .ofType(ColumnType.STRING).withColumn("greeting").ofType(ColumnType.STRING).execute();
-                assertEquals("[_id, _rev, foo, greeting]", Arrays.toString(table.getColumnNames()));
+                assertEquals("[_id, _rev, foo, greeting]", Arrays.toString(table.getColumnNames().toArray()));
             }
         });
 
@@ -256,10 +256,10 @@ public class CouchDbDataContextTest extends CouchDbTestCase {
 
         // verify schema and execute query
         Schema schema = dc.getMainSchema();
-        assertEquals("[" + getDatabaseName() + "]", Arrays.toString(schema.getTableNames()));
+        assertEquals("[" + getDatabaseName() + "]", Arrays.toString(schema.getTableNames().toArray()));
 
         assertEquals("[_id, _rev, age, gender, name]",
-                Arrays.toString(schema.getTableByName(getDatabaseName()).getColumnNames()));
+                Arrays.toString(schema.getTableByName(getDatabaseName()).getColumnNames().toArray()));
         Column idColumn = schema.getTableByName(getDatabaseName()).getColumnByName("_id");
         assertEquals("Column[name=_id,columnNumber=0,type=STRING,nullable=false,nativeType=null,columnSize=null]",
                 idColumn.toString());
@@ -404,7 +404,7 @@ public class CouchDbDataContextTest extends CouchDbTestCase {
         Table table = dc.getTableByQualifiedLabel(getDatabaseName());
         assertNotNull(table);
 
-        assertEquals("[_id, _rev, name, gender, age]", Arrays.toString(table.getColumnNames()));
+        assertEquals("[_id, _rev, name, gender, age]", Arrays.toString(table.getColumnNames().toArray()));
 
         DataSet ds;
 
index cd0bb38..b197f31 100644 (file)
@@ -23,6 +23,8 @@ import org.apache.metamodel.schema.MutableTable;
 import org.apache.metamodel.schema.Schema;
 import org.apache.metamodel.schema.Table;
 
+import java.util.List;
+
 final class CsvCreateTableBuilder extends AbstractTableCreationBuilder<CsvUpdateCallback> {
 
     public CsvCreateTableBuilder(CsvUpdateCallback updateCallback, Schema schema, String name) {
@@ -37,12 +39,12 @@ final class CsvCreateTableBuilder extends AbstractTableCreationBuilder<CsvUpdate
         CsvUpdateCallback csvUpdateCallback = getUpdateCallback();
 
         MutableTable table = getTable();
-        String[] columnNames = table.getColumnNames();
+        List<String> columnNames = table.getColumnNames();
 
         CsvDataContext csvDataContext = (CsvDataContext) csvUpdateCallback.getDataContext();
 
         if (csvDataContext.getConfiguration().getColumnNameLineNumber() != CsvConfiguration.NO_COLUMN_NAME_LINE) {
-            csvUpdateCallback.writeRow(columnNames, false);
+            csvUpdateCallback.writeRow(columnNames.toArray(new String[columnNames.size()]), false);
         }
 
         CsvSchema schema = (CsvSchema) table.getSchema();
index 2e66ebe..34b25fa 100644 (file)
@@ -270,7 +270,7 @@ public final class CsvDataContext extends QueryPostprocessDataContext implements
     }
 
     @Override
-    public DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+    public DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) {
         final int lineNumber = _configuration.getColumnNameLineNumber();
         final int columnCount = table.getColumnCount();
 
@@ -282,7 +282,7 @@ public final class CsvDataContext extends QueryPostprocessDataContext implements
                 String line = reader.readLine();
                 if (line == null) {
                     FileHelper.safeClose(reader);
-                    return new EmptyDataSet(columns);
+                    return EmptyDataSet.fromColumns(columns);
                 }
             }
         } catch (IOException e) {
index b93db3e..96acae7 100644 (file)
 package org.apache.metamodel.csv;
 
 import java.io.IOException;
+import java.util.List;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.MetaModelException;
 import org.apache.metamodel.data.AbstractDataSet;
 import org.apache.metamodel.data.DefaultRow;
 import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.SelectItem;
 import org.apache.metamodel.schema.Column;
 import org.apache.metamodel.util.FileHelper;
 
@@ -41,9 +44,9 @@ final class CsvDataSet extends AbstractDataSet {
     private volatile Integer _rowsRemaining;
     private volatile Row _row;
 
-    public CsvDataSet(CSVReader reader, Column[] columns, Integer maxRows, int columnsInTable,
-            boolean failOnInconsistentRowLength) {
-        super(columns);
+    public CsvDataSet(CSVReader reader, List<Column> columns, Integer maxRows, int columnsInTable,
+                      boolean failOnInconsistentRowLength) {
+        super(columns.stream().map(SelectItem::new).collect(Collectors.toList()));
         _reader = reader;
         _columnsInTable = columnsInTable;
         _failOnInconsistentRowLength = failOnInconsistentRowLength;
index 6de36a6..6c9a01e 100644 (file)
  */
 package org.apache.metamodel.csv;
 
+import com.google.common.collect.Lists;
 import org.apache.metamodel.schema.AbstractSchema;
 import org.apache.metamodel.schema.Table;
 
+import java.util.ArrayList;
+import java.util.List;
+
 final class CsvSchema extends AbstractSchema {
 
     private static final long serialVersionUID = 1L;
@@ -54,10 +58,10 @@ final class CsvSchema extends AbstractSchema {
        }
 
        @Override
-       public Table[] getTables() {
+       public List<Table> getTables() {
                if (_table == null) {
-                       return new Table[0];
+                       return new ArrayList<>();
                }
-               return new Table[] { _table };
+               return Lists.newArrayList(_table);
        }
 }
index 0887eee..c786e70 100644 (file)
@@ -19,7 +19,9 @@
 package org.apache.metamodel.csv;
 
 import java.io.IOException;
+import java.util.*;
 
+import com.google.common.collect.Lists;
 import org.apache.metamodel.schema.AbstractTable;
 import org.apache.metamodel.schema.Column;
 import org.apache.metamodel.schema.ColumnType;
@@ -40,7 +42,7 @@ final class CsvTable extends AbstractTable {
 
     private final CsvSchema _schema;
     private final String _tableName;
-    private Column[] _columns;
+    private List<Column> _columns;
 
     /**
      * Constructor for creating a new CSV table which has not yet been written.
@@ -48,7 +50,7 @@ final class CsvTable extends AbstractTable {
      * @param schema
      * @param columnNames
      */
-    public CsvTable(CsvSchema schema, String tableName, String[] columnNames) {
+    public CsvTable(CsvSchema schema, String tableName, List<String> columnNames) {
         this(schema, tableName);
         _columns = buildColumns(columnNames);
     }
@@ -75,7 +77,7 @@ final class CsvTable extends AbstractTable {
     }
 
     @Override
-    public Column[] getColumns() {
+    public List<Column> getColumns() {
         if (_columns == null) {
             synchronized (this) {
                 if (_columns == null) {
@@ -86,7 +88,7 @@ final class CsvTable extends AbstractTable {
         return _columns;
     }
 
-    private Column[] buildColumns() {
+    private List<Column> buildColumns() {
         CSVReader reader = null;
         try {
             reader = _schema.getDataContext().createCsvReader(0);
@@ -95,7 +97,7 @@ final class CsvTable extends AbstractTable {
             for (int i = 1; i < columnNameLineNumber; i++) {
                 reader.readNext();
             }
-            final String[] columnHeaders = reader.readNext();
+            final List<String> columnHeaders = Arrays.asList(Optional.ofNullable(reader.readNext()).orElse(new String[0]));
 
             reader.close();
             return buildColumns(columnHeaders);
@@ -107,9 +109,9 @@ final class CsvTable extends AbstractTable {
         }
     }
 
-    private Column[] buildColumns(final String[] columnNames) {
+    private List<Column> buildColumns(final List<String> columnNames) {
         if (columnNames == null) {
-            return new Column[0];
+            return new ArrayList<>();
         }
         
         final CsvConfiguration configuration = _schema.getDataContext().getConfiguration();
@@ -117,16 +119,17 @@ final class CsvTable extends AbstractTable {
         final boolean nullable = !configuration.isFailOnInconsistentRowLength();
         final ColumnNamingStrategy columnNamingStrategy = configuration.getColumnNamingStrategy();
 
-        final Column[] columns = new Column[columnNames.length];
+        List<Column> columns = new ArrayList<>();
+
         try (final ColumnNamingSession namingSession = columnNamingStrategy.startColumnNamingSession()) {
-            for (int i = 0; i < columnNames.length; i++) {
+            for (int i = 0; i < columnNames.size(); i++) {
                 final String intrinsicColumnName = columnNameLineNumber == CsvConfiguration.NO_COLUMN_NAME_LINE ? null
-                        : columnNames[i];
+                        : columnNames.get(i);
                 final String columnName = namingSession.getNextColumnName(new ColumnNamingContextImpl(this,
                         intrinsicColumnName, i));
                 final Column column = new MutableColumn(columnName, ColumnType.STRING, this, i, null, null, nullable,
                         null, false, null);
-                columns[i] = column;
+                columns.add(column);
             }
         }
         return columns;
@@ -143,8 +146,8 @@ final class CsvTable extends AbstractTable {
     }
 
     @Override
-    public Relationship[] getRelationships() {
-        return new Relationship[0];
+    public Collection<Relationship> getRelationships() {
+        return Lists.newArrayList();
     }
 
     @Override
index 250c249..4b24892 100644 (file)
@@ -20,11 +20,14 @@ package org.apache.metamodel.csv;
 
 import java.io.BufferedReader;
 import java.io.IOException;
+import java.util.List;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.MetaModelException;
 import org.apache.metamodel.data.AbstractDataSet;
 import org.apache.metamodel.data.DataSetHeader;
 import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.SelectItem;
 import org.apache.metamodel.schema.Column;
 import org.apache.metamodel.util.FileHelper;
 
@@ -46,9 +49,9 @@ final class SingleLineCsvDataSet extends AbstractDataSet {
     private volatile Integer _rowsRemaining;
     private volatile Row _row;
 
-    public SingleLineCsvDataSet(BufferedReader reader, ICSVParser csvParser, Column[] columns, Integer maxRows,
-            int columnsInTable, boolean failOnInconsistentRowLength) {
-        super(columns);
+    public SingleLineCsvDataSet(BufferedReader reader, ICSVParser csvParser, List<Column> columns, Integer maxRows,
+                                int columnsInTable, boolean failOnInconsistentRowLength) {
+        super(columns.stream().map(SelectItem::new).collect(Collectors.toList()));
         _reader = reader;
         _csvParser = csvParser;
         _columnsInTable = columnsInTable;
index cf76c75..5c7d229 100644 (file)
@@ -62,7 +62,7 @@ public class CsvBigFileMemoryTest extends TestCase {
         System.out.println("time at start: " + timeAtStart);
 
         final DataContext dc = new CsvDataContext(file, new CsvConfiguration(1, false, false));
-        final Table t = dc.getDefaultSchema().getTables()[0];
+        final Table t = dc.getDefaultSchema().getTables().get(0);
 
         final long timeAfterDataContext = System.currentTimeMillis();
         System.out.println("time after DataContext: " + timeAfterDataContext);
@@ -116,7 +116,7 @@ public class CsvBigFileMemoryTest extends TestCase {
     public void testApproximatedCountHugeFile() throws Exception {
         DataContext dc = new CsvDataContext(getHugeFile());
 
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
         Query q = dc.query().from(table).selectCount().toQuery();
         SelectItem selectItem = q.getSelectClause().getItem(0);
         selectItem.setFunctionApproximationAllowed(true);
index 39f9d43..029a179 100644 (file)
@@ -79,10 +79,10 @@ public class CsvDataContextTest extends TestCase {
         
         CsvDataContext dc1 = new CsvDataContext(file, csvConfiguration);
 
-        Table[] tables = dc1.getDefaultSchema().getTables();
-        assertEquals(1, tables.length);
+        List<Table> tables = dc1.getDefaultSchema().getTables();
+        assertEquals(1, tables.size());
         
-        Table table = tables[0];
+        Table table = tables.get(0);
         assertEquals("testEmptyFileNoColumnHeaderLine.csv", table.getName());
         assertEquals(2, table.getColumnCount());
         
@@ -100,7 +100,7 @@ public class CsvDataContextTest extends TestCase {
         final CsvDataContext dc = new CsvDataContext(file);
         assertEquals(1, dc.getDefaultSchema().getTableCount());
 
-        final Table table1 = dc.getDefaultSchema().getTables()[0];
+        final Table table1 = dc.getDefaultSchema().getTables().get(0);
         assertEquals("testEmptyFileNoColumnHeaderLine.csv", table1.getName());
         assertEquals(0, table1.getColumnCount());
 
@@ -139,7 +139,7 @@ public class CsvDataContextTest extends TestCase {
                 .replaceAll("\n", "!LINEBREAK!"));
 
         final CsvDataContext dc = new CsvDataContext(targetFile);
-        final Table table = dc.getDefaultSchema().getTables()[0];
+        final Table table = dc.getDefaultSchema().getTables().get(0);
 
         dc.executeUpdate(new UpdateScript() {
             @Override
@@ -181,7 +181,7 @@ public class CsvDataContextTest extends TestCase {
                 CsvConfiguration.NO_COLUMN_NAME_LINE));
         assertEquals(1, dc.getDefaultSchema().getTableCount());
 
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
         assertEquals("empty_file.csv", table.getName());
         assertEquals(0, table.getColumnCount());
     }
@@ -190,7 +190,7 @@ public class CsvDataContextTest extends TestCase {
         DataContext dc = new CsvDataContext(new File("src/test/resources/csv_people.csv"), new CsvConfiguration(20));
         assertEquals(1, dc.getDefaultSchema().getTableCount());
 
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
         assertEquals("csv_people.csv", table.getName());
         assertEquals(0, table.getColumnCount());
     }
@@ -236,7 +236,7 @@ public class CsvDataContextTest extends TestCase {
     public void testApproximatedCountSmallFile() throws Exception {
         DataContext dc = new CsvDataContext(new File("src/test/resources/csv_people.csv"));
 
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
         Query q = dc.query().from(table).selectCount().toQuery();
         SelectItem selectItem = q.getSelectClause().getItem(0);
         selectItem.setFunctionApproximationAllowed(true);
@@ -252,7 +252,7 @@ public class CsvDataContextTest extends TestCase {
 
     public void testFilterOnNumberColumn() throws Exception {
         CsvDataContext dc = new CsvDataContext(new File("src/test/resources/csv_people.csv"));
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
 
         Query q = dc.query().from(table).select("name").where("age").greaterThan(18).toQuery();
         List<Object[]> result = dc.executeQuery(q).toObjectArrays();
@@ -297,7 +297,7 @@ public class CsvDataContextTest extends TestCase {
     }
 
     public void doTicketFileTests(DataContext dc) {
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
         Query q = dc.query().from(table).select(table.getColumns()).toQuery();
 
         DataSet dataSet = dc.executeQuery(q);
@@ -318,18 +318,18 @@ public class CsvDataContextTest extends TestCase {
     public void testHighColumnNameLineNumber() throws Exception {
         File file = new File("src/test/resources/csv_people.csv");
         QueryPostprocessDataContext dc = new CsvDataContext(file, new CsvConfiguration(3));
-        Schema[] schemas = dc.getSchemas();
-        assertEquals(2, schemas.length);
+
+        assertEquals(2, dc.getSchemas().size());
         Schema schema = dc.getDefaultSchema();
         assertEquals("resources", schema.getName());
         assertEquals(1, schema.getTableCount());
-        Table table = schema.getTables()[0];
+        Table table = schema.getTables().get(0);
         assertEquals("csv_people.csv", table.getName());
 
         assertEquals(4, table.getColumnCount());
         assertEquals(0, table.getRelationshipCount());
 
-        Column[] columns = table.getColumns();
+        Column[] columns = table.getColumns().toArray(new Column[0]);
         assertEquals("2", columns[0].getName());
         assertEquals("michael", columns[1].getName());
         assertEquals("male", columns[2].getName());
@@ -350,18 +350,17 @@ public class CsvDataContextTest extends TestCase {
         File file = new File("src/test/resources/csv_people.csv");
         QueryPostprocessDataContext dc = new CsvDataContext(file, new CsvConfiguration(
                 CsvConfiguration.NO_COLUMN_NAME_LINE));
-        Schema[] schemas = dc.getSchemas();
-        assertEquals(2, schemas.length);
+        assertEquals(2, dc.getSchemas().size());
         Schema schema = dc.getDefaultSchema();
         assertEquals("resources", schema.getName());
         assertEquals(1, schema.getTableCount());
-        Table table = schema.getTables()[0];
+        Table table = schema.getTables().get(0);
         assertEquals("csv_people.csv", table.getName());
 
         assertEquals(4, table.getColumnCount());
         assertEquals(0, table.getRelationshipCount());
 
-        Column[] columns = table.getColumns();
+        Column[] columns = table.getColumns().toArray(new Column[0]);
         assertEquals("A", columns[0].getName());
         assertEquals("B", columns[1].getName());
         assertEquals("C", columns[2].getName());
@@ -381,18 +380,17 @@ public class CsvDataContextTest extends TestCase {
     public void testGetSchemas() throws Exception {
         File file = new File("src/test/resources/csv_people.csv");
         QueryPostprocessDataContext dc = new CsvDataContext(file);
-        Schema[] schemas = dc.getSchemas();
-        assertEquals(2, schemas.length);
+        assertEquals(2, dc.getSchemas().size());
         Schema schema = dc.getDefaultSchema();
         assertEquals("resources", schema.getName());
         assertEquals(1, schema.getTableCount());
-        Table table = schema.getTables()[0];
+        Table table = schema.getTables().get(0);
         assertEquals("csv_people.csv", table.getName());
 
         assertEquals(4, table.getColumnCount());
         assertEquals(0, table.getRelationshipCount());
 
-        Column[] columns = table.getColumns();
+        Column[] columns = table.getColumns().toArray(new Column[0]);
         assertEquals("id", columns[0].getName());
         assertEquals("name", columns[1].getName());
         assertEquals("gender", columns[2].getName());
@@ -452,7 +450,7 @@ public class CsvDataContextTest extends TestCase {
         DataSet data = dc.executeQuery(q);
         assertEquals(
                 "[csv_people.csv.gender, MAX(csv_people.csv.age), MIN(csv_people.csv.age), COUNT(*) AS total, MIN(csv_people.csv.id) AS firstId]",
-                Arrays.toString(data.getSelectItems()));
+                Arrays.toString(data.getSelectItems().toArray()));
 
         String[] expectations = new String[] { "Row[values=[female, 20, 17, 5, 5]]", "Row[values=[male, 19, 17, 4, 1]]" };
 
@@ -466,7 +464,7 @@ public class CsvDataContextTest extends TestCase {
     public void testMaterializeTable() throws Exception {
         File file = new File("src/test/resources/csv_people.csv");
         CsvDataContext dc = new CsvDataContext(file, new CsvConfiguration(1, false, false));
-        Table table = dc.getSchemas()[0].getTables()[0];
+        Table table = dc.getSchemas().get(0).getTables().get(0);
         DataSet dataSet = dc.materializeMainSchemaTable(table, table.getColumns(), -1);
         assertNull(dataSet.getRow());
         assertTrue(dataSet.next());
@@ -494,7 +492,7 @@ public class CsvDataContextTest extends TestCase {
     public void testAlternativeDelimitors() throws Exception {
         File file = new File("src/test/resources/csv_semicolon_singlequote.csv");
         CsvDataContext dc = new CsvDataContext(file, semicolonConfiguration);
-        Table table = dc.getSchemas()[0].getTables()[0];
+        Table table = dc.getSchemas().get(0).getTables().get(0);
         DataSet dataSet = dc.materializeMainSchemaTable(table, table.getColumns(), -1);
         assertTrue(dataSet.next());
         assertEquals("Row[values=[1, mike, male, 18]]", dataSet.getRow().toString());
@@ -517,7 +515,7 @@ public class CsvDataContextTest extends TestCase {
     public void testMaxRows() throws Exception {
         File file = new File("src/test/resources/csv_semicolon_singlequote.csv");
         CsvDataContext dc = new CsvDataContext(file, semicolonConfiguration);
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
         Query query = new Query().from(table).select(table.getColumns()).setMaxRows(5);
         DataSet dataSet = dc.executeQuery(query);
 
@@ -528,7 +526,7 @@ public class CsvDataContextTest extends TestCase {
     public void testQueryOnlyAggregate() throws Exception {
         File file = new File("src/test/resources/csv_people.csv");
         QueryPostprocessDataContext dc = new CsvDataContext(file);
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
 
         Query q = new Query().selectCount().from(table);
         assertEquals("SELECT COUNT(*) FROM resources.csv_people.csv", q.toString());
@@ -539,7 +537,7 @@ public class CsvDataContextTest extends TestCase {
         assertEquals(1, row.length);
         assertEquals("[9]", Arrays.toString(row));
 
-        q.select(table.getColumns()[0]);
+        q.select(table.getColumns().get(0));
         assertEquals("SELECT COUNT(*), csv_people.csv.id FROM resources.csv_people.csv", q.toString());
         data = dc.executeQuery(q).toObjectArrays();
         assertEquals(9, data.size());
@@ -563,7 +561,7 @@ public class CsvDataContextTest extends TestCase {
     public void testOffsetAndMaxrows() throws Exception {
         DataContext dc = new CsvDataContext(new File("src/test/resources/csv_people.csv"));
 
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
         Query q = dc.query().from(table).select(table.getColumnByName("name")).toQuery();
         q.setFirstRow(3);
         q.setMaxRows(2);
@@ -571,7 +569,7 @@ public class CsvDataContextTest extends TestCase {
         DataSet ds;
 
         ds = dc.executeQuery(q);
-        assertEquals(1, ds.getSelectItems().length);
+        assertEquals(1, ds.getSelectItems().size());
         assertTrue(ds.next());
         assertEquals("peter", ds.getRow().getValue(0).toString());
         assertTrue(ds.next());
@@ -594,7 +592,7 @@ public class CsvDataContextTest extends TestCase {
         FileHelper.copy(new File("src/test/resources/csv_to_be_truncated.csv"), file);
 
         CsvDataContext dc = new CsvDataContext(file, new CsvConfiguration(1, "UTF8", ',', '"', '\\', true));
-        assertEquals("[id, name, gender, age]", Arrays.toString(dc.getDefaultSchema().getTable(0).getColumnNames()));
+        assertEquals("[id, name, gender, age]", Arrays.toString(dc.getDefaultSchema().getTable(0).getColumnNames().toArray()));
 
         dc.executeUpdate(new UpdateScript() {
             @Override
@@ -628,10 +626,10 @@ public class CsvDataContextTest extends TestCase {
                 Table table = cb.createTable(schema, "foobar").withColumn("foo").withColumn("bar").execute();
                 tableRef.set(table);
                 assertEquals(schema, table.getSchema());
-                assertEquals(schema.getTables()[0], table);
+                assertEquals(schema.getTables().get(0), table);
                 assertTrue(file.exists());
 
-                assertEquals("[foo, bar]", Arrays.toString(table.getColumnNames()));
+                assertEquals("[foo, bar]", Arrays.toString(table.getColumnNames().toArray()));
 
                 cb.insertInto(table).value(0, "f").value(1, "b").execute();
                 cb.insertInto(table).value(0, "o").value(table.getColumnByName("bar"), "a").execute();
@@ -640,9 +638,9 @@ public class CsvDataContextTest extends TestCase {
         });
 
         // query the file to check results
-        final Table readTable = schema.getTables()[0];
+        final Table readTable = schema.getTables().get(0);
         assertEquals(tableRef.get(), readTable);
-        assertEquals("[foo, bar]", Arrays.toString(readTable.getColumnNames()));
+        assertEquals("[foo, bar]", Arrays.toString(readTable.getColumnNames().toArray()));
 
         final Query query = dc.query().from(readTable).select("bar").and("foo").toQuery();
         DataSet ds = dc.executeQuery(query);
@@ -723,15 +721,15 @@ public class CsvDataContextTest extends TestCase {
     public void testOnlyNumberOneSymbol() throws Exception {
         DataContext dc = new CsvDataContext(new File("src/test/resources/csv_only_number_one.csv"));
         Map<Column, TypeConverter<?, ?>> converters = Converters.autoDetectConverters(dc, dc.getDefaultSchema()
-                .getTables()[0], 1000);
+                .getTables().get(0), 1000);
 
         assertEquals(1, converters.size());
         assertEquals(StringToBooleanConverter.class, converters.values().iterator().next().getClass());
 
         dc = Converters.addTypeConverters(dc, converters);
 
-        Table table = dc.getDefaultSchema().getTables()[0];
-        MutableColumn col = (MutableColumn) table.getColumns()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
+        MutableColumn col = (MutableColumn) table.getColumns().get(0);
         Query q = dc.query().from(table).select(col).toQuery();
         assertEquals("SELECT csv_only_number_one.csv.number FROM resources.csv_only_number_one.csv", q.toSql());
 
index a01821c..0686cab 100644 (file)
@@ -22,7 +22,9 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.util.List;
 
+import com.google.common.collect.Lists;
 import org.apache.metamodel.data.Row;
 import org.apache.metamodel.schema.Column;
 import org.apache.metamodel.schema.MutableColumn;
@@ -35,7 +37,7 @@ public class SingleLineCsvRowTest {
 
     @Test
     public void testSerialize() throws Exception {
-        final Column[] columns = new Column[] { new MutableColumn("1"), new MutableColumn("2") };
+        final List<Column> columns = Lists.newArrayList( new MutableColumn("1"), new MutableColumn("2"));
         CSVParser csvParser = new CSVParser();
         final SingleLineCsvDataSet dataSet = new SingleLineCsvDataSet(null, csvParser, columns, null, 2, false);
         final SingleLineCsvRow originalRow = new SingleLineCsvRow(dataSet, "foo,bar", 2, false, 1);
index 7974beb..06c1822 100644 (file)
@@ -68,10 +68,10 @@ public class InterceptionCsvIntegrationTest extends TestCase {
                });
 
                assertEquals("[table]",
-                               Arrays.toString(dc.getDefaultSchema().getTableNames()));
-               Table table = dc.getDefaultSchema().getTables()[0];
+                               Arrays.toString(dc.getDefaultSchema().getTableNames().toArray()));
+               Table table = dc.getDefaultSchema().getTables().get(0);
                assertEquals("[col1, col2, foobar]",
-                               Arrays.toString(table.getColumnNames()));
+                               Arrays.toString(table.getColumnNames().toArray()));
 
                DataSet ds = dc.query().from(table).select(table.getColumns())
                                .execute();
index 255120c..504769d 100644 (file)
@@ -24,6 +24,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.MetaModelException;
 import org.apache.metamodel.QueryPostprocessDataContext;
@@ -257,11 +258,8 @@ public class DynamoDbDataContext extends QueryPostprocessDataContext implements
     }
 
     @Override
-    protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
-        final List<String> attributeNames = new ArrayList<>(columns.length);
-        for (final Column column : columns) {
-            attributeNames.add(column.getName());
-        }
+    protected DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) {
+        final List<String> attributeNames = columns.stream().map(col-> col.getName()).collect(Collectors.toList());
         final ScanRequest scanRequest = new ScanRequest(table.getName());
         scanRequest.setAttributesToGet(attributeNames);
         if (maxRows > 0) {
index 17b781b..887b3e4 100644 (file)
 package org.apache.metamodel.dynamodb;
 
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.data.AbstractDataSet;
 import org.apache.metamodel.data.DataSetHeader;
 import org.apache.metamodel.data.DefaultRow;
 import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.SelectItem;
 import org.apache.metamodel.schema.Column;
 
 import com.amazonaws.services.dynamodbv2.model.AttributeValue;
@@ -35,8 +38,8 @@ final class DynamoDbDataSet extends AbstractDataSet {
     private final Iterator<Map<String, AttributeValue>> _iterator;
     private Map<String, AttributeValue> _currentItem;
 
-    public DynamoDbDataSet(Column[] columns, ScanResult result) {
-        super(columns);
+    public DynamoDbDataSet(List<Column> columns, ScanResult result) {
+        super(columns.stream().map(SelectItem::new).collect(Collectors.toList()));
         _iterator = result.getItems().iterator();
     }
 
index c9779df..f989b5d 100644 (file)
@@ -63,8 +63,7 @@ class DynamoDbTableCreationBuilder extends AbstractTableCreationBuilder<DynamoDb
                 DynamoDbDataContext.SYSTEM_PROPERTY_THROUGHPUT_WRITE_CAPACITY, "5"));
         final ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput(readCapacity, writeCapacity);
 
-        final Column[] columns = table.getColumns();
-        for (Column column : columns) {
+        for (Column column : table.getColumns()) {
             if (column.isPrimaryKey()) {
                 final KeyType keyType = getKeyType(column.getRemarks());
                 keySchema.add(new KeySchemaElement(column.getName(), keyType));
index 967655d..ba60096 100644 (file)
@@ -147,7 +147,7 @@ public class DynamoDbDataContextIntegrationTest {
                 assertEquals(tableName, table.getName());
 
                 // Right now we can only discover indexed columns
-                assertEquals("[id, counter, project, foundation]", Arrays.toString(table.getColumnNames()));
+                assertEquals("[id, counter, project, foundation]", Arrays.toString(table.getColumnNames().toArray()));
 
                 final Column idColumn = table.getColumnByName("id");
                 assertEquals(true, idColumn.isPrimaryKey());
index 7353cbd..83d89c7 100644 (file)
@@ -24,6 +24,7 @@ import java.util.Arrays;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.DataContext;
 import org.apache.metamodel.MetaModelException;
@@ -253,7 +254,7 @@ public class ElasticSearchDataContext extends QueryPostprocessDataContext implem
             dynamicTableDefinitions.clear();
             dynamicTableDefinitions.addAll(Arrays.asList(tables));
             for (final SimpleTableDef tableDef : dynamicTableDefinitions) {
-                final List<String> tableNames = Arrays.asList(theSchema.getTableNames());
+                final List<String> tableNames = theSchema.getTableNames();
 
                 if (!tableNames.contains(tableDef.getName())) {
                     addTable(theSchema, tableDef);
@@ -294,10 +295,10 @@ public class ElasticSearchDataContext extends QueryPostprocessDataContext implem
     }
 
     @Override
-    protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+    protected DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) {
         final SearchRequestBuilder searchRequest = createSearchRequest(table, 1, maxRows, null);
         final SearchResponse response = searchRequest.execute().actionGet();
-        return new ElasticSearchDataSet(elasticSearchClient, response, columns, false);
+        return new ElasticSearchDataSet(elasticSearchClient, response, columns.stream().map(SelectItem::new).collect(Collectors.toList()), false);
     }
 
     private SearchRequestBuilder createSearchRequest(Table table, int firstRow, int maxRows, QueryBuilder queryBuilder) {
index 7f4048a..1a04bc8 100644 (file)
@@ -55,14 +55,7 @@ final class ElasticSearchDataSet extends AbstractDataSet {
         _searchResponse = searchResponse;
         _closed = new AtomicBoolean(false);
     }
-    
-    public ElasticSearchDataSet(Client client, SearchResponse searchResponse, Column[] columns,
-            boolean queryPostProcessed) {
-        super(columns);
-        _client = client;
-        _searchResponse = searchResponse;
-        _closed = new AtomicBoolean(false);
-    }
+
 
     @Override
     public void close() {
index 8a83263..ec5ecba 100644 (file)
@@ -125,11 +125,11 @@ public class ElasticSearchDataContextTest {
     @Test
     public void testSimpleQuery() throws Exception {
         assertEquals("[bulktype, peopletype, tweet1, tweet2]",
-                Arrays.toString(dataContext.getDefaultSchema().getTableNames()));
+                Arrays.toString(dataContext.getDefaultSchema().getTableNames().toArray()));
 
         Table table = dataContext.getDefaultSchema().getTableByName("tweet1");
 
-        assertEquals("[_id, message, postDate, user]", Arrays.toString(table.getColumnNames()));
+        assertEquals("[_id, message, postDate, user]", Arrays.toString(table.getColumnNames().toArray()));
 
         assertEquals(ColumnType.STRING, table.getColumnByName("user").getType());
         assertEquals(ColumnType.DATE, table.getColumnByName("postDate").getType());
@@ -146,7 +146,7 @@ public class ElasticSearchDataContextTest {
     @Test
     public void testDocumentIdAsPrimaryKey() throws Exception {
         Table table = dataContext.getDefaultSchema().getTableByName("tweet2");
-        Column[] pks = table.getPrimaryKeys();
+        Column[] pks = table.getPrimaryKeys().toArray(new Column[0]);
         assertEquals(1, pks.length);
         assertEquals("_id", pks[0].getName());
 
@@ -159,7 +159,7 @@ public class ElasticSearchDataContextTest {
     @Test
     public void testExecutePrimaryKeyLookupQuery() throws Exception {
         Table table = dataContext.getDefaultSchema().getTableByName("tweet2");
-        Column[] pks = table.getPrimaryKeys();
+        Column[] pks = table.getPrimaryKeys().toArray(new Column[0]);
 
         try (DataSet ds = dataContext.query().from(table).selectAll().where(pks[0]).eq("tweet_tweet2_1").execute()) {
             assertTrue(ds.next());
@@ -209,10 +209,10 @@ public class ElasticSearchDataContextTest {
         dataContext.executeUpdate(createTable);
 
         final Table table = schema.getTableByName("testCreateTable");
-        assertEquals("[" + ElasticSearchUtils.FIELD_ID + ", foo, bar]", Arrays.toString(table.getColumnNames()));
+        assertEquals("[" + ElasticSearchUtils.FIELD_ID + ", foo, bar]", Arrays.toString(table.getColumnNames().toArray()));
 
         final Column fooColumn = table.getColumnByName("foo");
-        final Column idColumn = table.getPrimaryKeys()[0];
+        final Column idColumn = table.getPrimaryKeys().get(0);
         assertEquals("Column[name=_id,columnNumber=0,type=STRING,nullable=null,nativeType=null,columnSize=null]",
                 idColumn.toString());
 
@@ -491,7 +491,7 @@ public class ElasticSearchDataContextTest {
         DataSet data = dataContext.executeQuery(q);
         assertEquals(
                 "[peopletype.gender, MAX(peopletype.age), MIN(peopletype.age), COUNT(*) AS total, MIN(peopletype.id) AS firstId]",
-                Arrays.toString(data.getSelectItems()));
+                Arrays.toString(data.getSelectItems().toArray()));
 
         assertTrue(data.next());
         assertEquals("Row[values=[female, 20, 17, 5, 5]]", data.getRow().toString());
@@ -553,7 +553,7 @@ public class ElasticSearchDataContextTest {
 
         ElasticSearchDataContext dataContext2 = new ElasticSearchDataContext(client, indexName2);
 
-        assertEquals("[tweet3]", Arrays.toString(dataContext2.getDefaultSchema().getTableNames()));
+        assertEquals("[tweet3]", Arrays.toString(dataContext2.getDefaultSchema().getTableNames().toArray()));
     }
 
     private static void createIndex() {
index 57ad267..8d89c05 100644 (file)
@@ -25,6 +25,7 @@ import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.BatchUpdateScript;
 import org.apache.metamodel.DataContext;
@@ -234,7 +235,7 @@ public class ElasticSearchRestDataContext extends QueryPostprocessDataContext im
             dynamicTableDefinitions.clear();
             dynamicTableDefinitions.addAll(Arrays.asList(tables));
             for (final SimpleTableDef tableDef : dynamicTableDefinitions) {
-                final List<String> tableNames = Arrays.asList(theSchema.getTableNames());
+                final List<String> tableNames = theSchema.getTableNames();
 
                 if (!tableNames.contains(tableDef.getName())) {
                     addTable(theSchema, tableDef);
@@ -299,11 +300,11 @@ public class ElasticSearchRestDataContext extends QueryPostprocessDataContext im
     }
 
     @Override
-    protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+    protected DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) {
         SearchResult searchResult = executeSearch(table, createSearchRequest(1, maxRows, null), scrollNeeded(
                 maxRows));
 
-        return new JestElasticSearchDataSet(elasticSearchClient, searchResult, columns);
+        return new JestElasticSearchDataSet(elasticSearchClient, searchResult, columns.stream().map(SelectItem::new).collect(Collectors.toList()));
     }
 
     private SearchSourceBuilder createSearchRequest(int firstRow, int maxRows, QueryBuilder queryBuilder) {
index 7f485ba..0414358 100644 (file)
@@ -56,12 +56,6 @@ final class JestElasticSearchDataSet extends AbstractDataSet {
         _closed = new AtomicBoolean(false);
     }
 
-    public JestElasticSearchDataSet(JestClient client, JestResult searchResponse, Column[] columns) {
-        super(columns);
-        _client = client;
-        _searchResponse = searchResponse;
-        _closed = new AtomicBoolean(false);
-    }
 
     @Override
     public void close() {
index 9d7d2a8..53dbdf6 100644 (file)
@@ -124,11 +124,11 @@ public class JestElasticSearchDataContextTest {
     @Test
     public void testSimpleQuery() throws Exception {
         assertEquals("[bulktype, peopletype, tweet1, tweet2]",
-                Arrays.toString(dataContext.getDefaultSchema().getTableNames()));
+                Arrays.toString(dataContext.getDefaultSchema().getTableNames().toArray()));
 
         Table table = dataContext.getDefaultSchema().getTableByName("tweet1");
 
-        assertEquals("[_id, message, postDate, user]", Arrays.toString(table.getColumnNames()));
+        assertEquals("[_id, message, postDate, user]", Arrays.toString(table.getColumnNames().toArray()));
 
         assertEquals(ColumnType.STRING, table.getColumnByName("user").getType());
         assertEquals(ColumnType.DATE, table.getColumnByName("postDate").getType());
@@ -145,7 +145,7 @@ public class JestElasticSearchDataContextTest {
     @Test
     public void testDocumentIdAsPrimaryKey() throws Exception {
         Table table = dataContext.getDefaultSchema().getTableByName("tweet2");
-        Column[] pks = table.getPrimaryKeys();
+        Column[] pks = table.getPrimaryKeys().toArray(new Column[0]);
         assertEquals(1, pks.length);
         assertEquals("_id", pks[0].getName());
 
@@ -158,7 +158,7 @@ public class JestElasticSearchDataContextTest {
     @Test
     public void testExecutePrimaryKeyLookupQuery() throws Exception {
         Table table = dataContext.getDefaultSchema().getTableByName("tweet2");
-        Column[] pks = table.getPrimaryKeys();
+        Column[] pks = table.getPrimaryKeys().toArray(new Column[0]);
 
         try (DataSet ds = dataContext.query().from(table).selectAll().where(pks[0]).eq("tweet_tweet2_1").execute()) {
             assertTrue(ds.next());
@@ -209,10 +209,10 @@ public class JestElasticSearchDataContextTest {
 
         final Table table = schema.getTableByName("testCreateTable");
         assertNotNull(table);
-        assertEquals("[" + ElasticSearchRestDataContext.FIELD_ID + ", foo, bar]", Arrays.toString(table.getColumnNames()));
+        assertEquals("[" + ElasticSearchRestDataContext.FIELD_ID + ", foo, bar]", Arrays.toString(table.getColumnNames().toArray()));
 
         final Column fooColumn = table.getColumnByName("foo");
-        final Column idColumn = table.getPrimaryKeys()[0];
+        final Column idColumn = table.getPrimaryKeys().get(0);
         assertEquals("Column[name=_id,columnNumber=0,type=STRING,nullable=null,nativeType=null,columnSize=null]",
                 idColumn.toString());
 
@@ -490,7 +490,7 @@ public class JestElasticSearchDataContextTest {
         DataSet data = dataContext.executeQuery(q);
         assertEquals(
                 "[peopletype.gender, MAX(peopletype.age), MIN(peopletype.age), COUNT(*) AS total, MIN(peopletype.id) AS firstId]",
-                Arrays.toString(data.getSelectItems()));
+                Arrays.toString(data.getSelectItems().toArray()));
 
         assertTrue(data.next());
         assertEquals("Row[values=[female, 20, 17, 5, 5]]", data.getRow().toString());
@@ -552,7 +552,7 @@ public class JestElasticSearchDataContextTest {
 
         ElasticSearchRestDataContext dataContext2 = new ElasticSearchRestDataContext(client, indexName2);
 
-        assertEquals("[tweet3]", Arrays.toString(dataContext2.getDefaultSchema().getTableNames()));
+        assertEquals("[tweet3]", Arrays.toString(dataContext2.getDefaultSchema().getTableNames().toArray()));
     }
 
     private static void createIndex() {
index f114826..4c8cca1 100644 (file)
@@ -26,7 +26,9 @@ import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
+import com.google.common.collect.Lists;
 import org.apache.metamodel.data.DataSetHeader;
 import org.apache.metamodel.data.Row;
 import org.apache.metamodel.data.SimpleDataSetHeader;
@@ -62,7 +64,7 @@ public class JestElasticSearchUtilsTest {
     public void testCreateRowWithNullValues() throws Exception {
         final Column col1 = new MutableColumn("col1", ColumnType.STRING);
         final Column col2 = new MutableColumn("col2", ColumnType.STRING);
-        final DataSetHeader header = new SimpleDataSetHeader(new Column[] { col1, col2 });
+        final DataSetHeader header = new SimpleDataSetHeader(Lists.newArrayList(col1, col2).stream().map(SelectItem::new).collect(Collectors.toList()));
         final JsonObject source = new JsonObject();
         source.addProperty("col1", "foo");
         source.addProperty("col2", (String) null);
@@ -75,7 +77,7 @@ public class JestElasticSearchUtilsTest {
     @Test
     public void testCreateRowWithNumberValueAndStringType() throws Exception {
         final Column col1 = new MutableColumn("col1", ColumnType.STRING);
-        final DataSetHeader header = new SimpleDataSetHeader(new Column[] { col1 });
+        final DataSetHeader header =  SimpleDataSetHeader.fromColumns(Lists.newArrayList(col1));
         final JsonObject source = new JsonObject();
         source.addProperty("col1", 42);
         final String documentId = "row1";
@@ -87,7 +89,7 @@ public class JestElasticSearchUtilsTest {
     @Test
     public void testCreateRowWithStringValueAndNumberType() throws Exception {
         final Column col1 = new MutableColumn("col1", ColumnType.NUMBER);
-        final DataSetHeader header = new SimpleDataSetHeader(new Column[] { col1 });
+        final DataSetHeader header = SimpleDataSetHeader.fromColumns(Lists.newArrayList(col1));
         final JsonObject source = new JsonObject();
         source.addProperty("col1", "hello world");
         final String documentId = "row1";
@@ -104,7 +106,7 @@ public class JestElasticSearchUtilsTest {
     @Test
     public void testCreateRowWithJsonObject() throws Exception {
         final Column col1 = new MutableColumn("col1", ColumnType.MAP);
-        final DataSetHeader header = new SimpleDataSetHeader(new Column[] { col1 });
+        final DataSetHeader header = SimpleDataSetHeader.fromColumns(Lists.newArrayList(col1));
         final JsonObject source = new JsonObject();
         final JsonObject value = new JsonObject();
         value.addProperty("foo1", "bar");
@@ -122,7 +124,7 @@ public class JestElasticSearchUtilsTest {
     @Test
     public void testCreateRowWithJsonArray() throws Exception {
         final Column col1 = new MutableColumn("col1", ColumnType.LIST);
-        final DataSetHeader header = new SimpleDataSetHeader(new Column[] { col1 });
+        final DataSetHeader header = SimpleDataSetHeader.fromColumns(Lists.newArrayList(col1));
         final JsonObject source = new JsonObject();
         final JsonArray value = new JsonArray();
         value.add(new JsonPrimitive("foo"));
@@ -140,7 +142,7 @@ public class JestElasticSearchUtilsTest {
     @Test
     public void testCreateRowWithDeepNesting() throws Exception {
         final Column col1 = new MutableColumn("col1", ColumnType.LIST);
-        final DataSetHeader header = new SimpleDataSetHeader(new Column[] { col1 });
+        final DataSetHeader header = SimpleDataSetHeader.fromColumns(Lists.newArrayList(col1));
         final JsonObject source = new JsonObject();
 
         final JsonObject obj2 = new JsonObject();
index 009fad4..934d47c 100644 (file)
 package org.apache.metamodel.excel;
 
 import java.util.Iterator;
+import java.util.List;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.data.DataSet;
 import org.apache.metamodel.data.EmptyDataSet;
 import org.apache.metamodel.data.MaxRowsDataSet;
+import org.apache.metamodel.query.SelectItem;
 import org.apache.metamodel.schema.Column;
 import org.apache.metamodel.schema.ColumnType;
 import org.apache.metamodel.schema.MutableColumn;
@@ -78,12 +81,12 @@ final class DefaultSpreadsheetReaderDelegate implements SpreadsheetReaderDelegat
     }
 
     @Override
-    public DataSet executeQuery(Table table, Column[] columns, int maxRows) {
+    public DataSet executeQuery(Table table, List<Column> columns, int maxRows) {
         final Workbook wb = ExcelUtils.readWorkbook(_resource);
         final Sheet sheet = wb.getSheet(table.getName());
 
         if (sheet == null || sheet.getPhysicalNumberOfRows() == 0) {
-            return new EmptyDataSet(columns);
+            return new EmptyDataSet(columns.stream().map(SelectItem::new).collect(Collectors.toList()));
         }
 
         DataSet dataSet = ExcelUtils.getDataSet(wb, sheet, table, _configuration);
index 9ef931b..1ce4244 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.metamodel.excel;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.List;
 
 import org.apache.metamodel.DataContext;
 import org.apache.metamodel.MetaModelException;
@@ -128,7 +129,7 @@ public final class ExcelDataContext extends QueryPostprocessDataContext implemen
     }
 
     @Override
-    public DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+    public DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) {
         try {
             SpreadsheetReaderDelegate delegate = getSpreadsheetReaderDelegate();
 
index 7d835c7..e4731b3 100644 (file)
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
@@ -55,7 +56,7 @@ final class ExcelDeleteBuilder extends AbstractRowDeletionBuilder {
         final Workbook workbook = _updateCallback.getWorkbook(false);
 
         final String tableName = getTable().getName();
-        final SelectItem[] selectItems = MetaModelHelper.createSelectItems(getTable().getColumns());
+        final List<SelectItem> selectItems = getTable().getColumns().stream().map(SelectItem::new).collect(Collectors.toList());
         final DataSetHeader header = new SimpleDataSetHeader(selectItems);
         final Sheet sheet = workbook.getSheet(tableName);
 
index 765886e..2d68a69 100644 (file)
@@ -48,9 +48,7 @@ final class ExcelTableCreationBuilder extends AbstractTableCreationBuilder<Excel
         if (lineNumber != ExcelConfiguration.NO_COLUMN_NAME_LINE) {
             final int zeroBasedLineNumber = lineNumber - 1;
             final Row row = sheet.createRow(zeroBasedLineNumber);
-            final Column[] columns = table.getColumns();
-            for (int i = 0; i < columns.length; i++) {
-                final Column column = columns[i];
+            for (final Column column : table.getColumns()) {
                 final int columnNumber = column.getColumnNumber();
                 row.createCell(columnNumber).setCellValue(column.getName());
             }
index 7504d64..1f424d6 100644 (file)
@@ -24,6 +24,8 @@ import java.io.OutputStream;
 import java.text.NumberFormat;
 import java.util.Date;
 import java.util.Iterator;
+import java.util.List;
+import java.util.stream.Collectors;
 
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
@@ -440,7 +442,7 @@ final class ExcelUtils {
     }
 
     public static DataSet getDataSet(Workbook workbook, Sheet sheet, Table table, ExcelConfiguration configuration) {
-        final SelectItem[] selectItems = MetaModelHelper.createSelectItems(table.getColumns());
+        final List<SelectItem> selectItems = table.getColumns().stream().map(SelectItem::new).collect(Collectors.toList());
         final Iterator<Row> rowIterator = getRowIterator(sheet, configuration, true);
         if (!rowIterator.hasNext()) {
             // no more rows!
index 1181b07..5fdd7ec 100644 (file)
@@ -23,6 +23,8 @@ import org.apache.metamodel.schema.Column;
 import org.apache.metamodel.schema.Schema;
 import org.apache.metamodel.schema.Table;
 
+import java.util.List;
+
 /**
  * Delegate for spreadsheet-implementation specific operations in an
  * {@link ExcelDataContext}.
@@ -33,6 +35,6 @@ interface SpreadsheetReaderDelegate {
 
     public Schema createSchema(String schemaName) throws Exception;
 
-    public DataSet executeQuery(Table table, Column[] columns, int maxRows) throws Exception;
+    public DataSet executeQuery(Table table, List<Column> columns, int maxRows) throws Exception;
 
 }
index 4e097e4..e0f4986 100644 (file)
@@ -19,6 +19,7 @@
 package org.apache.metamodel.excel;
 
 import java.util.Iterator;
+import java.util.List;
 
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.metamodel.data.AbstractDataSet;
@@ -46,8 +47,8 @@ final class XlsDataSet extends AbstractDataSet {
      * @param workbook
      * @param rowIterator
      */
-    public XlsDataSet(SelectItem[] selectItems, Workbook workbook,
-            Iterator<org.apache.poi.ss.usermodel.Row> rowIterator) {
+    public XlsDataSet(List<SelectItem> selectItems, Workbook workbook,
+                      Iterator<org.apache.poi.ss.usermodel.Row> rowIterator) {
         super(selectItems);
         _workbook = workbook;
         _rowIterator = rowIterator;
index a154251..5635de6 100644 (file)
@@ -38,12 +38,12 @@ class XlsxRowPublisherAction implements Action<RowPublisher> {
                        .getLogger(XlsxRowPublisherAction.class);
 
        private final ExcelConfiguration _configuration;
-       private final Column[] _columns;
+       private final List<Column> _columns;
        private final String _relationshipId;
        private final XSSFReader _xssfReader;
 
        public XlsxRowPublisherAction(ExcelConfiguration configuration,
-                       Column[] columns, String relationshipId, XSSFReader xssfReader) {
+                       List<Column> columns, String relationshipId, XSSFReader xssfReader) {
                _configuration = configuration;
                _columns = columns;
                _relationshipId = relationshipId;
@@ -66,10 +66,10 @@ class XlsxRowPublisherAction implements Action<RowPublisher> {
                                        }
                                }
 
-                               Object[] rowData = new Object[_columns.length];
-                               Style[] styleData = new Style[_columns.length];
-                               for (int i = 0; i < _columns.length; i++) {
-                                       int columnNumber = _columns[i].getColumnNumber();
+                               Object[] rowData = new Object[_columns.size()];
+                               Style[] styleData = new Style[_columns.size()];
+                               for (int i = 0; i < _columns.size(); i++) {
+                                       int columnNumber = _columns.get(i).getColumnNumber();
                                        if (columnNumber < values.size()) {
                                                rowData[i] = values.get(columnNumber);
                                                styleData[i] = styles.get(columnNumber);
index 94a9ff7..0436a2a 100644 (file)
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.data.DataSet;
 import org.apache.metamodel.data.RowPublisherDataSet;
@@ -72,7 +73,7 @@ final class XlsxSpreadsheetReaderDelegate implements SpreadsheetReaderDelegate {
     }
 
     @Override
-    public DataSet executeQuery(Table table, Column[] columns, int maxRows) throws Exception {
+    public DataSet executeQuery(Table table, List<Column> columns, int maxRows) throws Exception {
         final OPCPackage pkg = openOPCPackage();
         final XSSFReader xssfReader = new XSSFReader(pkg);
         final String relationshipId = _tableNamesToInternalIds.get(table.getName());
@@ -136,13 +137,10 @@ final class XlsxSpreadsheetReaderDelegate implements SpreadsheetReaderDelegate {
         }
     }
 
-    private DataSet buildDataSet(final Column[] columns, int maxRows, final String relationshipId,
+    private DataSet buildDataSet(final List<Column> columns, int maxRows, final String relationshipId,
             final XSSFReader xssfReader, final OPCPackage pkg) throws Exception {
 
-        List<SelectItem> selectItems = new ArrayList<SelectItem>(columns.length);
-        for (Column column : columns) {
-            selectItems.add(new SelectItem(column));
-        }
+        List<SelectItem> selectItems = columns.stream().map(SelectItem::new).collect(Collectors.toList());
         final XlsxRowPublisherAction publishAction = new XlsxRowPublisherAction(_configuration, columns, relationshipId,
                 xssfReader);
 
index 96d7dff..91d336b 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.metamodel.excel;
 
 import java.io.File;
 import java.lang.reflect.Field;
+import java.util.List;
 
 import org.apache.metamodel.data.DataSet;
 import org.apache.metamodel.data.Row;
@@ -85,31 +86,31 @@ public class DefaultSpreadsheetReaderDelegateTest extends TestCase {
 
         assertEquals(DefaultSpreadsheetReaderDelegate.class, mainDataContext.getSpreadsheetReaderDelegateClass());
 
-        Table[] tables = schema.getTables();
-        assertTrue(tables.length > 0);
+        List<Table> tables = schema.getTables();
+        assertTrue(tables.size() > 0);
 
-        Table[] comparedTables = null;
+        List<Table> comparedTables = null;
         if (comparedDataContext != null) {
             assertEquals(XlsxSpreadsheetReaderDelegate.class, comparedDataContext.getSpreadsheetReaderDelegateClass());
             comparedTables = comparedDataContext.getDefaultSchema().getTables();
-            assertEquals(comparedTables.length, tables.length);
+            assertEquals(comparedTables.size(), tables.size());
         }
 
-        for (int i = 0; i < tables.length; i++) {
-            Table table = tables[i];
-            Column[] columns = table.getColumns();
+        for (int i = 0; i < tables.size(); i++) {
+            Table table = tables.get(i);
+            List<Column> columns = table.getColumns();
             Query query = mainDataContext.query().from(table).select(columns).toQuery();
             DataSet dataSet = mainDataContext.executeQuery(query);
 
             DataSet comparedDataSet = null;
             if (comparedDataContext != null) {
-                Table comparedTable = comparedTables[i];
+                Table comparedTable = comparedTables.get(i);
                 assertEquals(comparedTable.getName(), table.getName());
                 assertEquals(comparedTable.getColumnCount(), table.getColumnCount());
 
-                Column[] comparedColumns = comparedTable.getColumns();
-                for (int j = 0; j < comparedColumns.length; j++) {
-                    assertEquals(columns[j].getColumnNumber(), comparedColumns[j].getColumnNumber());
+                List<Column> comparedColumns = comparedTable.getColumns();
+                for (int j = 0; j < comparedColumns.size(); j++) {
+                    assertEquals(columns.get(j).getColumnNumber(), comparedColumns.get(j).getColumnNumber());
                 }
 
                 Query comparedQuery = comparedDataContext.query().from(comparedTable).select(comparedColumns).toQuery();
@@ -173,7 +174,7 @@ public class DefaultSpreadsheetReaderDelegateTest extends TestCase {
         ExcelDataContext dc = new ExcelDataContext(copyOf("src/test/resources/Spreadsheet2007.xlsx"));
         applyReaderDelegate(dc);
 
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
 
         final String expectedStyling = "";
 
@@ -194,7 +195,7 @@ public class DefaultSpreadsheetReaderDelegateTest extends TestCase {
         ExcelDataContext dc = new ExcelDataContext(copyOf("src/test/resources/formulas.xlsx"));
         applyReaderDelegate(dc);
 
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
 
         DataSet dataSet = dc.query().from(table).select("Foo").and("Bar").where("Foo").isEquals("7").execute();
         assertTrue(dataSet.next());
index ecd6691..844522e 100644 (file)
@@ -82,7 +82,7 @@ public class ExcelDataContextTest extends TestCase {
         assertNull(dc.getSpreadsheetReaderDelegateClass());
         assertEquals(1, dc.getDefaultSchema().getTableCount());
 
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
         assertEquals("sheet", table.getName());
         assertEquals(0, table.getColumnCount());
 
@@ -94,7 +94,7 @@ public class ExcelDataContextTest extends TestCase {
                 ExcelConfiguration.NO_COLUMN_NAME_LINE, false, false));
         assertEquals(1, dc.getDefaultSchema().getTableCount());
 
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
         assertEquals("sheet", table.getName());
         assertEquals(0, table.getColumnCount());
     }
@@ -104,7 +104,7 @@ public class ExcelDataContextTest extends TestCase {
                 true, false));
         assertEquals(1, dc.getDefaultSchema().getTableCount());
 
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
         assertEquals("xls_people", table.getName());
         assertEquals(0, table.getColumnCount());
     }
@@ -112,8 +112,8 @@ public class ExcelDataContextTest extends TestCase {
     public void testSkipEmptyColumns() throws Exception {
         ExcelConfiguration conf = new ExcelConfiguration(ExcelConfiguration.DEFAULT_COLUMN_NAME_LINE, true, true);
         ExcelDataContext dc = new ExcelDataContext(copyOf("src/test/resources/skipped_lines.xlsx"), conf);
-        Table table = dc.getDefaultSchema().getTables()[0];
-        assertEquals("[hello, world]", Arrays.toString(table.getColumnNames()));
+        Table table = dc.getDefaultSchema().getTables().get(0);
+        assertEquals("[hello, world]", Arrays.toString(table.getColumnNames().toArray()));
 
         DataSet ds = dc.executeQuery(dc.query().from(table).select("hello").toQuery());
         assertTrue(ds.next());
@@ -123,8 +123,8 @@ public class ExcelDataContextTest extends TestCase {
     public void testDontSkipEmptyLinesNoHeader() throws Exception {
         ExcelConfiguration conf = new ExcelConfiguration(ExcelConfiguration.NO_COLUMN_NAME_LINE, false, true);
         ExcelDataContext dc = new ExcelDataContext(copyOf("src/test/resources/skipped_lines.xlsx"), conf);
-        Table table = dc.getDefaultSchema().getTables()[0];
-        assertEquals("[G, H]", Arrays.toString(table.getColumnNames()));
+        Table table = dc.getDefaultSchema().getTables().get(0);
+        assertEquals("[G, H]", Arrays.toString(table.getColumnNames().toArray()));
 
         assertEquals(6, table.getColumnByName("G").getColumnNumber());
         assertEquals(7, table.getColumnByName("H").getColumnNumber());
@@ -147,8 +147,8 @@ public class ExcelDataContextTest extends TestCase {
     public void testDontSkipEmptyLinesAbsoluteHeader() throws Exception {
         ExcelConfiguration conf = new ExcelConfiguration(6, false, true);
         ExcelDataContext dc = new ExcelDataContext(copyOf("src/test/resources/skipped_lines.xlsx"), conf);
-        Table table = dc.getDefaultSchema().getTables()[0];
-        assertEquals("[hello, world]", Arrays.toString(table.getColumnNames()));
+        Table table = dc.getDefaultSchema().getTables().get(0);
+        assertEquals("[hello, world]", Arrays.toString(table.getColumnNames().toArray()));
         assertEquals(6, table.getColumnByName("hello").getColumnNumber());
         assertEquals(7, table.getColumnByName("world").getColumnNumber());
 
@@ -159,9 +159,9 @@ public class ExcelDataContextTest extends TestCase {
 
     public void testInvalidFormula() throws Exception {
         ExcelDataContext dc = new ExcelDataContext(copyOf("src/test/resources/invalid_formula.xls"));
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
 
-        assertEquals("[name]", Arrays.toString(table.getColumnNames()));
+        assertEquals("[name]", Arrays.toString(table.getColumnNames().toArray()));
 
         Query q = dc.query().from(table).select("name").toQuery();
 
@@ -197,11 +197,11 @@ public class ExcelDataContextTest extends TestCase {
     public void testEvaluateFormula() throws Exception {
         ExcelDataContext dc = new ExcelDataContext(copyOf("src/test/resources/xls_formulas.xls"));
 
-        Table table = dc.getDefaultSchema().getTables()[0];
-        Column[] columns = table.getColumns();
+        Table table = dc.getDefaultSchema().getTables().get(0);
+        Column[] columns = table.getColumns().toArray(new Column[0]);
 
         assertEquals("[some number, some mixed formula, some int only formula]",
-                Arrays.toString(table.getColumnNames()));
+                Arrays.toString(table.getColumnNames().toArray()));
 
         Query q = dc.query().from(table).select(columns).toQuery();
         DataSet ds = dc.executeQuery(q);
@@ -277,7 +277,7 @@ public class ExcelDataContextTest extends TestCase {
 
         assertNotNull(table);
 
-        assertEquals("[A, hello]", Arrays.toString(table.getColumnNames()));
+        assertEquals("[A, hello]", Arrays.toString(table.getColumnNames().toArray()));
 
         Query q = dc.query().from(table).select(table.getColumns()).toQuery();
         DataSet ds = dc.executeQuery(q);
@@ -289,14 +289,14 @@ public class ExcelDataContextTest extends TestCase {
         Schema schema = dc.getDefaultSchema();
         assertEquals("Schema[name=testOpenXlsxFormat-Spreadsheet2007.xlsx]", schema.toString());
 
-        assertEquals("[Sheet1, Sheet2, Sheet3]", Arrays.toString(schema.getTableNames()));
+        assertEquals("[Sheet1, Sheet2, Sheet3]", Arrays.toString(schema.getTableNames().toArray()));
 
         assertEquals(0, schema.getTableByName("Sheet2").getColumnCount());
         assertEquals(0, schema.getTableByName("Sheet3").getColumnCount());
 
         Table table = schema.getTableByName("Sheet1");
 
-        assertEquals("[string, number, date]", Arrays.toString(table.getColumnNames()));
+        assertEquals("[string, number, date]", Arrays.toString(table.getColumnNames().toArray()));
 
         Query q = dc.query().from(table).select(table.getColumns()).orderBy(table.getColumnByName("number")).toQuery();
         DataSet ds = dc.executeQuery(q);
@@ -312,9 +312,9 @@ public class ExcelDataContextTest extends TestCase {
         File file = copyOf("src/test/resources/xls_people.xls");
         DataContext dc = new ExcelDataContext(file, new ExcelConfiguration(ExcelConfiguration.NO_COLUMN_NAME_LINE,
                 true, true));
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
 
-        String[] columnNames = table.getColumnNames();
+        String[] columnNames = table.getColumnNames().toArray(new String[0]);
         assertEquals("[A, B, C, D]", Arrays.toString(columnNames));
 
         Query q = dc.query().from(table).select(table.getColumnByName("A")).toQuery();
@@ -334,9 +334,9 @@ public class ExcelDataContextTest extends TestCase {
     public void testConfigurationNonDefaultColumnNameLineNumber() throws Exception {
         File file = copyOf("src/test/resources/xls_people.xls");
         DataContext dc = new ExcelDataContext(file, new ExcelConfiguration(2, true, true));
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
 
-        String[] columnNames = table.getColumnNames();
+        String[] columnNames = table.getColumnNames().toArray(new String[0]);
         assertEquals("[1, mike, male, 18]", Arrays.toString(columnNames));
 
         Query q = dc.query().from(table).select(table.getColumnByName("1")).toQuery();
@@ -355,18 +355,18 @@ public class ExcelDataContextTest extends TestCase {
     public void testGetSchemas() throws Exception {
         File file = copyOf("src/test/resources/xls_people.xls");
         DataContext dc = new ExcelDataContext(file);
-        Schema[] schemas = dc.getSchemas();
+        Schema[] schemas = dc.getSchemas().toArray(new Schema[0]);
         assertEquals(2, schemas.length);
         Schema schema = schemas[1];
         assertEquals("testGetSchemas-xls_people.xls", schema.getName());
         assertEquals(1, schema.getTableCount());
-        Table table = schema.getTables()[0];
+        Table table = schema.getTables().get(0);
         assertEquals("xls_people", table.getName());
 
         assertEquals(4, table.getColumnCount());
         assertEquals(0, table.getRelationshipCount());
 
-        Column[] columns = table.getColumns();
+        Column[] columns = table.getColumns().toArray(new Column[0]);
         assertEquals("id", columns[0].getName());
         assertEquals("name", columns[1].getName());
         assertEquals("gender", columns[2].getName());
@@ -376,7 +376,7 @@ public class ExcelDataContextTest extends TestCase {
     public void testMaterializeTable() throws Exception {
         File file = copyOf("src/test/resources/xls_people.xls");
         ExcelDataContext dc = new ExcelDataContext(file);
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
         DataSet dataSet = dc.materializeMainSchemaTable(table, table.getColumns(), -1);
         assertTrue(dataSet.next());
         assertEquals("Row[values=[1, mike, male, 18]]", dataSet.getRow().toString());
@@ -401,12 +401,12 @@ public class ExcelDataContextTest extends TestCase {
         Schema schema = dc.getDefaultSchema();
         assertEquals(1, schema.getTableCount());
 
-        Table table = schema.getTables()[0];
+        Table table = schema.getTables().get(0);
         assertEquals("[Column[name=a,columnNumber=0,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
                 + "Column[name=b,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
                 + "Column[name=c,columnNumber=2,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
                 + "Column[name=d,columnNumber=3,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]",
-                Arrays.toString(table.getColumns()));
+                Arrays.toString(table.getColumns().toArray()));
 
         Query q = new Query().select(table.getColumns()).from(table);
         DataSet ds = dc.executeQuery(q);
@@ -425,12 +425,12 @@ public class ExcelDataContextTest extends TestCase {
         Schema schema = dc.getDefaultSchema();
         assertEquals(1, schema.getTableCount());
 
-        Table table = schema.getTables()[0];
+        Table table = schema.getTables().get(0);
         assertEquals("[Column[name=a,columnNumber=0,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
                 + "Column[name=b,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
                 + "Column[name=A,columnNumber=2,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
                 + "Column[name=d,columnNumber=3,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]",
-                Arrays.toString(table.getColumns()));
+                Arrays.toString(table.getColumns().toArray()));
 
         Query q = new Query().select(table.getColumns()).from(table);
         DataSet ds = dc.executeQuery(q);
@@ -447,11 +447,11 @@ public class ExcelDataContextTest extends TestCase {
         File file = copyOf("src/test/resources/formulas.xlsx");
         ExcelDataContext dc = new ExcelDataContext(file);
 
-        assertEquals("[sh1]", Arrays.toString(dc.getDefaultSchema().getTableNames()));
+        assertEquals("[sh1]", Arrays.toString(dc.getDefaultSchema().getTableNames().toArray()));
         assertEquals(XlsxSpreadsheetReaderDelegate.class, dc.getSpreadsheetReaderDelegateClass());
 
         Table table = dc.getDefaultSchema().getTableByName("sh1");
-        assertEquals("[Foo, Bar]", Arrays.toString(table.getColumnNames()));
+        assertEquals("[Foo, Bar]", Arrays.toString(table.getColumnNames().toArray()));
 
         Query q = dc.query().from(table).select("Foo").toQuery();
         DataSet ds = dc.executeQuery(q);
@@ -525,7 +525,7 @@ public class ExcelDataContextTest extends TestCase {
         Schema schema = dc.getDefaultSchema();
         assertEquals(
                 "[Table[name=Sheet1,type=null,remarks=null], Table[name=Sheet2,type=null,remarks=null], Table[name=Sheet3,type=null,remarks=null]]",
-                Arrays.toString(schema.getTables()));
+                Arrays.toString(schema.getTables().toArray()));
 
         assertEquals(0, schema.getTableByName("Sheet2").getColumnCount());
         assertEquals(0, schema.getTableByName("Sheet3").getColumnCount());
@@ -537,14 +537,14 @@ public class ExcelDataContextTest extends TestCase {
                         + "Column[name=Description,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
                         + "Column[name=Room,columnNumber=2,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
                         + "Column[name=Level,columnNumber=3,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]",
-                Arrays.toString(table.getColumns()));
+                Arrays.toString(table.getColumns().toArray()));
     }
 
     public void testInsertInto() throws Exception {
         final File file = copyOf("src/test/resources/xls_people.xls");
 
         final ExcelDataContext dc = new ExcelDataContext(file);
-        final Table table = dc.getDefaultSchema().getTables()[0];
+        final Table table = dc.getDefaultSchema().getTables().get(0);
         final Column nameColumn = table.getColumnByName("name");
 
         dc.executeUpdate(new UpdateScript() {
@@ -620,13 +620,13 @@ public class ExcelDataContextTest extends TestCase {
 
                 assertEquals(1, schema.getTableCount());
                 assertSame(table1.getSchema(), schema);
-                assertSame(table1, schema.getTables()[0]);
+                assertSame(table1, schema.getTables().get(0));
 
                 Table table2 = cb.createTable(schema, "my_table_2").withColumn("foo").withColumn("bar")
                         .withColumn("baz").execute();
 
                 assertSame(table2.getSchema(), schema);
-                assertSame(table2, schema.getTables()[1]);
+                assertSame(table2, schema.getTables().get(1));
                 assertEquals(2, schema.getTableCount());
 
                 cb.insertInto(table1).value("foo", 123.0).value("bar", "str 1").value("baz", true).execute();
@@ -637,7 +637,7 @@ public class ExcelDataContextTest extends TestCase {
 
         Schema schema = dc.getDefaultSchema();
         assertEquals(2, schema.getTableCount());
-        assertEquals("[my_table_1, my_table_2]", Arrays.toString(schema.getTableNames()));
+        assertEquals("[my_table_1, my_table_2]", Arrays.toString(schema.getTableNames().toArray()));
 
         dc.executeUpdate(new UpdateScript() {
             @Override
@@ -689,18 +689,18 @@ public class ExcelDataContextTest extends TestCase {
             }
         });
 
-        assertEquals("[my_table_2]", Arrays.toString(schema.getTableNames()));
+        assertEquals("[my_table_2]", Arrays.toString(schema.getTableNames().toArray()));
 
         dc.refreshSchemas();
 
-        assertEquals("[my_table_2]", Arrays.toString(dc.getDefaultSchema().getTableNames()));
+        assertEquals("[my_table_2]", Arrays.toString(dc.getDefaultSchema().getTableNames().toArray()));
         assertEquals(1, dc.getDefaultSchema().getTableCount());
     }
 
     public void testGetStyles() throws Exception {
         DataContext dc = new ExcelDataContext(copyOf("src/test/resources/styles.xlsx"));
-        Table table = dc.getDefaultSchema().getTables()[0];
-        assertEquals("[style name, example]", Arrays.toString(table.getColumnNames()));
+        Table table = dc.getDefaultSchema().getTables().get(0);
+        assertEquals("[style name, example]", Arrays.toString(table.getColumnNames().toArray()));
 
         DataSet ds = dc.query().from(table).select(table.getColumns()).execute();
         assertTrue(ds.next());
index 97101bd..a181248 100644 (file)
@@ -84,11 +84,11 @@ public class ExcelUpdateCallbackTest extends TestCase {
                {
                        ExcelDataContext dc = new ExcelDataContext(file);
                        assertEquals("[foobar]",
-                                       Arrays.toString(dc.getDefaultSchema().getTableNames()));
+                                       Arrays.toString(dc.getDefaultSchema().getTableNames().toArray()));
 
                        Table table = dc.getDefaultSchema().getTableByName("foobar");
 
-                       assertEquals("[value0]", Arrays.toString(table.getColumnNames()));
+                       assertEquals("[value0]", Arrays.toString(table.getColumnNames().toArray()));
 
                        DataSet ds = dc.query().from(table).select("value0").execute();
                        int recordNo = 1;
index 952c4b5..aac5ada 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.metamodel.fixedwidth;
 import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.InputStream;
+import java.util.List;
 
 import org.apache.metamodel.MetaModelException;
 import org.apache.metamodel.QueryPostprocessDataContext;
@@ -130,7 +131,7 @@ public class FixedWidthDataContext extends QueryPostprocessDataContext {
     }
 
     @Override
-    public DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+    public DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) {
         final FixedWidthReader reader = createReader();
         try {
             for (int i = 1; i <= _configuration.getColumnNameLineNumber(); i++) {
index 4f78bab..ae469c1 100644 (file)
@@ -21,9 +21,13 @@ package org.apache.metamodel.fixedwidth;
 import org.apache.metamodel.data.AbstractDataSet;
 import org.apache.metamodel.data.DefaultRow;
 import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.SelectItem;
 import org.apache.metamodel.schema.Column;
 import org.apache.metamodel.util.FileHelper;
 
+import java.util.List;
+import java.util.stream.Collectors;
+
 /**
  * DataSet implementation for fixed width values.
  */
@@ -33,9 +37,9 @@ class FixedWidthDataSet extends AbstractDataSet {
        private volatile Integer _rowsRemaining;
        private volatile Row _row;
 
-       public FixedWidthDataSet(FixedWidthReader reader, Column[] columns,
+       public FixedWidthDataSet(FixedWidthReader reader, List<Column> columns,
                        Integer maxRows) {
-               super(columns);
+               super(columns.stream().map(SelectItem::new).collect(Collectors.toList()));
                _reader = reader;
                _rowsRemaining = maxRows;
        }
index c34b294..61e10d4 100644 (file)
@@ -69,7 +69,7 @@ public class FixedWidthConfigurationReaderTest {
      */
     private void performAssertionsOnSpec1(FixedWidthDataContext dataContext) {
         final Table table = dataContext.getDefaultSchema().getTable(0);
-        final String[] columnNames = table.getColumnNames();
+        final String[] columnNames = table.getColumnNames().toArray(new String[0]);
         assertEquals("[Record type, Description, Initials]", Arrays.toString(columnNames));
 
         try (final DataSet dataSet = dataContext.query().from(table).selectAll().execute()) {
index 7a4b75f..16f2c5b 100644 (file)
@@ -37,7 +37,7 @@ public class FixedWidthDataContextTest extends TestCase {
                 new FixedWidthConfiguration(10));
         assertEquals(1, dc.getDefaultSchema().getTableCount());
 
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
         assertEquals("empty_file.txt", table.getName());
         assertEquals(0, table.getColumnCount());
     }
@@ -47,7 +47,7 @@ public class FixedWidthDataContextTest extends TestCase {
                 new FixedWidthConfiguration(FixedWidthConfiguration.NO_COLUMN_NAME_LINE, "UTF8", 10));
         assertEquals(1, dc.getDefaultSchema().getTableCount());
 
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
         assertEquals("empty_file.txt", table.getName());
         assertEquals(0, table.getColumnCount());
     }
@@ -57,7 +57,7 @@ public class FixedWidthDataContextTest extends TestCase {
                 new FixedWidthConfiguration(20, "UTF8", 10));
         assertEquals(1, dc.getDefaultSchema().getTableCount());
 
-        Table table = dc.getDefaultSchema().getTables()[0];
+        Table table = dc.getDefaultSchema().getTables().get(0);
         assertEquals("example_simple1.txt", table.getName());
         assertEquals(0, table.getColumnCount());
     }
@@ -66,7 +66,7 @@ public class FixedWidthDataContextTest extends TestCase {
         FixedWidthConfiguration conf = new FixedWidthConfiguration(10);
         FixedWidthDataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple1.txt"), conf);
 
-        String[] schemaNames = dc.getSchemaNames();
+        String[] schemaNames = dc.getSchemaNames().toArray(new String[0]);
         assertEquals(2, schemaNames.length);
         assertEquals("[information_schema, resources]", Arrays.toString(schemaNames));
 
@@ -78,7 +78,7 @@ public class FixedWidthDataContextTest extends TestCase {
         Table table = schema.getTableByName("example_simple1.txt");
         assertEquals("Table[name=example_simple1.txt,type=TABLE,remarks=null]", table.toString());
 
-        assertEquals("[greeting, greeter]", Arrays.toString(table.getColumnNames()));
+        assertEquals("[greeting, greeter]", Arrays.toString(table.getColumnNames().toArray()));
         assertEquals(10, table.getColumnByName("greeting").getColumnSize().intValue());
         assertEquals(10, table.getColumnByName("greeter").getColumnSize().intValue());
 
@@ -99,7 +99,7 @@ public class FixedWidthDataContextTest extends TestCase {
                 10, true);
         FixedWidthDataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple1.txt"), conf);
 
-        String[] schemaNames = dc.getSchemaNames();
+        String[] schemaNames = dc.getSchemaNames().toArray(new String[0]);
         assertEquals(2, schemaNames.length);
         assertEquals("[information_schema, resources]", Arrays.toString(schemaNames));
 
@@ -111,7 +111,7 @@ public class FixedWidthDataContextTest extends TestCase {
         Table table = schema.getTableByName("example_simple1.txt");
         assertEquals("Table[name=example_simple1.txt,type=TABLE,remarks=null]", table.toString());
 
-        assertEquals("[A, B]", Arrays.toString(table.getColumnNames()));
+        assertEquals("[A, B]", Arrays.toString(table.getColumnNames().toArray()));
 
         Query q = dc.query().from(table).select(table.getColumns()).toQuery();
         DataSet ds = dc.executeQuery(q);
@@ -137,8 +137,8 @@ public class FixedWidthDataContextTest extends TestCase {
     public void testVaryingValueLengthsCorrect() throws Exception {
         DataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple2.txt"),
                 new FixedWidthConfiguration(new int[] { 1, 8, 7 }));
-        Table table = dc.getDefaultSchema().getTables()[0];
-        assertEquals("[i, greeting, greeter]", Arrays.toString(table.getColumnNames()));
+        Table table = dc.getDefaultSchema().getTables().get(0);
+        assertEquals("[i, greeting, greeter]", Arrays.toString(table.getColumnNames().toArray()));
 
         assertEquals(1, table.getColumnByName("i").getColumnSize().intValue());
         assertEquals(8, table.getColumnByName("greeting").getColumnSize().intValue());
@@ -174,8 +174,8 @@ public class FixedWidthDataContextTest extends TestCase {
                 new FixedWidthConfiguration(FixedWidthConfiguration.DEFAULT_COLUMN_NAME_LINE, "UTF8", new int[] { 1, 5,
                         7 }, false));
 
-        Table table = dc.getDefaultSchema().getTables()[0];
-        assertEquals("[i, greet, inggree]", Arrays.toString(table.getColumnNames()));
+        Table table = dc.getDefaultSchema().getTables().get(0);
+        assertEquals("[i, greet, inggree]", Arrays.toString(table.getColumnNames().toArray()));
 
         Query q = dc.query().from(table).select(table.getColumns()).toQuery();
         DataSet ds = dc.executeQuery(q);
@@ -208,8 +208,8 @@ public class FixedWidthDataContextTest extends TestCase {
                 new FixedWidthConfiguration(FixedWidthConfiguration.DEFAULT_COLUMN_NAME_LINE, "UTF8", new int[] { 1, 8,
                         9 }, false));
 
-        Table table = dc.getDefaultSchema().getTables()[0];
-        assertEquals("[i, greeting, greeter]", Arrays.toString(table.getColumnNames()));
+        Table table = dc.getDefaultSchema().getTables().get(0);
+        assertEquals("[i, greeting, greeter]", Arrays.toString(table.getColumnNames().toArray()));
 
         Query q = dc.query().from(table).select(table.getColumns()).toQuery();
         DataSet ds = dc.executeQuery(q);
index e49076e..55e4f41 100644 (file)
@@ -211,7 +211,7 @@ public class HBaseDataContext extends QueryPostprocessDataContext {
     }
 
     @Override
-    protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+    protected DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) {
         final Scan scan = new Scan();
         for (Column column : columns) {
             if (!column.isPrimaryKey()) {
index a4158d5..c68e6da 100644 (file)
 package org.apache.metamodel.hbase;
 
 import java.io.IOException;
+import java.util.List;
+import java.util.stream.Collectors;
 
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.client.ResultScanner;
 import org.apache.metamodel.MetaModelException;
 import org.apache.metamodel.data.AbstractDataSet;
 import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.SelectItem;
 import org.apache.metamodel.schema.Column;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -37,8 +40,8 @@ final class HBaseDataSet extends AbstractDataSet {
     private final org.apache.hadoop.hbase.client.Table _hTable;
     private volatile Result _nextResult;
 
-    public HBaseDataSet(Column[] columns, ResultScanner scanner, org.apache.hadoop.hbase.client.Table hTable) {
-        super(columns);
+    public HBaseDataSet(List<Column> columns, ResultScanner scanner, org.apache.hadoop.hbase.client.Table hTable) {
+        super(columns.stream().map(SelectItem::new).collect(Collectors.toList()));
         _scanner = scanner;
         _hTable = hTable;
     }
index eb0ba48..6187f2c 100644 (file)
@@ -59,7 +59,7 @@ public class HBaseDataContextTest extends HBaseTestCase {
         final Table table = _dataContext.getDefaultSchema().getTableByName(EXAMPLE_TABLE_NAME);
         assertNotNull(table);
 
-        assertEquals("[_id, bar, foo]", Arrays.toString(table.getColumnNames()));
+        assertEquals("[_id, bar, foo]", Arrays.toString(table.getColumnNames().toArray()));
         assertEquals(ColumnType.MAP, table.getColumn(1).getType());
 
         // insert two records
index d20f369..0612b3e 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.metamodel.jdbc;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.util.List;
 
 import org.apache.metamodel.create.AbstractTableCreationBuilder;
 import org.apache.metamodel.jdbc.dialects.IQueryRewriter;
@@ -84,9 +85,9 @@ final class JdbcCreateTableBuilder extends AbstractTableCreationBuilder<JdbcUpda
         }
         sb.append(getUpdateCallback().quoteIfNescesary(table.getName()));
         sb.append(" (");
-        final Column[] columns = table.getColumns();
-        for (int i = 0; i < columns.length; i++) {
-            final Column column = columns[i];
+        final List<Column> columns = table.getColumns();
+        for (int i = 0; i < columns.size(); i++) {
+            final Column column = columns.get(i);
             if (i != 0) {
                 sb.append(", ");
             }
@@ -114,15 +115,15 @@ final class JdbcCreateTableBuilder extends AbstractTableCreationBuilder<JdbcUpda
             }
         }
         boolean primaryKeyExists = false;
-        for (int i = 0; i < columns.length; i++) {
-            if (columns[i].isPrimaryKey()) {
+        for (int i = 0; i < columns.size(); i++) {
+            if (columns.get(i).isPrimaryKey()) {
                 if (!primaryKeyExists) {
                     sb.append(", PRIMARY KEY(");
-                    sb.append(columns[i].getName());
+                    sb.append(columns.get(i).getName());
                     primaryKeyExists = true;
                 } else {
                     sb.append(",");
-                    sb.append(columns[i].getName());
+                    sb.append(columns.get(i).getName());
                 }
             }
         }
index 5a9b784..3f4a0ad 100644 (file)
@@ -643,12 +643,12 @@ public class JdbcDataContext extends AbstractDataContext implements UpdateableDa
         // databases).
         boolean found = false;
         String result = null;
-        String[] schemaNames = getSchemaNames();
+        List<String> schemaNames = getSchemaNames();
 
         // First strategy: If there's only one schema available, that must
         // be it
-        if (schemaNames.length == 1) {
-            result = schemaNames[0];
+        if (schemaNames.size() == 1) {
+            result = schemaNames.get(0);
             found = true;
         }
 
@@ -669,7 +669,7 @@ public class JdbcDataContext extends AbstractDataContext implements UpdateableDa
                         }
                     }
                     if (url != null && url.length() > 0) {
-                        if (schemaNames.length > 0) {
+                        if (schemaNames.size() > 0) {
                             StringTokenizer st = new StringTokenizer(url, "/\\:");
                             int tokenCount = st.countTokens();
                             if (tokenCount > 0) {
@@ -678,8 +678,8 @@ public class JdbcDataContext extends AbstractDataContext implements UpdateableDa
                                 }
                                 String lastToken = st.nextToken();
 
-                                for (int i = 0; i < schemaNames.length && !found; i++) {
-                                    String schemaName = schemaNames[i];
+                                for (int i = 0; i < schemaNames.size() && !found; i++) {
+                                    String schemaName = schemaNames.get(i);
                                     if (lastToken.indexOf(schemaName) != -1) {
                                         result = schemaName;
                                         found = true;
@@ -701,9 +701,9 @@ public class JdbcDataContext extends AbstractDataContext implements UpdateableDa
                         }
                     }
                     if (username != null) {
-                        for (int i = 0; i < schemaNames.length && !found; i++) {
-                            if (username.equalsIgnoreCase(schemaNames[i])) {
-                                result = schemaNames[i];
+                        for (int i = 0; i < schemaNames.size() && !found; i++) {
+                            if (username.equalsIgnoreCase(schemaNames.get(i))) {
+                                result = schemaNames.get(i);
                                 found = true;
                             }
                         }
@@ -741,7 +741,7 @@ public class JdbcDataContext extends AbstractDataContext implements UpdateableDa
         return result;
     }
 
-    private String findDefaultSchema(final String defaultName, final String[] schemaNames) {
+    private String findDefaultSchema(final String defaultName, final List<String> schemaNames) {
         for (String schemaName : schemaNames) {
             if (defaultName.equals(schemaName)) {
                 return schemaName;
@@ -785,14 +785,14 @@ public class JdbcDataContext extends AbstractDataContext implements UpdateableDa
     }
 
     @Override
-    protected String[] getSchemaNamesInternal() {
+    protected List<String> getSchemaNamesInternal() {
         Connection connection = getConnection();
         try {
             DatabaseMetaData metaData = connection.getMetaData();
-            Collection<String> result = new ArrayList<>();
+            List<String> result = new ArrayList<>();
 
             if (DATABASE_PRODUCT_SQLSERVER.equals(_databaseProductName)) {
-                result = getSchemaSQLServerNames(metaData);
+                result = new ArrayList<>(getSchemaSQLServerNames(metaData));
             } else if (_usesCatalogsAsSchemas) {
                 String[] catalogNames = getCatalogNames();
                 for (String name : catalogNames) {
@@ -818,7 +818,7 @@ public class JdbcDataContext extends AbstractDataContext implements UpdateableDa
                 logger.info("No schemas or catalogs found. Creating unnamed schema.");
                 result.add(null);
             }
-            return result.toArray(new String[result.size()]);
+            return result;
         } catch (SQLException e) {
             throw JdbcUtils.wrapException(e, "get schema names");
         } finally {
index 837fb18..49e242b 100644 (file)
@@ -398,9 +398,8 @@ final class JdbcMetadataLoader implements MetadataLoader {
                 return;
             }
             try {
-                final Table[] tables = schema.getTables();
                 final DatabaseMetaData metaData = connection.getMetaData();
-                for (Table table : tables) {
+                for (Table table : schema.getTables()) {
                     loadRelations(table, metaData);
                 }
                 _loadedRelations.add(identity);
@@ -453,7 +452,7 @@ final class JdbcMetadataLoader implements MetadataLoader {
                 logger.error("pkColumn={}", pkColumn);
                 logger.error("fkColumn={}", fkColumn);
             } else {
-                MutableRelationship.createRelationship(new Column[] { pkColumn }, new Column[] { fkColumn });
+                MutableRelationship.createRelationship(pkColumn, fkColumn);
             }
         }
     }
index 06aa93c..0dc0381 100644 (file)
@@ -59,8 +59,7 @@ final class JdbcSchema extends MutableSchema {
     }
 
     public Schema toSerializableForm() {
-        MutableTable[] tables = getTables();
-        for (MutableTable table : tables) {
+        for (MutableTable table : getMutableTables()) {
             table.getColumns();
             table.getIndexedColumns();
             table.getPrimaryKeys();
index bbb09c9..07a0db2 100644 (file)
@@ -274,9 +274,7 @@ public final class QuerySplitter {
     }
 
     private static void addColumnsToResult(Table table, List<Column> result) {
-        Column[] numberColumns = table.getNumberColumns();
-        for (int i = 0; i < numberColumns.length; i++) {
-            Column column = numberColumns[i];
+        for (Column column: table.getNumberColumns()) {
             if (column.isIndexed()) {
                 // Indexed columns have first priority, they will be
                 // added to the beginning of the list
index ff6ef22..eb026d8 100644 (file)
@@ -139,7 +139,7 @@ public class DerbyTest extends TestCase {
                 q.toSql());
 
         DataSet dataSet = dc.executeQuery(q);
-        assertEquals("[\"CUSTOMERS\".\"CUSTOMERNUMBER\"]", Arrays.toString(dataSet.getSelectItems()));
+        assertEquals("[\"CUSTOMERS\".\"CUSTOMERNUMBER\"]", Arrays.toString(dataSet.getSelectItems().toArray()));
         assertTrue(dataSet.next());
         assertEquals("Row[values=[114]]", dataSet.getRow().toString());
         assertTrue(dataSet.next());
@@ -152,7 +152,7 @@ public class DerbyTest extends TestCase {
 
     public void testGetSchemaNormalTableTypes() throws Exception {
         DataContext dc = new JdbcDataContext(_connection, new TableType[] { TableType.TABLE, TableType.VIEW }, null);
-        Schema[] schemas = dc.getSchemas();
+        Schema[] schemas = dc.getSchemas().toArray(new Schema[dc.getSchemas().size()]);
 
         assertEquals(11, schemas.length);
         assertEquals("Schema[name=APP]", schemas[0].toString());
@@ -182,7 +182,7 @@ public class DerbyTest extends TestCase {
     public void testGetSchemaAllTableTypes() throws Exception {
         DataContext dc = new JdbcDataContext(_connection,
                 new TableType[] { TableType.OTHER, TableType.GLOBAL_TEMPORARY }, null);
-        Schema[] schemas = dc.getSchemas();
+        Schema[] schemas = dc.getSchemas().toArray(new Schema[dc.getSchemas().size()]);
 
         assertEquals(11, schemas.length);
         assertEquals("Schema[name=APP]", schemas[0].toString());
@@ -194,7 +194,7 @@ public class DerbyTest extends TestCase {
                 + "Table[name=ORDERS,type=TABLE,remarks=], " + "Table[name=PAYMENTS,type=TABLE,remarks=], "
                 + "Table[name=PRODUCTS,type=TABLE,remarks=], " + "Table[name=QUADRANT_ACTUALS,type=TABLE,remarks=], "
                 + "Table[name=TIME,type=TABLE,remarks=], " + "Table[name=TRIAL_BALANCE,type=TABLE,remarks=]]",
-                Arrays.toString(schemas[0].getTables()));
+                Arrays.toString(schemas[0].getTables().toArray()));
         assertEquals("Schema[name=NULLID]", schemas[1].toString());
         assertEquals(0, schemas[1].getTableCount());
         assertEquals("Schema[name=SQLJ]", schemas[2].toString());
@@ -210,7 +210,7 @@ public class DerbyTest extends TestCase {
                 + "Table[name=SYSSCHEMAS,type=OTHER,remarks=], " + "Table[name=SYSSTATEMENTS,type=OTHER,remarks=], "
                 + "Table[name=SYSSTATISTICS,type=OTHER,remarks=], " + "Table[name=SYSTABLEPERMS,type=OTHER,remarks=], "
                 + "Table[name=SYSTABLES,type=OTHER,remarks=], " + "Table[name=SYSTRIGGERS,type=OTHER,remarks=], "
-                + "Table[name=SYSVIEWS,type=OTHER,remarks=]]", Arrays.toString(schemas[3].getTables()));
+                + "Table[name=SYSVIEWS,type=OTHER,remarks=]]", Arrays.toString(schemas[3].getTables().toArray()));
         assertEquals("Schema[name=SYSCAT]", schemas[4].toString());
         assertEquals(0, schemas[4].getTableCount());
         assertEquals("Schema[name=SYSCS_DIAG]", schemas[5].toString());
@@ -221,7 +221,7 @@ public class DerbyTest extends TestCase {
         assertEquals(0, schemas[7].getTableCount());
         assertEquals("Schema[name=SYSIBM]", schemas[8].toString());
         assertEquals(1, schemas[8].getTableCount());
-        assertEquals("[Table[name=SYSDUMMY1,type=OTHER,remarks=]]", Arrays.toString(schemas[8].getTables()));
+        assertEquals("[Table[name=SYSDUMMY1,type=OTHER,remarks=]]", Arrays.toString(schemas[8].getTables().toArray()));
         assertEquals("Schema[name=SYSPROC]", schemas[9].toString());
         assertEquals(0, schemas[9].getTableCount());
         assertEquals("Schema[name=SYSSTAT]", schemas[10].toString());
@@ -241,7 +241,7 @@ public class DerbyTest extends TestCase {
                         + "Column[name=COUNTRY,columnNumber=10,type=VARCHAR,nullable=true,nativeType=VARCHAR,columnSize=255], "
                         + "Column[name=SALESREPEMPLOYEENUMBER,columnNumber=11,type=INTEGER,nullable=true,nativeType=INTEGER,columnSize=10], "
                         + "Column[name=CREDITLIMIT,columnNumber=12,type=BIGINT,nullable=true,nativeType=BIGINT,columnSize=19]]",
-                Arrays.toString(schemas[0].getTableByName("CUSTOMERS").getColumns()));
+                Arrays.toString(schemas[0].getTableByName("CUSTOMERS").getColumns().toArray()));
     }
 
     public void testQueryRewriterQuoteAliases() throws Exception {
@@ -328,7 +328,7 @@ public class DerbyTest extends TestCase {
             assertSame(conn, dc.getConnection());
 
             final Table readTable = dc.getDefaultSchema().getTableByName("test_table");
-            assertEquals("[ID, NAME, AGE]", Arrays.toString(readTable.getColumnNames()));
+            assertEquals("[ID, NAME, AGE]", Arrays.toString(readTable.getColumnNames().toArray()));
             assertTrue(readTable.getColumnByName("id").isPrimaryKey());
             assertFalse(readTable.getColumnByName("age").isPrimaryKey());
             assertFalse(readTable.getColumnByName("name").isPrimaryKey());
index 6e21ae5..e7b5386 100644 (file)
@@ -143,16 +143,16 @@ public class H2databaseTest extends TestCase {
         }
 
         JdbcDataContext dc = new JdbcDataContext(conn);
-        assertEquals("[INFORMATION_SCHEMA, PUBLIC]", Arrays.toString(dc.getSchemaNames()));
+        assertEquals("[INFORMATION_SCHEMA, PUBLIC]", Arrays.toString(dc.getSchemaNames().toArray()));
 
         Schema schema = dc.getDefaultSchema();
         assertEquals("PUBLIC", schema.getName());
 
-        assertEquals("[TEST_TABLE]", Arrays.toString(schema.getTableNames()));
+        assertEquals("[TEST_TABLE]", Arrays.toString(schema.getTableNames().toArray()));
 
         Table table = schema.getTableByName("test_table");
 
-        assertEquals("[ID, NAME, AGE]", Arrays.toString(table.getColumnNames()));
+        assertEquals("[ID, NAME, AGE]", Arrays.toString(table.getColumnNames().toArray()));
 
         Column idColumn = table.getColumnByName("ID");
         assertEquals("Column[name=ID,columnNumber=0,type=INTEGER,nullable=false,nativeType=INTEGER,columnSize=10]",
@@ -283,18 +283,18 @@ public class H2databaseTest extends TestCase {
                 String sql = createTableBuilder.createSqlStatement();
                 assertEquals("CREATE TABLE PUBLIC.test_table (id INTEGER, name VARCHAR(255), age INTEGER, PRIMARY KEY(id))", sql);
                 assertNotNull(writtenTable);
-                assertEquals("[ID, NAME, AGE]", Arrays.toString(writtenTable.getColumnNames()));
+                assertEquals("[ID, NAME, AGE]", Arrays.toString(writtenTable.getColumnNames().toArray()));
 
                 writtenTableRef.set(writtenTable);
             }
         });
 
-        assertEquals("[TEST_TABLE]", Arrays.toString(dc.getDefaultSchema().getTableNames()));
+        assertEquals("[TEST_TABLE]", Arrays.toString(dc.getDefaultSchema().getTableNames().toArray()));
 
         readTable = dc.getDefaultSchema().getTableByName("test_table");
-        assertEquals("[ID, NAME, AGE]", Arrays.toString(readTable.getColumnNames()));
+        assertEquals("[ID, NAME, AGE]", Arrays.toString(readTable.getColumnNames().toArray()));
         assertEquals("[Column[name=ID,columnNumber=0,type=INTEGER,nullable=false,nativeType=INTEGER,columnSize=10]]",
-                Arrays.toString(readTable.getPrimaryKeys()));
+                Arrays.toString(readTable.getPrimaryKeys().toArray()));
         assertEquals(writtenTableRef.get(), readTable);
 
         assertFalse(conn.isReadOnly());
@@ -303,7 +303,7 @@ public class H2databaseTest extends TestCase {
         assertSame(conn, dc.getConnection());
 
         readTable = dc.getDefaultSchema().getTableByName("test_table");
-        assertEquals("[ID, NAME, AGE]", Arrays.toString(readTable.getColumnNames()));
+        assertEquals("[ID, NAME, AGE]", Arrays.toString(readTable.getColumnNames().toArray()));
         assertTrue(writtenTableRef.get().getQualifiedLabel().equalsIgnoreCase(readTable.getQualifiedLabel()));
 
         dc.executeUpdate(new UpdateScript() {
@@ -362,7 +362,7 @@ public class H2databaseTest extends TestCase {
         assertFalse(ds.next());
         ds.close();
 
-        assertEquals("[TEST_TABLE]", Arrays.toString(dc.getDefaultSchema().getTableNames()));
+        assertEquals("[TEST_TABLE]", Arrays.toString(dc.getDefaultSchema().getTableNames().toArray()));
 
         dc.executeUpdate(new UpdateScript() {
             @Override
@@ -371,7 +371,7 @@ public class H2databaseTest extends TestCase {
             }
         });
 
-        assertEquals("[]", Arrays.toString(dc.getDefaultSchema().getTableNames()));
+        assertEquals("[]", Arrays.toString(dc.getDefaultSchema().getTableNames().toArray()));
     }
 
     public void testSelectItemsThatReferencesDifferentFromItems() throws Exception {
index 12d5fe2..bf64fdd 100644 (file)
@@ -100,12 +100,12 @@ public class HsqldbTest extends TestCase {
     public void testGetSchemas() throws Exception {
         assertNotNull(_connection);
         JdbcDataContext dc = new JdbcDataContext(_connection);
-        assertEquals("[Schema[name=INFORMATION_SCHEMA], " + "Schema[name=PUBLIC]]", Arrays.toString(dc.getSchemas()));
+        assertEquals("[Schema[name=INFORMATION_SCHEMA], " + "Schema[name=PUBLIC]]", Arrays.toString(dc.getSchemas().toArray()));
 
         Schema defaultSchema = dc.getDefaultSchema();
         Schema publicSchema = dc.getSchemaByName("PUBLIC");
         assertSame(defaultSchema, publicSchema);
-        Table[] tables = publicSchema.getTables();
+        Table[] tables = publicSchema.getTables().toArray(new Table[publicSchema.getTables().size()]);
         assertEquals(13, tables.length);
         assertEquals("[Table[name=CUSTOMERS,type=TABLE,remarks=null], "
                 + "Table[name=CUSTOMER_W_TER,type=TABLE,remarks=null], "
@@ -128,16 +128,16 @@ public class HsqldbTest extends TestCase {
                         + "Column[name=OFFICECODE,columnNumber=5,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=20], "
                         + "Column[name=REPORTSTO,columnNumber=6,type=INTEGER,nullable=true,nativeType=INTEGER,columnSize=0], "
                         + "Column[name=JOBTITLE,columnNumber=7,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=50]]",
-                Arrays.toString(empTable.getColumns()));
+                Arrays.toString(empTable.getColumns().toArray()));
 
         assertEquals(
                 "[Column[name=EMPLOYEENUMBER,columnNumber=0,type=INTEGER,nullable=false,nativeType=INTEGER,columnSize=0]]",
-                Arrays.toString(empTable.getPrimaryKeys()));
+                Arrays.toString(empTable.getPrimaryKeys().toArray()));
 
         // Only a single relationship registered in the database
         assertEquals(
                 "[Relationship[primaryTable=PRODUCTS,primaryColumns=[PRODUCTCODE],foreignTable=ORDERFACT,foreignColumns=[PRODUCTCODE]]]",
-                Arrays.toString(publicSchema.getRelationships()));
+                Arrays.toString(publicSchema.getRelationships().toArray()));
     }
 
     public void testExecuteQuery() throws Exception {
@@ -146,8 +146,8 @@ public class HsqldbTest extends TestCase {
         Table productsTable = schema.getTableByName("PRODUCTS");
         Table factTable = schema.getTableByName("ORDERFACT");
 
-        Query q = new Query().from(new FromItem(JoinType.INNER, productsTable.getRelationships(factTable)[0])).select(
-                productsTable.getColumns()[0], factTable.getColumns()[0]);
+        Query q = new Query().from(new FromItem(JoinType.INNER, productsTable.getRelationships(factTable).iterator().next())).select(
+                productsTable.getColumns().get(0), factTable.getColumns().get(0));
         assertEquals(
                 "SELECT \"PRODUCTS\".\"PRODUCTCODE\", \"ORDERFACT\".\"ORDERNUMBER\" FROM PUBLIC.\"PRODUCTS\" INNER JOIN PUBLIC.\"ORDERFACT\" ON \"PRODUCTS\".\"PRODUCTCODE\" = \"ORDERFACT\".\"PRODUCTCODE\"",
                 q.toString());
index 17b86fa..c0f1b4e 100644 (file)
@@ -79,7 +79,7 @@ public class JdbcDataContextTest extends JdbcTestCase {
     public void testQueryMaxRows0() throws Exception {
         final Connection con = getTestDbConnection();
         final DataContext dc = new JdbcDataContext(con);
-        final Table table = dc.getDefaultSchema().getTables()[0];
+        final Table table = dc.getDefaultSchema().getTables().get(0);
         final DataSet dataSet = dc.query().from(table).selectAll().limit(0).execute();
         assertTrue(dataSet instanceof EmptyDataSet);
         assertFalse(dataSet.next());
@@ -142,7 +142,7 @@ public class JdbcDataContextTest extends JdbcTestCase {
         Schema schema = strategy.getSchemaByName(strategy.getDefaultSchemaName());
 
         Query q = new Query();
-        Table table = schema.getTables()[0];
+        Table table = schema.getTables().get(0);
         q.from(table, "a");
         q.select(table.getColumns());
         assertEquals(
@@ -174,7 +174,7 @@ public class JdbcDataContextTest extends JdbcTestCase {
         QueryParameter queryParameter = new QueryParameter();
 
         Query q = new Query();
-        Table table = schema.getTables()[0];
+        Table table = schema.getTables().get(0);
         q.select(table.getColumns());
         q.from(table, "a");
         q.where(table.getColumnByName("CUSTOMERNUMBER"), OperatorType.EQUALS_TO, queryParameter);
@@ -232,7 +232,7 @@ public class JdbcDataContextTest extends JdbcTestCase {
                 .select(FunctionType.TO_DATE, "creditlimit").select("creditlimit").limit(2).execute();
         try {
             assertEquals("[_CUSTOMERS_._CREDITLIMIT_, TO_DATE(_CUSTOMERS_._CREDITLIMIT_), _CUSTOMERS_._CREDITLIMIT_]",
-                    Arrays.toString(dataSet.getSelectItems()).replaceAll("\"", "_"));
+                    Arrays.toString(dataSet.getSelectItems().toArray()).replaceAll("\"", "_"));
 
             assertTrue(dataSet.next());
             final Object value0 = dataSet.getRow().getValue(0);
@@ -282,7 +282,7 @@ public class JdbcDataContextTest extends JdbcTestCase {
         QueryParameter queryParameter = new QueryParameter();
 
         Query q = new Query();
-        Table table = schema.getTables()[0];
+        Table table = schema.getTables().get(0);
         q.select(new SelectItem("COUNT(*)", null));
         q.from(table, "a");
         q.where(table.getColumnByName("CREDITLIMIT"), OperatorType.GREATER_THAN_OR_EQUAL, queryParameter);
@@ -338,7 +338,7 @@ public class JdbcDataContextTest extends JdbcTestCase {
         QueryParameter queryParameter = new QueryParameter();
 
         Query q = new Query();
-        Table table = schema.getTables()[0];
+        Table table = schema.getTables().get(0);
         q.select(new SelectItem("COUNT(*)", null));
         q.from(table, "a");
         q.where(table.getColumnByName("CREDITLIMIT"), OperatorType.LESS_THAN_OR_EQUAL, queryParameter);
@@ -388,7 +388,7 @@ public class JdbcDataContextTest extends JdbcTestCase {
     public void testGetSchemaNormalTableTypes() throws Exception {
         Connection connection = getTestDbConnection();
         JdbcDataContext dc = new JdbcDataContext(connection, new TableType[] { TableType.TABLE, TableType.VIEW }, null);
-        Schema[] schemas = dc.getSchemas();
+        Schema[] schemas = dc.getSchemas().toArray(new Schema[dc.getSchemas().size()]);
 
         assertEquals(2, schemas.length);
         assertEquals("Schema[name=INFORMATION_SCHEMA]", schemas[0].toString());
@@ -405,7 +405,6 @@ public class JdbcDataContextTest extends JdbcTestCase {
                 TableType.GLOBAL_TEMPORARY }, null);
         Schema schema = dc.getDefaultSchema();
         Table customersTable = schema.getTableByName("CUSTOMERS");
-        Column[] columns = customersTable.getColumns();
         assertEquals(
                 "[Column[name=CUSTOMERNUMBER,columnNumber=0,type=INTEGER,nullable=false,nativeType=INTEGER,columnSize=0], "
                         + "Column[name=CUSTOMERNAME,columnNumber=1,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=50], "
@@ -423,7 +422,7 @@ public class JdbcDataContextTest extends JdbcTestCase {
                         + "Column[name=SALESREPEMPLOYEENUMBER,columnNumber=11,type=INTEGER,nullable=true,nativeType=INTEGER,"
                         + "columnSize=0], "
                         + "Column[name=CREDITLIMIT,columnNumber=12,type=NUMERIC,nullable=true,nativeType=NUMERIC,columnSize=17]]",
-                Arrays.toString(columns));
+                Arrays.toString(customersTable.getColumns().toArray()));
         connection.close();
     }
 
@@ -432,18 +431,16 @@ public class JdbcDataContextTest extends JdbcTestCase {
         JdbcDataContext dc = new JdbcDataContext(connection, new TableType[] { TableType.TABLE }, null);
         Schema schema = dc.getDefaultSchema();
         Table productsTable = schema.getTableByName("PRODUCTS");
-        Relationship[] relations = productsTable.getRelationships();
 
         /**
          * TODO: A single constraint now exists, create more ...
          */
         assertEquals("[Relationship[primaryTable=PRODUCTS,primaryColumns=[PRODUCTCODE],foreignTable=ORDERFACT,"
-                + "foreignColumns=[PRODUCTCODE]]]", Arrays.toString(relations));
+                + "foreignColumns=[PRODUCTCODE]]]", Arrays.toString(productsTable.getRelationships().toArray()));
 
-        Column[] indexedColumns = productsTable.getIndexedColumns();
         assertEquals(
                 "[Column[name=PRODUCTCODE,columnNumber=0,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=50]]",
-                Arrays.toString(indexedColumns));
+                Arrays.toString(productsTable.getIndexedColumns().toArray()));
 
         connection.close();
     }
@@ -494,7 +491,7 @@ public class JdbcDataContextTest extends JdbcTestCase {
         Schema schema = dc.getDefaultSchema();
 
         Query q = new Query().setMaxRows(3);
-        Table table = schema.getTables()[0];
+        Table table = schema.getTables().get(0);
         q.from(table, "a");
         q.select(table.getColumns());
         assertEquals("SELECT a.\"CUSTOMERNUMBER\", a.\"CUSTOMERNAME\", a.\"CONTACTLASTNAME\", a.\"CONTACTFIRSTNAME\", "
@@ -540,7 +537,7 @@ public class JdbcDataContextTest extends JdbcTestCase {
         final DataContext dataContext1 = new JdbcDataContext(connection);
         final DataContext dataContext2 = new QueryPostprocessDataContext() {
             @Override
-            public DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+            public DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) {
                 Query q = new Query();
                 q.from(table, "a");
                 q.select(columns);
@@ -578,7 +575,7 @@ public class JdbcDataContextTest extends JdbcTestCase {
                         + "Column[name=SALESREPEMPLOYEENUMBER,columnNumber=11,type=INTEGER,nullable=true,nativeType=INTEGER,"
                         + "columnSize=0], "
                         + "Column[name=CREDITLIMIT,columnNumber=12,type=NUMERIC,nullable=true,nativeType=NUMERIC,columnSize=17]]",
-                Arrays.toString(customersTable.getColumns()));
+                Arrays.toString(customersTable.getColumns().toArray()));
         assertEquals(
                 "[Column[name=EMPLOYEENUMBER,columnNumber=0,type=INTEGER,nullable=false,nativeType=INTEGER,columnSize=0], "
                         + "Column[name=LASTNAME,columnNumber=1,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=50], "
@@ -588,7 +585,7 @@ public class JdbcDataContextTest extends JdbcTestCase {
                         + "Column[name=OFFICECODE,columnNumber=5,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=20], "
                         + "Column[name=REPORTSTO,columnNumber=6,type=INTEGER,nullable=true,nativeType=INTEGER,columnSize=0], "
                         + "Column[name=JOBTITLE,columnNumber=7,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=50]]",
-                Arrays.toString(employeeTable.getColumns()));
+                Arrays.toString(employeeTable.getColumns().toArray()));
 
         Column employeeNumberColumn1 = customersTable.getColumnByName("SALESREPEMPLOYEENUMBER");
         Column countryColumn = customersTable.getColumnByName("COUNTRY");
index dbade6a..fa1b064 100644 (file)
@@ -50,7 +50,7 @@ public class JdbcDeleteBuilderTest extends JdbcTestCase {
                 dataContext), true);
 
         assertEquals("[EMPLOYEENUMBER, LASTNAME, FIRSTNAME, EXTENSION, EMAIL, OFFICECODE, REPORTSTO, JOBTITLE]",
-                Arrays.toString(table.getColumnNames()));
+                Arrays.toString(table.getColumnNames().toArray()));
 
         updateBuilder.where("firstname").isNull().where("lastname").isNotNull();
         assertEquals(
@@ -64,7 +64,7 @@ public class JdbcDeleteBuilderTest extends JdbcTestCase {
         JdbcUpdateCallback updateCallback = new JdbcSimpleUpdateCallback(dataContext);
 
         assertEquals("[EMPLOYEENUMBER, LASTNAME, FIRSTNAME, EXTENSION, EMAIL, OFFICECODE, REPORTSTO, JOBTITLE]",
-                Arrays.toString(table.getColumnNames()));
+                Arrays.toString(table.getColumnNames().toArray()));
 
         JdbcDeleteBuilder updateBuilder = new JdbcDeleteBuilder(updateCallback, table, new DefaultQueryRewriter(
                 dataContext), false);
index 8b56e05..2a29943 100644 (file)
@@ -33,7 +33,7 @@ public class JdbcInsertBuilderTest extends JdbcTestCase {
                                new DefaultQueryRewriter(dataContext));
 
                assertEquals("[EMPLOYEENUMBER, LASTNAME, FIRSTNAME, EXTENSION, EMAIL, OFFICECODE, REPORTSTO, JOBTITLE]",
-                               Arrays.toString(table.getColumnNames()));
+                               Arrays.toString(table.getColumnNames().toArray()));
 
                insertBuilder.value("LASTNAME", "foo").value("firstname", "BAR");
                assertEquals("INSERT INTO PUBLIC._EMPLOYEES_ (LASTNAME,FIRSTNAME) VALUES ('foo','BAR')", insertBuilder.createSqlStatement()
@@ -53,7 +53,7 @@ public class JdbcInsertBuilderTest extends JdbcTestCase {
                                new DefaultQueryRewriter(dataContext));
 
                assertEquals("[EMPLOYEENUMBER, LASTNAME, FIRSTNAME, EXTENSION, EMAIL, OFFICECODE, REPORTSTO, JOBTITLE]",
-                               Arrays.toString(table.getColumnNames()));
+                               Arrays.toString(table.getColumnNames().toArray()));
 
                insertBuilder.value("LASTNAME", "foo").value("firstname", null);
                assertEquals("INSERT INTO PUBLIC._EMPLOYEES_ (LASTNAME,FIRSTNAME) VALUES ('foo',NULL)", insertBuilder.createSqlStatement()
@@ -68,7 +68,7 @@ public class JdbcInsertBuilderTest extends JdbcTestCase {
                                new DefaultQueryRewriter(dataContext));
 
                assertEquals("[EMPLOYEENUMBER, LASTNAME, FIRSTNAME, EXTENSION, EMAIL, OFFICECODE, REPORTSTO, JOBTITLE]",
-                               Arrays.toString(table.getColumnNames()));
+                               Arrays.toString(table.getColumnNames().toArray()));
 
                insertBuilder.value("LASTNAME", "foo").value("firstname", "BAR");
                assertEquals("INSERT INTO PUBLIC._EMPLOYEES_ (LASTNAME,FIRSTNAME) VALUES ('foo','BAR')", insertBuilder.createSqlStatement()
index 020b37d..8654679 100644 (file)
@@ -54,7 +54,7 @@ public class JdbcSchemaTest extends JdbcTestCase {
 
                assertEquals(
                                "[CUSTOMERS, CUSTOMER_W_TER, DEPARTMENT_MANAGERS, DIM_TIME, EMPLOYEES, OFFICES, ORDERDETAILS, ORDERFACT, ORDERS, PAYMENTS, PRODUCTS, QUADRANT_ACTUALS, TRIAL_BALANCE]",
-                               Arrays.toString(schema.getTableNames()));
+                               Arrays.toString(schema.getTableNames().toArray()));
 
                connection.close();
                dataContext = null;
@@ -72,14 +72,14 @@ public class JdbcSchemaTest extends JdbcTestCase {
 
                assertEquals(
                                "[CUSTOMERS, CUSTOMER_W_TER, DEPARTMENT_MANAGERS, DIM_TIME, EMPLOYEES, OFFICES, ORDERDETAILS, ORDERFACT, ORDERS, PAYMENTS, PRODUCTS, QUADRANT_ACTUALS, TRIAL_BALANCE]",
-                               Arrays.toString(schema.getTableNames()));
+                               Arrays.toString(schema.getTableNames().toArray()));
 
                Table table = schema.getTableByName("CUSTOMERS");
                assertTrue(table instanceof JdbcTable);
                assertNotNull(table);
                assertEquals(
                                "[CUSTOMERNUMBER, CUSTOMERNAME, CONTACTLASTNAME, CONTACTFIRSTNAME, PHONE, ADDRESSLINE1, ADDRESSLINE2, CITY, STATE, POSTALCODE, COUNTRY, SALESREPEMPLOYEENUMBER, CREDITLIMIT]",
-                               Arrays.toString(table.getColumnNames()));
+                               Arrays.toString(table.getColumnNames().toArray()));
        }
 
        public void testToSerializableForm() throws Exception {
@@ -92,10 +92,10 @@ public class JdbcSchemaTest extends JdbcTestCase {
                Table table = schema.getTableByName("CUSTOMERS");
                assertEquals(
                                "[CUSTOMERNUMBER, CUSTOMERNAME, CONTACTLASTNAME, CONTACTFIRSTNAME, PHONE, ADDRESSLINE1, ADDRESSLINE2, CITY, STATE, POSTALCODE, COUNTRY, SALESREPEMPLOYEENUMBER, CREDITLIMIT]",
-                               Arrays.toString(table.getColumnNames()));
+                               Arrays.toString(table.getColumnNames().toArray()));
 
                assertEquals(
                                "[Relationship[primaryTable=PRODUCTS,primaryColumns=[PRODUCTCODE],foreignTable=ORDERFACT,foreignColumns=[PRODUCTCODE]]]",
-                               Arrays.toString(schema.getRelationships()));
+                               Arrays.toString(schema.getRelationships().toArray()));
        }
 }
\ No newline at end of file
index 0f6d82d..aca3780 100644 (file)
@@ -626,7 +626,7 @@ public class JdbcTestTemplates {
             final Table table = defaultSchema.getTableByName(testTableName);
             assertNotNull(table);
 
-            Column[] primaryKeys = table.getPrimaryKeys();
+            Column[] primaryKeys = table.getPrimaryKeys().toArray(new Column[table.getPrimaryKeys().size()]);
             assertEquals(2, primaryKeys.length);
             assertEquals("mykey1", primaryKeys[0].getName().toLowerCase());
             assertEquals("mykey2", primaryKeys[1].getName().toLowerCase());
index f44c77b..3c338ff 100644 (file)
@@ -33,7 +33,7 @@ public class JdbcUpdateBuilderTest extends JdbcTestCase {
                 dataContext), true);
 
         assertEquals("[EMPLOYEENUMBER, LASTNAME, FIRSTNAME, EXTENSION, EMAIL, OFFICECODE, REPORTSTO, JOBTITLE]",
-                Arrays.toString(table.getColumnNames()));
+                Arrays.toString(table.getColumnNames().toArray()));
 
         updateBuilder.value("LASTNAME", "foo").value("firstname", "BAR");
         assertEquals("UPDATE PUBLIC._EMPLOYEES_ SET LASTNAME='foo',FIRSTNAME='BAR'", updateBuilder.createSqlStatement()
@@ -58,7 +58,7 @@ public class JdbcUpdateBuilderTest extends JdbcTestCase {
                 dataContext), true);
 
         assertEquals("[EMPLOYEENUMBER, LASTNAME, FIRSTNAME, EXTENSION, EMAIL, OFFICECODE, REPORTSTO, JOBTITLE]",
-                Arrays.toString(table.getColumnNames()));
+                Arrays.toString(table.getColumnNames().toArray()));
 
         updateBuilder.value("LASTNAME", "foo").value("firstname", null);
         assertEquals("UPDATE PUBLIC._EMPLOYEES_ SET LASTNAME='foo',FIRSTNAME=NULL", updateBuilder.createSqlStatement()
@@ -71,7 +71,7 @@ public class JdbcUpdateBuilderTest extends JdbcTestCase {
         JdbcUpdateCallback updateCallback = new JdbcSimpleUpdateCallback(dataContext);
 
         assertEquals("[EMPLOYEENUMBER, LASTNAME, FIRSTNAME, EXTENSION, EMAIL, OFFICECODE, REPORTSTO, JOBTITLE]",
-                Arrays.toString(table.getColumnNames()));
+                Arrays.toString(table.getColumnNames().toArray()));
 
         JdbcUpdateBuilder updateBuilder = new JdbcUpdateBuilder(updateCallback, table, new DefaultQueryRewriter(
                 dataContext), false);
@@ -89,7 +89,7 @@ public class JdbcUpdateBuilderTest extends JdbcTestCase {
                 dataContext), true);
 
         assertEquals("[EMPLOYEENUMBER, LASTNAME, FIRSTNAME, EXTENSION, EMAIL, OFFICECODE, REPORTSTO, JOBTITLE]",
-                Arrays.toString(table.getColumnNames()));
+                Arrays.toString(table.getColumnNames().toArray()));
 
         updateBuilder.value("LASTNAME", "foo").value("firstname", "BAR");
         assertEquals("UPDATE PUBLIC._EMPLOYEES_ SET LASTNAME='foo',FIRSTNAME='BAR'", updateBuilder.createSqlStatement()
index 8e4842c..a67dc63 100644 (file)
@@ -43,7 +43,7 @@ public class QuerySplitterTest extends JdbcTestCase {
                Table customersTable = schema.getTableByName("CUSTOMERS");
                Query q = new Query().from(employeesTable, "e").from(customersTable,
                                "c");
-               q.select(employeesTable.getColumns()[0], customersTable.getColumns()[0]);
+               q.select(employeesTable.getColumns().get(0), customersTable.getColumns().get(0));
                assertEquals(
                                "SELECT e._EMPLOYEENUMBER_, c._CUSTOMERNUMBER_ FROM PUBLIC._EMPLOYEES_ e, PUBLIC._CUSTOMERS_ c",
                                q.toString().replace('\"', '_'));
@@ -83,10 +83,10 @@ public class QuerySplitterTest extends JdbcTestCase {
                Table orderDetailsTable = schema.getTableByName("ORDERDETAILS");
                Query q = new Query().from(employeesTable, "e").from(orderDetailsTable,
                                "c");
-               q.select(orderDetailsTable.getColumns()[0])
+               q.select(orderDetailsTable.getColumns().get(0))
                                .select(new SelectItem(FunctionType.MAX, employeesTable
-                                               .getColumns()[0]));
-               q.groupBy(orderDetailsTable.getColumns()[0]);
+                                               .getColumns().get(0)));
+               q.groupBy(orderDetailsTable.getColumns().get(0));
                assertEquals(
                                "SELECT c._ORDERNUMBER_, MAX(e._EMPLOYEENUMBER_) FROM PUBLIC._EMPLOYEES_ e, PUBLIC._ORDERDETAILS_ c GROUP BY c._ORDERNUMBER_",
                                q.toString().replace('\"', '_'));
@@ -121,8 +121,7 @@ public class QuerySplitterTest extends JdbcTestCase {
                DataContext dc = new JdbcDataContext(con);
                Schema schema = dc.getDefaultSchema();
                Table productsTable = schema.getTableByName("PRODUCTS");
-               Relationship[] relationships = productsTable.getRelationships();
-               Relationship relationship = relationships[0];
+               Relationship relationship = productsTable.getRelationships().iterator().next();
                assertEquals(
                                "Relationship[primaryTable=PRODUCTS,primaryColumns=[PRODUCTCODE],foreignTable=ORDERFACT,foreignColumns=[PRODUCTCODE]]",
                                relationship.toString());
@@ -153,9 +152,9 @@ public class QuerySplitterTest extends JdbcTestCase {
                Query sq = new Query().from(employeesTable, "e").from(customersTable,
                                "c");
                SelectItem empSelectItem = new SelectItem(
-                               employeesTable.getColumns()[0]);
+                               employeesTable.getColumns().get(0));
                SelectItem custSelectItem = new SelectItem(
-                               customersTable.getColumns()[0]);
+                               customersTable.getColumns().get(0));
                sq.select(empSelectItem, custSelectItem);
                assertEquals(
                                "SELECT e._EMPLOYEENUMBER_, c._CUSTOMERNUMBER_ FROM PUBLIC._EMPLOYEES_ e, PUBLIC._CUSTOMERS_ c",
index 3a8d1a4..6e4b417 100644 (file)
@@ -97,14 +97,13 @@ public class SqliteTest extends TestCase {
 
     public void testGetSchemas() throws Exception {
         DataContext dc = new JdbcDataContext(_connection);
-        String[] schemaNames = dc.getSchemaNames();
+        String[] schemaNames = dc.getSchemaNames().toArray(new String[dc.getSchemaNames().size()]);
         assertEquals("[null]", Arrays.toString(schemaNames));
 
         Schema schema = dc.getDefaultSchema();
         assertNotNull(schema);
         assertNull(schema.getName());
 
-        Table[] tables = schema.getTables();
         assertEquals("[Table[name=system,type=TABLE,remarks=null], "
                 + "Table[name=permission,type=TABLE,remarks=null], "
                 + "Table[name=auth_cookie,type=TABLE,remarks=null], " + "Table[name=session,type=TABLE,remarks=null], "
@@ -115,11 +114,11 @@ public class SqliteTest extends TestCase {
                 + "Table[name=ticket_custom,type=TABLE,remarks=null], " + "Table[name=enum,type=TABLE,remarks=null], "
                 + "Table[name=component,type=TABLE,remarks=null], " + "Table[name=milestone,type=TABLE,remarks=null], "
                 + "Table[name=version,type=TABLE,remarks=null], " + "Table[name=report,type=TABLE,remarks=null]]",
-                Arrays.toString(tables));
+                Arrays.toString(schema.getTables().toArray()));
 
         // Index- and key-info is not yet implemented in the JDBC driver
 
-        assertEquals("[]", Arrays.toString(schema.getRelationships()));
+        assertEquals("[]", Arrays.toString(schema.getRelationships().toArray()));
 
         Table wikiTable = schema.getTableByName("WIKI");
         assertEquals(
@@ -131,13 +130,13 @@ public class SqliteTest extends TestCase {
                         + "Column[name=text,columnNumber=5,type=VARCHAR,nullable=true,nativeType=TEXT,columnSize=2000000000], "
                         + "Column[name=comment,columnNumber=6,type=VARCHAR,nullable=true,nativeType=TEXT,columnSize=2000000000], "
                         + "Column[name=readonly,columnNumber=7,type=INTEGER,nullable=true,nativeType=INTEGER,columnSize=2000000000]]",
-                Arrays.toString(wikiTable.getColumns()));
+                Arrays.toString(wikiTable.getColumns().toArray()));
 
         Table permissionTable = schema.getTableByName("PERMISSION");
         assertEquals(
                 "[Column[name=username,columnNumber=0,type=VARCHAR,nullable=true,nativeType=TEXT,columnSize=2000000000], "
                         + "Column[name=action,columnNumber=1,type=VARCHAR,nullable=true,nativeType=TEXT,columnSize=2000000000]]",
-                Arrays.toString(permissionTable.getColumns()));
+                Arrays.toString(permissionTable.getColumns().toArray()));
     }
 
     public void testExecuteQuery() throws Exception {
index aef6f51..f4a7df7 100644 (file)
@@ -85,8 +85,7 @@ public class DB2Test extends AbstractJdbIntegrationTest {
         }
         JdbcDataContext dc = new JdbcDataContext(getConnection());
         Schema schema = dc.getDefaultSchema();
-        String[] tableNames = schema.getTableNames();
-        System.out.println("Tables: " + Arrays.toString(tableNames));
+        System.out.println("Tables: " + Arrays.toString(schema.getTableNames().toArray()));
 
         Table countryTable = schema.getTableByName("COUNTRY");
         assertNotNull(countryTable);
@@ -110,8 +109,7 @@ public class DB2Test extends AbstractJdbIntegrationTest {
         }
         JdbcDataContext dc = new JdbcDataContext(getConnection());
         Schema schema = dc.getDefaultSchema();
-        String[] tableNames = schema.getTableNames();
-        System.out.println("Tables: " + Arrays.toString(tableNames));
+        System.out.println("Tables: " + Arrays.toString(schema.getTableNames().toArray()));
 
         Table countryTable = schema.getTableByName("COUNTRY");
         assertNotNull(countryTable);
index f883e83..9857ea5 100644 (file)
@@ -21,9 +21,13 @@ package org.apache.metamodel.jdbc.integrationtests;
 import java.text.SimpleDateFormat;
 import java.util.Arrays;
 import java.util.Date;
+import java.util.Set;
+import java.util.stream.Collectors;
 
+import javax.management.relation.Relation;
 import javax.swing.table.TableModel;
 
+import com.google.common.collect.Sets;
 import org.apache.metamodel.data.DataSet;
 import org.apache.metamodel.data.DataSetTableModel;
 import org.apache.metamodel.jdbc.JdbcDataContext;
@@ -56,7 +60,7 @@ public class FirebirdTest extends AbstractJdbIntegrationTest {
                return;
            }
                JdbcDataContext dataContext = getDataContext();
-        Schema[] schemas = dataContext.getSchemas();
+        Schema[] schemas = dataContext.getSchemas().toArray(new Schema[dataContext.getSchemas().size()]);
                assertEquals(1, schemas.length);
                Schema schema = dataContext.getDefaultSchema();
                assertEquals("{JdbcTable[name=COUNTRY,type=TABLE,remarks=<null>],"
@@ -69,26 +73,28 @@ public class FirebirdTest extends AbstractJdbIntegrationTest {
                                + "JdbcTable[name=PROJECT,type=TABLE,remarks=<null>],"
                                + "JdbcTable[name=PROJ_DEPT_BUDGET,type=TABLE,remarks=<null>],"
                                + "JdbcTable[name=SALARY_HISTORY,type=TABLE,remarks=<null>],"
-                               + "JdbcTable[name=SALES,type=TABLE,remarks=<null>]}", Arrays.toString(schema.getTables()));
-
-               assertEquals(
-                               "{Relationship[primaryTable=COUNTRY,primaryColumns={COUNTRY},foreignTable=CUSTOMER,foreignColumns={COUNTRY}],"
-                                               + "Relationship[primaryTable=COUNTRY,primaryColumns={COUNTRY},foreignTable=JOB,foreignColumns={JOB_COUNTRY}],"
-                                               + "Relationship[primaryTable=CUSTOMER,primaryColumns={CUST_NO},foreignTable=SALES,foreignColumns={CUST_NO}],"
-                                               + "Relationship[primaryTable=DEPARTMENT,primaryColumns={DEPT_NO},foreignTable=DEPARTMENT,foreignColumns={HEAD_DEPT}],"
-                                               + "Relationship[primaryTable=DEPARTMENT,primaryColumns={DEPT_NO},foreignTable=EMPLOYEE,foreignColumns={DEPT_NO}],"
-                                               + "Relationship[primaryTable=DEPARTMENT,primaryColumns={DEPT_NO},foreignTable=PROJ_DEPT_BUDGET,foreignColumns={DEPT_NO}],"
-                                               + "Relationship[primaryTable=EMPLOYEE,primaryColumns={EMP_NO},foreignTable=DEPARTMENT,foreignColumns={MNGR_NO}],"
-                                               + "Relationship[primaryTable=EMPLOYEE,primaryColumns={EMP_NO},foreignTable=EMPLOYEE_PROJECT,foreignColumns={EMP_NO}],"
-                                               + "Relationship[primaryTable=EMPLOYEE,primaryColumns={EMP_NO},foreignTable=PROJECT,foreignColumns={TEAM_LEADER}],"
-                                               + "Relationship[primaryTable=EMPLOYEE,primaryColumns={EMP_NO},foreignTable=SALARY_HISTORY,foreignColumns={EMP_NO}],"
-                                               + "Relationship[primaryTable=EMPLOYEE,primaryColumns={EMP_NO},foreignTable=SALES,foreignColumns={SALES_REP}],"
-                                               + "Relationship[primaryTable=JOB,primaryColumns={JOB_CODE},foreignTable=EMPLOYEE,foreignColumns={JOB_CODE}],"
-                                               + "Relationship[primaryTable=JOB,primaryColumns={JOB_GRADE},foreignTable=EMPLOYEE,foreignColumns={JOB_GRADE}],"
-                                               + "Relationship[primaryTable=JOB,primaryColumns={JOB_COUNTRY},foreignTable=EMPLOYEE,foreignColumns={JOB_COUNTRY}],"
-                                               + "Relationship[primaryTable=PROJECT,primaryColumns={PROJ_ID},foreignTable=EMPLOYEE_PROJECT,foreignColumns={PROJ_ID}],"
-                                               + "Relationship[primaryTable=PROJECT,primaryColumns={PROJ_ID},foreignTable=PROJ_DEPT_BUDGET,foreignColumns={PROJ_ID}]}",
-                               Arrays.toString(schema.getRelationships()));
+                               + "JdbcTable[name=SALES,type=TABLE,remarks=<null>]}", Arrays.toString(schema.getTables().toArray()));
+               
+               Set<String> relationStrings = schema.getRelationships().stream().map(rel -> rel.toString()).collect(Collectors.toSet());
+               Set<String> referenceRelationStrings = Sets.newHashSet(
+                               "Relationship[primaryTable=COUNTRY,primaryColumns={COUNTRY},foreignTable=CUSTOMER,foreignColumns={COUNTRY}]",
+                                               "Relationship[primaryTable=COUNTRY,primaryColumns={COUNTRY},foreignTable=JOB,foreignColumns={JOB_COUNTRY}]",
+                                               "Relationship[primaryTable=CUSTOMER,primaryColumns={CUST_NO},foreignTable=SALES,foreignColumns={CUST_NO}]",
+                                               "Relationship[primaryTable=DEPARTMENT,primaryColumns={DEPT_NO},foreignTable=DEPARTMENT,foreignColumns={HEAD_DEPT}]",
+                                               "Relationship[primaryTable=DEPARTMENT,primaryColumns={DEPT_NO},foreignTable=EMPLOYEE,foreignColumns={DEPT_NO}]",
+                                               "Relationship[primaryTable=DEPARTMENT,primaryColumns={DEPT_NO},foreignTable=PROJ_DEPT_BUDGET,foreignColumns={DEPT_NO}]",
+                                               "Relationship[primaryTable=EMPLOYEE,primaryColumns={EMP_NO},foreignTable=DEPARTMENT,foreignColumns={MNGR_NO}]",
+                                               "Relationship[primaryTable=EMPLOYEE,primaryColumns={EMP_NO},foreignTable=EMPLOYEE_PROJECT,foreignColumns={EMP_NO}]",
+                                               "Relationship[primaryTable=EMPLOYEE,primaryColumns={EMP_NO},foreignTable=PROJECT,foreignColumns={TEAM_LEADER}]",
+                                               "Relationship[primaryTable=EMPLOYEE,primaryColumns={EMP_NO},foreignTable=SALARY_HISTORY,foreignColumns={EMP_NO}]",
+                                               "Relationship[primaryTable=EMPLOYEE,primaryColumns={EMP_NO},foreignTable=SALES,foreignColumns={SALES_REP}]",
+                                               "Relationship[primaryTable=JOB,primaryColumns={JOB_CODE},foreignTable=EMPLOYEE,foreignColumns={JOB_CODE}]",
+                                               "Relationship[primaryTable=JOB,primaryColumns={JOB_GRADE},foreignTable=EMPLOYEE,foreignColumns={JOB_GRADE}]",
+                                               "Relationship[primaryTable=JOB,primaryColumns={JOB_COUNTRY},foreignTable=EMPLOYEE,foreignColumns={JOB_COUNTRY}]",
+                                               "Relationship[primaryTable=PROJECT,primaryColumns={PROJ_ID},foreignTable=EMPLOYEE_PROJECT,foreignColumns={PROJ_ID}]",
+                                               "Relationship[primaryTable=PROJECT,primaryColumns={PROJ_ID},foreignTable=PROJ_DEPT_BUDGET,foreignColumns={PROJ_ID}]"
+               );
+               assertEquals(relationStrings,referenceRelationStrings);
        }
 
        public void testExecuteQuery() throws Exception {
@@ -99,9 +105,9 @@ public class FirebirdTest extends AbstractJdbIntegrationTest {
         Schema schema = dataContext.getDefaultSchema();
                Table departmentTable = schema.getTableByName("DEPARTMENT");
                Table employeeTable = schema.getTableByName("EMPLOYEE");
-               Query q = new Query().from(new FromItem(JoinType.INNER, departmentTable.getRelationships(employeeTable)[0]));
-               q.select(departmentTable.getColumns()[1]);
-               q.select(new SelectItem(employeeTable.getColumns()[4]).setAlias("hire-date"));
+               Query q = new Query().from(new FromItem(JoinType.INNER, departmentTable.getRelationships(employeeTable).iterator().next()));
+               q.select(departmentTable.getColumns().get(1));
+               q.select(new SelectItem(employeeTable.getColumns().get(4)).setAlias("hire-date"));
                assertEquals(
                                "SELECT \"DEPARTMENT\".\"DEPARTMENT\", \"EMPLOYEE\".\"HIRE_DATE\" AS hire-date FROM \"EMPLOYEE\" INNER JOIN \"DEPARTMENT\" ON \"EMPLOYEE\".\"EMP_NO\" = \"DEPARTMENT\".\"MNGR_NO\"",
                                q.toString());
index c5485ca..dc93a28 100644 (file)
@@ -227,17 +227,17 @@ public class MysqlTest extends AbstractJdbIntegrationTest {
         Table actorTable = schema.getTableByName("actor");
         assertEquals(
                 "[Column[name=actor_id,columnNumber=0,type=SMALLINT,nullable=false,nativeType=SMALLINT UNSIGNED,columnSize=5], Column[name=first_name,columnNumber=1,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=45], Column[name=last_name,columnNumber=2,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=45], Column[name=last_update,columnNumber=3,type=TIMESTAMP,nullable=false,nativeType=TIMESTAMP,columnSize=19]]",
-                Arrays.toString(actorTable.getColumns()));
+                Arrays.toString(actorTable.getColumns().toArray()));
         Table filmTable = schema.getTableByName("film");
         assertEquals(
                 "[Column[name=film_id,columnNumber=0,type=SMALLINT,nullable=false,nativeType=SMALLINT UNSIGNED,columnSize=5], Column[name=title,columnNumber=1,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=255], Column[name=description,columnNumber=2,type=LONGVARCHAR,nullable=true,nativeType=TEXT,columnSize=65535], Column[name=release_year,columnNumber=3,type=DATE,nullable=true,nativeType=YEAR,columnSize=0], Column[name=language_id,columnNumber=4,type=TINYINT,nullable=false,nativeType=TINYINT UNSIGNED,columnSize=3], Column[name=original_language_id,columnNumber=5,type=TINYINT,nullable=true,nativeType=TINYINT UNSIGNED,columnSize=3], Column[name=rental_duration,columnNumber=6,type=TINYINT,nullable=false,nativeType=TINYINT UNSIGNED,columnSize=3], Column[name=rental_rate,columnNumber=7,type=DECIMAL,nullable=false,nativeType=DECIMAL,columnSize=4], Column[name=length,columnNumber=8,type=SMALLINT,nullable=true,nativeType=SMALLINT UNSIGNED,columnSize=5], Column[name=replacement_cost,columnNumber=9,type=DECIMAL,nullable=false,nativeType=DECIMAL,columnSize=5], Column[name=rating,columnNumber=10,type=CHAR,nullable=true,nativeType=ENUM,columnSize=5], Column[name=special_features,columnNumber=11,type=CHAR,nullable=true,nativeType=SET,columnSize=54], Column[name=last_update,columnNumber=12,type=TIMESTAMP,nullable=false,nativeType=TIMESTAMP,columnSize=19]]",
-                Arrays.toString(filmTable.getColumns()));
+                Arrays.toString(filmTable.getColumns().toArray()));
         Table filmActorJoinTable = schema.getTableByName("film_actor");
         assertEquals(
                 "[Column[name=actor_id,columnNumber=0,type=SMALLINT,nullable=false,nativeType=SMALLINT UNSIGNED,columnSize=5], "
                         + "Column[name=film_id,columnNumber=1,type=SMALLINT,nullable=false,nativeType=SMALLINT UNSIGNED,columnSize=5], "
                         + "Column[name=last_update,columnNumber=2,type=TIMESTAMP,nullable=false,nativeType=TIMESTAMP,columnSize=19]]",
-                Arrays.toString(filmActorJoinTable.getColumns()));
+                Arrays.toString(filmActorJoinTable.getColumns().toArray()));
 
         Query q = new Query();
         q.from(new FromItem(actorTable).setAlias("a"));
@@ -314,7 +314,7 @@ public class MysqlTest extends AbstractJdbIntegrationTest {
                 + "Table[name=nicer_but_slower_film_list,type=VIEW,remarks=], "
                 + "Table[name=sales_by_film_category,type=VIEW,remarks=], "
                 + "Table[name=sales_by_store,type=VIEW,remarks=], " + "Table[name=staff_list,type=VIEW,remarks=]]",
-                Arrays.toString(schema.getTables()));
+                Arrays.toString(schema.getTables().toArray()));
 
         Table filmTable = schema.getTableByName("film");
         assertEquals(
@@ -331,10 +331,10 @@ public class MysqlTest extends AbstractJdbIntegrationTest {
                         + "Column[name=rating,columnNumber=10,type=CHAR,nullable=true,nativeType=ENUM,columnSize=5], "
                         + "Column[name=special_features,columnNumber=11,type=CHAR,nullable=true,nativeType=SET,columnSize=54], "
                         + "Column[name=last_update,columnNumber=12,type=TIMESTAMP,nullable=false,nativeType=TIMESTAMP,columnSize=19]]",
-                Arrays.toString(filmTable.getColumns()));
+                Arrays.toString(filmTable.getColumns().toArray()));
         assertEquals(
                 "[Relationship[primaryTable=language,primaryColumns=[language_id],foreignTable=film,foreignColumns=[language_id]], Relationship[primaryTable=language,primaryColumns=[language_id],foreignTable=film,foreignColumns=[original_language_id]], Relationship[primaryTable=film,primaryColumns=[film_id],foreignTable=film_actor,foreignColumns=[film_id]], Relationship[primaryTable=film,primaryColumns=[film_id],foreignTable=film_category,foreignColumns=[film_id]], Relationship[primaryTable=film,primaryColumns=[film_id],foreignTable=inventory,foreignColumns=[film_id]]]",
-                Arrays.toString(filmTable.getRelationships()));
+                Arrays.toString(filmTable.getRelationships().toArray()));
 
         assertEquals("[Table[name=actor,type=TABLE,remarks=], " + "Table[name=address,type=TABLE,remarks=], "
                 + "Table[name=category,type=TABLE,remarks=], " + "Table[name=city,type=TABLE,remarks=], "
@@ -349,7 +349,7 @@ public class MysqlTest extends AbstractJdbIntegrationTest {
                 + "Table[name=nicer_but_slower_film_list,type=VIEW,remarks=], "
                 + "Table[name=sales_by_film_category,type=VIEW,remarks=], "
                 + "Table[name=sales_by_store,type=VIEW,remarks=], " + "Table[name=staff_list,type=VIEW,remarks=]]",
-                Arrays.toString(schema.getTables()));
+                Arrays.toString(schema.getTables().toArray()));
 
         Table staffView = schema.getTableByName("staff_list");
         assertEquals(
@@ -361,7 +361,7 @@ public class MysqlTest extends AbstractJdbIntegrationTest {
                         + "Column[name=city,columnNumber=5,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=50], "
                         + "Column[name=country,columnNumber=6,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=50], "
                         + "Column[name=SID,columnNumber=7,type=TINYINT,nullable=false,nativeType=TINYINT UNSIGNED,columnSize=3]]",
-                Arrays.toString(staffView.getColumns()));
+                Arrays.toString(staffView.getColumns().toArray()));
     }
 
     public void testSplitQuery() throws Exception {
@@ -377,7 +377,7 @@ public class MysqlTest extends AbstractJdbIntegrationTest {
         assertNotNull(paymentTable);
         Column countryColumn = staffListTable.getColumnByName("country");
         assertNotNull(countryColumn);
-        Column paymentColumn = paymentTable.getColumns()[0];
+        Column paymentColumn = paymentTable.getColumns().get(0);
         assertNotNull(paymentColumn);
         Query q = new Query().from(staffListTable, "sl").from(paymentTable, "e").select(countryColumn, paymentColumn);
         assertEquals("SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e",
index 6924362..826bc81 100644 (file)
@@ -21,10 +21,16 @@ package org.apache.metamodel.jdbc.integrationtests;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.util.Arrays;
+import java.util.Collection;
+import java.util.Optional;
+import java.util.Set;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
 
 import javax.swing.table.TableModel;
+import javax.swing.text.html.Option;
 
+import com.google.common.collect.Sets;
 import org.apache.metamodel.DataContext;
 import org.apache.metamodel.data.DataSet;
 import org.apache.metamodel.data.DataSetTableModel;
@@ -126,7 +132,7 @@ public class OracleTest extends AbstractJdbIntegrationTest {
             return;
         }
         DataContext dc = new JdbcDataContext(getConnection());
-        String[] schemaNames = dc.getSchemaNames();
+        String[] schemaNames = dc.getSchemaNames().toArray(new String[dc.getSchemas().size()]);
 
         String concatSchemas = Arrays.toString(schemaNames);
 
@@ -198,16 +204,19 @@ public class OracleTest extends AbstractJdbIntegrationTest {
                 + ",JdbcTable[name=JOB_HISTORY,type=TABLE,remarks=<null>]"
                 + ",JdbcTable[name=LOCATIONS,type=TABLE,remarks=<null>]"
                 + ",JdbcTable[name=REGIONS,type=TABLE,remarks=<null>]"
-                + ",JdbcTable[name=EMP_DETAILS_VIEW,type=VIEW,remarks=<null>]}", Arrays.toString(schema.getTables()));
+                + ",JdbcTable[name=EMP_DETAILS_VIEW,type=VIEW,remarks=<null>]}", Arrays.toString(schema.getTables().toArray()));
 
-        Relationship[] employeeRelationships = schema.getTableByName("EMPLOYEES").getRelationships();
-        assertEquals(
-                "{Relationship[primaryTable=EMPLOYEES,primaryColumns={EMPLOYEE_ID},foreignTable=DEPARTMENTS,foreignColumns={MANAGER_ID}],"
-                        + "Relationship[primaryTable=DEPARTMENTS,primaryColumns={DEPARTMENT_ID},foreignTable=EMPLOYEES,foreignColumns={DEPARTMENT_ID}],"
-                        + "Relationship[primaryTable=EMPLOYEES,primaryColumns={EMPLOYEE_ID},foreignTable=EMPLOYEES,foreignColumns={MANAGER_ID}],"
-                        + "Relationship[primaryTable=JOBS,primaryColumns={JOB_ID},foreignTable=EMPLOYEES,foreignColumns={JOB_ID}],"
-                        + "Relationship[primaryTable=EMPLOYEES,primaryColumns={EMPLOYEE_ID},foreignTable=JOB_HISTORY,foreignColumns={EMPLOYEE_ID}]}",
-                Arrays.toString(employeeRelationships));
+        Collection<Relationship> employeeRelationships = schema.getTableByName("EMPLOYEES").getRelationships();
+
+        Set<String> employeeRelStrings = employeeRelationships.stream().map(rel -> rel.toString()).collect(Collectors.toSet());
+
+        assertEquals(Sets.newHashSet(
+                "Relationship[primaryTable=EMPLOYEES,primaryColumns={EMPLOYEE_ID},foreignTable=DEPARTMENTS,foreignColumns={MANAGER_ID}]",
+                        "Relationship[primaryTable=DEPARTMENTS,primaryColumns={DEPARTMENT_ID},foreignTable=EMPLOYEES,foreignColumns={DEPARTMENT_ID}]",
+                        "Relationship[primaryTable=EMPLOYEES,primaryColumns={EMPLOYEE_ID},foreignTable=EMPLOYEES,foreignColumns={MANAGER_ID}]",
+                        "Relationship[primaryTable=JOBS,primaryColumns={JOB_ID},foreignTable=EMPLOYEES,foreignColumns={JOB_ID}]",
+                        "Relationship[primaryTable=EMPLOYEES,primaryColumns={EMPLOYEE_ID},foreignTable=JOB_HISTORY,foreignColumns={EMPLOYEE_ID}]"),
+                employeeRelStrings);
 
         assertEquals(
                 "{JdbcColumn[name=EMPLOYEE_ID,columnNumber=0,type=DECIMAL,nullable=false,nativeType=NUMBER,columnSize=6],"
@@ -221,14 +230,14 @@ public class OracleTest extends AbstractJdbIntegrationTest {
                         + "JdbcColumn[name=COMMISSION_PCT,columnNumber=8,type=DECIMAL,nullable=true,nativeType=NUMBER,columnSize=2],"
                         + "JdbcColumn[name=MANAGER_ID,columnNumber=9,type=DECIMAL,nullable=true,nativeType=NUMBER,columnSize=6],"
                         + "JdbcColumn[name=DEPARTMENT_ID,columnNumber=10,type=DECIMAL,nullable=true,nativeType=NUMBER,columnSize=4]}",
-                Arrays.toString(schema.getTableByName("EMPLOYEES").getColumns()));
+                Arrays.toString(schema.getTableByName("EMPLOYEES").getColumns().toArray()));
 
         assertEquals(
                 "{JdbcColumn[name=DEPARTMENT_ID,columnNumber=0,type=DECIMAL,nullable=false,nativeType=NUMBER,columnSize=4],"
                         + "JdbcColumn[name=DEPARTMENT_NAME,columnNumber=1,type=VARCHAR,nullable=false,nativeType=VARCHAR2,columnSize=30],"
                         + "JdbcColumn[name=MANAGER_ID,columnNumber=2,type=DECIMAL,nullable=true,nativeType=NUMBER,columnSize=6],"
                         + "JdbcColumn[name=LOCATION_ID,columnNumber=3,type=DECIMAL,nullable=true,nativeType=NUMBER,columnSize=4]}",
-                Arrays.toString(schema.getTableByName("DEPARTMENTS").getColumns()));
+                Arrays.toString(schema.getTableByName("DEPARTMENTS").getColumns().toArray()));
     }
 
     public void testExecuteQuery() throws Exception {
@@ -238,12 +247,12 @@ public class OracleTest extends AbstractJdbIntegrationTest {
         Schema schema = getDataContext().getSchemaByName("HR");
         Table employeeTable = schema.getTableByName("EMPLOYEES");
         Table departmentsTable = schema.getTableByName("DEPARTMENTS");
-        Relationship relationship = employeeTable.getRelationships(departmentsTable)[0];
-        assertEquals(
-                "Relationship[primaryTable=EMPLOYEES,primaryColumns={EMPLOYEE_ID},foreignTable=DEPARTMENTS,foreignColumns={MANAGER_ID}]",
-                relationship.toString());
+        Optional<Relationship> relationship = employeeTable.getRelationships(departmentsTable).stream()
+                .filter(rel-> rel.toString().equals("Relationship[primaryTable=EMPLOYEES,primaryColumns={EMPLOYEE_ID},foreignTable=DEPARTMENTS,foreignColumns={MANAGER_ID}]"))
+                .findFirst();
+        assertTrue(relationship.isPresent());
 
-        Query q = new Query().from(new FromItem(JoinType.INNER, relationship)).select(
+        Query q = new Query().from(new FromItem(JoinType.INNER, relationship.get())).select(
                 employeeTable.getColumnByName("EMAIL"), departmentsTable.getColumnByName("DEPARTMENT_NAME"));
         q.getSelectClause().getItem(0).setAlias("e-mail");
 
index 6f8fb09..a34be81 100644 (file)
@@ -21,11 +21,7 @@ package org.apache.metamodel.jdbc.integrationtests;
 import java.lang.reflect.Method;
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Optional;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 
 import javax.swing.table.TableModel;
@@ -455,15 +451,15 @@ public class PostgresqlTest extends AbstractJdbIntegrationTest {
         try {
             DataSet ds = dc.query().from("my_table").select("some_double").execute();
             assertTrue(ds.next());
-            Double minVal = (Double) ds.getRow().getValue(ds.getSelectItems()[0]);
+            Double minVal = (Double) ds.getRow().getValue(ds.getSelectItems().get(0));
             assertTrue(ds.next());
-            Double maxVal = (Double) ds.getRow().getValue(ds.getSelectItems()[0]);
+            Double maxVal = (Double) ds.getRow().getValue(ds.getSelectItems().get(0));
             assertTrue(ds.next());
-            Double negInf = (Double) ds.getRow().getValue(ds.getSelectItems()[0]);
+            Double negInf = (Double) ds.getRow().getValue(ds.getSelectItems().get(0));
             assertTrue(ds.next());
-            Double posInf = (Double) ds.getRow().getValue(ds.getSelectItems()[0]);
+            Double posInf = (Double) ds.getRow().getValue(ds.getSelectItems().get(0));
             assertTrue(ds.next());
-            Double nAn = (Double) ds.getRow().getValue(ds.getSelectItems()[0]);
+            Double nAn = (Double) ds.getRow().getValue(ds.getSelectItems().get(0));
             assertFalse(ds.next());
 
             assertEquals(Double.MIN_VALUE, minVal, DELTA);
@@ -604,7 +600,7 @@ public class PostgresqlTest extends AbstractJdbIntegrationTest {
                     Table table = cb.createTable(schema, "my_table").withColumn("id").ofType(ColumnType.INTEGER)
                             .ofNativeType("SERIAL").nullable(false).withColumn("person name").ofSize(255).withColumn(
                                     "age").ofType(ColumnType.INTEGER).execute();
-                    assertEquals("[id, person name, age]", Arrays.toString(table.getColumnNames()));
+                    assertEquals("[id, person name, age]", Arrays.toString(table.getColumnNames().toArray()));
                     assertEquals(
                             "Column[name=id,columnNumber=0,type=INTEGER,nullable=false,nativeType=serial,columnSize=10]",
                             table.getColumnByName("id").toString());
@@ -670,7 +666,7 @@ public class PostgresqlTest extends AbstractJdbIntegrationTest {
                     Table table = cb.createTable(schema, "my_table").withColumn("id").ofType(ColumnType.INTEGER)
                             .ofNativeType("SERIAL").nullable(false).withColumn("person name").ofSize(255).withColumn(
                                     "age").ofType(ColumnType.INTEGER).execute();
-                    assertEquals("[id, person name, age]", Arrays.toString(table.getColumnNames()));
+                    assertEquals("[id, person name, age]", Arrays.toString(table.getColumnNames().toArray()));
                     assertEquals(
                             "Column[name=id,columnNumber=0,type=INTEGER,nullable=false,nativeType=serial,columnSize=10]",
                             table.getColumnByName("id").toString());
@@ -723,7 +719,7 @@ public class PostgresqlTest extends AbstractJdbIntegrationTest {
                     Table table = cb.createTable(schema, "my_table").withColumn("id").ofType(ColumnType.INTEGER)
                             .ofNativeType("SERIAL").nullable(false).withColumn("person name").ofSize(255).withColumn(
                                     "age").ofType(ColumnType.INTEGER).execute();
-                    assertEquals("[id, person name, age]", Arrays.toString(table.getColumnNames()));
+                    assertEquals("[id, person name, age]", Arrays.toString(table.getColumnNames().toArray()));
                     assertEquals(
                             "Column[name=id,columnNumber=0,type=INTEGER,nullable=false,nativeType=serial,columnSize=10]",
                             table.getColumnByName("id").toString());
@@ -781,8 +777,8 @@ public class PostgresqlTest extends AbstractJdbIntegrationTest {
         }
 
         DataContext dc = new JdbcDataContext(getConnection());
-        Schema[] schemas = dc.getSchemas();
-        assertTrue(schemas.length >= 3);
+        List<Schema> schemas = dc.getSchemas();
+        assertTrue(schemas.size() >= 3);
 
         assertNotNull(dc.getSchemaByName("information_schema"));
         assertNotNull(dc.getSchemaByName("pg_catalog"));
@@ -794,7 +790,7 @@ public class PostgresqlTest extends AbstractJdbIntegrationTest {
                 + "Table[name=cust_hist,type=TABLE,remarks=null], " + "Table[name=customers,type=TABLE,remarks=null], "
                 + "Table[name=inventory,type=TABLE,remarks=null], " + "Table[name=orderlines,type=TABLE,remarks=null], "
                 + "Table[name=orders,type=TABLE,remarks=null], " + "Table[name=products,type=TABLE,remarks=null], "
-                + "Table[name=reorder,type=TABLE,remarks=null]]", Arrays.toString(schema.getTables()));
+                + "Table[name=reorder,type=TABLE,remarks=null]]", Arrays.toString(schema.getTables().toArray()));
 
         Table productsTable = schema.getTableByName("products");
         assertEquals(
@@ -805,7 +801,7 @@ public class PostgresqlTest extends AbstractJdbIntegrationTest {
                         + "Column[name=price,columnNumber=4,type=NUMERIC,nullable=false,nativeType=numeric,columnSize=12], "
                         + "Column[name=special,columnNumber=5,type=SMALLINT,nullable=true,nativeType=int2,columnSize=5], "
                         + "Column[name=common_prod_id,columnNumber=6,type=INTEGER,nullable=false,nativeType=int4,columnSize=10]]",
-                Arrays.toString(productsTable.getColumns()));
+                Arrays.toString(productsTable.getColumns().toArray()));
         Table customersTable = schema.getTableByName("customers");
         assertEquals(
                 "[Column[name=customerid,columnNumber=0,type=INTEGER,nullable=false,nativeType=serial,columnSize=10], "
@@ -828,17 +824,19 @@ public class PostgresqlTest extends AbstractJdbIntegrationTest {
                         + "Column[name=age,columnNumber=17,type=SMALLINT,nullable=true,nativeType=int2,columnSize=5], "
                         + "Column[name=income,columnNumber=18,type=INTEGER,nullable=true,nativeType=int4,columnSize=10], "
                         + "Column[name=gender,columnNumber=19,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=1]]",
-                Arrays.toString(customersTable.getColumns()));
-        Relationship[] relations = customersTable.getRelationships();
-        assertEquals(2, relations.length);
+                Arrays.toString(customersTable.getColumns().toArray()));
+        List<Relationship> relations = new ArrayList<>(customersTable.getRelationships());
+        // bit o a hack to ensure ordering
+        Collections.sort(relations, (rel1,rel2) -> rel1.getForeignTable().getName().compareTo(rel2.getForeignTable().getName()));
+        assertEquals(2, relations.size());
         assertEquals(
                 "[Relationship[primaryTable=customers,primaryColumns=[customerid],foreignTable=cust_hist,foreignColumns=[customerid]], "
                         + "Relationship[primaryTable=customers,primaryColumns=[customerid],foreignTable=orders,foreignColumns=[customerid]]]",
-                Arrays.toString(relations));
-        assertEquals("Table[name=customers,type=TABLE,remarks=null]", relations[0].getPrimaryTable().toString());
-        assertEquals("Table[name=cust_hist,type=TABLE,remarks=null]", relations[0].getForeignTable().toString());
-        assertEquals("Table[name=customers,type=TABLE,remarks=null]", relations[1].getPrimaryTable().toString());
-        assertEquals("Table[name=orders,type=TABLE,remarks=null]", relations[1].getForeignTable().toString());
+                Arrays.toString(relations.toArray()));
+        assertEquals("Table[name=customers,type=TABLE,remarks=null]", relations.get(0).getPrimaryTable().toString());
+        assertEquals("Table[name=cust_hist,type=TABLE,remarks=null]", relations.get(0).getForeignTable().toString());
+        assertEquals("Table[name=customers,type=TABLE,remarks=null]", relations.get(1).getPrimaryTable().toString());
+        assertEquals("Table[name=orders,type=TABLE,remarks=null]", relations.get(1).getForeignTable().toString());
 
         Table ordersTable = schema.getTableByName("orderlines");
         assertEquals(
@@ -847,7 +845,7 @@ public class PostgresqlTest extends AbstractJdbIntegrationTest {
                         + "Column[name=prod_id,columnNumber=2,type=INTEGER,nullable=false,nativeType=int4,columnSize=10], "
                         + "Column[name=quantity,columnNumber=3,type=SMALLINT,nullable=false,nativeType=int2,columnSize=5], "
                         + "Column[name=orderdate,columnNumber=4,type=DATE,nullable=false,nativeType=date,columnSize=13]]",
-                Arrays.toString(ordersTable.getColumns()));
+                Arrays.toString(ordersTable.getColumns().toArray()));
     }
 
     public void testExecuteQueryInPublicSchema() throws Exception {
@@ -945,7 +943,7 @@ public class PostgresqlTest extends AbstractJdbIntegrationTest {
                     Table table = cb.createTable(schema, "my_table").withColumn("id").ofType(ColumnType.INTEGER)
                             .ofNativeType("SERIAL").nullable(false).withColumn("person name").ofSize(255).withColumn(
                                     "age").ofType(ColumnType.INTEGER).execute();
-                    assertEquals("[id, person name, age]", Arrays.toString(table.getColumnNames()));
+                    assertEquals("[id, person name, age]", Arrays.toString(table.getColumnNames().toArray()));
                     assertEquals(
                             "Column[name=id,columnNumber=0,type=INTEGER,nullable=false,nativeType=serial,columnSize=10]",
                             table.getColumnByName("id").toString());
index c72d2f3..9926b64 100644 (file)
@@ -161,7 +161,7 @@ public class SQLServerJtdsDriverTest extends AbstractJdbIntegrationTest {
         // the jdbc driver represents the date as a VARCHAR
         assertEquals("[Column[name=id,columnNumber=0,type=INTEGER,nullable=false,nativeType=int,columnSize=10], "
                 + "Column[name=birthdate,columnNumber=1,type=VARCHAR,nullable=true,nativeType=date,columnSize=10]]",
-                Arrays.toString(table.getColumns()));
+                Arrays.toString(table.getColumns().toArray()));
 
         DataSet ds = dc.query().from(table).select("id").and("birthdate").execute();
         assertTrue(ds.next());
@@ -184,7 +184,7 @@ public class SQLServerJtdsDriverTest extends AbstractJdbIntegrationTest {
                 TableType.VIEW }, DATABASE_NAME);
         Query q = new Query().select("Name").from("Production.Product").where("COlor IS NOT NULL").setMaxRows(5);
         DataSet dataSet = strategy.executeQuery(q);
-        assertEquals("[Name]", Arrays.toString(dataSet.getSelectItems()));
+        assertEquals("[Name]", Arrays.toString(dataSet.getSelectItems().toArray()));
         assertTrue(dataSet.next());
         assertEquals("Row[values=[LL Crankarm]]", dataSet.getRow().toString());
         assertTrue(dataSet.next());
@@ -200,7 +200,7 @@ public class SQLServerJtdsDriverTest extends AbstractJdbIntegrationTest {
         }
         JdbcDataContext dc = new JdbcDataContext(getConnection(), new TableType[] { TableType.TABLE, TableType.VIEW },
                 DATABASE_NAME);
-        Schema[] schemas = dc.getSchemas();
+        Schema[] schemas = dc.getSchemas().toArray(new Schema[dc.getSchemas().size()]);
 
         assertEquals(8, schemas.length);
         assertEquals("Schema[name=HumanResources]", schemas[0].toString());
@@ -228,7 +228,7 @@ public class SQLServerJtdsDriverTest extends AbstractJdbIntegrationTest {
         assertEquals("dbo", schema.getName());
 
         assertEquals("[Sales, HumanResources, dbo, Purchasing, sys, Production, INFORMATION_SCHEMA, Person]",
-                Arrays.toString(strategy.getSchemaNames()));
+                Arrays.toString(strategy.getSchemaNames().toArray()));
     }
 
     public void testQueryRewriterQuoteAliases() throws Exception {
index 2fcd0ff..f297622 100644 (file)
@@ -56,7 +56,7 @@ public class SQLServerMicrosoftDriverTest extends AbstractJdbIntegrationTest {
                 new TableType[] { TableType.TABLE, TableType.VIEW }, DATABASE_NAME);
         Query q = new Query().select("Name").from("Production.Product").where("COlor IS NOT NULL").setMaxRows(5);
         DataSet dataSet = strategy.executeQuery(q);
-        assertEquals("[Name]", Arrays.toString(dataSet.getSelectItems()));
+        assertEquals("[Name]", Arrays.toString(dataSet.getSelectItems().toArray()));
         assertTrue(dataSet.next());
         assertEquals("Row[values=[LL Crankarm]]", dataSet.getRow().toString());
         assertTrue(dataSet.next());
@@ -73,7 +73,7 @@ public class SQLServerMicrosoftDriverTest extends AbstractJdbIntegrationTest {
         
         JdbcDataContext dc = new JdbcDataContext(getConnection(), new TableType[] { TableType.TABLE, TableType.VIEW },
                 DATABASE_NAME);
-        Schema[] schemas = dc.getSchemas();
+        Schema[] schemas = dc.getSchemas().toArray(new Schema[dc.getSchemas().size()]);
 
         assertEquals(8, schemas.length);
         assertEquals("Schema[name=HumanResources]", schemas[0].toString());
@@ -100,7 +100,7 @@ public class SQLServerMicrosoftDriverTest extends AbstractJdbIntegrationTest {
                 TableType.GLOBAL_TEMPORARY }, DATABASE_NAME);
 
         assertEquals("[Sales, HumanResources, dbo, Purchasing, sys, Production, INFORMATION_SCHEMA, Person]",
-                Arrays.toString(strategy.getSchemaNames()));
+                Arrays.toString(strategy.getSchemaNames().toArray()));
 
         assertEquals("Schema[name=dbo]", strategy.getDefaultSchema().toString());
     }
index 90f726d..6578d7c 100644 (file)
@@ -20,6 +20,8 @@ package org.apache.metamodel.json;
 
 import java.io.File;
 import java.io.InputStream;
+import java.util.List;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.DataContext;
 import org.apache.metamodel.MetaModelException;
@@ -85,9 +87,9 @@ public class JsonDataContext extends QueryPostprocessDataContext implements Docu
     }
 
     @Override
-    protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+    protected DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) {
         final DocumentConverter documentConverter = _schemaBuilder.getDocumentConverter(table);
-        final SelectItem[] selectItems = MetaModelHelper.createSelectItems(columns);
+        final List<SelectItem> selectItems = columns.stream().map(SelectItem::new).collect(Collectors.toList());
         final DataSetHeader header = new CachingDataSetHeader(selectItems);
         final DocumentSource documentSource = getDocumentSourceForTable(table.getName());
 
index 0dba661..bfc1283 100644 (file)
@@ -55,7 +55,7 @@ public class JsonDataContextTest extends TestCase {
         final Table table = dc.getDefaultSchema().getTable(0);
         assertEquals("tbl", table.getName());
 
-        assertEquals("[cl]", Arrays.toString(table.getColumnNames()));
+        assertEquals("[cl]", Arrays.toString(table.getColumnNames().toArray()));
 
         final DataSet dataSet = dc.query().from("tbl").select("cl").execute();
         assertTrue(dataSet.next());
@@ -68,10 +68,9 @@ public class JsonDataContextTest extends TestCase {
 
     private void runParseabilityTest(JsonDataContext dc) {
         final Table table = dc.getDefaultSchema().getTable(0);
-        assertEquals("[country, gender, id, name]", Arrays.toString(table.getColumnNames()));
-        final Column[] columns = table.getColumns();
+        assertEquals("[country, gender, id, name]", Arrays.toString(table.getColumnNames().toArray()));
 
-        final DataSet dataSet = dc.materializeMainSchemaTable(table, columns, 100000);
+        final DataSet dataSet = dc.materializeMainSchemaTable(table, table.getColumns(), 100000);
         assertTrue(dataSet.next());
         assertEquals("Row[values=[US, null, 1234, John Doe]]", dataSet.getRow().toString());
         assertTrue(dataSet.next());
@@ -105,7 +104,7 @@ public class JsonDataContextTest extends TestCase {
         final JsonDataContext dataContext = new JsonDataContext(resource);
 
         final Schema schema = dataContext.getDefaultSchema();
-        assertEquals("[nested_fields.json]", Arrays.toString(schema.getTableNames()));
+        assertEquals("[nested_fields.json]", Arrays.toString(schema.getTableNames().toArray()));
 
         final DataSet ds = dataContext.query().from(schema.getTable(0))
                 .select(FunctionType.MAP_VALUE, "name", new Object[] { "first" }).execute();
@@ -125,7 +124,7 @@ public class JsonDataContextTest extends TestCase {
         final JsonDataContext dataContext = new JsonDataContext(resource);
 
         final Schema schema = dataContext.getDefaultSchema();
-        assertEquals("[nested_fields.json]", Arrays.toString(schema.getTableNames()));
+        assertEquals("[nested_fields.json]", Arrays.toString(schema.getTableNames().toArray()));
 
         final DataSet ds = dataContext.query().from(schema.getTable(0)).select("name.first").execute();
         try {
index 84ae8db..d5d0432 100644 (file)
@@ -26,6 +26,7 @@ import java.util.Set;
 import java.util.SortedMap;
 import java.util.TreeMap;
 import java.util.regex.Pattern;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.DataContext;
 import org.apache.metamodel.MetaModelException;
@@ -200,8 +201,7 @@ public class MongoDbDataContext extends QueryPostprocessDataContext implements U
             for (SimpleTableDef tableDef : _tableDefs) {
 
                 MutableTable table = tableDef.toTable().setSchema(schema);
-                Column[] rowIdColumns = table.getColumnsOfType(ColumnType.ROWID);
-                for (Column column : rowIdColumns) {
+                for (Column column : table.getColumnsOfType(ColumnType.ROWID)) {
                     if (column instanceof MutableColumn) {
                         ((MutableColumn) column).setPrimaryKey(true);
                     }
@@ -286,10 +286,7 @@ public class MongoDbDataContext extends QueryPostprocessDataContext implements U
                     logger.debug("Query can be expressed in full MongoDB, no post processing needed.");
 
                     // prepare for a non-post-processed query
-                    Column[] columns = new Column[selectItems.size()];
-                    for (int i = 0; i < columns.length; i++) {
-                        columns[i] = selectItems.get(i).getColumn();
-                    }
+
 
                     // checking if the query is a primary key lookup query
                     if (whereItems.size() == 1) {
@@ -324,16 +321,15 @@ public class MongoDbDataContext extends QueryPostprocessDataContext implements U
                     }
 
                     if (thereIsAtLeastOneAlias) {
-                        final SelectItem[] selectItemsAsArray = selectItems.toArray(new SelectItem[selectItems.size()]);
                         final DataSet dataSet = materializeMainSchemaTableInternal(
                                 table,
-                                selectItemsAsArray,
+                                selectItems,
                                 whereItems,
                                 firstRow,
                                 maxRows, false);
                         return dataSet;
                     } else {
-                        final DataSet dataSet = materializeMainSchemaTableInternal(table, columns, whereItems, firstRow,
+                        final DataSet dataSet = materializeMainSchemaTableInternal(table, selectItems, whereItems, firstRow,
                                 maxRows, false);
                         return dataSet;
                     }
@@ -345,14 +341,9 @@ public class MongoDbDataContext extends QueryPostprocessDataContext implements U
         return super.executeQuery(query);
     }
 
-    private DataSet materializeMainSchemaTableInternal(Table table, Column[] columns, List<FilterItem> whereItems,
-            int firstRow, int maxRows, boolean queryPostProcessed) {
-        DBCursor cursor = getCursor(table, whereItems, firstRow, maxRows);
 
-        return new MongoDbDataSet(cursor, columns, queryPostProcessed);
-    }
 
-    private DataSet materializeMainSchemaTableInternal(Table table, SelectItem[] selectItems,
+    private DataSet materializeMainSchemaTableInternal(Table table, List<SelectItem> selectItems,
             List<FilterItem> whereItems, int firstRow, int maxRows, boolean queryPostProcessed) {
         DBCursor cursor = getCursor(table, whereItems, firstRow, maxRows);
 
@@ -478,13 +469,25 @@ public class MongoDbDataContext extends QueryPostprocessDataContext implements U
     }
 
     @Override
-    protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
-        return materializeMainSchemaTableInternal(table, columns, null, 1, maxRows, true);
+    protected DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) {
+        return materializeMainSchemaTableInternal(
+                table,
+                columns.stream().map(SelectItem::new).collect(Collectors.toList()),
+                null,
+                1,
+                maxRows,
+                true);
     }
 
     @Override
-    protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int firstRow, int maxRows) {
-        return materializeMainSchemaTableInternal(table, columns, null, firstRow, maxRows, true);
+    protected DataSet materializeMainSchemaTable(Table table, List<Column> columns, int firstRow, int maxRows) {
+        return materializeMainSchemaTableInternal(
+                table,
+                columns.stream().map(SelectItem::new).collect(Collectors.toList()),
+                null,
+                firstRow,
+                maxRows,
+                true);
     }
 
     /**
index ea7cd9e..3197945 100644 (file)
@@ -29,6 +29,8 @@ import org.slf4j.LoggerFactory;
 import com.mongodb.DBCursor;
 import com.mongodb.DBObject;
 
+import java.util.List;
+
 final class MongoDbDataSet extends AbstractDataSet {
 
     private static final Logger logger = LoggerFactory.getLogger(MongoDbDataSet.class);
@@ -39,14 +41,9 @@ final class MongoDbDataSet extends AbstractDataSet {
     private boolean _closed;
     private volatile DBObject _dbObject;
 
-    public MongoDbDataSet(DBCursor cursor, Column[] columns, boolean queryPostProcessed) {
-        super(columns);
-        _cursor = cursor;
-        _queryPostProcessed = queryPostProcessed;
-        _closed = false;
-    }
 
-    public MongoDbDataSet(DBCursor cursor, SelectItem[] selectItems, boolean queryPostProcessed) {
+
+    public MongoDbDataSet(DBCursor cursor, List<SelectItem> selectItems, boolean queryPostProcessed) {
         super(selectItems);
         _cursor = cursor;
         _queryPostProcessed = queryPostProcessed;
index da99955..398c408 100644 (file)
@@ -280,7 +280,7 @@ public class MongoDbDataContextTest extends MongoDbTestCase {
 
         assertTrue(Arrays.asList(dataContext.getDefaultSchema().getTableNames()).contains(getCollectionName()));
         Table table = dataContext.getDefaultSchema().getTableByName(getCollectionName());
-        assertEquals("[_id, baz, foo, id, list, name]", Arrays.toString(table.getColumnNames()));
+        assertEquals("[_id, baz, foo, id, list, name]", Arrays.toString(table.getColumnNames().toArray()));
 
         assertEquals(ColumnType.MAP, table.getColumnByName("baz").getType());
         assertEquals(ColumnType.STRING, table.getColumnByName("foo").getType());
@@ -460,7 +460,7 @@ public class MongoDbDataContextTest extends MongoDbTestCase {
         // do a query that we cannot push to mongo
         // Replace column index 0 by 1
         ds = dataContext.query().from(getCollectionName())
-                .select(FunctionType.SUM, dataContext.getDefaultSchema().getTables()[0].getColumnByName("id"))
+                .select(FunctionType.SUM, dataContext.getDefaultSchema().getTables().get(0).getColumnByName("id"))
                 .where("foo").isEquals("bar").execute();
         assertEquals(InMemoryDataSet.class, ds.getClass());
 
@@ -478,8 +478,7 @@ public class MongoDbDataContextTest extends MongoDbTestCase {
         dc.executeUpdate(new UpdateScript() {
             @Override
             public void run(UpdateCallback callback) {
-                Table[] tables = defaultSchema.getTables();
-                for (Table table : tables) {
+                for (Table table : defaultSchema.getTables()) {
                     callback.deleteFrom(table).execute();
                 }
             }
@@ -514,8 +513,8 @@ public class MongoDbDataContextTest extends MongoDbTestCase {
         dataSet = dc.query().from("some_entries").selectCount().execute();
         dataSet.close();
         assertTrue(dataSet.next());
-        assertEquals(1, dataSet.getSelectItems().length);
-        assertEquals(SelectItem.getCountAllItem(), dataSet.getSelectItems()[0]);
+        assertEquals(1, dataSet.getSelectItems().size());
+        assertEquals(SelectItem.getCountAllItem(), dataSet.getSelectItems().get(0));
         assertEquals(4l, dataSet.getRow().getValue(SelectItem.getCountAllItem()));
         assertFalse(dataSet.next());
         assertEquals(InMemoryDataSet.class, dataSet.getClass());
@@ -524,8 +523,8 @@ public class MongoDbDataContextTest extends MongoDbTestCase {
         dataSet = dc.query().from("some_entries").selectCount().where("foo").greaterThan(2).execute();
         dataSet.close();
         assertTrue(dataSet.next());
-        assertEquals(1, dataSet.getSelectItems().length);
-        assertEquals(SelectItem.getCountAllItem(), dataSet.getSelectItems()[0]);
+        assertEquals(1, dataSet.getSelectItems().size());
+        assertEquals(SelectItem.getCountAllItem(), dataSet.getSelectItems().get(0));
         assertEquals(2l, dataSet.getRow().getValue(SelectItem.getCountAllItem()));
         assertFalse(dataSet.next());
         assertEquals(InMemoryDataSet.class, dataSet.getClass());
@@ -657,7 +656,7 @@ public class MongoDbDataContextTest extends MongoDbTestCase {
                 "addresses[5].foobar" }));
 
         final DataSet ds1 = dc.executeQuery("select gender AS my_gender, name.first AS my_name from my_collection where gender LIKE '%MALE%'");
-        final SelectItem[] selectItems = ds1.getSelectItems();
+        final SelectItem[] selectItems = ds1.getSelectItems().toArray(new SelectItem[ds1.getSelectItems().size()]);
         SelectItem firstSelectItem = selectItems[0];
         SelectItem secondSelectItem = selectItems[1];
         try {
index b0aa9dc..becda44 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.metamodel.mongodb.mongo2;
 import java.io.File;
 import java.sql.Connection;
 import java.sql.DriverManager;
+import java.util.List;
 
 import org.apache.metamodel.DataContext;
 import org.apache.metamodel.UpdateCallback;
@@ -95,7 +96,7 @@ public class MongoDbDataCopyer {
                 final Table sourceTable = getSourceTable();
                 final Table targetTable = callback.createTable(targetDataContext.getDefaultSchema(), _collectionName)
                         .like(sourceTable).execute();
-                final Column[] sourceColumns = sourceTable.getColumns();
+                final List<Column> sourceColumns = sourceTable.getColumns();
                 final DataSet dataSet = _sourceDataContext.query().from(sourceTable).select(sourceColumns).execute();
                 while (dataSet.next()) {
                     final Row row = dataSet.getRow();
index ddb18d5..9bdec81 100644 (file)
@@ -27,6 +27,7 @@ import java.util.Set;
 import java.util.SortedMap;
 import java.util.TreeMap;
 import java.util.regex.Pattern;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.DataContext;
 import org.apache.metamodel.MetaModelException;
@@ -200,7 +201,7 @@ public class MongoDbDataContext extends QueryPostprocessDataContext implements U
             for (SimpleTableDef tableDef : _tableDefs) {
 
                 MutableTable table = tableDef.toTable().setSchema(schema);
-                Column[] rowIdColumns = table.getColumnsOfType(ColumnType.ROWID);
+                List<Column> rowIdColumns = table.getColumnsOfType(ColumnType.ROWID);
                 for (Column column : rowIdColumns) {
                     if (column instanceof MutableColumn) {
                         ((MutableColumn) column).setPrimaryKey(true);
@@ -286,10 +287,7 @@ public class MongoDbDataContext extends QueryPostprocessDataContext implements U
                     logger.debug("Query can be expressed in full MongoDB, no post processing needed.");
 
                     // prepare for a non-post-processed query
-                    Column[] columns = new Column[selectItems.size()];
-                    for (int i = 0; i < columns.length; i++) {
-                        columns[i] = selectItems.get(i).getColumn();
-                    }
+
 
                     // checking if the query is a primary key lookup query
                     if (whereItems.size() == 1) {
@@ -325,16 +323,15 @@ public class MongoDbDataContext extends QueryPostprocessDataContext implements U
                     }
 
                     if (thereIsAtLeastOneAlias) {
-                        final SelectItem[] selectItemsAsArray = selectItems.toArray(new SelectItem[selectItems.size()]);
                         final DataSet dataSet = materializeMainSchemaTableInternal(
                                 table,
-                                selectItemsAsArray,
+                                selectItems,
                                 whereItems,
                                 firstRow,
                                 maxRows, false);
                         return dataSet;
                     } else {
-                        final DataSet dataSet = materializeMainSchemaTableInternal(table, columns, whereItems, firstRow,
+                        final DataSet dataSet = materializeMainSchemaTableInternal(table, selectItems, whereItems, firstRow,
                                 maxRows, false);
                         return dataSet;
                     }
@@ -346,14 +343,8 @@ public class MongoDbDataContext extends QueryPostprocessDataContext implements U
         return super.executeQuery(query);
     }
 
-    private DataSet materializeMainSchemaTableInternal(Table table, Column[] columns, List<FilterItem> whereItems,
-            int firstRow, int maxRows, boolean queryPostProcessed) {
-        MongoCursor<Document> cursor = getDocumentMongoCursor(table, whereItems, firstRow, maxRows);
-
-        return new MongoDbDataSet(cursor, columns, queryPostProcessed);
-    }
 
-    private DataSet materializeMainSchemaTableInternal(Table table, SelectItem[] selectItems, List<FilterItem> whereItems,
+    private DataSet materializeMainSchemaTableInternal(Table table, List<SelectItem> selectItems, List<FilterItem> whereItems,
             int firstRow, int maxRows, boolean queryPostProcessed) {
         MongoCursor<Document> cursor = getDocumentMongoCursor(table, whereItems, firstRow, maxRows);
 
@@ -507,13 +498,26 @@ public class MongoDbDataContext extends QueryPostprocessDataContext implements U
     }
 
     @Override
-    protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
-        return materializeMainSchemaTableInternal(table, columns, null, 1, maxRows, true);
+    protected DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) {
+
+        return materializeMainSchemaTableInternal(
+                table,
+                columns.stream().map(SelectItem::new).collect(Collectors.toList()),
+                null,
+                1,
+                maxRows,
+                true);
     }
 
     @Override
-    protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int firstRow, int maxRows) {
-        return materializeMainSchemaTableInternal(table, columns, null, firstRow, maxRows, true);
+    protected DataSet materializeMainSchemaTable(Table table, List<Column> columns, int firstRow, int maxRows) {
+        return materializeMainSchemaTableInternal(
+                table,
+                columns.stream().map(SelectItem::new).collect(Collectors.toList()),
+                null,
+                firstRow,
+                maxRows,
+                true);
     }
 
     /**
index 19e543f..76a7636 100644 (file)
@@ -29,6 +29,8 @@ import org.slf4j.LoggerFactory;
 
 import com.mongodb.client.MongoCursor;
 
+import java.util.List;
+
 final class MongoDbDataSet extends AbstractDataSet {
 
     private static final Logger logger = LoggerFactory.getLogger(MongoDbDataSet.class);
@@ -39,14 +41,8 @@ final class MongoDbDataSet extends AbstractDataSet {
     private boolean _closed;
     private volatile Document _document;
 
-    public MongoDbDataSet(MongoCursor<Document> cursor, Column[] columns, boolean queryPostProcessed) {
-        super(columns);
-        _cursor = cursor;
-        _queryPostProcessed = queryPostProcessed;
-        _closed = false;
-    }
 
-    public MongoDbDataSet(MongoCursor<Document> cursor, SelectItem[] selectItems, boolean queryPostProcessed) {
+    public MongoDbDataSet(MongoCursor<Document> cursor, List<SelectItem> selectItems, boolean queryPostProcessed) {
         super(selectItems);
         _cursor = cursor;
         _queryPostProcessed = queryPostProcessed;
index 197fae9..9751719 100644 (file)
@@ -265,7 +265,7 @@ public class MongoDbDataContextTest extends MongoDbTestCase {
         assertTrue(Arrays.asList(dataContext.getDefaultSchema().getTableNames()).contains(getCollectionName()));
         
         Table table = dataContext.getDefaultSchema().getTableByName(getCollectionName());
-        assertEquals("[_id, baz, foo, id, list, name]", Arrays.toString(table.getColumnNames()));
+        assertEquals("[_id, baz, foo, id, list, name]", Arrays.toString(table.getColumnNames().toArray()));
 
         assertEquals(ColumnType.MAP, table.getColumnByName("baz").getType());
         assertEquals(ColumnType.STRING, table.getColumnByName("foo").getType());
@@ -445,7 +445,7 @@ public class MongoDbDataContextTest extends MongoDbTestCase {
         // do a query that we cannot push to mongo
         // Replace column index 0 by 1
         ds = dataContext.query().from(getCollectionName())
-                .select(FunctionType.SUM, dataContext.getDefaultSchema().getTables()[0].getColumnByName("id"))
+                .select(FunctionType.SUM, dataContext.getDefaultSchema().getTables().get(0).getColumnByName("id"))
                 .where("foo").isEquals("bar").execute();
         assertEquals(InMemoryDataSet.class, ds.getClass());
 
@@ -463,8 +463,7 @@ public class MongoDbDataContextTest extends MongoDbTestCase {
         dc.executeUpdate(new UpdateScript() {
             @Override
             public void run(UpdateCallback callback) {
-                Table[] tables = defaultSchema.getTables();
-                for (Table table : tables) {
+                for (Table table : defaultSchema.getTables()) {
                     callback.deleteFrom(table).execute();
                 }
             }
@@ -499,8 +498,8 @@ public class MongoDbDataContextTest extends MongoDbTestCase {
         dataSet = dc.query().from("some_entries").selectCount().execute();
         dataSet.close();
         assertTrue(dataSet.next());
-        assertEquals(1, dataSet.getSelectItems().length);
-        assertEquals(SelectItem.getCountAllItem(), dataSet.getSelectItems()[0]);
+        assertEquals(1, dataSet.getSelectItems().size());
+        assertEquals(SelectItem.getCountAllItem(), dataSet.getSelectItems().get(0));
         assertEquals(4l, dataSet.getRow().getValue(SelectItem.getCountAllItem()));
         assertFalse(dataSet.next());
         assertEquals(InMemoryDataSet.class, dataSet.getClass());
@@ -509,8 +508,8 @@ public class MongoDbDataContextTest extends MongoDbTestCase {
         dataSet = dc.query().from("some_entries").selectCount().where("foo").greaterThan(2).execute();
         dataSet.close();
         assertTrue(dataSet.next());
-        assertEquals(1, dataSet.getSelectItems().length);
-        assertEquals(SelectItem.getCountAllItem(), dataSet.getSelectItems()[0]);
+        assertEquals(1, dataSet.getSelectItems().size());
+        assertEquals(SelectItem.getCountAllItem(), dataSet.getSelectItems().get(0));
         assertEquals(2l, dataSet.getRow().getValue(SelectItem.getCountAllItem()));
         assertFalse(dataSet.next());
         assertEquals(InMemoryDataSet.class, dataSet.getClass());
@@ -633,7 +632,7 @@ public class MongoDbDataContextTest extends MongoDbTestCase {
                         "addresses[5].foobar" }));
 
         final DataSet ds1 = dc.executeQuery("select gender as my_gender, name.first as my_name from my_collection where gender LIKE '%MALE%'");
-        final SelectItem[] selectItems = ds1.getSelectItems();
+        final SelectItem[] selectItems = ds1.getSelectItems().toArray(new SelectItem[ds1.getSelectItems().size()]);
         SelectItem firstSelectItem = selectItems[0];
         SelectItem secondSelectItem = selectItems[1];
         try {
index 42ef536..351d6ee 100644 (file)
@@ -98,7 +98,7 @@ public class MongoDbDataCopyer {
                 final Table sourceTable = getSourceTable();
                 final Table targetTable = callback.createTable(targetDataContext.getDefaultSchema(), _collectionName)
                         .like(sourceTable).execute();
-                final Column[] sourceColumns = sourceTable.getColumns();
+                final Column[] sourceColumns = sourceTable.getColumns().toArray(new Column[sourceTable.getColumns().size()]);
                 final DataSet dataSet = _sourceDataContext.query().from(sourceTable).select(sourceColumns).execute();
                 while (dataSet.next()) {
                     final Row row = dataSet.getRow();
index 5d3ac6c..38079ce 100644 (file)
@@ -22,6 +22,7 @@ import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.query.FilterItem;
 import org.apache.metamodel.schema.Column;
@@ -29,15 +30,14 @@ import org.apache.metamodel.schema.Table;
 
 public class Neo4jCypherQueryBuilder {
 
-    public static String buildSelectQuery(Table table, Column[] columns, int firstRow, int maxRows) {
-        String[] columnNames = new String[columns.length];
-        for (int i = 0; i < columns.length; i++) {
-            columnNames[i] = columns[i].getName();
-        }
+    public static String buildSelectQuery(Table table, List<Column> columns, int firstRow, int maxRows) {
+        List<String> columnNames = columns.stream()
+                .map(col -> col.getName())
+                .collect(Collectors.toList());
         return buildSelectQuery(table.getName(), columnNames, firstRow, maxRows);
     }
 
-    public static String buildSelectQuery(String tableName, String[] columnNames, int firstRow, int maxRows) {
+    public static String buildSelectQuery(String tableName, List<String> columnNames, int firstRow, int maxRows) {
         Map<String, String> returnClauseMap = new LinkedHashMap<>();
         Map<String, Integer> relationshipIndexMap = new LinkedHashMap<>();
         for (String columnName : columnNames) {
index cb0b2ac..82f710d 100644 (file)
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 import org.apache.http.HttpHost;
 import org.apache.http.client.methods.HttpGet;
@@ -296,14 +297,14 @@ public class Neo4jDataContext extends QueryPostprocessDataContext implements Dat
     }
 
     @Override
-    protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int firstRow, int maxRows) {
-        if ((columns != null) && (columns.length > 0)) {
+    protected DataSet materializeMainSchemaTable(Table table, List<Column> columns, int firstRow, int maxRows) {
+        if ((columns != null) && (columns.size() > 0)) {
             Neo4jDataSet dataSet = null;
             try {
                 String selectQuery = Neo4jCypherQueryBuilder.buildSelectQuery(table, columns, firstRow, maxRows);
                 String responseJSONString = _requestWrapper.executeCypherQuery(selectQuery);
                 JSONObject resultJSONObject = new JSONObject(responseJSONString);
-                final SelectItem[] selectItems = MetaModelHelper.createSelectItems(columns);
+                final List<SelectItem> selectItems = columns.stream().map(SelectItem::new).collect(Collectors.toList());
                 dataSet = new Neo4jDataSet(selectItems, resultJSONObject);
             } catch (JSONException e) {
                 logger.error("Error occured in parsing JSON while materializing the schema: ", e);
@@ -318,7 +319,7 @@ public class Neo4jDataContext extends QueryPostprocessDataContext implements Dat
     }
 
     @Override
-    protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+    protected DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) {
         return materializeMainSchemaTable(table, columns, 1, maxRows);
     }
 
index bf132e8..537a068 100644 (file)
@@ -27,13 +27,15 @@ import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
+import java.util.List;
+
 final class Neo4jDataSet extends AbstractDataSet {
 
     private JSONObject _resultJSONObject;
     private int _currentRowIndex;
     private Row _row;
 
-    public Neo4jDataSet(SelectItem[] selectItems, JSONObject resultJSONObject) {
+    public Neo4jDataSet(List<SelectItem> selectItems, JSONObject resultJSONObject) {
         super(selectItems);
         _resultJSONObject = resultJSONObject;
         _currentRowIndex = 0;
index 1246ce2..89bf977 100644 (file)
@@ -78,13 +78,13 @@ public class Neo4jDataContextTest extends Neo4jTestCase {
 
         // Do not check the precise count, Neo4j keeps labels forever, there are
         // probably many more than you imagine...
-        List<String> tableNames = Arrays.asList(schema.getTableNames());
+        List<String> tableNames = schema.getTableNames();
         logger.info("Tables (labels) detected: " + tableNames);
         assertTrue(tableNames.contains("JUnitLabel"));
         assertFalse(tableNames.contains("JUnitLabelTemp"));
 
         Table table = schema.getTableByName("JUnitLabel");
-        List<String> columnNames = Arrays.asList(table.getColumnNames());
+        List<String> columnNames = table.getColumnNames();
         assertTrue(columnNames.contains("property1"));
         assertTrue(columnNames.contains("property2"));
     }
@@ -122,18 +122,18 @@ public class Neo4jDataContextTest extends Neo4jTestCase {
 
         // Do not check the precise count, Neo4j keeps labels forever, there are
         // probably many more than you imagine...
-        List<String> tableNames = Arrays.asList(schema.getTableNames());
+        List<String> tableNames = schema.getTableNames();
         logger.info("Tables (labels) detected: " + tableNames);
         assertTrue(tableNames.contains("JUnitPerson"));
         assertTrue(tableNames.contains("JUnitBook"));
 
         Table tablePerson = schema.getTableByName("JUnitPerson");
-        List<String> personColumnNames = Arrays.asList(tablePerson.getColumnNames());
+        List<String> personColumnNames = tablePerson.getColumnNames();
         assertEquals("[_id, name, age, rel_HAS_READ, rel_HAS_READ#rating, rel_HAS_BROWSED]",
                 personColumnNames.toString());
 
         Table tableBook = schema.getTableByName("JUnitBook");
-        List<String> bookColumnNames = Arrays.asList(tableBook.getColumnNames());
+        List<String> bookColumnNames = tableBook.getColumnNames();
         assertEquals("[_id, title]", bookColumnNames.toString());
     }
 
index 25275a5..7df2350 100644 (file)
@@ -26,6 +26,7 @@ import java.io.OutputStream;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.util.Enumeration;
+import java.util.List;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
@@ -114,7 +115,7 @@ public class OpenOfficeDataContext extends AbstractDataContext {
        }
 
        @Override
-       protected String[] getSchemaNamesInternal() {
+       protected List<String> getSchemaNamesInternal() {
                return _dataContextDelegate.getSchemaNames();
        }
 
index 78015d2..0ac3462 100644 (file)
@@ -57,7 +57,7 @@ public class OpenOfficeDataContextTest extends TestCase {
 
        public void testGetSchemas() throws Exception {
                assertEquals("[INFORMATION_SCHEMA, PUBLIC]",
-                               Arrays.toString(_dataContext.getSchemaNames()));
+                               Arrays.toString(_dataContext.getSchemaNames().toArray()));
 
                Schema informationSchema = _dataContext
                                .getSchemaByName("INFORMATION_SCHEMA");
@@ -68,10 +68,10 @@ public class OpenOfficeDataContextTest extends TestCase {
 
                assertEquals(
                                "[Table[name=CONTRIBUTORS,type=TABLE,remarks=null], Table[name=projects,type=TABLE,remarks=null]]",
-                               Arrays.toString(schema.getTables()));
+                               Arrays.toString(schema.getTables().toArray()));
                assertEquals(
                                "[Relationship[primaryTable=CONTRIBUTORS,primaryColumns=[ID],foreignTable=projects,foreignColumns=[admin]]]",
-                               Arrays.toString(schema.getRelationships()));
+                               Arrays.toString(schema.getRelationships().toArray()));
        }
 
        public void testQueryUppercaseTable() throws Exception {
index 9369e96..f694202 100644 (file)
@@ -24,6 +24,7 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.DataContext;
 import org.apache.metamodel.MetaModelException;
@@ -103,13 +104,13 @@ public class PojoDataContext extends QueryPostprocessDataContext implements Upda
     }
 
     @Override
-    protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+    protected DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) {
         final TableDataProvider<?> pojoTable = _tables.get(table.getName());
         if (pojoTable == null) {
             throw new IllegalArgumentException("No such POJO table: " + table.getName());
         }
 
-        final SelectItem[] selectItems = MetaModelHelper.createSelectItems(columns);
+        final List<SelectItem> selectItems = columns.stream().map(SelectItem::new).collect(Collectors.toList());
 
         @SuppressWarnings({ "rawtypes", "unchecked" })
         DataSet dataSet = new PojoDataSet(pojoTable, selectItems);
index 1c86ef1..952d85c 100644 (file)
@@ -19,6 +19,7 @@
 package org.apache.metamodel.pojo;
 
 import java.util.Iterator;
+import java.util.List;
 
 import org.apache.metamodel.data.AbstractDataSet;
 import org.apache.metamodel.data.DataSet;
@@ -38,7 +39,7 @@ final class PojoDataSet<E> extends AbstractDataSet {
     private final Iterator<E> _iterator;
     private E _next;
 
-    public PojoDataSet(TableDataProvider<E> pojoTable, SelectItem[] selectItems) {
+    public PojoDataSet(TableDataProvider<E> pojoTable, List<SelectItem> selectItems) {
         super(selectItems);
         _pojoTable = pojoTable;
 
index d5e093c..97f1a9f 100644 (file)
@@ -65,7 +65,7 @@ public class PojoDataContextTest extends TestCase {
         DataSet dataSet = dc.query().from("persons").innerJoin("titles").on("name", "name").selectAll().execute();
 
         assertEquals("[persons.age, persons.name, titles.name, titles.title]",
-                Arrays.toString(dataSet.getSelectItems()));
+                Arrays.toString(dataSet.getSelectItems().toArray()));
         assertTrue(dataSet.next());
         assertEquals("Row[values=[42, Elvis Presley, Elvis Presley, The King]]", dataSet.getRow().toString());
         assertFalse(dataSet.next());
@@ -117,7 +117,7 @@ public class PojoDataContextTest extends TestCase {
         final Table table = schema.getTable(0);
         assertEquals("foo.bar", table.getQualifiedLabel());
 
-        assertEquals("[col1, col2, col3]", Arrays.toString(table.getColumnNames()));
+        assertEquals("[col1, col2, col3]", Arrays.toString(table.getColumnNames().toArray()));
 
         DataSet ds = dc.query().from("bar").select("col2").where("col3").eq(true).execute();
         assertTrue(ds.next());
index 37467b7..8d25bf4 100644 (file)
 package org.apache.metamodel.salesforce;
 
 import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-import java.util.Locale;
-import java.util.TimeZone;
+import java.util.*;
 
 import com.sforce.ws.ConnectorConfig;
 
@@ -167,14 +164,14 @@ public class SalesforceDataContext extends QueryPostprocessDataContext implement
         try {
             sb.append("SELECT ");
             int i = 0;
-            final Column[] columns = new Column[selectItems.size()];
+            final List<Column> columns = new ArrayList(selectItems.size());
             for (SelectItem selectItem : selectItems) {
                 validateSoqlSupportedSelectItem(selectItem);
-                columns[i] = selectItem.getColumn();
+                columns.set(i,selectItem.getColumn());
                 if (i != 0) {
                     sb.append(", ");
                 }
-                sb.append(columns[i].getName());
+                sb.append(columns.get(i).getName());
                 i++;
             }
 
@@ -366,14 +363,14 @@ public class SalesforceDataContext extends QueryPostprocessDataContext implement
     }
 
     @Override
-    protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+    protected DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) {
         final StringBuilder sb = new StringBuilder();
         sb.append("SELECT ");
-        for (int i = 0; i < columns.length; i++) {
+        for (int i = 0; i < columns.size(); i++) {
             if (i != 0) {
                 sb.append(',');
             }
-            sb.append(columns[i].getName());
+            sb.append(columns.get(i).getName());
         }
         sb.append(" FROM ");
         sb.append(table.getName());
index 85f2d9a..55993bc 100644 (file)
@@ -20,13 +20,16 @@ package org.apache.metamodel.salesforce;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.List;
 import java.util.Locale;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.data.AbstractDataSet;
 import org.apache.metamodel.data.DataSetHeader;
 import org.apache.metamodel.data.DefaultRow;
 import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.SelectItem;
 import org.apache.metamodel.schema.Column;
 import org.apache.metamodel.schema.ColumnType;
 import org.apache.metamodel.util.BooleanComparator;
@@ -48,8 +51,8 @@ final class SalesforceDataSet extends AbstractDataSet {
     private SObject[] _records;
     private SObject _record;
 
-    public SalesforceDataSet(Column[] columns, QueryResult queryResult, PartnerConnection connection) {
-        super(columns);
+    public SalesforceDataSet(List<Column> columns, QueryResult queryResult, PartnerConnection connection) {
+        super(columns.stream().map(SelectItem::new).collect(Collectors.toList()));
         _connection = connection;
         _queryResult = queryResult;
         _records = _queryResult.getRecords();
index d5f70c9..b11add5 100644 (file)
@@ -19,6 +19,7 @@
 package org.apache.metamodel.salesforce;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.function.Supplier;
 
@@ -78,9 +79,8 @@ final class SalesforceSchema extends AbstractSchema {
     }
 
     @Override
-    public Table[] getTables() {
-        List<Table> tables = _tableRef.get();
-        return tables.toArray(new Table[tables.size()]);
+    public List<Table> getTables() {
+        return Collections.unmodifiableList(_tableRef.get());
     }
 
     @Override
index 5db2b47..9648bb9 100644 (file)
@@ -19,6 +19,7 @@
 package org.apache.metamodel.salesforce;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.function.Supplier;
 
@@ -135,12 +136,12 @@ final class SalesforceTable extends AbstractTable {
     }
 
     @Override
-    public Column[] getColumns() {
+    public List<Column> getColumns() {
         if (_columnRef == null) {
-            return new Column[0];
+            return new ArrayList<>();
         }
         List<Column> columns = _columnRef.get();
-        return columns.toArray(new Column[columns.size()]);
+        return Collections.unmodifiableList(columns);
     }
 
     @Override
@@ -154,8 +155,8 @@ final class SalesforceTable extends AbstractTable {
     }
 
     @Override
-    public Relationship[] getRelationships() {
-        return new Relationship[0];
+    public List<Relationship> getRelationships() {
+        return new ArrayList<>();
     }
 
     @Override
index 7cb6fb6..64f4eac 100644 (file)
@@ -51,7 +51,7 @@ public class SalesforceDataContextTest extends SalesforceTestCase {
         }
         SalesforceDataContext dc = getSalesforceDataContext();
 
-        Column[] timeColumns = dc.getDefaultSchema().getTableByName("Contact").getTimeBasedColumns();
+        List<Column> timeColumns = dc.getDefaultSchema().getTableByName("Contact").getTimeBasedColumns();
         assertEquals(
                 "[Column[name=Birthdate,columnNumber=30,type=DATE,nullable=true,nativeType=date,columnSize=0], "
                         + "Column[name=CreatedDate,columnNumber=33,type=TIMESTAMP,nullable=false,nativeType=datetime,columnSize=0], "
@@ -61,7 +61,7 @@ public class SalesforceDataContextTest extends SalesforceTestCase {
                         + "Column[name=LastCURequestDate,columnNumber=39,type=TIMESTAMP,nullable=true,nativeType=datetime,columnSize=0], "
                         + "Column[name=LastCUUpdateDate,columnNumber=40,type=TIMESTAMP,nullable=true,nativeType=datetime,columnSize=0], "
                         + "Column[name=EmailBouncedDate,columnNumber=42,type=TIMESTAMP,nullable=true,nativeType=datetime,columnSize=0]]",
-                Arrays.toString(timeColumns));
+                Arrays.toString(timeColumns.toArray()));
         DataSet ds = dc.query().from("Contact").select("LastModifiedDate").where("Id").eq("003b0000006xfAUAAY")
                 .execute();
         if (ds.next()) {
@@ -121,15 +121,15 @@ public class SalesforceDataContextTest extends SalesforceTestCase {
 
         assertEquals("Salesforce", schema.getName());
 
-        String[] tableNames = schema.getTableNames();
+        List<String> tableNames = schema.getTableNames();
 
-        System.out.println("All tables:\n" + Arrays.toString(tableNames));
+        System.out.println("All tables:\n" + Arrays.toString(tableNames.toArray()));
 
         Table accountTable = schema.getTableByName("Account");
         assertNotNull(accountTable);
 
-        String[] columnNames = accountTable.getColumnNames();
-        System.out.println("Account table columns: " + Arrays.toString(columnNames));
+        List<String> columnNames = accountTable.getColumnNames();
+        System.out.println("Account table columns: " + Arrays.toString(columnNames.toArray()));
 
         Column idColumn = accountTable.getColumnByName("Id");
         Column nameColumn = accountTable.getColumnByName("Name");
@@ -165,7 +165,7 @@ public class SalesforceDataContextTest extends SalesforceTestCase {
         q.setMaxRows(1);
 
         final DataSet ds = dc.executeQuery(q);
-        final SelectItem[] selectItems = ds.getSelectItems();
+        final List<SelectItem> selectItems = ds.getSelectItems();
         while (ds.next()) {
             Row row = ds.getRow();
 
index 838e386..a16cf13 100644 (file)
  */
 package org.apache.metamodel.salesforce;
 
+import com.google.common.collect.Lists;
 import com.sforce.soap.partner.QueryResult;
 import com.sforce.ws.ConnectionException;
 import com.sforce.ws.bind.TypeMapper;
 import com.sforce.ws.parser.PullParserException;
 import com.sforce.ws.parser.XmlInputStream;
 import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.SelectItem;
 import org.apache.metamodel.schema.Column;
 import org.apache.metamodel.schema.ColumnType;
 import org.apache.metamodel.schema.MutableColumn;
 import org.junit.Test;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 
 import static org.junit.Assert.assertEquals;
@@ -41,7 +44,7 @@ public class SalesforceDataSetTest {
         QueryResult qr = queryResult("/result/double-value.xml");
         MutableColumn version = new MutableColumn("Version", ColumnType.DOUBLE);
 
-        SalesforceDataSet dataSet = new SalesforceDataSet(new Column[] { version }, qr, null);
+        SalesforceDataSet dataSet = new SalesforceDataSet(Lists.newArrayList(version), qr, null);
         List<Row> rows = dataSet.toRows();
 
         assertEquals(5386.21, rows.get(0).getValue(version));
index 87ffef0..c43bf9d 100644 (file)
@@ -53,6 +53,6 @@ public class CsvDefaultConfigurationFromResourceTest {
 
         assertEquals("example.csv", resource.getName());
 
-        assertEquals("[foo, bar]", Arrays.toString(csv.getDefaultSchema().getTable(0).getColumnNames()));
+        assertEquals("[foo, bar]", Arrays.toString(csv.getDefaultSchema().getTable(0).getColumnNames().toArray()));
     }
 }
index 01b6120..ec97106 100644 (file)
@@ -51,7 +51,7 @@ public class CsvSpecifiedConfigurationFromFilenameTest {
 
         assertEquals("example.csv", resource.getName());
 
-        assertEquals("[\"foo\", bar]", Arrays.toString(csv.getDefaultSchema().getTable(0).getColumnNames()));
+        assertEquals("[\"foo\", bar]", Arrays.toString(csv.getDefaultSchema().getTable(0).getColumnNames().toArray()));
 
         Assert.assertFalse(csv.getConfiguration().isMultilineValues());
     }
index 58a9317..a4589fc 100644 (file)
@@ -51,7 +51,7 @@ public class ExcelSpecifiedConfigurationFromFilenameTest {
 
         assertEquals("example.xlsx", resource.getName());
 
-        assertEquals("[hello, world]", Arrays.toString(excel.getDefaultSchema().getTable(0).getColumnNames()));
+        assertEquals("[hello, world]", Arrays.toString(excel.getDefaultSchema().getTable(0).getColumnNames().toArray()));
 
         Assert.assertTrue(excel.getConfiguration().isSkipEmptyLines());
         Assert.assertTrue(excel.getConfiguration().isSkipEmptyColumns());
index 558cda4..471dc96 100644 (file)
@@ -39,15 +39,15 @@ public class PojoDataContextFactoryBeanDelegateTest extends TestCase {
 
         Schema schema = dataContext.getDefaultSchema();
         assertEquals("my db", schema.getName());
-        assertEquals("[foo, hello world]", Arrays.toString(schema.getTableNames()));
+        assertEquals("[foo, hello world]", Arrays.toString(schema.getTableNames().toArray()));
 
         assertEquals(
                 "[Column[name=greeting,columnNumber=0,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
                         + "Column[name=who,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]",
-                Arrays.toString(schema.getTableByName("hello world").getColumns()));
+                Arrays.toString(schema.getTableByName("hello world").getColumns().toArray()));
 
         assertEquals("[Column[name=bar,columnNumber=0,type=INTEGER,nullable=true,nativeType=null,columnSize=null], "
                 + "Column[name=baz,columnNumber=1,type=DATE,nullable=true,nativeType=null,columnSize=null]]",
-                Arrays.toString(schema.getTableByName("foo").getColumns()));
+                Arrays.toString(schema.getTableByName("foo").getColumns().toArray()));
     }
 }
index e3908c0..9abe5da 100644 (file)
@@ -38,7 +38,7 @@ import org.apache.metamodel.util.LazyRef;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.sugarcrm.ws.soapyxyx.EntryValue;
+import com.sugarcrm.ws.soap.EntryValue;
 import com.sugarcrm.ws.soap.GetEntriesCountResult;
 import com.sugarcrm.ws.soap.GetEntryListResultVersion2;
 import com.sugarcrm.ws.soap.LinkNamesToFieldsArray;
@@ -147,7 +147,7 @@ public class SugarCrmDataContext extends QueryPostprocessDataContext implements
     }
 
     @Override
-    protected DataSet materializeMainSchemaTable(final Table table, final Column[] columns, final int maxRows) {
+    protected DataSet materializeMainSchemaTable(final Table table, final List<Column> columns, final int maxRows) {
 
         final String session = _sessionId.get();
         final String moduleName = table.getName();