first round of refactoring

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

Branch: refs/heads/master
Commit: ab5c9482dd2efbb4cdc17402fddabfed05915ff2
Parents: 6f9e094
Author: Jörg Unbehauen <jo...@unbehauen.net>
Authored: Thu Jul 27 13:01:26 2017 +0200
Committer: Jörg Unbehauen <jo...@unbehauen.net>
Committed: Thu Jul 27 13:01:26 2017 +0200

----------------------------------------------------------------------
 core/pom.xml                                    |   4 +
 .../apache/metamodel/AbstractDataContext.java   |  48 ++++---
 .../metamodel/AbstractUpdateCallback.java       |   4 +-
 .../apache/metamodel/CompositeDataContext.java  |  21 +---
 .../metamodel/CompositeQueryDelegate.java       |   3 +-
 .../java/org/apache/metamodel/DataContext.java  |   7 +-
 .../metamodel/DeleteAndInsertBuilder.java       |  13 +-
 .../org/apache/metamodel/MetaModelHelper.java   |  59 +++++----
 .../metamodel/QueryPostprocessDataContext.java  |  55 ++++----
 .../convert/ConvertedDataSetInterceptor.java    |   9 +-
 .../apache/metamodel/convert/Converters.java    |  33 ++---
 .../create/AbstractTableCreationBuilder.java    |  18 +--
 .../apache/metamodel/data/AbstractDataSet.java  |   6 +-
 .../org/apache/metamodel/data/AbstractRow.java  |   3 +-
 .../metamodel/data/AbstractRowBuilder.java      |   9 +-
 .../metamodel/data/CachingDataSetHeader.java    |   3 -
 .../java/org/apache/metamodel/data/DataSet.java |   2 +-
 .../apache/metamodel/data/DataSetHeader.java    |   3 +-
 .../metamodel/data/DataSetTableModel.java       |   8 +-
 .../org/apache/metamodel/data/EmptyDataSet.java |   8 --
 .../apache/metamodel/data/InMemoryDataSet.java  |   2 +-
 .../java/org/apache/metamodel/data/Row.java     |   3 +-
 .../metamodel/data/ScalarFunctionDataSet.java   |   2 +-
 .../metamodel/data/SimpleDataSetHeader.java     |   9 +-
 .../org/apache/metamodel/data/UnionDataSet.java |   2 +-
 .../insert/AbstractRowInsertionBuilder.java     |   8 +-
 .../intercept/InterceptableDataContext.java     |  30 +++--
 .../org/apache/metamodel/query/FromItem.java    |  14 +--
 .../java/org/apache/metamodel/query/Query.java  |  14 ++-
 .../query/builder/GroupedQueryBuilderImpl.java  |   2 +-
 .../query/builder/InitFromBuilderImpl.java      |   2 +-
 .../query/builder/SatisfiedFromBuilder.java     |   6 +-
 .../builder/SatisfiedFromBuilderCallback.java   |   5 +
 .../metamodel/schema/AbstractRelationship.java  |  32 ++---
 .../apache/metamodel/schema/AbstractSchema.java |  44 +++----
 .../apache/metamodel/schema/AbstractTable.java  | 119 ++++++++----------
 .../metamodel/schema/CompositeSchema.java       |  22 ++--
 .../metamodel/schema/ImmutableRelationship.java |  31 ++---
 .../metamodel/schema/ImmutableSchema.java       |  10 +-
 .../apache/metamodel/schema/ImmutableTable.java |  12 +-
 .../metamodel/schema/MutableRelationship.java   |  25 ++--
 .../apache/metamodel/schema/MutableSchema.java  |   6 +-
 .../apache/metamodel/schema/MutableTable.java   |  11 +-
 .../apache/metamodel/schema/Relationship.java   |   5 +-
 .../org/apache/metamodel/schema/Schema.java     |  10 +-
 .../java/org/apache/metamodel/schema/Table.java |  32 ++---
 .../metamodel/AbstractDataContextTest.java      |  24 ++--
 .../metamodel/CompositeDataContextTest.java     |  17 ++-
 .../apache/metamodel/MetaModelHelperTest.java   |  41 +++---
 .../org/apache/metamodel/MetaModelTestCase.java |  14 +--
 .../org/apache/metamodel/MockDataContext.java   |   9 +-
 .../metamodel/MockUpdateableDataContext.java    |  13 +-
 .../QueryPostprocessDataContextTest.java        | 124 +++++++++----------
 .../metamodel/convert/ConvertersTest.java       |   4 +-
 .../create/AbstractCreateTableBuilderTest.java  |  14 +--
 .../metamodel/data/DataSetTableModelTest.java   |   3 +-
 .../apache/metamodel/data/DefaultRowTest.java   |   9 +-
 .../java/org/apache/metamodel/data/RowTest.java |  17 ++-
 .../apache/metamodel/data/UnionDataSetTest.java |  19 ++-
 .../delete/AbstractRowDeletionCallbackTest.java |   2 +-
 .../intercept/InterceptableDataContextTest.java |  25 ++--
 .../apache/metamodel/query/FilterItemTest.java  |  30 ++---
 .../apache/metamodel/query/FromItemTest.java    |  11 +-
 .../org/apache/metamodel/query/QueryTest.java   |   2 +-
 .../apache/metamodel/query/SelectItemTest.java  |  14 ++-
 .../builder/GroupedQueryBuilderImplTest.java    |   4 +-
 .../query/builder/SyntaxExamplesTest.java       |   6 +-
 .../metamodel/schema/MutableTableTest.java      |  19 +--
 .../metamodel/schema/SchemaModelTest.java       |  40 +++---
 ...acyDeserializationObjectInputStreamTest.java |   5 +-
 .../metamodel/sugarcrm/SugarCrmDataContext.java |   2 +-
 .../apache/metamodel/xml/XmlDomDataContext.java |  69 +++++------
 .../apache/metamodel/xml/XmlSaxDataContext.java |  11 +-
 .../metamodel/xml/XmlDomDataContextTest.java    |  53 ++++----
 .../metamodel/xml/XmlSaxDataContextTest.java    |  10 +-
 75 files changed, 705 insertions(+), 680 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/pom.xml
----------------------------------------------------------------------
diff --git a/core/pom.xml b/core/pom.xml
index 3af58c9..4add6ad 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -28,6 +28,10 @@ under the License.
        <name>MetaModel core API</name>
        <dependencies>
                <dependency>
