You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metamodel.apache.org by ka...@apache.org on 2013/07/19 11:33:31 UTC

[48/61] [partial] Hard rename of all 'org/eobjects' folders to 'org/apache'.

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/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
new file mode 100644
index 0000000..d833b1e
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/create/AbstractTableCreationBuilder.java
@@ -0,0 +1,135 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.create;
+
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.schema.MutableTable;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.schema.TableType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract {@link TableCreationBuilder} implementation, provided as convenience
+ * for {@link TableCreatable} implementations. Handles all the building
+ * operations, but not the commit operation.
+ * 
+ * @author Kasper Sørensen
+ */
+public abstract class AbstractTableCreationBuilder<U extends UpdateCallback> implements TableCreationBuilder {
+
+    private static final Logger logger = LoggerFactory.getLogger(AbstractTableCreationBuilder.class);
+
+    private final U _updateCallback;
+    private final MutableTable _table;
+    private final Schema _schema;
+
+    public AbstractTableCreationBuilder(U updateCallback, Schema schema, String name) {
+        if (schema != null && schema.getTableByName(name) != null) {
+            throw new IllegalArgumentException("A table with the name '" + name + "' already exists in schema: "
+                    + schema);
+        }
+        _updateCallback = updateCallback;
+        _schema = schema;
+        _table = new MutableTable(name, TableType.TABLE, schema);
+    }
+
+    protected U getUpdateCallback() {
+        return _updateCallback;
+    }
+
+    protected Schema getSchema() {
+        return _schema;
+    }
+
+    protected MutableTable getTable() {
+        return _table;
+    }
+
+    @Override
+    public Table toTable() {
+        return _table;
+    }
+
+    @Override
+    public TableCreationBuilder like(Table table) {
+        logger.debug("like({})", table);
+        Column[] columns = table.getColumns();
+        for (Column column : columns) {
+            withColumn(column.getName()).like(column);
+        }
+        return this;
+    }
+
+    @Override
+    public ColumnCreationBuilder withColumn(String name) {
+        logger.debug("withColumn({})", name);
+        MutableColumn col = (MutableColumn) _table.getColumnByName(name);
+        if (col == null) {
+            col = new MutableColumn(name).setTable(_table).setColumnNumber(_table.getColumnCount());
+            _table.addColumn(col);
+        }
+        return new ColumnCreationBuilderImpl(this, col);
+    }
+
+    @Override
+    public String toString() {
+        return toSql();
+    }
+
+    @Override
+    public String toSql() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("CREATE TABLE ");
+        sb.append(_table.getQualifiedLabel());
+        sb.append(" (");
+        Column[] columns = _table.getColumns();
+        for (int i = 0; i < columns.length; i++) {
+            if (i != 0) {
+                sb.append(',');
+            }
+            Column column = columns[i];
+            sb.append(column.getName());
+            ColumnType type = column.getType();
+            if (type != null) {
+                sb.append(' ');
+                sb.append(type.toString());
+                Integer columnSize = column.getColumnSize();
+                if (columnSize != null) {
+                    sb.append('(');
+                    sb.append(columnSize);
+                    sb.append(')');
+                }
+            }
+            if (column.isNullable() != null
+                    && !column.isNullable().booleanValue()) {
+                sb.append(" NOT NULL");
+            }
+            if (column.isPrimaryKey()) {
+                sb.append(" PRIMARY KEY");
+            }
+        }
+        sb.append(")");
+        return sb.toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/create/ColumnBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/create/ColumnBuilder.java b/core/src/main/java/org/apache/metamodel/create/ColumnBuilder.java
new file mode 100644
index 0000000..1d6a7c2
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/create/ColumnBuilder.java
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.create;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+
+/**
+ * Abstract interface for components that build columns.
+ * 
+ * Defines methods for refining particular properties of the column build.
+ * 
+ * @param <T>
+ *            the return type of the builder methods
+ */
+public interface ColumnBuilder<T extends ColumnBuilder<?>> {
+
+    /**
+     * Builds several properties of a column, based on another {@link Column}
+     * object as a prototype.
+     * 
+     * @param column
+     *            a prototype for the column being built.
+     * @return a builder object for further column creation.
+     */
+    public T like(Column column);
+
+    /**
+     * Defines the {@link ColumnType} of the created column.
+     * 
+     * @param type
+     *            the column type of the created column.
+     * @return a builder object for further column creation.
+     */
+    public T ofType(ColumnType type);
+
+    /**
+     * Defines the native type of the created column (useful especially for SQL
+     * based {@link DataContext}s).
+     * 
+     * @param nativeType
+     *            the native type of the created column
+     * @return a builder object for further column creation.
+     */
+    public T ofNativeType(String nativeType);
+
+    /**
+     * Defines the size of the created column.
+     * 
+     * @param size
+     *            the size of the created column.
+     * @return a builder object for further column creation.
+     */
+    public T ofSize(int size);
+
+    /**
+     * Defines if the created column should be nullable or not.
+     * 
+     * @param nullable
+     *            if the created column should be nullable or not.
+     * @return a builder object for further column creation.
+     */
+    public T nullable(boolean nullable);
+
+    /**
+     * Defines that the created column should be a primary key
+     * 
+     * @return a builder object for further column creation.
+     */
+    public T asPrimaryKey();
+}

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/create/ColumnCreationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/create/ColumnCreationBuilder.java b/core/src/main/java/org/apache/metamodel/create/ColumnCreationBuilder.java
new file mode 100644
index 0000000..4792e85
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/create/ColumnCreationBuilder.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.create;
+
+import org.eobjects.metamodel.schema.Column;
+
+/**
+ * Builder object for creating {@link Column}s. This class also extendsthe
+ * {@link TableCreationBuilder} (allowing to step immediately out of the column
+ * building and back to the table building immediately).
+ * 
+ * @author Kasper Sørensen
+ */
+public interface ColumnCreationBuilder extends ColumnBuilder<ColumnCreationBuilder>, TableCreationBuilder {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/create/ColumnCreationBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/create/ColumnCreationBuilderImpl.java b/core/src/main/java/org/apache/metamodel/create/ColumnCreationBuilderImpl.java
new file mode 100644
index 0000000..1aba1d4
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/create/ColumnCreationBuilderImpl.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.create;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * Implementation of the {@link ColumnCreationBuilder}.
+ * 
+ * @author Kasper Sørensen
+ */
+final class ColumnCreationBuilderImpl extends AbstractColumnBuilder<ColumnCreationBuilder> implements ColumnCreationBuilder {
+
+    private final TableCreationBuilder _createTableBuilder;
+
+    public ColumnCreationBuilderImpl(TableCreationBuilder createTableBuilder, MutableColumn column) {
+        super(column);
+        _createTableBuilder = createTableBuilder;
+    }
+
+    @Override
+    public String toSql() {
+        return _createTableBuilder.toSql();
+    }
+
+    @Override
+    public TableCreationBuilder like(Table table) {
+        return _createTableBuilder.like(table);
+    }
+
+    @Override
+    public Table execute() throws MetaModelException {
+        return _createTableBuilder.execute();
+    }
+
+    @Override
+    public ColumnCreationBuilder withColumn(String name) {
+        return _createTableBuilder.withColumn(name);
+    }
+
+    @Override
+    public Table toTable() {
+        return _createTableBuilder.toTable();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/create/CreateTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/create/CreateTable.java b/core/src/main/java/org/apache/metamodel/create/CreateTable.java
new file mode 100644
index 0000000..c40c823
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/create/CreateTable.java
@@ -0,0 +1,67 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.create;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.UpdateableDataContext;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.schema.MutableSchema;
+import org.eobjects.metamodel.schema.MutableTable;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.TableType;
+
+/**
+ * Represents a single CREATE TABLE operation to be applied to a
+ * {@link UpdateableDataContext}. Instead of providing a custom implementation
+ * of the {@link UpdateScript} interface, one can use this pre-built create
+ * table implementation. Some {@link DataContext}s may even optimize
+ * specifically based on the knowledge that there will only be a single table
+ * created.
+ */
+public final class CreateTable implements UpdateScript {
+
+    private final MutableTable _table;
+
+    public CreateTable(Schema schema, String tableName) {
+        _table = new MutableTable(tableName, TableType.TABLE, schema);
+    }
+
+    public CreateTable(String schemaName, String tableName) {
+        _table = new MutableTable(tableName, TableType.TABLE, new MutableSchema(schemaName));
+    }
+
+    /**
+     * Adds a column to the current builder
+     * 
+     * @param name
+     * @return
+     */
+    public ColumnBuilder<CreateTableColumnBuilder> withColumn(String name) {
+        MutableColumn column = new MutableColumn(name);
+        _table.addColumn(column);
+        return new CreateTableColumnBuilder(this, column);
+    }
+
+    @Override
+    public void run(UpdateCallback callback) {
+        callback.createTable(_table.getSchema().getName(), _table.getName()).like(_table).execute();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/create/CreateTableColumnBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/create/CreateTableColumnBuilder.java b/core/src/main/java/org/apache/metamodel/create/CreateTableColumnBuilder.java
new file mode 100644
index 0000000..240abb2
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/create/CreateTableColumnBuilder.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.create;
+
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.schema.MutableColumn;
+
+/**
+ * Column builder for {@link CreateTable}.
+ */
+public final class CreateTableColumnBuilder extends AbstractColumnBuilder<CreateTableColumnBuilder> implements ColumnBuilder<CreateTableColumnBuilder>, UpdateScript {
+
+    private final CreateTable _createTable;
+
+    public CreateTableColumnBuilder(CreateTable createTable, MutableColumn column) {
+        super(column);
+        _createTable = createTable;
+    }
+
+    @Override
+    public void run(UpdateCallback callback) {
+        _createTable.run(callback);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/create/TableCreatable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/create/TableCreatable.java b/core/src/main/java/org/apache/metamodel/create/TableCreatable.java
new file mode 100644
index 0000000..2b42133
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/create/TableCreatable.java
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.create;
+
+import org.eobjects.metamodel.schema.Schema;
+
+/**
+ * Interface for objects that support creating new tables.
+ * 
+ * @author Kasper Sørensen
+ */
+public interface TableCreatable {
+
+    /**
+     * Determines whether table creation is supported
+     * 
+     * @return true if table creation is supported
+     */
+    public boolean isCreateTableSupported();
+
+    /**
+     * Initiates the building of a table creation operation.
+     * 
+     * @param schema
+     *            the schema to create the table in
+     * @param name
+     *            the name of the new table
+     * @return a builder object on which the details of the table can be
+     *         specified and committed.
+     * @throws IllegalArgumentException
+     *             if the table argument is null or invalid.
+     * @throws IllegalStateException
+     *             if the connection to the DataContext is read-only or another
+     *             access restriction is preventing the operation.
+     */
+    public TableCreationBuilder createTable(Schema schema, String name) throws IllegalArgumentException,
+            IllegalStateException;
+
+    /**
+     * Initiates the building of a table creation operation.
+     * 
+     * @param schemaName
+     *            the name of the schema to create the table in
+     * @param tableName
+     *            the name of the new table
+     * @return a builder object on which the details of the table can be
+     *         specified and committed.
+     * @throws IllegalArgumentException
+     *             if the table argument is null or invalid.
+     * @throws IllegalStateException
+     *             if the connection to the DataContext is read-only or another
+     *             access restriction is preventing the operation.
+     */
+    public TableCreationBuilder createTable(String schemaName, String tableName) throws IllegalArgumentException,
+            IllegalStateException;
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/create/TableCreationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/create/TableCreationBuilder.java b/core/src/main/java/org/apache/metamodel/create/TableCreationBuilder.java
new file mode 100644
index 0000000..c3dfefd
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/create/TableCreationBuilder.java
@@ -0,0 +1,77 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.create;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * Builder object for {@link Table} creation.
+ * 
+ * @author Kasper Sørensen
+ */
+public interface TableCreationBuilder {
+
+    /**
+     * Builds this table's columns based on another {@link Table} which will be
+     * used as a prototype. Using this method simplifies the creation of a table
+     * that is similar to an existing table.
+     * 
+     * @param table
+     *            the {@link Table} to use as a prototype
+     * @return a builder object for further table creation
+     */
+    public TableCreationBuilder like(Table table);
+
+    /**
+     * Adds a column to the current builder
+     * 
+     * @param name
+     * @return
+     */
+    public ColumnCreationBuilder withColumn(String name);
+
+    /**
+     * Returns this builder instance as a table. This allows for inspecting the
+     * table that is being built, before it is actually created.
+     * 
+     * @return a temporary representation of the table being built.
+     */
+    public Table toTable();
+
+    /**
+     * Gets a SQL representation of this create table operation. Note that the
+     * generated SQL is dialect agnostic, so it is not accurately the same as
+     * what will be passed to a potential backing database.
+     * 
+     * @return a SQL representation of this create table operation.
+     */
+    public String toSql();
+
+    /**
+     * Commits the built table and requests that the table structure should be
+     * written to the {@link DataContext}.
+     * 
+     * @return the {@link Table} that was build
+     * @throws MetaModelException
+     *             if the {@link DataContext} was not able to create the table
+     */
+    public Table execute() throws MetaModelException;
+}

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/create/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/create/package-info.java b/core/src/main/java/org/apache/metamodel/create/package-info.java
new file mode 100644
index 0000000..44c5ed9
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/create/package-info.java
@@ -0,0 +1,23 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * API for creating tables
+ */
+package org.eobjects.metamodel.create;
+

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/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
new file mode 100644
index 0000000..98b9416
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/AbstractDataSet.java
@@ -0,0 +1,171 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.data;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.swing.table.TableModel;
+
+import org.eobjects.metamodel.MetaModelHelper;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.util.BaseObject;
+
+/**
+ * Abstract DataSet implementation. Provides convenient implementations of
+ * trivial method and reusable parts of non-trivial methods of a DataSet.
+ * 
+ * @author Kasper Sørensen
+ */
+public abstract class AbstractDataSet extends BaseObject implements DataSet {
+
+    private final DataSetHeader _header;
+
+    /**
+     * @deprecated use one of the other constructors, to provide header
+     *             information.
+     */
+    @Deprecated
+    public AbstractDataSet() {
+        _header = null;
+    }
+
+    public AbstractDataSet(SelectItem[] selectItems) {
+        this(Arrays.asList(selectItems));
+    }
+
+    public AbstractDataSet(List<SelectItem> selectItems) {
+        this(new CachingDataSetHeader(selectItems));
+    }
+
+    /**
+     * Constructor appropriate for dataset implementations that wrap other
+     * datasets, such as the {@link MaxRowsDataSet}, {@link FilteredDataSet} and
+     * more.
+     * 
+     * @param dataSet
+     */
+    public AbstractDataSet(DataSet dataSet) {
+        if (dataSet instanceof AbstractDataSet) {
+            _header = ((AbstractDataSet) dataSet).getHeader();
+        } else {
+            _header = new CachingDataSetHeader(Arrays.asList(dataSet.getSelectItems()));
+        }
+    }
+
+    public AbstractDataSet(DataSetHeader header) {
+        _header = header;
+    }
+
+    public AbstractDataSet(Column[] columns) {
+        this(MetaModelHelper.createSelectItems(columns));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public SelectItem[] getSelectItems() {
+        return getHeader().getSelectItems();
+    }
+
+    protected DataSetHeader getHeader() {
+        return _header;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public final int indexOf(SelectItem item) {
+        return getHeader().indexOf(item);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void close() {
+        // do nothing
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public final TableModel toTableModel() {
+        TableModel tableModel = new DataSetTableModel(this);
+        return tableModel;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public final List<Object[]> toObjectArrays() {
+        try {
+            List<Object[]> objects = new ArrayList<Object[]>();
+            while (next()) {
+                Row row = getRow();
+                objects.add(row.getValues());
+            }
+            return objects;
+        } finally {
+            close();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String toString() {
+        return "DataSet[selectItems=" + Arrays.toString(getSelectItems()) + "]";
+    }
+
+    @Override
+    protected void decorateIdentity(List<Object> identifiers) {
+        identifiers.add(getClass());
+        identifiers.add(getSelectItems());
+    }
+
+    @Override
+    public List<Row> toRows() {
+        try {
+            List<Row> result = new ArrayList<Row>();
+            while (next()) {
+                result.add(getRow());
+            }
+            return result;
+        } finally {
+            close();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Iterator<Row> iterator() {
+        return new DataSetIterator(this);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/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
new file mode 100644
index 0000000..74340fe
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/AbstractRow.java
@@ -0,0 +1,176 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.data;
+
+import java.util.Arrays;
+
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+
+/**
+ * An abstract row that decorates another row. Useful for virtual data that may
+ * e.g. be converting physical data etc.
+ */
+public abstract class AbstractRow implements Cloneable, Row {
+
+    private static final long serialVersionUID = 1L;
+
+    protected abstract DataSetHeader getHeader();
+
+    @Override
+    public final int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + Arrays.hashCode(getValues());
+        return result;
+    }
+
+    @Override
+    public final boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        Row other = (Row) obj;
+        if (!Arrays.equals(getValues(), other.getValues()))
+            return false;
+        return true;
+    }
+
+    @Override
+    public final String toString() {
+        return "Row[values=" + Arrays.toString(getValues()) + "]";
+    }
+
+    @Override
+    public final Object getValue(SelectItem item) {
+        int index = indexOf(item);
+        if (index == -1) {
+            return null;
+        }
+        return getValue(index);
+    }
+
+    @Override
+    public final Style getStyle(SelectItem item) {
+        int index = indexOf(item);
+        if (index == -1) {
+            return Style.NO_STYLE;
+        }
+        return getStyle(index);
+    }
+
+    @Override
+    public final Style getStyle(Column column) {
+        int index = indexOf(column);
+        if (index == -1) {
+            return Style.NO_STYLE;
+        }
+        return getStyle(index);
+    }
+
+    @Override
+    public Object[] getValues() {
+        final Object[] values = new Object[size()];
+        for (int i = 0; i < values.length; i++) {
+            values[i] = getValue(i);
+        }
+        return values;
+    }
+
+    @Override
+    public final Object getValue(Column column) {
+        int index = indexOf(column);
+        if (index == -1) {
+            return null;
+        }
+        return getValue(index);
+    }
+
+    @Override
+    public final int indexOf(SelectItem item) {
+        if (item == null) {
+            return -1;
+        }
+        return getHeader().indexOf(item);
+    }
+
+    @Override
+    public final int indexOf(Column column) {
+        if (column == null) {
+            return -1;
+        }
+        return getHeader().indexOf(column);
+    }
+
+    @Override
+    public Row getSubSelection(final SelectItem[] selectItems) {
+        final DataSetHeader header = new SimpleDataSetHeader(selectItems);
+        return getSubSelection(header);
+    }
+
+    @Override
+    public final SelectItem[] getSelectItems() {
+        return getHeader().getSelectItems();
+    }
+
+    @Override
+    public final int size() {
+        return getHeader().size();
+    }
+
+    @Override
+    public Style[] getStyles() {
+        final Style[] styles = new Style[size()];
+        for (int i = 0; i < styles.length; i++) {
+            styles[i] = getStyle(i);
+        }
+        return styles;
+    }
+
+    @Override
+    protected Row clone() {
+        return new DefaultRow(getHeader(), getValues(), getStyles());
+    }
+
+    @Override
+    public final Row getSubSelection(DataSetHeader header) {
+        final int size = header.size();
+        final Object[] values = new Object[size];
+        final Style[] styles = new Style[size];
+        for (int i = 0; i < size; i++) {
+            final SelectItem selectItem = header.getSelectItem(i);
+
+            if (selectItem.getSubQuerySelectItem() != null) {
+                values[i] = getValue(selectItem.getSubQuerySelectItem());
+                styles[i] = getStyle(selectItem.getSubQuerySelectItem());
+                if (values[i] == null) {
+                    values[i] = getValue(selectItem);
+                    styles[i] = getStyle(selectItem);
+                }
+            } else {
+                values[i] = getValue(selectItem);
+                styles[i] = getStyle(selectItem);
+            }
+        }
+        return new DefaultRow(header, values, styles);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/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
new file mode 100644
index 0000000..32f6d33
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/AbstractRowBuilder.java
@@ -0,0 +1,146 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.data;
+
+import java.util.Arrays;
+
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * Abstract {@link RowBuilder} implementation.
+ */
+public abstract class AbstractRowBuilder<RB extends RowBuilder<?>> implements RowBuilder<RB> {
+
+    private final Column[] _columns;
+    private final Object[] _values;
+    private final Style[] _styles;
+    private final boolean[] _explicitNulls;
+
+    public AbstractRowBuilder(Table table) {
+        this(table.getColumns());
+    }
+
+    public AbstractRowBuilder(Column[] columns) {
+        _columns = columns;
+        _explicitNulls = new boolean[_columns.length];
+        _values = new Object[_columns.length];
+        _styles = new Style[_columns.length];
+    }
+
+    /**
+     * Gets a boolean array indicating if any of the values have been explicitly
+     * set to null (as opposed to just not set)
+     * 
+     * @return
+     */
+    protected boolean[] getExplicitNulls() {
+        return _explicitNulls;
+    }
+
+    protected Object[] getValues() {
+        return _values;
+    }
+
+    protected Column[] getColumns() {
+        return _columns;
+    }
+
+    protected Style[] getStyles() {
+        return _styles;
+    }
+
+    @Override
+    public final Row toRow() {
+        return new DefaultRow(new SimpleDataSetHeader(_columns), _values);
+    }
+
+    @Override
+    public final RB value(Column column, Object value) {
+        return value(column, value, null);
+    }
+
+    @Override
+    public RB value(Column column, Object value, Style style) {
+        if (column == null) {
+            throw new IllegalArgumentException("Column cannot be null");
+        }
+        boolean written = false;
+        for (int i = 0; i < _columns.length; i++) {
+            if (_columns[i].equals(column)) {
+                value(i, value, style);
+                written = true;
+                break;
+            }
+        }
+        if (!written) {
+            throw new IllegalArgumentException("No such column in table: " + column);
+        }
+
+        @SuppressWarnings("unchecked")
+        RB result = (RB) this;
+        return result;
+    }
+
+    @Override
+    public RB value(int columnIndex, Object value) {
+        return value(columnIndex, value, null);
+    }
+
+    @Override
+    public final RB value(int columnIndex, Object value, Style style) {
+        _values[columnIndex] = value;
+        _styles[columnIndex] = style;
+        _explicitNulls[columnIndex] = (value == null);
+
+        @SuppressWarnings("unchecked")
+        RB result = (RB) this;
+        return result;
+    }
+
+    @Override
+    public RB value(String columnName, Object value) {
+        return value(columnName, value, null);
+    }
+
+    @Override
+    public final RB value(String columnName, Object value, Style style) {
+        if (columnName == null) {
+            throw new IllegalArgumentException("Column name cannot be null");
+        }
+        for (int i = 0; i < _columns.length; i++) {
+            Column column = _columns[i];
+            if (column.getName().equalsIgnoreCase(columnName)) {
+                return value(i, value, style);
+            }
+        }
+        throw new IllegalArgumentException("No such column in table: " + columnName + ", available columns are: "
+                + Arrays.toString(_columns));
+    }
+
+    @Override
+    public boolean isSet(Column column) {
+        for (int i = 0; i < _columns.length; i++) {
+            if (_columns[i].equals(column)) {
+                return _values[i] != null || _explicitNulls[i];
+            }
+        }
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/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
new file mode 100644
index 0000000..25bad2b
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/CachingDataSetHeader.java
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.data;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+
+/**
+ * Most common implementation of {@link DataSetHeader}. This implementation is
+ * 'caching' in the sense that index values of selectitems are cached in a map
+ * to provide quick access when looking up by {@link SelectItem} or
+ * {@link Column}.
+ */
+public final class CachingDataSetHeader extends SimpleDataSetHeader implements DataSetHeader {
+
+    private static final long serialVersionUID = 1L;
+
+    // map of select item identity codes and indexes in the dataset
+    private transient Map<Integer, Integer> _selectItemIndexCache;
+
+    // map of column identity codes and indexes in the dataset
+    private transient Map<Integer, Integer> _columnIndexCache;
+
+    public CachingDataSetHeader(List<SelectItem> items) {
+        super(items);
+    }
+
+    public CachingDataSetHeader(SelectItem[] items) {
+        this(Arrays.asList(items));
+    }
+
+    @Override
+    public int indexOf(Column column) {
+        if (column == null) {
+            return -1;
+        }
+
+        if (_columnIndexCache == null) {
+            _columnIndexCache = new ConcurrentHashMap<Integer, Integer>(super.size());
+        }
+
+        final int identityCode = System.identityHashCode(column);
+        Integer index = _columnIndexCache.get(identityCode);
+        if (index == null) {
+            index = super.indexOf(column);
+
+            if (index != -1) {
+                _columnIndexCache.put(identityCode, index);
+            }
+        }
+        return index;
+    }
+
+    @Override
+    public final int indexOf(SelectItem item) {
+        if (item == null) {
+            return -1;
+        }
+
+        if (_selectItemIndexCache == null) {
+            _selectItemIndexCache = new ConcurrentHashMap<Integer, Integer>(super.size());
+        }
+
+        final int identityCode = System.identityHashCode(item);
+        Integer index = _selectItemIndexCache.get(identityCode);
+        if (index == null) {
+            index = super.indexOf(item);
+
+            if (index != -1) {
+                _selectItemIndexCache.put(identityCode, index);
+            }
+        }
+        return index;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/data/ColorImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/ColorImpl.java b/core/src/main/java/org/apache/metamodel/data/ColorImpl.java
new file mode 100644
index 0000000..d35b5ff
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/ColorImpl.java
@@ -0,0 +1,77 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.data;
+
+import java.util.List;
+
+import org.eobjects.metamodel.data.Style.Color;
+import org.eobjects.metamodel.util.BaseObject;
+
+final class ColorImpl extends BaseObject implements Color {
+	
+	private static final long serialVersionUID = 1L;
+
+	private final short _red;
+	private final short _green;
+	private final short _blue;
+
+	public ColorImpl(short red, short green, short blue) {
+		checkRange(red);
+		checkRange(green);
+		checkRange(blue);
+		_red = red;
+		_green = green;
+		_blue = blue;
+	}
+
+	private void checkRange(short rgbComponent) throws IllegalArgumentException {
+		if (rgbComponent < 0 || rgbComponent > 255) {
+			throw new IllegalArgumentException(
+					"All RGB components must be between 0 and 255. Found: "
+							+ rgbComponent);
+		}
+	}
+
+	@Override
+	public short getRed() {
+		return _red;
+	}
+
+	@Override
+	public short getGreen() {
+		return _green;
+	}
+
+	@Override
+	public short getBlue() {
+		return _blue;
+	}
+
+	@Override
+	protected void decorateIdentity(List<Object> identifiers) {
+		identifiers.add(_red);
+		identifiers.add(_green);
+		identifiers.add(_blue);
+	}
+
+	@Override
+	public String toString() {
+		return "Color[" + _red + "," + _green + "," + _blue + "]";
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/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
new file mode 100644
index 0000000..dc471b8
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/DataSet.java
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.data;
+
+import java.io.Closeable;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.swing.table.TableModel;
+
+import org.eobjects.metamodel.query.SelectItem;
+
+/**
+ * Represents a tabular DataSet where values are bound to columns and rows. A
+ * DataSet works similarly to a slightly modularized ResultSet when you traverse
+ * it - use the next() method to loop through the rows of the DataSet and use
+ * the getRow() method to get the current row.
+ * 
+ * @author Kasper Sørensen
+ */
+public interface DataSet extends Closeable, Iterable<Row> {
+
+    /**
+     * @return the SelectItems that represent the columns of this DataSet
+     */
+    public SelectItem[] getSelectItems();
+
+    /**
+     * Finds the index of a given SelectItem
+     * 
+     * @param item
+     * @return the index (0-based) of the SelectItem or -1 if the SelectItem
+     *         doesn't exist in this DataSet.
+     */
+    public int indexOf(SelectItem item);
+
+    /**
+     * Moves forward to the next row.
+     * 
+     * @return true if there is a next row or false if not.
+     */
+    public boolean next();
+
+    /**
+     * @return the current row.
+     */
+    public Row getRow();
+
+    /**
+     * Closes the DataSet and any resources it may be holding.
+     */
+    @Override
+    public void close();
+
+    /**
+     * Converts the DataSet into a TableModel (will load all values into memory).
+     * 
+     * @deprecated instantiate a new {@link DataSetTableModel} instead.
+     */
+    @Deprecated
+    public TableModel toTableModel();
+
+    /**
+     * Converts the DataSet into a list of object arrays (will load all values
+     * into memory)
+     */
+    public List<Object[]> toObjectArrays();
+
+    /**
+     * Converts the DataSet into a list of rows (will load all rows into memory)
+     */
+    public List<Row> toRows();
+
+    /**
+     * Converts the DataSet into an Iterator. Note that unlike many
+     * {@link Iterable} objects, {@link DataSet}s are unlikely to allow creation
+     * of multiple iterators without risking loss of data in each individual
+     * iteration loop.
+     */
+    @Override
+    public Iterator<Row> iterator();
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/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
new file mode 100644
index 0000000..186c7b9
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/DataSetHeader.java
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.data;
+
+import java.io.Serializable;
+
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+
+/**
+ * Represents the header of a {@link DataSet}, which define the
+ * columns/SelectItems of it.
+ */
+public interface DataSetHeader extends Serializable {
+
+    public SelectItem[] getSelectItems();
+
+    public int size();
+
+    public int indexOf(SelectItem item);
+
+    public int indexOf(Column column);
+
+    public SelectItem getSelectItem(int i);
+}

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/data/DataSetIterator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/DataSetIterator.java b/core/src/main/java/org/apache/metamodel/data/DataSetIterator.java
new file mode 100644
index 0000000..82481c5
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/DataSetIterator.java
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.data;
+
+import java.util.Iterator;
+
+/**
+ * Iterator implementation that iterates through a DataSet.
+ * 
+ * @author Kasper Sørensen
+ */
+public final class DataSetIterator implements Iterator<Row> {
+
+	private final DataSet _dataSet;
+	private volatile short _iterationState;
+	private volatile Row _row;
+
+	public DataSetIterator(DataSet dataSet) {
+		_dataSet = dataSet;
+		// 0 = uninitialized, 1=row not read yet, 2=row read, 3=finished
+		_iterationState = 0;
+	}
+
+	@Override
+	public boolean hasNext() {
+		if (_iterationState == 0 || _iterationState == 2) {
+			if (_dataSet.next()) {
+				_iterationState = 1;
+				_row = _dataSet.getRow();
+			} else {
+				_iterationState = 3;
+				_row = null;
+				_dataSet.close();
+			}
+		}
+		return _iterationState == 1;
+	}
+
+	@Override
+	public Row next() {
+		if (_iterationState == 1) {
+			_iterationState = 2;
+		}
+		return _row;
+	}
+
+	@Override
+	public void remove() {
+		throw new UnsupportedOperationException(
+				"DataSet is read-only, remove() is not supported.");
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/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
new file mode 100644
index 0000000..53fb2be
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/DataSetTableModel.java
@@ -0,0 +1,112 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.data;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.swing.table.AbstractTableModel;
+import javax.swing.table.TableModel;
+
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.util.EqualsBuilder;
+
+/**
+ * {@link TableModel} implementation which wraps a {@link DataSet} and presents its data.
+ * 
+ * @author Kasper Sørensen
+ * 
+ * @since 3.0
+ */
+public class DataSetTableModel extends AbstractTableModel {
+
+	private static final long serialVersionUID = 267644807447629777L;
+	private boolean _materialized;
+	private final List<Row> _materializedRows = new ArrayList<Row>();
+	private final DataSet _dataSet;
+	private final SelectItem[] _selectItems;
+
+	public DataSetTableModel(DataSet dataSet) {
+		_dataSet = dataSet;
+		_selectItems = dataSet.getSelectItems();
+		_materialized = false;
+	}
+
+	@Override
+	public int hashCode() {
+		return Arrays.hashCode(_selectItems) + _materializedRows.hashCode();
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (obj == null) {
+			return false;
+		}
+		if (obj == this) {
+			return true;
+		}
+		if (getClass() == obj.getClass()) {
+			DataSetTableModel that = (DataSetTableModel) obj;
+			EqualsBuilder eb = new EqualsBuilder();
+			eb.append(_materializedRows, that._materializedRows);
+			eb.append(_selectItems, that._selectItems);
+			return eb.isEquals();
+		}
+		return false;
+	}
+
+	public int getColumnCount() {
+		return _selectItems.length;
+	}
+
+	public int getRowCount() {
+		materialize();
+		return _materializedRows.size();
+	}
+
+	private void materialize() {
+		if (!_materialized) {
+		    try {
+		        while (_dataSet.next()) {
+		            _materializedRows.add(_dataSet.getRow());
+		        }
+		    } finally {
+		        _dataSet.close();
+		    }
+			_materialized = true;
+		}
+	}
+
+	public Object getValueAt(int rowIndex, int columnIndex) {
+		materialize();
+		return _materializedRows.get(rowIndex).getValue(columnIndex);
+	}
+
+	@Override
+	public String getColumnName(int column) {
+		return _selectItems[column].getSuperQueryAlias(false);
+	}
+
+	@Override
+	public void setValueAt(Object value, int rowIndex, int columnIndex) {
+		throw new UnsupportedOperationException(
+				"DataSetTableModels are immutable, so setValueAt() method is unsupported.");
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/data/DefaultRow.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/DefaultRow.java b/core/src/main/java/org/apache/metamodel/data/DefaultRow.java
new file mode 100644
index 0000000..3fee3b8
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/DefaultRow.java
@@ -0,0 +1,205 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.data;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eobjects.metamodel.query.SelectItem;
+
+/**
+ * Default Row implementation. Holds values in memory.
+ * 
+ * @author Kasper Sørensen
+ */
+public final class DefaultRow extends AbstractRow implements Row {
+
+    private static final long serialVersionUID = 1L;
+
+    private final DataSetHeader _header;
+    private final Object[] _values;
+    private final Style[] _styles;
+
+    /**
+     * This field was replaced by the DataSetHeader field above.
+     * 
+     * @deprecated no longer used, except for in deserialized objects
+     */
+    @Deprecated
+    private List<SelectItem> _items;
+
+    /**
+     * Constructs a row.
+     * 
+     * @param header
+     * @param values
+     * @param styles
+     */
+    public DefaultRow(DataSetHeader header, Object[] values, Style[] styles) {
+        if (header == null) {
+            throw new IllegalArgumentException("DataSet header cannot be null");
+        }
+        if (values == null) {
+            throw new IllegalArgumentException("Values cannot be null");
+        }
+        if (header.size() != values.length) {
+            throw new IllegalArgumentException("Header size and values length must be equal. " + header.size()
+                    + " select items present in header and encountered these values: " + Arrays.toString(values));
+        }
+        if (styles != null) {
+            if (values.length != styles.length) {
+                throw new IllegalArgumentException("Values length and styles length must be equal. " + values.length
+                        + " values present and encountered these styles: " + Arrays.toString(styles));
+            }
+            boolean entirelyNoStyle = true;
+            for (int i = 0; i < styles.length; i++) {
+                if (styles[i] == null) {
+                    throw new IllegalArgumentException("Elements in the style array cannot be null");
+                }
+                if (entirelyNoStyle && !Style.NO_STYLE.equals(styles[i])) {
+                    entirelyNoStyle = false;
+                }
+            }
+
+            if (entirelyNoStyle) {
+                // no need to reference any styles
+                styles = null;
+            }
+        }
+        _header = header;
+        _values = values;
+        _styles = styles;
+    }
+
+    /**
+     * Constructs a row.
+     * 
+     * @param header
+     * @param values
+     */
+    public DefaultRow(DataSetHeader header, Object[] values) {
+        this(header, values, null);
+    }
+
+    /**
+     * Constructs a row from an array of SelectItems and an array of
+     * corresponding values
+     * 
+     * @param items
+     *            the array of SelectItems
+     * @param values
+     *            the array of values
+     * 
+     * @deprecated use {@link #DefaultRow(DataSetHeader, Object[])} or
+     *             {@link #DefaultRow(DataSetHeader, Object[], Style[])}
+     *             instead.
+     */
+    @Deprecated
+    public DefaultRow(SelectItem[] items, Object[] values) {
+        this(Arrays.asList(items), values, null);
+    }
+
+    /**
+     * Constructs a row from an array of SelectItems and an array of
+     * corresponding values
+     * 
+     * @param items
+     *            the array of SelectItems
+     * @param values
+     *            the array of values
+     * @param styles
+     *            an optional array of styles
+     * @deprecated use {@link #DefaultRow(DataSetHeader, Object[])} or
+     *             {@link #DefaultRow(DataSetHeader, Object[], Style[])}
+     *             instead.
+     */
+    @Deprecated
+    public DefaultRow(SelectItem[] items, Object[] values, Style[] styles) {
+        this(Arrays.asList(items), values, styles);
+    }
+
+    /**
+     * Constructs a row from a list of SelectItems and an array of corresponding
+     * values
+     * 
+     * @param items
+     *            the list of SelectItems
+     * @param values
+     *            the array of values
+     * @deprecated use {@link #DefaultRow(DataSetHeader, Object[])} or
+     *             {@link #DefaultRow(DataSetHeader, Object[], Style[])}
+     *             instead.
+     */
+    @Deprecated
+    public DefaultRow(List<SelectItem> items, Object[] values) {
+        this(items, values, null);
+    }
+
+    /**
+     * Constructs a row from a list of SelectItems and an array of corresponding
+     * values
+     * 
+     * @param items
+     *            the list of SelectItems
+     * @param values
+     *            the array of values
+     * @param styles
+     *            an optional array of styles
+     * @deprecated use {@link #DefaultRow(DataSetHeader, Object[])} or
+     *             {@link #DefaultRow(DataSetHeader, Object[], Style[])}
+     *             instead.
+     */
+    @Deprecated
+    public DefaultRow(List<SelectItem> items, Object[] values, Style[] styles) {
+        this(new SimpleDataSetHeader(items), values, styles);
+    }
+
+    @Override
+    public Object getValue(int index) throws ArrayIndexOutOfBoundsException {
+        return _values[index];
+    }
+
+    @Override
+    public Object[] getValues() {
+        return _values;
+    }
+
+    @Override
+    public Style getStyle(int index) throws IndexOutOfBoundsException {
+        if (_styles == null) {
+            return Style.NO_STYLE;
+        }
+        return _styles[index];
+    }
+    
+    @Override
+    public Style[] getStyles() {
+        return _styles;
+    }
+
+    @Override
+    protected DataSetHeader getHeader() {
+        if (_header == null && _items != null) {
+            // this only happens for deserialized objects which where serialized
+            // prior to the introduction of DataSetHeader.
+            return new SimpleDataSetHeader(_items);
+        }
+        return _header;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/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
new file mode 100644
index 0000000..46ece93
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/EmptyDataSet.java
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.data;
+
+import java.util.List;
+
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+
+/**
+ * An empty data set.
+ * 
+ * @author Kasper Sørensen
+ */
+public final class EmptyDataSet extends AbstractDataSet {
+    
+    public EmptyDataSet(DataSetHeader header) {
+        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));
+    }
+
+    @Override
+    public boolean next() {
+        return false;
+    }
+
+    @Override
+    public Row getRow() {
+        return null;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/data/FilteredDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/FilteredDataSet.java b/core/src/main/java/org/apache/metamodel/data/FilteredDataSet.java
new file mode 100644
index 0000000..ca406ed
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/FilteredDataSet.java
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.data;
+
+
+/**
+ * Wraps another DataSet and transparently applies a set of filters to it.
+ * 
+ * @author Kasper Sørensen
+ */
+public final class FilteredDataSet extends AbstractDataSet {
+
+	private final DataSet _dataSet;
+	private final IRowFilter[] _filters;
+	private Row _row;
+
+	public FilteredDataSet(DataSet dataSet, IRowFilter... filters) {
+	    super(dataSet);
+		_dataSet = dataSet;
+		_filters = filters;
+	}
+
+	@Override
+	public void close() {
+		super.close();
+		_dataSet.close();
+	}
+
+	@Override
+	public boolean next() {
+		boolean next = false;
+		while (_dataSet.next()) {
+			Row row = _dataSet.getRow();
+			for (IRowFilter filter : _filters) {
+				next = filter.accept(row);
+				if (!next) {
+					break;
+				}
+			}
+			if (next) {
+				_row = row;
+				break;
+			}
+		}
+		return next;
+	}
+
+	@Override
+	public Row getRow() {
+		return _row;
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/data/FirstRowDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/FirstRowDataSet.java b/core/src/main/java/org/apache/metamodel/data/FirstRowDataSet.java
new file mode 100644
index 0000000..6662eb5
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/FirstRowDataSet.java
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.data;
+
+/**
+ * Wraps another DataSet and enforces a first row offset.
+ */
+public final class FirstRowDataSet extends AbstractDataSet {
+
+    private final DataSet _dataSet;
+    private volatile int _rowsLeftToSkip;
+
+    /**
+     * Constructs a {@link FirstRowDataSet}.
+     * 
+     * @param dataSet
+     *            the dataset to wrap
+     * @param firstRow
+     *            the first row number (1-based).
+     */
+    public FirstRowDataSet(DataSet dataSet, int firstRow) {
+        super(dataSet);
+        _dataSet = dataSet;
+        if (firstRow < 1) {
+            throw new IllegalArgumentException("First row cannot be negative or zero");
+        }
+        _rowsLeftToSkip = firstRow - 1;
+    }
+
+    @Override
+    public void close() {
+        _dataSet.close();
+    }
+
+    @Override
+    public Row getRow() {
+        return _dataSet.getRow();
+    }
+
+    @Override
+    public boolean next() {
+        boolean next = true;
+        if (_rowsLeftToSkip > 0) {
+            while (_rowsLeftToSkip > 0) {
+                next = _dataSet.next();
+                if (next) {
+                    _rowsLeftToSkip--;
+                } else {
+                    // no more rows at all - exit loop
+                    _rowsLeftToSkip = 0;
+                    return false;
+                }
+            }
+        }
+        return _dataSet.next();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/data/IRowFilter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/IRowFilter.java b/core/src/main/java/org/apache/metamodel/data/IRowFilter.java
new file mode 100644
index 0000000..ac46eea
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/IRowFilter.java
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.data;
+
+/**
+ * A filter that is executed client-side because filter criteria are either more
+ * dynamic than the Query-functionality offer or because it cannot be expressed
+ * using datastore-neutral queries.
+ * 
+ * @see FilteredDataSet
+ */
+public interface IRowFilter {
+
+	/**
+	 * Filters a row
+	 * 
+	 * @param row
+	 * @return true if the row is valid according to the filter
+	 */
+	public boolean accept(Row row);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/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
new file mode 100644
index 0000000..7e21412
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/InMemoryDataSet.java
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.data;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eobjects.metamodel.query.SelectItem;
+
+/**
+ * DataSet implementation based on in-memory data.
+ * 
+ * @author Kasper Sørensen
+ */
+public final class InMemoryDataSet extends AbstractDataSet {
+
+    private final List<Row> _rows;
+    private int _rowNumber = -1;
+
+    public InMemoryDataSet(Row... rows) {
+        this(Arrays.asList(rows));
+    }
+
+    public InMemoryDataSet(List<Row> rows) {
+        this(getHeader(rows), rows);
+    }
+
+    public InMemoryDataSet(DataSetHeader header, Row... rows) {
+        super(header);
+        _rows = Arrays.asList(rows);
+    }
+
+    public InMemoryDataSet(DataSetHeader header, List<Row> rows) {
+        super(header);
+        _rows = rows;
+    }
+
+    private static DataSetHeader getHeader(List<Row> rows) {
+        if (rows.isEmpty()) {
+            throw new IllegalArgumentException("Cannot hold an empty list of rows, use " + EmptyDataSet.class
+                    + " for this");
+        }
+
+        final SelectItem[] selectItems = rows.get(0).getSelectItems();
+
+        if (rows.size() > 3) {
+            // not that many records - caching will not have body to scale
+            return new SimpleDataSetHeader(selectItems);
+        }
+        return new CachingDataSetHeader(selectItems);
+    }
+
+    @Override
+    public boolean next() {
+        _rowNumber++;
+        if (_rowNumber < _rows.size()) {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public Row getRow() {
+        if (_rowNumber < 0 || _rowNumber >= _rows.size()) {
+            return null;
+        }
+        Row row = _rows.get(_rowNumber);
+        assert row.size() == getHeader().size();
+        return row;
+    }
+
+    public List<Row> getRows() {
+        return _rows;
+    }
+
+    public int size() {
+        return _rows.size();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/data/MaxRowsDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/MaxRowsDataSet.java b/core/src/main/java/org/apache/metamodel/data/MaxRowsDataSet.java
new file mode 100644
index 0000000..adecaed
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/MaxRowsDataSet.java
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.data;
+
+/**
+ * Wraps another DataSet and enforces a maximum number of rows constraint
+ */
+public final class MaxRowsDataSet extends AbstractDataSet {
+
+    private final DataSet _dataSet;
+    private volatile int _rowsLeft;
+
+    public MaxRowsDataSet(DataSet dataSet, int maxRows) {
+        super(dataSet);
+        _dataSet = dataSet;
+        _rowsLeft = maxRows;
+    }
+
+    @Override
+    public void close() {
+        _dataSet.close();
+    }
+
+    @Override
+    public Row getRow() {
+        return _dataSet.getRow();
+    }
+
+    @Override
+    public boolean next() {
+        if (_rowsLeft > 0) {
+            boolean next = _dataSet.next();
+            if (next) {
+                _rowsLeft--;
+            }
+            return next;
+        }
+        return false;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/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
new file mode 100644
index 0000000..47e95c0
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/Row.java
@@ -0,0 +1,135 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.data;
+
+import java.io.Serializable;
+
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+
+/**
+ * Represents a row of data in a DataSet. Each row is a mapping between
+ * SelectItems and values for each SelectItem.
+ * 
+ * @see DataSet
+ * @see SelectItem
+ */
+public interface Row extends Serializable {
+
+    /**
+     * Gets the value of the provided SelectItem.
+     * 
+     * @param item
+     * @return the value that corresponds to the provided SelectItem. Can be
+     *         null if either the value <i>is</i> null or if no value exists
+     *         that matches the SelectItem.
+     */
+    public Object getValue(SelectItem item);
+
+    /**
+     * Shorthand method for getting the value of a SelectItem based on the
+     * provided column. Invoking this method is equivalent to invoking
+     * getValue(new SelectItem(column)).
+     * 
+     * @param column
+     * @return the value of the specified column
+     */
+    public Object getValue(Column column);
+
+    /**
+     * Gets the value of the row at a given index
+     * 
+     * @param index
+     * @return the value at the specified index
+     * @throws IndexOutOfBoundsException
+     *             if the provided index is out of range
+     */
+    public Object getValue(int index) throws IndexOutOfBoundsException;
+
+    public Style getStyle(SelectItem item);
+
+    public Style getStyle(Column column);
+
+    public Style getStyle(int index) throws IndexOutOfBoundsException;
+    
+    public Style[] getStyles();
+
+    /**
+     * Gets the index of a SelectItem in the row.
+     * 
+     * @param item
+     *            the item to get the index of
+     * @return the index of a SelectItem in the row. If the SelectItem is not
+     *         found -1 will be returned.
+     */
+    public int indexOf(SelectItem item);
+
+    /**
+     * Gets the index of a Column in the row.
+     * 
+     * @param column
+     *            the column to get the index of
+     * @return the index of a column in the row. If the Column is not found, -1
+     *         will be returned.
+     */
+    public int indexOf(Column column);
+
+    /**
+     * Gets the select items that represent the columns of the {@link DataSet}
+     * that this row pertains to.
+     * 
+     * @return
+     */
+    public SelectItem[] getSelectItems();
+
+    /**
+     * Gets the values of the row, represented as an object array
+     * 
+     * @return an array of objects, containing the values of this row.
+     */
+    public Object[] getValues();
+
+    /**
+     * Creates a row similar to this one but only with a subset of the values.
+     * 
+     * @param selectItems
+     *            the select items (~ columns) to sub-select the row with
+     * @return a new Row object containing only the select items requested
+     * @deprecated use {@link #getSubSelection(DataSetHeader)} instead.
+     */
+    @Deprecated
+    public Row getSubSelection(SelectItem[] selectItems);
+
+    /**
+     * Creates a row similar to this one but only with a subset of the values.
+     * 
+     * @param header
+     *            the new header to sub-select the row with
+     * @return a new Row object containing only the select items in the newly
+     *         requested header
+     */
+    public Row getSubSelection(DataSetHeader header);
+
+    /**
+     * Gets the amount of values/columns/select items represented in this row.
+     * 
+     * @return
+     */
+    public int size();
+}
\ No newline at end of file