+                       <groupId>com.google.guava</groupId>
+                       <artifactId>guava</artifactId>
+               </dependency>
+               <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-api</artifactId>
                </dependency>

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/AbstractDataContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/AbstractDataContext.java 
b/core/src/main/java/org/apache/metamodel/AbstractDataContext.java
index a42d7f6..4fd00a6 100644
--- a/core/src/main/java/org/apache/metamodel/AbstractDataContext.java
+++ b/core/src/main/java/org/apache/metamodel/AbstractDataContext.java
@@ -45,7 +45,7 @@ public abstract class AbstractDataContext implements 
DataContext {
     private static final String NULL_SCHEMA_NAME_TOKEN = 
"<metamodel.schema.name.null>";
     private final ConcurrentMap<String, Schema> _schemaCache = new 
ConcurrentHashMap<String, Schema>();
     private final Comparator<? super String> _schemaNameComparator = 
SchemaNameComparator.getInstance();
-    private String[] _schemaNameCache;
+    private List<String> _schemaNameCache;
 
     /**
      * {@inheritDoc}
@@ -70,11 +70,10 @@ public abstract class AbstractDataContext implements 
DataContext {
      * {@inheritDoc}
      */
     @Override
-    public final Schema[] getSchemas() throws MetaModelException {
-        String[] schemaNames = getSchemaNames();
-        Schema[] schemas = new Schema[schemaNames.length];
-        for (int i = 0; i < schemaNames.length; i++) {
-            final String name = schemaNames[i];
+    public final List<Schema> getSchemas() throws MetaModelException {
+        List<String> schemaNames = getSchemaNames();
+        List<Schema> schemas = new ArrayList<>();
+        for (final String name: schemaNames) {
             final Schema schema = _schemaCache.get(getSchemaCacheKey(name));
             if (schema == null) {
                 final Schema newSchema = getSchemaByName(name);
@@ -83,12 +82,12 @@ public abstract class AbstractDataContext implements 
DataContext {
                 }
                 final Schema existingSchema = 
_schemaCache.putIfAbsent(getSchemaCacheKey(name), newSchema);
                 if (existingSchema == null) {
-                    schemas[i] = newSchema;
+                    schemas.add(newSchema);
                 } else {
-                    schemas[i] = existingSchema;
+                    schemas.add(existingSchema);
                 }
             } else {
-                schemas[i] = schema;
+                schemas.add(schema);
             }
         }
         return schemas;
@@ -105,12 +104,12 @@ public abstract class AbstractDataContext implements 
DataContext {
      * m {@inheritDoc}
      */
     @Override
-    public final String[] getSchemaNames() throws MetaModelException {
+    public final List<String> getSchemaNames() throws MetaModelException {
         if (_schemaNameCache == null) {
             _schemaNameCache = getSchemaNamesInternal();
         }
-        String[] schemaNames = Arrays.copyOf(_schemaNameCache, 
_schemaNameCache.length);
-        Arrays.sort(schemaNames, _schemaNameComparator);
+        List<String> schemaNames = new ArrayList<>(_schemaNameCache);
+        schemaNames.sort(_schemaNameComparator);
         return schemaNames;
     }
 
@@ -125,13 +124,12 @@ public abstract class AbstractDataContext implements 
DataContext {
             result = getSchemaByName(defaultSchemaName);
         }
         if (result == null) {
-            final Schema[] schemas = getSchemas();
-            if (schemas.length == 1) {
-                result = schemas[0];
+            final List<Schema> schemas = getSchemas();
+            if (schemas.size() == 1) {
+                result = schemas.get(0);
             } else {
                 int highestTableCount = -1;
-                for (int i = 0; i < schemas.length; i++) {
-                    final Schema schema = schemas[i];
+                for (Schema schema: schemas) {
                     String name = schema.getName();
                     if (schema != null) {
                         name = name.toLowerCase();
@@ -200,7 +198,7 @@ public abstract class AbstractDataContext implements 
DataContext {
             if (name == null) {
                 schema = getSchemaByNameInternal(null);
             } else {
-                String[] schemaNames = getSchemaNames();
+                List<String> schemaNames = getSchemaNames();
                 for (String schemaName : schemaNames) {
                     if (name.equalsIgnoreCase(schemaName)) {
                         schema = getSchemaByNameInternal(name);
@@ -255,7 +253,7 @@ public abstract class AbstractDataContext implements 
DataContext {
         }
 
         Schema schema = null;
-        final String[] schemaNames = getSchemaNames();
+        final List<String> schemaNames = getSchemaNames();
         for (final String schemaName : schemaNames) {
             if (schemaName == null) {
                 // search without schema name (some databases have only a 
single
@@ -333,7 +331,7 @@ public abstract class AbstractDataContext implements 
DataContext {
     private final Column getColumn(final Schema schema, final String 
tableAndColumnPath) {
         Table table = null;
         String columnPath = tableAndColumnPath;
-        final String[] tableNames = schema.getTableNames();
+        final List<String> tableNames = schema.getTableNames();
         for (final String tableName : tableNames) {
             if (tableName != null) {
                 // search case-sensitive
@@ -368,8 +366,8 @@ public abstract class AbstractDataContext implements 
DataContext {
             }
         }
 
-        if (table == null && tableNames.length == 1) {
-            table = schema.getTables()[0];
+        if (table == null && tableNames.size() == 1) {
+            table = schema.getTables().get(0);
         }
 
         if (table != null) {
@@ -403,7 +401,7 @@ public abstract class AbstractDataContext implements 
DataContext {
         }
 
         Schema schema = null;
-        String[] schemaNames = getSchemaNames();
+        List<String> schemaNames = getSchemaNames();
         for (String schemaName : schemaNames) {
             if (schemaName == null) {
                 // there's an unnamed schema present.
@@ -452,7 +450,7 @@ public abstract class AbstractDataContext implements 
DataContext {
     /**
      * Tokenizes a path for a table or a column.
      * 
-     * @param tableName
+     * @param path
      * @param expectedParts
      * @return
      */
@@ -545,7 +543,7 @@ public abstract class AbstractDataContext implements 
DataContext {
      * 
      * @return an array of schema names.
      */
-    protected abstract String[] getSchemaNamesInternal();
+    protected abstract List<String> getSchemaNamesInternal();
 
     /**
      * Gets the name of the default schema.

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/AbstractUpdateCallback.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/AbstractUpdateCallback.java 
b/core/src/main/java/org/apache/metamodel/AbstractUpdateCallback.java
index a1c2f1a..4ff7279 100644
--- a/core/src/main/java/org/apache/metamodel/AbstractUpdateCallback.java
+++ b/core/src/main/java/org/apache/metamodel/AbstractUpdateCallback.java
@@ -60,7 +60,7 @@ public abstract class AbstractUpdateCallback implements 
UpdateCallback {
         final Table table = schema.getTableByName(tableName);
         if (table == null) {
             throw new IllegalArgumentException("Nu such table '" + tableName + 
"' found in schema: " + schema
-                    + ". Available tables are: " + 
Arrays.toString(schema.getTableNames()));
+                    + ". Available tables are: " + 
Arrays.toString(schema.getTableNames().toArray()));
         }
         return dropTable(table);
     }
@@ -82,7 +82,7 @@ public abstract class AbstractUpdateCallback implements 
UpdateCallback {
         final Table table = schema.getTableByName(tableName);
         if (table == null) {
             throw new IllegalArgumentException("Nu such table '" + tableName + 
"' found in schema: " + schema
-                    + ". Available tables are: " + 
Arrays.toString(schema.getTableNames()));
+                    + ". Available tables are: " + 
Arrays.toString(schema.getTableNames().toArray()));
         }
         return table;
     }

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/CompositeDataContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/CompositeDataContext.java 
b/core/src/main/java/org/apache/metamodel/CompositeDataContext.java
index 8612a51..0ddc78c 100644
--- a/core/src/main/java/org/apache/metamodel/CompositeDataContext.java
+++ b/core/src/main/java/org/apache/metamodel/CompositeDataContext.java
@@ -18,16 +18,9 @@
  */
 package org.apache.metamodel;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 import java.util.function.Function;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.data.DataSet;
 import org.apache.metamodel.query.FromItem;
@@ -178,10 +171,10 @@ public class CompositeDataContext extends 
AbstractDataContext {
     }
 
     @Override
-    public String[] getSchemaNamesInternal() throws MetaModelException {
-        Set<String> set = new HashSet<String>();
+    public List<String> getSchemaNamesInternal() throws MetaModelException {
+        Set<String> set = new TreeSet<>();
         for (DataContext dc : _delegates) {
-            String[] schemaNames = dc.getSchemaNames();
+            List<String> schemaNames = dc.getSchemaNames();
             for (String name : schemaNames) {
                 if (!MetaModelHelper.isInformationSchema(name)) {
                     // we skip information schemas, since they're anyways going
@@ -190,9 +183,7 @@ public class CompositeDataContext extends 
AbstractDataContext {
                 }
             }
         }
-        String[] result = set.toArray(new String[set.size()]);
-        Arrays.sort(result);
-        return result;
+        return new ArrayList<>(set);
     }
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/CompositeQueryDelegate.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/CompositeQueryDelegate.java 
b/core/src/main/java/org/apache/metamodel/CompositeQueryDelegate.java
index d3e1a04..8402695 100644
--- a/core/src/main/java/org/apache/metamodel/CompositeQueryDelegate.java
+++ b/core/src/main/java/org/apache/metamodel/CompositeQueryDelegate.java
@@ -18,6 +18,7 @@
  */
 package org.apache.metamodel;
 
+import java.util.List;
 import java.util.function.Function;
 
 import org.apache.metamodel.data.DataSet;
@@ -35,7 +36,7 @@ final class CompositeQueryDelegate extends 
QueryPostprocessDelegate {
        }
 
        @Override
-       protected DataSet materializeMainSchemaTable(Table table, Column[] 
columns,
+       protected DataSet materializeMainSchemaTable(Table table, List<Column> 
columns,
                        int maxRows) {
                // find the appropriate datacontext to execute a simple
                // table materialization query

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/DataContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/DataContext.java 
b/core/src/main/java/org/apache/metamodel/DataContext.java
index 132ecfb..ee56f1e 100644
--- a/core/src/main/java/org/apache/metamodel/DataContext.java
+++ b/core/src/main/java/org/apache/metamodel/DataContext.java
@@ -27,6 +27,9 @@ import org.apache.metamodel.schema.Column;
 import org.apache.metamodel.schema.Schema;
 import org.apache.metamodel.schema.Table;
 
+import java.util.Collection;
+import java.util.List;
+
 /**
  * A DataContext represents the central entry point for interactions with
  * datastores. The DataContext contains of the structure of data (in the form 
of
@@ -51,7 +54,7 @@ public interface DataContext {
      * @throws MetaModelException
      *             if an error occurs retrieving the schema model
      */
-    public Schema[] getSchemas() throws MetaModelException;
+    public List<Schema> getSchemas() throws MetaModelException;
 
     /**
      * Gets the names of all schemas within this DataContext.
@@ -60,7 +63,7 @@ public interface DataContext {
      * @throws MetaModelException
      *             if an error occurs retrieving the schema model
      */
-    public String[] getSchemaNames() throws MetaModelException;
+    public List<String> getSchemaNames() throws MetaModelException;
 
     /**
      * Gets the default schema of this DataContext.

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/DeleteAndInsertBuilder.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/DeleteAndInsertBuilder.java 
b/core/src/main/java/org/apache/metamodel/DeleteAndInsertBuilder.java
index 1b4670b..2227256 100644
--- a/core/src/main/java/org/apache/metamodel/DeleteAndInsertBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/DeleteAndInsertBuilder.java
@@ -82,11 +82,11 @@ public class DeleteAndInsertBuilder extends 
AbstractRowUpdationBuilder {
      * @return
      */
     private Row update(final Row original) {
-        SelectItem[] items = original.getSelectItems();
-        Object[] values = new Object[items.length];
-        for (int i = 0; i < items.length; i++) {
+        List<SelectItem> items = original.getSelectItems();
+        Object[] values = new Object[items.size()];
+        for (int i = 0; i < items.size(); i++) {
             final Object value;
-            Column column = items[i].getColumn();
+            Column column = items.get(i).getColumn();
             if (isSet(column)) {
                 // use update statement's value
                 value = getValues()[i];
@@ -103,7 +103,10 @@ public class DeleteAndInsertBuilder extends 
AbstractRowUpdationBuilder {
         final DataContext dc = _updateCallback.getDataContext();
         final Table table = getTable();
         final List<FilterItem> whereItems = getWhereItems();
-        final DataSet dataSet = 
dc.query().from(table).select(table.getColumns()).where(whereItems).execute();
+        final DataSet dataSet = dc.query()
+                .from(table)
+                .select(table.getColumns().toArray(new 
Column[table.getColumns().size()]))
+                .where(whereItems).execute();
         final List<Row> rows = dataSet.toRows();
         return rows;
     }

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/MetaModelHelper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/MetaModelHelper.java 
b/core/src/main/java/org/apache/metamodel/MetaModelHelper.java
index 09d47bc..ae87083 100644
--- a/core/src/main/java/org/apache/metamodel/MetaModelHelper.java
+++ b/core/src/main/java/org/apache/metamodel/MetaModelHelper.java
@@ -28,7 +28,10 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
+import com.google.common.collect.Lists;
 import org.apache.metamodel.data.CachingDataSetHeader;
 import org.apache.metamodel.data.DataSet;
 import org.apache.metamodel.data.DataSetHeader;
@@ -185,8 +188,8 @@ public final class MetaModelHelper {
 
         List<SelectItem> selectItems = new ArrayList<SelectItem>();
         for (DataSet dataSet : fromDataSets) {
-            for (int i = 0; i < dataSet.getSelectItems().length; i++) {
-                SelectItem item = dataSet.getSelectItems()[i];
+            for (int i = 0; i < dataSet.getSelectItems().size(); i++) {
+                SelectItem item = dataSet.getSelectItems().get(i);
                 selectItems.add(item);
             }
         }
@@ -195,7 +198,7 @@ public final class MetaModelHelper {
         List<Object[]> data = new ArrayList<Object[]>();
         for (int fromDataSetIndex = 0; fromDataSetIndex < fromDataSets.length; 
fromDataSetIndex++) {
             DataSet fromDataSet = fromDataSets[fromDataSetIndex];
-            SelectItem[] fromSelectItems = fromDataSet.getSelectItems();
+            List<SelectItem> fromSelectItems = fromDataSet.getSelectItems();
             if (fromDataSetIndex == 0) {
                 while (fromDataSet.next()) {
                     Object[] values = fromDataSet.getRow().getValues();
@@ -220,7 +223,7 @@ public final class MetaModelHelper {
                     }
                 }
             }
-            selectItemOffset += fromSelectItems.length;
+            selectItemOffset += fromSelectItems.size();
         }
 
         if (data.isEmpty()) {
@@ -261,7 +264,7 @@ public final class MetaModelHelper {
     }
 
     public static DataSet getSelection(final List<SelectItem> selectItems, 
final DataSet dataSet) {
-        final List<SelectItem> dataSetSelectItems = 
Arrays.asList(dataSet.getSelectItems());
+        final List<SelectItem> dataSetSelectItems = dataSet.getSelectItems();
 
         // check if the selection is already the same
         if (selectItems.equals(dataSetSelectItems)) {
@@ -295,18 +298,17 @@ public final class MetaModelHelper {
 
     public static DataSet getGrouped(List<SelectItem> selectItems, DataSet 
dataSet,
             Collection<GroupByItem> groupByItems) {
-        return getGrouped(selectItems, dataSet, groupByItems.toArray(new 
GroupByItem[groupByItems.size()]));
+        return getGrouped(selectItems, dataSet, groupByItems);
     }
 
-    public static DataSet getGrouped(List<SelectItem> selectItems, DataSet 
dataSet, GroupByItem[] groupByItems) {
+    public static DataSet getGrouped(List<SelectItem> selectItems, DataSet 
dataSet, List<GroupByItem> groupByItems) {
         DataSet result = dataSet;
-        if (groupByItems != null && groupByItems.length > 0) {
+        if (groupByItems != null && groupByItems.size() > 0) {
             Map<Row, Map<SelectItem, List<Object>>> uniqueRows = new 
HashMap<Row, Map<SelectItem, List<Object>>>();
 
-            final SelectItem[] groupBySelects = new 
SelectItem[groupByItems.length];
-            for (int i = 0; i < groupBySelects.length; i++) {
-                groupBySelects[i] = groupByItems[i].getSelectItem();
-            }
+            final List<SelectItem> groupBySelects = groupByItems.stream()
+                    .map(gbi -> gbi.getSelectItem())
+                    .collect(Collectors.toList());
             final DataSetHeader groupByHeader = new 
CachingDataSetHeader(groupBySelects);
 
             // Creates a list of SelectItems that have aggregate functions
@@ -663,12 +665,9 @@ public final class MetaModelHelper {
         if (ds2 == null) {
             throw new IllegalArgumentException("Right DataSet cannot be null");
         }
-        SelectItem[] si1 = ds1.getSelectItems();
-        SelectItem[] si2 = ds2.getSelectItems();
-        SelectItem[] selectItems = new SelectItem[si1.length + si2.length];
-        System.arraycopy(si1, 0, selectItems, 0, si1.length);
-        System.arraycopy(si2, 0, selectItems, si1.length, si2.length);
-
+        List<SelectItem> si1 = ds1.getSelectItems();
+        List<SelectItem> si2 = ds2.getSelectItems();
+        List<SelectItem> selectItems = 
Stream.concat(si1.stream(),si2.stream()).collect(Collectors.toList());
         List<Row> resultRows = new ArrayList<Row>();
         List<Row> ds2data = readDataSetFull(ds2);
         if (ds2data.isEmpty()) {
@@ -695,7 +694,7 @@ public final class MetaModelHelper {
                 resultRows.addAll(carthesianRows);
             } else {
                 Object[] values = ds1row.getValues();
-                Object[] row = new Object[selectItems.length];
+                Object[] row = new Object[selectItems.size()];
                 System.arraycopy(values, 0, row, 0, values.length);
                 resultRows.add(new DefaultRow(header, row));
             }
@@ -721,11 +720,11 @@ public final class MetaModelHelper {
      * @return the right joined result dataset
      */
     public static DataSet getRightJoin(DataSet ds1, DataSet ds2, FilterItem[] 
onConditions) {
-        SelectItem[] ds1selects = ds1.getSelectItems();
-        SelectItem[] ds2selects = ds2.getSelectItems();
-        SelectItem[] leftOrderedSelects = new SelectItem[ds1selects.length + 
ds2selects.length];
-        System.arraycopy(ds1selects, 0, leftOrderedSelects, 0, 
ds1selects.length);
-        System.arraycopy(ds2selects, 0, leftOrderedSelects, ds1selects.length, 
ds2selects.length);
+        List<SelectItem> ds1selects = ds1.getSelectItems();
+        List<SelectItem> ds2selects = ds2.getSelectItems();
+        List<SelectItem> leftOrderedSelects = new ArrayList<>();
+        leftOrderedSelects.addAll(ds1selects);
+        leftOrderedSelects.addAll(ds2selects);
 
         // We will reuse the left join algorithm (but switch the datasets
         // around)
@@ -744,12 +743,12 @@ public final class MetaModelHelper {
     }
 
     public static DataSet getDistinct(DataSet dataSet) {
-        SelectItem[] selectItems = dataSet.getSelectItems();
-        GroupByItem[] groupByItems = new GroupByItem[selectItems.length];
-        for (int i = 0; i < groupByItems.length; i++) {
-            groupByItems[i] = new GroupByItem(selectItems[i]);
-        }
-        return getGrouped(Arrays.asList(selectItems), dataSet, groupByItems);
+        List<SelectItem> selectItems = dataSet.getSelectItems();
+        List<GroupByItem> groupByItems = selectItems.stream()
+                .map(GroupByItem::new)
+                .collect(Collectors.toList());
+
+        return getGrouped(selectItems, dataSet, groupByItems);
     }
 
     public static Table[] getTables(Column[] columns) {

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/QueryPostprocessDataContext.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/QueryPostprocessDataContext.java 
b/core/src/main/java/org/apache/metamodel/QueryPostprocessDataContext.java
index fac70d0..cbd97d3 100644
--- a/core/src/main/java/org/apache/metamodel/QueryPostprocessDataContext.java
+++ b/core/src/main/java/org/apache/metamodel/QueryPostprocessDataContext.java
@@ -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.convert.ConvertedDataSetInterceptor;
 import org.apache.metamodel.convert.Converters;
@@ -366,11 +367,11 @@ public abstract class QueryPostprocessDataContext extends 
AbstractDataContext im
         if (selectItems == null || selectItems.isEmpty()) {
             // add any column (typically this occurs because of COUNT(*)
             // queries)
-            Column[] columns = table.getColumns();
-            if (columns.length == 0) {
+            List<Column> columns = table.getColumns();
+            if (columns.size() == 0) {
                 logger.warn("Queried table has no columns: {}", table);
             } else {
-                selectItems.add(new SelectItem(columns[0]));
+                selectItems.add(new SelectItem(columns.get(0)));
             }
         }
 
@@ -442,10 +443,10 @@ public abstract class QueryPostprocessDataContext extends 
AbstractDataContext im
     }
 
     @Override
-    protected final String[] getSchemaNamesInternal() throws 
MetaModelException {
-        final String[] schemaNames = new String[2];
-        schemaNames[0] = INFORMATION_SCHEMA_NAME;
-        schemaNames[1] = getMainSchemaName();
+    protected final List<String> getSchemaNamesInternal() throws 
MetaModelException {
+        final List<String> schemaNames = new ArrayList<>();
+        schemaNames.add(INFORMATION_SCHEMA_NAME);
+        schemaNames.add(getMainSchemaName());
         return schemaNames;
     }
 
@@ -527,9 +528,11 @@ public abstract class QueryPostprocessDataContext extends 
AbstractDataContext im
 
     private DataSet materializeInformationSchemaTable(final Table table, final 
List<SelectItem> selectItems) {
         final String tableName = table.getName();
-        final SelectItem[] columnSelectItems = 
MetaModelHelper.createSelectItems(table.getColumns());
+        final List<SelectItem> columnSelectItems = table.getColumns().stream()
+                .map(SelectItem::new)
+                .collect(Collectors.toList());
         final SimpleDataSetHeader header = new 
SimpleDataSetHeader(columnSelectItems);
-        final Table[] tables = getDefaultSchema().getTables();
+        final List<Table> tables = getDefaultSchema().getTables();
         final List<Row> data = new ArrayList<Row>();
         if ("tables".equals(tableName)) {
             // "tables" columns: name, type, num_columns, remarks
@@ -558,13 +561,13 @@ public abstract class QueryPostprocessDataContext extends 
AbstractDataContext im
             // "relationships" columns: primary_table, primary_column,
             // foreign_table, foreign_column
             for (Relationship r : getDefaultSchema().getRelationships()) {
-                Column[] primaryColumns = r.getPrimaryColumns();
-                Column[] foreignColumns = r.getForeignColumns();
+                List<Column> primaryColumns = r.getPrimaryColumns();
+                List<Column> foreignColumns = r.getForeignColumns();
                 Table pTable = r.getPrimaryTable();
                 Table fTable = r.getForeignTable();
-                for (int i = 0; i < primaryColumns.length; i++) {
-                    Column pColumn = primaryColumns[i];
-                    Column fColumn = foreignColumns[i];
+                for (int i = 0; i < primaryColumns.size(); i++) {
+                    Column pColumn = primaryColumns.get(i);
+                    Column fColumn = foreignColumns.get(i);
                     data.add(new DefaultRow(header,
                             new Object[] { pTable.getName(), 
pColumn.getName(), fTable.getName(), fColumn.getName() }));
                 }
@@ -628,11 +631,11 @@ public abstract class QueryPostprocessDataContext extends 
AbstractDataContext im
         DataSet dataSet;
         if (whereItems.isEmpty()) {
             // paging is pushed down to materializeMainSchemaTable
-            dataSet = materializeMainSchemaTable(table, workingSelectItems, 
firstRow, maxRows);
+            dataSet = materializeMainSchemaTableSelect(table, 
workingSelectItems, firstRow, maxRows);
             dataSet = MetaModelHelper.getSelection(selectItems, dataSet);
         } else {
             // do not push down paging, first we have to apply filtering
-            dataSet = materializeMainSchemaTable(table, workingSelectItems, 1, 
-1);
+            dataSet = materializeMainSchemaTableSelect(table, 
workingSelectItems, 1, -1);
             dataSet = MetaModelHelper.getFiltered(dataSet, whereItems);
             dataSet = MetaModelHelper.getPaged(dataSet, firstRow, maxRows);
             dataSet = MetaModelHelper.getSelection(selectItems, dataSet);
@@ -643,19 +646,19 @@ public abstract class QueryPostprocessDataContext extends 
AbstractDataContext im
     /**
      * Executes a simple one-table query against a table in the main schema of
      * the subclasses of this class. This default implementation will delegate
-     * to {@link #materializeMainSchemaTable(Table, Column[], int, int)}.
-     * 
+     * to {@link #materializeMainSchemaTable(Table, List, int, int)}.
+     *
      * @param table
      * @param selectItems
      * @param firstRow
      * @param maxRows
      * @return
      */
-    protected DataSet materializeMainSchemaTable(Table table, List<SelectItem> 
selectItems, int firstRow, int maxRows) {
-        Column[] columns = new Column[selectItems.size()];
-        for (int i = 0; i < columns.length; i++) {
-            columns[i] = selectItems.get(i).getColumn();
-        }
+    protected DataSet materializeMainSchemaTableSelect(Table table, 
List<SelectItem> selectItems, int firstRow, int maxRows) {
+        List<Column> columns = selectItems.stream()
+                .map(si -> si.getColumn())
+                .collect(Collectors.toList());
+
         DataSet dataSet = materializeMainSchemaTable(table, columns, firstRow, 
maxRows);
 
         dataSet = MetaModelHelper.getSelection(selectItems, dataSet);
@@ -666,7 +669,7 @@ public abstract class QueryPostprocessDataContext extends 
AbstractDataContext im
     /**
      * Executes a simple one-table query against a table in the main schema of
      * the subclasses of this class. This default implementation will delegate
-     * to {@link #materializeMainSchemaTable(Table, Column[], int)} and apply a
+     * to {@link #materializeMainSchemaTable(Table, List, int)} and apply a
      * {@link FirstRowDataSet} if necessary.
      * 
      * @param table
@@ -675,7 +678,7 @@ public abstract class QueryPostprocessDataContext extends 
AbstractDataContext im
      * @param maxRows
      * @return
      */
-    protected DataSet materializeMainSchemaTable(Table table, Column[] 
columns, int firstRow, int maxRows) {
+    protected DataSet materializeMainSchemaTable(Table table, List<Column> 
columns, int firstRow, int maxRows) {
         final int rowsToMaterialize;
         if (firstRow == 1) {
             rowsToMaterialize = maxRows;
@@ -702,5 +705,5 @@ public abstract class QueryPostprocessDataContext extends 
AbstractDataContext im
      *            wanted.
      * @return a dataset with the raw table/column content.
      */
-    protected abstract DataSet materializeMainSchemaTable(Table table, 
Column[] columns, int maxRows);
+    protected abstract DataSet materializeMainSchemaTable(Table table, 
List<Column> columns, int maxRows);
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/convert/ConvertedDataSetInterceptor.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/convert/ConvertedDataSetInterceptor.java
 
b/core/src/main/java/org/apache/metamodel/convert/ConvertedDataSetInterceptor.java
index 082d121..4ff00e8 100644
--- 
a/core/src/main/java/org/apache/metamodel/convert/ConvertedDataSetInterceptor.java
+++ 
b/core/src/main/java/org/apache/metamodel/convert/ConvertedDataSetInterceptor.java
@@ -19,6 +19,7 @@
 package org.apache.metamodel.convert;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.metamodel.data.DataSet;
@@ -67,10 +68,10 @@ public class ConvertedDataSetInterceptor implements 
DataSetInterceptor, HasReadT
                }
 
                boolean hasConverter = false;
-               SelectItem[] selectItems = dataSet.getSelectItems();
-               TypeConverter<?, ?>[] converterArray = new 
TypeConverter[selectItems.length];
-               for (int i = 0; i < selectItems.length; i++) {
-                       SelectItem selectItem = selectItems[i];
+               List<SelectItem> selectItems = dataSet.getSelectItems();
+               TypeConverter<?, ?>[] converterArray = new 
TypeConverter[selectItems.size()];
+               for (int i = 0; i < selectItems.size(); i++) {
+                       SelectItem selectItem = selectItems.get(i);
                        Column column = selectItem.getColumn();
                        if (column != null && selectItem.getAggregateFunction() 
== null) {
                                TypeConverter<?, ?> converter = 
converters.get(column);

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/convert/Converters.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/Converters.java 
b/core/src/main/java/org/apache/metamodel/convert/Converters.java
index 1be0e13..142987e 100644
--- a/core/src/main/java/org/apache/metamodel/convert/Converters.java
+++ b/core/src/main/java/org/apache/metamodel/convert/Converters.java
@@ -18,10 +18,9 @@
  */
 package org.apache.metamodel.convert;
 
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
 import java.util.Map.Entry;
-import java.util.Set;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.DataContext;
 import org.apache.metamodel.MetaModelHelper;
@@ -136,15 +135,19 @@ public final class Converters {
      *         used (eg. with the {@link #addTypeConverters(DataContext, Map)}
      *         method) to decorate the DataContext with type converters.
      */
-    public static Map<Column, TypeConverter<?, ?>> 
autoDetectConverters(DataContext dataContext, Column[] columns,
+    public static Map<Column, TypeConverter<?, ?>> 
autoDetectConverters(DataContext dataContext, final List<Column> columns,
             int sampleSize) {
-        columns = MetaModelHelper.getColumnsBySuperType(columns, 
SuperColumnType.LITERAL_TYPE);
         final Map<Column, TypeConverter<?, ?>> result = new HashMap<Column, 
TypeConverter<?, ?>>();
-        Table[] tables = MetaModelHelper.getTables(columns);
-        for (Table table : tables) {
-            Column[] tableColumns = MetaModelHelper.getTableColumns(table, 
columns);
-            autoDetectConvertersInternally(dataContext, table, tableColumns, 
sampleSize, result);
-        }
+        columns.stream()
+                .filter(col -> col.getType() != null)
+                .filter(col -> 
col.getType().getSuperType().equals(SuperColumnType.LITERAL_TYPE))
+                // group by table
+                .collect(Collectors.toMap(Column::getTable,Arrays::asList))
+                //and detect it
+                .forEach((tab, cols) ->{
+                    
autoDetectConvertersInternally(dataContext,tab,cols,sampleSize,result);
+        });
+
         return result;
     }
 
@@ -172,14 +175,14 @@ public final class Converters {
     public static Map<Column, TypeConverter<?, ?>> 
autoDetectConverters(DataContext dataContext, Table table,
             int sampleSize) {
         final Map<Column, TypeConverter<?, ?>> result = new HashMap<Column, 
TypeConverter<?, ?>>();
-        Column[] columns = 
table.getColumnsOfSuperType(SuperColumnType.LITERAL_TYPE);
+        List<Column> columns = 
table.getColumnsOfSuperType(SuperColumnType.LITERAL_TYPE);
         autoDetectConvertersInternally(dataContext, table, columns, 
sampleSize, result);
         return result;
     }
 
-    private static void autoDetectConvertersInternally(DataContext 
dataContext, Table table, Column[] columns,
+    private static void autoDetectConvertersInternally(DataContext 
dataContext, Table table, List<Column> columns,
             int sampleSize, Map<Column, TypeConverter<?, ?>> result) {
-        if (columns == null || columns.length == 0) {
+        if (columns == null || columns.size() == 0) {
             return;
         }
 
@@ -188,7 +191,7 @@ public final class Converters {
             detectors.put(column, new ColumnTypeDetector());
         }
 
-        Query query = 
dataContext.query().from(table).select(columns).toQuery();
+        Query query = 
dataContext.query().from(table).select(columns.toArray(new 
Column[columns.size()])).toQuery();
         if (sampleSize > 0 && sampleSize != Integer.MAX_VALUE) {
             query.setMaxRows(sampleSize);
         }
@@ -306,7 +309,7 @@ public final class Converters {
      */
     protected static <RB extends RowBuilder<?>> RB convertRow(RB rowBuilder, 
Map<Column, TypeConverter<?, ?>> converters) {
         Table table = rowBuilder.getTable();
-        Column[] columns = table.getColumns();
+        List<Column> columns = table.getColumns();
         Row row = rowBuilder.toRow();
         for (Column column : columns) {
             @SuppressWarnings("unchecked")

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/create/AbstractTableCreationBuilder.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/create/AbstractTableCreationBuilder.java
 
b/core/src/main/java/org/apache/metamodel/create/AbstractTableCreationBuilder.java
index 401be9f..1833120 100644
--- 
a/core/src/main/java/org/apache/metamodel/create/AbstractTableCreationBuilder.java
+++ 
b/core/src/main/java/org/apache/metamodel/create/AbstractTableCreationBuilder.java
@@ -29,6 +29,8 @@ import org.apache.metamodel.schema.TableType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.List;
+
 /**
  * Abstract {@link TableCreationBuilder} implementation, provided as 
convenience
  * for {@link TableCreatable} implementations. Handles all the building
@@ -72,7 +74,7 @@ public abstract class AbstractTableCreationBuilder<U extends 
UpdateCallback> imp
     @Override
     public TableCreationBuilder like(Table table) {
         logger.debug("like({})", table);
-        Column[] columns = table.getColumns();
+        List<Column> columns = table.getColumns();
         for (Column column : columns) {
             withColumn(column.getName()).like(column);
         }
@@ -101,12 +103,12 @@ public abstract class AbstractTableCreationBuilder<U 
extends UpdateCallback> imp
         sb.append("CREATE TABLE ");
         sb.append(_table.getQualifiedLabel());
         sb.append(" (");
-        Column[] columns = _table.getColumns();
-        for (int i = 0; i < columns.length; i++) {
+        List<Column> columns = _table.getColumns();
+        for (int i = 0; i < columns.size(); i++) {
             if (i != 0) {
                 sb.append(',');
             }
-            Column column = columns[i];
+            Column column = columns.get(i);
             sb.append(column.getName());
             ColumnType type = column.getType();
             if (type != null) {
@@ -125,15 +127,15 @@ public abstract class AbstractTableCreationBuilder<U 
extends UpdateCallback> imp
             }
         }
         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());
                 }
             }    
         }

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/data/AbstractDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/AbstractDataSet.java 
b/core/src/main/java/org/apache/metamodel/data/AbstractDataSet.java
index f616ddc..6e64446 100644
--- a/core/src/main/java/org/apache/metamodel/data/AbstractDataSet.java
+++ b/core/src/main/java/org/apache/metamodel/data/AbstractDataSet.java
@@ -56,7 +56,7 @@ public abstract class AbstractDataSet extends BaseObject 
implements DataSet {
         if (dataSet instanceof AbstractDataSet) {
             _header = ((AbstractDataSet) dataSet).getHeader();
         } else {
-            _header = new 
CachingDataSetHeader(Arrays.asList(dataSet.getSelectItems()));
+            _header = new CachingDataSetHeader(dataSet.getSelectItems());
         }
     }
 
@@ -72,7 +72,7 @@ public abstract class AbstractDataSet extends BaseObject 
implements DataSet {
      * {@inheritDoc}
      */
     @Override
-    public SelectItem[] getSelectItems() {
+    public List<SelectItem> getSelectItems() {
         return getHeader().getSelectItems();
     }
 
@@ -118,7 +118,7 @@ public abstract class AbstractDataSet extends BaseObject 
implements DataSet {
      */
     @Override
     public String toString() {
-        return "DataSet[selectItems=" + Arrays.toString(getSelectItems()) + 
"]";
+        return "DataSet[selectItems=" + 
Arrays.toString(getSelectItems().toArray()) + "]";
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/data/AbstractRow.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/AbstractRow.java 
b/core/src/main/java/org/apache/metamodel/data/AbstractRow.java
index 9c931f1..f438a64 100644
--- a/core/src/main/java/org/apache/metamodel/data/AbstractRow.java
+++ b/core/src/main/java/org/apache/metamodel/data/AbstractRow.java
@@ -19,6 +19,7 @@
 package org.apache.metamodel.data;
 
 import java.util.Arrays;
+import java.util.List;
 
 import org.apache.metamodel.query.SelectItem;
 import org.apache.metamodel.schema.Column;
@@ -122,7 +123,7 @@ public abstract class AbstractRow implements Cloneable, Row 
{
     }
 
     @Override
-    public final SelectItem[] getSelectItems() {
+    public final List<SelectItem> getSelectItems() {
         return getHeader().getSelectItems();
     }
 

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/data/AbstractRowBuilder.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/data/AbstractRowBuilder.java 
b/core/src/main/java/org/apache/metamodel/data/AbstractRowBuilder.java
index fef04c9..144017c 100644
--- a/core/src/main/java/org/apache/metamodel/data/AbstractRowBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/data/AbstractRowBuilder.java
@@ -19,7 +19,10 @@
 package org.apache.metamodel.data;
 
 import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
 
+import org.apache.metamodel.query.SelectItem;
 import org.apache.metamodel.schema.Column;
 import org.apache.metamodel.schema.Table;
 
@@ -37,8 +40,8 @@ public abstract class AbstractRowBuilder<RB extends 
RowBuilder<?>> implements Ro
         this(table.getColumns());
     }
 
-    public AbstractRowBuilder(Column[] columns) {
-        _columns = columns;
+    public AbstractRowBuilder(List<Column> columns) {
+        _columns = columns.toArray(new Column[columns.size()]);
         _explicitNulls = new boolean[_columns.length];
         _values = new Object[_columns.length];
         _styles = new Style[_columns.length];
@@ -68,7 +71,7 @@ public abstract class AbstractRowBuilder<RB extends 
RowBuilder<?>> implements Ro
 
     @Override
     public final Row toRow() {
-        return new DefaultRow(new SimpleDataSetHeader(_columns), _values);
+        return new DefaultRow(new 
SimpleDataSetHeader(Arrays.stream(_columns).map(SelectItem::new).collect(Collectors.toList())),
 _values);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/data/CachingDataSetHeader.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/data/CachingDataSetHeader.java 
b/core/src/main/java/org/apache/metamodel/data/CachingDataSetHeader.java
index 2c4b0c9..76ce891 100644
--- a/core/src/main/java/org/apache/metamodel/data/CachingDataSetHeader.java
+++ b/core/src/main/java/org/apache/metamodel/data/CachingDataSetHeader.java
@@ -46,9 +46,6 @@ public final class CachingDataSetHeader extends 
SimpleDataSetHeader implements D
         super(items);
     }
 
-    public CachingDataSetHeader(SelectItem[] items) {
-        this(Arrays.asList(items));
-    }
 
     @Override
     public int indexOf(Column column) {

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/data/DataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/DataSet.java 
b/core/src/main/java/org/apache/metamodel/data/DataSet.java
index 993d408..fc277d0 100644
--- a/core/src/main/java/org/apache/metamodel/data/DataSet.java
+++ b/core/src/main/java/org/apache/metamodel/data/DataSet.java
@@ -35,7 +35,7 @@ public interface DataSet extends Closeable, Iterable<Row> {
     /**
      * @return the SelectItems that represent the columns of this DataSet
      */
-    public SelectItem[] getSelectItems();
+    public List<SelectItem> getSelectItems();
 
     /**
      * Finds the index of a given SelectItem

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/data/DataSetHeader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/DataSetHeader.java 
b/core/src/main/java/org/apache/metamodel/data/DataSetHeader.java
index 79e8c6c..6113497 100644
--- a/core/src/main/java/org/apache/metamodel/data/DataSetHeader.java
+++ b/core/src/main/java/org/apache/metamodel/data/DataSetHeader.java
@@ -19,6 +19,7 @@
 package org.apache.metamodel.data;
 
 import java.io.Serializable;
+import java.util.List;
 
 import org.apache.metamodel.query.SelectItem;
 import org.apache.metamodel.schema.Column;
@@ -29,7 +30,7 @@ import org.apache.metamodel.schema.Column;
  */
 public interface DataSetHeader extends Serializable {
 
-    public SelectItem[] getSelectItems();
+    public List<SelectItem> getSelectItems();
 
     public int size();
 

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/data/DataSetTableModel.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/data/DataSetTableModel.java 
b/core/src/main/java/org/apache/metamodel/data/DataSetTableModel.java
index 7316c00..c67ff05 100644
--- a/core/src/main/java/org/apache/metamodel/data/DataSetTableModel.java
+++ b/core/src/main/java/org/apache/metamodel/data/DataSetTableModel.java
@@ -39,7 +39,7 @@ public class DataSetTableModel extends AbstractTableModel {
        private boolean _materialized;
        private final List<Row> _materializedRows = new ArrayList<Row>();
        private final DataSet _dataSet;
-       private final SelectItem[] _selectItems;
+       private final List<SelectItem> _selectItems;
 
        public DataSetTableModel(DataSet dataSet) {
                _dataSet = dataSet;
@@ -49,7 +49,7 @@ public class DataSetTableModel extends AbstractTableModel {
 
        @Override
        public int hashCode() {
-               return Arrays.hashCode(_selectItems) + 
_materializedRows.hashCode();
+               return _selectItems.hashCode() + _materializedRows.hashCode();
        }
 
        @Override
@@ -71,7 +71,7 @@ public class DataSetTableModel extends AbstractTableModel {
        }
 
        public int getColumnCount() {
-               return _selectItems.length;
+               return _selectItems.size();
        }
 
        public int getRowCount() {
@@ -99,7 +99,7 @@ public class DataSetTableModel extends AbstractTableModel {
 
        @Override
        public String getColumnName(int column) {
-               return _selectItems[column].getSuperQueryAlias(false);
+               return _selectItems.get(column).getSuperQueryAlias(false);
        }
 
        @Override

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/data/EmptyDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/EmptyDataSet.java 
b/core/src/main/java/org/apache/metamodel/data/EmptyDataSet.java
index 0849255..fd71be3 100644
--- a/core/src/main/java/org/apache/metamodel/data/EmptyDataSet.java
+++ b/core/src/main/java/org/apache/metamodel/data/EmptyDataSet.java
@@ -32,14 +32,6 @@ public final class EmptyDataSet extends AbstractDataSet {
         super(header);
     }
 
-    public EmptyDataSet(SelectItem[] selectItems) {
-        super(new SimpleDataSetHeader(selectItems));
-    }
-
-    public EmptyDataSet(Column[] columns) {
-        super(new SimpleDataSetHeader(columns));
-    }
-
     public EmptyDataSet(List<SelectItem> selectItems) {
        this(new SimpleDataSetHeader(selectItems));
     }

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/data/InMemoryDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/InMemoryDataSet.java 
b/core/src/main/java/org/apache/metamodel/data/InMemoryDataSet.java
index a6b2d7e..88bf5ad 100644
--- a/core/src/main/java/org/apache/metamodel/data/InMemoryDataSet.java
+++ b/core/src/main/java/org/apache/metamodel/data/InMemoryDataSet.java
@@ -55,7 +55,7 @@ public final class InMemoryDataSet extends AbstractDataSet {
                     + " for this");
         }
 
-        final SelectItem[] selectItems = rows.get(0).getSelectItems();
+        final List<SelectItem> selectItems = rows.get(0).getSelectItems();
 
         if (rows.size() > 3) {
             // not that many records - caching will not have body to scale

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/data/Row.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/Row.java 
b/core/src/main/java/org/apache/metamodel/data/Row.java
index 65fc273..9f6f634 100644
--- a/core/src/main/java/org/apache/metamodel/data/Row.java
+++ b/core/src/main/java/org/apache/metamodel/data/Row.java
@@ -19,6 +19,7 @@
 package org.apache.metamodel.data;
 
 import java.io.Serializable;
+import java.util.List;
 
 import org.apache.metamodel.query.SelectItem;
 import org.apache.metamodel.schema.Column;
@@ -96,7 +97,7 @@ public interface Row extends Serializable {
      * 
      * @return
      */
-    public SelectItem[] getSelectItems();
+    public List<SelectItem> getSelectItems();
 
     /**
      * Gets the values of the row, represented as an object array

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/data/ScalarFunctionDataSet.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/data/ScalarFunctionDataSet.java 
b/core/src/main/java/org/apache/metamodel/data/ScalarFunctionDataSet.java
index 64a7866..9d45946 100644
--- a/core/src/main/java/org/apache/metamodel/data/ScalarFunctionDataSet.java
+++ b/core/src/main/java/org/apache/metamodel/data/ScalarFunctionDataSet.java
@@ -36,7 +36,7 @@ public class ScalarFunctionDataSet extends AbstractDataSet 
implements WrappingDa
 
     public ScalarFunctionDataSet(List<SelectItem> 
scalarFunctionSelectItemsToEvaluate, DataSet dataSet) {
         super(CollectionUtils.concat(false, 
scalarFunctionSelectItemsToEvaluate,
-                Arrays.<SelectItem> asList(dataSet.getSelectItems())));
+                dataSet.getSelectItems()));
         _scalarFunctionSelectItemsToEvaluate = 
scalarFunctionSelectItemsToEvaluate;
         _dataSet = dataSet;
     }

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/data/SimpleDataSetHeader.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/data/SimpleDataSetHeader.java 
b/core/src/main/java/org/apache/metamodel/data/SimpleDataSetHeader.java
index 8f8a8a8..afc6226 100644
--- a/core/src/main/java/org/apache/metamodel/data/SimpleDataSetHeader.java
+++ b/core/src/main/java/org/apache/metamodel/data/SimpleDataSetHeader.java
@@ -19,7 +19,9 @@
 package org.apache.metamodel.data;
 
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.MetaModelHelper;
 import org.apache.metamodel.query.SelectItem;
@@ -46,13 +48,10 @@ public class SimpleDataSetHeader implements DataSetHeader {
         this(Arrays.asList(selectItems));
     }
 
-    public SimpleDataSetHeader(Column[] columns) {
-        this(MetaModelHelper.createSelectItems(columns));
-    }
 
     @Override
-    public final SelectItem[] getSelectItems() {
-        return _items.toArray(new SelectItem[_items.size()]);
+    public final List<SelectItem> getSelectItems() {
+        return Collections.unmodifiableList(_items);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/data/UnionDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/UnionDataSet.java 
b/core/src/main/java/org/apache/metamodel/data/UnionDataSet.java
index 7962f56..f13124c 100644
--- a/core/src/main/java/org/apache/metamodel/data/UnionDataSet.java
+++ b/core/src/main/java/org/apache/metamodel/data/UnionDataSet.java
@@ -67,7 +67,7 @@ public class UnionDataSet extends AbstractDataSet implements 
WrappingDataSet {
                 return false;
             }
             _currentDataSet = _iterator.next().get();
-            assert getHeader().size() == 
_currentDataSet.getSelectItems().length;
+            assert getHeader().size() == 
_currentDataSet.getSelectItems().size();
         }
         return true;
     }

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/insert/AbstractRowInsertionBuilder.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/insert/AbstractRowInsertionBuilder.java
 
b/core/src/main/java/org/apache/metamodel/insert/AbstractRowInsertionBuilder.java
index bc09f98..58c0da8 100644
--- 
a/core/src/main/java/org/apache/metamodel/insert/AbstractRowInsertionBuilder.java
+++ 
b/core/src/main/java/org/apache/metamodel/insert/AbstractRowInsertionBuilder.java
@@ -25,6 +25,8 @@ import org.apache.metamodel.query.SelectItem;
 import org.apache.metamodel.schema.Column;
 import org.apache.metamodel.schema.Table;
 
+import java.util.List;
+
 /**
  * Abstract implementation of the {@link RowInsertionBuilder} interface,
  * provided as a convenience to {@link RowInsertable} implementations. Handles
@@ -53,9 +55,9 @@ public abstract class AbstractRowInsertionBuilder<U extends 
UpdateCallback> exte
 
     @Override
     public RowInsertionBuilder like(Row row) {
-        SelectItem[] selectItems = row.getSelectItems();
-        for (int i = 0; i < selectItems.length; i++) {
-            SelectItem selectItem = selectItems[i];
+        List<SelectItem> selectItems = row.getSelectItems();
+        for (int i = 0; i < selectItems.size(); i++) {
+            SelectItem selectItem = selectItems.get(i);
             Column column = selectItem.getColumn();
             if (column != null) {
                 if (_table == column.getTable()) {

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/intercept/InterceptableDataContext.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/intercept/InterceptableDataContext.java
 
b/core/src/main/java/org/apache/metamodel/intercept/InterceptableDataContext.java
index f8c74cb..1811e78 100644
--- 
a/core/src/main/java/org/apache/metamodel/intercept/InterceptableDataContext.java
+++ 
b/core/src/main/java/org/apache/metamodel/intercept/InterceptableDataContext.java
@@ -38,6 +38,10 @@ import org.apache.metamodel.schema.Table;
 import org.apache.metamodel.update.RowUpdationBuilder;
 import org.apache.metamodel.util.HasNameMapper;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
 public class InterceptableDataContext implements UpdateableDataContext {
 
     private final DataContext _delegate;
@@ -189,27 +193,29 @@ public class InterceptableDataContext implements 
UpdateableDataContext {
     }
 
     @Override
-    public Schema[] getSchemas() throws MetaModelException {
-        Schema[] schemas = _delegate.getSchemas();
+    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.length; i++) {
-                schemas[i] = _schemaInterceptors.interceptAll(schemas[i]);
+            for (int i = 0; i < schemas.size(); i++) {
+                schemas.set(i, 
_schemaInterceptors.interceptAll(schemas.get(i)));
             }
+        }else {
+            result = schemas;
         }
-        return schemas;
+        return result;
+
     }
 
     @Override
-    public String[] getSchemaNames() throws MetaModelException {
+    public List<String> getSchemaNames() throws MetaModelException {
         if (_schemaInterceptors.isEmpty()) {
             return _delegate.getSchemaNames();
         }
-        Schema[] schemas = getSchemas();
-        String[] schemaNames = new String[schemas.length];
-        for (int i = 0; i < schemaNames.length; i++) {
-            schemaNames[i] = new HasNameMapper().apply(schemas[i]);
-        }
-        return schemaNames;
+
+        return getSchemas().stream()
+                .map(schema -> schema.getName())
+                .collect(Collectors.toList());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/query/FromItem.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/FromItem.java 
b/core/src/main/java/org/apache/metamodel/query/FromItem.java
index 392c0bf..63eac69 100644
--- a/core/src/main/java/org/apache/metamodel/query/FromItem.java
+++ b/core/src/main/java/org/apache/metamodel/query/FromItem.java
@@ -88,16 +88,16 @@ public class FromItem extends BaseObject implements 
QueryItem, Cloneable {
     public FromItem(JoinType join, Relationship relationship) {
         _join = join;
         _leftSide = new FromItem(relationship.getPrimaryTable());
-        Column[] columns = relationship.getPrimaryColumns();
-        _leftOn = new SelectItem[columns.length];
-        for (int i = 0; i < columns.length; i++) {
-            _leftOn[i] = new SelectItem(columns[i]);
+        List<Column> columns = relationship.getPrimaryColumns();
+        _leftOn = new SelectItem[columns.size()];
+        for (int i = 0; i < columns.size(); i++) {
+            _leftOn[i] = new SelectItem(columns.get(i));
         }
         _rightSide = new FromItem(relationship.getForeignTable());
         columns = relationship.getForeignColumns();
-        _rightOn = new SelectItem[columns.length];
-        for (int i = 0; i < columns.length; i++) {
-            _rightOn[i] = new SelectItem(columns[i]);
+        _rightOn = new SelectItem[columns.size()];
+        for (int i = 0; i < columns.size(); i++) {
+            _rightOn[i] = new SelectItem(columns.get(i));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/query/Query.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/Query.java 
b/core/src/main/java/org/apache/metamodel/query/Query.java
index 7dc9278..e29b7dd 100644
--- a/core/src/main/java/org/apache/metamodel/query/Query.java
+++ b/core/src/main/java/org/apache/metamodel/query/Query.java
@@ -92,6 +92,10 @@ public final class Query extends BaseObject implements 
Cloneable, Serializable {
         return select(selectItem);
     }
 
+    public Query select(List<Column> columns){
+        return select(columns.toArray(new Column[columns.size()]));
+    }
+
     public Query select(Column... columns) {
         for (Column column : columns) {
             SelectItem selectItem = new SelectItem(column);
@@ -164,7 +168,7 @@ public final class Query extends BaseObject implements 
Cloneable, Serializable {
 
     public Query selectAll(final FromItem fromItem) {
         if (fromItem.getTable() != null) {
-            final Column[] columns = fromItem.getTable().getColumns();
+            final List<Column> columns = fromItem.getTable().getColumns();
             for (final Column column : columns) {
                 select(column, fromItem);
             }
@@ -242,6 +246,14 @@ public final class Query extends BaseObject implements 
Cloneable, Serializable {
         return this;
     }
 
+    public Query groupBy(List<Column> columns) {
+        for (Column column : columns) {
+            SelectItem selectItem = new SelectItem(column).setQuery(this);
+            _groupByClause.addItem(new GroupByItem(selectItem));
+        }
+        return this;
+    }
+
     public Query orderBy(OrderByItem... items) {
         _orderByClause.addItems(items);
         return this;

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilderImpl.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilderImpl.java
 
b/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilderImpl.java
index d73ae8f..904b657 100644
--- 
a/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilderImpl.java
+++ 
b/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilderImpl.java
@@ -198,7 +198,7 @@ final class GroupedQueryBuilderImpl extends BaseObject 
implements GroupedQueryBu
                 final Table table = fromItem.getTable();
                 if (table != null) {
                     logger.debug("Table available in FROM item: {}. Column 
names: {}", table, Arrays.toString(table
-                            .getColumnNames()));
+                            .getColumnNames().toArray()));
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/query/builder/InitFromBuilderImpl.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/query/builder/InitFromBuilderImpl.java
 
b/core/src/main/java/org/apache/metamodel/query/builder/InitFromBuilderImpl.java
index 2585bea..9248db6 100644
--- 
a/core/src/main/java/org/apache/metamodel/query/builder/InitFromBuilderImpl.java
+++ 
b/core/src/main/java/org/apache/metamodel/query/builder/InitFromBuilderImpl.java
@@ -65,7 +65,7 @@ public final class InitFromBuilderImpl extends BaseObject 
implements InitFromBui
         Table table = schema.getTableByName(tableName);
         if (table == null) {
             throw new IllegalArgumentException("Nu such table '" + tableName + 
"' found in schema: " + schema
-                    + ". Available tables are: " + 
Arrays.toString(schema.getTableNames()));
+                    + ". Available tables are: " + 
Arrays.toString(schema.getTableNames().toArray()));
         }
         return from(table);
     }

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedFromBuilder.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedFromBuilder.java
 
b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedFromBuilder.java
index f1a706c..8984dca 100644
--- 
a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedFromBuilder.java
+++ 
b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedFromBuilder.java
@@ -22,6 +22,8 @@ import org.apache.metamodel.query.FunctionType;
 import org.apache.metamodel.schema.Column;
 import org.apache.metamodel.schema.Table;
 
+import java.util.List;
+
 /**
  * Represents a builder where the FROM part is satisfied, ie. a SELECT clause 
is
  * now buildable.
@@ -47,7 +49,9 @@ public interface SatisfiedFromBuilder {
     public CountSelectBuilder<?> selectCount();
 
     public SatisfiedSelectBuilder<?> select(Column... columns);
-    
+
+    public SatisfiedSelectBuilder<?> select(List<Column> columns);
+
     public SatisfiedSelectBuilder<?> selectAll();
 
     public SatisfiedSelectBuilder<?> select(String selectExpression);

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedFromBuilderCallback.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedFromBuilderCallback.java
 
b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedFromBuilderCallback.java
index 74831e9..4fb54ef 100644
--- 
a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedFromBuilderCallback.java
+++ 
b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedFromBuilderCallback.java
@@ -150,6 +150,11 @@ abstract class SatisfiedFromBuilderCallback extends 
BaseObject implements Satisf
     }
 
     @Override
+    public SatisfiedSelectBuilder<?> select(List<Column> columns) {
+        return select(columns.toArray(new Column[columns.size()]));
+    }
+
+    @Override
     public SatisfiedSelectBuilder<?> select(String... columnNames) {
         if (columnNames == null) {
             throw new IllegalArgumentException("columnNames cannot be null");

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/schema/AbstractRelationship.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/schema/AbstractRelationship.java 
b/core/src/main/java/org/apache/metamodel/schema/AbstractRelationship.java
index 88dd54e..cafa1c1 100644
--- a/core/src/main/java/org/apache/metamodel/schema/AbstractRelationship.java
+++ b/core/src/main/java/org/apache/metamodel/schema/AbstractRelationship.java
@@ -27,16 +27,16 @@ public abstract class AbstractRelationship extends 
BaseObject implements
     
     private static final long serialVersionUID = 1L;
 
-       protected static Table checkSameTable(Column[] columns) {
-               if (columns == null || columns.length == 0) {
+       protected static Table checkSameTable(List<Column> columns) {
+               if (columns == null || columns.size() == 0) {
                        throw new IllegalArgumentException(
                                        "At least one key-column must exist on 
both "
                                                        + "primary and foreign 
side for "
                                                        + "a relation to 
exist.");
                }
                Table table = null;
-               for (int i = 0; i < columns.length; i++) {
-                       Column column = columns[i];
+               for (int i = 0; i < columns.size(); i++) {
+                       Column column = columns.get(i);
                        if (i == 0) {
                                table = column.getTable();
                        } else {
@@ -51,12 +51,12 @@ public abstract class AbstractRelationship extends 
BaseObject implements
 
        @Override
        public Table getForeignTable() {
-               return getForeignColumns()[0].getTable();
+               return getForeignColumns().get(0).getTable();
        }
 
        @Override
        public Table getPrimaryTable() {
-               return getPrimaryColumns()[0].getTable();
+               return getPrimaryColumns().get(0).getTable();
        }
 
        @Override
@@ -64,23 +64,23 @@ public abstract class AbstractRelationship extends 
BaseObject implements
                StringBuilder sb = new StringBuilder();
                sb.append("Relationship[");
                sb.append("primaryTable=" + getPrimaryTable().getName());
-               Column[] columns = getPrimaryColumns();
+               List<Column> columns = getPrimaryColumns();
                sb.append(",primaryColumns=[");
-               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("]");
                sb.append(",foreignTable=" + getForeignTable().getName());
                columns = getForeignColumns();
                sb.append(",foreignColumns=[");
-               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("]");
                sb.append("]");
@@ -105,11 +105,11 @@ public abstract class AbstractRelationship extends 
BaseObject implements
        @Override
        public boolean containsColumnPair(Column pkColumn, Column fkColumn) {
                if (pkColumn != null && fkColumn != null) {
-                       Column[] primaryColumns = getPrimaryColumns();
-                       Column[] foreignColumns = getForeignColumns();
-                       for (int i = 0; i < primaryColumns.length; i++) {
-                               if (pkColumn.equals(primaryColumns[i])
-                                               && 
fkColumn.equals(foreignColumns[i])) {
+                       List<Column> primaryColumns = getPrimaryColumns();
+                       List<Column> foreignColumns = getForeignColumns();
+                       for (int i = 0; i < primaryColumns.size(); i++) {
+                               if (pkColumn.equals(primaryColumns.get(i))
+                                               && 
fkColumn.equals(foreignColumns.get(i))) {
                                        return true;
                                }
                        }

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/schema/AbstractSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/AbstractSchema.java 
b/core/src/main/java/org/apache/metamodel/schema/AbstractSchema.java
index e44737a..df4a033 100644
--- a/core/src/main/java/org/apache/metamodel/schema/AbstractSchema.java
+++ b/core/src/main/java/org/apache/metamodel/schema/AbstractSchema.java
@@ -18,10 +18,8 @@
  */
 package org.apache.metamodel.schema;
 
-import java.util.ArrayList;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.util.CollectionUtils;
 import org.apache.metamodel.util.EqualsBuilder;
@@ -49,22 +47,15 @@ public abstract class AbstractSchema implements Schema {
     }
 
     @Override
-    public Relationship[] getRelationships() {
-        final Set<Relationship> result = new LinkedHashSet<Relationship>();
-        CollectionUtils.forEach(getTables(), table -> {
-            final Relationship[] relations = table.getRelationships();
-            for (int i = 0; i < relations.length; i++) {
-                final Relationship relation = relations[i];
-                result.add(relation);
-            }
-        });
-        return result.toArray(new Relationship[result.size()]);
+    public Collection<Relationship> getRelationships() {
+        return getTables().stream()
+                .flatMap(tab -> tab.getRelationships().stream())
+                .collect(Collectors.toCollection(LinkedHashSet::new));
     }
 
     @Override
     public Table getTable(int index) throws IndexOutOfBoundsException {
-        Table[] tables = getTables();
-        return tables[index];
+        return getTables().get(index);
     }
 
     @Override
@@ -74,24 +65,24 @@ public abstract class AbstractSchema implements Schema {
 
     @Override
     public final int getTableCount(TableType type) {
-        return getTables(type).length;
+        return getTables(type).size();
     }
 
     @Override
     public final int getRelationshipCount() {
-        return getRelationships().length;
+        return getRelationships().size();
     }
 
     @Override
     public final int getTableCount() {
-        return getTables().length;
+        return getTables().size();
     }
 
     @Override
-    public final Table[] getTables(final TableType type) {
-        return CollectionUtils.filter(getTables(), table -> {
-            return table.getType() == type;
-        }).toArray(new Table[0]);
+    public final List<Table> getTables(final TableType type) {
+        return  getTables().stream()
+                .filter(table -> table.getType().equals(type))
+                .collect(Collectors.toList());
     }
 
     @Override
@@ -131,9 +122,10 @@ public abstract class AbstractSchema implements Schema {
     }
 
     @Override
-    public final String[] getTableNames() {
-        Table[] tables = getTables();
-        return CollectionUtils.map(tables, new HasNameMapper()).toArray(new 
String[tables.length]);
+    public final List<String> getTableNames() {
+        return getTables().stream()
+                .map(table -> table.getName())
+                .collect(Collectors.toList());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/schema/AbstractTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/AbstractTable.java 
b/core/src/main/java/org/apache/metamodel/schema/AbstractTable.java
index 4f5ad7f..6e5b55f 100644
--- a/core/src/main/java/org/apache/metamodel/schema/AbstractTable.java
+++ b/core/src/main/java/org/apache/metamodel/schema/AbstractTable.java
@@ -18,16 +18,12 @@
  */
 package org.apache.metamodel.schema;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 import java.util.function.Predicate;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.MetaModelHelper;
 import org.apache.metamodel.util.CollectionUtils;
-import org.apache.metamodel.util.HasNameMapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -42,13 +38,12 @@ public abstract class AbstractTable implements Table {
 
     @Override
     public final int getColumnCount() {
-        return getColumns().length;
+        return getColumns().size();
     }
 
     @Override
     public Column getColumn(int index) throws IndexOutOfBoundsException {
-        Column[] columns = getColumns();
-        return columns[index];
+        return getColumns().get(index);
     }
 
     @Override
@@ -93,112 +88,102 @@ public abstract class AbstractTable implements Table {
 
     @Override
     public final int getRelationshipCount() {
-        return getRelationships().length;
+        return getRelationships().size();
     }
 
     @Override
-    public final Column[] getNumberColumns() {
-        return CollectionUtils.filter(getColumns(), new Predicate<Column>() {
-            @Override
-            public boolean test(Column col) {
-                ColumnType type = col.getType();
-                return type != null && type.isNumber();
-            }
-        }).toArray(new Column[0]);
+    public final List<Column> getNumberColumns() {
+        return getColumnsOfSuperType(SuperColumnType.NUMBER_TYPE);
     }
 
     @Override
-    public final Column[] getLiteralColumns() {
-        return CollectionUtils.filter(getColumns(), new Predicate<Column>() {
-            @Override
-            public boolean test(Column col) {
-                ColumnType type = col.getType();
-                return type != null && type.isLiteral();
-            }
-        }).toArray(new Column[0]);
+    public final List<Column> getLiteralColumns() {
+        return getColumnsOfSuperType(SuperColumnType.LITERAL_TYPE);
     }
 
     @Override
-    public final Column[] getTimeBasedColumns() {
-        return CollectionUtils.filter(getColumns(), col -> {
-            final ColumnType type = col.getType();
-            return type != null && type.isTimeBased();
-        }).toArray(new Column[0]);
+    public final List<Column> getTimeBasedColumns() {
+        return getColumnsOfSuperType(SuperColumnType.TIME_TYPE);
     }
 
     @Override
-    public final Column[] getBooleanColumns() {
-        return CollectionUtils.filter(getColumns(), col -> {
-            final ColumnType type = col.getType();
-            return type != null && type.isBoolean();
-        }).toArray(new Column[0]);
+    public final List<Column> getBooleanColumns() {
+        return getColumnsOfSuperType(SuperColumnType.BOOLEAN_TYPE);
     }
 
     @Override
-    public final Column[] getIndexedColumns() {
-        return CollectionUtils.filter(getColumns(), 
Column::isIndexed).toArray(new Column[0]);
+    public final List<Column> getIndexedColumns() {
+        return getColumns().stream()
+                .filter(Column::isIndexed)
+                .collect(Collectors.toList());
     }
 
     @Override
-    public final Relationship[] getForeignKeyRelationships() {
+    public final Collection<Relationship> getForeignKeyRelationships() {
         return CollectionUtils.filter(getRelationships(), rel -> {
             return AbstractTable.this.equals(rel.getForeignTable());
-        }).toArray(new Relationship[0]);
+        });
     }
 
     @Override
-    public final Relationship[] getPrimaryKeyRelationships() {
+    public final List<Relationship> getPrimaryKeyRelationships() {
         return CollectionUtils.filter(getRelationships(), rel -> {
             return AbstractTable.this.equals(rel.getPrimaryTable());
-        }).toArray(new Relationship[0]);
+        });
     }
 
     @Override
-    public final Column[] getForeignKeys() {
-        final Set<Column> columns = new HashSet<Column>();
-        final Relationship[] relationships = getForeignKeyRelationships();
+    public final List<Column> getForeignKeys() {
+        final Set<Column> columns = new LinkedHashSet<>();
+        final Collection<Relationship> relationships = 
getForeignKeyRelationships();
         CollectionUtils.forEach(relationships, rel -> {
-            Column[] foreignColumns = rel.getForeignColumns();
+            List<Column> foreignColumns = rel.getForeignColumns();
             for (Column column : foreignColumns) {
                 columns.add(column);
             }
         });
-        return columns.toArray(new Column[columns.size()]);
+        return new ArrayList<>(columns);
     }
 
     @Override
-    public final Column[] getPrimaryKeys() {
+    public final List<Column> getPrimaryKeys() {
         final List<Column> primaryKeyColumns = new ArrayList<Column>();
-        final Column[] columnsInTable = getColumns();
+        final List<Column> columnsInTable = getColumns();
         for (Column column : columnsInTable) {
             if (column.isPrimaryKey()) {
                 primaryKeyColumns.add(column);
             }
         }
-        return primaryKeyColumns.toArray(new Column[primaryKeyColumns.size()]);
+        return primaryKeyColumns;
     }
 
     @Override
-    public final String[] getColumnNames() {
-        Column[] columns = getColumns();
-        return CollectionUtils.map(columns, new HasNameMapper()).toArray(new 
String[columns.length]);
+    public final List<String> getColumnNames() {
+        return getColumns().stream()
+                .map(col -> col.getName())
+                .collect(Collectors.toList());
     }
 
     @Override
-    public final Column[] getColumnsOfType(ColumnType columnType) {
-        Column[] columns = getColumns();
-        return MetaModelHelper.getColumnsByType(columns, columnType);
+    public final List<Column> getColumnsOfType(ColumnType columnType) {
+        return getColumns().stream()
+                .filter(col -> col.getType()!=null)
+                .filter((col -> col.getType().equals(columnType)))
+                .collect(Collectors.toList());
     }
 
+
+
     @Override
-    public final Column[] getColumnsOfSuperType(final SuperColumnType 
superColumnType) {
-        Column[] columns = getColumns();
-        return MetaModelHelper.getColumnsBySuperType(columns, superColumnType);
+    public final List<Column> getColumnsOfSuperType(final SuperColumnType 
superColumnType) {
+        return getColumns().stream() .filter(col -> col.getType()!=null)
+                .filter((col -> 
col.getType().getSuperType().equals(superColumnType)))
+                .collect(Collectors.toList());
     }
 
     @Override
-    public final Relationship[] getRelationships(final Table otherTable) {
-        Relationship[] relationships = getRelationships();
+    public final Collection<Relationship> getRelationships(final Table 
otherTable) {
+        Collection<Relationship> relationships = getRelationships();
 
         return CollectionUtils.filter(relationships, relation -> {
             if (relation.getForeignTable() == otherTable && 
relation.getPrimaryTable() == AbstractTable.this) {
@@ -207,7 +192,7 @@ public abstract class AbstractTable implements Table {
                 return true;
             }
             return false;
-        }).toArray(new Relationship[0]);
+        });
     }
 
     @Override
@@ -270,12 +255,12 @@ public abstract class AbstractTable implements Table {
             }
 
             try {
-                final String[] columnNames1 = getColumnNames();
-                final String[] columnNames2 = other.getColumnNames();
+                final List<String> columnNames1 = getColumnNames();
+                final List<String> columnNames2 = other.getColumnNames();
 
-                if (columnNames1 != null && columnNames1.length != 0) {
-                    if (columnNames2 != null && columnNames2.length != 0) {
-                        if (!Arrays.equals(columnNames1, columnNames2)) {
+                if (columnNames1 != null && columnNames1.size() != 0) {
+                    if (columnNames2 != null && columnNames2.size() != 0) {
+                        if (!columnNames1.equals(columnNames2)) {
                             return false;
                         }
                     }

http://git-wip-us.apache.org/repos/asf/metamodel/blob/ab5c9482/core/src/main/java/org/apache/metamodel/schema/CompositeSchema.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/schema/CompositeSchema.java 
b/core/src/main/java/org/apache/metamodel/schema/CompositeSchema.java
index 68cfecf..4e5a569 100644
--- a/core/src/main/java/org/apache/metamodel/schema/CompositeSchema.java
+++ b/core/src/main/java/org/apache/metamodel/schema/CompositeSchema.java
@@ -20,7 +20,9 @@ package org.apache.metamodel.schema;
 
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 import org.apache.metamodel.DataContext;
 import org.apache.metamodel.util.CollectionUtils;
@@ -60,21 +62,17 @@ public class CompositeSchema extends AbstractSchema {
     }
 
     @Override
-    public Relationship[] getRelationships() {
-        Relationship[] result = new Relationship[0];
-        for (Schema delegate : delegates) {
-            result = CollectionUtils.array(result, 
delegate.getRelationships());
-        }
-        return result;
+    public List<Relationship> getRelationships() {
+        return delegates.stream()
+                .flatMap(delegate -> delegate.getRelationships().stream())
+                .collect(Collectors.toList());
     }
 
     @Override
-    public Table[] getTables() {
-        Table[] result = new Table[0];
-        for (Schema delegate : delegates) {
-            result = CollectionUtils.array(result, delegate.getTables());
-        }
-        return result;
+    public List<Table> getTables() {
+        return delegates.stream()
+                .flatMap(delegate -> delegate.getTables().stream())
+                .collect(Collectors.toList());
     }
 
     @Override

Reply via email to