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:32:44 UTC
[01/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Updated Branches:
refs/heads/namespace-rename [created] 660e69368
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/test/java/org/apache/metamodel/dialects/SQLServerQueryRewriterTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/dialects/SQLServerQueryRewriterTest.java b/jdbc/src/test/java/org/apache/metamodel/dialects/SQLServerQueryRewriterTest.java
new file mode 100644
index 0000000..f91b276
--- /dev/null
+++ b/jdbc/src/test/java/org/apache/metamodel/dialects/SQLServerQueryRewriterTest.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.dialects;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
+import org.eobjects.metamodel.jdbc.dialects.SQLServerQueryRewriter;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.schema.MutableSchema;
+import org.eobjects.metamodel.schema.MutableTable;
+
+public class SQLServerQueryRewriterTest extends TestCase {
+
+ private MutableTable table;
+ private MutableColumn column;
+ private IQueryRewriter qr = new SQLServerQueryRewriter(null);
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ table = new MutableTable("foo");
+ table.setSchema(new MutableSchema("MY_SCHEMA"));
+ table.setQuote("\"");
+ column = new MutableColumn("bar");
+ column.setQuote("\"");
+ column.setTable(table);
+ }
+
+ public void testRewriteFromItem() throws Exception {
+ assertEquals("foo",
+ qr.rewriteFromItem(new FromItem(new MutableTable("foo"))));
+ }
+
+ public void testAliasing() throws Exception {
+ Query q = new Query().from(table).select(column);
+
+ assertEquals("SELECT MY_SCHEMA.\"foo\".\"bar\" FROM MY_SCHEMA.\"foo\"",
+ qr.rewriteQuery(q));
+ }
+
+ public void testSelectMaxRowsRewriting() throws Exception {
+ Query q = new Query().from(table).select(column).setMaxRows(20);
+
+ assertEquals(
+ "SELECT TOP 20 MY_SCHEMA.\"foo\".\"bar\" FROM MY_SCHEMA.\"foo\"",
+ qr.rewriteQuery(q));
+ }
+}
\ No newline at end of file
[54/61] Renamed all import and package statements from 'org.eobjects'
to 'org.apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java b/excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java
index e31d61d..c042ec6 100644
--- a/excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java
+++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import java.io.InputStream;
import java.io.OutputStream;
@@ -47,22 +47,22 @@ import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFFont;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetHeader;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.EmptyDataSet;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.data.Style.SizeUnit;
-import org.eobjects.metamodel.data.StyleBuilder;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.Action;
-import org.eobjects.metamodel.util.DateUtils;
-import org.eobjects.metamodel.util.FormatHelper;
-import org.eobjects.metamodel.util.Func;
-import org.eobjects.metamodel.util.Resource;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.MetaModelHelper;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSetHeader;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.EmptyDataSet;
+import org.apache.metamodel.data.Style;
+import org.apache.metamodel.data.Style.SizeUnit;
+import org.apache.metamodel.data.StyleBuilder;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.Action;
+import org.apache.metamodel.util.DateUtils;
+import org.apache.metamodel.util.FormatHelper;
+import org.apache.metamodel.util.Func;
+import org.apache.metamodel.util.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.XMLReader;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/main/java/org/apache/metamodel/excel/SpreadsheetReaderDelegate.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/SpreadsheetReaderDelegate.java b/excel/src/main/java/org/apache/metamodel/excel/SpreadsheetReaderDelegate.java
index 9cdbe42..596eb1a 100644
--- a/excel/src/main/java/org/apache/metamodel/excel/SpreadsheetReaderDelegate.java
+++ b/excel/src/main/java/org/apache/metamodel/excel/SpreadsheetReaderDelegate.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import java.io.InputStream;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.Ref;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.Ref;
/**
* Delegate for spreadsheet-implementation specific operations in an
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/main/java/org/apache/metamodel/excel/XlsDataSet.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/XlsDataSet.java b/excel/src/main/java/org/apache/metamodel/excel/XlsDataSet.java
index 133233f..c712bb2 100644
--- a/excel/src/main/java/org/apache/metamodel/excel/XlsDataSet.java
+++ b/excel/src/main/java/org/apache/metamodel/excel/XlsDataSet.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Workbook;
-import org.eobjects.metamodel.data.AbstractDataSet;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.SelectItem;
+import org.apache.metamodel.data.AbstractDataSet;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.SelectItem;
/**
* Stream {@link DataSet} implementation for Excel support.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/main/java/org/apache/metamodel/excel/XlsxRowCallback.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/XlsxRowCallback.java b/excel/src/main/java/org/apache/metamodel/excel/XlsxRowCallback.java
index 630a512..c47b414 100644
--- a/excel/src/main/java/org/apache/metamodel/excel/XlsxRowCallback.java
+++ b/excel/src/main/java/org/apache/metamodel/excel/XlsxRowCallback.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import java.util.List;
-import org.eobjects.metamodel.data.Style;
+import org.apache.metamodel.data.Style;
/**
* Callback for read rows in an XLSX spreadsheet.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/main/java/org/apache/metamodel/excel/XlsxRowPublisherAction.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/XlsxRowPublisherAction.java b/excel/src/main/java/org/apache/metamodel/excel/XlsxRowPublisherAction.java
index 85bbd58..a154251 100644
--- a/excel/src/main/java/org/apache/metamodel/excel/XlsxRowPublisherAction.java
+++ b/excel/src/main/java/org/apache/metamodel/excel/XlsxRowPublisherAction.java
@@ -16,17 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import java.io.InputStream;
import java.util.List;
import org.apache.poi.xssf.eventusermodel.XSSFReader;
-import org.eobjects.metamodel.data.RowPublisher;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.util.Action;
-import org.eobjects.metamodel.util.FileHelper;
+import org.apache.metamodel.data.RowPublisher;
+import org.apache.metamodel.data.Style;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.util.Action;
+import org.apache.metamodel.util.FileHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.InputSource;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/main/java/org/apache/metamodel/excel/XlsxSheetToRowsHandler.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/XlsxSheetToRowsHandler.java b/excel/src/main/java/org/apache/metamodel/excel/XlsxSheetToRowsHandler.java
index b43c5d6..8bae40d 100644
--- a/excel/src/main/java/org/apache/metamodel/excel/XlsxSheetToRowsHandler.java
+++ b/excel/src/main/java/org/apache/metamodel/excel/XlsxSheetToRowsHandler.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import java.util.ArrayList;
import java.util.Collections;
@@ -36,10 +36,10 @@ import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.data.Style.SizeUnit;
-import org.eobjects.metamodel.data.StyleBuilder;
-import org.eobjects.metamodel.util.DateUtils;
+import org.apache.metamodel.data.Style;
+import org.apache.metamodel.data.Style.SizeUnit;
+import org.apache.metamodel.data.StyleBuilder;
+import org.apache.metamodel.util.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.Attributes;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/main/java/org/apache/metamodel/excel/XlsxSpreadsheetReaderDelegate.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/XlsxSpreadsheetReaderDelegate.java b/excel/src/main/java/org/apache/metamodel/excel/XlsxSpreadsheetReaderDelegate.java
index dadd978..8f36847 100644
--- a/excel/src/main/java/org/apache/metamodel/excel/XlsxSpreadsheetReaderDelegate.java
+++ b/excel/src/main/java/org/apache/metamodel/excel/XlsxSpreadsheetReaderDelegate.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import java.io.InputStream;
import java.util.ArrayList;
@@ -27,20 +27,20 @@ import java.util.Map.Entry;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xssf.eventusermodel.XSSFReader;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.RowPublisherDataSet;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-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.Table;
-import org.eobjects.metamodel.util.AlphabeticSequence;
-import org.eobjects.metamodel.util.FileHelper;
-import org.eobjects.metamodel.util.Ref;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.RowPublisherDataSet;
+import org.apache.metamodel.data.Style;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.AlphabeticSequence;
+import org.apache.metamodel.util.FileHelper;
+import org.apache.metamodel.util.Ref;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.InputSource;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/main/java/org/apache/metamodel/excel/XlsxStopParsingException.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/XlsxStopParsingException.java b/excel/src/main/java/org/apache/metamodel/excel/XlsxStopParsingException.java
index 47d8078..bcbf8ef 100644
--- a/excel/src/main/java/org/apache/metamodel/excel/XlsxStopParsingException.java
+++ b/excel/src/main/java/org/apache/metamodel/excel/XlsxStopParsingException.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import org.xml.sax.SAXException;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/main/java/org/apache/metamodel/excel/XlsxWorkbookToTablesHandler.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/XlsxWorkbookToTablesHandler.java b/excel/src/main/java/org/apache/metamodel/excel/XlsxWorkbookToTablesHandler.java
index fa65bf8..150cf21 100644
--- a/excel/src/main/java/org/apache/metamodel/excel/XlsxWorkbookToTablesHandler.java
+++ b/excel/src/main/java/org/apache/metamodel/excel/XlsxWorkbookToTablesHandler.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import java.util.Map;
-import org.eobjects.metamodel.schema.MutableSchema;
-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.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.schema.TableType;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/main/java/org/apache/metamodel/excel/ZeroBasedRowIterator.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/ZeroBasedRowIterator.java b/excel/src/main/java/org/apache/metamodel/excel/ZeroBasedRowIterator.java
index d897ec4..68674b4 100644
--- a/excel/src/main/java/org/apache/metamodel/excel/ZeroBasedRowIterator.java
+++ b/excel/src/main/java/org/apache/metamodel/excel/ZeroBasedRowIterator.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import java.util.Iterator;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/main/java/org/apache/metamodel/excel/package-info.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/package-info.java b/excel/src/main/java/org/apache/metamodel/excel/package-info.java
index 9bf3d30..7cd8e6b 100644
--- a/excel/src/main/java/org/apache/metamodel/excel/package-info.java
+++ b/excel/src/main/java/org/apache/metamodel/excel/package-info.java
@@ -19,5 +19,5 @@
/**
* Module package for MS Excel spreadsheet files
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/test/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegateTest.java
----------------------------------------------------------------------
diff --git a/excel/src/test/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegateTest.java b/excel/src/test/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegateTest.java
index cbf9723..fdf1e67 100644
--- a/excel/src/test/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegateTest.java
+++ b/excel/src/test/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegateTest.java
@@ -16,20 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import java.io.File;
import java.lang.reflect.Field;
import junit.framework.TestCase;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.data.Style;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public class DefaultSpreadsheetReaderDelegateTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/test/java/org/apache/metamodel/excel/ExcelConfigurationTest.java
----------------------------------------------------------------------
diff --git a/excel/src/test/java/org/apache/metamodel/excel/ExcelConfigurationTest.java b/excel/src/test/java/org/apache/metamodel/excel/ExcelConfigurationTest.java
index 4a3b0f8..6e7559c 100644
--- a/excel/src/test/java/org/apache/metamodel/excel/ExcelConfigurationTest.java
+++ b/excel/src/test/java/org/apache/metamodel/excel/ExcelConfigurationTest.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
-import org.eobjects.metamodel.excel.ExcelConfiguration;
+import org.apache.metamodel.excel.ExcelConfiguration;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/test/java/org/apache/metamodel/excel/ExcelDataContextTest.java
----------------------------------------------------------------------
diff --git a/excel/src/test/java/org/apache/metamodel/excel/ExcelDataContextTest.java b/excel/src/test/java/org/apache/metamodel/excel/ExcelDataContextTest.java
index 8710d52..010dd03 100644
--- a/excel/src/test/java/org/apache/metamodel/excel/ExcelDataContextTest.java
+++ b/excel/src/test/java/org/apache/metamodel/excel/ExcelDataContextTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import java.io.File;
import java.util.Arrays;
@@ -24,21 +24,21 @@ import java.util.List;
import junit.framework.TestCase;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.data.StyleBuilder;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.DateUtils;
-import org.eobjects.metamodel.util.FileHelper;
-import org.eobjects.metamodel.util.Month;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelHelper;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.data.Style;
+import org.apache.metamodel.data.StyleBuilder;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.DateUtils;
+import org.apache.metamodel.util.FileHelper;
+import org.apache.metamodel.util.Month;
public class ExcelDataContextTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/test/java/org/apache/metamodel/excel/ExcelUpdateCallbackTest.java
----------------------------------------------------------------------
diff --git a/excel/src/test/java/org/apache/metamodel/excel/ExcelUpdateCallbackTest.java b/excel/src/test/java/org/apache/metamodel/excel/ExcelUpdateCallbackTest.java
index d1b4e16..3ac116b 100644
--- a/excel/src/test/java/org/apache/metamodel/excel/ExcelUpdateCallbackTest.java
+++ b/excel/src/test/java/org/apache/metamodel/excel/ExcelUpdateCallbackTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import java.io.File;
import java.lang.reflect.Field;
@@ -29,8 +29,8 @@ import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.schema.Table;
public class ExcelUpdateCallbackTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/test/java/org/apache/metamodel/excel/ZeroBasedRowIteratorTest.java
----------------------------------------------------------------------
diff --git a/excel/src/test/java/org/apache/metamodel/excel/ZeroBasedRowIteratorTest.java b/excel/src/test/java/org/apache/metamodel/excel/ZeroBasedRowIteratorTest.java
index 3e2852a..40814ae 100644
--- a/excel/src/test/java/org/apache/metamodel/excel/ZeroBasedRowIteratorTest.java
+++ b/excel/src/test/java/org/apache/metamodel/excel/ZeroBasedRowIteratorTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import java.io.FileInputStream;
@@ -26,7 +26,7 @@ import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.easymock.EasyMock;
-import org.eobjects.metamodel.excel.ZeroBasedRowIterator;
+import org.apache.metamodel.excel.ZeroBasedRowIterator;
public class ZeroBasedRowIteratorTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthConfiguration.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthConfiguration.java b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthConfiguration.java
index 5054b01..bd5fc18 100644
--- a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthConfiguration.java
+++ b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthConfiguration.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.fixedwidth;
+package org.apache.metamodel.fixedwidth;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.util.BaseObject;
-import org.eobjects.metamodel.util.FileHelper;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.util.BaseObject;
+import org.apache.metamodel.util.FileHelper;
/**
* Configuration of metadata about a fixed width values datacontext.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataContext.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataContext.java b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataContext.java
index 704b376..1c807fa 100644
--- a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataContext.java
+++ b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataContext.java
@@ -16,27 +16,27 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.fixedwidth;
+package org.apache.metamodel.fixedwidth;
import java.io.File;
import java.io.InputStream;
import java.io.Reader;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-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.Table;
-import org.eobjects.metamodel.schema.TableType;
-import org.eobjects.metamodel.util.AlphabeticSequence;
-import org.eobjects.metamodel.util.FileHelper;
-import org.eobjects.metamodel.util.FileResource;
-import org.eobjects.metamodel.util.Resource;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.QueryPostprocessDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.schema.TableType;
+import org.apache.metamodel.util.AlphabeticSequence;
+import org.apache.metamodel.util.FileHelper;
+import org.apache.metamodel.util.FileResource;
+import org.apache.metamodel.util.Resource;
/**
* DataContext implementation for fixed width value files.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataSet.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataSet.java b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataSet.java
index 3ac8047..1fb1111 100644
--- a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataSet.java
+++ b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataSet.java
@@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.fixedwidth;
+package org.apache.metamodel.fixedwidth;
-import org.eobjects.metamodel.data.AbstractDataSet;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.util.FileHelper;
+import org.apache.metamodel.data.AbstractDataSet;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.util.FileHelper;
/**
* DataSet implementation for fixed width values.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthReader.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthReader.java b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthReader.java
index ca0aa6f..d6a5bd2 100644
--- a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthReader.java
+++ b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthReader.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.fixedwidth;
+package org.apache.metamodel.fixedwidth;
import java.io.BufferedReader;
import java.io.Closeable;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/InconsistentValueWidthException.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/InconsistentValueWidthException.java b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/InconsistentValueWidthException.java
index 2fa3573..ac6cef4 100644
--- a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/InconsistentValueWidthException.java
+++ b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/InconsistentValueWidthException.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.fixedwidth;
+package org.apache.metamodel.fixedwidth;
-import org.eobjects.metamodel.InconsistentRowFormatException;
-import org.eobjects.metamodel.data.Row;
+import org.apache.metamodel.InconsistentRowFormatException;
+import org.apache.metamodel.data.Row;
/**
* Exception thrown when inconsistent widths of a Fixed Width Value file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/package-info.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/package-info.java b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/package-info.java
index 9702557..0c94e0d 100644
--- a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/package-info.java
+++ b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/package-info.java
@@ -19,5 +19,5 @@
/**
* Module package for Fixed width value files
*/
-package org.eobjects.metamodel.fixedwidth;
+package org.apache.metamodel.fixedwidth;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthConfigurationTest.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthConfigurationTest.java b/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthConfigurationTest.java
index ff9cb12..8225be0 100644
--- a/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthConfigurationTest.java
+++ b/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthConfigurationTest.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.fixedwidth;
+package org.apache.metamodel.fixedwidth;
-import org.eobjects.metamodel.fixedwidth.FixedWidthConfiguration;
+import org.apache.metamodel.fixedwidth.FixedWidthConfiguration;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthDataContextTest.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthDataContextTest.java b/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthDataContextTest.java
index cf95c84..52af87f 100644
--- a/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthDataContextTest.java
+++ b/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthDataContextTest.java
@@ -16,21 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.fixedwidth;
+package org.apache.metamodel.fixedwidth;
import java.io.File;
import java.util.Arrays;
import junit.framework.TestCase;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.fixedwidth.FixedWidthConfiguration;
-import org.eobjects.metamodel.fixedwidth.FixedWidthDataContext;
-import org.eobjects.metamodel.fixedwidth.InconsistentValueWidthException;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.fixedwidth.FixedWidthConfiguration;
+import org.apache.metamodel.fixedwidth.FixedWidthDataContext;
+import org.apache.metamodel.fixedwidth.InconsistentValueWidthException;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public class FixedWidthDataContextTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/full/src/main/java/org/apache/metamodel/DataContextFactory.java
----------------------------------------------------------------------
diff --git a/full/src/main/java/org/apache/metamodel/DataContextFactory.java b/full/src/main/java/org/apache/metamodel/DataContextFactory.java
index 5b5598b..fc10f05 100644
--- a/full/src/main/java/org/apache/metamodel/DataContextFactory.java
+++ b/full/src/main/java/org/apache/metamodel/DataContextFactory.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.io.File;
import java.io.InputStream;
@@ -27,22 +27,22 @@ import java.util.Collection;
import javax.sql.DataSource;
import org.ektorp.http.StdHttpClient.Builder;
-import org.eobjects.metamodel.access.AccessDataContext;
-import org.eobjects.metamodel.couchdb.CouchDbDataContext;
-import org.eobjects.metamodel.csv.CsvConfiguration;
-import org.eobjects.metamodel.csv.CsvDataContext;
-import org.eobjects.metamodel.excel.ExcelConfiguration;
-import org.eobjects.metamodel.excel.ExcelDataContext;
-import org.eobjects.metamodel.fixedwidth.FixedWidthConfiguration;
-import org.eobjects.metamodel.fixedwidth.FixedWidthDataContext;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.mongodb.MongoDbDataContext;
-import org.eobjects.metamodel.openoffice.OpenOfficeDataContext;
-import org.eobjects.metamodel.salesforce.SalesforceDataContext;
-import org.eobjects.metamodel.schema.TableType;
-import org.eobjects.metamodel.sugarcrm.SugarCrmDataContext;
-import org.eobjects.metamodel.util.FileHelper;
-import org.eobjects.metamodel.xml.XmlDomDataContext;
+import org.apache.metamodel.access.AccessDataContext;
+import org.apache.metamodel.couchdb.CouchDbDataContext;
+import org.apache.metamodel.csv.CsvConfiguration;
+import org.apache.metamodel.csv.CsvDataContext;
+import org.apache.metamodel.excel.ExcelConfiguration;
+import org.apache.metamodel.excel.ExcelDataContext;
+import org.apache.metamodel.fixedwidth.FixedWidthConfiguration;
+import org.apache.metamodel.fixedwidth.FixedWidthDataContext;
+import org.apache.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.mongodb.MongoDbDataContext;
+import org.apache.metamodel.openoffice.OpenOfficeDataContext;
+import org.apache.metamodel.salesforce.SalesforceDataContext;
+import org.apache.metamodel.schema.TableType;
+import org.apache.metamodel.sugarcrm.SugarCrmDataContext;
+import org.apache.metamodel.util.FileHelper;
+import org.apache.metamodel.xml.XmlDomDataContext;
import org.xml.sax.InputSource;
import com.mongodb.DB;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/full/src/test/java/org/apache/metamodel/DataContextFactoryTest.java
----------------------------------------------------------------------
diff --git a/full/src/test/java/org/apache/metamodel/DataContextFactoryTest.java b/full/src/test/java/org/apache/metamodel/DataContextFactoryTest.java
index 5bf24e1..53edc03 100644
--- a/full/src/test/java/org/apache/metamodel/DataContextFactoryTest.java
+++ b/full/src/test/java/org/apache/metamodel/DataContextFactoryTest.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.io.File;
-import org.eobjects.metamodel.excel.ExcelConfiguration;
-import org.eobjects.metamodel.excel.ExcelDataContext;
+import org.apache.metamodel.excel.ExcelConfiguration;
+import org.apache.metamodel.excel.ExcelDataContext;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/FetchSizeCalculator.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/FetchSizeCalculator.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/FetchSizeCalculator.java
index 155adf9..cb0c259 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/FetchSizeCalculator.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/FetchSizeCalculator.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.util.List;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcBatchUpdateCallback.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcBatchUpdateCallback.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcBatchUpdateCallback.java
index 50e38a4..beb0092 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcBatchUpdateCallback.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcBatchUpdateCallback.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.util.FileHelper;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.util.FileHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcColumn.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcColumn.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcColumn.java
index de09ce7..fe69ec0 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcColumn.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcColumn.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.Table;
/**
* Column implementation for JDBC data contexts.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQuery.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQuery.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQuery.java
index ddadf1f..c69f5df 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQuery.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQuery.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -24,11 +24,11 @@ import java.sql.SQLException;
import java.util.List;
import org.apache.commons.pool.impl.GenericObjectPool;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.DefaultCompiledQuery;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.query.CompiledQuery;
+import org.apache.metamodel.query.DefaultCompiledQuery;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQueryLease.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQueryLease.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQueryLease.java
index 65bf7b5..c1397ab 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQueryLease.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQueryLease.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.Connection;
import java.sql.PreparedStatement;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQueryLeaseFactory.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQueryLeaseFactory.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQueryLeaseFactory.java
index e3712ed..d4770bb 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQueryLeaseFactory.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQueryLeaseFactory.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.Connection;
import java.sql.PreparedStatement;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCreateTableBuilder.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCreateTableBuilder.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCreateTableBuilder.java
index a1afc6c..5d4511c 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCreateTableBuilder.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCreateTableBuilder.java
@@ -16,19 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
-import org.eobjects.metamodel.create.AbstractTableCreationBuilder;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.FileHelper;
+import org.apache.metamodel.create.AbstractTableCreationBuilder;
+import org.apache.metamodel.jdbc.dialects.IQueryRewriter;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.FileHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataContext.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataContext.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataContext.java
index ddac728..ec309ff 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataContext.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataContext.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
@@ -33,27 +33,27 @@ import java.util.StringTokenizer;
import javax.sql.DataSource;
-import org.eobjects.metamodel.AbstractDataContext;
-import org.eobjects.metamodel.BatchUpdateScript;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.EmptyDataSet;
-import org.eobjects.metamodel.data.MaxRowsDataSet;
-import org.eobjects.metamodel.jdbc.dialects.DB2QueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.DefaultQueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.H2QueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.HsqldbQueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.MysqlQueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.PostgresqlQueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.SQLServerQueryRewriter;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.TableType;
-import org.eobjects.metamodel.util.FileHelper;
+import org.apache.metamodel.AbstractDataContext;
+import org.apache.metamodel.BatchUpdateScript;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.UpdateableDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.EmptyDataSet;
+import org.apache.metamodel.data.MaxRowsDataSet;
+import org.apache.metamodel.jdbc.dialects.DB2QueryRewriter;
+import org.apache.metamodel.jdbc.dialects.DefaultQueryRewriter;
+import org.apache.metamodel.jdbc.dialects.H2QueryRewriter;
+import org.apache.metamodel.jdbc.dialects.HsqldbQueryRewriter;
+import org.apache.metamodel.jdbc.dialects.IQueryRewriter;
+import org.apache.metamodel.jdbc.dialects.MysqlQueryRewriter;
+import org.apache.metamodel.jdbc.dialects.PostgresqlQueryRewriter;
+import org.apache.metamodel.jdbc.dialects.SQLServerQueryRewriter;
+import org.apache.metamodel.query.CompiledQuery;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.TableType;
+import org.apache.metamodel.util.FileHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataSet.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataSet.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataSet.java
index 09b3689..76b8552 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataSet.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataSet.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.io.InputStream;
import java.io.Reader;
@@ -27,15 +27,15 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.AbstractDataSet;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.util.FileHelper;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.data.AbstractDataSet;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.util.FileHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDeleteBuilder.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDeleteBuilder.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDeleteBuilder.java
index ef04b63..dfd0b0a 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDeleteBuilder.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDeleteBuilder.java
@@ -16,20 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.delete.AbstractRowDeletionBuilder;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.FileHelper;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.delete.AbstractRowDeletionBuilder;
+import org.apache.metamodel.delete.RowDeletionBuilder;
+import org.apache.metamodel.jdbc.dialects.IQueryRewriter;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.FileHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDropTableBuilder.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDropTableBuilder.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDropTableBuilder.java
index e903726..062c180 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDropTableBuilder.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDropTableBuilder.java
@@ -16,17 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.PreparedStatement;
import java.sql.SQLException;
-import org.eobjects.metamodel.drop.AbstractTableDropBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.drop.AbstractTableDropBuilder;
+import org.apache.metamodel.drop.TableDropBuilder;
+import org.apache.metamodel.jdbc.dialects.IQueryRewriter;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
/**
* {@link TableDropBuilder} that issues an SQL DROP TABLE statement
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcInsertBuilder.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcInsertBuilder.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcInsertBuilder.java
index 9cfd4bc..6f3d8dd 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcInsertBuilder.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcInsertBuilder.java
@@ -16,19 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Arrays;
-import org.eobjects.metamodel.insert.AbstractRowInsertionBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.FileHelper;
+import org.apache.metamodel.insert.AbstractRowInsertionBuilder;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.jdbc.dialects.IQueryRewriter;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.FileHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcMetadataLoader.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcMetadataLoader.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcMetadataLoader.java
index 97753a1..85c2514 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcMetadataLoader.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcMetadataLoader.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
@@ -28,14 +28,14 @@ import java.util.Set;
import java.util.StringTokenizer;
import java.util.concurrent.ConcurrentHashMap;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableRelationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.schema.TableType;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableRelationship;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.schema.TableType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSchema.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSchema.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSchema.java
index 28285f4..12d4873 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSchema.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSchema.java
@@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.io.ObjectStreamException;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Schema;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
/**
* Schema implementation for JDBC data contexts
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSimpleUpdateCallback.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSimpleUpdateCallback.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSimpleUpdateCallback.java
index 2a02be8..f41350d 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSimpleUpdateCallback.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSimpleUpdateCallback.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.PreparedStatement;
import java.sql.SQLException;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.util.FileHelper;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.util.FileHelper;
/**
* Jdbc {@link UpdateCallback} for databases that do not support batch features.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcTable.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcTable.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcTable.java
index 4ab1419..ceef279 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcTable.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcTable.java
@@ -16,16 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.io.ObjectStreamException;
import java.util.List;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.TableType;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Relationship;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.TableType;
/**
* Table implementation that is based on JDBC metadata.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUpdateBuilder.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUpdateBuilder.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUpdateBuilder.java
index 5860ec5..35eabe0 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUpdateBuilder.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUpdateBuilder.java
@@ -16,21 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.AbstractRowUpdationBuilder;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
-import org.eobjects.metamodel.util.FileHelper;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.jdbc.dialects.IQueryRewriter;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.update.AbstractRowUpdationBuilder;
+import org.apache.metamodel.update.RowUpdationBuilder;
+import org.apache.metamodel.util.FileHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUpdateCallback.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUpdateCallback.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUpdateCallback.java
index c0861fb..02e4b9b 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUpdateCallback.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUpdateCallback.java
@@ -16,21 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
-import org.eobjects.metamodel.AbstractUpdateCallback;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
+import org.apache.metamodel.AbstractUpdateCallback;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.create.TableCreationBuilder;
+import org.apache.metamodel.delete.RowDeletionBuilder;
+import org.apache.metamodel.drop.TableDropBuilder;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.update.RowUpdationBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUtils.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUtils.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUtils.java
index 80f0875..87e584f 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUtils.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUtils.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.io.InputStream;
import java.io.Reader;
@@ -29,16 +29,16 @@ import java.util.Calendar;
import java.util.Date;
import java.util.List;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.QueryParameter;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.TableType;
-import org.eobjects.metamodel.util.FileHelper;
-import org.eobjects.metamodel.util.FormatHelper;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.jdbc.dialects.IQueryRewriter;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.QueryParameter;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.TableType;
+import org.apache.metamodel.util.FileHelper;
+import org.apache.metamodel.util.FormatHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/MetadataLoader.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/MetadataLoader.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/MetadataLoader.java
index 07b17de..3e80426 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/MetadataLoader.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/MetadataLoader.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
/**
* Defines the interface for a component capable of loading schema-model
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/QuerySplitter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/QuerySplitter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/QuerySplitter.java
index 1f74866..bbb09c9 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/QuerySplitter.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/QuerySplitter.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.util.ArrayList;
import java.util.List;
@@ -24,20 +24,20 @@ import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromClause;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.GroupByItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelHelper;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FromClause;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.query.GroupByItem;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
/**
* The QuerySplitter class makes it possible to split up queries that are
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/SplitQueriesDataSet.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/SplitQueriesDataSet.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/SplitQueriesDataSet.java
index 68cc442..b019b35 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/SplitQueriesDataSet.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/SplitQueriesDataSet.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.util.ArrayList;
import java.util.Iterator;
@@ -25,13 +25,13 @@ import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.AbstractDataSet;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.data.AbstractDataSet;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
/**
* DataSet for split queries. Queries will be executed as needed, not at once.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/SqlKeywords.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/SqlKeywords.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/SqlKeywords.java
index 349e2c0..b2207df 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/SqlKeywords.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/SqlKeywords.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.util.HashSet;
import java.util.Set;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/AbstractQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/AbstractQueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/AbstractQueryRewriter.java
index 2cc8ece..a55ea2a 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/AbstractQueryRewriter.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/AbstractQueryRewriter.java
@@ -16,25 +16,25 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc.dialects;
+package org.apache.metamodel.jdbc.dialects;
import java.util.List;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.AbstractQueryClause;
-import org.eobjects.metamodel.query.FilterClause;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromClause;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.GroupByClause;
-import org.eobjects.metamodel.query.GroupByItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.OrderByClause;
-import org.eobjects.metamodel.query.OrderByItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectClause;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.ColumnType;
+import org.apache.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.query.AbstractQueryClause;
+import org.apache.metamodel.query.FilterClause;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FromClause;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.GroupByClause;
+import org.apache.metamodel.query.GroupByItem;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.OrderByClause;
+import org.apache.metamodel.query.OrderByItem;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectClause;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.ColumnType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/DB2QueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/DB2QueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/DB2QueryRewriter.java
index 90eeb9d..ef21fbf 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/DB2QueryRewriter.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/DB2QueryRewriter.java
@@ -16,20 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc.dialects;
+package org.apache.metamodel.jdbc.dialects;
import java.util.Date;
import java.util.List;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.util.FormatHelper;
-import org.eobjects.metamodel.util.TimeComparator;
+import org.apache.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.util.FormatHelper;
+import org.apache.metamodel.util.TimeComparator;
/**
* Query rewriter for IBM DB2
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/DefaultQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/DefaultQueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/DefaultQueryRewriter.java
index d3356cd..1ac72bc 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/DefaultQueryRewriter.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/DefaultQueryRewriter.java
@@ -16,18 +16,18 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc.dialects;
+package org.apache.metamodel.jdbc.dialects;
import java.util.List;
import java.util.ListIterator;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.util.CollectionUtils;
+import org.apache.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.util.CollectionUtils;
/**
* Generic query rewriter that adds syntax enhancements that are only possible
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/H2QueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/H2QueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/H2QueryRewriter.java
index f6d1c31..fd77300 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/H2QueryRewriter.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/H2QueryRewriter.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc.dialects;
+package org.apache.metamodel.jdbc.dialects;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.jdbc.JdbcDataContext;
/**
* Query rewriter for H2
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/HsqldbQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/HsqldbQueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/HsqldbQueryRewriter.java
index 36366cd..cc3d202 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/HsqldbQueryRewriter.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/HsqldbQueryRewriter.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc.dialects;
+package org.apache.metamodel.jdbc.dialects;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectClause;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
+import org.apache.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectClause;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
/**
* Query rewriter for HSQLDB
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/IQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/IQueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/IQueryRewriter.java
index 4d94d40..17140e3 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/IQueryRewriter.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/IQueryRewriter.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc.dialects;
+package org.apache.metamodel.jdbc.dialects;
import java.sql.Types;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.ColumnType;
+import org.apache.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.ColumnType;
/**
* A query rewriter can be used for rewriting (part of) a query's string
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/LimitOffsetQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/LimitOffsetQueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/LimitOffsetQueryRewriter.java
index 76a35a8..7960f4a 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/LimitOffsetQueryRewriter.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/LimitOffsetQueryRewriter.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc.dialects;
+package org.apache.metamodel.jdbc.dialects;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.Query;
+import org.apache.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.query.Query;
/**
* Query rewriter for databases that support LIMIT and OFFSET keywords for max
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/MysqlQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/MysqlQueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/MysqlQueryRewriter.java
index 88757be..3c0037b 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/MysqlQueryRewriter.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/MysqlQueryRewriter.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc.dialects;
+package org.apache.metamodel.jdbc.dialects;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.jdbc.JdbcDataContext;
/**
* Query rewriter for MySQL
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/PostgresqlQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/PostgresqlQueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/PostgresqlQueryRewriter.java
index d303c50..c3fd322 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/PostgresqlQueryRewriter.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/PostgresqlQueryRewriter.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc.dialects;
+package org.apache.metamodel.jdbc.dialects;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
/**
* Query rewriter for PostgreSQL
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/SQLServerQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/SQLServerQueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/SQLServerQueryRewriter.java
index 732ec34..42c54c1 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/SQLServerQueryRewriter.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/SQLServerQueryRewriter.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc.dialects;
+package org.apache.metamodel.jdbc.dialects;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectClause;
+import org.apache.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectClause;
public class SQLServerQueryRewriter extends DefaultQueryRewriter {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/main/java/org/apache/metamodel/jdbc/package-info.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/package-info.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/package-info.java
index fac1963..c5a1aee 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/package-info.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/package-info.java
@@ -19,5 +19,5 @@
/**
* Module package for JDBC compliant databases
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/integrationtests/org/apache/metamodel/DB2Test.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/apache/metamodel/DB2Test.java b/jdbc/src/test/integrationtests/org/apache/metamodel/DB2Test.java
index 13cc501..f32f016 100644
--- a/jdbc/src/test/integrationtests/org/apache/metamodel/DB2Test.java
+++ b/jdbc/src/test/integrationtests/org/apache/metamodel/DB2Test.java
@@ -1,4 +1,4 @@
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -6,12 +6,12 @@ import java.util.Arrays;
import junit.framework.TestCase;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.jdbc.JdbcTestTemplates;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.jdbc.JdbcTestTemplates;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
/**
* DB2 integration test. This is a read-only integration test, meant to be
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/integrationtests/org/apache/metamodel/FirebirdTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/apache/metamodel/FirebirdTest.java b/jdbc/src/test/integrationtests/org/apache/metamodel/FirebirdTest.java
index ec1ba32..b7a4467 100644
--- a/jdbc/src/test/integrationtests/org/apache/metamodel/FirebirdTest.java
+++ b/jdbc/src/test/integrationtests/org/apache/metamodel/FirebirdTest.java
@@ -1,4 +1,4 @@
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -10,15 +10,15 @@ import javax.swing.table.TableModel;
import junit.framework.TestCase;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetTableModel;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.JoinType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSetTableModel;
+import org.apache.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.JoinType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
/**
* Integrationtests for Firebird SQL.
[51/61] [partial] git commit: Hard rename of all 'org/eobjects'
folders to 'org/apache'.
Posted by ka...@apache.org.
Hard rename of all 'org/eobjects' folders to 'org/apache'.
Project: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/commit/e2e2b37a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/tree/e2e2b37a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/diff/e2e2b37a
Branch: refs/heads/namespace-rename
Commit: e2e2b37ac25fe76e1250e6cf0e8c426e5650f519
Parents: c0c5b99
Author: kaspers <ka...@kaspers-think.humaninference.com>
Authored: Fri Jul 19 09:47:00 2013 +0200
Committer: kaspers <ka...@kaspers-think.humaninference.com>
Committed: Fri Jul 19 09:47:00 2013 +0200
----------------------------------------------------------------------
.../metamodel/access/AccessDataContext.java | 170 ++++
.../apache/metamodel/access/package-info.java | 23 +
.../metamodel/access/AccessDataContext.java | 170 ----
.../eobjects/metamodel/access/package-info.java | 23 -
.../apache/metamodel/AbstractDataContext.java | 463 ++++++++++
.../metamodel/AbstractUpdateCallback.java | 164 ++++
.../org/apache/metamodel/BatchUpdateScript.java | 29 +
.../apache/metamodel/CompositeDataContext.java | 204 +++++
.../metamodel/CompositeQueryDelegate.java | 49 ++
.../java/org/apache/metamodel/DataContext.java | 199 +++++
.../metamodel/DeleteAndInsertBuilder.java | 111 +++
.../InconsistentRowFormatException.java | 82 ++
.../apache/metamodel/MetaModelException.java | 47 +
.../org/apache/metamodel/MetaModelHelper.java | 775 +++++++++++++++++
.../metamodel/QueryPostprocessDataContext.java | 589 +++++++++++++
.../metamodel/QueryPostprocessDelegate.java | 45 +
.../apache/metamodel/SchemaNameComparator.java | 58 ++
.../org/apache/metamodel/UpdateCallback.java | 45 +
.../java/org/apache/metamodel/UpdateScript.java | 41 +
.../apache/metamodel/UpdateableDataContext.java | 41 +
.../metamodel/convert/ColumnTypeDetector.java | 82 ++
.../metamodel/convert/ConvertedDataSet.java | 74 ++
.../convert/ConvertedDataSetInterceptor.java | 91 ++
.../ConvertedRowInsertionInterceptor.java | 75 ++
.../ConvertedRowUpdationInterceptor.java | 67 ++
.../apache/metamodel/convert/Converters.java | 329 +++++++
.../convert/HasReadTypeConverters.java | 33 +
.../convert/StringToBooleanConverter.java | 54 ++
.../convert/StringToDateConverter.java | 127 +++
.../convert/StringToDoubleConverter.java | 52 ++
.../convert/StringToIntegerConverter.java | 52 ++
.../apache/metamodel/convert/TypeConverter.java | 54 ++
.../apache/metamodel/convert/package-info.java | 23 +
.../metamodel/create/AbstractColumnBuilder.java | 87 ++
.../create/AbstractTableCreationBuilder.java | 135 +++
.../apache/metamodel/create/ColumnBuilder.java | 88 ++
.../metamodel/create/ColumnCreationBuilder.java | 32 +
.../create/ColumnCreationBuilderImpl.java | 63 ++
.../apache/metamodel/create/CreateTable.java | 67 ++
.../create/CreateTableColumnBuilder.java | 42 +
.../apache/metamodel/create/TableCreatable.java | 73 ++
.../metamodel/create/TableCreationBuilder.java | 77 ++
.../apache/metamodel/create/package-info.java | 23 +
.../apache/metamodel/data/AbstractDataSet.java | 171 ++++
.../org/apache/metamodel/data/AbstractRow.java | 176 ++++
.../metamodel/data/AbstractRowBuilder.java | 146 ++++
.../metamodel/data/CachingDataSetHeader.java | 96 +++
.../org/apache/metamodel/data/ColorImpl.java | 77 ++
.../java/org/apache/metamodel/data/DataSet.java | 99 +++
.../apache/metamodel/data/DataSetHeader.java | 41 +
.../apache/metamodel/data/DataSetIterator.java | 69 ++
.../metamodel/data/DataSetTableModel.java | 112 +++
.../org/apache/metamodel/data/DefaultRow.java | 205 +++++
.../org/apache/metamodel/data/EmptyDataSet.java | 59 ++
.../apache/metamodel/data/FilteredDataSet.java | 68 ++
.../apache/metamodel/data/FirstRowDataSet.java | 73 ++
.../org/apache/metamodel/data/IRowFilter.java | 37 +
.../apache/metamodel/data/InMemoryDataSet.java | 95 ++
.../apache/metamodel/data/MaxRowsDataSet.java | 56 ++
.../java/org/apache/metamodel/data/Row.java | 135 +++
.../org/apache/metamodel/data/RowBuilder.java | 119 +++
.../org/apache/metamodel/data/RowPublisher.java | 70 ++
.../metamodel/data/RowPublisherDataSet.java | 111 +++
.../apache/metamodel/data/RowPublisherImpl.java | 126 +++
.../metamodel/data/SimpleDataSetHeader.java | 132 +++
.../java/org/apache/metamodel/data/Style.java | 156 ++++
.../org/apache/metamodel/data/StyleBuilder.java | 355 ++++++++
.../org/apache/metamodel/data/StyleImpl.java | 177 ++++
.../metamodel/data/SubSelectionDataSet.java | 57 ++
.../metamodel/data/WhereClauseBuilder.java | 69 ++
.../org/apache/metamodel/data/package-info.java | 23 +
.../delete/AbstractRowDeletionBuilder.java | 135 +++
.../org/apache/metamodel/delete/DeleteFrom.java | 94 ++
.../apache/metamodel/delete/RowDeletable.java | 68 ++
.../metamodel/delete/RowDeletionBuilder.java | 57 ++
.../apache/metamodel/delete/package-info.java | 23 +
.../drop/AbstractTableDropBuilder.java | 51 ++
.../org/apache/metamodel/drop/DropTable.java | 68 ++
.../apache/metamodel/drop/TableDropBuilder.java | 49 ++
.../apache/metamodel/drop/TableDroppable.java | 44 +
.../org/apache/metamodel/drop/package-info.java | 23 +
.../insert/AbstractRowInsertionBuilder.java | 108 +++
.../org/apache/metamodel/insert/InsertInto.java | 77 ++
.../apache/metamodel/insert/RowInsertable.java | 92 ++
.../metamodel/insert/RowInsertionBuilder.java | 68 ++
.../apache/metamodel/insert/package-info.java | 23 +
.../metamodel/intercept/DataSetInterceptor.java | 31 +
.../InterceptableColumnCreationBuilder.java | 102 +++
.../intercept/InterceptableDataContext.java | 284 ++++++
.../InterceptableRowDeletionBuilder.java | 87 ++
.../InterceptableRowInsertionBuilder.java | 111 +++
.../InterceptableRowUpdationBuilder.java | 136 +++
.../InterceptableTableCreationBuilder.java | 69 ++
.../InterceptableTableDropBuilder.java | 53 ++
.../intercept/InterceptableUpdateCallback.java | 128 +++
.../intercept/InterceptableUpdateScript.java | 62 ++
.../apache/metamodel/intercept/Interceptor.java | 52 ++
.../metamodel/intercept/InterceptorList.java | 74 ++
.../metamodel/intercept/Interceptors.java | 35 +
.../metamodel/intercept/QueryInterceptor.java | 31 +
.../intercept/RowDeletionInterceptor.java | 31 +
.../intercept/RowInsertionInterceptor.java | 32 +
.../intercept/RowUpdationInterceptor.java | 32 +
.../metamodel/intercept/SchemaInterceptor.java | 31 +
.../intercept/TableCreationInterceptor.java | 32 +
.../intercept/TableDropInterceptor.java | 32 +
.../java/org/apache/metamodel/package-info.java | 23 +
.../metamodel/query/AbstractQueryClause.java | 163 ++++
.../query/AverageAggregateBuilder.java | 49 ++
.../apache/metamodel/query/CompiledQuery.java | 65 ++
.../metamodel/query/CountAggregateBuilder.java | 39 +
.../metamodel/query/DefaultCompiledQuery.java | 176 ++++
.../apache/metamodel/query/FilterClause.java | 88 ++
.../org/apache/metamodel/query/FilterItem.java | 542 ++++++++++++
.../org/apache/metamodel/query/FromClause.java | 103 +++
.../org/apache/metamodel/query/FromItem.java | 349 ++++++++
.../apache/metamodel/query/FunctionType.java | 122 +++
.../apache/metamodel/query/GroupByClause.java | 47 +
.../org/apache/metamodel/query/GroupByItem.java | 91 ++
.../org/apache/metamodel/query/JoinType.java | 29 +
.../apache/metamodel/query/LogicalOperator.java | 28 +
.../metamodel/query/MaxAggregateBuilder.java | 48 ++
.../metamodel/query/MinAggregateBuilder.java | 48 ++
.../apache/metamodel/query/OperatorType.java | 69 ++
.../apache/metamodel/query/OrderByClause.java | 49 ++
.../org/apache/metamodel/query/OrderByItem.java | 152 ++++
.../java/org/apache/metamodel/query/Query.java | 603 +++++++++++++
.../org/apache/metamodel/query/QueryClause.java | 53 ++
.../org/apache/metamodel/query/QueryItem.java | 39 +
.../apache/metamodel/query/QueryParameter.java | 37 +
.../apache/metamodel/query/SelectClause.java | 77 ++
.../org/apache/metamodel/query/SelectItem.java | 517 +++++++++++
.../metamodel/query/SumAggregateBuilder.java | 45 +
.../query/builder/AbstractFilterBuilder.java | 459 ++++++++++
.../builder/AbstractQueryFilterBuilder.java | 344 ++++++++
.../query/builder/ColumnSelectBuilder.java | 25 +
.../query/builder/ColumnSelectBuilderImpl.java | 54 ++
.../query/builder/CountSelectBuilder.java | 25 +
.../query/builder/CountSelectBuilderImpl.java | 51 ++
.../metamodel/query/builder/FilterBuilder.java | 355 ++++++++
.../query/builder/FunctionSelectBuilder.java | 25 +
.../builder/FunctionSelectBuilderImpl.java | 56 ++
.../query/builder/GroupedQueryBuilder.java | 37 +
.../builder/GroupedQueryBuilderCallback.java | 168 ++++
.../query/builder/GroupedQueryBuilderImpl.java | 332 +++++++
.../metamodel/query/builder/HavingBuilder.java | 26 +
.../query/builder/HavingBuilderImpl.java | 87 ++
.../query/builder/InitFromBuilder.java | 39 +
.../query/builder/InitFromBuilderImpl.java | 89 ++
.../query/builder/JoinFromBuilder.java | 26 +
.../query/builder/JoinFromBuilderImpl.java | 73 ++
.../query/builder/SatisfiedFromBuilder.java | 52 ++
.../builder/SatisfiedFromBuilderCallback.java | 161 ++++
.../query/builder/SatisfiedHavingBuilder.java | 29 +
.../query/builder/SatisfiedOrderByBuilder.java | 31 +
.../builder/SatisfiedOrderByBuilderImpl.java | 64 ++
.../query/builder/SatisfiedQueryBuilder.java | 133 +++
.../query/builder/SatisfiedSelectBuilder.java | 35 +
.../builder/SatisfiedSelectBuilderImpl.java | 67 ++
.../query/builder/SatisfiedWhereBuilder.java | 33 +
.../query/builder/TableFromBuilder.java | 33 +
.../query/builder/TableFromBuilderImpl.java | 83 ++
.../metamodel/query/builder/WhereBuilder.java | 86 ++
.../query/builder/WhereBuilderImpl.java | 151 ++++
.../metamodel/query/builder/package-info.java | 23 +
.../apache/metamodel/query/package-info.java | 23 +
.../metamodel/query/parser/FromItemParser.java | 173 ++++
.../query/parser/GroupByItemParser.java | 36 +
.../query/parser/HavingItemParser.java | 36 +
.../query/parser/OrderByItemParser.java | 36 +
.../metamodel/query/parser/QueryParser.java | 264 ++++++
.../query/parser/QueryParserException.java | 46 +
.../parser/QueryPartCollectionProcessor.java | 52 ++
.../metamodel/query/parser/QueryPartParser.java | 126 +++
.../query/parser/QueryPartProcessor.java | 38 +
.../query/parser/SelectItemParser.java | 170 ++++
.../metamodel/query/parser/WhereItemParser.java | 35 +
.../apache/metamodel/schema/AbstractColumn.java | 104 +++
.../metamodel/schema/AbstractRelationship.java | 119 +++
.../apache/metamodel/schema/AbstractSchema.java | 198 +++++
.../apache/metamodel/schema/AbstractTable.java | 329 +++++++
.../org/apache/metamodel/schema/Column.java | 108 +++
.../org/apache/metamodel/schema/ColumnType.java | 292 +++++++
.../metamodel/schema/CompositeSchema.java | 91 ++
.../metamodel/schema/ImmutableColumn.java | 173 ++++
.../metamodel/schema/ImmutableRelationship.java | 82 ++
.../metamodel/schema/ImmutableSchema.java | 72 ++
.../apache/metamodel/schema/ImmutableTable.java | 106 +++
.../org/apache/metamodel/schema/JdbcTypes.java | 69 ++
.../apache/metamodel/schema/MutableColumn.java | 185 ++++
.../metamodel/schema/MutableRelationship.java | 132 +++
.../apache/metamodel/schema/MutableSchema.java | 106 +++
.../apache/metamodel/schema/MutableTable.java | 202 +++++
.../apache/metamodel/schema/NamedStructure.java | 63 ++
.../apache/metamodel/schema/Relationship.java | 74 ++
.../org/apache/metamodel/schema/Schema.java | 121 +++
.../metamodel/schema/SuperColumnType.java | 53 ++
.../java/org/apache/metamodel/schema/Table.java | 215 +++++
.../org/apache/metamodel/schema/TableType.java | 70 ++
.../apache/metamodel/schema/package-info.java | 23 +
.../update/AbstractRowUpdationBuilder.java | 122 +++
.../apache/metamodel/update/RowUpdateable.java | 68 ++
.../metamodel/update/RowUpdationBuilder.java | 59 ++
.../org/apache/metamodel/update/Update.java | 122 +++
.../apache/metamodel/update/package-info.java | 23 +
.../java/org/apache/metamodel/util/Action.java | 34 +
.../apache/metamodel/util/AggregateBuilder.java | 35 +
.../metamodel/util/AlphabeticSequence.java | 86 ++
.../org/apache/metamodel/util/BaseObject.java | 166 ++++
.../metamodel/util/BooleanComparator.java | 162 ++++
.../metamodel/util/ClasspathResource.java | 145 ++++
.../apache/metamodel/util/CollectionUtils.java | 240 ++++++
.../org/apache/metamodel/util/ConstantFunc.java | 65 ++
.../org/apache/metamodel/util/DateUtils.java | 112 +++
.../apache/metamodel/util/EqualsBuilder.java | 99 +++
.../metamodel/util/ExclusionPredicate.java | 49 ++
.../apache/metamodel/util/FalsePredicate.java | 46 +
.../org/apache/metamodel/util/FileHelper.java | 460 ++++++++++
.../org/apache/metamodel/util/FileResource.java | 138 +++
.../org/apache/metamodel/util/FormatHelper.java | 273 ++++++
.../java/org/apache/metamodel/util/Func.java | 43 +
.../java/org/apache/metamodel/util/HasName.java | 29 +
.../apache/metamodel/util/HasNameMapper.java | 39 +
.../apache/metamodel/util/ImmutableDate.java | 63 ++
.../org/apache/metamodel/util/ImmutableRef.java | 45 +
.../apache/metamodel/util/InMemoryResource.java | 160 ++++
.../metamodel/util/InclusionPredicate.java | 50 ++
.../java/org/apache/metamodel/util/LazyRef.java | 127 +++
.../java/org/apache/metamodel/util/Month.java | 94 ++
.../org/apache/metamodel/util/MutableRef.java | 48 ++
.../apache/metamodel/util/NumberComparator.java | 107 +++
.../apache/metamodel/util/ObjectComparator.java | 102 +++
.../org/apache/metamodel/util/Predicate.java | 31 +
.../java/org/apache/metamodel/util/Ref.java | 32 +
.../org/apache/metamodel/util/Resource.java | 129 +++
.../metamodel/util/ResourceException.java | 50 ++
.../apache/metamodel/util/SerializableRef.java | 90 ++
.../metamodel/util/SharedExecutorService.java | 78 ++
.../apache/metamodel/util/SimpleTableDef.java | 203 +++++
.../apache/metamodel/util/TimeComparator.java | 207 +++++
.../metamodel/util/ToStringComparator.java | 69 ++
.../apache/metamodel/util/TruePredicate.java | 46 +
.../apache/metamodel/util/UnicodeWriter.java | 236 +++++
.../org/apache/metamodel/util/UrlResource.java | 150 ++++
.../java/org/apache/metamodel/util/Weekday.java | 83 ++
.../apache/metamodel/util/WildcardPattern.java | 69 ++
.../org/apache/metamodel/util/package-info.java | 23 +
.../eobjects/metamodel/AbstractDataContext.java | 463 ----------
.../metamodel/AbstractUpdateCallback.java | 164 ----
.../eobjects/metamodel/BatchUpdateScript.java | 29 -
.../metamodel/CompositeDataContext.java | 204 -----
.../metamodel/CompositeQueryDelegate.java | 49 --
.../org/eobjects/metamodel/DataContext.java | 199 -----
.../metamodel/DeleteAndInsertBuilder.java | 111 ---
.../InconsistentRowFormatException.java | 82 --
.../eobjects/metamodel/MetaModelException.java | 47 -
.../org/eobjects/metamodel/MetaModelHelper.java | 775 -----------------
.../metamodel/QueryPostprocessDataContext.java | 589 -------------
.../metamodel/QueryPostprocessDelegate.java | 45 -
.../metamodel/SchemaNameComparator.java | 58 --
.../org/eobjects/metamodel/UpdateCallback.java | 45 -
.../org/eobjects/metamodel/UpdateScript.java | 41 -
.../metamodel/UpdateableDataContext.java | 41 -
.../metamodel/convert/ColumnTypeDetector.java | 82 --
.../metamodel/convert/ConvertedDataSet.java | 74 --
.../convert/ConvertedDataSetInterceptor.java | 91 --
.../ConvertedRowInsertionInterceptor.java | 75 --
.../ConvertedRowUpdationInterceptor.java | 67 --
.../eobjects/metamodel/convert/Converters.java | 329 -------
.../convert/HasReadTypeConverters.java | 33 -
.../convert/StringToBooleanConverter.java | 54 --
.../convert/StringToDateConverter.java | 127 ---
.../convert/StringToDoubleConverter.java | 52 --
.../convert/StringToIntegerConverter.java | 52 --
.../metamodel/convert/TypeConverter.java | 54 --
.../metamodel/convert/package-info.java | 23 -
.../metamodel/create/AbstractColumnBuilder.java | 87 --
.../create/AbstractTableCreationBuilder.java | 135 ---
.../metamodel/create/ColumnBuilder.java | 88 --
.../metamodel/create/ColumnCreationBuilder.java | 32 -
.../create/ColumnCreationBuilderImpl.java | 63 --
.../eobjects/metamodel/create/CreateTable.java | 67 --
.../create/CreateTableColumnBuilder.java | 42 -
.../metamodel/create/TableCreatable.java | 73 --
.../metamodel/create/TableCreationBuilder.java | 77 --
.../eobjects/metamodel/create/package-info.java | 23 -
.../metamodel/data/AbstractDataSet.java | 171 ----
.../eobjects/metamodel/data/AbstractRow.java | 176 ----
.../metamodel/data/AbstractRowBuilder.java | 146 ----
.../metamodel/data/CachingDataSetHeader.java | 96 ---
.../org/eobjects/metamodel/data/ColorImpl.java | 77 --
.../org/eobjects/metamodel/data/DataSet.java | 99 ---
.../eobjects/metamodel/data/DataSetHeader.java | 41 -
.../metamodel/data/DataSetIterator.java | 69 --
.../metamodel/data/DataSetTableModel.java | 112 ---
.../org/eobjects/metamodel/data/DefaultRow.java | 205 -----
.../eobjects/metamodel/data/EmptyDataSet.java | 59 --
.../metamodel/data/FilteredDataSet.java | 68 --
.../metamodel/data/FirstRowDataSet.java | 73 --
.../org/eobjects/metamodel/data/IRowFilter.java | 37 -
.../metamodel/data/InMemoryDataSet.java | 95 --
.../eobjects/metamodel/data/MaxRowsDataSet.java | 56 --
.../java/org/eobjects/metamodel/data/Row.java | 135 ---
.../org/eobjects/metamodel/data/RowBuilder.java | 119 ---
.../eobjects/metamodel/data/RowPublisher.java | 70 --
.../metamodel/data/RowPublisherDataSet.java | 111 ---
.../metamodel/data/RowPublisherImpl.java | 126 ---
.../metamodel/data/SimpleDataSetHeader.java | 132 ---
.../java/org/eobjects/metamodel/data/Style.java | 156 ----
.../eobjects/metamodel/data/StyleBuilder.java | 355 --------
.../org/eobjects/metamodel/data/StyleImpl.java | 177 ----
.../metamodel/data/SubSelectionDataSet.java | 57 --
.../metamodel/data/WhereClauseBuilder.java | 69 --
.../eobjects/metamodel/data/package-info.java | 23 -
.../delete/AbstractRowDeletionBuilder.java | 135 ---
.../eobjects/metamodel/delete/DeleteFrom.java | 94 --
.../eobjects/metamodel/delete/RowDeletable.java | 68 --
.../metamodel/delete/RowDeletionBuilder.java | 57 --
.../eobjects/metamodel/delete/package-info.java | 23 -
.../drop/AbstractTableDropBuilder.java | 51 --
.../org/eobjects/metamodel/drop/DropTable.java | 68 --
.../metamodel/drop/TableDropBuilder.java | 49 --
.../eobjects/metamodel/drop/TableDroppable.java | 44 -
.../eobjects/metamodel/drop/package-info.java | 23 -
.../insert/AbstractRowInsertionBuilder.java | 108 ---
.../eobjects/metamodel/insert/InsertInto.java | 77 --
.../metamodel/insert/RowInsertable.java | 92 --
.../metamodel/insert/RowInsertionBuilder.java | 68 --
.../eobjects/metamodel/insert/package-info.java | 23 -
.../metamodel/intercept/DataSetInterceptor.java | 31 -
.../InterceptableColumnCreationBuilder.java | 102 ---
.../intercept/InterceptableDataContext.java | 284 ------
.../InterceptableRowDeletionBuilder.java | 87 --
.../InterceptableRowInsertionBuilder.java | 111 ---
.../InterceptableRowUpdationBuilder.java | 136 ---
.../InterceptableTableCreationBuilder.java | 69 --
.../InterceptableTableDropBuilder.java | 53 --
.../intercept/InterceptableUpdateCallback.java | 128 ---
.../intercept/InterceptableUpdateScript.java | 62 --
.../metamodel/intercept/Interceptor.java | 52 --
.../metamodel/intercept/InterceptorList.java | 74 --
.../metamodel/intercept/Interceptors.java | 35 -
.../metamodel/intercept/QueryInterceptor.java | 31 -
.../intercept/RowDeletionInterceptor.java | 31 -
.../intercept/RowInsertionInterceptor.java | 32 -
.../intercept/RowUpdationInterceptor.java | 32 -
.../metamodel/intercept/SchemaInterceptor.java | 31 -
.../intercept/TableCreationInterceptor.java | 32 -
.../intercept/TableDropInterceptor.java | 32 -
.../org/eobjects/metamodel/package-info.java | 23 -
.../metamodel/query/AbstractQueryClause.java | 163 ----
.../query/AverageAggregateBuilder.java | 49 --
.../eobjects/metamodel/query/CompiledQuery.java | 65 --
.../metamodel/query/CountAggregateBuilder.java | 39 -
.../metamodel/query/DefaultCompiledQuery.java | 176 ----
.../eobjects/metamodel/query/FilterClause.java | 88 --
.../eobjects/metamodel/query/FilterItem.java | 542 ------------
.../eobjects/metamodel/query/FromClause.java | 103 ---
.../org/eobjects/metamodel/query/FromItem.java | 349 --------
.../eobjects/metamodel/query/FunctionType.java | 122 ---
.../eobjects/metamodel/query/GroupByClause.java | 47 -
.../eobjects/metamodel/query/GroupByItem.java | 91 --
.../org/eobjects/metamodel/query/JoinType.java | 29 -
.../metamodel/query/LogicalOperator.java | 28 -
.../metamodel/query/MaxAggregateBuilder.java | 48 --
.../metamodel/query/MinAggregateBuilder.java | 48 --
.../eobjects/metamodel/query/OperatorType.java | 69 --
.../eobjects/metamodel/query/OrderByClause.java | 49 --
.../eobjects/metamodel/query/OrderByItem.java | 152 ----
.../org/eobjects/metamodel/query/Query.java | 603 -------------
.../eobjects/metamodel/query/QueryClause.java | 53 --
.../org/eobjects/metamodel/query/QueryItem.java | 39 -
.../metamodel/query/QueryParameter.java | 37 -
.../eobjects/metamodel/query/SelectClause.java | 77 --
.../eobjects/metamodel/query/SelectItem.java | 517 -----------
.../metamodel/query/SumAggregateBuilder.java | 45 -
.../query/builder/AbstractFilterBuilder.java | 459 ----------
.../builder/AbstractQueryFilterBuilder.java | 344 --------
.../query/builder/ColumnSelectBuilder.java | 25 -
.../query/builder/ColumnSelectBuilderImpl.java | 54 --
.../query/builder/CountSelectBuilder.java | 25 -
.../query/builder/CountSelectBuilderImpl.java | 51 --
.../metamodel/query/builder/FilterBuilder.java | 355 --------
.../query/builder/FunctionSelectBuilder.java | 25 -
.../builder/FunctionSelectBuilderImpl.java | 56 --
.../query/builder/GroupedQueryBuilder.java | 37 -
.../builder/GroupedQueryBuilderCallback.java | 168 ----
.../query/builder/GroupedQueryBuilderImpl.java | 332 -------
.../metamodel/query/builder/HavingBuilder.java | 26 -
.../query/builder/HavingBuilderImpl.java | 87 --
.../query/builder/InitFromBuilder.java | 39 -
.../query/builder/InitFromBuilderImpl.java | 89 --
.../query/builder/JoinFromBuilder.java | 26 -
.../query/builder/JoinFromBuilderImpl.java | 73 --
.../query/builder/SatisfiedFromBuilder.java | 52 --
.../builder/SatisfiedFromBuilderCallback.java | 161 ----
.../query/builder/SatisfiedHavingBuilder.java | 29 -
.../query/builder/SatisfiedOrderByBuilder.java | 31 -
.../builder/SatisfiedOrderByBuilderImpl.java | 64 --
.../query/builder/SatisfiedQueryBuilder.java | 133 ---
.../query/builder/SatisfiedSelectBuilder.java | 35 -
.../builder/SatisfiedSelectBuilderImpl.java | 67 --
.../query/builder/SatisfiedWhereBuilder.java | 33 -
.../query/builder/TableFromBuilder.java | 33 -
.../query/builder/TableFromBuilderImpl.java | 83 --
.../metamodel/query/builder/WhereBuilder.java | 86 --
.../query/builder/WhereBuilderImpl.java | 151 ----
.../metamodel/query/builder/package-info.java | 23 -
.../eobjects/metamodel/query/package-info.java | 23 -
.../metamodel/query/parser/FromItemParser.java | 173 ----
.../query/parser/GroupByItemParser.java | 36 -
.../query/parser/HavingItemParser.java | 36 -
.../query/parser/OrderByItemParser.java | 36 -
.../metamodel/query/parser/QueryParser.java | 264 ------
.../query/parser/QueryParserException.java | 46 -
.../parser/QueryPartCollectionProcessor.java | 52 --
.../metamodel/query/parser/QueryPartParser.java | 126 ---
.../query/parser/QueryPartProcessor.java | 38 -
.../query/parser/SelectItemParser.java | 170 ----
.../metamodel/query/parser/WhereItemParser.java | 35 -
.../metamodel/schema/AbstractColumn.java | 104 ---
.../metamodel/schema/AbstractRelationship.java | 119 ---
.../metamodel/schema/AbstractSchema.java | 198 -----
.../metamodel/schema/AbstractTable.java | 329 -------
.../org/eobjects/metamodel/schema/Column.java | 108 ---
.../eobjects/metamodel/schema/ColumnType.java | 292 -------
.../metamodel/schema/CompositeSchema.java | 91 --
.../metamodel/schema/ImmutableColumn.java | 173 ----
.../metamodel/schema/ImmutableRelationship.java | 82 --
.../metamodel/schema/ImmutableSchema.java | 72 --
.../metamodel/schema/ImmutableTable.java | 106 ---
.../eobjects/metamodel/schema/JdbcTypes.java | 69 --
.../metamodel/schema/MutableColumn.java | 185 ----
.../metamodel/schema/MutableRelationship.java | 132 ---
.../metamodel/schema/MutableSchema.java | 106 ---
.../eobjects/metamodel/schema/MutableTable.java | 202 -----
.../metamodel/schema/NamedStructure.java | 63 --
.../eobjects/metamodel/schema/Relationship.java | 74 --
.../org/eobjects/metamodel/schema/Schema.java | 121 ---
.../metamodel/schema/SuperColumnType.java | 53 --
.../org/eobjects/metamodel/schema/Table.java | 215 -----
.../eobjects/metamodel/schema/TableType.java | 70 --
.../eobjects/metamodel/schema/package-info.java | 23 -
.../update/AbstractRowUpdationBuilder.java | 122 ---
.../metamodel/update/RowUpdateable.java | 68 --
.../metamodel/update/RowUpdationBuilder.java | 59 --
.../org/eobjects/metamodel/update/Update.java | 122 ---
.../eobjects/metamodel/update/package-info.java | 23 -
.../org/eobjects/metamodel/util/Action.java | 34 -
.../metamodel/util/AggregateBuilder.java | 35 -
.../metamodel/util/AlphabeticSequence.java | 86 --
.../org/eobjects/metamodel/util/BaseObject.java | 166 ----
.../metamodel/util/BooleanComparator.java | 162 ----
.../metamodel/util/ClasspathResource.java | 145 ----
.../metamodel/util/CollectionUtils.java | 240 ------
.../eobjects/metamodel/util/ConstantFunc.java | 65 --
.../org/eobjects/metamodel/util/DateUtils.java | 112 ---
.../eobjects/metamodel/util/EqualsBuilder.java | 99 ---
.../metamodel/util/ExclusionPredicate.java | 49 --
.../eobjects/metamodel/util/FalsePredicate.java | 46 -
.../org/eobjects/metamodel/util/FileHelper.java | 460 ----------
.../eobjects/metamodel/util/FileResource.java | 138 ---
.../eobjects/metamodel/util/FormatHelper.java | 273 ------
.../java/org/eobjects/metamodel/util/Func.java | 43 -
.../org/eobjects/metamodel/util/HasName.java | 29 -
.../eobjects/metamodel/util/HasNameMapper.java | 39 -
.../eobjects/metamodel/util/ImmutableDate.java | 63 --
.../eobjects/metamodel/util/ImmutableRef.java | 45 -
.../metamodel/util/InMemoryResource.java | 160 ----
.../metamodel/util/InclusionPredicate.java | 50 --
.../org/eobjects/metamodel/util/LazyRef.java | 127 ---
.../java/org/eobjects/metamodel/util/Month.java | 94 --
.../org/eobjects/metamodel/util/MutableRef.java | 48 --
.../metamodel/util/NumberComparator.java | 107 ---
.../metamodel/util/ObjectComparator.java | 102 ---
.../org/eobjects/metamodel/util/Predicate.java | 31 -
.../java/org/eobjects/metamodel/util/Ref.java | 32 -
.../org/eobjects/metamodel/util/Resource.java | 129 ---
.../metamodel/util/ResourceException.java | 50 --
.../metamodel/util/SerializableRef.java | 90 --
.../metamodel/util/SharedExecutorService.java | 78 --
.../eobjects/metamodel/util/SimpleTableDef.java | 203 -----
.../eobjects/metamodel/util/TimeComparator.java | 207 -----
.../metamodel/util/ToStringComparator.java | 69 --
.../eobjects/metamodel/util/TruePredicate.java | 46 -
.../eobjects/metamodel/util/UnicodeWriter.java | 236 -----
.../eobjects/metamodel/util/UrlResource.java | 150 ----
.../org/eobjects/metamodel/util/Weekday.java | 83 --
.../metamodel/util/WildcardPattern.java | 69 --
.../eobjects/metamodel/util/package-info.java | 23 -
.../metamodel/AbstractDataContextTest.java | 247 ++++++
.../metamodel/CompositeDataContextTest.java | 117 +++
.../apache/metamodel/MetaModelHelperTest.java | 327 +++++++
.../org/apache/metamodel/MetaModelTestCase.java | 199 +++++
.../org/apache/metamodel/MockDataContext.java | 99 +++
.../metamodel/MockUpdateableDataContext.java | 181 ++++
.../QueryPostprocessDataContextTest.java | 861 +++++++++++++++++++
.../metamodel/SchemaNameComparatorTest.java | 40 +
.../convert/ColumnTypeDetectorTest.java | 72 ++
.../ConvertedDataSetInterceptorTest.java | 92 ++
.../ConvertedRowInsertionInterceptorTest.java | 61 ++
.../metamodel/convert/ConvertersTest.java | 160 ++++
.../convert/StringToBooleanConverterTest.java | 37 +
.../convert/StringToDateConverterTest.java | 66 ++
.../convert/StringToDoubleConverterTest.java | 39 +
.../convert/StringToIntegerConverterTest.java | 37 +
.../create/AbstractCreateTableBuilderTest.java | 110 +++
.../metamodel/create/SyntaxExamplesTest.java | 38 +
.../metamodel/data/DataSetIteratorTest.java | 74 ++
.../metamodel/data/DataSetTableModelTest.java | 57 ++
.../apache/metamodel/data/DefaultRowTest.java | 109 +++
.../metamodel/data/FirstRowDataSetTest.java | 83 ++
.../metamodel/data/RowPublisherDataSetTest.java | 89 ++
.../java/org/apache/metamodel/data/RowTest.java | 57 ++
.../apache/metamodel/data/StyleBuilderTest.java | 60 ++
.../delete/AbstractRowDeletionCallbackTest.java | 76 ++
.../insert/AbstractInsertBuilderTest.java | 92 ++
.../metamodel/insert/SyntaxExamplesTest.java | 44 +
.../intercept/InterceptableDataContextTest.java | 113 +++
.../intercept/InterceptorListTest.java | 61 ++
.../metamodel/intercept/InterceptorsTest.java | 33 +
.../query/DefaultCompiledQueryTest.java | 92 ++
.../apache/metamodel/query/FilterItemTest.java | 413 +++++++++
.../apache/metamodel/query/FromClauseTest.java | 46 +
.../apache/metamodel/query/FromItemTest.java | 101 +++
.../metamodel/query/FunctionTypeTest.java | 42 +
.../apache/metamodel/query/GroupByItemTest.java | 42 +
.../metamodel/query/OperatorTypeTest.java | 34 +
.../apache/metamodel/query/OrderByItemTest.java | 33 +
.../org/apache/metamodel/query/QueryTest.java | 245 ++++++
.../metamodel/query/SelectClauseTest.java | 41 +
.../apache/metamodel/query/SelectItemTest.java | 99 +++
.../builder/GroupedQueryBuilderImplTest.java | 108 +++
.../query/builder/SyntaxExamplesTest.java | 80 ++
.../query/builder/WhereBuilderImplTest.java | 81 ++
.../metamodel/query/parser/QueryParserTest.java | 320 +++++++
.../query/parser/QueryPartParserTest.java | 110 +++
.../apache/metamodel/schema/ColumnTypeTest.java | 92 ++
.../apache/metamodel/schema/DataTypeTest.java | 28 +
.../metamodel/schema/ImmutableSchemaTest.java | 35 +
.../org/apache/metamodel/schema/Java5Types.java | 246 ++++++
.../org/apache/metamodel/schema/Java6Types.java | 297 +++++++
.../apache/metamodel/schema/JavaTypesTest.java | 50 ++
.../metamodel/schema/MutableColumnTest.java | 66 ++
.../metamodel/schema/MutableSchemaTest.java | 61 ++
.../metamodel/schema/MutableTableTest.java | 96 +++
.../metamodel/schema/SchemaModelTest.java | 104 +++
.../apache/metamodel/schema/TableTypeTest.java | 38 +
.../metamodel/util/AlphabeticSequenceTest.java | 69 ++
.../apache/metamodel/util/BaseObjectTest.java | 49 ++
.../metamodel/util/BooleanComparatorTest.java | 53 ++
.../metamodel/util/ClasspathResourceTest.java | 46 +
.../metamodel/util/CollectionUtilsTest.java | 128 +++
.../apache/metamodel/util/DateUtilsTest.java | 41 +
.../metamodel/util/EqualsBuilderTest.java | 53 ++
.../metamodel/util/ExclusionPredicateTest.java | 36 +
.../apache/metamodel/util/FileHelperTest.java | 78 ++
.../apache/metamodel/util/FormatHelperTest.java | 63 ++
.../metamodel/util/InMemoryResourceTest.java | 79 ++
.../metamodel/util/InclusionPredicateTest.java | 36 +
.../org/apache/metamodel/util/LazyRefTest.java | 91 ++
.../org/apache/metamodel/util/MonthTest.java | 38 +
.../metamodel/util/NumberComparatorTest.java | 37 +
.../metamodel/util/ObjectComparatorTest.java | 63 ++
.../metamodel/util/SerializableRefTest.java | 61 ++
.../apache/metamodel/util/SimpleRefTest.java | 35 +
.../metamodel/util/TimeComparatorTest.java | 79 ++
.../metamodel/util/ToStringComparatorTest.java | 51 ++
.../apache/metamodel/util/UrlResourceTest.java | 32 +
.../org/apache/metamodel/util/WeekdayTest.java | 38 +
.../metamodel/util/WildcardPatternTest.java | 45 +
.../metamodel/AbstractDataContextTest.java | 247 ------
.../metamodel/CompositeDataContextTest.java | 117 ---
.../eobjects/metamodel/MetaModelHelperTest.java | 327 -------
.../eobjects/metamodel/MetaModelTestCase.java | 199 -----
.../org/eobjects/metamodel/MockDataContext.java | 99 ---
.../metamodel/MockUpdateableDataContext.java | 181 ----
.../QueryPostprocessDataContextTest.java | 861 -------------------
.../metamodel/SchemaNameComparatorTest.java | 40 -
.../convert/ColumnTypeDetectorTest.java | 72 --
.../ConvertedDataSetInterceptorTest.java | 92 --
.../ConvertedRowInsertionInterceptorTest.java | 61 --
.../metamodel/convert/ConvertersTest.java | 160 ----
.../convert/StringToBooleanConverterTest.java | 37 -
.../convert/StringToDateConverterTest.java | 66 --
.../convert/StringToDoubleConverterTest.java | 39 -
.../convert/StringToIntegerConverterTest.java | 37 -
.../create/AbstractCreateTableBuilderTest.java | 110 ---
.../metamodel/create/SyntaxExamplesTest.java | 38 -
.../metamodel/data/DataSetIteratorTest.java | 74 --
.../metamodel/data/DataSetTableModelTest.java | 57 --
.../eobjects/metamodel/data/DefaultRowTest.java | 109 ---
.../metamodel/data/FirstRowDataSetTest.java | 83 --
.../metamodel/data/RowPublisherDataSetTest.java | 89 --
.../org/eobjects/metamodel/data/RowTest.java | 57 --
.../metamodel/data/StyleBuilderTest.java | 60 --
.../delete/AbstractRowDeletionCallbackTest.java | 76 --
.../insert/AbstractInsertBuilderTest.java | 92 --
.../metamodel/insert/SyntaxExamplesTest.java | 44 -
.../intercept/InterceptableDataContextTest.java | 113 ---
.../intercept/InterceptorListTest.java | 61 --
.../metamodel/intercept/InterceptorsTest.java | 33 -
.../query/DefaultCompiledQueryTest.java | 92 --
.../metamodel/query/FilterItemTest.java | 413 ---------
.../metamodel/query/FromClauseTest.java | 46 -
.../eobjects/metamodel/query/FromItemTest.java | 101 ---
.../metamodel/query/FunctionTypeTest.java | 42 -
.../metamodel/query/GroupByItemTest.java | 42 -
.../metamodel/query/OperatorTypeTest.java | 34 -
.../metamodel/query/OrderByItemTest.java | 33 -
.../org/eobjects/metamodel/query/QueryTest.java | 245 ------
.../metamodel/query/SelectClauseTest.java | 41 -
.../metamodel/query/SelectItemTest.java | 99 ---
.../builder/GroupedQueryBuilderImplTest.java | 108 ---
.../query/builder/SyntaxExamplesTest.java | 80 --
.../query/builder/WhereBuilderImplTest.java | 81 --
.../metamodel/query/parser/QueryParserTest.java | 320 -------
.../query/parser/QueryPartParserTest.java | 110 ---
.../metamodel/schema/ColumnTypeTest.java | 92 --
.../eobjects/metamodel/schema/DataTypeTest.java | 28 -
.../metamodel/schema/ImmutableSchemaTest.java | 35 -
.../eobjects/metamodel/schema/Java5Types.java | 246 ------
.../eobjects/metamodel/schema/Java6Types.java | 297 -------
.../metamodel/schema/JavaTypesTest.java | 50 --
.../metamodel/schema/MutableColumnTest.java | 66 --
.../metamodel/schema/MutableSchemaTest.java | 61 --
.../metamodel/schema/MutableTableTest.java | 96 ---
.../metamodel/schema/SchemaModelTest.java | 104 ---
.../metamodel/schema/TableTypeTest.java | 38 -
.../metamodel/util/AlphabeticSequenceTest.java | 69 --
.../eobjects/metamodel/util/BaseObjectTest.java | 49 --
.../metamodel/util/BooleanComparatorTest.java | 53 --
.../metamodel/util/ClasspathResourceTest.java | 46 -
.../metamodel/util/CollectionUtilsTest.java | 128 ---
.../eobjects/metamodel/util/DateUtilsTest.java | 41 -
.../metamodel/util/EqualsBuilderTest.java | 53 --
.../metamodel/util/ExclusionPredicateTest.java | 36 -
.../eobjects/metamodel/util/FileHelperTest.java | 78 --
.../metamodel/util/FormatHelperTest.java | 63 --
.../metamodel/util/InMemoryResourceTest.java | 79 --
.../metamodel/util/InclusionPredicateTest.java | 36 -
.../eobjects/metamodel/util/LazyRefTest.java | 91 --
.../org/eobjects/metamodel/util/MonthTest.java | 38 -
.../metamodel/util/NumberComparatorTest.java | 37 -
.../metamodel/util/ObjectComparatorTest.java | 63 --
.../metamodel/util/SerializableRefTest.java | 61 --
.../eobjects/metamodel/util/SimpleRefTest.java | 35 -
.../metamodel/util/TimeComparatorTest.java | 79 --
.../metamodel/util/ToStringComparatorTest.java | 51 --
.../metamodel/util/UrlResourceTest.java | 32 -
.../eobjects/metamodel/util/WeekdayTest.java | 38 -
.../metamodel/util/WildcardPatternTest.java | 45 -
.../metamodel/couchdb/CouchDbDataContext.java | 254 ++++++
.../metamodel/couchdb/CouchDbDataSet.java | 123 +++
.../couchdb/CouchDbInsertionBuilder.java | 54 ++
.../couchdb/CouchDbRowDeletionBuilder.java | 62 ++
.../couchdb/CouchDbRowUpdationBuilder.java | 79 ++
.../couchdb/CouchDbTableCreationBuilder.java | 75 ++
.../couchdb/CouchDbTableDropBuilder.java | 46 +
.../couchdb/CouchDbUpdateCallback.java | 143 +++
.../apache/metamodel/couchdb/package-info.java | 23 +
.../metamodel/couchdb/CouchDbDataContext.java | 254 ------
.../metamodel/couchdb/CouchDbDataSet.java | 123 ---
.../couchdb/CouchDbInsertionBuilder.java | 54 --
.../couchdb/CouchDbRowDeletionBuilder.java | 62 --
.../couchdb/CouchDbRowUpdationBuilder.java | 79 --
.../couchdb/CouchDbTableCreationBuilder.java | 75 --
.../couchdb/CouchDbTableDropBuilder.java | 46 -
.../couchdb/CouchDbUpdateCallback.java | 143 ---
.../metamodel/couchdb/package-info.java | 23 -
.../couchdb/CouchDbDataContextTest.java | 354 ++++++++
.../couchdb/CouchDbDataContextTest.java | 354 --------
.../apache/metamodel/csv/CsvConfiguration.java | 160 ++++
.../metamodel/csv/CsvCreateTableBuilder.java | 51 ++
.../apache/metamodel/csv/CsvDataContext.java | 393 +++++++++
.../org/apache/metamodel/csv/CsvDataSet.java | 127 +++
.../apache/metamodel/csv/CsvDeleteBuilder.java | 103 +++
.../apache/metamodel/csv/CsvInsertBuilder.java | 40 +
.../org/apache/metamodel/csv/CsvSchema.java | 63 ++
.../java/org/apache/metamodel/csv/CsvTable.java | 149 ++++
.../metamodel/csv/CsvTableDropBuilder.java | 38 +
.../apache/metamodel/csv/CsvUpdateCallback.java | 249 ++++++
.../org/apache/metamodel/csv/CsvWriter.java | 94 ++
.../csv/InconsistentRowLengthException.java | 101 +++
.../org/apache/metamodel/csv/package-info.java | 23 +
.../metamodel/csv/CsvConfiguration.java | 160 ----
.../metamodel/csv/CsvCreateTableBuilder.java | 51 --
.../eobjects/metamodel/csv/CsvDataContext.java | 393 ---------
.../org/eobjects/metamodel/csv/CsvDataSet.java | 127 ---
.../metamodel/csv/CsvDeleteBuilder.java | 103 ---
.../metamodel/csv/CsvInsertBuilder.java | 40 -
.../org/eobjects/metamodel/csv/CsvSchema.java | 63 --
.../org/eobjects/metamodel/csv/CsvTable.java | 149 ----
.../metamodel/csv/CsvTableDropBuilder.java | 38 -
.../metamodel/csv/CsvUpdateCallback.java | 249 ------
.../org/eobjects/metamodel/csv/CsvWriter.java | 94 --
.../csv/InconsistentRowLengthException.java | 101 ---
.../eobjects/metamodel/csv/package-info.java | 23 -
.../metamodel/csv/CsvBigFileMemoryTest.java | 103 +++
.../metamodel/csv/CsvConfigurationTest.java | 46 +
.../metamodel/csv/CsvDataContextTest.java | 744 ++++++++++++++++
.../csv/DefaultExampleValueGenerator.java | 31 +
.../metamodel/csv/ExampleDataGenerator.java | 96 +++
.../metamodel/csv/ExampleValueGenerator.java | 27 +
.../csv/RandomizedExampleValueGenerator.java | 92 ++
.../apache/metamodel/csv/UnicodeWriterTest.java | 51 ++
.../InterceptionCsvIntegrationTest.java | 85 ++
.../metamodel/csv/CsvBigFileMemoryTest.java | 103 ---
.../metamodel/csv/CsvConfigurationTest.java | 46 -
.../metamodel/csv/CsvDataContextTest.java | 744 ----------------
.../csv/DefaultExampleValueGenerator.java | 31 -
.../metamodel/csv/ExampleDataGenerator.java | 96 ---
.../metamodel/csv/ExampleValueGenerator.java | 27 -
.../csv/RandomizedExampleValueGenerator.java | 92 --
.../metamodel/csv/UnicodeWriterTest.java | 51 --
.../InterceptionCsvIntegrationTest.java | 85 --
.../excel/DefaultSpreadsheetReaderDelegate.java | 212 +++++
.../metamodel/excel/ExcelConfiguration.java | 101 +++
.../metamodel/excel/ExcelDataContext.java | 259 ++++++
.../metamodel/excel/ExcelDeleteBuilder.java | 81 ++
.../metamodel/excel/ExcelDropTableBuilder.java | 44 +
.../metamodel/excel/ExcelInsertBuilder.java | 181 ++++
.../excel/ExcelTableCreationBuilder.java | 65 ++
.../metamodel/excel/ExcelUpdateCallback.java | 238 +++++
.../org/apache/metamodel/excel/ExcelUtils.java | 419 +++++++++
.../excel/SpreadsheetReaderDelegate.java | 45 +
.../org/apache/metamodel/excel/XlsDataSet.java | 78 ++
.../apache/metamodel/excel/XlsxRowCallback.java | 33 +
.../metamodel/excel/XlsxRowPublisherAction.java | 103 +++
.../metamodel/excel/XlsxSheetToRowsHandler.java | 341 ++++++++
.../excel/XlsxSpreadsheetReaderDelegate.java | 192 +++++
.../excel/XlsxStopParsingException.java | 33 +
.../excel/XlsxWorkbookToTablesHandler.java | 66 ++
.../metamodel/excel/ZeroBasedRowIterator.java | 58 ++
.../apache/metamodel/excel/package-info.java | 23 +
.../excel/DefaultSpreadsheetReaderDelegate.java | 212 -----
.../metamodel/excel/ExcelConfiguration.java | 101 ---
.../metamodel/excel/ExcelDataContext.java | 259 ------
.../metamodel/excel/ExcelDeleteBuilder.java | 81 --
.../metamodel/excel/ExcelDropTableBuilder.java | 44 -
.../metamodel/excel/ExcelInsertBuilder.java | 181 ----
.../excel/ExcelTableCreationBuilder.java | 65 --
.../metamodel/excel/ExcelUpdateCallback.java | 238 -----
.../eobjects/metamodel/excel/ExcelUtils.java | 419 ---------
.../excel/SpreadsheetReaderDelegate.java | 45 -
.../eobjects/metamodel/excel/XlsDataSet.java | 78 --
.../metamodel/excel/XlsxRowCallback.java | 33 -
.../metamodel/excel/XlsxRowPublisherAction.java | 103 ---
.../metamodel/excel/XlsxSheetToRowsHandler.java | 341 --------
.../excel/XlsxSpreadsheetReaderDelegate.java | 192 -----
.../excel/XlsxStopParsingException.java | 33 -
.../excel/XlsxWorkbookToTablesHandler.java | 66 --
.../metamodel/excel/ZeroBasedRowIterator.java | 58 --
.../eobjects/metamodel/excel/package-info.java | 23 -
.../DefaultSpreadsheetReaderDelegateTest.java | 244 ++++++
.../metamodel/excel/ExcelConfigurationTest.java | 42 +
.../metamodel/excel/ExcelDataContextTest.java | 741 ++++++++++++++++
.../excel/ExcelUpdateCallbackTest.java | 103 +++
.../excel/ZeroBasedRowIteratorTest.java | 75 ++
.../DefaultSpreadsheetReaderDelegateTest.java | 244 ------
.../metamodel/excel/ExcelConfigurationTest.java | 42 -
.../metamodel/excel/ExcelDataContextTest.java | 741 ----------------
.../excel/ExcelUpdateCallbackTest.java | 103 ---
.../excel/ZeroBasedRowIteratorTest.java | 75 --
.../fixedwidth/FixedWidthConfiguration.java | 151 ++++
.../fixedwidth/FixedWidthDataContext.java | 192 +++++
.../metamodel/fixedwidth/FixedWidthDataSet.java | 115 +++
.../metamodel/fixedwidth/FixedWidthReader.java | 188 ++++
.../InconsistentValueWidthException.java | 67 ++
.../metamodel/fixedwidth/package-info.java | 23 +
.../fixedwidth/FixedWidthConfiguration.java | 151 ----
.../fixedwidth/FixedWidthDataContext.java | 192 -----
.../metamodel/fixedwidth/FixedWidthDataSet.java | 115 ---
.../metamodel/fixedwidth/FixedWidthReader.java | 188 ----
.../InconsistentValueWidthException.java | 67 --
.../metamodel/fixedwidth/package-info.java | 23 -
.../fixedwidth/FixedWidthConfigurationTest.java | 44 +
.../fixedwidth/FixedWidthDataContextTest.java | 227 +++++
.../fixedwidth/FixedWidthConfigurationTest.java | 44 -
.../fixedwidth/FixedWidthDataContextTest.java | 227 -----
.../apache/metamodel/DataContextFactory.java | 591 +++++++++++++
.../eobjects/metamodel/DataContextFactory.java | 591 -------------
.../metamodel/DataContextFactoryTest.java | 46 +
.../metamodel/DataContextFactoryTest.java | 46 -
.../metamodel/jdbc/FetchSizeCalculator.java | 264 ++++++
.../metamodel/jdbc/JdbcBatchUpdateCallback.java | 76 ++
.../org/apache/metamodel/jdbc/JdbcColumn.java | 55 ++
.../metamodel/jdbc/JdbcCompiledQuery.java | 140 +++
.../metamodel/jdbc/JdbcCompiledQueryLease.java | 48 ++
.../jdbc/JdbcCompiledQueryLeaseFactory.java | 71 ++
.../metamodel/jdbc/JdbcCreateTableBuilder.java | 127 +++
.../apache/metamodel/jdbc/JdbcDataContext.java | 794 +++++++++++++++++
.../org/apache/metamodel/jdbc/JdbcDataSet.java | 229 +++++
.../metamodel/jdbc/JdbcDeleteBuilder.java | 98 +++
.../metamodel/jdbc/JdbcDropTableBuilder.java | 72 ++
.../metamodel/jdbc/JdbcInsertBuilder.java | 151 ++++
.../metamodel/jdbc/JdbcMetadataLoader.java | 427 +++++++++
.../org/apache/metamodel/jdbc/JdbcSchema.java | 71 ++
.../jdbc/JdbcSimpleUpdateCallback.java | 49 ++
.../org/apache/metamodel/jdbc/JdbcTable.java | 84 ++
.../metamodel/jdbc/JdbcUpdateBuilder.java | 153 ++++
.../metamodel/jdbc/JdbcUpdateCallback.java | 216 +++++
.../org/apache/metamodel/jdbc/JdbcUtils.java | 265 ++++++
.../apache/metamodel/jdbc/MetadataLoader.java | 36 +
.../apache/metamodel/jdbc/QuerySplitter.java | 336 ++++++++
.../metamodel/jdbc/SplitQueriesDataSet.java | 106 +++
.../org/apache/metamodel/jdbc/SqlKeywords.java | 51 ++
.../jdbc/dialects/AbstractQueryRewriter.java | 259 ++++++
.../jdbc/dialects/DB2QueryRewriter.java | 161 ++++
.../jdbc/dialects/DefaultQueryRewriter.java | 146 ++++
.../jdbc/dialects/H2QueryRewriter.java | 31 +
.../jdbc/dialects/HsqldbQueryRewriter.java | 99 +++
.../metamodel/jdbc/dialects/IQueryRewriter.java | 93 ++
.../jdbc/dialects/LimitOffsetQueryRewriter.java | 71 ++
.../jdbc/dialects/MysqlQueryRewriter.java | 36 +
.../jdbc/dialects/PostgresqlQueryRewriter.java | 70 ++
.../jdbc/dialects/SQLServerQueryRewriter.java | 56 ++
.../org/apache/metamodel/jdbc/package-info.java | 23 +
.../metamodel/jdbc/FetchSizeCalculator.java | 264 ------
.../metamodel/jdbc/JdbcBatchUpdateCallback.java | 76 --
.../org/eobjects/metamodel/jdbc/JdbcColumn.java | 55 --
.../metamodel/jdbc/JdbcCompiledQuery.java | 140 ---
.../metamodel/jdbc/JdbcCompiledQueryLease.java | 48 --
.../jdbc/JdbcCompiledQueryLeaseFactory.java | 71 --
.../metamodel/jdbc/JdbcCreateTableBuilder.java | 127 ---
.../metamodel/jdbc/JdbcDataContext.java | 794 -----------------
.../eobjects/metamodel/jdbc/JdbcDataSet.java | 229 -----
.../metamodel/jdbc/JdbcDeleteBuilder.java | 98 ---
.../metamodel/jdbc/JdbcDropTableBuilder.java | 72 --
.../metamodel/jdbc/JdbcInsertBuilder.java | 151 ----
.../metamodel/jdbc/JdbcMetadataLoader.java | 427 ---------
.../org/eobjects/metamodel/jdbc/JdbcSchema.java | 71 --
.../jdbc/JdbcSimpleUpdateCallback.java | 49 --
.../org/eobjects/metamodel/jdbc/JdbcTable.java | 84 --
.../metamodel/jdbc/JdbcUpdateBuilder.java | 153 ----
.../metamodel/jdbc/JdbcUpdateCallback.java | 216 -----
.../org/eobjects/metamodel/jdbc/JdbcUtils.java | 265 ------
.../eobjects/metamodel/jdbc/MetadataLoader.java | 36 -
.../eobjects/metamodel/jdbc/QuerySplitter.java | 336 --------
.../metamodel/jdbc/SplitQueriesDataSet.java | 106 ---
.../eobjects/metamodel/jdbc/SqlKeywords.java | 51 --
.../jdbc/dialects/AbstractQueryRewriter.java | 259 ------
.../jdbc/dialects/DB2QueryRewriter.java | 161 ----
.../jdbc/dialects/DefaultQueryRewriter.java | 146 ----
.../jdbc/dialects/H2QueryRewriter.java | 31 -
.../jdbc/dialects/HsqldbQueryRewriter.java | 99 ---
.../metamodel/jdbc/dialects/IQueryRewriter.java | 93 --
.../jdbc/dialects/LimitOffsetQueryRewriter.java | 71 --
.../jdbc/dialects/MysqlQueryRewriter.java | 36 -
.../jdbc/dialects/PostgresqlQueryRewriter.java | 70 --
.../jdbc/dialects/SQLServerQueryRewriter.java | 56 --
.../eobjects/metamodel/jdbc/package-info.java | 23 -
.../org/apache/metamodel/DB2Test.java | 107 +++
.../org/apache/metamodel/FirebirdTest.java | 115 +++
.../org/apache/metamodel/MysqlTest.java | 334 +++++++
.../org/apache/metamodel/OracleTest.java | 222 +++++
.../org/apache/metamodel/PostgresqlTest.java | 810 +++++++++++++++++
.../metamodel/SQLServerJtdsDriverTest.java | 208 +++++
.../metamodel/SQLServerMicrosoftDriverTest.java | 141 +++
.../org/eobjects/metamodel/DB2Test.java | 107 ---
.../org/eobjects/metamodel/FirebirdTest.java | 115 ---
.../org/eobjects/metamodel/MysqlTest.java | 334 -------
.../org/eobjects/metamodel/OracleTest.java | 222 -----
.../org/eobjects/metamodel/PostgresqlTest.java | 810 -----------------
.../metamodel/SQLServerJtdsDriverTest.java | 208 -----
.../metamodel/SQLServerMicrosoftDriverTest.java | 141 ---
.../metamodel/dbmains/PostgresqlMain.java | 92 ++
.../dialects/AbstractQueryRewriterTest.java | 66 ++
.../dialects/DB2QueryRewriterTest.java | 150 ++++
.../dialects/MysqlQueryRewriterTest.java | 46 +
.../dialects/PostgresqlQueryRewriterTest.java | 58 ++
.../dialects/SQLServerQueryRewriterTest.java | 67 ++
.../jdbc/CloseableConnectionWrapper.java | 297 +++++++
.../org/apache/metamodel/jdbc/DerbyTest.java | 388 +++++++++
.../metamodel/jdbc/FetchSizeCalculatorTest.java | 129 +++
.../metamodel/jdbc/FilteredDataSetTest.java | 74 ++
.../apache/metamodel/jdbc/H2databaseTest.java | 508 +++++++++++
.../org/apache/metamodel/jdbc/HsqldbTest.java | 379 ++++++++
.../apache/metamodel/jdbc/JdbcColumnTest.java | 58 ++
.../metamodel/jdbc/JdbcDataContextTest.java | 428 +++++++++
.../metamodel/jdbc/JdbcDeleteBuilderTest.java | 72 ++
.../metamodel/jdbc/JdbcInsertBuilderTest.java | 83 ++
.../apache/metamodel/jdbc/JdbcSchemaTest.java | 101 +++
.../org/apache/metamodel/jdbc/JdbcTestCase.java | 51 ++
.../metamodel/jdbc/JdbcTestTemplates.java | 507 +++++++++++
.../metamodel/jdbc/JdbcUpdateBuilderTest.java | 89 ++
.../apache/metamodel/jdbc/JdbcUtilsTest.java | 49 ++
.../metamodel/jdbc/QuerySplitterTest.java | 232 +++++
.../org/apache/metamodel/jdbc/SqliteTest.java | 256 ++++++
.../metamodel/dbmains/PostgresqlMain.java | 92 --
.../dialects/AbstractQueryRewriterTest.java | 66 --
.../dialects/DB2QueryRewriterTest.java | 150 ----
.../dialects/MysqlQueryRewriterTest.java | 46 -
.../dialects/PostgresqlQueryRewriterTest.java | 58 --
.../dialects/SQLServerQueryRewriterTest.java | 67 --
.../jdbc/CloseableConnectionWrapper.java | 297 -------
.../org/eobjects/metamodel/jdbc/DerbyTest.java | 388 ---------
.../metamodel/jdbc/FetchSizeCalculatorTest.java | 129 ---
.../metamodel/jdbc/FilteredDataSetTest.java | 74 --
.../eobjects/metamodel/jdbc/H2databaseTest.java | 508 -----------
.../org/eobjects/metamodel/jdbc/HsqldbTest.java | 379 --------
.../eobjects/metamodel/jdbc/JdbcColumnTest.java | 58 --
.../metamodel/jdbc/JdbcDataContextTest.java | 428 ---------
.../metamodel/jdbc/JdbcDeleteBuilderTest.java | 72 --
.../metamodel/jdbc/JdbcInsertBuilderTest.java | 83 --
.../eobjects/metamodel/jdbc/JdbcSchemaTest.java | 101 ---
.../eobjects/metamodel/jdbc/JdbcTestCase.java | 51 --
.../metamodel/jdbc/JdbcTestTemplates.java | 507 -----------
.../metamodel/jdbc/JdbcUpdateBuilderTest.java | 89 --
.../eobjects/metamodel/jdbc/JdbcUtilsTest.java | 49 --
.../metamodel/jdbc/QuerySplitterTest.java | 232 -----
.../org/eobjects/metamodel/jdbc/SqliteTest.java | 256 ------
.../mongodb/DefaultWriteConcernAdvisor.java | 32 +
.../metamodel/mongodb/MongoDbDataContext.java | 465 ++++++++++
.../metamodel/mongodb/MongoDbDataSet.java | 114 +++
.../metamodel/mongodb/MongoDbDeleteBuilder.java | 56 ++
.../mongodb/MongoDbDropTableBuilder.java | 43 +
.../mongodb/MongoDbInsertionBuilder.java | 64 ++
.../mongodb/MongoDbTableCreationBuilder.java | 57 ++
.../metamodel/mongodb/MongoDbTableDef.java | 48 ++
.../mongodb/MongoDbUpdateCallback.java | 114 +++
.../mongodb/SimpleWriteConcernAdvisor.java | 50 ++
.../metamodel/mongodb/WriteConcernAdvisor.java | 35 +
.../apache/metamodel/mongodb/package-info.java | 23 +
.../mongodb/DefaultWriteConcernAdvisor.java | 32 -
.../metamodel/mongodb/MongoDbDataContext.java | 465 ----------
.../metamodel/mongodb/MongoDbDataSet.java | 114 ---
.../metamodel/mongodb/MongoDbDeleteBuilder.java | 56 --
.../mongodb/MongoDbDropTableBuilder.java | 43 -
.../mongodb/MongoDbInsertionBuilder.java | 64 --
.../mongodb/MongoDbTableCreationBuilder.java | 57 --
.../metamodel/mongodb/MongoDbTableDef.java | 48 --
.../mongodb/MongoDbUpdateCallback.java | 114 ---
.../mongodb/SimpleWriteConcernAdvisor.java | 50 --
.../metamodel/mongodb/WriteConcernAdvisor.java | 35 -
.../metamodel/mongodb/package-info.java | 23 -
.../mongodb/MongoDbDataContextTest.java | 380 ++++++++
.../metamodel/mongodb/MongoDbDataCopyer.java | 126 +++
.../mongodb/MongoDbDataContextTest.java | 380 --------
.../metamodel/mongodb/MongoDbDataCopyer.java | 126 ---
.../openoffice/OpenOfficeDataContext.java | 130 +++
.../metamodel/openoffice/package-info.java | 23 +
.../openoffice/OpenOfficeDataContext.java | 130 ---
.../metamodel/openoffice/package-info.java | 23 -
.../openoffice/OpenOfficeDataContextTest.java | 110 +++
.../openoffice/OpenOfficeDataContextTest.java | 110 ---
.../metamodel/pojo/ArrayTableDataProvider.java | 74 ++
.../metamodel/pojo/MapTableDataProvider.java | 68 ++
.../metamodel/pojo/ObjectTableDataProvider.java | 162 ++++
.../apache/metamodel/pojo/PojoDataContext.java | 162 ++++
.../org/apache/metamodel/pojo/PojoDataSet.java | 79 ++
.../metamodel/pojo/PojoUpdateCallback.java | 148 ++++
.../metamodel/pojo/TableDataProvider.java | 38 +
.../metamodel/pojo/ArrayTableDataProvider.java | 74 --
.../metamodel/pojo/MapTableDataProvider.java | 68 --
.../metamodel/pojo/ObjectTableDataProvider.java | 162 ----
.../metamodel/pojo/PojoDataContext.java | 162 ----
.../eobjects/metamodel/pojo/PojoDataSet.java | 79 --
.../metamodel/pojo/PojoUpdateCallback.java | 148 ----
.../metamodel/pojo/TableDataProvider.java | 38 -
.../org/apache/metamodel/pojo/FoobarBean.java | 67 ++
.../pojo/ObjectTableDataProviderTest.java | 36 +
.../metamodel/pojo/PojoDataContextTest.java | 161 ++++
.../org/eobjects/metamodel/pojo/FoobarBean.java | 67 --
.../pojo/ObjectTableDataProviderTest.java | 36 -
.../metamodel/pojo/PojoDataContextTest.java | 161 ----
.../salesforce/SalesforceDataContext.java | 338 ++++++++
.../metamodel/salesforce/SalesforceDataSet.java | 124 +++
.../salesforce/SalesforceDeleteBuilder.java | 57 ++
.../salesforce/SalesforceInsertBuilder.java | 68 ++
.../metamodel/salesforce/SalesforceSchema.java | 91 ++
.../metamodel/salesforce/SalesforceTable.java | 168 ++++
.../salesforce/SalesforceUpdateBuilder.java | 88 ++
.../salesforce/SalesforceUpdateCallback.java | 258 ++++++
.../metamodel/salesforce/SalesforceUtils.java | 55 ++
.../salesforce/SalesforceDataContext.java | 338 --------
.../metamodel/salesforce/SalesforceDataSet.java | 124 ---
.../salesforce/SalesforceDeleteBuilder.java | 57 --
.../salesforce/SalesforceInsertBuilder.java | 68 --
.../metamodel/salesforce/SalesforceSchema.java | 91 --
.../metamodel/salesforce/SalesforceTable.java | 168 ----
.../salesforce/SalesforceUpdateBuilder.java | 88 --
.../salesforce/SalesforceUpdateCallback.java | 258 ------
.../metamodel/salesforce/SalesforceUtils.java | 55 --
.../salesforce/SalesforceDataContextTest.java | 283 ++++++
.../salesforce/SalesforceTestCase.java | 78 ++
.../salesforce/SalesforceDataContextTest.java | 283 ------
.../salesforce/SalesforceTestCase.java | 78 --
.../sugarcrm/LoggingMessageHandler.java | 98 +++
.../metamodel/sugarcrm/SugarCrmDataContext.java | 178 ++++
.../metamodel/sugarcrm/SugarCrmDataSet.java | 156 ++++
.../metamodel/sugarcrm/SugarCrmSchema.java | 69 ++
.../metamodel/sugarcrm/SugarCrmTable.java | 159 ++++
.../metamodel/sugarcrm/SugarCrmXmlHelper.java | 109 +++
.../sugarcrm/LoggingMessageHandler.java | 98 ---
.../metamodel/sugarcrm/SugarCrmDataContext.java | 178 ----
.../metamodel/sugarcrm/SugarCrmDataSet.java | 156 ----
.../metamodel/sugarcrm/SugarCrmSchema.java | 69 --
.../metamodel/sugarcrm/SugarCrmTable.java | 159 ----
.../metamodel/sugarcrm/SugarCrmXmlHelper.java | 109 ---
.../sugarcrm/SugarCrmDataContextTest.java | 242 ++++++
.../metamodel/sugarcrm/SugarCrmTestCase.java | 78 ++
.../sugarcrm/SugarCrmDataContextTest.java | 242 ------
.../metamodel/sugarcrm/SugarCrmTestCase.java | 78 --
.../apache/metamodel/xml/XmlDataContext.java | 61 ++
.../apache/metamodel/xml/XmlDomDataContext.java | 634 ++++++++++++++
.../metamodel/xml/XmlSaxContentHandler.java | 173 ++++
.../apache/metamodel/xml/XmlSaxDataContext.java | 256 ++++++
.../apache/metamodel/xml/XmlSaxTableDef.java | 149 ++++
.../metamodel/xml/XmlStopParsingException.java | 33 +
.../org/apache/metamodel/xml/package-info.java | 23 +
.../eobjects/metamodel/xml/XmlDataContext.java | 61 --
.../metamodel/xml/XmlDomDataContext.java | 634 --------------
.../metamodel/xml/XmlSaxContentHandler.java | 173 ----
.../metamodel/xml/XmlSaxDataContext.java | 256 ------
.../eobjects/metamodel/xml/XmlSaxTableDef.java | 149 ----
.../metamodel/xml/XmlStopParsingException.java | 33 -
.../eobjects/metamodel/xml/package-info.java | 23 -
.../metamodel/xml/XmlDomDataContextTest.java | 360 ++++++++
.../metamodel/xml/XmlSaxContentHandlerTest.java | 77 ++
.../metamodel/xml/XmlSaxDataContextTest.java | 242 ++++++
.../metamodel/xml/XmlDomDataContextTest.java | 360 --------
.../metamodel/xml/XmlSaxContentHandlerTest.java | 77 --
.../metamodel/xml/XmlSaxDataContextTest.java | 242 ------
1024 files changed, 62485 insertions(+), 62485 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/access/src/main/java/org/apache/metamodel/access/AccessDataContext.java
----------------------------------------------------------------------
diff --git a/access/src/main/java/org/apache/metamodel/access/AccessDataContext.java b/access/src/main/java/org/apache/metamodel/access/AccessDataContext.java
new file mode 100644
index 0000000..0b3875a
--- /dev/null
+++ b/access/src/main/java/org/apache/metamodel/access/AccessDataContext.java
@@ -0,0 +1,170 @@
+/**
+ * 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.access;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.QueryPostprocessDataContext;
+import org.eobjects.metamodel.data.CachingDataSetHeader;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.DataSetHeader;
+import org.eobjects.metamodel.data.DefaultRow;
+import org.eobjects.metamodel.data.InMemoryDataSet;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+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.Table;
+import org.eobjects.metamodel.schema.TableType;
+
+import com.healthmarketscience.jackcess.Database;
+import com.healthmarketscience.jackcess.Index;
+import com.healthmarketscience.jackcess.IndexData.ColumnDescriptor;
+
+/**
+ * DataContext implementation for MS Access database files.
+ *
+ * @author Kasper Sørensen
+ */
+public final class AccessDataContext extends QueryPostprocessDataContext {
+
+ private final File _file;
+ private Database _database;
+
+ public AccessDataContext(File file) {
+ _file = file;
+ }
+
+ public AccessDataContext(String filename) {
+ this(new File(filename));
+ }
+
+ private Database getDatabase() {
+ if (_database == null) {
+ synchronized (this) {
+ if (_database == null) {
+ try {
+ _database = Database.open(_file, true);
+ } catch (IOException e) {
+ throw new MetaModelException(e);
+ }
+ }
+ }
+ }
+ return _database;
+ }
+
+ @Override
+ protected Schema getMainSchema() throws MetaModelException {
+ MutableSchema schema = new MutableSchema(_file.getName());
+ Database db = getDatabase();
+ for (com.healthmarketscience.jackcess.Table mdbTable : db) {
+ final MutableTable table = new MutableTable(mdbTable.getName(), TableType.TABLE, schema);
+
+ try {
+ int i = 0;
+ for (com.healthmarketscience.jackcess.Column mdbColumn : mdbTable.getColumns()) {
+ final ColumnType columnType = ColumnType.convertColumnType(mdbColumn.getSQLType());
+ final MutableColumn column = new MutableColumn(mdbColumn.getName(), columnType, table, i, null);
+ column.setColumnSize((int) mdbColumn.getLength());
+ column.setNativeType(mdbColumn.getType().name());
+
+ table.addColumn(column);
+ i++;
+ }
+
+ final Index primaryKeyIndex = mdbTable.getPrimaryKeyIndex();
+ final List<ColumnDescriptor> columnDescriptors = primaryKeyIndex.getColumns();
+ for (ColumnDescriptor columnDescriptor : columnDescriptors) {
+ final String name = columnDescriptor.getColumn().getName();
+ final MutableColumn column = (MutableColumn) table.getColumnByName(name);
+ column.setPrimaryKey(true);
+ }
+
+ schema.addTable(table);
+
+ } catch (Exception e) {
+ throw new MetaModelException(e);
+ }
+ }
+ return schema;
+ }
+
+ @Override
+ protected String getMainSchemaName() throws MetaModelException {
+ return _file.getName();
+ }
+
+ @Override
+ protected Number executeCountQuery(Table table, List<FilterItem> whereItems, boolean functionApproximationAllowed) {
+ try {
+ com.healthmarketscience.jackcess.Table mdbTable = getDatabase().getTable(table.getName());
+ return mdbTable.getRowCount();
+ } catch (Exception e) {
+ throw new MetaModelException(e);
+ }
+ }
+
+ @Override
+ public DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+ try {
+ final com.healthmarketscience.jackcess.Table mdbTable = getDatabase().getTable(table.getName());
+ final SelectItem[] selectItems = new SelectItem[columns.length];
+ for (int i = 0; i < columns.length; i++) {
+ selectItems[i] = new SelectItem(columns[i]);
+ }
+
+ final DataSetHeader header = new CachingDataSetHeader(selectItems);
+
+ int rowNum = 0;
+ final List<Row> data = new LinkedList<Row>();
+ final Iterator<Map<String, Object>> it = mdbTable.iterator();
+ while (it.hasNext() && (maxRows < 0 || rowNum < maxRows)) {
+ rowNum++;
+ final Map<String, Object> valueMap = it.next();
+ final Object[] values = new Object[columns.length];
+ for (int j = 0; j < columns.length; j++) {
+ values[j] = valueMap.get(columns[j].getName());
+ }
+ data.add(new DefaultRow(header, values));
+ }
+
+ return new InMemoryDataSet(header, data);
+ } catch (Exception e) {
+ throw new MetaModelException(e);
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ _database.close();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/access/src/main/java/org/apache/metamodel/access/package-info.java
----------------------------------------------------------------------
diff --git a/access/src/main/java/org/apache/metamodel/access/package-info.java b/access/src/main/java/org/apache/metamodel/access/package-info.java
new file mode 100644
index 0000000..d64d867
--- /dev/null
+++ b/access/src/main/java/org/apache/metamodel/access/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.
+ */
+/**
+ * Module package for MS Access database files
+ */
+package org.eobjects.metamodel.access;
+
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/access/src/main/java/org/eobjects/metamodel/access/AccessDataContext.java
----------------------------------------------------------------------
diff --git a/access/src/main/java/org/eobjects/metamodel/access/AccessDataContext.java b/access/src/main/java/org/eobjects/metamodel/access/AccessDataContext.java
deleted file mode 100644
index 0b3875a..0000000
--- a/access/src/main/java/org/eobjects/metamodel/access/AccessDataContext.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/**
- * 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.access;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.data.CachingDataSetHeader;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetHeader;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-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.Table;
-import org.eobjects.metamodel.schema.TableType;
-
-import com.healthmarketscience.jackcess.Database;
-import com.healthmarketscience.jackcess.Index;
-import com.healthmarketscience.jackcess.IndexData.ColumnDescriptor;
-
-/**
- * DataContext implementation for MS Access database files.
- *
- * @author Kasper Sørensen
- */
-public final class AccessDataContext extends QueryPostprocessDataContext {
-
- private final File _file;
- private Database _database;
-
- public AccessDataContext(File file) {
- _file = file;
- }
-
- public AccessDataContext(String filename) {
- this(new File(filename));
- }
-
- private Database getDatabase() {
- if (_database == null) {
- synchronized (this) {
- if (_database == null) {
- try {
- _database = Database.open(_file, true);
- } catch (IOException e) {
- throw new MetaModelException(e);
- }
- }
- }
- }
- return _database;
- }
-
- @Override
- protected Schema getMainSchema() throws MetaModelException {
- MutableSchema schema = new MutableSchema(_file.getName());
- Database db = getDatabase();
- for (com.healthmarketscience.jackcess.Table mdbTable : db) {
- final MutableTable table = new MutableTable(mdbTable.getName(), TableType.TABLE, schema);
-
- try {
- int i = 0;
- for (com.healthmarketscience.jackcess.Column mdbColumn : mdbTable.getColumns()) {
- final ColumnType columnType = ColumnType.convertColumnType(mdbColumn.getSQLType());
- final MutableColumn column = new MutableColumn(mdbColumn.getName(), columnType, table, i, null);
- column.setColumnSize((int) mdbColumn.getLength());
- column.setNativeType(mdbColumn.getType().name());
-
- table.addColumn(column);
- i++;
- }
-
- final Index primaryKeyIndex = mdbTable.getPrimaryKeyIndex();
- final List<ColumnDescriptor> columnDescriptors = primaryKeyIndex.getColumns();
- for (ColumnDescriptor columnDescriptor : columnDescriptors) {
- final String name = columnDescriptor.getColumn().getName();
- final MutableColumn column = (MutableColumn) table.getColumnByName(name);
- column.setPrimaryKey(true);
- }
-
- schema.addTable(table);
-
- } catch (Exception e) {
- throw new MetaModelException(e);
- }
- }
- return schema;
- }
-
- @Override
- protected String getMainSchemaName() throws MetaModelException {
- return _file.getName();
- }
-
- @Override
- protected Number executeCountQuery(Table table, List<FilterItem> whereItems, boolean functionApproximationAllowed) {
- try {
- com.healthmarketscience.jackcess.Table mdbTable = getDatabase().getTable(table.getName());
- return mdbTable.getRowCount();
- } catch (Exception e) {
- throw new MetaModelException(e);
- }
- }
-
- @Override
- public DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
- try {
- final com.healthmarketscience.jackcess.Table mdbTable = getDatabase().getTable(table.getName());
- final SelectItem[] selectItems = new SelectItem[columns.length];
- for (int i = 0; i < columns.length; i++) {
- selectItems[i] = new SelectItem(columns[i]);
- }
-
- final DataSetHeader header = new CachingDataSetHeader(selectItems);
-
- int rowNum = 0;
- final List<Row> data = new LinkedList<Row>();
- final Iterator<Map<String, Object>> it = mdbTable.iterator();
- while (it.hasNext() && (maxRows < 0 || rowNum < maxRows)) {
- rowNum++;
- final Map<String, Object> valueMap = it.next();
- final Object[] values = new Object[columns.length];
- for (int j = 0; j < columns.length; j++) {
- values[j] = valueMap.get(columns[j].getName());
- }
- data.add(new DefaultRow(header, values));
- }
-
- return new InMemoryDataSet(header, data);
- } catch (Exception e) {
- throw new MetaModelException(e);
- }
- }
-
- @Override
- protected void finalize() throws Throwable {
- super.finalize();
- _database.close();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/access/src/main/java/org/eobjects/metamodel/access/package-info.java
----------------------------------------------------------------------
diff --git a/access/src/main/java/org/eobjects/metamodel/access/package-info.java b/access/src/main/java/org/eobjects/metamodel/access/package-info.java
deleted file mode 100644
index 3d01cbb..0000000
--- a/access/src/main/java/org/eobjects/metamodel/access/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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.
- */
-/**
- * Module package for MS Access database files
- */
-package org.eobjects.metamodel.access;
-
[39/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/TimeComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/TimeComparator.java b/core/src/main/java/org/apache/metamodel/util/TimeComparator.java
new file mode 100644
index 0000000..5601deb
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/TimeComparator.java
@@ -0,0 +1,207 @@
+/**
+ * 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.util;
+
+import java.text.DateFormat;
+import java.text.DateFormatSymbols;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.Locale;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Compares dates of various formats. Since this class has unchecked generic
+ * conversion it can compare java.util.Date, java.sql.Date, java.sql.Time,
+ * java.util.Calendar, Date-formatted strings etc.
+ */
+public final class TimeComparator implements Comparator<Object> {
+
+ private static final Logger logger = LoggerFactory.getLogger(TimeComparator.class);
+
+ private static final String[] prototypePatterns = { "yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd HH:mm:ss",
+ "yyyy-MM-dd HH:mm", "HH:mm:ss.SSS", "yyyy-MM-dd", "dd-MM-yyyy", "yy-MM-dd", "MM-dd-yyyy", "HH:mm:ss",
+ "HH:mm" };
+
+ private static final Comparator<Object> _instance = new TimeComparator();
+
+ public static Comparator<Object> getComparator() {
+ return _instance;
+ }
+
+ private TimeComparator() {
+ }
+
+ public static Comparable<Object> getComparable(final Object o) {
+ final Date dt1 = toDate(o);
+ return new Comparable<Object>() {
+
+ @Override
+ public boolean equals(Object obj) {
+ return _instance.equals(obj);
+ }
+
+ public int compareTo(Object o) {
+ return _instance.compare(dt1, o);
+ }
+
+ @Override
+ public String toString() {
+ return "TimeComparable[time=" + dt1 + "]";
+ }
+ };
+ }
+
+ public int compare(final Object o1, final Object o2) {
+ if (o1 == null && o2 == null) {
+ return 0;
+ }
+ if (o1 == null) {
+ return -1;
+ }
+ if (o2 == null) {
+ return 1;
+ }
+ try {
+ Date dt1 = toDate(o1);
+ Date dt2 = toDate(o2);
+ return dt1.compareTo(dt2);
+ } catch (Exception e) {
+ logger.error("Could not compare {} and {}", o1, o2);
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static Date toDate(final Object value) {
+ Date result = null;
+ if (value == null) {
+ result = null;
+ } else if (value instanceof Date) {
+ result = (Date) value;
+ } else if (value instanceof Calendar) {
+ result = ((Calendar) value).getTime();
+ } else if (value instanceof String) {
+ result = convertFromString((String) value);
+ } else if (value instanceof Number) {
+ result = convertFromNumber((Number) value);
+ }
+
+ if (result == null) {
+ logger.warn("Could not convert '{}' to date, returning null", value);
+ }
+
+ return result;
+ }
+
+ public static boolean isTimeBased(Object o) {
+ if (o instanceof Date || o instanceof Calendar) {
+ return true;
+ }
+ return false;
+ }
+
+ private static Date convertFromString(final String value) {
+ try {
+ long longValue = Long.parseLong(value);
+ return convertFromNumber(longValue);
+ } catch (NumberFormatException e) {
+ // do nothing, proceed to dateFormat parsing
+ }
+
+ // try with Date.toString() date format first
+ try {
+ DateFormatSymbols dateFormatSymbols = DateFormatSymbols.getInstance(Locale.US);
+ SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", dateFormatSymbols);
+ return dateFormat.parse(value);
+ } catch (ParseException e) {
+ // do noting
+ }
+
+ for (String prototypePattern : prototypePatterns) {
+ if (prototypePattern.length() == value.length()) {
+ DateFormat dateFormat;
+ try {
+ dateFormat = DateUtils.createDateFormat(prototypePattern);
+ return dateFormat.parse(value);
+ } catch (Exception e) {
+ // proceed to next formatter
+ }
+
+ if (prototypePattern.indexOf('-') != -1) {
+ // try with '.' in stead of '-'
+ try {
+ dateFormat = DateUtils.createDateFormat(prototypePattern.replaceAll("\\-", "\\."));
+ return dateFormat.parse(value);
+ } catch (Exception e) {
+ // proceed to next formatter
+ }
+
+ // try with '/' in stead of '-'
+ try {
+ dateFormat = DateUtils.createDateFormat(prototypePattern.replaceAll("\\-", "\\/"));
+ return dateFormat.parse(value);
+ } catch (Exception e) {
+ // proceed to next formatter
+ }
+ }
+ }
+
+ }
+
+ return null;
+ }
+
+ private static Date convertFromNumber(Number value) {
+ Number numberValue = (Number) value;
+ long longValue = numberValue.longValue();
+
+ String stringValue = Long.toString(longValue);
+ // test if the number is actually a format of the type yyyyMMdd
+ if (stringValue.length() == 8 && (stringValue.startsWith("1") || stringValue.startsWith("2"))) {
+ try {
+ return DateUtils.createDateFormat("yyyyMMdd").parse(stringValue);
+ } catch (Exception e) {
+ // do nothing, proceed to next method of conversion
+ }
+ }
+
+ // test if the number is actually a format of the type yyMMdd
+ if (stringValue.length() == 6) {
+ try {
+ return DateUtils.createDateFormat("yyMMdd").parse(stringValue);
+ } catch (Exception e) {
+ // do nothing, proceed to next method of conversion
+ }
+ }
+
+ if (longValue > 5000000) {
+ // this number is most probably amount of milliseconds since
+ // 1970
+ return new Date(longValue);
+ } else {
+ // this number is most probably the amount of days since
+ // 1970
+ return new Date(longValue * 1000 * 60 * 60 * 24);
+ }
+ }
+}
\ 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/util/ToStringComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/ToStringComparator.java b/core/src/main/java/org/apache/metamodel/util/ToStringComparator.java
new file mode 100644
index 0000000..cfca4c5
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/ToStringComparator.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.util;
+
+import java.util.Comparator;
+
+/**
+ * Uses the toString method for comparison of objects
+ */
+public final class ToStringComparator implements Comparator<Object> {
+
+ private static Comparator<Object> _instance = new ToStringComparator();
+
+ public static Comparator<Object> getComparator() {
+ return _instance;
+ }
+
+ private ToStringComparator() {
+ }
+
+ public static Comparable<Object> getComparable(final Object o) {
+ final String s = o.toString();
+ return new Comparable<Object>() {
+
+ @Override
+ public boolean equals(Object obj) {
+ return _instance.equals(obj);
+ }
+
+ public int compareTo(Object o2) {
+ return _instance.compare(s, o2);
+ }
+
+ @Override
+ public String toString() {
+ return "ToStringComparable[string=" + s + "]";
+ }
+ };
+ }
+
+ public int compare(Object o1, Object o2) {
+ if (o1 == null && o2 == null) {
+ return -1;
+ }
+ if (o1 == null) {
+ return -1;
+ }
+ if (o2 == null) {
+ return 1;
+ }
+ return o1.toString().compareTo(o2.toString());
+ }
+}
\ 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/util/TruePredicate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/TruePredicate.java b/core/src/main/java/org/apache/metamodel/util/TruePredicate.java
new file mode 100644
index 0000000..5def8d3
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/TruePredicate.java
@@ -0,0 +1,46 @@
+/**
+ * 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.util;
+
+import java.io.Serializable;
+
+/**
+ * A predicate that is always true
+ *
+ * @param <E>
+ */
+public final class TruePredicate<E> implements Predicate<E>, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Boolean eval(E arg) {
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return Boolean.TRUE.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return obj != null && obj.getClass() == TruePredicate.class;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/UnicodeWriter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/UnicodeWriter.java b/core/src/main/java/org/apache/metamodel/util/UnicodeWriter.java
new file mode 100644
index 0000000..c95f381
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/UnicodeWriter.java
@@ -0,0 +1,236 @@
+/**
+ * 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.util;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+
+/**
+ * Writes Unicode text to an output stream. If the specified encoding is a
+ * Unicode, then the text is preceeded by the proper Unicode BOM. If it is any
+ * other encoding, this class behaves just like <code>OutputStreamWriter</code>.
+ * This class is here because Java's <code>OutputStreamWriter</code> apparently
+ * doesn't believe in writing BOMs.
+ * <p>
+ *
+ * For optimum performance, it is recommended that you wrap all instances of
+ * <code>UnicodeWriter</code> with a <code>java.io.BufferedWriter</code>.
+ *
+ * This file is a redistribution of Rubert Futrell from FifeSoft UnicodeWriter
+ * (also LGPL licensed).
+ *
+ * <pre>
+ * UnicodeWriter.java - Writes Unicode output with the proper BOM.
+ * Copyright (C) 2004 Robert Futrell
+ * robert_futrell at users.sourceforge.net
+ * http://fifesoft.com/rsyntaxtextarea
+ * </pre>
+ *
+ * @author Robert Futrell
+ * @version 0.7
+ */
+public class UnicodeWriter extends Writer {
+
+ public static final byte[] UTF8_BOM = new byte[] { (byte) 0xEF,
+ (byte) 0xBB, (byte) 0xBF };
+
+ public static final byte[] UTF16LE_BOM = new byte[] { (byte) 0xFF,
+ (byte) 0xFE };
+
+ public static final byte[] UTF16BE_BOM = new byte[] { (byte) 0xFE,
+ (byte) 0xFF };
+
+ public static final byte[] UTF32LE_BOM = new byte[] { (byte) 0xFF,
+ (byte) 0xFE, (byte) 0x00, (byte) 0x00 };
+
+ public static final byte[] UTF32BE_BOM = new byte[] { (byte) 0x00,
+ (byte) 0x00, (byte) 0xFE, (byte) 0xFF };
+
+ /**
+ * The writer actually doing the writing.
+ */
+ private final OutputStreamWriter writer;
+
+ /**
+ * This is a utility constructor since the vast majority of the time, this
+ * class will be used to write Unicode files.
+ *
+ * @param fileName
+ * The file to which to write the Unicode output.
+ * @param encoding
+ * The encoding to use.
+ * @throws UnsupportedEncodingException
+ * If the specified encoding is not supported.
+ * @throws IOException
+ * If an IO exception occurs.
+ */
+ public UnicodeWriter(String fileName, String encoding)
+ throws UnsupportedEncodingException, IOException {
+ this(new FileOutputStream(fileName), encoding);
+ }
+
+ /**
+ * This is a utility constructor since the vast majority of the time, this
+ * class will be used to write Unicode files.
+ *
+ * @param file
+ * The file to which to write the Unicode output.
+ * @param encoding
+ * The encoding to use.
+ * @throws UnsupportedEncodingException
+ * If the specified encoding is not supported.
+ * @throws IOException
+ * If an IO exception occurs.
+ */
+ public UnicodeWriter(File file, String encoding)
+ throws UnsupportedEncodingException, IOException {
+ this(new FileOutputStream(file), encoding);
+ }
+
+ /**
+ * Creates a new writer.
+ *
+ * @param outputStream
+ * The output stream to write.
+ * @param encoding
+ * The encoding to use.
+ * @throws UnsupportedEncodingException
+ * If the specified encoding is not supported.
+ * @throws IOException
+ * If an IO exception occurs.
+ */
+ public UnicodeWriter(OutputStream outputStream, String encoding)
+ throws UnsupportedEncodingException, IOException {
+ writer = createWriter(outputStream, encoding);
+ }
+
+ /**
+ * Closes this writer.
+ *
+ * @throws IOException
+ * If an IO exception occurs.
+ */
+ @Override
+ public void close() throws IOException {
+ writer.close();
+ }
+
+ /**
+ * Flushes the stream.
+ *
+ * @throws IOException
+ * If an IO exception occurs.
+ */
+ @Override
+ public void flush() throws IOException {
+ writer.flush();
+ }
+
+ /**
+ * Initializes the internal output stream and writes the BOM if the
+ * specified encoding is a Unicode encoding.
+ *
+ * @param outputStream
+ * The output stream we are writing.
+ * @param encoding
+ * The encoding in which to write.
+ * @throws UnsupportedEncodingException
+ * If the specified encoding isn't supported.
+ * @throws IOException
+ * If an I/O error occurs while writing a BOM.
+ */
+ private OutputStreamWriter createWriter(OutputStream outputStream,
+ String encoding) throws UnsupportedEncodingException, IOException {
+ OutputStreamWriter writer = new OutputStreamWriter(outputStream,
+ encoding);
+
+ // Write the proper BOM if they specified a Unicode encoding.
+ // NOTE: Creating an OutputStreamWriter with encoding "UTF-16"
+ // DOES write out the BOM; "UTF-16LE", "UTF-16BE", "UTF-32", "UTF-32LE"
+ // and "UTF-32BE" don't.
+ if ("UTF-8".equalsIgnoreCase(encoding)) {
+ outputStream.write(UTF8_BOM, 0, UTF8_BOM.length);
+ } else if ("UTF-16LE".equalsIgnoreCase(encoding)) {
+ outputStream.write(UTF16LE_BOM, 0, UTF16LE_BOM.length);
+ } else if (/* "UTF-16".equalsIgnoreCase(encoding) || */
+ "UTF-16BE".equalsIgnoreCase(encoding)) {
+ outputStream.write(UTF16BE_BOM, 0, UTF16BE_BOM.length);
+ } else if ("UTF-32LE".equalsIgnoreCase(encoding)) {
+ outputStream.write(UTF32LE_BOM, 0, UTF32LE_BOM.length);
+ } else if ("UTF-32".equalsIgnoreCase(encoding)
+ || "UTF-32BE".equalsIgnoreCase(encoding)) {
+ outputStream.write(UTF32BE_BOM, 0, UTF32BE_BOM.length);
+ }
+
+ return writer;
+ }
+
+ /**
+ * Writes a portion of an array of characters.
+ *
+ * @param cbuf
+ * The buffer of characters.
+ * @param off
+ * The offset from which to start writing characters.
+ * @param len
+ * The number of characters to write.
+ * @throws IOException
+ * If an I/O error occurs.
+ */
+ @Override
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ writer.write(cbuf, off, len);
+ }
+
+ /**
+ * Writes a single character.
+ *
+ * @param c
+ * An integer specifying the character to write.
+ * @throws IOException
+ * If an IO error occurs.
+ */
+ @Override
+ public void write(int c) throws IOException {
+ writer.write(c);
+ }
+
+ /**
+ * Writes a portion of a string.
+ *
+ * @param str
+ * The string from which to write.
+ * @param off
+ * The offset from which to start writing characters.
+ * @param len
+ * The number of characters to write.
+ * @throws IOException
+ * If an IO error occurs.
+ */
+ @Override
+ public void write(String str, int off, int len) throws IOException {
+ writer.write(str, off, len);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/UrlResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/UrlResource.java b/core/src/main/java/org/apache/metamodel/util/UrlResource.java
new file mode 100644
index 0000000..b195b95
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/UrlResource.java
@@ -0,0 +1,150 @@
+/**
+ * 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.util;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+/**
+ * Resource based on URL or URI.
+ */
+public class UrlResource implements Resource, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private final URI _uri;
+
+ public UrlResource(URL url) {
+ try {
+ _uri = url.toURI();
+ } catch (URISyntaxException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public UrlResource(URI uri) {
+ _uri = uri;
+ }
+
+ public UrlResource(String urlString) {
+ try {
+ _uri = new URI(urlString);
+ } catch (URISyntaxException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "UrlResource[" + _uri + "]";
+ }
+
+ /**
+ * Gets the URI associated with this resource.
+ *
+ * @return
+ */
+ public URI getUri() {
+ return _uri;
+ }
+
+ @Override
+ public String getName() {
+ final String name = _uri.toString();
+ final int lastSlash = name.lastIndexOf('/');
+ final int lastBackSlash = name.lastIndexOf('\\');
+ final int lastIndex = Math.max(lastSlash, lastBackSlash);
+ if (lastIndex != -1) {
+ final String lastPart = name.substring(lastIndex + 1);
+ if (!"".equals(lastPart)) {
+ return lastPart;
+ }
+ }
+ return name;
+ }
+
+ @Override
+ public boolean isReadOnly() {
+ return true;
+ }
+
+ @Override
+ public void write(Action<OutputStream> writeCallback) throws ResourceException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void append(Action<OutputStream> appendCallback) throws ResourceException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void read(Action<InputStream> readCallback) throws ResourceException {
+ final InputStream in = read();
+ try {
+ readCallback.run(in);
+ } catch (Exception e) {
+ throw new ResourceException(this, "Error occurred in read callback", e);
+ } finally {
+ FileHelper.safeClose(in);
+ }
+ }
+
+ @Override
+ public <E> E read(Func<InputStream, E> readCallback) throws ResourceException {
+ final InputStream in = read();
+ try {
+ E result = readCallback.eval(in);
+ return result;
+ } catch (Exception e) {
+ throw new ResourceException(this, "Error occurred in read callback", e);
+ } finally {
+ FileHelper.safeClose(in);
+ }
+ }
+
+ @Override
+ public boolean isExists() {
+ return true;
+ }
+
+ @Override
+ public long getSize() {
+ return -1;
+ }
+
+ @Override
+ public long getLastModified() {
+ return -1;
+ }
+
+ @Override
+ public InputStream read() throws ResourceException {
+ try {
+ return _uri.toURL().openStream();
+ } catch (Exception e) {
+ throw new ResourceException(this, "Failed to open InputStream", e);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/Weekday.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/Weekday.java b/core/src/main/java/org/apache/metamodel/util/Weekday.java
new file mode 100644
index 0000000..d9ab224
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/Weekday.java
@@ -0,0 +1,83 @@
+/**
+ * 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.util;
+
+import java.util.Calendar;
+
+/**
+ * Provides a handy and type-safe enum around the weekdays otherwise defined as
+ * int constants in java.util.Calendar.
+ *
+ * @author Kasper Sørensen
+ */
+public enum Weekday implements HasName {
+
+ MONDAY(Calendar.MONDAY),
+
+ TUESDAY(Calendar.TUESDAY),
+
+ WEDNESDAY(Calendar.WEDNESDAY),
+
+ THURSDAY(Calendar.THURSDAY),
+
+ FRIDAY(Calendar.FRIDAY),
+
+ SATURDAY(Calendar.SATURDAY),
+
+ SUNDAY(Calendar.SUNDAY);
+
+ private int calendarConstant;
+
+ private Weekday(int calendarConstant) {
+ this.calendarConstant = calendarConstant;
+ }
+
+ public int getCalendarConstant() {
+ return calendarConstant;
+ }
+
+ public static Weekday getByCalendarConstant(int calendarConstant) {
+ for (Weekday weekday : values()) {
+ if (weekday.getCalendarConstant() == calendarConstant) {
+ return weekday;
+ }
+ }
+ return null;
+ }
+
+ public Weekday next() {
+ if (this == SUNDAY) {
+ return MONDAY;
+ }
+ return values()[ordinal() + 1];
+ }
+
+ public Weekday previous() {
+ if (this == MONDAY) {
+ return SUNDAY;
+ }
+ return values()[ordinal() - 1];
+ }
+
+ @Override
+ public String getName() {
+ final String capitalized = toString();
+ return capitalized.charAt(0) + capitalized.substring(1).toLowerCase();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/WildcardPattern.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/WildcardPattern.java b/core/src/main/java/org/apache/metamodel/util/WildcardPattern.java
new file mode 100644
index 0000000..36f388a
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/WildcardPattern.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.util;
+
+import java.io.Serializable;
+import java.util.StringTokenizer;
+
+import org.eobjects.metamodel.query.FilterItem;
+
+/**
+ * Represents a pattern with a wildcard character. These are typically used in
+ * FilterItems with the LIKE operator.
+ *
+ * @see FilterItem
+ */
+public final class WildcardPattern implements Serializable {
+
+ private static final long serialVersionUID = 857462137797209624L;
+ private String _pattern;
+ private char _wildcard;
+ private boolean _endsWithDelim;
+
+ public WildcardPattern(String pattern, char wildcard) {
+ _pattern = pattern;
+ _wildcard = wildcard;
+ _endsWithDelim = (_pattern.charAt(pattern.length() - 1) == _wildcard);
+ }
+
+ public boolean matches(String value) {
+ if (value == null) {
+ return false;
+ }
+ StringTokenizer st = new StringTokenizer(_pattern,
+ Character.toString(_wildcard));
+ int charIndex = 0;
+ while (st.hasMoreTokens()) {
+ String token = st.nextToken();
+ charIndex = value.indexOf(token, charIndex);
+ if (charIndex == -1) {
+ return false;
+ }
+ charIndex = charIndex + token.length();
+ }
+ if (!_endsWithDelim) {
+ // Unless the last char of the pattern is a wildcard, we need to
+ // have reached the end of the string
+ if (charIndex != value.length()) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
\ 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/util/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/package-info.java b/core/src/main/java/org/apache/metamodel/util/package-info.java
new file mode 100644
index 0000000..0423170
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/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.
+ */
+/**
+ * Utilities and convenient classes
+ */
+package org.eobjects.metamodel.util;
+
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/AbstractDataContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/AbstractDataContext.java b/core/src/main/java/org/eobjects/metamodel/AbstractDataContext.java
deleted file mode 100644
index 3300e17..0000000
--- a/core/src/main/java/org/eobjects/metamodel/AbstractDataContext.java
+++ /dev/null
@@ -1,463 +0,0 @@
-/**
- * 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;
-
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.DefaultCompiledQuery;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.builder.InitFromBuilder;
-import org.eobjects.metamodel.query.builder.InitFromBuilderImpl;
-import org.eobjects.metamodel.query.parser.QueryParser;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * Abstract implementation of the DataContext interface. Provides convenient
- * implementations of all trivial and datastore-independent methods.
- *
- * @author Kasper Sørensen
- */
-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;
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final DataContext refreshSchemas() {
- _schemaCache.clear();
- _schemaNameCache = null;
- return this;
- }
-
- /**
- * {@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];
- final Schema schema = _schemaCache.get(getSchemaCacheKey(name));
- if (schema == null) {
- final Schema newSchema = getSchemaByName(name);
- if (newSchema == null) {
- throw new MetaModelException("Declared schema does not exist: " + name);
- }
- final Schema existingSchema = _schemaCache.putIfAbsent(getSchemaCacheKey(name), newSchema);
- if (existingSchema == null) {
- schemas[i] = newSchema;
- } else {
- schemas[i] = existingSchema;
- }
- } else {
- schemas[i] = schema;
- }
- }
- return schemas;
- }
-
- private String getSchemaCacheKey(String name) {
- if (name == null) {
- return NULL_SCHEMA_NAME_TOKEN;
- }
- return name;
- }
-
- /**
- * m {@inheritDoc}
- */
- @Override
- public final String[] getSchemaNames() throws MetaModelException {
- if (_schemaNameCache == null) {
- _schemaNameCache = getSchemaNamesInternal();
- }
- String[] schemaNames = Arrays.copyOf(_schemaNameCache, _schemaNameCache.length);
- Arrays.sort(schemaNames, _schemaNameComparator);
- return schemaNames;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final Schema getDefaultSchema() throws MetaModelException {
- Schema result = null;
- String defaultSchemaName = getDefaultSchemaName();
- if (defaultSchemaName != null) {
- result = getSchemaByName(defaultSchemaName);
- }
- if (result == null) {
- Schema[] schemas = getSchemas();
- if (schemas.length == 1) {
- result = schemas[0];
- } else {
- int highestTableCount = -1;
- for (int i = 0; i < schemas.length; i++) {
- final Schema schema = schemas[i];
- String name = schema.getName();
- if (schema != null) {
- name = name.toLowerCase();
- boolean isInformationSchema = name.startsWith("information") && name.endsWith("schema");
- if (!isInformationSchema && schema.getTableCount() > highestTableCount) {
- highestTableCount = schema.getTableCount();
- result = schema;
- }
- }
- }
- }
- }
- return result;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final InitFromBuilder query() {
- return new InitFromBuilderImpl(this);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Query parseQuery(final String queryString) throws MetaModelException {
- final QueryParser parser = new QueryParser(this, queryString);
- final Query query = parser.parse();
- return query;
- }
-
- @Override
- public CompiledQuery compileQuery(final Query query) throws MetaModelException {
- return new DefaultCompiledQuery(query);
- }
-
- @Override
- public DataSet executeQuery(CompiledQuery compiledQuery, Object... values) {
- assert compiledQuery instanceof DefaultCompiledQuery;
-
- final DefaultCompiledQuery defaultCompiledQuery = (DefaultCompiledQuery) compiledQuery;
- final Query query = defaultCompiledQuery.cloneWithParameterValues(values);
-
- return executeQuery(query);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final DataSet executeQuery(final String queryString) throws MetaModelException {
- final Query query = parseQuery(queryString);
- final DataSet dataSet = executeQuery(query);
- return dataSet;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final Schema getSchemaByName(String name) throws MetaModelException {
- Schema schema = _schemaCache.get(getSchemaCacheKey(name));
- if (schema == null) {
- if (name == null) {
- schema = getSchemaByNameInternal(null);
- } else {
- String[] schemaNames = getSchemaNames();
- for (String schemaName : schemaNames) {
- if (name.equalsIgnoreCase(schemaName)) {
- schema = getSchemaByNameInternal(name);
- break;
- }
- }
- if (schema == null) {
- for (String schemaName : schemaNames) {
- if (name.equalsIgnoreCase(schemaName)) {
- // try again with "schemaName" as param instead of
- // "name".
- schema = getSchemaByNameInternal(schemaName);
- break;
- }
- }
- }
- }
- if (schema != null) {
- Schema existingSchema = _schemaCache.putIfAbsent(getSchemaCacheKey(schema.getName()), schema);
- if (existingSchema != null) {
- // race conditions may cause two schemas to be created.
- // We'll favor the existing schema if possible, since schema
- // may contain lazy-loading logic and so on.
- return existingSchema;
- }
- }
- }
- return schema;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final Column getColumnByQualifiedLabel(final String columnName) {
- if (columnName == null) {
- return null;
- }
- Schema schema = null;
- final String[] schemaNames = getSchemaNames();
- for (final String schemaName : schemaNames) {
- if (schemaName == null) {
- // search without schema name (some databases have only a single
- // schema with no name)
- schema = getSchemaByName(null);
- if (schema != null) {
- Column column = getColumn(schema, columnName);
- if (column != null) {
- return column;
- }
- }
- } else {
- // Search case-sensitive
- Column col = searchColumn(schemaName, columnName, columnName);
- if (col != null) {
- return col;
- }
- }
- }
-
- final String columnNameInLowerCase = columnName.toLowerCase();
- for (final String schemaName : schemaNames) {
- if (schemaName != null) {
- // search case-insensitive
- String schameNameInLowerCase = schemaName.toLowerCase();
- Column col = searchColumn(schameNameInLowerCase, columnName, columnNameInLowerCase);
- if (col != null) {
- return col;
- }
- }
- }
-
- schema = getDefaultSchema();
- if (schema != null) {
- Column column = getColumn(schema, columnName);
- if (column != null) {
- return column;
- }
- }
-
- return null;
- }
-
- /**
- * Searches for a particular column within a schema
- *
- * @param schemaNameSearch
- * the schema name to use for search
- * @param columnNameOriginal
- * the original column name
- * @param columnNameSearch
- * the column name as it should be searched for (either the same
- * as original, or lower case in case of case-insensitive search)
- * @return
- */
- private Column searchColumn(String schemaNameSearch, String columnNameOriginal, String columnNameSearch) {
- if (columnNameSearch.startsWith(schemaNameSearch)) {
- Schema schema = getSchemaByName(schemaNameSearch);
- if (schema != null) {
- String tableAndColumnPath = columnNameOriginal.substring(schemaNameSearch.length());
-
- if (tableAndColumnPath.charAt(0) == '.') {
- tableAndColumnPath = tableAndColumnPath.substring(1);
-
- Column column = getColumn(schema, tableAndColumnPath);
- if (column != null) {
- return column;
- }
- }
- }
- }
- return null;
- }
-
- private final Column getColumn(final Schema schema, final String tableAndColumnPath) {
- Table table = null;
- String columnPath = tableAndColumnPath;
- final String[] tableNames = schema.getTableNames();
- for (final String tableName : tableNames) {
- if (tableName != null) {
- // search case-sensitive
- if (isStartingToken(tableName, tableAndColumnPath)) {
- table = schema.getTableByName(tableName);
- columnPath = tableAndColumnPath.substring(tableName.length());
-
- if (columnPath.charAt(0) == '.') {
- columnPath = columnPath.substring(1);
- break;
- }
- }
- }
- }
-
- if (table == null) {
- final String tableAndColumnPathInLowerCase = tableAndColumnPath.toLowerCase();
- for (final String tableName : tableNames) {
- if (tableName != null) {
- String tableNameInLowerCase = tableName.toLowerCase();
- // search case-insensitive
- if (isStartingToken(tableNameInLowerCase, tableAndColumnPathInLowerCase)) {
- table = schema.getTableByName(tableName);
- columnPath = tableAndColumnPath.substring(tableName.length());
-
- if (columnPath.charAt(0) == '.') {
- columnPath = columnPath.substring(1);
- break;
- }
- }
- }
- }
- }
-
- if (table == null && tableNames.length == 1) {
- table = schema.getTables()[0];
- }
-
- if (table != null) {
- Column column = table.getColumnByName(columnPath);
- if (column != null) {
- return column;
- }
- }
-
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final Table getTableByQualifiedLabel(final String tableName) {
- if (tableName == null) {
- return null;
- }
- Schema schema = null;
- String[] schemaNames = getSchemaNames();
- for (String schemaName : schemaNames) {
- if (schemaName == null) {
- // there's an unnamed schema present.
- schema = getSchemaByName(null);
- if (schema != null) {
- Table table = schema.getTableByName(tableName);
- return table;
- }
- } else {
- // case-sensitive search
- if (isStartingToken(schemaName, tableName)) {
- schema = getSchemaByName(schemaName);
- }
- }
- }
-
- if (schema == null) {
- final String tableNameInLowerCase = tableName.toLowerCase();
- for (final String schemaName : schemaNames) {
- if (schemaName != null) {
- // case-insensitive search
- final String schemaNameInLowerCase = schemaName.toLowerCase();
- if (isStartingToken(schemaNameInLowerCase, tableNameInLowerCase)) {
- schema = getSchemaByName(schemaName);
- }
- }
- }
- }
-
- if (schema == null) {
- schema = getDefaultSchema();
- }
-
- String tablePart = tableName.toLowerCase();
- String schemaName = schema.getName();
- if (schemaName != null && isStartingToken(schemaName.toLowerCase(), tablePart)) {
- tablePart = tablePart.substring(schemaName.length());
- if (tablePart.startsWith(".")) {
- tablePart = tablePart.substring(1);
- }
- }
-
- return schema.getTableByName(tablePart);
- }
-
- private boolean isStartingToken(String partName, String fullName) {
- if (fullName.startsWith(partName)) {
- final int length = partName.length();
- if (length == 0) {
- return false;
- }
- if (fullName.length() > length) {
- final char nextChar = fullName.charAt(length);
- if (isQualifiedPathDelim(nextChar)) {
- return true;
- }
- }
- }
- return false;
- }
-
- protected boolean isQualifiedPathDelim(char c) {
- return c == '.' || c == '"';
- }
-
- /**
- * Gets schema names from the non-abstract implementation. These schema
- * names will be cached except if the {@link #refreshSchemas()} method is
- * called.
- *
- * @return an array of schema names.
- */
- protected abstract String[] getSchemaNamesInternal();
-
- /**
- * Gets the name of the default schema.
- *
- * @return the default schema name.
- */
- protected abstract String getDefaultSchemaName();
-
- /**
- * Gets a specific schema from the non-abstract implementation. This schema
- * object will be cached except if the {@link #refreshSchemas()} method is
- * called.
- *
- * @param name
- * the name of the schema to get
- * @return a schema object representing the named schema, or null if no such
- * schema exists.
- */
- protected abstract Schema getSchemaByNameInternal(String name);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/AbstractUpdateCallback.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/AbstractUpdateCallback.java b/core/src/main/java/org/eobjects/metamodel/AbstractUpdateCallback.java
deleted file mode 100644
index 726af15..0000000
--- a/core/src/main/java/org/eobjects/metamodel/AbstractUpdateCallback.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/**
- * 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;
-
-import java.util.Arrays;
-
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
-
-/**
- * Abstract implementation of the {@link UpdateCallback} interface. Implements
- * only the data store agnostic methods.
- *
- * @author Kasper Sørensen
- */
-public abstract class AbstractUpdateCallback implements UpdateCallback {
-
- private final DataContext _dataContext;
-
- public AbstractUpdateCallback(DataContext dataContext) {
- _dataContext = dataContext;
- }
-
- @Override
- public TableCreationBuilder createTable(String schemaName, String tableName) throws IllegalArgumentException,
- IllegalStateException {
- Schema schema = getSchema(schemaName);
- return createTable(schema, tableName);
- }
-
- @Override
- public TableDropBuilder dropTable(String schemaName, String tableName) throws IllegalArgumentException,
- IllegalStateException, UnsupportedOperationException {
- Table table = getTable(schemaName, tableName);
- return dropTable(table);
- }
-
- @Override
- public TableDropBuilder dropTable(Schema schema, String tableName) throws IllegalArgumentException,
- IllegalStateException, UnsupportedOperationException {
- 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()));
- }
- return dropTable(table);
- }
-
- @Override
- public final RowInsertionBuilder insertInto(String tableName) throws IllegalArgumentException,
- IllegalStateException {
- return insertInto(getTable(tableName));
- }
-
- @Override
- public RowInsertionBuilder insertInto(String schemaName, String tableName) throws IllegalArgumentException,
- IllegalStateException, UnsupportedOperationException {
- return insertInto(getTable(schemaName, tableName));
- }
-
- private Table getTable(String schemaName, String tableName) {
- final Schema schema = getSchema(schemaName);
- 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()));
- }
- return table;
- }
-
- private Schema getSchema(String schemaName) {
- final Schema schema = _dataContext.getSchemaByName(schemaName);
- if (schema == null) {
- throw new IllegalArgumentException("No such schema: " + schemaName);
- }
- return schema;
- }
-
- @Override
- public final RowDeletionBuilder deleteFrom(String tableName) {
- return deleteFrom(getTable(tableName));
- }
-
- @Override
- public RowDeletionBuilder deleteFrom(String schemaName, String tableName) throws IllegalArgumentException,
- IllegalStateException, UnsupportedOperationException {
- final Table table = getTable(schemaName, tableName);
- return deleteFrom(table);
- }
-
- @Override
- public final TableDropBuilder dropTable(String tableName) {
- return dropTable(getTable(tableName));
- }
-
- @Override
- public final RowUpdationBuilder update(String tableName) {
- return update(getTable(tableName));
- }
-
- private Table getTable(String tableName) {
- Table table = getDataContext().getTableByQualifiedLabel(tableName);
- if (table == null) {
- throw new IllegalArgumentException("No such table: " + tableName);
- }
- return table;
- }
-
- @Override
- public DataContext getDataContext() {
- return _dataContext;
- }
-
- @Override
- public boolean isCreateTableSupported() {
- // since 2.0 all updateable datacontext have create table support
- return true;
- }
-
- @Override
- public boolean isInsertSupported() {
- // since 2.0 all updateable datacontext have create table support
- return true;
- }
-
- @Override
- public boolean isUpdateSupported() {
- return isInsertSupported() && isDeleteSupported();
- }
-
- @Override
- public RowUpdationBuilder update(String schemaName, String tableName) throws IllegalArgumentException,
- IllegalStateException, UnsupportedOperationException {
- final Table table = getTable(schemaName, tableName);
- return update(table);
- }
-
- @Override
- public RowUpdationBuilder update(Table table) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException {
- return new DeleteAndInsertBuilder(this, table);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/BatchUpdateScript.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/BatchUpdateScript.java b/core/src/main/java/org/eobjects/metamodel/BatchUpdateScript.java
deleted file mode 100644
index 4d83ba3..0000000
--- a/core/src/main/java/org/eobjects/metamodel/BatchUpdateScript.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * 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;
-
-/**
- * Indicator sub-interface of {@link UpdateScript}. Implementing your updates
- * using this interface indicates to the underlying
- * {@link UpdateableDataContext} that the update script represents a large batch
- * update and that appropriate optimizations may be taken into use if available.
- */
-public interface BatchUpdateScript extends UpdateScript {
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/CompositeDataContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/CompositeDataContext.java b/core/src/main/java/org/eobjects/metamodel/CompositeDataContext.java
deleted file mode 100644
index 82d6c01..0000000
--- a/core/src/main/java/org/eobjects/metamodel/CompositeDataContext.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/**
- * 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;
-
-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 org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.CompositeSchema;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.Func;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * DataContext for composite datacontexts. Composite DataContexts wrap several
- * other datacontexts and makes cross-datastore querying possible.
- *
- * @author Kasper Sørensen
- */
-public class CompositeDataContext extends AbstractDataContext {
-
- private final static Logger logger = LoggerFactory.getLogger(CompositeDataContext.class);
- private Map<String, CompositeSchema> _compositeSchemas = new HashMap<String, CompositeSchema>();
- private DataContext[] _delegates;
-
- public CompositeDataContext(DataContext... delegates) {
- if (delegates == null) {
- throw new IllegalArgumentException("delegates cannot be null");
- }
- _delegates = delegates;
- }
-
- public CompositeDataContext(Collection<DataContext> delegates) {
- if (delegates == null) {
- throw new IllegalArgumentException("delegates cannot be null");
- }
- _delegates = delegates.toArray(new DataContext[delegates.size()]);
- }
-
- @Override
- public DataSet executeQuery(Query query) throws MetaModelException {
- // a set of all datacontexts involved
- Set<DataContext> dataContexts = new HashSet<DataContext>();
-
- // find all datacontexts involved, by investigating FROM items
- List<FromItem> items = query.getFromClause().getItems();
- for (FromItem item : items) {
- List<FromItem> tableFromItems = MetaModelHelper.getTableFromItems(item);
- for (FromItem fromItem : tableFromItems) {
- Table table = fromItem.getTable();
-
- DataContext dc = getDataContext(table);
- if (dc == null) {
- throw new MetaModelException("Could not resolve child-datacontext for table: " + table);
- }
- dataContexts.add(dc);
- }
- }
-
- if (dataContexts.isEmpty()) {
- throw new MetaModelException("No suiting delegate DataContext to execute query: " + query);
- } else if (dataContexts.size() == 1) {
- Iterator<DataContext> it = dataContexts.iterator();
- assert it.hasNext();
- DataContext dc = it.next();
- return dc.executeQuery(query);
- } else {
- // we create a datacontext which can materialize tables from
- // separate datacontexts.
- final Func<Table, DataContext> dataContextRetrievalFunction = new Func<Table, DataContext>() {
- @Override
- public DataContext eval(Table table) {
- return getDataContext(table);
- }
- };
- return new CompositeQueryDelegate(dataContextRetrievalFunction).executeQuery(query);
- }
- }
-
- private DataContext getDataContext(Table table) {
- DataContext result = null;
- if (table != null) {
- Schema schema = table.getSchema();
-
- if (schema != null) {
- for (DataContext dc : _delegates) {
- Schema dcSchema = dc.getSchemaByName(schema.getName());
- if (dcSchema != null) {
-
- // first round = try with schema identity match
- if (dcSchema == schema) {
- logger.debug("DataContext for '{}' resolved (using identity) to: '{}'", table, dcSchema);
- result = dc;
- break;
- }
- }
- }
-
- if (result == null) {
- for (DataContext dc : _delegates) {
- Schema dcSchema = dc.getSchemaByName(schema.getName());
- if (dcSchema != null) {
- // second round = try with schema equals method
- if (dcSchema.equals(schema)) {
- logger.debug("DataContext for '{}' resolved (using equals) to: '{}'", table, dcSchema);
- result = dc;
- break;
- }
- }
- }
- }
- }
- }
-
- if (result == null) {
- logger.warn("Couldn't resolve DataContext for {}", table);
- }
- return result;
- }
-
- @Override
- public String getDefaultSchemaName() throws MetaModelException {
- for (DataContext dc : _delegates) {
- Schema schema = dc.getDefaultSchema();
- if (schema != null) {
- return schema.getName();
- }
- }
- return null;
- }
-
- @Override
- public Schema getSchemaByNameInternal(String name) throws MetaModelException {
- CompositeSchema compositeSchema = _compositeSchemas.get(name);
- if (compositeSchema != null) {
- return compositeSchema;
- }
- List<Schema> matchingSchemas = new ArrayList<Schema>();
- for (DataContext dc : _delegates) {
- Schema schema = dc.getSchemaByName(name);
- if (schema != null) {
- matchingSchemas.add(schema);
- }
- }
- if (matchingSchemas.size() == 1) {
- return matchingSchemas.iterator().next();
- }
- if (matchingSchemas.size() > 1) {
- if (logger.isInfoEnabled()) {
- logger.info("Name-clash detected for Schema '{}'. Creating CompositeSchema.");
- }
- compositeSchema = new CompositeSchema(name, matchingSchemas);
- _compositeSchemas.put(name, compositeSchema);
- return compositeSchema;
- }
- return null;
- }
-
- @Override
- public String[] getSchemaNamesInternal() throws MetaModelException {
- Set<String> set = new HashSet<String>();
- for (DataContext dc : _delegates) {
- String[] schemaNames = dc.getSchemaNames();
- for (String name : schemaNames) {
- if (!MetaModelHelper.isInformationSchema(name)) {
- // we skip information schemas, since they're anyways going
- // to be incomplete and misleading.
- set.add(name);
- }
- }
- }
- String[] result = set.toArray(new String[set.size()]);
- Arrays.sort(result);
- return result;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/CompositeQueryDelegate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/CompositeQueryDelegate.java b/core/src/main/java/org/eobjects/metamodel/CompositeQueryDelegate.java
deleted file mode 100644
index a2d5a7f..0000000
--- a/core/src/main/java/org/eobjects/metamodel/CompositeQueryDelegate.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * 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;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.Func;
-
-final class CompositeQueryDelegate extends QueryPostprocessDelegate {
-
- private final Func<Table, DataContext> _dataContextRetrievalFunction;
-
- public CompositeQueryDelegate(
- Func<Table, DataContext> dataContextRetrievalFunction) {
- _dataContextRetrievalFunction = dataContextRetrievalFunction;
- }
-
- @Override
- protected DataSet materializeMainSchemaTable(Table table, Column[] columns,
- int maxRows) {
- // find the appropriate datacontext to execute a simple
- // table materialization query
- DataContext dc = _dataContextRetrievalFunction.eval(table);
- Query q = new Query().select(columns).from(table);
- if (maxRows >= 0) {
- q.setMaxRows(maxRows);
- }
- return dc.executeQuery(q);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/DataContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/DataContext.java b/core/src/main/java/org/eobjects/metamodel/DataContext.java
deleted file mode 100644
index b536d7d..0000000
--- a/core/src/main/java/org/eobjects/metamodel/DataContext.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/**
- * 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;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.QueryParameter;
-import org.eobjects.metamodel.query.builder.InitFromBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * A DataContext represents the central entry point for interactions with
- * datastores. The DataContext contains of the structure of data (in the form of
- * schemas) and interactions (in the form of queries) with data.
- *
- * @author Kasper Sørensen
- */
-public interface DataContext {
-
- /**
- * Enforces a refresh of the schemas. If not refreshed, cached schema
- * objects may be used.
- *
- * @return this DataContext
- */
- public DataContext refreshSchemas();
-
- /**
- * Gets all schemas within this DataContext.
- *
- * @return the schemas in this data context. Schemas are cached for reuse in
- * many situations so if you want to update the schemas, use the
- * refreshSchemas() method.
- * @throws MetaModelException
- * if an error occurs retrieving the schema model
- */
- public Schema[] getSchemas() throws MetaModelException;
-
- /**
- * Gets the names of all schemas within this DataContext.
- *
- * @return an array of valid schema names
- * @throws MetaModelException
- * if an error occurs retrieving the schema model
- */
- public String[] getSchemaNames() throws MetaModelException;
-
- /**
- * Gets the default schema of this DataContext.
- *
- * @return the schema that you are most probable to be interested in. The
- * default schema is determined by finding the schema with most
- * available of tables. In a lot of situations there will only be a
- * single available schema and in that case this will of course be
- * the schema returned.
- * @throws MetaModelException
- * if an error occurs retrieving the schema model
- */
- public Schema getDefaultSchema() throws MetaModelException;
-
- /**
- * Gets a schema by a specified name.
- *
- * @param name
- * the name of the desired schema
- * @return the Schema with the specified name or null if no such schema
- * exists
- * @throws MetaModelException
- * if an error occurs retrieving the schema model
- */
- public Schema getSchemaByName(String name) throws MetaModelException;
-
- /**
- * Starts building a query using the query builder API. This way of building
- * queries is the preferred approach since it provides a more type-safe
- * approach to building API's as well as allows the DataContext
- * implementation to be aware of the query building process.
- *
- * @return a query builder component at the initial position in building a
- * query.
- */
- public InitFromBuilder query();
-
- /**
- * Parses a string-based SQL query and produces a corresponding
- * {@link Query} object.
- *
- * @param queryString
- * the SQL query to parse
- * @return a {@link Query} object corresponding to the SQL query.
- * @throws MetaModelException
- * in case the parsing was unsuccesful.
- */
- public Query parseQuery(String queryString) throws MetaModelException;
-
- /**
- * Executes a query against the DataContext.
- *
- * @param query
- * the query object to execute
- * @return the {@link DataSet} produced from executing the query
- * @throws MetaModelException
- * if the specified query does not make sense or cannot be
- * executed because of restraints on the type of datastore.
- */
- public DataSet executeQuery(Query query) throws MetaModelException;
-
- /**
- * Compiles a query, preparing it for reuse. Often times compiled queries
- * have a performance improvement when executed, but at the cost of a
- * preparation time penalty. Therefore it is adviced to use compiled queries
- * when the same query is to be fired multiple times.
- *
- * Compiled queries can contain {@link QueryParameter}s as operands in the
- * WHERE clause, making it possible to reuse the same query with different
- * parameter values.
- *
- * @see CompiledQuery
- * @see QueryParameter
- *
- * @param query
- * the query object to execute, possibly holding one or more
- * {@link QueryParameter}s.
- * @return the {@link CompiledQuery} after preparing the query
- *
- * @throws MetaModelException
- * if preparing the query is unsuccesful
- */
- public CompiledQuery compileQuery(Query query) throws MetaModelException;
-
- /**
- * Executes a compiled query with given values as parameters.
- *
- * @param compiledQuery
- * the compiledQuery object to execute
- * @param values
- * the values for parameters in the {@link CompiledQuery}.
- * @return the {@link DataSet} produced from executing the query.
- */
- public DataSet executeQuery(CompiledQuery compiledQuery, Object... values);
-
- /**
- * Parses and executes a string-based SQL query.
- *
- * This method is essentially equivalent to calling first
- * {@link #parseQuery(String)} and then {@link #executeQuery(Query)} with
- * the parsed query.
- *
- * @param query
- * the SQL query to parse
- * @return the {@link DataSet} produced from executing the query
- * @throws MetaModelException
- * if either parsing or executing the query produces an
- * exception
- */
- public DataSet executeQuery(String queryString) throws MetaModelException;
-
- /**
- * Finds a column in the DataContext based on a fully qualified column
- * label. The qualified label consists of the the schema, table and column
- * name, delimited by a dot (.).
- *
- * @param columnName
- * @return a column that matches the qualified label, or null if no such
- * column exists
- */
- public Column getColumnByQualifiedLabel(final String columnName);
-
- /**
- * Finds a table in the DataContext based on a fully qualified table label.
- * The qualified label consists of the the schema and table name, delimited
- * by a dot (.).
- *
- * @param tableName
- * @return a table that matches the qualified label, or null if no such
- * table exists
- */
- public Table getTableByQualifiedLabel(final String tableName);
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/DeleteAndInsertBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/DeleteAndInsertBuilder.java b/core/src/main/java/org/eobjects/metamodel/DeleteAndInsertBuilder.java
deleted file mode 100644
index 91f26fb..0000000
--- a/core/src/main/java/org/eobjects/metamodel/DeleteAndInsertBuilder.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- * 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;
-
-import java.util.List;
-import java.util.ListIterator;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.SimpleDataSetHeader;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.AbstractRowUpdationBuilder;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
-
-/**
- * Simple implementation of the {@link RowUpdationBuilder} interface, which
- * simply uses a combined delete+insert strategy for performing updates. Note
- * that this implementation is not desirable performance-wise in many cases, but
- * does provide a functional equivalent to a "real" update.
- */
-public class DeleteAndInsertBuilder extends AbstractRowUpdationBuilder {
-
- private final AbstractUpdateCallback _updateCallback;
-
- public DeleteAndInsertBuilder(AbstractUpdateCallback updateCallback, Table table) {
- super(table);
- assert updateCallback.isInsertSupported();
- assert updateCallback.isDeleteSupported();
- _updateCallback = updateCallback;
- }
-
- @Override
- public void execute() throws MetaModelException {
- // retain rows in memory
- List<Row> rows = getRowsToUpdate();
-
- // delete rows
- _updateCallback.deleteFrom(getTable()).where(getWhereItems()).execute();
-
- // modify rows
- rows = updateRows(rows);
-
- // insert rows
- for (Row row : rows) {
- _updateCallback.insertInto(getTable()).like(row).execute();
- }
- }
-
- private List<Row> updateRows(List<Row> rows) {
- for (ListIterator<Row> it = rows.listIterator(); it.hasNext();) {
- final Row original = (Row) it.next();
- final Row updated = update(original);
- it.set(updated);
- }
- return rows;
- }
-
- /**
- * Produces an updated row out of the original
- *
- * @param original
- * @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++) {
- final Object value;
- Column column = items[i].getColumn();
- if (isSet(column)) {
- // use update statement's value
- value = getValues()[i];
- } else {
- // use original value
- value = original.getValue(i);
- }
- values[i] = value;
- }
- return new DefaultRow(new SimpleDataSetHeader(items), values);
- }
-
- protected List<Row> getRowsToUpdate() {
- 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 List<Row> rows = dataSet.toRows();
- return rows;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/InconsistentRowFormatException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/InconsistentRowFormatException.java b/core/src/main/java/org/eobjects/metamodel/InconsistentRowFormatException.java
deleted file mode 100644
index fd67478..0000000
--- a/core/src/main/java/org/eobjects/metamodel/InconsistentRowFormatException.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- * 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;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-
-/**
- * Abstract exception type that represents exceptions that occur when reading a
- * data format which contain formatting errors or inconsistencies in on or more
- * rows.
- *
- * Typically {@link InconsistentRowFormatException}s are thrown when calling
- * {@link DataSet#next()}.
- *
- * All {@link InconsistentRowFormatException}s are optional, meaning that you
- * can turn them on and off. When turned off the result of
- * {@link #getProposedRow()} will be used transparently instead of throwing the
- * exception.
- *
- * @author Kasper Sørensen
- */
-public abstract class InconsistentRowFormatException extends MetaModelException {
-
- private static final long serialVersionUID = 1L;
-
- private final Row _proposedRow;
- private final int _rowNumber;
-
- public InconsistentRowFormatException(Row proposedRow, int rowNumber) {
- super();
- _proposedRow = proposedRow;
- _rowNumber = rowNumber;
- }
-
- public InconsistentRowFormatException(Row proposedRow, int rowNumber,
- Exception cause) {
- super(cause);
- _proposedRow = proposedRow;
- _rowNumber = rowNumber;
- }
-
- /**
- * Gets the row as MetaModel would gracefully interpret it.
- *
- * @return a row object which represents the {@link Row} as MetaModel would
- * gracefully interpret it.
- */
- public Row getProposedRow() {
- return _proposedRow;
- }
-
- /**
- * Gets the row number (1-based).
- *
- * @return the index of the row.
- */
- public int getRowNumber() {
- return _rowNumber;
- }
-
- @Override
- public String getMessage() {
- return "Inconsistent row format of row no. " + getRowNumber() + ".";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/MetaModelException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/MetaModelException.java b/core/src/main/java/org/eobjects/metamodel/MetaModelException.java
deleted file mode 100644
index 787b8c5..0000000
--- a/core/src/main/java/org/eobjects/metamodel/MetaModelException.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * 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;
-
-/**
- * Unchecked exception used to signal errors occuring in MetaModel.
- *
- * All MetaModelExceptions represent errors discovered withing the MetaModel
- * framework. Typically these will occur if you have put together a query that
- * is not meaningful or if there is a structural problem in a schema.
- */
-public class MetaModelException extends RuntimeException {
-
- private static final long serialVersionUID = 5455738384633428319L;
-
- public MetaModelException(String message, Exception cause) {
- super(message, cause);
- }
-
- public MetaModelException(String message) {
- super(message);
- }
-
- public MetaModelException(Exception cause) {
- super(cause);
- }
-
- public MetaModelException() {
- super();
- }
-}
\ No newline at end of file
[45/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/FilterItem.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/FilterItem.java b/core/src/main/java/org/apache/metamodel/query/FilterItem.java
new file mode 100644
index 0000000..86fdd20
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/FilterItem.java
@@ -0,0 +1,542 @@
+/**
+ * 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.query;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eobjects.metamodel.data.IRowFilter;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.util.BaseObject;
+import org.eobjects.metamodel.util.CollectionUtils;
+import org.eobjects.metamodel.util.FormatHelper;
+import org.eobjects.metamodel.util.ObjectComparator;
+import org.eobjects.metamodel.util.WildcardPattern;
+
+/**
+ * Represents a filter in a query that resides either within a WHERE clause or a
+ * HAVING clause
+ *
+ * @see FilterClause
+ * @see OperatorType
+ * @see LogicalOperator
+ */
+public class FilterItem extends BaseObject implements QueryItem, Cloneable, IRowFilter {
+
+ private static final long serialVersionUID = 2435322742894653227L;
+
+ private Query _query;
+ private final SelectItem _selectItem;
+ private final OperatorType _operator;
+ private final Object _operand;
+ private final List<FilterItem> _childItems;
+ private final LogicalOperator _logicalOperator;
+ private final String _expression;
+ private transient Set<?> _inValues;
+
+ /**
+ * Private constructor, used for cloning
+ */
+ private FilterItem(SelectItem selectItem, OperatorType operator, Object operand, List<FilterItem> orItems,
+ String expression, LogicalOperator logicalOperator) {
+ _selectItem = selectItem;
+ _operator = operator;
+ _operand = validateOperand(operand);
+ _childItems = orItems;
+ _expression = expression;
+ _logicalOperator = logicalOperator;
+ }
+
+ private Object validateOperand(Object operand) {
+ if (operand instanceof Column) {
+ // gracefully convert to a select item.
+ operand = new SelectItem((Column) operand);
+ }
+ return operand;
+ }
+
+ /**
+ * Creates a single filter item based on a SelectItem, an operator and an
+ * operand.
+ *
+ * @param selectItem
+ * the selectItem to put constraints on, cannot be null
+ * @param operator
+ * The operator to use. Can be OperatorType.EQUALS_TO,
+ * OperatorType.DIFFERENT_FROM,
+ * OperatorType.GREATER_THAN,OperatorType.LESS_THAN
+ * @param operand
+ * The operand. Can be a constant like null or a String, a
+ * Number, a Boolean, a Date, a Time, a DateTime. Or another
+ * SelectItem
+ * @throws IllegalArgumentException
+ * if the SelectItem is null or if the combination of operator
+ * and operand does not make sense.
+ */
+ public FilterItem(SelectItem selectItem, OperatorType operator, Object operand) throws IllegalArgumentException {
+ this(selectItem, operator, operand, null, null, null);
+ if (_operand == null) {
+ require("Can only use EQUALS or DIFFERENT_FROM operator with null-operand",
+ _operator == OperatorType.DIFFERENT_FROM || _operator == OperatorType.EQUALS_TO);
+ }
+ if (_operator == OperatorType.LIKE) {
+ ColumnType type = _selectItem.getColumn().getType();
+ if (type != null) {
+ require("Can only use LIKE operator with strings", type.isLiteral()
+ && (_operand instanceof String || _operand instanceof SelectItem));
+ }
+ }
+ require("SelectItem cannot be null", _selectItem != null);
+ }
+
+ /**
+ * Creates a single unvalidated filter item based on a expression.
+ * Expression based filters are typically NOT datastore-neutral but are
+ * available for special "hacking" needs.
+ *
+ * Expression based filters can only be used for JDBC based datastores since
+ * they are translated directly into SQL.
+ *
+ * @param expression
+ * An expression to use for the filter, for example
+ * "YEAR(my_date) = 2008".
+ */
+ public FilterItem(String expression) {
+ this(null, null, null, null, expression, null);
+
+ require("Expression cannot be null", _expression != null);
+ }
+
+ /**
+ * Creates a composite filter item based on other filter items. Each
+ * provided filter items will be OR'ed meaning that if one of the evaluates
+ * as true, then the composite filter will be evaluated as true
+ *
+ * @param items
+ * a list of items to include in the composite
+ */
+ public FilterItem(List<FilterItem> items) {
+ this(LogicalOperator.OR, items);
+ }
+
+ /**
+ * Creates a compound filter item based on other filter items. Each provided
+ * filter item will be combined according to the {@link LogicalOperator}.
+ *
+ * @param logicalOperator
+ * the logical operator to apply
+ * @param items
+ * a list of items to include in the composite
+ */
+ public FilterItem(LogicalOperator logicalOperator, List<FilterItem> items) {
+ this(null, null, null, items, null, logicalOperator);
+
+ require("Child items cannot be null", _childItems != null);
+ require("Child items cannot be empty", !_childItems.isEmpty());
+ }
+
+ /**
+ * Creates a compound filter item based on other filter items. Each provided
+ * filter item will be combined according to the {@link LogicalOperator}.
+ *
+ * @param logicalOperator
+ * the logical operator to apply
+ * @param items
+ * an array of items to include in the composite
+ */
+ public FilterItem(LogicalOperator logicalOperator, FilterItem... items) {
+ this(logicalOperator, Arrays.asList(items));
+ }
+
+ /**
+ * Creates a compound filter item based on other filter items. Each provided
+ * filter items will be OR'ed meaning that if one of the evaluates as true,
+ * then the compound filter will be evaluated as true
+ *
+ * @param items
+ * an array of items to include in the composite
+ */
+ public FilterItem(FilterItem... items) {
+ this(Arrays.asList(items));
+ }
+
+ private void require(String errorMessage, boolean b) {
+ if (!b) {
+ throw new IllegalArgumentException(errorMessage);
+ }
+ }
+
+ public SelectItem getSelectItem() {
+ return _selectItem;
+ }
+
+ public OperatorType getOperator() {
+ return _operator;
+ }
+
+ public Object getOperand() {
+ return _operand;
+ }
+
+ public String getExpression() {
+ return _expression;
+ }
+
+ public Query getQuery() {
+ return _query;
+ }
+
+ public LogicalOperator getLogicalOperator() {
+ return _logicalOperator;
+ }
+
+ public FilterItem setQuery(Query query) {
+ _query = query;
+ if (_childItems == null) {
+ if (_expression == null) {
+ if (_selectItem.getQuery() == null) {
+ _selectItem.setQuery(_query);
+ }
+ if (_operand instanceof SelectItem) {
+ SelectItem operand = (SelectItem) _operand;
+ if (operand.getQuery() == null) {
+ operand.setQuery(_query);
+ }
+ }
+ }
+ } else {
+ for (FilterItem item : _childItems) {
+ if (item.getQuery() == null) {
+ item.setQuery(_query);
+ }
+ }
+ }
+ return this;
+ }
+
+ @Override
+ public String toSql() {
+ return toSql(false);
+ }
+
+ /**
+ * Parses the constraint as a SQL Where-clause item
+ */
+ @Override
+ public String toSql(boolean includeSchemaInColumnPaths) {
+ if (_expression != null) {
+ return _expression;
+ }
+
+ StringBuilder sb = new StringBuilder();
+ if (_childItems == null) {
+ sb.append(_selectItem.getSameQueryAlias(includeSchemaInColumnPaths));
+
+ if (_operand == null && _operator == OperatorType.EQUALS_TO) {
+ sb.append(" IS NULL");
+ } else if (_operand == null && _operator == OperatorType.DIFFERENT_FROM) {
+ sb.append(" IS NOT NULL");
+ } else {
+ final Object operand = appendOperator(sb, _operand, _operator);
+
+ if (operand instanceof SelectItem) {
+ final String selectItemString = ((SelectItem) operand).getSameQueryAlias(includeSchemaInColumnPaths);
+ sb.append(selectItemString);
+ } else {
+ ColumnType columnType = _selectItem.getExpectedColumnType();
+ final String sqlValue = FormatHelper.formatSqlValue(columnType, operand);
+ sb.append(sqlValue);
+ }
+ }
+ } else {
+ sb.append('(');
+ for (int i = 0; i < _childItems.size(); i++) {
+ FilterItem item = _childItems.get(i);
+ if (i != 0) {
+ sb.append(' ');
+ sb.append(_logicalOperator.toString());
+ sb.append(' ');
+ }
+ sb.append(item.toSql());
+ }
+ sb.append(')');
+ }
+
+ return sb.toString();
+ }
+
+ @SuppressWarnings("deprecation")
+ public static Object appendOperator(StringBuilder sb, Object operand, OperatorType operator) {
+ switch (operator) {
+ case DIFFERENT_FROM:
+ sb.append(" <> ");
+ break;
+ case EQUALS_TO:
+ sb.append(" = ");
+ break;
+ case LIKE:
+ sb.append(" LIKE ");
+ break;
+ case GREATER_THAN:
+ case HIGHER_THAN:
+ sb.append(" > ");
+ break;
+ case LESS_THAN:
+ case LOWER_THAN:
+ sb.append(" < ");
+ break;
+ case IN:
+ sb.append(" IN ");
+ operand = CollectionUtils.toList(operand);
+ break;
+ default:
+ throw new IllegalStateException("Operator could not be determined");
+ }
+ return operand;
+ }
+
+ /**
+ * Does a "manual" evaluation, useful for CSV data and alike, where queries
+ * cannot be created.
+ */
+ public boolean evaluate(Row row) {
+ require("Expression-based filters cannot be manually evaluated", _expression == null);
+
+ if (_childItems == null) {
+ // Evaluate a single constraint
+ Object selectItemValue = row.getValue(_selectItem);
+ Object operandValue = _operand;
+ if (_operand instanceof SelectItem) {
+ SelectItem selectItem = (SelectItem) _operand;
+ operandValue = row.getValue(selectItem);
+ }
+ if (operandValue == null) {
+ if (_operator == OperatorType.DIFFERENT_FROM) {
+ return (selectItemValue != null);
+ } else if (_operator == OperatorType.EQUALS_TO) {
+ return (selectItemValue == null);
+ } else {
+ return false;
+ }
+ } else if (selectItemValue == null) {
+ if (_operator == OperatorType.DIFFERENT_FROM) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return compare(selectItemValue, operandValue);
+ }
+ } else {
+
+ // Evaluate several constraints
+ if (_logicalOperator == LogicalOperator.AND) {
+ // require all results to be true
+ for (FilterItem item : _childItems) {
+ boolean result = item.evaluate(row);
+ if (!result) {
+ return false;
+ }
+ }
+ return true;
+ } else {
+ // require at least one result to be true
+ for (FilterItem item : _childItems) {
+ boolean result = item.evaluate(row);
+ if (result) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ private boolean compare(Object selectItemValue, Object operandValue) {
+ Comparator<Object> comparator = ObjectComparator.getComparator();
+ if (_operator == OperatorType.DIFFERENT_FROM) {
+ return comparator.compare(selectItemValue, operandValue) != 0;
+ } else if (_operator == OperatorType.EQUALS_TO) {
+ return comparator.compare(selectItemValue, operandValue) == 0;
+ } else if (_operator == OperatorType.GREATER_THAN || _operator == OperatorType.HIGHER_THAN) {
+ return comparator.compare(selectItemValue, operandValue) > 0;
+ } else if (_operator == OperatorType.LESS_THAN || _operator == OperatorType.LOWER_THAN) {
+ return comparator.compare(selectItemValue, operandValue) < 0;
+ } else if (_operator == OperatorType.LIKE) {
+ WildcardPattern matcher = new WildcardPattern((String) operandValue, '%');
+ return matcher.matches((String) selectItemValue);
+ } else if (_operator == OperatorType.IN) {
+ Set<?> inValues = getInValues();
+ return inValues.contains(selectItemValue);
+ } else {
+ throw new IllegalStateException("Operator could not be determined");
+ }
+ }
+
+ /**
+ * Lazy initializes a set (for fast searching) of IN values.
+ *
+ * @return a hash set appropriate for IN clause evaluation
+ */
+ private Set<?> getInValues() {
+ if (_inValues == null) {
+ if (_operand instanceof Set) {
+ _inValues = (Set<?>) _operand;
+ } else {
+ List<?> list = CollectionUtils.toList(_operand);
+ _inValues = new HashSet<Object>(list);
+ }
+ }
+ return _inValues;
+ }
+
+ @Override
+ protected FilterItem clone() {
+ final List<FilterItem> orItems;
+ if (_childItems == null) {
+ orItems = null;
+ } else {
+ orItems = new ArrayList<FilterItem>(_childItems);
+ }
+
+ final Object operand;
+ if (_operand instanceof SelectItem) {
+ operand = ((SelectItem) _operand).clone();
+ } else {
+ operand = _operand;
+ }
+
+ final SelectItem selectItem;
+ if (_selectItem == null) {
+ selectItem = null;
+ } else {
+ selectItem = _selectItem.clone();
+ }
+
+ return new FilterItem(selectItem, _operator, operand, orItems, _expression, _logicalOperator);
+ }
+
+ public boolean isReferenced(Column column) {
+ if (column != null) {
+ if (_selectItem != null) {
+ if (_selectItem.isReferenced(column)) {
+ return true;
+ }
+ }
+ if (_operand != null && _operand instanceof SelectItem) {
+ if (((SelectItem) _operand).isReferenced(column)) {
+ return true;
+ }
+ }
+ if (_childItems != null) {
+ for (FilterItem item : _childItems) {
+ if (item.isReferenced(column)) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ identifiers.add(_expression);
+ identifiers.add(_operand);
+ identifiers.add(_childItems);
+ identifiers.add(_operator);
+ identifiers.add(_selectItem);
+ identifiers.add(_logicalOperator);
+ }
+
+ /**
+ * Gets the {@link FilterItem}s that this filter item consists of, if it is
+ * a compound filter item.
+ *
+ * @return
+ * @deprecated use {@link #getChildItems()} instead
+ */
+ @Deprecated
+ public FilterItem[] getOrItems() {
+ return getChildItems();
+ }
+
+ /**
+ * Gets the number of child items, if this is a compound filter item.
+ *
+ * @return
+ * @deprecated use {@link #getChildItemCount()} instead.
+ */
+ @Deprecated
+ public int getOrItemCount() {
+ return getChildItemCount();
+ }
+
+ /**
+ * Get the number of child items, if this is a compound filter item.
+ *
+ * @return
+ */
+ public int getChildItemCount() {
+ if (_childItems == null) {
+ return 0;
+ }
+ return _childItems.size();
+ }
+
+ /**
+ * Gets the {@link FilterItem}s that this filter item consists of, if it is
+ * a compound filter item.
+ *
+ * @return
+ */
+ public FilterItem[] getChildItems() {
+ if (_childItems == null) {
+ return null;
+ }
+ return _childItems.toArray(new FilterItem[_childItems.size()]);
+ }
+
+ /**
+ * Determines whether this {@link FilterItem} is a compound filter or not
+ * (ie. if it has child items or not)
+ *
+ * @return
+ */
+ public boolean isCompoundFilter() {
+ return _childItems != null;
+ }
+
+ @Override
+ public String toString() {
+ return toSql();
+ }
+
+ @Override
+ public boolean accept(Row row) {
+ return evaluate(row);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/FromClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/FromClause.java b/core/src/main/java/org/apache/metamodel/query/FromClause.java
new file mode 100644
index 0000000..950c246
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/FromClause.java
@@ -0,0 +1,103 @@
+/**
+ * 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.query;
+
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * Represents the FROM clause of a query containing FromItem's.
+ *
+ * @see FromItem
+ */
+public class FromClause extends AbstractQueryClause<FromItem> {
+
+ private static final long serialVersionUID = -8227310702249122115L;
+
+ public FromClause(Query query) {
+ super(query, AbstractQueryClause.PREFIX_FROM, AbstractQueryClause.DELIM_COMMA);
+ }
+
+ /**
+ * Gets the alias of a table, if it is registered (and visible, ie. not part
+ * of a sub-query) in the FromClause
+ *
+ * @param table
+ * the table to get the alias for
+ * @return the alias or null if none is found
+ */
+ public String getAlias(Table table) {
+ if (table != null) {
+ for (FromItem item : getItems()) {
+ String alias = item.getAlias(table);
+ if (alias != null) {
+ return alias;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Retrieves a table by it's reference which may be it's alias or it's
+ * qualified table name. Typically, this method is used to resolve a
+ * SelectItem with a reference like "foo.bar", where "foo" may either be an
+ * alias or a table name
+ *
+ * @param reference
+ * @return a FromItem which matches the provided reference string
+ */
+ public FromItem getItemByReference(String reference) {
+ if (reference == null) {
+ return null;
+ }
+ for (final FromItem item : getItems()) {
+ FromItem result = getItemByReference(item, reference);
+ if (result != null) {
+ return result;
+ }
+ }
+ return null;
+ }
+
+ private FromItem getItemByReference(FromItem item, String reference) {
+ final String alias = item.getAlias();
+ if (reference.equals(alias)) {
+ return item;
+ }
+
+ final Table table = item.getTable();
+ if (alias == null && table != null && reference.equals(table.getName())) {
+ return item;
+ }
+
+ final JoinType join = item.getJoin();
+ if (join != null) {
+ final FromItem leftResult = getItemByReference(item.getLeftSide(), reference);
+ if (leftResult != null) {
+ return leftResult;
+ }
+ final FromItem rightResult = getItemByReference(item.getRightSide(), reference);
+ if (rightResult != null) {
+ return rightResult;
+ }
+ }
+
+ return null;
+ }
+}
\ 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/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
new file mode 100644
index 0000000..2ea22bd
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/FromItem.java
@@ -0,0 +1,349 @@
+/**
+ * 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.query;
+
+import java.util.List;
+
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Relationship;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.BaseObject;
+
+/**
+ * Represents a FROM item. FROM items can take different forms:
+ * <ul>
+ * <li>table FROMs (eg. "FROM products p")</li>
+ * <lI>join FROMs with an ON clause (eg. "FROM products p INNER JOIN orders o ON
+ * p.id = o.product_id")</li>
+ * <li>subquery FROMs (eg. "FROM (SELECT * FROM products) p")</li>
+ * <li>expression FROM (any string based from item)</li>
+ * </ul>
+ *
+ * @see FromClause
+ */
+public class FromItem extends BaseObject implements QueryItem, Cloneable {
+
+ private static final long serialVersionUID = -6559220014058975193L;
+ private Table _table;
+ private String _alias;
+ private Query _subQuery;
+ private JoinType _join;
+ private FromItem _leftSide;
+ private FromItem _rightSide;
+ private SelectItem[] _leftOn;
+ private SelectItem[] _rightOn;
+ private Query _query;
+ private String _expression;
+
+ /**
+ * Private constructor, used for cloning
+ */
+ private FromItem() {
+ }
+
+ /**
+ * Constructor for table FROM clauses
+ */
+ public FromItem(Table table) {
+ _table = table;
+ }
+
+ /**
+ * Constructor for sub-query FROM clauses
+ *
+ * @param subQuery
+ * the subquery to use
+ */
+ public FromItem(Query subQuery) {
+ _subQuery = subQuery;
+ }
+
+ /**
+ * Constructor for join FROM clauses that join two tables using their
+ * relationship. The primary table of the relationship will be the left side
+ * of the join and the foreign table of the relationship will be the right
+ * side of the join.
+ *
+ * @param join
+ * the join type to use
+ * @param relationship
+ * the relationship to use for joining the tables
+ */
+ 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]);
+ }
+ _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]);
+ }
+ }
+
+ /**
+ * Constructor for advanced join types with custom relationships
+ *
+ * @param join
+ * the join type to use
+ * @param leftSide
+ * the left side of the join
+ * @param rightSide
+ * the right side of the join
+ * @param leftOn
+ * what left-side select items to use for the ON clause
+ * @param rightOn
+ * what right-side select items to use for the ON clause
+ */
+ public FromItem(JoinType join, FromItem leftSide, FromItem rightSide, SelectItem[] leftOn, SelectItem[] rightOn) {
+ _join = join;
+ _leftSide = leftSide;
+ _rightSide = rightSide;
+ _leftOn = leftOn;
+ _rightOn = rightOn;
+ }
+
+ /**
+ * Creates a single unvalidated from item based on a expression. Expression
+ * based from items are typically NOT datastore-neutral but are available
+ * for special "hacking" needs.
+ *
+ * Expression based from items can only be used for JDBC based datastores
+ * since they are translated directly into SQL.
+ *
+ * @param expression
+ * An expression to use for the from item, for example "MYTABLE".
+ */
+ public FromItem(String expression) {
+ if (expression == null) {
+ throw new IllegalArgumentException("Expression cannot be null");
+ }
+ _expression = expression;
+ }
+
+ public String getAlias() {
+ return _alias;
+ }
+
+ public String getSameQueryAlias() {
+ if (_alias != null) {
+ return _alias;
+ }
+ if (_table != null) {
+ return _table.getQuotedName();
+ }
+ return null;
+ }
+
+ public FromItem setAlias(String alias) {
+ _alias = alias;
+ return this;
+ }
+
+ public Table getTable() {
+ return _table;
+ }
+
+ public Query getSubQuery() {
+ return _subQuery;
+ }
+
+ public JoinType getJoin() {
+ return _join;
+ }
+
+ public FromItem getLeftSide() {
+ return _leftSide;
+ }
+
+ public FromItem getRightSide() {
+ return _rightSide;
+ }
+
+ public SelectItem[] getLeftOn() {
+ return _leftOn;
+ }
+
+ public SelectItem[] getRightOn() {
+ return _rightOn;
+ }
+
+ public String getExpression() {
+ return _expression;
+ }
+
+ @Override
+ public String toSql() {
+ return toSql(false);
+ }
+
+ @Override
+ public String toSql(boolean includeSchemaInColumnPaths) {
+ final String stringNoAlias = toStringNoAlias(includeSchemaInColumnPaths);
+ final StringBuilder sb = new StringBuilder(stringNoAlias);
+ if (_join != null && _alias != null) {
+ sb.insert(0, '(');
+ sb.append(')');
+ }
+ if (_alias != null) {
+ sb.append(' ');
+ sb.append(_alias);
+ }
+ return sb.toString();
+ }
+
+ public String toStringNoAlias() {
+ return toStringNoAlias(false);
+ }
+
+ public String toStringNoAlias(boolean includeSchemaInColumnPaths) {
+ if (_expression != null) {
+ return _expression;
+ }
+ StringBuilder sb = new StringBuilder();
+ if (_table != null) {
+ if (_table.getSchema() != null && _table.getSchema().getName() != null) {
+ sb.append(_table.getSchema().getName());
+ sb.append('.');
+ }
+ sb.append(_table.getQuotedName());
+ } else if (_subQuery != null) {
+ sb.append('(');
+ sb.append(_subQuery.toSql(includeSchemaInColumnPaths));
+ sb.append(')');
+ } else if (_join != null) {
+ String leftSideAlias = _leftSide.getSameQueryAlias();
+ String rightSideAlias = _rightSide.getSameQueryAlias();
+ sb.append(_leftSide.toSql());
+ sb.append(' ');
+ sb.append(_join);
+ sb.append(" JOIN ");
+ sb.append(_rightSide.toSql());
+ for (int i = 0; i < _leftOn.length; i++) {
+ if (i == 0) {
+ sb.append(" ON ");
+ } else {
+ sb.append(" AND ");
+ }
+ SelectItem primary = _leftOn[i];
+ appendJoinOnItem(sb, leftSideAlias, primary);
+
+ sb.append(" = ");
+
+ SelectItem foreign = _rightOn[i];
+ appendJoinOnItem(sb, rightSideAlias, foreign);
+ }
+ }
+ return sb.toString();
+ }
+
+ private void appendJoinOnItem(StringBuilder sb, String sideAlias, SelectItem onItem) {
+ final FromItem fromItem = onItem.getFromItem();
+ if (fromItem != null && fromItem.getSubQuery() != null && fromItem.getAlias() != null) {
+ // there's a corner case scenario where an ON item references a
+ // subquery being joined. In that case the getSuperQueryAlias()
+ // method will include the subquery alias.
+ final String superQueryAlias = onItem.getSuperQueryAlias();
+ sb.append(superQueryAlias);
+ return;
+ }
+
+ if (sideAlias != null) {
+ sb.append(sideAlias);
+ sb.append('.');
+ }
+ final String superQueryAlias = onItem.getSuperQueryAlias();
+ sb.append(superQueryAlias);
+ }
+
+ /**
+ * Gets the alias of a table, if it is registered (and visible, ie. not part
+ * of a sub-query) in the FromItem
+ *
+ * @param table
+ * the table to get the alias for
+ * @return the alias or null if none is found
+ */
+ public String getAlias(Table table) {
+ String result = null;
+ if (table != null) {
+ // Search recursively through left and right side, unless they
+ // are sub-query FromItems
+ if (table.equals(_table)) {
+ result = _alias;
+ } else if (_join != null) {
+ result = _rightSide.getAlias(table);
+ if (result == null) {
+ result = _leftSide.getAlias(table);
+ }
+ }
+ }
+ return result;
+ }
+
+ public Query getQuery() {
+ return _query;
+ }
+
+ public QueryItem setQuery(Query query) {
+ _query = query;
+ return this;
+ }
+
+ @Override
+ protected FromItem clone() {
+ FromItem f = new FromItem();
+ f._alias = _alias;
+ f._join = _join;
+ f._table = _table;
+ f._expression = _expression;
+ if (_subQuery != null) {
+ f._subQuery = _subQuery.clone();
+ }
+ if (_leftOn != null && _leftSide != null && _rightOn != null && _rightSide != null) {
+ f._leftSide = _leftSide.clone();
+ f._leftOn = _leftOn.clone();
+ f._rightSide = _rightSide.clone();
+ f._rightOn = _rightOn.clone();
+ }
+ return f;
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ identifiers.add(_table);
+ identifiers.add(_alias);
+ identifiers.add(_subQuery);
+ identifiers.add(_join);
+ identifiers.add(_leftSide);
+ identifiers.add(_rightSide);
+ identifiers.add(_leftOn);
+ identifiers.add(_rightOn);
+ identifiers.add(_expression);
+ }
+
+ @Override
+ public String toString() {
+ return toSql();
+ }
+}
\ 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/query/FunctionType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/FunctionType.java b/core/src/main/java/org/apache/metamodel/query/FunctionType.java
new file mode 100644
index 0000000..c8d79c7
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/FunctionType.java
@@ -0,0 +1,122 @@
+/**
+ * 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.query;
+
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.util.AggregateBuilder;
+
+/**
+ * Represents an aggregate function to use in a SelectItem.
+ *
+ * @see SelectItem
+ */
+public enum FunctionType {
+
+ COUNT {
+ @Override
+ public AggregateBuilder<Long> build() {
+ return new CountAggregateBuilder();
+ }
+ },
+ AVG {
+ @Override
+ public AggregateBuilder<Double> build() {
+ return new AverageAggregateBuilder();
+ }
+ },
+ SUM {
+ @Override
+ public AggregateBuilder<Double> build() {
+ return new SumAggregateBuilder();
+ }
+ },
+ MAX {
+ @Override
+ public AggregateBuilder<Object> build() {
+ return new MaxAggregateBuilder();
+ }
+ },
+ MIN {
+ @Override
+ public AggregateBuilder<Object> build() {
+ return new MinAggregateBuilder();
+ }
+ };
+
+ public ColumnType getExpectedColumnType(ColumnType type) {
+ switch (this) {
+ case COUNT:
+ return ColumnType.BIGINT;
+ case AVG:
+ case SUM:
+ return ColumnType.DOUBLE;
+ case MAX:
+ case MIN:
+ return type;
+ default:
+ return type;
+ }
+ }
+
+ public SelectItem createSelectItem(Column column) {
+ return new SelectItem(this, column);
+ }
+
+ public SelectItem createSelectItem(String expression, String alias) {
+ return new SelectItem(this, expression, alias);
+ }
+
+ public Object evaluate(Iterable<?> values) {
+ AggregateBuilder<?> builder = build();
+ for (Object object : values) {
+ builder.add(object);
+ }
+ return builder.getAggregate();
+ }
+
+ /**
+ * Executes the function
+ *
+ * @param values
+ * the values to be evaluated. If a value is null it won't be
+ * evaluated
+ * @return the result of the function execution. The return type class is
+ * dependent on the FunctionType and the values provided. COUNT
+ * yields a Long, AVG and SUM yields Double values and MAX and MIN
+ * yields the type of the provided values.
+ */
+ public Object evaluate(Object... values) {
+ AggregateBuilder<?> builder = build();
+ for (Object object : values) {
+ builder.add(object);
+ }
+ return builder.getAggregate();
+ }
+
+ public abstract AggregateBuilder<?> build();
+
+ public static FunctionType get(String functionName) {
+ try {
+ return valueOf(functionName);
+ } catch (IllegalArgumentException e) {
+ return null;
+ }
+ }
+}
\ 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/query/GroupByClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/GroupByClause.java b/core/src/main/java/org/apache/metamodel/query/GroupByClause.java
new file mode 100644
index 0000000..8e7e6bd
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/GroupByClause.java
@@ -0,0 +1,47 @@
+/**
+ * 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.query;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents the GROUP BY clause of a query that contains GroupByItem's.
+ *
+ * @see GroupByItem
+ */
+public class GroupByClause extends AbstractQueryClause<GroupByItem> {
+
+ private static final long serialVersionUID = -3824934110331202101L;
+
+ public GroupByClause(Query query) {
+ super(query, AbstractQueryClause.PREFIX_GROUP_BY,
+ AbstractQueryClause.DELIM_COMMA);
+ }
+
+ public List<SelectItem> getEvaluatedSelectItems() {
+ final List<SelectItem> result = new ArrayList<SelectItem>();
+ final List<GroupByItem> items = getItems();
+ for (GroupByItem item : items) {
+ result.add(item.getSelectItem());
+ }
+ return result;
+ }
+
+}
\ 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/query/GroupByItem.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/GroupByItem.java b/core/src/main/java/org/apache/metamodel/query/GroupByItem.java
new file mode 100644
index 0000000..cf94623
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/GroupByItem.java
@@ -0,0 +1,91 @@
+/**
+ * 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.query;
+
+import java.util.List;
+
+import org.eobjects.metamodel.util.BaseObject;
+
+/**
+ * Represents a GROUP BY item. GroupByItems always use a select item (that may
+ * or not be a part of the query already) for grouping.
+ *
+ * @see GroupByClause
+ */
+public class GroupByItem extends BaseObject implements QueryItem, Cloneable {
+
+ private static final long serialVersionUID = 5218878395877852919L;
+ private final SelectItem _selectItem;
+ private Query _query;
+
+ /**
+ * Constructs a GROUP BY item based on a select item that should be grouped.
+ *
+ * @param selectItem
+ */
+ public GroupByItem(SelectItem selectItem) {
+ if (selectItem == null) {
+ throw new IllegalArgumentException("SelectItem cannot be null");
+ }
+ _selectItem = selectItem;
+ }
+
+ public SelectItem getSelectItem() {
+ return _selectItem;
+ }
+
+ @Override
+ public String toSql() {
+ return toSql(false);
+ }
+
+ @Override
+ public String toSql(boolean includeSchemaInColumnPaths) {
+ final String sameQueryAlias = _selectItem.getSameQueryAlias(includeSchemaInColumnPaths);
+ return sameQueryAlias;
+ }
+
+ @Override
+ public String toString() {
+ return toSql();
+ }
+
+ public Query getQuery() {
+ return _query;
+ }
+
+ public GroupByItem setQuery(Query query) {
+ _query = query;
+ if (_selectItem != null) {
+ _selectItem.setQuery(query);
+ }
+ return this;
+ }
+
+ @Override
+ protected GroupByItem clone() {
+ GroupByItem g = new GroupByItem(_selectItem.clone());
+ return g;
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ identifiers.add(_selectItem);
+ }
+}
\ 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/query/JoinType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/JoinType.java b/core/src/main/java/org/apache/metamodel/query/JoinType.java
new file mode 100644
index 0000000..c40ab0e
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/JoinType.java
@@ -0,0 +1,29 @@
+/**
+ * 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.query;
+
+/**
+ * Represents a join type, used in a FromItem.
+ *
+ * @see FromItem
+ */
+public enum JoinType {
+
+ INNER, LEFT, RIGHT;
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/LogicalOperator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/LogicalOperator.java b/core/src/main/java/org/apache/metamodel/query/LogicalOperator.java
new file mode 100644
index 0000000..a17cb1e
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/LogicalOperator.java
@@ -0,0 +1,28 @@
+/**
+ * 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.query;
+
+/**
+ * Represents a logical operator (AND or OR) to use when defining compound
+ * {@link FilterItem}s.
+ */
+public enum LogicalOperator {
+
+ AND, OR
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/MaxAggregateBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/MaxAggregateBuilder.java b/core/src/main/java/org/apache/metamodel/query/MaxAggregateBuilder.java
new file mode 100644
index 0000000..93591f1
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/MaxAggregateBuilder.java
@@ -0,0 +1,48 @@
+/**
+ * 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.query;
+
+import org.eobjects.metamodel.util.AggregateBuilder;
+import org.eobjects.metamodel.util.ObjectComparator;
+
+final class MaxAggregateBuilder implements AggregateBuilder<Object> {
+
+ private Object max;
+
+ @Override
+ public void add(Object o) {
+ if (o == null) {
+ return;
+ }
+ if (max == null) {
+ max = o;
+ } else {
+ Comparable<Object> comparable = ObjectComparator.getComparable(max);
+ if (comparable.compareTo(o) < 0) {
+ max = o;
+ }
+ }
+ }
+
+ @Override
+ public Object getAggregate() {
+ return max;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/MinAggregateBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/MinAggregateBuilder.java b/core/src/main/java/org/apache/metamodel/query/MinAggregateBuilder.java
new file mode 100644
index 0000000..5321b22
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/MinAggregateBuilder.java
@@ -0,0 +1,48 @@
+/**
+ * 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.query;
+
+import org.eobjects.metamodel.util.AggregateBuilder;
+import org.eobjects.metamodel.util.ObjectComparator;
+
+final class MinAggregateBuilder implements AggregateBuilder<Object> {
+
+ private Object min;
+
+ @Override
+ public void add(Object o) {
+ if (o == null) {
+ return;
+ }
+ if (min == null) {
+ min = o;
+ } else {
+ Comparable<Object> comparable = ObjectComparator.getComparable(min);
+ if (comparable.compareTo(o) > 0) {
+ min = o;
+ }
+ }
+ }
+
+ @Override
+ public Object getAggregate() {
+ return min;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/OperatorType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/OperatorType.java b/core/src/main/java/org/apache/metamodel/query/OperatorType.java
new file mode 100644
index 0000000..3f4782e
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/OperatorType.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.query;
+
+/**
+ * Defines the types of operators that can be used in filters.
+ *
+ * @see FilterItem
+ */
+public enum OperatorType {
+
+ EQUALS_TO("="), DIFFERENT_FROM("<>"), LIKE("LIKE"), GREATER_THAN(">"), LESS_THAN("<"), IN("IN"),
+
+ /**
+ * @deprecated use {@link #LESS_THAN} instead.
+ */
+ @Deprecated
+ LOWER_THAN("<"),
+
+ /**
+ * @deprecated use {@link #GREATER_THAN} instead.
+ */
+ @Deprecated
+ HIGHER_THAN(">");
+
+ private final String _sql;
+
+ private OperatorType(String sql) {
+ _sql = sql;
+ }
+
+ public String toSql() {
+ return _sql;
+ }
+
+ /**
+ * Converts from SQL string literals to an OperatorType. Valid SQL values
+ * are "=", "<>", "LIKE", ">" and "<".
+ *
+ * @param sqlType
+ * @return a OperatorType object representing the specified SQL type
+ */
+ public static OperatorType convertOperatorType(String sqlType) {
+ if (sqlType != null) {
+ for (OperatorType operator : values()) {
+ if (sqlType.equals(operator.toSql())) {
+ return operator;
+ }
+ }
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/OrderByClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/OrderByClause.java b/core/src/main/java/org/apache/metamodel/query/OrderByClause.java
new file mode 100644
index 0000000..8ce04ec
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/OrderByClause.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.query;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents the ORDER BY clause of a query containing OrderByItem's. The order
+ * and direction of the OrderItems define the way that the result of a query
+ * will be sorted.
+ *
+ * @see OrderByItem
+ */
+public class OrderByClause extends AbstractQueryClause<OrderByItem> {
+
+ private static final long serialVersionUID = 2441926135870143715L;
+
+ public OrderByClause(Query query) {
+ super(query, AbstractQueryClause.PREFIX_ORDER_BY,
+ AbstractQueryClause.DELIM_COMMA);
+ }
+
+ public List<SelectItem> getEvaluatedSelectItems() {
+ final List<SelectItem> result = new ArrayList<SelectItem>();
+ final List<OrderByItem> items = getItems();
+ for (OrderByItem item : items) {
+ result.add(item.getSelectItem());
+ }
+ return result;
+ }
+
+}
\ 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/query/OrderByItem.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/OrderByItem.java b/core/src/main/java/org/apache/metamodel/query/OrderByItem.java
new file mode 100644
index 0000000..a52aa1d
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/OrderByItem.java
@@ -0,0 +1,152 @@
+/**
+ * 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.query;
+
+import java.util.List;
+
+import org.eobjects.metamodel.util.BaseObject;
+
+/**
+ * Represents an ORDER BY item. An OrderByItem sorts the resulting DataSet
+ * according to a SelectItem that may or may not be a part of the query already.
+ *
+ * @see OrderByClause
+ * @see SelectItem
+ */
+public class OrderByItem extends BaseObject implements QueryItem, Cloneable {
+
+ public enum Direction {
+ ASC, DESC
+ }
+
+ private static final long serialVersionUID = -8397473619828484774L;
+ private final SelectItem _selectItem;
+ private Direction _direction;
+ private Query _query;
+
+ /**
+ * Creates an OrderByItem
+ *
+ * @param selectItem
+ * the select item to order
+ * @param direction
+ * the direction to order the select item
+ */
+ public OrderByItem(SelectItem selectItem, Direction direction) {
+ if (selectItem == null) {
+ throw new IllegalArgumentException("SelectItem cannot be null");
+ }
+ _selectItem = selectItem;
+ _direction = direction;
+ }
+
+ /**
+ * Creates an OrderByItem
+ *
+ * @param selectItem
+ * @param ascending
+ * @deprecated user OrderByItem(SelectItem, Direction) instead
+ */
+ @Deprecated
+ public OrderByItem(SelectItem selectItem, boolean ascending) {
+ if (selectItem == null) {
+ throw new IllegalArgumentException("SelectItem cannot be null");
+ }
+ _selectItem = selectItem;
+ if (ascending) {
+ _direction = Direction.ASC;
+ } else {
+ _direction = Direction.DESC;
+ }
+ }
+
+ /**
+ * Creates an ascending OrderByItem
+ *
+ * @param selectItem
+ */
+ public OrderByItem(SelectItem selectItem) {
+ this(selectItem, Direction.ASC);
+ }
+
+
+ @Override
+ public String toSql(boolean includeSchemaInColumnPaths) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(_selectItem.getSameQueryAlias(includeSchemaInColumnPaths) + ' ');
+ sb.append(_direction);
+ return sb.toString();
+ }
+
+ @Override
+ public String toSql() {
+ return toSql(false);
+ }
+
+ public boolean isAscending() {
+ return (_direction == Direction.ASC);
+ }
+
+ public boolean isDescending() {
+ return (_direction == Direction.DESC);
+ }
+
+ public Direction getDirection() {
+ return _direction;
+ }
+
+ public OrderByItem setDirection(Direction direction) {
+ _direction = direction;
+ return this;
+ }
+
+ public SelectItem getSelectItem() {
+ return _selectItem;
+ }
+
+ public Query getQuery() {
+ return _query;
+ }
+
+ public OrderByItem setQuery(Query query) {
+ _query = query;
+ if (_selectItem != null) {
+ _selectItem.setQuery(query);
+ }
+ return this;
+ }
+
+ @Override
+ protected OrderByItem clone() {
+ OrderByItem o = new OrderByItem(_selectItem.clone());
+ o._direction = _direction;
+ return o;
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ identifiers.add(_direction);
+ identifiers.add(_selectItem);
+ }
+
+ @Override
+ public String toString() {
+ return toSql();
+ }
+}
\ 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/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
new file mode 100644
index 0000000..0986b6b
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/Query.java
@@ -0,0 +1,603 @@
+/**
+ * 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.query;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.query.OrderByItem.Direction;
+import org.eobjects.metamodel.query.parser.QueryParserException;
+import org.eobjects.metamodel.query.parser.QueryPartCollectionProcessor;
+import org.eobjects.metamodel.query.parser.QueryPartParser;
+import org.eobjects.metamodel.query.parser.QueryPartProcessor;
+import org.eobjects.metamodel.query.parser.SelectItemParser;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.BaseObject;
+import org.eobjects.metamodel.util.BooleanComparator;
+import org.eobjects.metamodel.util.FormatHelper;
+import org.eobjects.metamodel.util.NumberComparator;
+
+/**
+ * Represents a query to retrieve data by. A query is made up of six clauses,
+ * equivalent to the SQL standard:
+ * <ul>
+ * <li>the SELECT clause, which define the wanted columns of the resulting
+ * DataSet</li>
+ * <li>the FROM clause, which define where to retrieve the data from</li>
+ * <li>the WHERE clause, which define filters on the retrieved data</li>
+ * <li>the GROUP BY clause, which define if the result should be grouped and
+ * aggregated according to some columns acting as categories</li>
+ * <li>the HAVING clause, which define filters on the grouped data</li>
+ * <li>the ORDER BY clause, which define sorting of the resulting dataset</li>
+ * </ul>
+ *
+ * In addition two properties are applied to queries to limit the resulting
+ * dataset:
+ * <ul>
+ * <li>First row: The first row (aka. offset) of the result of the query.</li>
+ * <li>Max rows: The maximum amount of rows to return when executing the query.</li>
+ * </ul>
+ *
+ * Queries are executed using the DataContext.executeQuery method or can
+ * alternatively be used directly in JDBC by using the toString() method.
+ *
+ * @see DataContext
+ */
+public final class Query extends BaseObject implements Cloneable, Serializable {
+
+ private static final long serialVersionUID = -5976325207498574216L;
+
+ private final SelectClause _selectClause;
+ private final FromClause _fromClause;
+ private final FilterClause _whereClause;
+ private final GroupByClause _groupByClause;
+ private final FilterClause _havingClause;
+ private final OrderByClause _orderByClause;
+
+ private Integer _maxRows;
+ private Integer _firstRow;
+
+ public Query() {
+ _selectClause = new SelectClause(this);
+ _fromClause = new FromClause(this);
+ _whereClause = new FilterClause(this, AbstractQueryClause.PREFIX_WHERE);
+ _groupByClause = new GroupByClause(this);
+ _havingClause = new FilterClause(this, AbstractQueryClause.PREFIX_HAVING);
+ _orderByClause = new OrderByClause(this);
+ }
+
+ public Query select(Column column, FromItem fromItem) {
+ SelectItem selectItem = new SelectItem(column, fromItem);
+ return select(selectItem);
+ }
+
+ public Query select(Column... columns) {
+ for (Column column : columns) {
+ SelectItem selectItem = new SelectItem(column);
+ selectItem.setQuery(this);
+ _selectClause.addItem(selectItem);
+ }
+ return this;
+ }
+
+ public Query select(SelectItem... items) {
+ _selectClause.addItems(items);
+ return this;
+ }
+
+ public Query select(FunctionType functionType, Column column) {
+ _selectClause.addItem(new SelectItem(functionType, column));
+ return this;
+ }
+
+ public Query select(String expression, String alias) {
+ return select(new SelectItem(expression, alias));
+ }
+
+ /**
+ * Adds a selection to this query.
+ *
+ * @param expression
+ * @return
+ */
+ public Query select(String expression) {
+ if ("*".equals(expression)) {
+ return selectAll();
+ }
+
+ SelectItem selectItem = findSelectItem(expression, true);
+ return select(selectItem);
+ }
+
+ private SelectItem findSelectItem(String expression, boolean allowExpressionBasedSelectItem) {
+ SelectItemParser parser = new SelectItemParser(this, allowExpressionBasedSelectItem);
+ return parser.findSelectItem(expression);
+ }
+
+ /**
+ * Select all available select items from all currently available FROM
+ * items. Equivalent of the expression "SELECT * FROM ..." in SQL.
+ *
+ * @return
+ */
+ public Query selectAll() {
+ List<FromItem> items = getFromClause().getItems();
+ for (FromItem fromItem : items) {
+ selectAll(fromItem);
+ }
+ return this;
+ }
+
+ public Query selectAll(final FromItem fromItem) {
+ if (fromItem.getTable() != null) {
+ final Column[] columns = fromItem.getTable().getColumns();
+ for (final Column column : columns) {
+ select(column, fromItem);
+ }
+ } else if (fromItem.getJoin() != null) {
+ selectAll(fromItem.getLeftSide());
+ selectAll(fromItem.getRightSide());
+ } else if (fromItem.getSubQuery() != null) {
+ final List<SelectItem> items = fromItem.getSubQuery().getSelectClause().getItems();
+ for (final SelectItem subQuerySelectItem : items) {
+ select(new SelectItem(subQuerySelectItem, fromItem));
+ }
+ } else {
+ throw new MetaModelException("All select items ('*') not determinable with from item: " + fromItem);
+ }
+ return this;
+ }
+
+ public Query selectDistinct() {
+ _selectClause.setDistinct(true);
+ return this;
+ }
+
+ public Query selectCount() {
+ return select(SelectItem.getCountAllItem());
+ }
+
+ public Query from(FromItem... items) {
+ _fromClause.addItems(items);
+ return this;
+ }
+
+ public Query from(Table table) {
+ return from(new FromItem(table));
+ }
+
+ public Query from(String expression) {
+ return from(new FromItem(expression));
+ }
+
+ public Query from(Table table, String alias) {
+ return from(new FromItem(table).setAlias(alias));
+ }
+
+ public Query from(Table leftTable, Table rightTable, JoinType joinType, Column leftOnColumn, Column rightOnColumn) {
+ SelectItem[] leftOn = new SelectItem[] { new SelectItem(leftOnColumn) };
+ SelectItem[] rightOn = new SelectItem[] { new SelectItem(rightOnColumn) };
+ FromItem fromItem = new FromItem(joinType, new FromItem(leftTable), new FromItem(rightTable), leftOn, rightOn);
+ return from(fromItem);
+ }
+
+ public Query groupBy(String... groupByTokens) {
+ for (String groupByToken : groupByTokens) {
+ SelectItem selectItem = findSelectItem(groupByToken, true);
+ groupBy(new GroupByItem(selectItem));
+ }
+ return this;
+ }
+
+ public Query groupBy(GroupByItem... items) {
+ for (GroupByItem item : items) {
+ SelectItem selectItem = item.getSelectItem();
+ if (selectItem != null && selectItem.getQuery() == null) {
+ selectItem.setQuery(this);
+ }
+ }
+ _groupByClause.addItems(items);
+ return this;
+ }
+
+ public Query groupBy(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;
+ }
+
+ public Query orderBy(String... orderByTokens) {
+ for (String orderByToken : orderByTokens) {
+ orderByToken = orderByToken.trim();
+ final Direction direction;
+ if (orderByToken.toUpperCase().endsWith("DESC")) {
+ direction = Direction.DESC;
+ orderByToken = orderByToken.substring(0, orderByToken.length() - 4).trim();
+ } else if (orderByToken.toUpperCase().endsWith("ASC")) {
+ direction = Direction.ASC;
+ orderByToken = orderByToken.substring(0, orderByToken.length() - 3).trim();
+ } else {
+ direction = Direction.ASC;
+ }
+
+ OrderByItem orderByItem = new OrderByItem(findSelectItem(orderByToken, true), direction);
+ orderBy(orderByItem);
+ }
+ return this;
+ }
+
+ public Query orderBy(Column column) {
+ return orderBy(column, Direction.ASC);
+ }
+
+ /**
+ * @deprecated use orderBy(Column, Direction) instead
+ */
+ @Deprecated
+ public Query orderBy(Column column, boolean ascending) {
+ if (ascending) {
+ return orderBy(column, Direction.ASC);
+ } else {
+ return orderBy(column, Direction.DESC);
+ }
+ }
+
+ public Query orderBy(Column column, Direction direction) {
+ SelectItem selectItem = _selectClause.getSelectItem(column);
+ if (selectItem == null) {
+ selectItem = new SelectItem(column);
+ }
+ return orderBy(new OrderByItem(selectItem, direction));
+ }
+
+ public Query where(FilterItem... items) {
+ _whereClause.addItems(items);
+ return this;
+ }
+
+ public Query where(Iterable<FilterItem> items) {
+ _whereClause.addItems(items);
+ return this;
+ }
+
+ public Query where(String... whereItemTokens) {
+ for (String whereItemToken : whereItemTokens) {
+ FilterItem filterItem = findFilterItem(whereItemToken);
+ where(filterItem);
+ }
+ return this;
+ }
+
+ private FilterItem findFilterItem(String expression) {
+ final QueryPartCollectionProcessor collectionProcessor = new QueryPartCollectionProcessor();
+ new QueryPartParser(collectionProcessor, expression, " AND ", " OR ").parse();
+
+ final List<String> tokens = collectionProcessor.getTokens();
+ final List<String> delims = collectionProcessor.getDelims();
+ if (tokens.size() == 1) {
+ expression = tokens.get(0);
+ } else {
+ final LogicalOperator logicalOperator = LogicalOperator.valueOf(delims.get(1).trim());
+
+ final List<FilterItem> filterItems = new ArrayList<FilterItem>();
+ for (int i = 0; i < tokens.size(); i++) {
+ String token = tokens.get(i);
+ FilterItem filterItem = findFilterItem(token);
+ filterItems.add(filterItem);
+ }
+ return new FilterItem(logicalOperator, filterItems);
+ }
+
+ OperatorType operator = null;
+ String leftSide = null;
+ final String rightSide;
+ {
+ String rightSideCandidate = null;
+ final OperatorType[] operators = OperatorType.values();
+ for (OperatorType operatorCandidate : operators) {
+ final int operatorIndex = expression.indexOf(' ' + operatorCandidate.toSql() + ' ');
+ if (operatorIndex > 0) {
+ operator = operatorCandidate;
+ leftSide = expression.substring(0, operatorIndex).trim();
+ rightSideCandidate = expression.substring(operatorIndex + operator.toSql().length() + 2).trim();
+ break;
+ }
+ }
+
+ if (operator == null) {
+ // check special cases for IS NULL and IS NOT NULL
+ if (expression.endsWith(" IS NOT NULL")) {
+ operator = OperatorType.DIFFERENT_FROM;
+ leftSide = expression.substring(0, expression.lastIndexOf(" IS NOT NULL")).trim();
+ rightSideCandidate = "NULL";
+ } else if (expression.endsWith(" IS NULL")) {
+ operator = OperatorType.EQUALS_TO;
+ leftSide = expression.substring(0, expression.lastIndexOf(" IS NULL")).trim();
+ rightSideCandidate = "NULL";
+ }
+ }
+
+ rightSide = rightSideCandidate;
+ }
+
+ if (operator == null) {
+ return new FilterItem(expression);
+ }
+
+ final SelectItem selectItem = findSelectItem(leftSide, false);
+ if (selectItem == null) {
+ return new FilterItem(expression);
+ }
+
+ final Object operand;
+ if (operator == OperatorType.IN) {
+ final List<Object> list = new ArrayList<Object>();
+ new QueryPartParser(new QueryPartProcessor() {
+ @Override
+ public void parse(String delim, String itemToken) {
+ Object operand = createOperand(itemToken, selectItem, false);
+ list.add(operand);
+ }
+ }, rightSide, ",").parse();
+ operand = list;
+ } else {
+ operand = createOperand(rightSide, selectItem, true);
+ }
+
+ return new FilterItem(selectItem, operator, operand);
+ }
+
+ private Object createOperand(final String token, final SelectItem leftSelectItem, final boolean searchSelectItems) {
+ if (token.equalsIgnoreCase("NULL")) {
+ return null;
+ }
+
+ if (token.startsWith("'") && token.endsWith("'") && token.length() > 2) {
+ String stringOperand = token.substring(1, token.length() - 1);
+ stringOperand = stringOperand.replaceAll("\\\\'", "'");
+ return stringOperand;
+ }
+
+ if (searchSelectItems) {
+ final SelectItem selectItem = findSelectItem(token, false);
+ if (selectItem != null) {
+ return selectItem;
+ }
+ }
+
+ final ColumnType expectedColumnType = leftSelectItem.getExpectedColumnType();
+ final Object result;
+ if (expectedColumnType == null) {
+ // We're assuming number here, but it could also be boolean or a
+ // time based type. But anyways, this should not happen since
+ // expected column type should be available.
+ result = NumberComparator.toNumber(token);
+ } else if (expectedColumnType.isBoolean()) {
+ result = BooleanComparator.toBoolean(token);
+ } else if (expectedColumnType.isTimeBased()) {
+ result = FormatHelper.parseSqlTime(expectedColumnType, token);
+ } else {
+ result = NumberComparator.toNumber(token);
+ }
+
+ if (result == null) {
+ // shouldn't happen since only "NULL" is parsed as null.
+ throw new QueryParserException("Could not parse operand: " + token);
+ }
+
+ return result;
+ }
+
+ public Query where(SelectItem selectItem, OperatorType operatorType, Object operand) {
+ return where(new FilterItem(selectItem, operatorType, operand));
+ }
+
+ public Query where(Column column, OperatorType operatorType, Object operand) {
+ SelectItem selectItem = _selectClause.getSelectItem(column);
+ if (selectItem == null) {
+ selectItem = new SelectItem(column);
+ }
+ return where(selectItem, operatorType, operand);
+ }
+
+ public Query having(FilterItem... items) {
+ _havingClause.addItems(items);
+ return this;
+ }
+
+ public Query having(FunctionType function, Column column, OperatorType operatorType, Object operand) {
+ SelectItem selectItem = new SelectItem(function, column);
+ return having(new FilterItem(selectItem, operatorType, operand));
+ }
+
+ public Query having(Column column, OperatorType operatorType, Object operand) {
+ SelectItem selectItem = _selectClause.getSelectItem(column);
+ if (selectItem == null) {
+ selectItem = new SelectItem(column);
+ }
+ return having(new FilterItem(selectItem, operatorType, operand));
+ }
+
+ public Query having(String... havingItemTokens) {
+ for (String havingItemToken : havingItemTokens) {
+ FilterItem filterItem = findFilterItem(havingItemToken);
+ having(filterItem);
+ }
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return toSql();
+ }
+
+ /*
+ * A string representation of this query. This representation will be SQL 99
+ * compatible and can thus be used for database queries on databases that
+ * meet SQL standards.
+ */
+ public String toSql() {
+ return toSql(false);
+ }
+
+ protected String toSql(boolean includeSchemaInColumnPaths) {
+ final StringBuilder sb = new StringBuilder();
+ sb.append(_selectClause.toSql(includeSchemaInColumnPaths));
+ sb.append(_fromClause.toSql(includeSchemaInColumnPaths));
+ sb.append(_whereClause.toSql(includeSchemaInColumnPaths));
+ sb.append(_groupByClause.toSql(includeSchemaInColumnPaths));
+ sb.append(_havingClause.toSql(includeSchemaInColumnPaths));
+ sb.append(_orderByClause.toSql(includeSchemaInColumnPaths));
+ return sb.toString();
+ }
+
+ public SelectClause getSelectClause() {
+ return _selectClause;
+ }
+
+ public FromClause getFromClause() {
+ return _fromClause;
+ }
+
+ public FilterClause getWhereClause() {
+ return _whereClause;
+ }
+
+ public GroupByClause getGroupByClause() {
+ return _groupByClause;
+ }
+
+ public FilterClause getHavingClause() {
+ return _havingClause;
+ }
+
+ public OrderByClause getOrderByClause() {
+ return _orderByClause;
+ }
+
+ /**
+ * Sets the maximum number of rows to be queried. If the result of the query
+ * yields more rows they should be discarded.
+ *
+ * @param maxRows
+ * the number of desired maximum rows. Can be null (default) for
+ * no limits
+ * @return this query
+ */
+ public Query setMaxRows(Integer maxRows) {
+ if (maxRows != null) {
+ final int maxRowsValue = maxRows.intValue();
+ if (maxRowsValue == 0) {
+ throw new IllegalArgumentException("Max rows cannot be zero");
+ }
+ if (maxRowsValue < 0) {
+ throw new IllegalArgumentException("Max rows cannot be negative");
+ }
+ }
+ _maxRows = maxRows;
+ return this;
+ }
+
+ /**
+ * @return the number of maximum rows to yield from executing this query or
+ * null if no maximum/limit is set.
+ */
+ public Integer getMaxRows() {
+ return _maxRows;
+ }
+
+ /**
+ * Sets the first row (aka offset) of the query's result. The row number is
+ * 1-based, so setting a first row value of 1 is equivalent to not setting
+ * it at all..
+ *
+ * @param firstRow
+ * the first row, where 1 is the first row.
+ * @return this query
+ */
+ public Query setFirstRow(Integer firstRow) {
+ if (firstRow != null && firstRow.intValue() < 1) {
+ throw new IllegalArgumentException("First row cannot be negative or zero");
+ }
+ _firstRow = firstRow;
+ return this;
+ }
+
+ /**
+ * Gets the first row (aka offset) of the query's result, or null if none is
+ * specified. The row number is 1-based, so setting a first row value of 1
+ * is equivalent to not setting it at all..
+ *
+ * @return the first row (aka offset) of the query's result, or null if no
+ * offset is specified.
+ */
+ public Integer getFirstRow() {
+ return _firstRow;
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ identifiers.add(_maxRows);
+ identifiers.add(_selectClause);
+ identifiers.add(_fromClause);
+ identifiers.add(_whereClause);
+ identifiers.add(_groupByClause);
+ identifiers.add(_havingClause);
+ identifiers.add(_orderByClause);
+ }
+
+ @Override
+ public Query clone() {
+ Query q = new Query();
+ q.setMaxRows(_maxRows);
+ q.setFirstRow(_firstRow);
+ q.getSelectClause().setDistinct(_selectClause.isDistinct());
+ for (FromItem item : _fromClause.getItems()) {
+ q.from(item.clone());
+ }
+ for (SelectItem item : _selectClause.getItems()) {
+ q.select(item.clone());
+ }
+ for (FilterItem item : _whereClause.getItems()) {
+ q.where(item.clone());
+ }
+ for (GroupByItem item : _groupByClause.getItems()) {
+ q.groupBy(item.clone());
+ }
+ for (FilterItem item : _havingClause.getItems()) {
+ q.having(item.clone());
+ }
+ for (OrderByItem item : _orderByClause.getItems()) {
+ q.orderBy(item.clone());
+ }
+ return q;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/QueryClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/QueryClause.java b/core/src/main/java/org/apache/metamodel/query/QueryClause.java
new file mode 100644
index 0000000..e3dddc8
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/QueryClause.java
@@ -0,0 +1,53 @@
+/**
+ * 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.query;
+
+import java.io.Serializable;
+import java.util.List;
+
+public interface QueryClause<E> extends Serializable {
+
+ public QueryClause<E> setItems(E... items);
+
+ public QueryClause<E> addItems(E... items);
+
+ public QueryClause<E> addItems(Iterable<E> items);
+
+ public QueryClause<E> addItem(int index, E item);
+
+ public QueryClause<E> addItem(E item);
+
+ public boolean isEmpty();
+
+ public int getItemCount();
+
+ public E getItem(int index);
+
+ public List<E> getItems();
+
+ public QueryClause<E> removeItem(int index);
+
+ public QueryClause<E> removeItem(E item);
+
+ public QueryClause<E> removeItems();
+
+ public String toSql(boolean includeSchemaInColumnPaths);
+
+ public String toSql();
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/QueryItem.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/QueryItem.java b/core/src/main/java/org/apache/metamodel/query/QueryItem.java
new file mode 100644
index 0000000..ab79959
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/QueryItem.java
@@ -0,0 +1,39 @@
+/**
+ * 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.query;
+
+import java.io.Serializable;
+
+/**
+ * Interface for items in a query. All QueryItems reside within a QueryClause.
+ *
+ * @see AbstractQueryClause
+ */
+public interface QueryItem extends Serializable {
+
+ public QueryItem setQuery(Query query);
+
+ public Query getQuery();
+
+ public String toSql();
+
+ public String toSql(boolean includeSchemaInColumnPaths);
+
+ public String toString();
+}
\ 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/query/QueryParameter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/QueryParameter.java b/core/src/main/java/org/apache/metamodel/query/QueryParameter.java
new file mode 100644
index 0000000..c8c0401
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/QueryParameter.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.query;
+
+import org.eobjects.metamodel.DataContext;
+
+/**
+ * Represents a query parameter, in SQL represented with a '?' symbol.
+ * Parameters are values in the query that will be defined at execution time,
+ * not parsing/preparation time.
+ *
+ * @see CompiledQuery
+ * @see DataContext#compileQuery(Query)
+ */
+public class QueryParameter {
+
+ @Override
+ public String toString() {
+ return "?";
+ }
+}
[24/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/query/SelectItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/SelectItemTest.java b/core/src/test/java/org/apache/metamodel/query/SelectItemTest.java
new file mode 100644
index 0000000..5896d9a
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/query/SelectItemTest.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.query;
+
+import org.eobjects.metamodel.MetaModelTestCase;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+public class SelectItemTest extends MetaModelTestCase {
+
+ private Schema _schema = getExampleSchema();
+
+ public void testSelectColumnInFromItem() throws Exception {
+ final Table projectTable = _schema.getTableByName(TABLE_PROJECT);
+ final Column column1 = projectTable.getColumns()[0];
+ final Column column2 = projectTable.getColumns()[1];
+
+ Query q = new Query().from(projectTable, "a").from(projectTable, "b");
+ q.select(column1, q.getFromClause().getItem(1));
+ q.select(column2, q.getFromClause().getItem(0));
+
+ assertEquals("SELECT b.project_id, a.name FROM MetaModelSchema.project a, MetaModelSchema.project b", q.toSql());
+ }
+
+ public void testToSql() throws Exception {
+ SelectItem selectItem = new SelectItem(_schema.getTableByName(TABLE_PROJECT).getColumns()[0]);
+ assertEquals("project.project_id", selectItem.toSql());
+ }
+
+ public void testSubQuerySelectItem() throws Exception {
+ Table projectTable = _schema.getTableByName(TABLE_PROJECT);
+ Table roleTable = _schema.getTableByName(TABLE_ROLE);
+
+ Column projectIdColumn = projectTable.getColumnByName(COLUMN_PROJECT_PROJECT_ID);
+
+ FromItem leftSide = new FromItem(projectTable);
+ leftSide.setAlias("a");
+ SelectItem[] leftOn = new SelectItem[] { new SelectItem(projectIdColumn) };
+
+ Query subQuery = new Query();
+ FromItem subQueryFrom = new FromItem(roleTable);
+ subQueryFrom.setAlias("c");
+ subQuery.from(subQueryFrom);
+ Column[] columns = roleTable.getColumns();
+ subQuery.select(columns);
+
+ SelectItem subQuerySelectItem = subQuery.getSelectClause().getSelectItem(columns[1]);
+ FromItem rightSide = new FromItem(subQuery);
+ rightSide.setAlias("b");
+ SelectItem[] rightOn = new SelectItem[] { subQuerySelectItem };
+ FromItem from = new FromItem(JoinType.LEFT, leftSide, rightSide, leftOn, rightOn);
+
+ assertEquals(
+ "MetaModelSchema.project a LEFT JOIN (SELECT c.contributor_id, c.project_id, c.name FROM MetaModelSchema.role c) b ON a.project_id = b.project_id",
+ from.toString());
+
+ Query q = new Query();
+ q.from(from);
+ try {
+ new SelectItem(subQuerySelectItem, from);
+ fail("Exception should have been thrown!");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Only sub-query based FromItems allowed.", e.getMessage());
+ }
+
+ q.select(new SelectItem(subQuerySelectItem, rightSide));
+ assertEquals(
+ "SELECT b.project_id FROM MetaModelSchema.project a LEFT JOIN (SELECT c.contributor_id, c.project_id, c.name FROM MetaModelSchema.role c) b ON a.project_id = b.project_id",
+ q.toString());
+ }
+
+ public void testGetSuperQueryAlias() throws Exception {
+ SelectItem item = new SelectItem(FunctionType.COUNT, "*", "").setAlias(null);
+ assertEquals("COUNT(*)", item.getSameQueryAlias());
+ assertEquals("COUNT(*)", item.getSuperQueryAlias());
+
+ item = new SelectItem(FunctionType.SUM, new MutableColumn("foo"));
+ assertEquals("SUM(foo)", item.getSameQueryAlias());
+ assertEquals("SUM(foo)", item.getSuperQueryAlias());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/query/builder/GroupedQueryBuilderImplTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/builder/GroupedQueryBuilderImplTest.java b/core/src/test/java/org/apache/metamodel/query/builder/GroupedQueryBuilderImplTest.java
new file mode 100644
index 0000000..4b3b399
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/query/builder/GroupedQueryBuilderImplTest.java
@@ -0,0 +1,108 @@
+/**
+ * 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.query.builder;
+
+import junit.framework.TestCase;
+
+import org.easymock.EasyMock;
+import org.eobjects.metamodel.AbstractDataContext;
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.schema.MutableTable;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+public class GroupedQueryBuilderImplTest extends TestCase {
+
+ public void testFindColumnWithAlias() throws Exception {
+ DataContext dataContext = EasyMock.createMock(DataContext.class);
+
+ MutableTable table1 = new MutableTable("foo");
+ table1.addColumn(new MutableColumn("col1").setTable(table1));
+ table1.addColumn(new MutableColumn("col2").setTable(table1));
+ table1.addColumn(new MutableColumn("col3").setTable(table1));
+
+ MutableTable table2 = new MutableTable("bar");
+ table2.addColumn(new MutableColumn("col1").setTable(table2));
+ table2.addColumn(new MutableColumn("col2").setTable(table2));
+ table2.addColumn(new MutableColumn("col3").setTable(table2));
+
+ Query query = new Query().from(table1, "f").from(table2, "b");
+ GroupedQueryBuilderImpl gqbi = new GroupedQueryBuilderImpl(dataContext,
+ query);
+
+ Column col = gqbi.findColumn("b.col2");
+ assertEquals("bar.col2", col.getQualifiedLabel());
+
+ col = gqbi.findColumn("f.col2");
+ assertEquals("foo.col2", col.getQualifiedLabel());
+
+ try {
+ col = gqbi.findColumn("f.col4");
+ fail("Exception expected");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Could not find column: f.col4", e.getMessage());
+ }
+ }
+
+ // test-case to recreate the problems reported at
+ // http://eobjects.org/trac/discussion/7/134
+ public void testLeftJoinQueries() throws Exception {
+ DataContext dc = new AbstractDataContext() {
+
+ @Override
+ public DataSet executeQuery(Query query) throws MetaModelException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected String[] getSchemaNamesInternal() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected String getDefaultSchemaName() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected Schema getSchemaByNameInternal(String name) {
+ throw new UnsupportedOperationException();
+ }
+ };
+ Table tableAB = new MutableTable("tableAB");
+ Table tableC = new MutableTable("tableC");
+
+ Column colA = new MutableColumn("colA", null, tableAB, 0, true);
+ Column colB = new MutableColumn("colB", null, tableAB, 1, true);
+ Column colC = new MutableColumn("colC", null, tableC, 0, true);
+
+ Query q = dc.query().from(tableAB).leftJoin(tableC).on(colB, colC)
+ .select(colA).as("a").select(colB).as("b").select(colC).as("c")
+ .toQuery();
+
+ assertEquals(
+ "SELECT tableAB.colA AS a, tableAB.colB AS b, tableC.colC AS c FROM tableAB LEFT JOIN tableC ON tableAB.colB = tableC.colC",
+ q.toSql());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/query/builder/SyntaxExamplesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/builder/SyntaxExamplesTest.java b/core/src/test/java/org/apache/metamodel/query/builder/SyntaxExamplesTest.java
new file mode 100644
index 0000000..0f04584
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/query/builder/SyntaxExamplesTest.java
@@ -0,0 +1,80 @@
+/**
+ * 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.query.builder;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.MockDataContext;
+import org.eobjects.metamodel.query.FunctionType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.MutableSchema;
+import org.eobjects.metamodel.schema.MutableTable;
+import org.eobjects.metamodel.schema.Table;
+
+public class SyntaxExamplesTest extends TestCase {
+
+ private DataContext dc;
+ private Table table1;
+ private Table table2;
+ private Column col1;
+ private Column col2;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ dc = new MockDataContext("sch", "tab1", "foo");
+ MutableSchema schema = (MutableSchema) dc.getDefaultSchema();
+ table1 = schema.getTables()[0];
+ schema.addTable(new MutableTable("tab2").setSchema(schema));
+ table2 = schema.getTableByName("tab2");
+ col1 = table1.getColumns()[0];
+ col2 = table1.getColumns()[1];
+ }
+
+ public void testSchema() throws Exception {
+ assertEquals("tab1", table1.getName());
+ assertEquals("sch.tab1", table1.getQualifiedLabel());
+ }
+
+ public void testFromAlias() throws Exception {
+ dc.query().from(table1).as("t");
+ }
+
+ public void testFromJoin() throws Exception {
+ dc.query().from(table1).innerJoin(table2).on(col1, col2).select(col1);
+ }
+
+ public void testWhereOr() throws Exception {
+ dc.query().from(table1).as("t").select(col2).where(col1).isNotNull().or(col1).isNull().orderBy(col1).asc();
+ }
+
+ public void testGroupBy() throws Exception {
+ dc.query().from(table1).selectCount().select(col1).groupBy(col1).having(FunctionType.SUM, col1).greaterThan(3)
+ .orderBy(col1).asc();
+ }
+
+ public void testMultipleTables() throws Exception {
+ Query q = dc.query().from(table1).as("t1").and(table2).as("t2").select(col1).where(col1).greaterThan(col2)
+ .orderBy(col2).desc().toQuery();
+ assertEquals("SELECT t1.foo FROM sch.tab1 t1, sch.tab2 t2 " + "WHERE t1.foo > t1.bar ORDER BY t1.bar DESC",
+ q.toSql());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/query/builder/WhereBuilderImplTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/builder/WhereBuilderImplTest.java b/core/src/test/java/org/apache/metamodel/query/builder/WhereBuilderImplTest.java
new file mode 100644
index 0000000..4d45f61
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/query/builder/WhereBuilderImplTest.java
@@ -0,0 +1,81 @@
+/**
+ * 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.query.builder;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.MutableColumn;
+import junit.framework.TestCase;
+
+public class WhereBuilderImplTest extends TestCase {
+
+ private MutableColumn col1 = new MutableColumn("col1", ColumnType.BOOLEAN);
+ private MutableColumn col2 = new MutableColumn("col2");
+ private WhereBuilderImpl whereBuilder;
+ private Query query;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ query = new Query();
+ GroupedQueryBuilder queryBuilder = new GroupedQueryBuilderImpl(null,
+ query);
+ whereBuilder = new WhereBuilderImpl(col1, query, queryBuilder);
+ }
+
+ public void testOr() throws Exception {
+ whereBuilder.eq(true).or(col2).like("%testcase%");
+
+ assertEquals(" WHERE (col1 = TRUE OR col2 LIKE '%testcase%')",
+ query.toSql());
+ }
+
+ public void testAnd() throws Exception {
+ whereBuilder.differentFrom(true).and(col2).eq(1).or(col2).eq(2)
+ .or(col2).eq(3).and(new MutableColumn("col3")).eq(4);
+
+ assertEquals(
+ " WHERE col1 <> TRUE AND (col2 = 1 OR col2 = 2 OR col2 = 3) AND col3 = 4",
+ query.toSql());
+ }
+
+ public void testInStringArray() throws Exception {
+ whereBuilder.eq(true).or(col2).in("foo", "bar");
+
+ assertEquals(" WHERE (col1 = TRUE OR col2 IN ('foo' , 'bar'))",
+ query.toSql());
+ }
+
+ public void testInNumberArray() throws Exception {
+ whereBuilder.eq(true).or(col2).in(3, 1);
+
+ assertEquals(" WHERE (col1 = TRUE OR col2 IN (3 , 1))", query.toSql());
+ }
+
+ public void testInCollection() throws Exception {
+ Collection<?> col = Arrays.asList("foo", "bar");
+ whereBuilder.eq(true).or(col2).in(col);
+
+ assertEquals(" WHERE (col1 = TRUE OR col2 IN ('foo' , 'bar'))",
+ query.toSql());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/query/parser/QueryParserTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/parser/QueryParserTest.java b/core/src/test/java/org/apache/metamodel/query/parser/QueryParserTest.java
new file mode 100644
index 0000000..786b79e
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/query/parser/QueryParserTest.java
@@ -0,0 +1,320 @@
+/**
+ * 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.query.parser;
+
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.MetaModelHelper;
+import org.eobjects.metamodel.MockDataContext;
+import org.eobjects.metamodel.query.FilterClause;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.OperatorType;
+import org.eobjects.metamodel.query.OrderByItem;
+import org.eobjects.metamodel.query.OrderByItem.Direction;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.MutableColumn;
+
+public class QueryParserTest extends TestCase {
+
+ private MockDataContext dc;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ dc = new MockDataContext("sch", "tbl", "foo");
+
+ // set 'baz' column to an integer column (to influence query generation)
+ MutableColumn col = (MutableColumn) dc.getColumnByQualifiedLabel("tbl.baz");
+ col.setType(ColumnType.INTEGER);
+ };
+
+ public void testQueryInLowerCase() throws Exception {
+ Query q = MetaModelHelper.parseQuery(dc,
+ "select a.foo as f from sch.tbl a inner join sch.tbl b on a.foo=b.foo order by a.foo asc");
+ assertEquals("SELECT a.foo AS f FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo ORDER BY a.foo ASC",
+ q.toSql());
+ }
+
+ public void testSelectEverythingFromTable() throws Exception {
+ Query q = MetaModelHelper.parseQuery(dc, "SELECT * FROM sch.tbl");
+ assertEquals("SELECT tbl.foo, tbl.bar, tbl.baz FROM sch.tbl", q.toSql());
+ }
+
+ public void testSelectEverythingFromJoin() throws Exception {
+ Query q = MetaModelHelper.parseQuery(dc, "SELECT * FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo");
+ assertEquals(
+ "SELECT a.foo, a.bar, a.baz, b.foo, b.bar, b.baz FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo",
+ q.toSql());
+
+ q = MetaModelHelper.parseQuery(dc, "SELECT a.foo, b.* FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo");
+ assertEquals("SELECT a.foo, b.foo, b.bar, b.baz FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo",
+ q.toSql());
+ }
+
+ public void testSelectColumnWithDotInName() throws Exception {
+ MutableColumn col = (MutableColumn) dc.getTableByQualifiedLabel("tbl").getColumn(0);
+ col.setName("fo.o");
+
+ Query q = MetaModelHelper.parseQuery(dc, "SELECT fo.o AS f FROM sch.tbl");
+ assertEquals("SELECT tbl.fo.o AS f FROM sch.tbl", q.toSql());
+ }
+
+ public void testSelectAlias() throws Exception {
+ Query q = MetaModelHelper.parseQuery(dc, "SELECT foo AS f FROM sch.tbl");
+ assertEquals("SELECT tbl.foo AS f FROM sch.tbl", q.toSql());
+
+ q = MetaModelHelper.parseQuery(dc, "SELECT a.foo AS foobarbaz FROM sch.tbl a WHERE foobarbaz = '123'");
+ assertEquals("SELECT a.foo AS foobarbaz FROM sch.tbl a WHERE foobarbaz = '123'", q.toSql());
+ }
+
+ public void testSelectDistinct() throws Exception {
+ Query q = MetaModelHelper.parseQuery(dc, "SELECT DISTINCT foo, bar AS f FROM sch.tbl");
+ assertEquals("SELECT DISTINCT tbl.foo, tbl.bar AS f FROM sch.tbl", q.toSql());
+ }
+
+ public void testSimpleSelectFrom() throws Exception {
+ Query q = MetaModelHelper.parseQuery(dc, "SELECT foo\nFROM sch.tbl");
+ assertEquals("SELECT tbl.foo FROM sch.tbl", q.toSql());
+
+ assertEquals(1, q.getFromClause().getItemCount());
+ FromItem fromItem = q.getFromClause().getItem(0);
+ assertNull("FROM item was an expression based item, which indicates it was not parsed",
+ fromItem.getExpression());
+ assertNotNull(fromItem.getTable());
+ assertEquals("tbl", fromItem.getTable().getName());
+
+ assertEquals(1, q.getSelectClause().getItemCount());
+ SelectItem selectItem = q.getSelectClause().getItem(0);
+ assertNull("SELECT item was an expression based item, which indicates it was not parsed",
+ selectItem.getExpression());
+ assertNotNull(selectItem.getColumn());
+ assertEquals("foo", selectItem.getColumn().getName());
+
+ assertNull(q.getFirstRow());
+ assertNull(q.getMaxRows());
+ }
+
+ public void testCarthesianProduct() throws Exception {
+ Query q = MetaModelHelper.parseQuery(dc,
+ " SELECT a.foo,b.bar FROM sch.tbl a, sch.tbl b \t WHERE a.foo = b.foo");
+ assertEquals("SELECT a.foo, b.bar FROM sch.tbl a, sch.tbl b WHERE a.foo = b.foo", q.toSql());
+
+ List<FromItem> fromItems = q.getFromClause().getItems();
+ assertNotNull(fromItems.get(0).getTable());
+ assertNotNull(fromItems.get(1).getTable());
+
+ List<FilterItem> whereItems = q.getWhereClause().getItems();
+ assertNotNull(whereItems.get(0).getSelectItem().getColumn());
+ assertNotNull(whereItems.get(0).getSelectItem().getFromItem().getTable());
+ }
+
+ public void testJoin() throws Exception {
+ Query q = MetaModelHelper.parseQuery(dc,
+ "SELECT a.foo,b.bar FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo");
+ assertEquals("SELECT a.foo, b.bar FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo", q.toSql());
+
+ q = MetaModelHelper.parseQuery(dc,
+ "SELECT COUNT(*) FROM sch.tbl a LEFT JOIN sch.tbl b ON a.foo = b.foo AND a.bar = b.baz");
+ assertEquals("SELECT COUNT(*) FROM sch.tbl a LEFT JOIN sch.tbl b ON a.foo = b.foo AND a.bar = b.baz", q.toSql());
+ }
+
+ public void testSimpleSelectFromWhere() throws Exception {
+ Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE bar = 'baz' AND baz > 5");
+ assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.bar = 'baz' AND tbl.baz > 5", q.toSql());
+
+ FilterClause whereClause = q.getWhereClause();
+ assertEquals(2, whereClause.getItemCount());
+ assertNull("WHERE item was an expression based item, which indicates it was not parsed", whereClause.getItem(0)
+ .getExpression());
+ assertEquals(2, whereClause.getItemCount());
+ assertNull("WHERE item was an expression based item, which indicates it was not parsed", whereClause.getItem(1)
+ .getExpression());
+
+ assertEquals("baz", whereClause.getItem(0).getOperand());
+ assertEquals(Integer.class, whereClause.getItem(1).getOperand().getClass());
+ }
+
+ public void testWhereStringEscaped() throws Exception {
+ Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE bar = 'ba\\'z'");
+ assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.bar = 'ba'z'", q.toSql());
+ }
+
+ public void testWhereOperandIsBoolean() throws Exception {
+ // set 'baz' column to an integer column (to influence query generation)
+ MutableColumn col = (MutableColumn) dc.getColumnByQualifiedLabel("tbl.baz");
+ col.setType(ColumnType.BOOLEAN);
+
+ Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE baz = TRUE");
+ assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.baz = TRUE", q.toSql());
+ }
+
+ public void testWhereOperandIsDate() throws Exception {
+ // set 'baz' column to an integer column (to influence query generation)
+ MutableColumn col = (MutableColumn) dc.getColumnByQualifiedLabel("tbl.baz");
+ col.setType(ColumnType.TIME);
+
+ Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE baz = 10:24");
+ assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.baz = TIME '10:24:00'", q.toSql());
+ }
+
+ public void testCoumpoundWhereClause() throws Exception {
+ Query q = MetaModelHelper
+ .parseQuery(dc, "SELECT foo FROM sch.tbl WHERE (bar = 'baz' OR (baz > 5 AND baz < 7))");
+ assertEquals("SELECT tbl.foo FROM sch.tbl WHERE (tbl.bar = 'baz' OR (tbl.baz > 5 AND tbl.baz < 7))", q.toSql());
+
+ FilterClause wc = q.getWhereClause();
+ assertEquals(1, wc.getItemCount());
+ FilterItem item = wc.getItem(0);
+ assertTrue(item.isCompoundFilter());
+
+ FilterItem[] childItems = item.getChildItems();
+ assertEquals(2, childItems.length);
+
+ FilterItem bazConditions = childItems[1];
+ assertTrue(bazConditions.isCompoundFilter());
+ }
+
+ public void testWhereSomethingIsNull() throws Exception {
+ Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE bar IS NULL");
+ assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.bar IS NULL", q.toSql());
+
+ assertEquals(1, q.getWhereClause().getItemCount());
+ assertNull("WHERE item was an expression based item, which indicates it was not parsed", q.getWhereClause()
+ .getItem(0).getExpression());
+ assertNull(q.getWhereClause().getItem(0).getOperand());
+ assertEquals(OperatorType.EQUALS_TO, q.getWhereClause().getItem(0).getOperator());
+ }
+
+ public void testWhereSomethingIsNotNull() throws Exception {
+ Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE bar IS NOT NULL");
+ assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.bar IS NOT NULL", q.toSql());
+
+ assertEquals(1, q.getWhereClause().getItemCount());
+ assertNull("WHERE item was an expression based item, which indicates it was not parsed", q.getWhereClause()
+ .getItem(0).getExpression());
+ assertNull(q.getWhereClause().getItem(0).getOperand());
+ assertEquals(OperatorType.DIFFERENT_FROM, q.getWhereClause().getItem(0).getOperator());
+ }
+
+ public void testLimitAndOffset() throws Exception {
+ Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl LIMIT 1234 OFFSET 5");
+ assertEquals("SELECT tbl.foo FROM sch.tbl", q.toSql());
+ assertEquals(1234, q.getMaxRows().intValue());
+ assertEquals(6, q.getFirstRow().intValue());
+ }
+
+ public void testWhereIn() throws Exception {
+ Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE foo IN ('a','b',5)");
+ assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.foo IN ('a' , 'b' , '5')", q.toSql());
+
+ FilterItem whereItem = q.getWhereClause().getItem(0);
+ assertEquals(OperatorType.IN, whereItem.getOperator());
+ Object operand = whereItem.getOperand();
+ assertTrue(operand instanceof List);
+ assertEquals("a", ((List<?>) operand).get(0));
+ assertEquals("b", ((List<?>) operand).get(1));
+ assertEquals(5, ((List<?>) operand).get(2));
+ }
+
+ public void testSimpleSubQuery() throws Exception {
+ Query q = MetaModelHelper.parseQuery(dc, "SELECT f.foo AS fo FROM (SELECT * FROM sch.tbl) f");
+ assertEquals("SELECT f.foo AS fo FROM (SELECT tbl.foo, tbl.bar, tbl.baz FROM sch.tbl) f", q.toSql());
+ }
+
+ public void testSelectEverythingFromSubQuery() throws Exception {
+ Query q = MetaModelHelper.parseQuery(dc, "SELECT * FROM (SELECT foo, bar FROM sch.tbl) f");
+ assertEquals("SELECT f.foo, f.bar FROM (SELECT tbl.foo, tbl.bar FROM sch.tbl) f", q.toSql());
+ }
+
+ public void testGetIndicesVanillaScenario() throws Exception {
+ QueryParser qp = new QueryParser(dc, "SELECT ... FROM ... BAR BAZ");
+ assertEquals("[0, 7]", Arrays.toString(qp.indexesOf("SELECT ", null)));
+ assertEquals("[10, 16]", Arrays.toString(qp.indexesOf(" FROM ", null)));
+ }
+
+ public void testGetIndicesIgnoreWhiteSpaceAndCaseDifferences() throws Exception {
+ QueryParser qp = new QueryParser(dc, " \t\r\n select ... from ... BAR BAZ");
+ assertEquals("[0, 7]", Arrays.toString(qp.indexesOf("SELECT ", null)));
+ assertEquals("[10, 16]", Arrays.toString(qp.indexesOf(" FROM ", null)));
+ }
+
+ public void testInvalidQueries() throws Exception {
+ try {
+ MetaModelHelper.parseQuery(dc, "foobar");
+ fail("Exception expected");
+ } catch (MetaModelException e) {
+ assertEquals("SELECT not found in query: foobar", e.getMessage());
+ }
+
+ try {
+ MetaModelHelper.parseQuery(dc, "SELECT foobar");
+ fail("Exception expected");
+ } catch (MetaModelException e) {
+ assertEquals("FROM not found in query: SELECT foobar", e.getMessage());
+ }
+ }
+
+ public void testFullQuery() throws Exception {
+ Query q = MetaModelHelper.parseQuery(dc,
+ "SELECT foo, COUNT(* ), MAX( baz ) FROM sch.tbl WHERE bar = 'baz' AND foo = bar AND baz > 5 "
+ + "GROUP BY foo HAVING COUNT(*) > 2 ORDER BY foo LIMIT 20 OFFSET 10");
+ assertEquals(
+ "SELECT tbl.foo, COUNT(*), MAX(tbl.baz) FROM sch.tbl WHERE tbl.bar = 'baz' AND tbl.foo = tbl.bar AND tbl.baz > 5 "
+ + "GROUP BY tbl.foo HAVING COUNT(*) > 2 ORDER BY tbl.foo ASC", q.toSql());
+ assertEquals(20, q.getMaxRows().intValue());
+ assertEquals(11, q.getFirstRow().intValue());
+
+ // SELECT ...
+ // tbl.foo
+ assertNotNull("SelectItem 1 should be a column", q.getSelectClause().getItem(0).getColumn());
+
+ // COUNT(*)
+ assertNotNull("SelectItem 2 should be a Function", q.getSelectClause().getItem(1).getFunction());
+ assertNotNull("SelectItem 2 should be a Function of '*'", q.getSelectClause().getItem(1).getExpression());
+
+ // MAX(tbl.baz)
+ assertNotNull("SelectItem 3 should be a Function", q.getSelectClause().getItem(2).getFunction());
+ assertNotNull("SelectItem 4 should be a Function of a column", q.getSelectClause().getItem(2).getColumn());
+
+ // FROM tbl.foo
+ assertNotNull(q.getFromClause().getItem(0).getTable());
+
+ // GROUP BY tbl.foo
+ assertNotNull(q.getGroupByClause().getItem(0).getSelectItem().getColumn());
+
+ // HAVING COUNT(*) > 2
+ FilterItem havingItem = q.getHavingClause().getItem(0);
+ assertNull(havingItem.getExpression());
+ assertNotNull(havingItem.getSelectItem().getFunction());
+ assertEquals("*", havingItem.getSelectItem().getExpression());
+
+ // ORDER BY tbl.foo ASC
+ OrderByItem orderByItem = q.getOrderByClause().getItem(0);
+ assertNull(orderByItem.getSelectItem().getExpression());
+ assertNotNull(orderByItem.getSelectItem().getColumn());
+ assertEquals(Direction.ASC, orderByItem.getDirection());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/query/parser/QueryPartParserTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/parser/QueryPartParserTest.java b/core/src/test/java/org/apache/metamodel/query/parser/QueryPartParserTest.java
new file mode 100644
index 0000000..0066f9c
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/query/parser/QueryPartParserTest.java
@@ -0,0 +1,110 @@
+/**
+ * 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.query.parser;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public class QueryPartParserTest extends TestCase {
+
+ public void testParseNone() throws Exception {
+ QueryPartCollectionProcessor itemParser = new QueryPartCollectionProcessor();
+
+ new QueryPartParser(itemParser, " ", ",").parse();
+
+ List<String> items = itemParser.getTokens();
+ assertEquals(0, items.size());
+ assertEquals("[]", items.toString());
+ }
+
+ public void testParseSingle() throws Exception {
+ QueryPartCollectionProcessor itemParser = new QueryPartCollectionProcessor();
+
+ new QueryPartParser(itemParser, "foo ", ",").parse();
+
+ List<String> items = itemParser.getTokens();
+ assertEquals(1, items.size());
+ assertEquals("[foo]", items.toString());
+ assertEquals("[null]", itemParser.getDelims().toString());
+ }
+
+ public void testParseMultiple() throws Exception {
+ QueryPartCollectionProcessor itemParser = new QueryPartCollectionProcessor();
+
+ new QueryPartParser(itemParser, "foo , bar", ",").parse();
+
+ List<String> items = itemParser.getTokens();
+ assertEquals(2, items.size());
+ assertEquals("[foo, bar]", items.toString());
+ }
+
+ public void testParseWithParenthesis() throws Exception {
+ QueryPartCollectionProcessor itemParser = new QueryPartCollectionProcessor();
+
+ new QueryPartParser(itemParser, "foo , bar (a,b,c),(doh)", ",").parse();
+
+ List<String> items = itemParser.getTokens();
+ assertEquals("[foo, bar (a,b,c), (doh)]", items.toString());
+ assertEquals(3, items.size());
+ }
+
+ public void testMultipleDelims() throws Exception {
+ QueryPartCollectionProcessor itemParser = new QueryPartCollectionProcessor();
+
+ new QueryPartParser(itemParser, "foo AND bar OR baz AND (foo( AND bar) OR baz)", " AND ", " OR ").parse();
+
+ List<String> items = itemParser.getTokens();
+ assertEquals(4, items.size());
+ assertEquals("[foo, bar, baz, (foo( AND bar) OR baz)]", items.toString());
+ assertEquals("[null, AND , OR , AND ]", itemParser.getDelims().toString());
+ }
+
+ public void testEmptyClause() throws Exception {
+ QueryPartCollectionProcessor itemParser = new QueryPartCollectionProcessor();
+
+ new QueryPartParser(itemParser, "", ",").parse();
+ assertEquals(0, itemParser.getTokens().size());
+ }
+
+ public void testEmptyParenthesis() throws Exception {
+ QueryPartCollectionProcessor itemParser = new QueryPartCollectionProcessor();
+
+ new QueryPartParser(itemParser, "()", ",").parse();
+ assertEquals(0, itemParser.getTokens().size());
+ }
+
+ public void testMultiParenthesisLevels() throws Exception {
+ QueryPartCollectionProcessor itemParser = new QueryPartCollectionProcessor();
+
+ new QueryPartParser(itemParser, "(((Hello world)))", ",").parse();
+ assertEquals(1, itemParser.getTokens().size());
+ assertEquals("Hello world", itemParser.getTokens().get(0));
+ }
+
+ public void testOuterParenthesis() throws Exception {
+ QueryPartCollectionProcessor itemParser = new QueryPartCollectionProcessor();
+
+ new QueryPartParser(itemParser, "(foo,bar)", ",").parse();
+
+ List<String> items = itemParser.getTokens();
+ assertEquals(2, items.size());
+ assertEquals("[foo, bar]", items.toString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/schema/ColumnTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/ColumnTypeTest.java b/core/src/test/java/org/apache/metamodel/schema/ColumnTypeTest.java
new file mode 100644
index 0000000..54b0689
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/schema/ColumnTypeTest.java
@@ -0,0 +1,92 @@
+/**
+ * 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.schema;
+
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import junit.framework.TestCase;
+
+public class ColumnTypeTest extends TestCase {
+
+ public void testConvertColumnTypeFromJdbcTypes() throws Exception {
+ ColumnType type = ColumnType.convertColumnType(Types.VARCHAR);
+ assertEquals(ColumnType.VARCHAR, type);
+
+ type = ColumnType.convertColumnType(Types.DATE);
+ assertEquals(ColumnType.DATE, type);
+
+ type = ColumnType.convertColumnType(Types.TIME);
+ assertEquals(ColumnType.TIME, type);
+
+ type = ColumnType.convertColumnType(Types.TIMESTAMP);
+ assertEquals(ColumnType.TIMESTAMP, type);
+
+ type = ColumnType.convertColumnType(42397443);
+ assertEquals(ColumnType.OTHER, type);
+
+ type = ColumnType.convertColumnType(-42397443);
+ assertEquals(ColumnType.OTHER, type);
+ }
+
+ public void testConvertColumnTypeFromJavaClass() throws Exception {
+ ColumnType type = ColumnType.convertColumnType(String.class);
+ assertEquals(ColumnType.VARCHAR, type);
+
+ type = ColumnType.convertColumnType(Time.class);
+ assertEquals(ColumnType.TIME, type);
+
+ type = ColumnType.convertColumnType(Timestamp.class);
+ assertEquals(ColumnType.TIMESTAMP, type);
+
+ type = ColumnType.convertColumnType(java.sql.Date.class);
+ assertEquals(ColumnType.DATE, type);
+
+ type = ColumnType.convertColumnType(Date.class);
+ assertEquals(ColumnType.TIMESTAMP, type);
+
+ type = ColumnType.convertColumnType(Integer.class);
+ assertEquals(ColumnType.INTEGER, type);
+
+ type = ColumnType.convertColumnType(Object.class);
+ assertEquals(ColumnType.OTHER, type);
+
+ type = ColumnType.convertColumnType(Map.class);
+ assertEquals(ColumnType.MAP, type);
+ type = ColumnType.convertColumnType(HashMap.class);
+ assertEquals(ColumnType.MAP, type);
+ type = ColumnType.convertColumnType(TreeMap.class);
+ assertEquals(ColumnType.MAP, type);
+
+ type = ColumnType.convertColumnType(List.class);
+ assertEquals(ColumnType.LIST, type);
+ type = ColumnType.convertColumnType(ArrayList.class);
+ assertEquals(ColumnType.LIST, type);
+ type = ColumnType.convertColumnType(LinkedList.class);
+ assertEquals(ColumnType.LIST, type);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/schema/DataTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/DataTypeTest.java b/core/src/test/java/org/apache/metamodel/schema/DataTypeTest.java
new file mode 100644
index 0000000..087062d
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/schema/DataTypeTest.java
@@ -0,0 +1,28 @@
+/**
+ * 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.schema;
+
+import junit.framework.TestCase;
+
+public class DataTypeTest extends TestCase {
+
+ public void testIsLiteral() throws Exception {
+ assertTrue(ColumnType.NCHAR.isLiteral());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/schema/ImmutableSchemaTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/ImmutableSchemaTest.java b/core/src/test/java/org/apache/metamodel/schema/ImmutableSchemaTest.java
new file mode 100644
index 0000000..476af09
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/schema/ImmutableSchemaTest.java
@@ -0,0 +1,35 @@
+/**
+ * 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.schema;
+
+import org.eobjects.metamodel.MetaModelTestCase;
+
+public class ImmutableSchemaTest extends MetaModelTestCase {
+
+ public void testConstructor() throws Exception {
+ Schema mutableSchema = getExampleSchema();
+ assertTrue(mutableSchema instanceof MutableSchema);
+
+ ImmutableSchema immutableSchema = new ImmutableSchema(mutableSchema);
+
+ assertEquals(mutableSchema.getRelationshipCount(), immutableSchema.getRelationshipCount());
+
+ assertEquals(immutableSchema, mutableSchema);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/schema/Java5Types.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/Java5Types.java b/core/src/test/java/org/apache/metamodel/schema/Java5Types.java
new file mode 100644
index 0000000..8f44fa9
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/schema/Java5Types.java
@@ -0,0 +1,246 @@
+/**
+ * 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.schema;
+
+/**
+ * This is a copy of the content of Java 5.0's java.sql.Types
+ */
+class Java5Types {
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>BIT</code>.
+ */
+ public final static int BIT = -7;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>TINYINT</code>.
+ */
+ public final static int TINYINT = -6;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>SMALLINT</code>.
+ */
+ public final static int SMALLINT = 5;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>INTEGER</code>.
+ */
+ public final static int INTEGER = 4;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>BIGINT</code>.
+ */
+ public final static int BIGINT = -5;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>FLOAT</code>.
+ */
+ public final static int FLOAT = 6;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>REAL</code>.
+ */
+ public final static int REAL = 7;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>DOUBLE</code>.
+ */
+ public final static int DOUBLE = 8;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>NUMERIC</code>.
+ */
+ public final static int NUMERIC = 2;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>DECIMAL</code>.
+ */
+ public final static int DECIMAL = 3;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>CHAR</code>.
+ */
+ public final static int CHAR = 1;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>VARCHAR</code>.
+ */
+ public final static int VARCHAR = 12;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>LONGVARCHAR</code>.
+ */
+ public final static int LONGVARCHAR = -1;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>DATE</code>.
+ */
+ public final static int DATE = 91;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>TIME</code>.
+ */
+ public final static int TIME = 92;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>TIMESTAMP</code>.
+ */
+ public final static int TIMESTAMP = 93;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>BINARY</code>.
+ */
+ public final static int BINARY = -2;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>VARBINARY</code>.
+ */
+ public final static int VARBINARY = -3;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type
+ * <code>LONGVARBINARY</code>.
+ */
+ public final static int LONGVARBINARY = -4;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>NULL</code>.
+ */
+ public final static int NULL = 0;
+
+ /**
+ * The constant in the Java programming language that indicates that the SQL
+ * type is database-specific and gets mapped to a Java object that can be
+ * accessed via the methods <code>getObject</code> and
+ * <code>setObject</code>.
+ */
+ public final static int OTHER = 1111;
+
+ /**
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>JAVA_OBJECT</code>.
+ *
+ * @since 1.2
+ */
+ public final static int JAVA_OBJECT = 2000;
+
+ /**
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>DISTINCT</code>.
+ *
+ * @since 1.2
+ */
+ public final static int DISTINCT = 2001;
+
+ /**
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>STRUCT</code>.
+ *
+ * @since 1.2
+ */
+ public final static int STRUCT = 2002;
+
+ /**
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>ARRAY</code>.
+ *
+ * @since 1.2
+ */
+ public final static int ARRAY = 2003;
+
+ /**
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>BLOB</code>.
+ *
+ * @since 1.2
+ */
+ public final static int BLOB = 2004;
+
+ /**
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>CLOB</code>.
+ *
+ * @since 1.2
+ */
+ public final static int CLOB = 2005;
+
+ /**
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>REF</code>.
+ *
+ * @since 1.2
+ */
+ public final static int REF = 2006;
+
+ /**
+ * The constant in the Java programming language, somtimes referred to as a
+ * type code, that identifies the generic SQL type <code>DATALINK</code>.
+ *
+ * @since 1.4
+ */
+ public final static int DATALINK = 70;
+
+ /**
+ * The constant in the Java programming language, somtimes referred to as a
+ * type code, that identifies the generic SQL type <code>BOOLEAN</code>.
+ *
+ * @since 1.4
+ */
+ public final static int BOOLEAN = 16;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/schema/Java6Types.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/Java6Types.java b/core/src/test/java/org/apache/metamodel/schema/Java6Types.java
new file mode 100644
index 0000000..d48600a
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/schema/Java6Types.java
@@ -0,0 +1,297 @@
+/**
+ * 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.schema;
+
+/**
+ * This is a copy of the content of Java 6.0's java.sql.Types
+ */
+class Java6Types {
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>BIT</code>.
+ */
+ public final static int BIT = -7;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>TINYINT</code>.
+ */
+ public final static int TINYINT = -6;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>SMALLINT</code>.
+ */
+ public final static int SMALLINT = 5;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>INTEGER</code>.
+ */
+ public final static int INTEGER = 4;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>BIGINT</code>.
+ */
+ public final static int BIGINT = -5;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>FLOAT</code>.
+ */
+ public final static int FLOAT = 6;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>REAL</code>.
+ */
+ public final static int REAL = 7;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>DOUBLE</code>.
+ */
+ public final static int DOUBLE = 8;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>NUMERIC</code>.
+ */
+ public final static int NUMERIC = 2;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>DECIMAL</code>.
+ */
+ public final static int DECIMAL = 3;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>CHAR</code>.
+ */
+ public final static int CHAR = 1;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>VARCHAR</code>.
+ */
+ public final static int VARCHAR = 12;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>LONGVARCHAR</code>.
+ */
+ public final static int LONGVARCHAR = -1;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>DATE</code>.
+ */
+ public final static int DATE = 91;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>TIME</code>.
+ */
+ public final static int TIME = 92;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>TIMESTAMP</code>.
+ */
+ public final static int TIMESTAMP = 93;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>BINARY</code>.
+ */
+ public final static int BINARY = -2;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>VARBINARY</code>.
+ */
+ public final static int VARBINARY = -3;
+
+ /**
+ * <P>
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type
+ * <code>LONGVARBINARY</code>.
+ */
+ public final static int LONGVARBINARY = -4;
+
+ /**
+ * <P>
+ * The constant in the Java programming language that identifies the generic
+ * SQL value <code>NULL</code>.
+ */
+ public final static int NULL = 0;
+
+ /**
+ * The constant in the Java programming language that indicates that the SQL
+ * type is database-specific and gets mapped to a Java object that can be
+ * accessed via the methods <code>getObject</code> and
+ * <code>setObject</code>.
+ */
+ public final static int OTHER = 1111;
+
+ /**
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>JAVA_OBJECT</code>.
+ *
+ * @since 1.2
+ */
+ public final static int JAVA_OBJECT = 2000;
+
+ /**
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>DISTINCT</code>.
+ *
+ * @since 1.2
+ */
+ public final static int DISTINCT = 2001;
+
+ /**
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>STRUCT</code>.
+ *
+ * @since 1.2
+ */
+ public final static int STRUCT = 2002;
+
+ /**
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>ARRAY</code>.
+ *
+ * @since 1.2
+ */
+ public final static int ARRAY = 2003;
+
+ /**
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>BLOB</code>.
+ *
+ * @since 1.2
+ */
+ public final static int BLOB = 2004;
+
+ /**
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>CLOB</code>.
+ *
+ * @since 1.2
+ */
+ public final static int CLOB = 2005;
+
+ /**
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>REF</code>.
+ *
+ * @since 1.2
+ */
+ public final static int REF = 2006;
+
+ /**
+ * The constant in the Java programming language, somtimes referred to as a
+ * type code, that identifies the generic SQL type <code>DATALINK</code>.
+ *
+ * @since 1.4
+ */
+ public final static int DATALINK = 70;
+
+ /**
+ * The constant in the Java programming language, somtimes referred to as a
+ * type code, that identifies the generic SQL type <code>BOOLEAN</code>.
+ *
+ * @since 1.4
+ */
+ public final static int BOOLEAN = 16;
+
+ // ------------------------- JDBC 4.0 -----------------------------------
+
+ /**
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>ROWID</code>
+ *
+ * @since 1.6
+ *
+ */
+ public final static int ROWID = -8;
+
+ /**
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>NCHAR</code>
+ *
+ * @since 1.6
+ */
+ public static final int NCHAR = -15;
+
+ /**
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>NVARCHAR</code>.
+ *
+ * @since 1.6
+ */
+ public static final int NVARCHAR = -9;
+
+ /**
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>LONGNVARCHAR</code>.
+ *
+ * @since 1.6
+ */
+ public static final int LONGNVARCHAR = -16;
+
+ /**
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>NCLOB</code>.
+ *
+ * @since 1.6
+ */
+ public static final int NCLOB = 2011;
+
+ /**
+ * The constant in the Java programming language, sometimes referred to as a
+ * type code, that identifies the generic SQL type <code>XML</code>.
+ *
+ * @since 1.6
+ */
+ public static final int SQLXML = 2009;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/schema/JavaTypesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/JavaTypesTest.java b/core/src/test/java/org/apache/metamodel/schema/JavaTypesTest.java
new file mode 100644
index 0000000..2d5eb9c
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/schema/JavaTypesTest.java
@@ -0,0 +1,50 @@
+/**
+ * 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.schema;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+import junit.framework.TestCase;
+
+public class JavaTypesTest extends TestCase {
+
+ /**
+ * Tests that the constant values of java 6 is backwards compatible with
+ * java 5
+ */
+ public void testConstantValues() throws Exception {
+ Class<Java5Types> types5 = Java5Types.class;
+ Class<JdbcTypes> types6 = JdbcTypes.class;
+ Field[] fields = types5.getFields();
+ for (int i = 0; i < fields.length; i++) {
+ Field field5 = fields[i];
+ String fieldName = field5.getName();
+ int mod = field5.getModifiers();
+ if (Modifier.isFinal(mod) && Modifier.isPublic(mod)
+ && Modifier.isStatic(mod)) {
+ int value5 = field5.getInt(null);
+ Field field6 = types6.getField(fieldName);
+ int value6 = field6.getInt(null);
+ assertEquals("Value of field " + fieldName
+ + " was not the same", value5, value6);
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/schema/MutableColumnTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/MutableColumnTest.java b/core/src/test/java/org/apache/metamodel/schema/MutableColumnTest.java
new file mode 100644
index 0000000..a2b3ca6
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/schema/MutableColumnTest.java
@@ -0,0 +1,66 @@
+/**
+ * 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.schema;
+
+import junit.framework.TestCase;
+
+public class MutableColumnTest extends TestCase {
+
+ /**
+ * Tests that the following (general) rules apply to the object:
+ *
+ * <li>the hashcode is the same when run twice on an unaltered object</li>
+ * <li>if o1.equals(o2) then this condition must be true: o1.hashCode() ==
+ * 02.hashCode()
+ */
+ public void testEqualsAndHashCode() throws Exception {
+ Column column1 = new MutableColumn("foo");
+ Column column2 = new MutableColumn("foo");
+
+ assertEquals(column1.hashCode(), column2.hashCode());
+ assertEquals(column1, column2);
+
+ column2 = new MutableColumn("bar");
+ assertFalse(column1.equals(column2));
+
+ column2 = new MutableColumn("foo", ColumnType.VARBINARY);
+ assertFalse(column1.equals(column2));
+
+ column1 = new MutableColumn("foo", ColumnType.VARBINARY);
+ assertTrue(column1.equals(column2));
+ }
+
+ public void testQualifiedLabel() throws Exception {
+ MutableSchema s = new MutableSchema("FOO_SCHEMA");
+ MutableTable t = new MutableTable("FOO_TABLE");
+ MutableColumn c = new MutableColumn("FOO_COLUMN");
+
+ assertEquals("FOO_COLUMN", c.getQualifiedLabel());
+ t.addColumn(c);
+ c.setTable(t);
+ assertEquals("FOO_TABLE.FOO_COLUMN", c.getQualifiedLabel());
+ s.addTable(t);
+ t.setSchema(s);
+ assertEquals("FOO_SCHEMA.FOO_TABLE.FOO_COLUMN", c.getQualifiedLabel());
+
+ s.setName("new_schema_name");
+ assertEquals("new_schema_name.FOO_TABLE.FOO_COLUMN",
+ c.getQualifiedLabel());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/schema/MutableSchemaTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/MutableSchemaTest.java b/core/src/test/java/org/apache/metamodel/schema/MutableSchemaTest.java
new file mode 100644
index 0000000..8eca7b2
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/schema/MutableSchemaTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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.schema;
+
+import junit.framework.TestCase;
+
+public class MutableSchemaTest extends TestCase {
+
+ /**
+ * Tests that the following (general) rules apply to the object:
+ *
+ * <li>the hashcode is the same when run twice on an unaltered object</li>
+ * <li>if o1.equals(o2) then this condition must be true: o1.hashCode() ==
+ * 02.hashCode()
+ */
+ public void testEqualsAndHashCode() throws Exception {
+ MutableSchema schema1 = new MutableSchema("foo");
+ MutableSchema schema2 = new MutableSchema("foo");
+
+ assertTrue(schema1.equals(schema2));
+ assertTrue(schema1.hashCode() == schema2.hashCode());
+
+ schema2.addTable(new MutableTable("foo"));
+ assertFalse(schema1.equals(schema2));
+ assertTrue(schema1.hashCode() == schema2.hashCode());
+
+ schema2 = new MutableSchema("foo");
+ assertTrue(schema1.equals(schema2));
+ assertTrue(schema1.hashCode() == schema2.hashCode());
+ }
+
+ public void testGetTableByName() throws Exception {
+ MutableSchema s = new MutableSchema("foobar");
+ s.addTable(new MutableTable("Foo"));
+ s.addTable(new MutableTable("FOO"));
+ s.addTable(new MutableTable("bar"));
+
+ assertEquals("Foo", s.getTableByName("Foo").getName());
+ assertEquals("FOO", s.getTableByName("FOO").getName());
+ assertEquals("bar", s.getTableByName("bar").getName());
+
+ // picking the first alternative that matches case insensitively
+ assertEquals("Foo", s.getTableByName("fOO").getName());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/schema/MutableTableTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/MutableTableTest.java b/core/src/test/java/org/apache/metamodel/schema/MutableTableTest.java
new file mode 100644
index 0000000..4efb0d6
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/schema/MutableTableTest.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.schema;
+
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+public class MutableTableTest extends TestCase {
+
+ /**
+ * Tests that the following (general) rules apply to the object:
+ *
+ * <li>the hashcode is the same when run twice on an unaltered object</li>
+ * <li>if o1.equals(o2) then this condition must be true: o1.hashCode() ==
+ * 02.hashCode()
+ */
+ public void testEqualsAndHashCode() throws Exception {
+ MutableTable table1 = new MutableTable("Foo").addColumn(new MutableColumn("col1"));
+ MutableTable table2 = new MutableTable("Foo").addColumn(new MutableColumn("col1"));
+
+ assertFalse(table2.equals(null));
+ assertEquals(table1.hashCode(), table2.hashCode());
+ assertEquals(table1, table2);
+
+ table2.addColumn(new MutableColumn("bar"));
+ assertFalse(table1.equals(table2));
+
+ int table1hash = table1.hashCode();
+ int table2hash = table2.hashCode();
+ assertTrue(table1hash + "==" + table2hash, table1hash == table2hash);
+ }
+
+ public void testGetColumnsOfType() throws Exception {
+ MutableTable t = new MutableTable("foo");
+ t.addColumn(new MutableColumn("b").setType(ColumnType.VARCHAR));
+ t.addColumn(new MutableColumn("a").setType(ColumnType.VARCHAR));
+ t.addColumn(new MutableColumn("r").setType(ColumnType.INTEGER));
+
+ Column[] cols = t.getColumnsOfType(ColumnType.VARCHAR);
+ assertEquals(2, cols.length);
+ assertEquals("b", cols[0].getName());
+ assertEquals("a", cols[1].getName());
+
+ cols = t.getColumnsOfType(ColumnType.INTEGER);
+ assertEquals(1, cols.length);
+ assertEquals("r", cols[0].getName());
+
+ cols = t.getColumnsOfType(ColumnType.FLOAT);
+ assertEquals(0, cols.length);
+ }
+
+ public void testGetIndexedColumns() throws Exception {
+ MutableTable t = new MutableTable("foo");
+ t.addColumn(new MutableColumn("b").setIndexed(true));
+ t.addColumn(new MutableColumn("a").setIndexed(false));
+ t.addColumn(new MutableColumn("r").setIndexed(true));
+ Column[] indexedColumns = t.getIndexedColumns();
+ assertEquals(
+ "[Column[name=b,columnNumber=0,type=null,nullable=null,nativeType=null,columnSize=null], Column[name=r,columnNumber=0,type=null,nullable=null,nativeType=null,columnSize=null]]",
+ Arrays.toString(indexedColumns));
+ for (Column column : indexedColumns) {
+ assertTrue(column.isIndexed());
+ }
+ }
+
+ public void testGetColumnByName() throws Exception {
+ MutableTable t = new MutableTable("foobar");
+ t.addColumn(new MutableColumn("Foo"));
+ t.addColumn(new MutableColumn("FOO"));
+ t.addColumn(new MutableColumn("bar"));
+
+ assertEquals("Foo", t.getColumnByName("Foo").getName());
+ assertEquals("FOO", t.getColumnByName("FOO").getName());
+ assertEquals("bar", t.getColumnByName("bar").getName());
+
+ // picking the first alternative that matches case insensitively
+ assertEquals("Foo", t.getColumnByName("fOO").getName());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/schema/SchemaModelTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/SchemaModelTest.java b/core/src/test/java/org/apache/metamodel/schema/SchemaModelTest.java
new file mode 100644
index 0000000..380d9d1
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/schema/SchemaModelTest.java
@@ -0,0 +1,104 @@
+/**
+ * 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.schema;
+
+import java.util.Arrays;
+
+import org.eobjects.metamodel.MetaModelTestCase;
+
+public class SchemaModelTest extends MetaModelTestCase {
+
+ public void testGetExampleSchema() throws Exception {
+ Schema schema = getExampleSchema();
+ assertEquals("MetaModelSchema", schema.getName());
+ assertEquals("Schema[name=MetaModelSchema]", schema.toString());
+ assertEquals(5, schema.getRelationships().length);
+
+ assertEquals(4, schema.getTableCount());
+ assertEquals(3, schema.getTableCount(TableType.TABLE));
+ assertEquals(1, schema.getTableCount(TableType.VIEW));
+
+ assertNull(schema.getTableByName("foobar"));
+ assertNull(schema.getTableByName(null));
+
+ Table contributorTable = schema.getTableByName(TABLE_CONTRIBUTOR);
+ assertEquals(3, contributorTable.getColumnCount());
+ assertEquals(2, contributorTable.getRelationshipCount());
+
+ Table projectTable = schema.getTableByName(TABLE_PROJECT);
+ assertEquals(4, projectTable.getColumnCount());
+ assertEquals(2, projectTable.getRelationshipCount());
+ assertNotNull(projectTable.getColumnByName("project_id"));
+
+ assertEquals("[project_id, name, lines_of_code, parent_project_id]",
+ Arrays.toString(projectTable.getColumnNames()));
+
+ assertEquals(
+ "[Column[name=project_id,columnNumber=0,type=INTEGER,nullable=false,nativeType=null,columnSize=null], "
+ + "Column[name=lines_of_code,columnNumber=2,type=BIGINT,nullable=true,nativeType=null,columnSize=null], "
+ + "Column[name=parent_project_id,columnNumber=3,type=INTEGER,nullable=true,nativeType=null,columnSize=null]]",
+ Arrays.toString(projectTable.getNumberColumns()));
+
+ assertEquals("[Column[name=name,columnNumber=1,type=VARCHAR,nullable=false,nativeType=null,columnSize=null]]",
+ Arrays.toString(projectTable.getLiteralColumns()));
+
+ assertEquals("[]", Arrays.toString(projectTable.getTimeBasedColumns()));
+
+ assertNull(projectTable.getColumnByName("foobar"));
+ assertNull(projectTable.getColumnByName(null));
+
+ Table roleTable = schema.getTableByName(TABLE_ROLE);
+ assertEquals(3, roleTable.getColumnCount());
+ assertEquals(3, roleTable.getRelationshipCount());
+
+ Table projectContributorView = schema.getTableByName(TABLE_PROJECT_CONTRIBUTOR);
+ assertEquals(3, projectContributorView.getColumnCount());
+ assertEquals(3, projectContributorView.getRelationshipCount());
+
+ Relationship[] projectContributorToContributorRelations = projectContributorView
+ .getRelationships(contributorTable);
+ assertEquals(1, projectContributorToContributorRelations.length);
+ Relationship[] contributorToProjectContributorRelations = contributorTable
+ .getRelationships(projectContributorView);
+ assertEquals(1, contributorToProjectContributorRelations.length);
+ assertTrue(Arrays.equals(projectContributorToContributorRelations, contributorToProjectContributorRelations));
+
+ assertEquals(
+ "Relationship[primaryTable=contributor,primaryColumns=[name],foreignTable=project_contributor,foreignColumns=[contributor]]",
+ projectContributorToContributorRelations[0].toString());
+
+ ((MutableRelationship) projectContributorToContributorRelations[0]).remove();
+ projectContributorToContributorRelations = projectContributorView.getRelationships(contributorTable);
+ assertEquals(0, projectContributorToContributorRelations.length);
+ contributorToProjectContributorRelations = contributorTable.getRelationships(projectContributorView);
+ assertEquals(0, contributorToProjectContributorRelations.length);
+
+ // Get primary keys / Get foreign keys test
+ assertEquals(
+ "[Column[name=contributor_id,columnNumber=0,type=INTEGER,nullable=false,nativeType=null,columnSize=null]]",
+ Arrays.toString(contributorTable.getPrimaryKeys()));
+ assertEquals("[]", Arrays.toString(contributorTable.getForeignKeys()));
+
+ assertEquals(
+ "[Column[name=contributor_id,columnNumber=0,type=INTEGER,nullable=false,nativeType=null,columnSize=null], Column[name=project_id,columnNumber=1,type=INTEGER,nullable=false,nativeType=null,columnSize=null]]",
+ Arrays.toString(roleTable.getPrimaryKeys()));
+ Column[] foreignKeys = roleTable.getForeignKeys();
+ assertEquals(2, foreignKeys.length);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/schema/TableTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/TableTypeTest.java b/core/src/test/java/org/apache/metamodel/schema/TableTypeTest.java
new file mode 100644
index 0000000..127c54b
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/schema/TableTypeTest.java
@@ -0,0 +1,38 @@
+/**
+ * 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.schema;
+
+import junit.framework.TestCase;
+
+public class TableTypeTest extends TestCase {
+
+ public void testGetTableType() throws Exception {
+ assertSame(TableType.TABLE, TableType.getTableType("table"));
+ assertSame(TableType.VIEW, TableType.getTableType("view"));
+ assertSame(TableType.GLOBAL_TEMPORARY, TableType
+ .getTableType("GLOBAL_TEMPORARY"));
+ assertSame(TableType.SYSTEM_TABLE, TableType
+ .getTableType("system_table"));
+ assertSame(TableType.LOCAL_TEMPORARY, TableType
+ .getTableType("LOCAL_TEMPORARY"));
+ assertSame(TableType.ALIAS, TableType.getTableType("alIAs"));
+ assertSame(TableType.SYNONYM, TableType.getTableType("synonym"));
+ assertSame(TableType.OTHER, TableType.getTableType("foobar"));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/AlphabeticSequenceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/AlphabeticSequenceTest.java b/core/src/test/java/org/apache/metamodel/util/AlphabeticSequenceTest.java
new file mode 100644
index 0000000..075098e
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/AlphabeticSequenceTest.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.util;
+
+import junit.framework.TestCase;
+
+public class AlphabeticSequenceTest extends TestCase {
+
+ public void testNoArgsConstructor() throws Exception {
+ AlphabeticSequence seq = new AlphabeticSequence();
+ assertEquals("A", seq.next());
+ }
+
+ public void testNext() throws Exception {
+ AlphabeticSequence seq = new AlphabeticSequence("A");
+ assertEquals("A", seq.current());
+ assertEquals("B", seq.next());
+ assertEquals("C", seq.next());
+ assertEquals("D", seq.next());
+ assertEquals("E", seq.next());
+ assertEquals("F", seq.next());
+ assertEquals("G", seq.next());
+ assertEquals("H", seq.next());
+ assertEquals("I", seq.next());
+ assertEquals("J", seq.next());
+ assertEquals("K", seq.next());
+ assertEquals("L", seq.next());
+ assertEquals("M", seq.next());
+ assertEquals("N", seq.next());
+ assertEquals("O", seq.next());
+ assertEquals("P", seq.next());
+ assertEquals("Q", seq.next());
+ assertEquals("R", seq.next());
+ assertEquals("S", seq.next());
+ assertEquals("T", seq.next());
+ assertEquals("U", seq.next());
+ assertEquals("V", seq.next());
+ assertEquals("W", seq.next());
+ assertEquals("X", seq.next());
+ assertEquals("Y", seq.next());
+ assertEquals("Z", seq.next());
+ assertEquals("AA", seq.next());
+
+ seq = new AlphabeticSequence("AZ");
+ assertEquals("BA", seq.next());
+
+ seq = new AlphabeticSequence("ZZ");
+ assertEquals("AAA", seq.next());
+
+ seq = new AlphabeticSequence("ABZ");
+ assertEquals("ACA", seq.next());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/BaseObjectTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/BaseObjectTest.java b/core/src/test/java/org/apache/metamodel/util/BaseObjectTest.java
new file mode 100644
index 0000000..e147bc1
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/BaseObjectTest.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.util;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public class BaseObjectTest extends TestCase {
+
+ class MyClass extends BaseObject {
+ private int[] ints;
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ identifiers.add(ints);
+ }
+ }
+
+ public void testHashCodeForPrimitiveArray() throws Exception {
+ MyClass o1 = new MyClass();
+ o1.ints = new int[] { 1, 2, 3 };
+ MyClass o2 = new MyClass();
+ o2.ints = new int[] { 4, 5, 6 };
+ MyClass o3 = new MyClass();
+ o3.ints = new int[] { 1, 2, 3 };
+
+ assertTrue(o1.hashCode() == o1.hashCode());
+ assertTrue(o1.hashCode() == o3.hashCode());
+ assertFalse(o1.hashCode() == o2.hashCode());
+ assertFalse(o3.hashCode() == o2.hashCode());
+ }
+}
[08/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataContext.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataContext.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataContext.java
new file mode 100644
index 0000000..ddac728
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataContext.java
@@ -0,0 +1,794 @@
+/**
+ * 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.jdbc;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import javax.sql.DataSource;
+
+import org.eobjects.metamodel.AbstractDataContext;
+import org.eobjects.metamodel.BatchUpdateScript;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.UpdateableDataContext;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.EmptyDataSet;
+import org.eobjects.metamodel.data.MaxRowsDataSet;
+import org.eobjects.metamodel.jdbc.dialects.DB2QueryRewriter;
+import org.eobjects.metamodel.jdbc.dialects.DefaultQueryRewriter;
+import org.eobjects.metamodel.jdbc.dialects.H2QueryRewriter;
+import org.eobjects.metamodel.jdbc.dialects.HsqldbQueryRewriter;
+import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
+import org.eobjects.metamodel.jdbc.dialects.MysqlQueryRewriter;
+import org.eobjects.metamodel.jdbc.dialects.PostgresqlQueryRewriter;
+import org.eobjects.metamodel.jdbc.dialects.SQLServerQueryRewriter;
+import org.eobjects.metamodel.query.CompiledQuery;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.TableType;
+import org.eobjects.metamodel.util.FileHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DataContextStrategy to use for JDBC-compliant databases
+ */
+public class JdbcDataContext extends AbstractDataContext implements UpdateableDataContext {
+
+ public static final String SYSTEM_PROPERTY_BATCH_UPDATES = "metamodel.jdbc.batch.updates";
+ public static final String SYSTEM_PROPERTY_CONVERT_LOBS = "metamodel.jdbc.convert.lobs";
+
+ public static final String DATABASE_PRODUCT_POSTGRESQL = "PostgreSQL";
+ public static final String DATABASE_PRODUCT_MYSQL = "MySQL";
+ public static final String DATABASE_PRODUCT_HSQLDB = "HSQL Database Engine";
+ public static final String DATABASE_PRODUCT_H2 = "H2";
+ public static final String DATABASE_PRODUCT_SQLSERVER = "Microsoft SQL Server";
+ public static final String DATABASE_PRODUCT_DB2 = "DB2";
+ public static final String DATABASE_PRODUCT_DB2_PREFIX = "DB2/";
+
+ private static final Logger logger = LoggerFactory.getLogger(JdbcDataContext.class);
+
+ private final FetchSizeCalculator _fetchSizeCalculator;
+ private final Connection _connection;
+ private final DataSource _dataSource;
+ private final TableType[] _tableTypes;
+ private final String _catalogName;
+ private final boolean _singleConnection;
+
+ private final MetadataLoader _metadataLoader;
+
+ /**
+ * Defines the way that queries are written once dispatched to the database
+ */
+ private IQueryRewriter _queryRewriter;
+ private final String _databaseProductName;
+
+ /**
+ * There are some confusion as to the definition of catalogs and schemas.
+ * Some databases seperate "groups of tables" by using schemas, others by
+ * catalogs. This variable indicates whether a MetaModel schema really
+ * represents a catalog.
+ */
+ private final String _identifierQuoteString;
+ private final boolean _supportsBatchUpdates;
+ private final boolean _isDefaultAutoCommit;
+ private final boolean _usesCatalogsAsSchemas;
+
+ /**
+ * Creates the strategy based on a data source, some table types and an
+ * optional catalogName
+ *
+ * @param dataSource
+ * the datasource objcet to use for making connections
+ * @param tableTypes
+ * the types of tables to include
+ * @param catalogName
+ * a catalog name to use, can be null
+ */
+ public JdbcDataContext(DataSource dataSource, TableType[] tableTypes, String catalogName) {
+ this(dataSource, null, tableTypes, catalogName);
+ }
+
+ /**
+ * Creates the strategy based on a {@link Connection}, some table types and
+ * an optional catalogName
+ *
+ * @param connection
+ * the database connection
+ * @param tableTypes
+ * the types of tables to include
+ * @param catalogName
+ * a catalog name to use, can be null
+ */
+ public JdbcDataContext(Connection connection, TableType[] tableTypes, String catalogName) {
+ this(null, connection, tableTypes, catalogName);
+ }
+
+ /**
+ * Creates the strategy based on a {@link DataSource}, some table types and
+ * an optional catalogName
+ *
+ * @param dataSource
+ * the data source
+ * @param tableTypes
+ * the types of tables to include
+ * @param catalogName
+ * a catalog name to use, can be null
+ */
+ private JdbcDataContext(DataSource dataSource, Connection connection, TableType[] tableTypes, String catalogName) {
+ _dataSource = dataSource;
+ _connection = connection;
+ _tableTypes = tableTypes;
+ _catalogName = catalogName;
+
+ if (_dataSource == null) {
+ _singleConnection = true;
+ } else {
+ _singleConnection = false;
+ }
+
+ // available memory for fetching is so far fixed at 16 megs.
+ _fetchSizeCalculator = new FetchSizeCalculator(16 * 1024 * 1024);
+
+ boolean supportsBatchUpdates = false;
+ String identifierQuoteString = null;
+ String databaseProductName = null;
+ boolean usesCatalogsAsSchemas = false;
+
+ final Connection con = getConnection();
+
+ try {
+ _isDefaultAutoCommit = con.getAutoCommit();
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "determine auto-commit behaviour");
+ }
+
+ try {
+ DatabaseMetaData metaData = con.getMetaData();
+
+ supportsBatchUpdates = supportsBatchUpdates(metaData);
+
+ try {
+ identifierQuoteString = metaData.getIdentifierQuoteString();
+ if (identifierQuoteString != null) {
+ identifierQuoteString = identifierQuoteString.trim();
+ }
+ } catch (SQLException e) {
+ logger.warn("could not retrieve identifier quote string from database metadata", e);
+ }
+
+ usesCatalogsAsSchemas = usesCatalogsAsSchemas(metaData);
+ try {
+ databaseProductName = metaData.getDatabaseProductName();
+ } catch (SQLException e) {
+ logger.warn("Could not retrieve database product name: " + e.getMessage());
+ }
+ } catch (SQLException e) {
+ logger.debug("Unexpected exception during JdbcDataContext initialization", e);
+ } finally {
+ closeIfNescesary(con);
+ }
+ _databaseProductName = databaseProductName;
+ logger.debug("Database product name: {}", _databaseProductName);
+ if (DATABASE_PRODUCT_MYSQL.equals(_databaseProductName)) {
+ setQueryRewriter(new MysqlQueryRewriter(this));
+ } else if (DATABASE_PRODUCT_POSTGRESQL.equals(_databaseProductName)) {
+ setQueryRewriter(new PostgresqlQueryRewriter(this));
+ } else if (DATABASE_PRODUCT_SQLSERVER.equals(_databaseProductName)) {
+ setQueryRewriter(new SQLServerQueryRewriter(this));
+ } else if (DATABASE_PRODUCT_DB2.equals(_databaseProductName)
+ || (_databaseProductName != null && _databaseProductName.startsWith(DATABASE_PRODUCT_DB2_PREFIX))) {
+ setQueryRewriter(new DB2QueryRewriter(this));
+ } else if (DATABASE_PRODUCT_HSQLDB.equals(_databaseProductName)) {
+ setQueryRewriter(new HsqldbQueryRewriter(this));
+ } else if (DATABASE_PRODUCT_H2.equals(_databaseProductName)) {
+ setQueryRewriter(new H2QueryRewriter(this));
+ } else {
+ setQueryRewriter(new DefaultQueryRewriter(this));
+ }
+
+ _supportsBatchUpdates = supportsBatchUpdates;
+ _identifierQuoteString = identifierQuoteString;
+ _usesCatalogsAsSchemas = usesCatalogsAsSchemas;
+ _metadataLoader = new JdbcMetadataLoader(this, _usesCatalogsAsSchemas, _identifierQuoteString);
+ }
+
+ /**
+ * Creates the strategy based on a {@link Connection}
+ *
+ * @param connection
+ * the database connection
+ */
+ public JdbcDataContext(Connection connection) {
+ this(connection, TableType.DEFAULT_TABLE_TYPES, null);
+ }
+
+ /**
+ * Creates the strategy based on a {@link DataSource}
+ *
+ * @param dataSource
+ * the data source
+ */
+ public JdbcDataContext(DataSource dataSource) {
+ this(dataSource, TableType.DEFAULT_TABLE_TYPES, null);
+ }
+
+ private boolean supportsBatchUpdates(DatabaseMetaData metaData) {
+ if ("true".equals(System.getProperty(SYSTEM_PROPERTY_BATCH_UPDATES))) {
+ return true;
+ }
+ if ("false".equals(System.getProperty(SYSTEM_PROPERTY_BATCH_UPDATES))) {
+ return false;
+ }
+
+ try {
+ return metaData.supportsBatchUpdates();
+ } catch (Exception e) {
+ logger.warn("Could not determine if driver support batch updates, returning false", e);
+ return false;
+ }
+ }
+
+ private boolean usesCatalogsAsSchemas(DatabaseMetaData metaData) {
+ boolean result = true;
+ ResultSet rs = null;
+ try {
+ rs = metaData.getSchemas();
+ while (rs.next() && result) {
+ result = false;
+ }
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "retrieve schema and catalog metadata");
+ } finally {
+ close(null, rs, null);
+ }
+ return result;
+ }
+
+ @Override
+ public CompiledQuery compileQuery(Query query) {
+ return new JdbcCompiledQuery(this, query);
+ }
+
+ @Override
+ public DataSet executeQuery(CompiledQuery compiledQuery, Object... values) {
+
+ final JdbcCompiledQuery jdbcCompiledQuery = (JdbcCompiledQuery) compiledQuery;
+
+ final Query query = jdbcCompiledQuery.getQuery();
+ final int countMatches = jdbcCompiledQuery.getParameters().size();
+
+ final int valueArrayLength = values.length;
+
+ if (countMatches != valueArrayLength) {
+ throw new MetaModelException("Number of parameters in query and number of values does not match.");
+ }
+
+ final JdbcCompiledQueryLease lease = jdbcCompiledQuery.borrowLease();
+ final DataSet dataSet;
+ try {
+ dataSet = execute(lease.getConnection(), query, lease.getStatement(), jdbcCompiledQuery, lease, values);
+ } catch (SQLException e) {
+ // only close in case of an error - the JdbcDataSet will close
+ // otherwise
+ jdbcCompiledQuery.returnLease(lease);
+ throw JdbcUtils.wrapException(e, "execute compiled query");
+ }
+
+ return dataSet;
+ }
+
+ private DataSet execute(Connection connection, Query query, Statement statement, JdbcCompiledQuery compiledQuery,
+ JdbcCompiledQueryLease lease, Object[] values) throws SQLException {
+ if (_databaseProductName.equals(DATABASE_PRODUCT_POSTGRESQL)) {
+
+ try {
+ // this has to be done in order to make a result set not load
+ // all data in memory only for Postgres.
+ connection.setAutoCommit(false);
+ } catch (Exception e) {
+ logger.warn("Could not disable auto-commit (PostgreSQL specific hack)", e);
+ }
+ }
+
+ ResultSet resultSet = null;
+
+ boolean postProcessFirstRow = false;
+ final Integer firstRow = query.getFirstRow();
+ if (firstRow != null) {
+ if (_queryRewriter.isFirstRowSupported()) {
+ logger.debug("First row property will be treated by query rewriter");
+ } else {
+ postProcessFirstRow = true;
+ }
+ }
+
+ boolean postProcessMaxRows = false;
+ Integer maxRows = query.getMaxRows();
+ if (maxRows != null) {
+ if (postProcessFirstRow) {
+ // if First row is being post processed, we need to
+ // increment the "Max rows" accordingly (but subtract one, since
+ // firstRow is 1-based).
+ maxRows = maxRows + (firstRow - 1);
+ query = query.clone().setMaxRows(maxRows);
+
+ logger.debug("Setting Max rows to {} because of post processing strategy of First row.", maxRows);
+ }
+
+ if (_queryRewriter.isMaxRowsSupported()) {
+ logger.debug("Max rows property will be treated by query rewriter");
+ } else {
+ try {
+ statement.setMaxRows(maxRows);
+ } catch (SQLException e) {
+ if (logger.isInfoEnabled()) {
+ logger.info("setMaxRows(" + maxRows + ") was rejected.", e);
+ }
+ postProcessMaxRows = true;
+ }
+ }
+ }
+
+ DataSet dataSet = null;
+ try {
+ final int fetchSize = getFetchSize(query, statement);
+
+ logger.debug("Applying fetch_size={}", fetchSize);
+
+ try {
+ statement.setFetchSize(fetchSize);
+ } catch (Exception e) {
+ // Ticket #372: Sometimes an exception is thrown here even
+ // though it's contrary to the jdbc spec. We'll proceed without
+ // doing anything about it though.
+ logger.info("Could not get or set fetch size on Statement: {}", e.getMessage());
+ }
+
+ if (lease == null) {
+ final String queryString = _queryRewriter.rewriteQuery(query);
+
+ logger.debug("Executing rewritten query: {}", queryString);
+
+ resultSet = statement.executeQuery(queryString);
+ } else {
+ PreparedStatement preparedStatement = (PreparedStatement) statement;
+ for (int i = 0; i < values.length; i++) {
+ preparedStatement.setObject(i + 1, values[i]);
+ }
+ resultSet = preparedStatement.executeQuery();
+ }
+ try {
+ resultSet.setFetchSize(fetchSize);
+ } catch (Exception e) {
+ logger.warn("Could not set fetch size on ResultSet: {}", e.getMessage());
+ }
+
+ if (postProcessFirstRow) {
+ // we iterate to the "first row" using the resultset itself.
+ for (int i = 1; i < firstRow; i++) {
+ if (!resultSet.next()) {
+ // the result set was not as long as the first row
+ if (resultSet != null) {
+ resultSet.close();
+ }
+ return new EmptyDataSet(query.getSelectClause().getItems());
+ }
+ }
+ }
+
+ if (lease == null) {
+ dataSet = new JdbcDataSet(query, this, connection, statement, resultSet);
+ } else {
+ dataSet = new JdbcDataSet(compiledQuery, lease, resultSet);
+ }
+
+ if (postProcessMaxRows) {
+ dataSet = new MaxRowsDataSet(dataSet, maxRows);
+ }
+ } catch (SQLException exception) {
+ if (resultSet != null) {
+ resultSet.close();
+ }
+ throw exception;
+ }
+ return dataSet;
+ }
+
+ public DataSet executeQuery(Query query) throws MetaModelException {
+
+ final Connection connection = getConnection();
+ final Statement statement;
+ try {
+ statement = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "create statement for query");
+ }
+ DataSet dataSet = null;
+ try {
+
+ dataSet = execute(connection, query, statement, null, null, null);
+
+ } catch (SQLException e) {
+ // only close in case of an error - the JdbcDataSet will close
+ // otherwise
+ close(connection, null, statement);
+ throw JdbcUtils.wrapException(e, "execute query");
+ }
+
+ return dataSet;
+ }
+
+ private int getFetchSize(Query query, final Statement statement) {
+ try {
+ final int defaultFetchSize = statement.getFetchSize();
+ if (DATABASE_PRODUCT_MYSQL.equals(_databaseProductName) && defaultFetchSize == Integer.MIN_VALUE) {
+ return defaultFetchSize;
+ }
+ } catch (Exception e) {
+ // exceptions here are ignored.
+ logger.debug("Ignoring exception while getting fetch size", e);
+ }
+ return _fetchSizeCalculator.getFetchSize(query);
+ }
+
+ /**
+ * Quietly closes any of the parameterized JDBC objects
+ *
+ * @param connection
+ *
+ * @param rs
+ * @param st
+ */
+ public void close(Connection connection, ResultSet rs, Statement st) {
+ closeIfNescesary(connection);
+ FileHelper.safeClose(rs, st);
+ }
+
+ /**
+ * Convenience method to get the available catalogNames using this
+ * connection.
+ *
+ * @return a String-array with the names of the available catalogs.
+ */
+ public String[] getCatalogNames() {
+ Connection connection = getConnection();
+
+ // Retrieve metadata
+ DatabaseMetaData metaData = null;
+ ResultSet rs = null;
+ try {
+ metaData = connection.getMetaData();
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "retrieve metadata");
+ }
+
+ // Retrieve catalogs
+ logger.debug("Retrieving catalogs");
+ List<String> catalogs = new ArrayList<String>();
+ try {
+ rs = metaData.getCatalogs();
+ while (rs.next()) {
+ String catalogName = rs.getString(1);
+ logger.debug("Found catalogName: {}", catalogName);
+ catalogs.add(catalogName);
+ }
+ } catch (SQLException e) {
+ logger.error("Error retrieving catalog metadata", e);
+ } finally {
+ close(connection, rs, null);
+ logger.debug("Retrieved {} catalogs", catalogs.size());
+ }
+ return catalogs.toArray(new String[catalogs.size()]);
+ }
+
+ /**
+ * Gets the delegate from the JDBC API (ie. Connection or DataSource) that
+ * is being used to perform database interactions.
+ *
+ * @return either a DataSource or a Connection, depending on the
+ * configuration of the DataContext.
+ */
+ public Object getDelegate() {
+ if (_dataSource == null) {
+ return _connection;
+ }
+ return _dataSource;
+ }
+
+ /**
+ * Gets an appropriate connection object to use - either a dedicated
+ * connection or a new connection from the datasource object.
+ *
+ * Hint: Use the {@link #close(Connection, ResultSet, Statement)} method to
+ * close the connection (and any ResultSet or Statements involved).
+ */
+ public Connection getConnection() {
+ if (_dataSource == null) {
+ return _connection;
+ }
+ try {
+ return _dataSource.getConnection();
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "establish connection");
+ }
+ }
+
+ private void closeIfNescesary(Connection con) {
+ if (con != null) {
+ if (_dataSource != null) {
+ // closing connections after individual usage is only nescesary
+ // when they are being pulled from a DataSource.
+ FileHelper.safeClose(con);
+ }
+ }
+ }
+
+ public String getDefaultSchemaName() {
+ // Use a boolean to check if the result has been
+ // found, because a schema name can actually be
+ // null (for example in the case of Firebird
+ // databases).
+ boolean found = false;
+ String result = null;
+ String[] schemaNames = getSchemaNames();
+
+ // First strategy: If there's only one schema available, that must
+ // be it
+ if (schemaNames.length == 1) {
+ result = schemaNames[0];
+ found = true;
+ }
+
+ if (!found) {
+ Connection connection = getConnection();
+ try {
+ DatabaseMetaData metaData = connection.getMetaData();
+
+ // Second strategy: Find default schema name by examining the
+ // URL
+ if (!found) {
+ String url = metaData.getURL();
+ if (url != null && url.length() > 0) {
+ if (schemaNames.length > 0) {
+ StringTokenizer st = new StringTokenizer(url, "/\\:");
+ int tokenCount = st.countTokens();
+ if (tokenCount > 0) {
+ for (int i = 1; i < tokenCount; i++) {
+ st.nextToken();
+ }
+ String lastToken = st.nextToken();
+
+ for (int i = 0; i < schemaNames.length && !found; i++) {
+ String schemaName = schemaNames[i];
+ if (lastToken.indexOf(schemaName) != -1) {
+ result = schemaName;
+ found = true;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // Third strategy: Check for schema equal to username
+ if (!found) {
+ String username = metaData.getUserName();
+ if (username != null) {
+ for (int i = 0; i < schemaNames.length && !found; i++) {
+ if (username.equalsIgnoreCase(schemaNames[i])) {
+ result = schemaNames[i];
+ found = true;
+ }
+ }
+ }
+ }
+
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "determine default schema name");
+ } finally {
+ closeIfNescesary(connection);
+ }
+
+ // Fourth strategy: Find default schema name by vendor-specific
+ // hacks
+ if (!found) {
+ if (DATABASE_PRODUCT_POSTGRESQL.equalsIgnoreCase(_databaseProductName)) {
+ if (_catalogName == null) {
+ result = "public";
+ } else {
+ result = _catalogName;
+ }
+ found = true;
+ }
+ if (DATABASE_PRODUCT_HSQLDB.equalsIgnoreCase(_databaseProductName)) {
+ for (int i = 0; i < schemaNames.length && !found; i++) {
+ String schemaName = schemaNames[i];
+ if ("PUBLIC".equals(schemaName)) {
+ result = schemaName;
+ found = true;
+ break;
+ }
+ }
+ }
+ if (DATABASE_PRODUCT_SQLSERVER.equals(_databaseProductName)) {
+ for (int i = 0; i < schemaNames.length && !found; i++) {
+ String schemaName = schemaNames[i];
+ if ("dbo".equals(schemaName)) {
+ result = schemaName;
+ found = true;
+ break;
+ }
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Microsoft SQL Server returns users instead of schemas when calling
+ * metadata.getSchemas() This is a simple workaround.
+ *
+ * @return
+ * @throws SQLException
+ */
+ private Set<String> getSchemaSQLServerNames(DatabaseMetaData metaData) throws SQLException {
+ // Distinct schema names. metaData.getTables() is a denormalized
+ // resultset
+ Set<String> schemas = new HashSet<String>();
+ ResultSet rs = metaData.getTables(_catalogName, null, null, JdbcUtils.getTableTypesAsStrings(_tableTypes));
+ while (rs.next()) {
+ schemas.add(rs.getString("TABLE_SCHEM"));
+ }
+ return schemas;
+ }
+
+ public JdbcDataContext setQueryRewriter(IQueryRewriter queryRewriter) {
+ if (queryRewriter == null) {
+ throw new IllegalArgumentException("Query rewriter cannot be null");
+ }
+ _queryRewriter = queryRewriter;
+ return this;
+ }
+
+ public IQueryRewriter getQueryRewriter() {
+ return _queryRewriter;
+ }
+
+ public String getIdentifierQuoteString() {
+ return _identifierQuoteString;
+ }
+
+ @Override
+ protected String[] getSchemaNamesInternal() {
+ Connection connection = getConnection();
+ try {
+ DatabaseMetaData metaData = connection.getMetaData();
+ Collection<String> result = new ArrayList<String>();
+
+ if (DATABASE_PRODUCT_SQLSERVER.equals(_databaseProductName)) {
+ result = getSchemaSQLServerNames(metaData);
+ } else if (_usesCatalogsAsSchemas) {
+ String[] catalogNames = getCatalogNames();
+ for (String name : catalogNames) {
+ logger.debug("Found catalogName: {}", name);
+ result.add(name);
+ }
+ } else {
+ ResultSet rs = metaData.getSchemas();
+ while (rs.next()) {
+ String schemaName = rs.getString(1);
+ logger.debug("Found schemaName: {}", schemaName);
+ result.add(schemaName);
+ }
+ rs.close();
+ }
+
+ if (DATABASE_PRODUCT_MYSQL.equals(_databaseProductName)) {
+ result.remove("information_schema");
+ }
+
+ // If still no schemas are found, add a schema with a null-name
+ if (result.isEmpty()) {
+ logger.info("No schemas or catalogs found. Creating unnamed schema.");
+ result.add(null);
+ }
+ return result.toArray(new String[result.size()]);
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "get schema names");
+ } finally {
+ closeIfNescesary(connection);
+ }
+ }
+
+ @Override
+ protected Schema getSchemaByNameInternal(String name) {
+ JdbcSchema schema = new JdbcSchema(name, _metadataLoader);
+ _metadataLoader.loadTables(schema);
+ return schema;
+ }
+
+ public FetchSizeCalculator getFetchSizeCalculator() {
+ return _fetchSizeCalculator;
+ }
+
+ @Override
+ public void executeUpdate(final UpdateScript update) {
+ final JdbcUpdateCallback updateCallback;
+
+ if (_supportsBatchUpdates && update instanceof BatchUpdateScript) {
+ updateCallback = new JdbcBatchUpdateCallback(this);
+ } else {
+ updateCallback = new JdbcSimpleUpdateCallback(this);
+ }
+
+ try {
+ if (isSingleConnection() && isDefaultAutoCommit()) {
+ // if auto-commit is going to be switched off and on during
+ // updates, then the update needs to be synchronized, to avoid
+ // race-conditions when switching off and on.
+ synchronized (_connection) {
+ update.run(updateCallback);
+ }
+ } else {
+ update.run(updateCallback);
+ }
+ updateCallback.close(true);
+ } catch (RuntimeException e) {
+ updateCallback.close(false);
+ throw e;
+ }
+ }
+
+ protected boolean isSingleConnection() {
+ return _singleConnection;
+ }
+
+ protected boolean isDefaultAutoCommit() {
+ return _isDefaultAutoCommit;
+ }
+
+ @Override
+ protected boolean isQualifiedPathDelim(char c) {
+ if (_identifierQuoteString == null || _identifierQuoteString.length() == 0) {
+ return super.isQualifiedPathDelim(c);
+ }
+ return c == '.' || c == _identifierQuoteString.charAt(0);
+ }
+
+ public TableType[] getTableTypes() {
+ return _tableTypes;
+ }
+
+ public String getCatalogName() {
+ return _catalogName;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataSet.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataSet.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataSet.java
new file mode 100644
index 0000000..09b3689
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataSet.java
@@ -0,0 +1,229 @@
+/**
+ * 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.jdbc;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.data.AbstractDataSet;
+import org.eobjects.metamodel.data.DefaultRow;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.util.FileHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DataSet implementation that wraps a JDBC resultset.
+ *
+ * @author Kasper Sørensen
+ */
+final class JdbcDataSet extends AbstractDataSet {
+
+ private static final Logger logger = LoggerFactory.getLogger(JdbcDataSet.class);
+
+ private final JdbcCompiledQuery _compiledQuery;
+ private final JdbcCompiledQueryLease _lease;
+ private final Statement _statement;
+ private final ResultSet _resultSet;
+ private final JdbcDataContext _jdbcDataContext;
+ private final Connection _connection;
+ private Row _row;
+ private boolean _closed;
+
+ /**
+ * Constructor used for regular query execution.
+ *
+ * @param query
+ * @param jdbcDataContext
+ * @param connection
+ * @param statement
+ * @param resultSet
+ */
+ public JdbcDataSet(Query query, JdbcDataContext jdbcDataContext, Connection connection, Statement statement,
+ ResultSet resultSet) {
+ super(query.getSelectClause().getItems());
+ if (query == null || statement == null || resultSet == null) {
+ throw new IllegalArgumentException("Arguments cannot be null");
+ }
+ _jdbcDataContext = jdbcDataContext;
+ _connection = connection;
+ _statement = statement;
+ _resultSet = resultSet;
+ _closed = false;
+ _compiledQuery = null;
+ _lease = null;
+ }
+
+ /**
+ * Constructor used for compiled query execution
+ *
+ * @param query
+ * @param jdbcDataContext
+ * @param resultSet
+ */
+ public JdbcDataSet(JdbcCompiledQuery compiledQuery, JdbcCompiledQueryLease lease, ResultSet resultSet) {
+ super(compiledQuery.getSelectItems());
+ if (compiledQuery == null || lease == null || resultSet == null) {
+ throw new IllegalArgumentException("Arguments cannot be null");
+ }
+
+ _compiledQuery = compiledQuery;
+ _lease = lease;
+
+ _jdbcDataContext = null;
+ _connection = null;
+ _statement = null;
+ _resultSet = resultSet;
+ _closed = false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Row getRow() {
+ return _row;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean next() throws MetaModelException {
+ try {
+ boolean result = _resultSet.next();
+ if (result) {
+ Object[] values = new Object[getHeader().size()];
+ for (int i = 0; i < values.length; i++) {
+
+ values[i] = getValue(_resultSet, i);
+
+ try {
+ // some drivers return boxed primitive types in stead of
+ // nulls (such as false in stead of null for a Boolean
+ // column)
+ if (_resultSet.wasNull()) {
+ values[i] = null;
+ }
+ } catch (Exception e) {
+ logger.debug("Could not invoke wasNull() method on resultset, error message: {}",
+ e.getMessage());
+ }
+ }
+ _row = new DefaultRow(getHeader(), values);
+ } else {
+ _row = null;
+ }
+ return result;
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "get next record in resultset");
+ }
+ }
+
+ private Object getValue(ResultSet resultSet, int i) throws SQLException {
+ final SelectItem selectItem = getHeader().getSelectItem(i);
+ final int columnIndex = i + 1;
+ if (selectItem.getFunction() == null) {
+ Column column = selectItem.getColumn();
+ if (column != null) {
+ ColumnType type = column.getType();
+ try {
+ switch (type) {
+ case TIME:
+ return _resultSet.getTime(columnIndex);
+ case DATE:
+ return _resultSet.getDate(columnIndex);
+ case TIMESTAMP:
+ return _resultSet.getTimestamp(columnIndex);
+ case BLOB:
+ final Blob blob = _resultSet.getBlob(columnIndex);
+ if (isLobConversionEnabled()) {
+ final InputStream inputStream = blob.getBinaryStream();
+ final byte[] bytes = FileHelper.readAsBytes(inputStream);
+ return bytes;
+ }
+ return blob;
+ case BINARY:
+ case VARBINARY:
+ case LONGVARBINARY:
+ return _resultSet.getBytes(columnIndex);
+ case CLOB:
+ case NCLOB:
+ final Clob clob = _resultSet.getClob(columnIndex);
+ if (isLobConversionEnabled()) {
+ final Reader reader = clob.getCharacterStream();
+ final String result = FileHelper.readAsString(reader);
+ return result;
+ }
+ return clob;
+ case BIT:
+ case BOOLEAN:
+ return _resultSet.getBoolean(columnIndex);
+ }
+ } catch (Exception e) {
+ logger.warn("Failed to retrieve " + type
+ + " value using type-specific getter, retrying with generic getObject(...) method", e);
+ }
+ }
+ }
+ return _resultSet.getObject(columnIndex);
+ }
+
+ private boolean isLobConversionEnabled() {
+ final String systemProperty = System.getProperty(JdbcDataContext.SYSTEM_PROPERTY_CONVERT_LOBS);
+ return "true".equals(systemProperty);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void close() {
+ if (_closed) {
+ return;
+ }
+ if (_jdbcDataContext != null) {
+ _jdbcDataContext.close(_connection, _resultSet, _statement);
+ }
+ if (_compiledQuery != null) {
+ _compiledQuery.returnLease(_lease);
+ }
+ _closed = true;
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ if (!_closed) {
+ logger.warn("finalize() invoked, but DataSet is not closed. Invoking close() on {}", this);
+ close();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDeleteBuilder.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDeleteBuilder.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDeleteBuilder.java
new file mode 100644
index 0000000..ef04b63
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDeleteBuilder.java
@@ -0,0 +1,98 @@
+/**
+ * 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.jdbc;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.List;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.delete.AbstractRowDeletionBuilder;
+import org.eobjects.metamodel.delete.RowDeletionBuilder;
+import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.FileHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * {@link RowDeletionBuilder} that issues an SQL DELETE FROM statement
+ *
+ * @author Kasper Sørensen
+ */
+final class JdbcDeleteBuilder extends AbstractRowDeletionBuilder {
+
+ private static final Logger logger = LoggerFactory.getLogger(JdbcDeleteBuilder.class);
+
+ private final JdbcUpdateCallback _updateCallback;
+ private final IQueryRewriter _queryRewriter;
+ private final boolean _inlineValues;
+
+ public JdbcDeleteBuilder(JdbcUpdateCallback updateCallback, Table table, IQueryRewriter queryRewriter) {
+ this(updateCallback, table, queryRewriter, false);
+ }
+
+ public JdbcDeleteBuilder(JdbcUpdateCallback updateCallback, Table table, IQueryRewriter queryRewriter,
+ boolean inlineValues) {
+ super(table);
+ _updateCallback = updateCallback;
+ _queryRewriter = queryRewriter;
+ _inlineValues = inlineValues;
+ }
+
+ @Override
+ public void execute() throws MetaModelException {
+ String sql = createSqlStatement();
+
+ logger.debug("Delete statement created: {}", sql);
+ final boolean reuseStatement = !_inlineValues;
+ final PreparedStatement st = _updateCallback.getPreparedStatement(sql, reuseStatement);
+ try {
+ if (reuseStatement) {
+ int valueCounter = 1;
+ final List<FilterItem> whereItems = getWhereItems();
+ for (FilterItem whereItem : whereItems) {
+ if (JdbcUtils.isPreparedParameterCandidate(whereItem)) {
+ Object operand = whereItem.getOperand();
+ st.setObject(valueCounter, operand);
+ valueCounter++;
+ }
+ }
+ }
+ _updateCallback.executePreparedStatement(st, reuseStatement);
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "execute delete statement: " + sql);
+ } finally {
+ if (_inlineValues) {
+ FileHelper.safeClose(st);
+ }
+ }
+ }
+
+ protected String createSqlStatement() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("DELETE FROM ");
+ sb.append(_queryRewriter.rewriteFromItem(new FromItem(getTable())));
+ sb.append(JdbcUtils.createWhereClause(getWhereItems(), _queryRewriter, _inlineValues));
+ return sb.toString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDropTableBuilder.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDropTableBuilder.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDropTableBuilder.java
new file mode 100644
index 0000000..e903726
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDropTableBuilder.java
@@ -0,0 +1,72 @@
+/**
+ * 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.jdbc;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import org.eobjects.metamodel.drop.AbstractTableDropBuilder;
+import org.eobjects.metamodel.drop.TableDropBuilder;
+import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * {@link TableDropBuilder} that issues an SQL DROP TABLE statement
+ *
+ * @author Kasper Sørensen
+ */
+final class JdbcDropTableBuilder extends AbstractTableDropBuilder implements TableDropBuilder {
+
+ private final JdbcUpdateCallback _updateCallback;
+ private final IQueryRewriter _queryRewriter;
+
+ public JdbcDropTableBuilder(JdbcUpdateCallback updateCallback, Table table, IQueryRewriter queryRewriter) {
+ super(table);
+ _updateCallback = updateCallback;
+ _queryRewriter = queryRewriter;
+ }
+
+ @Override
+ public void execute() {
+ String sql = createSqlStatement();
+
+ PreparedStatement statement = _updateCallback.getPreparedStatement(sql, false);
+ try {
+ _updateCallback.executePreparedStatement(statement, false);
+
+ // remove the table reference from the schema
+ final Schema schema = getTable().getSchema();
+ if (schema instanceof JdbcSchema) {
+ ((JdbcSchema) schema).refreshTables();
+ }
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "execute drop table statement: " + sql);
+ }
+ }
+
+ protected String createSqlStatement() {
+ FromItem fromItem = new FromItem(getTable());
+ String tableLabel = _queryRewriter.rewriteFromItem(fromItem);
+
+ return "DROP TABLE " + tableLabel;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcInsertBuilder.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcInsertBuilder.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcInsertBuilder.java
new file mode 100644
index 0000000..9cfd4bc
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcInsertBuilder.java
@@ -0,0 +1,151 @@
+/**
+ * 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.jdbc;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.Arrays;
+
+import org.eobjects.metamodel.insert.AbstractRowInsertionBuilder;
+import org.eobjects.metamodel.insert.RowInsertionBuilder;
+import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.FileHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * {@link RowInsertionBuilder} that issues an SQL INSERT statement
+ *
+ * @author Kasper Sørensen
+ */
+final class JdbcInsertBuilder extends AbstractRowInsertionBuilder<JdbcUpdateCallback> {
+
+ private static final Logger logger = LoggerFactory.getLogger(JdbcInsertBuilder.class);
+
+ private final boolean _inlineValues;
+ private final IQueryRewriter _queryRewriter;
+
+ public JdbcInsertBuilder(JdbcUpdateCallback updateCallback, Table table, IQueryRewriter queryRewriter) {
+ this(updateCallback, table, false, queryRewriter);
+ }
+
+ public JdbcInsertBuilder(JdbcUpdateCallback updateCallback, Table table, boolean isInlineValues,
+ IQueryRewriter queryRewriter) {
+ super(updateCallback, table);
+ if (!(table instanceof JdbcTable)) {
+ throw new IllegalArgumentException("Not a valid JDBC table: " + table);
+ }
+
+ _inlineValues = isInlineValues;
+ _queryRewriter = queryRewriter;
+ }
+
+ @Override
+ public void execute() {
+ final String sql = createSqlStatement();
+ if (logger.isDebugEnabled()) {
+ logger.debug("Inserting: {}", Arrays.toString(getValues()));
+ logger.debug("Insert statement created: {}", sql);
+ }
+ final JdbcUpdateCallback updateCallback = getUpdateCallback();
+ final boolean reuseStatement = !_inlineValues;
+ final PreparedStatement st = updateCallback.getPreparedStatement(sql, reuseStatement);
+ try {
+ if (reuseStatement) {
+ Column[] columns = getColumns();
+ Object[] values = getValues();
+ boolean[] explicitNulls = getExplicitNulls();
+ int valueCounter = 1;
+ for (int i = 0; i < columns.length; i++) {
+ boolean explicitNull = explicitNulls[i];
+ if (values[i] != null || explicitNull) {
+ JdbcUtils.setStatementValue(st, valueCounter, columns[i], values[i]);
+ valueCounter++;
+ }
+ }
+ }
+ updateCallback.executePreparedStatement(st, reuseStatement);
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "execute insert statement: " + sql);
+ } finally {
+ if (_inlineValues) {
+ FileHelper.safeClose(st);
+ }
+ }
+ }
+
+ protected String createSqlStatement() {
+ return createSqlStatement(_inlineValues);
+ }
+
+ private String createSqlStatement(boolean inlineValues) {
+ final Object[] values = getValues();
+ final Table table = getTable();
+ final StringBuilder sb = new StringBuilder();
+
+ final String tableLabel = _queryRewriter.rewriteFromItem(new FromItem(table));
+
+ sb.append("INSERT INTO ");
+ sb.append(tableLabel);
+ sb.append(" (");
+ Column[] columns = getColumns();
+ boolean[] explicitNulls = getExplicitNulls();
+ boolean firstValue = true;
+ for (int i = 0; i < columns.length; i++) {
+ if (values[i] != null || explicitNulls[i]) {
+ if (firstValue) {
+ firstValue = false;
+ } else {
+ sb.append(',');
+ }
+ String columnName = columns[i].getName();
+ columnName = getUpdateCallback().quoteIfNescesary(columnName);
+ sb.append(columnName);
+ }
+ }
+
+ sb.append(") VALUES (");
+ firstValue = true;
+ for (int i = 0; i < columns.length; i++) {
+ if (values[i] != null || explicitNulls[i]) {
+ if (firstValue) {
+ firstValue = false;
+ } else {
+ sb.append(',');
+ }
+ if (inlineValues) {
+ sb.append(JdbcUtils.getValueAsSql(columns[i], values[i], _queryRewriter));
+ } else {
+ sb.append('?');
+ }
+ }
+ }
+ sb.append(")");
+ String sql = sb.toString();
+ return sql;
+ }
+
+ @Override
+ public String toSql() {
+ return createSqlStatement(true);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcMetadataLoader.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcMetadataLoader.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcMetadataLoader.java
new file mode 100644
index 0000000..97753a1
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcMetadataLoader.java
@@ -0,0 +1,427 @@
+/**
+ * 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.jdbc;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.schema.MutableRelationship;
+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;
+
+/**
+ * {@link MetadataLoader} for JDBC metadata loading.
+ */
+final class JdbcMetadataLoader implements MetadataLoader {
+
+ private static final Logger logger = LoggerFactory.getLogger(JdbcMetadataLoader.class);
+
+ private final JdbcDataContext _dataContext;
+ private final boolean _usesCatalogsAsSchemas;
+ private final String _identifierQuoteString;
+
+ // these three sets contains the system identifies of whether specific items
+ // have been loaded for tables/schemas. Using system identities avoid having
+ // to call equals(...) method etc. while doing lazy loading of these items.
+ // Invoking equals(...) would be prone to stack overflows ...
+ private final Set<Integer> _loadedRelations;
+ private final Set<Integer> _loadedColumns;
+ private final Set<Integer> _loadedIndexes;
+ private final Set<Integer> _loadedPrimaryKeys;
+
+ public JdbcMetadataLoader(JdbcDataContext dataContext, boolean usesCatalogsAsSchemas, String identifierQuoteString) {
+ _dataContext = dataContext;
+ _usesCatalogsAsSchemas = usesCatalogsAsSchemas;
+ _identifierQuoteString = identifierQuoteString;
+ _loadedRelations = Collections.newSetFromMap(new ConcurrentHashMap<Integer, Boolean>());
+ _loadedColumns = Collections.newSetFromMap(new ConcurrentHashMap<Integer, Boolean>());
+ _loadedIndexes = Collections.newSetFromMap(new ConcurrentHashMap<Integer, Boolean>());
+ _loadedPrimaryKeys = Collections.newSetFromMap(new ConcurrentHashMap<Integer, Boolean>());
+ }
+
+ @Override
+ public void loadTables(JdbcSchema schema) {
+ final Connection connection = _dataContext.getConnection();
+ try {
+ final DatabaseMetaData metaData = connection.getMetaData();
+
+ // Creates string array to represent the table types
+ final String[] types = JdbcUtils.getTableTypesAsStrings(_dataContext.getTableTypes());
+ loadTables(schema, metaData, types);
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "retrieve table metadata for " + schema.getName());
+ } finally {
+ _dataContext.close(connection, null, null);
+ }
+ }
+
+ private void loadTables(JdbcSchema schema, DatabaseMetaData metaData, String[] types) {
+ String catalogName = _dataContext.getCatalogName();
+
+ ResultSet rs = null;
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Querying for table types " + Arrays.toString(types) + " in catalog: " + catalogName
+ + ", schema: " + schema.getName());
+ }
+ if (_usesCatalogsAsSchemas) {
+ rs = metaData.getTables(schema.getName(), null, null, types);
+ } else {
+ rs = metaData.getTables(catalogName, schema.getName(), null, types);
+ }
+ schema.clearTables();
+ int tableNumber = -1;
+ while (rs.next()) {
+ tableNumber++;
+ String tableCatalog = rs.getString(1);
+ String tableSchema = rs.getString(2);
+ String tableName = rs.getString(3);
+ String tableTypeName = rs.getString(4);
+ TableType tableType = TableType.getTableType(tableTypeName);
+ String tableRemarks = rs.getString(5);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Found table: tableCatalog=" + tableCatalog + ",tableSchema=" + tableSchema
+ + ",tableName=" + tableName);
+ }
+
+ if (tableSchema == null) {
+ tableSchema = tableCatalog;
+ }
+
+ JdbcTable table = new JdbcTable(tableName, tableType, schema, this);
+ table.setRemarks(tableRemarks);
+ table.setQuote(_identifierQuoteString);
+ schema.addTable(table);
+ }
+
+ final int tablesReturned = tableNumber + 1;
+ if (tablesReturned == 0) {
+ logger.info("No table metadata records returned for schema '{}'", schema.getName());
+ } else {
+ logger.debug("Returned {} table metadata records for schema '{}'", new Object[] { tablesReturned,
+ schema.getName() });
+ }
+
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "retrieve table metadata for " + schema.getName());
+ } finally {
+ _dataContext.close(null, rs, null);
+ }
+ }
+
+ @Override
+ public void loadIndexes(JdbcTable table) {
+ final int identity = System.identityHashCode(table);
+ if (_loadedIndexes.contains(identity)) {
+ return;
+ }
+ synchronized (this) {
+ if (_loadedIndexes.contains(identity)) {
+ return;
+ }
+
+ final Connection connection = _dataContext.getConnection();
+ try {
+ DatabaseMetaData metaData = connection.getMetaData();
+ loadIndexes(table, metaData);
+ _loadedIndexes.add(identity);
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "load indexes");
+ } finally {
+ _dataContext.close(connection, null, null);
+ }
+ }
+ }
+
+ @Override
+ public void loadPrimaryKeys(JdbcTable table) {
+ final int identity = System.identityHashCode(table);
+ if (_loadedPrimaryKeys.contains(identity)) {
+ return;
+ }
+ synchronized (this) {
+ if (_loadedPrimaryKeys.contains(identity)) {
+ return;
+ }
+ final Connection connection = _dataContext.getConnection();
+ try {
+ DatabaseMetaData metaData = connection.getMetaData();
+ loadPrimaryKeys(table, metaData);
+ _loadedPrimaryKeys.add(identity);
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "load primary keys");
+ } finally {
+ _dataContext.close(connection, null, null);
+ }
+ }
+ }
+
+ private void loadPrimaryKeys(JdbcTable table, DatabaseMetaData metaData) throws MetaModelException {
+ Schema schema = table.getSchema();
+ ResultSet rs = null;
+
+ try {
+ if (_usesCatalogsAsSchemas) {
+ rs = metaData.getPrimaryKeys(schema.getName(), null, table.getName());
+ } else {
+ rs = metaData.getPrimaryKeys(_dataContext.getCatalogName(), schema.getName(), table.getName());
+ }
+ while (rs.next()) {
+ String columnName = rs.getString(4);
+ if (columnName != null) {
+ MutableColumn column = (MutableColumn) table.getColumnByName(columnName);
+ if (column != null) {
+ column.setPrimaryKey(true);
+ } else {
+ logger.error("Indexed column \"{}\" could not be found in table: {}", columnName, table);
+ }
+ }
+ }
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "retrieve primary keys for " + table.getName());
+ } finally {
+ _dataContext.close(null, rs, null);
+ }
+ }
+
+ private void loadIndexes(Table table, DatabaseMetaData metaData) throws MetaModelException {
+ Schema schema = table.getSchema();
+ ResultSet rs = null;
+ // Ticket #170: IndexInfo is nice-to-have, not need-to-have, so
+ // we will do a nice failover on SQLExceptions
+ try {
+ if (_usesCatalogsAsSchemas) {
+ rs = metaData.getIndexInfo(schema.getName(), null, table.getName(), false, true);
+ } else {
+ rs = metaData.getIndexInfo(_dataContext.getCatalogName(), schema.getName(), table.getName(), false,
+ true);
+ }
+ while (rs.next()) {
+ String columnName = rs.getString(9);
+ if (columnName != null) {
+ MutableColumn column = (MutableColumn) table.getColumnByName(columnName);
+ if (column != null) {
+ column.setIndexed(true);
+ } else {
+ logger.error("Indexed column \"{}\" could not be found in table: {}", columnName, table);
+ }
+ }
+ }
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "retrieve index information for " + table.getName());
+ } finally {
+ _dataContext.close(null, rs, null);
+ }
+ }
+
+ /**
+ * Loads column metadata (no indexes though) for a table
+ *
+ * @param table
+ */
+ @Override
+ public void loadColumns(JdbcTable table) {
+ final int identity = System.identityHashCode(table);
+ if (_loadedColumns.contains(identity)) {
+ return;
+ }
+ synchronized (this) {
+ if (_loadedColumns.contains(identity)) {
+ return;
+ }
+
+ final Connection connection = _dataContext.getConnection();
+ try {
+ DatabaseMetaData metaData = connection.getMetaData();
+ loadColumns(table, metaData);
+ _loadedColumns.add(identity);
+ } catch (Exception e) {
+ logger.error("Could not load columns for table: " + table, e);
+ } finally {
+ _dataContext.close(connection, null, null);
+ }
+ }
+ }
+
+ private void loadColumns(JdbcTable table, DatabaseMetaData metaData) {
+ final Schema schema = table.getSchema();
+ ResultSet rs = null;
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Querying for columns in table: " + table.getName());
+ }
+ int columnNumber = -1;
+ if (_usesCatalogsAsSchemas) {
+ rs = metaData.getColumns(schema.getName(), null, table.getName(), null);
+ } else {
+ rs = metaData.getColumns(_dataContext.getCatalogName(), schema.getName(), table.getName(), null);
+ }
+ while (rs.next()) {
+ columnNumber++;
+ final String columnName = rs.getString(4);
+ if (_identifierQuoteString == null && new StringTokenizer(columnName).countTokens() > 1) {
+ logger.warn("column name contains whitespace: \"" + columnName + "\".");
+ }
+
+ final int jdbcType = rs.getInt(5);
+ final String nativeType = rs.getString(6);
+ final Integer columnSize = rs.getInt(7);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Found column: table=" + table.getName() + ",columnName=" + columnName
+ + ",nativeType=" + nativeType + ",columnSize=" + columnSize);
+ }
+
+ final ColumnType columnType = _dataContext.getQueryRewriter().getColumnType(jdbcType, nativeType,
+ columnSize);
+
+ final int jdbcNullable = rs.getInt(11);
+ final Boolean nullable;
+ if (jdbcNullable == DatabaseMetaData.columnNullable) {
+ nullable = true;
+ } else if (jdbcNullable == DatabaseMetaData.columnNoNulls) {
+ nullable = false;
+ } else {
+ nullable = null;
+ }
+
+ final String remarks = rs.getString(12);
+
+ final JdbcColumn column = new JdbcColumn(columnName, columnType, table, columnNumber, nullable);
+ column.setRemarks(remarks);
+ column.setNativeType(nativeType);
+ column.setColumnSize(columnSize);
+ column.setQuote(_identifierQuoteString);
+ table.addColumn(column);
+ }
+
+ final int columnsReturned = columnNumber + 1;
+ if (columnsReturned == 0) {
+ logger.info("No column metadata records returned for table '{}' in schema '{}'", table.getName(),
+ schema.getName());
+ } else {
+ logger.debug("Returned {} column metadata records for table '{}' in schema '{}'", new Object[] {
+ columnsReturned, table.getName(), schema.getName() });
+ }
+
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "retrieve table metadata for " + table.getName());
+ } finally {
+ _dataContext.close(null, rs, null);
+ }
+ }
+
+ @Override
+ public void loadRelations(JdbcSchema schema) {
+ final int identity = System.identityHashCode(schema);
+ if (_loadedRelations.contains(identity)) {
+ return;
+ }
+ synchronized (this) {
+ if (_loadedRelations.contains(identity)) {
+ return;
+ }
+ final Connection connection = _dataContext.getConnection();
+ try {
+ final Table[] tables = schema.getTables();
+ final DatabaseMetaData metaData = connection.getMetaData();
+ for (Table table : tables) {
+ loadRelations(table, metaData);
+ }
+ _loadedRelations.add(identity);
+ } catch (Exception e) {
+ logger.error("Could not load relations for schema: " + schema, e);
+ } finally {
+ _dataContext.close(connection, null, null);
+ }
+ }
+ }
+
+ private void loadRelations(Table table, DatabaseMetaData metaData) {
+ Schema schema = table.getSchema();
+ ResultSet rs = null;
+ try {
+ if (_usesCatalogsAsSchemas) {
+ rs = metaData.getImportedKeys(schema.getName(), null, table.getName());
+ } else {
+ rs = metaData.getImportedKeys(_dataContext.getCatalogName(), schema.getName(), table.getName());
+ }
+ loadRelations(rs, schema);
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "retrieve imported keys for " + table.getName());
+ } finally {
+ _dataContext.close(null, rs, null);
+ }
+ }
+
+ private void loadRelations(ResultSet rs, Schema schema) throws SQLException {
+ while (rs.next()) {
+ String pkTableName = rs.getString(3);
+ String pkColumnName = rs.getString(4);
+
+ Column pkColumn = null;
+ Table pkTable = schema.getTableByName(pkTableName);
+ if (pkTable != null) {
+ pkColumn = pkTable.getColumnByName(pkColumnName);
+ }
+ if (logger.isDebugEnabled()) {
+ logger.debug("Found primary key relation: tableName=" + pkTableName + ",columnName=" + pkColumnName
+ + ", matching column: " + pkColumn);
+ }
+
+ String fkTableName = rs.getString(7);
+ String fkColumnName = rs.getString(8);
+ Column fkColumn = null;
+ Table fkTable = schema.getTableByName(fkTableName);
+ if (fkTable != null) {
+ fkColumn = fkTable.getColumnByName(fkColumnName);
+ }
+ if (logger.isDebugEnabled()) {
+ logger.debug("Found foreign key relation: tableName=" + fkTableName + ",columnName=" + fkColumnName
+ + ", matching column: " + fkColumn);
+ }
+
+ if (pkColumn == null || fkColumn == null) {
+ logger.error(
+ "Could not find relation columns: pkTableName={},pkColumnName={},fkTableName={},fkColumnName={}",
+ new Object[] { pkTableName, pkColumnName, fkTableName, fkColumnName });
+ logger.error("pkColumn={}", pkColumn);
+ logger.error("fkColumn={}", fkColumn);
+ } else {
+ MutableRelationship.createRelationship(new Column[] { pkColumn }, new Column[] { fkColumn });
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSchema.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSchema.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSchema.java
new file mode 100644
index 0000000..28285f4
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSchema.java
@@ -0,0 +1,71 @@
+/**
+ * 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.jdbc;
+
+import java.io.ObjectStreamException;
+
+import org.eobjects.metamodel.schema.MutableSchema;
+import org.eobjects.metamodel.schema.MutableTable;
+import org.eobjects.metamodel.schema.Schema;
+
+/**
+ * Schema implementation for JDBC data contexts
+ *
+ * @author Kasper Sørensen
+ */
+final class JdbcSchema extends MutableSchema {
+
+ private static final long serialVersionUID = 7543633400859277467L;
+ private transient MetadataLoader _metadataLoader;
+
+ public JdbcSchema(String name, MetadataLoader metadataLoader) {
+ super(name);
+ _metadataLoader = metadataLoader;
+ }
+
+ protected void refreshTables() {
+ if (_metadataLoader != null) {
+ _metadataLoader.loadTables(this);
+ }
+ }
+
+ public void loadRelations() {
+ if (_metadataLoader != null) {
+ _metadataLoader.loadRelations(this);
+ }
+ }
+
+ public Schema toSerializableForm() {
+ MutableTable[] tables = getTables();
+ for (MutableTable table : tables) {
+ table.getColumns();
+ table.getIndexedColumns();
+ table.getPrimaryKeys();
+ }
+ loadRelations();
+ return this;
+ }
+
+ /**
+ * Called by the Java Serialization API to serialize the object.
+ */
+ private Object writeReplace() throws ObjectStreamException {
+ return toSerializableForm();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSimpleUpdateCallback.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSimpleUpdateCallback.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSimpleUpdateCallback.java
new file mode 100644
index 0000000..2a02be8
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSimpleUpdateCallback.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.jdbc;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.util.FileHelper;
+
+/**
+ * Jdbc {@link UpdateCallback} for databases that do not support batch features.
+ * Instead we will use a single transaction for the {@link UpdateScript}.
+ *
+ * @author Kasper Sørensen
+ */
+final class JdbcSimpleUpdateCallback extends JdbcUpdateCallback {
+
+ public JdbcSimpleUpdateCallback(JdbcDataContext dataContext) {
+ super(dataContext);
+ }
+
+ @Override
+ protected void closePreparedStatement(PreparedStatement preparedStatement) {
+ FileHelper.safeClose(preparedStatement);
+ }
+
+ @Override
+ protected void executePreparedStatement(PreparedStatement st) throws SQLException {
+ st.executeUpdate();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcTable.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcTable.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcTable.java
new file mode 100644
index 0000000..4ab1419
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcTable.java
@@ -0,0 +1,84 @@
+/**
+ * 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.jdbc;
+
+import java.io.ObjectStreamException;
+import java.util.List;
+
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.MutableTable;
+import org.eobjects.metamodel.schema.Relationship;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.TableType;
+
+/**
+ * Table implementation that is based on JDBC metadata.
+ *
+ * @author Kasper Sørensen
+ */
+final class JdbcTable extends MutableTable {
+
+ private static final long serialVersionUID = 5952310469458880330L;
+
+ private final transient MetadataLoader _metadataLoader;
+
+ public JdbcTable(String name, TableType type, JdbcSchema schema, MetadataLoader metadataLoader) {
+ super(name, type, schema);
+ _metadataLoader = metadataLoader;
+ }
+
+ @Override
+ protected List<Column> getColumnsInternal() {
+ if (_metadataLoader != null) {
+ _metadataLoader.loadColumns(this);
+ }
+ return super.getColumnsInternal();
+ }
+
+ @Override
+ protected List<Relationship> getRelationshipsInternal() {
+ Schema schema = getSchema();
+ if (schema instanceof JdbcSchema) {
+ ((JdbcSchema) schema).loadRelations();
+ }
+ return super.getRelationshipsInternal();
+ }
+
+ protected void loadIndexes() {
+ if (_metadataLoader != null) {
+ _metadataLoader.loadIndexes(this);
+ }
+ }
+
+ /**
+ * Called by the Java Serialization API to serialize the object.
+ */
+ private Object writeReplace() throws ObjectStreamException {
+ getColumns();
+ loadIndexes();
+ loadPrimaryKeys();
+ return this;
+ }
+
+ public void loadPrimaryKeys() {
+ if (_metadataLoader != null) {
+ _metadataLoader.loadPrimaryKeys(this);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUpdateBuilder.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUpdateBuilder.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUpdateBuilder.java
new file mode 100644
index 0000000..5860ec5
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUpdateBuilder.java
@@ -0,0 +1,153 @@
+/**
+ * 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.jdbc;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.List;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.update.AbstractRowUpdationBuilder;
+import org.eobjects.metamodel.update.RowUpdationBuilder;
+import org.eobjects.metamodel.util.FileHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * {@link RowUpdationBuilder} that issues an SQL UPDATE statement
+ *
+ * @author Kasper Sørensen
+ */
+final class JdbcUpdateBuilder extends AbstractRowUpdationBuilder {
+
+ private static final Logger logger = LoggerFactory.getLogger(JdbcUpdateBuilder.class);
+
+ private final boolean _inlineValues;
+ private final JdbcUpdateCallback _updateCallback;
+ private final IQueryRewriter _queryRewriter;
+
+ public JdbcUpdateBuilder(JdbcUpdateCallback updateCallback, Table table, IQueryRewriter queryRewriter) {
+ this(updateCallback, table, queryRewriter, false);
+ }
+
+ public JdbcUpdateBuilder(JdbcUpdateCallback updateCallback, Table table, IQueryRewriter queryRewriter,
+ boolean inlineValues) {
+ super(table);
+ _updateCallback = updateCallback;
+ _queryRewriter = queryRewriter;
+ _inlineValues = inlineValues;
+ }
+
+ @Override
+ public void execute() throws MetaModelException {
+ String sql = createSqlStatement();
+ logger.debug("Update statement created: {}", sql);
+ final boolean reuseStatement = !_inlineValues;
+ final PreparedStatement st = _updateCallback.getPreparedStatement(sql, reuseStatement);
+ try {
+ if (reuseStatement) {
+ Column[] columns = getColumns();
+ Object[] values = getValues();
+ boolean[] explicitNulls = getExplicitNulls();
+ int valueCounter = 1;
+ for (int i = 0; i < columns.length; i++) {
+ boolean explicitNull = explicitNulls[i];
+ if (values[i] != null || explicitNull) {
+ JdbcUtils.setStatementValue(st, valueCounter, columns[i], values[i]);
+
+ valueCounter++;
+ }
+ }
+
+ List<FilterItem> whereItems = getWhereItems();
+ for (FilterItem whereItem : whereItems) {
+ if (JdbcUtils.isPreparedParameterCandidate(whereItem)) {
+ final Object operand = whereItem.getOperand();
+ final Column column = whereItem.getSelectItem().getColumn();
+
+ JdbcUtils.setStatementValue(st, valueCounter, column, operand);
+
+ valueCounter++;
+ }
+ }
+ }
+ _updateCallback.executePreparedStatement(st, reuseStatement);
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "execute update statement: " + sql);
+ } finally {
+ if (_inlineValues) {
+ FileHelper.safeClose(st);
+ }
+ }
+ }
+
+ protected String createSqlStatement() {
+ return createSqlStatement(_inlineValues);
+ }
+
+ private String createSqlStatement(boolean inlineValues) {
+ final Object[] values = getValues();
+ final Table table = getTable();
+ final StringBuilder sb = new StringBuilder();
+
+ final String tableLabel = _queryRewriter.rewriteFromItem(new FromItem(table));
+
+ sb.append("UPDATE ");
+ sb.append(tableLabel);
+ sb.append(" SET ");
+
+ Column[] columns = getColumns();
+ boolean[] explicitNulls = getExplicitNulls();
+ boolean firstValue = true;
+ for (int i = 0; i < columns.length; i++) {
+ if (values[i] != null || explicitNulls[i]) {
+ if (firstValue) {
+ firstValue = false;
+ } else {
+ sb.append(',');
+ }
+ String columnName = columns[i].getName();
+ columnName = _updateCallback.quoteIfNescesary(columnName);
+ sb.append(columnName);
+
+ sb.append('=');
+
+ if (inlineValues) {
+ sb.append(JdbcUtils.getValueAsSql(columns[i], values[i], _queryRewriter));
+ } else {
+ sb.append('?');
+ }
+ }
+ }
+
+ sb.append(JdbcUtils.createWhereClause(getWhereItems(), _queryRewriter, inlineValues));
+ String sql = sb.toString();
+ return sql;
+ }
+
+ @Override
+ public String toSql() {
+ return createSqlStatement(true);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUpdateCallback.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUpdateCallback.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUpdateCallback.java
new file mode 100644
index 0000000..c0861fb
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUpdateCallback.java
@@ -0,0 +1,216 @@
+/**
+ * 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.jdbc;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import org.eobjects.metamodel.AbstractUpdateCallback;
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.create.TableCreationBuilder;
+import org.eobjects.metamodel.delete.RowDeletionBuilder;
+import org.eobjects.metamodel.drop.TableDropBuilder;
+import org.eobjects.metamodel.insert.RowInsertionBuilder;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.update.RowUpdationBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+abstract class JdbcUpdateCallback extends AbstractUpdateCallback implements UpdateCallback {
+
+ private static final Logger logger = LoggerFactory.getLogger(JdbcUpdateCallback.class);
+
+ private final JdbcDataContext _dataContext;
+ private Connection _connection;
+ private String _preparedStatementSql;
+ private PreparedStatement _preparedStatement;
+
+ public JdbcUpdateCallback(JdbcDataContext dataContext) {
+ super(dataContext);
+ _dataContext = dataContext;
+ }
+
+ protected abstract void closePreparedStatement(PreparedStatement preparedStatement);
+
+ protected abstract void executePreparedStatement(PreparedStatement preparedStatement) throws SQLException;
+
+ public void executePreparedStatement(PreparedStatement preparedStatement, boolean reusedStatement)
+ throws SQLException {
+ executePreparedStatement(preparedStatement);
+ if (!reusedStatement) {
+ closePreparedStatement(preparedStatement);
+ }
+ }
+
+ protected final Connection getConnection() {
+ if (_connection == null) {
+ _connection = getDataContext().getConnection();
+ try {
+ _connection.setAutoCommit(false);
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "disable auto-commit");
+ }
+ }
+ return _connection;
+ }
+
+ public final void close(boolean success) {
+ if (_connection != null) {
+ if (success && _preparedStatement != null) {
+ closePreparedStatement(_preparedStatement);
+ }
+
+ try {
+ commitOrRollback(success);
+
+ if (_dataContext.isDefaultAutoCommit()) {
+ try {
+ getConnection().setAutoCommit(true);
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "enable auto-commit");
+ }
+ }
+ } finally {
+ getDataContext().close(_connection, null, null);
+ }
+ }
+ }
+
+ private void commitOrRollback(boolean success) {
+ if (success) {
+ try {
+ getConnection().commit();
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "commit transaction");
+ }
+ } else {
+ try {
+ getConnection().rollback();
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "rollback transaction");
+ }
+ }
+ }
+
+ @Override
+ public final TableCreationBuilder createTable(Schema schema, String name) throws IllegalArgumentException,
+ IllegalStateException {
+ return new JdbcCreateTableBuilder(this, schema, name);
+ }
+
+ @Override
+ public final RowInsertionBuilder insertInto(Table table) throws IllegalArgumentException, IllegalStateException {
+ return new JdbcInsertBuilder(this, table, _dataContext.getQueryRewriter());
+ }
+
+ @Override
+ public final JdbcDataContext getDataContext() {
+ return _dataContext;
+ }
+
+ protected String quoteIfNescesary(String identifier) {
+ if (identifier == null) {
+ return null;
+ }
+ final String quote = _dataContext.getIdentifierQuoteString();
+ if (quote == null) {
+ return identifier;
+ }
+ boolean quotes = false;
+ if (identifier.indexOf(' ') != -1 || identifier.indexOf('-') != -1) {
+ quotes = true;
+ } else {
+ if (SqlKeywords.isKeyword(identifier)) {
+ quotes = true;
+ }
+ }
+
+ if (quotes) {
+ identifier = quote + identifier + quote;
+ }
+ return identifier;
+ }
+
+ public final PreparedStatement getPreparedStatement(String sql, boolean reuseStatement) {
+ final PreparedStatement preparedStatement;
+ if (reuseStatement) {
+ if (sql.equals(_preparedStatementSql)) {
+ preparedStatement = _preparedStatement;
+ } else {
+ if (_preparedStatement != null) {
+ try {
+ closePreparedStatement(_preparedStatement);
+ } catch (RuntimeException e) {
+ logger.error("Exception occurred while closing prepared statement: " + _preparedStatementSql);
+ throw e;
+ }
+ }
+ preparedStatement = createPreparedStatement(sql);
+ _preparedStatement = preparedStatement;
+ _preparedStatementSql = sql;
+ }
+ } else {
+ preparedStatement = createPreparedStatement(sql);
+ }
+ return preparedStatement;
+ }
+
+ private final PreparedStatement createPreparedStatement(String sql) {
+ try {
+ return getConnection().prepareStatement(sql);
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "create prepared statement for: " + sql);
+ }
+ }
+
+ @Override
+ public boolean isDeleteSupported() {
+ return true;
+ }
+
+ @Override
+ public RowDeletionBuilder deleteFrom(Table table) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException {
+ return new JdbcDeleteBuilder(this, table, _dataContext.getQueryRewriter());
+ }
+
+ @Override
+ public boolean isDropTableSupported() {
+ return true;
+ }
+
+ @Override
+ public TableDropBuilder dropTable(Table table) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException {
+ return new JdbcDropTableBuilder(this, table, _dataContext.getQueryRewriter());
+ }
+
+ @Override
+ public boolean isUpdateSupported() {
+ return true;
+ }
+
+ @Override
+ public RowUpdationBuilder update(Table table) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException {
+ return new JdbcUpdateBuilder(this, table, _dataContext.getQueryRewriter());
+ }
+}
[53/61] Renamed all import and package statements from 'org.eobjects'
to 'org.apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/integrationtests/org/apache/metamodel/MysqlTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/apache/metamodel/MysqlTest.java b/jdbc/src/test/integrationtests/org/apache/metamodel/MysqlTest.java
index 4bd814d..95d97e5 100644
--- a/jdbc/src/test/integrationtests/org/apache/metamodel/MysqlTest.java
+++ b/jdbc/src/test/integrationtests/org/apache/metamodel/MysqlTest.java
@@ -1,4 +1,4 @@
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
@@ -12,21 +12,21 @@ import javax.swing.table.TableModel;
import junit.framework.TestCase;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetTableModel;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.jdbc.JdbcTestTemplates;
-import org.eobjects.metamodel.jdbc.QuerySplitter;
-import org.eobjects.metamodel.jdbc.dialects.MysqlQueryRewriter;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.schema.TableType;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSetTableModel;
+import org.apache.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.jdbc.JdbcTestTemplates;
+import org.apache.metamodel.jdbc.QuerySplitter;
+import org.apache.metamodel.jdbc.dialects.MysqlQueryRewriter;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.schema.TableType;
/**
* Test case that tests mysql interaction. The test requires the "sakila" sample
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/integrationtests/org/apache/metamodel/OracleTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/apache/metamodel/OracleTest.java b/jdbc/src/test/integrationtests/org/apache/metamodel/OracleTest.java
index 4717873..68efee2 100644
--- a/jdbc/src/test/integrationtests/org/apache/metamodel/OracleTest.java
+++ b/jdbc/src/test/integrationtests/org/apache/metamodel/OracleTest.java
@@ -1,4 +1,4 @@
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -9,16 +9,16 @@ import javax.swing.table.TableModel;
import junit.framework.TestCase;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetTableModel;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.JoinType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.schema.TableType;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSetTableModel;
+import org.apache.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.JoinType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Relationship;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.schema.TableType;
/**
* Test case that tests oracle interaction. An express edition of the oracle
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/integrationtests/org/apache/metamodel/PostgresqlTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/apache/metamodel/PostgresqlTest.java b/jdbc/src/test/integrationtests/org/apache/metamodel/PostgresqlTest.java
index 9c8cf34..54b9e6c 100644
--- a/jdbc/src/test/integrationtests/org/apache/metamodel/PostgresqlTest.java
+++ b/jdbc/src/test/integrationtests/org/apache/metamodel/PostgresqlTest.java
@@ -1,4 +1,4 @@
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.lang.reflect.Method;
import java.sql.Connection;
@@ -11,23 +11,23 @@ import javax.swing.table.TableModel;
import junit.framework.TestCase;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetTableModel;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.jdbc.JdbcTestTemplates;
-import org.eobjects.metamodel.jdbc.QuerySplitter;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.OrderByItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSetTableModel;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.jdbc.JdbcTestTemplates;
+import org.apache.metamodel.jdbc.QuerySplitter;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.OrderByItem;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Relationship;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
import org.junit.Ignore;
/**
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/integrationtests/org/apache/metamodel/SQLServerJtdsDriverTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/apache/metamodel/SQLServerJtdsDriverTest.java b/jdbc/src/test/integrationtests/org/apache/metamodel/SQLServerJtdsDriverTest.java
index a488549..b0df4bf 100644
--- a/jdbc/src/test/integrationtests/org/apache/metamodel/SQLServerJtdsDriverTest.java
+++ b/jdbc/src/test/integrationtests/org/apache/metamodel/SQLServerJtdsDriverTest.java
@@ -1,4 +1,4 @@
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -7,17 +7,17 @@ import java.util.Arrays;
import junit.framework.TestCase;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.jdbc.JdbcTestTemplates;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.SQLServerQueryRewriter;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.schema.TableType;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.jdbc.JdbcTestTemplates;
+import org.apache.metamodel.jdbc.dialects.IQueryRewriter;
+import org.apache.metamodel.jdbc.dialects.SQLServerQueryRewriter;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.schema.TableType;
/**
* Test case that tests MS SQL Server interaction. The test uses the
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/integrationtests/org/apache/metamodel/SQLServerMicrosoftDriverTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/apache/metamodel/SQLServerMicrosoftDriverTest.java b/jdbc/src/test/integrationtests/org/apache/metamodel/SQLServerMicrosoftDriverTest.java
index ee0a664..83ceeba 100644
--- a/jdbc/src/test/integrationtests/org/apache/metamodel/SQLServerMicrosoftDriverTest.java
+++ b/jdbc/src/test/integrationtests/org/apache/metamodel/SQLServerMicrosoftDriverTest.java
@@ -1,4 +1,4 @@
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -6,15 +6,15 @@ import java.util.Arrays;
import junit.framework.TestCase;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.SQLServerQueryRewriter;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.schema.TableType;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.jdbc.dialects.IQueryRewriter;
+import org.apache.metamodel.jdbc.dialects.SQLServerQueryRewriter;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.schema.TableType;
/**
* Test case that tests MS SQL Server interaction. The test uses the
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/dbmains/PostgresqlMain.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/dbmains/PostgresqlMain.java b/jdbc/src/test/java/org/apache/metamodel/dbmains/PostgresqlMain.java
index cc01766..e7d48e8 100644
--- a/jdbc/src/test/java/org/apache/metamodel/dbmains/PostgresqlMain.java
+++ b/jdbc/src/test/java/org/apache/metamodel/dbmains/PostgresqlMain.java
@@ -16,21 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.dbmains;
+package org.apache.metamodel.dbmains;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public class PostgresqlMain {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/dialects/AbstractQueryRewriterTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/dialects/AbstractQueryRewriterTest.java b/jdbc/src/test/java/org/apache/metamodel/dialects/AbstractQueryRewriterTest.java
index f880401..216ccb5 100644
--- a/jdbc/src/test/java/org/apache/metamodel/dialects/AbstractQueryRewriterTest.java
+++ b/jdbc/src/test/java/org/apache/metamodel/dialects/AbstractQueryRewriterTest.java
@@ -16,19 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.dialects;
+package org.apache.metamodel.dialects;
import junit.framework.TestCase;
-import org.eobjects.metamodel.jdbc.dialects.AbstractQueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.DefaultQueryRewriter;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableTable;
+import org.apache.metamodel.jdbc.dialects.AbstractQueryRewriter;
+import org.apache.metamodel.jdbc.dialects.DefaultQueryRewriter;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableTable;
public class AbstractQueryRewriterTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/dialects/DB2QueryRewriterTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/dialects/DB2QueryRewriterTest.java b/jdbc/src/test/java/org/apache/metamodel/dialects/DB2QueryRewriterTest.java
index c511b7c..b71e98a 100644
--- a/jdbc/src/test/java/org/apache/metamodel/dialects/DB2QueryRewriterTest.java
+++ b/jdbc/src/test/java/org/apache/metamodel/dialects/DB2QueryRewriterTest.java
@@ -16,21 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.dialects;
+package org.apache.metamodel.dialects;
import java.util.Arrays;
import junit.framework.TestCase;
-import org.eobjects.metamodel.jdbc.dialects.DB2QueryRewriter;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.TableType;
+import org.apache.metamodel.jdbc.dialects.DB2QueryRewriter;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.TableType;
public class DB2QueryRewriterTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/dialects/MysqlQueryRewriterTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/dialects/MysqlQueryRewriterTest.java b/jdbc/src/test/java/org/apache/metamodel/dialects/MysqlQueryRewriterTest.java
index c643337..f9aec48 100644
--- a/jdbc/src/test/java/org/apache/metamodel/dialects/MysqlQueryRewriterTest.java
+++ b/jdbc/src/test/java/org/apache/metamodel/dialects/MysqlQueryRewriterTest.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.dialects;
+package org.apache.metamodel.dialects;
import junit.framework.TestCase;
-import org.eobjects.metamodel.jdbc.dialects.MysqlQueryRewriter;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableTable;
+import org.apache.metamodel.jdbc.dialects.MysqlQueryRewriter;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableTable;
public class MysqlQueryRewriterTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/dialects/PostgresqlQueryRewriterTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/dialects/PostgresqlQueryRewriterTest.java b/jdbc/src/test/java/org/apache/metamodel/dialects/PostgresqlQueryRewriterTest.java
index 1bc8c58..6582d8e 100644
--- a/jdbc/src/test/java/org/apache/metamodel/dialects/PostgresqlQueryRewriterTest.java
+++ b/jdbc/src/test/java/org/apache/metamodel/dialects/PostgresqlQueryRewriterTest.java
@@ -16,19 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.dialects;
+package org.apache.metamodel.dialects;
import java.sql.Types;
import junit.framework.TestCase;
-import org.eobjects.metamodel.jdbc.dialects.PostgresqlQueryRewriter;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
+import org.apache.metamodel.jdbc.dialects.PostgresqlQueryRewriter;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
public class PostgresqlQueryRewriterTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/dialects/SQLServerQueryRewriterTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/dialects/SQLServerQueryRewriterTest.java b/jdbc/src/test/java/org/apache/metamodel/dialects/SQLServerQueryRewriterTest.java
index f91b276..b3ffac3 100644
--- a/jdbc/src/test/java/org/apache/metamodel/dialects/SQLServerQueryRewriterTest.java
+++ b/jdbc/src/test/java/org/apache/metamodel/dialects/SQLServerQueryRewriterTest.java
@@ -16,17 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.dialects;
+package org.apache.metamodel.dialects;
import junit.framework.TestCase;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.SQLServerQueryRewriter;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
+import org.apache.metamodel.jdbc.dialects.IQueryRewriter;
+import org.apache.metamodel.jdbc.dialects.SQLServerQueryRewriter;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
public class SQLServerQueryRewriterTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/jdbc/CloseableConnectionWrapper.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/jdbc/CloseableConnectionWrapper.java b/jdbc/src/test/java/org/apache/metamodel/jdbc/CloseableConnectionWrapper.java
index a497590..ce2d795 100644
--- a/jdbc/src/test/java/org/apache/metamodel/jdbc/CloseableConnectionWrapper.java
+++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/CloseableConnectionWrapper.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.Array;
import java.sql.Blob;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/jdbc/DerbyTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/jdbc/DerbyTest.java b/jdbc/src/test/java/org/apache/metamodel/jdbc/DerbyTest.java
index dd265d9..3feb3f6 100644
--- a/jdbc/src/test/java/org/apache/metamodel/jdbc/DerbyTest.java
+++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/DerbyTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.io.File;
import java.sql.Connection;
@@ -26,19 +26,19 @@ import java.util.Arrays;
import junit.framework.TestCase;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.jdbc.dialects.DefaultQueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.schema.TableType;
-import org.eobjects.metamodel.util.FileHelper;
-import org.eobjects.metamodel.util.MutableRef;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.jdbc.dialects.DefaultQueryRewriter;
+import org.apache.metamodel.jdbc.dialects.IQueryRewriter;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.schema.TableType;
+import org.apache.metamodel.util.FileHelper;
+import org.apache.metamodel.util.MutableRef;
/**
* Test case that tests Derby interaction. The test uses an embedded copy of the
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/jdbc/FetchSizeCalculatorTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/jdbc/FetchSizeCalculatorTest.java b/jdbc/src/test/java/org/apache/metamodel/jdbc/FetchSizeCalculatorTest.java
index 1fcd6c8..01d80e1 100644
--- a/jdbc/src/test/java/org/apache/metamodel/jdbc/FetchSizeCalculatorTest.java
+++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/FetchSizeCalculatorTest.java
@@ -16,16 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import junit.framework.TestCase;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-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.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableTable;
public class FetchSizeCalculatorTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/jdbc/FilteredDataSetTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/jdbc/FilteredDataSetTest.java b/jdbc/src/test/java/org/apache/metamodel/jdbc/FilteredDataSetTest.java
index 3f47ca3..a7208b5 100644
--- a/jdbc/src/test/java/org/apache/metamodel/jdbc/FilteredDataSetTest.java
+++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/FilteredDataSetTest.java
@@ -16,17 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.Connection;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.FilteredDataSet;
-import org.eobjects.metamodel.data.IRowFilter;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.FilteredDataSet;
+import org.apache.metamodel.data.IRowFilter;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Table;
public class FilteredDataSetTest extends JdbcTestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/jdbc/H2databaseTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/jdbc/H2databaseTest.java b/jdbc/src/test/java/org/apache/metamodel/jdbc/H2databaseTest.java
index 8475ecb..7fd0102 100644
--- a/jdbc/src/test/java/org/apache/metamodel/jdbc/H2databaseTest.java
+++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/H2databaseTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -27,25 +27,25 @@ import java.util.List;
import junit.framework.TestCase;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.create.CreateTable;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.delete.DeleteFrom;
-import org.eobjects.metamodel.drop.DropTable;
-import org.eobjects.metamodel.insert.InsertInto;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.Update;
-import org.eobjects.metamodel.util.MutableRef;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.create.CreateTable;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.delete.DeleteFrom;
+import org.apache.metamodel.drop.DropTable;
+import org.apache.metamodel.insert.InsertInto;
+import org.apache.metamodel.jdbc.dialects.IQueryRewriter;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.update.Update;
+import org.apache.metamodel.util.MutableRef;
/**
* Test case that tests interaction with the H2 embedded database
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/jdbc/HsqldbTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/jdbc/HsqldbTest.java b/jdbc/src/test/java/org/apache/metamodel/jdbc/HsqldbTest.java
index c3f4d5b..f225526 100644
--- a/jdbc/src/test/java/org/apache/metamodel/jdbc/HsqldbTest.java
+++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/HsqldbTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -28,23 +28,23 @@ import javax.swing.table.TableModel;
import junit.framework.TestCase;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetTableModel;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.jdbc.dialects.HsqldbQueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.JoinType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelHelper;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSetTableModel;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.jdbc.dialects.HsqldbQueryRewriter;
+import org.apache.metamodel.jdbc.dialects.IQueryRewriter;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.JoinType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
/**
* Test case that tests hsqldb interaction. The test uses an embedded copy of
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcColumnTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcColumnTest.java b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcColumnTest.java
index 9e7e002..b2c33b1 100644
--- a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcColumnTest.java
+++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcColumnTest.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.Connection;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
public class JdbcColumnTest extends JdbcTestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcDataContextTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcDataContextTest.java b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcDataContextTest.java
index 3551636..7a079cd 100644
--- a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcDataContextTest.java
+++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcDataContextTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.Connection;
import java.sql.ResultSet;
@@ -28,26 +28,26 @@ import javax.sql.DataSource;
import javax.swing.table.TableModel;
import org.easymock.EasyMock;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetTableModel;
-import org.eobjects.metamodel.jdbc.dialects.DefaultQueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.OrderByItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.QueryParameter;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.schema.TableType;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.QueryPostprocessDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSetTableModel;
+import org.apache.metamodel.jdbc.dialects.DefaultQueryRewriter;
+import org.apache.metamodel.jdbc.dialects.IQueryRewriter;
+import org.apache.metamodel.query.CompiledQuery;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.OrderByItem;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.QueryParameter;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Relationship;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.schema.TableType;
public class JdbcDataContextTest extends JdbcTestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcDeleteBuilderTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcDeleteBuilderTest.java b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcDeleteBuilderTest.java
index 4c5f436..a530967 100644
--- a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcDeleteBuilderTest.java
+++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcDeleteBuilderTest.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.util.Arrays;
-import org.eobjects.metamodel.jdbc.dialects.DefaultQueryRewriter;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.jdbc.dialects.DefaultQueryRewriter;
+import org.apache.metamodel.schema.Table;
public class JdbcDeleteBuilderTest extends JdbcTestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcInsertBuilderTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcInsertBuilderTest.java b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcInsertBuilderTest.java
index 5bcfeff..8b56e05 100644
--- a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcInsertBuilderTest.java
+++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcInsertBuilderTest.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.util.Arrays;
-import org.eobjects.metamodel.jdbc.dialects.DefaultQueryRewriter;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.jdbc.dialects.DefaultQueryRewriter;
+import org.apache.metamodel.schema.Table;
public class JdbcInsertBuilderTest extends JdbcTestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcSchemaTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcSchemaTest.java b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcSchemaTest.java
index 7d0f5ae..020b37d 100644
--- a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcSchemaTest.java
+++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcSchemaTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.io.File;
import java.io.FileInputStream;
@@ -26,9 +26,9 @@ import java.io.ObjectOutputStream;
import java.sql.Connection;
import java.util.Arrays;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public class JdbcSchemaTest extends JdbcTestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcTestCase.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcTestCase.java b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcTestCase.java
index 3e13a49..88cf13c 100644
--- a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcTestCase.java
+++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcTestCase.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcTestTemplates.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcTestTemplates.java b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcTestTemplates.java
index ff272f8..8fc878c 100644
--- a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcTestTemplates.java
+++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcTestTemplates.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -34,19 +34,19 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
-import org.eobjects.metamodel.BatchUpdateScript;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.create.ColumnCreationBuilder;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.drop.DropTable;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.DateUtils;
-import org.eobjects.metamodel.util.Month;
+import org.apache.metamodel.BatchUpdateScript;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.create.ColumnCreationBuilder;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.drop.DropTable;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.DateUtils;
+import org.apache.metamodel.util.Month;
import org.junit.Ignore;
/**
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcUpdateBuilderTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcUpdateBuilderTest.java b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcUpdateBuilderTest.java
index 815b3db..08a8229 100644
--- a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcUpdateBuilderTest.java
+++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcUpdateBuilderTest.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.util.Arrays;
-import org.eobjects.metamodel.jdbc.dialects.DefaultQueryRewriter;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.jdbc.dialects.DefaultQueryRewriter;
+import org.apache.metamodel.schema.Table;
public class JdbcUpdateBuilderTest extends JdbcTestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcUtilsTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcUtilsTest.java b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcUtilsTest.java
index e912b44..808d5de 100644
--- a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcUtilsTest.java
+++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcUtilsTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.io.File;
import java.io.FileInputStream;
@@ -25,7 +25,7 @@ import java.util.logging.LogManager;
import junit.framework.TestCase;
-import org.eobjects.metamodel.MetaModelException;
+import org.apache.metamodel.MetaModelException;
public class JdbcUtilsTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/jdbc/QuerySplitterTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/jdbc/QuerySplitterTest.java b/jdbc/src/test/java/org/apache/metamodel/jdbc/QuerySplitterTest.java
index 072edde..8e4842c 100644
--- a/jdbc/src/test/java/org/apache/metamodel/jdbc/QuerySplitterTest.java
+++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/QuerySplitterTest.java
@@ -16,22 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.sql.Connection;
import java.util.Arrays;
import java.util.List;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.JoinType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.query.JoinType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Relationship;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public class QuerySplitterTest extends JdbcTestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/jdbc/src/test/java/org/apache/metamodel/jdbc/SqliteTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/jdbc/SqliteTest.java b/jdbc/src/test/java/org/apache/metamodel/jdbc/SqliteTest.java
index 69a1127..fad6efe 100644
--- a/jdbc/src/test/java/org/apache/metamodel/jdbc/SqliteTest.java
+++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/SqliteTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.jdbc;
+package org.apache.metamodel.jdbc;
import java.io.File;
import java.sql.Connection;
@@ -27,19 +27,19 @@ import java.util.List;
import junit.framework.TestCase;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.DateUtils;
-import org.eobjects.metamodel.util.FileHelper;
-import org.eobjects.metamodel.util.Month;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.DateUtils;
+import org.apache.metamodel.util.FileHelper;
+import org.apache.metamodel.util.Month;
/**
* Test case that tests SQLite interaction. The test uses an example database
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/mongodb/src/main/java/org/apache/metamodel/mongodb/DefaultWriteConcernAdvisor.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/metamodel/mongodb/DefaultWriteConcernAdvisor.java b/mongodb/src/main/java/org/apache/metamodel/mongodb/DefaultWriteConcernAdvisor.java
index 508b1e1..6ea1903 100644
--- a/mongodb/src/main/java/org/apache/metamodel/mongodb/DefaultWriteConcernAdvisor.java
+++ b/mongodb/src/main/java/org/apache/metamodel/mongodb/DefaultWriteConcernAdvisor.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.mongodb;
+package org.apache.metamodel.mongodb;
import com.mongodb.WriteConcern;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDataContext.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDataContext.java b/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDataContext.java
index 2e97a8a..83f866a 100644
--- a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDataContext.java
+++ b/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDataContext.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.mongodb;
+package org.apache.metamodel.mongodb;
import java.util.HashSet;
import java.util.List;
@@ -26,23 +26,23 @@ import java.util.SortedMap;
import java.util.TreeMap;
import org.bson.types.ObjectId;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.SimpleTableDef;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.QueryPostprocessDataContext;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.UpdateableDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.SimpleTableDef;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDataSet.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDataSet.java b/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDataSet.java
index 217fb2f..39fdb35 100644
--- a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDataSet.java
+++ b/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDataSet.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.mongodb;
+package org.apache.metamodel.mongodb;
import java.util.List;
-import org.eobjects.metamodel.data.AbstractDataSet;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.data.AbstractDataSet;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDeleteBuilder.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDeleteBuilder.java b/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDeleteBuilder.java
index c3bdba9..f1b8591 100644
--- a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDeleteBuilder.java
+++ b/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDeleteBuilder.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.mongodb;
+package org.apache.metamodel.mongodb;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.delete.AbstractRowDeletionBuilder;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.delete.AbstractRowDeletionBuilder;
+import org.apache.metamodel.schema.Table;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDropTableBuilder.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDropTableBuilder.java b/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDropTableBuilder.java
index 98e7c41..4164346 100644
--- a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDropTableBuilder.java
+++ b/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDropTableBuilder.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.mongodb;
+package org.apache.metamodel.mongodb;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.drop.AbstractTableDropBuilder;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.drop.AbstractTableDropBuilder;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.Table;
final class MongoDbDropTableBuilder extends AbstractTableDropBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbInsertionBuilder.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbInsertionBuilder.java b/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbInsertionBuilder.java
index 8c10c17..412612c 100644
--- a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbInsertionBuilder.java
+++ b/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbInsertionBuilder.java
@@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.mongodb;
+package org.apache.metamodel.mongodb;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.insert.AbstractRowInsertionBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.insert.AbstractRowInsertionBuilder;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbTableCreationBuilder.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbTableCreationBuilder.java b/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbTableCreationBuilder.java
index ecb7ea0..a57590d 100644
--- a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbTableCreationBuilder.java
+++ b/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbTableCreationBuilder.java
@@ -16,16 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.mongodb;
+package org.apache.metamodel.mongodb;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.create.AbstractTableCreationBuilder;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.ImmutableColumn;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.create.AbstractTableCreationBuilder;
+import org.apache.metamodel.create.TableCreationBuilder;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.ImmutableColumn;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
final class MongoDbTableCreationBuilder extends
AbstractTableCreationBuilder<MongoDbUpdateCallback> implements
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbTableDef.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbTableDef.java b/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbTableDef.java
index f227f91..dfa9d87 100644
--- a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbTableDef.java
+++ b/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbTableDef.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.mongodb;
+package org.apache.metamodel.mongodb;
import java.io.Serializable;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.util.SimpleTableDef;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.util.SimpleTableDef;
/**
* Defines a table layout for {@link MongoDbDataContext} tables. This class can
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbUpdateCallback.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbUpdateCallback.java b/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbUpdateCallback.java
index 1a5eb0d..16d74a4 100644
--- a/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbUpdateCallback.java
+++ b/mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbUpdateCallback.java
@@ -16,20 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.mongodb;
+package org.apache.metamodel.mongodb;
import java.io.Closeable;
import java.util.HashMap;
import java.util.Map;
-import org.eobjects.metamodel.AbstractUpdateCallback;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.AbstractUpdateCallback;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.create.TableCreationBuilder;
+import org.apache.metamodel.delete.RowDeletionBuilder;
+import org.apache.metamodel.drop.TableDropBuilder;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
import com.mongodb.DBCollection;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/mongodb/src/main/java/org/apache/metamodel/mongodb/SimpleWriteConcernAdvisor.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/metamodel/mongodb/SimpleWriteConcernAdvisor.java b/mongodb/src/main/java/org/apache/metamodel/mongodb/SimpleWriteConcernAdvisor.java
index 4bce1fe..2d6f76a 100644
--- a/mongodb/src/main/java/org/apache/metamodel/mongodb/SimpleWriteConcernAdvisor.java
+++ b/mongodb/src/main/java/org/apache/metamodel/mongodb/SimpleWriteConcernAdvisor.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.mongodb;
+package org.apache.metamodel.mongodb;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/mongodb/src/main/java/org/apache/metamodel/mongodb/WriteConcernAdvisor.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/metamodel/mongodb/WriteConcernAdvisor.java b/mongodb/src/main/java/org/apache/metamodel/mongodb/WriteConcernAdvisor.java
index d230371..006234b 100644
--- a/mongodb/src/main/java/org/apache/metamodel/mongodb/WriteConcernAdvisor.java
+++ b/mongodb/src/main/java/org/apache/metamodel/mongodb/WriteConcernAdvisor.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.mongodb;
+package org.apache.metamodel.mongodb;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/mongodb/src/main/java/org/apache/metamodel/mongodb/package-info.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/metamodel/mongodb/package-info.java b/mongodb/src/main/java/org/apache/metamodel/mongodb/package-info.java
index abf821b..99bf0fc 100644
--- a/mongodb/src/main/java/org/apache/metamodel/mongodb/package-info.java
+++ b/mongodb/src/main/java/org/apache/metamodel/mongodb/package-info.java
@@ -19,5 +19,5 @@
/**
* Module package for MongoDB support
*/
-package org.eobjects.metamodel.mongodb;
+package org.apache.metamodel.mongodb;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/mongodb/src/test/java/org/apache/metamodel/mongodb/MongoDbDataContextTest.java
----------------------------------------------------------------------
diff --git a/mongodb/src/test/java/org/apache/metamodel/mongodb/MongoDbDataContextTest.java b/mongodb/src/test/java/org/apache/metamodel/mongodb/MongoDbDataContextTest.java
index 053a419..a71b08c 100644
--- a/mongodb/src/test/java/org/apache/metamodel/mongodb/MongoDbDataContextTest.java
+++ b/mongodb/src/test/java/org/apache/metamodel/mongodb/MongoDbDataContextTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.mongodb;
+package org.apache.metamodel.mongodb;
import java.util.Arrays;
import java.util.HashMap;
@@ -26,16 +26,16 @@ import java.util.Map;
import junit.framework.TestCase;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.InMemoryDataSet;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/mongodb/src/test/java/org/apache/metamodel/mongodb/MongoDbDataCopyer.java
----------------------------------------------------------------------
diff --git a/mongodb/src/test/java/org/apache/metamodel/mongodb/MongoDbDataCopyer.java b/mongodb/src/test/java/org/apache/metamodel/mongodb/MongoDbDataCopyer.java
index d12d1e3..43eed55 100644
--- a/mongodb/src/test/java/org/apache/metamodel/mongodb/MongoDbDataCopyer.java
+++ b/mongodb/src/test/java/org/apache/metamodel/mongodb/MongoDbDataCopyer.java
@@ -16,23 +16,23 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.mongodb;
+package org.apache.metamodel.mongodb;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.FileHelper;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.FileHelper;
import com.mongodb.DB;
import com.mongodb.Mongo;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/openoffice/src/main/java/org/apache/metamodel/openoffice/OpenOfficeDataContext.java
----------------------------------------------------------------------
diff --git a/openoffice/src/main/java/org/apache/metamodel/openoffice/OpenOfficeDataContext.java b/openoffice/src/main/java/org/apache/metamodel/openoffice/OpenOfficeDataContext.java
index 7f0e901..25275a5 100644
--- a/openoffice/src/main/java/org/apache/metamodel/openoffice/OpenOfficeDataContext.java
+++ b/openoffice/src/main/java/org/apache/metamodel/openoffice/OpenOfficeDataContext.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.openoffice;
+package org.apache.metamodel.openoffice;
import java.io.BufferedOutputStream;
import java.io.File;
@@ -29,14 +29,14 @@ import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
-import org.eobjects.metamodel.AbstractDataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.TableType;
-import org.eobjects.metamodel.util.FileHelper;
+import org.apache.metamodel.AbstractDataContext;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.TableType;
+import org.apache.metamodel.util.FileHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/openoffice/src/main/java/org/apache/metamodel/openoffice/package-info.java
----------------------------------------------------------------------
diff --git a/openoffice/src/main/java/org/apache/metamodel/openoffice/package-info.java b/openoffice/src/main/java/org/apache/metamodel/openoffice/package-info.java
index c6fc241..238fa0d 100644
--- a/openoffice/src/main/java/org/apache/metamodel/openoffice/package-info.java
+++ b/openoffice/src/main/java/org/apache/metamodel/openoffice/package-info.java
@@ -19,5 +19,5 @@
/**
* Module package for OpenOffice.org database files
*/
-package org.eobjects.metamodel.openoffice;
+package org.apache.metamodel.openoffice;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/openoffice/src/test/java/org/apache/metamodel/openoffice/OpenOfficeDataContextTest.java
----------------------------------------------------------------------
diff --git a/openoffice/src/test/java/org/apache/metamodel/openoffice/OpenOfficeDataContextTest.java b/openoffice/src/test/java/org/apache/metamodel/openoffice/OpenOfficeDataContextTest.java
index 139bc37..78015d2 100644
--- a/openoffice/src/test/java/org/apache/metamodel/openoffice/OpenOfficeDataContextTest.java
+++ b/openoffice/src/test/java/org/apache/metamodel/openoffice/OpenOfficeDataContextTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.openoffice;
+package org.apache.metamodel.openoffice;
import java.io.File;
import java.sql.Connection;
@@ -25,12 +25,12 @@ import java.util.Arrays;
import javax.swing.table.TableModel;
import junit.framework.TestCase;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetTableModel;
-import org.eobjects.metamodel.openoffice.OpenOfficeDataContext;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSetTableModel;
+import org.apache.metamodel.openoffice.OpenOfficeDataContext;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public class OpenOfficeDataContextTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/pojo/src/main/java/org/apache/metamodel/pojo/ArrayTableDataProvider.java
----------------------------------------------------------------------
diff --git a/pojo/src/main/java/org/apache/metamodel/pojo/ArrayTableDataProvider.java b/pojo/src/main/java/org/apache/metamodel/pojo/ArrayTableDataProvider.java
index 241d877..ac95fca 100644
--- a/pojo/src/main/java/org/apache/metamodel/pojo/ArrayTableDataProvider.java
+++ b/pojo/src/main/java/org/apache/metamodel/pojo/ArrayTableDataProvider.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.pojo;
+package org.apache.metamodel.pojo;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import org.eobjects.metamodel.util.SimpleTableDef;
+import org.apache.metamodel.util.SimpleTableDef;
/**
* {@link TableDataProvider} based on an {@link Collection} (for instance a
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/pojo/src/main/java/org/apache/metamodel/pojo/MapTableDataProvider.java
----------------------------------------------------------------------
diff --git a/pojo/src/main/java/org/apache/metamodel/pojo/MapTableDataProvider.java b/pojo/src/main/java/org/apache/metamodel/pojo/MapTableDataProvider.java
index 8384865..e8993f6 100644
--- a/pojo/src/main/java/org/apache/metamodel/pojo/MapTableDataProvider.java
+++ b/pojo/src/main/java/org/apache/metamodel/pojo/MapTableDataProvider.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.pojo;
+package org.apache.metamodel.pojo;
import java.util.Collection;
import java.util.HashMap;
@@ -24,7 +24,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import org.eobjects.metamodel.util.SimpleTableDef;
+import org.apache.metamodel.util.SimpleTableDef;
/**
* {@link TableDataProvider} based on an {@link Collection} (for instance a
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/pojo/src/main/java/org/apache/metamodel/pojo/ObjectTableDataProvider.java
----------------------------------------------------------------------
diff --git a/pojo/src/main/java/org/apache/metamodel/pojo/ObjectTableDataProvider.java b/pojo/src/main/java/org/apache/metamodel/pojo/ObjectTableDataProvider.java
index c19045a..65afdf1 100644
--- a/pojo/src/main/java/org/apache/metamodel/pojo/ObjectTableDataProvider.java
+++ b/pojo/src/main/java/org/apache/metamodel/pojo/ObjectTableDataProvider.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.pojo;
+package org.apache.metamodel.pojo;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -28,8 +28,8 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.util.SimpleTableDef;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.util.SimpleTableDef;
/**
* {@link TableDataProvider} for regular Java objects with getter and setter
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/pojo/src/main/java/org/apache/metamodel/pojo/PojoDataContext.java
----------------------------------------------------------------------
diff --git a/pojo/src/main/java/org/apache/metamodel/pojo/PojoDataContext.java b/pojo/src/main/java/org/apache/metamodel/pojo/PojoDataContext.java
index 5c1db78..2de3d59 100644
--- a/pojo/src/main/java/org/apache/metamodel/pojo/PojoDataContext.java
+++ b/pojo/src/main/java/org/apache/metamodel/pojo/PojoDataContext.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.pojo;
+package org.apache.metamodel.pojo;
import java.io.Serializable;
import java.util.ArrayList;
@@ -25,21 +25,21 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.MaxRowsDataSet;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.SimpleTableDef;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.MetaModelHelper;
+import org.apache.metamodel.QueryPostprocessDataContext;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.UpdateableDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.MaxRowsDataSet;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.SimpleTableDef;
/**
* A {@link DataContext} used to serve MetaModel support for collections of Java
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/pojo/src/main/java/org/apache/metamodel/pojo/PojoDataSet.java
----------------------------------------------------------------------
diff --git a/pojo/src/main/java/org/apache/metamodel/pojo/PojoDataSet.java b/pojo/src/main/java/org/apache/metamodel/pojo/PojoDataSet.java
index ce85afd..1c86ef1 100644
--- a/pojo/src/main/java/org/apache/metamodel/pojo/PojoDataSet.java
+++ b/pojo/src/main/java/org/apache/metamodel/pojo/PojoDataSet.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.pojo;
+package org.apache.metamodel.pojo;
import java.util.Iterator;
-import org.eobjects.metamodel.data.AbstractDataSet;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.SelectItem;
+import org.apache.metamodel.data.AbstractDataSet;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.SelectItem;
/**
* {@link DataSet} implementation that passes on most responsibility to
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/pojo/src/main/java/org/apache/metamodel/pojo/PojoUpdateCallback.java
----------------------------------------------------------------------
diff --git a/pojo/src/main/java/org/apache/metamodel/pojo/PojoUpdateCallback.java b/pojo/src/main/java/org/apache/metamodel/pojo/PojoUpdateCallback.java
index a7bab84..c53c3c9 100644
--- a/pojo/src/main/java/org/apache/metamodel/pojo/PojoUpdateCallback.java
+++ b/pojo/src/main/java/org/apache/metamodel/pojo/PojoUpdateCallback.java
@@ -16,32 +16,32 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.pojo;
+package org.apache.metamodel.pojo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.eobjects.metamodel.AbstractUpdateCallback;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.create.AbstractTableCreationBuilder;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.delete.AbstractRowDeletionBuilder;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.AbstractTableDropBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.AbstractRowInsertionBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.SimpleTableDef;
+import org.apache.metamodel.AbstractUpdateCallback;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.create.AbstractTableCreationBuilder;
+import org.apache.metamodel.create.TableCreationBuilder;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.delete.AbstractRowDeletionBuilder;
+import org.apache.metamodel.delete.RowDeletionBuilder;
+import org.apache.metamodel.drop.AbstractTableDropBuilder;
+import org.apache.metamodel.drop.TableDropBuilder;
+import org.apache.metamodel.insert.AbstractRowInsertionBuilder;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.SimpleTableDef;
/**
* Update callback for the pojo module.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/pojo/src/main/java/org/apache/metamodel/pojo/TableDataProvider.java
----------------------------------------------------------------------
diff --git a/pojo/src/main/java/org/apache/metamodel/pojo/TableDataProvider.java b/pojo/src/main/java/org/apache/metamodel/pojo/TableDataProvider.java
index d14fea1..7786517 100644
--- a/pojo/src/main/java/org/apache/metamodel/pojo/TableDataProvider.java
+++ b/pojo/src/main/java/org/apache/metamodel/pojo/TableDataProvider.java
@@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.pojo;
+package org.apache.metamodel.pojo;
import java.io.Serializable;
import java.util.Map;
-import org.eobjects.metamodel.util.HasName;
-import org.eobjects.metamodel.util.SimpleTableDef;
+import org.apache.metamodel.util.HasName;
+import org.apache.metamodel.util.SimpleTableDef;
/**
* Represents a named collection to be comprehended by a {@link PojoDataContext}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/pojo/src/test/java/org/apache/metamodel/pojo/FoobarBean.java
----------------------------------------------------------------------
diff --git a/pojo/src/test/java/org/apache/metamodel/pojo/FoobarBean.java b/pojo/src/test/java/org/apache/metamodel/pojo/FoobarBean.java
index 2f5a9f6..9ccf15d 100644
--- a/pojo/src/test/java/org/apache/metamodel/pojo/FoobarBean.java
+++ b/pojo/src/test/java/org/apache/metamodel/pojo/FoobarBean.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.pojo;
+package org.apache.metamodel.pojo;
import java.io.Serializable;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/pojo/src/test/java/org/apache/metamodel/pojo/ObjectTableDataProviderTest.java
----------------------------------------------------------------------
diff --git a/pojo/src/test/java/org/apache/metamodel/pojo/ObjectTableDataProviderTest.java b/pojo/src/test/java/org/apache/metamodel/pojo/ObjectTableDataProviderTest.java
index f7f4723..f0a87f2 100644
--- a/pojo/src/test/java/org/apache/metamodel/pojo/ObjectTableDataProviderTest.java
+++ b/pojo/src/test/java/org/apache/metamodel/pojo/ObjectTableDataProviderTest.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.pojo;
+package org.apache.metamodel.pojo;
import junit.framework.TestCase;
-import org.eobjects.metamodel.util.SimpleTableDef;
+import org.apache.metamodel.util.SimpleTableDef;
public class ObjectTableDataProviderTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/pojo/src/test/java/org/apache/metamodel/pojo/PojoDataContextTest.java
----------------------------------------------------------------------
diff --git a/pojo/src/test/java/org/apache/metamodel/pojo/PojoDataContextTest.java b/pojo/src/test/java/org/apache/metamodel/pojo/PojoDataContextTest.java
index e40c672..d893e4a 100644
--- a/pojo/src/test/java/org/apache/metamodel/pojo/PojoDataContextTest.java
+++ b/pojo/src/test/java/org/apache/metamodel/pojo/PojoDataContextTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.pojo;
+package org.apache.metamodel.pojo;
import java.util.ArrayList;
import java.util.Arrays;
@@ -25,13 +25,13 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.SimpleTableDef;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.SimpleTableDef;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataContext.java
----------------------------------------------------------------------
diff --git a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataContext.java b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataContext.java
index ea606f3..1075114 100644
--- a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataContext.java
+++ b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataContext.java
@@ -16,28 +16,28 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.salesforce;
+package org.apache.metamodel.salesforce;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.FirstRowDataSet;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.OrderByItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.QueryPostprocessDataContext;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.UpdateableDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.FirstRowDataSet;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.OrderByItem;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataSet.java
----------------------------------------------------------------------
diff --git a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataSet.java b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataSet.java
index 442a009..d44bb47 100644
--- a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataSet.java
+++ b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataSet.java
@@ -16,20 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.salesforce;
+package org.apache.metamodel.salesforce;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.concurrent.atomic.AtomicInteger;
-import org.eobjects.metamodel.data.AbstractDataSet;
-import org.eobjects.metamodel.data.DataSetHeader;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.util.BooleanComparator;
-import org.eobjects.metamodel.util.NumberComparator;
+import org.apache.metamodel.data.AbstractDataSet;
+import org.apache.metamodel.data.DataSetHeader;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.util.BooleanComparator;
+import org.apache.metamodel.util.NumberComparator;
import com.sforce.soap.partner.PartnerConnection;
import com.sforce.soap.partner.QueryResult;
[07/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUtils.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUtils.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUtils.java
new file mode 100644
index 0000000..80f0875
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUtils.java
@@ -0,0 +1,265 @@
+/**
+ * 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.jdbc;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.NClob;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.OperatorType;
+import org.eobjects.metamodel.query.QueryParameter;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.TableType;
+import org.eobjects.metamodel.util.FileHelper;
+import org.eobjects.metamodel.util.FormatHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class JdbcUtils {
+
+ private static final Logger logger = LoggerFactory
+ .getLogger(JdbcUtils.class);
+
+ public static MetaModelException wrapException(SQLException e,
+ String actionDescription) throws MetaModelException {
+ String message = e.getMessage();
+ if (message == null || message.isEmpty()) {
+ message = "Could not " + actionDescription;
+ } else {
+ message = "Could not " + actionDescription + ": " + message;
+ }
+
+ logger.error(message, e);
+ logger.error("Error code={}, SQL state={}", e.getErrorCode(),
+ e.getSQLState());
+
+ final SQLException nextException = e.getNextException();
+ if (nextException != null) {
+ logger.error("Next SQL exception: " + nextException.getMessage(),
+ nextException);
+ }
+
+ return new MetaModelException(message, e);
+ }
+
+ /**
+ * Method which handles the action of setting a parameterized value on a
+ * statement. Traditionally this is done using the
+ * {@link PreparedStatement#setObject(int, Object)} method but for some
+ * types we use more specific setter methods.
+ *
+ * @param st
+ * @param valueIndex
+ * @param column
+ * @param value
+ * @throws SQLException
+ */
+ public static void setStatementValue(final PreparedStatement st,
+ final int valueIndex, final Column column, Object value)
+ throws SQLException {
+ final ColumnType type = (column == null ? null : column.getType());
+
+ if (type == null || type == ColumnType.OTHER) {
+ // type is not known - nothing more we can do to narrow the type
+ st.setObject(valueIndex, value);
+ return;
+ }
+
+ if (value == null && type != null) {
+ try {
+ final int jdbcType = type.getJdbcType();
+ st.setNull(valueIndex, jdbcType);
+ return;
+ } catch (Exception e) {
+ logger.warn(
+ "Exception occurred while calling setNull(...) for value index "
+ + valueIndex
+ + ". Attempting value-based setter method instead.",
+ e);
+ }
+ }
+
+ if (type == ColumnType.VARCHAR && value instanceof Date) {
+ // some drivers (SQLite and JTDS for MS SQL server) treat dates as
+ // VARCHARS. In that case we need to convert the dates to the
+ // correct format
+ String nativeType = column.getNativeType();
+ Date date = (Date) value;
+ if ("DATE".equalsIgnoreCase(nativeType)) {
+ value = FormatHelper
+ .formatSqlTime(ColumnType.DATE, date, false);
+ } else if ("TIME".equalsIgnoreCase(nativeType)) {
+ value = FormatHelper
+ .formatSqlTime(ColumnType.TIME, date, false);
+ } else if ("TIMESTAMP".equalsIgnoreCase(nativeType)
+ || "DATETIME".equalsIgnoreCase(nativeType)) {
+ value = FormatHelper.formatSqlTime(ColumnType.TIMESTAMP, date,
+ false);
+ }
+ }
+
+ if (type != null && type.isTimeBased() && value instanceof String) {
+ value = FormatHelper.parseSqlTime(type, (String) value);
+ }
+
+ try {
+ if (type == ColumnType.DATE && value instanceof Date) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime((Date) value);
+ st.setDate(valueIndex,
+ new java.sql.Date(cal.getTimeInMillis()), cal);
+ } else if (type == ColumnType.TIME && value instanceof Date) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime((Date) value);
+ st.setTime(valueIndex,
+ new java.sql.Time(cal.getTimeInMillis()), cal);
+ } else if (type == ColumnType.TIMESTAMP && value instanceof Date) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime((Date) value);
+ st.setTimestamp(valueIndex,
+ new java.sql.Timestamp(cal.getTimeInMillis()), cal);
+ } else if (type == ColumnType.CLOB || type == ColumnType.NCLOB) {
+ if (value instanceof InputStream) {
+ InputStream inputStream = (InputStream) value;
+ st.setAsciiStream(valueIndex, inputStream);
+ } else if (value instanceof Reader) {
+ Reader reader = (Reader) value;
+ st.setCharacterStream(valueIndex, reader);
+ } else if (value instanceof NClob) {
+ NClob nclob = (NClob) value;
+ st.setNClob(valueIndex, nclob);
+ } else if (value instanceof Clob) {
+ Clob clob = (Clob) value;
+ st.setClob(valueIndex, clob);
+ } else if (value instanceof String) {
+ st.setString(valueIndex, (String) value);
+ } else {
+ st.setObject(valueIndex, value);
+ }
+ } else if (type == ColumnType.BLOB || type == ColumnType.BINARY) {
+ if (value instanceof byte[]) {
+ byte[] bytes = (byte[]) value;
+ st.setBytes(valueIndex, bytes);
+ } else if (value instanceof InputStream) {
+ InputStream inputStream = (InputStream) value;
+ st.setBinaryStream(valueIndex, inputStream);
+ } else if (value instanceof Blob) {
+ Blob blob = (Blob) value;
+ st.setBlob(valueIndex, blob);
+ } else {
+ st.setObject(valueIndex, value);
+ }
+ } else if (type.isLiteral()) {
+ final String str;
+ if (value instanceof Reader) {
+ Reader reader = (Reader) value;
+ str = FileHelper.readAsString(reader);
+ } else {
+ str = value.toString();
+ }
+ st.setString(valueIndex, str);
+ } else {
+ st.setObject(valueIndex, value);
+ }
+ } catch (SQLException e) {
+ logger.error("Failed to set parameter {} to value: {}", valueIndex,
+ value);
+ throw e;
+ }
+ }
+
+ public static String getValueAsSql(Column column, Object value,
+ IQueryRewriter queryRewriter) {
+ if (value == null) {
+ return "NULL";
+ }
+ final ColumnType columnType = column.getType();
+ if (columnType.isLiteral() && value instanceof String) {
+ value = queryRewriter.escapeQuotes((String) value);
+ }
+ String formatSqlValue = FormatHelper.formatSqlValue(columnType, value);
+ return formatSqlValue;
+ }
+
+ public static String createWhereClause(List<FilterItem> whereItems,
+ IQueryRewriter queryRewriter, boolean inlineValues) {
+ if (whereItems.isEmpty()) {
+ return "";
+ }
+ StringBuilder sb = new StringBuilder();
+ sb.append(" WHERE ");
+ boolean firstValue = true;
+ for (FilterItem whereItem : whereItems) {
+ if (firstValue) {
+ firstValue = false;
+ } else {
+ sb.append(" AND ");
+ }
+ if (!inlineValues) {
+ if (isPreparedParameterCandidate(whereItem)) {
+ // replace operator with parameter
+ whereItem = new FilterItem(whereItem.getSelectItem(),
+ whereItem.getOperator(), new QueryParameter());
+ }
+ }
+ final String whereItemLabel = queryRewriter
+ .rewriteFilterItem(whereItem);
+ sb.append(whereItemLabel);
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Determines if a particular {@link FilterItem} will have it's parameter
+ * (operand) replaced during SQL generation. Such filter items should
+ * succesively have their parameters set at execution time.
+ *
+ * @param whereItem
+ * @return
+ */
+ public static boolean isPreparedParameterCandidate(FilterItem whereItem) {
+ return !whereItem.isCompoundFilter()
+ && whereItem.getOperator() != OperatorType.IN;
+ }
+
+ public static String[] getTableTypesAsStrings(TableType[] tableTypes) {
+ String[] types = new String[tableTypes.length];
+ for (int i = 0; i < types.length; i++) {
+ if (tableTypes[i] == TableType.OTHER) {
+ // if the OTHER type has been selected, don't use a table
+ // pattern (ie. include all types)
+ types = null;
+ break;
+ }
+ types[i] = tableTypes[i].toString();
+ }
+ return types;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/MetadataLoader.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/MetadataLoader.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/MetadataLoader.java
new file mode 100644
index 0000000..07b17de
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/MetadataLoader.java
@@ -0,0 +1,36 @@
+/**
+ * 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.jdbc;
+
+/**
+ * Defines the interface for a component capable of loading schema-model
+ * metadata.
+ */
+interface MetadataLoader {
+
+ public void loadTables(JdbcSchema jdbcSchema);
+
+ public void loadRelations(JdbcSchema jdbcSchema);
+
+ public void loadColumns(JdbcTable jdbcTable);
+
+ public void loadIndexes(JdbcTable jdbcTable);
+
+ public void loadPrimaryKeys(JdbcTable jdbcTable);
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/QuerySplitter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/QuerySplitter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/QuerySplitter.java
new file mode 100644
index 0000000..1f74866
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/QuerySplitter.java
@@ -0,0 +1,336 @@
+/**
+ * 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.jdbc;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.MetaModelHelper;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.FromClause;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.FunctionType;
+import org.eobjects.metamodel.query.GroupByItem;
+import org.eobjects.metamodel.query.OperatorType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * The QuerySplitter class makes it possible to split up queries that are
+ * expected to yield a huge result set which may cause performance problems like
+ * OutOfMemoryError's or very long processing periods. The resulting queries
+ * will in union produce the same result, but in smaller bits (resultsets with
+ * less rows).
+ *
+ * Note that there is an initial performance-penalty associated with splitting
+ * the query since some queries will be executed in order to determine
+ * reasonable intervals to use for the resulting queries WHERE clauses.
+ *
+ * @see Query
+ * @see DataContext
+ */
+public final class QuerySplitter {
+
+ public final static long DEFAULT_MAX_ROWS = 300000;
+ private static final int MINIMUM_MAX_ROWS = 100;
+ private final static Logger logger = LoggerFactory.getLogger(QuerySplitter.class);
+
+ private final Query _query;
+ private final DataContext _dataContext;
+ private long _maxRows = DEFAULT_MAX_ROWS;
+ private Long _cachedRowCount = null;
+
+ public QuerySplitter(DataContext dc, Query q) {
+ if (dc == null) {
+ throw new IllegalArgumentException("DataContext cannot be null");
+ }
+ if (q == null) {
+ throw new IllegalArgumentException("Query cannot be null");
+ }
+ _dataContext = dc;
+ _query = q;
+ }
+
+ /**
+ * Splits the query into several queries that will together yield the same
+ * result set
+ *
+ * @return a list of queries that can be executed to yield the same
+ * collective result as this QuerySplitter's query
+ */
+ public List<Query> splitQuery() {
+ List<Query> result = new ArrayList<Query>();
+ if (isSplittable()) {
+ if (getRowCount() > _maxRows) {
+ Integer subQueryIndex = getSubQueryFromItemIndex();
+ List<Query> splitQueries = null;
+ if (subQueryIndex != null) {
+ splitQueries = splitQueryBasedOnSubQueries(subQueryIndex);
+ } else {
+ List<Column> splitColumns = getSplitColumns();
+ splitQueries = splitQueryBasedOnColumns(splitColumns);
+ }
+ result.addAll(splitQueries);
+ } else {
+ if (logger.isInfoEnabled()) {
+ logger.info("Accepted query, maxRows not exceeded: " + _query);
+ }
+ result.add(_query);
+ }
+ }
+ if (result.isEmpty()) {
+ logger.debug("Cannot further split query: {}", _query);
+ result.add(_query);
+ }
+ return result;
+ }
+
+ private List<Query> splitQueryBasedOnColumns(List<Column> splitColumns) {
+ List<Query> result = new ArrayList<Query>();
+ if (splitColumns.isEmpty() || getRowCount() <= _maxRows) {
+ if (getRowCount() > 0) {
+ result.add(_query);
+ }
+ } else {
+ Column firstColumn = splitColumns.get(0);
+ splitColumns.remove(0);
+ List<Query> splitQueries = splitQueryBasedOnColumn(firstColumn);
+ for (Query splitQuery : splitQueries) {
+ QuerySplitter qs = new QuerySplitter(_dataContext, splitQuery).setMaxRows(_maxRows);
+ if (qs.getRowCount() > _maxRows) {
+ // Recursively use the next columns to split queries
+ // subsequently
+ result.addAll(qs.splitQueryBasedOnColumns(splitColumns));
+ } else {
+ if (qs.getRowCount() > 0) {
+ result.add(splitQuery);
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ private List<Query> splitQueryBasedOnColumn(Column column) {
+ SelectItem maxItem = new SelectItem(FunctionType.MAX, column);
+ SelectItem minItem = new SelectItem(FunctionType.MIN, column);
+ Query q = new Query().from(column.getTable()).select(maxItem, minItem);
+ Row row = MetaModelHelper.executeSingleRowQuery(_dataContext, q);
+ long max = ceil((Number) row.getValue(maxItem));
+ long min = floor((Number) row.getValue(minItem));
+ long wholeRange = max - min;
+ List<Query> result = new ArrayList<Query>();
+ if (wholeRange <= 1) {
+ result.add(_query);
+ } else {
+ long numSplits = ceil(getRowCount() / _maxRows);
+ if (numSplits < 2) {
+ // Must as a minimum yield two new queries
+ numSplits = 2;
+ }
+ int splitInterval = (int) (wholeRange / numSplits);
+ for (int i = 0; i < numSplits; i++) {
+ q = _query.clone();
+ long lowLimit = min + (i * splitInterval);
+ long highLimit = lowLimit + splitInterval;
+
+ FilterItem lowerThanFilter = new FilterItem(new SelectItem(column), OperatorType.LESS_THAN, highLimit);
+ FilterItem higherThanFilter = new FilterItem(new SelectItem(column), OperatorType.GREATER_THAN,
+ lowLimit);
+ FilterItem equalsFilter = new FilterItem(new SelectItem(column), OperatorType.EQUALS_TO, lowLimit);
+
+ if (i == 0) {
+ // This is the first split query: no higherThan filter and
+ // include
+ // IS NULL
+ FilterItem nullFilter = new FilterItem(new SelectItem(column), OperatorType.EQUALS_TO, null);
+ FilterItem orFilterItem = new FilterItem(lowerThanFilter, nullFilter);
+ q.where(orFilterItem);
+ } else if (i + 1 == numSplits) {
+ // This is the lats split query: no lowerThan filter,
+ FilterItem orFilterItem = new FilterItem(higherThanFilter, equalsFilter);
+ q.where(orFilterItem);
+ } else {
+ higherThanFilter = new FilterItem(higherThanFilter, equalsFilter);
+ lowerThanFilter = new FilterItem(lowerThanFilter, equalsFilter);
+ q.where(higherThanFilter);
+ q.where(lowerThanFilter);
+ }
+ result.add(q);
+ }
+ }
+ return result;
+ }
+
+ private static long floor(Number value) {
+ Double floor = Math.floor(value.doubleValue());
+ return floor.longValue();
+ }
+
+ private static long ceil(Number value) {
+ Double ceil = Math.ceil(value.doubleValue());
+ return ceil.longValue();
+ }
+
+ private List<Query> splitQueryBasedOnSubQueries(int fromItemIndex) {
+ Query subQuery = _query.getFromClause().getItem(fromItemIndex).getSubQuery();
+ QuerySplitter subQuerySplitter = new QuerySplitter(_dataContext, subQuery);
+
+ subQuerySplitter.setMaxRows(_maxRows);
+ List<Query> splitQueries = subQuerySplitter.splitQuery();
+ List<Query> result = new ArrayList<Query>(splitQueries.size());
+ for (Query splitQuery : splitQueries) {
+ Query newQuery = _query.clone();
+ FromClause fromClause = newQuery.getFromClause();
+ String alias = fromClause.getItem(fromItemIndex).getAlias();
+ fromClause.removeItem(fromItemIndex);
+ newQuery.from(new FromItem(splitQuery).setAlias(alias));
+ result.add(newQuery);
+ }
+ return result;
+ }
+
+ private Integer getSubQueryFromItemIndex() {
+ List<FromItem> fromItems = _query.getFromClause().getItems();
+ for (int i = 0; i < fromItems.size(); i++) {
+ Query subQuery = fromItems.get(i).getSubQuery();
+ if (subQuery != null) {
+ if (isSplittable(subQuery)) {
+ return i;
+ }
+ }
+ }
+ return null;
+ }
+
+ private boolean isSplittable() {
+ return isSplittable(_query);
+ }
+
+ public static boolean isSplittable(Query q) {
+ if (q.getOrderByClause().getItemCount() != 0) {
+ return false;
+ }
+ return true;
+ }
+
+ private List<Column> getSplitColumns() {
+ List<Column> result = new ArrayList<Column>();
+ if (_query.getGroupByClause().getItemCount() != 0) {
+ List<GroupByItem> groupByItems = _query.getGroupByClause().getItems();
+ for (GroupByItem groupByItem : groupByItems) {
+ Column column = groupByItem.getSelectItem().getColumn();
+ if (column != null) {
+ if (column.isIndexed()) {
+ // Indexed columns have first priority, they will be
+ // added to the beginning of the list
+ result.add(0, column);
+ } else {
+ result.add(column);
+ }
+ }
+ }
+ } else {
+ List<FromItem> fromItems = _query.getFromClause().getItems();
+ for (FromItem fromItem : fromItems) {
+ if (fromItem.getTable() != null) {
+ addColumnsToResult(fromItem.getTable(), result);
+ }
+ if (fromItem.getJoin() != null && fromItem.getAlias() == null) {
+ if (fromItem.getLeftSide().getTable() != null) {
+ addColumnsToResult(fromItem.getLeftSide().getTable(), result);
+ }
+ if (fromItem.getRightSide().getTable() != null) {
+ addColumnsToResult(fromItem.getRightSide().getTable(), result);
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ private static void addColumnsToResult(Table table, List<Column> result) {
+ Column[] numberColumns = table.getNumberColumns();
+ for (int i = 0; i < numberColumns.length; i++) {
+ Column column = numberColumns[i];
+ if (column.isIndexed()) {
+ // Indexed columns have first priority, they will be
+ // added to the beginning of the list
+ result.add(0, column);
+ } else {
+ result.add(column);
+ }
+ }
+ }
+
+ /**
+ * @return the total number of rows expected from executing the query.
+ */
+ public long getRowCount() {
+ if (_cachedRowCount == null) {
+ _cachedRowCount = getRowCount(_query);
+ }
+ return _cachedRowCount;
+ }
+
+ private long getRowCount(Query q) {
+ q = q.clone();
+ SelectItem countAllItem = SelectItem.getCountAllItem();
+ if (q.getGroupByClause().getItemCount() > 0) {
+ q = new Query().from(new FromItem(q).setAlias("sq")).select(countAllItem);
+ } else {
+ q.getSelectClause().removeItems();
+ q.select(countAllItem);
+ }
+ Row row = MetaModelHelper.executeSingleRowQuery(_dataContext, q);
+ Number count = (Number) row.getValue(countAllItem);
+ return count.longValue();
+ }
+
+ /**
+ * Sets the desired maximum result set row count. Note that this size cannot
+ * be guaranteed, but will serve as an indicator for determining the
+ * split-size
+ *
+ * @param maxRows
+ */
+ public QuerySplitter setMaxRows(long maxRows) {
+ if (maxRows < MINIMUM_MAX_ROWS) {
+ throw new IllegalArgumentException("maxRows must be higher than " + MINIMUM_MAX_ROWS);
+ }
+ _maxRows = maxRows;
+ return this;
+ }
+
+ public DataSet executeQueries() {
+ return executeQueries(splitQuery());
+ }
+
+ public DataSet executeQueries(List<Query> splitQueries) {
+ return new SplitQueriesDataSet(_dataContext, splitQueries);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/SplitQueriesDataSet.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/SplitQueriesDataSet.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/SplitQueriesDataSet.java
new file mode 100644
index 0000000..68cc442
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/SplitQueriesDataSet.java
@@ -0,0 +1,106 @@
+/**
+ * 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.jdbc;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.data.AbstractDataSet;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+
+/**
+ * DataSet for split queries. Queries will be executed as needed, not at once.
+ *
+ * @see org.eobjects.metamodel.jdbc.QuerySplitter
+ */
+final class SplitQueriesDataSet extends AbstractDataSet {
+
+ private static final Logger logger = LoggerFactory.getLogger(SplitQueriesDataSet.class);
+ private final DataContext _dataContext;
+ private Iterator<Query> _queryIterator;
+ private DataSet _currentDataSet;
+ private int _queryIndex = 0;
+
+ public SplitQueriesDataSet(DataContext dataContext, List<Query> splitQueries) {
+ super(getSelectItems(splitQueries));
+ if (dataContext == null || splitQueries == null) {
+ throw new IllegalArgumentException("Arguments cannot be null");
+ }
+ _dataContext = dataContext;
+ _queryIterator = splitQueries.iterator();
+ }
+
+ private static List<SelectItem> getSelectItems(List<Query> splitQueries) {
+ if (splitQueries.isEmpty()) {
+ return new ArrayList<SelectItem>(0);
+ }
+ return splitQueries.get(0).getSelectClause().getItems();
+ }
+
+ @Override
+ public void close() {
+ if (_currentDataSet != null) {
+ logger.debug("currentDataSet.close()");
+ _currentDataSet.close();
+ }
+ _currentDataSet = null;
+ _queryIterator = null;
+ }
+
+ @Override
+ public Row getRow() throws MetaModelException {
+ if (_currentDataSet != null) {
+ return _currentDataSet.getRow();
+ }
+ throw new IllegalStateException("No rows available. Either DataSet is closed or next() hasn't been called");
+ }
+
+ @Override
+ public boolean next() {
+ boolean result;
+ if (_currentDataSet == null) {
+ result = false;
+ } else {
+ result = _currentDataSet.next();
+ }
+ if (!result && _queryIterator.hasNext()) {
+ if (_currentDataSet != null) {
+ logger.debug("currentDataSet.close()");
+ _currentDataSet.close();
+ }
+ Query q = _queryIterator.next();
+ _currentDataSet = _dataContext.executeQuery(q);
+ if (logger.isDebugEnabled()) {
+ _queryIndex++;
+ logger.debug("Executing query #{}", _queryIndex);
+ }
+ result = next();
+ }
+ return result;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/SqlKeywords.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/SqlKeywords.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/SqlKeywords.java
new file mode 100644
index 0000000..349e2c0
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/SqlKeywords.java
@@ -0,0 +1,51 @@
+/**
+ * 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.jdbc;
+
+import java.util.HashSet;
+import java.util.Set;
+
+class SqlKeywords {
+
+ private static final Set<String> KEYWORDS;
+
+ static {
+ KEYWORDS = new HashSet<String>();
+ KEYWORDS.add("SELECT");
+ KEYWORDS.add("DISTINCT");
+ KEYWORDS.add("AS");
+ KEYWORDS.add("COUNT");
+ KEYWORDS.add("SUM");
+ KEYWORDS.add("MIN");
+ KEYWORDS.add("MAX");
+ KEYWORDS.add("FROM");
+ KEYWORDS.add("WHERE");
+ KEYWORDS.add("LIKE");
+ KEYWORDS.add("IN");
+ KEYWORDS.add("GROUP");
+ KEYWORDS.add("BY");
+ KEYWORDS.add("HAVING");
+ KEYWORDS.add("ORDER");
+ }
+
+ public static boolean isKeyword(String str) {
+ str = str.toUpperCase();
+ return KEYWORDS.contains(str);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/AbstractQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/AbstractQueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/AbstractQueryRewriter.java
new file mode 100644
index 0000000..2cc8ece
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/AbstractQueryRewriter.java
@@ -0,0 +1,259 @@
+/**
+ * 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.jdbc.dialects;
+
+import java.util.List;
+
+import org.eobjects.metamodel.jdbc.JdbcDataContext;
+import org.eobjects.metamodel.query.AbstractQueryClause;
+import org.eobjects.metamodel.query.FilterClause;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.FromClause;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.GroupByClause;
+import org.eobjects.metamodel.query.GroupByItem;
+import org.eobjects.metamodel.query.OperatorType;
+import org.eobjects.metamodel.query.OrderByClause;
+import org.eobjects.metamodel.query.OrderByItem;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectClause;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract implementation of query rewriter. This implementation delegates the
+ * rewriting of the Query into several subtasks according to the query items to
+ * be rendered. This makes it easy to overload single methods in order to
+ * correct syntax quirks.
+ */
+public abstract class AbstractQueryRewriter implements IQueryRewriter {
+
+ protected final Logger logger = LoggerFactory.getLogger(getClass());
+
+ private final JdbcDataContext _dataContext;
+
+ public AbstractQueryRewriter(JdbcDataContext dataContext) {
+ _dataContext = dataContext;
+ }
+
+ public JdbcDataContext getDataContext() {
+ return _dataContext;
+ }
+
+ @Override
+ public ColumnType getColumnType(int jdbcType, String nativeType, Integer columnSize) {
+ return ColumnType.convertColumnType(jdbcType);
+ }
+
+ public String rewriteQuery(Query query) {
+ query = beforeRewrite(query);
+
+ final StringBuilder sb = new StringBuilder();
+ sb.append(rewriteSelectClause(query, query.getSelectClause()));
+ sb.append(rewriteFromClause(query, query.getFromClause()));
+ sb.append(rewriteWhereClause(query, query.getWhereClause()));
+ sb.append(rewriteGroupByClause(query, query.getGroupByClause()));
+ sb.append(rewriteHavingClause(query, query.getHavingClause()));
+ sb.append(rewriteOrderByClause(query, query.getOrderByClause()));
+ return sb.toString();
+ }
+
+ public boolean isSchemaIncludedInColumnPaths() {
+ return false;
+ }
+
+ /**
+ * Method to modify query before rewriting begins. Overwrite this method if
+ * you want to change parts of the query that are not just rendering
+ * related. Cloning the query before modifying is recommended in order to
+ * not violate referential integrity of clients (the query is mutable).
+ *
+ * @param strategy
+ * @param query
+ * @return the modified query
+ */
+ protected Query beforeRewrite(Query query) {
+ return query;
+ }
+
+ @Override
+ public String rewriteColumnType(ColumnType columnType) {
+ return columnType.toString();
+ }
+
+ protected String rewriteOrderByClause(Query query, OrderByClause orderByClause) {
+ StringBuilder sb = new StringBuilder();
+ if (orderByClause.getItemCount() > 0) {
+ sb.append(AbstractQueryClause.PREFIX_ORDER_BY);
+ List<OrderByItem> items = orderByClause.getItems();
+ for (int i = 0; i < items.size(); i++) {
+ OrderByItem item = items.get(i);
+ if (i != 0) {
+ sb.append(AbstractQueryClause.DELIM_COMMA);
+ }
+ sb.append(rewriteOrderByItem(query, item));
+ }
+ }
+ return sb.toString();
+ }
+
+ @Override
+ public String rewriteFromItem(FromItem item) {
+ return rewriteFromItem(item.getQuery(), item);
+ }
+
+ protected String rewriteOrderByItem(Query query, OrderByItem item) {
+ return item.toSql(isSchemaIncludedInColumnPaths());
+ }
+
+ protected String rewriteHavingClause(Query query, FilterClause havingClause) {
+ StringBuilder sb = new StringBuilder();
+ if (havingClause.getItemCount() > 0) {
+ sb.append(AbstractQueryClause.PREFIX_HAVING);
+ List<FilterItem> items = havingClause.getItems();
+ for (int i = 0; i < items.size(); i++) {
+ FilterItem item = items.get(i);
+ if (i != 0) {
+ sb.append(AbstractQueryClause.DELIM_AND);
+ }
+ sb.append(rewriteFilterItem(item));
+ }
+ }
+ return sb.toString();
+ }
+
+ protected String rewriteGroupByClause(Query query, GroupByClause groupByClause) {
+ StringBuilder sb = new StringBuilder();
+ if (groupByClause.getItemCount() > 0) {
+ sb.append(AbstractQueryClause.PREFIX_GROUP_BY);
+ List<GroupByItem> items = groupByClause.getItems();
+ for (int i = 0; i < items.size(); i++) {
+ GroupByItem item = items.get(i);
+ if (i != 0) {
+ sb.append(AbstractQueryClause.DELIM_COMMA);
+ }
+ sb.append(rewriteGroupByItem(query, item));
+ }
+ }
+ return sb.toString();
+ }
+
+ protected String rewriteGroupByItem(Query query, GroupByItem item) {
+ return item.toSql(isSchemaIncludedInColumnPaths());
+ }
+
+ protected String rewriteWhereClause(Query query, FilterClause whereClause) {
+ StringBuilder sb = new StringBuilder();
+ if (whereClause.getItemCount() > 0) {
+ sb.append(AbstractQueryClause.PREFIX_WHERE);
+ List<FilterItem> items = whereClause.getItems();
+ for (int i = 0; i < items.size(); i++) {
+ FilterItem item = items.get(i);
+ if (i != 0) {
+ sb.append(AbstractQueryClause.DELIM_AND);
+ }
+ sb.append(rewriteFilterItem(item));
+ }
+ }
+ return sb.toString();
+ }
+
+ @Override
+ public String rewriteFilterItem(FilterItem item) {
+ if (item.isCompoundFilter()) {
+ FilterItem[] childItems = item.getChildItems();
+ StringBuilder sb = new StringBuilder();
+ sb.append('(');
+ for (int i = 0; i < childItems.length; i++) {
+ FilterItem child = childItems[i];
+ if (i != 0) {
+ sb.append(' ');
+ sb.append(item.getLogicalOperator().toString());
+ sb.append(' ');
+ }
+ sb.append(rewriteFilterItem(child));
+ }
+ sb.append(')');
+ return sb.toString();
+ }
+
+ final String primaryFilterSql = item.toSql(isSchemaIncludedInColumnPaths());
+
+ final OperatorType operator = item.getOperator();
+ if (operator == OperatorType.DIFFERENT_FROM) {
+ final Object operand = item.getOperand();
+ if (operand != null) {
+ // special case in SQL where NULL is not treated as a value -
+ // see Ticket #1058
+
+ FilterItem isNullFilter = new FilterItem(item.getSelectItem(), OperatorType.EQUALS_TO, null);
+ final String secondaryFilterSql = rewriteFilterItem(isNullFilter);
+
+ return '(' + primaryFilterSql + " OR " + secondaryFilterSql + ')';
+ }
+ }
+
+ return primaryFilterSql;
+ }
+
+ protected String rewriteFromClause(Query query, FromClause fromClause) {
+ StringBuilder sb = new StringBuilder();
+ if (fromClause.getItemCount() > 0) {
+ sb.append(AbstractQueryClause.PREFIX_FROM);
+ List<FromItem> items = fromClause.getItems();
+ for (int i = 0; i < items.size(); i++) {
+ FromItem item = items.get(i);
+ if (i != 0) {
+ sb.append(AbstractQueryClause.DELIM_COMMA);
+ }
+ sb.append(rewriteFromItem(query, item));
+ }
+ }
+ return sb.toString();
+ }
+
+ protected String rewriteFromItem(Query query, FromItem item) {
+ return item.toSql(isSchemaIncludedInColumnPaths());
+ }
+
+ protected String rewriteSelectClause(Query query, SelectClause selectClause) {
+ StringBuilder sb = new StringBuilder();
+ if (selectClause.getItemCount() > 0) {
+ sb.append(AbstractQueryClause.PREFIX_SELECT);
+ if (selectClause.isDistinct()) {
+ sb.append("DISTINCT ");
+ }
+ List<SelectItem> items = selectClause.getItems();
+ for (int i = 0; i < items.size(); i++) {
+ SelectItem item = items.get(i);
+ if (i != 0) {
+ sb.append(AbstractQueryClause.DELIM_COMMA);
+ }
+ sb.append(rewriteSelectItem(query, item));
+ }
+ }
+ return sb.toString();
+ }
+
+ protected String rewriteSelectItem(Query query, SelectItem item) {
+ return item.toSql(isSchemaIncludedInColumnPaths());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/DB2QueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/DB2QueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/DB2QueryRewriter.java
new file mode 100644
index 0000000..90eeb9d
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/DB2QueryRewriter.java
@@ -0,0 +1,161 @@
+/**
+ * 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.jdbc.dialects;
+
+import java.util.Date;
+import java.util.List;
+
+import org.eobjects.metamodel.jdbc.JdbcDataContext;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.OperatorType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.util.FormatHelper;
+import org.eobjects.metamodel.util.TimeComparator;
+
+/**
+ * Query rewriter for IBM DB2
+ */
+public class DB2QueryRewriter extends DefaultQueryRewriter implements IQueryRewriter {
+
+ public DB2QueryRewriter(JdbcDataContext dataContext) {
+ super(dataContext);
+ }
+
+ @Override
+ public String escapeQuotes(String filterItemOperand) {
+ return filterItemOperand.replaceAll("\\'", "\\\\'");
+ }
+
+ /**
+ * DB2 expects the fully qualified column name, including schema, in select
+ * items.
+ */
+ @Override
+ public boolean isSchemaIncludedInColumnPaths() {
+ return true;
+ }
+
+ @Override
+ public boolean isMaxRowsSupported() {
+ return true;
+ }
+
+ @Override
+ public boolean isFirstRowSupported() {
+ return true;
+ }
+
+ @Override
+ public String rewriteQuery(Query query) {
+ final Integer firstRow = query.getFirstRow();
+ final Integer maxRows = query.getMaxRows();
+
+ if (maxRows == null && firstRow == null) {
+ return super.rewriteQuery(query);
+ }
+
+ if (firstRow == null || firstRow.intValue() == 1) {
+ // We prefer to use the "FETCH FIRST [n] ROWS ONLY" approach, if
+ // firstRow is not specified.
+ return super.rewriteQuery(query) + " FETCH FIRST " + maxRows + " ROWS ONLY";
+
+ } else {
+ // build a ROW_NUMBER() query like this:
+
+ // SELECT [original select clause]
+ // FROM ([original select clause],
+ // ROW_NUMBER() AS metamodel_row_number
+ // FROM [remainder of regular query])
+ // WHERE metamodel_row_number BETWEEN [firstRow] and [maxRows];
+
+ final Query innerQuery = query.clone();
+ innerQuery.setFirstRow(null);
+ innerQuery.setMaxRows(null);
+
+ final Query outerQuery = new Query();
+ final FromItem subQuerySelectItem = new FromItem(innerQuery).setAlias("metamodel_subquery");
+ outerQuery.from(subQuerySelectItem);
+
+ final List<SelectItem> innerSelectItems = innerQuery.getSelectClause().getItems();
+ for (SelectItem selectItem : innerSelectItems) {
+ outerQuery.select(new SelectItem(selectItem, subQuerySelectItem));
+ }
+
+ innerQuery.select(new SelectItem("ROW_NUMBER() OVER()", "metamodel_row_number"));
+
+ final String baseQueryString = rewriteQuery(outerQuery);
+
+ if (maxRows == null) {
+ return baseQueryString + " WHERE metamodel_row_number > " + (firstRow - 1);
+ }
+
+ return baseQueryString + " WHERE metamodel_row_number BETWEEN " + firstRow + " AND " + (firstRow - 1 + maxRows);
+ }
+ }
+
+ @Override
+ public String rewriteColumnType(ColumnType columnType) {
+ switch (columnType) {
+ case BOOLEAN:
+ case BIT:
+ return "SMALLINT";
+ default:
+ return super.rewriteColumnType(columnType);
+ }
+ }
+
+ @Override
+ public String rewriteFilterItem(FilterItem item) {
+ SelectItem _selectItem = item.getSelectItem();
+ Object _operand = item.getOperand();
+ OperatorType _operator = item.getOperator();
+ if (null != _selectItem && _operand != null) {
+ ColumnType columnType = _selectItem.getExpectedColumnType();
+ if (columnType != null) {
+ if (columnType.isTimeBased()) {
+ // special logic for DB2 based time operands.
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(_selectItem.getSameQueryAlias(true));
+ final Object operand = FilterItem.appendOperator(sb, _operand, _operator);
+
+ if (operand instanceof SelectItem) {
+ final String selectItemString = ((SelectItem) operand).getSameQueryAlias(true);
+ sb.append(selectItemString);
+ } else {
+ Date date = TimeComparator.toDate(_operand);
+ if (date == null) {
+ throw new IllegalStateException("Could not convert " + _operand + " to date");
+ }
+
+ final String sqlValue = FormatHelper.formatSqlTime(columnType, date, true, "('", "')");
+ sb.append(sqlValue);
+ }
+
+ return sb.toString();
+ }
+ }
+ }
+ return super.rewriteFilterItem(item);
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/DefaultQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/DefaultQueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/DefaultQueryRewriter.java
new file mode 100644
index 0000000..d3356cd
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/DefaultQueryRewriter.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.jdbc.dialects;
+
+import java.util.List;
+import java.util.ListIterator;
+
+import org.eobjects.metamodel.jdbc.JdbcDataContext;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.OperatorType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.util.CollectionUtils;
+
+/**
+ * Generic query rewriter that adds syntax enhancements that are only possible
+ * to resolve just before execution time.
+ */
+public class DefaultQueryRewriter extends AbstractQueryRewriter {
+
+ private static final String SPECIAL_ALIAS_CHARACTERS = "- ,.|*%()!#¤/\\=?;:~";
+
+ public DefaultQueryRewriter(JdbcDataContext dataContext) {
+ super(dataContext);
+ }
+
+ @Override
+ protected Query beforeRewrite(Query query) {
+ query = query.clone();
+
+ JdbcDataContext dataContext = getDataContext();
+ if (dataContext != null) {
+ String identifierQuoteString = dataContext.getIdentifierQuoteString();
+ if (identifierQuoteString != null) {
+ List<SelectItem> selectItems = query.getSelectClause().getItems();
+ for (SelectItem item : selectItems) {
+ String alias = item.getAlias();
+ if (needsQuoting(alias, identifierQuoteString)) {
+ item.setAlias(identifierQuoteString + alias + identifierQuoteString);
+ }
+ }
+ List<FromItem> fromItems = query.getFromClause().getItems();
+ for (FromItem item : fromItems) {
+ String alias = item.getAlias();
+ if (needsQuoting(alias, identifierQuoteString)) {
+ item.setAlias(identifierQuoteString + alias + identifierQuoteString);
+ }
+ }
+ }
+ }
+ return query;
+ }
+
+ private boolean needsQuoting(String alias, String identifierQuoteString) {
+ boolean result = false;
+ if (alias != null && identifierQuoteString != null) {
+ if (alias.indexOf(identifierQuoteString) == -1) {
+ for (int i = 0; i < SPECIAL_ALIAS_CHARACTERS.length(); i++) {
+ char specialCharacter = SPECIAL_ALIAS_CHARACTERS.charAt(i);
+ if (alias.indexOf(specialCharacter) != -1) {
+ result = true;
+ break;
+ }
+ }
+ }
+ }
+ if (logger.isDebugEnabled()) {
+ logger.debug("needsQuoting(" + alias + "," + identifierQuoteString + ") = " + result);
+ }
+ return result;
+ }
+
+ @Override
+ public String rewriteFilterItem(FilterItem item) {
+ Object operand = item.getOperand();
+ if (operand != null) {
+ if (operand instanceof String) {
+ String str = (String) operand;
+ // escape single quotes
+ if (str.indexOf('\'') != -1) {
+ str = escapeQuotes(str);
+ FilterItem replacementFilterItem = new FilterItem(item.getSelectItem(), item.getOperator(), str);
+ return super.rewriteFilterItem(replacementFilterItem);
+ }
+ } else if (operand instanceof Iterable || operand.getClass().isArray()) {
+ // operand is a set of values (typically in combination with an
+ // IN operator). Each individual element must be escaped.
+
+ assert item.getOperator() == OperatorType.IN;
+
+ @SuppressWarnings("unchecked")
+ final List<Object> elements = (List<Object>) CollectionUtils.toList(operand);
+
+ for (ListIterator<Object> it = elements.listIterator(); it.hasNext();) {
+ Object next = it.next();
+ if (next == null) {
+ logger.warn("element in IN list is NULL, which isn't supported by SQL. Stripping the element from the list: {}", item);
+ it.remove();
+ } else if (next instanceof String) {
+ String str = (String) next;
+ if (str.indexOf('\'') != -1) {
+ str = escapeQuotes(str);
+ it.set(str);
+ }
+ }
+ }
+
+ FilterItem replacementFilterItem = new FilterItem(item.getSelectItem(), item.getOperator(), elements);
+ return super.rewriteFilterItem(replacementFilterItem);
+ }
+ }
+ return super.rewriteFilterItem(item);
+ }
+
+ @Override
+ public boolean isFirstRowSupported() {
+ return false;
+ }
+
+ @Override
+ public boolean isMaxRowsSupported() {
+ return false;
+ }
+
+ @Override
+ public String escapeQuotes(String item) {
+ return item.replaceAll("\\'", "\\'\\'");
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/H2QueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/H2QueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/H2QueryRewriter.java
new file mode 100644
index 0000000..f6d1c31
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/H2QueryRewriter.java
@@ -0,0 +1,31 @@
+/**
+ * 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.jdbc.dialects;
+
+import org.eobjects.metamodel.jdbc.JdbcDataContext;
+
+/**
+ * Query rewriter for H2
+ */
+public class H2QueryRewriter extends LimitOffsetQueryRewriter {
+
+ public H2QueryRewriter(JdbcDataContext dataContext) {
+ super(dataContext);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/HsqldbQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/HsqldbQueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/HsqldbQueryRewriter.java
new file mode 100644
index 0000000..36366cd
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/HsqldbQueryRewriter.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.jdbc.dialects;
+
+import org.eobjects.metamodel.jdbc.JdbcDataContext;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectClause;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+
+/**
+ * Query rewriter for HSQLDB
+ */
+public class HsqldbQueryRewriter extends DefaultQueryRewriter {
+
+ public HsqldbQueryRewriter(JdbcDataContext dataContext) {
+ super(dataContext);
+ }
+
+ @Override
+ public String rewriteColumnType(ColumnType columnType) {
+ if (columnType == ColumnType.BLOB) {
+ return "LONGVARBINARY";
+ }
+ return super.rewriteColumnType(columnType);
+ }
+
+ @Override
+ public boolean isFirstRowSupported() {
+ return true;
+ }
+
+ @Override
+ public boolean isMaxRowsSupported() {
+ return true;
+ }
+
+ @Override
+ protected String rewriteSelectClause(Query query, SelectClause selectClause) {
+ String result = super.rewriteSelectClause(query, selectClause);
+
+ Integer firstRow = query.getFirstRow();
+ Integer maxRows = query.getMaxRows();
+ if (maxRows != null || firstRow != null) {
+ if (maxRows == null) {
+ maxRows = Integer.MAX_VALUE;
+ }
+ if (firstRow == null || firstRow <= 0) {
+ result = "SELECT TOP " + maxRows + " " + result.substring(7);
+ } else {
+ final int offset = firstRow - 1;
+ result = "SELECT LIMIT " + offset + " " + maxRows + " " + result.substring(7);
+ }
+ }
+
+ return result;
+ }
+
+ @Override
+ public String rewriteFilterItem(FilterItem item) {
+ if (!item.isCompoundFilter()) {
+ final SelectItem selectItem = item.getSelectItem();
+ final Column column = selectItem.getColumn();
+ if (column != null) {
+ if (column.getType() == ColumnType.TIMESTAMP) {
+ // HSQLDB does not treat (TIMESTAMP 'yyyy-MM-dd hh:mm:ss')
+ // tokens correctly
+ String result = super.rewriteFilterItem(item);
+ int indexOfTimestamp = result.lastIndexOf("TIMESTAMP");
+ if (indexOfTimestamp != -1) {
+ result = result.substring(0, indexOfTimestamp)
+ + result.substring(indexOfTimestamp + "TIMESTAMP".length());
+ }
+ return result;
+ }
+ }
+ }
+ return super.rewriteFilterItem(item);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/IQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/IQueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/IQueryRewriter.java
new file mode 100644
index 0000000..4d94d40
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/IQueryRewriter.java
@@ -0,0 +1,93 @@
+/**
+ * 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.jdbc.dialects;
+
+import java.sql.Types;
+
+import org.eobjects.metamodel.jdbc.JdbcDataContext;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.ColumnType;
+
+/**
+ * A query rewriter can be used for rewriting (part of) a query's string
+ * representation. This is usefull for databases that deviate from the SQL 99
+ * compliant syntax which is delievered by the query and it's query item's
+ * toString() methods.
+ *
+ * @see AbstractQueryRewriter
+ * @see JdbcDataContext
+ */
+public interface IQueryRewriter {
+
+ public String rewriteFromItem(FromItem item);
+
+ public String rewriteQuery(Query query);
+
+ public String rewriteFilterItem(FilterItem whereItem);
+
+ /**
+ * Gets whether this query rewriter is able to write the "Max rows" query
+ * property to the query string.
+ *
+ * @return whether this query rewriter is able to write the "Max rows" query
+ * property to the query string.
+ */
+ public boolean isMaxRowsSupported();
+
+ /**
+ * Gets whether this query rewriter is able to write the "First row" query
+ * property to the query string.
+ *
+ * @return whether this query rewriter is able to write the "First row"
+ * query property to the query string.
+ */
+ public boolean isFirstRowSupported();
+
+ /**
+ * Escapes the quotes within a String literal of a query item.
+ *
+ * @return String item with quotes escaped.
+ */
+ public String escapeQuotes(String item);
+
+ /**
+ * Rewrites the name of a column type, as it is written in CREATE TABLE
+ * statements. Some databases dont support all column types, or have
+ * different names for them. The implementation of this method will do that
+ * conversion.
+ *
+ * @param columnType
+ * @return
+ */
+ public String rewriteColumnType(ColumnType columnType);
+
+ /**
+ * Gets the column type for a specific JDBC type (as defined in
+ * {@link Types}), native type name and column size.
+ *
+ * @param jdbcType
+ * @param nativeType
+ * @param columnSize
+ * @return
+ */
+ public ColumnType getColumnType(int jdbcType, String nativeType, Integer columnSize);
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/LimitOffsetQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/LimitOffsetQueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/LimitOffsetQueryRewriter.java
new file mode 100644
index 0000000..76a35a8
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/LimitOffsetQueryRewriter.java
@@ -0,0 +1,71 @@
+/**
+ * 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.jdbc.dialects;
+
+import org.eobjects.metamodel.jdbc.JdbcDataContext;
+import org.eobjects.metamodel.query.Query;
+
+/**
+ * Query rewriter for databases that support LIMIT and OFFSET keywords for max
+ * rows and first row properties.
+ */
+public abstract class LimitOffsetQueryRewriter extends DefaultQueryRewriter {
+
+ public LimitOffsetQueryRewriter(JdbcDataContext dataContext) {
+ super(dataContext);
+ }
+
+ @Override
+ public final boolean isFirstRowSupported() {
+ return true;
+ }
+
+ @Override
+ public final boolean isMaxRowsSupported() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * If the Max rows and/or First row property of the query is set, then we
+ * will use the database's LIMIT and OFFSET functions.
+ */
+ @Override
+ public String rewriteQuery(Query query) {
+ String queryString = super.rewriteQuery(query);
+ Integer maxRows = query.getMaxRows();
+ Integer firstRow = query.getFirstRow();
+ if (maxRows != null || firstRow != null) {
+ if (maxRows == null) {
+ maxRows = Integer.MAX_VALUE;
+ }
+ queryString = queryString + " LIMIT " + maxRows;
+
+ if (firstRow != null && firstRow > 1) {
+ // offset is 0-based
+ int offset = firstRow - 1;
+ queryString = queryString + " OFFSET " + offset;
+ }
+ }
+
+
+ return queryString;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/MysqlQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/MysqlQueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/MysqlQueryRewriter.java
new file mode 100644
index 0000000..88757be
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/MysqlQueryRewriter.java
@@ -0,0 +1,36 @@
+/**
+ * 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.jdbc.dialects;
+
+import org.eobjects.metamodel.jdbc.JdbcDataContext;
+
+/**
+ * Query rewriter for MySQL
+ */
+public class MysqlQueryRewriter extends LimitOffsetQueryRewriter implements IQueryRewriter {
+
+ public MysqlQueryRewriter(JdbcDataContext dataContext) {
+ super(dataContext);
+ }
+
+ @Override
+ public String escapeQuotes(String filterItemOperand) {
+ return filterItemOperand.replaceAll("\\'", "\\\\'");
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/PostgresqlQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/PostgresqlQueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/PostgresqlQueryRewriter.java
new file mode 100644
index 0000000..d303c50
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/PostgresqlQueryRewriter.java
@@ -0,0 +1,70 @@
+/**
+ * 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.jdbc.dialects;
+
+import org.eobjects.metamodel.jdbc.JdbcDataContext;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * Query rewriter for PostgreSQL
+ */
+public class PostgresqlQueryRewriter extends LimitOffsetQueryRewriter implements IQueryRewriter {
+
+ public PostgresqlQueryRewriter(JdbcDataContext dataContext) {
+ super(dataContext);
+ }
+
+ @Override
+ public ColumnType getColumnType(int jdbcType, String nativeType, Integer columnSize) {
+ if ("bool".equals(nativeType)) {
+ // override the normal behaviour of postgresql which maps "bool" to
+ // a BIT.
+ return ColumnType.BOOLEAN;
+ }
+ return super.getColumnType(jdbcType, nativeType, columnSize);
+ }
+
+ @Override
+ public String rewriteColumnType(ColumnType columnType) {
+ if (columnType == ColumnType.BLOB) {
+ return "bytea";
+ }
+ return super.rewriteColumnType(columnType);
+ }
+
+ @Override
+ protected String rewriteFromItem(Query query, FromItem item) {
+ String result = super.rewriteFromItem(query, item);
+ Table table = item.getTable();
+ if (table != null) {
+ Schema schema = table.getSchema();
+ if (schema != null) {
+ String schemaName = schema.getName();
+ if (schemaName != null) {
+ result = result.replaceFirst(schemaName, '\"' + schema.getName() + '\"');
+ }
+ }
+ }
+ return result;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/SQLServerQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/SQLServerQueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/SQLServerQueryRewriter.java
new file mode 100644
index 0000000..732ec34
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/SQLServerQueryRewriter.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.jdbc.dialects;
+
+import org.eobjects.metamodel.jdbc.JdbcDataContext;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectClause;
+
+public class SQLServerQueryRewriter extends DefaultQueryRewriter {
+
+ public SQLServerQueryRewriter(JdbcDataContext dataContext) {
+ super(dataContext);
+ }
+
+ @Override
+ public boolean isMaxRowsSupported() {
+ return true;
+ }
+
+ /**
+ * SQL server expects the fully qualified column name, including schema, in
+ * select items.
+ */
+ @Override
+ public boolean isSchemaIncludedInColumnPaths() {
+ return true;
+ }
+
+ @Override
+ protected String rewriteSelectClause(Query query, SelectClause selectClause) {
+ String result = super.rewriteSelectClause(query, selectClause);
+
+ Integer maxRows = query.getMaxRows();
+ if (maxRows != null) {
+ result = "SELECT TOP " + maxRows + " " + result.substring(7);
+ }
+
+ return result;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/package-info.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/package-info.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/package-info.java
new file mode 100644
index 0000000..fac1963
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/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.
+ */
+/**
+ * Module package for JDBC compliant databases
+ */
+package org.eobjects.metamodel.jdbc;
+
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/FetchSizeCalculator.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/FetchSizeCalculator.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/FetchSizeCalculator.java
deleted file mode 100644
index 155adf9..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/FetchSizeCalculator.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.util.List;
-
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Class used to calculate an appropriate fetch size of a JDBC query.
- *
- * The approach used in this class is largely based on the documentation of
- * Oracle's caching size, see <a href=
- * "http://www.oracle.com/technetwork/database/enterprise-edition/memory.pdf"
- * >JDBC Memory Management</a>, section "Where does it all go?".
- *
- * @author Kasper Sørensen
- */
-final class FetchSizeCalculator {
-
- /**
- * 22 bytes is a reasonable approximation for remaining row types, we add a
- * few bytes to be on the safe side.
- */
- private static final int DEFAULT_COLUMN_SIZE = 30;
-
- /**
- * A kilobyte (kb)
- */
- private static final int KB = 1024;
-
- private static final Logger logger = LoggerFactory
- .getLogger(FetchSizeCalculator.class);
-
- private static final int MIN_FETCH_SIZE = 1;
- private static final int MAX_FETCH_SIZE = 25000;
- private final int _bytesInMemory;
-
- public FetchSizeCalculator(int bytesInMemory) {
- _bytesInMemory = bytesInMemory;
- }
-
- /**
- * Gets the fetch size of a query
- *
- * @param query
- * the query to execute
- * @return an integer representing how many rows to eagerly fetch for the
- * query
- */
- public int getFetchSize(Query query) {
- if (isSingleRowQuery(query)) {
- return 1;
- }
- int bytesPerRow = getRowSize(query);
- int result = getFetchSize(bytesPerRow);
- final Integer maxRows = query.getMaxRows();
- if (maxRows != null && result > maxRows) {
- logger.debug("Result ({}) was below max rows ({}), adjusting.",
- result, maxRows);
- result = maxRows;
- }
- return result;
- }
-
- /**
- * Gets whether a query is guaranteed to only yield a single row. Such
- * queries are queries that only consist of aggregation functions and no
- * group by clause.
- *
- * @param query
- * @return
- */
- private boolean isSingleRowQuery(Query query) {
- if (!query.getGroupByClause().isEmpty()) {
- return false;
- }
-
- List<SelectItem> items = query.getSelectClause().getItems();
- for (SelectItem item : items) {
- if (item.getFunction() == null) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Gets the fetch size of a query based on the columns to query.
- *
- * @param columns
- * the columns to query
- * @return an integer representing how many rows to eagerly fetch for the
- * query
- */
- public int getFetchSize(Column... columns) {
- int bytesPerRow = getRowSize(columns);
- return getFetchSize(bytesPerRow);
- }
-
- /**
- * Gets the size of a row (in bytes).
- *
- * @param query
- * the query that will yield the rows
- * @return an integer representing the size of a row from the given query
- * (in bytes).
- */
- protected int getRowSize(Query query) {
- List<SelectItem> items = query.getSelectClause().getItems();
- int bytesPerRow = 0;
- for (SelectItem selectItem : items) {
- bytesPerRow += getValueSize(selectItem);
- }
- return bytesPerRow;
- }
-
- /**
- * Gets the size of a row (in bytes).
- *
- * @param columns
- * the columns in the row
- * @return an integer representing the size of a row with the given columns
- * (in bytes).
- */
- protected int getRowSize(Column... columns) {
- int bytesPerRow = 0;
- for (Column column : columns) {
- bytesPerRow += getValueSize(column);
- }
- return bytesPerRow;
- }
-
- /**
- * Gets the principal fetch size for a query where a row has the given size.
- *
- * @param bytesPerRow
- * the size (in bytes) of a single row in the result set.
- * @return an appropriate fetch size.
- */
- protected int getFetchSize(int bytesPerRow) {
- if (bytesPerRow == 0) {
- // prevent divide by zero
- return MAX_FETCH_SIZE;
- }
- int result = _bytesInMemory / bytesPerRow;
- if (result < MIN_FETCH_SIZE) {
- logger.debug(
- "Result ({}) was below minimum fetch size ({}), adjusting.",
- result, MIN_FETCH_SIZE);
- result = MIN_FETCH_SIZE;
- } else if (result > MAX_FETCH_SIZE) {
- logger.debug(
- "Result ({}) was above maximum fetch size ({}), adjusting.",
- result, MAX_FETCH_SIZE);
- result = MAX_FETCH_SIZE;
- }
- return result;
- }
-
- /**
- * Gets the size (in bytes) of a single {@link SelectItem}
- */
- protected int getValueSize(SelectItem selectItem) {
- Column column = selectItem.getColumn();
- if (column == null) {
- return DEFAULT_COLUMN_SIZE;
- } else {
- return getValueSize(column);
- }
- }
-
- /**
- * Gets the size (in bytes) of a single {@link Column}
- */
- protected int getValueSize(Column column) {
- ColumnType type = column.getType();
- if (type == null) {
- return DEFAULT_COLUMN_SIZE;
- } else {
- Integer columnSize = column.getColumnSize();
- if (columnSize == null) {
- // if column size is missing, then use
- // size-indifferent approach
- return getSize(type);
- } else if (columnSize > 10000 && !type.isLargeObject()) {
- // if column size is unrealistically high, then use
- // size-indifferent approach
- return getSize(type);
- } else {
- return getSize(type, columnSize);
- }
- }
- }
-
- /**
- * Gets the size (in bytes) of a column with a specific {@link ColumnType}
- * and size
- */
- private int getSize(ColumnType type, int columnSize) {
- final int baseSize;
- if (type.isBinary()) {
- baseSize = 1;
- } else if (type.isBoolean()) {
- baseSize = 1;
- } else if (type.isLiteral()) {
- baseSize = 2;
- } else if (type.isNumber()) {
- baseSize = 16;
- } else {
- baseSize = DEFAULT_COLUMN_SIZE;
- }
-
- int result = baseSize * columnSize;
-
- if (type.isLargeObject()) {
- // assign at least 4KB for LOBs.
- result = Math.max(result, 4 * KB);
- }
-
- return result;
- }
-
- /**
- * Gets the (approximate) size (in bytes) of a column with a specific
- * {@link ColumnType}.
- */
- private int getSize(ColumnType type) {
- if (type.isBinary()) {
- return 4 * KB;
- } else if (type.isBoolean()) {
- return 2;
- } else if (type.isLargeObject()) {
- return 4 * KB;
- } else if (type.isLiteral()) {
- return KB;
- } else if (type.isNumber()) {
- return 16;
- } else {
- return DEFAULT_COLUMN_SIZE;
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcBatchUpdateCallback.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcBatchUpdateCallback.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcBatchUpdateCallback.java
deleted file mode 100644
index 1fe31d3..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcBatchUpdateCallback.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.util.FileHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Jdbc {@link UpdateCallback} for databases that support the JDBC Batch
- * features.
- *
- * @author Kasper Sørensen
- */
-final class JdbcBatchUpdateCallback extends JdbcUpdateCallback {
-
- private static final Logger logger = LoggerFactory.getLogger(JdbcBatchUpdateCallback.class);
-
- public JdbcBatchUpdateCallback(JdbcDataContext dataContext) {
- super(dataContext);
- }
-
- @Override
- protected void closePreparedStatement(PreparedStatement preparedStatement) {
- try {
- int[] results = preparedStatement.executeBatch();
- if (logger.isDebugEnabled()) {
- for (int i = 0; i < results.length; i++) {
- int result = results[i];
- final String resultString;
- switch (result) {
- case Statement.SUCCESS_NO_INFO:
- resultString = "SUCCESS_NO_INFO";
- break;
- case Statement.EXECUTE_FAILED:
- resultString = "EXECUTE_FAILED";
- break;
- default:
- resultString = result + " rows updated";
- }
- logger.debug("batch execute result[" + i + "]:" + resultString);
- }
- }
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "execute batch: " + preparedStatement);
- } finally {
- FileHelper.safeClose(preparedStatement);
- }
- }
-
- @Override
- protected void executePreparedStatement(PreparedStatement st) throws SQLException {
- st.addBatch();
- }
-}
[46/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/intercept/InterceptableColumnCreationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/InterceptableColumnCreationBuilder.java b/core/src/main/java/org/apache/metamodel/intercept/InterceptableColumnCreationBuilder.java
new file mode 100644
index 0000000..1ce3092
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/intercept/InterceptableColumnCreationBuilder.java
@@ -0,0 +1,102 @@
+/**
+ * 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.intercept;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.create.ColumnCreationBuilder;
+import org.eobjects.metamodel.create.TableCreationBuilder;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.Table;
+
+final class InterceptableColumnCreationBuilder implements ColumnCreationBuilder {
+
+ private final ColumnCreationBuilder _columnCreationBuilder;
+ private final InterceptableTableCreationBuilder _tableCreationBuilder;
+
+ public InterceptableColumnCreationBuilder(
+ ColumnCreationBuilder columnCreationBuilder,
+ InterceptableTableCreationBuilder tableCreationBuilder) {
+ _columnCreationBuilder = columnCreationBuilder;
+ _tableCreationBuilder = tableCreationBuilder;
+ }
+
+ @Override
+ public String toSql() {
+ return _tableCreationBuilder.toSql();
+ }
+
+ @Override
+ public TableCreationBuilder like(Table table) {
+ return _tableCreationBuilder.like(table);
+ }
+
+ @Override
+ public ColumnCreationBuilder withColumn(String name) {
+ _columnCreationBuilder.withColumn(name);
+ return this;
+ }
+
+ @Override
+ public Table toTable() {
+ return _tableCreationBuilder.toTable();
+ }
+
+ @Override
+ public Table execute() throws MetaModelException {
+ return _tableCreationBuilder.execute();
+ }
+
+ @Override
+ public ColumnCreationBuilder like(Column column) {
+ _columnCreationBuilder.like(column);
+ return this;
+ }
+
+ @Override
+ public ColumnCreationBuilder asPrimaryKey() {
+ _columnCreationBuilder.asPrimaryKey();
+ return this;
+ }
+
+ @Override
+ public ColumnCreationBuilder ofType(ColumnType type) {
+ _columnCreationBuilder.ofType(type);
+ return this;
+ }
+
+ @Override
+ public ColumnCreationBuilder ofNativeType(String nativeType) {
+ _columnCreationBuilder.ofNativeType(nativeType);
+ return this;
+ }
+
+ @Override
+ public ColumnCreationBuilder ofSize(int size) {
+ _columnCreationBuilder.ofSize(size);
+ return this;
+ }
+
+ @Override
+ public ColumnCreationBuilder nullable(boolean nullable) {
+ _columnCreationBuilder.nullable(nullable);
+ return this;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/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
new file mode 100644
index 0000000..63a6dc2
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/intercept/InterceptableDataContext.java
@@ -0,0 +1,284 @@
+/**
+ * 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.intercept;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.UpdateableDataContext;
+import org.eobjects.metamodel.create.TableCreationBuilder;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.delete.RowDeletionBuilder;
+import org.eobjects.metamodel.drop.TableDropBuilder;
+import org.eobjects.metamodel.insert.RowInsertionBuilder;
+import org.eobjects.metamodel.query.CompiledQuery;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.builder.InitFromBuilder;
+import org.eobjects.metamodel.query.builder.InitFromBuilderImpl;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.update.RowUpdationBuilder;
+import org.eobjects.metamodel.util.HasNameMapper;
+
+public class InterceptableDataContext implements UpdateableDataContext {
+
+ private final DataContext _delegate;
+ private final InterceptorList<DataSet> _dataSetInterceptors;
+ private final InterceptorList<Query> _queryInterceptors;
+ private final InterceptorList<Schema> _schemaInterceptors;
+ private final InterceptorList<RowInsertionBuilder> _rowInsertionInterceptors;
+ private final InterceptorList<RowUpdationBuilder> _rowUpdationInterceptors;
+ private final InterceptorList<RowDeletionBuilder> _rowDeletionInterceptors;
+ private final InterceptorList<TableCreationBuilder> _tableCreationInterceptors;
+ private final InterceptorList<TableDropBuilder> _tableDropInterceptors;
+
+ protected InterceptableDataContext(DataContext delegate) {
+ _delegate = delegate;
+ _dataSetInterceptors = new InterceptorList<DataSet>();
+ _queryInterceptors = new InterceptorList<Query>();
+ _schemaInterceptors = new InterceptorList<Schema>();
+ _rowInsertionInterceptors = new InterceptorList<RowInsertionBuilder>();
+ _rowUpdationInterceptors = new InterceptorList<RowUpdationBuilder>();
+ _rowDeletionInterceptors = new InterceptorList<RowDeletionBuilder>();
+ _tableCreationInterceptors = new InterceptorList<TableCreationBuilder>();
+ _tableDropInterceptors = new InterceptorList<TableDropBuilder>();
+ }
+
+ public InterceptableDataContext addTableCreationInterceptor(TableCreationInterceptor interceptor) {
+ _tableCreationInterceptors.add(interceptor);
+ return this;
+ }
+
+ public InterceptableDataContext removeTableCreationInterceptor(TableCreationInterceptor interceptor) {
+ _tableCreationInterceptors.remove(interceptor);
+ return this;
+ }
+
+ public InterceptableDataContext addTableDropInterceptor(TableDropInterceptor interceptor) {
+ _tableDropInterceptors.add(interceptor);
+ return this;
+ }
+
+ public InterceptableDataContext removeTableDropInterceptor(TableDropInterceptor interceptor) {
+ _tableDropInterceptors.remove(interceptor);
+ return this;
+ }
+
+ public InterceptableDataContext addRowInsertionInterceptor(RowInsertionInterceptor interceptor) {
+ _rowInsertionInterceptors.add(interceptor);
+ return this;
+ }
+
+ public InterceptableDataContext removeRowInsertionInterceptor(RowInsertionInterceptor interceptor) {
+ _rowInsertionInterceptors.remove(interceptor);
+ return this;
+ }
+
+ public InterceptableDataContext addRowUpdationInterceptor(RowUpdationInterceptor interceptor) {
+ _rowUpdationInterceptors.add(interceptor);
+ return this;
+ }
+
+ public InterceptableDataContext removeRowUpdationInterceptor(RowUpdationInterceptor interceptor) {
+ _rowUpdationInterceptors.remove(interceptor);
+ return this;
+ }
+
+ public InterceptableDataContext addRowDeletionInterceptor(RowDeletionInterceptor interceptor) {
+ _rowDeletionInterceptors.add(interceptor);
+ return this;
+ }
+
+ public InterceptableDataContext removeRowDeletionInterceptor(RowDeletionInterceptor interceptor) {
+ _rowDeletionInterceptors.remove(interceptor);
+ return this;
+ }
+
+ public InterceptableDataContext addQueryInterceptor(QueryInterceptor interceptor) {
+ _queryInterceptors.add(interceptor);
+ return this;
+ }
+
+ public InterceptableDataContext removeQueryInterceptor(QueryInterceptor interceptor) {
+ _queryInterceptors.remove(interceptor);
+ return this;
+ }
+
+ public InterceptableDataContext addSchemaInterceptor(SchemaInterceptor interceptor) {
+ _schemaInterceptors.add(interceptor);
+ return this;
+ }
+
+ public InterceptableDataContext removeSchemaInterceptor(SchemaInterceptor interceptor) {
+ _schemaInterceptors.remove(interceptor);
+ return this;
+ }
+
+ public InterceptableDataContext addDataSetInterceptor(DataSetInterceptor interceptor) {
+ _dataSetInterceptors.add(interceptor);
+ return this;
+ }
+
+ public InterceptableDataContext removeDataSetInterceptor(DataSetInterceptor interceptor) {
+ _dataSetInterceptors.remove(interceptor);
+ return this;
+ }
+
+ public InterceptorList<DataSet> getDataSetInterceptors() {
+ return _dataSetInterceptors;
+ }
+
+ public InterceptorList<Query> getQueryInterceptors() {
+ return _queryInterceptors;
+ }
+
+ public InterceptorList<RowInsertionBuilder> getRowInsertionInterceptors() {
+ return _rowInsertionInterceptors;
+ }
+
+ public InterceptorList<RowUpdationBuilder> getRowUpdationInterceptors() {
+ return _rowUpdationInterceptors;
+ }
+
+ public InterceptorList<RowDeletionBuilder> getRowDeletionInterceptors() {
+ return _rowDeletionInterceptors;
+ }
+
+ public InterceptorList<Schema> getSchemaInterceptors() {
+ return _schemaInterceptors;
+ }
+
+ public InterceptorList<TableCreationBuilder> getTableCreationInterceptors() {
+ return _tableCreationInterceptors;
+ }
+
+ public DataContext getDelegate() {
+ return _delegate;
+ }
+
+ @Override
+ public DataSet executeQuery(Query query) throws MetaModelException {
+ query = _queryInterceptors.interceptAll(query);
+ DataSet dataSet = _delegate.executeQuery(query);
+ dataSet = _dataSetInterceptors.interceptAll(dataSet);
+ return dataSet;
+ }
+
+ @Override
+ public UpdateableDataContext refreshSchemas() {
+ _delegate.refreshSchemas();
+ return this;
+ }
+
+ @Override
+ public Schema[] getSchemas() throws MetaModelException {
+ Schema[] schemas = _delegate.getSchemas();
+ if (!_schemaInterceptors.isEmpty()) {
+ for (int i = 0; i < schemas.length; i++) {
+ schemas[i] = _schemaInterceptors.interceptAll(schemas[i]);
+ }
+ }
+ return schemas;
+ }
+
+ @Override
+ public 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().eval(schemas[i]);
+ }
+ return schemaNames;
+ }
+
+ @Override
+ public Schema getDefaultSchema() throws MetaModelException {
+ Schema schema = _delegate.getDefaultSchema();
+ schema = _schemaInterceptors.interceptAll(schema);
+ return schema;
+ }
+
+ @Override
+ public Schema getSchemaByName(String name) throws MetaModelException {
+ Schema schema = _delegate.getSchemaByName(name);
+ schema = _schemaInterceptors.interceptAll(schema);
+ return schema;
+ }
+
+ @Override
+ public InitFromBuilder query() {
+ return new InitFromBuilderImpl(this);
+ }
+
+ @Override
+ public Column getColumnByQualifiedLabel(String columnName) {
+ return _delegate.getColumnByQualifiedLabel(columnName);
+ }
+
+ @Override
+ public Table getTableByQualifiedLabel(String tableName) {
+ return _delegate.getTableByQualifiedLabel(tableName);
+ }
+
+ @Override
+ public void executeUpdate(UpdateScript update) {
+ if (!(_delegate instanceof UpdateableDataContext)) {
+ throw new UnsupportedOperationException("Delegate is not an UpdateableDataContext");
+ }
+ final UpdateableDataContext delegate = (UpdateableDataContext) _delegate;
+
+ if (_tableCreationInterceptors.isEmpty() && _tableDropInterceptors.isEmpty()
+ && _rowInsertionInterceptors.isEmpty() && _rowUpdationInterceptors.isEmpty()
+ && _rowDeletionInterceptors.isEmpty()) {
+ delegate.executeUpdate(update);
+ return;
+ }
+
+ UpdateScript interceptableUpdateScript = new InterceptableUpdateScript(this, update,
+ _tableCreationInterceptors, _tableDropInterceptors, _rowInsertionInterceptors,
+ _rowUpdationInterceptors, _rowDeletionInterceptors);
+ delegate.executeUpdate(interceptableUpdateScript);
+ }
+
+ @Override
+ public Query parseQuery(String queryString) throws MetaModelException {
+ return _delegate.parseQuery(queryString);
+ }
+
+ @Override
+ public DataSet executeQuery(String queryString) throws MetaModelException {
+ final Query query = parseQuery(queryString);
+ final DataSet dataSet = executeQuery(query);
+ return dataSet;
+ }
+
+ @Override
+ public CompiledQuery compileQuery(Query query) {
+ return _delegate.compileQuery(query);
+ }
+
+ @Override
+ public DataSet executeQuery(CompiledQuery compiledQuery, Object... values) {
+ return _delegate.executeQuery(compiledQuery, values);
+ }
+}
\ 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/intercept/InterceptableRowDeletionBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowDeletionBuilder.java b/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowDeletionBuilder.java
new file mode 100644
index 0000000..8a1d516
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowDeletionBuilder.java
@@ -0,0 +1,87 @@
+/**
+ * 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.intercept;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.delete.RowDeletionBuilder;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.query.builder.AbstractFilterBuilder;
+import org.eobjects.metamodel.query.builder.FilterBuilder;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+
+final class InterceptableRowDeletionBuilder implements RowDeletionBuilder {
+
+ private final RowDeletionBuilder _rowDeletionBuilder;
+ private final InterceptorList<RowDeletionBuilder> _rowDeletionInterceptors;
+
+ public InterceptableRowDeletionBuilder(RowDeletionBuilder rowDeletionBuilder,
+ InterceptorList<RowDeletionBuilder> rowDeletionInterceptors) {
+ _rowDeletionBuilder = rowDeletionBuilder;
+ _rowDeletionInterceptors = rowDeletionInterceptors;
+ }
+
+ @Override
+ public FilterBuilder<RowDeletionBuilder> where(Column column) {
+ final SelectItem selectItem = new SelectItem(column);
+ return new AbstractFilterBuilder<RowDeletionBuilder>(selectItem) {
+ @Override
+ protected RowDeletionBuilder applyFilter(FilterItem filter) {
+ return where(filter);
+ }
+ };
+ }
+
+ @Override
+ public FilterBuilder<RowDeletionBuilder> where(String columnName) {
+ Column column = getTable().getColumnByName(columnName);
+ return where(column);
+ }
+
+ @Override
+ public RowDeletionBuilder where(FilterItem... filterItems) {
+ _rowDeletionBuilder.where(filterItems);
+ return this;
+ }
+
+ @Override
+ public RowDeletionBuilder where(Iterable<FilterItem> filterItems) {
+ _rowDeletionBuilder.where(filterItems);
+ return this;
+ }
+
+ @Override
+ public Table getTable() {
+ return _rowDeletionBuilder.getTable();
+ }
+
+ @Override
+ public String toSql() {
+ return _rowDeletionBuilder.toSql();
+ }
+
+ @Override
+ public void execute() throws MetaModelException {
+ RowDeletionBuilder rowDeletionBuilder = _rowDeletionBuilder;
+ rowDeletionBuilder = _rowDeletionInterceptors.interceptAll(rowDeletionBuilder);
+ rowDeletionBuilder.execute();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowInsertionBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowInsertionBuilder.java b/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowInsertionBuilder.java
new file mode 100644
index 0000000..3a0228b
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowInsertionBuilder.java
@@ -0,0 +1,111 @@
+/**
+ * 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.intercept;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.data.Style;
+import org.eobjects.metamodel.insert.RowInsertionBuilder;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+
+final class InterceptableRowInsertionBuilder implements RowInsertionBuilder {
+
+ private final RowInsertionBuilder _rowInsertionBuilder;
+ private final InterceptorList<RowInsertionBuilder> _rowInsertionInterceptors;
+
+ public InterceptableRowInsertionBuilder(
+ RowInsertionBuilder rowInsertionBuilder,
+ InterceptorList<RowInsertionBuilder> rowInsertionInterceptors) {
+ _rowInsertionBuilder = rowInsertionBuilder;
+ _rowInsertionInterceptors = rowInsertionInterceptors;
+ }
+
+ @Override
+ public String toSql() {
+ return _rowInsertionBuilder.toSql();
+ }
+
+ @Override
+ public RowInsertionBuilder value(int columnIndex, Object value) {
+ _rowInsertionBuilder.value(columnIndex, value);
+ return this;
+ }
+
+ @Override
+ public RowInsertionBuilder value(int columnIndex, Object value, Style style) {
+ _rowInsertionBuilder.value(columnIndex, value, style);
+ return this;
+ }
+
+ @Override
+ public RowInsertionBuilder value(Column column, Object value) {
+ _rowInsertionBuilder.value(column, value);
+ return this;
+ }
+
+ @Override
+ public RowInsertionBuilder value(Column column, Object value, Style style) {
+ _rowInsertionBuilder.value(column, value, style);
+ return this;
+ }
+
+ @Override
+ public RowInsertionBuilder value(String columnName, Object value) {
+ _rowInsertionBuilder.value(columnName, value);
+ return this;
+ }
+
+ @Override
+ public RowInsertionBuilder like(Row row) {
+ _rowInsertionBuilder.like(row);
+ return this;
+ }
+
+ @Override
+ public RowInsertionBuilder value(String columnName, Object value,
+ Style style) {
+ _rowInsertionBuilder.value(columnName, value, style);
+ return this;
+ }
+
+ @Override
+ public void execute() throws MetaModelException {
+ RowInsertionBuilder rowInsertionBuilder = _rowInsertionBuilder;
+ rowInsertionBuilder = _rowInsertionInterceptors
+ .interceptAll(rowInsertionBuilder);
+ rowInsertionBuilder.execute();
+ }
+
+ @Override
+ public Row toRow() {
+ return _rowInsertionBuilder.toRow();
+ }
+
+ @Override
+ public Table getTable() {
+ return _rowInsertionBuilder.getTable();
+ }
+
+ @Override
+ public boolean isSet(Column column) {
+ return _rowInsertionBuilder.isSet(column);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowUpdationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowUpdationBuilder.java b/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowUpdationBuilder.java
new file mode 100644
index 0000000..d5dbc16
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowUpdationBuilder.java
@@ -0,0 +1,136 @@
+/**
+ * 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.intercept;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.data.Style;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.query.builder.AbstractFilterBuilder;
+import org.eobjects.metamodel.query.builder.FilterBuilder;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.update.RowUpdationBuilder;
+
+final class InterceptableRowUpdationBuilder implements RowUpdationBuilder {
+
+ private final RowUpdationBuilder _rowUpdationBuilder;
+ private final InterceptorList<RowUpdationBuilder> _rowUpdationInterceptors;
+
+ public InterceptableRowUpdationBuilder(RowUpdationBuilder rowUpdationBuilder,
+ InterceptorList<RowUpdationBuilder> rowUpdationInterceptors) {
+ _rowUpdationBuilder = rowUpdationBuilder;
+ _rowUpdationInterceptors = rowUpdationInterceptors;
+ }
+
+ @Override
+ public RowUpdationBuilder value(int columnIndex, Object value) {
+ _rowUpdationBuilder.value(columnIndex, value);
+ return this;
+ }
+
+ @Override
+ public RowUpdationBuilder value(int columnIndex, Object value, Style style) {
+ _rowUpdationBuilder.value(columnIndex, value, style);
+ return this;
+ }
+
+ @Override
+ public RowUpdationBuilder value(Column column, Object value) {
+ _rowUpdationBuilder.value(column, value);
+ return this;
+ }
+
+ @Override
+ public RowUpdationBuilder value(Column column, Object value, Style style) {
+ _rowUpdationBuilder.value(column, value, style);
+ return this;
+ }
+
+ @Override
+ public RowUpdationBuilder value(String columnName, Object value) {
+ _rowUpdationBuilder.value(columnName, value);
+ return this;
+ }
+
+ @Override
+ public RowUpdationBuilder value(String columnName, Object value, Style style) {
+ _rowUpdationBuilder.value(columnName, value, style);
+ return this;
+ }
+
+ @Override
+ public Row toRow() {
+ return _rowUpdationBuilder.toRow();
+ }
+
+ @Override
+ public boolean isSet(Column column) {
+ return _rowUpdationBuilder.isSet(column);
+ }
+
+ @Override
+ public FilterBuilder<RowUpdationBuilder> where(Column column) {
+ final SelectItem selectItem = new SelectItem(column);
+ return new AbstractFilterBuilder<RowUpdationBuilder>(selectItem) {
+ @Override
+ protected RowUpdationBuilder applyFilter(FilterItem filter) {
+ where(filter);
+ return InterceptableRowUpdationBuilder.this;
+ }
+ };
+ }
+
+ @Override
+ public FilterBuilder<RowUpdationBuilder> where(String columnName) {
+ Column column = getTable().getColumnByName(columnName);
+ return where(column);
+ }
+
+ @Override
+ public RowUpdationBuilder where(FilterItem... filterItems) {
+ _rowUpdationBuilder.where(filterItems);
+ return this;
+ }
+
+ @Override
+ public RowUpdationBuilder where(Iterable<FilterItem> filterItems) {
+ _rowUpdationBuilder.where(filterItems);
+ return this;
+ }
+
+ @Override
+ public String toSql() {
+ return _rowUpdationBuilder.toSql();
+ }
+
+ @Override
+ public Table getTable() {
+ return _rowUpdationBuilder.getTable();
+ }
+
+ @Override
+ public void execute() throws MetaModelException {
+ RowUpdationBuilder rowUpdationBuilder = _rowUpdationBuilder;
+ rowUpdationBuilder = _rowUpdationInterceptors.interceptAll(rowUpdationBuilder);
+ rowUpdationBuilder.execute();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/intercept/InterceptableTableCreationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/InterceptableTableCreationBuilder.java b/core/src/main/java/org/apache/metamodel/intercept/InterceptableTableCreationBuilder.java
new file mode 100644
index 0000000..0976113
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/intercept/InterceptableTableCreationBuilder.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.intercept;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.create.ColumnCreationBuilder;
+import org.eobjects.metamodel.create.TableCreationBuilder;
+import org.eobjects.metamodel.schema.Table;
+
+final class InterceptableTableCreationBuilder implements TableCreationBuilder {
+
+ private final TableCreationBuilder _tabelCreationBuilder;
+ private final InterceptorList<TableCreationBuilder> _tableCreationInterceptors;
+
+ public InterceptableTableCreationBuilder(
+ TableCreationBuilder tabelCreationBuilder,
+ InterceptorList<TableCreationBuilder> tableCreationInterceptors) {
+ _tabelCreationBuilder = tabelCreationBuilder;
+ _tableCreationInterceptors = tableCreationInterceptors;
+ }
+
+ @Override
+ public String toSql() {
+ return _tabelCreationBuilder.toSql();
+ }
+
+ @Override
+ public TableCreationBuilder like(Table table) {
+ _tabelCreationBuilder.like(table);
+ return this;
+ }
+
+ @Override
+ public ColumnCreationBuilder withColumn(String name) {
+ ColumnCreationBuilder columnCreationBuilder = _tabelCreationBuilder
+ .withColumn(name);
+ return new InterceptableColumnCreationBuilder(columnCreationBuilder,
+ this);
+ }
+
+ @Override
+ public Table toTable() {
+ return _tabelCreationBuilder.toTable();
+ }
+
+ @Override
+ public Table execute() throws MetaModelException {
+ TableCreationBuilder tableCreationBuilder = _tabelCreationBuilder;
+ tableCreationBuilder = _tableCreationInterceptors
+ .interceptAll(tableCreationBuilder);
+ return tableCreationBuilder.execute();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/intercept/InterceptableTableDropBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/InterceptableTableDropBuilder.java b/core/src/main/java/org/apache/metamodel/intercept/InterceptableTableDropBuilder.java
new file mode 100644
index 0000000..cb275a2
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/intercept/InterceptableTableDropBuilder.java
@@ -0,0 +1,53 @@
+/**
+ * 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.intercept;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.drop.TableDropBuilder;
+import org.eobjects.metamodel.schema.Table;
+
+final class InterceptableTableDropBuilder implements TableDropBuilder {
+
+ private final TableDropBuilder _tableDropBuilder;
+ private final InterceptorList<TableDropBuilder> _tableDropInterceptors;
+
+ public InterceptableTableDropBuilder(TableDropBuilder tableDropBuilder,
+ InterceptorList<TableDropBuilder> tableDropInterceptors) {
+ _tableDropBuilder = tableDropBuilder;
+ _tableDropInterceptors = tableDropInterceptors;
+ }
+
+ @Override
+ public Table getTable() {
+ return _tableDropBuilder.getTable();
+ }
+
+ @Override
+ public String toSql() {
+ return _tableDropBuilder.toSql();
+ }
+
+ @Override
+ public void execute() throws MetaModelException {
+ TableDropBuilder tableDropBuilder = _tableDropBuilder;
+ tableDropBuilder = _tableDropInterceptors.interceptAll(_tableDropBuilder);
+ tableDropBuilder.execute();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/intercept/InterceptableUpdateCallback.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/InterceptableUpdateCallback.java b/core/src/main/java/org/apache/metamodel/intercept/InterceptableUpdateCallback.java
new file mode 100644
index 0000000..1538374
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/intercept/InterceptableUpdateCallback.java
@@ -0,0 +1,128 @@
+/**
+ * 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.intercept;
+
+import org.eobjects.metamodel.AbstractUpdateCallback;
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.create.TableCreationBuilder;
+import org.eobjects.metamodel.delete.RowDeletionBuilder;
+import org.eobjects.metamodel.drop.TableDropBuilder;
+import org.eobjects.metamodel.insert.RowInsertionBuilder;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.update.RowUpdationBuilder;
+
+/**
+ * {@link UpdateCallback} wrapper that allows adding interceptors for certain operations.
+ */
+final class InterceptableUpdateCallback extends AbstractUpdateCallback implements UpdateCallback {
+
+ private final UpdateCallback _updateCallback;
+ private final InterceptorList<TableCreationBuilder> _tableCreationInterceptors;
+ private final InterceptorList<TableDropBuilder> _tableDropInterceptors;
+ private final InterceptorList<RowInsertionBuilder> _rowInsertionInterceptors;
+ private final InterceptorList<RowUpdationBuilder> _rowUpdationInterceptors;
+ private final InterceptorList<RowDeletionBuilder> _rowDeletionInterceptors;
+
+ public InterceptableUpdateCallback(InterceptableDataContext dataContext, UpdateCallback updateCallback,
+ InterceptorList<TableCreationBuilder> tableCreationInterceptors,
+ InterceptorList<TableDropBuilder> tableDropInterceptors,
+ InterceptorList<RowInsertionBuilder> rowInsertionInterceptors,
+ InterceptorList<RowUpdationBuilder> rowUpdationInterceptors,
+ InterceptorList<RowDeletionBuilder> rowDeletionInterceptors) {
+ super(dataContext);
+ _updateCallback = updateCallback;
+ _tableCreationInterceptors = tableCreationInterceptors;
+ _tableDropInterceptors = tableDropInterceptors;
+ _rowInsertionInterceptors = rowInsertionInterceptors;
+ _rowUpdationInterceptors = rowUpdationInterceptors;
+ _rowDeletionInterceptors = rowDeletionInterceptors;
+ }
+
+ @Override
+ public TableCreationBuilder createTable(Schema schema, String name) throws IllegalArgumentException,
+ IllegalStateException {
+ TableCreationBuilder tabelCreationBuilder = _updateCallback.createTable(schema, name);
+ if (_tableCreationInterceptors.isEmpty()) {
+ return tabelCreationBuilder;
+ }
+ return new InterceptableTableCreationBuilder(tabelCreationBuilder, _tableCreationInterceptors);
+ }
+
+ @Override
+ public RowInsertionBuilder insertInto(Table table) throws IllegalArgumentException, IllegalStateException {
+ RowInsertionBuilder rowInsertionBuilder = _updateCallback.insertInto(table);
+ if (_rowInsertionInterceptors.isEmpty()) {
+ return rowInsertionBuilder;
+ }
+ return new InterceptableRowInsertionBuilder(rowInsertionBuilder, _rowInsertionInterceptors);
+ }
+
+ @Override
+ public boolean isCreateTableSupported() {
+ return _updateCallback.isCreateTableSupported();
+ }
+
+ @Override
+ public boolean isDropTableSupported() {
+ return _updateCallback.isDropTableSupported();
+ }
+
+ @Override
+ public TableDropBuilder dropTable(Table table) {
+ TableDropBuilder tableDropBuilder = _updateCallback.dropTable(table);
+ if (_tableDropInterceptors.isEmpty()) {
+ return tableDropBuilder;
+ }
+ return new InterceptableTableDropBuilder(tableDropBuilder, _tableDropInterceptors);
+ }
+
+ @Override
+ public boolean isInsertSupported() {
+ return _updateCallback.isInsertSupported();
+ }
+
+ @Override
+ public boolean isUpdateSupported() {
+ return _updateCallback.isUpdateSupported();
+ }
+
+ @Override
+ public RowUpdationBuilder update(Table table) {
+ RowUpdationBuilder rowUpdationBuilder = _updateCallback.update(table);
+ if (_rowUpdationInterceptors.isEmpty()) {
+ return rowUpdationBuilder;
+ }
+ return new InterceptableRowUpdationBuilder(rowUpdationBuilder, _rowUpdationInterceptors);
+ }
+
+ @Override
+ public boolean isDeleteSupported() {
+ return _updateCallback.isDeleteSupported();
+ }
+
+ @Override
+ public RowDeletionBuilder deleteFrom(Table table) {
+ RowDeletionBuilder rowDeletionBuilder = _updateCallback.deleteFrom(table);
+ if (_rowDeletionInterceptors.isEmpty()) {
+ return rowDeletionBuilder;
+ }
+ return new InterceptableRowDeletionBuilder(rowDeletionBuilder, _rowDeletionInterceptors);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/intercept/InterceptableUpdateScript.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/InterceptableUpdateScript.java b/core/src/main/java/org/apache/metamodel/intercept/InterceptableUpdateScript.java
new file mode 100644
index 0000000..c5796c3
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/intercept/InterceptableUpdateScript.java
@@ -0,0 +1,62 @@
+/**
+ * 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.intercept;
+
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.create.TableCreationBuilder;
+import org.eobjects.metamodel.delete.RowDeletionBuilder;
+import org.eobjects.metamodel.drop.TableDropBuilder;
+import org.eobjects.metamodel.insert.RowInsertionBuilder;
+import org.eobjects.metamodel.update.RowUpdationBuilder;
+
+final class InterceptableUpdateScript implements UpdateScript {
+
+ private final InterceptableDataContext _interceptableDataContext;
+ private final UpdateScript _updateScript;
+ private final InterceptorList<TableCreationBuilder> _tableCreationInterceptors;
+ private final InterceptorList<TableDropBuilder> _tableDropInterceptors;
+ private final InterceptorList<RowInsertionBuilder> _rowInsertionInterceptors;
+ private final InterceptorList<RowUpdationBuilder> _rowUpdationInterceptors;
+ private final InterceptorList<RowDeletionBuilder> _rowDeletionInterceptors;
+
+ public InterceptableUpdateScript(InterceptableDataContext interceptableDataContext, UpdateScript updateScript,
+ InterceptorList<TableCreationBuilder> tableCreationInterceptors,
+ InterceptorList<TableDropBuilder> tableDropInterceptors,
+ InterceptorList<RowInsertionBuilder> rowInsertionInterceptors,
+ InterceptorList<RowUpdationBuilder> rowUpdationInterceptors,
+ InterceptorList<RowDeletionBuilder> rowDeletionInterceptors) {
+ _interceptableDataContext = interceptableDataContext;
+ _updateScript = updateScript;
+ _tableCreationInterceptors = tableCreationInterceptors;
+ _tableDropInterceptors = tableDropInterceptors;
+ _rowInsertionInterceptors = rowInsertionInterceptors;
+ _rowUpdationInterceptors = rowUpdationInterceptors;
+ _rowDeletionInterceptors = rowDeletionInterceptors;
+ }
+
+ @Override
+ public void run(UpdateCallback callback) {
+ UpdateCallback interceptableUpdateCallback = new InterceptableUpdateCallback(_interceptableDataContext,
+ callback, _tableCreationInterceptors, _tableDropInterceptors, _rowInsertionInterceptors,
+ _rowUpdationInterceptors, _rowDeletionInterceptors);
+ _updateScript.run(interceptableUpdateCallback);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/intercept/Interceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/Interceptor.java b/core/src/main/java/org/apache/metamodel/intercept/Interceptor.java
new file mode 100644
index 0000000..2eb2c4a
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/intercept/Interceptor.java
@@ -0,0 +1,52 @@
+/**
+ * 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.intercept;
+
+/**
+ * Defines a high-level interface for interceptors in MetaModel.
+ *
+ * An intereptor can touch, modify, enhance or do other operations on certain
+ * object types as they are passed around for execution in MetaModel. There are
+ * 5 types of concrete interceptors:
+ *
+ * @see QueryInterceptor
+ * @see DataSetInterceptor
+ * @see RowInsertionInterceptor
+ * @see TableCreationInterceptor
+ * @see SchemaInterceptor
+ *
+ * @author Kasper Sørensen
+ *
+ * @param <E>
+ * the type of object to intercept
+ */
+public interface Interceptor<E> {
+
+ /**
+ * Interception method invoked by MetaModel when the intercepted object is
+ * being activated.
+ *
+ * @param input
+ * the intercepted object
+ * @return the intercepted object, or a modification of this if the object
+ * is to be replaced by the interceptor. The returned object must
+ * not be null.
+ */
+ public E intercept(E input);
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/intercept/InterceptorList.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/InterceptorList.java b/core/src/main/java/org/apache/metamodel/intercept/InterceptorList.java
new file mode 100644
index 0000000..32c1e0e
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/intercept/InterceptorList.java
@@ -0,0 +1,74 @@
+/**
+ * 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.intercept;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents a list of interceptors
+ *
+ * @author Kasper Sørensen
+ *
+ * @param <E>
+ * the thing to intercept
+ *
+ * @see Interceptor
+ */
+public final class InterceptorList<E> {
+
+ private final List<Interceptor<E>> _interceptors = new ArrayList<Interceptor<E>>();
+
+ public void add(Interceptor<E> interceptor) {
+ _interceptors.add(interceptor);
+ }
+
+ public void remove(Interceptor<E> interceptor) {
+ _interceptors.remove(interceptor);
+ }
+
+ /**
+ * Gets the first (if any) interceptor of a specific type.
+ *
+ * @param interceptorClazz
+ * @return
+ */
+ public <I extends Interceptor<E>> I getInterceptorOfType(
+ Class<I> interceptorClazz) {
+ for (Interceptor<?> interceptor : _interceptors) {
+ if (interceptorClazz.isAssignableFrom(interceptor.getClass())) {
+ @SuppressWarnings("unchecked")
+ I result = (I) interceptor;
+ return result;
+ }
+ }
+ return null;
+ }
+
+ public boolean isEmpty() {
+ return _interceptors.isEmpty();
+ }
+
+ protected E interceptAll(E input) {
+ for (Interceptor<E> interceptor : _interceptors) {
+ input = interceptor.intercept(input);
+ }
+ return input;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/intercept/Interceptors.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/Interceptors.java b/core/src/main/java/org/apache/metamodel/intercept/Interceptors.java
new file mode 100644
index 0000000..2111fa2
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/intercept/Interceptors.java
@@ -0,0 +1,35 @@
+/**
+ * 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.intercept;
+
+import org.eobjects.metamodel.DataContext;
+
+public final class Interceptors {
+
+ private Interceptors() {
+ // prevent instantiation
+ }
+
+ public static InterceptableDataContext intercept(DataContext dc) {
+ if (dc instanceof InterceptableDataContext) {
+ return (InterceptableDataContext) dc;
+ }
+ return new InterceptableDataContext(dc);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/intercept/QueryInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/QueryInterceptor.java b/core/src/main/java/org/apache/metamodel/intercept/QueryInterceptor.java
new file mode 100644
index 0000000..b1299cf
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/intercept/QueryInterceptor.java
@@ -0,0 +1,31 @@
+/**
+ * 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.intercept;
+
+import org.eobjects.metamodel.query.Query;
+
+/**
+ * An {@link Interceptor} for Queries, allowing to touch or modify a query
+ * before execution.
+ *
+ * @author Kasper Sørensen
+ */
+public interface QueryInterceptor extends Interceptor<Query> {
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/intercept/RowDeletionInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/RowDeletionInterceptor.java b/core/src/main/java/org/apache/metamodel/intercept/RowDeletionInterceptor.java
new file mode 100644
index 0000000..4891185
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/intercept/RowDeletionInterceptor.java
@@ -0,0 +1,31 @@
+/**
+ * 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.intercept;
+
+import org.eobjects.metamodel.delete.RowDeletionBuilder;
+
+/**
+ * An {@link Interceptor} for {@link RowDeletionBuilder}, allowing for
+ * interception of "delete from table" operations before they are executed.
+ *
+ * @author Kasper Sørensen
+ */
+public interface RowDeletionInterceptor extends Interceptor<RowDeletionBuilder> {
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/intercept/RowInsertionInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/RowInsertionInterceptor.java b/core/src/main/java/org/apache/metamodel/intercept/RowInsertionInterceptor.java
new file mode 100644
index 0000000..c652e47
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/intercept/RowInsertionInterceptor.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.intercept;
+
+import org.eobjects.metamodel.insert.RowInsertionBuilder;
+
+/**
+ * An {@link Interceptor} for {@link RowInsertionBuilder}, allowing for
+ * interception of "insert into table" operations before they are executed.
+ *
+ * @author Kasper Sørensen
+ */
+public interface RowInsertionInterceptor extends
+ Interceptor<RowInsertionBuilder> {
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/intercept/RowUpdationInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/RowUpdationInterceptor.java b/core/src/main/java/org/apache/metamodel/intercept/RowUpdationInterceptor.java
new file mode 100644
index 0000000..5a9cded
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/intercept/RowUpdationInterceptor.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.intercept;
+
+import org.eobjects.metamodel.update.RowUpdationBuilder;
+
+/**
+ * An {@link Interceptor} for {@link RowUpdationBuilder}, allowing for
+ * interception of "update table" operations before they are executed.
+ *
+ * @author Kasper Sørensen
+ */
+public interface RowUpdationInterceptor extends
+ Interceptor<RowUpdationBuilder> {
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/intercept/SchemaInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/SchemaInterceptor.java b/core/src/main/java/org/apache/metamodel/intercept/SchemaInterceptor.java
new file mode 100644
index 0000000..3ff3489
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/intercept/SchemaInterceptor.java
@@ -0,0 +1,31 @@
+/**
+ * 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.intercept;
+
+import org.eobjects.metamodel.schema.Schema;
+
+/**
+ * An {@link Interceptor} for {@link Schema}s, which allows for intercepting
+ * schema objects before they are returned to the user.
+ *
+ * @author Kasper Sørensen
+ */
+public interface SchemaInterceptor extends Interceptor<Schema> {
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/intercept/TableCreationInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/TableCreationInterceptor.java b/core/src/main/java/org/apache/metamodel/intercept/TableCreationInterceptor.java
new file mode 100644
index 0000000..af55dde
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/intercept/TableCreationInterceptor.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.intercept;
+
+import org.eobjects.metamodel.create.TableCreationBuilder;
+
+/**
+ * An {@link Interceptor} for {@link TableCreationBuilder}s, which allows for
+ * intercepting "create table" operations before they are executed.
+ *
+ * @author Kasper Sørensen
+ */
+public interface TableCreationInterceptor extends
+ Interceptor<TableCreationBuilder> {
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/intercept/TableDropInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/TableDropInterceptor.java b/core/src/main/java/org/apache/metamodel/intercept/TableDropInterceptor.java
new file mode 100644
index 0000000..d148ec1
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/intercept/TableDropInterceptor.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.intercept;
+
+import org.eobjects.metamodel.drop.TableDropBuilder;
+
+/**
+ * An {@link Interceptor} for {@link TableDropBuilder}s, which allows for
+ * intercepting "drop table" operations before they are executed.
+ *
+ * @author Kasper Sørensen
+ */
+public interface TableDropInterceptor extends
+ Interceptor<TableDropBuilder> {
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/package-info.java b/core/src/main/java/org/apache/metamodel/package-info.java
new file mode 100644
index 0000000..74b215c
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/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.
+ */
+/**
+ * Root package for MetaModel
+ */
+package org.eobjects.metamodel;
+
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/AbstractQueryClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/AbstractQueryClause.java b/core/src/main/java/org/apache/metamodel/query/AbstractQueryClause.java
new file mode 100644
index 0000000..c06cf27
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/AbstractQueryClause.java
@@ -0,0 +1,163 @@
+/**
+ * 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.query;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eobjects.metamodel.util.BaseObject;
+
+/**
+ * Represents an abstract clause in a query. Clauses contains IQueryItems and
+ * provide basic ways of adding, modifying and removing these.
+ *
+ * @param <E>
+ * the type of query item this QueryClause handles
+ *
+ * @see Query
+ */
+public abstract class AbstractQueryClause<E extends QueryItem> extends BaseObject implements QueryClause<E> {
+
+ private static final long serialVersionUID = 3987346267433022231L;
+
+ public static final String PREFIX_SELECT = "SELECT ";
+ public static final String PREFIX_FROM = " FROM ";
+ public static final String PREFIX_WHERE = " WHERE ";
+ public static final String PREFIX_GROUP_BY = " GROUP BY ";
+ public static final String PREFIX_HAVING = " HAVING ";
+ public static final String PREFIX_ORDER_BY = " ORDER BY ";
+ public static final String DELIM_COMMA = ", ";
+ public static final String DELIM_AND = " AND ";
+
+ private final Query _query;
+ private final List<E> _items = new ArrayList<E>();
+ private final String _prefix;
+ private final String _delim;
+
+ public AbstractQueryClause(Query query, String prefix, String delim) {
+ _query = query;
+ _prefix = prefix;
+ _delim = delim;
+ }
+
+ @Override
+ public QueryClause<E> setItems(E... items) {
+ _items.clear();
+ return addItems(items);
+ }
+
+ @Override
+ public QueryClause<E> addItems(E... items) {
+ for (E item : items) {
+ addItem(item);
+ }
+ return this;
+ }
+
+ @Override
+ public QueryClause<E> addItems(Iterable<E> items) {
+ for (E item : items) {
+ addItem(item);
+ }
+ return this;
+ }
+
+ public QueryClause<E> addItem(int index, E item) {
+ if (item.getQuery() == null) {
+ item.setQuery(_query);
+ }
+ _items.add(index, item);
+ return this;
+ };
+
+ @Override
+ public QueryClause<E> addItem(E item) {
+ return addItem(getItemCount(), item);
+ }
+
+ @Override
+ public int getItemCount() {
+ return _items.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return getItemCount() == 0;
+ }
+
+ @Override
+ public E getItem(int index) {
+ return _items.get(index);
+ }
+
+ @Override
+ public List<E> getItems() {
+ return _items;
+ }
+
+ @Override
+ public QueryClause<E> removeItem(int index) {
+ _items.remove(index);
+ return this;
+ }
+
+ @Override
+ public QueryClause<E> removeItem(E item) {
+ _items.remove(item);
+ return this;
+ }
+
+ @Override
+ public QueryClause<E> removeItems() {
+ _items.clear();
+ return this;
+ }
+
+ @Override
+ public String toSql() {
+ return toSql(false);
+ }
+
+ @Override
+ public String toSql(boolean includeSchemaInColumnPaths) {
+ if (_items.size() == 0) {
+ return "";
+ }
+ final StringBuilder sb = new StringBuilder(_prefix);
+ for (int i = 0; i < _items.size(); i++) {
+ final E item = _items.get(i);
+ if (i != 0) {
+ sb.append(_delim);
+ }
+ final String sql = item.toSql(includeSchemaInColumnPaths);
+ sb.append(sql);
+ }
+ return sb.toString();
+ }
+
+ @Override
+ public String toString() {
+ return toSql();
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ identifiers.add(_items);
+ }
+}
\ 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/query/AverageAggregateBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/AverageAggregateBuilder.java b/core/src/main/java/org/apache/metamodel/query/AverageAggregateBuilder.java
new file mode 100644
index 0000000..3b2d949
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/AverageAggregateBuilder.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.query;
+
+import org.eobjects.metamodel.util.AggregateBuilder;
+import org.eobjects.metamodel.util.NumberComparator;
+
+final class AverageAggregateBuilder implements AggregateBuilder<Double> {
+
+ public double _average;
+ public int _numValues;
+
+ @Override
+ public void add(Object o) {
+ if (o == null) {
+ return;
+ }
+ Number number = NumberComparator.toNumber(o);
+ if (number == null) {
+ throw new IllegalArgumentException("Could not convert to number: "
+ + o);
+ }
+ double total = _average * _numValues + number.doubleValue();
+ _numValues++;
+ _average = total / _numValues;
+ }
+
+ @Override
+ public Double getAggregate() {
+ return _average;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/CompiledQuery.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/CompiledQuery.java b/core/src/main/java/org/apache/metamodel/query/CompiledQuery.java
new file mode 100644
index 0000000..cd242b9
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/CompiledQuery.java
@@ -0,0 +1,65 @@
+/**
+ * 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.query;
+
+import java.io.Closeable;
+import java.util.List;
+
+import org.eobjects.metamodel.DataContext;
+
+/**
+ * A {@link CompiledQuery} is a {@link Query} which has been compiled, typically
+ * by the data source itself, to provide optimized execution speed. Compiled
+ * queries are produced using the {@link DataContext#compileQuery(Query)} method.
+ *
+ * Typically the compilation itself takes a bit of time, but firing the compiled
+ * query is faster than regular queries. This means that for repeated executions
+ * of the same query, it is usually faster to use compiled queries.
+ *
+ * To make {@link CompiledQuery} useful for more than just one specific query,
+ * variations of the query can be fired, as long as the variations can be
+ * expressed as a {@link QueryParameter} for instance in the WHERE clause of the
+ * query.
+ *
+ * @see DataContext#compileQuery(Query)
+ * @see QueryParameter
+ */
+public interface CompiledQuery extends Closeable {
+
+ /**
+ * Gets the {@link QueryParameter}s associated with the compiled query.
+ * Values for these parameters are expected when the query is executed.
+ *
+ * @return a list of query parameters
+ */
+ public List<QueryParameter> getParameters();
+
+ /**
+ * A representation of the query as SQL.
+ *
+ * @return a SQL string.
+ */
+ public String toSql();
+
+ /**
+ * Closes any resources related to the compiled query.
+ */
+ @Override
+ public void close();
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/CountAggregateBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/CountAggregateBuilder.java b/core/src/main/java/org/apache/metamodel/query/CountAggregateBuilder.java
new file mode 100644
index 0000000..c5bca84
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/CountAggregateBuilder.java
@@ -0,0 +1,39 @@
+/**
+ * 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.query;
+
+import org.eobjects.metamodel.util.AggregateBuilder;
+
+final class CountAggregateBuilder implements AggregateBuilder<Long> {
+
+ private long counter = 0;
+
+ @Override
+ public void add(Object o) {
+ if (o != null) {
+ counter++;
+ }
+ }
+
+ @Override
+ public Long getAggregate() {
+ return counter;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/DefaultCompiledQuery.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/DefaultCompiledQuery.java b/core/src/main/java/org/apache/metamodel/query/DefaultCompiledQuery.java
new file mode 100644
index 0000000..c1f3dab
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/DefaultCompiledQuery.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.query;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Represents a default implementation of the {@link CompiledQuery} interface.
+ * This implementation does not actually do anything to prepare the query, but
+ * allows creating a clone of the originating query with the parameters replaced
+ * by values.
+ */
+public class DefaultCompiledQuery implements CompiledQuery {
+
+ private final Query _query;
+ private final List<QueryParameter> _parameters;
+
+ public DefaultCompiledQuery(Query query) {
+ _query = query;
+ _parameters = createParameterList();
+ }
+
+ /**
+ * Clones the query while replacing query parameters with corresponding
+ * values.
+ *
+ * @param values
+ * @return
+ */
+ public Query cloneWithParameterValues(Object[] values) {
+ final AtomicInteger parameterIndex = new AtomicInteger(0);
+ final Query clonedQuery = _query.clone();
+ replaceParametersInQuery(values, parameterIndex, _query, clonedQuery);
+ return clonedQuery;
+ }
+
+ private void replaceParametersInQuery(Object[] values, AtomicInteger parameterIndex, Query originalQuery,
+ Query newQuery) {
+ replaceParametersInFromClause(values, parameterIndex, originalQuery, newQuery);
+ replaceParametersInWhereClause(values, parameterIndex, originalQuery, newQuery);
+ }
+
+ private void replaceParametersInWhereClause(Object[] values, final AtomicInteger parameterIndex,
+ Query originalQuery, Query newQuery) {
+ // creates a clone of the original query, but rebuilds a completely new
+ // where clause based on parameter values
+
+ final List<FilterItem> items = originalQuery.getWhereClause().getItems();
+ int i = 0;
+ for (FilterItem filterItem : items) {
+ final FilterItem newFilter = copyFilterItem(filterItem, values, parameterIndex);
+ if (filterItem != newFilter) {
+ newQuery.getWhereClause().removeItem(i);
+ newQuery.getWhereClause().addItem(i, newFilter);
+ }
+ i++;
+ }
+ }
+
+ private void replaceParametersInFromClause(Object[] values, AtomicInteger parameterIndex, Query originalQuery,
+ Query newQuery) {
+ final List<FromItem> fromItems = originalQuery.getFromClause().getItems();
+ int i = 0;
+ for (FromItem fromItem : fromItems) {
+ final Query subQuery = fromItem.getSubQuery();
+ if (subQuery != null) {
+ final Query newSubQuery = newQuery.getFromClause().getItem(i).getSubQuery();
+ replaceParametersInQuery(values, parameterIndex, subQuery, newSubQuery);
+
+ newQuery.getFromClause().removeItem(i);
+ newQuery.getFromClause().addItem(i, new FromItem(newSubQuery).setAlias(fromItem.getAlias()));
+ }
+ i++;
+ }
+ }
+
+ private FilterItem copyFilterItem(FilterItem item, Object[] values, AtomicInteger parameterIndex) {
+ if (item.isCompoundFilter()) {
+ final FilterItem[] childItems = item.getChildItems();
+ final FilterItem[] newChildItems = new FilterItem[childItems.length];
+ for (int i = 0; i < childItems.length; i++) {
+ final FilterItem childItem = childItems[i];
+ final FilterItem newChildItem = copyFilterItem(childItem, values, parameterIndex);
+ newChildItems[i] = newChildItem;
+ }
+ final FilterItem newFilter = new FilterItem(newChildItems);
+ return newFilter;
+ } else {
+ if (item.getOperand() instanceof QueryParameter) {
+ final Object newOperand = values[parameterIndex.getAndIncrement()];
+ final FilterItem newFilter = new FilterItem(item.getSelectItem(), item.getOperator(), newOperand);
+ return newFilter;
+ } else {
+ return item;
+ }
+ }
+ }
+
+ private List<QueryParameter> createParameterList() {
+ final List<QueryParameter> parameters = new ArrayList<QueryParameter>();
+
+ buildParameterListInFromClause(parameters, _query);
+ buildParameterListInWhereClause(parameters, _query);
+ return parameters;
+ }
+
+ private void buildParameterListInWhereClause(List<QueryParameter> parameters, Query query) {
+ List<FilterItem> items = query.getWhereClause().getItems();
+ for (FilterItem item : items) {
+ buildParameterFromFilterItem(parameters, item);
+ }
+ }
+
+ private void buildParameterListInFromClause(List<QueryParameter> parameters, Query query) {
+ List<FromItem> fromItems = query.getFromClause().getItems();
+ for (FromItem fromItem : fromItems) {
+ Query subQuery = fromItem.getSubQuery();
+ if (subQuery != null) {
+ buildParameterListInFromClause(parameters, subQuery);
+ buildParameterListInWhereClause(parameters, subQuery);
+ }
+ }
+ }
+
+ @Override
+ public List<QueryParameter> getParameters() {
+ return _parameters;
+ }
+
+ @Override
+ public String toSql() {
+ return _query.toSql();
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + "[" + toSql() + "]";
+ }
+
+ @Override
+ public void close() {
+ // do nothing
+ }
+
+ private void buildParameterFromFilterItem(List<QueryParameter> parameters, FilterItem item) {
+ if (item.isCompoundFilter()) {
+ FilterItem[] childItems = item.getChildItems();
+ for (FilterItem childItem : childItems) {
+ buildParameterFromFilterItem(parameters, childItem);
+ }
+ } else {
+ if (item.getOperand() instanceof QueryParameter) {
+ parameters.add((QueryParameter) item.getOperand());
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/FilterClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/FilterClause.java b/core/src/main/java/org/apache/metamodel/query/FilterClause.java
new file mode 100644
index 0000000..591fb01
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/FilterClause.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.query;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eobjects.metamodel.schema.Column;
+
+/**
+ * Represents a clause of filters in the query. This type of clause is used for
+ * the WHERE and HAVING parts of an SQL query.
+ *
+ * Each provided FilterItem will be evaluated with the logical AND operator,
+ * which requires that all filters are applied. Alternatively, if you wan't to
+ * use an OR operator, then use the appropriate constructor of FilterItem to
+ * create a composite filter.
+ *
+ * @see FilterItem
+ */
+public class FilterClause extends AbstractQueryClause<FilterItem> {
+
+ private static final long serialVersionUID = -9077342278766808934L;
+
+ public FilterClause(Query query, String prefix) {
+ super(query, prefix, AbstractQueryClause.DELIM_AND);
+ }
+
+ public List<SelectItem> getEvaluatedSelectItems() {
+ List<SelectItem> result = new ArrayList<SelectItem>();
+ List<FilterItem> items = getItems();
+ for (FilterItem item : items) {
+ addEvaluatedSelectItems(result, item);
+ }
+ return result;
+ }
+
+ private void addEvaluatedSelectItems(List<SelectItem> result,
+ FilterItem item) {
+ FilterItem[] orItems = item.getChildItems();
+ if (orItems != null) {
+ for (FilterItem filterItem : orItems) {
+ addEvaluatedSelectItems(result, filterItem);
+ }
+ }
+ SelectItem selectItem = item.getSelectItem();
+ if (selectItem != null && !result.contains(selectItem)) {
+ result.add(selectItem);
+ }
+ Object operand = item.getOperand();
+ if (operand != null && operand instanceof SelectItem
+ && !result.contains(operand)) {
+ result.add((SelectItem) operand);
+ }
+ }
+
+ /**
+ * Traverses the items and evaluates whether or not the given column is
+ * referenced in either of them.
+ *
+ * @param column
+ * @return true if the column is referenced in the clause or false if not
+ */
+ public boolean isColumnReferenced(Column column) {
+ for (FilterItem item : getItems()) {
+ if (item.isReferenced(column)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
\ No newline at end of file
[16/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/eobjects/metamodel/csv/CsvDataContext.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/eobjects/metamodel/csv/CsvDataContext.java b/csv/src/main/java/org/eobjects/metamodel/csv/CsvDataContext.java
deleted file mode 100644
index 6409596..0000000
--- a/csv/src/main/java/org/eobjects/metamodel/csv/CsvDataContext.java
+++ /dev/null
@@ -1,393 +0,0 @@
-/**
- * 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.csv;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.UnsupportedEncodingException;
-import java.net.URL;
-import java.util.List;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.FileHelper;
-import org.eobjects.metamodel.util.FileResource;
-import org.eobjects.metamodel.util.Func;
-import org.eobjects.metamodel.util.Resource;
-import org.eobjects.metamodel.util.UrlResource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import au.com.bytecode.opencsv.CSVReader;
-
-/**
- * DataContext implementation for reading CSV files.
- */
-public final class CsvDataContext extends QueryPostprocessDataContext implements UpdateableDataContext {
-
- private static final Logger logger = LoggerFactory.getLogger(CsvDataContext.class);
-
- private final Object WRITE_LOCK = new Object();
-
- private final Resource _resource;
- private final CsvConfiguration _configuration;
- private final boolean _writable;
-
- /**
- * Constructs a CSV DataContext based on a file
- *
- * @param file
- * @param configuration
- */
- public CsvDataContext(File file, CsvConfiguration configuration) {
- if (file == null) {
- throw new IllegalArgumentException("File cannot be null");
- }
- if (configuration == null) {
- throw new IllegalArgumentException("CsvConfiguration cannot be null");
- }
- _resource = new FileResource(file);
- _configuration = configuration;
- _writable = true;
- }
-
- public CsvDataContext(Resource resource, CsvConfiguration configuration) {
- if (resource == null) {
- throw new IllegalArgumentException("File cannot be null");
- }
- if (configuration == null) {
- throw new IllegalArgumentException("CsvConfiguration cannot be null");
- }
- _resource = resource;
- _configuration = configuration;
- _writable = !resource.isReadOnly();
- }
-
- /**
- * Constructs a CSV DataContext based on a {@link URL}
- *
- * @param url
- * @param configuration
- */
- public CsvDataContext(URL url, CsvConfiguration configuration) {
- _resource = new UrlResource(url);
- _configuration = configuration;
- _writable = false;
- }
-
- /**
- * Constructs a CSV DataContext based on a file
- *
- * @param file
- */
- public CsvDataContext(File file) {
- this(file, new CsvConfiguration());
- }
-
- /**
- * Constructs a CSV DataContext based on an {@link InputStream}
- *
- * @param inputStream
- * @param configuration
- */
- public CsvDataContext(InputStream inputStream, CsvConfiguration configuration) {
- File file = createFileFromInputStream(inputStream, configuration.getEncoding());
- _configuration = configuration;
- _writable = false;
- _resource = new FileResource(file);
- }
-
- /**
- * @deprecated use {@link #CsvDataContext(File, CsvConfiguration)} instead.
- */
- @Deprecated
- public CsvDataContext(File file, char separatorChar) {
- this(file, separatorChar, CsvConfiguration.DEFAULT_QUOTE_CHAR);
- }
-
- /**
- * @deprecated use {@link #CsvDataContext(File, CsvConfiguration)} instead.
- */
- @Deprecated
- public CsvDataContext(File file, char separatorChar, char quoteChar) {
- this(file, new CsvConfiguration(CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, FileHelper.DEFAULT_ENCODING,
- separatorChar, quoteChar, CsvConfiguration.DEFAULT_ESCAPE_CHAR));
- }
-
- /**
- * @deprecated use {@link #CsvDataContext(File, CsvConfiguration)} instead.
- */
- @Deprecated
- public CsvDataContext(File file, char separatorChar, char quoteChar, String encoding) {
- this(file, new CsvConfiguration(CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, encoding, separatorChar, quoteChar,
- CsvConfiguration.DEFAULT_ESCAPE_CHAR));
- }
-
- /**
- * @deprecated use {@link #CsvDataContext(URL, CsvConfiguration)} instead.
- */
- @Deprecated
- public CsvDataContext(URL url, char separatorChar, char quoteChar) {
- this(url, separatorChar, quoteChar, FileHelper.DEFAULT_ENCODING);
- }
-
- /**
- * @deprecated use {@link #CsvDataContext(URL, CsvConfiguration)} instead.
- */
- @Deprecated
- public CsvDataContext(URL url, char separatorChar, char quoteChar, String encoding) {
- this(url, new CsvConfiguration(CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, encoding, separatorChar, quoteChar,
- CsvConfiguration.DEFAULT_ESCAPE_CHAR));
- }
-
- /**
- * @deprecated use {@link #CsvDataContext(InputStream, CsvConfiguration)}
- * instead.
- */
- @Deprecated
- public CsvDataContext(InputStream inputStream, char separatorChar, char quoteChar) {
- this(inputStream, new CsvConfiguration(CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, FileHelper.DEFAULT_ENCODING,
- separatorChar, quoteChar, CsvConfiguration.DEFAULT_ESCAPE_CHAR));
- }
-
- /**
- * @deprecated use {@link #CsvDataContext(InputStream, CsvConfiguration)}
- * instead.
- */
- @Deprecated
- public CsvDataContext(InputStream inputStream, char separatorChar, char quoteChar, String encoding) {
- this(inputStream, new CsvConfiguration(CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, encoding, separatorChar,
- quoteChar, CsvConfiguration.DEFAULT_ESCAPE_CHAR));
- }
-
- /**
- * Gets the CSV configuration used
- *
- * @return a CSV configuration
- */
- public CsvConfiguration getConfiguration() {
- return _configuration;
- }
-
- /**
- * Gets the CSV file being read
- *
- * @return a file
- *
- * @deprecated use {@link #getResource()} instead.
- */
- @Deprecated
- public File getFile() {
- if (_resource instanceof FileResource) {
- return ((FileResource) _resource).getFile();
- }
- return null;
- }
-
- /**
- * Gets the resource that is being read from.
- *
- * @return
- */
- public Resource getResource() {
- return _resource;
- }
-
- private static File createFileFromInputStream(InputStream inputStream, String encoding) {
- final File file;
- final File tempDir = FileHelper.getTempDir();
-
- File fileCandidate = null;
- boolean usableName = false;
- int index = 0;
-
- while (!usableName) {
- index++;
- fileCandidate = new File(tempDir, "metamodel" + index + ".csv");
- usableName = !fileCandidate.exists();
- }
- file = fileCandidate;
-
- final BufferedWriter writer = FileHelper.getBufferedWriter(file, encoding);
- final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
-
- try {
- file.createNewFile();
- file.deleteOnExit();
-
- boolean firstLine = true;
-
- for (String line = reader.readLine(); line != null; line = reader.readLine()) {
- if (firstLine) {
- firstLine = false;
- } else {
- writer.write('\n');
- }
- writer.write(line);
- }
- } catch (IOException e) {
- throw new IllegalStateException(e);
- } finally {
- FileHelper.safeClose(writer, reader);
- }
-
- return file;
- }
-
- @Override
- protected Number executeCountQuery(Table table, List<FilterItem> whereItems, boolean functionApproximationAllowed) {
- if (!functionApproximationAllowed) {
- return null;
- }
-
- return _resource.read(new Func<InputStream, Number>() {
- @Override
- public Number eval(InputStream inputStream) {
- try {
- final long length = _resource.getSize();
- // read up to 5 megs of the file and approximate number of
- // lines
- // based on that.
-
- final int sampleSize = (int) Math.min(length, 1024 * 1024 * 5);
- final int chunkSize = Math.min(sampleSize, 1024 * 1024);
-
- int readSize = 0;
- int newlines = 0;
- int carriageReturns = 0;
- byte[] byteBuffer = new byte[chunkSize];
- char[] charBuffer = new char[chunkSize];
-
- while (readSize < sampleSize) {
- final int read = inputStream.read(byteBuffer);
- if (read == -1) {
- break;
- } else {
- readSize += read;
- }
-
- Reader reader = getReader(byteBuffer, _configuration.getEncoding());
- reader.read(charBuffer);
- for (char c : charBuffer) {
- if ('\n' == c) {
- newlines++;
- } else if ('\r' == c) {
- carriageReturns++;
- }
- }
- }
-
- int lines = Math.max(newlines, carriageReturns);
-
- logger.info("Found {} lines breaks in {} bytes", lines, sampleSize);
-
- long approxCount = (long) (lines * length / sampleSize);
- return approxCount;
- } catch (IOException e) {
- logger.error("Unexpected error during COUNT(*) approximation", e);
- throw new IllegalStateException(e);
- }
- }
- });
- }
-
- private Reader getReader(byte[] byteBuffer, String encoding) throws UnsupportedEncodingException {
- try {
- return new InputStreamReader(new ByteArrayInputStream(byteBuffer), encoding);
- } catch (UnsupportedEncodingException e1) {
- // this may happen on more exotic encodings, but since this reader
- // is only meant for finding newlines, we'll try again with UTF8
- try {
- return new InputStreamReader(new ByteArrayInputStream(byteBuffer), "UTF8");
- } catch (UnsupportedEncodingException e2) {
- throw e1;
- }
- }
- }
-
- @Override
- public DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
- final int lineNumber = _configuration.getColumnNameLineNumber();
- final CSVReader reader = createCsvReader(lineNumber);
- final int columnCount = table.getColumnCount();
- final boolean failOnInconsistentRowLength = _configuration.isFailOnInconsistentRowLength();
- if (maxRows < 0) {
- return new CsvDataSet(reader, columns, null, columnCount, failOnInconsistentRowLength);
- } else {
- return new CsvDataSet(reader, columns, maxRows, columnCount, failOnInconsistentRowLength);
- }
- }
-
- protected CSVReader createCsvReader(int skipLines) {
- final Reader fileReader = FileHelper.getReader(_resource.read(), _configuration.getEncoding());
- final CSVReader csvReader = new CSVReader(fileReader, _configuration.getSeparatorChar(),
- _configuration.getQuoteChar(), _configuration.getEscapeChar(), skipLines);
- return csvReader;
- }
-
- @Override
- protected CsvSchema getMainSchema() throws MetaModelException {
- CsvSchema schema = new CsvSchema(getMainSchemaName(), this);
- if (_resource.isExists()) {
- schema.setTable(new CsvTable(schema));
- }
- return schema;
- }
-
- @Override
- protected String getMainSchemaName() {
- return _resource.getName();
- }
-
- protected boolean isWritable() {
- return _writable;
- }
-
- private void checkWritable() {
- if (!isWritable()) {
- throw new IllegalStateException(
- "This CSV DataContext is not writable, as it based on a read-only resource.");
- }
- }
-
- @Override
- public void executeUpdate(UpdateScript update) {
- checkWritable();
- CsvUpdateCallback callback = new CsvUpdateCallback(this);
- synchronized (WRITE_LOCK) {
- try {
- update.run(callback);
- } finally {
- callback.close();
- }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/eobjects/metamodel/csv/CsvDataSet.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/eobjects/metamodel/csv/CsvDataSet.java b/csv/src/main/java/org/eobjects/metamodel/csv/CsvDataSet.java
deleted file mode 100644
index ae31865..0000000
--- a/csv/src/main/java/org/eobjects/metamodel/csv/CsvDataSet.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/**
- * 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.csv;
-
-import java.io.IOException;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.AbstractDataSet;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.util.FileHelper;
-
-import au.com.bytecode.opencsv.CSVReader;
-
-/**
- * Streaming DataSet implementation for CSV support
- *
- * @author Kasper Sørensen
- */
-final class CsvDataSet extends AbstractDataSet {
-
- private final CSVReader _reader;
- private final boolean _failOnInconsistentRowLength;
- private final int _columnsInTable;
- private volatile int _rowNumber;
- private volatile Integer _rowsRemaining;
- private volatile Row _row;
-
- public CsvDataSet(CSVReader reader, Column[] columns, Integer maxRows,
- int columnsInTable, boolean failOnInconsistentRowLength) {
- super(columns);
- _reader = reader;
- _columnsInTable = columnsInTable;
- _failOnInconsistentRowLength = failOnInconsistentRowLength;
- _rowNumber = 0;
- _rowsRemaining = maxRows;
- }
-
- @Override
- public void close() {
- FileHelper.safeClose(_reader);
- _row = null;
- _rowsRemaining = null;
- }
-
- @Override
- protected void finalize() throws Throwable {
- super.finalize();
- // close is always safe to invoke
- close();
- }
-
- @Override
- public Row getRow() throws MetaModelException {
- return _row;
- }
-
- @Override
- public boolean next() {
- if (_rowsRemaining != null && _rowsRemaining > 0) {
- _rowsRemaining--;
- return nextInternal();
- } else if (_rowsRemaining == null) {
- return nextInternal();
- } else {
- return false;
- }
- }
-
- private boolean nextInternal() {
- if (_reader == null) {
- return false;
- }
- final String[] csvValues;
- try {
- csvValues = _reader.readNext();
- } catch (IOException e) {
- throw new IllegalStateException("Exception reading from file", e);
- }
- if (csvValues == null) {
- close();
- return false;
- }
-
- final int size = getHeader().size();
- final Object[] rowValues = new Object[size];
- for (int i = 0; i < size; i++) {
- Column column = getHeader().getSelectItem(i).getColumn();
- int columnNumber = column.getColumnNumber();
- if (columnNumber < csvValues.length) {
- rowValues[i] = csvValues[columnNumber];
- } else {
- // Ticket #125: Missing values should be enterpreted as
- // null.
- rowValues[i] = null;
- }
- }
- _row = new DefaultRow(getHeader(), rowValues);
-
- if (_failOnInconsistentRowLength) {
- _rowNumber++;
- if (_columnsInTable != csvValues.length) {
- throw new InconsistentRowLengthException(_columnsInTable, _row,
- csvValues, _rowNumber);
- }
- }
-
- return true;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/eobjects/metamodel/csv/CsvDeleteBuilder.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/eobjects/metamodel/csv/CsvDeleteBuilder.java b/csv/src/main/java/org/eobjects/metamodel/csv/CsvDeleteBuilder.java
deleted file mode 100644
index d245ff3..0000000
--- a/csv/src/main/java/org/eobjects/metamodel/csv/CsvDeleteBuilder.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/**
- * 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.csv;
-
-import java.io.File;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.delete.AbstractRowDeletionBuilder;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.Action;
-import org.eobjects.metamodel.util.FileHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-final class CsvDeleteBuilder extends AbstractRowDeletionBuilder {
-
- private static final Logger logger = LoggerFactory.getLogger(CsvDeleteBuilder.class);
-
- private final CsvUpdateCallback _updateCallback;
-
- public CsvDeleteBuilder(CsvUpdateCallback updateCallback, Table table) {
- super(table);
- _updateCallback = updateCallback;
- }
-
- @Override
- public void execute() throws MetaModelException {
- final File tempFile = FileHelper.createTempFile("metamodel_deletion", "csv");
-
- final CsvConfiguration configuration = _updateCallback.getConfiguration();
-
- final CsvDataContext copyDataContext = new CsvDataContext(tempFile, configuration);
- copyDataContext.executeUpdate(new UpdateScript() {
-
- @Override
- public void run(UpdateCallback callback) {
- final Table originalTable = getTable();
- final Table copyTable = callback.createTable(copyDataContext.getDefaultSchema(), originalTable.getName())
- .like(originalTable).execute();
-
- if (isTruncateTableOperation()) {
- // no need to iterate old records, they should all be
- // removed
- return;
- }
-
- final DataSet dataSet = _updateCallback.getDataContext().query().from(originalTable)
- .select(originalTable.getColumns()).execute();
- try {
- while (dataSet.next()) {
- final Row row = dataSet.getRow();
- if (!deleteRow(row)) {
- callback.insertInto(copyTable).like(row).execute();
- }
- }
- } finally {
- dataSet.close();
- }
- }
- });
-
- // copy the copy (which does not have deleted records) to overwrite the
- // original
- final InputStream in = FileHelper.getInputStream(tempFile);
- try {
- _updateCallback.getResource().write(new Action<OutputStream>() {
- @Override
- public void run(OutputStream out) throws Exception {
- FileHelper.copy(in, out);
- }
- });
- } finally {
- FileHelper.safeClose(in);
- }
-
- final boolean deleted = tempFile.delete();
- if (!deleted) {
- logger.warn("Could not delete temporary copy-file: {}", tempFile);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/eobjects/metamodel/csv/CsvInsertBuilder.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/eobjects/metamodel/csv/CsvInsertBuilder.java b/csv/src/main/java/org/eobjects/metamodel/csv/CsvInsertBuilder.java
deleted file mode 100644
index 8faccc6..0000000
--- a/csv/src/main/java/org/eobjects/metamodel/csv/CsvInsertBuilder.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * 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.csv;
-
-import org.eobjects.metamodel.insert.AbstractRowInsertionBuilder;
-import org.eobjects.metamodel.schema.Table;
-
-final class CsvInsertBuilder extends AbstractRowInsertionBuilder<CsvUpdateCallback> {
-
- public CsvInsertBuilder(CsvUpdateCallback updateCallback, Table table) {
- super(updateCallback, table);
- }
-
- @Override
- public void execute() {
- Object[] values = getValues();
- String[] stringValues = new String[values.length];
- for (int i = 0; i < stringValues.length; i++) {
- stringValues[i] = values[i] == null ? "" : values[i].toString();
- }
- getUpdateCallback().writeRow(stringValues, true);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/eobjects/metamodel/csv/CsvSchema.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/eobjects/metamodel/csv/CsvSchema.java b/csv/src/main/java/org/eobjects/metamodel/csv/CsvSchema.java
deleted file mode 100644
index c6d2ba9..0000000
--- a/csv/src/main/java/org/eobjects/metamodel/csv/CsvSchema.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * 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.csv;
-
-import org.eobjects.metamodel.schema.AbstractSchema;
-import org.eobjects.metamodel.schema.Table;
-
-final class CsvSchema extends AbstractSchema {
-
- private static final long serialVersionUID = 1L;
-
- private final String _name;
- private final transient CsvDataContext _dataContext;
- private CsvTable _table;
-
- public CsvSchema(String name, CsvDataContext dataContext) {
- super();
- _name = name;
- _dataContext = dataContext;
- }
-
- protected void setTable(CsvTable table) {
- _table = table;
- }
-
- @Override
- public String getName() {
- return _name;
- }
-
- protected CsvDataContext getDataContext() {
- return _dataContext;
- }
-
- @Override
- public String getQuote() {
- return null;
- }
-
- @Override
- public Table[] getTables() {
- if (_table == null) {
- return new Table[0];
- }
- return new Table[] { _table };
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/eobjects/metamodel/csv/CsvTable.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/eobjects/metamodel/csv/CsvTable.java b/csv/src/main/java/org/eobjects/metamodel/csv/CsvTable.java
deleted file mode 100644
index eb9bdc0..0000000
--- a/csv/src/main/java/org/eobjects/metamodel/csv/CsvTable.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/**
- * 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.csv;
-
-import java.io.IOException;
-
-import org.eobjects.metamodel.schema.AbstractTable;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.TableType;
-import org.eobjects.metamodel.util.AlphabeticSequence;
-import org.eobjects.metamodel.util.FileHelper;
-
-import au.com.bytecode.opencsv.CSVReader;
-
-final class CsvTable extends AbstractTable {
-
- private static final long serialVersionUID = 1L;
-
- private final CsvSchema _schema;
- private Column[] _columns;
-
- /**
- * Constructor for creating a new CSV table which has not yet been written.
- *
- * @param schema
- * @param columnNames
- */
- public CsvTable(CsvSchema schema, String[] columnNames) {
- this(schema);
- _columns = buildColumns(columnNames);
- }
-
- /**
- * Constructor for reading an existing CSV table.
- *
- * @param schema
- */
- public CsvTable(CsvSchema schema) {
- _schema = schema;
- }
-
- @Override
- public String getName() {
- String schemaName = _schema.getName();
- return schemaName.substring(0, schemaName.length() - 4);
- }
-
- @Override
- public Column[] getColumns() {
- if (_columns == null) {
- synchronized (this) {
- if (_columns == null) {
- _columns = buildColumns();
- }
- }
- }
- return _columns;
- }
-
- private Column[] buildColumns() {
- CSVReader reader = null;
- try {
- reader = _schema.getDataContext().createCsvReader(0);
-
- final int columnNameLineNumber = _schema.getDataContext().getConfiguration().getColumnNameLineNumber();
- for (int i = 1; i < columnNameLineNumber; i++) {
- reader.readNext();
- }
- final String[] columnHeaders = reader.readNext();
-
- reader.close();
- return buildColumns(columnHeaders);
- } catch (IOException e) {
- throw new IllegalStateException("Exception reading from resource: " + _schema.getDataContext().getResource().getName(), e);
- } finally {
- FileHelper.safeClose(reader);
- }
- }
-
- private Column[] buildColumns(final String[] columnNames) {
- if (columnNames == null) {
- return new Column[0];
- }
-
- final CsvConfiguration configuration = _schema.getDataContext().getConfiguration();
- final int columnNameLineNumber = configuration.getColumnNameLineNumber();
- final boolean nullable = !configuration.isFailOnInconsistentRowLength();
-
- final Column[] columns = new Column[columnNames.length];
- final AlphabeticSequence sequence = new AlphabeticSequence();
- for (int i = 0; i < columnNames.length; i++) {
- final String columnName;
- if (columnNameLineNumber == CsvConfiguration.NO_COLUMN_NAME_LINE) {
- columnName = sequence.next();
- } else {
- columnName = columnNames[i];
- }
- Column column = new MutableColumn(columnName, ColumnType.VARCHAR, this, i, null, null, nullable, null,
- false, null);
- columns[i] = column;
- }
- return columns;
- }
-
- @Override
- public Schema getSchema() {
- return _schema;
- }
-
- @Override
- public TableType getType() {
- return TableType.TABLE;
- }
-
- @Override
- public Relationship[] getRelationships() {
- return new Relationship[0];
- }
-
- @Override
- public String getRemarks() {
- return null;
- }
-
- @Override
- public String getQuote() {
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/eobjects/metamodel/csv/CsvTableDropBuilder.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/eobjects/metamodel/csv/CsvTableDropBuilder.java b/csv/src/main/java/org/eobjects/metamodel/csv/CsvTableDropBuilder.java
deleted file mode 100644
index 29e0202..0000000
--- a/csv/src/main/java/org/eobjects/metamodel/csv/CsvTableDropBuilder.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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.csv;
-
-import org.eobjects.metamodel.drop.AbstractTableDropBuilder;
-import org.eobjects.metamodel.schema.Table;
-
-final class CsvTableDropBuilder extends AbstractTableDropBuilder {
-
- private final CsvUpdateCallback _updateCallback;
-
- public CsvTableDropBuilder(CsvUpdateCallback updateCallback, Table table) {
- super(table);
- _updateCallback = updateCallback;
- }
-
- @Override
- public void execute() {
- _updateCallback.dropTable();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/eobjects/metamodel/csv/CsvUpdateCallback.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/eobjects/metamodel/csv/CsvUpdateCallback.java b/csv/src/main/java/org/eobjects/metamodel/csv/CsvUpdateCallback.java
deleted file mode 100644
index d35ff3b..0000000
--- a/csv/src/main/java/org/eobjects/metamodel/csv/CsvUpdateCallback.java
+++ /dev/null
@@ -1,249 +0,0 @@
-/**
- * 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.csv;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.RandomAccessFile;
-import java.io.Writer;
-import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
-import java.nio.charset.Charset;
-
-import org.eobjects.metamodel.AbstractUpdateCallback;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
-import org.eobjects.metamodel.util.Action;
-import org.eobjects.metamodel.util.EqualsBuilder;
-import org.eobjects.metamodel.util.FileHelper;
-import org.eobjects.metamodel.util.FileResource;
-import org.eobjects.metamodel.util.Resource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-final class CsvUpdateCallback extends AbstractUpdateCallback implements UpdateCallback {
-
- private static final Logger logger = LoggerFactory.getLogger(CsvUpdateCallback.class);
-
- private final CsvConfiguration _configuration;
- private final Resource _resource;
- private Writer _writer;
-
- public CsvUpdateCallback(CsvDataContext dataContext) {
- super(dataContext);
- _resource = dataContext.getResource();
- _configuration = dataContext.getConfiguration();
- }
-
- @Override
- public TableCreationBuilder createTable(Schema schema, String name) throws IllegalArgumentException, IllegalStateException {
- return new CsvCreateTableBuilder(this, schema, name);
- }
-
- @Override
- public RowInsertionBuilder insertInto(Table table) throws IllegalArgumentException, IllegalStateException {
- validateTable(table);
- return new CsvInsertBuilder(this, table);
- }
-
- public CsvConfiguration getConfiguration() {
- return _configuration;
- }
-
- public Resource getResource() {
- return _resource;
- }
-
- private void validateTable(Table table) {
- if (!(table instanceof CsvTable)) {
- throw new IllegalArgumentException("Not a valid CSV table: " + table);
- }
- }
-
- protected synchronized void writeRow(final String[] stringValues, final boolean append) {
- final CsvWriter _csvWriter = new CsvWriter(_configuration);
- final String line = _csvWriter.buildLine(stringValues);
- if (_resource instanceof FileResource) {
- // optimized handling for file-based resources
- final File file = ((FileResource) _resource).getFile();
- final Writer writer = getFileWriter(file, append);
- try {
- writer.write(line);
- } catch (IOException e) {
- throw new MetaModelException("Failed to write line to file: " + line, e);
- }
- } else {
- // generic handling for any kind of resource
- final Action<OutputStream> action = new Action<OutputStream>() {
- @Override
- public void run(OutputStream out) throws Exception {
- final String encoding = _configuration.getEncoding();
- final OutputStreamWriter writer = new OutputStreamWriter(out, encoding);
- writer.write(line);
- writer.flush();
- }
- };
- if (append) {
- _resource.append(action);
- } else {
- _resource.write(action);
- }
- }
- }
-
- private Writer getFileWriter(File file, boolean append) {
- if (_writer == null || !append) {
- final boolean needsLineBreak = needsLineBreak(file, _configuration);
-
- final Writer writer = FileHelper.getWriter(file, _configuration.getEncoding(), append);
- if (needsLineBreak) {
- try {
- writer.write('\n');
- } catch (IOException e) {
- logger.debug("Failed to insert newline", e);
- }
- }
- _writer = writer;
- }
- return _writer;
- }
-
- protected static boolean needsLineBreak(File file, CsvConfiguration configuration) {
- if (!file.exists() || file.length() == 0) {
- return false;
- }
-
- try {
- // find the bytes a newline would match under the encoding
- final byte[] bytesInLineBreak;
- {
- ByteBuffer encodedLineBreak = Charset.forName(configuration.getEncoding()).encode("\n");
- bytesInLineBreak = new byte[encodedLineBreak.capacity()];
- encodedLineBreak.get(bytesInLineBreak);
- }
-
- // find the last bytes of the file
- final byte[] bytesFromFile = new byte[bytesInLineBreak.length];
- {
- final RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");
- try {
- FileChannel channel = randomAccessFile.getChannel();
- try {
- long length = randomAccessFile.length();
-
- channel = channel.position(length - bytesInLineBreak.length);
- channel.read(ByteBuffer.wrap(bytesFromFile));
- } finally {
- channel.close();
- }
- } finally {
- randomAccessFile.close();
- }
- }
-
- // if the two byte arrays match, then the newline is not needed.
- if (EqualsBuilder.equals(bytesInLineBreak, bytesFromFile)) {
- return false;
- }
- return true;
- } catch (Exception e) {
- logger.error("Error occurred while checking if file needs linebreak, omitting check", e);
- }
- return false;
- }
-
- /**
- * Closes all open handles
- */
- protected void close() {
- if (_writer != null) {
- try {
- _writer.flush();
- } catch (IOException e) {
- logger.warn("Failed to flush CSV writer", e);
- }
- try {
- _writer.close();
- } catch (IOException e) {
- logger.error("Failed to close CSV writer", e);
- } finally {
- _writer = null;
- }
- }
- }
-
- @Override
- public RowUpdationBuilder update(Table table) throws IllegalArgumentException, IllegalStateException {
- close();
- return super.update(table);
- }
-
- @Override
- public boolean isDropTableSupported() {
- return true;
- }
-
- @Override
- public TableDropBuilder dropTable(Table table) {
- validateTable(table);
- return new CsvTableDropBuilder(this, table);
- }
-
- /**
- * Callback method used by {@link CsvTableDropBuilder} when execute is
- * called
- */
- protected void dropTable() {
- close();
- if (_resource instanceof FileResource) {
- final File file = ((FileResource) _resource).getFile();
- final boolean success = file.delete();
- if (!success) {
- throw new MetaModelException("Could not delete (drop) file: " + file);
- }
- } else {
- _resource.write(new Action<OutputStream>() {
- @Override
- public void run(OutputStream arg) throws Exception {
- // do nothing, just write an empty file
- }
- });
- }
- }
-
- @Override
- public boolean isDeleteSupported() {
- return true;
- }
-
- @Override
- public RowDeletionBuilder deleteFrom(Table table) {
- validateTable(table);
- return new CsvDeleteBuilder(this, table);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/eobjects/metamodel/csv/CsvWriter.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/eobjects/metamodel/csv/CsvWriter.java b/csv/src/main/java/org/eobjects/metamodel/csv/CsvWriter.java
deleted file mode 100644
index 4a95af4..0000000
--- a/csv/src/main/java/org/eobjects/metamodel/csv/CsvWriter.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/**
- * 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.csv;
-
-import org.eobjects.metamodel.util.Resource;
-
-/**
- * This class is an adaptation of the CSVWriter class of OpenCSV. We've made the
- * writer work without having the output stream as state (suiting for
- * {@link Resource} usage).
- */
-public final class CsvWriter {
-
- public static final int INITIAL_STRING_SIZE = 128;
-
- private final CsvConfiguration _configuration;
-
- public CsvWriter(CsvConfiguration configuration) {
- _configuration = configuration;
- }
-
- /**
- * Builds a line for the CSV file output
- *
- * @param nextLine
- * a string array with each comma-separated element as a separate
- * entry.
- */
- public String buildLine(String[] nextLine) {
- final StringBuilder sb = new StringBuilder(INITIAL_STRING_SIZE);
- for (int i = 0; i < nextLine.length; i++) {
-
- if (i != 0) {
- sb.append(_configuration.getSeparatorChar());
- }
-
- final String nextElement = nextLine[i];
- if (nextElement == null) {
- continue;
- }
- final char quoteChar = _configuration.getQuoteChar();
- if (quoteChar != CsvConfiguration.NOT_A_CHAR) {
- sb.append(quoteChar);
- }
-
- sb.append(stringContainsSpecialCharacters(nextElement) ? processLine(nextElement) : nextElement);
-
- if (quoteChar != CsvConfiguration.NOT_A_CHAR) {
- sb.append(quoteChar);
- }
- }
-
- sb.append('\n');
- return sb.toString();
-
- }
-
- private boolean stringContainsSpecialCharacters(String line) {
- return line.indexOf(_configuration.getQuoteChar()) != -1 || line.indexOf(_configuration.getEscapeChar()) != -1;
- }
-
- private StringBuilder processLine(String nextElement) {
- final StringBuilder sb = new StringBuilder(INITIAL_STRING_SIZE);
- for (int j = 0; j < nextElement.length(); j++) {
- final char nextChar = nextElement.charAt(j);
- final char escapeChar = _configuration.getEscapeChar();
- if (escapeChar != CsvConfiguration.NOT_A_CHAR && nextChar == _configuration.getQuoteChar()) {
- sb.append(escapeChar).append(nextChar);
- } else if (escapeChar != CsvConfiguration.NOT_A_CHAR && nextChar == escapeChar) {
- sb.append(escapeChar).append(nextChar);
- } else {
- sb.append(nextChar);
- }
- }
-
- return sb;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/eobjects/metamodel/csv/InconsistentRowLengthException.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/eobjects/metamodel/csv/InconsistentRowLengthException.java b/csv/src/main/java/org/eobjects/metamodel/csv/InconsistentRowLengthException.java
deleted file mode 100644
index 3fd80d7..0000000
--- a/csv/src/main/java/org/eobjects/metamodel/csv/InconsistentRowLengthException.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * 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.csv;
-
-import org.eobjects.metamodel.InconsistentRowFormatException;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-
-/**
- * Exception thrown when a line in a CSV file has an inconsistent amount of
- * columns compared to the previous lines (and headers). The exception will be
- * thrown when {@link DataSet#next()} is called.
- *
- * Note that this exception is only thrown if the
- * {@link CsvConfiguration#isFailOnInconsistentRowLength()} property is true.
- * Enabling it allows a somewhat different approach to iterating through a
- * resulting DataSet. For example something like:
- *
- * <pre>
- * while (true) {
- * try {
- * if (!dataSet.next) {
- * break;
- * }
- * Row row = dataSet.getRow();
- * handleRegularRow(row);
- * } catch (InconsistentRowLengthException e) {
- * handleIrregularRow(e.getSourceLine());
- * }
- * }
- * </pre>
- *
- * @author Kasper Sørensen
- */
-public final class InconsistentRowLengthException extends
- InconsistentRowFormatException {
-
- private static final long serialVersionUID = 1L;
-
- private final int _columnsInTable;
- private final String[] _line;
-
- public InconsistentRowLengthException(int columnsInTable, Row proposedRow,
- String[] line, int rowNumber) {
- super(proposedRow, rowNumber);
- _columnsInTable = columnsInTable;
- _line = line;
- }
-
- @Override
- public String getMessage() {
- return "Inconsistent length of row no. " + getRowNumber()
- + ". Expected " + getColumnsInTable() + " columns but found "
- + getColumnsInLine() + ".";
- }
-
- /**
- * Gets the source line, as parsed by the CSV parser (regardless of table
- * metadata).
- *
- * @return an array of string values.
- */
- public String[] getSourceLine() {
- return _line;
- }
-
- /**
- * Gets the amount of columns in the parsed line.
- *
- * @return an int representing the amount of values in the inconsistent
- * line.
- */
- public int getColumnsInLine() {
- return _line.length;
- }
-
- /**
- * Gets the expected amounts of columns, as defined by the table metadata.
- *
- * @return an int representing the amount of columns defined in the table.
- */
- public int getColumnsInTable() {
- return _columnsInTable;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/eobjects/metamodel/csv/package-info.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/eobjects/metamodel/csv/package-info.java b/csv/src/main/java/org/eobjects/metamodel/csv/package-info.java
deleted file mode 100644
index b390eb8..0000000
--- a/csv/src/main/java/org/eobjects/metamodel/csv/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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.
- */
-/**
- * Module package for Comma Separated Values (CSV) files
- */
-package org.eobjects.metamodel.csv;
-
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/test/java/org/apache/metamodel/csv/CsvBigFileMemoryTest.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/apache/metamodel/csv/CsvBigFileMemoryTest.java b/csv/src/test/java/org/apache/metamodel/csv/CsvBigFileMemoryTest.java
new file mode 100644
index 0000000..ffc11ca
--- /dev/null
+++ b/csv/src/test/java/org/apache/metamodel/csv/CsvBigFileMemoryTest.java
@@ -0,0 +1,103 @@
+/**
+ * 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.csv;
+
+import java.io.File;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.csv.CsvConfiguration;
+import org.eobjects.metamodel.csv.CsvDataContext;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Table;
+
+import junit.framework.TestCase;
+
+public class CsvBigFileMemoryTest extends TestCase {
+
+ private final int hugeFileRows = 3000;
+ private final int hugeFileCols = 2000;
+
+ private File getHugeFile() {
+ final File file = new File("target/huge_csv.csv");
+ if (!file.exists()) {
+
+ final ExampleDataGenerator exampleDataGenerator = new ExampleDataGenerator(
+ hugeFileRows, hugeFileCols);
+ exampleDataGenerator.createFile(file);
+ }
+ return file;
+ }
+
+ /**
+ * Runs a performance test based on the data created by the
+ * ExampleDataCreator utility.
+ *
+ * @see ExampleDataGenerator
+ * @throws Exception
+ */
+ public void testHugeFile() throws Exception {
+ final File file = getHugeFile();
+
+ final long timeAtStart = System.currentTimeMillis();
+ System.out.println("time at start: " + timeAtStart);
+
+ final DataContext dc = new CsvDataContext(file, new CsvConfiguration());
+ final Table t = dc.getDefaultSchema().getTables()[0];
+
+ final long timeAfterDataContext = System.currentTimeMillis();
+ System.out.println("time after DataContext: " + timeAfterDataContext);
+
+ final Query q = new Query().select(t.getColumns()).from(t);
+ DataSet ds = dc.executeQuery(q);
+
+ long timeAfterQuery = System.currentTimeMillis();
+ System.out.println("time after query: " + timeAfterQuery);
+
+ while (ds.next()) {
+ assertEquals(hugeFileCols, ds.getRow().getValues().length);
+ }
+ ds.close();
+
+ long timeAfterDataSet = System.currentTimeMillis();
+ System.out.println("time after dataSet: " + timeAfterDataSet);
+
+ if (!file.delete()) {
+ file.deleteOnExit();
+ }
+ }
+
+ public void testApproximatedCountHugeFile() throws Exception {
+ DataContext dc = new CsvDataContext(getHugeFile());
+
+ Table table = dc.getDefaultSchema().getTables()[0];
+ Query q = dc.query().from(table).selectCount().toQuery();
+ SelectItem selectItem = q.getSelectClause().getItem(0);
+ selectItem.setFunctionApproximationAllowed(true);
+
+ DataSet ds = dc.executeQuery(q);
+ assertTrue(ds.next());
+ Object[] values = ds.getRow().getValues();
+ assertEquals(1, values.length);
+ assertEquals(3332, ((Long) ds.getRow().getValue(selectItem)).intValue());
+ assertEquals(3332, ((Long) values[0]).intValue());
+ assertFalse(ds.next());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/test/java/org/apache/metamodel/csv/CsvConfigurationTest.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/apache/metamodel/csv/CsvConfigurationTest.java b/csv/src/test/java/org/apache/metamodel/csv/CsvConfigurationTest.java
new file mode 100644
index 0000000..2948762
--- /dev/null
+++ b/csv/src/test/java/org/apache/metamodel/csv/CsvConfigurationTest.java
@@ -0,0 +1,46 @@
+/**
+ * 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.csv;
+
+import junit.framework.TestCase;
+
+public class CsvConfigurationTest extends TestCase {
+
+ public void testToString() throws Exception {
+ CsvConfiguration conf = new CsvConfiguration(0, "UTF8", ',', '"', '\\',
+ true);
+ assertEquals(
+ "CsvConfiguration[columnNameLineNumber=0, encoding=UTF8, separatorChar=,, quoteChar=\", escapeChar=\\, failOnInconsistentRowLength=true]",
+ conf.toString());
+ }
+
+ public void testEquals() throws Exception {
+ CsvConfiguration conf1 = new CsvConfiguration(0, "UTF8", ',', '"',
+ '\\', true);
+ CsvConfiguration conf2 = new CsvConfiguration(0, "UTF8", ',', '"',
+ '\\', true);
+
+ assertEquals(conf1, conf2);
+
+ CsvConfiguration conf3 = new CsvConfiguration(1, "UTF8", ',', '"',
+ '\\', true);
+ assertFalse(conf1.equals(conf3));
+ }
+
+}
\ No newline at end of file
[41/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/schema/MutableTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/MutableTable.java b/core/src/main/java/org/apache/metamodel/schema/MutableTable.java
new file mode 100644
index 0000000..fb54377
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/MutableTable.java
@@ -0,0 +1,202 @@
+/**
+ * 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.schema;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Represents the metadata about a table. Tables reside within a schema and
+ * contains columns and relationships to other tables.
+ *
+ * @see Schema
+ * @see Column
+ * @see Relationship
+ */
+public class MutableTable extends AbstractTable implements Serializable {
+
+ private static final long serialVersionUID = -5094888465714027354L;
+ protected String _name;
+ protected TableType _type;
+ protected String _remarks;
+ protected Schema _schema;
+ protected final List<Column> _columns;
+ protected final List<Relationship> _relationships;
+ protected String _quoteString = null;
+
+ public MutableTable() {
+ super();
+ _columns = new ArrayList<Column>();
+ _relationships = new ArrayList<Relationship>();
+ }
+
+ public MutableTable(String name) {
+ this();
+ setName(name);
+ }
+
+ public MutableTable(String name, TableType type) {
+ this(name);
+ _type = type;
+ }
+
+ public MutableTable(String name, TableType type, Schema schema) {
+ this(name, type);
+ _schema = schema;
+ }
+
+ public MutableTable(String name, TableType type, Schema schema, Column... columns) {
+ this(name, type, schema);
+ setColumns(columns);
+ }
+
+ @Override
+ public String getName() {
+ return _name;
+ }
+
+ public MutableTable setName(String name) {
+ _name = name;
+ return this;
+ }
+
+ /**
+ * Internal getter for the columns of the table. Overwrite this method to
+ * implement column lookup, column lazy-loading or similar.
+ */
+ protected List<Column> getColumnsInternal() {
+ return _columns;
+ }
+
+ /**
+ * Internal getter for the relationships of the table. Overwrite this method
+ * to implement relationship lookup, relationship lazy-loading or similar.
+ */
+ protected List<Relationship> getRelationshipsInternal() {
+ return _relationships;
+ }
+
+ @Override
+ public Column[] getColumns() {
+ List<Column> columns = getColumnsInternal();
+ return columns.toArray(new Column[columns.size()]);
+ }
+
+ public MutableTable setColumns(Column... columns) {
+ _columns.clear();
+ for (Column column : columns) {
+ _columns.add(column);
+ }
+ return this;
+ }
+
+ public MutableTable setColumns(Collection<Column> columns) {
+ _columns.clear();
+ for (Column column : columns) {
+ _columns.add(column);
+ }
+ return this;
+ }
+
+ public MutableTable addColumn(Column column) {
+ _columns.add(column);
+ return this;
+ }
+
+ public MutableTable addColumn(int index, Column column) {
+ _columns.add(index, column);
+ return this;
+ }
+
+ public MutableTable removeColumn(Column column) {
+ _columns.remove(column);
+ return this;
+ }
+
+ @Override
+ public Schema getSchema() {
+ return _schema;
+ }
+
+ public MutableTable setSchema(Schema schema) {
+ _schema = schema;
+ return this;
+ }
+
+ @Override
+ public TableType getType() {
+ return _type;
+ }
+
+ public MutableTable setType(TableType type) {
+ _type = type;
+ return this;
+ }
+
+ @Override
+ public Relationship[] getRelationships() {
+ List<Relationship> relationships = getRelationshipsInternal();
+ return relationships.toArray(new Relationship[relationships.size()]);
+ }
+
+ /**
+ * Protected method for adding a relationship to this table. Should not be
+ * used. Use Relationship.createRelationship(Column[], Column[]) instead.
+ */
+ protected void addRelationship(Relationship relation) {
+ for (Relationship existingRelationship : _relationships) {
+ if (existingRelationship.equals(relation)) {
+ // avoid duplicate relationships
+ return;
+ }
+ }
+ _relationships.add(relation);
+ }
+
+ /**
+ * Protected method for removing a relationship from this table. Should not
+ * be used. Use Relationship.remove() instead.
+ */
+ protected MutableTable removeRelationship(Relationship relation) {
+ _relationships.remove(relation);
+ return this;
+ }
+
+ @Override
+ public String getRemarks() {
+ return _remarks;
+ }
+
+ public MutableTable setRemarks(String remarks) {
+ _remarks = remarks;
+ return this;
+ }
+
+ @Override
+ public String getQuote() {
+ return _quoteString;
+ }
+
+ public MutableTable setQuote(String quoteString) {
+ _quoteString = quoteString;
+ return 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/schema/NamedStructure.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/NamedStructure.java b/core/src/main/java/org/apache/metamodel/schema/NamedStructure.java
new file mode 100644
index 0000000..a5027d6
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/NamedStructure.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.schema;
+
+import org.eobjects.metamodel.util.HasName;
+
+/**
+ * Super-interface for named structural types in a DataContext.
+ *
+ * @author Kasper Sørensen
+ */
+public interface NamedStructure extends HasName {
+
+ /**
+ * Gets the name of this structure.
+ *
+ * @return The name of the structure
+ */
+ public String getName();
+
+ /**
+ * Gets an optional quote string that is used to enclose the name of this
+ * structure.
+ *
+ * @return A quote string used to enclose the name or null if none exists.
+ */
+ public String getQuote();
+
+ /**
+ * Gets the name, including optional quotes, of this structure.
+ *
+ * @return The name of the structure with added quote strings.
+ */
+ public String getQuotedName();
+
+ /**
+ * Gets a qualified label for later lookup. Typically this qualified label
+ * is formatted with a simple dot separator. For example, for a column a
+ * typical qualified label would be: "MY_SCHEMA.MY_TABLE.MY_COLUMN".
+ *
+ * The qualified label can be used as a unique identifier for the structure
+ * but is not necessarily directly transferable to SQL syntax.
+ *
+ * @return a qualified label
+ */
+ public String getQualifiedLabel();
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/schema/Relationship.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/Relationship.java b/core/src/main/java/org/apache/metamodel/schema/Relationship.java
new file mode 100644
index 0000000..00a63d9
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/Relationship.java
@@ -0,0 +1,74 @@
+/**
+ * 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.schema;
+
+import java.io.Serializable;
+
+/**
+ * Represents a relationship between two tables where one set of columns is the
+ * primary key, and another set is the foreign key.
+ *
+ * @see Table
+ * @see Column
+ *
+ * @author Kasper Sørensen
+ */
+public interface Relationship extends Serializable, Comparable<Relationship> {
+
+ /**
+ * Gets the table of the primary key column(s).
+ *
+ * @return the table of the primary key column(s).
+ */
+ public Table getPrimaryTable();
+
+ /**
+ * Gets the primary key columns of this relationship.
+ *
+ * @return an array of primary key columns.
+ */
+ public Column[] getPrimaryColumns();
+
+ /**
+ * Gets the table of the foreign key column(s).
+ *
+ * @return the table of the foreign key column(s).
+ */
+ public Table getForeignTable();
+
+ /**
+ * Gets the foreign key columns of this relationship.
+ *
+ * @return an array of foreign key columns.
+ */
+ public Column[] getForeignColumns();
+
+ /**
+ * Determines whether this relationship contains a specific pair of columns
+ *
+ * @param pkColumn
+ * primary key column
+ * @param fkColumn
+ * foreign key column
+ * @return true if this relation contains the specified primary and foreign
+ * columns as a part of the relation
+ */
+ public boolean containsColumnPair(Column pkColumn, Column fkColumn);
+
+}
\ 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/schema/Schema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/Schema.java b/core/src/main/java/org/apache/metamodel/schema/Schema.java
new file mode 100644
index 0000000..6aa7183
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/Schema.java
@@ -0,0 +1,121 @@
+/**
+ * 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.schema;
+
+import java.io.Serializable;
+
+import org.eobjects.metamodel.DataContext;
+
+/**
+ * Represents a schema and it's metadata description. Schemas represent a
+ * collection of tables.
+ *
+ * @see DataContext
+ * @see Table
+ *
+ * @author Kasper Sørensen
+ */
+public interface Schema extends Comparable<Schema>, Serializable, NamedStructure {
+
+ /**
+ * Gets the name of this Schema
+ *
+ * @return the name of this Schema
+ */
+ @Override
+ public String getName();
+
+ /**
+ * Gets the number of tables that reside in this schema.
+ *
+ * @return the number of tables that reside in this schema.
+ */
+ public int getTableCount();
+
+ /**
+ * Gets the number of tables in this Schema that comply to a given
+ * TableType.
+ *
+ * @param type
+ * the TableType to use for searching and matching.
+ * @return the count of tables that match the provided TableType.
+ */
+ public int getTableCount(TableType type);
+
+ /**
+ * Gets the names of the tables that reside in this Schema.
+ *
+ * @return an array of table names.
+ */
+ public String[] getTableNames();
+
+ /**
+ * Gets all tables in this Schema.
+ *
+ * @return the tables that reside in the schema
+ */
+ public Table[] getTables();
+
+ /**
+ * Gets all tables in this Schema of a particular type.
+ *
+ * @param type
+ * the TableType to use for searching and matching.
+ * @return an array of tables in this schema that matches the specified
+ * type.
+ */
+ public Table[] getTables(TableType type);
+
+ /**
+ * Gets a table by index. Use {@link #getTableCount()} to get the (0-based)
+ * index range
+ *
+ * @param index
+ * the index of the table
+ * @return the column with the specified index
+ *
+ * @throws IndexOutOfBoundsException
+ * if the index is out of bounds (index >= table count)
+ */
+ public Table getTable(int index) throws IndexOutOfBoundsException;
+
+ /**
+ * Convenience method for retrieving a table by it's name.
+ *
+ * @param tableName
+ * the name of the table to retrieve
+ * @return the table with the given name. Returns null if no such table is
+ * found.
+ */
+ public Table getTableByName(String tableName);
+
+ /**
+ * Gets all relationships to and from this Schema.
+ *
+ * @return an array of relationships.
+ */
+ public Relationship[] getRelationships();
+
+ /**
+ * Gets the number of relationships to and from this Schema.
+ *
+ * @return the number of relationships to and from this Schema
+ */
+ public int getRelationshipCount();
+}
\ 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/schema/SuperColumnType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/SuperColumnType.java b/core/src/main/java/org/apache/metamodel/schema/SuperColumnType.java
new file mode 100644
index 0000000..d6545bc
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/SuperColumnType.java
@@ -0,0 +1,53 @@
+/**
+ * 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.schema;
+
+import java.util.Date;
+
+/**
+ * Represents an abstract, generalized type of column
+ */
+public enum SuperColumnType {
+
+ BOOLEAN_TYPE(Boolean.class),
+
+ LITERAL_TYPE(String.class),
+
+ NUMBER_TYPE(Number.class),
+
+ TIME_TYPE(Date.class),
+
+ BINARY_TYPE(byte[].class),
+
+ OTHER_TYPE(Object.class);
+
+ private Class<?> _javaEquivalentClass;
+
+ private SuperColumnType(Class<?> javaEquivalentClass) {
+ _javaEquivalentClass = javaEquivalentClass;
+ }
+
+ /**
+ * @return a java class that is appropriate for handling column values of
+ * this column super type
+ */
+ public Class<?> getJavaEquivalentClass() {
+ return _javaEquivalentClass;
+ }
+}
\ 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/schema/Table.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/Table.java b/core/src/main/java/org/apache/metamodel/schema/Table.java
new file mode 100644
index 0000000..bc9043c
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/Table.java
@@ -0,0 +1,215 @@
+/**
+ * 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.schema;
+
+import java.io.Serializable;
+
+/**
+ * Represents a table and it's metadata description. Tables reside within a
+ * schema and contains columns and relationships to other tables.
+ *
+ * @see Schema
+ * @see Column
+ *
+ * @author Kasper Sørensen
+ */
+public interface Table extends Comparable<Table>, Serializable, NamedStructure {
+
+ /**
+ * Gets the name of this Table
+ *
+ * @return the name of this Table
+ */
+ @Override
+ public String getName();
+
+ /**
+ * Gets the number of columns in this table.
+ *
+ * @return the number of columns in this table.
+ */
+ public int getColumnCount();
+
+ /**
+ * Gets the columns of this table.
+ *
+ * @return the columns of this table.
+ */
+ public Column[] getColumns();
+
+ /**
+ * Convenience method for retrieving a column by it's name.
+ *
+ * @param columnName
+ * the name of the column to retrieve
+ * @return the column with the given name. Returns null if no such column is
+ * found.
+ */
+ public Column getColumnByName(String columnName);
+
+ /**
+ * Gets a column by index. Use {@link #getColumnCount()} to get the
+ * (0-based) index range.
+ *
+ * @param index
+ * the index of the column
+ * @return the column with the specified index
+ * @throws IndexOutOfBoundsException
+ * if the index is out of bounds (index >= column count)
+ */
+ public Column getColumn(int index) throws IndexOutOfBoundsException;
+
+ /**
+ * Gets the schema that this table resides in.
+ *
+ * @return the schema that the table resides in.
+ */
+ public Schema getSchema();
+
+ /**
+ * Gets the table type of this table.
+ *
+ * @return the type of table
+ */
+ public TableType getType();
+
+ /**
+ * Gets all relationships for this table.
+ *
+ * @return all relationsips for this table. To add relations use
+ * TableRelation.createRelation();
+ */
+ public Relationship[] getRelationships();
+
+ /**
+ * Gets relationships between this table and another table.
+ *
+ * @param otherTable
+ * another table for which to find relationships to and from.
+ * @return an array of relationsips between this and the other table.
+ */
+ public Relationship[] getRelationships(Table otherTable);
+
+ /**
+ * Gets a count of relationships to and from this table.
+ *
+ * @return a count of relationships to and from this table.
+ */
+ public int getRelationshipCount();
+
+ /**
+ * Gets remarks/comments to this table.
+ *
+ * @return remarks/comments to this table or null if none exist.
+ */
+ public String getRemarks();
+
+ /**
+ * Gets all of this table's columns that are of number type.
+ *
+ * @return an array of columns.
+ * @see ColumnType
+ */
+ public Column[] getNumberColumns();
+
+ /**
+ * Gets all of this table's columns that are of literal (String/text) type.
+ *
+ * @return an array of columns.
+ * @see ColumnType
+ */
+ public Column[] getLiteralColumns();
+
+ /**
+ * Gets all of this table's columns that are time and/or date based.
+ *
+ * @return an array of columns.
+ * @see ColumnType
+ */
+ public Column[] getTimeBasedColumns();
+
+ /**
+ * Gets all of this table's columns that are of boolean type.
+ *
+ * @return an array of columns.
+ * @see ColumnType
+ */
+ public Column[] getBooleanColumns();
+
+ /**
+ * Gets all of this table's columns that are indexed.
+ *
+ * @return an array of columns.
+ */
+ public Column[] getIndexedColumns();
+
+ /**
+ * @return the relationships where this table is the foreign table
+ */
+ public Relationship[] getForeignKeyRelationships();
+
+ /**
+ * @return the relationships where this table is the primary table
+ */
+ public Relationship[] getPrimaryKeyRelationships();
+
+ /**
+ * Gets the columns of this table that are known to be foreign keys (ie.
+ * references primary keys in other tables).
+ *
+ * @return an array of columns that are known to be foreign keys.
+ */
+ public Column[] getForeignKeys();
+
+ /**
+ * Gets the columns of this table that are known to be primary keys. See
+ * {@link Column#isPrimaryKey()}.
+ *
+ * @return an array of columns that are known to be primary keys.
+ */
+ public Column[] getPrimaryKeys();
+
+ /**
+ * Gets the names of this table's columns.
+ *
+ * @return an array of column names.
+ */
+ public String[] getColumnNames();
+
+ /**
+ * Gets the columns of this table that conforms to a specified
+ * {@link ColumnType}.
+ *
+ * @param columnType
+ * the column type to search for.
+ * @return an array of columns that match the specified ColumnType.
+ */
+ public Column[] getColumnsOfType(ColumnType columnType);
+
+ /**
+ * Gets the columns of this table that conforms to a specified
+ * {@link SuperColumnType}.
+ *
+ * @param superColumnType
+ * the super type of the column
+ * @return an array of columns that match the specified SuperColumnType.
+ */
+ public Column[] getColumnsOfSuperType(SuperColumnType superColumnType);
+
+}
\ 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/schema/TableType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/TableType.java b/core/src/main/java/org/apache/metamodel/schema/TableType.java
new file mode 100644
index 0000000..51b7361
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/TableType.java
@@ -0,0 +1,70 @@
+/**
+ * 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.schema;
+
+/**
+ * Represents the various types of tables
+ */
+public enum TableType {
+
+ TABLE, VIEW, SYSTEM_TABLE, GLOBAL_TEMPORARY, LOCAL_TEMPORARY, ALIAS, SYNONYM, OTHER;
+
+ public static final TableType[] DEFAULT_TABLE_TYPES = new TableType[] {
+ TableType.TABLE, TableType.VIEW };
+
+ public boolean isMaterialized() {
+ switch (this) {
+ case TABLE:
+ case SYSTEM_TABLE:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * Tries to resolve a TableType based on an incoming string/literal. If no
+ * fitting TableType is found, OTHER will be returned.
+ */
+ public static TableType getTableType(String literalType) {
+ literalType = literalType.toUpperCase();
+ if ("TABLE".equals(literalType)) {
+ return TABLE;
+ }
+ if ("VIEW".equals(literalType)) {
+ return VIEW;
+ }
+ if ("SYSTEM_TABLE".equals(literalType)) {
+ return SYSTEM_TABLE;
+ }
+ if ("GLOBAL_TEMPORARY".equals(literalType)) {
+ return GLOBAL_TEMPORARY;
+ }
+ if ("LOCAL_TEMPORARY".equals(literalType)) {
+ return LOCAL_TEMPORARY;
+ }
+ if ("ALIAS".equals(literalType)) {
+ return ALIAS;
+ }
+ if ("SYNONYM".equals(literalType)) {
+ return SYNONYM;
+ }
+ return OTHER;
+ }
+}
\ 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/schema/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/package-info.java b/core/src/main/java/org/apache/metamodel/schema/package-info.java
new file mode 100644
index 0000000..87d991f
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/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 schema structure
+ */
+package org.eobjects.metamodel.schema;
+
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/update/AbstractRowUpdationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/update/AbstractRowUpdationBuilder.java b/core/src/main/java/org/apache/metamodel/update/AbstractRowUpdationBuilder.java
new file mode 100644
index 0000000..fd4341c
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/update/AbstractRowUpdationBuilder.java
@@ -0,0 +1,122 @@
+/**
+ * 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.update;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eobjects.metamodel.data.AbstractRowBuilder;
+import org.eobjects.metamodel.query.FilterClause;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.query.builder.AbstractFilterBuilder;
+import org.eobjects.metamodel.query.builder.FilterBuilder;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * Abstract {@link RowUpdationBuilder} implementation.
+ */
+public abstract class AbstractRowUpdationBuilder extends AbstractRowBuilder<RowUpdationBuilder> implements
+ RowUpdationBuilder {
+
+ private final Table _table;
+ private final List<FilterItem> _whereItems;
+
+ public AbstractRowUpdationBuilder(Table table) {
+ super(table);
+ _table = table;
+ _whereItems = new ArrayList<FilterItem>();
+ }
+
+ protected List<FilterItem> getWhereItems() {
+ return _whereItems;
+ }
+
+ @Override
+ public FilterBuilder<RowUpdationBuilder> where(Column column) {
+ SelectItem selectItem = new SelectItem(column);
+ return new AbstractFilterBuilder<RowUpdationBuilder>(selectItem) {
+ @Override
+ protected RowUpdationBuilder applyFilter(FilterItem filter) {
+ return where(filter);
+ }
+ };
+ }
+
+ @Override
+ public FilterBuilder<RowUpdationBuilder> where(String columnName) {
+ Column column = _table.getColumnByName(columnName);
+ if (column == null) {
+ throw new IllegalArgumentException("No such column: " + columnName);
+ }
+ return where(column);
+ }
+
+ @Override
+ public RowUpdationBuilder where(FilterItem... filterItems) {
+ for (FilterItem filterItem : filterItems) {
+ _whereItems.add(filterItem);
+ }
+ return this;
+ }
+
+ @Override
+ public RowUpdationBuilder where(Iterable<FilterItem> filterItems) {
+ for (FilterItem filterItem : filterItems) {
+ _whereItems.add(filterItem);
+ }
+ return this;
+ }
+
+ @Override
+ public Table getTable() {
+ return _table;
+ }
+
+ @Override
+ public String toSql() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("UPDATE ");
+ sb.append(_table.getQualifiedLabel());
+ sb.append(" SET ");
+ Column[] columns = getColumns();
+ Object[] values = getValues();
+
+ for (int i = 0; i < columns.length; i++) {
+ if (i != 0) {
+ sb.append(',');
+ }
+ sb.append(columns[i].getName());
+ sb.append('=');
+ sb.append(values[i] == null ? "NULL" : values[i].toString());
+ }
+
+ List<FilterItem> whereItems = getWhereItems();
+ String whereClause = new FilterClause(null, " WHERE ").addItems(whereItems).toSql();
+ sb.append(whereClause);
+ return sb.toString();
+ }
+
+ @Override
+ public String toString() {
+ return toSql();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/update/RowUpdateable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/update/RowUpdateable.java b/core/src/main/java/org/apache/metamodel/update/RowUpdateable.java
new file mode 100644
index 0000000..8e42517
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/update/RowUpdateable.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.update;
+
+import org.eobjects.metamodel.schema.Table;
+
+public interface RowUpdateable {
+
+ /**
+ * Determines whether row update is supported
+ *
+ * @return true if row update is supported
+ */
+ public boolean isUpdateSupported();
+
+ /**
+ * Initiates a row updation builder.
+ *
+ * @param table
+ * @return
+ * @throws IllegalArgumentException
+ * @throws IllegalStateException
+ * @throws UnsupportedOperationException
+ */
+ public RowUpdationBuilder update(Table table) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException;
+
+ /**
+ * Initiates a row updation builder.
+ *
+ * @param tableName
+ * @return
+ * @throws IllegalArgumentException
+ * @throws IllegalStateException
+ * @throws UnsupportedOperationException
+ */
+ public RowUpdationBuilder update(String tableName) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException;
+
+ /**
+ * Initiates a row updation builder.
+ *
+ * @param schemaName
+ * @param tableName
+ * @return
+ * @throws IllegalArgumentException
+ * @throws IllegalStateException
+ * @throws UnsupportedOperationException
+ */
+ public RowUpdationBuilder update(String schemaName, String tableName) throws IllegalArgumentException,
+ IllegalStateException, UnsupportedOperationException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/update/RowUpdationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/update/RowUpdationBuilder.java b/core/src/main/java/org/apache/metamodel/update/RowUpdationBuilder.java
new file mode 100644
index 0000000..500d066
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/update/RowUpdationBuilder.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.update;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.data.RowBuilder;
+import org.eobjects.metamodel.data.WhereClauseBuilder;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * Builder object for row update on a {@link Table}.
+ *
+ * @author Kasper Sørensen
+ */
+public interface RowUpdationBuilder extends RowBuilder<RowUpdationBuilder>, WhereClauseBuilder<RowUpdationBuilder> {
+
+ /**
+ * Gets the table that this update pertains to.
+ *
+ * @return the table that this update pertains to.
+ */
+ @Override
+ public Table getTable();
+
+ /**
+ * Gets a SQL representation of this update 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 update operation.
+ */
+ public String toSql();
+
+ /**
+ * Commits the row updation operation. This operation will overwrite rows in
+ * the {@link DataContext}.
+ *
+ * @throws MetaModelException
+ * if the operation was rejected
+ */
+ public void execute() throws MetaModelException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/update/Update.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/update/Update.java b/core/src/main/java/org/apache/metamodel/update/Update.java
new file mode 100644
index 0000000..540dc3c
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/update/Update.java
@@ -0,0 +1,122 @@
+/**
+ * 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.update;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.UpdateableDataContext;
+import org.eobjects.metamodel.data.AbstractRowBuilder;
+import org.eobjects.metamodel.data.Style;
+import org.eobjects.metamodel.data.WhereClauseBuilder;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.query.builder.AbstractFilterBuilder;
+import org.eobjects.metamodel.query.builder.FilterBuilder;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * Represents a single UPDATE 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 update
+ * implementation. Some {@link DataContext}s may even optimize specifically
+ * based on the knowledge that there will only be a single update statement
+ * executed.
+ */
+public final class Update extends AbstractRowBuilder<Update> implements UpdateScript, WhereClauseBuilder<Update> {
+
+ private final Table _table;
+ private final List<FilterItem> _whereItems;
+
+ public Update(Table table) {
+ super(table);
+ _table = table;
+ _whereItems = new ArrayList<FilterItem>();
+ }
+
+ @Override
+ public Table getTable() {
+ return _table;
+ }
+
+ @Override
+ public void run(UpdateCallback callback) {
+ RowUpdationBuilder updateBuilder = callback.update(_table).where(_whereItems);
+
+ final Column[] columns = getColumns();
+ final Object[] values = getValues();
+ final Style[] styles = getStyles();
+ final boolean[] explicitNulls = getExplicitNulls();
+
+ for (int i = 0; i < columns.length; i++) {
+ Object value = values[i];
+ Column column = columns[i];
+ Style style = styles[i];
+ if (value == null) {
+ if (explicitNulls[i]) {
+ updateBuilder = updateBuilder.value(column, value, style);
+ }
+ } else {
+ updateBuilder = updateBuilder.value(column, value, style);
+ }
+ }
+
+ updateBuilder.execute();
+ }
+
+ @Override
+ public FilterBuilder<Update> where(Column column) {
+ SelectItem selectItem = new SelectItem(column);
+ return new AbstractFilterBuilder<Update>(selectItem) {
+ @Override
+ protected Update applyFilter(FilterItem filter) {
+ return where(filter);
+ }
+ };
+ }
+
+ @Override
+ public FilterBuilder<Update> where(String columnName) {
+ Column column = _table.getColumnByName(columnName);
+ if (column == null) {
+ throw new IllegalArgumentException("No such column: " + columnName);
+ }
+ return where(column);
+ }
+
+ @Override
+ public Update where(FilterItem... filterItems) {
+ for (FilterItem filterItem : filterItems) {
+ _whereItems.add(filterItem);
+ }
+ return this;
+ }
+
+ @Override
+ public Update where(Iterable<FilterItem> filterItems) {
+ for (FilterItem filterItem : filterItems) {
+ _whereItems.add(filterItem);
+ }
+ return this;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/update/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/update/package-info.java b/core/src/main/java/org/apache/metamodel/update/package-info.java
new file mode 100644
index 0000000..4b03ca5
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/update/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 updating rows
+ */
+package org.eobjects.metamodel.update;
+
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/Action.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/Action.java b/core/src/main/java/org/apache/metamodel/util/Action.java
new file mode 100644
index 0000000..2d79054
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/Action.java
@@ -0,0 +1,34 @@
+/**
+ * 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.util;
+
+/**
+ * Represents an abstract action, which is an executable piece of functionality
+ * that takes an argument. An {@link Action} has no return type, unlike a
+ * {@link Func}.
+ *
+ * @author Kasper Sørensen
+ *
+ * @param <E>
+ * the argument type of the action
+ */
+public interface Action<E> {
+
+ public void run(E arg) throws Exception;
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/AggregateBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/AggregateBuilder.java b/core/src/main/java/org/apache/metamodel/util/AggregateBuilder.java
new file mode 100644
index 0000000..3663959
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/AggregateBuilder.java
@@ -0,0 +1,35 @@
+/**
+ * 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.util;
+
+/**
+ * Interface for aggregate builders which allows for an iterative approach to
+ * evaluating aggregates.
+ *
+ * @author Kasper Sørensen
+ *
+ * @param <E>
+ * the aggregate result type
+ */
+public interface AggregateBuilder<E> {
+
+ public void add(Object o);
+
+ public E getAggregate();
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/AlphabeticSequence.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/AlphabeticSequence.java b/core/src/main/java/org/apache/metamodel/util/AlphabeticSequence.java
new file mode 100644
index 0000000..5f578f6
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/AlphabeticSequence.java
@@ -0,0 +1,86 @@
+/**
+ * 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.util;
+
+/**
+ * A sequence based on alphabetic representations. Typically a sequence begin
+ * with "A", "B", "C" etc. and go from "Z" to "AA", from "AZ" to "BA" etc.
+ *
+ * This sequence is practical for generating column names that correspond to
+ * column identifiers in spreadsheets and the like.
+ *
+ * @author Kasper Sørensen
+ */
+public class AlphabeticSequence {
+
+ private StringBuilder _stringBuilder;
+
+ /**
+ * Creates an alphabetic sequence that will have "A" as it's first value, if
+ * iterated using next().
+ */
+ public AlphabeticSequence() {
+ this(Character.toString((char) ('A' - 1)));
+ }
+
+ /**
+ * Creates an alphabetic sequence based on a value
+ *
+ * @param value
+ */
+ public AlphabeticSequence(String value) {
+ _stringBuilder = new StringBuilder(value.toUpperCase());
+ }
+
+ /**
+ * Gets the current value (ie. doesn't iterate).
+ *
+ * @return a string identifier, eg. "A", "B", "AA" etc.
+ */
+ public String current() {
+ return _stringBuilder.toString();
+ }
+
+ /**
+ * Iterates to the next value and returns it.
+ *
+ * @return a string identifier, eg. "A", "B", "AA" etc.
+ */
+ public String next() {
+ boolean updated = false;
+ int length = _stringBuilder.length();
+ for (int i = length - 1; i >= 0; i--) {
+ char c = _stringBuilder.charAt(i);
+ if (c != 'Z') {
+ c = (char) (c + 1);
+ _stringBuilder.setCharAt(i, c);
+ updated = true;
+ break;
+ } else {
+ _stringBuilder.setCharAt(i, 'A');
+ }
+ }
+
+ if (!updated) {
+ // need to add another char
+ _stringBuilder.append('A');
+ }
+ return current();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/BaseObject.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/BaseObject.java b/core/src/main/java/org/apache/metamodel/util/BaseObject.java
new file mode 100644
index 0000000..dde30da
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/BaseObject.java
@@ -0,0 +1,166 @@
+/**
+ * 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.util;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A base object type with conveniently implemented base methods like hashCode()
+ * and equals(). Subclasses should implement the {@link #decorateIdentity(List)}
+ * method to have {@link #equals(Object)} and {@link #hashCode()} automatically
+ * implemented.
+ *
+ * @author Kasper Sørensen
+ */
+public abstract class BaseObject {
+
+ private static final Logger logger = LoggerFactory
+ .getLogger(BaseObject.class);
+
+ @Override
+ public String toString() {
+ // overridden version of toString() method that uses identity hash code
+ // (to prevent hashCode() recursion due to logging!)
+ return getClass().getName() + "@"
+ + Integer.toHexString(System.identityHashCode(this));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final int hashCode() {
+ logger.debug("{}.hashCode()", this);
+ int hashCode = -1;
+ List<Object> list = new ArrayList<Object>();
+ decorateIdentity(list);
+ if (list.isEmpty()) {
+ list.add(toString());
+ }
+ hashCode -= list.size();
+ for (Object obj : list) {
+ hashCode += hashCode(obj);
+ }
+ return hashCode;
+ }
+
+ private static final int hashCode(Object obj) {
+ if (obj == null) {
+ logger.debug("obj is null, returning constant");
+ return -17;
+ }
+ if (obj.getClass().isArray()) {
+ logger.debug("obj is an array, returning a sum");
+ int length = Array.getLength(obj);
+ int hashCode = 4324;
+ for (int i = 0; i < length; i++) {
+ Object o = Array.get(obj, i);
+ hashCode += hashCode(o);
+ }
+ return hashCode;
+ }
+ logger.debug("obj is a regular object, returning hashCode");
+ return obj.hashCode();
+ }
+
+ /**
+ * Override this method if the equals method should support different
+ * subtypes. For example, if different subtypes of Number should be
+ * supported, implement this method with:
+ *
+ * <code>
+ * obj instanceof Number
+ * </code>
+ *
+ * and make sure that the decorateIdentity(...) method will always return a
+ * comparable list of identity-objects.
+ *
+ * @param obj
+ * @return true if the provided object's class is accepted for equals
+ * comparison
+ */
+ protected boolean classEquals(BaseObject obj) {
+ return getClass() == obj.getClass();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (obj == this) {
+ return true;
+ }
+ if (obj instanceof BaseObject) {
+ BaseObject that = (BaseObject) obj;
+ if (classEquals(that)) {
+ List<Object> list1 = new ArrayList<Object>();
+ List<Object> list2 = new ArrayList<Object>();
+
+ decorateIdentity(list1);
+ that.decorateIdentity(list2);
+
+ if (list1.size() != list2.size()) {
+ throw new IllegalStateException(
+ "Two instances of the same class ("
+ + getClass().getName()
+ + ") returned different size decorated identity lists");
+ }
+
+ if (list1.isEmpty()) {
+ assert list2.isEmpty();
+ list1.add(toString());
+ list2.add(that.toString());
+ }
+
+ EqualsBuilder eb = new EqualsBuilder();
+
+ Iterator<Object> it1 = list1.iterator();
+ Iterator<Object> it2 = list2.iterator();
+ while (it1.hasNext()) {
+ assert it2.hasNext();
+ Object next1 = it1.next();
+ Object next2 = it2.next();
+ eb.append(next1, next2);
+ }
+ assert !it2.hasNext();
+
+ return eb.isEquals();
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Subclasses should implement this method and add all fields to the list
+ * that are to be included in equals(...) and hashCode() evaluation
+ *
+ * @param identifiers
+ */
+ protected abstract void decorateIdentity(List<Object> identifiers);
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/BooleanComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/BooleanComparator.java b/core/src/main/java/org/apache/metamodel/util/BooleanComparator.java
new file mode 100644
index 0000000..22bc9f1
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/BooleanComparator.java
@@ -0,0 +1,162 @@
+/**
+ * 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.util;
+
+import java.util.Comparator;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Comparator of booleans
+ *
+ * @author Kasper Sørensen
+ */
+public final class BooleanComparator implements Comparator<Object> {
+
+ private static final Logger logger = LoggerFactory
+ .getLogger(BooleanComparator.class);
+
+ private static BooleanComparator _instance = new BooleanComparator();
+
+ private BooleanComparator() {
+ }
+
+ public static Comparator<Object> getComparator() {
+ return _instance;
+ }
+
+ public static Comparable<Object> getComparable(Object object) {
+ final Boolean b = toBoolean(object);
+ return new Comparable<Object>() {
+
+ @Override
+ public boolean equals(Object obj) {
+ return _instance.equals(obj);
+ }
+
+ public int compareTo(Object o) {
+ return _instance.compare(b, o);
+ }
+
+ @Override
+ public String toString() {
+ return "BooleanComparable[boolean=" + b + "]";
+ }
+ };
+ }
+
+ public int compare(Object o1, Object o2) {
+ if (o1 == null && o2 == null) {
+ return 0;
+ }
+ if (o1 == null) {
+ return -1;
+ }
+ if (o2 == null) {
+ return 1;
+ }
+ Boolean b1 = toBoolean(o1);
+ Boolean b2 = toBoolean(o2);
+ return b1.compareTo(b2);
+ }
+
+ public static Boolean toBoolean(Object o) {
+ if (o == null) {
+ return null;
+ }
+
+ if (o instanceof Boolean) {
+ return (Boolean) o;
+ }
+ if (o instanceof String) {
+ try {
+ return parseBoolean((String) o);
+ } catch (IllegalArgumentException e) {
+ logger.warn(
+ "Could not convert String '{}' to boolean, returning false", o);
+ return false;
+ }
+ }
+ if (o instanceof Number) {
+ int i = ((Number) o).intValue();
+ return i >= 1;
+ }
+
+ logger.warn(
+ "Could not convert '{}' to boolean, returning false",
+ o);
+ return false;
+ }
+
+ /**
+ * Parses a string and returns a boolean representation of it. To parse the
+ * string the following values will be accepted, irrespective of case.
+ * <ul>
+ * <li>true</li>
+ * <li>false</li>
+ * <li>1</li>
+ * <li>0</li>
+ * <li>yes</li>
+ * <li>no</li>
+ * <li>y</li>
+ * <li>n</li>
+ * </ul>
+ *
+ * @param string
+ * the string to parse
+ * @return a boolean
+ * @throws IllegalArgumentException
+ * if the string provided is null or cannot be parsed as a
+ * boolean
+ */
+ public static boolean parseBoolean(String string)
+ throws IllegalArgumentException {
+ if (string == null) {
+ throw new IllegalArgumentException("string cannot be null");
+ }
+ string = string.trim();
+ if ("true".equalsIgnoreCase(string) || "1".equals(string)
+ || "y".equalsIgnoreCase(string)
+ || "yes".equalsIgnoreCase(string)) {
+ return true;
+ } else if ("false".equalsIgnoreCase(string) || "0".equals(string)
+ || "n".equalsIgnoreCase(string)
+ || "no".equalsIgnoreCase(string)) {
+ return false;
+ } else {
+ throw new IllegalArgumentException(
+ "Could not get boolean value of string: " + string);
+ }
+ }
+
+ public static boolean isBoolean(Object o) {
+ if (o instanceof Boolean) {
+ return true;
+ }
+ if (o instanceof String) {
+ if ("true".equalsIgnoreCase((String) o)
+ || "false".equalsIgnoreCase((String) o)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/ClasspathResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/ClasspathResource.java b/core/src/main/java/org/apache/metamodel/util/ClasspathResource.java
new file mode 100644
index 0000000..e38b372
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/ClasspathResource.java
@@ -0,0 +1,145 @@
+/**
+ * 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.util;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.net.URL;
+
+/**
+ * A {@link Resource} based on a classpath entry
+ */
+public class ClasspathResource implements Resource, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private final String _resourcePath;
+
+ public ClasspathResource(String resourcePath) {
+ if (resourcePath == null) {
+ throw new IllegalArgumentException("Classpath resource path cannot be null");
+ }
+ _resourcePath = resourcePath;
+ }
+
+ @Override
+ public String toString() {
+ return "ClasspathResource[" + _resourcePath + "]";
+ }
+
+ /**
+ * Gets the name of the classpath entry
+ * @return
+ */
+ public String getResourcePath() {
+ return _resourcePath;
+ }
+
+ @Override
+ public String getName() {
+ String name = _resourcePath;
+ final int lastSlash = name.lastIndexOf('/');
+ final int lastBackSlash = name.lastIndexOf('\\');
+ final int lastIndex = Math.max(lastSlash, lastBackSlash);
+ if (lastIndex != -1) {
+ final String lastPart = name.substring(lastIndex + 1);
+ if (!"".equals(lastPart)) {
+ return lastPart;
+ }
+ }
+ return name;
+ }
+
+ protected ClassLoader getClassLoader() {
+ return ClassLoader.getSystemClassLoader();
+ }
+
+ private UrlResource getUrlResourceDelegate() {
+ ClassLoader classLoader = getClassLoader();
+
+ URL url = classLoader.getResource(_resourcePath);
+ if (url == null && _resourcePath.startsWith("/")) {
+ url = classLoader.getResource(_resourcePath.substring(1));
+ }
+
+ if (url == null) {
+ return null;
+ }
+ return new UrlResource(url);
+ }
+
+ @Override
+ public boolean isReadOnly() {
+ return true;
+ }
+
+ @Override
+ public boolean isExists() {
+ UrlResource delegate = getUrlResourceDelegate();
+ if (delegate == null) {
+ return false;
+ }
+ return delegate.isExists();
+ }
+
+ @Override
+ public long getSize() {
+ UrlResource delegate = getUrlResourceDelegate();
+ if (delegate == null) {
+ return -1;
+ }
+ return delegate.getSize();
+ }
+
+ @Override
+ public long getLastModified() {
+ UrlResource delegate = getUrlResourceDelegate();
+ if (delegate == null) {
+ return -1;
+ }
+ return delegate.getLastModified();
+ }
+
+ @Override
+ public void write(Action<OutputStream> writeCallback) throws ResourceException {
+ getUrlResourceDelegate().write(writeCallback);
+ }
+
+ @Override
+ public void append(Action<OutputStream> appendCallback) throws ResourceException {
+ getUrlResourceDelegate().append(appendCallback);
+ }
+
+ @Override
+ public InputStream read() throws ResourceException {
+ return getUrlResourceDelegate().read();
+ }
+
+ @Override
+ public void read(Action<InputStream> readCallback) throws ResourceException {
+ getUrlResourceDelegate().read(readCallback);
+ }
+
+ @Override
+ public <E> E read(Func<InputStream, E> readCallback) throws ResourceException {
+ return getUrlResourceDelegate().read(readCallback);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/CollectionUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/CollectionUtils.java b/core/src/main/java/org/apache/metamodel/util/CollectionUtils.java
new file mode 100644
index 0000000..52cff9a
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/CollectionUtils.java
@@ -0,0 +1,240 @@
+/**
+ * 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.util;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Various utility methods for handling of collections and arrays.
+ *
+ * @author Kasper Sørensen
+ */
+public final class CollectionUtils {
+
+ private CollectionUtils() {
+ // prevent instantiation
+ }
+
+ /**
+ * Concatenates two arrays
+ *
+ * @param existingArray an existing array
+ * @param elements the elements to add to the end of it
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ public static <E> E[] array(final E[] existingArray, final E... elements) {
+ if (existingArray == null) {
+ return elements;
+ }
+ Object result = Array.newInstance(existingArray.getClass()
+ .getComponentType(), existingArray.length + elements.length);
+ System.arraycopy(existingArray, 0, result, 0, existingArray.length);
+ System.arraycopy(elements, 0, result, existingArray.length,
+ elements.length);
+ return (E[]) result;
+ }
+
+ public static <E> List<E> concat(boolean removeDuplicates,
+ Collection<? extends E> firstCollection,
+ Collection<?>... collections) {
+ final List<E> result;
+ if (removeDuplicates) {
+ result = new ArrayList<E>();
+ addElements(removeDuplicates, result, firstCollection);
+ } else {
+ result = new ArrayList<E>(firstCollection);
+ }
+ for (Collection<?> collection : collections) {
+ @SuppressWarnings("unchecked")
+ Collection<? extends E> elems = (Collection<? extends E>) collection;
+ addElements(removeDuplicates, result, elems);
+ }
+ return result;
+ }
+
+ private static <E> void addElements(boolean removeDuplicates,
+ final List<E> result, Collection<? extends E> elements) {
+ for (E item : elements) {
+ if (removeDuplicates) {
+ if (!result.contains(item)) {
+ result.add(item);
+ }
+ } else {
+ result.add(item);
+ }
+ }
+ }
+
+ public static <E> E[] arrayRemove(E[] array, E elementToRemove) {
+ @SuppressWarnings("unchecked")
+ E[] result = (E[]) arrayRemoveInternal(array, elementToRemove);
+ return result;
+ }
+
+ public static Object arrayRemove(Object array, Object elementToRemove) {
+ return arrayRemoveInternal(array, elementToRemove);
+ }
+
+ private static Object arrayRemoveInternal(Object array,
+ Object elementToRemove) {
+ boolean found = false;
+ final int oldLength = Array.getLength(array);
+ if (oldLength == 0) {
+ return array;
+ }
+ final int newLength = oldLength - 1;
+ final Object result = Array.newInstance(array.getClass()
+ .getComponentType(), newLength);
+ int nextIndex = 0;
+ for (int i = 0; i < oldLength; i++) {
+ final Object e = Array.get(array, i);
+ if (e.equals(elementToRemove)) {
+ found = true;
+ } else {
+ if (nextIndex == newLength) {
+ break;
+ }
+ Array.set(result, nextIndex, e);
+ nextIndex++;
+ }
+ }
+ if (!found) {
+ return array;
+ }
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <E> E[] arrayOf(Class<E> elementClass, Object arrayOrElement) {
+ if (arrayOrElement == null) {
+ return null;
+ }
+ if (arrayOrElement.getClass().isArray()) {
+ return (E[]) arrayOrElement;
+ }
+ Object result = Array.newInstance(elementClass, 1);
+ Array.set(result, 0, arrayOrElement);
+ return (E[]) result;
+ }
+
+ public static <E> List<E> filter(E[] items, Predicate<? super E> predicate) {
+ return filter(Arrays.asList(items), predicate);
+ }
+
+ public static <E> List<E> filter(Iterable<E> items,
+ Predicate<? super E> predicate) {
+ List<E> result = new ArrayList<E>();
+ for (E e : items) {
+ if (predicate.eval(e).booleanValue()) {
+ result.add(e);
+ }
+ }
+ return result;
+ }
+
+ public static <I, O> List<O> map(I[] items, Func<? super I, O> func) {
+ return map(Arrays.asList(items), func);
+ }
+
+ public static <I, O> List<O> map(Iterable<I> items, Func<? super I, O> func) {
+ List<O> result = new ArrayList<O>();
+ for (I item : items) {
+ O output = func.eval(item);
+ result.add(output);
+ }
+ return result;
+ }
+
+ public static <E> void forEach(E[] items, Action<? super E> action) {
+ forEach(Arrays.asList(items), action);
+ }
+
+ public static <E> void forEach(Iterable<E> items, Action<? super E> action) {
+ for (E item : items) {
+ try {
+ action.run(item);
+ } catch (Exception e) {
+ if (e instanceof RuntimeException) {
+ throw (RuntimeException) e;
+ }
+ throw new IllegalStateException("Action threw exception", e);
+ }
+ }
+ }
+
+ public static <E> boolean isNullOrEmpty(E[] arr) {
+ return arr == null || arr.length == 0;
+ }
+
+ public static boolean isNullOrEmpty(Collection<?> col) {
+ return col == null || col.isEmpty();
+ }
+
+ /**
+ * General purpose list converter method. Will convert arrays, collections,
+ * iterables etc. into lists.
+ *
+ * If the argument is a single object (such as a String or a POJO) it will
+ * be wrapped in a single-element list.
+ *
+ * Null will be converted to the empty list.
+ *
+ * @param obj
+ * any object
+ * @return a list representation of the object
+ */
+ public static List<?> toList(Object obj) {
+ final List<Object> result;
+ if (obj == null) {
+ result = Collections.emptyList();
+ } else if (obj instanceof List) {
+ @SuppressWarnings("unchecked")
+ List<Object> list = (List<Object>) obj;
+ result = list;
+ } else if (obj.getClass().isArray()) {
+ int length = Array.getLength(obj);
+ result = new ArrayList<Object>(length);
+ for (int i = 0; i < length; i++) {
+ result.add(Array.get(obj, i));
+ }
+ } else if (obj instanceof Iterable) {
+ result = new ArrayList<Object>();
+ for (Object item : (Iterable<?>) obj) {
+ result.add(item);
+ }
+ } else if (obj instanceof Iterator) {
+ result = new ArrayList<Object>();
+ Iterator<?> it = (Iterator<?>) obj;
+ while (it.hasNext()) {
+ result.add(it.next());
+ }
+ } else {
+ result = new ArrayList<Object>(1);
+ result.add(obj);
+ }
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/ConstantFunc.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/ConstantFunc.java b/core/src/main/java/org/apache/metamodel/util/ConstantFunc.java
new file mode 100644
index 0000000..0f071e5
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/ConstantFunc.java
@@ -0,0 +1,65 @@
+/**
+ * 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.util;
+
+/**
+ * A function that always returns the same constant response.
+ *
+ * @param <I>
+ * @param <O>
+ */
+public final class ConstantFunc<I, O> implements Func<I, O> {
+
+ private final O _response;
+
+ public ConstantFunc(O response) {
+ _response = response;
+ }
+
+ @Override
+ public O eval(I arg) {
+ return _response;
+ }
+
+ @Override
+ public int hashCode() {
+ if (_response == null) {
+ return -1;
+ }
+ return _response.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (obj instanceof ConstantFunc) {
+ Object otherResponse = ((ConstantFunc<?, ?>) obj)._response;
+ if (otherResponse == null && _response == null) {
+ return true;
+ } else if (_response == null) {
+ return false;
+ } else {
+ return _response.equals(otherResponse);
+ }
+ }
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/DateUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/DateUtils.java b/core/src/main/java/org/apache/metamodel/util/DateUtils.java
new file mode 100644
index 0000000..b146523
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/DateUtils.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.util;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * Various utility methods pertaining to date handling
+ *
+ * @author Kasper Sørensen
+ */
+public final class DateUtils {
+
+ public static final long MILLISECONDS_PER_SECOND = 1000;
+ public static final long MILLISECONDS_PER_MINUTE = MILLISECONDS_PER_SECOND * 60;
+ public static final long MILLISECONDS_PER_HOUR = MILLISECONDS_PER_MINUTE * 60;
+ public static final long MILLISECONDS_PER_DAY = MILLISECONDS_PER_HOUR * 24;
+
+ private DateUtils() {
+ // prevent instantiation
+ }
+
+ public static Date get(int year, Month month, int dayOfMonth) {
+ Calendar c = createCalendar();
+ c.set(Calendar.YEAR, year);
+ c.set(Calendar.MONTH, month.getCalendarConstant());
+ c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
+ c.set(Calendar.HOUR, 0);
+ c.set(Calendar.MINUTE, 0);
+ c.set(Calendar.SECOND, 0);
+ c.set(Calendar.MILLISECOND, 0);
+ return c.getTime();
+ }
+
+ public static Date get(Date date) {
+ Calendar c = Calendar.getInstance();
+ c.setTime(date);
+ c.set(Calendar.HOUR, 0);
+ c.set(Calendar.MINUTE, 0);
+ c.set(Calendar.SECOND, 0);
+ c.set(Calendar.MILLISECOND, 0);
+
+ return c.getTime();
+ }
+
+ public static Date get(Date originalDate, int daysDiff) {
+ long millis = originalDate.getTime();
+ long diff = daysDiff * MILLISECONDS_PER_DAY;
+ millis = millis + diff;
+ return new Date(millis);
+ }
+
+ public static int getYear(Date date) {
+ Calendar cal = createCalendar();
+ cal.setTime(date);
+ return cal.get(Calendar.YEAR);
+ }
+
+ public static Month getMonth(Date date) {
+ Calendar cal = createCalendar();
+ cal.setTime(date);
+ int monthConstant = cal.get(Calendar.MONTH);
+ return Month.getByCalendarConstant(monthConstant);
+ }
+
+ public static Weekday getWeekday(Date date) {
+ Calendar cal = createCalendar();
+ cal.setTime(date);
+ int weekdayConstant = cal.get(Calendar.DAY_OF_WEEK);
+ return Weekday.getByCalendarConstant(weekdayConstant);
+ }
+
+ public static int getDayOfMonth(Date date) {
+ Calendar cal = createCalendar();
+ cal.setTime(date);
+ return cal.get(Calendar.DAY_OF_MONTH);
+ }
+
+ public static Calendar createCalendar() {
+ Calendar c = Calendar.getInstance();
+ c.setTimeInMillis(0l);
+ return c;
+ }
+
+ public static DateFormat createDateFormat() {
+ return createDateFormat("yyyy-MM-dd HH:mm:ss");
+ }
+
+ public static DateFormat createDateFormat(String datePattern) {
+ SimpleDateFormat dateFormat = new SimpleDateFormat(datePattern);
+ return dateFormat;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/EqualsBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/EqualsBuilder.java b/core/src/main/java/org/apache/metamodel/util/EqualsBuilder.java
new file mode 100644
index 0000000..b02b6df
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/EqualsBuilder.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.util;
+
+import java.lang.reflect.Array;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A helper class for implementing equals(...) methods.
+ *
+ * @author Kasper Sørensen
+ */
+public final class EqualsBuilder {
+
+ private static final Logger logger = LoggerFactory
+ .getLogger(EqualsBuilder.class);
+ private boolean equals = true;
+
+ public EqualsBuilder append(boolean b) {
+ logger.debug("append({})", b);
+ if (equals) {
+ equals = b;
+ }
+ return this;
+ }
+
+ public EqualsBuilder append(Object o1, Object o2) {
+ if (equals) {
+ equals = equals(o1, o2);
+ }
+ return this;
+ }
+
+ public static boolean equals(final Object obj1, final Object obj2) {
+ if (obj1 == obj2) {
+ return true;
+ }
+
+ if (obj1 == null || obj2 == null) {
+ return false;
+ }
+
+ Class<? extends Object> class1 = obj1.getClass();
+ Class<? extends Object> class2 = obj2.getClass();
+ if (class1.isArray()) {
+ if (!class2.isArray()) {
+ return false;
+ } else {
+ Class<?> componentType1 = class1.getComponentType();
+ Class<?> componentType2 = class2.getComponentType();
+ if (!componentType1.equals(componentType2)) {
+ return false;
+ }
+
+ int length1 = Array.getLength(obj1);
+ int length2 = Array.getLength(obj2);
+ if (length1 != length2) {
+ return false;
+ }
+ for (int i = 0; i < length1; i++) {
+ Object elem1 = Array.get(obj1, i);
+ Object elem2 = Array.get(obj2, i);
+ if (!equals(elem1, elem2)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ } else {
+ if (class2.isArray()) {
+ return false;
+ }
+ }
+
+ return obj1.equals(obj2);
+ }
+
+ public boolean isEquals() {
+ return equals;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/ExclusionPredicate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/ExclusionPredicate.java b/core/src/main/java/org/apache/metamodel/util/ExclusionPredicate.java
new file mode 100644
index 0000000..78744bc
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/ExclusionPredicate.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.util;
+
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * A predicate that uses an exclusion list ("black list") of elements to
+ * determine whether to evaluate true or false.
+ *
+ * @param <E>
+ */
+public class ExclusionPredicate<E> implements Predicate<E> {
+
+ private final Collection<E> _exclusionList;
+
+ public ExclusionPredicate(Collection<E> exclusionList) {
+ _exclusionList = exclusionList;
+ }
+
+ @Override
+ public Boolean eval(E arg) {
+ if (_exclusionList.contains(arg)) {
+ return false;
+ }
+ return true;
+ }
+
+ public Collection<E> getExclusionList() {
+ return Collections.unmodifiableCollection(_exclusionList);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/FalsePredicate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/FalsePredicate.java b/core/src/main/java/org/apache/metamodel/util/FalsePredicate.java
new file mode 100644
index 0000000..01be8eb
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/FalsePredicate.java
@@ -0,0 +1,46 @@
+/**
+ * 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.util;
+
+import java.io.Serializable;
+
+/**
+ * A predicate that is always false
+ *
+ * @param <E>
+ */
+public final class FalsePredicate<E> implements Predicate<E>, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Boolean eval(E arg) {
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Boolean.FALSE.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return obj != null && obj.getClass() == FalsePredicate.class;
+ }
+}
[05/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcSimpleUpdateCallback.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcSimpleUpdateCallback.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcSimpleUpdateCallback.java
deleted file mode 100644
index 0bb7cf7..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcSimpleUpdateCallback.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.util.FileHelper;
-
-/**
- * Jdbc {@link UpdateCallback} for databases that do not support batch features.
- * Instead we will use a single transaction for the {@link UpdateScript}.
- *
- * @author Kasper Sørensen
- */
-final class JdbcSimpleUpdateCallback extends JdbcUpdateCallback {
-
- public JdbcSimpleUpdateCallback(JdbcDataContext dataContext) {
- super(dataContext);
- }
-
- @Override
- protected void closePreparedStatement(PreparedStatement preparedStatement) {
- FileHelper.safeClose(preparedStatement);
- }
-
- @Override
- protected void executePreparedStatement(PreparedStatement st) throws SQLException {
- st.executeUpdate();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcTable.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcTable.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcTable.java
deleted file mode 100644
index 4ab1419..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcTable.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.io.ObjectStreamException;
-import java.util.List;
-
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.TableType;
-
-/**
- * Table implementation that is based on JDBC metadata.
- *
- * @author Kasper Sørensen
- */
-final class JdbcTable extends MutableTable {
-
- private static final long serialVersionUID = 5952310469458880330L;
-
- private final transient MetadataLoader _metadataLoader;
-
- public JdbcTable(String name, TableType type, JdbcSchema schema, MetadataLoader metadataLoader) {
- super(name, type, schema);
- _metadataLoader = metadataLoader;
- }
-
- @Override
- protected List<Column> getColumnsInternal() {
- if (_metadataLoader != null) {
- _metadataLoader.loadColumns(this);
- }
- return super.getColumnsInternal();
- }
-
- @Override
- protected List<Relationship> getRelationshipsInternal() {
- Schema schema = getSchema();
- if (schema instanceof JdbcSchema) {
- ((JdbcSchema) schema).loadRelations();
- }
- return super.getRelationshipsInternal();
- }
-
- protected void loadIndexes() {
- if (_metadataLoader != null) {
- _metadataLoader.loadIndexes(this);
- }
- }
-
- /**
- * Called by the Java Serialization API to serialize the object.
- */
- private Object writeReplace() throws ObjectStreamException {
- getColumns();
- loadIndexes();
- loadPrimaryKeys();
- return this;
- }
-
- public void loadPrimaryKeys() {
- if (_metadataLoader != null) {
- _metadataLoader.loadPrimaryKeys(this);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcUpdateBuilder.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcUpdateBuilder.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcUpdateBuilder.java
deleted file mode 100644
index 622a5ae..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcUpdateBuilder.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.List;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.AbstractRowUpdationBuilder;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
-import org.eobjects.metamodel.util.FileHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * {@link RowUpdationBuilder} that issues an SQL UPDATE statement
- *
- * @author Kasper Sørensen
- */
-final class JdbcUpdateBuilder extends AbstractRowUpdationBuilder {
-
- private static final Logger logger = LoggerFactory.getLogger(JdbcUpdateBuilder.class);
-
- private final boolean _inlineValues;
- private final JdbcUpdateCallback _updateCallback;
- private final IQueryRewriter _queryRewriter;
-
- public JdbcUpdateBuilder(JdbcUpdateCallback updateCallback, Table table, IQueryRewriter queryRewriter) {
- this(updateCallback, table, queryRewriter, false);
- }
-
- public JdbcUpdateBuilder(JdbcUpdateCallback updateCallback, Table table, IQueryRewriter queryRewriter,
- boolean inlineValues) {
- super(table);
- _updateCallback = updateCallback;
- _queryRewriter = queryRewriter;
- _inlineValues = inlineValues;
- }
-
- @Override
- public void execute() throws MetaModelException {
- String sql = createSqlStatement();
- logger.debug("Update statement created: {}", sql);
- final boolean reuseStatement = !_inlineValues;
- final PreparedStatement st = _updateCallback.getPreparedStatement(sql, reuseStatement);
- try {
- if (reuseStatement) {
- Column[] columns = getColumns();
- Object[] values = getValues();
- boolean[] explicitNulls = getExplicitNulls();
- int valueCounter = 1;
- for (int i = 0; i < columns.length; i++) {
- boolean explicitNull = explicitNulls[i];
- if (values[i] != null || explicitNull) {
- JdbcUtils.setStatementValue(st, valueCounter, columns[i], values[i]);
-
- valueCounter++;
- }
- }
-
- List<FilterItem> whereItems = getWhereItems();
- for (FilterItem whereItem : whereItems) {
- if (JdbcUtils.isPreparedParameterCandidate(whereItem)) {
- final Object operand = whereItem.getOperand();
- final Column column = whereItem.getSelectItem().getColumn();
-
- JdbcUtils.setStatementValue(st, valueCounter, column, operand);
-
- valueCounter++;
- }
- }
- }
- _updateCallback.executePreparedStatement(st, reuseStatement);
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "execute update statement: " + sql);
- } finally {
- if (_inlineValues) {
- FileHelper.safeClose(st);
- }
- }
- }
-
- protected String createSqlStatement() {
- return createSqlStatement(_inlineValues);
- }
-
- private String createSqlStatement(boolean inlineValues) {
- final Object[] values = getValues();
- final Table table = getTable();
- final StringBuilder sb = new StringBuilder();
-
- final String tableLabel = _queryRewriter.rewriteFromItem(new FromItem(table));
-
- sb.append("UPDATE ");
- sb.append(tableLabel);
- sb.append(" SET ");
-
- Column[] columns = getColumns();
- boolean[] explicitNulls = getExplicitNulls();
- boolean firstValue = true;
- for (int i = 0; i < columns.length; i++) {
- if (values[i] != null || explicitNulls[i]) {
- if (firstValue) {
- firstValue = false;
- } else {
- sb.append(',');
- }
- String columnName = columns[i].getName();
- columnName = _updateCallback.quoteIfNescesary(columnName);
- sb.append(columnName);
-
- sb.append('=');
-
- if (inlineValues) {
- sb.append(JdbcUtils.getValueAsSql(columns[i], values[i], _queryRewriter));
- } else {
- sb.append('?');
- }
- }
- }
-
- sb.append(JdbcUtils.createWhereClause(getWhereItems(), _queryRewriter, inlineValues));
- String sql = sb.toString();
- return sql;
- }
-
- @Override
- public String toSql() {
- return createSqlStatement(true);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcUpdateCallback.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcUpdateCallback.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcUpdateCallback.java
deleted file mode 100644
index 67f1b7c..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcUpdateCallback.java
+++ /dev/null
@@ -1,216 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-
-import org.eobjects.metamodel.AbstractUpdateCallback;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-abstract class JdbcUpdateCallback extends AbstractUpdateCallback implements UpdateCallback {
-
- private static final Logger logger = LoggerFactory.getLogger(JdbcUpdateCallback.class);
-
- private final JdbcDataContext _dataContext;
- private Connection _connection;
- private String _preparedStatementSql;
- private PreparedStatement _preparedStatement;
-
- public JdbcUpdateCallback(JdbcDataContext dataContext) {
- super(dataContext);
- _dataContext = dataContext;
- }
-
- protected abstract void closePreparedStatement(PreparedStatement preparedStatement);
-
- protected abstract void executePreparedStatement(PreparedStatement preparedStatement) throws SQLException;
-
- public void executePreparedStatement(PreparedStatement preparedStatement, boolean reusedStatement)
- throws SQLException {
- executePreparedStatement(preparedStatement);
- if (!reusedStatement) {
- closePreparedStatement(preparedStatement);
- }
- }
-
- protected final Connection getConnection() {
- if (_connection == null) {
- _connection = getDataContext().getConnection();
- try {
- _connection.setAutoCommit(false);
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "disable auto-commit");
- }
- }
- return _connection;
- }
-
- public final void close(boolean success) {
- if (_connection != null) {
- if (success && _preparedStatement != null) {
- closePreparedStatement(_preparedStatement);
- }
-
- try {
- commitOrRollback(success);
-
- if (_dataContext.isDefaultAutoCommit()) {
- try {
- getConnection().setAutoCommit(true);
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "enable auto-commit");
- }
- }
- } finally {
- getDataContext().close(_connection, null, null);
- }
- }
- }
-
- private void commitOrRollback(boolean success) {
- if (success) {
- try {
- getConnection().commit();
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "commit transaction");
- }
- } else {
- try {
- getConnection().rollback();
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "rollback transaction");
- }
- }
- }
-
- @Override
- public final TableCreationBuilder createTable(Schema schema, String name) throws IllegalArgumentException,
- IllegalStateException {
- return new JdbcCreateTableBuilder(this, schema, name);
- }
-
- @Override
- public final RowInsertionBuilder insertInto(Table table) throws IllegalArgumentException, IllegalStateException {
- return new JdbcInsertBuilder(this, table, _dataContext.getQueryRewriter());
- }
-
- @Override
- public final JdbcDataContext getDataContext() {
- return _dataContext;
- }
-
- protected String quoteIfNescesary(String identifier) {
- if (identifier == null) {
- return null;
- }
- final String quote = _dataContext.getIdentifierQuoteString();
- if (quote == null) {
- return identifier;
- }
- boolean quotes = false;
- if (identifier.indexOf(' ') != -1 || identifier.indexOf('-') != -1) {
- quotes = true;
- } else {
- if (SqlKeywords.isKeyword(identifier)) {
- quotes = true;
- }
- }
-
- if (quotes) {
- identifier = quote + identifier + quote;
- }
- return identifier;
- }
-
- public final PreparedStatement getPreparedStatement(String sql, boolean reuseStatement) {
- final PreparedStatement preparedStatement;
- if (reuseStatement) {
- if (sql.equals(_preparedStatementSql)) {
- preparedStatement = _preparedStatement;
- } else {
- if (_preparedStatement != null) {
- try {
- closePreparedStatement(_preparedStatement);
- } catch (RuntimeException e) {
- logger.error("Exception occurred while closing prepared statement: " + _preparedStatementSql);
- throw e;
- }
- }
- preparedStatement = createPreparedStatement(sql);
- _preparedStatement = preparedStatement;
- _preparedStatementSql = sql;
- }
- } else {
- preparedStatement = createPreparedStatement(sql);
- }
- return preparedStatement;
- }
-
- private final PreparedStatement createPreparedStatement(String sql) {
- try {
- return getConnection().prepareStatement(sql);
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "create prepared statement for: " + sql);
- }
- }
-
- @Override
- public boolean isDeleteSupported() {
- return true;
- }
-
- @Override
- public RowDeletionBuilder deleteFrom(Table table) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException {
- return new JdbcDeleteBuilder(this, table, _dataContext.getQueryRewriter());
- }
-
- @Override
- public boolean isDropTableSupported() {
- return true;
- }
-
- @Override
- public TableDropBuilder dropTable(Table table) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException {
- return new JdbcDropTableBuilder(this, table, _dataContext.getQueryRewriter());
- }
-
- @Override
- public boolean isUpdateSupported() {
- return true;
- }
-
- @Override
- public RowUpdationBuilder update(Table table) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException {
- return new JdbcUpdateBuilder(this, table, _dataContext.getQueryRewriter());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcUtils.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcUtils.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcUtils.java
deleted file mode 100644
index 853750f..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcUtils.java
+++ /dev/null
@@ -1,265 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.io.InputStream;
-import java.io.Reader;
-import java.sql.Blob;
-import java.sql.Clob;
-import java.sql.NClob;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.QueryParameter;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.TableType;
-import org.eobjects.metamodel.util.FileHelper;
-import org.eobjects.metamodel.util.FormatHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public final class JdbcUtils {
-
- private static final Logger logger = LoggerFactory
- .getLogger(JdbcUtils.class);
-
- public static MetaModelException wrapException(SQLException e,
- String actionDescription) throws MetaModelException {
- String message = e.getMessage();
- if (message == null || message.isEmpty()) {
- message = "Could not " + actionDescription;
- } else {
- message = "Could not " + actionDescription + ": " + message;
- }
-
- logger.error(message, e);
- logger.error("Error code={}, SQL state={}", e.getErrorCode(),
- e.getSQLState());
-
- final SQLException nextException = e.getNextException();
- if (nextException != null) {
- logger.error("Next SQL exception: " + nextException.getMessage(),
- nextException);
- }
-
- return new MetaModelException(message, e);
- }
-
- /**
- * Method which handles the action of setting a parameterized value on a
- * statement. Traditionally this is done using the
- * {@link PreparedStatement#setObject(int, Object)} method but for some
- * types we use more specific setter methods.
- *
- * @param st
- * @param valueIndex
- * @param column
- * @param value
- * @throws SQLException
- */
- public static void setStatementValue(final PreparedStatement st,
- final int valueIndex, final Column column, Object value)
- throws SQLException {
- final ColumnType type = (column == null ? null : column.getType());
-
- if (type == null || type == ColumnType.OTHER) {
- // type is not known - nothing more we can do to narrow the type
- st.setObject(valueIndex, value);
- return;
- }
-
- if (value == null && type != null) {
- try {
- final int jdbcType = type.getJdbcType();
- st.setNull(valueIndex, jdbcType);
- return;
- } catch (Exception e) {
- logger.warn(
- "Exception occurred while calling setNull(...) for value index "
- + valueIndex
- + ". Attempting value-based setter method instead.",
- e);
- }
- }
-
- if (type == ColumnType.VARCHAR && value instanceof Date) {
- // some drivers (SQLite and JTDS for MS SQL server) treat dates as
- // VARCHARS. In that case we need to convert the dates to the
- // correct format
- String nativeType = column.getNativeType();
- Date date = (Date) value;
- if ("DATE".equalsIgnoreCase(nativeType)) {
- value = FormatHelper
- .formatSqlTime(ColumnType.DATE, date, false);
- } else if ("TIME".equalsIgnoreCase(nativeType)) {
- value = FormatHelper
- .formatSqlTime(ColumnType.TIME, date, false);
- } else if ("TIMESTAMP".equalsIgnoreCase(nativeType)
- || "DATETIME".equalsIgnoreCase(nativeType)) {
- value = FormatHelper.formatSqlTime(ColumnType.TIMESTAMP, date,
- false);
- }
- }
-
- if (type != null && type.isTimeBased() && value instanceof String) {
- value = FormatHelper.parseSqlTime(type, (String) value);
- }
-
- try {
- if (type == ColumnType.DATE && value instanceof Date) {
- Calendar cal = Calendar.getInstance();
- cal.setTime((Date) value);
- st.setDate(valueIndex,
- new java.sql.Date(cal.getTimeInMillis()), cal);
- } else if (type == ColumnType.TIME && value instanceof Date) {
- Calendar cal = Calendar.getInstance();
- cal.setTime((Date) value);
- st.setTime(valueIndex,
- new java.sql.Time(cal.getTimeInMillis()), cal);
- } else if (type == ColumnType.TIMESTAMP && value instanceof Date) {
- Calendar cal = Calendar.getInstance();
- cal.setTime((Date) value);
- st.setTimestamp(valueIndex,
- new java.sql.Timestamp(cal.getTimeInMillis()), cal);
- } else if (type == ColumnType.CLOB || type == ColumnType.NCLOB) {
- if (value instanceof InputStream) {
- InputStream inputStream = (InputStream) value;
- st.setAsciiStream(valueIndex, inputStream);
- } else if (value instanceof Reader) {
- Reader reader = (Reader) value;
- st.setCharacterStream(valueIndex, reader);
- } else if (value instanceof NClob) {
- NClob nclob = (NClob) value;
- st.setNClob(valueIndex, nclob);
- } else if (value instanceof Clob) {
- Clob clob = (Clob) value;
- st.setClob(valueIndex, clob);
- } else if (value instanceof String) {
- st.setString(valueIndex, (String) value);
- } else {
- st.setObject(valueIndex, value);
- }
- } else if (type == ColumnType.BLOB || type == ColumnType.BINARY) {
- if (value instanceof byte[]) {
- byte[] bytes = (byte[]) value;
- st.setBytes(valueIndex, bytes);
- } else if (value instanceof InputStream) {
- InputStream inputStream = (InputStream) value;
- st.setBinaryStream(valueIndex, inputStream);
- } else if (value instanceof Blob) {
- Blob blob = (Blob) value;
- st.setBlob(valueIndex, blob);
- } else {
- st.setObject(valueIndex, value);
- }
- } else if (type.isLiteral()) {
- final String str;
- if (value instanceof Reader) {
- Reader reader = (Reader) value;
- str = FileHelper.readAsString(reader);
- } else {
- str = value.toString();
- }
- st.setString(valueIndex, str);
- } else {
- st.setObject(valueIndex, value);
- }
- } catch (SQLException e) {
- logger.error("Failed to set parameter {} to value: {}", valueIndex,
- value);
- throw e;
- }
- }
-
- public static String getValueAsSql(Column column, Object value,
- IQueryRewriter queryRewriter) {
- if (value == null) {
- return "NULL";
- }
- final ColumnType columnType = column.getType();
- if (columnType.isLiteral() && value instanceof String) {
- value = queryRewriter.escapeQuotes((String) value);
- }
- String formatSqlValue = FormatHelper.formatSqlValue(columnType, value);
- return formatSqlValue;
- }
-
- public static String createWhereClause(List<FilterItem> whereItems,
- IQueryRewriter queryRewriter, boolean inlineValues) {
- if (whereItems.isEmpty()) {
- return "";
- }
- StringBuilder sb = new StringBuilder();
- sb.append(" WHERE ");
- boolean firstValue = true;
- for (FilterItem whereItem : whereItems) {
- if (firstValue) {
- firstValue = false;
- } else {
- sb.append(" AND ");
- }
- if (!inlineValues) {
- if (isPreparedParameterCandidate(whereItem)) {
- // replace operator with parameter
- whereItem = new FilterItem(whereItem.getSelectItem(),
- whereItem.getOperator(), new QueryParameter());
- }
- }
- final String whereItemLabel = queryRewriter
- .rewriteFilterItem(whereItem);
- sb.append(whereItemLabel);
- }
- return sb.toString();
- }
-
- /**
- * Determines if a particular {@link FilterItem} will have it's parameter
- * (operand) replaced during SQL generation. Such filter items should
- * succesively have their parameters set at execution time.
- *
- * @param whereItem
- * @return
- */
- public static boolean isPreparedParameterCandidate(FilterItem whereItem) {
- return !whereItem.isCompoundFilter()
- && whereItem.getOperator() != OperatorType.IN;
- }
-
- public static String[] getTableTypesAsStrings(TableType[] tableTypes) {
- String[] types = new String[tableTypes.length];
- for (int i = 0; i < types.length; i++) {
- if (tableTypes[i] == TableType.OTHER) {
- // if the OTHER type has been selected, don't use a table
- // pattern (ie. include all types)
- types = null;
- break;
- }
- types[i] = tableTypes[i].toString();
- }
- return types;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/MetadataLoader.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/MetadataLoader.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/MetadataLoader.java
deleted file mode 100644
index f7f3861..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/MetadataLoader.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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.jdbc;
-
-/**
- * Defines the interface for a component capable of loading schema-model
- * metadata.
- */
-interface MetadataLoader {
-
- public void loadTables(JdbcSchema jdbcSchema);
-
- public void loadRelations(JdbcSchema jdbcSchema);
-
- public void loadColumns(JdbcTable jdbcTable);
-
- public void loadIndexes(JdbcTable jdbcTable);
-
- public void loadPrimaryKeys(JdbcTable jdbcTable);
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/QuerySplitter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/QuerySplitter.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/QuerySplitter.java
deleted file mode 100644
index 1f74866..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/QuerySplitter.java
+++ /dev/null
@@ -1,336 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromClause;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.GroupByItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * The QuerySplitter class makes it possible to split up queries that are
- * expected to yield a huge result set which may cause performance problems like
- * OutOfMemoryError's or very long processing periods. The resulting queries
- * will in union produce the same result, but in smaller bits (resultsets with
- * less rows).
- *
- * Note that there is an initial performance-penalty associated with splitting
- * the query since some queries will be executed in order to determine
- * reasonable intervals to use for the resulting queries WHERE clauses.
- *
- * @see Query
- * @see DataContext
- */
-public final class QuerySplitter {
-
- public final static long DEFAULT_MAX_ROWS = 300000;
- private static final int MINIMUM_MAX_ROWS = 100;
- private final static Logger logger = LoggerFactory.getLogger(QuerySplitter.class);
-
- private final Query _query;
- private final DataContext _dataContext;
- private long _maxRows = DEFAULT_MAX_ROWS;
- private Long _cachedRowCount = null;
-
- public QuerySplitter(DataContext dc, Query q) {
- if (dc == null) {
- throw new IllegalArgumentException("DataContext cannot be null");
- }
- if (q == null) {
- throw new IllegalArgumentException("Query cannot be null");
- }
- _dataContext = dc;
- _query = q;
- }
-
- /**
- * Splits the query into several queries that will together yield the same
- * result set
- *
- * @return a list of queries that can be executed to yield the same
- * collective result as this QuerySplitter's query
- */
- public List<Query> splitQuery() {
- List<Query> result = new ArrayList<Query>();
- if (isSplittable()) {
- if (getRowCount() > _maxRows) {
- Integer subQueryIndex = getSubQueryFromItemIndex();
- List<Query> splitQueries = null;
- if (subQueryIndex != null) {
- splitQueries = splitQueryBasedOnSubQueries(subQueryIndex);
- } else {
- List<Column> splitColumns = getSplitColumns();
- splitQueries = splitQueryBasedOnColumns(splitColumns);
- }
- result.addAll(splitQueries);
- } else {
- if (logger.isInfoEnabled()) {
- logger.info("Accepted query, maxRows not exceeded: " + _query);
- }
- result.add(_query);
- }
- }
- if (result.isEmpty()) {
- logger.debug("Cannot further split query: {}", _query);
- result.add(_query);
- }
- return result;
- }
-
- private List<Query> splitQueryBasedOnColumns(List<Column> splitColumns) {
- List<Query> result = new ArrayList<Query>();
- if (splitColumns.isEmpty() || getRowCount() <= _maxRows) {
- if (getRowCount() > 0) {
- result.add(_query);
- }
- } else {
- Column firstColumn = splitColumns.get(0);
- splitColumns.remove(0);
- List<Query> splitQueries = splitQueryBasedOnColumn(firstColumn);
- for (Query splitQuery : splitQueries) {
- QuerySplitter qs = new QuerySplitter(_dataContext, splitQuery).setMaxRows(_maxRows);
- if (qs.getRowCount() > _maxRows) {
- // Recursively use the next columns to split queries
- // subsequently
- result.addAll(qs.splitQueryBasedOnColumns(splitColumns));
- } else {
- if (qs.getRowCount() > 0) {
- result.add(splitQuery);
- }
- }
- }
- }
- return result;
- }
-
- private List<Query> splitQueryBasedOnColumn(Column column) {
- SelectItem maxItem = new SelectItem(FunctionType.MAX, column);
- SelectItem minItem = new SelectItem(FunctionType.MIN, column);
- Query q = new Query().from(column.getTable()).select(maxItem, minItem);
- Row row = MetaModelHelper.executeSingleRowQuery(_dataContext, q);
- long max = ceil((Number) row.getValue(maxItem));
- long min = floor((Number) row.getValue(minItem));
- long wholeRange = max - min;
- List<Query> result = new ArrayList<Query>();
- if (wholeRange <= 1) {
- result.add(_query);
- } else {
- long numSplits = ceil(getRowCount() / _maxRows);
- if (numSplits < 2) {
- // Must as a minimum yield two new queries
- numSplits = 2;
- }
- int splitInterval = (int) (wholeRange / numSplits);
- for (int i = 0; i < numSplits; i++) {
- q = _query.clone();
- long lowLimit = min + (i * splitInterval);
- long highLimit = lowLimit + splitInterval;
-
- FilterItem lowerThanFilter = new FilterItem(new SelectItem(column), OperatorType.LESS_THAN, highLimit);
- FilterItem higherThanFilter = new FilterItem(new SelectItem(column), OperatorType.GREATER_THAN,
- lowLimit);
- FilterItem equalsFilter = new FilterItem(new SelectItem(column), OperatorType.EQUALS_TO, lowLimit);
-
- if (i == 0) {
- // This is the first split query: no higherThan filter and
- // include
- // IS NULL
- FilterItem nullFilter = new FilterItem(new SelectItem(column), OperatorType.EQUALS_TO, null);
- FilterItem orFilterItem = new FilterItem(lowerThanFilter, nullFilter);
- q.where(orFilterItem);
- } else if (i + 1 == numSplits) {
- // This is the lats split query: no lowerThan filter,
- FilterItem orFilterItem = new FilterItem(higherThanFilter, equalsFilter);
- q.where(orFilterItem);
- } else {
- higherThanFilter = new FilterItem(higherThanFilter, equalsFilter);
- lowerThanFilter = new FilterItem(lowerThanFilter, equalsFilter);
- q.where(higherThanFilter);
- q.where(lowerThanFilter);
- }
- result.add(q);
- }
- }
- return result;
- }
-
- private static long floor(Number value) {
- Double floor = Math.floor(value.doubleValue());
- return floor.longValue();
- }
-
- private static long ceil(Number value) {
- Double ceil = Math.ceil(value.doubleValue());
- return ceil.longValue();
- }
-
- private List<Query> splitQueryBasedOnSubQueries(int fromItemIndex) {
- Query subQuery = _query.getFromClause().getItem(fromItemIndex).getSubQuery();
- QuerySplitter subQuerySplitter = new QuerySplitter(_dataContext, subQuery);
-
- subQuerySplitter.setMaxRows(_maxRows);
- List<Query> splitQueries = subQuerySplitter.splitQuery();
- List<Query> result = new ArrayList<Query>(splitQueries.size());
- for (Query splitQuery : splitQueries) {
- Query newQuery = _query.clone();
- FromClause fromClause = newQuery.getFromClause();
- String alias = fromClause.getItem(fromItemIndex).getAlias();
- fromClause.removeItem(fromItemIndex);
- newQuery.from(new FromItem(splitQuery).setAlias(alias));
- result.add(newQuery);
- }
- return result;
- }
-
- private Integer getSubQueryFromItemIndex() {
- List<FromItem> fromItems = _query.getFromClause().getItems();
- for (int i = 0; i < fromItems.size(); i++) {
- Query subQuery = fromItems.get(i).getSubQuery();
- if (subQuery != null) {
- if (isSplittable(subQuery)) {
- return i;
- }
- }
- }
- return null;
- }
-
- private boolean isSplittable() {
- return isSplittable(_query);
- }
-
- public static boolean isSplittable(Query q) {
- if (q.getOrderByClause().getItemCount() != 0) {
- return false;
- }
- return true;
- }
-
- private List<Column> getSplitColumns() {
- List<Column> result = new ArrayList<Column>();
- if (_query.getGroupByClause().getItemCount() != 0) {
- List<GroupByItem> groupByItems = _query.getGroupByClause().getItems();
- for (GroupByItem groupByItem : groupByItems) {
- Column column = groupByItem.getSelectItem().getColumn();
- if (column != null) {
- if (column.isIndexed()) {
- // Indexed columns have first priority, they will be
- // added to the beginning of the list
- result.add(0, column);
- } else {
- result.add(column);
- }
- }
- }
- } else {
- List<FromItem> fromItems = _query.getFromClause().getItems();
- for (FromItem fromItem : fromItems) {
- if (fromItem.getTable() != null) {
- addColumnsToResult(fromItem.getTable(), result);
- }
- if (fromItem.getJoin() != null && fromItem.getAlias() == null) {
- if (fromItem.getLeftSide().getTable() != null) {
- addColumnsToResult(fromItem.getLeftSide().getTable(), result);
- }
- if (fromItem.getRightSide().getTable() != null) {
- addColumnsToResult(fromItem.getRightSide().getTable(), result);
- }
- }
- }
- }
- return result;
- }
-
- private static void addColumnsToResult(Table table, List<Column> result) {
- Column[] numberColumns = table.getNumberColumns();
- for (int i = 0; i < numberColumns.length; i++) {
- Column column = numberColumns[i];
- if (column.isIndexed()) {
- // Indexed columns have first priority, they will be
- // added to the beginning of the list
- result.add(0, column);
- } else {
- result.add(column);
- }
- }
- }
-
- /**
- * @return the total number of rows expected from executing the query.
- */
- public long getRowCount() {
- if (_cachedRowCount == null) {
- _cachedRowCount = getRowCount(_query);
- }
- return _cachedRowCount;
- }
-
- private long getRowCount(Query q) {
- q = q.clone();
- SelectItem countAllItem = SelectItem.getCountAllItem();
- if (q.getGroupByClause().getItemCount() > 0) {
- q = new Query().from(new FromItem(q).setAlias("sq")).select(countAllItem);
- } else {
- q.getSelectClause().removeItems();
- q.select(countAllItem);
- }
- Row row = MetaModelHelper.executeSingleRowQuery(_dataContext, q);
- Number count = (Number) row.getValue(countAllItem);
- return count.longValue();
- }
-
- /**
- * Sets the desired maximum result set row count. Note that this size cannot
- * be guaranteed, but will serve as an indicator for determining the
- * split-size
- *
- * @param maxRows
- */
- public QuerySplitter setMaxRows(long maxRows) {
- if (maxRows < MINIMUM_MAX_ROWS) {
- throw new IllegalArgumentException("maxRows must be higher than " + MINIMUM_MAX_ROWS);
- }
- _maxRows = maxRows;
- return this;
- }
-
- public DataSet executeQueries() {
- return executeQueries(splitQuery());
- }
-
- public DataSet executeQueries(List<Query> splitQueries) {
- return new SplitQueriesDataSet(_dataContext, splitQueries);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/SplitQueriesDataSet.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/SplitQueriesDataSet.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/SplitQueriesDataSet.java
deleted file mode 100644
index 68cc442..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/SplitQueriesDataSet.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.AbstractDataSet;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-
-/**
- * DataSet for split queries. Queries will be executed as needed, not at once.
- *
- * @see org.eobjects.metamodel.jdbc.QuerySplitter
- */
-final class SplitQueriesDataSet extends AbstractDataSet {
-
- private static final Logger logger = LoggerFactory.getLogger(SplitQueriesDataSet.class);
- private final DataContext _dataContext;
- private Iterator<Query> _queryIterator;
- private DataSet _currentDataSet;
- private int _queryIndex = 0;
-
- public SplitQueriesDataSet(DataContext dataContext, List<Query> splitQueries) {
- super(getSelectItems(splitQueries));
- if (dataContext == null || splitQueries == null) {
- throw new IllegalArgumentException("Arguments cannot be null");
- }
- _dataContext = dataContext;
- _queryIterator = splitQueries.iterator();
- }
-
- private static List<SelectItem> getSelectItems(List<Query> splitQueries) {
- if (splitQueries.isEmpty()) {
- return new ArrayList<SelectItem>(0);
- }
- return splitQueries.get(0).getSelectClause().getItems();
- }
-
- @Override
- public void close() {
- if (_currentDataSet != null) {
- logger.debug("currentDataSet.close()");
- _currentDataSet.close();
- }
- _currentDataSet = null;
- _queryIterator = null;
- }
-
- @Override
- public Row getRow() throws MetaModelException {
- if (_currentDataSet != null) {
- return _currentDataSet.getRow();
- }
- throw new IllegalStateException("No rows available. Either DataSet is closed or next() hasn't been called");
- }
-
- @Override
- public boolean next() {
- boolean result;
- if (_currentDataSet == null) {
- result = false;
- } else {
- result = _currentDataSet.next();
- }
- if (!result && _queryIterator.hasNext()) {
- if (_currentDataSet != null) {
- logger.debug("currentDataSet.close()");
- _currentDataSet.close();
- }
- Query q = _queryIterator.next();
- _currentDataSet = _dataContext.executeQuery(q);
- if (logger.isDebugEnabled()) {
- _queryIndex++;
- logger.debug("Executing query #{}", _queryIndex);
- }
- result = next();
- }
- return result;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/SqlKeywords.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/SqlKeywords.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/SqlKeywords.java
deleted file mode 100644
index eca70fa..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/SqlKeywords.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.util.HashSet;
-import java.util.Set;
-
-class SqlKeywords {
-
- private static final Set<String> KEYWORDS;
-
- static {
- KEYWORDS = new HashSet<String>();
- KEYWORDS.add("SELECT");
- KEYWORDS.add("DISTINCT");
- KEYWORDS.add("AS");
- KEYWORDS.add("COUNT");
- KEYWORDS.add("SUM");
- KEYWORDS.add("MIN");
- KEYWORDS.add("MAX");
- KEYWORDS.add("FROM");
- KEYWORDS.add("WHERE");
- KEYWORDS.add("LIKE");
- KEYWORDS.add("IN");
- KEYWORDS.add("GROUP");
- KEYWORDS.add("BY");
- KEYWORDS.add("HAVING");
- KEYWORDS.add("ORDER");
- }
-
- public static boolean isKeyword(String str) {
- str = str.toUpperCase();
- return KEYWORDS.contains(str);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/AbstractQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/AbstractQueryRewriter.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/AbstractQueryRewriter.java
deleted file mode 100644
index 2cc8ece..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/AbstractQueryRewriter.java
+++ /dev/null
@@ -1,259 +0,0 @@
-/**
- * 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.jdbc.dialects;
-
-import java.util.List;
-
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.AbstractQueryClause;
-import org.eobjects.metamodel.query.FilterClause;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromClause;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.GroupByClause;
-import org.eobjects.metamodel.query.GroupByItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.OrderByClause;
-import org.eobjects.metamodel.query.OrderByItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectClause;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Abstract implementation of query rewriter. This implementation delegates the
- * rewriting of the Query into several subtasks according to the query items to
- * be rendered. This makes it easy to overload single methods in order to
- * correct syntax quirks.
- */
-public abstract class AbstractQueryRewriter implements IQueryRewriter {
-
- protected final Logger logger = LoggerFactory.getLogger(getClass());
-
- private final JdbcDataContext _dataContext;
-
- public AbstractQueryRewriter(JdbcDataContext dataContext) {
- _dataContext = dataContext;
- }
-
- public JdbcDataContext getDataContext() {
- return _dataContext;
- }
-
- @Override
- public ColumnType getColumnType(int jdbcType, String nativeType, Integer columnSize) {
- return ColumnType.convertColumnType(jdbcType);
- }
-
- public String rewriteQuery(Query query) {
- query = beforeRewrite(query);
-
- final StringBuilder sb = new StringBuilder();
- sb.append(rewriteSelectClause(query, query.getSelectClause()));
- sb.append(rewriteFromClause(query, query.getFromClause()));
- sb.append(rewriteWhereClause(query, query.getWhereClause()));
- sb.append(rewriteGroupByClause(query, query.getGroupByClause()));
- sb.append(rewriteHavingClause(query, query.getHavingClause()));
- sb.append(rewriteOrderByClause(query, query.getOrderByClause()));
- return sb.toString();
- }
-
- public boolean isSchemaIncludedInColumnPaths() {
- return false;
- }
-
- /**
- * Method to modify query before rewriting begins. Overwrite this method if
- * you want to change parts of the query that are not just rendering
- * related. Cloning the query before modifying is recommended in order to
- * not violate referential integrity of clients (the query is mutable).
- *
- * @param strategy
- * @param query
- * @return the modified query
- */
- protected Query beforeRewrite(Query query) {
- return query;
- }
-
- @Override
- public String rewriteColumnType(ColumnType columnType) {
- return columnType.toString();
- }
-
- protected String rewriteOrderByClause(Query query, OrderByClause orderByClause) {
- StringBuilder sb = new StringBuilder();
- if (orderByClause.getItemCount() > 0) {
- sb.append(AbstractQueryClause.PREFIX_ORDER_BY);
- List<OrderByItem> items = orderByClause.getItems();
- for (int i = 0; i < items.size(); i++) {
- OrderByItem item = items.get(i);
- if (i != 0) {
- sb.append(AbstractQueryClause.DELIM_COMMA);
- }
- sb.append(rewriteOrderByItem(query, item));
- }
- }
- return sb.toString();
- }
-
- @Override
- public String rewriteFromItem(FromItem item) {
- return rewriteFromItem(item.getQuery(), item);
- }
-
- protected String rewriteOrderByItem(Query query, OrderByItem item) {
- return item.toSql(isSchemaIncludedInColumnPaths());
- }
-
- protected String rewriteHavingClause(Query query, FilterClause havingClause) {
- StringBuilder sb = new StringBuilder();
- if (havingClause.getItemCount() > 0) {
- sb.append(AbstractQueryClause.PREFIX_HAVING);
- List<FilterItem> items = havingClause.getItems();
- for (int i = 0; i < items.size(); i++) {
- FilterItem item = items.get(i);
- if (i != 0) {
- sb.append(AbstractQueryClause.DELIM_AND);
- }
- sb.append(rewriteFilterItem(item));
- }
- }
- return sb.toString();
- }
-
- protected String rewriteGroupByClause(Query query, GroupByClause groupByClause) {
- StringBuilder sb = new StringBuilder();
- if (groupByClause.getItemCount() > 0) {
- sb.append(AbstractQueryClause.PREFIX_GROUP_BY);
- List<GroupByItem> items = groupByClause.getItems();
- for (int i = 0; i < items.size(); i++) {
- GroupByItem item = items.get(i);
- if (i != 0) {
- sb.append(AbstractQueryClause.DELIM_COMMA);
- }
- sb.append(rewriteGroupByItem(query, item));
- }
- }
- return sb.toString();
- }
-
- protected String rewriteGroupByItem(Query query, GroupByItem item) {
- return item.toSql(isSchemaIncludedInColumnPaths());
- }
-
- protected String rewriteWhereClause(Query query, FilterClause whereClause) {
- StringBuilder sb = new StringBuilder();
- if (whereClause.getItemCount() > 0) {
- sb.append(AbstractQueryClause.PREFIX_WHERE);
- List<FilterItem> items = whereClause.getItems();
- for (int i = 0; i < items.size(); i++) {
- FilterItem item = items.get(i);
- if (i != 0) {
- sb.append(AbstractQueryClause.DELIM_AND);
- }
- sb.append(rewriteFilterItem(item));
- }
- }
- return sb.toString();
- }
-
- @Override
- public String rewriteFilterItem(FilterItem item) {
- if (item.isCompoundFilter()) {
- FilterItem[] childItems = item.getChildItems();
- StringBuilder sb = new StringBuilder();
- sb.append('(');
- for (int i = 0; i < childItems.length; i++) {
- FilterItem child = childItems[i];
- if (i != 0) {
- sb.append(' ');
- sb.append(item.getLogicalOperator().toString());
- sb.append(' ');
- }
- sb.append(rewriteFilterItem(child));
- }
- sb.append(')');
- return sb.toString();
- }
-
- final String primaryFilterSql = item.toSql(isSchemaIncludedInColumnPaths());
-
- final OperatorType operator = item.getOperator();
- if (operator == OperatorType.DIFFERENT_FROM) {
- final Object operand = item.getOperand();
- if (operand != null) {
- // special case in SQL where NULL is not treated as a value -
- // see Ticket #1058
-
- FilterItem isNullFilter = new FilterItem(item.getSelectItem(), OperatorType.EQUALS_TO, null);
- final String secondaryFilterSql = rewriteFilterItem(isNullFilter);
-
- return '(' + primaryFilterSql + " OR " + secondaryFilterSql + ')';
- }
- }
-
- return primaryFilterSql;
- }
-
- protected String rewriteFromClause(Query query, FromClause fromClause) {
- StringBuilder sb = new StringBuilder();
- if (fromClause.getItemCount() > 0) {
- sb.append(AbstractQueryClause.PREFIX_FROM);
- List<FromItem> items = fromClause.getItems();
- for (int i = 0; i < items.size(); i++) {
- FromItem item = items.get(i);
- if (i != 0) {
- sb.append(AbstractQueryClause.DELIM_COMMA);
- }
- sb.append(rewriteFromItem(query, item));
- }
- }
- return sb.toString();
- }
-
- protected String rewriteFromItem(Query query, FromItem item) {
- return item.toSql(isSchemaIncludedInColumnPaths());
- }
-
- protected String rewriteSelectClause(Query query, SelectClause selectClause) {
- StringBuilder sb = new StringBuilder();
- if (selectClause.getItemCount() > 0) {
- sb.append(AbstractQueryClause.PREFIX_SELECT);
- if (selectClause.isDistinct()) {
- sb.append("DISTINCT ");
- }
- List<SelectItem> items = selectClause.getItems();
- for (int i = 0; i < items.size(); i++) {
- SelectItem item = items.get(i);
- if (i != 0) {
- sb.append(AbstractQueryClause.DELIM_COMMA);
- }
- sb.append(rewriteSelectItem(query, item));
- }
- }
- return sb.toString();
- }
-
- protected String rewriteSelectItem(Query query, SelectItem item) {
- return item.toSql(isSchemaIncludedInColumnPaths());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/DB2QueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/DB2QueryRewriter.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/DB2QueryRewriter.java
deleted file mode 100644
index 90eeb9d..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/DB2QueryRewriter.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/**
- * 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.jdbc.dialects;
-
-import java.util.Date;
-import java.util.List;
-
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.util.FormatHelper;
-import org.eobjects.metamodel.util.TimeComparator;
-
-/**
- * Query rewriter for IBM DB2
- */
-public class DB2QueryRewriter extends DefaultQueryRewriter implements IQueryRewriter {
-
- public DB2QueryRewriter(JdbcDataContext dataContext) {
- super(dataContext);
- }
-
- @Override
- public String escapeQuotes(String filterItemOperand) {
- return filterItemOperand.replaceAll("\\'", "\\\\'");
- }
-
- /**
- * DB2 expects the fully qualified column name, including schema, in select
- * items.
- */
- @Override
- public boolean isSchemaIncludedInColumnPaths() {
- return true;
- }
-
- @Override
- public boolean isMaxRowsSupported() {
- return true;
- }
-
- @Override
- public boolean isFirstRowSupported() {
- return true;
- }
-
- @Override
- public String rewriteQuery(Query query) {
- final Integer firstRow = query.getFirstRow();
- final Integer maxRows = query.getMaxRows();
-
- if (maxRows == null && firstRow == null) {
- return super.rewriteQuery(query);
- }
-
- if (firstRow == null || firstRow.intValue() == 1) {
- // We prefer to use the "FETCH FIRST [n] ROWS ONLY" approach, if
- // firstRow is not specified.
- return super.rewriteQuery(query) + " FETCH FIRST " + maxRows + " ROWS ONLY";
-
- } else {
- // build a ROW_NUMBER() query like this:
-
- // SELECT [original select clause]
- // FROM ([original select clause],
- // ROW_NUMBER() AS metamodel_row_number
- // FROM [remainder of regular query])
- // WHERE metamodel_row_number BETWEEN [firstRow] and [maxRows];
-
- final Query innerQuery = query.clone();
- innerQuery.setFirstRow(null);
- innerQuery.setMaxRows(null);
-
- final Query outerQuery = new Query();
- final FromItem subQuerySelectItem = new FromItem(innerQuery).setAlias("metamodel_subquery");
- outerQuery.from(subQuerySelectItem);
-
- final List<SelectItem> innerSelectItems = innerQuery.getSelectClause().getItems();
- for (SelectItem selectItem : innerSelectItems) {
- outerQuery.select(new SelectItem(selectItem, subQuerySelectItem));
- }
-
- innerQuery.select(new SelectItem("ROW_NUMBER() OVER()", "metamodel_row_number"));
-
- final String baseQueryString = rewriteQuery(outerQuery);
-
- if (maxRows == null) {
- return baseQueryString + " WHERE metamodel_row_number > " + (firstRow - 1);
- }
-
- return baseQueryString + " WHERE metamodel_row_number BETWEEN " + firstRow + " AND " + (firstRow - 1 + maxRows);
- }
- }
-
- @Override
- public String rewriteColumnType(ColumnType columnType) {
- switch (columnType) {
- case BOOLEAN:
- case BIT:
- return "SMALLINT";
- default:
- return super.rewriteColumnType(columnType);
- }
- }
-
- @Override
- public String rewriteFilterItem(FilterItem item) {
- SelectItem _selectItem = item.getSelectItem();
- Object _operand = item.getOperand();
- OperatorType _operator = item.getOperator();
- if (null != _selectItem && _operand != null) {
- ColumnType columnType = _selectItem.getExpectedColumnType();
- if (columnType != null) {
- if (columnType.isTimeBased()) {
- // special logic for DB2 based time operands.
-
- StringBuilder sb = new StringBuilder();
- sb.append(_selectItem.getSameQueryAlias(true));
- final Object operand = FilterItem.appendOperator(sb, _operand, _operator);
-
- if (operand instanceof SelectItem) {
- final String selectItemString = ((SelectItem) operand).getSameQueryAlias(true);
- sb.append(selectItemString);
- } else {
- Date date = TimeComparator.toDate(_operand);
- if (date == null) {
- throw new IllegalStateException("Could not convert " + _operand + " to date");
- }
-
- final String sqlValue = FormatHelper.formatSqlTime(columnType, date, true, "('", "')");
- sb.append(sqlValue);
- }
-
- return sb.toString();
- }
- }
- }
- return super.rewriteFilterItem(item);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/DefaultQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/DefaultQueryRewriter.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/DefaultQueryRewriter.java
deleted file mode 100644
index d3356cd..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/DefaultQueryRewriter.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/**
- * 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.jdbc.dialects;
-
-import java.util.List;
-import java.util.ListIterator;
-
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.util.CollectionUtils;
-
-/**
- * Generic query rewriter that adds syntax enhancements that are only possible
- * to resolve just before execution time.
- */
-public class DefaultQueryRewriter extends AbstractQueryRewriter {
-
- private static final String SPECIAL_ALIAS_CHARACTERS = "- ,.|*%()!#¤/\\=?;:~";
-
- public DefaultQueryRewriter(JdbcDataContext dataContext) {
- super(dataContext);
- }
-
- @Override
- protected Query beforeRewrite(Query query) {
- query = query.clone();
-
- JdbcDataContext dataContext = getDataContext();
- if (dataContext != null) {
- String identifierQuoteString = dataContext.getIdentifierQuoteString();
- if (identifierQuoteString != null) {
- List<SelectItem> selectItems = query.getSelectClause().getItems();
- for (SelectItem item : selectItems) {
- String alias = item.getAlias();
- if (needsQuoting(alias, identifierQuoteString)) {
- item.setAlias(identifierQuoteString + alias + identifierQuoteString);
- }
- }
- List<FromItem> fromItems = query.getFromClause().getItems();
- for (FromItem item : fromItems) {
- String alias = item.getAlias();
- if (needsQuoting(alias, identifierQuoteString)) {
- item.setAlias(identifierQuoteString + alias + identifierQuoteString);
- }
- }
- }
- }
- return query;
- }
-
- private boolean needsQuoting(String alias, String identifierQuoteString) {
- boolean result = false;
- if (alias != null && identifierQuoteString != null) {
- if (alias.indexOf(identifierQuoteString) == -1) {
- for (int i = 0; i < SPECIAL_ALIAS_CHARACTERS.length(); i++) {
- char specialCharacter = SPECIAL_ALIAS_CHARACTERS.charAt(i);
- if (alias.indexOf(specialCharacter) != -1) {
- result = true;
- break;
- }
- }
- }
- }
- if (logger.isDebugEnabled()) {
- logger.debug("needsQuoting(" + alias + "," + identifierQuoteString + ") = " + result);
- }
- return result;
- }
-
- @Override
- public String rewriteFilterItem(FilterItem item) {
- Object operand = item.getOperand();
- if (operand != null) {
- if (operand instanceof String) {
- String str = (String) operand;
- // escape single quotes
- if (str.indexOf('\'') != -1) {
- str = escapeQuotes(str);
- FilterItem replacementFilterItem = new FilterItem(item.getSelectItem(), item.getOperator(), str);
- return super.rewriteFilterItem(replacementFilterItem);
- }
- } else if (operand instanceof Iterable || operand.getClass().isArray()) {
- // operand is a set of values (typically in combination with an
- // IN operator). Each individual element must be escaped.
-
- assert item.getOperator() == OperatorType.IN;
-
- @SuppressWarnings("unchecked")
- final List<Object> elements = (List<Object>) CollectionUtils.toList(operand);
-
- for (ListIterator<Object> it = elements.listIterator(); it.hasNext();) {
- Object next = it.next();
- if (next == null) {
- logger.warn("element in IN list is NULL, which isn't supported by SQL. Stripping the element from the list: {}", item);
- it.remove();
- } else if (next instanceof String) {
- String str = (String) next;
- if (str.indexOf('\'') != -1) {
- str = escapeQuotes(str);
- it.set(str);
- }
- }
- }
-
- FilterItem replacementFilterItem = new FilterItem(item.getSelectItem(), item.getOperator(), elements);
- return super.rewriteFilterItem(replacementFilterItem);
- }
- }
- return super.rewriteFilterItem(item);
- }
-
- @Override
- public boolean isFirstRowSupported() {
- return false;
- }
-
- @Override
- public boolean isMaxRowsSupported() {
- return false;
- }
-
- @Override
- public String escapeQuotes(String item) {
- return item.replaceAll("\\'", "\\'\\'");
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/H2QueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/H2QueryRewriter.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/H2QueryRewriter.java
deleted file mode 100644
index 4ed4555..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/H2QueryRewriter.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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.jdbc.dialects;
-
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-
-/**
- * Query rewriter for H2
- */
-public class H2QueryRewriter extends LimitOffsetQueryRewriter {
-
- public H2QueryRewriter(JdbcDataContext dataContext) {
- super(dataContext);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/HsqldbQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/HsqldbQueryRewriter.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/HsqldbQueryRewriter.java
deleted file mode 100644
index cf54718..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/HsqldbQueryRewriter.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * 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.jdbc.dialects;
-
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectClause;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-
-/**
- * Query rewriter for HSQLDB
- */
-public class HsqldbQueryRewriter extends DefaultQueryRewriter {
-
- public HsqldbQueryRewriter(JdbcDataContext dataContext) {
- super(dataContext);
- }
-
- @Override
- public String rewriteColumnType(ColumnType columnType) {
- if (columnType == ColumnType.BLOB) {
- return "LONGVARBINARY";
- }
- return super.rewriteColumnType(columnType);
- }
-
- @Override
- public boolean isFirstRowSupported() {
- return true;
- }
-
- @Override
- public boolean isMaxRowsSupported() {
- return true;
- }
-
- @Override
- protected String rewriteSelectClause(Query query, SelectClause selectClause) {
- String result = super.rewriteSelectClause(query, selectClause);
-
- Integer firstRow = query.getFirstRow();
- Integer maxRows = query.getMaxRows();
- if (maxRows != null || firstRow != null) {
- if (maxRows == null) {
- maxRows = Integer.MAX_VALUE;
- }
- if (firstRow == null || firstRow <= 0) {
- result = "SELECT TOP " + maxRows + " " + result.substring(7);
- } else {
- final int offset = firstRow - 1;
- result = "SELECT LIMIT " + offset + " " + maxRows + " " + result.substring(7);
- }
- }
-
- return result;
- }
-
- @Override
- public String rewriteFilterItem(FilterItem item) {
- if (!item.isCompoundFilter()) {
- final SelectItem selectItem = item.getSelectItem();
- final Column column = selectItem.getColumn();
- if (column != null) {
- if (column.getType() == ColumnType.TIMESTAMP) {
- // HSQLDB does not treat (TIMESTAMP 'yyyy-MM-dd hh:mm:ss')
- // tokens correctly
- String result = super.rewriteFilterItem(item);
- int indexOfTimestamp = result.lastIndexOf("TIMESTAMP");
- if (indexOfTimestamp != -1) {
- result = result.substring(0, indexOfTimestamp)
- + result.substring(indexOfTimestamp + "TIMESTAMP".length());
- }
- return result;
- }
- }
- }
- return super.rewriteFilterItem(item);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/IQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/IQueryRewriter.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/IQueryRewriter.java
deleted file mode 100644
index 4d94d40..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/IQueryRewriter.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * 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.jdbc.dialects;
-
-import java.sql.Types;
-
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.ColumnType;
-
-/**
- * A query rewriter can be used for rewriting (part of) a query's string
- * representation. This is usefull for databases that deviate from the SQL 99
- * compliant syntax which is delievered by the query and it's query item's
- * toString() methods.
- *
- * @see AbstractQueryRewriter
- * @see JdbcDataContext
- */
-public interface IQueryRewriter {
-
- public String rewriteFromItem(FromItem item);
-
- public String rewriteQuery(Query query);
-
- public String rewriteFilterItem(FilterItem whereItem);
-
- /**
- * Gets whether this query rewriter is able to write the "Max rows" query
- * property to the query string.
- *
- * @return whether this query rewriter is able to write the "Max rows" query
- * property to the query string.
- */
- public boolean isMaxRowsSupported();
-
- /**
- * Gets whether this query rewriter is able to write the "First row" query
- * property to the query string.
- *
- * @return whether this query rewriter is able to write the "First row"
- * query property to the query string.
- */
- public boolean isFirstRowSupported();
-
- /**
- * Escapes the quotes within a String literal of a query item.
- *
- * @return String item with quotes escaped.
- */
- public String escapeQuotes(String item);
-
- /**
- * Rewrites the name of a column type, as it is written in CREATE TABLE
- * statements. Some databases dont support all column types, or have
- * different names for them. The implementation of this method will do that
- * conversion.
- *
- * @param columnType
- * @return
- */
- public String rewriteColumnType(ColumnType columnType);
-
- /**
- * Gets the column type for a specific JDBC type (as defined in
- * {@link Types}), native type name and column size.
- *
- * @param jdbcType
- * @param nativeType
- * @param columnSize
- * @return
- */
- public ColumnType getColumnType(int jdbcType, String nativeType, Integer columnSize);
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/LimitOffsetQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/LimitOffsetQueryRewriter.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/LimitOffsetQueryRewriter.java
deleted file mode 100644
index b15b8ca..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/LimitOffsetQueryRewriter.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * 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.jdbc.dialects;
-
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.Query;
-
-/**
- * Query rewriter for databases that support LIMIT and OFFSET keywords for max
- * rows and first row properties.
- */
-public abstract class LimitOffsetQueryRewriter extends DefaultQueryRewriter {
-
- public LimitOffsetQueryRewriter(JdbcDataContext dataContext) {
- super(dataContext);
- }
-
- @Override
- public final boolean isFirstRowSupported() {
- return true;
- }
-
- @Override
- public final boolean isMaxRowsSupported() {
- return true;
- }
-
- /**
- * {@inheritDoc}
- *
- * If the Max rows and/or First row property of the query is set, then we
- * will use the database's LIMIT and OFFSET functions.
- */
- @Override
- public String rewriteQuery(Query query) {
- String queryString = super.rewriteQuery(query);
- Integer maxRows = query.getMaxRows();
- Integer firstRow = query.getFirstRow();
- if (maxRows != null || firstRow != null) {
- if (maxRows == null) {
- maxRows = Integer.MAX_VALUE;
- }
- queryString = queryString + " LIMIT " + maxRows;
-
- if (firstRow != null && firstRow > 1) {
- // offset is 0-based
- int offset = firstRow - 1;
- queryString = queryString + " OFFSET " + offset;
- }
- }
-
-
- return queryString;
- }
-}
[50/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/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
new file mode 100644
index 0000000..3300e17
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/AbstractDataContext.java
@@ -0,0 +1,463 @@
+/**
+ * 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;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.query.CompiledQuery;
+import org.eobjects.metamodel.query.DefaultCompiledQuery;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.builder.InitFromBuilder;
+import org.eobjects.metamodel.query.builder.InitFromBuilderImpl;
+import org.eobjects.metamodel.query.parser.QueryParser;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * Abstract implementation of the DataContext interface. Provides convenient
+ * implementations of all trivial and datastore-independent methods.
+ *
+ * @author Kasper Sørensen
+ */
+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;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final DataContext refreshSchemas() {
+ _schemaCache.clear();
+ _schemaNameCache = null;
+ return this;
+ }
+
+ /**
+ * {@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];
+ final Schema schema = _schemaCache.get(getSchemaCacheKey(name));
+ if (schema == null) {
+ final Schema newSchema = getSchemaByName(name);
+ if (newSchema == null) {
+ throw new MetaModelException("Declared schema does not exist: " + name);
+ }
+ final Schema existingSchema = _schemaCache.putIfAbsent(getSchemaCacheKey(name), newSchema);
+ if (existingSchema == null) {
+ schemas[i] = newSchema;
+ } else {
+ schemas[i] = existingSchema;
+ }
+ } else {
+ schemas[i] = schema;
+ }
+ }
+ return schemas;
+ }
+
+ private String getSchemaCacheKey(String name) {
+ if (name == null) {
+ return NULL_SCHEMA_NAME_TOKEN;
+ }
+ return name;
+ }
+
+ /**
+ * m {@inheritDoc}
+ */
+ @Override
+ public final String[] getSchemaNames() throws MetaModelException {
+ if (_schemaNameCache == null) {
+ _schemaNameCache = getSchemaNamesInternal();
+ }
+ String[] schemaNames = Arrays.copyOf(_schemaNameCache, _schemaNameCache.length);
+ Arrays.sort(schemaNames, _schemaNameComparator);
+ return schemaNames;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final Schema getDefaultSchema() throws MetaModelException {
+ Schema result = null;
+ String defaultSchemaName = getDefaultSchemaName();
+ if (defaultSchemaName != null) {
+ result = getSchemaByName(defaultSchemaName);
+ }
+ if (result == null) {
+ Schema[] schemas = getSchemas();
+ if (schemas.length == 1) {
+ result = schemas[0];
+ } else {
+ int highestTableCount = -1;
+ for (int i = 0; i < schemas.length; i++) {
+ final Schema schema = schemas[i];
+ String name = schema.getName();
+ if (schema != null) {
+ name = name.toLowerCase();
+ boolean isInformationSchema = name.startsWith("information") && name.endsWith("schema");
+ if (!isInformationSchema && schema.getTableCount() > highestTableCount) {
+ highestTableCount = schema.getTableCount();
+ result = schema;
+ }
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final InitFromBuilder query() {
+ return new InitFromBuilderImpl(this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Query parseQuery(final String queryString) throws MetaModelException {
+ final QueryParser parser = new QueryParser(this, queryString);
+ final Query query = parser.parse();
+ return query;
+ }
+
+ @Override
+ public CompiledQuery compileQuery(final Query query) throws MetaModelException {
+ return new DefaultCompiledQuery(query);
+ }
+
+ @Override
+ public DataSet executeQuery(CompiledQuery compiledQuery, Object... values) {
+ assert compiledQuery instanceof DefaultCompiledQuery;
+
+ final DefaultCompiledQuery defaultCompiledQuery = (DefaultCompiledQuery) compiledQuery;
+ final Query query = defaultCompiledQuery.cloneWithParameterValues(values);
+
+ return executeQuery(query);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final DataSet executeQuery(final String queryString) throws MetaModelException {
+ final Query query = parseQuery(queryString);
+ final DataSet dataSet = executeQuery(query);
+ return dataSet;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final Schema getSchemaByName(String name) throws MetaModelException {
+ Schema schema = _schemaCache.get(getSchemaCacheKey(name));
+ if (schema == null) {
+ if (name == null) {
+ schema = getSchemaByNameInternal(null);
+ } else {
+ String[] schemaNames = getSchemaNames();
+ for (String schemaName : schemaNames) {
+ if (name.equalsIgnoreCase(schemaName)) {
+ schema = getSchemaByNameInternal(name);
+ break;
+ }
+ }
+ if (schema == null) {
+ for (String schemaName : schemaNames) {
+ if (name.equalsIgnoreCase(schemaName)) {
+ // try again with "schemaName" as param instead of
+ // "name".
+ schema = getSchemaByNameInternal(schemaName);
+ break;
+ }
+ }
+ }
+ }
+ if (schema != null) {
+ Schema existingSchema = _schemaCache.putIfAbsent(getSchemaCacheKey(schema.getName()), schema);
+ if (existingSchema != null) {
+ // race conditions may cause two schemas to be created.
+ // We'll favor the existing schema if possible, since schema
+ // may contain lazy-loading logic and so on.
+ return existingSchema;
+ }
+ }
+ }
+ return schema;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final Column getColumnByQualifiedLabel(final String columnName) {
+ if (columnName == null) {
+ return null;
+ }
+ Schema schema = null;
+ final String[] schemaNames = getSchemaNames();
+ for (final String schemaName : schemaNames) {
+ if (schemaName == null) {
+ // search without schema name (some databases have only a single
+ // schema with no name)
+ schema = getSchemaByName(null);
+ if (schema != null) {
+ Column column = getColumn(schema, columnName);
+ if (column != null) {
+ return column;
+ }
+ }
+ } else {
+ // Search case-sensitive
+ Column col = searchColumn(schemaName, columnName, columnName);
+ if (col != null) {
+ return col;
+ }
+ }
+ }
+
+ final String columnNameInLowerCase = columnName.toLowerCase();
+ for (final String schemaName : schemaNames) {
+ if (schemaName != null) {
+ // search case-insensitive
+ String schameNameInLowerCase = schemaName.toLowerCase();
+ Column col = searchColumn(schameNameInLowerCase, columnName, columnNameInLowerCase);
+ if (col != null) {
+ return col;
+ }
+ }
+ }
+
+ schema = getDefaultSchema();
+ if (schema != null) {
+ Column column = getColumn(schema, columnName);
+ if (column != null) {
+ return column;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Searches for a particular column within a schema
+ *
+ * @param schemaNameSearch
+ * the schema name to use for search
+ * @param columnNameOriginal
+ * the original column name
+ * @param columnNameSearch
+ * the column name as it should be searched for (either the same
+ * as original, or lower case in case of case-insensitive search)
+ * @return
+ */
+ private Column searchColumn(String schemaNameSearch, String columnNameOriginal, String columnNameSearch) {
+ if (columnNameSearch.startsWith(schemaNameSearch)) {
+ Schema schema = getSchemaByName(schemaNameSearch);
+ if (schema != null) {
+ String tableAndColumnPath = columnNameOriginal.substring(schemaNameSearch.length());
+
+ if (tableAndColumnPath.charAt(0) == '.') {
+ tableAndColumnPath = tableAndColumnPath.substring(1);
+
+ Column column = getColumn(schema, tableAndColumnPath);
+ if (column != null) {
+ return column;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ private final Column getColumn(final Schema schema, final String tableAndColumnPath) {
+ Table table = null;
+ String columnPath = tableAndColumnPath;
+ final String[] tableNames = schema.getTableNames();
+ for (final String tableName : tableNames) {
+ if (tableName != null) {
+ // search case-sensitive
+ if (isStartingToken(tableName, tableAndColumnPath)) {
+ table = schema.getTableByName(tableName);
+ columnPath = tableAndColumnPath.substring(tableName.length());
+
+ if (columnPath.charAt(0) == '.') {
+ columnPath = columnPath.substring(1);
+ break;
+ }
+ }
+ }
+ }
+
+ if (table == null) {
+ final String tableAndColumnPathInLowerCase = tableAndColumnPath.toLowerCase();
+ for (final String tableName : tableNames) {
+ if (tableName != null) {
+ String tableNameInLowerCase = tableName.toLowerCase();
+ // search case-insensitive
+ if (isStartingToken(tableNameInLowerCase, tableAndColumnPathInLowerCase)) {
+ table = schema.getTableByName(tableName);
+ columnPath = tableAndColumnPath.substring(tableName.length());
+
+ if (columnPath.charAt(0) == '.') {
+ columnPath = columnPath.substring(1);
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ if (table == null && tableNames.length == 1) {
+ table = schema.getTables()[0];
+ }
+
+ if (table != null) {
+ Column column = table.getColumnByName(columnPath);
+ if (column != null) {
+ return column;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final Table getTableByQualifiedLabel(final String tableName) {
+ if (tableName == null) {
+ return null;
+ }
+ Schema schema = null;
+ String[] schemaNames = getSchemaNames();
+ for (String schemaName : schemaNames) {
+ if (schemaName == null) {
+ // there's an unnamed schema present.
+ schema = getSchemaByName(null);
+ if (schema != null) {
+ Table table = schema.getTableByName(tableName);
+ return table;
+ }
+ } else {
+ // case-sensitive search
+ if (isStartingToken(schemaName, tableName)) {
+ schema = getSchemaByName(schemaName);
+ }
+ }
+ }
+
+ if (schema == null) {
+ final String tableNameInLowerCase = tableName.toLowerCase();
+ for (final String schemaName : schemaNames) {
+ if (schemaName != null) {
+ // case-insensitive search
+ final String schemaNameInLowerCase = schemaName.toLowerCase();
+ if (isStartingToken(schemaNameInLowerCase, tableNameInLowerCase)) {
+ schema = getSchemaByName(schemaName);
+ }
+ }
+ }
+ }
+
+ if (schema == null) {
+ schema = getDefaultSchema();
+ }
+
+ String tablePart = tableName.toLowerCase();
+ String schemaName = schema.getName();
+ if (schemaName != null && isStartingToken(schemaName.toLowerCase(), tablePart)) {
+ tablePart = tablePart.substring(schemaName.length());
+ if (tablePart.startsWith(".")) {
+ tablePart = tablePart.substring(1);
+ }
+ }
+
+ return schema.getTableByName(tablePart);
+ }
+
+ private boolean isStartingToken(String partName, String fullName) {
+ if (fullName.startsWith(partName)) {
+ final int length = partName.length();
+ if (length == 0) {
+ return false;
+ }
+ if (fullName.length() > length) {
+ final char nextChar = fullName.charAt(length);
+ if (isQualifiedPathDelim(nextChar)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ protected boolean isQualifiedPathDelim(char c) {
+ return c == '.' || c == '"';
+ }
+
+ /**
+ * Gets schema names from the non-abstract implementation. These schema
+ * names will be cached except if the {@link #refreshSchemas()} method is
+ * called.
+ *
+ * @return an array of schema names.
+ */
+ protected abstract String[] getSchemaNamesInternal();
+
+ /**
+ * Gets the name of the default schema.
+ *
+ * @return the default schema name.
+ */
+ protected abstract String getDefaultSchemaName();
+
+ /**
+ * Gets a specific schema from the non-abstract implementation. This schema
+ * object will be cached except if the {@link #refreshSchemas()} method is
+ * called.
+ *
+ * @param name
+ * the name of the schema to get
+ * @return a schema object representing the named schema, or null if no such
+ * schema exists.
+ */
+ protected abstract Schema getSchemaByNameInternal(String name);
+}
\ 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/AbstractUpdateCallback.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/AbstractUpdateCallback.java b/core/src/main/java/org/apache/metamodel/AbstractUpdateCallback.java
new file mode 100644
index 0000000..602a412
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/AbstractUpdateCallback.java
@@ -0,0 +1,164 @@
+/**
+ * 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;
+
+import java.util.Arrays;
+
+import org.eobjects.metamodel.create.TableCreationBuilder;
+import org.eobjects.metamodel.delete.RowDeletionBuilder;
+import org.eobjects.metamodel.drop.TableDropBuilder;
+import org.eobjects.metamodel.insert.RowInsertionBuilder;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.update.RowUpdationBuilder;
+
+/**
+ * Abstract implementation of the {@link UpdateCallback} interface. Implements
+ * only the data store agnostic methods.
+ *
+ * @author Kasper Sørensen
+ */
+public abstract class AbstractUpdateCallback implements UpdateCallback {
+
+ private final DataContext _dataContext;
+
+ public AbstractUpdateCallback(DataContext dataContext) {
+ _dataContext = dataContext;
+ }
+
+ @Override
+ public TableCreationBuilder createTable(String schemaName, String tableName) throws IllegalArgumentException,
+ IllegalStateException {
+ Schema schema = getSchema(schemaName);
+ return createTable(schema, tableName);
+ }
+
+ @Override
+ public TableDropBuilder dropTable(String schemaName, String tableName) throws IllegalArgumentException,
+ IllegalStateException, UnsupportedOperationException {
+ Table table = getTable(schemaName, tableName);
+ return dropTable(table);
+ }
+
+ @Override
+ public TableDropBuilder dropTable(Schema schema, String tableName) throws IllegalArgumentException,
+ IllegalStateException, UnsupportedOperationException {
+ 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()));
+ }
+ return dropTable(table);
+ }
+
+ @Override
+ public final RowInsertionBuilder insertInto(String tableName) throws IllegalArgumentException,
+ IllegalStateException {
+ return insertInto(getTable(tableName));
+ }
+
+ @Override
+ public RowInsertionBuilder insertInto(String schemaName, String tableName) throws IllegalArgumentException,
+ IllegalStateException, UnsupportedOperationException {
+ return insertInto(getTable(schemaName, tableName));
+ }
+
+ private Table getTable(String schemaName, String tableName) {
+ final Schema schema = getSchema(schemaName);
+ 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()));
+ }
+ return table;
+ }
+
+ private Schema getSchema(String schemaName) {
+ final Schema schema = _dataContext.getSchemaByName(schemaName);
+ if (schema == null) {
+ throw new IllegalArgumentException("No such schema: " + schemaName);
+ }
+ return schema;
+ }
+
+ @Override
+ public final RowDeletionBuilder deleteFrom(String tableName) {
+ return deleteFrom(getTable(tableName));
+ }
+
+ @Override
+ public RowDeletionBuilder deleteFrom(String schemaName, String tableName) throws IllegalArgumentException,
+ IllegalStateException, UnsupportedOperationException {
+ final Table table = getTable(schemaName, tableName);
+ return deleteFrom(table);
+ }
+
+ @Override
+ public final TableDropBuilder dropTable(String tableName) {
+ return dropTable(getTable(tableName));
+ }
+
+ @Override
+ public final RowUpdationBuilder update(String tableName) {
+ return update(getTable(tableName));
+ }
+
+ private Table getTable(String tableName) {
+ Table table = getDataContext().getTableByQualifiedLabel(tableName);
+ if (table == null) {
+ throw new IllegalArgumentException("No such table: " + tableName);
+ }
+ return table;
+ }
+
+ @Override
+ public DataContext getDataContext() {
+ return _dataContext;
+ }
+
+ @Override
+ public boolean isCreateTableSupported() {
+ // since 2.0 all updateable datacontext have create table support
+ return true;
+ }
+
+ @Override
+ public boolean isInsertSupported() {
+ // since 2.0 all updateable datacontext have create table support
+ return true;
+ }
+
+ @Override
+ public boolean isUpdateSupported() {
+ return isInsertSupported() && isDeleteSupported();
+ }
+
+ @Override
+ public RowUpdationBuilder update(String schemaName, String tableName) throws IllegalArgumentException,
+ IllegalStateException, UnsupportedOperationException {
+ final Table table = getTable(schemaName, tableName);
+ return update(table);
+ }
+
+ @Override
+ public RowUpdationBuilder update(Table table) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException {
+ return new DeleteAndInsertBuilder(this, table);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/BatchUpdateScript.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/BatchUpdateScript.java b/core/src/main/java/org/apache/metamodel/BatchUpdateScript.java
new file mode 100644
index 0000000..d7b567c
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/BatchUpdateScript.java
@@ -0,0 +1,29 @@
+/**
+ * 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;
+
+/**
+ * Indicator sub-interface of {@link UpdateScript}. Implementing your updates
+ * using this interface indicates to the underlying
+ * {@link UpdateableDataContext} that the update script represents a large batch
+ * update and that appropriate optimizations may be taken into use if available.
+ */
+public interface BatchUpdateScript extends UpdateScript {
+
+}
\ 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/CompositeDataContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/CompositeDataContext.java b/core/src/main/java/org/apache/metamodel/CompositeDataContext.java
new file mode 100644
index 0000000..82d6c01
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/CompositeDataContext.java
@@ -0,0 +1,204 @@
+/**
+ * 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;
+
+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 org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.CompositeSchema;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.Func;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DataContext for composite datacontexts. Composite DataContexts wrap several
+ * other datacontexts and makes cross-datastore querying possible.
+ *
+ * @author Kasper Sørensen
+ */
+public class CompositeDataContext extends AbstractDataContext {
+
+ private final static Logger logger = LoggerFactory.getLogger(CompositeDataContext.class);
+ private Map<String, CompositeSchema> _compositeSchemas = new HashMap<String, CompositeSchema>();
+ private DataContext[] _delegates;
+
+ public CompositeDataContext(DataContext... delegates) {
+ if (delegates == null) {
+ throw new IllegalArgumentException("delegates cannot be null");
+ }
+ _delegates = delegates;
+ }
+
+ public CompositeDataContext(Collection<DataContext> delegates) {
+ if (delegates == null) {
+ throw new IllegalArgumentException("delegates cannot be null");
+ }
+ _delegates = delegates.toArray(new DataContext[delegates.size()]);
+ }
+
+ @Override
+ public DataSet executeQuery(Query query) throws MetaModelException {
+ // a set of all datacontexts involved
+ Set<DataContext> dataContexts = new HashSet<DataContext>();
+
+ // find all datacontexts involved, by investigating FROM items
+ List<FromItem> items = query.getFromClause().getItems();
+ for (FromItem item : items) {
+ List<FromItem> tableFromItems = MetaModelHelper.getTableFromItems(item);
+ for (FromItem fromItem : tableFromItems) {
+ Table table = fromItem.getTable();
+
+ DataContext dc = getDataContext(table);
+ if (dc == null) {
+ throw new MetaModelException("Could not resolve child-datacontext for table: " + table);
+ }
+ dataContexts.add(dc);
+ }
+ }
+
+ if (dataContexts.isEmpty()) {
+ throw new MetaModelException("No suiting delegate DataContext to execute query: " + query);
+ } else if (dataContexts.size() == 1) {
+ Iterator<DataContext> it = dataContexts.iterator();
+ assert it.hasNext();
+ DataContext dc = it.next();
+ return dc.executeQuery(query);
+ } else {
+ // we create a datacontext which can materialize tables from
+ // separate datacontexts.
+ final Func<Table, DataContext> dataContextRetrievalFunction = new Func<Table, DataContext>() {
+ @Override
+ public DataContext eval(Table table) {
+ return getDataContext(table);
+ }
+ };
+ return new CompositeQueryDelegate(dataContextRetrievalFunction).executeQuery(query);
+ }
+ }
+
+ private DataContext getDataContext(Table table) {
+ DataContext result = null;
+ if (table != null) {
+ Schema schema = table.getSchema();
+
+ if (schema != null) {
+ for (DataContext dc : _delegates) {
+ Schema dcSchema = dc.getSchemaByName(schema.getName());
+ if (dcSchema != null) {
+
+ // first round = try with schema identity match
+ if (dcSchema == schema) {
+ logger.debug("DataContext for '{}' resolved (using identity) to: '{}'", table, dcSchema);
+ result = dc;
+ break;
+ }
+ }
+ }
+
+ if (result == null) {
+ for (DataContext dc : _delegates) {
+ Schema dcSchema = dc.getSchemaByName(schema.getName());
+ if (dcSchema != null) {
+ // second round = try with schema equals method
+ if (dcSchema.equals(schema)) {
+ logger.debug("DataContext for '{}' resolved (using equals) to: '{}'", table, dcSchema);
+ result = dc;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (result == null) {
+ logger.warn("Couldn't resolve DataContext for {}", table);
+ }
+ return result;
+ }
+
+ @Override
+ public String getDefaultSchemaName() throws MetaModelException {
+ for (DataContext dc : _delegates) {
+ Schema schema = dc.getDefaultSchema();
+ if (schema != null) {
+ return schema.getName();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Schema getSchemaByNameInternal(String name) throws MetaModelException {
+ CompositeSchema compositeSchema = _compositeSchemas.get(name);
+ if (compositeSchema != null) {
+ return compositeSchema;
+ }
+ List<Schema> matchingSchemas = new ArrayList<Schema>();
+ for (DataContext dc : _delegates) {
+ Schema schema = dc.getSchemaByName(name);
+ if (schema != null) {
+ matchingSchemas.add(schema);
+ }
+ }
+ if (matchingSchemas.size() == 1) {
+ return matchingSchemas.iterator().next();
+ }
+ if (matchingSchemas.size() > 1) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Name-clash detected for Schema '{}'. Creating CompositeSchema.");
+ }
+ compositeSchema = new CompositeSchema(name, matchingSchemas);
+ _compositeSchemas.put(name, compositeSchema);
+ return compositeSchema;
+ }
+ return null;
+ }
+
+ @Override
+ public String[] getSchemaNamesInternal() throws MetaModelException {
+ Set<String> set = new HashSet<String>();
+ for (DataContext dc : _delegates) {
+ String[] schemaNames = dc.getSchemaNames();
+ for (String name : schemaNames) {
+ if (!MetaModelHelper.isInformationSchema(name)) {
+ // we skip information schemas, since they're anyways going
+ // to be incomplete and misleading.
+ set.add(name);
+ }
+ }
+ }
+ String[] result = set.toArray(new String[set.size()]);
+ Arrays.sort(result);
+ return result;
+ }
+
+}
\ 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/CompositeQueryDelegate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/CompositeQueryDelegate.java b/core/src/main/java/org/apache/metamodel/CompositeQueryDelegate.java
new file mode 100644
index 0000000..70b19f1
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/CompositeQueryDelegate.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.Func;
+
+final class CompositeQueryDelegate extends QueryPostprocessDelegate {
+
+ private final Func<Table, DataContext> _dataContextRetrievalFunction;
+
+ public CompositeQueryDelegate(
+ Func<Table, DataContext> dataContextRetrievalFunction) {
+ _dataContextRetrievalFunction = dataContextRetrievalFunction;
+ }
+
+ @Override
+ protected DataSet materializeMainSchemaTable(Table table, Column[] columns,
+ int maxRows) {
+ // find the appropriate datacontext to execute a simple
+ // table materialization query
+ DataContext dc = _dataContextRetrievalFunction.eval(table);
+ Query q = new Query().select(columns).from(table);
+ if (maxRows >= 0) {
+ q.setMaxRows(maxRows);
+ }
+ return dc.executeQuery(q);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/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
new file mode 100644
index 0000000..b536d7d
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/DataContext.java
@@ -0,0 +1,199 @@
+/**
+ * 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;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.query.CompiledQuery;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.QueryParameter;
+import org.eobjects.metamodel.query.builder.InitFromBuilder;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * A DataContext represents the central entry point for interactions with
+ * datastores. The DataContext contains of the structure of data (in the form of
+ * schemas) and interactions (in the form of queries) with data.
+ *
+ * @author Kasper Sørensen
+ */
+public interface DataContext {
+
+ /**
+ * Enforces a refresh of the schemas. If not refreshed, cached schema
+ * objects may be used.
+ *
+ * @return this DataContext
+ */
+ public DataContext refreshSchemas();
+
+ /**
+ * Gets all schemas within this DataContext.
+ *
+ * @return the schemas in this data context. Schemas are cached for reuse in
+ * many situations so if you want to update the schemas, use the
+ * refreshSchemas() method.
+ * @throws MetaModelException
+ * if an error occurs retrieving the schema model
+ */
+ public Schema[] getSchemas() throws MetaModelException;
+
+ /**
+ * Gets the names of all schemas within this DataContext.
+ *
+ * @return an array of valid schema names
+ * @throws MetaModelException
+ * if an error occurs retrieving the schema model
+ */
+ public String[] getSchemaNames() throws MetaModelException;
+
+ /**
+ * Gets the default schema of this DataContext.
+ *
+ * @return the schema that you are most probable to be interested in. The
+ * default schema is determined by finding the schema with most
+ * available of tables. In a lot of situations there will only be a
+ * single available schema and in that case this will of course be
+ * the schema returned.
+ * @throws MetaModelException
+ * if an error occurs retrieving the schema model
+ */
+ public Schema getDefaultSchema() throws MetaModelException;
+
+ /**
+ * Gets a schema by a specified name.
+ *
+ * @param name
+ * the name of the desired schema
+ * @return the Schema with the specified name or null if no such schema
+ * exists
+ * @throws MetaModelException
+ * if an error occurs retrieving the schema model
+ */
+ public Schema getSchemaByName(String name) throws MetaModelException;
+
+ /**
+ * Starts building a query using the query builder API. This way of building
+ * queries is the preferred approach since it provides a more type-safe
+ * approach to building API's as well as allows the DataContext
+ * implementation to be aware of the query building process.
+ *
+ * @return a query builder component at the initial position in building a
+ * query.
+ */
+ public InitFromBuilder query();
+
+ /**
+ * Parses a string-based SQL query and produces a corresponding
+ * {@link Query} object.
+ *
+ * @param queryString
+ * the SQL query to parse
+ * @return a {@link Query} object corresponding to the SQL query.
+ * @throws MetaModelException
+ * in case the parsing was unsuccesful.
+ */
+ public Query parseQuery(String queryString) throws MetaModelException;
+
+ /**
+ * Executes a query against the DataContext.
+ *
+ * @param query
+ * the query object to execute
+ * @return the {@link DataSet} produced from executing the query
+ * @throws MetaModelException
+ * if the specified query does not make sense or cannot be
+ * executed because of restraints on the type of datastore.
+ */
+ public DataSet executeQuery(Query query) throws MetaModelException;
+
+ /**
+ * Compiles a query, preparing it for reuse. Often times compiled queries
+ * have a performance improvement when executed, but at the cost of a
+ * preparation time penalty. Therefore it is adviced to use compiled queries
+ * when the same query is to be fired multiple times.
+ *
+ * Compiled queries can contain {@link QueryParameter}s as operands in the
+ * WHERE clause, making it possible to reuse the same query with different
+ * parameter values.
+ *
+ * @see CompiledQuery
+ * @see QueryParameter
+ *
+ * @param query
+ * the query object to execute, possibly holding one or more
+ * {@link QueryParameter}s.
+ * @return the {@link CompiledQuery} after preparing the query
+ *
+ * @throws MetaModelException
+ * if preparing the query is unsuccesful
+ */
+ public CompiledQuery compileQuery(Query query) throws MetaModelException;
+
+ /**
+ * Executes a compiled query with given values as parameters.
+ *
+ * @param compiledQuery
+ * the compiledQuery object to execute
+ * @param values
+ * the values for parameters in the {@link CompiledQuery}.
+ * @return the {@link DataSet} produced from executing the query.
+ */
+ public DataSet executeQuery(CompiledQuery compiledQuery, Object... values);
+
+ /**
+ * Parses and executes a string-based SQL query.
+ *
+ * This method is essentially equivalent to calling first
+ * {@link #parseQuery(String)} and then {@link #executeQuery(Query)} with
+ * the parsed query.
+ *
+ * @param query
+ * the SQL query to parse
+ * @return the {@link DataSet} produced from executing the query
+ * @throws MetaModelException
+ * if either parsing or executing the query produces an
+ * exception
+ */
+ public DataSet executeQuery(String queryString) throws MetaModelException;
+
+ /**
+ * Finds a column in the DataContext based on a fully qualified column
+ * label. The qualified label consists of the the schema, table and column
+ * name, delimited by a dot (.).
+ *
+ * @param columnName
+ * @return a column that matches the qualified label, or null if no such
+ * column exists
+ */
+ public Column getColumnByQualifiedLabel(final String columnName);
+
+ /**
+ * Finds a table in the DataContext based on a fully qualified table label.
+ * The qualified label consists of the the schema and table name, delimited
+ * by a dot (.).
+ *
+ * @param tableName
+ * @return a table that matches the qualified label, or null if no such
+ * table exists
+ */
+ public Table getTableByQualifiedLabel(final String tableName);
+
+}
\ 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/DeleteAndInsertBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/DeleteAndInsertBuilder.java b/core/src/main/java/org/apache/metamodel/DeleteAndInsertBuilder.java
new file mode 100644
index 0000000..36e4b3e
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/DeleteAndInsertBuilder.java
@@ -0,0 +1,111 @@
+/**
+ * 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;
+
+import java.util.List;
+import java.util.ListIterator;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.DefaultRow;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.data.SimpleDataSetHeader;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.update.AbstractRowUpdationBuilder;
+import org.eobjects.metamodel.update.RowUpdationBuilder;
+
+/**
+ * Simple implementation of the {@link RowUpdationBuilder} interface, which
+ * simply uses a combined delete+insert strategy for performing updates. Note
+ * that this implementation is not desirable performance-wise in many cases, but
+ * does provide a functional equivalent to a "real" update.
+ */
+public class DeleteAndInsertBuilder extends AbstractRowUpdationBuilder {
+
+ private final AbstractUpdateCallback _updateCallback;
+
+ public DeleteAndInsertBuilder(AbstractUpdateCallback updateCallback, Table table) {
+ super(table);
+ assert updateCallback.isInsertSupported();
+ assert updateCallback.isDeleteSupported();
+ _updateCallback = updateCallback;
+ }
+
+ @Override
+ public void execute() throws MetaModelException {
+ // retain rows in memory
+ List<Row> rows = getRowsToUpdate();
+
+ // delete rows
+ _updateCallback.deleteFrom(getTable()).where(getWhereItems()).execute();
+
+ // modify rows
+ rows = updateRows(rows);
+
+ // insert rows
+ for (Row row : rows) {
+ _updateCallback.insertInto(getTable()).like(row).execute();
+ }
+ }
+
+ private List<Row> updateRows(List<Row> rows) {
+ for (ListIterator<Row> it = rows.listIterator(); it.hasNext();) {
+ final Row original = (Row) it.next();
+ final Row updated = update(original);
+ it.set(updated);
+ }
+ return rows;
+ }
+
+ /**
+ * Produces an updated row out of the original
+ *
+ * @param original
+ * @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++) {
+ final Object value;
+ Column column = items[i].getColumn();
+ if (isSet(column)) {
+ // use update statement's value
+ value = getValues()[i];
+ } else {
+ // use original value
+ value = original.getValue(i);
+ }
+ values[i] = value;
+ }
+ return new DefaultRow(new SimpleDataSetHeader(items), values);
+ }
+
+ protected List<Row> getRowsToUpdate() {
+ 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 List<Row> rows = dataSet.toRows();
+ return rows;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/InconsistentRowFormatException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/InconsistentRowFormatException.java b/core/src/main/java/org/apache/metamodel/InconsistentRowFormatException.java
new file mode 100644
index 0000000..b3baff9
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/InconsistentRowFormatException.java
@@ -0,0 +1,82 @@
+/**
+ * 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;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.Row;
+
+/**
+ * Abstract exception type that represents exceptions that occur when reading a
+ * data format which contain formatting errors or inconsistencies in on or more
+ * rows.
+ *
+ * Typically {@link InconsistentRowFormatException}s are thrown when calling
+ * {@link DataSet#next()}.
+ *
+ * All {@link InconsistentRowFormatException}s are optional, meaning that you
+ * can turn them on and off. When turned off the result of
+ * {@link #getProposedRow()} will be used transparently instead of throwing the
+ * exception.
+ *
+ * @author Kasper Sørensen
+ */
+public abstract class InconsistentRowFormatException extends MetaModelException {
+
+ private static final long serialVersionUID = 1L;
+
+ private final Row _proposedRow;
+ private final int _rowNumber;
+
+ public InconsistentRowFormatException(Row proposedRow, int rowNumber) {
+ super();
+ _proposedRow = proposedRow;
+ _rowNumber = rowNumber;
+ }
+
+ public InconsistentRowFormatException(Row proposedRow, int rowNumber,
+ Exception cause) {
+ super(cause);
+ _proposedRow = proposedRow;
+ _rowNumber = rowNumber;
+ }
+
+ /**
+ * Gets the row as MetaModel would gracefully interpret it.
+ *
+ * @return a row object which represents the {@link Row} as MetaModel would
+ * gracefully interpret it.
+ */
+ public Row getProposedRow() {
+ return _proposedRow;
+ }
+
+ /**
+ * Gets the row number (1-based).
+ *
+ * @return the index of the row.
+ */
+ public int getRowNumber() {
+ return _rowNumber;
+ }
+
+ @Override
+ public String getMessage() {
+ return "Inconsistent row format of row no. " + getRowNumber() + ".";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/MetaModelException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/MetaModelException.java b/core/src/main/java/org/apache/metamodel/MetaModelException.java
new file mode 100644
index 0000000..787b8c5
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/MetaModelException.java
@@ -0,0 +1,47 @@
+/**
+ * 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;
+
+/**
+ * Unchecked exception used to signal errors occuring in MetaModel.
+ *
+ * All MetaModelExceptions represent errors discovered withing the MetaModel
+ * framework. Typically these will occur if you have put together a query that
+ * is not meaningful or if there is a structural problem in a schema.
+ */
+public class MetaModelException extends RuntimeException {
+
+ private static final long serialVersionUID = 5455738384633428319L;
+
+ public MetaModelException(String message, Exception cause) {
+ super(message, cause);
+ }
+
+ public MetaModelException(String message) {
+ super(message);
+ }
+
+ public MetaModelException(Exception cause) {
+ super(cause);
+ }
+
+ public MetaModelException() {
+ super();
+ }
+}
\ 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/MetaModelHelper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/MetaModelHelper.java b/core/src/main/java/org/apache/metamodel/MetaModelHelper.java
new file mode 100644
index 0000000..a105973
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/MetaModelHelper.java
@@ -0,0 +1,775 @@
+/**
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.eobjects.metamodel.data.CachingDataSetHeader;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.DataSetHeader;
+import org.eobjects.metamodel.data.DefaultRow;
+import org.eobjects.metamodel.data.EmptyDataSet;
+import org.eobjects.metamodel.data.FilteredDataSet;
+import org.eobjects.metamodel.data.IRowFilter;
+import org.eobjects.metamodel.data.InMemoryDataSet;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.data.SimpleDataSetHeader;
+import org.eobjects.metamodel.data.SubSelectionDataSet;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.GroupByItem;
+import org.eobjects.metamodel.query.OrderByItem;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.query.parser.QueryParser;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.SuperColumnType;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.AggregateBuilder;
+import org.eobjects.metamodel.util.CollectionUtils;
+import org.eobjects.metamodel.util.EqualsBuilder;
+import org.eobjects.metamodel.util.Func;
+import org.eobjects.metamodel.util.ObjectComparator;
+import org.eobjects.metamodel.util.Predicate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class contains various helper functionality to common tasks in
+ * MetaModel, eg.:
+ *
+ * <ul>
+ * <li>Easy-access for traversing common schema items</li>
+ * <li>Manipulate data in memory. These methods are primarily used to enable
+ * queries for non-queryable data sources like CSV files and spreadsheets.</li>
+ * <li>Query rewriting, traversing and manipulation.</li>
+ * </ul>
+ *
+ * The class is mainly intended for internal use within the framework
+ * operations, but is kept stable, so it can also be used by framework users.
+ */
+public final class MetaModelHelper {
+
+ private final static Logger logger = LoggerFactory.getLogger(MetaModelHelper.class);
+
+ private MetaModelHelper() {
+ // Prevent instantiation
+ }
+
+ /**
+ * Creates an array of tables where all occurences of tables in the provided
+ * list of tables and columns are included
+ */
+ public static Table[] getTables(Collection<Table> tableList, Iterable<Column> columnList) {
+ HashSet<Table> set = new HashSet<Table>();
+ set.addAll(tableList);
+ for (Column column : columnList) {
+ set.add(column.getTable());
+ }
+ return set.toArray(new Table[set.size()]);
+ }
+
+ /**
+ * Determines if a schema is an information schema
+ *
+ * @param schema
+ * @return
+ */
+ public static boolean isInformationSchema(Schema schema) {
+ String name = schema.getName();
+ return isInformationSchema(name);
+ }
+
+ /**
+ * Determines if a schema name is the name of an information schema
+ *
+ * @param name
+ * @return
+ */
+ public static boolean isInformationSchema(String name) {
+ if (name == null) {
+ return false;
+ }
+ return QueryPostprocessDataContext.INFORMATION_SCHEMA_NAME.equals(name.toLowerCase());
+ }
+
+ /**
+ * Converts a list of columns to a corresponding array of tables
+ *
+ * @param columns
+ * the columns that the tables will be extracted from
+ * @return an array containing the tables of the provided columns.
+ */
+ public static Table[] getTables(Iterable<Column> columns) {
+ ArrayList<Table> result = new ArrayList<Table>();
+ for (Column column : columns) {
+ Table table = column.getTable();
+ if (!result.contains(table)) {
+ result.add(table);
+ }
+ }
+ return result.toArray(new Table[result.size()]);
+ }
+
+ /**
+ * Creates a subset array of columns, where only columns that are contained
+ * within the specified table are included.
+ *
+ * @param table
+ * @param columns
+ * @return an array containing the columns that exist in the table
+ */
+ public static Column[] getTableColumns(Table table, Iterable<Column> columns) {
+ if (table == null) {
+ return new Column[0];
+ }
+ final List<Column> result = new ArrayList<Column>();
+ for (Column column : columns) {
+ final boolean sameTable = table.equals(column.getTable());
+ if (sameTable) {
+ result.add(column);
+ }
+ }
+ return result.toArray(new Column[result.size()]);
+ }
+
+ /**
+ * Creates a subset array of columns, where only columns that are contained
+ * within the specified table are included.
+ *
+ * @param table
+ * @param columns
+ * @return an array containing the columns that exist in the table
+ */
+ public static Column[] getTableColumns(Table table, Column[] columns) {
+ return getTableColumns(table, Arrays.asList(columns));
+ }
+
+ public static DataSet getCarthesianProduct(DataSet... fromDataSets) {
+ return getCarthesianProduct(fromDataSets, new FilterItem[0]);
+ }
+
+ public static DataSet getCarthesianProduct(DataSet[] fromDataSets, Iterable<FilterItem> whereItems) {
+ // First check if carthesian product is even nescesary
+ if (fromDataSets.length == 1) {
+ return getFiltered(fromDataSets[0], whereItems);
+ }
+
+ List<SelectItem> selectItems = new ArrayList<SelectItem>();
+ for (DataSet dataSet : fromDataSets) {
+ for (int i = 0; i < dataSet.getSelectItems().length; i++) {
+ SelectItem item = dataSet.getSelectItems()[i];
+ selectItems.add(item);
+ }
+ }
+
+ int selectItemOffset = 0;
+ List<Object[]> data = new ArrayList<Object[]>();
+ for (int fromDataSetIndex = 0; fromDataSetIndex < fromDataSets.length; fromDataSetIndex++) {
+ DataSet fromDataSet = fromDataSets[fromDataSetIndex];
+ SelectItem[] fromSelectItems = fromDataSet.getSelectItems();
+ if (fromDataSetIndex == 0) {
+ while (fromDataSet.next()) {
+ Object[] values = fromDataSet.getRow().getValues();
+ Object[] row = new Object[selectItems.size()];
+ System.arraycopy(values, 0, row, selectItemOffset, values.length);
+ data.add(row);
+ }
+ fromDataSet.close();
+ } else {
+ List<Object[]> fromDataRows = new ArrayList<Object[]>();
+ while (fromDataSet.next()) {
+ fromDataRows.add(fromDataSet.getRow().getValues());
+ }
+ fromDataSet.close();
+ for (int i = 0; i < data.size(); i = i + fromDataRows.size()) {
+ Object[] originalRow = data.get(i);
+ data.remove(i);
+ for (int j = 0; j < fromDataRows.size(); j++) {
+ Object[] newRow = fromDataRows.get(j);
+ System.arraycopy(newRow, 0, originalRow, selectItemOffset, newRow.length);
+ data.add(i + j, originalRow.clone());
+ }
+ }
+ }
+ selectItemOffset += fromSelectItems.length;
+ }
+
+ if (data.isEmpty()) {
+ return new EmptyDataSet(selectItems);
+ }
+
+ final DataSetHeader header = new CachingDataSetHeader(selectItems);
+ final List<Row> rows = new ArrayList<Row>(data.size());
+ for (Object[] objects : data) {
+ rows.add(new DefaultRow(header, objects, null));
+ }
+
+ DataSet result = new InMemoryDataSet(header, rows);
+ if (whereItems != null) {
+ result = getFiltered(result, whereItems);
+ }
+ return result;
+ }
+
+ public static DataSet getCarthesianProduct(DataSet[] fromDataSets, FilterItem... filterItems) {
+ return getCarthesianProduct(fromDataSets, Arrays.asList(filterItems));
+ }
+
+ public static DataSet getFiltered(DataSet dataSet, Iterable<FilterItem> filterItems) {
+ List<IRowFilter> filters = CollectionUtils.map(filterItems, new Func<FilterItem, IRowFilter>() {
+ @Override
+ public IRowFilter eval(FilterItem filterItem) {
+ return filterItem;
+ }
+ });
+ if (filters.isEmpty()) {
+ return dataSet;
+ }
+
+ return new FilteredDataSet(dataSet, filters.toArray(new IRowFilter[filters.size()]));
+ }
+
+ public static DataSet getFiltered(DataSet dataSet, FilterItem... filterItems) {
+ return getFiltered(dataSet, Arrays.asList(filterItems));
+ }
+
+ public static DataSet getSelection(final List<SelectItem> selectItems, final DataSet dataSet) {
+ final SelectItem[] dataSetSelectItems = dataSet.getSelectItems();
+
+ // check if the selection is already the same
+ if (selectItems.size() == dataSetSelectItems.length) {
+ boolean same = true;
+ int i = 0;
+ for (SelectItem selectItem : selectItems) {
+ if (!EqualsBuilder.equals(selectItem, dataSetSelectItems[i])) {
+ same = false;
+ break;
+ }
+ i++;
+ }
+
+ if (same) {
+ // return the dataSet unmodified
+ return dataSet;
+ }
+ }
+
+ SelectItem[] selectItemsArray = selectItems.toArray(new SelectItem[selectItems.size()]);
+ return new SubSelectionDataSet(selectItemsArray, dataSet);
+ }
+
+ public static DataSet getSelection(SelectItem[] selectItems, DataSet dataSet) {
+ return getSelection(Arrays.asList(selectItems), dataSet);
+ }
+
+ public static DataSet getGrouped(List<SelectItem> selectItems, DataSet dataSet, Collection<GroupByItem> groupByItems) {
+ return getGrouped(selectItems, dataSet, groupByItems.toArray(new GroupByItem[groupByItems.size()]));
+ }
+
+ public static DataSet getGrouped(List<SelectItem> selectItems, DataSet dataSet, GroupByItem[] groupByItems) {
+ DataSet result = dataSet;
+ if (groupByItems != null && groupByItems.length > 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 DataSetHeader groupByHeader = new CachingDataSetHeader(groupBySelects);
+
+ // Creates a list of SelectItems that have functions
+ List<SelectItem> functionItems = getFunctionSelectItems(selectItems);
+
+ // Loop through the dataset and identify groups
+ while (dataSet.next()) {
+ Row row = dataSet.getRow();
+
+ // Subselect a row prototype with only the unique values that
+ // define the group
+ Row uniqueRow = row.getSubSelection(groupByHeader);
+
+ // function input is the values used for calculating aggregate
+ // functions in the group
+ Map<SelectItem, List<Object>> functionInput;
+ if (!uniqueRows.containsKey(uniqueRow)) {
+ // If this group already exist, use an existing function
+ // input
+ functionInput = new HashMap<SelectItem, List<Object>>();
+ for (SelectItem item : functionItems) {
+ functionInput.put(item, new ArrayList<Object>());
+ }
+ uniqueRows.put(uniqueRow, functionInput);
+ } else {
+ // If this is a new group, create a new function input
+ functionInput = uniqueRows.get(uniqueRow);
+ }
+
+ // Loop through aggregate functions to check for validity
+ for (SelectItem item : functionItems) {
+ List<Object> objects = functionInput.get(item);
+ Column column = item.getColumn();
+ if (column != null) {
+ Object value = row.getValue(new SelectItem(column));
+ objects.add(value);
+ } else if (SelectItem.isCountAllItem(item)) {
+ // Just use the empty string, since COUNT(*) don't
+ // evaluate values (but null values should be prevented)
+ objects.add("");
+ } else {
+ throw new IllegalArgumentException("Expression function not supported: " + item);
+ }
+ }
+ }
+
+ dataSet.close();
+ final List<Row> resultData = new ArrayList<Row>();
+ final DataSetHeader resultHeader = new CachingDataSetHeader(selectItems);
+
+ // Loop through the groups to generate aggregates
+ for (Entry<Row, Map<SelectItem, List<Object>>> entry : uniqueRows.entrySet()) {
+ Row row = entry.getKey();
+ Map<SelectItem, List<Object>> functionInput = entry.getValue();
+ Object[] resultRow = new Object[selectItems.size()];
+ // Loop through select items to generate a row
+ int i = 0;
+ for (SelectItem item : selectItems) {
+ int uniqueRowIndex = row.indexOf(item);
+ if (uniqueRowIndex != -1) {
+ // If there's already a value for the select item in the
+ // row, keep it (it's one of the grouped by columns)
+ resultRow[i] = row.getValue(uniqueRowIndex);
+ } else {
+ // Use the function input to calculate the aggregate
+ // value
+ List<Object> objects = functionInput.get(item);
+ if (objects != null) {
+ Object functionResult = item.getFunction().evaluate(objects.toArray());
+ resultRow[i] = functionResult;
+ } else {
+ if (item.getFunction() != null) {
+ logger.error("No function input found for SelectItem: {}", item);
+ }
+ }
+ }
+ i++;
+ }
+ resultData.add(new DefaultRow(resultHeader, resultRow, null));
+ }
+
+ if (resultData.isEmpty()) {
+ result = new EmptyDataSet(selectItems);
+ } else {
+ result = new InMemoryDataSet(resultHeader, resultData);
+ }
+ }
+ result = getSelection(selectItems, result);
+ return result;
+ }
+
+ /**
+ * Applies aggregate values to a dataset. This method is to be invoked AFTER
+ * any filters have been applied.
+ *
+ * @param workSelectItems
+ * all select items included in the processing of the query
+ * (including those originating from other clauses than the
+ * SELECT clause).
+ * @param dataSet
+ * @return
+ */
+ public static DataSet getAggregated(List<SelectItem> workSelectItems, DataSet dataSet) {
+ final List<SelectItem> functionItems = getFunctionSelectItems(workSelectItems);
+ if (functionItems.isEmpty()) {
+ return dataSet;
+ }
+
+ final Map<SelectItem, AggregateBuilder<?>> aggregateBuilders = new HashMap<SelectItem, AggregateBuilder<?>>();
+ for (SelectItem item : functionItems) {
+ aggregateBuilders.put(item, item.getFunction().build());
+ }
+
+ final DataSetHeader header;
+ final boolean onlyAggregates;
+ if (functionItems.size() != workSelectItems.size()) {
+ onlyAggregates = false;
+ header = new CachingDataSetHeader(workSelectItems);
+ } else {
+ onlyAggregates = true;
+ header = new SimpleDataSetHeader(workSelectItems);
+ }
+
+ final List<Row> resultRows = new ArrayList<Row>();
+ while (dataSet.next()) {
+ final Row inputRow = dataSet.getRow();
+ for (SelectItem item : functionItems) {
+ final AggregateBuilder<?> aggregateBuilder = aggregateBuilders.get(item);
+ final Column column = item.getColumn();
+ if (column != null) {
+ Object value = inputRow.getValue(new SelectItem(column));
+ aggregateBuilder.add(value);
+ } else if (SelectItem.isCountAllItem(item)) {
+ // Just use the empty string, since COUNT(*) don't
+ // evaluate values (but null values should be prevented)
+ aggregateBuilder.add("");
+ } else {
+ throw new IllegalArgumentException("Expression function not supported: " + item);
+ }
+ }
+
+ // If the result should also contain non-aggregated values, we
+ // will keep those in the rows list
+ if (!onlyAggregates) {
+ final Object[] values = new Object[header.size()];
+ for (int i = 0; i < header.size(); i++) {
+ final Object value = inputRow.getValue(header.getSelectItem(i));
+ if (value != null) {
+ values[i] = value;
+ }
+ }
+ resultRows.add(new DefaultRow(header, values));
+ }
+ }
+ dataSet.close();
+
+ // Collect the aggregates
+ Map<SelectItem, Object> functionResult = new HashMap<SelectItem, Object>();
+ for (SelectItem item : functionItems) {
+ AggregateBuilder<?> aggregateBuilder = aggregateBuilders.get(item);
+ Object result = aggregateBuilder.getAggregate();
+ functionResult.put(item, result);
+ }
+
+ // if there are no result rows (no matching records at all), we still
+ // need to return a record with the aggregates
+ final boolean noResultRows = resultRows.isEmpty();
+
+ if (onlyAggregates || noResultRows) {
+ // We will only create a single row with all the aggregates
+ Object[] values = new Object[header.size()];
+ for (int i = 0; i < header.size(); i++) {
+ values[i] = functionResult.get(header.getSelectItem(i));
+ }
+ Row row = new DefaultRow(header, values);
+ resultRows.add(row);
+ } else {
+ // We will create the aggregates as well as regular values
+ for (int i = 0; i < resultRows.size(); i++) {
+ Row row = resultRows.get(i);
+ Object[] values = row.getValues();
+ for (Entry<SelectItem, Object> entry : functionResult.entrySet()) {
+ SelectItem item = entry.getKey();
+ int itemIndex = row.indexOf(item);
+ if (itemIndex != -1) {
+ Object value = entry.getValue();
+ values[itemIndex] = value;
+ }
+ }
+ resultRows.set(i, new DefaultRow(header, values));
+ }
+ }
+
+ return new InMemoryDataSet(header, resultRows);
+ }
+
+ public static List<SelectItem> getFunctionSelectItems(Iterable<SelectItem> selectItems) {
+ return CollectionUtils.filter(selectItems, new Predicate<SelectItem>() {
+ @Override
+ public Boolean eval(SelectItem arg) {
+ return arg.getFunction() != null;
+ }
+ });
+ }
+
+ public static DataSet getOrdered(DataSet dataSet, List<OrderByItem> orderByItems) {
+ return getOrdered(dataSet, orderByItems.toArray(new OrderByItem[orderByItems.size()]));
+ }
+
+ public static DataSet getOrdered(DataSet dataSet, final OrderByItem... orderByItems) {
+ if (orderByItems != null && orderByItems.length != 0) {
+ final int[] sortIndexes = new int[orderByItems.length];
+ for (int i = 0; i < orderByItems.length; i++) {
+ OrderByItem item = orderByItems[i];
+ int indexOf = dataSet.indexOf(item.getSelectItem());
+ sortIndexes[i] = indexOf;
+ }
+
+ final List<Row> data = readDataSetFull(dataSet);
+ if (data.isEmpty()) {
+ return new EmptyDataSet(dataSet.getSelectItems());
+ }
+
+ final Comparator<Object> valueComparator = ObjectComparator.getComparator();
+
+ // create a comparator for doing the actual sorting/ordering
+ final Comparator<Row> comparator = new Comparator<Row>() {
+ public int compare(Row o1, Row o2) {
+ for (int i = 0; i < sortIndexes.length; i++) {
+ int sortIndex = sortIndexes[i];
+ Object sortObj1 = o1.getValue(sortIndex);
+ Object sortObj2 = o2.getValue(sortIndex);
+ int compare = valueComparator.compare(sortObj1, sortObj2);
+ if (compare != 0) {
+ OrderByItem orderByItem = orderByItems[i];
+ boolean ascending = orderByItem.isAscending();
+ if (ascending) {
+ return compare;
+ } else {
+ return compare * -1;
+ }
+ }
+ }
+ return 0;
+ }
+ };
+
+ Collections.sort(data, comparator);
+
+ dataSet = new InMemoryDataSet(data);
+ }
+ return dataSet;
+ }
+
+ public static List<Row> readDataSetFull(DataSet dataSet) {
+ final List<Row> result;
+ if (dataSet instanceof InMemoryDataSet) {
+ // if dataset is an in memory dataset we have a shortcut to avoid
+ // creating a new list
+ result = ((InMemoryDataSet) dataSet).getRows();
+ } else {
+ result = new ArrayList<Row>();
+ while (dataSet.next()) {
+ result.add(dataSet.getRow());
+ }
+ }
+ dataSet.close();
+ return result;
+ }
+
+ /**
+ * Examines a query and extracts an array of FromItem's that refer
+ * (directly) to tables (hence Joined FromItems and SubQuery FromItems are
+ * traversed but not included).
+ *
+ * @param q
+ * the query to examine
+ * @return an array of FromItem's that refer directly to tables
+ */
+ public static FromItem[] getTableFromItems(Query q) {
+ List<FromItem> result = new ArrayList<FromItem>();
+ List<FromItem> items = q.getFromClause().getItems();
+ for (FromItem item : items) {
+ result.addAll(getTableFromItems(item));
+ }
+ return result.toArray(new FromItem[result.size()]);
+ }
+
+ public static List<FromItem> getTableFromItems(FromItem item) {
+ List<FromItem> result = new ArrayList<FromItem>();
+ if (item.getTable() != null) {
+ result.add(item);
+ } else if (item.getSubQuery() != null) {
+ FromItem[] sqItems = getTableFromItems(item.getSubQuery());
+ for (int i = 0; i < sqItems.length; i++) {
+ result.add(sqItems[i]);
+ }
+ } else if (item.getJoin() != null) {
+ FromItem leftSide = item.getLeftSide();
+ result.addAll(getTableFromItems(leftSide));
+ FromItem rightSide = item.getRightSide();
+ result.addAll(getTableFromItems(rightSide));
+ } else {
+ throw new IllegalStateException("FromItem was neither of Table type, SubQuery type or Join type: " + item);
+ }
+ return result;
+ }
+
+ /**
+ * Executes a single row query, like "SELECT COUNT(*), MAX(SOME_COLUMN) FROM
+ * MY_TABLE" or similar.
+ *
+ * @param dataContext
+ * the DataContext object to use for executing the query
+ * @param query
+ * the query to execute
+ * @return a row object representing the single row returned from the query
+ * @throws MetaModelException
+ * if less or more than one Row is returned from the query
+ */
+ public static Row executeSingleRowQuery(DataContext dataContext, Query query) throws MetaModelException {
+ DataSet dataSet = dataContext.executeQuery(query);
+ boolean next = dataSet.next();
+ if (!next) {
+ throw new MetaModelException("No rows returned from query: " + query);
+ }
+ Row row = dataSet.getRow();
+ next = dataSet.next();
+ if (next) {
+ throw new MetaModelException("More than one row returned from query: " + query);
+ }
+ dataSet.close();
+ return row;
+ }
+
+ /**
+ * Performs a left join (aka left outer join) operation on two datasets.
+ *
+ * @param ds1
+ * the left dataset
+ * @param ds2
+ * the right dataset
+ * @param onConditions
+ * the conditions to join by
+ * @return the left joined result dataset
+ */
+ public static DataSet getLeftJoin(DataSet ds1, DataSet ds2, FilterItem[] onConditions) {
+ if (ds1 == null) {
+ throw new IllegalArgumentException("Left DataSet cannot be null");
+ }
+ 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<Row> resultRows = new ArrayList<Row>();
+ List<Row> ds2data = readDataSetFull(ds2);
+ if (ds2data.isEmpty()) {
+ // no need to join, simply return a new view (with null values) on
+ // the previous dataset.
+ return getSelection(selectItems, ds1);
+ }
+
+ final DataSetHeader header = new CachingDataSetHeader(selectItems);
+
+ while (ds1.next()) {
+
+ // Construct a single-row dataset for making a carthesian product
+ // against ds2
+ Row ds1row = ds1.getRow();
+ List<Row> ds1rows = new ArrayList<Row>();
+ ds1rows.add(ds1row);
+
+ DataSet carthesianProduct = getCarthesianProduct(new DataSet[] {
+ new InMemoryDataSet(new CachingDataSetHeader(si1), ds1rows),
+ new InMemoryDataSet(new CachingDataSetHeader(si2), ds2data) }, onConditions);
+ List<Row> carthesianRows = readDataSetFull(carthesianProduct);
+ if (carthesianRows.size() > 0) {
+ resultRows.addAll(carthesianRows);
+ } else {
+ Object[] values = ds1row.getValues();
+ Object[] row = new Object[selectItems.length];
+ System.arraycopy(values, 0, row, 0, values.length);
+ resultRows.add(new DefaultRow(header, row));
+ }
+ }
+ ds1.close();
+
+ if (resultRows.isEmpty()) {
+ return new EmptyDataSet(selectItems);
+ }
+
+ return new InMemoryDataSet(header, resultRows);
+ }
+
+ /**
+ * Performs a right join (aka right outer join) operation on two datasets.
+ *
+ * @param ds1
+ * the left dataset
+ * @param ds2
+ * the right dataset
+ * @param onConditions
+ * the conditions to join by
+ * @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);
+
+ // We will reuse the left join algorithm (but switch the datasets
+ // around)
+ DataSet dataSet = getLeftJoin(ds2, ds1, onConditions);
+
+ dataSet = getSelection(leftOrderedSelects, dataSet);
+ return dataSet;
+ }
+
+ public static SelectItem[] createSelectItems(Column... columns) {
+ SelectItem[] items = new SelectItem[columns.length];
+ for (int i = 0; i < items.length; i++) {
+ items[i] = new SelectItem(columns[i]);
+ }
+ return items;
+ }
+
+ 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);
+ }
+
+ public static Table[] getTables(Column[] columns) {
+ return getTables(Arrays.asList(columns));
+ }
+
+ public static Column[] getColumnsByType(Column[] columns, final ColumnType columnType) {
+ return CollectionUtils.filter(columns, new Predicate<Column>() {
+ @Override
+ public Boolean eval(Column column) {
+ return column.getType() == columnType;
+ }
+ }).toArray(new Column[0]);
+ }
+
+ public static Column[] getColumnsBySuperType(Column[] columns, final SuperColumnType superColumnType) {
+ return CollectionUtils.filter(columns, new Predicate<Column>() {
+ @Override
+ public Boolean eval(Column column) {
+ return column.getType().getSuperType() == superColumnType;
+ }
+ }).toArray(new Column[0]);
+ }
+
+ public static Query parseQuery(DataContext dc, String queryString) {
+ final QueryParser parser = new QueryParser(dc, queryString);
+ return parser.parse();
+ }
+
+}
\ No newline at end of file
[33/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/MaxAggregateBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/MaxAggregateBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/MaxAggregateBuilder.java
deleted file mode 100644
index 93591f1..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/MaxAggregateBuilder.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * 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.query;
-
-import org.eobjects.metamodel.util.AggregateBuilder;
-import org.eobjects.metamodel.util.ObjectComparator;
-
-final class MaxAggregateBuilder implements AggregateBuilder<Object> {
-
- private Object max;
-
- @Override
- public void add(Object o) {
- if (o == null) {
- return;
- }
- if (max == null) {
- max = o;
- } else {
- Comparable<Object> comparable = ObjectComparator.getComparable(max);
- if (comparable.compareTo(o) < 0) {
- max = o;
- }
- }
- }
-
- @Override
- public Object getAggregate() {
- return max;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/MinAggregateBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/MinAggregateBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/MinAggregateBuilder.java
deleted file mode 100644
index 5321b22..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/MinAggregateBuilder.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * 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.query;
-
-import org.eobjects.metamodel.util.AggregateBuilder;
-import org.eobjects.metamodel.util.ObjectComparator;
-
-final class MinAggregateBuilder implements AggregateBuilder<Object> {
-
- private Object min;
-
- @Override
- public void add(Object o) {
- if (o == null) {
- return;
- }
- if (min == null) {
- min = o;
- } else {
- Comparable<Object> comparable = ObjectComparator.getComparable(min);
- if (comparable.compareTo(o) > 0) {
- min = o;
- }
- }
- }
-
- @Override
- public Object getAggregate() {
- return min;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/OperatorType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/OperatorType.java b/core/src/main/java/org/eobjects/metamodel/query/OperatorType.java
deleted file mode 100644
index 3f4782e..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/OperatorType.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * 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.query;
-
-/**
- * Defines the types of operators that can be used in filters.
- *
- * @see FilterItem
- */
-public enum OperatorType {
-
- EQUALS_TO("="), DIFFERENT_FROM("<>"), LIKE("LIKE"), GREATER_THAN(">"), LESS_THAN("<"), IN("IN"),
-
- /**
- * @deprecated use {@link #LESS_THAN} instead.
- */
- @Deprecated
- LOWER_THAN("<"),
-
- /**
- * @deprecated use {@link #GREATER_THAN} instead.
- */
- @Deprecated
- HIGHER_THAN(">");
-
- private final String _sql;
-
- private OperatorType(String sql) {
- _sql = sql;
- }
-
- public String toSql() {
- return _sql;
- }
-
- /**
- * Converts from SQL string literals to an OperatorType. Valid SQL values
- * are "=", "<>", "LIKE", ">" and "<".
- *
- * @param sqlType
- * @return a OperatorType object representing the specified SQL type
- */
- public static OperatorType convertOperatorType(String sqlType) {
- if (sqlType != null) {
- for (OperatorType operator : values()) {
- if (sqlType.equals(operator.toSql())) {
- return operator;
- }
- }
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/OrderByClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/OrderByClause.java b/core/src/main/java/org/eobjects/metamodel/query/OrderByClause.java
deleted file mode 100644
index 8ce04ec..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/OrderByClause.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * 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.query;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Represents the ORDER BY clause of a query containing OrderByItem's. The order
- * and direction of the OrderItems define the way that the result of a query
- * will be sorted.
- *
- * @see OrderByItem
- */
-public class OrderByClause extends AbstractQueryClause<OrderByItem> {
-
- private static final long serialVersionUID = 2441926135870143715L;
-
- public OrderByClause(Query query) {
- super(query, AbstractQueryClause.PREFIX_ORDER_BY,
- AbstractQueryClause.DELIM_COMMA);
- }
-
- public List<SelectItem> getEvaluatedSelectItems() {
- final List<SelectItem> result = new ArrayList<SelectItem>();
- final List<OrderByItem> items = getItems();
- for (OrderByItem item : items) {
- result.add(item.getSelectItem());
- }
- return result;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/OrderByItem.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/OrderByItem.java b/core/src/main/java/org/eobjects/metamodel/query/OrderByItem.java
deleted file mode 100644
index a52aa1d..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/OrderByItem.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/**
- * 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.query;
-
-import java.util.List;
-
-import org.eobjects.metamodel.util.BaseObject;
-
-/**
- * Represents an ORDER BY item. An OrderByItem sorts the resulting DataSet
- * according to a SelectItem that may or may not be a part of the query already.
- *
- * @see OrderByClause
- * @see SelectItem
- */
-public class OrderByItem extends BaseObject implements QueryItem, Cloneable {
-
- public enum Direction {
- ASC, DESC
- }
-
- private static final long serialVersionUID = -8397473619828484774L;
- private final SelectItem _selectItem;
- private Direction _direction;
- private Query _query;
-
- /**
- * Creates an OrderByItem
- *
- * @param selectItem
- * the select item to order
- * @param direction
- * the direction to order the select item
- */
- public OrderByItem(SelectItem selectItem, Direction direction) {
- if (selectItem == null) {
- throw new IllegalArgumentException("SelectItem cannot be null");
- }
- _selectItem = selectItem;
- _direction = direction;
- }
-
- /**
- * Creates an OrderByItem
- *
- * @param selectItem
- * @param ascending
- * @deprecated user OrderByItem(SelectItem, Direction) instead
- */
- @Deprecated
- public OrderByItem(SelectItem selectItem, boolean ascending) {
- if (selectItem == null) {
- throw new IllegalArgumentException("SelectItem cannot be null");
- }
- _selectItem = selectItem;
- if (ascending) {
- _direction = Direction.ASC;
- } else {
- _direction = Direction.DESC;
- }
- }
-
- /**
- * Creates an ascending OrderByItem
- *
- * @param selectItem
- */
- public OrderByItem(SelectItem selectItem) {
- this(selectItem, Direction.ASC);
- }
-
-
- @Override
- public String toSql(boolean includeSchemaInColumnPaths) {
- StringBuilder sb = new StringBuilder();
- sb.append(_selectItem.getSameQueryAlias(includeSchemaInColumnPaths) + ' ');
- sb.append(_direction);
- return sb.toString();
- }
-
- @Override
- public String toSql() {
- return toSql(false);
- }
-
- public boolean isAscending() {
- return (_direction == Direction.ASC);
- }
-
- public boolean isDescending() {
- return (_direction == Direction.DESC);
- }
-
- public Direction getDirection() {
- return _direction;
- }
-
- public OrderByItem setDirection(Direction direction) {
- _direction = direction;
- return this;
- }
-
- public SelectItem getSelectItem() {
- return _selectItem;
- }
-
- public Query getQuery() {
- return _query;
- }
-
- public OrderByItem setQuery(Query query) {
- _query = query;
- if (_selectItem != null) {
- _selectItem.setQuery(query);
- }
- return this;
- }
-
- @Override
- protected OrderByItem clone() {
- OrderByItem o = new OrderByItem(_selectItem.clone());
- o._direction = _direction;
- return o;
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- identifiers.add(_direction);
- identifiers.add(_selectItem);
- }
-
- @Override
- public String toString() {
- return toSql();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/Query.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/Query.java b/core/src/main/java/org/eobjects/metamodel/query/Query.java
deleted file mode 100644
index 0986b6b..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/Query.java
+++ /dev/null
@@ -1,603 +0,0 @@
-/**
- * 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.query;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.query.OrderByItem.Direction;
-import org.eobjects.metamodel.query.parser.QueryParserException;
-import org.eobjects.metamodel.query.parser.QueryPartCollectionProcessor;
-import org.eobjects.metamodel.query.parser.QueryPartParser;
-import org.eobjects.metamodel.query.parser.QueryPartProcessor;
-import org.eobjects.metamodel.query.parser.SelectItemParser;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.BaseObject;
-import org.eobjects.metamodel.util.BooleanComparator;
-import org.eobjects.metamodel.util.FormatHelper;
-import org.eobjects.metamodel.util.NumberComparator;
-
-/**
- * Represents a query to retrieve data by. A query is made up of six clauses,
- * equivalent to the SQL standard:
- * <ul>
- * <li>the SELECT clause, which define the wanted columns of the resulting
- * DataSet</li>
- * <li>the FROM clause, which define where to retrieve the data from</li>
- * <li>the WHERE clause, which define filters on the retrieved data</li>
- * <li>the GROUP BY clause, which define if the result should be grouped and
- * aggregated according to some columns acting as categories</li>
- * <li>the HAVING clause, which define filters on the grouped data</li>
- * <li>the ORDER BY clause, which define sorting of the resulting dataset</li>
- * </ul>
- *
- * In addition two properties are applied to queries to limit the resulting
- * dataset:
- * <ul>
- * <li>First row: The first row (aka. offset) of the result of the query.</li>
- * <li>Max rows: The maximum amount of rows to return when executing the query.</li>
- * </ul>
- *
- * Queries are executed using the DataContext.executeQuery method or can
- * alternatively be used directly in JDBC by using the toString() method.
- *
- * @see DataContext
- */
-public final class Query extends BaseObject implements Cloneable, Serializable {
-
- private static final long serialVersionUID = -5976325207498574216L;
-
- private final SelectClause _selectClause;
- private final FromClause _fromClause;
- private final FilterClause _whereClause;
- private final GroupByClause _groupByClause;
- private final FilterClause _havingClause;
- private final OrderByClause _orderByClause;
-
- private Integer _maxRows;
- private Integer _firstRow;
-
- public Query() {
- _selectClause = new SelectClause(this);
- _fromClause = new FromClause(this);
- _whereClause = new FilterClause(this, AbstractQueryClause.PREFIX_WHERE);
- _groupByClause = new GroupByClause(this);
- _havingClause = new FilterClause(this, AbstractQueryClause.PREFIX_HAVING);
- _orderByClause = new OrderByClause(this);
- }
-
- public Query select(Column column, FromItem fromItem) {
- SelectItem selectItem = new SelectItem(column, fromItem);
- return select(selectItem);
- }
-
- public Query select(Column... columns) {
- for (Column column : columns) {
- SelectItem selectItem = new SelectItem(column);
- selectItem.setQuery(this);
- _selectClause.addItem(selectItem);
- }
- return this;
- }
-
- public Query select(SelectItem... items) {
- _selectClause.addItems(items);
- return this;
- }
-
- public Query select(FunctionType functionType, Column column) {
- _selectClause.addItem(new SelectItem(functionType, column));
- return this;
- }
-
- public Query select(String expression, String alias) {
- return select(new SelectItem(expression, alias));
- }
-
- /**
- * Adds a selection to this query.
- *
- * @param expression
- * @return
- */
- public Query select(String expression) {
- if ("*".equals(expression)) {
- return selectAll();
- }
-
- SelectItem selectItem = findSelectItem(expression, true);
- return select(selectItem);
- }
-
- private SelectItem findSelectItem(String expression, boolean allowExpressionBasedSelectItem) {
- SelectItemParser parser = new SelectItemParser(this, allowExpressionBasedSelectItem);
- return parser.findSelectItem(expression);
- }
-
- /**
- * Select all available select items from all currently available FROM
- * items. Equivalent of the expression "SELECT * FROM ..." in SQL.
- *
- * @return
- */
- public Query selectAll() {
- List<FromItem> items = getFromClause().getItems();
- for (FromItem fromItem : items) {
- selectAll(fromItem);
- }
- return this;
- }
-
- public Query selectAll(final FromItem fromItem) {
- if (fromItem.getTable() != null) {
- final Column[] columns = fromItem.getTable().getColumns();
- for (final Column column : columns) {
- select(column, fromItem);
- }
- } else if (fromItem.getJoin() != null) {
- selectAll(fromItem.getLeftSide());
- selectAll(fromItem.getRightSide());
- } else if (fromItem.getSubQuery() != null) {
- final List<SelectItem> items = fromItem.getSubQuery().getSelectClause().getItems();
- for (final SelectItem subQuerySelectItem : items) {
- select(new SelectItem(subQuerySelectItem, fromItem));
- }
- } else {
- throw new MetaModelException("All select items ('*') not determinable with from item: " + fromItem);
- }
- return this;
- }
-
- public Query selectDistinct() {
- _selectClause.setDistinct(true);
- return this;
- }
-
- public Query selectCount() {
- return select(SelectItem.getCountAllItem());
- }
-
- public Query from(FromItem... items) {
- _fromClause.addItems(items);
- return this;
- }
-
- public Query from(Table table) {
- return from(new FromItem(table));
- }
-
- public Query from(String expression) {
- return from(new FromItem(expression));
- }
-
- public Query from(Table table, String alias) {
- return from(new FromItem(table).setAlias(alias));
- }
-
- public Query from(Table leftTable, Table rightTable, JoinType joinType, Column leftOnColumn, Column rightOnColumn) {
- SelectItem[] leftOn = new SelectItem[] { new SelectItem(leftOnColumn) };
- SelectItem[] rightOn = new SelectItem[] { new SelectItem(rightOnColumn) };
- FromItem fromItem = new FromItem(joinType, new FromItem(leftTable), new FromItem(rightTable), leftOn, rightOn);
- return from(fromItem);
- }
-
- public Query groupBy(String... groupByTokens) {
- for (String groupByToken : groupByTokens) {
- SelectItem selectItem = findSelectItem(groupByToken, true);
- groupBy(new GroupByItem(selectItem));
- }
- return this;
- }
-
- public Query groupBy(GroupByItem... items) {
- for (GroupByItem item : items) {
- SelectItem selectItem = item.getSelectItem();
- if (selectItem != null && selectItem.getQuery() == null) {
- selectItem.setQuery(this);
- }
- }
- _groupByClause.addItems(items);
- return this;
- }
-
- public Query groupBy(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;
- }
-
- public Query orderBy(String... orderByTokens) {
- for (String orderByToken : orderByTokens) {
- orderByToken = orderByToken.trim();
- final Direction direction;
- if (orderByToken.toUpperCase().endsWith("DESC")) {
- direction = Direction.DESC;
- orderByToken = orderByToken.substring(0, orderByToken.length() - 4).trim();
- } else if (orderByToken.toUpperCase().endsWith("ASC")) {
- direction = Direction.ASC;
- orderByToken = orderByToken.substring(0, orderByToken.length() - 3).trim();
- } else {
- direction = Direction.ASC;
- }
-
- OrderByItem orderByItem = new OrderByItem(findSelectItem(orderByToken, true), direction);
- orderBy(orderByItem);
- }
- return this;
- }
-
- public Query orderBy(Column column) {
- return orderBy(column, Direction.ASC);
- }
-
- /**
- * @deprecated use orderBy(Column, Direction) instead
- */
- @Deprecated
- public Query orderBy(Column column, boolean ascending) {
- if (ascending) {
- return orderBy(column, Direction.ASC);
- } else {
- return orderBy(column, Direction.DESC);
- }
- }
-
- public Query orderBy(Column column, Direction direction) {
- SelectItem selectItem = _selectClause.getSelectItem(column);
- if (selectItem == null) {
- selectItem = new SelectItem(column);
- }
- return orderBy(new OrderByItem(selectItem, direction));
- }
-
- public Query where(FilterItem... items) {
- _whereClause.addItems(items);
- return this;
- }
-
- public Query where(Iterable<FilterItem> items) {
- _whereClause.addItems(items);
- return this;
- }
-
- public Query where(String... whereItemTokens) {
- for (String whereItemToken : whereItemTokens) {
- FilterItem filterItem = findFilterItem(whereItemToken);
- where(filterItem);
- }
- return this;
- }
-
- private FilterItem findFilterItem(String expression) {
- final QueryPartCollectionProcessor collectionProcessor = new QueryPartCollectionProcessor();
- new QueryPartParser(collectionProcessor, expression, " AND ", " OR ").parse();
-
- final List<String> tokens = collectionProcessor.getTokens();
- final List<String> delims = collectionProcessor.getDelims();
- if (tokens.size() == 1) {
- expression = tokens.get(0);
- } else {
- final LogicalOperator logicalOperator = LogicalOperator.valueOf(delims.get(1).trim());
-
- final List<FilterItem> filterItems = new ArrayList<FilterItem>();
- for (int i = 0; i < tokens.size(); i++) {
- String token = tokens.get(i);
- FilterItem filterItem = findFilterItem(token);
- filterItems.add(filterItem);
- }
- return new FilterItem(logicalOperator, filterItems);
- }
-
- OperatorType operator = null;
- String leftSide = null;
- final String rightSide;
- {
- String rightSideCandidate = null;
- final OperatorType[] operators = OperatorType.values();
- for (OperatorType operatorCandidate : operators) {
- final int operatorIndex = expression.indexOf(' ' + operatorCandidate.toSql() + ' ');
- if (operatorIndex > 0) {
- operator = operatorCandidate;
- leftSide = expression.substring(0, operatorIndex).trim();
- rightSideCandidate = expression.substring(operatorIndex + operator.toSql().length() + 2).trim();
- break;
- }
- }
-
- if (operator == null) {
- // check special cases for IS NULL and IS NOT NULL
- if (expression.endsWith(" IS NOT NULL")) {
- operator = OperatorType.DIFFERENT_FROM;
- leftSide = expression.substring(0, expression.lastIndexOf(" IS NOT NULL")).trim();
- rightSideCandidate = "NULL";
- } else if (expression.endsWith(" IS NULL")) {
- operator = OperatorType.EQUALS_TO;
- leftSide = expression.substring(0, expression.lastIndexOf(" IS NULL")).trim();
- rightSideCandidate = "NULL";
- }
- }
-
- rightSide = rightSideCandidate;
- }
-
- if (operator == null) {
- return new FilterItem(expression);
- }
-
- final SelectItem selectItem = findSelectItem(leftSide, false);
- if (selectItem == null) {
- return new FilterItem(expression);
- }
-
- final Object operand;
- if (operator == OperatorType.IN) {
- final List<Object> list = new ArrayList<Object>();
- new QueryPartParser(new QueryPartProcessor() {
- @Override
- public void parse(String delim, String itemToken) {
- Object operand = createOperand(itemToken, selectItem, false);
- list.add(operand);
- }
- }, rightSide, ",").parse();
- operand = list;
- } else {
- operand = createOperand(rightSide, selectItem, true);
- }
-
- return new FilterItem(selectItem, operator, operand);
- }
-
- private Object createOperand(final String token, final SelectItem leftSelectItem, final boolean searchSelectItems) {
- if (token.equalsIgnoreCase("NULL")) {
- return null;
- }
-
- if (token.startsWith("'") && token.endsWith("'") && token.length() > 2) {
- String stringOperand = token.substring(1, token.length() - 1);
- stringOperand = stringOperand.replaceAll("\\\\'", "'");
- return stringOperand;
- }
-
- if (searchSelectItems) {
- final SelectItem selectItem = findSelectItem(token, false);
- if (selectItem != null) {
- return selectItem;
- }
- }
-
- final ColumnType expectedColumnType = leftSelectItem.getExpectedColumnType();
- final Object result;
- if (expectedColumnType == null) {
- // We're assuming number here, but it could also be boolean or a
- // time based type. But anyways, this should not happen since
- // expected column type should be available.
- result = NumberComparator.toNumber(token);
- } else if (expectedColumnType.isBoolean()) {
- result = BooleanComparator.toBoolean(token);
- } else if (expectedColumnType.isTimeBased()) {
- result = FormatHelper.parseSqlTime(expectedColumnType, token);
- } else {
- result = NumberComparator.toNumber(token);
- }
-
- if (result == null) {
- // shouldn't happen since only "NULL" is parsed as null.
- throw new QueryParserException("Could not parse operand: " + token);
- }
-
- return result;
- }
-
- public Query where(SelectItem selectItem, OperatorType operatorType, Object operand) {
- return where(new FilterItem(selectItem, operatorType, operand));
- }
-
- public Query where(Column column, OperatorType operatorType, Object operand) {
- SelectItem selectItem = _selectClause.getSelectItem(column);
- if (selectItem == null) {
- selectItem = new SelectItem(column);
- }
- return where(selectItem, operatorType, operand);
- }
-
- public Query having(FilterItem... items) {
- _havingClause.addItems(items);
- return this;
- }
-
- public Query having(FunctionType function, Column column, OperatorType operatorType, Object operand) {
- SelectItem selectItem = new SelectItem(function, column);
- return having(new FilterItem(selectItem, operatorType, operand));
- }
-
- public Query having(Column column, OperatorType operatorType, Object operand) {
- SelectItem selectItem = _selectClause.getSelectItem(column);
- if (selectItem == null) {
- selectItem = new SelectItem(column);
- }
- return having(new FilterItem(selectItem, operatorType, operand));
- }
-
- public Query having(String... havingItemTokens) {
- for (String havingItemToken : havingItemTokens) {
- FilterItem filterItem = findFilterItem(havingItemToken);
- having(filterItem);
- }
- return this;
- }
-
- @Override
- public String toString() {
- return toSql();
- }
-
- /*
- * A string representation of this query. This representation will be SQL 99
- * compatible and can thus be used for database queries on databases that
- * meet SQL standards.
- */
- public String toSql() {
- return toSql(false);
- }
-
- protected String toSql(boolean includeSchemaInColumnPaths) {
- final StringBuilder sb = new StringBuilder();
- sb.append(_selectClause.toSql(includeSchemaInColumnPaths));
- sb.append(_fromClause.toSql(includeSchemaInColumnPaths));
- sb.append(_whereClause.toSql(includeSchemaInColumnPaths));
- sb.append(_groupByClause.toSql(includeSchemaInColumnPaths));
- sb.append(_havingClause.toSql(includeSchemaInColumnPaths));
- sb.append(_orderByClause.toSql(includeSchemaInColumnPaths));
- return sb.toString();
- }
-
- public SelectClause getSelectClause() {
- return _selectClause;
- }
-
- public FromClause getFromClause() {
- return _fromClause;
- }
-
- public FilterClause getWhereClause() {
- return _whereClause;
- }
-
- public GroupByClause getGroupByClause() {
- return _groupByClause;
- }
-
- public FilterClause getHavingClause() {
- return _havingClause;
- }
-
- public OrderByClause getOrderByClause() {
- return _orderByClause;
- }
-
- /**
- * Sets the maximum number of rows to be queried. If the result of the query
- * yields more rows they should be discarded.
- *
- * @param maxRows
- * the number of desired maximum rows. Can be null (default) for
- * no limits
- * @return this query
- */
- public Query setMaxRows(Integer maxRows) {
- if (maxRows != null) {
- final int maxRowsValue = maxRows.intValue();
- if (maxRowsValue == 0) {
- throw new IllegalArgumentException("Max rows cannot be zero");
- }
- if (maxRowsValue < 0) {
- throw new IllegalArgumentException("Max rows cannot be negative");
- }
- }
- _maxRows = maxRows;
- return this;
- }
-
- /**
- * @return the number of maximum rows to yield from executing this query or
- * null if no maximum/limit is set.
- */
- public Integer getMaxRows() {
- return _maxRows;
- }
-
- /**
- * Sets the first row (aka offset) of the query's result. The row number is
- * 1-based, so setting a first row value of 1 is equivalent to not setting
- * it at all..
- *
- * @param firstRow
- * the first row, where 1 is the first row.
- * @return this query
- */
- public Query setFirstRow(Integer firstRow) {
- if (firstRow != null && firstRow.intValue() < 1) {
- throw new IllegalArgumentException("First row cannot be negative or zero");
- }
- _firstRow = firstRow;
- return this;
- }
-
- /**
- * Gets the first row (aka offset) of the query's result, or null if none is
- * specified. The row number is 1-based, so setting a first row value of 1
- * is equivalent to not setting it at all..
- *
- * @return the first row (aka offset) of the query's result, or null if no
- * offset is specified.
- */
- public Integer getFirstRow() {
- return _firstRow;
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- identifiers.add(_maxRows);
- identifiers.add(_selectClause);
- identifiers.add(_fromClause);
- identifiers.add(_whereClause);
- identifiers.add(_groupByClause);
- identifiers.add(_havingClause);
- identifiers.add(_orderByClause);
- }
-
- @Override
- public Query clone() {
- Query q = new Query();
- q.setMaxRows(_maxRows);
- q.setFirstRow(_firstRow);
- q.getSelectClause().setDistinct(_selectClause.isDistinct());
- for (FromItem item : _fromClause.getItems()) {
- q.from(item.clone());
- }
- for (SelectItem item : _selectClause.getItems()) {
- q.select(item.clone());
- }
- for (FilterItem item : _whereClause.getItems()) {
- q.where(item.clone());
- }
- for (GroupByItem item : _groupByClause.getItems()) {
- q.groupBy(item.clone());
- }
- for (FilterItem item : _havingClause.getItems()) {
- q.having(item.clone());
- }
- for (OrderByItem item : _orderByClause.getItems()) {
- q.orderBy(item.clone());
- }
- return q;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/QueryClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/QueryClause.java b/core/src/main/java/org/eobjects/metamodel/query/QueryClause.java
deleted file mode 100644
index e3dddc8..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/QueryClause.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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.query;
-
-import java.io.Serializable;
-import java.util.List;
-
-public interface QueryClause<E> extends Serializable {
-
- public QueryClause<E> setItems(E... items);
-
- public QueryClause<E> addItems(E... items);
-
- public QueryClause<E> addItems(Iterable<E> items);
-
- public QueryClause<E> addItem(int index, E item);
-
- public QueryClause<E> addItem(E item);
-
- public boolean isEmpty();
-
- public int getItemCount();
-
- public E getItem(int index);
-
- public List<E> getItems();
-
- public QueryClause<E> removeItem(int index);
-
- public QueryClause<E> removeItem(E item);
-
- public QueryClause<E> removeItems();
-
- public String toSql(boolean includeSchemaInColumnPaths);
-
- public String toSql();
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/QueryItem.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/QueryItem.java b/core/src/main/java/org/eobjects/metamodel/query/QueryItem.java
deleted file mode 100644
index ab79959..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/QueryItem.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.query;
-
-import java.io.Serializable;
-
-/**
- * Interface for items in a query. All QueryItems reside within a QueryClause.
- *
- * @see AbstractQueryClause
- */
-public interface QueryItem extends Serializable {
-
- public QueryItem setQuery(Query query);
-
- public Query getQuery();
-
- public String toSql();
-
- public String toSql(boolean includeSchemaInColumnPaths);
-
- public String toString();
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/QueryParameter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/QueryParameter.java b/core/src/main/java/org/eobjects/metamodel/query/QueryParameter.java
deleted file mode 100644
index cbbc64e..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/QueryParameter.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * 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.query;
-
-import org.eobjects.metamodel.DataContext;
-
-/**
- * Represents a query parameter, in SQL represented with a '?' symbol.
- * Parameters are values in the query that will be defined at execution time,
- * not parsing/preparation time.
- *
- * @see CompiledQuery
- * @see DataContext#compileQuery(Query)
- */
-public class QueryParameter {
-
- @Override
- public String toString() {
- return "?";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/SelectClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/SelectClause.java b/core/src/main/java/org/eobjects/metamodel/query/SelectClause.java
deleted file mode 100644
index 82688a5..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/SelectClause.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * 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.query;
-
-import java.util.List;
-
-import org.eobjects.metamodel.schema.Column;
-
-/**
- * Represents the SELECT clause of a query containing SelectItems.
- *
- * @see SelectItem
- */
-public class SelectClause extends AbstractQueryClause<SelectItem> {
-
- private static final long serialVersionUID = -2458447191169901181L;
- private boolean _distinct = false;
-
- public SelectClause(Query query) {
- super(query, AbstractQueryClause.PREFIX_SELECT, AbstractQueryClause.DELIM_COMMA);
- }
-
- public SelectItem getSelectItem(Column column) {
- if (column != null) {
- for (SelectItem item : getItems()) {
- if (column.equals(item.getColumn())) {
- return item;
- }
- }
- }
- return null;
- }
-
- @Override
- public String toSql(boolean includeSchemaInColumnPaths) {
- if (getItems().size() == 0) {
- return "";
- }
-
- final String sql = super.toSql(includeSchemaInColumnPaths);
- StringBuilder sb = new StringBuilder(sql);
- if (_distinct) {
- sb.insert(AbstractQueryClause.PREFIX_SELECT.length(), "DISTINCT ");
- }
- return sb.toString();
- }
-
- public boolean isDistinct() {
- return _distinct;
- }
-
- public void setDistinct(boolean distinct) {
- _distinct = distinct;
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- super.decorateIdentity(identifiers);
- identifiers.add(_distinct);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/SelectItem.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/SelectItem.java b/core/src/main/java/org/eobjects/metamodel/query/SelectItem.java
deleted file mode 100644
index a9b1707..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/SelectItem.java
+++ /dev/null
@@ -1,517 +0,0 @@
-/**
- * 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.query;
-
-import java.util.List;
-
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.BaseObject;
-import org.eobjects.metamodel.util.EqualsBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Represents a SELECT item. SelectItems can take different forms:
- * <ul>
- * <li>column SELECTs (selects a column from a table)</li>
- * <li>column function SELECTs (aggregates the values of a column)</li>
- * <li>expression SELECTs (retrieves data based on an expression (only supported
- * for JDBC datastores)</li>
- * <li>expression function SELECTs (retrieves databased on a function and an
- * expression, only COUNT(*) is supported for non-JDBC datastores))</li>
- * <li>SELECTs from subqueries (works just like column selects, but in stead of
- * pointing to a column, it retrieves data from the select item of a subquery)</li>
- * </ul>
- *
- * @see SelectClause
- */
-public class SelectItem extends BaseObject implements QueryItem, Cloneable {
-
- private static final long serialVersionUID = 317475105509663973L;
- private static final Logger logger = LoggerFactory.getLogger(SelectItem.class);
-
- // immutable fields (essense)
- private final Column _column;
- private final FunctionType _function;
- private final String _expression;
- private final SelectItem _subQuerySelectItem;
- private final FromItem _fromItem;
-
- // mutable fields (tweaking)
- private boolean _functionApproximationAllowed;
- private Query _query;
- private String _alias;
-
- /**
- * All-arguments constructor
- *
- * @param column
- * @param fromItem
- * @param function
- * @param expression
- * @param subQuerySelectItem
- * @param alias
- * @param functionApproximationAllowed
- */
- private SelectItem(Column column, FromItem fromItem, FunctionType function, String expression,
- SelectItem subQuerySelectItem, String alias, boolean functionApproximationAllowed) {
- super();
- _column = column;
- _fromItem = fromItem;
- _function = function;
- _expression = expression;
- _subQuerySelectItem = subQuerySelectItem;
- _alias = alias;
- _functionApproximationAllowed = functionApproximationAllowed;
- }
-
- /**
- * Generates a COUNT(*) select item
- */
- public static SelectItem getCountAllItem() {
- return new SelectItem(FunctionType.COUNT, "*", null);
- }
-
- public static boolean isCountAllItem(SelectItem item) {
- if (item != null && item.getFunction() == FunctionType.COUNT && item.getExpression() == "*") {
- return true;
- }
- return false;
- }
-
- /**
- * Creates a simple SelectItem that selects from a column
- *
- * @param column
- */
- public SelectItem(Column column) {
- this(null, column);
- }
-
- /**
- * Creates a SelectItem that uses a function on a column, for example
- * SUM(price) or MAX(age)
- *
- * @param function
- * @param column
- */
- public SelectItem(FunctionType function, Column column) {
- this(function, column, null);
- }
-
- /**
- * Creates a SelectItem that references a column from a particular
- * {@link FromItem}, for example a.price or p.age
- *
- * @param column
- * @param fromItem
- */
- public SelectItem(Column column, FromItem fromItem) {
- this(null, column, fromItem);
- if (fromItem != null) {
- Table fromItemTable = fromItem.getTable();
- if (fromItemTable != null) {
- Table columnTable = column.getTable();
- if (columnTable != null && !columnTable.equals(fromItemTable)) {
- throw new IllegalArgumentException("Column's table '" + columnTable.getName()
- + "' is not equal to referenced table: " + fromItemTable);
- }
- }
- }
- }
-
- /**
- * Creates a SelectItem that uses a function on a column from a particular
- * {@link FromItem}, for example SUM(a.price) or MAX(p.age)
- *
- * @param function
- * @param column
- * @param fromItem
- */
- public SelectItem(FunctionType function, Column column, FromItem fromItem) {
- this(column, fromItem, function, null, null, null, false);
- if (column == null) {
- throw new IllegalArgumentException("column=null");
- }
- }
-
- /**
- * Creates a SelectItem based on an expression. All expression-based
- * SelectItems must have aliases.
- *
- * @param expression
- * @param alias
- */
- public SelectItem(String expression, String alias) {
- this(null, expression, alias);
- }
-
- /**
- * Creates a SelectItem based on a function and an expression. All
- * expression-based SelectItems must have aliases.
- *
- * @param function
- * @param expression
- * @param alias
- */
- public SelectItem(FunctionType function, String expression, String alias) {
- this(null, null, function, expression, null, alias, false);
- if (expression == null) {
- throw new IllegalArgumentException("expression=null");
- }
- }
-
- /**
- * Creates a SelectItem that references another select item in a subquery
- *
- * @param subQuerySelectItem
- * @param subQueryFromItem
- * the FromItem that holds the sub-query
- */
- public SelectItem(SelectItem subQuerySelectItem, FromItem subQueryFromItem) {
- this(null, subQueryFromItem, null, null, subQuerySelectItem, null, false);
- if (subQueryFromItem.getSubQuery() == null) {
- throw new IllegalArgumentException("Only sub-query based FromItems allowed.");
- }
- if (subQuerySelectItem.getQuery() != null
- && !subQuerySelectItem.getQuery().equals(subQueryFromItem.getSubQuery())) {
- throw new IllegalArgumentException("The SelectItem must exist in the sub-query");
- }
- }
-
- public String getAlias() {
- return _alias;
- }
-
- public SelectItem setAlias(String alias) {
- _alias = alias;
- return this;
- }
-
- public FunctionType getFunction() {
- return _function;
- }
-
- /**
- * @return if this is a function based SelectItem where function calculation
- * is allowed to be approximated (if the datastore type has an
- * approximate calculation method). Approximated function results
- * are as the name implies not exact, but might be valuable as an
- * optimization in some cases.
- */
- public boolean isFunctionApproximationAllowed() {
- return _functionApproximationAllowed;
- }
-
- public void setFunctionApproximationAllowed(boolean functionApproximationAllowed) {
- _functionApproximationAllowed = functionApproximationAllowed;
- }
-
- public Column getColumn() {
- return _column;
- }
-
- /**
- * Tries to infer the {@link ColumnType} of this {@link SelectItem}. For
- * expression based select items, this is not possible, and the method will
- * return null.
- *
- * @return
- */
- public ColumnType getExpectedColumnType() {
- if (_subQuerySelectItem != null) {
- return _subQuerySelectItem.getExpectedColumnType();
- }
- if (_function != null) {
- if (_column != null) {
- return _function.getExpectedColumnType(_column.getType());
- } else {
- return _function.getExpectedColumnType(null);
- }
- }
- if (_column != null) {
- return _column.getType();
- }
- return null;
- }
-
- public String getExpression() {
- return _expression;
- }
-
- public SelectItem setQuery(Query query) {
- _query = query;
- return this;
- }
-
- public Query getQuery() {
- return _query;
- }
-
- public SelectItem getSubQuerySelectItem() {
- return _subQuerySelectItem;
- }
-
- /**
- * @deprecated use {@link #getFromItem()} instead
- */
- @Deprecated
- public FromItem getSubQueryFromItem() {
- return _fromItem;
- }
-
- public FromItem getFromItem() {
- return _fromItem;
- }
-
- /**
- * @return the name that this SelectItem can be referenced with, if
- * referenced from a super-query. This will usually be the alias,
- * but if there is no alias, then the column name will be used.
- */
- public String getSuperQueryAlias() {
- return getSuperQueryAlias(true);
- }
-
- /**
- * @return the name that this SelectItem can be referenced with, if
- * referenced from a super-query. This will usually be the alias,
- * but if there is no alias, then the column name will be used.
- *
- * @param includeQuotes
- * indicates whether or not the output should include quotes, if
- * the select item's column has quotes associated (typically
- * true, but false if used for presentation)
- */
- public String getSuperQueryAlias(boolean includeQuotes) {
- if (_alias != null) {
- return _alias;
- } else if (_column != null) {
- final StringBuilder sb = new StringBuilder();
- if (_function != null) {
- sb.append(_function.toString());
- sb.append('(');
- }
- if (includeQuotes) {
- sb.append(_column.getQuotedName());
- } else {
- sb.append(_column.getName());
- }
- if (_function != null) {
- sb.append(')');
- }
- return sb.toString();
- } else {
- logger.debug("Could not resolve a reasonable super-query alias for SelectItem: {}", toSql());
- return toStringNoAlias().toString();
- }
- }
-
- public String getSameQueryAlias() {
- return getSameQueryAlias(false);
- }
-
- /**
- * @return an alias that can be used in WHERE, GROUP BY and ORDER BY clauses
- * in the same query
- */
- public String getSameQueryAlias(boolean includeSchemaInColumnPath) {
- if (_column != null) {
- StringBuilder sb = new StringBuilder();
- String columnPrefix = getToStringColumnPrefix(includeSchemaInColumnPath);
- sb.append(columnPrefix);
- sb.append(_column.getQuotedName());
- if (_function != null) {
- sb.insert(0, _function + "(");
- sb.append(")");
- }
- return sb.toString();
- }
- String alias = getAlias();
- if (alias == null) {
- alias = toStringNoAlias(includeSchemaInColumnPath).toString();
- logger.debug("Could not resolve a reasonable same-query alias for SelectItem: {}", toSql());
- }
- return alias;
- }
-
- @Override
- public String toSql() {
- return toSql(false);
- }
-
- @Override
- public String toSql(boolean includeSchemaInColumnPath) {
- StringBuilder sb = toStringNoAlias(includeSchemaInColumnPath);
- if (_alias != null) {
- sb.append(" AS ");
- sb.append(_alias);
- }
- return sb.toString();
- }
-
- public StringBuilder toStringNoAlias() {
- return toStringNoAlias(false);
- }
-
- public StringBuilder toStringNoAlias(boolean includeSchemaInColumnPath) {
- StringBuilder sb = new StringBuilder();
- if (_column != null) {
- sb.append(getToStringColumnPrefix(includeSchemaInColumnPath));
- sb.append(_column.getQuotedName());
- }
- if (_expression != null) {
- sb.append(_expression);
- }
- if (_fromItem != null && _subQuerySelectItem != null) {
- if (_fromItem.getAlias() != null) {
- sb.append(_fromItem.getAlias() + '.');
- }
- sb.append(_subQuerySelectItem.getSuperQueryAlias());
- }
- if (_function != null) {
- sb.insert(0, _function + "(");
- sb.append(")");
- }
- return sb;
- }
-
- private String getToStringColumnPrefix(boolean includeSchemaInColumnPath) {
- StringBuilder sb = new StringBuilder();
- if (_fromItem != null && _fromItem.getAlias() != null) {
- sb.append(_fromItem.getAlias());
- sb.append('.');
- } else {
- final Table table = _column.getTable();
- String tableLabel;
- if (_query == null) {
- tableLabel = null;
- } else {
- tableLabel = _query.getFromClause().getAlias(table);
- }
- if (table != null) {
- if (tableLabel == null) {
- tableLabel = table.getQuotedName();
- if (includeSchemaInColumnPath) {
- Schema schema = table.getSchema();
- if (schema != null) {
- tableLabel = schema.getQuotedName() + "." + tableLabel;
- }
- }
- }
- sb.append(tableLabel);
- sb.append('.');
- }
- }
- return sb.toString();
- }
-
- public boolean equalsIgnoreAlias(SelectItem that) {
- return equalsIgnoreAlias(that, false);
- }
-
- public boolean equalsIgnoreAlias(SelectItem that, boolean exactColumnCompare) {
- if (that == null) {
- return false;
- }
- if (that == this) {
- return true;
- }
-
- EqualsBuilder eb = new EqualsBuilder();
- if (exactColumnCompare) {
- eb.append(this._column == that._column);
- eb.append(this._fromItem, that._fromItem);
- } else {
- eb.append(this._column, that._column);
- }
- eb.append(this._function, that._function);
- eb.append(this._functionApproximationAllowed, that._functionApproximationAllowed);
- eb.append(this._expression, that._expression);
- if (_subQuerySelectItem != null) {
- eb.append(_subQuerySelectItem.equalsIgnoreAlias(that._subQuerySelectItem));
- } else {
- if (that._subQuerySelectItem != null) {
- eb.append(false);
- }
- }
- return eb.isEquals();
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- identifiers.add(_expression);
- identifiers.add(_alias);
- identifiers.add(_column);
- identifiers.add(_function);
- identifiers.add(_functionApproximationAllowed);
- identifiers.add(_fromItem);
- identifiers.add(_subQuerySelectItem);
- }
-
- @Override
- protected SelectItem clone() {
- final SelectItem subQuerySelectItem = (_subQuerySelectItem == null ? null : _subQuerySelectItem.clone());
- final FromItem fromItem = (_fromItem == null ? null : _fromItem.clone());
- final SelectItem s = new SelectItem(_column, fromItem, _function, _expression, subQuerySelectItem, _alias,
- _functionApproximationAllowed);
- return s;
- }
-
- /**
- * Creates a copy of the {@link SelectItem}, with a different
- * {@link FunctionType}.
- *
- * @param function
- * @return
- */
- public SelectItem replaceFunction(FunctionType function) {
- return new SelectItem(_column, _fromItem, function, _expression, _subQuerySelectItem, _alias,
- _functionApproximationAllowed);
- }
-
- /**
- * Investigates whether or not this SelectItem references a particular
- * column. This will search for direct references and indirect references
- * via subqueries.
- *
- * @param column
- * @return a boolean that is true if the specified column is referenced by
- * this SelectItem and false otherwise.
- */
- public boolean isReferenced(Column column) {
- if (column != null) {
- if (column.equals(_column)) {
- return true;
- }
- if (_subQuerySelectItem != null) {
- return _subQuerySelectItem.isReferenced(column);
- }
- }
- return false;
- }
-
- @Override
- public String toString() {
- return toSql();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/SumAggregateBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/SumAggregateBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/SumAggregateBuilder.java
deleted file mode 100644
index 2cf8811..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/SumAggregateBuilder.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * 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.query;
-
-import org.eobjects.metamodel.util.AggregateBuilder;
-import org.eobjects.metamodel.util.NumberComparator;
-
-final class SumAggregateBuilder implements AggregateBuilder<Double> {
-
- private double sum;
-
- @Override
- public void add(Object o) {
- if (o == null) {
- return;
- }
- Number number = NumberComparator.toNumber(o);
- if (number == null) {
- throw new IllegalArgumentException("Could not convert to number: " + o);
- }
- sum += number.doubleValue();
- }
-
- @Override
- public Double getAggregate() {
- return sum;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/AbstractFilterBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/AbstractFilterBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/builder/AbstractFilterBuilder.java
deleted file mode 100644
index 2d3bd25..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/AbstractFilterBuilder.java
+++ /dev/null
@@ -1,459 +0,0 @@
-/**
- * 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.query.builder;
-
-import java.util.Collection;
-import java.util.Date;
-
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-
-/**
- * Abstract implementation of {@link FilterBuilder} interface. All built filters
- * are channeled to the {@link #applyFilter(FilterItem)} method which needs to
- * be implemented by concrete implementations.
- */
-public abstract class AbstractFilterBuilder<B> implements FilterBuilder<B> {
-
- private final SelectItem _selectItem;
-
- public AbstractFilterBuilder(SelectItem selectItem) {
- this._selectItem = selectItem;
- }
-
- protected abstract B applyFilter(FilterItem filter);
-
- /**
- * Provides a way to
- *
- * @param queryParameter
- * @return
- */
- public B applyFilter(OperatorType operator, Object operand) {
- return applyFilter(new FilterItem(_selectItem, operator, operand));
- }
-
- @Override
- public B in(Collection<?> values) {
- return applyFilter(new FilterItem(_selectItem, OperatorType.IN, values));
- }
-
- @Override
- public B in(Number... numbers) {
- return applyFilter(new FilterItem(_selectItem, OperatorType.IN, numbers));
- }
-
- @Override
- public B in(String... strings) {
- return applyFilter(new FilterItem(_selectItem, OperatorType.IN, strings));
- }
-
- @Override
- public B isNull() {
- return applyFilter(new FilterItem(_selectItem, OperatorType.EQUALS_TO, null));
- }
-
- @Override
- public B isNotNull() {
- return applyFilter(new FilterItem(_selectItem, OperatorType.DIFFERENT_FROM, null));
- }
-
- @Override
- public B isEquals(Column column) {
- if (column == null) {
- throw new IllegalArgumentException("column cannot be null");
- }
- return applyFilter(new FilterItem(_selectItem, OperatorType.EQUALS_TO, new SelectItem(column)));
- }
-
- @Override
- public B isEquals(Date date) {
- if (date == null) {
- throw new IllegalArgumentException("date cannot be null");
- }
- return applyFilter(new FilterItem(_selectItem, OperatorType.EQUALS_TO, date));
- }
-
- @Override
- public B isEquals(Number number) {
- if (number == null) {
- throw new IllegalArgumentException("number cannot be null");
- }
- return applyFilter(new FilterItem(_selectItem, OperatorType.EQUALS_TO, number));
- }
-
- @Override
- public B isEquals(String string) {
- if (string == null) {
- throw new IllegalArgumentException("string cannot be null");
- }
- return applyFilter(new FilterItem(_selectItem, OperatorType.EQUALS_TO, string));
- }
-
- @Override
- public B isEquals(Boolean bool) {
- if (bool == null) {
- throw new IllegalArgumentException("bool cannot be null");
- }
- return applyFilter(new FilterItem(_selectItem, OperatorType.EQUALS_TO, bool));
- }
-
- @Override
- public B isEquals(Object obj) {
- if (obj == null) {
- return isNull();
- }
- if (obj instanceof Boolean) {
- return isEquals((Boolean) obj);
- }
- if (obj instanceof Number) {
- return isEquals((Number) obj);
- }
- if (obj instanceof Date) {
- return isEquals((Date) obj);
- }
- if (obj instanceof String) {
- return isEquals((String) obj);
- }
- throw new UnsupportedOperationException("Argument must be a Boolean, Number, Date or String. Found: " + obj);
- }
-
- @Override
- public B differentFrom(Column column) {
- if (column == null) {
- throw new IllegalArgumentException("column cannot be null");
- }
- return applyFilter(new FilterItem(_selectItem, OperatorType.DIFFERENT_FROM, new SelectItem(column)));
- }
-
- @Override
- public B differentFrom(Date date) {
- if (date == null) {
- throw new IllegalArgumentException("date cannot be null");
- }
- return applyFilter(new FilterItem(_selectItem, OperatorType.DIFFERENT_FROM, date));
- }
-
- @Override
- public B differentFrom(Number number) {
- if (number == null) {
- throw new IllegalArgumentException("number cannot be null");
- }
- return applyFilter(new FilterItem(_selectItem, OperatorType.DIFFERENT_FROM, number));
- }
-
- @Override
- public B differentFrom(String string) {
- if (string == null) {
- throw new IllegalArgumentException("string cannot be null");
- }
- return applyFilter(new FilterItem(_selectItem, OperatorType.DIFFERENT_FROM, string));
- }
-
- @Override
- public B differentFrom(Boolean bool) {
- if (bool == null) {
- throw new IllegalArgumentException("bool cannot be null");
- }
- return applyFilter(new FilterItem(_selectItem, OperatorType.DIFFERENT_FROM, bool));
- }
-
- @Override
- public B differentFrom(Object obj) {
- if (obj == null) {
- return isNotNull();
- }
- if (obj instanceof Boolean) {
- return differentFrom((Boolean) obj);
- }
- if (obj instanceof Number) {
- return differentFrom((Number) obj);
- }
- if (obj instanceof Date) {
- return differentFrom((Date) obj);
- }
- if (obj instanceof String) {
- return differentFrom((String) obj);
- }
- throw new UnsupportedOperationException("Argument must be a Boolean, Number, Date or String. Found: " + obj);
- }
-
- @Deprecated
- @Override
- public B higherThan(Column arg) {
- return greaterThan(arg);
- }
-
- @Override
- public B greaterThan(Column column) {
- if (column == null) {
- throw new IllegalArgumentException("column cannot be null");
- }
- return applyFilter(new FilterItem(_selectItem, OperatorType.GREATER_THAN, new SelectItem(column)));
- }
-
- @Deprecated
- @Override
- public B higherThan(Date arg) {
- return greaterThan(arg);
- }
-
- @Override
- public B greaterThan(Date date) {
- if (date == null) {
- throw new IllegalArgumentException("date cannot be null");
- }
- return applyFilter(new FilterItem(_selectItem, OperatorType.GREATER_THAN, date));
- }
-
- @Deprecated
- @Override
- public B higherThan(Number arg) {
- return greaterThan(arg);
- }
-
- @Override
- public B greaterThan(Number number) {
- if (number == null) {
- throw new IllegalArgumentException("number cannot be null");
- }
- return applyFilter(new FilterItem(_selectItem, OperatorType.GREATER_THAN, number));
- }
-
- @Deprecated
- @Override
- public B higherThan(String arg) {
- return greaterThan(arg);
- }
-
- @Override
- public B greaterThan(String string) {
- if (string == null) {
- throw new IllegalArgumentException("string cannot be null");
- }
- return applyFilter(new FilterItem(_selectItem, OperatorType.GREATER_THAN, string));
- }
-
- @Override
- public B lessThan(Column column) {
- if (column == null) {
- throw new IllegalArgumentException("column cannot be null");
- }
- return applyFilter(new FilterItem(_selectItem, OperatorType.LESS_THAN, new SelectItem(column)));
- }
-
- @Override
- public B lessThan(Date date) {
- if (date == null) {
- throw new IllegalArgumentException("date cannot be null");
- }
- return applyFilter(new FilterItem(_selectItem, OperatorType.LESS_THAN, date));
- }
-
- @Override
- public B lessThan(Number number) {
- if (number == null) {
- throw new IllegalArgumentException("number cannot be null");
- }
- return applyFilter(new FilterItem(_selectItem, OperatorType.LESS_THAN, number));
- }
-
- @Override
- public B lessThan(String string) {
- if (string == null) {
- throw new IllegalArgumentException("string cannot be null");
- }
- return applyFilter(new FilterItem(_selectItem, OperatorType.LESS_THAN, string));
- }
-
- @Override
- public B lessThan(Object obj) {
- if (obj instanceof Number) {
- return lessThan((Number) obj);
- }
- if (obj instanceof Date) {
- return lessThan((Date) obj);
- }
- if (obj instanceof String) {
- return lessThan((String) obj);
- }
- throw new UnsupportedOperationException("Argument must be a Number, Date or String. Found: " + obj);
- }
-
- @Override
- public B greaterThan(Object obj) {
- if (obj instanceof Number) {
- return greaterThan((Number) obj);
- }
- if (obj instanceof Date) {
- return greaterThan((Date) obj);
- }
- if (obj instanceof String) {
- return greaterThan((String) obj);
- }
- throw new UnsupportedOperationException("Argument must be a Number, Date or String. Found: " + obj);
- }
-
- @Override
- public B like(String string) {
- if (string == null) {
- throw new IllegalArgumentException("string cannot be null");
- }
- return applyFilter(new FilterItem(_selectItem, OperatorType.LIKE, string));
- }
-
- @Override
- public B gt(Column column) {
- return greaterThan(column);
- }
-
- @Override
- public B gt(Date date) {
- return greaterThan(date);
- }
-
- @Override
- public B gt(Number number) {
- return greaterThan(number);
- }
-
- @Override
- public B gt(String string) {
- return greaterThan(string);
- }
-
- @Override
- public B lt(Column column) {
- return lessThan(column);
- }
-
- public B lt(Date date) {
- return lessThan(date);
- };
-
- public B lt(Number number) {
- return lessThan(number);
- };
-
- public B lt(String string) {
- return lessThan(string);
- };
-
- @Override
- public B eq(Boolean bool) {
- return isEquals(bool);
- }
-
- @Override
- public B eq(Column column) {
- return isEquals(column);
- }
-
- @Override
- public B eq(Date date) {
- return isEquals(date);
- }
-
- @Override
- public B eq(Number number) {
- return isEquals(number);
- }
-
- @Override
- public B eq(String string) {
- return isEquals(string);
- }
-
- @Override
- public B eq(Object obj) {
- return isEquals(obj);
- }
-
- @Override
- public B ne(Boolean bool) {
- return differentFrom(bool);
- }
-
- @Override
- public B ne(Column column) {
- return differentFrom(column);
- }
-
- @Override
- public B ne(Date date) {
- return differentFrom(date);
- }
-
- @Override
- public B ne(Number number) {
- return differentFrom(number);
- }
-
- @Override
- public B ne(String string) {
- return differentFrom(string);
- }
-
- @Override
- public B ne(Object obj) {
- return differentFrom(obj);
- }
-
- @Override
- @Deprecated
- public B equals(Boolean bool) {
- return isEquals(bool);
- }
-
- @Override
- @Deprecated
- public B equals(Column column) {
- return isEquals(column);
- }
-
- @Override
- @Deprecated
- public B equals(Date date) {
- return isEquals(date);
- }
-
- @Override
- @Deprecated
- public B equals(Number number) {
- return isEquals(number);
- }
-
- @Override
- @Deprecated
- public B equals(String string) {
- return isEquals(string);
- }
-
- @Override
- public B lt(Object obj) {
- return lessThan(obj);
- }
-
- @Override
- public B gt(Object obj) {
- return greaterThan(obj);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/AbstractQueryFilterBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/AbstractQueryFilterBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/builder/AbstractQueryFilterBuilder.java
deleted file mode 100644
index a015292..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/AbstractQueryFilterBuilder.java
+++ /dev/null
@@ -1,344 +0,0 @@
-/**
- * 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.query.builder;
-
-import java.util.Collection;
-import java.util.Date;
-
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-
-abstract class AbstractQueryFilterBuilder<B> extends GroupedQueryBuilderCallback implements FilterBuilder<B> {
-
- protected final AbstractFilterBuilder<B> _filterBuilder;
-
- public AbstractQueryFilterBuilder(SelectItem selectItem, GroupedQueryBuilder queryBuilder) {
- super(queryBuilder);
- _filterBuilder = new AbstractFilterBuilder<B>(selectItem) {
- @Override
- protected B applyFilter(FilterItem filter) {
- return AbstractQueryFilterBuilder.this.applyFilter(filter);
- }
- };
- }
-
- protected abstract B applyFilter(FilterItem filter);
-
- @Override
- public B in(Collection<?> values) {
- return _filterBuilder.in(values);
- }
-
- @Override
- public B in(Number... numbers) {
- return _filterBuilder.in(numbers);
- }
-
- @Override
- public B in(String... strings) {
- return _filterBuilder.in(strings);
- }
-
- @Override
- public B isNull() {
- return _filterBuilder.isNull();
- }
-
- @Override
- public B isNotNull() {
- return _filterBuilder.isNotNull();
- }
-
- @Override
- public B isEquals(Column column) {
- return _filterBuilder.isEquals(column);
- }
-
- @Override
- public B isEquals(Date date) {
- return _filterBuilder.isEquals(date);
- }
-
- @Override
- public B isEquals(Number number) {
- return _filterBuilder.isEquals(number);
- }
-
- @Override
- public B isEquals(String string) {
- return _filterBuilder.isEquals(string);
- }
-
- @Override
- public B isEquals(Boolean bool) {
- return _filterBuilder.isEquals(bool);
- }
-
- @Override
- public B isEquals(Object obj) {
- return _filterBuilder.isEquals(obj);
- }
-
- @Override
- public B differentFrom(Column column) {
- return _filterBuilder.differentFrom(column);
- }
-
- @Override
- public B differentFrom(Date date) {
- return _filterBuilder.differentFrom(date);
- }
-
- @Override
- public B differentFrom(Number number) {
- return _filterBuilder.differentFrom(number);
- }
-
- @Override
- public B differentFrom(String string) {
- return _filterBuilder.differentFrom(string);
- }
-
- @Override
- public B differentFrom(Boolean bool) {
- return _filterBuilder.differentFrom(bool);
- }
-
- @Override
- public B differentFrom(Object obj) {
- return _filterBuilder.differentFrom(obj);
- }
-
- @Deprecated
- @Override
- public B higherThan(Column arg) {
- return _filterBuilder.higherThan(arg);
- }
-
- public B greaterThan(Column column) {
- return _filterBuilder.greaterThan(column);
- }
-
- @Override
- public B greaterThan(Object obj) {
- return _filterBuilder.greaterThan(obj);
- }
-
- @Deprecated
- @Override
- public B higherThan(Date arg) {
- return _filterBuilder.higherThan(arg);
- }
-
- @Override
- public B greaterThan(Date date) {
- return _filterBuilder.greaterThan(date);
- }
-
- @Deprecated
- @Override
- public B higherThan(Number arg) {
- return _filterBuilder.higherThan(arg);
- }
-
- @Override
- public B greaterThan(Number number) {
- return _filterBuilder.greaterThan(number);
- }
-
- @Deprecated
- @Override
- public B higherThan(String arg) {
- return _filterBuilder.higherThan(arg);
- }
-
- @Override
- public B greaterThan(String string) {
- return _filterBuilder.greaterThan(string);
- }
-
- @Override
- public B lessThan(Column column) {
- return _filterBuilder.lessThan(column);
- }
-
- @Override
- public B lessThan(Date date) {
- return _filterBuilder.lessThan(date);
- }
-
- @Override
- public B lessThan(Number number) {
- return _filterBuilder.lessThan(number);
- }
-
- @Override
- public B lessThan(String string) {
- return _filterBuilder.lessThan(string);
- }
-
- @Override
- public B lessThan(Object obj) {
- return _filterBuilder.lessThan(obj);
- }
-
- @Override
- public B like(String string) {
- return _filterBuilder.like(string);
- }
-
- @Override
- public B gt(Column column) {
- return greaterThan(column);
- }
-
- @Override
- public B gt(Date date) {
- return greaterThan(date);
- }
-
- @Override
- public B gt(Number number) {
- return greaterThan(number);
- }
-
- @Override
- public B gt(String string) {
- return greaterThan(string);
- }
-
- @Override
- public B lt(Column column) {
- return lessThan(column);
- }
-
- public B lt(Date date) {
- return lessThan(date);
- };
-
- public B lt(Number number) {
- return lessThan(number);
- };
-
- public B lt(String string) {
- return lessThan(string);
- };
-
- @Override
- public B eq(Boolean bool) {
- return isEquals(bool);
- }
-
- @Override
- public B eq(Column column) {
- return isEquals(column);
- }
-
- @Override
- public B eq(Date date) {
- return isEquals(date);
- }
-
- @Override
- public B eq(Number number) {
- return isEquals(number);
- }
-
- @Override
- public B eq(String string) {
- return isEquals(string);
- }
-
- @Override
- public B eq(Object obj) {
- return isEquals(obj);
- }
-
- @Override
- public B ne(Boolean bool) {
- return differentFrom(bool);
- }
-
- @Override
- public B ne(Column column) {
- return differentFrom(column);
- }
-
- @Override
- public B ne(Date date) {
- return differentFrom(date);
- }
-
- @Override
- public B ne(Number number) {
- return differentFrom(number);
- }
-
- @Override
- public B ne(String string) {
- return differentFrom(string);
- }
-
- @Override
- public B ne(Object obj) {
- return differentFrom(obj);
- }
-
- @Override
- @Deprecated
- public B equals(Boolean bool) {
- return isEquals(bool);
- }
-
- @Override
- @Deprecated
- public B equals(Column column) {
- return isEquals(column);
- }
-
- @Override
- @Deprecated
- public B equals(Date date) {
- return isEquals(date);
- }
-
- @Override
- @Deprecated
- public B equals(Number number) {
- return isEquals(number);
- }
-
- @Override
- @Deprecated
- public B equals(String string) {
- return isEquals(string);
- }
-
- @Override
- public B lt(Object obj) {
- return lessThan(obj);
- }
-
- @Override
- public B gt(Object obj) {
- return greaterThan(obj);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/ColumnSelectBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/ColumnSelectBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/builder/ColumnSelectBuilder.java
deleted file mode 100644
index 00208cf..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/ColumnSelectBuilder.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * 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.query.builder;
-
-public interface ColumnSelectBuilder<B extends SatisfiedQueryBuilder<?>>
- extends SatisfiedSelectBuilder<B> {
-
- public B as(String alias);
-}
[06/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcColumn.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcColumn.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcColumn.java
deleted file mode 100644
index de09ce7..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcColumn.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * 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.jdbc;
-
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * Column implementation for JDBC data contexts.
- *
- * @author Kasper Sørensen
- */
-final class JdbcColumn extends MutableColumn {
-
- private static final long serialVersionUID = 389872697452157919L;
-
- public JdbcColumn(String columnName, ColumnType columnType, JdbcTable table, int columnNumber, Boolean nullable) {
- super(columnName, columnType, table, columnNumber, nullable);
- }
-
- @Override
- public boolean isIndexed() {
- Table table = getTable();
- if (table instanceof JdbcTable) {
- ((JdbcTable) table).loadIndexes();
- }
- return super.isIndexed();
- }
-
- @Override
- public boolean isPrimaryKey() {
- Table table = getTable();
- if (table instanceof JdbcTable) {
- ((JdbcTable) table).loadPrimaryKeys();
- }
- return super.isPrimaryKey();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcCompiledQuery.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcCompiledQuery.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcCompiledQuery.java
deleted file mode 100644
index ddadf1f..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcCompiledQuery.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.List;
-
-import org.apache.commons.pool.impl.GenericObjectPool;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.DefaultCompiledQuery;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Implementation of {@link CompiledQuery} for JDBC which uses a
- * {@link PreparedStatement} behind the scenes.
- */
-final class JdbcCompiledQuery extends DefaultCompiledQuery implements CompiledQuery {
-
- private static final Logger logger = LoggerFactory.getLogger(JdbcCompiledQuery.class);
-
- private final JdbcDataContext _dataContext;
- private final Connection _connection;
- private final String _sql;
- private final Query _query;
- private final GenericObjectPool<JdbcCompiledQueryLease> _pool;
- private boolean _closed;
-
- public JdbcCompiledQuery(JdbcDataContext dc, Query query) {
- super(query);
- _dataContext = dc;
- _connection = dc.getConnection();
- _query = query;
- _sql = dc.getQueryRewriter().rewriteQuery(query);
- _pool = new GenericObjectPool<JdbcCompiledQueryLease>(new JdbcCompiledQueryLeaseFactory(dc, _connection, _sql));
- _closed = false;
-
- logger.debug("Created compiled JDBC query: {}", _sql);
- }
-
- public JdbcCompiledQueryLease borrowLease() {
- if (logger.isDebugEnabled()) {
- logger.debug("Borrowing lease. Leases (before): Active={}, Idle={}", getActiveLeases(), getIdleLeases());
- }
- try {
- return _pool.borrowObject();
- } catch (Exception e) {
- throw handleError(e, "borrow lease");
- }
- }
-
- public void returnLease(JdbcCompiledQueryLease lease) {
- if (logger.isDebugEnabled()) {
- logger.debug("Returning lease. Leases (before): Active={}, Idle={}", getActiveLeases(), getIdleLeases());
- }
- try {
- _pool.returnObject(lease);
- } catch (Exception e) {
- throw handleError(e, "return lease");
- }
- }
-
- private RuntimeException handleError(Exception e, String message) {
- if (logger.isWarnEnabled()) {
- logger.warn("Unexpected error occurred in compiled JDBC query: " + message, e);
- }
-
- if (e instanceof SQLException) {
- return JdbcUtils.wrapException((SQLException) e, message);
- } else if (e instanceof RuntimeException) {
- return (RuntimeException) e;
- } else {
- return new MetaModelException(message, e);
- }
- }
-
- protected int getActiveLeases() {
- return _pool.getNumActive();
- }
-
- protected int getIdleLeases() {
- return _pool.getNumIdle();
- }
-
- protected Query getQuery() {
- return _query;
- }
-
- @Override
- public String toSql() {
- return _sql;
- }
-
- @Override
- public void close() {
- logger.debug("Closing compiled JDBC query: {}", _sql);
- try {
- _pool.close();
- } catch (Exception e) {
- throw handleError(e, "close pool of leases");
- } finally {
- _dataContext.close(_connection, null, null);
- _closed = true;
- }
- }
-
- protected List<SelectItem> getSelectItems() {
- return _query.getSelectClause().getItems();
- }
-
- @Override
- protected void finalize() throws Throwable {
- super.finalize();
- if (!_closed) {
- logger.warn("finalize() invoked, but DataSet is not closed. Invoking close() on {}", this);
- close();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcCompiledQueryLease.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcCompiledQueryLease.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcCompiledQueryLease.java
deleted file mode 100644
index 65bf7b5..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcCompiledQueryLease.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-
-/**
- * Represents a "lease" of a JdbcCompiledQuery. A lease holds the
- * {@link Connection} and {@link PreparedStatement} object associated with
- * executing a compiled query. Since these are not thread-safe, but expensive to
- * create, they are pooled to allow proper isolation when executing compiled
- * queries.
- */
-final class JdbcCompiledQueryLease {
-
- private final Connection _connection;
- private final PreparedStatement _statement;
-
- public JdbcCompiledQueryLease(Connection connection, PreparedStatement statement) {
- _connection = connection;
- _statement = statement;
- }
-
- public Connection getConnection() {
- return _connection;
- }
-
- public PreparedStatement getStatement() {
- return _statement;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcCompiledQueryLeaseFactory.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcCompiledQueryLeaseFactory.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcCompiledQueryLeaseFactory.java
deleted file mode 100644
index e3712ed..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcCompiledQueryLeaseFactory.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-
-import org.apache.commons.pool.PoolableObjectFactory;
-
-/**
- * Factory for the object pool of {@link JdbcCompiledQueryLease}s.
- */
-final class JdbcCompiledQueryLeaseFactory implements PoolableObjectFactory<JdbcCompiledQueryLease> {
-
- private final JdbcDataContext _dataContext;
- private final Connection _connection;
- private final String _sql;
-
- public JdbcCompiledQueryLeaseFactory(JdbcDataContext dataContext, Connection connection, String sql) {
- _dataContext = dataContext;
- _connection = connection;
- _sql = sql;
- }
-
-
- @Override
- public JdbcCompiledQueryLease makeObject() throws Exception {
- try {
- final PreparedStatement statement = _connection.prepareStatement(_sql);
- final JdbcCompiledQueryLease lease = new JdbcCompiledQueryLease(_connection, statement);
- return lease;
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "preparing statement");
- }
- }
-
- @Override
- public void destroyObject(JdbcCompiledQueryLease lease) throws Exception {
- _dataContext.close(null, null, lease.getStatement());
- }
-
- @Override
- public boolean validateObject(JdbcCompiledQueryLease lease) {
- return true;
- }
-
- @Override
- public void activateObject(JdbcCompiledQueryLease obj) throws Exception {
- }
-
- @Override
- public void passivateObject(JdbcCompiledQueryLease obj) throws Exception {
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcCreateTableBuilder.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcCreateTableBuilder.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcCreateTableBuilder.java
deleted file mode 100644
index 9a8803c..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcCreateTableBuilder.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-import org.eobjects.metamodel.create.AbstractTableCreationBuilder;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.FileHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * {@link CreateTableBuilder} implementation that issues a SQL CREATE TABLE
- * statement.
- *
- * @author Kasper Sørensen
- */
-final class JdbcCreateTableBuilder extends AbstractTableCreationBuilder<JdbcUpdateCallback> {
-
- private static final Logger logger = LoggerFactory.getLogger(JdbcCreateTableBuilder.class);
-
- public JdbcCreateTableBuilder(JdbcUpdateCallback updateCallback, Schema schema, String name) {
- super(updateCallback, schema, name);
- if (!(schema instanceof JdbcSchema)) {
- throw new IllegalArgumentException("Not a valid JDBC schema: " + schema);
- }
- }
-
- @Override
- public Table execute() {
- final String sql = createSqlStatement();
- logger.info("Create table statement created: {}", sql);
-
- Connection connection = getUpdateCallback().getConnection();
- Statement st = null;
- try {
- st = connection.createStatement();
- int rowsAffected = st.executeUpdate(sql);
- logger.debug("Create table statement executed, {} rows affected", rowsAffected);
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "execute create table statement: " + sql);
- } finally {
- FileHelper.safeClose(st);
- }
-
- JdbcSchema schema = (JdbcSchema) getSchema();
- schema.refreshTables();
- return schema.getTableByName(getTable().getName());
- }
-
- protected String createSqlStatement() {
- return createSqlStatement(getTable());
- }
-
- private String createSqlStatement(Table table) {
- final IQueryRewriter queryRewriter = getUpdateCallback().getDataContext().getQueryRewriter();
- final StringBuilder sb = new StringBuilder();
- sb.append("CREATE TABLE ");
- final Schema schema = getSchema();
- if (schema != null && schema.getName() != null) {
- sb.append(schema.getQualifiedLabel());
- sb.append(".");
- }
- sb.append(getUpdateCallback().quoteIfNescesary(table.getName()));
- sb.append(" (");
- final Column[] columns = table.getColumns();
- for (int i = 0; i < columns.length; i++) {
- final Column column = columns[i];
- if (i != 0) {
- sb.append(", ");
- }
- sb.append(getUpdateCallback().quoteIfNescesary(column.getName()));
- sb.append(' ');
- final String nativeType = column.getNativeType();
- if (nativeType == null) {
- ColumnType columnType = column.getType();
- if (columnType == null) {
- columnType = ColumnType.VARCHAR;
- }
-
- final String columnTypeString = queryRewriter.rewriteColumnType(columnType);
-
- sb.append(columnTypeString);
- } else {
- sb.append(nativeType);
- }
- final Integer columnSize = column.getColumnSize();
- if (columnSize != null) {
- sb.append('(');
- sb.append(columnSize.intValue());
- 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/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcDataContext.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcDataContext.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcDataContext.java
deleted file mode 100644
index ddac728..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcDataContext.java
+++ /dev/null
@@ -1,794 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.StringTokenizer;
-
-import javax.sql.DataSource;
-
-import org.eobjects.metamodel.AbstractDataContext;
-import org.eobjects.metamodel.BatchUpdateScript;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.EmptyDataSet;
-import org.eobjects.metamodel.data.MaxRowsDataSet;
-import org.eobjects.metamodel.jdbc.dialects.DB2QueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.DefaultQueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.H2QueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.HsqldbQueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.MysqlQueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.PostgresqlQueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.SQLServerQueryRewriter;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.TableType;
-import org.eobjects.metamodel.util.FileHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * DataContextStrategy to use for JDBC-compliant databases
- */
-public class JdbcDataContext extends AbstractDataContext implements UpdateableDataContext {
-
- public static final String SYSTEM_PROPERTY_BATCH_UPDATES = "metamodel.jdbc.batch.updates";
- public static final String SYSTEM_PROPERTY_CONVERT_LOBS = "metamodel.jdbc.convert.lobs";
-
- public static final String DATABASE_PRODUCT_POSTGRESQL = "PostgreSQL";
- public static final String DATABASE_PRODUCT_MYSQL = "MySQL";
- public static final String DATABASE_PRODUCT_HSQLDB = "HSQL Database Engine";
- public static final String DATABASE_PRODUCT_H2 = "H2";
- public static final String DATABASE_PRODUCT_SQLSERVER = "Microsoft SQL Server";
- public static final String DATABASE_PRODUCT_DB2 = "DB2";
- public static final String DATABASE_PRODUCT_DB2_PREFIX = "DB2/";
-
- private static final Logger logger = LoggerFactory.getLogger(JdbcDataContext.class);
-
- private final FetchSizeCalculator _fetchSizeCalculator;
- private final Connection _connection;
- private final DataSource _dataSource;
- private final TableType[] _tableTypes;
- private final String _catalogName;
- private final boolean _singleConnection;
-
- private final MetadataLoader _metadataLoader;
-
- /**
- * Defines the way that queries are written once dispatched to the database
- */
- private IQueryRewriter _queryRewriter;
- private final String _databaseProductName;
-
- /**
- * There are some confusion as to the definition of catalogs and schemas.
- * Some databases seperate "groups of tables" by using schemas, others by
- * catalogs. This variable indicates whether a MetaModel schema really
- * represents a catalog.
- */
- private final String _identifierQuoteString;
- private final boolean _supportsBatchUpdates;
- private final boolean _isDefaultAutoCommit;
- private final boolean _usesCatalogsAsSchemas;
-
- /**
- * Creates the strategy based on a data source, some table types and an
- * optional catalogName
- *
- * @param dataSource
- * the datasource objcet to use for making connections
- * @param tableTypes
- * the types of tables to include
- * @param catalogName
- * a catalog name to use, can be null
- */
- public JdbcDataContext(DataSource dataSource, TableType[] tableTypes, String catalogName) {
- this(dataSource, null, tableTypes, catalogName);
- }
-
- /**
- * Creates the strategy based on a {@link Connection}, some table types and
- * an optional catalogName
- *
- * @param connection
- * the database connection
- * @param tableTypes
- * the types of tables to include
- * @param catalogName
- * a catalog name to use, can be null
- */
- public JdbcDataContext(Connection connection, TableType[] tableTypes, String catalogName) {
- this(null, connection, tableTypes, catalogName);
- }
-
- /**
- * Creates the strategy based on a {@link DataSource}, some table types and
- * an optional catalogName
- *
- * @param dataSource
- * the data source
- * @param tableTypes
- * the types of tables to include
- * @param catalogName
- * a catalog name to use, can be null
- */
- private JdbcDataContext(DataSource dataSource, Connection connection, TableType[] tableTypes, String catalogName) {
- _dataSource = dataSource;
- _connection = connection;
- _tableTypes = tableTypes;
- _catalogName = catalogName;
-
- if (_dataSource == null) {
- _singleConnection = true;
- } else {
- _singleConnection = false;
- }
-
- // available memory for fetching is so far fixed at 16 megs.
- _fetchSizeCalculator = new FetchSizeCalculator(16 * 1024 * 1024);
-
- boolean supportsBatchUpdates = false;
- String identifierQuoteString = null;
- String databaseProductName = null;
- boolean usesCatalogsAsSchemas = false;
-
- final Connection con = getConnection();
-
- try {
- _isDefaultAutoCommit = con.getAutoCommit();
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "determine auto-commit behaviour");
- }
-
- try {
- DatabaseMetaData metaData = con.getMetaData();
-
- supportsBatchUpdates = supportsBatchUpdates(metaData);
-
- try {
- identifierQuoteString = metaData.getIdentifierQuoteString();
- if (identifierQuoteString != null) {
- identifierQuoteString = identifierQuoteString.trim();
- }
- } catch (SQLException e) {
- logger.warn("could not retrieve identifier quote string from database metadata", e);
- }
-
- usesCatalogsAsSchemas = usesCatalogsAsSchemas(metaData);
- try {
- databaseProductName = metaData.getDatabaseProductName();
- } catch (SQLException e) {
- logger.warn("Could not retrieve database product name: " + e.getMessage());
- }
- } catch (SQLException e) {
- logger.debug("Unexpected exception during JdbcDataContext initialization", e);
- } finally {
- closeIfNescesary(con);
- }
- _databaseProductName = databaseProductName;
- logger.debug("Database product name: {}", _databaseProductName);
- if (DATABASE_PRODUCT_MYSQL.equals(_databaseProductName)) {
- setQueryRewriter(new MysqlQueryRewriter(this));
- } else if (DATABASE_PRODUCT_POSTGRESQL.equals(_databaseProductName)) {
- setQueryRewriter(new PostgresqlQueryRewriter(this));
- } else if (DATABASE_PRODUCT_SQLSERVER.equals(_databaseProductName)) {
- setQueryRewriter(new SQLServerQueryRewriter(this));
- } else if (DATABASE_PRODUCT_DB2.equals(_databaseProductName)
- || (_databaseProductName != null && _databaseProductName.startsWith(DATABASE_PRODUCT_DB2_PREFIX))) {
- setQueryRewriter(new DB2QueryRewriter(this));
- } else if (DATABASE_PRODUCT_HSQLDB.equals(_databaseProductName)) {
- setQueryRewriter(new HsqldbQueryRewriter(this));
- } else if (DATABASE_PRODUCT_H2.equals(_databaseProductName)) {
- setQueryRewriter(new H2QueryRewriter(this));
- } else {
- setQueryRewriter(new DefaultQueryRewriter(this));
- }
-
- _supportsBatchUpdates = supportsBatchUpdates;
- _identifierQuoteString = identifierQuoteString;
- _usesCatalogsAsSchemas = usesCatalogsAsSchemas;
- _metadataLoader = new JdbcMetadataLoader(this, _usesCatalogsAsSchemas, _identifierQuoteString);
- }
-
- /**
- * Creates the strategy based on a {@link Connection}
- *
- * @param connection
- * the database connection
- */
- public JdbcDataContext(Connection connection) {
- this(connection, TableType.DEFAULT_TABLE_TYPES, null);
- }
-
- /**
- * Creates the strategy based on a {@link DataSource}
- *
- * @param dataSource
- * the data source
- */
- public JdbcDataContext(DataSource dataSource) {
- this(dataSource, TableType.DEFAULT_TABLE_TYPES, null);
- }
-
- private boolean supportsBatchUpdates(DatabaseMetaData metaData) {
- if ("true".equals(System.getProperty(SYSTEM_PROPERTY_BATCH_UPDATES))) {
- return true;
- }
- if ("false".equals(System.getProperty(SYSTEM_PROPERTY_BATCH_UPDATES))) {
- return false;
- }
-
- try {
- return metaData.supportsBatchUpdates();
- } catch (Exception e) {
- logger.warn("Could not determine if driver support batch updates, returning false", e);
- return false;
- }
- }
-
- private boolean usesCatalogsAsSchemas(DatabaseMetaData metaData) {
- boolean result = true;
- ResultSet rs = null;
- try {
- rs = metaData.getSchemas();
- while (rs.next() && result) {
- result = false;
- }
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "retrieve schema and catalog metadata");
- } finally {
- close(null, rs, null);
- }
- return result;
- }
-
- @Override
- public CompiledQuery compileQuery(Query query) {
- return new JdbcCompiledQuery(this, query);
- }
-
- @Override
- public DataSet executeQuery(CompiledQuery compiledQuery, Object... values) {
-
- final JdbcCompiledQuery jdbcCompiledQuery = (JdbcCompiledQuery) compiledQuery;
-
- final Query query = jdbcCompiledQuery.getQuery();
- final int countMatches = jdbcCompiledQuery.getParameters().size();
-
- final int valueArrayLength = values.length;
-
- if (countMatches != valueArrayLength) {
- throw new MetaModelException("Number of parameters in query and number of values does not match.");
- }
-
- final JdbcCompiledQueryLease lease = jdbcCompiledQuery.borrowLease();
- final DataSet dataSet;
- try {
- dataSet = execute(lease.getConnection(), query, lease.getStatement(), jdbcCompiledQuery, lease, values);
- } catch (SQLException e) {
- // only close in case of an error - the JdbcDataSet will close
- // otherwise
- jdbcCompiledQuery.returnLease(lease);
- throw JdbcUtils.wrapException(e, "execute compiled query");
- }
-
- return dataSet;
- }
-
- private DataSet execute(Connection connection, Query query, Statement statement, JdbcCompiledQuery compiledQuery,
- JdbcCompiledQueryLease lease, Object[] values) throws SQLException {
- if (_databaseProductName.equals(DATABASE_PRODUCT_POSTGRESQL)) {
-
- try {
- // this has to be done in order to make a result set not load
- // all data in memory only for Postgres.
- connection.setAutoCommit(false);
- } catch (Exception e) {
- logger.warn("Could not disable auto-commit (PostgreSQL specific hack)", e);
- }
- }
-
- ResultSet resultSet = null;
-
- boolean postProcessFirstRow = false;
- final Integer firstRow = query.getFirstRow();
- if (firstRow != null) {
- if (_queryRewriter.isFirstRowSupported()) {
- logger.debug("First row property will be treated by query rewriter");
- } else {
- postProcessFirstRow = true;
- }
- }
-
- boolean postProcessMaxRows = false;
- Integer maxRows = query.getMaxRows();
- if (maxRows != null) {
- if (postProcessFirstRow) {
- // if First row is being post processed, we need to
- // increment the "Max rows" accordingly (but subtract one, since
- // firstRow is 1-based).
- maxRows = maxRows + (firstRow - 1);
- query = query.clone().setMaxRows(maxRows);
-
- logger.debug("Setting Max rows to {} because of post processing strategy of First row.", maxRows);
- }
-
- if (_queryRewriter.isMaxRowsSupported()) {
- logger.debug("Max rows property will be treated by query rewriter");
- } else {
- try {
- statement.setMaxRows(maxRows);
- } catch (SQLException e) {
- if (logger.isInfoEnabled()) {
- logger.info("setMaxRows(" + maxRows + ") was rejected.", e);
- }
- postProcessMaxRows = true;
- }
- }
- }
-
- DataSet dataSet = null;
- try {
- final int fetchSize = getFetchSize(query, statement);
-
- logger.debug("Applying fetch_size={}", fetchSize);
-
- try {
- statement.setFetchSize(fetchSize);
- } catch (Exception e) {
- // Ticket #372: Sometimes an exception is thrown here even
- // though it's contrary to the jdbc spec. We'll proceed without
- // doing anything about it though.
- logger.info("Could not get or set fetch size on Statement: {}", e.getMessage());
- }
-
- if (lease == null) {
- final String queryString = _queryRewriter.rewriteQuery(query);
-
- logger.debug("Executing rewritten query: {}", queryString);
-
- resultSet = statement.executeQuery(queryString);
- } else {
- PreparedStatement preparedStatement = (PreparedStatement) statement;
- for (int i = 0; i < values.length; i++) {
- preparedStatement.setObject(i + 1, values[i]);
- }
- resultSet = preparedStatement.executeQuery();
- }
- try {
- resultSet.setFetchSize(fetchSize);
- } catch (Exception e) {
- logger.warn("Could not set fetch size on ResultSet: {}", e.getMessage());
- }
-
- if (postProcessFirstRow) {
- // we iterate to the "first row" using the resultset itself.
- for (int i = 1; i < firstRow; i++) {
- if (!resultSet.next()) {
- // the result set was not as long as the first row
- if (resultSet != null) {
- resultSet.close();
- }
- return new EmptyDataSet(query.getSelectClause().getItems());
- }
- }
- }
-
- if (lease == null) {
- dataSet = new JdbcDataSet(query, this, connection, statement, resultSet);
- } else {
- dataSet = new JdbcDataSet(compiledQuery, lease, resultSet);
- }
-
- if (postProcessMaxRows) {
- dataSet = new MaxRowsDataSet(dataSet, maxRows);
- }
- } catch (SQLException exception) {
- if (resultSet != null) {
- resultSet.close();
- }
- throw exception;
- }
- return dataSet;
- }
-
- public DataSet executeQuery(Query query) throws MetaModelException {
-
- final Connection connection = getConnection();
- final Statement statement;
- try {
- statement = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "create statement for query");
- }
- DataSet dataSet = null;
- try {
-
- dataSet = execute(connection, query, statement, null, null, null);
-
- } catch (SQLException e) {
- // only close in case of an error - the JdbcDataSet will close
- // otherwise
- close(connection, null, statement);
- throw JdbcUtils.wrapException(e, "execute query");
- }
-
- return dataSet;
- }
-
- private int getFetchSize(Query query, final Statement statement) {
- try {
- final int defaultFetchSize = statement.getFetchSize();
- if (DATABASE_PRODUCT_MYSQL.equals(_databaseProductName) && defaultFetchSize == Integer.MIN_VALUE) {
- return defaultFetchSize;
- }
- } catch (Exception e) {
- // exceptions here are ignored.
- logger.debug("Ignoring exception while getting fetch size", e);
- }
- return _fetchSizeCalculator.getFetchSize(query);
- }
-
- /**
- * Quietly closes any of the parameterized JDBC objects
- *
- * @param connection
- *
- * @param rs
- * @param st
- */
- public void close(Connection connection, ResultSet rs, Statement st) {
- closeIfNescesary(connection);
- FileHelper.safeClose(rs, st);
- }
-
- /**
- * Convenience method to get the available catalogNames using this
- * connection.
- *
- * @return a String-array with the names of the available catalogs.
- */
- public String[] getCatalogNames() {
- Connection connection = getConnection();
-
- // Retrieve metadata
- DatabaseMetaData metaData = null;
- ResultSet rs = null;
- try {
- metaData = connection.getMetaData();
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "retrieve metadata");
- }
-
- // Retrieve catalogs
- logger.debug("Retrieving catalogs");
- List<String> catalogs = new ArrayList<String>();
- try {
- rs = metaData.getCatalogs();
- while (rs.next()) {
- String catalogName = rs.getString(1);
- logger.debug("Found catalogName: {}", catalogName);
- catalogs.add(catalogName);
- }
- } catch (SQLException e) {
- logger.error("Error retrieving catalog metadata", e);
- } finally {
- close(connection, rs, null);
- logger.debug("Retrieved {} catalogs", catalogs.size());
- }
- return catalogs.toArray(new String[catalogs.size()]);
- }
-
- /**
- * Gets the delegate from the JDBC API (ie. Connection or DataSource) that
- * is being used to perform database interactions.
- *
- * @return either a DataSource or a Connection, depending on the
- * configuration of the DataContext.
- */
- public Object getDelegate() {
- if (_dataSource == null) {
- return _connection;
- }
- return _dataSource;
- }
-
- /**
- * Gets an appropriate connection object to use - either a dedicated
- * connection or a new connection from the datasource object.
- *
- * Hint: Use the {@link #close(Connection, ResultSet, Statement)} method to
- * close the connection (and any ResultSet or Statements involved).
- */
- public Connection getConnection() {
- if (_dataSource == null) {
- return _connection;
- }
- try {
- return _dataSource.getConnection();
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "establish connection");
- }
- }
-
- private void closeIfNescesary(Connection con) {
- if (con != null) {
- if (_dataSource != null) {
- // closing connections after individual usage is only nescesary
- // when they are being pulled from a DataSource.
- FileHelper.safeClose(con);
- }
- }
- }
-
- public String getDefaultSchemaName() {
- // Use a boolean to check if the result has been
- // found, because a schema name can actually be
- // null (for example in the case of Firebird
- // databases).
- boolean found = false;
- String result = null;
- String[] schemaNames = getSchemaNames();
-
- // First strategy: If there's only one schema available, that must
- // be it
- if (schemaNames.length == 1) {
- result = schemaNames[0];
- found = true;
- }
-
- if (!found) {
- Connection connection = getConnection();
- try {
- DatabaseMetaData metaData = connection.getMetaData();
-
- // Second strategy: Find default schema name by examining the
- // URL
- if (!found) {
- String url = metaData.getURL();
- if (url != null && url.length() > 0) {
- if (schemaNames.length > 0) {
- StringTokenizer st = new StringTokenizer(url, "/\\:");
- int tokenCount = st.countTokens();
- if (tokenCount > 0) {
- for (int i = 1; i < tokenCount; i++) {
- st.nextToken();
- }
- String lastToken = st.nextToken();
-
- for (int i = 0; i < schemaNames.length && !found; i++) {
- String schemaName = schemaNames[i];
- if (lastToken.indexOf(schemaName) != -1) {
- result = schemaName;
- found = true;
- }
- }
- }
- }
- }
- }
-
- // Third strategy: Check for schema equal to username
- if (!found) {
- String username = metaData.getUserName();
- if (username != null) {
- for (int i = 0; i < schemaNames.length && !found; i++) {
- if (username.equalsIgnoreCase(schemaNames[i])) {
- result = schemaNames[i];
- found = true;
- }
- }
- }
- }
-
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "determine default schema name");
- } finally {
- closeIfNescesary(connection);
- }
-
- // Fourth strategy: Find default schema name by vendor-specific
- // hacks
- if (!found) {
- if (DATABASE_PRODUCT_POSTGRESQL.equalsIgnoreCase(_databaseProductName)) {
- if (_catalogName == null) {
- result = "public";
- } else {
- result = _catalogName;
- }
- found = true;
- }
- if (DATABASE_PRODUCT_HSQLDB.equalsIgnoreCase(_databaseProductName)) {
- for (int i = 0; i < schemaNames.length && !found; i++) {
- String schemaName = schemaNames[i];
- if ("PUBLIC".equals(schemaName)) {
- result = schemaName;
- found = true;
- break;
- }
- }
- }
- if (DATABASE_PRODUCT_SQLSERVER.equals(_databaseProductName)) {
- for (int i = 0; i < schemaNames.length && !found; i++) {
- String schemaName = schemaNames[i];
- if ("dbo".equals(schemaName)) {
- result = schemaName;
- found = true;
- break;
- }
- }
- }
- }
- }
- return result;
- }
-
- /**
- * Microsoft SQL Server returns users instead of schemas when calling
- * metadata.getSchemas() This is a simple workaround.
- *
- * @return
- * @throws SQLException
- */
- private Set<String> getSchemaSQLServerNames(DatabaseMetaData metaData) throws SQLException {
- // Distinct schema names. metaData.getTables() is a denormalized
- // resultset
- Set<String> schemas = new HashSet<String>();
- ResultSet rs = metaData.getTables(_catalogName, null, null, JdbcUtils.getTableTypesAsStrings(_tableTypes));
- while (rs.next()) {
- schemas.add(rs.getString("TABLE_SCHEM"));
- }
- return schemas;
- }
-
- public JdbcDataContext setQueryRewriter(IQueryRewriter queryRewriter) {
- if (queryRewriter == null) {
- throw new IllegalArgumentException("Query rewriter cannot be null");
- }
- _queryRewriter = queryRewriter;
- return this;
- }
-
- public IQueryRewriter getQueryRewriter() {
- return _queryRewriter;
- }
-
- public String getIdentifierQuoteString() {
- return _identifierQuoteString;
- }
-
- @Override
- protected String[] getSchemaNamesInternal() {
- Connection connection = getConnection();
- try {
- DatabaseMetaData metaData = connection.getMetaData();
- Collection<String> result = new ArrayList<String>();
-
- if (DATABASE_PRODUCT_SQLSERVER.equals(_databaseProductName)) {
- result = getSchemaSQLServerNames(metaData);
- } else if (_usesCatalogsAsSchemas) {
- String[] catalogNames = getCatalogNames();
- for (String name : catalogNames) {
- logger.debug("Found catalogName: {}", name);
- result.add(name);
- }
- } else {
- ResultSet rs = metaData.getSchemas();
- while (rs.next()) {
- String schemaName = rs.getString(1);
- logger.debug("Found schemaName: {}", schemaName);
- result.add(schemaName);
- }
- rs.close();
- }
-
- if (DATABASE_PRODUCT_MYSQL.equals(_databaseProductName)) {
- result.remove("information_schema");
- }
-
- // If still no schemas are found, add a schema with a null-name
- if (result.isEmpty()) {
- logger.info("No schemas or catalogs found. Creating unnamed schema.");
- result.add(null);
- }
- return result.toArray(new String[result.size()]);
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "get schema names");
- } finally {
- closeIfNescesary(connection);
- }
- }
-
- @Override
- protected Schema getSchemaByNameInternal(String name) {
- JdbcSchema schema = new JdbcSchema(name, _metadataLoader);
- _metadataLoader.loadTables(schema);
- return schema;
- }
-
- public FetchSizeCalculator getFetchSizeCalculator() {
- return _fetchSizeCalculator;
- }
-
- @Override
- public void executeUpdate(final UpdateScript update) {
- final JdbcUpdateCallback updateCallback;
-
- if (_supportsBatchUpdates && update instanceof BatchUpdateScript) {
- updateCallback = new JdbcBatchUpdateCallback(this);
- } else {
- updateCallback = new JdbcSimpleUpdateCallback(this);
- }
-
- try {
- if (isSingleConnection() && isDefaultAutoCommit()) {
- // if auto-commit is going to be switched off and on during
- // updates, then the update needs to be synchronized, to avoid
- // race-conditions when switching off and on.
- synchronized (_connection) {
- update.run(updateCallback);
- }
- } else {
- update.run(updateCallback);
- }
- updateCallback.close(true);
- } catch (RuntimeException e) {
- updateCallback.close(false);
- throw e;
- }
- }
-
- protected boolean isSingleConnection() {
- return _singleConnection;
- }
-
- protected boolean isDefaultAutoCommit() {
- return _isDefaultAutoCommit;
- }
-
- @Override
- protected boolean isQualifiedPathDelim(char c) {
- if (_identifierQuoteString == null || _identifierQuoteString.length() == 0) {
- return super.isQualifiedPathDelim(c);
- }
- return c == '.' || c == _identifierQuoteString.charAt(0);
- }
-
- public TableType[] getTableTypes() {
- return _tableTypes;
- }
-
- public String getCatalogName() {
- return _catalogName;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcDataSet.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcDataSet.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcDataSet.java
deleted file mode 100644
index 09b3689..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcDataSet.java
+++ /dev/null
@@ -1,229 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.io.InputStream;
-import java.io.Reader;
-import java.sql.Blob;
-import java.sql.Clob;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.AbstractDataSet;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.util.FileHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * DataSet implementation that wraps a JDBC resultset.
- *
- * @author Kasper Sørensen
- */
-final class JdbcDataSet extends AbstractDataSet {
-
- private static final Logger logger = LoggerFactory.getLogger(JdbcDataSet.class);
-
- private final JdbcCompiledQuery _compiledQuery;
- private final JdbcCompiledQueryLease _lease;
- private final Statement _statement;
- private final ResultSet _resultSet;
- private final JdbcDataContext _jdbcDataContext;
- private final Connection _connection;
- private Row _row;
- private boolean _closed;
-
- /**
- * Constructor used for regular query execution.
- *
- * @param query
- * @param jdbcDataContext
- * @param connection
- * @param statement
- * @param resultSet
- */
- public JdbcDataSet(Query query, JdbcDataContext jdbcDataContext, Connection connection, Statement statement,
- ResultSet resultSet) {
- super(query.getSelectClause().getItems());
- if (query == null || statement == null || resultSet == null) {
- throw new IllegalArgumentException("Arguments cannot be null");
- }
- _jdbcDataContext = jdbcDataContext;
- _connection = connection;
- _statement = statement;
- _resultSet = resultSet;
- _closed = false;
- _compiledQuery = null;
- _lease = null;
- }
-
- /**
- * Constructor used for compiled query execution
- *
- * @param query
- * @param jdbcDataContext
- * @param resultSet
- */
- public JdbcDataSet(JdbcCompiledQuery compiledQuery, JdbcCompiledQueryLease lease, ResultSet resultSet) {
- super(compiledQuery.getSelectItems());
- if (compiledQuery == null || lease == null || resultSet == null) {
- throw new IllegalArgumentException("Arguments cannot be null");
- }
-
- _compiledQuery = compiledQuery;
- _lease = lease;
-
- _jdbcDataContext = null;
- _connection = null;
- _statement = null;
- _resultSet = resultSet;
- _closed = false;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Row getRow() {
- return _row;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean next() throws MetaModelException {
- try {
- boolean result = _resultSet.next();
- if (result) {
- Object[] values = new Object[getHeader().size()];
- for (int i = 0; i < values.length; i++) {
-
- values[i] = getValue(_resultSet, i);
-
- try {
- // some drivers return boxed primitive types in stead of
- // nulls (such as false in stead of null for a Boolean
- // column)
- if (_resultSet.wasNull()) {
- values[i] = null;
- }
- } catch (Exception e) {
- logger.debug("Could not invoke wasNull() method on resultset, error message: {}",
- e.getMessage());
- }
- }
- _row = new DefaultRow(getHeader(), values);
- } else {
- _row = null;
- }
- return result;
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "get next record in resultset");
- }
- }
-
- private Object getValue(ResultSet resultSet, int i) throws SQLException {
- final SelectItem selectItem = getHeader().getSelectItem(i);
- final int columnIndex = i + 1;
- if (selectItem.getFunction() == null) {
- Column column = selectItem.getColumn();
- if (column != null) {
- ColumnType type = column.getType();
- try {
- switch (type) {
- case TIME:
- return _resultSet.getTime(columnIndex);
- case DATE:
- return _resultSet.getDate(columnIndex);
- case TIMESTAMP:
- return _resultSet.getTimestamp(columnIndex);
- case BLOB:
- final Blob blob = _resultSet.getBlob(columnIndex);
- if (isLobConversionEnabled()) {
- final InputStream inputStream = blob.getBinaryStream();
- final byte[] bytes = FileHelper.readAsBytes(inputStream);
- return bytes;
- }
- return blob;
- case BINARY:
- case VARBINARY:
- case LONGVARBINARY:
- return _resultSet.getBytes(columnIndex);
- case CLOB:
- case NCLOB:
- final Clob clob = _resultSet.getClob(columnIndex);
- if (isLobConversionEnabled()) {
- final Reader reader = clob.getCharacterStream();
- final String result = FileHelper.readAsString(reader);
- return result;
- }
- return clob;
- case BIT:
- case BOOLEAN:
- return _resultSet.getBoolean(columnIndex);
- }
- } catch (Exception e) {
- logger.warn("Failed to retrieve " + type
- + " value using type-specific getter, retrying with generic getObject(...) method", e);
- }
- }
- }
- return _resultSet.getObject(columnIndex);
- }
-
- private boolean isLobConversionEnabled() {
- final String systemProperty = System.getProperty(JdbcDataContext.SYSTEM_PROPERTY_CONVERT_LOBS);
- return "true".equals(systemProperty);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void close() {
- if (_closed) {
- return;
- }
- if (_jdbcDataContext != null) {
- _jdbcDataContext.close(_connection, _resultSet, _statement);
- }
- if (_compiledQuery != null) {
- _compiledQuery.returnLease(_lease);
- }
- _closed = true;
- }
-
- @Override
- protected void finalize() throws Throwable {
- super.finalize();
- if (!_closed) {
- logger.warn("finalize() invoked, but DataSet is not closed. Invoking close() on {}", this);
- close();
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcDeleteBuilder.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcDeleteBuilder.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcDeleteBuilder.java
deleted file mode 100644
index 73d8989..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcDeleteBuilder.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.List;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.delete.AbstractRowDeletionBuilder;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.FileHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * {@link RowDeletionBuilder} that issues an SQL DELETE FROM statement
- *
- * @author Kasper Sørensen
- */
-final class JdbcDeleteBuilder extends AbstractRowDeletionBuilder {
-
- private static final Logger logger = LoggerFactory.getLogger(JdbcDeleteBuilder.class);
-
- private final JdbcUpdateCallback _updateCallback;
- private final IQueryRewriter _queryRewriter;
- private final boolean _inlineValues;
-
- public JdbcDeleteBuilder(JdbcUpdateCallback updateCallback, Table table, IQueryRewriter queryRewriter) {
- this(updateCallback, table, queryRewriter, false);
- }
-
- public JdbcDeleteBuilder(JdbcUpdateCallback updateCallback, Table table, IQueryRewriter queryRewriter,
- boolean inlineValues) {
- super(table);
- _updateCallback = updateCallback;
- _queryRewriter = queryRewriter;
- _inlineValues = inlineValues;
- }
-
- @Override
- public void execute() throws MetaModelException {
- String sql = createSqlStatement();
-
- logger.debug("Delete statement created: {}", sql);
- final boolean reuseStatement = !_inlineValues;
- final PreparedStatement st = _updateCallback.getPreparedStatement(sql, reuseStatement);
- try {
- if (reuseStatement) {
- int valueCounter = 1;
- final List<FilterItem> whereItems = getWhereItems();
- for (FilterItem whereItem : whereItems) {
- if (JdbcUtils.isPreparedParameterCandidate(whereItem)) {
- Object operand = whereItem.getOperand();
- st.setObject(valueCounter, operand);
- valueCounter++;
- }
- }
- }
- _updateCallback.executePreparedStatement(st, reuseStatement);
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "execute delete statement: " + sql);
- } finally {
- if (_inlineValues) {
- FileHelper.safeClose(st);
- }
- }
- }
-
- protected String createSqlStatement() {
- StringBuilder sb = new StringBuilder();
- sb.append("DELETE FROM ");
- sb.append(_queryRewriter.rewriteFromItem(new FromItem(getTable())));
- sb.append(JdbcUtils.createWhereClause(getWhereItems(), _queryRewriter, _inlineValues));
- return sb.toString();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcDropTableBuilder.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcDropTableBuilder.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcDropTableBuilder.java
deleted file mode 100644
index a5dafb9..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcDropTableBuilder.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-
-import org.eobjects.metamodel.drop.AbstractTableDropBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * {@link TableDropBuilder} that issues an SQL DROP TABLE statement
- *
- * @author Kasper Sørensen
- */
-final class JdbcDropTableBuilder extends AbstractTableDropBuilder implements TableDropBuilder {
-
- private final JdbcUpdateCallback _updateCallback;
- private final IQueryRewriter _queryRewriter;
-
- public JdbcDropTableBuilder(JdbcUpdateCallback updateCallback, Table table, IQueryRewriter queryRewriter) {
- super(table);
- _updateCallback = updateCallback;
- _queryRewriter = queryRewriter;
- }
-
- @Override
- public void execute() {
- String sql = createSqlStatement();
-
- PreparedStatement statement = _updateCallback.getPreparedStatement(sql, false);
- try {
- _updateCallback.executePreparedStatement(statement, false);
-
- // remove the table reference from the schema
- final Schema schema = getTable().getSchema();
- if (schema instanceof JdbcSchema) {
- ((JdbcSchema) schema).refreshTables();
- }
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "execute drop table statement: " + sql);
- }
- }
-
- protected String createSqlStatement() {
- FromItem fromItem = new FromItem(getTable());
- String tableLabel = _queryRewriter.rewriteFromItem(fromItem);
-
- return "DROP TABLE " + tableLabel;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcInsertBuilder.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcInsertBuilder.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcInsertBuilder.java
deleted file mode 100644
index edf0316..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcInsertBuilder.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.Arrays;
-
-import org.eobjects.metamodel.insert.AbstractRowInsertionBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.FileHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * {@link RowInsertionBuilder} that issues an SQL INSERT statement
- *
- * @author Kasper Sørensen
- */
-final class JdbcInsertBuilder extends AbstractRowInsertionBuilder<JdbcUpdateCallback> {
-
- private static final Logger logger = LoggerFactory.getLogger(JdbcInsertBuilder.class);
-
- private final boolean _inlineValues;
- private final IQueryRewriter _queryRewriter;
-
- public JdbcInsertBuilder(JdbcUpdateCallback updateCallback, Table table, IQueryRewriter queryRewriter) {
- this(updateCallback, table, false, queryRewriter);
- }
-
- public JdbcInsertBuilder(JdbcUpdateCallback updateCallback, Table table, boolean isInlineValues,
- IQueryRewriter queryRewriter) {
- super(updateCallback, table);
- if (!(table instanceof JdbcTable)) {
- throw new IllegalArgumentException("Not a valid JDBC table: " + table);
- }
-
- _inlineValues = isInlineValues;
- _queryRewriter = queryRewriter;
- }
-
- @Override
- public void execute() {
- final String sql = createSqlStatement();
- if (logger.isDebugEnabled()) {
- logger.debug("Inserting: {}", Arrays.toString(getValues()));
- logger.debug("Insert statement created: {}", sql);
- }
- final JdbcUpdateCallback updateCallback = getUpdateCallback();
- final boolean reuseStatement = !_inlineValues;
- final PreparedStatement st = updateCallback.getPreparedStatement(sql, reuseStatement);
- try {
- if (reuseStatement) {
- Column[] columns = getColumns();
- Object[] values = getValues();
- boolean[] explicitNulls = getExplicitNulls();
- int valueCounter = 1;
- for (int i = 0; i < columns.length; i++) {
- boolean explicitNull = explicitNulls[i];
- if (values[i] != null || explicitNull) {
- JdbcUtils.setStatementValue(st, valueCounter, columns[i], values[i]);
- valueCounter++;
- }
- }
- }
- updateCallback.executePreparedStatement(st, reuseStatement);
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "execute insert statement: " + sql);
- } finally {
- if (_inlineValues) {
- FileHelper.safeClose(st);
- }
- }
- }
-
- protected String createSqlStatement() {
- return createSqlStatement(_inlineValues);
- }
-
- private String createSqlStatement(boolean inlineValues) {
- final Object[] values = getValues();
- final Table table = getTable();
- final StringBuilder sb = new StringBuilder();
-
- final String tableLabel = _queryRewriter.rewriteFromItem(new FromItem(table));
-
- sb.append("INSERT INTO ");
- sb.append(tableLabel);
- sb.append(" (");
- Column[] columns = getColumns();
- boolean[] explicitNulls = getExplicitNulls();
- boolean firstValue = true;
- for (int i = 0; i < columns.length; i++) {
- if (values[i] != null || explicitNulls[i]) {
- if (firstValue) {
- firstValue = false;
- } else {
- sb.append(',');
- }
- String columnName = columns[i].getName();
- columnName = getUpdateCallback().quoteIfNescesary(columnName);
- sb.append(columnName);
- }
- }
-
- sb.append(") VALUES (");
- firstValue = true;
- for (int i = 0; i < columns.length; i++) {
- if (values[i] != null || explicitNulls[i]) {
- if (firstValue) {
- firstValue = false;
- } else {
- sb.append(',');
- }
- if (inlineValues) {
- sb.append(JdbcUtils.getValueAsSql(columns[i], values[i], _queryRewriter));
- } else {
- sb.append('?');
- }
- }
- }
- sb.append(")");
- String sql = sb.toString();
- return sql;
- }
-
- @Override
- public String toSql() {
- return createSqlStatement(true);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcMetadataLoader.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcMetadataLoader.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcMetadataLoader.java
deleted file mode 100644
index ef92593..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcMetadataLoader.java
+++ /dev/null
@@ -1,427 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableRelationship;
-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;
-
-/**
- * {@link MetadataLoader} for JDBC metadata loading.
- */
-final class JdbcMetadataLoader implements MetadataLoader {
-
- private static final Logger logger = LoggerFactory.getLogger(JdbcMetadataLoader.class);
-
- private final JdbcDataContext _dataContext;
- private final boolean _usesCatalogsAsSchemas;
- private final String _identifierQuoteString;
-
- // these three sets contains the system identifies of whether specific items
- // have been loaded for tables/schemas. Using system identities avoid having
- // to call equals(...) method etc. while doing lazy loading of these items.
- // Invoking equals(...) would be prone to stack overflows ...
- private final Set<Integer> _loadedRelations;
- private final Set<Integer> _loadedColumns;
- private final Set<Integer> _loadedIndexes;
- private final Set<Integer> _loadedPrimaryKeys;
-
- public JdbcMetadataLoader(JdbcDataContext dataContext, boolean usesCatalogsAsSchemas, String identifierQuoteString) {
- _dataContext = dataContext;
- _usesCatalogsAsSchemas = usesCatalogsAsSchemas;
- _identifierQuoteString = identifierQuoteString;
- _loadedRelations = Collections.newSetFromMap(new ConcurrentHashMap<Integer, Boolean>());
- _loadedColumns = Collections.newSetFromMap(new ConcurrentHashMap<Integer, Boolean>());
- _loadedIndexes = Collections.newSetFromMap(new ConcurrentHashMap<Integer, Boolean>());
- _loadedPrimaryKeys = Collections.newSetFromMap(new ConcurrentHashMap<Integer, Boolean>());
- }
-
- @Override
- public void loadTables(JdbcSchema schema) {
- final Connection connection = _dataContext.getConnection();
- try {
- final DatabaseMetaData metaData = connection.getMetaData();
-
- // Creates string array to represent the table types
- final String[] types = JdbcUtils.getTableTypesAsStrings(_dataContext.getTableTypes());
- loadTables(schema, metaData, types);
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "retrieve table metadata for " + schema.getName());
- } finally {
- _dataContext.close(connection, null, null);
- }
- }
-
- private void loadTables(JdbcSchema schema, DatabaseMetaData metaData, String[] types) {
- String catalogName = _dataContext.getCatalogName();
-
- ResultSet rs = null;
- try {
- if (logger.isDebugEnabled()) {
- logger.debug("Querying for table types " + Arrays.toString(types) + " in catalog: " + catalogName
- + ", schema: " + schema.getName());
- }
- if (_usesCatalogsAsSchemas) {
- rs = metaData.getTables(schema.getName(), null, null, types);
- } else {
- rs = metaData.getTables(catalogName, schema.getName(), null, types);
- }
- schema.clearTables();
- int tableNumber = -1;
- while (rs.next()) {
- tableNumber++;
- String tableCatalog = rs.getString(1);
- String tableSchema = rs.getString(2);
- String tableName = rs.getString(3);
- String tableTypeName = rs.getString(4);
- TableType tableType = TableType.getTableType(tableTypeName);
- String tableRemarks = rs.getString(5);
-
- if (logger.isDebugEnabled()) {
- logger.debug("Found table: tableCatalog=" + tableCatalog + ",tableSchema=" + tableSchema
- + ",tableName=" + tableName);
- }
-
- if (tableSchema == null) {
- tableSchema = tableCatalog;
- }
-
- JdbcTable table = new JdbcTable(tableName, tableType, schema, this);
- table.setRemarks(tableRemarks);
- table.setQuote(_identifierQuoteString);
- schema.addTable(table);
- }
-
- final int tablesReturned = tableNumber + 1;
- if (tablesReturned == 0) {
- logger.info("No table metadata records returned for schema '{}'", schema.getName());
- } else {
- logger.debug("Returned {} table metadata records for schema '{}'", new Object[] { tablesReturned,
- schema.getName() });
- }
-
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "retrieve table metadata for " + schema.getName());
- } finally {
- _dataContext.close(null, rs, null);
- }
- }
-
- @Override
- public void loadIndexes(JdbcTable table) {
- final int identity = System.identityHashCode(table);
- if (_loadedIndexes.contains(identity)) {
- return;
- }
- synchronized (this) {
- if (_loadedIndexes.contains(identity)) {
- return;
- }
-
- final Connection connection = _dataContext.getConnection();
- try {
- DatabaseMetaData metaData = connection.getMetaData();
- loadIndexes(table, metaData);
- _loadedIndexes.add(identity);
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "load indexes");
- } finally {
- _dataContext.close(connection, null, null);
- }
- }
- }
-
- @Override
- public void loadPrimaryKeys(JdbcTable table) {
- final int identity = System.identityHashCode(table);
- if (_loadedPrimaryKeys.contains(identity)) {
- return;
- }
- synchronized (this) {
- if (_loadedPrimaryKeys.contains(identity)) {
- return;
- }
- final Connection connection = _dataContext.getConnection();
- try {
- DatabaseMetaData metaData = connection.getMetaData();
- loadPrimaryKeys(table, metaData);
- _loadedPrimaryKeys.add(identity);
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "load primary keys");
- } finally {
- _dataContext.close(connection, null, null);
- }
- }
- }
-
- private void loadPrimaryKeys(JdbcTable table, DatabaseMetaData metaData) throws MetaModelException {
- Schema schema = table.getSchema();
- ResultSet rs = null;
-
- try {
- if (_usesCatalogsAsSchemas) {
- rs = metaData.getPrimaryKeys(schema.getName(), null, table.getName());
- } else {
- rs = metaData.getPrimaryKeys(_dataContext.getCatalogName(), schema.getName(), table.getName());
- }
- while (rs.next()) {
- String columnName = rs.getString(4);
- if (columnName != null) {
- MutableColumn column = (MutableColumn) table.getColumnByName(columnName);
- if (column != null) {
- column.setPrimaryKey(true);
- } else {
- logger.error("Indexed column \"{}\" could not be found in table: {}", columnName, table);
- }
- }
- }
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "retrieve primary keys for " + table.getName());
- } finally {
- _dataContext.close(null, rs, null);
- }
- }
-
- private void loadIndexes(Table table, DatabaseMetaData metaData) throws MetaModelException {
- Schema schema = table.getSchema();
- ResultSet rs = null;
- // Ticket #170: IndexInfo is nice-to-have, not need-to-have, so
- // we will do a nice failover on SQLExceptions
- try {
- if (_usesCatalogsAsSchemas) {
- rs = metaData.getIndexInfo(schema.getName(), null, table.getName(), false, true);
- } else {
- rs = metaData.getIndexInfo(_dataContext.getCatalogName(), schema.getName(), table.getName(), false,
- true);
- }
- while (rs.next()) {
- String columnName = rs.getString(9);
- if (columnName != null) {
- MutableColumn column = (MutableColumn) table.getColumnByName(columnName);
- if (column != null) {
- column.setIndexed(true);
- } else {
- logger.error("Indexed column \"{}\" could not be found in table: {}", columnName, table);
- }
- }
- }
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "retrieve index information for " + table.getName());
- } finally {
- _dataContext.close(null, rs, null);
- }
- }
-
- /**
- * Loads column metadata (no indexes though) for a table
- *
- * @param table
- */
- @Override
- public void loadColumns(JdbcTable table) {
- final int identity = System.identityHashCode(table);
- if (_loadedColumns.contains(identity)) {
- return;
- }
- synchronized (this) {
- if (_loadedColumns.contains(identity)) {
- return;
- }
-
- final Connection connection = _dataContext.getConnection();
- try {
- DatabaseMetaData metaData = connection.getMetaData();
- loadColumns(table, metaData);
- _loadedColumns.add(identity);
- } catch (Exception e) {
- logger.error("Could not load columns for table: " + table, e);
- } finally {
- _dataContext.close(connection, null, null);
- }
- }
- }
-
- private void loadColumns(JdbcTable table, DatabaseMetaData metaData) {
- final Schema schema = table.getSchema();
- ResultSet rs = null;
- try {
- if (logger.isDebugEnabled()) {
- logger.debug("Querying for columns in table: " + table.getName());
- }
- int columnNumber = -1;
- if (_usesCatalogsAsSchemas) {
- rs = metaData.getColumns(schema.getName(), null, table.getName(), null);
- } else {
- rs = metaData.getColumns(_dataContext.getCatalogName(), schema.getName(), table.getName(), null);
- }
- while (rs.next()) {
- columnNumber++;
- final String columnName = rs.getString(4);
- if (_identifierQuoteString == null && new StringTokenizer(columnName).countTokens() > 1) {
- logger.warn("column name contains whitespace: \"" + columnName + "\".");
- }
-
- final int jdbcType = rs.getInt(5);
- final String nativeType = rs.getString(6);
- final Integer columnSize = rs.getInt(7);
-
- if (logger.isDebugEnabled()) {
- logger.debug("Found column: table=" + table.getName() + ",columnName=" + columnName
- + ",nativeType=" + nativeType + ",columnSize=" + columnSize);
- }
-
- final ColumnType columnType = _dataContext.getQueryRewriter().getColumnType(jdbcType, nativeType,
- columnSize);
-
- final int jdbcNullable = rs.getInt(11);
- final Boolean nullable;
- if (jdbcNullable == DatabaseMetaData.columnNullable) {
- nullable = true;
- } else if (jdbcNullable == DatabaseMetaData.columnNoNulls) {
- nullable = false;
- } else {
- nullable = null;
- }
-
- final String remarks = rs.getString(12);
-
- final JdbcColumn column = new JdbcColumn(columnName, columnType, table, columnNumber, nullable);
- column.setRemarks(remarks);
- column.setNativeType(nativeType);
- column.setColumnSize(columnSize);
- column.setQuote(_identifierQuoteString);
- table.addColumn(column);
- }
-
- final int columnsReturned = columnNumber + 1;
- if (columnsReturned == 0) {
- logger.info("No column metadata records returned for table '{}' in schema '{}'", table.getName(),
- schema.getName());
- } else {
- logger.debug("Returned {} column metadata records for table '{}' in schema '{}'", new Object[] {
- columnsReturned, table.getName(), schema.getName() });
- }
-
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "retrieve table metadata for " + table.getName());
- } finally {
- _dataContext.close(null, rs, null);
- }
- }
-
- @Override
- public void loadRelations(JdbcSchema schema) {
- final int identity = System.identityHashCode(schema);
- if (_loadedRelations.contains(identity)) {
- return;
- }
- synchronized (this) {
- if (_loadedRelations.contains(identity)) {
- return;
- }
- final Connection connection = _dataContext.getConnection();
- try {
- final Table[] tables = schema.getTables();
- final DatabaseMetaData metaData = connection.getMetaData();
- for (Table table : tables) {
- loadRelations(table, metaData);
- }
- _loadedRelations.add(identity);
- } catch (Exception e) {
- logger.error("Could not load relations for schema: " + schema, e);
- } finally {
- _dataContext.close(connection, null, null);
- }
- }
- }
-
- private void loadRelations(Table table, DatabaseMetaData metaData) {
- Schema schema = table.getSchema();
- ResultSet rs = null;
- try {
- if (_usesCatalogsAsSchemas) {
- rs = metaData.getImportedKeys(schema.getName(), null, table.getName());
- } else {
- rs = metaData.getImportedKeys(_dataContext.getCatalogName(), schema.getName(), table.getName());
- }
- loadRelations(rs, schema);
- } catch (SQLException e) {
- throw JdbcUtils.wrapException(e, "retrieve imported keys for " + table.getName());
- } finally {
- _dataContext.close(null, rs, null);
- }
- }
-
- private void loadRelations(ResultSet rs, Schema schema) throws SQLException {
- while (rs.next()) {
- String pkTableName = rs.getString(3);
- String pkColumnName = rs.getString(4);
-
- Column pkColumn = null;
- Table pkTable = schema.getTableByName(pkTableName);
- if (pkTable != null) {
- pkColumn = pkTable.getColumnByName(pkColumnName);
- }
- if (logger.isDebugEnabled()) {
- logger.debug("Found primary key relation: tableName=" + pkTableName + ",columnName=" + pkColumnName
- + ", matching column: " + pkColumn);
- }
-
- String fkTableName = rs.getString(7);
- String fkColumnName = rs.getString(8);
- Column fkColumn = null;
- Table fkTable = schema.getTableByName(fkTableName);
- if (fkTable != null) {
- fkColumn = fkTable.getColumnByName(fkColumnName);
- }
- if (logger.isDebugEnabled()) {
- logger.debug("Found foreign key relation: tableName=" + fkTableName + ",columnName=" + fkColumnName
- + ", matching column: " + fkColumn);
- }
-
- if (pkColumn == null || fkColumn == null) {
- logger.error(
- "Could not find relation columns: pkTableName={},pkColumnName={},fkTableName={},fkColumnName={}",
- new Object[] { pkTableName, pkColumnName, fkTableName, fkColumnName });
- logger.error("pkColumn={}", pkColumn);
- logger.error("fkColumn={}", fkColumn);
- } else {
- MutableRelationship.createRelationship(new Column[] { pkColumn }, new Column[] { fkColumn });
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcSchema.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcSchema.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcSchema.java
deleted file mode 100644
index 28285f4..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/JdbcSchema.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * 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.jdbc;
-
-import java.io.ObjectStreamException;
-
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Schema;
-
-/**
- * Schema implementation for JDBC data contexts
- *
- * @author Kasper Sørensen
- */
-final class JdbcSchema extends MutableSchema {
-
- private static final long serialVersionUID = 7543633400859277467L;
- private transient MetadataLoader _metadataLoader;
-
- public JdbcSchema(String name, MetadataLoader metadataLoader) {
- super(name);
- _metadataLoader = metadataLoader;
- }
-
- protected void refreshTables() {
- if (_metadataLoader != null) {
- _metadataLoader.loadTables(this);
- }
- }
-
- public void loadRelations() {
- if (_metadataLoader != null) {
- _metadataLoader.loadRelations(this);
- }
- }
-
- public Schema toSerializableForm() {
- MutableTable[] tables = getTables();
- for (MutableTable table : tables) {
- table.getColumns();
- table.getIndexedColumns();
- table.getPrimaryKeys();
- }
- loadRelations();
- return this;
- }
-
- /**
- * Called by the Java Serialization API to serialize the object.
- */
- private Object writeReplace() throws ObjectStreamException {
- return toSerializableForm();
- }
-}
\ No newline at end of file
[23/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/BooleanComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/BooleanComparatorTest.java b/core/src/test/java/org/apache/metamodel/util/BooleanComparatorTest.java
new file mode 100644
index 0000000..1c099fd
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/BooleanComparatorTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.util;
+
+import java.util.Comparator;
+
+import junit.framework.TestCase;
+
+public class BooleanComparatorTest extends TestCase {
+
+ public void testCompare() throws Exception {
+ Comparator<Object> c = BooleanComparator.getComparator();
+ assertEquals(1, c.compare(true, false));
+ assertEquals(-1, c.compare(false, true));
+ assertEquals(0, c.compare(true, true));
+ assertEquals(0, c.compare(false, false));
+
+ assertEquals(1, c.compare("true", "false"));
+ assertEquals(1, c.compare("1", "false"));
+ assertEquals(1, c.compare("true", "0"));
+ assertEquals(1, c.compare("true", "false"));
+
+ assertEquals(1, c.compare(1, 0));
+
+ assertEquals(1, c.compare(1, "false"));
+ assertEquals(1, c.compare("yes", false));
+ assertEquals(1, c.compare("y", false));
+ assertEquals(1, c.compare("TRUE", false));
+ }
+
+ public void testComparable() throws Exception {
+ Comparable<Object> comparable = BooleanComparator.getComparable(true);
+ assertEquals(1, comparable.compareTo(false));
+ assertEquals(1, comparable.compareTo(0));
+ assertEquals(1, comparable.compareTo("false"));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/ClasspathResourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/ClasspathResourceTest.java b/core/src/test/java/org/apache/metamodel/util/ClasspathResourceTest.java
new file mode 100644
index 0000000..3936092
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/ClasspathResourceTest.java
@@ -0,0 +1,46 @@
+/**
+ * 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.util;
+
+import java.io.InputStream;
+
+import junit.framework.TestCase;
+
+public class ClasspathResourceTest extends TestCase {
+
+ public void testGetName() throws Exception {
+ ClasspathResource resource = new ClasspathResource("folder/foo");
+ assertEquals("foo", resource.getName());
+ assertTrue(resource.isExists());
+ assertTrue(resource.isReadOnly());
+
+ resource = new ClasspathResource("/folder/foo");
+ assertEquals("foo", resource.getName());
+ assertTrue(resource.isExists());
+ assertTrue(resource.isReadOnly());
+
+ String result = resource.read(new Func<InputStream, String>() {
+ @Override
+ public String eval(InputStream inputStream) {
+ return FileHelper.readInputStreamAsString(inputStream, "UTF8");
+ }
+ });
+ assertEquals("bar-baz", result);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/CollectionUtilsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/CollectionUtilsTest.java b/core/src/test/java/org/apache/metamodel/util/CollectionUtilsTest.java
new file mode 100644
index 0000000..d3c5ebf
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/CollectionUtilsTest.java
@@ -0,0 +1,128 @@
+/**
+ * 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.util;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public class CollectionUtilsTest extends TestCase {
+
+ public void testArray1() throws Exception {
+ String[] result = CollectionUtils.array(new String[] { "foo", "bar" },
+ "hello", "world");
+ assertEquals("[foo, bar, hello, world]", Arrays.toString(result));
+ }
+
+ public void testArray2() throws Exception {
+ Object[] existingArray = new Object[] { 'c' };
+ Object[] result = CollectionUtils.array(existingArray, "foo", 1, "bar");
+
+ assertEquals("[c, foo, 1, bar]", Arrays.toString(result));
+ }
+
+ public void testConcat() throws Exception {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("hello");
+ list1.add("hello");
+ list1.add("world");
+ List<String> list2 = new ArrayList<String>();
+ list2.add("howdy");
+ list2.add("world");
+ List<String> list3 = new ArrayList<String>();
+ list3.add("hi");
+ list3.add("world");
+
+ List<String> result = CollectionUtils.concat(true, list1, list2, list3);
+ assertEquals("[hello, world, howdy, hi]", result.toString());
+ assertEquals(4, result.size());
+
+ result = CollectionUtils.concat(false, list1, list2, list3);
+ assertEquals("[hello, hello, world, howdy, world, hi, world]",
+ result.toString());
+ assertEquals(7, result.size());
+ }
+
+ public void testMap() throws Exception {
+ List<String> strings = new ArrayList<String>();
+ strings.add("hi");
+ strings.add("world");
+
+ List<Integer> ints = CollectionUtils.map(strings,
+ new Func<String, Integer>() {
+ @Override
+ public Integer eval(String arg) {
+ return arg.length();
+ }
+ });
+ assertEquals("[2, 5]", ints.toString());
+ }
+
+ public void testFilter() throws Exception {
+ List<String> list = new ArrayList<String>();
+ list.add("foo");
+ list.add("bar");
+ list.add("3");
+ list.add("2");
+
+ list = CollectionUtils.filter(list, new Predicate<String>() {
+ @Override
+ public Boolean eval(String arg) {
+ return arg.length() > 1;
+ }
+ });
+
+ assertEquals(2, list.size());
+ assertEquals("[foo, bar]", list.toString());
+ }
+
+ public void testArrayRemove() throws Exception {
+ String[] arr = new String[] { "a", "b", "c", "d", "e" };
+ arr = CollectionUtils.arrayRemove(arr, "c");
+ assertEquals("[a, b, d, e]", Arrays.toString(arr));
+
+ arr = CollectionUtils.arrayRemove(arr, "e");
+ assertEquals("[a, b, d]", Arrays.toString(arr));
+
+ arr = CollectionUtils.arrayRemove(arr, "e");
+ assertEquals("[a, b, d]", Arrays.toString(arr));
+
+ arr = CollectionUtils.arrayRemove(arr, "a");
+ assertEquals("[b, d]", Arrays.toString(arr));
+ }
+
+ public void testToList() throws Exception {
+ assertTrue(CollectionUtils.toList(null).isEmpty());
+ assertEquals("[foo]", CollectionUtils.toList("foo").toString());
+ assertEquals("[foo, bar]",
+ CollectionUtils.toList(new String[] { "foo", "bar" })
+ .toString());
+
+ List<Integer> ints = Arrays.asList(1, 2, 3);
+ assertSame(ints, CollectionUtils.toList(ints));
+
+ assertEquals("[1, 2, 3]", CollectionUtils.toList(ints.iterator())
+ .toString());
+ assertEquals("[1, 2, 3]",
+ CollectionUtils.toList(new HashSet<Integer>(ints)).toString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/DateUtilsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/DateUtilsTest.java b/core/src/test/java/org/apache/metamodel/util/DateUtilsTest.java
new file mode 100644
index 0000000..b1bd885
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/DateUtilsTest.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.util;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import junit.framework.TestCase;
+
+public class DateUtilsTest extends TestCase {
+
+ public void testGet() throws Exception {
+ SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+ Date christmasDay = DateUtils.get(2010, Month.DECEMBER, 24);
+ assertEquals("2010-12-24 00:00:00", f.format(christmasDay));
+ assertEquals(Weekday.FRIDAY, DateUtils.getWeekday(christmasDay));
+
+ Date date2 = DateUtils.get(christmasDay, 1);
+ assertEquals("2010-12-25 00:00:00", f.format(date2));
+
+ Date date3 = DateUtils.get(christmasDay, 10);
+ assertEquals("2011-01-03 00:00:00", f.format(date3));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/EqualsBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/EqualsBuilderTest.java b/core/src/test/java/org/apache/metamodel/util/EqualsBuilderTest.java
new file mode 100644
index 0000000..78649a8
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/EqualsBuilderTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.util;
+
+import junit.framework.TestCase;
+
+public class EqualsBuilderTest extends TestCase {
+
+ public void testEquals() throws Exception {
+ assertTrue(EqualsBuilder.equals(null, null));
+ assertTrue(EqualsBuilder.equals("hello", "hello"));
+ assertFalse(EqualsBuilder.equals("hello", null));
+ assertFalse(EqualsBuilder.equals(null, "hello"));
+ assertFalse(EqualsBuilder.equals("world", "hello"));
+
+ MyCloneable o1 = new MyCloneable();
+ assertTrue(EqualsBuilder.equals(o1, o1));
+ MyCloneable o2 = o1.clone();
+ assertFalse(EqualsBuilder.equals(o1, o2));
+ }
+
+ static final class MyCloneable implements Cloneable {
+ @Override
+ public boolean equals(Object obj) {
+ return false;
+ }
+
+ @Override
+ public MyCloneable clone() {
+ try {
+ return (MyCloneable) super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new UnsupportedOperationException();
+ }
+ }
+ };
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/ExclusionPredicateTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/ExclusionPredicateTest.java b/core/src/test/java/org/apache/metamodel/util/ExclusionPredicateTest.java
new file mode 100644
index 0000000..f2d9237
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/ExclusionPredicateTest.java
@@ -0,0 +1,36 @@
+/**
+ * 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.util;
+
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+public class ExclusionPredicateTest extends TestCase {
+
+ public void testEval() throws Exception {
+ ExclusionPredicate<String> predicate = new ExclusionPredicate<String>(Arrays.asList("foo","bar","baz"));
+
+ assertFalse(predicate.eval("foo"));
+ assertFalse(predicate.eval("bar"));
+ assertFalse(predicate.eval("baz"));
+
+ assertTrue(predicate.eval("hello world"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/FileHelperTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/FileHelperTest.java b/core/src/test/java/org/apache/metamodel/util/FileHelperTest.java
new file mode 100644
index 0000000..f51553f
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/FileHelperTest.java
@@ -0,0 +1,78 @@
+/**
+ * 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.util;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+public class FileHelperTest extends TestCase {
+
+ public void testGetTempDir() throws Exception {
+ File tempDir = FileHelper.getTempDir();
+ String property = System.getProperty("java.io.tmpdir");
+ assertEquals(normalize(property), normalize(tempDir.getPath()));
+ }
+
+ private String normalize(String path) {
+ if (path == null) {
+ return null;
+ }
+ if (path.endsWith(File.separator)) {
+ path = path.substring(0, path.length() - 1);
+ }
+ return path;
+ }
+
+ public void testWriteAndRead() throws Exception {
+ File file = new File("target/tmp/FileHelperTest.testWriteAndRead.txt");
+ if (file.exists()) {
+ file.delete();
+ }
+ file.getParentFile().mkdirs();
+ assertTrue(file.createNewFile());
+ FileHelper.writeStringAsFile(file, "foo\nbar");
+ String content = FileHelper.readFileAsString(file);
+ assertEquals("foo\nbar", content);
+ assertTrue(file.delete());
+ }
+
+ public void testByteOrderMarksInputStream() throws Exception {
+ String str1 = FileHelper.readFileAsString(new File("src/test/resources/unicode-text-utf16.txt"));
+ assertEquals("hello", str1);
+
+ String str2 = FileHelper.readFileAsString(new File("src/test/resources/unicode-text-utf8.txt"));
+ assertEquals(str1, str2);
+
+ String str3 = FileHelper.readFileAsString(new File("src/test/resources/unicode-text-utf16le.txt"));
+ assertEquals(str2, str3);
+
+ String str4 = FileHelper.readFileAsString(new File("src/test/resources/unicode-text-utf16be.txt"));
+ assertEquals(str3, str4);
+ }
+
+ public void testCannotAppendAndInsertBom() throws Exception {
+ try {
+ FileHelper.getWriter(new File("foo"), "foo", true, true);
+ fail("Exception expected");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Can not insert BOM into appending writer", e.getMessage());
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/FormatHelperTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/FormatHelperTest.java b/core/src/test/java/org/apache/metamodel/util/FormatHelperTest.java
new file mode 100644
index 0000000..eebe345
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/FormatHelperTest.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.util;
+
+import java.text.NumberFormat;
+import java.util.Arrays;
+
+import org.eobjects.metamodel.schema.ColumnType;
+
+import junit.framework.TestCase;
+
+public class FormatHelperTest extends TestCase {
+
+ public void testNumberFormat() throws Exception {
+ NumberFormat format = FormatHelper.getUiNumberFormat();
+ assertEquals("987643.21", format.format(987643.213456343));
+ assertEquals("0.22", format.format(0.218456343));
+ assertEquals("20.1", format.format(20.1));
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testFormatSqlValue() throws Exception {
+ assertEquals("'foo'", FormatHelper.formatSqlValue(null, "foo"));
+ assertEquals("1", FormatHelper.formatSqlValue(null, 1));
+ assertEquals("NULL", FormatHelper.formatSqlValue(null, null));
+ assertEquals(
+ "TIMESTAMP '2011-07-24 00:00:00'",
+ FormatHelper.formatSqlValue(ColumnType.TIMESTAMP,
+ DateUtils.get(2011, Month.JULY, 24)));
+ assertEquals(
+ "DATE '2011-07-24'",
+ FormatHelper.formatSqlValue(ColumnType.DATE,
+ DateUtils.get(2011, Month.JULY, 24)));
+ assertEquals(
+ "TIME '00:00:00'",
+ FormatHelper.formatSqlValue(ColumnType.TIME,
+ DateUtils.get(2011, Month.JULY, 24)));
+ assertEquals(
+ "('foo' , 1 , 'bar' , 0.1234)",
+ FormatHelper.formatSqlValue(null,
+ Arrays.asList("foo", 1, "bar", 0.1234)));
+ assertEquals(
+ "('foo' , 1 , 'bar' , 0.1234)",
+ FormatHelper.formatSqlValue(null, new Object[] { "foo", 1,
+ "bar", 0.1234 }));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/InMemoryResourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/InMemoryResourceTest.java b/core/src/test/java/org/apache/metamodel/util/InMemoryResourceTest.java
new file mode 100644
index 0000000..d6cc1e6
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/InMemoryResourceTest.java
@@ -0,0 +1,79 @@
+/**
+ * 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.util;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import junit.framework.TestCase;
+
+public class InMemoryResourceTest extends TestCase {
+
+ public void testScenario() throws Exception {
+ InMemoryResource r = new InMemoryResource("foo/bar");
+ assertEquals("bar", r.getName());
+ assertEquals(-1, r.getLastModified());
+ assertEquals(0, r.getSize());
+ assertFalse(r.isReadOnly());
+ assertTrue(r.isExists());
+
+ r.write(new Action<OutputStream>() {
+ @Override
+ public void run(OutputStream out) throws Exception {
+ out.write(1);
+ out.write(2);
+ out.write(3);
+ }
+ });
+
+ assertEquals(3, r.getSize());
+
+ r.read(new Action<InputStream>() {
+ @Override
+ public void run(InputStream in) throws Exception {
+ assertEquals(1, in.read());
+ assertEquals(2, in.read());
+ assertEquals(3, in.read());
+ assertEquals(-1, in.read());
+ }
+ });
+
+ r.append(new Action<OutputStream>() {
+ @Override
+ public void run(OutputStream out) throws Exception {
+ out.write(4);
+ out.write(5);
+ out.write(6);
+ }
+ });
+
+ r.read(new Action<InputStream>() {
+ @Override
+ public void run(InputStream in) throws Exception {
+ assertEquals(1, in.read());
+ assertEquals(2, in.read());
+ assertEquals(3, in.read());
+ assertEquals(4, in.read());
+ assertEquals(5, in.read());
+ assertEquals(6, in.read());
+ assertEquals(-1, in.read());
+ }
+ });
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/InclusionPredicateTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/InclusionPredicateTest.java b/core/src/test/java/org/apache/metamodel/util/InclusionPredicateTest.java
new file mode 100644
index 0000000..0225aff
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/InclusionPredicateTest.java
@@ -0,0 +1,36 @@
+/**
+ * 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.util;
+
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+public class InclusionPredicateTest extends TestCase {
+
+ public void testEval() throws Exception {
+ InclusionPredicate<String> predicate = new InclusionPredicate<String>(Arrays.asList("foo","bar","baz"));
+
+ assertTrue(predicate.eval("foo"));
+ assertTrue(predicate.eval("bar"));
+ assertTrue(predicate.eval("baz"));
+
+ assertFalse(predicate.eval("hello world"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/LazyRefTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/LazyRefTest.java b/core/src/test/java/org/apache/metamodel/util/LazyRefTest.java
new file mode 100644
index 0000000..f68fb96
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/LazyRefTest.java
@@ -0,0 +1,91 @@
+/**
+ * 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.util;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import junit.framework.TestCase;
+
+public class LazyRefTest extends TestCase {
+
+ public void testRequestLoad() throws Exception {
+ LazyRef<Integer> lazyRef = new LazyRef<Integer>() {
+ private final AtomicInteger counter = new AtomicInteger();
+
+ @Override
+ protected Integer fetch() {
+ return counter.incrementAndGet();
+ }
+ };
+
+ lazyRef.requestLoad();
+ Thread.sleep(20);
+ Integer integer = lazyRef.get();
+ assertEquals(1, integer.intValue());
+ }
+
+ public void testErrorHandling() throws Exception {
+ LazyRef<Object> ref = new LazyRef<Object>() {
+ @Override
+ protected Object fetch() throws Throwable {
+ throw new Exception("foo");
+ }
+ };
+
+ assertNull(ref.get());
+ assertEquals("foo", ref.getError().getMessage());
+
+ // now with a runtime exception (retain previous behaviour in this
+ // regard)
+ ref = new LazyRef<Object>() {
+ @Override
+ protected Object fetch() throws Throwable {
+ throw new IllegalStateException("bar");
+ }
+ };
+
+ try {
+ ref.get();
+ fail("Exception expected");
+ } catch (IllegalStateException e) {
+ assertEquals("bar", e.getMessage());
+ }
+ }
+
+ public void testGet() throws Exception {
+ final AtomicInteger counter = new AtomicInteger();
+ LazyRef<String> lazyRef = new LazyRef<String>() {
+ @Override
+ protected String fetch() {
+ counter.incrementAndGet();
+ return "foo";
+ }
+ };
+
+ assertFalse(lazyRef.isFetched());
+ assertEquals(0, counter.get());
+
+ assertEquals("foo", lazyRef.get());
+ assertEquals("foo", lazyRef.get());
+ assertEquals("foo", lazyRef.get());
+
+ assertTrue(lazyRef.isFetched());
+ assertEquals(1, counter.get());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/MonthTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/MonthTest.java b/core/src/test/java/org/apache/metamodel/util/MonthTest.java
new file mode 100644
index 0000000..b70de17
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/MonthTest.java
@@ -0,0 +1,38 @@
+/**
+ * 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.util;
+
+import junit.framework.TestCase;
+
+public class MonthTest extends TestCase {
+
+ public void testGetName() throws Exception {
+ assertEquals("December", Month.DECEMBER.getName());
+ }
+
+ public void testNext() throws Exception {
+ assertEquals(Month.APRIL, Month.MARCH.next());
+ assertEquals(Month.JANUARY, Month.DECEMBER.next());
+ }
+
+ public void testPrevious() throws Exception {
+ assertEquals(Month.FEBRUARY, Month.MARCH.previous());
+ assertEquals(Month.DECEMBER, Month.JANUARY.previous());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/NumberComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/NumberComparatorTest.java b/core/src/test/java/org/apache/metamodel/util/NumberComparatorTest.java
new file mode 100644
index 0000000..211c967
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/NumberComparatorTest.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.util;
+
+import java.util.Comparator;
+
+import junit.framework.TestCase;
+
+public class NumberComparatorTest extends TestCase {
+
+ public void testDoubleAndIntegerComparison() throws Exception {
+ Comparator<Object> comparator = NumberComparator.getComparator();
+ assertEquals(0, comparator.compare(1, 1.0));
+ }
+
+ public void testComparable() throws Exception {
+ Comparable<Object> comparable = NumberComparator.getComparable("125");
+ assertEquals(0, comparable.compareTo(125));
+ assertEquals(-1, comparable.compareTo(126));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/ObjectComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/ObjectComparatorTest.java b/core/src/test/java/org/apache/metamodel/util/ObjectComparatorTest.java
new file mode 100644
index 0000000..925318c
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/ObjectComparatorTest.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.util;
+
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.TreeSet;
+
+import junit.framework.TestCase;
+
+public class ObjectComparatorTest extends TestCase {
+
+ public void testString() throws Exception {
+ Comparator<Object> c = ObjectComparator.getComparator();
+ assertTrue(c.compare("aaaa", "bbbb") < 0);
+
+ assertTrue(c.compare("w", "y") < 0);
+ }
+
+ public void testComparable() throws Exception {
+ Comparable<Object> comparable = ObjectComparator.getComparable("aaaa");
+ assertEquals(-1, comparable.compareTo("bbbb"));
+ }
+
+ public void testNull() throws Exception {
+ Comparator<Object> comparator = ObjectComparator.getComparator();
+ assertEquals(0, comparator.compare(null, null));
+ assertEquals(1, comparator.compare("h", null));
+ assertEquals(-1, comparator.compare(null, "h"));
+
+ TreeSet<Object> set = new TreeSet<Object>(comparator);
+ set.add("Hello");
+ set.add(null);
+ set.add(null);
+ set.add(DateUtils.get(2010, Month.SEPTEMBER, 27));
+ set.add(DateUtils.get(2010, Month.SEPTEMBER, 28));
+ set.add(DateUtils.get(2010, Month.SEPTEMBER, 26));
+
+ assertEquals(5, set.size());
+ Iterator<Object> it = set.iterator();
+ assertEquals(null, it.next());
+ assertEquals("Hello", it.next());
+ assertEquals(DateUtils.get(2010, Month.SEPTEMBER, 26), it.next());
+ assertEquals(DateUtils.get(2010, Month.SEPTEMBER, 27), it.next());
+ assertEquals(DateUtils.get(2010, Month.SEPTEMBER, 28), it.next());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/SerializableRefTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/SerializableRefTest.java b/core/src/test/java/org/apache/metamodel/util/SerializableRefTest.java
new file mode 100644
index 0000000..2d32e54
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/SerializableRefTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.StringTokenizer;
+
+import junit.framework.TestCase;
+
+public class SerializableRefTest extends TestCase {
+
+ public void testSerialize() throws Exception {
+ SerializableRef<String> ref = new SerializableRef<String>("Foobar");
+ assertNotNull(ref.get());
+
+ SerializableRef<String> copy = copy(ref);
+ assertEquals("Foobar", copy.get());
+ }
+
+ public void testDontSerialize() throws Exception {
+ SerializableRef<StringTokenizer> ref = new SerializableRef<StringTokenizer>(new StringTokenizer("foobar"));
+ assertNotNull(ref.get());
+
+ SerializableRef<StringTokenizer> copy = copy(ref);
+ assertNull(copy.get());
+ }
+
+ @SuppressWarnings("unchecked")
+ private <E> SerializableRef<E> copy(SerializableRef<E> ref) throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream os = new ObjectOutputStream(baos);
+ os.writeObject(ref);
+ os.flush();
+ os.close();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ObjectInputStream is = new ObjectInputStream(bais);
+ Object obj = is.readObject();
+ is.close();
+ return (SerializableRef<E>) obj;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/SimpleRefTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/SimpleRefTest.java b/core/src/test/java/org/apache/metamodel/util/SimpleRefTest.java
new file mode 100644
index 0000000..fcc89c3
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/SimpleRefTest.java
@@ -0,0 +1,35 @@
+/**
+ * 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.util;
+
+import junit.framework.TestCase;
+
+public class SimpleRefTest extends TestCase {
+
+ public void testGet() throws Exception {
+ Ref<String> lazyRef = new ImmutableRef<String>("foo");
+
+ assertEquals("foo", lazyRef.get());
+
+ lazyRef = ImmutableRef.of("foo");
+
+ assertEquals("foo", lazyRef.get());
+ assertEquals("foo", lazyRef.get());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/TimeComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/TimeComparatorTest.java b/core/src/test/java/org/apache/metamodel/util/TimeComparatorTest.java
new file mode 100644
index 0000000..4b43dcb
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/TimeComparatorTest.java
@@ -0,0 +1,79 @@
+/**
+ * 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.util;
+
+import java.text.DateFormat;
+import java.util.Comparator;
+import java.util.Date;
+
+import junit.framework.TestCase;
+
+public class TimeComparatorTest extends TestCase {
+
+ public void testCompare() throws Exception {
+ Comparator<Object> c = TimeComparator.getComparator();
+ Date d1 = new Date();
+ Thread.sleep(100);
+ Date d2 = new Date();
+ assertEquals(0, c.compare(d1, d1));
+ assertEquals(-1, c.compare(d1, d2));
+ assertEquals(1, c.compare(d2, d1));
+
+ assertEquals(1, c.compare(d2, "2005-10-08"));
+ assertEquals(1, c.compare("2006-11-09", "2005-10-08"));
+ }
+
+ public void testComparable() throws Exception {
+ Comparable<Object> comparable = TimeComparator
+ .getComparable(new Date());
+ Thread.sleep(100);
+ assertEquals(-1, comparable.compareTo(new Date()));
+ }
+
+ public void testToDate() throws Exception {
+ DateFormat dateFormat = DateUtils
+ .createDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+
+ assertEquals("2008-11-04 00:00:00.000",
+ dateFormat.format(TimeComparator.toDate("08-11-04")));
+
+ assertEquals("2010-09-21 14:06:00.000",
+ dateFormat.format(TimeComparator.toDate("2010-09-21 14:06")));
+
+ assertEquals("2010-09-21 14:06:13.000",
+ dateFormat.format(TimeComparator.toDate("2010-09-21 14:06:13")));
+
+ assertEquals("2010-09-21 14:06:13.009",
+ dateFormat.format(TimeComparator
+ .toDate("2010-09-21 14:06:13.009")));
+
+ assertEquals("2000-12-31 02:30:05.100",
+ dateFormat.format(TimeComparator
+ .toDate("2000-12-31 02:30:05.100")));
+ }
+
+ public void testToDateOfDateToString() throws Exception {
+ Date date = new Date();
+ String dateString = date.toString();
+ Date convertedDate = TimeComparator.toDate(dateString);
+
+ String convertedToString = convertedDate.toString();
+ assertEquals(dateString, convertedToString);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/ToStringComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/ToStringComparatorTest.java b/core/src/test/java/org/apache/metamodel/util/ToStringComparatorTest.java
new file mode 100644
index 0000000..684c714
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/ToStringComparatorTest.java
@@ -0,0 +1,51 @@
+/**
+ * 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.util;
+
+import java.util.Comparator;
+
+import junit.framework.TestCase;
+import org.eobjects.metamodel.util.ToStringComparator;
+
+public class ToStringComparatorTest extends TestCase {
+
+ private Comparator<Object> comparator = ToStringComparator.getComparator();
+
+ public void testNotNull() throws Exception {
+ assertEquals(4, comparator.compare("foo", "bar"));
+ assertEquals(-4, comparator.compare("bar", "foo"));
+ }
+
+ public void testNull() throws Exception {
+ int result = comparator.compare(null, null);
+ assertEquals(-1, result);
+
+ result = comparator.compare(1, null);
+ assertEquals(1, result);
+
+ result = comparator.compare(null, 1);
+ assertEquals(-1, result);
+ }
+
+ public void testComparable() throws Exception {
+ Comparable<Object> comparable = ToStringComparator
+ .getComparable("aaaa");
+ assertEquals(-1, comparable.compareTo("bbbb"));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/UrlResourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/UrlResourceTest.java b/core/src/test/java/org/apache/metamodel/util/UrlResourceTest.java
new file mode 100644
index 0000000..43e6523
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/UrlResourceTest.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.util;
+
+import junit.framework.TestCase;
+
+public class UrlResourceTest extends TestCase {
+
+ public void testGetName() throws Exception {
+ UrlResource resource = new UrlResource("http://eobjects.org/foo.txt");
+ assertEquals("foo.txt", resource.getName());
+
+ resource = new UrlResource("http://eobjects.org/");
+ assertEquals("http://eobjects.org/", resource.getName());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/WeekdayTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/WeekdayTest.java b/core/src/test/java/org/apache/metamodel/util/WeekdayTest.java
new file mode 100644
index 0000000..1f92320
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/WeekdayTest.java
@@ -0,0 +1,38 @@
+/**
+ * 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.util;
+
+import junit.framework.TestCase;
+
+public class WeekdayTest extends TestCase {
+
+ public void testGetName() throws Exception {
+ assertEquals("Monday", Weekday.MONDAY.getName());
+ }
+
+ public void testNext() throws Exception {
+ assertEquals(Weekday.TUESDAY, Weekday.MONDAY.next());
+ assertEquals(Weekday.MONDAY, Weekday.SUNDAY.next());
+ }
+
+ public void testPrevious() throws Exception {
+ assertEquals(Weekday.SUNDAY, Weekday.MONDAY.previous());
+ assertEquals(Weekday.SATURDAY, Weekday.SUNDAY.previous());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/util/WildcardPatternTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/WildcardPatternTest.java b/core/src/test/java/org/apache/metamodel/util/WildcardPatternTest.java
new file mode 100644
index 0000000..13da97b
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/util/WildcardPatternTest.java
@@ -0,0 +1,45 @@
+/**
+ * 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.util;
+
+import junit.framework.TestCase;
+
+public class WildcardPatternTest extends TestCase {
+
+ public void testMatches() throws Exception {
+ WildcardPattern pattern = new WildcardPattern("foo%bar", '%');
+ assertTrue(pattern.matches("foobar"));
+ assertTrue(pattern.matches("foofoobar"));
+ assertFalse(pattern.matches("foobarbar"));
+ assertFalse(pattern.matches("w00p"));
+
+ pattern = new WildcardPattern("*foo*bar", '*');
+ assertTrue(pattern.matches("foobar"));
+ assertTrue(pattern.matches("foofoobar"));
+ assertFalse(pattern.matches("foobarbar"));
+ assertFalse(pattern.matches("w00p"));
+
+ pattern = new WildcardPattern("foo%bar%", '%');
+ assertTrue(pattern.matches("foobar"));
+ assertTrue(pattern.matches("foofoobar"));
+ assertTrue(pattern.matches("foobarbar"));
+ assertFalse(pattern.matches("w00p"));
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/AbstractDataContextTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/AbstractDataContextTest.java b/core/src/test/java/org/eobjects/metamodel/AbstractDataContextTest.java
deleted file mode 100644
index 4320a5b..0000000
--- a/core/src/test/java/org/eobjects/metamodel/AbstractDataContextTest.java
+++ /dev/null
@@ -1,247 +0,0 @@
-/**
- * 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;
-
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-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.Table;
-
-public class AbstractDataContextTest extends TestCase {
-
- private class MyDataContext extends AbstractDataContext {
- @Override
- public DataSet executeQuery(Query query) throws MetaModelException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected String[] getSchemaNamesInternal() {
- return new String[] { "barfoo", "foobar", "foo.bar" };
- }
-
- @Override
- protected String getDefaultSchemaName() {
- return "foobar";
- }
-
- @Override
- protected Schema getSchemaByNameInternal(String name) {
- if ("barfoo".equals(name) || "foobar".equals(name)
- || "foo.bar".equals(name)) {
- return createSchema(name);
- }
- throw new IllegalStateException("No such schema: " + name);
- }
-
- private Schema createSchema(String name) {
- MutableSchema schema = new MutableSchema(name);
- MutableTable t1 = new MutableTable("table");
- MutableColumn col1 = new MutableColumn("col1");
- MutableColumn col2 = new MutableColumn("col2");
- t1.addColumn(col1).addColumn(col2);
- col1.setTable(t1);
- col2.setTable(t1);
- MutableTable t2 = new MutableTable("tab.le");
- MutableColumn col3 = new MutableColumn("col3");
- MutableColumn col4 = new MutableColumn("col4");
- t2.addColumn(col3).addColumn(col4);
- col3.setTable(t2);
- col4.setTable(t2);
- schema.addTable(t1).addTable(t2);
- t1.setSchema(schema);
- t2.setSchema(schema);
- return schema;
- }
-
- }
-
-
- public void testGetColumnByQualifiedLabel() throws Exception {
- MyDataContext dc = new MyDataContext();
- Column result;
-
- result = dc.getColumnByQualifiedLabel("foobar.tab.le.col1");
- result = dc.getColumnByQualifiedLabel("blabla.tab.le.col4");
- result = dc.getColumnByQualifiedLabel("FOOBAR.TABLE.COL3");
- assertNull(result);
-
- result = dc.getColumnByQualifiedLabel("foobar.table.col1");
- assertEquals("col1", result.getName());
- assertEquals("table", result.getTable().getName());
- assertEquals("foobar", result.getTable().getSchema().getName());
-
- result = dc.getColumnByQualifiedLabel("foo.bar.table.col1");
- assertEquals("col1", result.getName());
- assertEquals("table", result.getTable().getName());
- assertEquals("foo.bar", result.getTable().getSchema().getName());
-
- result = dc.getColumnByQualifiedLabel("foobar.tab.le.col3");
- assertEquals("col3", result.getName());
- assertEquals("tab.le", result.getTable().getName());
- assertEquals("foobar", result.getTable().getSchema().getName());
-
- result = dc.getColumnByQualifiedLabel("FOO.BAR.tab.le.col3");
- assertEquals("col3", result.getName());
- assertEquals("tab.le", result.getTable().getName());
- assertEquals("foo.bar", result.getTable().getSchema().getName());
-
- result = dc.getColumnByQualifiedLabel("tab.le.col3");
- assertEquals("col3", result.getName());
- assertEquals("tab.le", result.getTable().getName());
- assertEquals("foobar", result.getTable().getSchema().getName());
- }
-
- public void testGetTableByQualfiedLabelSchemaNameInTableName() throws Exception {
- AbstractDataContext dc = new AbstractDataContext() {
- @Override
- public DataSet executeQuery(Query query) throws MetaModelException {
- return null;
- }
-
- @Override
- protected String[] getSchemaNamesInternal() {
- return new String[] {"test"};
- }
-
- @Override
- protected Schema getSchemaByNameInternal(String name) {
- MutableSchema sch = new MutableSchema("test");
- sch.addTable(new MutableTable("test_table1").setSchema(sch));
- sch.addTable(new MutableTable("test_table2").setSchema(sch));
- sch.addTable(new MutableTable("test_table3").setSchema(sch));
- return sch;
- }
-
- @Override
- protected String getDefaultSchemaName() {
- return "test";
- }
- };
-
- assertEquals("test_table1", dc.getTableByQualifiedLabel("test_table1").getName());
- assertEquals("test_table2", dc.getTableByQualifiedLabel("test_table2").getName());
- assertEquals("test_table3", dc.getTableByQualifiedLabel("test_table3").getName());
- }
-
- public void testGetTableByQualifiedLabel() throws Exception {
- MyDataContext dc = new MyDataContext();
-
- Table result;
-
- result = dc.getTableByQualifiedLabel("FOOBAR.table");
- assertEquals("table", result.getName());
- assertEquals("foobar", result.getSchema().getName());
-
- result = dc.getTableByQualifiedLabel("table");
- assertEquals("table", result.getName());
- assertEquals("foobar", result.getSchema().getName());
-
- result = dc.getTableByQualifiedLabel("foo.bar.table");
- assertEquals("table", result.getName());
- assertEquals("foo.bar", result.getSchema().getName());
-
- result = dc.getTableByQualifiedLabel("foobar.tab.le");
- assertEquals("tab.le", result.getName());
- assertEquals("foobar", result.getSchema().getName());
-
- result = dc.getTableByQualifiedLabel("foo.bar.tab.le");
- assertEquals("tab.le", result.getName());
- assertEquals("foo.bar", result.getSchema().getName());
-
- result = dc.getTableByQualifiedLabel("foo.table");
- assertNull(result);
- }
-
- public void testGetSchemas() throws Exception {
- MyDataContext dc = new MyDataContext();
- Schema[] schemas = dc.getSchemas();
- assertEquals(
- "[Schema[name=barfoo], Schema[name=foo.bar], Schema[name=foobar]]",
- Arrays.toString(schemas));
-
- dc.refreshSchemas();
- schemas = dc.getSchemas();
- assertEquals(
- "[Schema[name=barfoo], Schema[name=foo.bar], Schema[name=foobar]]",
- Arrays.toString(schemas));
- }
-
- public void testGetColumnByQualifiedLabelWithNameOverlaps()
- throws Exception {
- AbstractDataContext dc = new AbstractDataContext() {
-
- @Override
- public DataSet executeQuery(Query query) throws MetaModelException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected String[] getSchemaNamesInternal() {
- return new String[] { "sch" };
- }
-
- @Override
- protected Schema getSchemaByNameInternal(String name) {
- MutableSchema schema = new MutableSchema("sch");
- MutableTable table1 = new MutableTable("tab");
- MutableTable table2 = new MutableTable("tab_le");
- MutableTable table3 = new MutableTable("table");
- MutableTable table4 = new MutableTable("tabl_e");
- schema.addTable(table1.addColumn(new MutableColumn("col")
- .setTable(table1)));
- schema.addTable(table2.addColumn(new MutableColumn("col")
- .setTable(table2)));
- schema.addTable(table3.addColumn(new MutableColumn("col")
- .setTable(table3)));
- schema.addTable(table4.addColumn(new MutableColumn("col")
- .setTable(table4)));
- return schema;
- }
-
- @Override
- protected String getDefaultSchemaName() {
- return "sch";
- }
- };
-
- assertEquals("tab.col", dc.getColumnByQualifiedLabel("sch.tab.col")
- .getQualifiedLabel());
- assertEquals("table.col", dc.getColumnByQualifiedLabel("sch.table.col")
- .getQualifiedLabel());
- assertEquals("tab_le.col", dc.getColumnByQualifiedLabel(
- "sch.tab_le.col").getQualifiedLabel());
- assertEquals("tabl_e.col", dc.getColumnByQualifiedLabel(
- "sch.tabl_e.col").getQualifiedLabel());
- }
-
- public void testGetColumnByQualifiedLabelCaseInsensitive() throws Exception {
- MyDataContext dc = new MyDataContext();
- Column result = dc.getColumnByQualifiedLabel("FOOBAR.TABLE.COL1");
- assertNotNull(result);
- assertEquals("col1", result.getName());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/CompositeDataContextTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/CompositeDataContextTest.java b/core/src/test/java/org/eobjects/metamodel/CompositeDataContextTest.java
deleted file mode 100644
index 0a2e0f7..0000000
--- a/core/src/test/java/org/eobjects/metamodel/CompositeDataContextTest.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/**
- * 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;
-
-import java.util.Arrays;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.CompositeSchema;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-public class CompositeDataContextTest extends TestCase {
-
- /**
- * A "typical scenario": Use a database and a CSV file to create a query
- * that joins tables from each
- */
- public void testBaseCaseCompositeQuery() throws Exception {
- DataContext dc1 = new MockDataContext("schema1", "table1", "");
- DataContext dc2 = new MockDataContext("schema2", "table2", "");
-
- DataContext composite = new CompositeDataContext(dc1, dc2);
-
- assertEquals("[schema1, schema2]",
- Arrays.toString(composite.getSchemaNames()));
- assertSame(dc1.getDefaultSchema(), composite.getDefaultSchema());
-
- DataSet ds = composite.query()
- .from(dc1.getDefaultSchema().getTables()[0]).select("foo")
- .execute();
- List<Object[]> objectArrays = ds.toObjectArrays();
- assertEquals("1", objectArrays.get(0)[0]);
- assertEquals("2", objectArrays.get(1)[0]);
- assertEquals(4, objectArrays.size());
- }
-
- public void testSchemaNameClashes() throws Exception {
- DataContext dc1 = new MockDataContext("schema", "table1", "");
- DataContext dc2 = new MockDataContext("schema", "table2", "");
-
- DataContext composite = new CompositeDataContext(dc1, dc2);
-
- assertEquals("[schema]",
- Arrays.toString(composite.getSchemaNames()));
-
- Schema schema = composite.getDefaultSchema();
- assertEquals(4, schema.getTableCount());
- assertEquals("[table1, an_empty_table, table2, an_empty_table]",
- Arrays.toString(schema.getTableNames()));
- assertTrue(schema instanceof CompositeSchema);
- }
-
- public void testJoinSameTableNames() throws Exception {
- DataContext dc1 = new MockDataContext("schema", "table", "dc1");
- DataContext dc2 = new MockDataContext("schema", "table", "dc2");
-
- DataContext composite = new CompositeDataContext(dc1, dc2);
-
- assertEquals("[schema]",
- Arrays.toString(composite.getSchemaNames()));
-
- Schema schema = composite.getDefaultSchema();
- assertEquals(4, schema.getTableCount());
- assertEquals("[table, an_empty_table, table, an_empty_table]", Arrays.toString(schema.getTableNames()));
- assertTrue(schema instanceof CompositeSchema);
- Table[] tables = schema.getTables();
- Table table1 = tables[0];
- Table table2 = tables[2];
- assertNotSame(table1, table2);
-
- Query q = composite
- .query()
- .from(table1)
- .leftJoin(table2)
- .on(table1.getColumnByName("foo"),
- table2.getColumnByName("foo"))
- .select(table1.getColumnByName("foo"),
- table2.getColumnByName("foo"),
- table1.getColumnByName("bar"),
- table2.getColumnByName("baz")).toQuery();
- assertEquals(
- "SELECT table.foo, table.foo, table.bar, table.baz "
- + "FROM schema.table LEFT JOIN schema.table ON table.foo = table.foo",
- q.toSql());
-
- DataSet ds = composite.executeQuery(q);
- assertTrue(ds.next());
- assertEquals("Row[values=[1, 1, hello, world]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[2, 2, dc1, world]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[3, 3, hi, dc2]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[4, 4, yo, world]]", ds.getRow().toString());
- assertFalse(ds.next());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/MetaModelHelperTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/MetaModelHelperTest.java b/core/src/test/java/org/eobjects/metamodel/MetaModelHelperTest.java
deleted file mode 100644
index 50c1ad1..0000000
--- a/core/src/test/java/org/eobjects/metamodel/MetaModelHelperTest.java
+++ /dev/null
@@ -1,327 +0,0 @@
-/**
- * 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;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetHeader;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.EmptyDataSet;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.SimpleDataSetHeader;
-import org.eobjects.metamodel.data.SubSelectionDataSet;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.JoinType;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.OrderByItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-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;
-
-public class MetaModelHelperTest extends MetaModelTestCase {
-
- public void testLeftJoin() throws Exception {
- SelectItem si1 = new SelectItem(new MutableColumn("person_id", ColumnType.INTEGER));
- SelectItem si2 = new SelectItem(new MutableColumn("person_name", ColumnType.VARCHAR));
- SelectItem si3 = new SelectItem(new MutableColumn("person_age", ColumnType.INTEGER));
- SelectItem si4 = new SelectItem(new MutableColumn("person_role_id", ColumnType.INTEGER));
- SelectItem si5 = new SelectItem(new MutableColumn("role_id", ColumnType.INTEGER));
- SelectItem si6 = new SelectItem(new MutableColumn("role_name", ColumnType.VARCHAR));
- SelectItem si7 = new SelectItem(new MutableColumn("role_code", ColumnType.VARCHAR));
- List<Object[]> data1 = new ArrayList<Object[]>();
- data1.add(new Object[] { 1, "peter", 18, 1 });
- data1.add(new Object[] { 2, "tom", 19, 2 });
- data1.add(new Object[] { 3, "betty", 19, null });
- data1.add(new Object[] { 4, "barbara", 17, 3 });
- data1.add(new Object[] { 5, "susie", 18, 4 });
-
- List<Object[]> data2 = new ArrayList<Object[]>();
- data2.add(new Object[] { 1, "class president", "clpr" });
- data2.add(new Object[] { 2, "bad boy", "bb" });
- data2.add(new Object[] { 4, "trying harder", "try" });
-
- DataSet ds1 = createDataSet(new SelectItem[] { si1, si2, si3, si4 }, data1);
- DataSet ds2 = createDataSet(new SelectItem[] { si5, si6, si7 }, data2);
- FilterItem[] onConditions = new FilterItem[1];
- onConditions[0] = new FilterItem(si4, OperatorType.EQUALS_TO, si5);
-
- DataSet result = MetaModelHelper.getLeftJoin(ds1, ds2, onConditions);
- List<Object[]> objectArrays = result.toObjectArrays();
- assertEquals("[1, peter, 18, 1, 1, class president, clpr]", Arrays.toString(objectArrays.get(0)));
- assertEquals("[2, tom, 19, 2, 2, bad boy, bb]", Arrays.toString(objectArrays.get(1)));
- assertEquals("[3, betty, 19, null, null, null, null]", Arrays.toString(objectArrays.get(2)));
- assertEquals("[4, barbara, 17, 3, null, null, null]", Arrays.toString(objectArrays.get(3)));
- assertEquals("[5, susie, 18, 4, 4, trying harder, try]", Arrays.toString(objectArrays.get(4)));
- assertEquals(5, objectArrays.size());
- }
-
- public void testRightJoin() throws Exception {
- SelectItem si1 = new SelectItem(new MutableColumn("person_id", ColumnType.INTEGER));
- SelectItem si2 = new SelectItem(new MutableColumn("person_name", ColumnType.VARCHAR));
- SelectItem si3 = new SelectItem(new MutableColumn("person_age", ColumnType.INTEGER));
- SelectItem si4 = new SelectItem(new MutableColumn("person_role_id", ColumnType.INTEGER));
- SelectItem si5 = new SelectItem(new MutableColumn("role_id", ColumnType.INTEGER));
- SelectItem si6 = new SelectItem(new MutableColumn("role_name", ColumnType.VARCHAR));
- SelectItem si7 = new SelectItem(new MutableColumn("role_code", ColumnType.VARCHAR));
- List<Object[]> data1 = new ArrayList<Object[]>();
- data1.add(new Object[] { 1, "peter", 18, 1 });
- data1.add(new Object[] { 2, "tom", 19, 2 });
- data1.add(new Object[] { 3, "betty", 19, null });
- data1.add(new Object[] { 4, "barbara", 17, 3 });
-
- List<Object[]> data2 = new ArrayList<Object[]>();
- data2.add(new Object[] { 1, "class president", "clpr" });
- data2.add(new Object[] { 2, "bad boy", "bb" });
- data2.add(new Object[] { 4, "trying harder", "try" });
-
- DataSet ds1 = createDataSet(new SelectItem[] { si1, si2, si3, si4 }, data1);
- DataSet ds2 = createDataSet(new SelectItem[] { si5, si6, si7 }, data2);
- FilterItem[] onConditions = new FilterItem[1];
- onConditions[0] = new FilterItem(si4, OperatorType.EQUALS_TO, si5);
-
- DataSet result = MetaModelHelper.getRightJoin(ds1, ds2, onConditions);
- List<Object[]> objectArrays = result.toObjectArrays();
- assertEquals("[1, peter, 18, 1, 1, class president, clpr]", Arrays.toString(objectArrays.get(0)));
- assertEquals("[2, tom, 19, 2, 2, bad boy, bb]", Arrays.toString(objectArrays.get(1)));
- assertEquals("[null, null, null, null, 4, trying harder, try]", Arrays.toString(objectArrays.get(2)));
- assertEquals(3, objectArrays.size());
- }
-
- public void testSimpleCarthesianProduct() throws Exception {
- DataSet dataSet = MetaModelHelper.getCarthesianProduct(createDataSet1(), createDataSet2());
-
- assertEquals(2, dataSet.getSelectItems().length);
- assertTrue(dataSet.next());
- assertEquals("Row[values=[f, b]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[f, a]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[o, r]]", dataSet.getRow().toString());
- assertFalse(dataSet.next());
- }
-
- public void testTripleCarthesianProduct() throws Exception {
- DataSet dataSet = MetaModelHelper.getCarthesianProduct(createDataSet1(), createDataSet2(), createDataSet3());
- assertEquals(4, dataSet.getSelectItems().length);
- for (int i = 0; i < 3 * 3 * 2; i++) {
- assertTrue("Assertion failed at i=" + i, dataSet.next());
- }
- assertFalse(dataSet.next());
- }
-
- public void testTripleCarthesianProductWithWhereItems() throws Exception {
- DataSet ds1 = createDataSet1();
- DataSet ds2 = createDataSet2();
- DataSet[] dataSets = new DataSet[] { ds1, ds2, };
- FilterItem w1 = new FilterItem(ds1.getSelectItems()[0], OperatorType.EQUALS_TO, "f");
- DataSet dataSet = MetaModelHelper.getCarthesianProduct(dataSets, w1);
- assertEquals(2, dataSet.getSelectItems().length);
- for (int i = 0; i < 1 * 3; i++) {
- assertTrue("Assertion failed at i=" + i, dataSet.next());
- assertEquals("f", dataSet.getRow().getValue(0));
- }
- assertFalse(dataSet.next());
- }
-
- public void testGetCarthesianProductNoRows() throws Exception {
- DataSet dataSet = MetaModelHelper.getCarthesianProduct(createDataSet4(), createDataSet2(), createDataSet3());
- assertEquals(4, dataSet.getSelectItems().length);
- assertFalse(dataSet.next());
-
- dataSet = MetaModelHelper.getCarthesianProduct(createDataSet1(), createDataSet4(), createDataSet3());
- assertEquals(4, dataSet.getSelectItems().length);
- assertFalse(dataSet.next());
-
- dataSet = MetaModelHelper.getCarthesianProduct(createDataSet1(), createDataSet2(), createDataSet4());
- assertEquals(3, dataSet.getSelectItems().length);
- assertFalse(dataSet.next());
- }
-
- public void testGetOrdered() throws Exception {
- DataSet dataSet = createDataSet3();
- List<OrderByItem> orderByItems = new ArrayList<OrderByItem>();
- orderByItems.add(new OrderByItem(dataSet.getSelectItems()[0]));
-
- dataSet = MetaModelHelper.getOrdered(dataSet, orderByItems);
- assertTrue(dataSet.next());
- assertEquals("Row[values=[w00p, true]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[yippie, false]]", dataSet.getRow().toString());
- assertFalse(dataSet.next());
- }
-
- private DataSet createDataSet1() {
- List<Object[]> data1 = new ArrayList<Object[]>();
- data1.add(new Object[] { "f" });
- data1.add(new Object[] { "o" });
- data1.add(new Object[] { "o" });
- DataSet dataSet1 = createDataSet(
- new SelectItem[] { new SelectItem(new MutableColumn("foo", ColumnType.VARCHAR)) }, data1);
- return dataSet1;
- }
-
- private DataSet createDataSet2() {
- List<Object[]> data2 = new ArrayList<Object[]>();
- data2.add(new Object[] { "b" });
- data2.add(new Object[] { "a" });
- data2.add(new Object[] { "r" });
- DataSet dataSet2 = createDataSet(new SelectItem[] { new SelectItem("bar", "bar") }, data2);
- return dataSet2;
- }
-
- private DataSet createDataSet3() {
- List<Object[]> data3 = new ArrayList<Object[]>();
- data3.add(new Object[] { "w00p", true });
- data3.add(new Object[] { "yippie", false });
- DataSet dataSet3 = createDataSet(new SelectItem[] { new SelectItem("expression", "e"),
- new SelectItem("webish?", "w") }, data3);
- return dataSet3;
- }
-
- private DataSet createDataSet4() {
- List<Object[]> data4 = new ArrayList<Object[]>();
- DataSet dataSet4 = createDataSet(new SelectItem[] { new SelectItem("abc", "abc") }, data4);
- return dataSet4;
- }
-
- public void testGetTables() throws Exception {
- MutableTable table1 = new MutableTable("table1");
- MutableTable table2 = new MutableTable("table2");
- MutableColumn t1column1 = new MutableColumn("t1c1", ColumnType.BIGINT);
- MutableColumn t2column1 = new MutableColumn("t2c1", ColumnType.BIGINT);
- MutableColumn t2column2 = new MutableColumn("t2c2", ColumnType.BIGINT);
- table1.addColumn(t1column1);
- t1column1.setTable(table1);
- table2.addColumn(t2column1);
- t2column1.setTable(table2);
- table2.addColumn(t2column2);
- t2column2.setTable(table2);
-
- ArrayList<Table> tableList = new ArrayList<Table>();
- tableList.add(table1);
-
- ArrayList<Column> columnList = new ArrayList<Column>();
- columnList.add(t2column1);
-
- Table[] tables = MetaModelHelper.getTables(tableList, columnList);
- assertEquals(2, tables.length);
- assertTrue(Arrays.asList(tables).contains(table1));
- assertTrue(Arrays.asList(tables).contains(table2));
- }
-
- public void testGetTableColumns() throws Exception {
- MutableTable table1 = new MutableTable("table1");
- MutableColumn column1 = new MutableColumn("c1", ColumnType.BIGINT);
- MutableColumn column2 = new MutableColumn("c2", ColumnType.BIGINT);
- MutableColumn column3 = new MutableColumn("c3", ColumnType.BIGINT);
- table1.addColumn(column1);
- column1.setTable(table1);
- table1.addColumn(column2);
- column2.setTable(table1);
- table1.addColumn(column3);
- column3.setTable(table1);
-
- ArrayList<Column> columnList = new ArrayList<Column>();
-
- Column[] columns = MetaModelHelper.getTableColumns(table1, columnList);
- assertEquals(0, columns.length);
-
- columnList.add(column1);
- columnList.add(column3);
-
- columns = MetaModelHelper.getTableColumns(table1, columnList);
- assertEquals(2, columns.length);
- assertSame(column1, columns[0]);
- assertSame(column3, columns[1]);
- }
-
- public void testGetTableFromItems() throws Exception {
- Schema schema = getExampleSchema();
- Table contributorTable = schema.getTableByName(TABLE_CONTRIBUTOR);
- Table projectTable = schema.getTableByName(TABLE_PROJECT);
- Table projectContributorTable = schema.getTableByName(TABLE_PROJECT_CONTRIBUTOR);
-
- FromItem sqFromItem = new FromItem(new Query().from(projectTable).from(projectContributorTable));
- FromItem fromItem = new FromItem(JoinType.INNER, new FromItem(contributorTable), sqFromItem, new SelectItem[0],
- new SelectItem[0]);
- Query q = new Query().from(fromItem);
-
- FromItem[] fromItems = MetaModelHelper.getTableFromItems(q);
- assertEquals(3, fromItems.length);
- assertEquals("[MetaModelSchema.contributor, MetaModelSchema.project, MetaModelSchema.project_contributor]",
- Arrays.toString(fromItems));
- }
-
- public void testGetSelectionNoRows() throws Exception {
- SelectItem item1 = new SelectItem("foo", "f");
- SelectItem item2 = new SelectItem("bar", "b");
- SelectItem item3 = new SelectItem("baz", "bz");
- List<SelectItem> selectItems1 = Arrays.asList(item1, item2, item3);
- List<SelectItem> selectItems2 = Arrays.asList(item2, item1);
-
- DataSet ds = MetaModelHelper.getSelection(selectItems2, new EmptyDataSet(selectItems1));
- assertEquals(SubSelectionDataSet.class, ds.getClass());
-
- assertEquals("[bar AS b, foo AS f]", Arrays.toString(ds.getSelectItems()));
- }
-
- public void testLeftJoinNoRowsOrSingleRow() throws Exception {
- SelectItem item1 = new SelectItem("foo", "f");
- SelectItem item2 = new SelectItem("bar", "b");
- SelectItem item3 = new SelectItem("baz", "z");
- List<SelectItem> selectItems1 = Arrays.asList(item1, item2);
- List<SelectItem> selectItems2 = Arrays.asList(item3);
-
- DataSet ds1 = new EmptyDataSet(selectItems1);
- DataSet ds2 = new EmptyDataSet(selectItems2);
-
- DataSet joinedDs = MetaModelHelper.getLeftJoin(ds1, ds2, new FilterItem[] { new FilterItem(item2,
- OperatorType.EQUALS_TO, item3) });
-
- assertEquals(SubSelectionDataSet.class, joinedDs.getClass());
- assertEquals("[foo AS f, bar AS b, baz AS z]", Arrays.toString(joinedDs.getSelectItems()));
-
- DataSetHeader header1 = new SimpleDataSetHeader(selectItems1);
- Row row = new DefaultRow(header1, new Object[] { 1, 2 }, null);
- ds1 = new InMemoryDataSet(header1, row);
-
- joinedDs = MetaModelHelper.getLeftJoin(ds1, ds2, new FilterItem[] { new FilterItem(item2,
- OperatorType.EQUALS_TO, item3) });
- assertEquals("[foo AS f, bar AS b, baz AS z]", Arrays.toString(joinedDs.getSelectItems()));
- assertTrue(joinedDs.next());
- assertEquals("Row[values=[1, 2, null]]", joinedDs.getRow().toString());
- assertFalse(joinedDs.next());
- }
-}
[26/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/QueryPostprocessDataContextTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/QueryPostprocessDataContextTest.java b/core/src/test/java/org/apache/metamodel/QueryPostprocessDataContextTest.java
new file mode 100644
index 0000000..0562bc5
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/QueryPostprocessDataContextTest.java
@@ -0,0 +1,861 @@
+/**
+ * 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;
+
+import java.nio.channels.UnsupportedAddressTypeException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.swing.table.TableModel;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.DataSetTableModel;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.query.CompiledQuery;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.FunctionType;
+import org.eobjects.metamodel.query.GroupByItem;
+import org.eobjects.metamodel.query.JoinType;
+import org.eobjects.metamodel.query.OperatorType;
+import org.eobjects.metamodel.query.OrderByItem;
+import org.eobjects.metamodel.query.QueryParameter;
+import org.eobjects.metamodel.query.OrderByItem.Direction;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.schema.MutableSchema;
+import org.eobjects.metamodel.schema.MutableTable;
+import org.eobjects.metamodel.schema.Relationship;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+public class QueryPostprocessDataContextTest extends MetaModelTestCase {
+
+ private final Schema schema = getExampleSchema();
+ private final Table table1 = schema.getTableByName(TABLE_CONTRIBUTOR);
+ private final Table table2 = schema.getTableByName(TABLE_ROLE);
+
+ public void testAggregateQueryNoWhereClause() throws Exception {
+ MockDataContext dc = new MockDataContext("sch", "tab", "1");
+ Table table = dc.getDefaultSchema().getTables()[0];
+ assertSingleRowResult("Row[values=[4]]", dc.query().from(table).selectCount().execute());
+ }
+
+ public void testAggregateQueryRegularWhereClause() throws Exception {
+ MockDataContext dc = new MockDataContext("sch", "tab", "1");
+ Table table = dc.getDefaultSchema().getTables()[0];
+ assertSingleRowResult("Row[values=[3]]", dc.query().from(table).selectCount().where("baz").eq("world")
+ .execute());
+ }
+
+ public void testAggregateQueryWhereClauseExcludingAll() throws Exception {
+ MockDataContext dc = new MockDataContext("sch", "tab", "1");
+ assertSingleRowResult("Row[values=[0]]",
+ dc.query().from("tab").selectCount().where("baz").eq("non_existing_value").execute());
+ }
+
+ public void testMixedAggregateAndRawQueryOnEmptyTable() throws Exception {
+ MockDataContext dc = new MockDataContext("sch", "tab", "1");
+ Table emptyTable = dc.getTableByQualifiedLabel("an_empty_table");
+
+ assertSingleRowResult("Row[values=[0, null]]", dc.query().from(emptyTable).selectCount().and("foo").execute());
+ }
+
+ private void assertSingleRowResult(String rowStr, DataSet ds) {
+ assertTrue("DataSet had no rows", ds.next());
+ Row row = ds.getRow();
+ assertEquals(rowStr, row.toString());
+ assertFalse("DataSet had more than a single row!", ds.next());
+ ds.close();
+ }
+
+ public void testMixedAggregateAndRawQuery() throws Exception {
+ MockDataContext dc = new MockDataContext("sch", "tab", "1");
+ Table table = dc.getDefaultSchema().getTables()[0];
+ Column[] columns = table.getColumns();
+
+ Query query = dc.query().from(table).select(FunctionType.MAX, columns[0]).and(columns[1]).toQuery();
+ assertEquals("SELECT MAX(tab.foo), tab.bar FROM sch.tab", query.toSql());
+
+ DataSet ds = dc.executeQuery(query);
+ assertTrue(ds.next());
+ assertEquals("Row[values=[4, hello]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[4, 1]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[4, hi]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[4, yo]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ }
+
+ public void testSelectItemReferencesToFromItems() throws Exception {
+ MockDataContext dc = new MockDataContext("sch", "tab", "1");
+
+ Table table = dc.getDefaultSchema().getTables()[0];
+
+ Query q = new Query();
+ FromItem fromItem1 = q.from(table, "t1").getFromClause().getItem(0);
+ FromItem fromItem2 = q.from(table, "t2").getFromClause().getItem(1);
+ q.select(table.getColumnByName("foo"), fromItem1);
+ q.select(table.getColumnByName("foo"), fromItem2);
+ q.where(q.getSelectClause().getItem(0), OperatorType.EQUALS_TO, "2");
+ assertEquals("SELECT t1.foo, t2.foo FROM sch.tab t1, sch.tab t2 WHERE t1.foo = '2'", q.toSql());
+
+ DataSet ds = dc.executeQuery(q);
+ SelectItem[] selectItems = ds.getSelectItems();
+ assertEquals(2, selectItems.length);
+ assertEquals("t1.foo", selectItems[0].toSql());
+ assertEquals("t2.foo", selectItems[1].toSql());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[2, 1]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[2, 2]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[2, 3]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[2, 4]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ ds.close();
+ }
+
+ private DataContext getDataContext() {
+ QueryPostprocessDataContext dataContext = new QueryPostprocessDataContext() {
+
+ @Override
+ public DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+ if (table == table1) {
+ Column[] columns1 = table1.getColumns();
+ SelectItem[] selectItems = new SelectItem[columns1.length];
+ for (int i = 0; i < selectItems.length; i++) {
+ SelectItem selectItem = new SelectItem(columns1[i]);
+ selectItems[i] = selectItem;
+ }
+ List<Object[]> data = new ArrayList<Object[]>();
+ data.add(new Object[] { 1, "kasper", "denmark" });
+ data.add(new Object[] { 2, "asbjorn", "denmark" });
+ data.add(new Object[] { 3, "johny", "israel" });
+ data.add(new Object[] { 4, "daniel", "canada" });
+ data.add(new Object[] { 5, "sasidhar", "unknown" });
+ data.add(new Object[] { 6, "jesper", "denmark" });
+ if (maxRows != -1) {
+ for (int i = data.size() - 1; i >= maxRows; i--) {
+ data.remove(i);
+ }
+ }
+ return createDataSet(selectItems, data);
+ } else if (table == table2) {
+ Column[] columns2 = table2.getColumns();
+ SelectItem[] selectItems = new SelectItem[columns2.length];
+ for (int i = 0; i < selectItems.length; i++) {
+ SelectItem selectItem = new SelectItem(columns2[i]);
+ selectItems[i] = selectItem;
+ }
+ List<Object[]> data = new ArrayList<Object[]>();
+ data.add(new Object[] { 1, 1, "founder" });
+ data.add(new Object[] { 1, 1, "developer" });
+ data.add(new Object[] { 1, 2, "developer" });
+ data.add(new Object[] { 2, 1, "developer" });
+ data.add(new Object[] { 2, 3, "developer" });
+ data.add(new Object[] { 4, 1, "advisor" });
+ data.add(new Object[] { 5, 2, "developer" });
+ data.add(new Object[] { 6, 1, "founder" });
+ if (maxRows != -1) {
+ for (int i = data.size() - 1; i >= maxRows; i--) {
+ data.remove(i);
+ }
+ }
+ return createDataSet(selectItems, data);
+ }
+ throw new IllegalArgumentException("This test only accepts table1 and table2");
+ }
+
+ @Override
+ protected String getMainSchemaName() throws MetaModelException {
+ return schema.getName();
+ }
+
+ @Override
+ protected Schema getMainSchema() throws MetaModelException {
+ return schema;
+ }
+ };
+ return dataContext;
+ }
+
+ public void testDistinct() throws Exception {
+
+ Column roleColumn = table2.getColumnByName(COLUMN_ROLE_ROLE_NAME);
+
+ Query q = new Query().select(roleColumn).from(table2).orderBy(roleColumn);
+ q.getSelectClause().setDistinct(true);
+
+ DataContext dc = getDataContext();
+ DataSet data = dc.executeQuery(q);
+ assertTrue(data.next());
+ assertEquals("advisor", data.getRow().getValue(roleColumn));
+ assertTrue(data.next());
+ assertEquals("developer", data.getRow().getValue(roleColumn));
+ assertTrue(data.next());
+ assertEquals("founder", data.getRow().getValue(roleColumn));
+ assertFalse(data.next());
+ }
+
+ public void testInformationSchema() throws Exception {
+ DataContext dc = getDataContext();
+ assertEquals("[information_schema, MetaModelSchema]", Arrays.toString(dc.getSchemaNames()));
+ Schema informationSchema = dc.getSchemaByName("information_schema");
+ assertEquals(
+ "[Table[name=tables,type=TABLE,remarks=null], Table[name=columns,type=TABLE,remarks=null], Table[name=relationships,type=TABLE,remarks=null]]",
+ Arrays.toString(informationSchema.getTables()));
+ assertEquals(
+ "[Relationship[primaryTable=tables,primaryColumns=[name],foreignTable=columns,foreignColumns=[table]], "
+ + "Relationship[primaryTable=tables,primaryColumns=[name],foreignTable=relationships,foreignColumns=[primary_table]], "
+ + "Relationship[primaryTable=tables,primaryColumns=[name],foreignTable=relationships,foreignColumns=[foreign_table]], "
+ + "Relationship[primaryTable=columns,primaryColumns=[name],foreignTable=relationships,foreignColumns=[primary_column]], "
+ + "Relationship[primaryTable=columns,primaryColumns=[name],foreignTable=relationships,foreignColumns=[foreign_column]]]",
+ Arrays.toString(informationSchema.getRelationships()));
+ Table tablesTable = informationSchema.getTableByName("tables");
+ assertEquals(
+ "[Column[name=name,columnNumber=0,type=VARCHAR,nullable=false,nativeType=null,columnSize=null], "
+ + "Column[name=type,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
+ + "Column[name=num_columns,columnNumber=2,type=INTEGER,nullable=true,nativeType=null,columnSize=null], "
+ + "Column[name=remarks,columnNumber=3,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]",
+ Arrays.toString(tablesTable.getColumns()));
+ Table columnsTable = informationSchema.getTableByName("columns");
+ assertEquals(
+ "[Column[name=name,columnNumber=0,type=VARCHAR,nullable=false,nativeType=null,columnSize=null], "
+ + "Column[name=type,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
+ + "Column[name=native_type,columnNumber=2,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
+ + "Column[name=size,columnNumber=3,type=INTEGER,nullable=true,nativeType=null,columnSize=null], "
+ + "Column[name=nullable,columnNumber=4,type=BOOLEAN,nullable=true,nativeType=null,columnSize=null], "
+ + "Column[name=indexed,columnNumber=5,type=BOOLEAN,nullable=true,nativeType=null,columnSize=null], "
+ + "Column[name=table,columnNumber=6,type=VARCHAR,nullable=false,nativeType=null,columnSize=null], "
+ + "Column[name=remarks,columnNumber=7,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]",
+ Arrays.toString(columnsTable.getColumns()));
+ Table relationshipsTable = informationSchema.getTableByName("relationships");
+ assertEquals(
+ "[Column[name=primary_table,columnNumber=0,type=VARCHAR,nullable=false,nativeType=null,columnSize=null], "
+ + "Column[name=primary_column,columnNumber=1,type=VARCHAR,nullable=false,nativeType=null,columnSize=null], "
+ + "Column[name=foreign_table,columnNumber=2,type=VARCHAR,nullable=false,nativeType=null,columnSize=null], "
+ + "Column[name=foreign_column,columnNumber=3,type=VARCHAR,nullable=false,nativeType=null,columnSize=null]]",
+ Arrays.toString(relationshipsTable.getColumns()));
+
+ DataSet dataSet = dc.query().from(tablesTable).select(tablesTable.getColumns()).execute();
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[contributor, TABLE, 3, null]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[project, TABLE, 4, null]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[role, TABLE, 3, null]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[project_contributor, VIEW, 3, null]]", dataSet.getRow().toString());
+ assertFalse(dataSet.next());
+ dataSet.close();
+
+ Relationship relationship = tablesTable.getRelationships(columnsTable)[0];
+ FromItem joinFromItem = new FromItem(JoinType.INNER, relationship);
+ Query q = new Query().select(tablesTable.getColumnByName("name")).select(columnsTable.getColumnByName("name"))
+ .select(columnsTable.getBooleanColumns()).from(joinFromItem);
+
+ assertEquals("SELECT tables.name, columns.name, columns.nullable, columns.indexed "
+ + "FROM information_schema.tables INNER JOIN information_schema.columns "
+ + "ON tables.name = columns.table", q.toString());
+
+ dataSet = dc.executeQuery(q);
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[contributor, contributor_id, false, true]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[contributor, name, false, false]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[contributor, country, true, false]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[project, project_id, false, false]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[project, name, false, false]]", dataSet.getRow().toString());
+ dataSet.close();
+ }
+
+ public void testOrderByWithoutSelecting() throws Exception {
+ Query q = new Query();
+ q.from(new FromItem(table2).setAlias("r"));
+ Column roleColumn = table2.getColumnByName(COLUMN_ROLE_ROLE_NAME);
+ Column projectIdColumn = table2.getColumnByName(COLUMN_ROLE_PROJECT_ID);
+ q.select(new SelectItem(projectIdColumn));
+ q.orderBy(roleColumn);
+ assertEquals("SELECT r.project_id FROM MetaModelSchema.role r ORDER BY r.name ASC", q.toString());
+
+ DataContext dc = getDataContext();
+ DataSet data = dc.executeQuery(q);
+ assertEquals(1, data.getSelectItems().length);
+
+ @SuppressWarnings("deprecation")
+ TableModel tableModel = data.toTableModel();
+
+ // should correspond to these lines:
+
+ // data.add(new Object[] { 4, 1, "advisor" });
+ // data.add(new Object[] { 1, 1, "developer" });
+ // data.add(new Object[] { 1, 2, "developer" });
+ // data.add(new Object[] { 2, 1, "developer" });
+ // data.add(new Object[] { 2, 3, "developer" });
+ // data.add(new Object[] { 5, 2, "developer" });
+ // data.add(new Object[] { 1, 1, "founder" });
+ // data.add(new Object[] { 6, 1, "founder" });
+
+ assertEquals(8, tableModel.getRowCount());
+ assertEquals(1, tableModel.getColumnCount());
+ assertEquals(1, tableModel.getValueAt(0, 0));
+ assertEquals(1, tableModel.getValueAt(1, 0));
+ assertEquals(2, tableModel.getValueAt(2, 0));
+ assertEquals(1, tableModel.getValueAt(3, 0));
+ assertEquals(3, tableModel.getValueAt(4, 0));
+ assertEquals(2, tableModel.getValueAt(5, 0));
+ assertEquals(1, tableModel.getValueAt(6, 0));
+ assertEquals(1, tableModel.getValueAt(7, 0));
+ }
+
+ public void testGroupByWithoutSelecting() throws Exception {
+ Query q = new Query();
+ q.from(new FromItem(table2).setAlias("r"));
+ Column roleColumn = table2.getColumnByName(COLUMN_ROLE_ROLE_NAME);
+ Column projectIdColumn = table2.getColumnByName(COLUMN_ROLE_PROJECT_ID);
+ q.select(new SelectItem(FunctionType.SUM, projectIdColumn));
+ q.groupBy(new GroupByItem(new SelectItem(roleColumn)));
+ q.orderBy(roleColumn);
+ assertEquals("SELECT SUM(r.project_id) FROM MetaModelSchema.role r GROUP BY r.name ORDER BY r.name ASC",
+ q.toString());
+
+ DataContext dc = getDataContext();
+ DataSet data = dc.executeQuery(q);
+ assertEquals(1, data.getSelectItems().length);
+ assertEquals("SUM(r.project_id)", data.getSelectItems()[0].toString());
+
+ @SuppressWarnings("deprecation")
+ TableModel tableModel = data.toTableModel();
+ assertEquals(3, tableModel.getRowCount());
+ assertEquals(1, tableModel.getColumnCount());
+ assertEquals(1.0, tableModel.getValueAt(0, 0));
+ assertEquals(9.0, tableModel.getValueAt(1, 0));
+ assertEquals(2.0, tableModel.getValueAt(2, 0));
+
+ q = dc.query().from(table2).select("name").orderBy("name").toQuery();
+ q.getSelectClause().setDistinct(true);
+
+ tableModel = new DataSetTableModel(dc.executeQuery(q));
+ assertEquals(3, tableModel.getRowCount());
+ assertEquals(1, tableModel.getColumnCount());
+ assertEquals("advisor", tableModel.getValueAt(0, 0));
+ assertEquals("developer", tableModel.getValueAt(1, 0));
+ assertEquals("founder", tableModel.getValueAt(2, 0));
+ }
+
+ public void testSimpleGroupBy() throws Exception {
+ Query q = new Query();
+ q.from(new FromItem(table2).setAlias("r"));
+ Column roleColumn = table2.getColumnByName(COLUMN_ROLE_ROLE_NAME);
+ q.select(new SelectItem(roleColumn));
+ q.groupBy(new GroupByItem(new SelectItem(roleColumn)));
+ assertEquals("SELECT r.name FROM MetaModelSchema.role r GROUP BY r.name", q.toString());
+
+ DataContext dc = getDataContext();
+ DataSet data = dc.executeQuery(q);
+ assertEquals(1, data.getSelectItems().length);
+ assertEquals("r.name", data.getSelectItems()[0].toString());
+ TableModel tableModel = new DataSetTableModel(data);
+ assertEquals(3, tableModel.getRowCount());
+
+ q.select(new SelectItem(FunctionType.COUNT, "*", "c"));
+ q.where(new FilterItem(new SelectItem(roleColumn), OperatorType.EQUALS_TO, "founder"));
+ data = dc.executeQuery(q);
+ assertEquals(2, data.getSelectItems().length);
+ assertEquals("r.name", data.getSelectItems()[0].toString());
+ assertEquals("COUNT(*) AS c", data.getSelectItems()[1].toString());
+ tableModel = new DataSetTableModel(data);
+ assertEquals(1, tableModel.getRowCount());
+ assertEquals("founder", tableModel.getValueAt(0, 0));
+ assertEquals(2l, tableModel.getValueAt(0, 1));
+
+ q.select(new SelectItem(FunctionType.SUM, table2.getColumns()[0]));
+ assertEquals(
+ "SELECT r.name, COUNT(*) AS c, SUM(r.contributor_id) FROM MetaModelSchema.role r WHERE r.name = 'founder' GROUP BY r.name",
+ q.toString());
+ data = dc.executeQuery(q);
+ assertEquals(3, data.getSelectItems().length);
+ assertEquals("r.name", data.getSelectItems()[0].toString());
+ assertEquals("COUNT(*) AS c", data.getSelectItems()[1].toString());
+ assertEquals("SUM(r.contributor_id)", data.getSelectItems()[2].toString());
+ tableModel = new DataSetTableModel(data);
+ assertEquals(1, tableModel.getRowCount());
+ assertEquals("founder", tableModel.getValueAt(0, 0));
+ assertEquals(2l, tableModel.getValueAt(0, 1));
+ assertEquals(7.0, tableModel.getValueAt(0, 2));
+ }
+
+ public void testSimpleHaving() throws Exception {
+ Query q = new Query();
+ q.from(table2, "c");
+ Column roleColumn = table2.getColumnByName(COLUMN_ROLE_ROLE_NAME);
+ Column contributorIdColumn = table2.getColumnByName(COLUMN_ROLE_CONTRIBUTOR_ID);
+
+ q.groupBy(roleColumn);
+ SelectItem countSelectItem = new SelectItem(FunctionType.COUNT, contributorIdColumn).setAlias("my_count");
+ q.select(new SelectItem(roleColumn), countSelectItem);
+ q.having(new FilterItem(countSelectItem, OperatorType.GREATER_THAN, 1));
+ q.orderBy(new OrderByItem(countSelectItem));
+ assertEquals(
+ "SELECT c.name, COUNT(c.contributor_id) AS my_count FROM MetaModelSchema.role c GROUP BY c.name HAVING COUNT(c.contributor_id) > 1 ORDER BY COUNT(c.contributor_id) ASC",
+ q.toString());
+
+ DataSet data = getDataContext().executeQuery(q);
+ assertTrue(data.next());
+ assertEquals("Row[values=[founder, 2]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[developer, 5]]", data.getRow().toString());
+ assertFalse(data.next());
+ }
+
+ public void testHavingFunctionNotSelected() throws Exception {
+ Query q = new Query();
+ q.from(table2, "c");
+ Column roleColumn = table2.getColumnByName(COLUMN_ROLE_ROLE_NAME);
+ Column contributorIdColumn = table2.getColumnByName(COLUMN_ROLE_CONTRIBUTOR_ID);
+
+ q.groupBy(roleColumn);
+ SelectItem countSelectItem = new SelectItem(FunctionType.COUNT, contributorIdColumn).setAlias("my_count");
+ q.select(new SelectItem(roleColumn));
+ q.having(new FilterItem(countSelectItem, OperatorType.GREATER_THAN, 3));
+ assertEquals("SELECT c.name FROM MetaModelSchema.role c GROUP BY c.name HAVING COUNT(c.contributor_id) > 3",
+ q.toString());
+
+ DataSet data = getDataContext().executeQuery(q);
+ assertTrue(data.next());
+ assertEquals("Row[values=[developer]]", data.getRow().toString());
+ assertFalse(data.next());
+ data.close();
+
+ q.getHavingClause().removeItems();
+ q.having(new FilterItem(SelectItem.getCountAllItem(), OperatorType.GREATER_THAN, 3));
+ assertEquals("SELECT c.name FROM MetaModelSchema.role c GROUP BY c.name HAVING COUNT(*) > 3", q.toString());
+ data = getDataContext().executeQuery(q);
+ assertTrue(data.next());
+ assertEquals("Row[values=[developer]]", data.getRow().toString());
+ assertFalse(data.next());
+ data.close();
+ }
+
+ public void testCompiledQueryParameterInWhereClause() throws Exception {
+ DataContext dc = getDataContext();
+ QueryParameter param1 = new QueryParameter();
+ CompiledQuery compiledQuery = dc.query().from(table1).select("name").where(COLUMN_CONTRIBUTOR_COUNTRY)
+ .eq(param1).compile();
+ try {
+ assertEquals(1, compiledQuery.getParameters().size());
+ assertSame(param1, compiledQuery.getParameters().get(0));
+
+ DataSet ds = dc.executeQuery(compiledQuery, "denmark");
+ try {
+ assertTrue(ds.next());
+ assertEquals("Row[values=[kasper]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[asbjorn]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[jesper]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ } finally {
+ ds.close();
+ }
+
+ try {
+ ds = dc.executeQuery(compiledQuery, "canada");
+ assertTrue(ds.next());
+ assertEquals("Row[values=[daniel]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ } finally {
+ ds.close();
+ }
+ } finally {
+ compiledQuery.close();
+ }
+ }
+
+ public void testCompiledQueryParameterInSubQuery() throws Exception {
+ final DataContext dc = getDataContext();
+
+ final QueryParameter param1 = new QueryParameter();
+ final Query subQuery = dc.query().from(table1).select("name").where(COLUMN_CONTRIBUTOR_COUNTRY).eq(param1)
+ .toQuery();
+
+ final FromItem subQueryFromItem = new FromItem(subQuery);
+ final Query query = new Query().select(new SelectItem(subQuery.getSelectClause().getItem(0), subQueryFromItem))
+ .from(subQueryFromItem);
+
+ final CompiledQuery compiledQuery = dc.compileQuery(query);
+
+ try {
+ assertEquals(1, compiledQuery.getParameters().size());
+ assertSame(param1, compiledQuery.getParameters().get(0));
+
+ DataSet ds = dc.executeQuery(compiledQuery, "denmark");
+ List<Object[]> objectArrays = ds.toObjectArrays();
+ assertEquals(3, objectArrays.size());
+
+ } finally {
+ compiledQuery.close();
+ }
+ }
+
+ public void testSelectCount() throws Exception {
+ DataContext dc = getDataContext();
+ Query q = new Query();
+ q.from(table1);
+ q.selectCount();
+
+ Row row = MetaModelHelper.executeSingleRowQuery(dc, q);
+ assertEquals("6", row.getValue(0).toString());
+ }
+
+ public void testSimpleSelect() throws Exception {
+ DataContext dc = getDataContext();
+ Query q = new Query();
+ q.from(table1);
+ q.select(table1.getColumns());
+ DataSet dataSet = dc.executeQuery(q);
+ assertTrue(dataSet.next());
+ Row row = dataSet.getRow();
+ assertEquals("Row[values=[1, kasper, denmark]]", row.toString());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertFalse(dataSet.next());
+ }
+
+ public void testCarthesianProduct() throws Exception {
+ DataContext dc = getDataContext();
+ Query q = new Query();
+ q.from(table1);
+ q.from(table2);
+ q.select(table1.getColumns());
+ q.select(table2.getColumns());
+ DataSet data = dc.executeQuery(q);
+ assertEquals(table1.getColumnCount() + table2.getColumnCount(), data.getSelectItems().length);
+ for (int i = 0; i < 6 * 8; i++) {
+ assertTrue(data.next());
+ if (i == 0) {
+ assertEquals("Row[values=[1, kasper, denmark, 1, 1, founder]]", data.getRow().toString());
+ } else if (i == 1) {
+ assertEquals("Row[values=[1, kasper, denmark, 1, 1, developer]]", data.getRow().toString());
+ }
+ }
+ assertFalse(data.next());
+ }
+
+ public void testJoinAndFirstRow() throws Exception {
+ DataSet data;
+
+ DataContext dc = getDataContext();
+ Query q = new Query();
+ q.from(table1);
+ q.from(table2);
+ q.select(table1.getColumns());
+ q.select(table2.getColumns());
+ data = dc.executeQuery(q);
+ assertEquals(48, data.toObjectArrays().size());
+
+ q.setFirstRow(3);
+ data = dc.executeQuery(q);
+ assertEquals(46, data.toObjectArrays().size());
+ }
+
+ public void testSimpleWhere() throws Exception {
+ DataContext dc = getDataContext();
+ Query q = new Query();
+ q.from(table1);
+ q.select(table1.getColumns());
+ SelectItem countrySelectItem = q.getSelectClause().getSelectItem(
+ table1.getColumnByName(COLUMN_CONTRIBUTOR_COUNTRY));
+ q.where(new FilterItem(countrySelectItem, OperatorType.EQUALS_TO, "denmark"));
+
+ DataSet data = dc.executeQuery(q);
+ for (int i = 0; i < 3; i++) {
+ assertTrue("Assertion failed at i=" + i, data.next());
+ }
+ assertFalse(data.next());
+ }
+
+ public void testMaxRows() throws Exception {
+ DataContext dc = getDataContext();
+ Query q = new Query();
+ q.from(table1);
+ q.select(table1.getColumns());
+ q.setMaxRows(3);
+ DataSet data1 = dc.executeQuery(q);
+
+ assertTrue(data1.next());
+ assertEquals("Row[values=[1, kasper, denmark]]", data1.getRow().toString());
+ assertTrue(data1.next());
+ assertEquals("Row[values=[2, asbjorn, denmark]]", data1.getRow().toString());
+ assertTrue(data1.next());
+ assertEquals("Row[values=[3, johny, israel]]", data1.getRow().toString());
+
+ assertFalse(data1.next());
+ data1.close();
+
+ q = new Query();
+ q.from(table1);
+ q.select(table1.getColumns());
+ q.setFirstRow(2);
+ q.setMaxRows(2);
+ DataSet data2 = dc.executeQuery(q);
+ assertTrue(data2.next());
+ assertEquals("Row[values=[2, asbjorn, denmark]]", data2.getRow().toString());
+ assertTrue(data2.next());
+ assertEquals("Row[values=[3, johny, israel]]", data2.getRow().toString());
+
+ assertFalse(data2.next());
+ data2.close();
+ }
+
+ public void testCarthesianProductWithWhere() throws Exception {
+ DataContext dc = getDataContext();
+
+ SelectItem s1 = new SelectItem(table1.getColumnByName(COLUMN_CONTRIBUTOR_NAME));
+ SelectItem s2 = new SelectItem(table2.getColumnByName(COLUMN_ROLE_ROLE_NAME));
+ FromItem f1 = new FromItem(table1);
+ FromItem f2 = new FromItem(table2);
+
+ Query q = new Query();
+ q.select(s1);
+ q.select(s2);
+ q.from(f1);
+ q.from(f2);
+ SelectItem s3 = new SelectItem(table1.getColumnByName(COLUMN_CONTRIBUTOR_CONTRIBUTOR_ID));
+ SelectItem s4 = new SelectItem(table2.getColumnByName(COLUMN_ROLE_CONTRIBUTOR_ID));
+ q.where(new FilterItem(s3, OperatorType.EQUALS_TO, s4));
+ assertEquals(
+ "SELECT contributor.name, role.name FROM MetaModelSchema.contributor, MetaModelSchema.role WHERE contributor.contributor_id = role.contributor_id",
+ q.toString());
+
+ DataSet data = dc.executeQuery(q);
+ assertEquals(2, data.getSelectItems().length);
+ assertTrue(data.next());
+ assertEquals("Row[values=[kasper, founder]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[kasper, developer]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[kasper, developer]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[asbjorn, developer]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[asbjorn, developer]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[daniel, advisor]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[sasidhar, developer]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[jesper, founder]]", data.getRow().toString());
+ assertFalse(data.next());
+ }
+
+ public void testSelectDistinct() throws Exception {
+ // there will be three distinct values in bar column: hello (x2), hi,
+ // howdy
+ MockDataContext dc = new MockDataContext("sch", "tab", "hello");
+
+ Table table = dc.getTableByQualifiedLabel("sch.tab");
+ Query q = dc.query().from(table).select("bar").toQuery();
+ q.getSelectClause().setDistinct(true);
+ q.orderBy(table.getColumnByName("bar"));
+
+ DataSet ds = dc.executeQuery(q);
+ assertTrue(ds.next());
+ assertEquals("Row[values=[hello]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[hi]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[yo]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ }
+
+ public void testSubSelectionAndInnerJoin() throws Exception {
+ DataContext dc = getDataContext();
+
+ SelectItem s1 = new SelectItem(table1.getColumnByName(COLUMN_CONTRIBUTOR_NAME));
+ SelectItem s2 = new SelectItem(table2.getColumnByName(COLUMN_ROLE_ROLE_NAME));
+ FromItem fromItem = new FromItem(JoinType.INNER, table1.getRelationships(table2)[0]);
+
+ Query q = new Query();
+ q.select(s1);
+ q.select(s2);
+ q.from(fromItem);
+ assertEquals(
+ "SELECT contributor.name, role.name FROM MetaModelSchema.contributor INNER JOIN MetaModelSchema.role ON contributor.contributor_id = role.contributor_id",
+ q.toString());
+
+ DataSet data = dc.executeQuery(q);
+ assertEquals(2, data.getSelectItems().length);
+ assertTrue(data.next());
+ assertEquals("Row[values=[kasper, founder]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[kasper, developer]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[kasper, developer]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[asbjorn, developer]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[asbjorn, developer]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[daniel, advisor]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[sasidhar, developer]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[jesper, founder]]", data.getRow().toString());
+ assertFalse(data.next());
+ }
+
+ public void testSubquery() throws Exception {
+ Query q1 = new Query();
+ q1.from(table1);
+ q1.select(table1.getColumns());
+
+ Query q2 = new Query();
+ FromItem fromItem = new FromItem(q1);
+ q2.from(fromItem);
+ SelectItem selectItem = new SelectItem(q1.getSelectClause().getItems().get(1), fromItem);
+ selectItem.setAlias("e");
+ q2.select(selectItem);
+ assertEquals(
+ "SELECT name AS e FROM (SELECT contributor.contributor_id, contributor.name, contributor.country FROM MetaModelSchema.contributor)",
+ q2.toString());
+
+ fromItem.setAlias("c");
+ assertEquals(
+ "SELECT c.name AS e FROM (SELECT contributor.contributor_id, contributor.name, contributor.country FROM MetaModelSchema.contributor) c",
+ q2.toString());
+
+ DataContext dc = getDataContext();
+ DataSet data = dc.executeQuery(q2);
+ assertEquals(1, data.getSelectItems().length);
+ assertTrue(data.next());
+ assertEquals("Row[values=[kasper]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[asbjorn]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[johny]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[daniel]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[sasidhar]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[jesper]]", data.getRow().toString());
+ assertFalse(data.next());
+
+ // Create a sub-query for a sub-query
+ Query q3 = new Query();
+ fromItem = new FromItem(q2);
+ q3.from(fromItem);
+ selectItem = new SelectItem(q2.getSelectClause().getItems().get(0), fromItem);
+ selectItem.setAlias("f");
+ q3.select(selectItem);
+ fromItem.setAlias("d");
+ assertEquals(
+ "SELECT d.e AS f FROM (SELECT c.name AS e FROM (SELECT contributor.contributor_id, contributor.name, contributor.country FROM MetaModelSchema.contributor) c) d",
+ q3.toString());
+ data = dc.executeQuery(q3);
+ assertEquals(1, data.getSelectItems().length);
+ assertTrue(data.next());
+ assertEquals("Row[values=[kasper]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[asbjorn]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[johny]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[daniel]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[sasidhar]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[jesper]]", data.getRow().toString());
+ assertFalse(data.next());
+ }
+
+ public void testOrderBy() throws Exception {
+ Query q = new Query();
+ q.from(new FromItem(table1).setAlias("c"));
+ q.select(table1.getColumns());
+ OrderByItem countryOrderBy = new OrderByItem(q.getSelectClause().getItem(2), Direction.DESC);
+ OrderByItem nameOrderBy = new OrderByItem(q.getSelectClause().getItem(1));
+ q.orderBy(countryOrderBy, nameOrderBy);
+
+ assertEquals(
+ "SELECT c.contributor_id, c.name, c.country FROM MetaModelSchema.contributor c ORDER BY c.country DESC, c.name ASC",
+ q.toString());
+
+ DataSet data = getDataContext().executeQuery(q);
+ assertTrue(data.next());
+ assertEquals("Row[values=[5, sasidhar, unknown]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[3, johny, israel]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[2, asbjorn, denmark]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[6, jesper, denmark]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[1, kasper, denmark]]", data.getRow().toString());
+ assertTrue(data.next());
+ assertEquals("Row[values=[4, daniel, canada]]", data.getRow().toString());
+ assertFalse(data.next());
+ }
+
+ public void testExecuteCount() throws Exception {
+ QueryPostprocessDataContext dc = new QueryPostprocessDataContext() {
+ @Override
+ protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+ throw new UnsupportedAddressTypeException();
+ }
+
+ @Override
+ protected Number executeCountQuery(Table table, List<FilterItem> whereItems,
+ boolean functionApproximationAllowed) {
+ return 1337;
+ }
+
+ @Override
+ protected String getMainSchemaName() throws MetaModelException {
+ return "sch";
+ }
+
+ @Override
+ protected Schema getMainSchema() throws MetaModelException {
+ MutableSchema schema = new MutableSchema(getMainSchemaName());
+ MutableTable table = new MutableTable("tabl").setSchema(schema);
+ return schema.addTable(table.addColumn(new MutableColumn("col").setTable(table)));
+ }
+ };
+
+ DataSet ds = dc.query().from("sch.tabl").selectCount().execute();
+ assertTrue(ds.next());
+ assertEquals("Row[values=[1337]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/SchemaNameComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/SchemaNameComparatorTest.java b/core/src/test/java/org/apache/metamodel/SchemaNameComparatorTest.java
new file mode 100644
index 0000000..f03ff11
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/SchemaNameComparatorTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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;
+
+import java.util.Comparator;
+
+import junit.framework.TestCase;
+
+public class SchemaNameComparatorTest extends TestCase {
+
+ final Comparator<? super String> comp = SchemaNameComparator.getInstance();
+
+ public void testNormalComparison() throws Exception {
+ assertTrue(comp.compare("foo", "bar") > 0);
+ assertTrue(comp.compare("bar", "foo") < 0);
+ assertTrue(comp.compare("bar", "bar") == 0);
+ }
+
+ public void testNull() throws Exception {
+ assertTrue(comp.compare(null, null) == 0);
+ assertTrue(comp.compare("foo", null) > 0);
+ assertTrue(comp.compare(null, "foo") < 0);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/convert/ColumnTypeDetectorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/convert/ColumnTypeDetectorTest.java b/core/src/test/java/org/apache/metamodel/convert/ColumnTypeDetectorTest.java
new file mode 100644
index 0000000..e36df03
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/convert/ColumnTypeDetectorTest.java
@@ -0,0 +1,72 @@
+/**
+ * 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.convert;
+
+import junit.framework.TestCase;
+
+public class ColumnTypeDetectorTest extends TestCase {
+
+ public void testBooleanConverter() throws Exception {
+ ColumnTypeDetector d = new ColumnTypeDetector();
+
+ d.registerValue("1");
+ d.registerValue("true");
+ d.registerValue("0");
+
+ assertEquals(StringToBooleanConverter.class, d.createConverter()
+ .getClass());
+
+ d.registerValue("2");
+
+ assertNull(d.createConverter());
+ }
+
+ public void testIntegerAndDoubleConverter() throws Exception {
+ ColumnTypeDetector d = new ColumnTypeDetector();
+
+ d.registerValue("123");
+ d.registerValue("0");
+
+ assertEquals(StringToIntegerConverter.class, d.createConverter()
+ .getClass());
+
+ d.registerValue("1123.23");
+ d.registerValue("0.0");
+
+ assertEquals(StringToDoubleConverter.class, d.createConverter()
+ .getClass());
+
+ d.registerValue("abc");
+
+ assertNull(d.createConverter());
+ }
+
+ public void testDateConverter() throws Exception {
+ ColumnTypeDetector d = new ColumnTypeDetector();
+
+ d.registerValue("2010-12-30");
+
+ assertEquals(StringToDateConverter.class, d.createConverter()
+ .getClass());
+
+ d.registerValue("2 abc");
+
+ assertNull(d.createConverter());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/convert/ConvertedDataSetInterceptorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/convert/ConvertedDataSetInterceptorTest.java b/core/src/test/java/org/apache/metamodel/convert/ConvertedDataSetInterceptorTest.java
new file mode 100644
index 0000000..4e1b0db
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/convert/ConvertedDataSetInterceptorTest.java
@@ -0,0 +1,92 @@
+/**
+ * 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.convert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.MockUpdateableDataContext;
+import org.eobjects.metamodel.UpdateableDataContext;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.InMemoryDataSet;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+
+public class ConvertedDataSetInterceptorTest extends TestCase {
+
+ public void testConvertedQuery() throws Exception {
+ UpdateableDataContext dc = new MockUpdateableDataContext();
+ Column fooColumn = dc.getColumnByQualifiedLabel("schema.table.foo");
+ assertNotNull(fooColumn);
+
+ dc = Converters.addTypeConverter(dc, fooColumn,
+ new StringToIntegerConverter());
+
+ Table table = dc.getDefaultSchema().getTableByName("table");
+ Query query = dc.query().from(table).select(table.getColumns())
+ .toQuery();
+ assertEquals("SELECT table.foo, table.bar FROM schema.table",
+ query.toSql());
+
+ DataSet ds = dc.executeQuery(query);
+ assertEquals(ConvertedDataSet.class, ds.getClass());
+
+ assertTrue(ds.next());
+ assertEquals("Row[values=[1, hello]]", ds.getRow().toString());
+ assertEquals(Integer.class, ds.getRow().getValue(0).getClass());
+ assertEquals(String.class, ds.getRow().getValue(1).getClass());
+
+ assertTrue(ds.next());
+ assertEquals("Row[values=[2, there]]", ds.getRow().toString());
+ assertEquals(Integer.class, ds.getRow().getValue(0).getClass());
+ assertEquals(String.class, ds.getRow().getValue(1).getClass());
+
+ assertTrue(ds.next());
+ assertEquals("Row[values=[3, world]]", ds.getRow().toString());
+ assertEquals(Integer.class, ds.getRow().getValue(0).getClass());
+ assertEquals(String.class, ds.getRow().getValue(1).getClass());
+
+ assertFalse(ds.next());
+ ds.close();
+ }
+
+ public void testNonConvertedQuery() throws Exception {
+ MockUpdateableDataContext source = new MockUpdateableDataContext();
+ Column fooColumn = source.getColumnByQualifiedLabel("schema.table.foo");
+ assertNotNull(fooColumn);
+
+ Map<Column, TypeConverter<?, ?>> converters = new HashMap<Column, TypeConverter<?, ?>>();
+ converters.put(fooColumn, new StringToIntegerConverter());
+ DataContext converted = Converters.addTypeConverter(source, fooColumn,
+ new StringToIntegerConverter());
+
+ // only select "bar" which is not converted
+ Table table = converted.getDefaultSchema().getTableByName("table");
+ Query query = converted.query().from(table).select("bar").toQuery();
+ assertEquals("SELECT table.bar FROM schema.table", query.toSql());
+
+ DataSet ds = converted.executeQuery(query);
+ assertEquals(InMemoryDataSet.class, ds.getClass());
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/convert/ConvertedRowInsertionInterceptorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/convert/ConvertedRowInsertionInterceptorTest.java b/core/src/test/java/org/apache/metamodel/convert/ConvertedRowInsertionInterceptorTest.java
new file mode 100644
index 0000000..9f4fbcb
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/convert/ConvertedRowInsertionInterceptorTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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.convert;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.MockUpdateableDataContext;
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.UpdateableDataContext;
+import org.eobjects.metamodel.schema.Column;
+
+public class ConvertedRowInsertionInterceptorTest extends TestCase {
+
+ public void testConvertedInsert() throws Exception {
+ MockUpdateableDataContext source = new MockUpdateableDataContext();
+ Column fooColumn = source.getColumnByQualifiedLabel("schema.table.foo");
+ assertNotNull(fooColumn);
+
+ UpdateableDataContext intercepted = Converters.addTypeConverter(source,
+ fooColumn, new StringToIntegerConverter());
+
+ final List<Object[]> values = source.getValues();
+
+ assertEquals(3, values.size());
+
+ intercepted.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.insertInto("schema.table").value(0, 1).value(1, "2")
+ .execute();
+ callback.insertInto("schema.table").value(0, 3).value(1, "4")
+ .execute();
+ }
+ });
+
+ assertEquals(5, values.size());
+ assertEquals("1", values.get(3)[0]);
+ assertEquals("2", values.get(3)[1]);
+ assertEquals("3", values.get(4)[0]);
+ assertEquals("4", values.get(4)[1]);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/convert/ConvertersTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/convert/ConvertersTest.java b/core/src/test/java/org/apache/metamodel/convert/ConvertersTest.java
new file mode 100644
index 0000000..61e1495
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/convert/ConvertersTest.java
@@ -0,0 +1,160 @@
+/**
+ * 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.convert;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.MockUpdateableDataContext;
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.UpdateableDataContext;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+
+public class ConvertersTest extends TestCase {
+
+ public void testAutoDetectConverters() throws Exception {
+ final MockUpdateableDataContext decoratedDataContext = new MockUpdateableDataContext();
+ final Table table = decoratedDataContext.getDefaultSchema().getTables()[0];
+ Map<Column, TypeConverter<?, ?>> converters = Converters.autoDetectConverters(decoratedDataContext, table, 2);
+ assertEquals(1, converters.size());
+ assertEquals(
+ "[Column[name=foo,columnNumber=0,type=VARCHAR,nullable=null,nativeType=null,columnSize=null]]",
+ converters.keySet().toString());
+ assertEquals(StringToIntegerConverter.class, converters.values().iterator().next().getClass());
+
+ final UpdateableDataContext dc = Converters.addTypeConverters(decoratedDataContext, converters);
+
+ DataSet ds = dc.query().from(table).select(table.getColumns()).execute();
+ assertEquals(ConvertedDataSet.class, ds.getClass());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[1, hello]]", ds.getRow().toString());
+ assertEquals(Integer.class, ds.getRow().getValue(0).getClass());
+ assertEquals(1, ds.getRow().getValue(0));
+ assertTrue(ds.next());
+ assertEquals(Integer.class, ds.getRow().getValue(0).getClass());
+ assertEquals(2, ds.getRow().getValue(0));
+ assertTrue(ds.next());
+ assertEquals(Integer.class, ds.getRow().getValue(0).getClass());
+ assertEquals(3, ds.getRow().getValue(0));
+ assertFalse(ds.next());
+ ds.close();
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.insertInto(table).value("foo", 4).value("bar", "mrrrrh").execute();
+ }
+ });
+
+ // query the decorator
+ ds = dc.query().from(table).select(table.getColumns()).where("foo").eq(4).execute();
+ assertTrue(ds.next());
+ assertEquals("Row[values=[4, mrrrrh]]", ds.getRow().toString());
+ assertEquals(Integer.class, ds.getRow().getValue(0).getClass());
+ assertEquals(4, ds.getRow().getValue(0));
+ assertFalse(ds.next());
+ ds.close();
+
+ // query the decorated
+ Object[] physicalRow = decoratedDataContext.getValues().get(3);
+ assertEquals("[4, mrrrrh]", Arrays.toString(physicalRow));
+ assertEquals(String.class, physicalRow[0].getClass());
+ }
+
+ public void testScenario() throws Exception {
+ UpdateableDataContext dc = new MockUpdateableDataContext();
+ List<Object[]> physicalValuesList = ((MockUpdateableDataContext) dc).getValues();
+ assertEquals(3, physicalValuesList.size());
+ for (Object[] physicalValues : physicalValuesList) {
+ assertEquals("foo is expected to be string", String.class, physicalValues[0].getClass());
+ }
+
+ final Table table = dc.getDefaultSchema().getTables()[0];
+ Map<Column, TypeConverter<?, ?>> converters = Converters.autoDetectConverters(dc, table, 1000);
+ assertEquals(1, converters.size());
+ dc = Converters.addTypeConverters(dc, converters);
+
+ final Query q = dc.query().from(table).select("foo").toQuery();
+ assertEquals("SELECT table.foo FROM schema.table", q.toSql());
+ DataSet ds = dc.executeQuery(q);
+ assertTrue(ds.next());
+ assertEquals(1, ds.getRow().getValue(0));
+ assertTrue(ds.next());
+ assertEquals(2, ds.getRow().getValue(0));
+ assertTrue(ds.next());
+ assertEquals(3, ds.getRow().getValue(0));
+ assertFalse(ds.next());
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.insertInto(table).value("foo", 4).value("bar", "heidiho!").execute();
+ }
+ });
+
+ ds = dc.executeQuery(q);
+ assertTrue(ds.next());
+ assertEquals(1, ds.getRow().getValue(0));
+ assertTrue(ds.next());
+ assertEquals(2, ds.getRow().getValue(0));
+ assertTrue(ds.next());
+ assertEquals(3, ds.getRow().getValue(0));
+ assertTrue(ds.next());
+ assertEquals(4, ds.getRow().getValue(0));
+ assertFalse(ds.next());
+
+ assertEquals(4, physicalValuesList.size());
+ for (Object[] physicalValues : physicalValuesList) {
+ assertEquals("foo is expected to be string", String.class, physicalValues[0].getClass());
+ }
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.insertInto(table).value("foo", 5).value("bar", "hejsa...").execute();
+ callback.update(table).where("foo").lessThan(3).value("foo", 100).execute();
+ }
+ });
+
+ ds = dc.executeQuery(q);
+ assertTrue(ds.next());
+ assertEquals(3, ds.getRow().getValue(0));
+ assertTrue(ds.next());
+ assertEquals(4, ds.getRow().getValue(0));
+ assertTrue(ds.next());
+ assertEquals(5, ds.getRow().getValue(0));
+ assertTrue(ds.next());
+ assertEquals(100, ds.getRow().getValue(0));
+ assertTrue(ds.next());
+ assertEquals(100, ds.getRow().getValue(0));
+ assertFalse(ds.next());
+
+ assertEquals(5, physicalValuesList.size());
+ for (Object[] physicalValues : physicalValuesList) {
+ assertEquals("foo is expected to be string", String.class, physicalValues[0].getClass());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/convert/StringToBooleanConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/convert/StringToBooleanConverterTest.java b/core/src/test/java/org/apache/metamodel/convert/StringToBooleanConverterTest.java
new file mode 100644
index 0000000..7f14f68
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/convert/StringToBooleanConverterTest.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.convert;
+
+import junit.framework.TestCase;
+
+public class StringToBooleanConverterTest extends TestCase {
+
+ private StringToBooleanConverter conv = new StringToBooleanConverter();
+
+ public void testToVirtual() throws Exception {
+ assertNull(conv.toVirtualValue(null));
+ assertNull(conv.toVirtualValue(""));
+ assertEquals(true, conv.toVirtualValue("true").booleanValue());
+ }
+
+ public void testToPhysical() throws Exception {
+ assertNull(conv.toPhysicalValue(null));
+ assertEquals("true", conv.toPhysicalValue(true));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/convert/StringToDateConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/convert/StringToDateConverterTest.java b/core/src/test/java/org/apache/metamodel/convert/StringToDateConverterTest.java
new file mode 100644
index 0000000..dc936f3
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/convert/StringToDateConverterTest.java
@@ -0,0 +1,66 @@
+/**
+ * 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.convert;
+
+import java.text.DateFormat;
+import java.util.Date;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.util.DateUtils;
+import org.eobjects.metamodel.util.Month;
+
+public class StringToDateConverterTest extends TestCase {
+
+ public void testToVirtualSimpleDateFormat() throws Exception {
+ StringToDateConverter conv = new StringToDateConverter("yyyy-MM-dd");
+ assertNull(conv.toVirtualValue(null));
+ assertNull(conv.toVirtualValue(""));
+
+ assertEquals(DateUtils.get(2010, Month.DECEMBER, 31),
+ conv.toVirtualValue("2010-12-31"));
+ }
+
+ public void testToVirtualNoArgs() throws Exception {
+ StringToDateConverter conv = new StringToDateConverter();
+ assertNull(conv.toVirtualValue(null));
+ assertNull(conv.toVirtualValue(""));
+
+ assertEquals(DateUtils.get(2010, Month.DECEMBER, 31),
+ conv.toVirtualValue("2010-12-31"));
+ }
+
+ public void testToPhysicalSimpleDateFormat() throws Exception {
+ StringToDateConverter conv = new StringToDateConverter("yyyy-MM-dd");
+ assertNull(conv.toPhysicalValue(null));
+ Date input = DateUtils.get(2010, Month.DECEMBER, 31);
+ String physicalValue = conv.toPhysicalValue(input);
+ assertEquals("2010-12-31", physicalValue);
+ }
+
+ public void testToPhysicalNoArgs() throws Exception {
+ StringToDateConverter conv = new StringToDateConverter();
+ assertNull(conv.toPhysicalValue(null));
+ Date input = DateUtils.get(2010, Month.DECEMBER, 31);
+ String physicalValue = conv.toPhysicalValue(input);
+ Date virtualValue = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
+ DateFormat.MEDIUM).parse(physicalValue);
+ assertEquals(virtualValue, input);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/convert/StringToDoubleConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/convert/StringToDoubleConverterTest.java b/core/src/test/java/org/apache/metamodel/convert/StringToDoubleConverterTest.java
new file mode 100644
index 0000000..854326e
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/convert/StringToDoubleConverterTest.java
@@ -0,0 +1,39 @@
+/**
+ * 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.convert;
+
+import junit.framework.TestCase;
+
+public class StringToDoubleConverterTest extends TestCase {
+
+ private StringToDoubleConverter conv = new StringToDoubleConverter();
+
+ public void testToVirtual() throws Exception {
+ assertNull(conv.toVirtualValue(null));
+ assertNull(conv.toVirtualValue(""));
+ assertEquals(123d, conv.toVirtualValue("123").doubleValue());
+ assertEquals(123.0d, conv.toVirtualValue("123.0").doubleValue());
+ }
+
+ public void testToPhysical() throws Exception {
+ assertNull(conv.toPhysicalValue(null));
+ assertEquals("123.0", conv.toPhysicalValue(123d));
+ assertEquals("123.0", conv.toPhysicalValue(123.0d));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/convert/StringToIntegerConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/convert/StringToIntegerConverterTest.java b/core/src/test/java/org/apache/metamodel/convert/StringToIntegerConverterTest.java
new file mode 100644
index 0000000..d077cf4
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/convert/StringToIntegerConverterTest.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.convert;
+
+import junit.framework.TestCase;
+
+public class StringToIntegerConverterTest extends TestCase {
+
+ private StringToIntegerConverter conv = new StringToIntegerConverter();
+
+ public void testToVirtual() throws Exception {
+ assertNull(conv.toVirtualValue(null));
+ assertNull(conv.toVirtualValue(""));
+ assertEquals(123, conv.toVirtualValue("123").intValue());
+ }
+
+ public void testToPhysical() throws Exception {
+ assertNull(conv.toPhysicalValue(null));
+ assertEquals("123", conv.toPhysicalValue(123));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/create/AbstractCreateTableBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/create/AbstractCreateTableBuilderTest.java b/core/src/test/java/org/apache/metamodel/create/AbstractCreateTableBuilderTest.java
new file mode 100644
index 0000000..b5a44aa
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/create/AbstractCreateTableBuilderTest.java
@@ -0,0 +1,110 @@
+/**
+ * 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 junit.framework.TestCase;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.schema.ColumnType;
+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.Table;
+import org.eobjects.metamodel.util.MutableRef;
+
+public class AbstractCreateTableBuilderTest extends TestCase {
+
+ public void testExecute() throws Exception {
+ final MutableRef<Boolean> executed = new MutableRef<Boolean>(false);
+
+ Schema schema = new MutableSchema("schema");
+ AbstractTableCreationBuilder<UpdateCallback> builder = new AbstractTableCreationBuilder<UpdateCallback>(null,
+ schema, "tablename") {
+ @Override
+ public Table execute() throws MetaModelException {
+ executed.set(true);
+ return getTable();
+ }
+ };
+
+ assertFalse(executed.get().booleanValue());
+
+ builder.withColumn("foo").ofType(ColumnType.VARCHAR).asPrimaryKey().ofNativeType("vch").ofSize(1234)
+ .nullable(true);
+ builder.withColumn("bar").withColumn("baz").nullable(false);
+ Table table = builder.execute();
+
+ assertTrue(executed.get().booleanValue());
+
+ assertEquals("tablename", table.getName());
+ assertEquals(3, table.getColumnCount());
+ assertEquals(
+ "Column[name=foo,columnNumber=0,type=VARCHAR,nullable=true,nativeType=vch,columnSize=1234]",
+ table.getColumns()[0].toString());
+ assertEquals(
+ "Column[name=bar,columnNumber=1,type=null,nullable=null,nativeType=null,columnSize=null]",
+ table.getColumns()[1].toString());
+ assertEquals(
+ "Column[name=baz,columnNumber=2,type=null,nullable=false,nativeType=null,columnSize=null]",
+ table.getColumns()[2].toString());
+
+ assertEquals("CREATE TABLE schema.tablename (foo VARCHAR(1234) PRIMARY KEY,bar,baz NOT NULL)", builder.toSql());
+ }
+
+ public void testLike() throws Exception {
+ final MutableRef<Boolean> executed = new MutableRef<Boolean>(false);
+
+ Schema schema = new MutableSchema("schema");
+ AbstractTableCreationBuilder<UpdateCallback> builder = new AbstractTableCreationBuilder<UpdateCallback>(null,
+ schema, "tablename") {
+ @Override
+ public Table execute() throws MetaModelException {
+ executed.set(true);
+ return toTable();
+ }
+ };
+
+ assertFalse(executed.get().booleanValue());
+
+ MutableTable likeTable = new MutableTable("blablablabla");
+ likeTable.addColumn(new MutableColumn("foo", ColumnType.VARCHAR, likeTable, 0, 1234, "vch", true, null, false,
+ null));
+ likeTable.addColumn(new MutableColumn("bar"));
+ likeTable.addColumn(new MutableColumn("baz"));
+
+ builder.like(likeTable);
+ Table table = builder.execute();
+
+ assertTrue(executed.get().booleanValue());
+
+ assertEquals("tablename", table.getName());
+ assertEquals(3, table.getColumnCount());
+ assertEquals(
+ "Column[name=foo,columnNumber=0,type=VARCHAR,nullable=true,nativeType=vch,columnSize=1234]",
+ table.getColumns()[0].toString());
+ assertEquals(
+ "Column[name=bar,columnNumber=1,type=null,nullable=null,nativeType=null,columnSize=null]",
+ table.getColumns()[1].toString());
+ assertEquals(
+ "Column[name=baz,columnNumber=2,type=null,nullable=null,nativeType=null,columnSize=null]",
+ table.getColumns()[2].toString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/create/SyntaxExamplesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/create/SyntaxExamplesTest.java b/core/src/test/java/org/apache/metamodel/create/SyntaxExamplesTest.java
new file mode 100644
index 0000000..264fd91
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/create/SyntaxExamplesTest.java
@@ -0,0 +1,38 @@
+/**
+ * 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 junit.framework.TestCase;
+
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+public abstract class SyntaxExamplesTest extends TestCase {
+
+ private TableCreatable dc;
+ private Table table;
+ private Column col;
+ private Schema schema;
+
+ public void testCreateLikeExistingStructure() throws Exception {
+ dc.createTable(schema, "foo").like(table).withColumn("bar").like(col)
+ .nullable(false).execute();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/data/DataSetIteratorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/data/DataSetIteratorTest.java b/core/src/test/java/org/apache/metamodel/data/DataSetIteratorTest.java
new file mode 100644
index 0000000..96443d2
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/data/DataSetIteratorTest.java
@@ -0,0 +1,74 @@
+/**
+ * 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 org.easymock.EasyMock;
+
+import junit.framework.TestCase;
+
+public class DataSetIteratorTest extends TestCase {
+
+ public void testHasNextAndNextAndClose() throws Exception {
+ DataSet ds = EasyMock.createMock(DataSet.class);
+ Row row = EasyMock.createMock(Row.class);
+
+ EasyMock.expect(ds.next()).andReturn(true);
+ EasyMock.expect(ds.getRow()).andReturn(row);
+ EasyMock.expect(ds.next()).andReturn(true);
+ EasyMock.expect(ds.getRow()).andReturn(row);
+ EasyMock.expect(ds.next()).andReturn(false);
+ ds.close();
+
+ EasyMock.replay(ds, row);
+
+ DataSetIterator it = new DataSetIterator(ds);
+
+ // multiple hasNext calls does not iterate before next is called
+ assertTrue(it.hasNext());
+ assertTrue(it.hasNext());
+ assertTrue(it.hasNext());
+
+ assertSame(row, it.next());
+
+ assertTrue(it.hasNext());
+ assertTrue(it.hasNext());
+
+ assertSame(row, it.next());
+ assertFalse(it.hasNext());
+ assertFalse(it.hasNext());
+ assertFalse(it.hasNext());
+
+ assertNull(it.next());
+
+ EasyMock.verify(ds, row);
+ }
+
+ public void testRemove() throws Exception {
+ DataSet ds = EasyMock.createMock(DataSet.class);
+ DataSetIterator it = new DataSetIterator(ds);
+
+ try {
+ it.remove();
+ fail("Exception expected");
+ } catch (UnsupportedOperationException e) {
+ assertEquals("DataSet is read-only, remove() is not supported.",
+ e.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/data/DataSetTableModelTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/data/DataSetTableModelTest.java b/core/src/test/java/org/apache/metamodel/data/DataSetTableModelTest.java
new file mode 100644
index 0000000..b125f8f
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/data/DataSetTableModelTest.java
@@ -0,0 +1,57 @@
+/**
+ * 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.List;
+
+import javax.swing.table.TableModel;
+
+import org.eobjects.metamodel.MetaModelHelper;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.MutableColumn;
+
+import junit.framework.TestCase;
+
+public class DataSetTableModelTest extends TestCase {
+
+ public void testToTableModel() throws Exception {
+ SelectItem[] selectItems = MetaModelHelper.createSelectItems(new MutableColumn("CUSTOMERNUMBER"),
+ new MutableColumn("CUSTOMERNAME"), new MutableColumn("CONTACTLASTNAME"));
+ CachingDataSetHeader header = new CachingDataSetHeader(selectItems);
+ List<Row> rows = new ArrayList<Row>();
+ rows.add(new DefaultRow(header, new Object[] { 1, "John", "Doe" }));
+ rows.add(new DefaultRow(header, new Object[] { 2, "John", "Taylor" }));
+ DataSet data = new InMemoryDataSet(header, rows);
+
+ @SuppressWarnings("deprecation")
+ TableModel tableModel = data.toTableModel();
+ data.close();
+
+ assertEquals(3, tableModel.getColumnCount());
+ assertEquals("CUSTOMERNUMBER", tableModel.getColumnName(0));
+ assertEquals("CUSTOMERNAME", tableModel.getColumnName(1));
+ assertEquals("CONTACTLASTNAME", tableModel.getColumnName(2));
+ assertEquals(2, tableModel.getRowCount());
+
+ // Take a small sample from the data
+ assertEquals("Taylor", tableModel.getValueAt(1, 2).toString());
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/data/DefaultRowTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/data/DefaultRowTest.java b/core/src/test/java/org/apache/metamodel/data/DefaultRowTest.java
new file mode 100644
index 0000000..7ab78c1
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/data/DefaultRowTest.java
@@ -0,0 +1,109 @@
+/**
+ * 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.FileInputStream;
+import java.io.ObjectInputStream;
+import java.lang.reflect.Field;
+
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.util.FileHelper;
+
+import junit.framework.TestCase;
+
+public class DefaultRowTest extends TestCase {
+
+ SelectItem[] items = new SelectItem[] { new SelectItem(new MutableColumn("foo")),
+ new SelectItem(new MutableColumn("bar")) };
+ Object[] values = new Object[] { "foo", "bar" };
+
+ public void testDeserializeBackwardsCompatible() throws Exception {
+ Object obj;
+ FileInputStream fileIn = new FileInputStream("src/test/resources/metamodel-3.0-default-row.ser");
+ try {
+ ObjectInputStream ois = new ObjectInputStream(fileIn);
+ obj = ois.readObject();
+ ois.close();
+ } finally {
+ FileHelper.safeClose(fileIn);
+ }
+
+ assertTrue(obj instanceof Row);
+ assertTrue(obj instanceof DefaultRow);
+
+ Row row = (Row) obj;
+ assertEquals(2, row.size());
+ SelectItem[] selectItems = row.getSelectItems();
+ assertEquals("foo", selectItems[0].toString());
+ assertEquals("bar", selectItems[1].toString());
+
+ assertEquals("foo", row.getValue(0));
+ assertEquals("bar", row.getValue(1));
+
+ assertEquals(Style.NO_STYLE, row.getStyle(0));
+ assertEquals(Style.NO_STYLE, row.getStyle(1));
+ }
+
+ public void testGetValueOfColumn() throws Exception {
+ DefaultRow row = new DefaultRow(new SimpleDataSetHeader(items), values);
+ assertEquals("foo", row.getValue(new MutableColumn("foo")));
+ assertNull(row.getValue(new MutableColumn("hello world")));
+ }
+
+ public void testCustomStyles() throws Exception {
+ Style[] styles = new Style[] { Style.NO_STYLE, new StyleBuilder().bold().create() };
+ DefaultRow row = new DefaultRow(new SimpleDataSetHeader(items), values, styles);
+
+ Field field = DefaultRow.class.getDeclaredField("_styles");
+ assertNotNull(field);
+
+ field.setAccessible(true);
+ assertNotNull(field.get(row));
+
+ assertEquals(Style.NO_STYLE, row.getStyle(0));
+ assertEquals("font-weight: bold;", row.getStyle(1).toCSS());
+ }
+
+ public void testNoStylesReference() throws Exception {
+ Style[] styles = new Style[] { Style.NO_STYLE, Style.NO_STYLE };
+ DefaultRow row = new DefaultRow(new SimpleDataSetHeader(items), values, styles);
+
+ Field field = DefaultRow.class.getDeclaredField("_styles");
+ assertNotNull(field);
+
+ field.setAccessible(true);
+ assertNull(field.get(row));
+
+ assertEquals(Style.NO_STYLE, row.getStyle(0));
+ assertEquals(Style.NO_STYLE, row.getStyle(items[0]));
+ assertEquals(Style.NO_STYLE, row.getStyle(items[0].getColumn()));
+ }
+
+ public void testNullStyle() throws Exception {
+ Style[] styles = new Style[] { Style.NO_STYLE, null };
+
+ try {
+ new DefaultRow(new SimpleDataSetHeader(items), values, styles);
+ fail("Exception expected");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Elements in the style array cannot be null", e.getMessage());
+ }
+ }
+}
[12/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelUtils.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelUtils.java b/excel/src/main/java/org/eobjects/metamodel/excel/ExcelUtils.java
deleted file mode 100644
index 7b3a67e..0000000
--- a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelUtils.java
+++ /dev/null
@@ -1,419 +0,0 @@
-/**
- * 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.excel;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.text.NumberFormat;
-import java.util.Date;
-import java.util.Iterator;
-
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.apache.poi.hssf.usermodel.HSSFDateUtil;
-import org.apache.poi.hssf.usermodel.HSSFFont;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.util.HSSFColor;
-import org.apache.poi.ss.formula.FormulaParseException;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.Color;
-import org.apache.poi.ss.usermodel.Font;
-import org.apache.poi.ss.usermodel.FontUnderline;
-import org.apache.poi.ss.usermodel.FormulaError;
-import org.apache.poi.ss.usermodel.FormulaEvaluator;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.WorkbookFactory;
-import org.apache.poi.xssf.streaming.SXSSFWorkbook;
-import org.apache.poi.xssf.usermodel.XSSFCell;
-import org.apache.poi.xssf.usermodel.XSSFColor;
-import org.apache.poi.xssf.usermodel.XSSFFont;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetHeader;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.EmptyDataSet;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.data.Style.SizeUnit;
-import org.eobjects.metamodel.data.StyleBuilder;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.Action;
-import org.eobjects.metamodel.util.DateUtils;
-import org.eobjects.metamodel.util.FormatHelper;
-import org.eobjects.metamodel.util.Func;
-import org.eobjects.metamodel.util.Resource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.xml.sax.XMLReader;
-
-/**
- * Convenience/reusable methods for Excel workbook handling.
- *
- * @author Kasper Sørensen
- */
-final class ExcelUtils {
-
- private static final Logger logger = LoggerFactory.getLogger(ExcelUtils.class);
-
- private static final NumberFormat _numberFormat = FormatHelper.getUiNumberFormat();
-
- private ExcelUtils() {
- // prevent instantiation
- }
-
- public static XMLReader createXmlReader() {
- try {
- SAXParserFactory saxFactory = SAXParserFactory.newInstance();
- SAXParser saxParser = saxFactory.newSAXParser();
- XMLReader sheetParser = saxParser.getXMLReader();
- return sheetParser;
- } catch (Exception e) {
- throw new MetaModelException(e);
- }
- }
-
- /**
- * Initializes a workbook instance based on a inputstream.
- *
- * @return a workbook instance based on the inputstream.
- */
- public static Workbook readWorkbook(InputStream inputStream) {
- try {
- return WorkbookFactory.create(inputStream);
- } catch (Exception e) {
- logger.error("Could not open workbook", e);
- throw new IllegalStateException("Could not open workbook", e);
- }
- }
-
- public static Workbook readWorkbook(Resource resource) {
- return resource.read(new Func<InputStream, Workbook>() {
- @Override
- public Workbook eval(InputStream inputStream) {
- return readWorkbook(inputStream);
- }
- });
- }
-
- public static boolean isXlsxFile(Resource resource) {
- if (resource == null) {
- return false;
- }
- return resource.getName().toLowerCase().endsWith(".xlsx");
- }
-
- /**
- * Initializes a workbook instance based on a {@link ExcelDataContext}.
- *
- * @return a workbook instance based on the ExcelDataContext.
- */
- public static Workbook readWorkbook(ExcelDataContext dataContext) {
- Resource resource = dataContext.getResource();
- if (!resource.isExists()) {
- if (isXlsxFile(resource)) {
- return new SXSSFWorkbook(1000);
- } else {
- return new HSSFWorkbook();
- }
- }
- return readWorkbook(resource);
- }
-
- public static void writeWorkbook(ExcelDataContext dataContext, final Workbook wb) {
- final Resource resource = dataContext.getResource();
- resource.write(new Action<OutputStream>() {
- @Override
- public void run(OutputStream outputStream) throws Exception {
- wb.write(outputStream);
- }
- });
- }
-
- public static String getCellValue(Workbook wb, Cell cell) {
- if (cell == null) {
- return null;
- }
-
- final String cellCoordinate = "(" + cell.getRowIndex() + "," + cell.getColumnIndex() + ")";
-
- final String result;
-
- switch (cell.getCellType()) {
- case Cell.CELL_TYPE_BLANK:
- result = null;
- break;
- case Cell.CELL_TYPE_BOOLEAN:
- result = Boolean.toString(cell.getBooleanCellValue());
- break;
- case Cell.CELL_TYPE_ERROR:
- String errorResult;
- try {
- byte errorCode = cell.getErrorCellValue();
- FormulaError formulaError = FormulaError.forInt(errorCode);
- errorResult = formulaError.getString();
- } catch (RuntimeException e) {
- logger.debug("Getting error code for {} failed!: {}", cellCoordinate, e.getMessage());
- if (cell instanceof XSSFCell) {
- // hack to get error string, which is available
- String value = ((XSSFCell) cell).getErrorCellString();
- errorResult = value;
- } else {
- logger.error("Couldn't handle unexpected error scenario in cell: " + cellCoordinate, e);
- throw e;
- }
- }
- result = errorResult;
- break;
- case Cell.CELL_TYPE_FORMULA:
- // result = cell.getCellFormula();
- result = getFormulaCellValue(wb, cell);
- break;
- case Cell.CELL_TYPE_NUMERIC:
- if (HSSFDateUtil.isCellDateFormatted(cell)) {
- Date date = cell.getDateCellValue();
- if (date == null) {
- result = null;
- } else {
- result = DateUtils.createDateFormat().format(date);
- }
- } else {
- // TODO: Consider not formatting it, but simple using
- // Double.toString(...)
- result = _numberFormat.format(cell.getNumericCellValue());
- }
- break;
- case Cell.CELL_TYPE_STRING:
- result = cell.getRichStringCellValue().getString();
- break;
- default:
- throw new IllegalStateException("Unknown cell type: " + cell.getCellType());
- }
-
- logger.debug("cell {} resolved to value: {}", cellCoordinate, result);
-
- return result;
- }
-
- private static String getFormulaCellValue(Workbook wb, Cell cell) {
- // first try with a cached/precalculated value
- try {
- double numericCellValue = cell.getNumericCellValue();
- // TODO: Consider not formatting it, but simple using
- // Double.toString(...)
- return _numberFormat.format(numericCellValue);
- } catch (Exception e) {
- if (logger.isInfoEnabled()) {
- logger.info("Failed to fetch cached/precalculated formula value of cell: " + cell, e);
- }
- }
-
- // evaluate cell first, if possible
- try {
- if (logger.isInfoEnabled()) {
- logger.info("cell({},{}) is a formula. Attempting to evaluate: {}",
- new Object[] { cell.getRowIndex(), cell.getColumnIndex(), cell.getCellFormula() });
- }
-
- final FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
-
- // calculates the formula and puts it's value back into the cell
- final Cell evaluatedCell = evaluator.evaluateInCell(cell);
-
- return getCellValue(wb, evaluatedCell);
- } catch (RuntimeException e) {
- logger.warn("Exception occurred while evaluating formula at position ({},{}): {}", new Object[] { cell.getRowIndex(),
- cell.getColumnIndex(), e.getMessage() });
- // Some exceptions we simply log - result will be then be the
- // actual formula
- if (e instanceof FormulaParseException) {
- logger.error("Parse exception occurred while evaluating cell formula: " + cell, e);
- } else if (e instanceof IllegalArgumentException) {
- logger.error("Illegal formula argument occurred while evaluating cell formula: " + cell, e);
- } else {
- logger.error("Unexpected exception occurred while evaluating cell formula: " + cell, e);
- }
- }
-
- // last resort: return the string formula
- return cell.getCellFormula();
- }
-
- public static Style getCellStyle(Workbook workbook, Cell cell) {
- if (cell == null) {
- return Style.NO_STYLE;
- }
- final CellStyle cellStyle = cell.getCellStyle();
-
- final short fontIndex = cellStyle.getFontIndex();
- final Font font = workbook.getFontAt(fontIndex);
- final StyleBuilder styleBuilder = new StyleBuilder();
-
- // Font bold, italic, underline
- if (font.getBoldweight() >= Font.BOLDWEIGHT_BOLD) {
- styleBuilder.bold();
- }
- if (font.getItalic()) {
- styleBuilder.italic();
- }
- if (font.getUnderline() != FontUnderline.NONE.getByteValue()) {
- styleBuilder.underline();
- }
-
- // Font size
- final Font stdFont = workbook.getFontAt((short) 0);
- final short fontSize = font.getFontHeightInPoints();
- if (stdFont.getFontHeightInPoints() != fontSize) {
- styleBuilder.fontSize(fontSize, SizeUnit.PT);
- }
-
- // Font color
- final short colorIndex = font.getColor();
- if (font instanceof HSSFFont) {
- if (colorIndex != HSSFFont.COLOR_NORMAL) {
- final HSSFWorkbook wb = (HSSFWorkbook) workbook;
- HSSFColor color = wb.getCustomPalette().getColor(colorIndex);
- if (color != null) {
- short[] triplet = color.getTriplet();
- styleBuilder.foreground(triplet);
- }
- }
- } else if (font instanceof XSSFFont) {
- XSSFFont xssfFont = (XSSFFont) font;
-
- XSSFColor color = xssfFont.getXSSFColor();
- if (color != null) {
- String argbHex = color.getARGBHex();
- if (argbHex != null) {
- styleBuilder.foreground(argbHex.substring(2));
- }
- }
- } else {
- throw new IllegalStateException("Unexpected font type: " + (font == null ? "null" : font.getClass()) + ")");
- }
-
- // Background color
- if (cellStyle.getFillPattern() == 1) {
- Color color = cellStyle.getFillForegroundColorColor();
- if (color instanceof HSSFColor) {
- short[] triplet = ((HSSFColor) color).getTriplet();
- if (triplet != null) {
- styleBuilder.background(triplet);
- }
- } else if (color instanceof XSSFColor) {
- String argb = ((XSSFColor) color).getARGBHex();
- if (argb != null) {
- styleBuilder.background(argb.substring(2));
- }
- } else {
- throw new IllegalStateException("Unexpected color type: " + (color == null ? "null" : color.getClass()) + ")");
- }
- }
-
- // alignment
- switch (cellStyle.getAlignment()) {
- case CellStyle.ALIGN_LEFT:
- styleBuilder.leftAligned();
- break;
- case CellStyle.ALIGN_RIGHT:
- styleBuilder.rightAligned();
- break;
- case CellStyle.ALIGN_CENTER:
- styleBuilder.centerAligned();
- break;
- case CellStyle.ALIGN_JUSTIFY:
- styleBuilder.justifyAligned();
- break;
- }
-
- return styleBuilder.create();
- }
-
- public static Iterator<Row> getRowIterator(Sheet sheet, ExcelConfiguration configuration, boolean jumpToDataRows) {
- final Iterator<Row> iterator;
- if (configuration.isSkipEmptyLines()) {
- iterator = sheet.rowIterator();
- } else {
- iterator = new ZeroBasedRowIterator(sheet);
- }
-
- if (jumpToDataRows) {
- final int columnNameLineNumber = configuration.getColumnNameLineNumber();
- if (columnNameLineNumber != ExcelConfiguration.NO_COLUMN_NAME_LINE) {
- // iterate past the column headers
- if (iterator.hasNext()) {
- iterator.next();
- }
- for (int i = 1; i < columnNameLineNumber; i++) {
- if (iterator.hasNext()) {
- iterator.next();
- } else {
- // no more rows!
- break;
- }
- }
- }
- }
-
- return iterator;
- }
-
- /**
- * Creates a MetaModel row based on an Excel row
- *
- * @param workbook
- * @param row
- * @param selectItems
- * select items of the columns in the table
- * @return
- */
- public static DefaultRow createRow(Workbook workbook, Row row, DataSetHeader header) {
- final int size = header.size();
- final String[] values = new String[size];
- final Style[] styles = new Style[size];
- if (row != null) {
- for (int i = 0; i < size; i++) {
- final int columnNumber = header.getSelectItem(i).getColumn().getColumnNumber();
- final Cell cell = row.getCell(columnNumber);
- final String value = ExcelUtils.getCellValue(workbook, cell);
- final Style style = ExcelUtils.getCellStyle(workbook, cell);
- values[i] = value;
- styles[i] = style;
- }
- }
-
- return new DefaultRow(header, values, styles);
- }
-
- public static DataSet getDataSet(Workbook workbook, Sheet sheet, Table table, ExcelConfiguration configuration) {
- final SelectItem[] selectItems = MetaModelHelper.createSelectItems(table.getColumns());
- final Iterator<Row> rowIterator = getRowIterator(sheet, configuration, true);
- if (!rowIterator.hasNext()) {
- // no more rows!
- return new EmptyDataSet(selectItems);
- }
-
- final DataSet dataSet = new XlsDataSet(selectItems, workbook, rowIterator);
- return dataSet;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/eobjects/metamodel/excel/SpreadsheetReaderDelegate.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/eobjects/metamodel/excel/SpreadsheetReaderDelegate.java b/excel/src/main/java/org/eobjects/metamodel/excel/SpreadsheetReaderDelegate.java
deleted file mode 100644
index 8678edf..0000000
--- a/excel/src/main/java/org/eobjects/metamodel/excel/SpreadsheetReaderDelegate.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * 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.excel;
-
-import java.io.InputStream;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.Ref;
-
-/**
- * Delegate for spreadsheet-implementation specific operations in an
- * {@link ExcelDataContext}.
- *
- * @author Kasper Sørensen
- */
-interface SpreadsheetReaderDelegate {
-
- public void notifyTablesModified(Ref<InputStream> inputStreamRef);
-
- public Schema createSchema(InputStream inputStream, String schemaName)
- throws Exception;
-
- public DataSet executeQuery(InputStream inputStream, Table table,
- Column[] columns, int maxRows) throws Exception;
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/eobjects/metamodel/excel/XlsDataSet.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/eobjects/metamodel/excel/XlsDataSet.java b/excel/src/main/java/org/eobjects/metamodel/excel/XlsDataSet.java
deleted file mode 100644
index b18fbcb..0000000
--- a/excel/src/main/java/org/eobjects/metamodel/excel/XlsDataSet.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * 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.excel;
-
-import java.util.Iterator;
-
-import org.apache.poi.ss.usermodel.Workbook;
-import org.eobjects.metamodel.data.AbstractDataSet;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.SelectItem;
-
-/**
- * Stream {@link DataSet} implementation for Excel support.
- *
- * @author Kasper Sørensen
- */
-final class XlsDataSet extends AbstractDataSet {
-
- private final Iterator<org.apache.poi.ss.usermodel.Row> _rowIterator;
- private final Workbook _workbook;
-
- private volatile org.apache.poi.ss.usermodel.Row _row;
- private volatile boolean _closed;
-
- /**
- * Creates an XLS dataset
- *
- * @param selectItems
- * the selectitems representing the columns of the table
- * @param workbook
- * @param rowIterator
- */
- public XlsDataSet(SelectItem[] selectItems, Workbook workbook,
- Iterator<org.apache.poi.ss.usermodel.Row> rowIterator) {
- super(selectItems);
- _workbook = workbook;
- _rowIterator = rowIterator;
- _closed = false;
- }
-
- @Override
- public boolean next() {
- if (_rowIterator.hasNext()) {
- _row = _rowIterator.next();
- return true;
- } else {
- _row = null;
- _closed = true;
- return false;
- }
- }
-
- @Override
- public Row getRow() {
- if (_closed) {
- return null;
- }
-
- return ExcelUtils.createRow(_workbook, _row, getHeader());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/eobjects/metamodel/excel/XlsxRowCallback.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/eobjects/metamodel/excel/XlsxRowCallback.java b/excel/src/main/java/org/eobjects/metamodel/excel/XlsxRowCallback.java
deleted file mode 100644
index 37bf14f..0000000
--- a/excel/src/main/java/org/eobjects/metamodel/excel/XlsxRowCallback.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * 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.excel;
-
-import java.util.List;
-
-import org.eobjects.metamodel.data.Style;
-
-/**
- * Callback for read rows in an XLSX spreadsheet.
- *
- * @author Kasper Sørensen
- */
-interface XlsxRowCallback {
-
- public boolean row(int rowNumber, List<String> values, List<Style> styles);
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/eobjects/metamodel/excel/XlsxRowPublisherAction.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/eobjects/metamodel/excel/XlsxRowPublisherAction.java b/excel/src/main/java/org/eobjects/metamodel/excel/XlsxRowPublisherAction.java
deleted file mode 100644
index 85bbd58..0000000
--- a/excel/src/main/java/org/eobjects/metamodel/excel/XlsxRowPublisherAction.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/**
- * 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.excel;
-
-import java.io.InputStream;
-import java.util.List;
-
-import org.apache.poi.xssf.eventusermodel.XSSFReader;
-import org.eobjects.metamodel.data.RowPublisher;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.util.Action;
-import org.eobjects.metamodel.util.FileHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.xml.sax.InputSource;
-import org.xml.sax.XMLReader;
-
-class XlsxRowPublisherAction implements Action<RowPublisher> {
-
- private static final Logger logger = LoggerFactory
- .getLogger(XlsxRowPublisherAction.class);
-
- private final ExcelConfiguration _configuration;
- private final Column[] _columns;
- private final String _relationshipId;
- private final XSSFReader _xssfReader;
-
- public XlsxRowPublisherAction(ExcelConfiguration configuration,
- Column[] columns, String relationshipId, XSSFReader xssfReader) {
- _configuration = configuration;
- _columns = columns;
- _relationshipId = relationshipId;
- _xssfReader = xssfReader;
- }
-
- @Override
- public void run(final RowPublisher publisher) throws Exception {
- final InputStream sheetData = _xssfReader.getSheet(_relationshipId);
-
- final XlsxRowCallback rowCallback = new XlsxRowCallback() {
- @Override
- public boolean row(int rowNumber, List<String> values,
- List<Style> styles) {
- if (_configuration.getColumnNameLineNumber() != ExcelConfiguration.NO_COLUMN_NAME_LINE) {
- final int zeroBasedLineNumber = _configuration.getColumnNameLineNumber() - 1;
- if (rowNumber <= zeroBasedLineNumber) {
- // skip header rows
- return true;
- }
- }
-
- Object[] rowData = new Object[_columns.length];
- Style[] styleData = new Style[_columns.length];
- for (int i = 0; i < _columns.length; i++) {
- int columnNumber = _columns[i].getColumnNumber();
- if (columnNumber < values.size()) {
- rowData[i] = values.get(columnNumber);
- styleData[i] = styles.get(columnNumber);
- } else {
- rowData[i] = null;
- styleData[i] = Style.NO_STYLE;
- }
- }
-
- return publisher.publish(rowData, styleData);
- }
- };
- final XlsxSheetToRowsHandler handler = new XlsxSheetToRowsHandler(
- rowCallback, _xssfReader, _configuration);
-
- final XMLReader sheetParser = ExcelUtils.createXmlReader();
- sheetParser.setContentHandler(handler);
- sheetParser.setErrorHandler(handler);
- try {
- sheetParser.parse(new InputSource(sheetData));
- } catch (XlsxStopParsingException e) {
- logger.debug("Parsing stop signal thrown");
- } catch (Exception e) {
- logger.warn("Unexpected error occurred while parsing", e);
- throw e;
- } finally {
- publisher.finished();
- FileHelper.safeClose(sheetData);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/eobjects/metamodel/excel/XlsxSheetToRowsHandler.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/eobjects/metamodel/excel/XlsxSheetToRowsHandler.java b/excel/src/main/java/org/eobjects/metamodel/excel/XlsxSheetToRowsHandler.java
deleted file mode 100644
index 2a6b9ad..0000000
--- a/excel/src/main/java/org/eobjects/metamodel/excel/XlsxSheetToRowsHandler.java
+++ /dev/null
@@ -1,341 +0,0 @@
-/**
- * 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.excel;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-
-import org.apache.poi.hssf.usermodel.HSSFDateUtil;
-import org.apache.poi.ss.usermodel.BuiltinFormats;
-import org.apache.poi.ss.usermodel.DataFormatter;
-import org.apache.poi.ss.usermodel.DateUtil;
-import org.apache.poi.ss.usermodel.FillPatternType;
-import org.apache.poi.ss.usermodel.FontUnderline;
-import org.apache.poi.xssf.eventusermodel.XSSFReader;
-import org.apache.poi.xssf.model.SharedStringsTable;
-import org.apache.poi.xssf.model.StylesTable;
-import org.apache.poi.xssf.usermodel.XSSFCellStyle;
-import org.apache.poi.xssf.usermodel.XSSFColor;
-import org.apache.poi.xssf.usermodel.XSSFFont;
-import org.apache.poi.xssf.usermodel.XSSFRichTextString;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.data.Style.SizeUnit;
-import org.eobjects.metamodel.data.StyleBuilder;
-import org.eobjects.metamodel.util.DateUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * XML handler for transforming a sheet into rows. Uses an
- * {@link XlsxRowCallback} to publish identified rows.
- *
- * @author Kasper Sørensen
- */
-final class XlsxSheetToRowsHandler extends DefaultHandler {
-
- private static final Logger logger = LoggerFactory
- .getLogger(XlsxSheetToRowsHandler.class);
-
- private static enum XssfDataType {
- BOOL, ERROR, FORMULA, INLINESTR, SSTINDEX, NUMBER,
- }
-
- // global variables
- private final XlsxRowCallback _callback;
- private final ExcelConfiguration _configuration;
- private final StylesTable _stylesTable;
- private final SharedStringsTable _sharedStringTable;
-
- // variables used to hold information about the current rows
- private int _rowNumber;
- private final List<String> _rowValues;
- private final List<Style> _styles;
-
- // variables used to hold information about the current visited cells
- private final StringBuilder _value;
- private final StyleBuilder _style;
- private boolean _inCell;
- private boolean _inFormula;
- private int _columnNumber;
- private XssfDataType _dataType;
- private int _formatIndex;
- private String _formatString;
-
- public XlsxSheetToRowsHandler(XlsxRowCallback callback,
- XSSFReader xssfReader, ExcelConfiguration configuration)
- throws Exception {
- _callback = callback;
- _configuration = configuration;
-
- _sharedStringTable = xssfReader.getSharedStringsTable();
- _stylesTable = xssfReader.getStylesTable();
-
- _value = new StringBuilder();
- _style = new StyleBuilder();
- _rowValues = new ArrayList<String>();
- _styles = new ArrayList<Style>();
- _rowNumber = -1;
- _inCell = false;
- _inFormula = false;
- }
-
- @Override
- public void startElement(String uri, String localName, String qName,
- Attributes attributes) throws SAXException {
- if ("row".equals(qName)) {
- // element is a row
-
- // excel row numbers are 1-based
- int rowNumber = Integer.parseInt(attributes.getValue("r"));
- rowNumber = rowNumber - 1;
-
- if (_configuration.isSkipEmptyLines()) {
- _rowNumber++;
- } else {
- while (_rowNumber + 1 < rowNumber) {
- // empty lines are not skipped, so dispatch empty lines
- _rowNumber++;
- List<String> emptyValues = Collections.emptyList();
- List<Style> emptyStyles = Collections.emptyList();
- _callback.row(_rowNumber, emptyValues, emptyStyles);
- }
- _rowNumber = rowNumber;
- }
- } else if ("c".equals(qName)) {
- // element is a cell
-
- _inCell = true;
-
- final String r = attributes.getValue("r");
- int firstDigit = -1;
- for (int c = 0; c < r.length(); ++c) {
- if (Character.isDigit(r.charAt(c))) {
- firstDigit = c;
- break;
- }
- }
- _columnNumber = nameToColumn(r.substring(0, firstDigit));
-
- // Set up defaults.
- _dataType = XssfDataType.NUMBER;
- _formatIndex = -1;
- _formatString = null;
-
- final String cellType = attributes.getValue("t");
- if ("b".equals(cellType)) {
- _dataType = XssfDataType.BOOL;
- } else if ("e".equals(cellType)) {
- _dataType = XssfDataType.ERROR;
- } else if ("inlineStr".equals(cellType)) {
- _dataType = XssfDataType.INLINESTR;
- } else if ("s".equals(cellType)) {
- _dataType = XssfDataType.SSTINDEX;
- } else if ("str".equals(cellType)) {
- _dataType = XssfDataType.FORMULA;
- }
-
- String cellStyleStr = attributes.getValue("s");
- if (cellStyleStr != null) {
- // It's a number, but almost certainly one
- // with a special style or format
- int styleIndex = Integer.parseInt(cellStyleStr);
- XSSFCellStyle style = _stylesTable.getStyleAt(styleIndex);
-
- configureStyle(style);
-
- if (_dataType == XssfDataType.NUMBER) {
- this._formatIndex = style.getDataFormat();
- this._formatString = style.getDataFormatString();
- if (this._formatString == null) {
- this._formatString = BuiltinFormats
- .getBuiltinFormat(this._formatIndex);
- }
- }
- }
- } else if (_inCell && "f".equals(qName)) {
- // skip the actual formula line
- _inFormula = true;
- }
- }
-
- private void configureStyle(XSSFCellStyle style) {
- XSSFFont font = style.getFont();
- if (font.getBold()) {
- _style.bold();
- }
- if (font.getItalic()) {
- _style.italic();
- }
- if (font.getUnderline() != FontUnderline.NONE.getByteValue()) {
- _style.underline();
- }
-
- if (style.getFillPatternEnum() == FillPatternType.SOLID_FOREGROUND) {
- XSSFColor fillForegroundXSSFColor = style
- .getFillForegroundXSSFColor();
- String argb = fillForegroundXSSFColor.getARGBHex();
- if (argb != null) {
- _style.background(argb.substring(2));
- }
- }
-
- final XSSFFont stdFont = _stylesTable.getStyleAt(0).getFont();
- final short fontHeight = style.getFont().getFontHeightInPoints();
- if (stdFont.getFontHeightInPoints() != fontHeight) {
- _style.fontSize(fontHeight, SizeUnit.PT);
- }
-
- XSSFColor fontColor = style.getFont().getXSSFColor();
- if (fontColor != null) {
- String argbHex = fontColor.getARGBHex();
- if (argbHex != null) {
- _style.foreground(argbHex.substring(2));
- }
- }
-
- switch (style.getAlignmentEnum()) {
- case LEFT:
- _style.leftAligned();
- break;
- case RIGHT:
- _style.rightAligned();
- break;
- case CENTER:
- _style.centerAligned();
- break;
- case JUSTIFY:
- _style.justifyAligned();
- break;
- }
-
- }
-
- @Override
- public void endElement(String uri, String localName, String qName)
- throws SAXException {
- if ("row".equals(qName)) {
- // element was a row
- boolean next = _callback.row(_rowNumber, _rowValues, _styles);
- if (!next) {
- throw new XlsxStopParsingException();
- }
- _rowValues.clear();
- _styles.clear();
- } else if ("c".equals(qName)) {
- // element was a cell
-
- _inCell = false;
-
- while (_rowValues.size() < _columnNumber) {
- _rowValues.add(null);
- _styles.add(Style.NO_STYLE);
- }
-
- _rowValues.add(createValue());
- _styles.add(_style.create());
- _value.setLength(0);
- _style.reset();
- } else if (_inFormula && "f".equals(qName)) {
- // skip the actual formula line
- _inFormula = false;
- }
- }
-
- private String createValue() {
- if (_value.length() == 0) {
- return null;
- }
-
- switch (_dataType) {
-
- case BOOL:
- char first = _value.charAt(0);
- return first == '0' ? "false" : "true";
- case ERROR:
- logger.warn("Error-cell occurred: {}", _value);
- return _value.toString();
- case FORMULA:
- return _value.toString();
- case INLINESTR:
- XSSFRichTextString rtsi = new XSSFRichTextString(_value.toString());
- return rtsi.toString();
- case SSTINDEX:
- String sstIndex = _value.toString();
- int idx = Integer.parseInt(sstIndex);
- XSSFRichTextString rtss = new XSSFRichTextString(
- _sharedStringTable.getEntryAt(idx));
- return rtss.toString();
- case NUMBER:
- final String numberString = _value.toString();
- if (_formatString != null) {
- DataFormatter formatter = getDataFormatter();
- if (HSSFDateUtil.isADateFormat(_formatIndex, _formatString)) {
- Date date = DateUtil.getJavaDate(Double
- .parseDouble(numberString));
- return DateUtils.createDateFormat().format(date);
- }
- return formatter.formatRawCellContents(
- Double.parseDouble(numberString), _formatIndex,
- _formatString);
- } else {
- if (numberString.endsWith(".0")) {
- // xlsx only stores doubles, so integers get ".0" appended
- // to them
- return numberString.substring(0, numberString.length() - 2);
- }
- return numberString;
- }
- default:
- logger.error("Unsupported data type: {}", _dataType);
- return "";
- }
- }
-
- private DataFormatter getDataFormatter() {
- return new DataFormatter();
- }
-
- @Override
- public void characters(char[] ch, int start, int length)
- throws SAXException {
- if (_inCell && !_inFormula) {
- _value.append(ch, start, length);
- }
- }
-
- /**
- * Converts an Excel column name like "C" to a zero-based index.
- *
- * @param name
- * @return Index corresponding to the specified name
- */
- private int nameToColumn(String name) {
- int column = -1;
- for (int i = 0; i < name.length(); ++i) {
- int c = name.charAt(i);
- column = (column + 1) * 26 + c - 'A';
- }
- return column;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/eobjects/metamodel/excel/XlsxSpreadsheetReaderDelegate.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/eobjects/metamodel/excel/XlsxSpreadsheetReaderDelegate.java b/excel/src/main/java/org/eobjects/metamodel/excel/XlsxSpreadsheetReaderDelegate.java
deleted file mode 100644
index 423d38f..0000000
--- a/excel/src/main/java/org/eobjects/metamodel/excel/XlsxSpreadsheetReaderDelegate.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/**
- * 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.excel;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.poi.openxml4j.opc.OPCPackage;
-import org.apache.poi.xssf.eventusermodel.XSSFReader;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.RowPublisherDataSet;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-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.Table;
-import org.eobjects.metamodel.util.AlphabeticSequence;
-import org.eobjects.metamodel.util.FileHelper;
-import org.eobjects.metamodel.util.Ref;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.xml.sax.InputSource;
-import org.xml.sax.XMLReader;
-
-/**
- * {@link SpreadsheetReaderDelegate} implementation for the "new" XLSX format.
- * This implementation is very efficient as it uses SAX XML parsing which does
- * not bloat memory usage in the same way that POI's user model does.
- *
- * @author Kasper Sørensen
- */
-final class XlsxSpreadsheetReaderDelegate implements SpreadsheetReaderDelegate {
-
- private static final Logger logger = LoggerFactory.getLogger(XlsxSpreadsheetReaderDelegate.class);
-
- private final ExcelConfiguration _configuration;
- private final Map<String, String> _tableNamesToInternalIds;
-
- public XlsxSpreadsheetReaderDelegate(ExcelConfiguration configuration) {
- _configuration = configuration;
- _tableNamesToInternalIds = new HashMap<String, String>();
- }
-
- @Override
- public DataSet executeQuery(InputStream inputStream, Table table, Column[] columns, int maxRows) throws Exception {
- final OPCPackage pkg = OPCPackage.open(inputStream);
- final XSSFReader xssfReader = new XSSFReader(pkg);
- final String relationshipId = _tableNamesToInternalIds.get(table.getName());
-
- return buildDataSet(columns, maxRows, relationshipId, xssfReader);
- }
-
- @Override
- public Schema createSchema(InputStream inputStream, String schemaName) throws Exception {
- final MutableSchema schema = new MutableSchema(schemaName);
- final OPCPackage pkg = OPCPackage.open(inputStream);
- final XSSFReader xssfReader = new XSSFReader(pkg);
-
- final XlsxWorkbookToTablesHandler workbookToTables = new XlsxWorkbookToTablesHandler(schema,
- _tableNamesToInternalIds);
- buildTables(xssfReader, workbookToTables);
-
- for (Entry<String, String> entry : _tableNamesToInternalIds.entrySet()) {
-
- final String tableName = entry.getKey();
- final String relationshipId = entry.getValue();
-
- final MutableTable table = (MutableTable) schema.getTableByName(tableName);
-
- buildColumns(table, relationshipId, xssfReader);
- }
- return schema;
- }
-
- @Override
- public void notifyTablesModified(Ref<InputStream> inputStreamRef) {
- InputStream inputStream = inputStreamRef.get();
- final XlsxWorkbookToTablesHandler workbookToTables = new XlsxWorkbookToTablesHandler(null,
- _tableNamesToInternalIds);
- try {
- final OPCPackage pkg = OPCPackage.open(inputStream);
- final XSSFReader xssfReader = new XSSFReader(pkg);
- buildTables(xssfReader, workbookToTables);
- } catch (Exception e) {
- throw new IllegalStateException(e);
- } finally {
- FileHelper.safeClose(inputStream);
- }
- }
-
- private DataSet buildDataSet(final Column[] columns, int maxRows, final String relationshipId,
- final XSSFReader xssfReader) throws Exception {
-
- List<SelectItem> selectItems = new ArrayList<SelectItem>(columns.length);
- for (Column column : columns) {
- selectItems.add(new SelectItem(column));
- }
- final XlsxRowPublisherAction publishAction = new XlsxRowPublisherAction(_configuration, columns,
- relationshipId, xssfReader);
-
- return new RowPublisherDataSet(selectItems.toArray(new SelectItem[selectItems.size()]), maxRows, publishAction);
- }
-
- private void buildColumns(final MutableTable table, final String relationshipId, final XSSFReader xssfReader)
- throws Exception {
- final InputStream sheetData = xssfReader.getSheet(relationshipId);
-
- final XlsxRowCallback rowCallback = new XlsxRowCallback() {
- @Override
- public boolean row(int rowNumber, List<String> values, List<Style> styles) {
- final int columnNameLineNumber = _configuration.getColumnNameLineNumber();
- if (columnNameLineNumber == ExcelConfiguration.NO_COLUMN_NAME_LINE) {
- AlphabeticSequence alphabeticSequence = new AlphabeticSequence();
- List<String> generatedColumnNames = new ArrayList<String>(values.size());
- for (String originalColumnName : values) {
- String columnName = alphabeticSequence.next();
- if (originalColumnName == null) {
- columnName = null;
- }
- generatedColumnNames.add(columnName);
- }
- buildColumns(table, generatedColumnNames);
- return false;
- } else {
- final int zeroBasedLineNumber = columnNameLineNumber - 1;
- if (rowNumber >= zeroBasedLineNumber) {
- buildColumns(table, values);
- return false;
- }
- }
- return true;
- }
- };
- final XlsxSheetToRowsHandler handler = new XlsxSheetToRowsHandler(rowCallback, xssfReader, _configuration);
-
- final XMLReader sheetParser = ExcelUtils.createXmlReader();
- sheetParser.setContentHandler(handler);
- try {
- sheetParser.parse(new InputSource(sheetData));
- } catch (XlsxStopParsingException e) {
- logger.debug("Parsing stop signal thrown");
- } finally {
- FileHelper.safeClose(sheetData);
- }
- }
-
- protected void buildColumns(final MutableTable table, final List<String> columnNames) {
- int columnNumber = 0;
- for (String columnName : columnNames) {
- if (columnName != null || !_configuration.isSkipEmptyColumns()) {
- if (columnName == null) {
- columnName = "[Column " + (columnNumber + 1) + "]";
- }
- table.addColumn(new MutableColumn(columnName, ColumnType.VARCHAR, table, columnNumber, true));
- }
- columnNumber++;
- }
- }
-
- private void buildTables(final XSSFReader xssfReader, final XlsxWorkbookToTablesHandler workbookToTables)
- throws Exception {
- final InputStream workbookData = xssfReader.getWorkbookData();
- final XMLReader workbookParser = ExcelUtils.createXmlReader();
- workbookParser.setContentHandler(workbookToTables);
- workbookParser.parse(new InputSource(workbookData));
- FileHelper.safeClose(workbookData);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/eobjects/metamodel/excel/XlsxStopParsingException.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/eobjects/metamodel/excel/XlsxStopParsingException.java b/excel/src/main/java/org/eobjects/metamodel/excel/XlsxStopParsingException.java
deleted file mode 100644
index ea2ba4c..0000000
--- a/excel/src/main/java/org/eobjects/metamodel/excel/XlsxStopParsingException.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * 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.excel;
-
-import org.xml.sax.SAXException;
-
-/**
- * Exception thrown when all elements of interest in a spreadsheet have been
- * parsed.
- *
- * @author Kasper Sørensen
- */
-final class XlsxStopParsingException extends SAXException {
-
- private static final long serialVersionUID = 1L;
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/eobjects/metamodel/excel/XlsxWorkbookToTablesHandler.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/eobjects/metamodel/excel/XlsxWorkbookToTablesHandler.java b/excel/src/main/java/org/eobjects/metamodel/excel/XlsxWorkbookToTablesHandler.java
deleted file mode 100644
index 3302ab7..0000000
--- a/excel/src/main/java/org/eobjects/metamodel/excel/XlsxWorkbookToTablesHandler.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * 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.excel;
-
-import java.util.Map;
-
-import org.eobjects.metamodel.schema.MutableSchema;
-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.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * XML handler for transforming a workbook document into {@link Table}s in a
- * MetaModel {@link Schema}.
- *
- * @author Kasper Sørensen
- */
-final class XlsxWorkbookToTablesHandler extends DefaultHandler {
-
- private final MutableSchema _schema;
- private final Map<String, String> _tableNamesToRelationshipIds;
-
- public XlsxWorkbookToTablesHandler(MutableSchema schema,
- Map<String, String> tableNamesToRelationshipIds) {
- _schema = schema;
- _tableNamesToRelationshipIds = tableNamesToRelationshipIds;
- }
-
- @Override
- public void startElement(String uri, String localName, String qName,
- Attributes attributes) throws SAXException {
- if ("sheet".equals(qName)) {
- String name = attributes.getValue("name");
- assert name != null;
- String relationId = attributes.getValue("r:id");
- assert relationId != null;
-
- if (_schema != null) {
- MutableTable table = new MutableTable(name, TableType.TABLE,
- _schema);
- _schema.addTable(table);
- }
- _tableNamesToRelationshipIds.put(name, relationId);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/eobjects/metamodel/excel/ZeroBasedRowIterator.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/eobjects/metamodel/excel/ZeroBasedRowIterator.java b/excel/src/main/java/org/eobjects/metamodel/excel/ZeroBasedRowIterator.java
deleted file mode 100644
index fc18dde..0000000
--- a/excel/src/main/java/org/eobjects/metamodel/excel/ZeroBasedRowIterator.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * 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.excel;
-
-import java.util.Iterator;
-
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-
-/**
- * An iterator implementation that iterates from the first logical (as opposed
- * to physical, which is the default in POI) row in a spreadsheet.
- *
- * @author Kasper Sørensen
- */
-final class ZeroBasedRowIterator implements Iterator<Row> {
-
- private final Sheet _sheet;
- private volatile int _rowNumber;
-
- public ZeroBasedRowIterator(Sheet sheet) {
- _sheet = sheet;
- _rowNumber = -1;
- }
-
- @Override
- public boolean hasNext() {
- return _rowNumber < _sheet.getLastRowNum();
- }
-
- @Override
- public Row next() {
- _rowNumber++;
- return _sheet.getRow(_rowNumber);
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException("remove() is not supported");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/eobjects/metamodel/excel/package-info.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/eobjects/metamodel/excel/package-info.java b/excel/src/main/java/org/eobjects/metamodel/excel/package-info.java
deleted file mode 100644
index 4300052..0000000
--- a/excel/src/main/java/org/eobjects/metamodel/excel/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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.
- */
-/**
- * Module package for MS Excel spreadsheet files
- */
-package org.eobjects.metamodel.excel;
-
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/test/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegateTest.java
----------------------------------------------------------------------
diff --git a/excel/src/test/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegateTest.java b/excel/src/test/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegateTest.java
new file mode 100644
index 0000000..cbf9723
--- /dev/null
+++ b/excel/src/test/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegateTest.java
@@ -0,0 +1,244 @@
+/**
+ * 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.excel;
+
+import java.io.File;
+import java.lang.reflect.Field;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.data.Style;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+public class DefaultSpreadsheetReaderDelegateTest extends TestCase {
+
+ public void testReadAllTestResourceFiles() {
+ File[] listFiles = new File("src/test/resources").listFiles();
+ for (File file : listFiles) {
+ if (file.isFile() && file.getName().indexOf(".xls") != -1) {
+ try {
+ runTest(file);
+ } catch (Throwable e) {
+ throw new IllegalStateException("Exception in file: "
+ + file, e);
+ }
+ }
+ }
+ }
+
+ private void runTest(File file) throws Exception {
+ ExcelDataContext mainDataContext = new ExcelDataContext(file);
+ applyReaderDelegate(mainDataContext);
+
+ ExcelDataContext comparedDataContext = null;
+ if (file.getName().endsWith(".xlsx")) {
+ comparedDataContext = new ExcelDataContext(file);
+ }
+
+ Schema schema = mainDataContext.getDefaultSchema();
+ assertNotNull(schema);
+ assertEquals(file.getName(), schema.getName());
+
+ if (comparedDataContext != null) {
+ assertEquals(comparedDataContext.getDefaultSchema().getName(),
+ schema.getName());
+ }
+
+ assertEquals(DefaultSpreadsheetReaderDelegate.class,
+ mainDataContext.getSpreadsheetReaderDelegateClass());
+
+ Table[] tables = schema.getTables();
+ assertTrue(tables.length > 0);
+
+ Table[] comparedTables = null;
+ if (comparedDataContext != null) {
+ assertEquals(XlsxSpreadsheetReaderDelegate.class,
+ comparedDataContext.getSpreadsheetReaderDelegateClass());
+ comparedTables = comparedDataContext.getDefaultSchema().getTables();
+ assertEquals(comparedTables.length, tables.length);
+ }
+
+ for (int i = 0; i < tables.length; i++) {
+ Table table = tables[i];
+ Column[] columns = table.getColumns();
+ Query query = mainDataContext.query().from(table).select(columns)
+ .toQuery();
+ DataSet dataSet = mainDataContext.executeQuery(query);
+
+ DataSet comparedDataSet = null;
+ if (comparedDataContext != null) {
+ Table comparedTable = comparedTables[i];
+ assertEquals(comparedTable.getName(), table.getName());
+ assertEquals(comparedTable.getColumnCount(),
+ table.getColumnCount());
+
+ Column[] comparedColumns = comparedTable.getColumns();
+ for (int j = 0; j < comparedColumns.length; j++) {
+ assertEquals(columns[j].getColumnNumber(),
+ comparedColumns[j].getColumnNumber());
+ }
+
+ Query comparedQuery = comparedDataContext.query()
+ .from(comparedTable).select(comparedColumns).toQuery();
+ comparedDataSet = comparedDataContext
+ .executeQuery(comparedQuery);
+ }
+
+ while (dataSet.next()) {
+ Row row = dataSet.getRow();
+ assertNotNull(row);
+ Object[] values = row.getValues();
+
+ assertEquals(values.length, table.getColumnCount());
+
+ if (comparedDataSet != null) {
+ boolean next = comparedDataSet.next();
+ assertTrue("No comparable row exists for: " + row, next);
+ Row comparedRow = comparedDataSet.getRow();
+ assertNotNull(comparedRow);
+ Object[] comparedValues = comparedRow.getValues();
+ assertEquals(comparedValues.length, table.getColumnCount());
+
+ for (int j = 0; j < comparedValues.length; j++) {
+ assertEquals(comparedValues[j], values[j]);
+ }
+
+ // compare styles
+ for (int j = 0; j < comparedValues.length; j++) {
+ Style style1 = comparedRow.getStyle(j);
+ Style style2 = row.getStyle(j);
+ assertEquals("Diff in style on row: " + row
+ + " (value index = " + j + ")\nStyle 1: "
+ + style1 + "\nStyle 2: " + style2 + ". ",
+ style1, style2);
+ }
+ }
+ }
+ dataSet.close();
+
+ if (comparedDataSet != null) {
+ assertFalse(comparedDataSet.next());
+ comparedDataSet.close();
+ }
+ }
+ }
+
+ /**
+ * Applies the {@link DefaultSpreadsheetReaderDelegate} through reflection.
+ *
+ * @param dataContext
+ * @throws NoSuchFieldException
+ * @throws IllegalAccessException
+ */
+ private void applyReaderDelegate(ExcelDataContext dataContext)
+ throws NoSuchFieldException, IllegalAccessException {
+ Field field = ExcelDataContext.class
+ .getDeclaredField("_spreadsheetReaderDelegate");
+ assertNotNull(field);
+ field.setAccessible(true);
+ field.set(
+ dataContext,
+ new DefaultSpreadsheetReaderDelegate(dataContext
+ .getConfiguration()));
+ }
+
+ public void testStylingOfDateCell() throws Exception {
+ ExcelDataContext dc = new ExcelDataContext(new File(
+ "src/test/resources/Spreadsheet2007.xlsx"));
+ applyReaderDelegate(dc);
+
+ Table table = dc.getDefaultSchema().getTables()[0];
+
+ final String expectedStyling = "";
+
+ DataSet dataSet = dc.query().from(table).select("date").execute();
+ assertTrue(dataSet.next());
+ assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
+ assertTrue(dataSet.next());
+ assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
+ assertTrue(dataSet.next());
+ assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
+ assertTrue(dataSet.next());
+ assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
+ assertFalse(dataSet.next());
+ dataSet.close();
+ }
+
+ public void testStylingOfNullCell() throws Exception {
+ ExcelDataContext dc = new ExcelDataContext(new File(
+ "src/test/resources/formulas.xlsx"));
+ applyReaderDelegate(dc);
+
+ Table table = dc.getDefaultSchema().getTables()[0];
+
+ DataSet dataSet = dc.query().from(table).select("Foo").and("Bar")
+ .where("Foo").isEquals("7").execute();
+ assertTrue(dataSet.next());
+ Row row = dataSet.getRow();
+ assertNotNull(row.getStyle(0));
+
+ final String expectedStyling = "";
+
+ assertEquals(expectedStyling, row.getStyle(0).toCSS());
+ assertNotNull(row.getStyle(1));
+ assertEquals(expectedStyling, row.getStyle(1).toCSS());
+ assertFalse(dataSet.next());
+ dataSet.close();
+
+ dataSet = dc.query().from(table).select("Foo").and("Bar").execute();
+ assertTrue(dataSet.next());
+ row = dataSet.getRow();
+ assertNotNull(row.getStyle(0));
+ assertEquals(expectedStyling, row.getStyle(0).toCSS());
+ assertNotNull(row.getStyle(1));
+ assertEquals(expectedStyling, row.getStyle(1).toCSS());
+
+ assertTrue(dataSet.next());
+ assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
+ assertTrue(dataSet.next());
+ assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
+ assertTrue(dataSet.next());
+ assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
+ assertTrue(dataSet.next());
+ assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
+ assertTrue(dataSet.next());
+ assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
+ assertTrue(dataSet.next());
+ assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
+ assertTrue(dataSet.next());
+ assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
+ assertTrue(dataSet.next());
+ assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
+ assertTrue(dataSet.next());
+ assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
+ assertTrue(dataSet.next());
+ assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
+ assertTrue(dataSet.next());
+ assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
+ assertTrue(dataSet.next());
+ assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
+ assertFalse(dataSet.next());
+ dataSet.close();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/test/java/org/apache/metamodel/excel/ExcelConfigurationTest.java
----------------------------------------------------------------------
diff --git a/excel/src/test/java/org/apache/metamodel/excel/ExcelConfigurationTest.java b/excel/src/test/java/org/apache/metamodel/excel/ExcelConfigurationTest.java
new file mode 100644
index 0000000..4a3b0f8
--- /dev/null
+++ b/excel/src/test/java/org/apache/metamodel/excel/ExcelConfigurationTest.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.excel;
+
+import org.eobjects.metamodel.excel.ExcelConfiguration;
+
+import junit.framework.TestCase;
+
+public class ExcelConfigurationTest extends TestCase {
+
+ public void testToString() throws Exception {
+ ExcelConfiguration conf = new ExcelConfiguration(1, true, false);
+ assertEquals(
+ "ExcelConfiguration[columnNameLineNumber=1, skipEmptyLines=true, skipEmptyColumns=false]",
+ conf.toString());
+ }
+
+ public void testEquals() throws Exception {
+ ExcelConfiguration conf1 = new ExcelConfiguration(1, true, false);
+ ExcelConfiguration conf2 = new ExcelConfiguration(1, true, false);
+ ExcelConfiguration conf3 = new ExcelConfiguration(2, true, false);
+
+ assertEquals(conf1, conf2);
+ assertFalse(conf1.equals(conf3));
+ }
+}
[40/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/FileHelper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/FileHelper.java b/core/src/main/java/org/apache/metamodel/util/FileHelper.java
new file mode 100644
index 0000000..229baeb
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/FileHelper.java
@@ -0,0 +1,460 @@
+/**
+ * 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.util;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.Flushable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PushbackInputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Various helper methods for handling files
+ */
+public final class FileHelper {
+
+ private final static Logger logger = LoggerFactory.getLogger(FileHelper.class);
+
+ public static final String UTF_8_ENCODING = "UTF-8";
+ public static final String UTF_16_ENCODING = "UTF-16";
+ public static final String US_ASCII_ENCODING = "US-ASCII";
+ public static final String ISO_8859_1_ENCODING = "ISO_8859_1";
+ public static final String DEFAULT_ENCODING = UTF_8_ENCODING;
+
+ private FileHelper() {
+ // prevent instantiation
+ }
+
+ public static File createTempFile(String prefix, String suffix) {
+ try {
+ return File.createTempFile(prefix, suffix);
+ } catch (IOException e) {
+ logger.error("Could not create tempFile", e);
+ File tempDir = getTempDir();
+ return new File(tempDir, prefix + '.' + suffix);
+ }
+ }
+
+ public static File getTempDir() {
+ File result = null;
+ String tmpDirPath = System.getProperty("java.io.tmpdir");
+ if (tmpDirPath != null && !"".equals(tmpDirPath)) {
+ result = new File(tmpDirPath);
+ } else {
+ logger.debug("Could not determine tmpdir by using environment variable.");
+ try {
+ File file = File.createTempFile("foo", "bar");
+ result = file.getParentFile();
+ if (!file.delete()) {
+ logger.warn("Could not delete temp file '{}'", file.getAbsolutePath());
+ }
+ } catch (IOException e) {
+ logger.error("Could not create tempFile in order to find temporary dir", e);
+ result = new File("metamodel.tmp.dir");
+ if (!result.mkdir()) {
+ throw new IllegalStateException("Could not create directory for temporary files: " + result.getName());
+ }
+ result.deleteOnExit();
+ }
+ }
+ if (logger.isInfoEnabled()) {
+ logger.info("Using '{}' as tmpdir.", result.getAbsolutePath());
+ }
+ return result;
+ }
+
+ public static Writer getWriter(File file, String encoding, boolean append) throws IllegalStateException {
+ boolean insertBom = !append;
+ return getWriter(file, encoding, append, insertBom);
+ }
+
+ public static Writer getWriter(OutputStream outputStream, String encoding) throws IllegalStateException {
+ return getWriter(outputStream, encoding, false);
+ }
+
+ public static Writer getWriter(OutputStream outputStream, String encoding, boolean insertBom) throws IllegalStateException {
+ if (!(outputStream instanceof BufferedOutputStream)) {
+ outputStream = new BufferedOutputStream(outputStream);
+ }
+
+ try {
+ if (insertBom) {
+ Writer writer = new UnicodeWriter(outputStream, encoding);
+ return writer;
+ } else {
+ Writer writer = new OutputStreamWriter(outputStream, encoding);
+ return writer;
+ }
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public static Writer getWriter(File file, String encoding, boolean append, boolean insertBom) throws IllegalStateException {
+ if (append && insertBom) {
+ throw new IllegalArgumentException("Can not insert BOM into appending writer");
+ }
+ final OutputStream outputStream = getOutputStream(file, append);
+ return getWriter(outputStream, encoding, insertBom);
+
+ }
+
+ public static Writer getWriter(File file, String encoding) throws IllegalStateException {
+ return getWriter(file, encoding, false);
+ }
+
+ public static Reader getReader(InputStream inputStream, String encoding) throws IllegalStateException {
+ try {
+ if (encoding == null || encoding.toLowerCase().indexOf("utf") != -1) {
+ byte bom[] = new byte[4];
+ int unread;
+
+ // auto-detect byte-order-mark
+ PushbackInputStream pushbackInputStream = new PushbackInputStream(inputStream, bom.length);
+ int n = pushbackInputStream.read(bom, 0, bom.length);
+
+ // Read ahead four bytes and check for BOM marks.
+ if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF)) {
+ encoding = "UTF-8";
+ unread = n - 3;
+ } else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) {
+ encoding = "UTF-16BE";
+ unread = n - 2;
+ } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) {
+ encoding = "UTF-16LE";
+ unread = n - 2;
+ } else if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00) && (bom[2] == (byte) 0xFE)
+ && (bom[3] == (byte) 0xFF)) {
+ encoding = "UTF-32BE";
+ unread = n - 4;
+ } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) && (bom[2] == (byte) 0x00)
+ && (bom[3] == (byte) 0x00)) {
+ encoding = "UTF-32LE";
+ unread = n - 4;
+ } else {
+ unread = n;
+ }
+
+ if (unread > 0) {
+ pushbackInputStream.unread(bom, (n - unread), unread);
+ } else if (unread < -1) {
+ pushbackInputStream.unread(bom, 0, 0);
+ }
+
+ inputStream = pushbackInputStream;
+ }
+
+ final InputStreamReader inputStreamReader;
+ if (encoding == null) {
+ inputStreamReader = new InputStreamReader(inputStream);
+ } else {
+ inputStreamReader = new InputStreamReader(inputStream, encoding);
+ }
+ return inputStreamReader;
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public static Reader getReader(File file, String encoding) throws IllegalStateException {
+ final InputStream inputStream;
+ try {
+ inputStream = new BufferedInputStream(new FileInputStream(file));
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ return getReader(inputStream, encoding);
+ }
+
+ public static String readInputStreamAsString(InputStream inputStream, String encoding) throws IllegalStateException {
+ Reader reader = getReader(inputStream, encoding);
+ return readAsString(reader);
+ }
+
+ public static String readFileAsString(File file, String encoding) throws IllegalStateException {
+ Reader br = getReader(file, encoding);
+ return readAsString(br);
+ }
+
+ public static String readAsString(Reader reader) throws IllegalStateException {
+ final BufferedReader br = getBufferedReader(reader);
+ try {
+ StringBuilder sb = new StringBuilder();
+ boolean firstLine = true;
+ for (String line = br.readLine(); line != null; line = br.readLine()) {
+ if (firstLine) {
+ firstLine = false;
+ } else {
+ sb.append('\n');
+ }
+ sb.append(line);
+ }
+ return sb.toString();
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ } finally {
+ safeClose(br, reader);
+ }
+ }
+
+ public static void safeClose(Object... objects) {
+ boolean debugEnabled = logger.isDebugEnabled();
+
+ if (objects == null || objects.length == 0) {
+ logger.info("safeClose(...) was invoked with null or empty array: {}", objects);
+ return;
+ }
+
+ for (Object obj : objects) {
+ if (obj != null) {
+ if (debugEnabled) {
+ logger.debug("Trying to safely close {}", obj);
+ }
+
+ if (obj instanceof Flushable) {
+ try {
+ ((Flushable) obj).flush();
+ } catch (Exception e) {
+ if (debugEnabled) {
+ logger.debug("Flushing Flushable failed", e);
+ }
+ }
+ }
+
+ if (obj instanceof Closeable) {
+ try {
+ ((Closeable) obj).close();
+ } catch (IOException e) {
+ if (debugEnabled) {
+ logger.debug("Closing Closeable failed", e);
+ }
+ }
+ } else if (obj instanceof Connection) {
+ try {
+ ((Connection) obj).close();
+ } catch (Exception e) {
+ if (debugEnabled) {
+ logger.debug("Closing Connection failed", e);
+ }
+ }
+ } else if (obj instanceof Statement) {
+ try {
+ ((Statement) obj).close();
+ } catch (Exception e) {
+ if (debugEnabled) {
+ logger.debug("Closing Statement failed", e);
+ }
+ }
+ } else if (obj instanceof ResultSet) {
+ try {
+ ((ResultSet) obj).close();
+ } catch (Exception e) {
+ if (debugEnabled) {
+ logger.debug("Closing ResultSet failed", e);
+ }
+ }
+ } else {
+ logger.info("obj was neither Closeable, Connection, Statement or ResultSet.");
+
+ try {
+ Method method = obj.getClass().getMethod("close", new Class[0]);
+ if (method == null) {
+ logger.info("obj did not have a close() method, ignoring");
+ } else {
+ method.setAccessible(true);
+ method.invoke(obj);
+ }
+ } catch (InvocationTargetException e) {
+ logger.warn("Invoking close() by reflection threw exception", e);
+ } catch (Exception e) {
+ logger.warn("Could not invoke close() by reflection", e);
+ }
+ }
+ }
+
+ }
+ }
+
+ public static BufferedWriter getBufferedWriter(File file, String encoding) throws IllegalStateException {
+ Writer writer = getWriter(file, encoding);
+ return new BufferedWriter(writer);
+ }
+
+ public static BufferedReader getBufferedReader(File file, String encoding) throws IllegalStateException {
+ Reader reader = getReader(file, encoding);
+ return new BufferedReader(reader);
+ }
+
+ public static BufferedReader getBufferedReader(InputStream inputStream, String encoding) throws IllegalStateException {
+ Reader reader = getReader(inputStream, encoding);
+ return new BufferedReader(reader);
+ }
+
+ public static Reader getReader(File file) throws IllegalStateException {
+ return getReader(file, DEFAULT_ENCODING);
+ }
+
+ public static String readFileAsString(File file) throws IllegalStateException {
+ return readFileAsString(file, DEFAULT_ENCODING);
+ }
+
+ public static BufferedWriter getBufferedWriter(File file) throws IllegalStateException {
+ return getBufferedWriter(file, DEFAULT_ENCODING);
+ }
+
+ public static Writer getWriter(File file) throws IllegalStateException {
+ return getWriter(file, DEFAULT_ENCODING);
+ }
+
+ public static void writeString(OutputStream outputStream, String string) throws IllegalStateException {
+ writeString(outputStream, string, DEFAULT_ENCODING);
+ }
+
+ public static void writeString(OutputStream outputStream, String string, String encoding) throws IllegalStateException {
+ final Writer writer = getWriter(outputStream, encoding);
+ writeString(writer, string, encoding);
+ }
+
+ public static void writeString(Writer writer, String string) throws IllegalStateException {
+ writeString(writer, string, DEFAULT_ENCODING);
+ }
+
+ public static void writeString(Writer writer, String string, String encoding) throws IllegalStateException {
+ try {
+ writer.write(string);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ } finally {
+ safeClose(writer);
+ }
+ }
+
+ public static void writeStringAsFile(File file, String string) throws IllegalStateException {
+ writeStringAsFile(file, string, DEFAULT_ENCODING);
+ }
+
+ public static void writeStringAsFile(File file, String string, String encoding) throws IllegalStateException {
+ final BufferedWriter bw = getBufferedWriter(file, encoding);
+ writeString(bw, string, encoding);
+ }
+
+ public static BufferedReader getBufferedReader(File file) throws IllegalStateException {
+ return getBufferedReader(file, DEFAULT_ENCODING);
+ }
+
+ public static void copy(Reader reader, Writer writer) throws IllegalStateException {
+ final BufferedReader bufferedReader = getBufferedReader(reader);
+ try {
+ boolean firstLine = true;
+ for (String line = bufferedReader.readLine(); line != null; line = bufferedReader.readLine()) {
+ if (firstLine) {
+ firstLine = false;
+ } else {
+ writer.write('\n');
+ }
+ writer.write(line);
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public static BufferedReader getBufferedReader(Reader reader) {
+ if (reader instanceof BufferedReader) {
+ return (BufferedReader) reader;
+ }
+ return new BufferedReader(reader);
+ }
+
+ public static void copy(InputStream fromStream, OutputStream toStream) throws IllegalStateException {
+ try {
+ byte[] buffer = new byte[1024 * 32];
+ for (int read = fromStream.read(buffer); read != -1; read = fromStream.read(buffer)) {
+ toStream.write(buffer, 0, read);
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public static void copy(File from, File to) throws IllegalStateException {
+ assert from.exists();
+
+ final InputStream fromStream = getInputStream(from);
+ final OutputStream toStream = getOutputStream(to);
+
+ try {
+ copy(fromStream, toStream);
+ } finally {
+ safeClose(fromStream, toStream);
+ }
+ }
+
+ public static OutputStream getOutputStream(File file) throws IllegalStateException {
+ return getOutputStream(file, false);
+ }
+
+ public static OutputStream getOutputStream(File file, boolean append) {
+ try {
+ return new BufferedOutputStream(new FileOutputStream(file, append));
+ } catch (FileNotFoundException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public static InputStream getInputStream(File file) throws IllegalStateException {
+ try {
+ return new BufferedInputStream(new FileInputStream(file));
+ } catch (FileNotFoundException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public static byte[] readAsBytes(InputStream inputStream) {
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try {
+ copy(inputStream, baos);
+ } finally {
+ safeClose(inputStream);
+ }
+ return baos.toByteArray();
+ }
+}
\ 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/util/FileResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/FileResource.java b/core/src/main/java/org/apache/metamodel/util/FileResource.java
new file mode 100644
index 0000000..bf17c8f
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/FileResource.java
@@ -0,0 +1,138 @@
+/**
+ * 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.util;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+
+/**
+ * {@link File} based {@link Resource} implementation.
+ */
+public class FileResource implements Resource, Serializable {
+
+ private static final long serialVersionUID = 1L;
+ private final File _file;
+
+ public FileResource(String filename) {
+ _file = new File(filename);
+ }
+
+ public FileResource(File file) {
+ _file = file;
+ }
+
+ @Override
+ public String toString() {
+ return "FileResource[" + _file.getPath() + "]";
+ }
+
+ @Override
+ public String getName() {
+ return _file.getName();
+ }
+
+ @Override
+ public boolean isReadOnly() {
+ if (!isExists()) {
+ return false;
+ }
+ boolean canWrite = _file.canWrite();
+ return !canWrite;
+ }
+
+ @Override
+ public void write(Action<OutputStream> writeCallback) throws ResourceException {
+ final OutputStream out = FileHelper.getOutputStream(_file);
+ try {
+ writeCallback.run(out);
+ } catch (Exception e) {
+ throw new ResourceException(this, "Error occurred in write callback", e);
+ } finally {
+ FileHelper.safeClose(out);
+ }
+ }
+
+ @Override
+ public void append(Action<OutputStream> appendCallback) {
+ final OutputStream out = FileHelper.getOutputStream(_file, true);
+ try {
+ appendCallback.run(out);
+ } catch (Exception e) {
+ throw new ResourceException(this, "Error occurred in append callback", e);
+ } finally {
+ FileHelper.safeClose(out);
+ }
+ }
+
+ @Override
+ public void read(Action<InputStream> readCallback) {
+ final InputStream in = read();
+ try {
+ readCallback.run(in);
+ } catch (Exception e) {
+ throw new ResourceException(this, "Error occurred in read callback", e);
+ } finally {
+ FileHelper.safeClose(in);
+ }
+ }
+
+ @Override
+ public <E> E read(Func<InputStream, E> readCallback) {
+ final InputStream in = read();
+ try {
+ final E result = readCallback.eval(in);
+ return result;
+ } catch (Exception e) {
+ throw new ResourceException(this, "Error occurred in read callback", e);
+ } finally {
+ FileHelper.safeClose(in);
+ }
+ }
+
+ public File getFile() {
+ return _file;
+ }
+
+ @Override
+ public boolean isExists() {
+ return _file.exists();
+ }
+
+ @Override
+ public long getSize() {
+ return _file.length();
+ }
+
+ @Override
+ public long getLastModified() {
+ final long lastModified = _file.lastModified();
+ if (lastModified == 0) {
+ return -1;
+ }
+ return lastModified;
+ }
+
+ @Override
+ public InputStream read() throws ResourceException {
+ final InputStream in = FileHelper.getInputStream(_file);
+ return in;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/FormatHelper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/FormatHelper.java b/core/src/main/java/org/apache/metamodel/util/FormatHelper.java
new file mode 100644
index 0000000..3b954dc
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/FormatHelper.java
@@ -0,0 +1,273 @@
+/**
+ * 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.util;
+
+import java.text.DateFormat;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.util.Date;
+
+import org.eobjects.metamodel.query.QueryParameter;
+import org.eobjects.metamodel.schema.ColumnType;
+
+/**
+ * Helper class for formatting
+ */
+public final class FormatHelper {
+
+ /**
+ * Creates a uniform number format which is similar to that of eg. Java
+ * doubles. The format will not include thousand separators and it will use
+ * a dot as a decimal separator.
+ *
+ * @return
+ */
+ public static NumberFormat getUiNumberFormat() {
+ DecimalFormatSymbols symbols = new DecimalFormatSymbols();
+ symbols.setDecimalSeparator('.');
+ DecimalFormat format = new DecimalFormat("###.##", symbols);
+ format.setGroupingUsed(false);
+ return format;
+ }
+
+ public static NumberFormat getSqlNumberFormat() {
+ DecimalFormatSymbols symbols = new DecimalFormatSymbols();
+ symbols.setDecimalSeparator('.');
+ DecimalFormat format = new DecimalFormat("###.##", symbols);
+ format.setGroupingUsed(false);
+ format.setMaximumFractionDigits(100);
+ return format;
+ }
+
+ public static String formatSqlBoolean(ColumnType columnType, boolean b) {
+ if (columnType == ColumnType.BIT) {
+ if (b) {
+ return "1";
+ } else {
+ return "0";
+ }
+ } else {
+ if (b) {
+ return "TRUE";
+ } else {
+ return "FALSE";
+ }
+ }
+ }
+
+ /**
+ * Formats a date according to a specific column type (DATE, TIME or
+ * TIMESTAMP)
+ *
+ * @param columnType
+ * the column type
+ * @param date
+ * the date value
+ * @return
+ */
+ public static String formatSqlTime(ColumnType columnType, Date date) {
+ return formatSqlTime(columnType, date, true);
+ }
+
+ /**
+ * Formats a date according to a specific column type (DATE, TIME or
+ * TIMESTAMP)
+ *
+ * @param columnType
+ * the column type
+ * @param date
+ * the date value
+ * @param typeCastDeclaration
+ * whether or not to include a type cast declaration
+ * @param beforeDateLiteral
+ * before date literal
+ * @param afterDateLiteral
+ * after date literal
+ * @return
+ */
+ public static String formatSqlTime(ColumnType columnType, Date date,
+ boolean typeCastDeclaration, String beforeDateLiteral,
+ String afterDateLiteral) {
+ if (columnType == null) {
+ throw new IllegalArgumentException("Column type cannot be null");
+ }
+ final DateFormat format;
+ final String typePrefix;
+ switch (columnType) {
+ case DATE:
+ format = DateUtils.createDateFormat("yyyy-MM-dd");
+ typePrefix = "DATE";
+ break;
+ case TIME:
+ format = DateUtils.createDateFormat("HH:mm:ss");
+ typePrefix = "TIME";
+ break;
+ case TIMESTAMP:
+ format = DateUtils.createDateFormat("yyyy-MM-dd HH:mm:ss");
+ typePrefix = "TIMESTAMP";
+ break;
+ default:
+ throw new IllegalArgumentException(
+ "Cannot format time value of type: " + columnType);
+ }
+
+ if (typeCastDeclaration) {
+ return typePrefix + " " + beforeDateLiteral + format.format(date) + afterDateLiteral;
+ } else {
+ return format.format(date);
+ }
+ }
+
+ /**
+ * Formats a date according to a specific column type (DATE, TIME or TIMESTAMP). For backward compatibility.
+ * @param columnType
+ * @param date
+ * @param typeCastDeclaration
+ * @return
+ */
+ public static String formatSqlTime(ColumnType columnType, Date date, boolean typeCastDeclaration) {
+ return formatSqlTime(columnType, date, typeCastDeclaration, "\'", "\'");
+ }
+
+ /**
+ * Parses a SQL string representation of a time based value
+ *
+ * @param type
+ * @param value
+ * @return
+ */
+ public static Date parseSqlTime(ColumnType columnType, String value) {
+ final String[] formats;
+ switch (columnType) {
+ case DATE:
+ formats = new String[] { "yyyy-MM-dd", };
+ break;
+ case TIME:
+ formats = new String[] { "HH:mm:ss", "HH:mm" };
+ break;
+ case TIMESTAMP:
+ formats = new String[] { "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm",
+ "yyyy-MM-dd" };
+ break;
+ default:
+ throw new IllegalArgumentException(
+ "Cannot parse time value of type: " + columnType);
+ }
+
+ for (String format : formats) {
+ try {
+ DateFormat dateFormat = DateUtils.createDateFormat(format);
+ return dateFormat.parse(value);
+ } catch (ParseException e) {
+ // proceed to next format
+ }
+ }
+
+ throw new IllegalArgumentException("String value '" + value
+ + "' not parseable as a " + columnType);
+ }
+
+ public static String formatSqlValue(ColumnType columnType, Object value) {
+ if (value == null) {
+ return "NULL";
+ }
+ if (value instanceof QueryParameter) {
+ return value.toString();
+ }
+ if (value.getClass().isArray()) {
+ value = CollectionUtils.toList(value);
+ }
+ if (value instanceof Iterable) {
+ StringBuilder sb = new StringBuilder();
+ sb.append('(');
+ for (Object item : (Iterable<?>) value) {
+ if (sb.length() > 1) {
+ sb.append(" , ");
+ }
+ sb.append(formatSqlValue(columnType, item));
+ }
+ sb.append(')');
+ return sb.toString();
+ } else if (isNumber(columnType, value)) {
+ NumberFormat numberFormat = getSqlNumberFormat();
+ Number n = NumberComparator.toNumber(value);
+ if (n == null) {
+ throw new IllegalStateException("Could not convert " + value
+ + " to number");
+ }
+ String numberString = numberFormat.format(n);
+ return numberString;
+ } else if (isBoolean(columnType, value)) {
+ Boolean b = BooleanComparator.toBoolean(value);
+ if (b == null) {
+ throw new IllegalStateException("Could not convert " + value
+ + " to boolean");
+ }
+ String booleanString = formatSqlBoolean(columnType, b);
+ return booleanString;
+ } else if (isTimeBased(columnType, value)) {
+ Date date = TimeComparator.toDate(value);
+ if (date == null) {
+ throw new IllegalStateException("Could not convert " + value
+ + " to date");
+ }
+ String timeString = formatSqlTime(columnType, date);
+ return timeString;
+ } else if (isLiteral(columnType, value)) {
+ return '\'' + value.toString() + '\'';
+ } else {
+ if (columnType == null) {
+ throw new IllegalStateException("Value type not supported: "
+ + value);
+ }
+ throw new IllegalStateException("Column type not supported: "
+ + columnType);
+ }
+ }
+
+ private static boolean isTimeBased(ColumnType columnType, Object operand) {
+ if (columnType == null) {
+ return TimeComparator.isTimeBased(operand);
+ }
+ return columnType.isTimeBased();
+ }
+
+ private static boolean isBoolean(ColumnType columnType, Object operand) {
+ if (columnType == null) {
+ return operand instanceof Boolean;
+ }
+ return columnType.isBoolean();
+ }
+
+ private static boolean isNumber(ColumnType columnType, Object operand) {
+ if (columnType == null) {
+ return operand instanceof Number;
+ }
+ return columnType.isNumber();
+ }
+
+ private static boolean isLiteral(ColumnType columnType, Object operand) {
+ if (columnType == null) {
+ return operand instanceof String;
+ }
+ return columnType.isLiteral();
+ }
+}
\ 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/util/Func.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/Func.java b/core/src/main/java/org/apache/metamodel/util/Func.java
new file mode 100644
index 0000000..c576456
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/Func.java
@@ -0,0 +1,43 @@
+/**
+ * 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.util;
+
+/**
+ * Represents an abstract function, which is an executable piece of
+ * functionality that has an input and an output. A {@link Func} has a return
+ * type, unlike an {@link Action}.
+ *
+ * @author Kasper Sørensen
+ *
+ * @param <I>
+ * the input type
+ * @param <O>
+ * the output type
+ */
+public interface Func<I, O> {
+
+ /**
+ * Evaluates an element and transforms it using this function.
+ *
+ * @param arg
+ * the input given to the function
+ * @return the output result of the function
+ */
+ public O eval(I arg);
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/HasName.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/HasName.java b/core/src/main/java/org/apache/metamodel/util/HasName.java
new file mode 100644
index 0000000..647848f
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/HasName.java
@@ -0,0 +1,29 @@
+/**
+ * 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.util;
+
+/**
+ * Represents anything with a (String based) name.
+ *
+ * @author Kasper Sørensen
+ */
+public interface HasName {
+
+ public String getName();
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/HasNameMapper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/HasNameMapper.java b/core/src/main/java/org/apache/metamodel/util/HasNameMapper.java
new file mode 100644
index 0000000..3b22a32
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/HasNameMapper.java
@@ -0,0 +1,39 @@
+/**
+ * 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.util;
+
+import java.io.Serializable;
+
+/**
+ * {@link Func} useful for mapping {@link HasName} instances to names, using
+ * {@link CollectionUtils#map(Object[], Func)} and
+ * {@link CollectionUtils#map(Iterable, Func)}.
+ *
+ * @author Kasper Sørensen
+ */
+public final class HasNameMapper implements Func<HasName, String>, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public String eval(HasName arg) {
+ return arg.getName();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/ImmutableDate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/ImmutableDate.java b/core/src/main/java/org/apache/metamodel/util/ImmutableDate.java
new file mode 100644
index 0000000..4ed34a6
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/ImmutableDate.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.util;
+
+import java.text.DateFormat;
+import java.util.Date;
+
+/**
+ * A Date implementation that is immutable and has a predictable
+ * (locale-indifferent) toString() method.
+ *
+ * @author Kasper Sørensen
+ *
+ * @deprecated MetaModel is not a Date API, use Joda time or live with
+ * java.util.Date.
+ */
+@Deprecated
+public final class ImmutableDate extends Date {
+
+ private static final long serialVersionUID = 1L;
+
+ public ImmutableDate(long time) {
+ super(time);
+ }
+
+ public ImmutableDate(Date date) {
+ super(date.getTime());
+ }
+
+ /**
+ * This mutator will throw an {@link UnsupportedOperationException}, since
+ * the date is ummutable.
+ *
+ * @param time
+ * new time to set
+ */
+ @Override
+ public void setTime(long time) {
+ throw new UnsupportedOperationException("setTime(...) is not allowed");
+ }
+
+ @Override
+ public String toString() {
+ DateFormat format = DateUtils.createDateFormat();
+ return format.format(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/ImmutableRef.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/ImmutableRef.java b/core/src/main/java/org/apache/metamodel/util/ImmutableRef.java
new file mode 100644
index 0000000..e8653cf
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/ImmutableRef.java
@@ -0,0 +1,45 @@
+/**
+ * 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.util;
+
+/**
+ * Simple/hard implementation of the {@link Ref} interface.
+ *
+ * @author Kasper Sørensen
+ *
+ * @param <E>
+ */
+public final class ImmutableRef<E> implements Ref<E> {
+
+ private final E _object;
+
+ public ImmutableRef(E object) {
+ _object = object;
+ }
+
+ @Override
+ public E get() {
+ return _object;
+ }
+
+ public static <E> Ref<E> of(E object) {
+ return new ImmutableRef<E>(object);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/InMemoryResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/InMemoryResource.java b/core/src/main/java/org/apache/metamodel/util/InMemoryResource.java
new file mode 100644
index 0000000..3a8d138
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/InMemoryResource.java
@@ -0,0 +1,160 @@
+/**
+ * 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.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+
+/**
+ * An entirely in-memory kept {@link Resource}.
+ */
+public class InMemoryResource implements Resource, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private final String _path;
+ private byte[] _contents;
+ private long _lastModified;
+
+ /**
+ * Constructs a new {@link InMemoryResource} with a path/name
+ *
+ * @param path
+ */
+ public InMemoryResource(String path) {
+ this(path, new byte[0], -1);
+ }
+
+ /**
+ * Constructs a new {@link InMemoryResource} with a path/name and some
+ * initial contents.
+ *
+ * @param path
+ * @param contents
+ * @param lastModified
+ */
+ public InMemoryResource(String path, byte[] contents, long lastModified) {
+ _path = path;
+ _contents = contents;
+ _lastModified = lastModified;
+ }
+
+ @Override
+ public String toString() {
+ return "InMemoryResource[" + _path + "]";
+ }
+
+ @Override
+ public String getName() {
+ String name = _path;
+ final int lastSlash = name.lastIndexOf('/');
+ final int lastBackSlash = name.lastIndexOf('\\');
+ final int lastIndex = Math.max(lastSlash, lastBackSlash);
+ if (lastIndex != -1) {
+ final String lastPart = name.substring(lastIndex + 1);
+ if (!"".equals(lastPart)) {
+ return lastPart;
+ }
+ }
+ return name;
+ }
+
+ /**
+ * Gets the path of this resource
+ *
+ * @return
+ */
+ public String getPath() {
+ return _path;
+ }
+
+ @Override
+ public boolean isReadOnly() {
+ return false;
+ }
+
+ @Override
+ public boolean isExists() {
+ return true;
+ }
+
+ @Override
+ public long getSize() {
+ return _contents.length;
+ }
+
+ @Override
+ public long getLastModified() {
+ return _lastModified;
+ }
+
+ @Override
+ public void write(Action<OutputStream> writeCallback) throws ResourceException {
+ try {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ writeCallback.run(baos);
+ _contents = baos.toByteArray();
+ _lastModified = System.currentTimeMillis();
+ } catch (Exception e) {
+ throw new ResourceException(this, e);
+ }
+ }
+
+ @Override
+ public void append(Action<OutputStream> appendCallback) throws ResourceException {
+ try {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ baos.write(_contents);
+ appendCallback.run(baos);
+ _contents = baos.toByteArray();
+ _lastModified = System.currentTimeMillis();
+ } catch (Exception e) {
+ throw new ResourceException(this, e);
+ }
+ }
+
+ @Override
+ public InputStream read() throws ResourceException {
+ return new ByteArrayInputStream(_contents);
+ }
+
+ @Override
+ public void read(Action<InputStream> readCallback) throws ResourceException {
+ final InputStream inputStream = read();
+ try {
+ readCallback.run(inputStream);
+ } catch (Exception e) {
+ throw new ResourceException(this, e);
+ }
+ }
+
+ @Override
+ public <E> E read(Func<InputStream, E> readCallback) throws ResourceException {
+ final InputStream inputStream = read();
+ try {
+ return readCallback.eval(inputStream);
+ } catch (Exception e) {
+ throw new ResourceException(this, e);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/InclusionPredicate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/InclusionPredicate.java b/core/src/main/java/org/apache/metamodel/util/InclusionPredicate.java
new file mode 100644
index 0000000..03bc689
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/InclusionPredicate.java
@@ -0,0 +1,50 @@
+/**
+ * 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.util;
+
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * A predicate that uses an inclusion list ("white list") of elements to
+ * determine whether to evaluate true or false.
+ *
+ * @param <E>
+ */
+public class InclusionPredicate<E> implements Predicate<E> {
+
+ private final Collection<E> _inclusionList;
+
+ public InclusionPredicate(Collection<E> inclusionList) {
+ _inclusionList = inclusionList;
+ }
+
+ @Override
+ public Boolean eval(E arg) {
+ if (_inclusionList.contains(arg)) {
+ return true;
+ }
+ return false;
+ }
+
+ public Collection<E> getInclusionList() {
+ return Collections.unmodifiableCollection(_inclusionList);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/LazyRef.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/LazyRef.java b/core/src/main/java/org/apache/metamodel/util/LazyRef.java
new file mode 100644
index 0000000..ab39c66
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/LazyRef.java
@@ -0,0 +1,127 @@
+/**
+ * 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.util;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Represents a lazy loaded reference.
+ *
+ * @author Kasper Sørensen
+ *
+ * @param <E>
+ */
+public abstract class LazyRef<E> implements Ref<E> {
+
+ private static final Logger logger = LoggerFactory.getLogger(LazyRef.class);
+
+ private final AtomicBoolean _fetched = new AtomicBoolean(false);
+ private volatile Throwable _error;
+ private E _object;
+
+ @Override
+ public final E get() {
+ if (!_fetched.get()) {
+ synchronized (_fetched) {
+ if (!_fetched.get()) {
+ try {
+ _object = fetch();
+ } catch (Throwable t) {
+ _error = t;
+ if (t instanceof RuntimeException) {
+ throw (RuntimeException) t;
+ }
+ logger.warn("Failed to fetch value: " + this + ". Reporting error.", t);
+ } finally {
+ _fetched.set(true);
+ }
+ }
+ }
+ }
+ return _object;
+ }
+
+ protected abstract E fetch() throws Throwable;
+
+ /**
+ * Gets whether the lazy loaded reference has been loaded or not.
+ *
+ * @return a boolean indicating whether or not the reference has been loaded
+ * or not
+ */
+ public boolean isFetched() {
+ return _fetched.get();
+ }
+
+ /**
+ * Gets any error that occurred while fetching the lazy loaded value.
+ *
+ * @return
+ */
+ public Throwable getError() {
+ return _error;
+ }
+
+ /**
+ * Requests an asynchronous load of the lazy reference. If not already
+ * loaded, this will cause another thread to load the reference, typically
+ * to make it immediately available for later evaluation.
+ *
+ * @param errorAction
+ * an optional error action to invoke if an exception is thrown
+ * during loading of the reference.
+ */
+ public void requestLoad(final Action<Throwable> errorAction) {
+ if (!isFetched()) {
+ ExecutorService executorService = SharedExecutorService.get();
+ executorService.submit(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ get();
+ } catch (RuntimeException e) {
+ // do nothing, the exception will be handled via _error
+ // below
+ }
+ if (_error != null && errorAction != null) {
+ try {
+ errorAction.run(_error);
+ } catch (Exception e) {
+ logger.error("Error handling action failed!", e);
+ }
+ }
+ }
+ });
+ }
+ }
+
+ /**
+ * Requests an asynchronous load of the lazy reference. If not already
+ * loaded, this will cause another thread to load the reference, typically
+ * to make it immediately available for later evaluation.
+ */
+ public void requestLoad() {
+ requestLoad(null);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/Month.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/Month.java b/core/src/main/java/org/apache/metamodel/util/Month.java
new file mode 100644
index 0000000..3380e5f
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/Month.java
@@ -0,0 +1,94 @@
+/**
+ * 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.util;
+
+import java.util.Calendar;
+
+/**
+ * Provides a handy and type-safe enum around the months otherwise defined as
+ * int constants in java.util.Calendar.
+ *
+ * @author Kasper Sørensen
+ *
+ */
+public enum Month implements HasName {
+
+ JANUARY(Calendar.JANUARY),
+
+ FEBRUARY(Calendar.FEBRUARY),
+
+ MARCH(Calendar.MARCH),
+
+ APRIL(Calendar.APRIL),
+
+ MAY(Calendar.MAY),
+
+ JUNE(Calendar.JUNE),
+
+ JULY(Calendar.JULY),
+
+ AUGUST(Calendar.AUGUST),
+
+ SEPTEMBER(Calendar.SEPTEMBER),
+
+ OCTOBER(Calendar.OCTOBER),
+
+ NOVEMBER(Calendar.NOVEMBER),
+
+ DECEMBER(Calendar.DECEMBER);
+
+ private int calendarConstant;
+
+ private Month(int calendarConstant) {
+ this.calendarConstant = calendarConstant;
+ }
+
+ public int getCalendarConstant() {
+ return calendarConstant;
+ }
+
+ public static Month getByCalendarConstant(int calendarConstant) {
+ for (Month month : values()) {
+ if (month.getCalendarConstant() == calendarConstant) {
+ return month;
+ }
+ }
+ return null;
+ }
+
+ public Month next() {
+ if (this == DECEMBER) {
+ return JANUARY;
+ }
+ return values()[ordinal() + 1];
+ }
+
+ public Month previous() {
+ if (this == JANUARY) {
+ return DECEMBER;
+ }
+ return values()[ordinal() - 1];
+ }
+
+ @Override
+ public String getName() {
+ final String capitalized = toString();
+ return capitalized.charAt(0) + capitalized.substring(1).toLowerCase();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/MutableRef.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/MutableRef.java b/core/src/main/java/org/apache/metamodel/util/MutableRef.java
new file mode 100644
index 0000000..81f8ea6
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/MutableRef.java
@@ -0,0 +1,48 @@
+/**
+ * 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.util;
+
+/**
+ * Represents a mutable reference to any object
+ *
+ * @author Kasper Sørensen
+ *
+ * @param <E>
+ */
+public final class MutableRef<E> implements Ref<E> {
+
+ private E _object;
+
+ public MutableRef() {
+ }
+
+ public MutableRef(E object) {
+ _object = object;
+ }
+
+ @Override
+ public E get() {
+ return _object;
+ }
+
+ public void set(E object) {
+ _object = object;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/NumberComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/NumberComparator.java b/core/src/main/java/org/apache/metamodel/util/NumberComparator.java
new file mode 100644
index 0000000..5a1ba02
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/NumberComparator.java
@@ -0,0 +1,107 @@
+/**
+ * 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.util;
+
+import java.util.Comparator;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Comparator that can compare numbers of various kinds (short, integer, float,
+ * double etc)
+ */
+public final class NumberComparator implements Comparator<Object> {
+
+ private static final Logger logger = LoggerFactory
+ .getLogger(NumberComparator.class);
+
+ private static final Comparator<Object> _instance = new NumberComparator();
+
+ public static Comparator<Object> getComparator() {
+ return _instance;
+ }
+
+ private NumberComparator() {
+ }
+
+ public static Comparable<Object> getComparable(Object o) {
+ final Number n = toNumber(o);
+ return new Comparable<Object>() {
+
+ @Override
+ public boolean equals(Object obj) {
+ return _instance.equals(obj);
+ }
+
+ public int compareTo(Object o) {
+ return _instance.compare(n, o);
+ }
+
+ @Override
+ public String toString() {
+ return "NumberComparable[number=" + n + "]";
+ }
+
+ };
+ }
+
+ public int compare(Object o1, Object o2) {
+ if (o1 == null && o2 == null) {
+ return 0;
+ }
+ if (o1 == null) {
+ return -1;
+ }
+ if (o2 == null) {
+ return 1;
+ }
+ Number n1 = toNumber(o1);
+ Number n2 = toNumber(o2);
+ return Double.valueOf(n1.doubleValue()).compareTo(n2.doubleValue());
+ }
+
+ public static Number toNumber(Object value) {
+ if (value == null) {
+ return null;
+ } else if (value instanceof Number) {
+ return (Number) value;
+ } else if (value instanceof Boolean) {
+ if (Boolean.TRUE.equals(value)) {
+ return 1;
+ } else {
+ return 0;
+ }
+ } else {
+ String stringValue = value.toString();
+ try {
+ return Integer.parseInt(stringValue);
+ } catch (NumberFormatException e1) {
+ try {
+ return Double.parseDouble(stringValue);
+ } catch (NumberFormatException e2) {
+ logger.warn(
+ "Could not convert '{}' to number, returning null",
+ value);
+ return null;
+ }
+ }
+ }
+ }
+}
\ 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/util/ObjectComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/ObjectComparator.java b/core/src/main/java/org/apache/metamodel/util/ObjectComparator.java
new file mode 100644
index 0000000..9b15452
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/ObjectComparator.java
@@ -0,0 +1,102 @@
+/**
+ * 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.util;
+
+import java.util.Comparator;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * General purpose comparator to use for objects of various kinds. Prevents
+ * NullPointerExceptions and tries to use comparable interface if available and
+ * appropriate on incoming objects.
+ */
+public final class ObjectComparator implements Comparator<Object> {
+
+ private static final Logger logger = LoggerFactory
+ .getLogger(ObjectComparator.class);
+
+ private static final Comparator<Object> _instance = new ObjectComparator();
+
+ public static Comparator<Object> getComparator() {
+ return _instance;
+ }
+
+ private ObjectComparator() {
+ }
+
+ public static Comparable<Object> getComparable(final Object o) {
+ return new Comparable<Object>() {
+
+ @Override
+ public boolean equals(Object obj) {
+ return _instance.equals(obj);
+ }
+
+ public int compareTo(Object o2) {
+ return _instance.compare(o, o2);
+ }
+
+ @Override
+ public String toString() {
+ return "ObjectComparable[object=" + o + "]";
+ }
+ };
+ }
+
+ @SuppressWarnings("unchecked")
+ public int compare(final Object o1, final Object o2) {
+ logger.debug("compare({},{})", o1, o2);
+ if (o1 == null && o2 == null) {
+ return 0;
+ }
+ if (o1 == null) {
+ return -1;
+ }
+ if (o2 == null) {
+ return 1;
+ }
+ if (o1 instanceof Number && o1 instanceof Number) {
+ return NumberComparator.getComparator().compare(o1, o2);
+ }
+ if (TimeComparator.isTimeBased(o1) && TimeComparator.isTimeBased(o2)) {
+ return TimeComparator.getComparator().compare(o1, o2);
+ }
+ if (BooleanComparator.isBoolean(o1) && BooleanComparator.isBoolean(o2)) {
+ return BooleanComparator.getComparator().compare(o1, o2);
+ }
+ if (o1 instanceof Comparable && o2 instanceof Comparable) {
+ @SuppressWarnings("rawtypes")
+ Comparable c1 = (Comparable) o1;
+ @SuppressWarnings("rawtypes")
+ Comparable c2 = (Comparable) o2;
+ // We can only count on using the comparable interface if o1 and o2
+ // are within of the same class or if one is a subclass of the other
+ if (c1.getClass().isAssignableFrom(c2.getClass())) {
+ return c1.compareTo(o2);
+ }
+ if (o2.getClass().isAssignableFrom(c1.getClass())) {
+ return -1 * c2.compareTo(o1);
+ }
+ }
+ logger.info("Using ToStringComparator because no apparent better comparison method could be found");
+ return ToStringComparator.getComparator().compare(o1, o2);
+ }
+}
\ 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/util/Predicate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/Predicate.java b/core/src/main/java/org/apache/metamodel/util/Predicate.java
new file mode 100644
index 0000000..4268c66
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/Predicate.java
@@ -0,0 +1,31 @@
+/**
+ * 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.util;
+
+/**
+ * A predicate is a special type of {@link Func}, used typically for
+ * inclusion/exclusion criteria.
+ *
+ * @author Kasper Sørensen
+ *
+ * @param <E>
+ */
+public interface Predicate<E> extends Func<E, Boolean> {
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/Ref.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/Ref.java b/core/src/main/java/org/apache/metamodel/util/Ref.java
new file mode 100644
index 0000000..0e9985f
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/Ref.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.util;
+
+/**
+ * Represents an abstract reference. This interface enables use of both regular,
+ * hard references, soft references and deferred/lazy references.
+ *
+ * @author Kasper Sørensen
+ *
+ * @param <E>
+ */
+public interface Ref<E> {
+
+ public E get();
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/Resource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/Resource.java b/core/src/main/java/org/apache/metamodel/util/Resource.java
new file mode 100644
index 0000000..8da25d6
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/Resource.java
@@ -0,0 +1,129 @@
+/**
+ * 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.util;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * Represents a resource from which we can read and write bytes
+ */
+public interface Resource extends HasName {
+
+ /**
+ * Gets the name of the resource, typically a filename or other identifying
+ * string
+ */
+ @Override
+ public String getName();
+
+ /**
+ * Determines if the file is read only, or if writes are also possible.
+ *
+ * @return
+ */
+ public boolean isReadOnly();
+
+ /**
+ * Determines if the resource referenced by this object exists or not.
+ *
+ * @return
+ */
+ public boolean isExists();
+
+ /**
+ * Gets the size (in number of bytes) of this resource's data. An
+ * approximated number is allowed.
+ *
+ * If the size is not determinable without actually reading through the
+ * whole contents of the resource, -1 is returned.
+ *
+ * @return
+ */
+ public long getSize();
+
+ /**
+ * Gets the last modified timestamp value (measured in milliseconds since
+ * the epoch (00:00:00 GMT, January 1, 1970)) of the resource, if available.
+ * If the last modified date is not available, -1 is returned.
+ *
+ * @return
+ */
+ public long getLastModified();
+
+ /**
+ * Opens up an {@link OutputStream} to write to the resource, and allows a
+ * callback to perform writing actions on it.
+ *
+ * @param writeCallback
+ * a callback which should define what to write to the resource.
+ *
+ * @throws ResourceException
+ * if an error occurs while writing
+ */
+ public void write(Action<OutputStream> writeCallback) throws ResourceException;
+
+ /**
+ * Opens up an {@link InputStream} to append (write at the end of the
+ * existing stream) to the resource.
+ *
+ * @param appendCallback
+ * a callback which should define what to append to the resource.
+ * @throws ResourceException
+ * if an error occurs while appending
+ */
+ public void append(Action<OutputStream> appendCallback) throws ResourceException;
+
+ /**
+ * Opens up an {@link InputStream} to read from the resource. Consumers of
+ * this method are expected to invoke the {@link InputStream#close()} method
+ * manually.
+ *
+ * If possible, the other read(...) methods are preferred over this one,
+ * since they guarantee proper closing of the resource's handles.
+ *
+ * @return
+ * @throws ResourceException
+ */
+ public InputStream read() throws ResourceException;
+
+ /**
+ * Opens up an {@link InputStream} to read from the resource, and allows a
+ * callback to perform writing actions on it.
+ *
+ * @param readCallback
+ *
+ * @throws ResourceException
+ * if an error occurs while reading
+ */
+ public void read(Action<InputStream> readCallback) throws ResourceException;
+
+ /**
+ * Opens up an {@link InputStream} to read from the resource, and allows a
+ * callback function to perform writing actions on it and return the
+ * function's result.
+ *
+ * @param readCallback
+ * @return the result of the function
+ *
+ * @throws ResourceException
+ * if an error occurs while reading
+ */
+ public <E> E read(Func<InputStream, E> readCallback) throws ResourceException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/ResourceException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/ResourceException.java b/core/src/main/java/org/apache/metamodel/util/ResourceException.java
new file mode 100644
index 0000000..4f61677
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/ResourceException.java
@@ -0,0 +1,50 @@
+/**
+ * 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.util;
+
+import org.eobjects.metamodel.MetaModelException;
+
+/**
+ * Exception type for errors that occur while dealing with {@link Resource}s.
+ */
+public class ResourceException extends MetaModelException {
+
+ private static final long serialVersionUID = 1L;
+
+ private final Resource _resource;
+
+ public ResourceException(Resource resource, Exception cause) {
+ super(cause);
+ _resource = resource;
+ }
+
+ public ResourceException(Resource resource,String message, Exception cause) {
+ super(message, cause);
+ _resource = resource;
+ }
+
+ public ResourceException(Resource resource,String message) {
+ super(message);
+ _resource = resource;
+ }
+
+ public Resource getResource() {
+ return _resource;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/SerializableRef.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/SerializableRef.java b/core/src/main/java/org/apache/metamodel/util/SerializableRef.java
new file mode 100644
index 0000000..3ae688e
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/SerializableRef.java
@@ -0,0 +1,90 @@
+/**
+ * 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.util;
+
+import java.io.Serializable;
+
+/**
+ * A serializable reference to an object which may or may not be serializable.
+ * Using this reference there is safety that if the object IS serializable, it
+ * will be serialized, or otherwise it will be gracefully ignored.
+ *
+ * @param <E>
+ */
+public final class SerializableRef<E> implements Ref<E>, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private final E _serializableObj;
+ private final transient E _transientObj;
+
+ public SerializableRef(E obj) {
+ if (obj instanceof Serializable) {
+ _serializableObj = obj;
+ _transientObj = null;
+ } else {
+ _serializableObj = null;
+ _transientObj = obj;
+ }
+ }
+
+ @Override
+ public E get() {
+ if (_serializableObj == null) {
+ return _transientObj;
+ }
+ return _serializableObj;
+ }
+
+ public boolean isSerializing() {
+ return _serializableObj != null;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((_serializableObj == null) ? 0 : _serializableObj.hashCode());
+ result = prime * result + ((_transientObj == null) ? 0 : _transientObj.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ SerializableRef<?> other = (SerializableRef<?>) obj;
+ if (_serializableObj == null) {
+ if (other._serializableObj != null)
+ return false;
+ } else if (!_serializableObj.equals(other._serializableObj))
+ return false;
+ if (_transientObj == null) {
+ if (other._transientObj != null)
+ return false;
+ } else if (!_transientObj.equals(other._transientObj))
+ return false;
+ return true;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/SharedExecutorService.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/SharedExecutorService.java b/core/src/main/java/org/apache/metamodel/util/SharedExecutorService.java
new file mode 100644
index 0000000..37b5aa5
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/SharedExecutorService.java
@@ -0,0 +1,78 @@
+/**
+ * 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.util;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * A shared {@link ExecutorService} for use on ad-hoc tasks that can be
+ * optimized by running operations in parallel.
+ *
+ * Note that since this {@link ExecutorService} is shared, it is not recommended
+ * to use it for dedicated tasks or daemon-like long-running tasks.
+ *
+ * @author Kasper Sørensen
+ */
+public final class SharedExecutorService {
+
+ /**
+ * A custom thread factory that creates daemon threads.
+ */
+ private static final class ThreadFactoryImpl implements ThreadFactory {
+
+ private static final AtomicInteger counter = new AtomicInteger(0);
+
+ private final ThreadGroup _threadGroup;
+
+ public ThreadFactoryImpl() {
+ SecurityManager s = System.getSecurityManager();
+ _threadGroup = (s != null) ? s.getThreadGroup() : Thread
+ .currentThread().getThreadGroup();
+ }
+
+ @Override
+ public Thread newThread(Runnable r) {
+ Thread thread = new Thread(_threadGroup, r,
+ "MetaModel.SharedExecutorService.Thread."
+ + counter.incrementAndGet());
+ thread.setDaemon(true);
+ thread.setPriority(Thread.NORM_PRIORITY);
+ return thread;
+ }
+ }
+
+ private static final ExecutorService executor = Executors
+ .newCachedThreadPool(new ThreadFactoryImpl());
+
+ private SharedExecutorService() {
+ // prevent instantiation
+ }
+
+ /**
+ * Gets the shared {@link ExecutorService}.
+ *
+ * @return an {@link ExecutorService} for shared usage.
+ */
+ public static final ExecutorService get() {
+ return executor;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/SimpleTableDef.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/SimpleTableDef.java b/core/src/main/java/org/apache/metamodel/util/SimpleTableDef.java
new file mode 100644
index 0000000..1739e95
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/SimpleTableDef.java
@@ -0,0 +1,203 @@
+/**
+ * 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.util;
+
+import java.io.Serializable;
+import java.util.Arrays;
+
+import org.eobjects.metamodel.DataContext;
+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.Table;
+import org.eobjects.metamodel.schema.TableType;
+
+/**
+ * Represents a table definition to be used in scenarios where a
+ * {@link DataContext} is unable to detect/discover the table structure and
+ * needs some basic input around expected table structures.
+ *
+ * @author Kasper Sørensen
+ */
+public class SimpleTableDef implements Serializable, HasName {
+
+ private static final long serialVersionUID = 1L;
+
+ private final String _name;
+ private final String[] _columnNames;
+ private final ColumnType[] _columnTypes;
+
+ /**
+ * Constructs a {@link SimpleTableDef} using a {@link Table} as a prototype.
+ *
+ * @param table
+ */
+ public SimpleTableDef(Table table) {
+ _name = table.getName();
+ _columnNames = new String[table.getColumnCount()];
+ _columnTypes = new ColumnType[table.getColumnCount()];
+ for (int i = 0; i < table.getColumnCount(); i++) {
+ Column column = table.getColumn(i);
+ _columnNames[i] = column.getName();
+ _columnTypes[i] = column.getType();
+ }
+ }
+
+ /**
+ * Constructs a {@link SimpleTableDef}.
+ *
+ * @param name
+ * the name of the table
+ * @param columnNames
+ * the names of the columns to include in the table
+ */
+ public SimpleTableDef(String name, String[] columnNames) {
+ this(name, columnNames, null);
+ }
+
+ /**
+ * Constructs a {@link SimpleTableDef}.
+ *
+ * @param name
+ * the name of table
+ * @param columnNames
+ * the names of the columns to include in the table
+ * @param columnTypes
+ * the column types of the columns specified.
+ */
+ public SimpleTableDef(String name, String[] columnNames, ColumnType[] columnTypes) {
+ _name = name;
+ _columnNames = columnNames;
+ if (columnTypes == null) {
+ columnTypes = new ColumnType[columnNames.length];
+ for (int i = 0; i < columnTypes.length; i++) {
+ columnTypes[i] = ColumnType.VARCHAR;
+ }
+ } else {
+ if (columnNames.length != columnTypes.length) {
+ throw new IllegalArgumentException(
+ "Property names and column types cannot have different lengths (found " + columnNames.length
+ + " and " + columnTypes.length + ")");
+ }
+ }
+ _columnTypes = columnTypes;
+ }
+
+ /**
+ * Gets the name of the table
+ *
+ * @return the name of the table
+ */
+ public String getName() {
+ return _name;
+ }
+
+ /**
+ * Gets the names of the columns in the table
+ *
+ * @return the names of the columns in the table
+ */
+ public String[] getColumnNames() {
+ return _columnNames;
+ }
+
+ /**
+ * Gets the types of the columns in the table
+ *
+ * @return the types of the columns in the table
+ */
+ public ColumnType[] getColumnTypes() {
+ return _columnTypes;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((_name == null) ? 0 : _name.hashCode());
+ result = prime * result + Arrays.hashCode(_columnTypes);
+ result = prime * result + Arrays.hashCode(_columnNames);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ SimpleTableDef other = (SimpleTableDef) obj;
+ if (_name == null) {
+ if (other._name != null)
+ return false;
+ } else if (!_name.equals(other._name))
+ return false;
+ if (!Arrays.equals(_columnTypes, other._columnTypes))
+ return false;
+ if (!Arrays.equals(_columnNames, other._columnNames))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "SimpleDbTableDef[name=" + _name + ",columnNames=" + Arrays.toString(_columnNames) + ",columnTypes="
+ + Arrays.toString(_columnTypes) + "]";
+ }
+
+ /**
+ * Creates a {@link MutableTable} based on this {@link SimpleTableDef}. Note
+ * that the created table will not have any schema set.
+ *
+ * @return a table representation of this table definition.
+ */
+ public MutableTable toTable() {
+ String name = getName();
+ String[] columnNames = getColumnNames();
+ ColumnType[] columnTypes = getColumnTypes();
+
+ MutableTable table = new MutableTable(name, TableType.TABLE);
+
+ for (int i = 0; i < columnNames.length; i++) {
+ table.addColumn(new MutableColumn(columnNames[i], columnTypes[i], table, i, true));
+ }
+ return table;
+ }
+
+ /**
+ * Gets the index of a column name, or -1 if the column name does not exist
+ *
+ * @param columnName
+ * @return
+ */
+ public int indexOf(String columnName) {
+ if (columnName == null) {
+ throw new IllegalArgumentException("Column name cannot be null");
+ }
+ for (int i = 0; i < _columnNames.length; i++) {
+ if (columnName.equals(_columnNames[i])) {
+ return i;
+ }
+ }
+ return -1;
+ }
+}
[37/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/convert/Converters.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/convert/Converters.java b/core/src/main/java/org/eobjects/metamodel/convert/Converters.java
deleted file mode 100644
index 11dd331..0000000
--- a/core/src/main/java/org/eobjects/metamodel/convert/Converters.java
+++ /dev/null
@@ -1,329 +0,0 @@
-/**
- * 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.convert;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.RowBuilder;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.intercept.InterceptableDataContext;
-import org.eobjects.metamodel.intercept.Interceptors;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.SuperColumnType;
-import org.eobjects.metamodel.schema.Table;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class consists of static methods for decorating {@link DataContext}s
- * with {@link TypeConverter}s, which allows for automatic conversion of values
- * on data read and write operations.
- */
-public final class Converters {
-
- private static final Logger logger = LoggerFactory.getLogger(Converters.class);
-
- private Converters() {
- // prevent instantiation
- }
-
- /**
- * Adds a type converter to a specific column in the {@link DataContext}.
- *
- * @param dataContext
- * the DataContext to decorate
- * @param column
- * the column which holds values to convert
- * @param converter
- * the converter to use on the specified column
- * @return a decorated DataContext, which should be used for successive
- * operations on the data.
- */
- public static UpdateableDataContext addTypeConverter(UpdateableDataContext dataContext, Column column,
- TypeConverter<?, ?> converter) {
- return addTypeConverterInternally(dataContext, column, converter);
- }
-
- /**
- * Adds a type converter to a specific column in the {@link DataContext}.
- *
- * @param dataContext
- * the DataContext to decorate
- * @param column
- * the column which holds values to convert
- * @param converter
- * the converter to use on the specified column
- * @return a decorated DataContext, which should be used for successive
- * operations on the data.
- */
- public static DataContext addTypeConverter(DataContext dataContext, Column column, TypeConverter<?, ?> converter) {
- return addTypeConverterInternally(dataContext, column, converter);
- }
-
- /**
- * Adds a collection of type converters to specific columns in the
- * {@link DataContext}
- *
- * @param dataContext
- * the DataContext to decorate
- * @param converters
- * a map containing columns and mapped type converters.
- * @return a decorated DataContext, which should be used for successive
- * operations on the data.
- */
- public static UpdateableDataContext addTypeConverters(UpdateableDataContext dataContext,
- Map<Column, TypeConverter<?, ?>> converters) {
- return addTypeConvertersInternally(dataContext, converters);
- }
-
- /**
- * Adds a collection of type converters to specific columns in the
- * {@link DataContext}
- *
- * @param dataContext
- * the DataContext to decorate
- * @param converters
- * a map containing columns and mapped type converters.
- * @return a decorated DataContext, which should be used for successive
- * operations on the data.
- */
- public static DataContext addTypeConverters(DataContext dataContext, Map<Column, TypeConverter<?, ?>> converters) {
- return addTypeConvertersInternally(dataContext, converters);
- }
-
- /**
- * Auto-detects / guesses the type converters to be applied on set of
- * columns. This method will query the String columns in order to assert
- * which columns are likely candidates for conversion.
- *
- * As such this method is not guaranteed to pick the correct converters,
- * since data can change over time or other conversions can be requested.
- *
- * @param dataContext
- * the DataContext that holds the data.
- * @param columns
- * the columns to inspect to find type conversion candidates.
- * @param sampleSize
- * the max amount of rows to query for doing auto-detection. Use
- * {@link Integer#MAX_VALUE} if no constraint should be put on
- * the number of records to sample.
- * @return a map of {@link Column}s and {@link TypeConverter}s which can be
- * 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,
- 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);
- }
- return result;
- }
-
- /**
- * Auto-detects / guesses the type converters to be applied on a table. This
- * method will query the String columns of a table in order to assert which
- * columns are likely candidates for conversion.
- *
- * As such this method is not guaranteed to pick the correct converters,
- * since data can change over time or other conversions can be requested.
- *
- * @param dataContext
- * the DataContext that holds the data.
- * @param table
- * the table to inspect to find type conversion candidates. This
- * table will hold all columns of the result.
- * @param sampleSize
- * the max amount of rows to query for doing auto-detection. Use
- * {@link Integer#MAX_VALUE} if no constraint should be put on
- * the number of records to sample.
- * @return a map of {@link Column}s and {@link TypeConverter}s which can be
- * used (eg. with the {@link #addTypeConverters(DataContext, Map)}
- * method) to decorate the DataContext with type 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);
- autoDetectConvertersInternally(dataContext, table, columns, sampleSize, result);
- return result;
- }
-
- private static void autoDetectConvertersInternally(DataContext dataContext, Table table, Column[] columns,
- int sampleSize, Map<Column, TypeConverter<?, ?>> result) {
- if (columns == null || columns.length == 0) {
- return;
- }
-
- Map<Column, ColumnTypeDetector> detectors = new HashMap<Column, ColumnTypeDetector>();
- for (Column column : columns) {
- detectors.put(column, new ColumnTypeDetector());
- }
-
- Query query = dataContext.query().from(table).select(columns).toQuery();
- if (sampleSize > 0 && sampleSize != Integer.MAX_VALUE) {
- query.setMaxRows(sampleSize);
- }
- DataSet dataSet = dataContext.executeQuery(query);
- try {
- while (dataSet.next()) {
- Row row = dataSet.getRow();
- for (Column column : columns) {
- String stringValue = (String) row.getValue(column);
- ColumnTypeDetector detector = detectors.get(column);
- detector.registerValue(stringValue);
- }
- }
- } finally {
- dataSet.close();
- }
- for (Column column : columns) {
- ColumnTypeDetector detector = detectors.get(column);
- TypeConverter<?, ?> converter = detector.createConverter();
- if (converter != null) {
- result.put(column, converter);
- }
- }
- }
-
- private static InterceptableDataContext addTypeConvertersInternally(final DataContext dc,
- Map<Column, TypeConverter<?, ?>> converters) {
- if (converters == null) {
- throw new IllegalArgumentException("Converters cannot be null");
- }
-
- InterceptableDataContext interceptable = Interceptors.intercept(dc);
-
- Set<Entry<Column, TypeConverter<?, ?>>> entries = converters.entrySet();
- for (Entry<Column, TypeConverter<?, ?>> entry : entries) {
- Column column = entry.getKey();
- TypeConverter<?, ?> converter = entry.getValue();
- interceptable = addTypeConverterInternally(interceptable, column, converter);
- }
-
- return interceptable;
- }
-
- private static InterceptableDataContext addTypeConverterInternally(final DataContext dc, Column column,
- TypeConverter<?, ?> converter) {
- if (column == null) {
- throw new IllegalArgumentException("Column cannot be null");
- }
-
- InterceptableDataContext interceptable = Interceptors.intercept(dc);
- DataContext delegate = interceptable.getDelegate();
-
- boolean interceptDataSets = true;
-
- if (delegate instanceof HasReadTypeConverters) {
- // some DataContexts implement the HasTypeConverters interface,
- // which is preferred when available
- HasReadTypeConverters hasTypeConverter = (HasReadTypeConverters) delegate;
- hasTypeConverter.addConverter(column, converter);
-
- interceptDataSets = false;
- }
-
- addTypeConverterInterceptors(interceptable, column, converter, interceptDataSets);
- return interceptable;
- }
-
- private static void addTypeConverterInterceptors(InterceptableDataContext interceptable, Column column,
- TypeConverter<?, ?> converter, boolean interceptDataSets) {
- // intercept datasets (reads)
- if (interceptDataSets) {
- ConvertedDataSetInterceptor interceptor = interceptable.getDataSetInterceptors().getInterceptorOfType(
- ConvertedDataSetInterceptor.class);
- if (interceptor == null) {
- interceptor = new ConvertedDataSetInterceptor();
- interceptable.addDataSetInterceptor(interceptor);
- }
- interceptor.addConverter(column, converter);
- }
-
- // intercept inserts (writes)
- {
- ConvertedRowInsertionInterceptor interceptor = interceptable.getRowInsertionInterceptors()
- .getInterceptorOfType(ConvertedRowInsertionInterceptor.class);
- if (interceptor == null) {
- interceptor = new ConvertedRowInsertionInterceptor();
- interceptable.addRowInsertionInterceptor(interceptor);
- }
- interceptor.addConverter(column, converter);
- }
-
- // convert updates
- {
- ConvertedRowUpdationInterceptor interceptor = interceptable.getRowUpdationInterceptors()
- .getInterceptorOfType(ConvertedRowUpdationInterceptor.class);
- if (interceptor == null) {
- interceptor = new ConvertedRowUpdationInterceptor();
- interceptable.addRowUpdationInterceptor(interceptor);
- }
- interceptor.addConverter(column, converter);
- }
-
- // converting deletes (as well as where-items in updates) should not be
- // applied, because the DataSet interceptor is anyways only working on
- // the output. In that sense it adds symetry to NOT support conversion
- // in the where clause of UPDATEs and DELETEs.
- }
-
- /**
- * Converts values in a {@link RowBuilder}.
- *
- * @param rowBuilder
- * @param converters
- * @return
- */
- protected static <RB extends RowBuilder<?>> RB convertRow(RB rowBuilder, Map<Column, TypeConverter<?, ?>> converters) {
- Table table = rowBuilder.getTable();
- Column[] columns = table.getColumns();
- Row row = rowBuilder.toRow();
- for (Column column : columns) {
- @SuppressWarnings("unchecked")
- TypeConverter<?, Object> converter = (TypeConverter<?, Object>) converters.get(column);
- if (converter != null) {
- final int indexInRow = row.indexOf(column);
- final Object value = row.getValue(indexInRow);
- final Object physicalValue = converter.toPhysicalValue(value);
- logger.debug("Converted virtual value {} to {}", value, physicalValue);
- if (value == null && physicalValue == null && !rowBuilder.isSet(column)) {
- logger.debug("Omitting implicit null value for column: {}", column);
- } else {
- final Style style = row.getStyle(indexInRow);
- rowBuilder.value(column, physicalValue, style);
- }
- }
- }
- return rowBuilder;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/convert/HasReadTypeConverters.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/convert/HasReadTypeConverters.java b/core/src/main/java/org/eobjects/metamodel/convert/HasReadTypeConverters.java
deleted file mode 100644
index a5c1f86..0000000
--- a/core/src/main/java/org/eobjects/metamodel/convert/HasReadTypeConverters.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * 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.convert;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.schema.Column;
-
-/**
- * Defines an interface for objects that are aware of {@link TypeConverter}s,
- * and know how to apply them to read operations (Queries or {@link DataSet}s).
- *
- * @author Kasper Sørensen
- */
-public interface HasReadTypeConverters {
-
- public void addConverter(Column column, TypeConverter<?, ?> converter);
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/convert/StringToBooleanConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/convert/StringToBooleanConverter.java b/core/src/main/java/org/eobjects/metamodel/convert/StringToBooleanConverter.java
deleted file mode 100644
index 6f3fdaa..0000000
--- a/core/src/main/java/org/eobjects/metamodel/convert/StringToBooleanConverter.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * 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.convert;
-
-import org.eobjects.metamodel.util.BooleanComparator;
-
-/**
- * A {@link TypeConverter} that converts String values (on the physical layer)
- * to interpreted Booleans.
- *
- * @author Kasper Sørensen
- * @author Ankit Kumar
- */
-public class StringToBooleanConverter implements TypeConverter<String, Boolean> {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toPhysicalValue(Boolean virtualValue) {
- if (virtualValue == null) {
- return null;
- }
- return virtualValue.toString();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Boolean toVirtualValue(String physicalValue) {
- if (physicalValue == null || physicalValue.length() == 0) {
- return null;
- }
- return BooleanComparator.parseBoolean(physicalValue);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/convert/StringToDateConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/convert/StringToDateConverter.java b/core/src/main/java/org/eobjects/metamodel/convert/StringToDateConverter.java
deleted file mode 100644
index 862bc64..0000000
--- a/core/src/main/java/org/eobjects/metamodel/convert/StringToDateConverter.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/**
- * 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.convert;
-
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import org.eobjects.metamodel.util.Func;
-import org.eobjects.metamodel.util.TimeComparator;
-
-/**
- * A {@link TypeConverter} that converts String values (on the physical layer)
- * to interpreted {@link Date}s.
- *
- * @author Kasper Sørensen
- * @author Ankit Kumar
- */
-public class StringToDateConverter implements TypeConverter<String, Date> {
-
- private final Func<Date, String> _serializeFunc;
- private final Func<String, Date> _deserializeFunc;
-
- /**
- * Constructs a new {@link StringToDateConverter} which will use the
- * {@link TimeComparator#toDate(Object)} method for parsing dates and the
- * {@link DateFormat#MEDIUM} date time format for physical representation.
- */
- public StringToDateConverter() {
- _deserializeFunc = new Func<String, Date>() {
- @Override
- public Date eval(String stringValue) {
- return TimeComparator.toDate(stringValue);
- }
- };
- _serializeFunc = new Func<Date, String>() {
- @Override
- public String eval(Date date) {
- return DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
- DateFormat.MEDIUM).format(date);
- }
- };
- }
-
- /**
- * Constructs a new {@link StringToDateConverter} using a given date
- * pattern.
- *
- * @param datePattern
- * a String date pattern, corresponding to the syntax of a
- * {@link SimpleDateFormat}.
- */
- public StringToDateConverter(String datePattern) {
- this(new SimpleDateFormat(datePattern));
- }
-
- /**
- * Constructs a new {@link StringToDateConverter} using a given
- * {@link DateFormat}.
- *
- * @param dateFormat
- * the {@link DateFormat} to use for parsing and formatting
- * dates.
- */
- public StringToDateConverter(final DateFormat dateFormat) {
- if (dateFormat == null) {
- throw new IllegalArgumentException("DateFormat cannot be null");
- }
- _deserializeFunc = new Func<String, Date>() {
- @Override
- public Date eval(String string) {
- try {
- return dateFormat.parse(string);
- } catch (ParseException e) {
- throw new IllegalArgumentException(
- "Could not parse date string: " + string);
- }
- }
- };
- _serializeFunc = new Func<Date, String>() {
- @Override
- public String eval(Date date) {
- return dateFormat.format(date);
- }
- };
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toPhysicalValue(Date virtualValue) {
- if (virtualValue == null) {
- return null;
- }
- return _serializeFunc.eval(virtualValue);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Date toVirtualValue(String physicalValue) {
- if (physicalValue == null || physicalValue.length() == 0) {
- return null;
- }
- return _deserializeFunc.eval(physicalValue);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/convert/StringToDoubleConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/convert/StringToDoubleConverter.java b/core/src/main/java/org/eobjects/metamodel/convert/StringToDoubleConverter.java
deleted file mode 100644
index d073cfc..0000000
--- a/core/src/main/java/org/eobjects/metamodel/convert/StringToDoubleConverter.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * 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.convert;
-
-/**
- * A {@link TypeConverter} that converts String values (on the physical layer)
- * to interpreted Doubles.
- *
- * @author Kasper Sørensen
- * @author Ankit Kumar
- */
-public class StringToDoubleConverter implements TypeConverter<String, Double> {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toPhysicalValue(Double virtualValue) {
- if (virtualValue == null) {
- return null;
- }
- return virtualValue.toString();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Double toVirtualValue(String physicalValue) {
- if (physicalValue == null || physicalValue.length() == 0) {
- return null;
- }
- return Double.parseDouble(physicalValue);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/convert/StringToIntegerConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/convert/StringToIntegerConverter.java b/core/src/main/java/org/eobjects/metamodel/convert/StringToIntegerConverter.java
deleted file mode 100644
index 19d1bb5..0000000
--- a/core/src/main/java/org/eobjects/metamodel/convert/StringToIntegerConverter.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * 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.convert;
-
-/**
- * A {@link TypeConverter} that converts String values (on the physical layer)
- * to interpreted Integers.
- *
- * @author Kasper Sørensen
- * @author Ankit Kumar
- */
-public class StringToIntegerConverter implements TypeConverter<String, Integer> {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toPhysicalValue(Integer virtualValue) {
- if (virtualValue == null) {
- return null;
- }
- return virtualValue.toString();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Integer toVirtualValue(String physicalValue) {
- if (physicalValue == null || physicalValue.length() == 0) {
- return null;
- }
- return Integer.parseInt(physicalValue);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/convert/TypeConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/convert/TypeConverter.java b/core/src/main/java/org/eobjects/metamodel/convert/TypeConverter.java
deleted file mode 100644
index 5827b2a..0000000
--- a/core/src/main/java/org/eobjects/metamodel/convert/TypeConverter.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * 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.convert;
-
-/**
- * Defines an interface for converting values from and to their physical
- * materializations and their virtual representations.
- *
- * @see ConvertedDataContext
- *
- * @author Kasper Sørensen
- * @author Ankit Kumar
- *
- * @param <P>
- * the physical type of value
- * @param <V>
- * the virtual type of value
- */
-public interface TypeConverter<P, V> {
-
- /**
- * Converts a virtual representation of a value into it's physical value.
- *
- * @param virtualValue
- * the virtual representation
- * @return the physical value
- */
- public P toPhysicalValue(V virtualValue);
-
- /**
- * Converts a physical value into it's virtual representation.
- *
- * @param physicalValue
- * the physical value
- * @return the virtual representation
- */
- public V toVirtualValue(P physicalValue);
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/convert/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/convert/package-info.java b/core/src/main/java/org/eobjects/metamodel/convert/package-info.java
deleted file mode 100644
index 88ec009..0000000
--- a/core/src/main/java/org/eobjects/metamodel/convert/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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.
- */
-/**
- * DataContext decorator for implicit conversion of value types after querying and before insertion.
- */
-package org.eobjects.metamodel.convert;
-
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/create/AbstractColumnBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/create/AbstractColumnBuilder.java b/core/src/main/java/org/eobjects/metamodel/create/AbstractColumnBuilder.java
deleted file mode 100644
index 2f2e422..0000000
--- a/core/src/main/java/org/eobjects/metamodel/create/AbstractColumnBuilder.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * 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;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-
-/**
- * Convenience implementation of all {@link ColumnBuilder} methods
- *
- * @param <T>
- * the return type of the builder methods.
- */
-abstract class AbstractColumnBuilder<T extends ColumnBuilder<?>> implements ColumnBuilder<T> {
-
- private final MutableColumn _column;
-
- public AbstractColumnBuilder(MutableColumn column) {
- _column = column;
- }
-
- protected MutableColumn getColumn() {
- return _column;
- }
-
- @SuppressWarnings("unchecked")
- protected T getReturnObject() {
- return (T) this;
- }
-
- @Override
- public final T like(Column column) {
- _column.setColumnSize(column.getColumnSize());
- _column.setNativeType(column.getNativeType());
- _column.setType(column.getType());
- _column.setNullable(column.isNullable());
- return getReturnObject();
- }
-
- @Override
- public final T ofType(ColumnType type) {
- _column.setType(type);
- return getReturnObject();
- }
-
- @Override
- public final T ofNativeType(String nativeType) {
- _column.setNativeType(nativeType);
- return getReturnObject();
- }
-
- @Override
- public final T ofSize(int size) {
- _column.setColumnSize(size);
- return getReturnObject();
- }
-
- @Override
- public final T nullable(boolean nullable) {
- _column.setNullable(nullable);
- return getReturnObject();
- }
-
- @Override
- public final T asPrimaryKey() {
- _column.setPrimaryKey(true);
- return getReturnObject();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/create/AbstractTableCreationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/create/AbstractTableCreationBuilder.java b/core/src/main/java/org/eobjects/metamodel/create/AbstractTableCreationBuilder.java
deleted file mode 100644
index 2d52275..0000000
--- a/core/src/main/java/org/eobjects/metamodel/create/AbstractTableCreationBuilder.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/**
- * 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/eobjects/metamodel/create/ColumnBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/create/ColumnBuilder.java b/core/src/main/java/org/eobjects/metamodel/create/ColumnBuilder.java
deleted file mode 100644
index 1f1ea74..0000000
--- a/core/src/main/java/org/eobjects/metamodel/create/ColumnBuilder.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/**
- * 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/eobjects/metamodel/create/ColumnCreationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/create/ColumnCreationBuilder.java b/core/src/main/java/org/eobjects/metamodel/create/ColumnCreationBuilder.java
deleted file mode 100644
index d53abda..0000000
--- a/core/src/main/java/org/eobjects/metamodel/create/ColumnCreationBuilder.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * 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/eobjects/metamodel/create/ColumnCreationBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/create/ColumnCreationBuilderImpl.java b/core/src/main/java/org/eobjects/metamodel/create/ColumnCreationBuilderImpl.java
deleted file mode 100644
index 9add137..0000000
--- a/core/src/main/java/org/eobjects/metamodel/create/ColumnCreationBuilderImpl.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * 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/eobjects/metamodel/create/CreateTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/create/CreateTable.java b/core/src/main/java/org/eobjects/metamodel/create/CreateTable.java
deleted file mode 100644
index 56e1694..0000000
--- a/core/src/main/java/org/eobjects/metamodel/create/CreateTable.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * 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/eobjects/metamodel/create/CreateTableColumnBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/create/CreateTableColumnBuilder.java b/core/src/main/java/org/eobjects/metamodel/create/CreateTableColumnBuilder.java
deleted file mode 100644
index e1a6b4a..0000000
--- a/core/src/main/java/org/eobjects/metamodel/create/CreateTableColumnBuilder.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * 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/eobjects/metamodel/create/TableCreatable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/create/TableCreatable.java b/core/src/main/java/org/eobjects/metamodel/create/TableCreatable.java
deleted file mode 100644
index 888c09d..0000000
--- a/core/src/main/java/org/eobjects/metamodel/create/TableCreatable.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * 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/eobjects/metamodel/create/TableCreationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/create/TableCreationBuilder.java b/core/src/main/java/org/eobjects/metamodel/create/TableCreationBuilder.java
deleted file mode 100644
index 042049a..0000000
--- a/core/src/main/java/org/eobjects/metamodel/create/TableCreationBuilder.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * 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/eobjects/metamodel/create/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/create/package-info.java b/core/src/main/java/org/eobjects/metamodel/create/package-info.java
deleted file mode 100644
index fef2d9e..0000000
--- a/core/src/main/java/org/eobjects/metamodel/create/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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/eobjects/metamodel/data/AbstractDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/AbstractDataSet.java b/core/src/main/java/org/eobjects/metamodel/data/AbstractDataSet.java
deleted file mode 100644
index 98b9416..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/AbstractDataSet.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/**
- * 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/eobjects/metamodel/data/AbstractRow.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/AbstractRow.java b/core/src/main/java/org/eobjects/metamodel/data/AbstractRow.java
deleted file mode 100644
index a879454..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/AbstractRow.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/**
- * 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/eobjects/metamodel/data/AbstractRowBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/AbstractRowBuilder.java b/core/src/main/java/org/eobjects/metamodel/data/AbstractRowBuilder.java
deleted file mode 100644
index b02fd8e..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/AbstractRowBuilder.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/**
- * 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/eobjects/metamodel/data/CachingDataSetHeader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/CachingDataSetHeader.java b/core/src/main/java/org/eobjects/metamodel/data/CachingDataSetHeader.java
deleted file mode 100644
index 25bad2b..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/CachingDataSetHeader.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- * 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/eobjects/metamodel/data/ColorImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/ColorImpl.java b/core/src/main/java/org/eobjects/metamodel/data/ColorImpl.java
deleted file mode 100644
index be2d14c..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/ColorImpl.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * 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/eobjects/metamodel/data/DataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/DataSet.java b/core/src/main/java/org/eobjects/metamodel/data/DataSet.java
deleted file mode 100644
index dc471b8..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/DataSet.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * 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
[10/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/test/java/org/eobjects/metamodel/excel/ExcelUpdateCallbackTest.java
----------------------------------------------------------------------
diff --git a/excel/src/test/java/org/eobjects/metamodel/excel/ExcelUpdateCallbackTest.java b/excel/src/test/java/org/eobjects/metamodel/excel/ExcelUpdateCallbackTest.java
deleted file mode 100644
index 2bf778b..0000000
--- a/excel/src/test/java/org/eobjects/metamodel/excel/ExcelUpdateCallbackTest.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/**
- * 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.excel;
-
-import java.io.File;
-import java.lang.reflect.Field;
-import java.util.Arrays;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.xssf.streaming.SXSSFRow;
-import org.apache.poi.xssf.streaming.SXSSFSheet;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.schema.Table;
-
-public class ExcelUpdateCallbackTest extends TestCase {
-
- public void testStreamingAPI() throws Exception {
- File file = new File("target/streaming-api-test.xlsx");
- if (file.exists()) {
- file.delete();
- }
-
- assertFalse(file.exists());
-
- // write using streaming writer
- {
- ExcelDataContext dc = new ExcelDataContext(file);
- ExcelUpdateCallback callback = new ExcelUpdateCallback(dc);
-
- SXSSFSheet sheet = (SXSSFSheet) callback.createSheet("foobar");
-
- Field windowSizeField = SXSSFSheet.class
- .getDeclaredField("_randomAccessWindowSize");
- windowSizeField.setAccessible(true);
- int windowSize = windowSizeField.getInt(sheet);
- assertEquals(1000, windowSize);
-
- Field rowsField = SXSSFSheet.class.getDeclaredField("_rows");
- rowsField.setAccessible(true);
- @SuppressWarnings("unchecked")
- Map<Integer, SXSSFRow> rows = (Map<Integer, SXSSFRow>) rowsField
- .get(sheet);
- assertEquals(0, rows.size());
-
- // create 5x the amound of rows as the streaming sheet will hold in
- // memory
- for (int i = 0; i < windowSize * 5; i++) {
- Row row = sheet.createRow(i);
- Cell cell = row.createCell(0);
- cell.setCellValue("value" + i);
-
- assertTrue(rows.size() <= 1000);
- }
-
- assertEquals(1000, rows.size());
-
- ExcelUtils.writeWorkbook(dc, sheet.getWorkbook());
- }
-
- assertTrue("Usually the file size will be circa 42000, but it was: "
- + file.length(), file.length() > 40000 && file.length() < 45000);
-
- // read to check results
- {
- ExcelDataContext dc = new ExcelDataContext(file);
- assertEquals("[foobar]",
- Arrays.toString(dc.getDefaultSchema().getTableNames()));
-
- Table table = dc.getDefaultSchema().getTableByName("foobar");
-
- assertEquals("[value0]", Arrays.toString(table.getColumnNames()));
-
- DataSet ds = dc.query().from(table).select("value0").execute();
- int recordNo = 1;
- while (ds.next()) {
- assertEquals("value" + recordNo, ds.getRow().getValue(0));
- recordNo++;
- }
-
- assertEquals(5000, recordNo);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/test/java/org/eobjects/metamodel/excel/ZeroBasedRowIteratorTest.java
----------------------------------------------------------------------
diff --git a/excel/src/test/java/org/eobjects/metamodel/excel/ZeroBasedRowIteratorTest.java b/excel/src/test/java/org/eobjects/metamodel/excel/ZeroBasedRowIteratorTest.java
deleted file mode 100644
index 730727e..0000000
--- a/excel/src/test/java/org/eobjects/metamodel/excel/ZeroBasedRowIteratorTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- * 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.excel;
-
-import java.io.FileInputStream;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.WorkbookFactory;
-import org.easymock.EasyMock;
-import org.eobjects.metamodel.excel.ZeroBasedRowIterator;
-
-public class ZeroBasedRowIteratorTest extends TestCase {
-
- public void testHasNext() throws Exception {
- Workbook workbook = WorkbookFactory.create(new FileInputStream(
- "src/test/resources/xls_single_cell_sheet.xls"));
- Sheet sheet = workbook.getSheetAt(0);
-
- // POI's row numbers are 0-based also - the last cell in the sheet is
- // actually A6.
- assertEquals(5, sheet.getLastRowNum());
-
- ZeroBasedRowIterator it = new ZeroBasedRowIterator(sheet);
-
- assertTrue(it.hasNext());
- assertNull(it.next());
-
- assertTrue(it.hasNext());
- assertNull(it.next());
-
- assertTrue(it.hasNext());
- assertNull(it.next());
-
- assertTrue(it.hasNext());
- assertNull(it.next());
-
- assertTrue(it.hasNext());
- assertNull(it.next());
-
- assertTrue(it.hasNext());
- assertNotNull(it.next());
-
- assertFalse(it.hasNext());
- }
-
- public void testUnsupportedRemove() throws Exception {
- ZeroBasedRowIterator it = new ZeroBasedRowIterator(EasyMock.createMock(Sheet.class));
-
- try {
- it.remove();
- fail("Exception expected");
- } catch (UnsupportedOperationException e) {
- assertEquals("remove() is not supported", e.getMessage());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthConfiguration.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthConfiguration.java b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthConfiguration.java
new file mode 100644
index 0000000..5054b01
--- /dev/null
+++ b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthConfiguration.java
@@ -0,0 +1,151 @@
+/**
+ * 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.fixedwidth;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.util.BaseObject;
+import org.eobjects.metamodel.util.FileHelper;
+
+/**
+ * Configuration of metadata about a fixed width values datacontext.
+ *
+ * @author Kasper Sørensen
+ */
+public final class FixedWidthConfiguration extends BaseObject implements
+ Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ public static final int NO_COLUMN_NAME_LINE = 0;
+ public static final int DEFAULT_COLUMN_NAME_LINE = 1;
+
+ private final String encoding;
+ private final int fixedValueWidth;
+ private final int[] valueWidths;
+ private final int columnNameLineNumber;
+ private final boolean failOnInconsistentLineWidth;
+
+ public FixedWidthConfiguration(int fixedValueWidth) {
+ this(DEFAULT_COLUMN_NAME_LINE, FileHelper.DEFAULT_ENCODING,
+ fixedValueWidth);
+ }
+
+ public FixedWidthConfiguration(int[] valueWidth) {
+ this(DEFAULT_COLUMN_NAME_LINE, FileHelper.DEFAULT_ENCODING, valueWidth,
+ false);
+ }
+
+ public FixedWidthConfiguration(int columnNameLineNumber, String encoding,
+ int fixedValueWidth) {
+ this(columnNameLineNumber, encoding, fixedValueWidth, false);
+ }
+
+ public FixedWidthConfiguration(int columnNameLineNumber, String encoding,
+ int fixedValueWidth, boolean failOnInconsistentLineWidth) {
+ this.encoding = encoding;
+ this.fixedValueWidth = fixedValueWidth;
+ this.columnNameLineNumber = columnNameLineNumber;
+ this.failOnInconsistentLineWidth = failOnInconsistentLineWidth;
+ this.valueWidths = new int[0];
+ }
+
+ public FixedWidthConfiguration(int columnNameLineNumber, String encoding,
+ int[] valueWidths, boolean failOnInconsistentLineWidth) {
+ this.encoding = encoding;
+ this.fixedValueWidth = -1;
+ this.columnNameLineNumber = columnNameLineNumber;
+ this.failOnInconsistentLineWidth = failOnInconsistentLineWidth;
+ this.valueWidths = valueWidths;
+ }
+
+ /**
+ * The line number (1 based) from which to get the names of the columns.
+ *
+ * @return an int representing the line number of the column headers/names.
+ */
+ public int getColumnNameLineNumber() {
+ return columnNameLineNumber;
+ }
+
+ /**
+ * Gets the file encoding to use for reading the file.
+ *
+ * @return the text encoding to use for reading the file.
+ */
+ public String getEncoding() {
+ return encoding;
+ }
+
+ /**
+ * Gets the width of each value within the fixed width value file.
+ *
+ * @return the fixed width to use when parsing the file.
+ */
+ public int getFixedValueWidth() {
+ return fixedValueWidth;
+ }
+
+ public int[] getValueWidths() {
+ return valueWidths;
+ }
+
+ /**
+ * Determines if the {@link DataSet#next()} should throw an exception in
+ * case of inconsistent line width in the fixed width value file.
+ *
+ * @return a boolean indicating whether or not to fail on inconsistent line
+ * widths.
+ */
+ public boolean isFailOnInconsistentLineWidth() {
+ return failOnInconsistentLineWidth;
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ identifiers.add(columnNameLineNumber);
+ identifiers.add(encoding);
+ identifiers.add(fixedValueWidth);
+ identifiers.add(valueWidths);
+ identifiers.add(failOnInconsistentLineWidth);
+ }
+
+ @Override
+ public String toString() {
+ return "FixedWidthConfiguration[encoding=" + encoding
+ + ", fixedValueWidth=" + fixedValueWidth + ", valueWidths="
+ + Arrays.toString(valueWidths) + ", columnNameLineNumber="
+ + columnNameLineNumber + ", failOnInconsistentLineWidth="
+ + failOnInconsistentLineWidth + "]";
+ }
+
+ public boolean isConstantValueWidth() {
+ return fixedValueWidth != -1;
+ }
+
+ public int getValueWidth(int columnIndex) {
+ if (isConstantValueWidth()) {
+ return fixedValueWidth;
+ }
+ return valueWidths[columnIndex];
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataContext.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataContext.java b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataContext.java
new file mode 100644
index 0000000..704b376
--- /dev/null
+++ b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataContext.java
@@ -0,0 +1,192 @@
+/**
+ * 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.fixedwidth;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.Reader;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.QueryPostprocessDataContext;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+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.Table;
+import org.eobjects.metamodel.schema.TableType;
+import org.eobjects.metamodel.util.AlphabeticSequence;
+import org.eobjects.metamodel.util.FileHelper;
+import org.eobjects.metamodel.util.FileResource;
+import org.eobjects.metamodel.util.Resource;
+
+/**
+ * DataContext implementation for fixed width value files.
+ *
+ * @author Kasper Sørensen
+ */
+public class FixedWidthDataContext extends QueryPostprocessDataContext {
+
+ private final Resource _resource;
+ private final FixedWidthConfiguration _configuration;
+
+ /**
+ * @deprecated use
+ * {@link #FixedWidthDataContext(File, FixedWidthConfiguration)}
+ * instead
+ */
+ @Deprecated
+ public FixedWidthDataContext(String filename, String fileEncoding, int fixedValueWidth) {
+ this(new FileResource(filename), new FixedWidthConfiguration(fixedValueWidth));
+ }
+
+ /**
+ * @deprecated use
+ * {@link #FixedWidthDataContext(File, FixedWidthConfiguration)}
+ * instead
+ */
+ @Deprecated
+ public FixedWidthDataContext(File file, String fileEncoding, int fixedValueWidth, int headerLineNumber) {
+ this(file, new FixedWidthConfiguration(headerLineNumber, fileEncoding, fixedValueWidth));
+ }
+
+ public FixedWidthDataContext(File file, FixedWidthConfiguration configuration) {
+ _resource = new FileResource(file);
+ _configuration = configuration;
+ }
+
+ public FixedWidthDataContext(Resource resource, FixedWidthConfiguration configuration) {
+ _resource = resource;
+ _configuration = configuration;
+ }
+
+ /**
+ * Gets the Fixed width value configuration used.
+ *
+ * @return a fixed width configuration
+ */
+ public FixedWidthConfiguration getConfiguration() {
+ return _configuration;
+ }
+
+ /**
+ * Gets the file being read.
+ *
+ * @return a file
+ *
+ * @deprecated use {@link #getResource()} instead.
+ */
+ @Deprecated
+ public File getFile() {
+ if (_resource instanceof FileResource) {
+ return ((FileResource) _resource).getFile();
+ }
+ return null;
+ }
+
+ /**
+ * Gets the resource being read
+ *
+ * @return
+ */
+ public Resource getResource() {
+ return _resource;
+ }
+
+ @Override
+ protected Schema getMainSchema() throws MetaModelException {
+ final String schemaName = getDefaultSchemaName();
+ final MutableSchema schema = new MutableSchema(schemaName);
+ final String tableName = schemaName.substring(0, schemaName.length() - 4);
+ final MutableTable table = new MutableTable(tableName, TableType.TABLE, schema);
+ schema.addTable(table);
+
+ final FixedWidthReader reader = createReader();
+ final String[] columnNames;
+ try {
+ if (_configuration.getColumnNameLineNumber() != FixedWidthConfiguration.NO_COLUMN_NAME_LINE) {
+ for (int i = 1; i < _configuration.getColumnNameLineNumber(); i++) {
+ reader.readLine();
+ }
+ columnNames = reader.readLine();
+ } else {
+ columnNames = reader.readLine();
+ if (columnNames != null) {
+ AlphabeticSequence sequence = new AlphabeticSequence();
+ for (int i = 0; i < columnNames.length; i++) {
+ columnNames[i] = sequence.next();
+ }
+ }
+ }
+ } finally {
+ FileHelper.safeClose(reader);
+ }
+
+ if (columnNames != null) {
+ for (int i = 0; i < columnNames.length; i++) {
+ final String columnName = columnNames[i];
+ final MutableColumn column = new MutableColumn(columnName, ColumnType.VARCHAR, table, i, true);
+ column.setColumnSize(_configuration.getValueWidth(i));
+ table.addColumn(column);
+ }
+ }
+
+ return schema;
+ }
+
+ @Override
+ protected String getMainSchemaName() throws MetaModelException {
+ return _resource.getName();
+ }
+
+ @Override
+ public DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+ final FixedWidthReader reader = createReader();
+ try {
+ for (int i = 1; i <= _configuration.getColumnNameLineNumber(); i++) {
+ reader.readLine();
+ }
+ } catch (IllegalStateException e) {
+ FileHelper.safeClose(reader);
+ throw e;
+ }
+ if (maxRows > 0) {
+ return new FixedWidthDataSet(reader, columns, maxRows);
+ } else {
+ return new FixedWidthDataSet(reader, columns, null);
+ }
+ }
+
+ private FixedWidthReader createReader() {
+ final InputStream inputStream = _resource.read();
+ final Reader fileReader = FileHelper.getReader(inputStream, _configuration.getEncoding());
+ final FixedWidthReader reader;
+ if (_configuration.isConstantValueWidth()) {
+ reader = new FixedWidthReader(fileReader, _configuration.getFixedValueWidth(),
+ _configuration.isFailOnInconsistentLineWidth());
+ } else {
+ reader = new FixedWidthReader(fileReader, _configuration.getValueWidths(),
+ _configuration.isFailOnInconsistentLineWidth());
+ }
+ return reader;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataSet.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataSet.java b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataSet.java
new file mode 100644
index 0000000..3ac8047
--- /dev/null
+++ b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataSet.java
@@ -0,0 +1,115 @@
+/**
+ * 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.fixedwidth;
+
+import org.eobjects.metamodel.data.AbstractDataSet;
+import org.eobjects.metamodel.data.DefaultRow;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.util.FileHelper;
+
+/**
+ * DataSet implementation for fixed width values.
+ *
+ * @author Kasper Sørensen
+ */
+class FixedWidthDataSet extends AbstractDataSet {
+
+ private final FixedWidthReader _reader;
+ private volatile Integer _rowsRemaining;
+ private volatile Row _row;
+
+ public FixedWidthDataSet(FixedWidthReader reader, Column[] columns,
+ Integer maxRows) {
+ super(columns);
+ _reader = reader;
+ _rowsRemaining = maxRows;
+ }
+
+ @Override
+ public void close() {
+ FileHelper.safeClose(_reader);
+ _row = null;
+ _rowsRemaining = null;
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ // close is always safe to invoke
+ close();
+ }
+
+ @Override
+ public Row getRow() {
+ return _row;
+ }
+
+ @Override
+ public boolean next() {
+ if (_rowsRemaining != null && _rowsRemaining > 0) {
+ _rowsRemaining--;
+ return nextInternal();
+ } else if (_rowsRemaining == null) {
+ return nextInternal();
+ } else {
+ return false;
+ }
+ }
+
+ private boolean nextInternal() {
+ if (_reader == null) {
+ return false;
+ }
+
+ InconsistentValueWidthException exception;
+ String[] stringValues;
+ try {
+ stringValues = _reader.readLine();
+ exception = null;
+ } catch (InconsistentValueWidthException e) {
+ stringValues = e.getSourceResult();
+ exception = e;
+ }
+ if (stringValues == null) {
+ close();
+ return false;
+ }
+
+ final int size = getHeader().size();
+ Object[] rowValues = new Object[size];
+ for (int i = 0; i < size; i++) {
+ Column column = getHeader().getSelectItem(i).getColumn();
+ int columnNumber = column.getColumnNumber();
+ if (columnNumber < stringValues.length) {
+ rowValues[i] = stringValues[columnNumber];
+ } else {
+ // Ticket #125: Missing values should be enterpreted as
+ // null.
+ rowValues[i] = null;
+ }
+ }
+ _row = new DefaultRow(getHeader(), rowValues);
+
+ if (exception != null) {
+ throw new InconsistentValueWidthException(_row, exception);
+ }
+ return true;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthReader.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthReader.java b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthReader.java
new file mode 100644
index 0000000..ca0aa6f
--- /dev/null
+++ b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthReader.java
@@ -0,0 +1,188 @@
+/**
+ * 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.fixedwidth;
+
+import java.io.BufferedReader;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.Reader;
+import java.text.CharacterIterator;
+import java.text.StringCharacterIterator;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Reader capable of separating values based on a fixed width setting.
+ *
+ * @author Kasper Sørensen
+ */
+final class FixedWidthReader implements Closeable {
+
+ private final BufferedReader _reader;
+ private final int _fixedValueWidth;
+ private final int[] _valueWidths;
+ private final boolean _failOnInconsistentLineWidth;
+ private final int expectedLineLength;
+ private final boolean constantWidth;
+ private volatile int _rowNumber;
+
+ public FixedWidthReader(Reader reader, int fixedValueWidth,
+ boolean failOnInconsistentLineWidth) {
+ this(new BufferedReader(reader), fixedValueWidth,
+ failOnInconsistentLineWidth);
+ }
+
+ public FixedWidthReader(BufferedReader reader, int fixedValueWidth,
+ boolean failOnInconsistentLineWidth) {
+ _reader = reader;
+ _fixedValueWidth = fixedValueWidth;
+ _failOnInconsistentLineWidth = failOnInconsistentLineWidth;
+ _rowNumber = 0;
+ _valueWidths = null;
+
+ constantWidth = true;
+ expectedLineLength = -1;
+ }
+
+ public FixedWidthReader(Reader reader, int[] valueWidths,
+ boolean failOnInconsistentLineWidth) {
+ this(new BufferedReader(reader), valueWidths,
+ failOnInconsistentLineWidth);
+ }
+
+ public FixedWidthReader(BufferedReader reader, int[] valueWidths,
+ boolean failOnInconsistentLineWidth) {
+ _reader = reader;
+ _fixedValueWidth = -1;
+ _valueWidths = valueWidths;
+ _failOnInconsistentLineWidth = failOnInconsistentLineWidth;
+ _rowNumber = 0;
+
+ constantWidth = false;
+ int expectedLineLength = 0;
+ if (_fixedValueWidth == -1) {
+ for (int i = 0; i < _valueWidths.length; i++) {
+ expectedLineLength += _valueWidths[i];
+ }
+ }
+ this.expectedLineLength = expectedLineLength;
+ }
+
+ /***
+ * Reads the next line in the file.
+ *
+ * @return an array of values in the next line, or null if the end of the
+ * file has been reached.
+ *
+ * @throws IllegalStateException
+ * if an exception occurs while reading the file.
+ */
+ public String[] readLine() throws IllegalStateException {
+
+ try {
+ final List<String> values = new ArrayList<String>();
+ final String line = _reader.readLine();
+ if (line == null) {
+ return null;
+ }
+
+ StringBuilder nextValue = new StringBuilder();
+
+ int valueIndex = 0;
+
+ final CharacterIterator it = new StringCharacterIterator(line);
+ for (char c = it.first(); c != CharacterIterator.DONE; c = it
+ .next()) {
+ nextValue.append(c);
+
+ final int valueWidth;
+ if (constantWidth) {
+ valueWidth = _fixedValueWidth;
+ } else {
+ if (valueIndex >= _valueWidths.length) {
+ if (_failOnInconsistentLineWidth) {
+ String[] result = values.toArray(new String[values
+ .size()]);
+ throw new InconsistentValueWidthException(result,
+ line, _rowNumber + 1);
+ } else {
+ // silently ignore the inconsistency
+ break;
+ }
+ }
+ valueWidth = _valueWidths[valueIndex];
+ }
+
+ if (nextValue.length() == valueWidth) {
+ // write the value
+ values.add(nextValue.toString().trim());
+ nextValue = new StringBuilder();
+ valueIndex++;
+ }
+ }
+
+ if (nextValue.length() > 0) {
+ values.add(nextValue.toString().trim());
+ }
+
+ String[] result = values.toArray(new String[values.size()]);
+
+ if (!_failOnInconsistentLineWidth && !constantWidth) {
+ if (result.length != _valueWidths.length) {
+ String[] correctedResult = new String[_valueWidths.length];
+ for (int i = 0; i < result.length
+ && i < _valueWidths.length; i++) {
+ correctedResult[i] = result[i];
+ }
+ result = correctedResult;
+ }
+ }
+
+ if (_failOnInconsistentLineWidth) {
+ _rowNumber++;
+ if (constantWidth) {
+ if (line.length() % _fixedValueWidth != 0) {
+ throw new InconsistentValueWidthException(result, line,
+ _rowNumber);
+ }
+ } else {
+ if (result.length != values.size()) {
+ throw new InconsistentValueWidthException(result, line,
+ _rowNumber);
+ }
+
+ if (line.length() != expectedLineLength) {
+ throw new InconsistentValueWidthException(result, line,
+ _rowNumber);
+ }
+ }
+ }
+
+ return result;
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ _reader.close();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/InconsistentValueWidthException.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/InconsistentValueWidthException.java b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/InconsistentValueWidthException.java
new file mode 100644
index 0000000..2fa3573
--- /dev/null
+++ b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/InconsistentValueWidthException.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.fixedwidth;
+
+import org.eobjects.metamodel.InconsistentRowFormatException;
+import org.eobjects.metamodel.data.Row;
+
+/**
+ * Exception thrown when inconsistent widths of a Fixed Width Value file
+ *
+ * @author Kasper Sørensen
+ */
+public final class InconsistentValueWidthException extends
+ InconsistentRowFormatException {
+
+ private static final long serialVersionUID = 1L;
+ private final String[] _sourceResult;
+ private final String _sourceLine;
+
+ public InconsistentValueWidthException(String[] result, String line,
+ int rowNumber) {
+ super(null, rowNumber);
+ _sourceResult = result;
+ _sourceLine = line;
+ }
+
+ public InconsistentValueWidthException(Row proposedRow,
+ InconsistentValueWidthException cause) {
+ super(proposedRow, cause.getRowNumber(), cause);
+ _sourceResult = cause.getSourceResult();
+ _sourceLine = cause.getSourceLine();
+ }
+
+ /**
+ * Gets the source line as represented in the Fixed Width file
+ *
+ * @return the source line as a string
+ */
+ public String getSourceLine() {
+ return _sourceLine;
+ }
+
+ /**
+ * Gets the parsed result as read by the Fixed Width reader.
+ *
+ * @return the gracefully parsed line
+ */
+ public String[] getSourceResult() {
+ return _sourceResult;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/package-info.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/package-info.java b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/package-info.java
new file mode 100644
index 0000000..9702557
--- /dev/null
+++ b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/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.
+ */
+/**
+ * Module package for Fixed width value files
+ */
+package org.eobjects.metamodel.fixedwidth;
+
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/FixedWidthConfiguration.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/FixedWidthConfiguration.java b/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/FixedWidthConfiguration.java
deleted file mode 100644
index a5236a9..0000000
--- a/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/FixedWidthConfiguration.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/**
- * 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.fixedwidth;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.util.BaseObject;
-import org.eobjects.metamodel.util.FileHelper;
-
-/**
- * Configuration of metadata about a fixed width values datacontext.
- *
- * @author Kasper Sørensen
- */
-public final class FixedWidthConfiguration extends BaseObject implements
- Serializable {
-
- private static final long serialVersionUID = 1L;
-
- public static final int NO_COLUMN_NAME_LINE = 0;
- public static final int DEFAULT_COLUMN_NAME_LINE = 1;
-
- private final String encoding;
- private final int fixedValueWidth;
- private final int[] valueWidths;
- private final int columnNameLineNumber;
- private final boolean failOnInconsistentLineWidth;
-
- public FixedWidthConfiguration(int fixedValueWidth) {
- this(DEFAULT_COLUMN_NAME_LINE, FileHelper.DEFAULT_ENCODING,
- fixedValueWidth);
- }
-
- public FixedWidthConfiguration(int[] valueWidth) {
- this(DEFAULT_COLUMN_NAME_LINE, FileHelper.DEFAULT_ENCODING, valueWidth,
- false);
- }
-
- public FixedWidthConfiguration(int columnNameLineNumber, String encoding,
- int fixedValueWidth) {
- this(columnNameLineNumber, encoding, fixedValueWidth, false);
- }
-
- public FixedWidthConfiguration(int columnNameLineNumber, String encoding,
- int fixedValueWidth, boolean failOnInconsistentLineWidth) {
- this.encoding = encoding;
- this.fixedValueWidth = fixedValueWidth;
- this.columnNameLineNumber = columnNameLineNumber;
- this.failOnInconsistentLineWidth = failOnInconsistentLineWidth;
- this.valueWidths = new int[0];
- }
-
- public FixedWidthConfiguration(int columnNameLineNumber, String encoding,
- int[] valueWidths, boolean failOnInconsistentLineWidth) {
- this.encoding = encoding;
- this.fixedValueWidth = -1;
- this.columnNameLineNumber = columnNameLineNumber;
- this.failOnInconsistentLineWidth = failOnInconsistentLineWidth;
- this.valueWidths = valueWidths;
- }
-
- /**
- * The line number (1 based) from which to get the names of the columns.
- *
- * @return an int representing the line number of the column headers/names.
- */
- public int getColumnNameLineNumber() {
- return columnNameLineNumber;
- }
-
- /**
- * Gets the file encoding to use for reading the file.
- *
- * @return the text encoding to use for reading the file.
- */
- public String getEncoding() {
- return encoding;
- }
-
- /**
- * Gets the width of each value within the fixed width value file.
- *
- * @return the fixed width to use when parsing the file.
- */
- public int getFixedValueWidth() {
- return fixedValueWidth;
- }
-
- public int[] getValueWidths() {
- return valueWidths;
- }
-
- /**
- * Determines if the {@link DataSet#next()} should throw an exception in
- * case of inconsistent line width in the fixed width value file.
- *
- * @return a boolean indicating whether or not to fail on inconsistent line
- * widths.
- */
- public boolean isFailOnInconsistentLineWidth() {
- return failOnInconsistentLineWidth;
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- identifiers.add(columnNameLineNumber);
- identifiers.add(encoding);
- identifiers.add(fixedValueWidth);
- identifiers.add(valueWidths);
- identifiers.add(failOnInconsistentLineWidth);
- }
-
- @Override
- public String toString() {
- return "FixedWidthConfiguration[encoding=" + encoding
- + ", fixedValueWidth=" + fixedValueWidth + ", valueWidths="
- + Arrays.toString(valueWidths) + ", columnNameLineNumber="
- + columnNameLineNumber + ", failOnInconsistentLineWidth="
- + failOnInconsistentLineWidth + "]";
- }
-
- public boolean isConstantValueWidth() {
- return fixedValueWidth != -1;
- }
-
- public int getValueWidth(int columnIndex) {
- if (isConstantValueWidth()) {
- return fixedValueWidth;
- }
- return valueWidths[columnIndex];
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/FixedWidthDataContext.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/FixedWidthDataContext.java b/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/FixedWidthDataContext.java
deleted file mode 100644
index 704b376..0000000
--- a/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/FixedWidthDataContext.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/**
- * 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.fixedwidth;
-
-import java.io.File;
-import java.io.InputStream;
-import java.io.Reader;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-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.Table;
-import org.eobjects.metamodel.schema.TableType;
-import org.eobjects.metamodel.util.AlphabeticSequence;
-import org.eobjects.metamodel.util.FileHelper;
-import org.eobjects.metamodel.util.FileResource;
-import org.eobjects.metamodel.util.Resource;
-
-/**
- * DataContext implementation for fixed width value files.
- *
- * @author Kasper Sørensen
- */
-public class FixedWidthDataContext extends QueryPostprocessDataContext {
-
- private final Resource _resource;
- private final FixedWidthConfiguration _configuration;
-
- /**
- * @deprecated use
- * {@link #FixedWidthDataContext(File, FixedWidthConfiguration)}
- * instead
- */
- @Deprecated
- public FixedWidthDataContext(String filename, String fileEncoding, int fixedValueWidth) {
- this(new FileResource(filename), new FixedWidthConfiguration(fixedValueWidth));
- }
-
- /**
- * @deprecated use
- * {@link #FixedWidthDataContext(File, FixedWidthConfiguration)}
- * instead
- */
- @Deprecated
- public FixedWidthDataContext(File file, String fileEncoding, int fixedValueWidth, int headerLineNumber) {
- this(file, new FixedWidthConfiguration(headerLineNumber, fileEncoding, fixedValueWidth));
- }
-
- public FixedWidthDataContext(File file, FixedWidthConfiguration configuration) {
- _resource = new FileResource(file);
- _configuration = configuration;
- }
-
- public FixedWidthDataContext(Resource resource, FixedWidthConfiguration configuration) {
- _resource = resource;
- _configuration = configuration;
- }
-
- /**
- * Gets the Fixed width value configuration used.
- *
- * @return a fixed width configuration
- */
- public FixedWidthConfiguration getConfiguration() {
- return _configuration;
- }
-
- /**
- * Gets the file being read.
- *
- * @return a file
- *
- * @deprecated use {@link #getResource()} instead.
- */
- @Deprecated
- public File getFile() {
- if (_resource instanceof FileResource) {
- return ((FileResource) _resource).getFile();
- }
- return null;
- }
-
- /**
- * Gets the resource being read
- *
- * @return
- */
- public Resource getResource() {
- return _resource;
- }
-
- @Override
- protected Schema getMainSchema() throws MetaModelException {
- final String schemaName = getDefaultSchemaName();
- final MutableSchema schema = new MutableSchema(schemaName);
- final String tableName = schemaName.substring(0, schemaName.length() - 4);
- final MutableTable table = new MutableTable(tableName, TableType.TABLE, schema);
- schema.addTable(table);
-
- final FixedWidthReader reader = createReader();
- final String[] columnNames;
- try {
- if (_configuration.getColumnNameLineNumber() != FixedWidthConfiguration.NO_COLUMN_NAME_LINE) {
- for (int i = 1; i < _configuration.getColumnNameLineNumber(); i++) {
- reader.readLine();
- }
- columnNames = reader.readLine();
- } else {
- columnNames = reader.readLine();
- if (columnNames != null) {
- AlphabeticSequence sequence = new AlphabeticSequence();
- for (int i = 0; i < columnNames.length; i++) {
- columnNames[i] = sequence.next();
- }
- }
- }
- } finally {
- FileHelper.safeClose(reader);
- }
-
- if (columnNames != null) {
- for (int i = 0; i < columnNames.length; i++) {
- final String columnName = columnNames[i];
- final MutableColumn column = new MutableColumn(columnName, ColumnType.VARCHAR, table, i, true);
- column.setColumnSize(_configuration.getValueWidth(i));
- table.addColumn(column);
- }
- }
-
- return schema;
- }
-
- @Override
- protected String getMainSchemaName() throws MetaModelException {
- return _resource.getName();
- }
-
- @Override
- public DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
- final FixedWidthReader reader = createReader();
- try {
- for (int i = 1; i <= _configuration.getColumnNameLineNumber(); i++) {
- reader.readLine();
- }
- } catch (IllegalStateException e) {
- FileHelper.safeClose(reader);
- throw e;
- }
- if (maxRows > 0) {
- return new FixedWidthDataSet(reader, columns, maxRows);
- } else {
- return new FixedWidthDataSet(reader, columns, null);
- }
- }
-
- private FixedWidthReader createReader() {
- final InputStream inputStream = _resource.read();
- final Reader fileReader = FileHelper.getReader(inputStream, _configuration.getEncoding());
- final FixedWidthReader reader;
- if (_configuration.isConstantValueWidth()) {
- reader = new FixedWidthReader(fileReader, _configuration.getFixedValueWidth(),
- _configuration.isFailOnInconsistentLineWidth());
- } else {
- reader = new FixedWidthReader(fileReader, _configuration.getValueWidths(),
- _configuration.isFailOnInconsistentLineWidth());
- }
- return reader;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/FixedWidthDataSet.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/FixedWidthDataSet.java b/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/FixedWidthDataSet.java
deleted file mode 100644
index 3ac8047..0000000
--- a/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/FixedWidthDataSet.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/**
- * 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.fixedwidth;
-
-import org.eobjects.metamodel.data.AbstractDataSet;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.util.FileHelper;
-
-/**
- * DataSet implementation for fixed width values.
- *
- * @author Kasper Sørensen
- */
-class FixedWidthDataSet extends AbstractDataSet {
-
- private final FixedWidthReader _reader;
- private volatile Integer _rowsRemaining;
- private volatile Row _row;
-
- public FixedWidthDataSet(FixedWidthReader reader, Column[] columns,
- Integer maxRows) {
- super(columns);
- _reader = reader;
- _rowsRemaining = maxRows;
- }
-
- @Override
- public void close() {
- FileHelper.safeClose(_reader);
- _row = null;
- _rowsRemaining = null;
- }
-
- @Override
- protected void finalize() throws Throwable {
- super.finalize();
- // close is always safe to invoke
- close();
- }
-
- @Override
- public Row getRow() {
- return _row;
- }
-
- @Override
- public boolean next() {
- if (_rowsRemaining != null && _rowsRemaining > 0) {
- _rowsRemaining--;
- return nextInternal();
- } else if (_rowsRemaining == null) {
- return nextInternal();
- } else {
- return false;
- }
- }
-
- private boolean nextInternal() {
- if (_reader == null) {
- return false;
- }
-
- InconsistentValueWidthException exception;
- String[] stringValues;
- try {
- stringValues = _reader.readLine();
- exception = null;
- } catch (InconsistentValueWidthException e) {
- stringValues = e.getSourceResult();
- exception = e;
- }
- if (stringValues == null) {
- close();
- return false;
- }
-
- final int size = getHeader().size();
- Object[] rowValues = new Object[size];
- for (int i = 0; i < size; i++) {
- Column column = getHeader().getSelectItem(i).getColumn();
- int columnNumber = column.getColumnNumber();
- if (columnNumber < stringValues.length) {
- rowValues[i] = stringValues[columnNumber];
- } else {
- // Ticket #125: Missing values should be enterpreted as
- // null.
- rowValues[i] = null;
- }
- }
- _row = new DefaultRow(getHeader(), rowValues);
-
- if (exception != null) {
- throw new InconsistentValueWidthException(_row, exception);
- }
- return true;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/FixedWidthReader.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/FixedWidthReader.java b/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/FixedWidthReader.java
deleted file mode 100644
index ca0aa6f..0000000
--- a/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/FixedWidthReader.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/**
- * 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.fixedwidth;
-
-import java.io.BufferedReader;
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.Reader;
-import java.text.CharacterIterator;
-import java.text.StringCharacterIterator;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Reader capable of separating values based on a fixed width setting.
- *
- * @author Kasper Sørensen
- */
-final class FixedWidthReader implements Closeable {
-
- private final BufferedReader _reader;
- private final int _fixedValueWidth;
- private final int[] _valueWidths;
- private final boolean _failOnInconsistentLineWidth;
- private final int expectedLineLength;
- private final boolean constantWidth;
- private volatile int _rowNumber;
-
- public FixedWidthReader(Reader reader, int fixedValueWidth,
- boolean failOnInconsistentLineWidth) {
- this(new BufferedReader(reader), fixedValueWidth,
- failOnInconsistentLineWidth);
- }
-
- public FixedWidthReader(BufferedReader reader, int fixedValueWidth,
- boolean failOnInconsistentLineWidth) {
- _reader = reader;
- _fixedValueWidth = fixedValueWidth;
- _failOnInconsistentLineWidth = failOnInconsistentLineWidth;
- _rowNumber = 0;
- _valueWidths = null;
-
- constantWidth = true;
- expectedLineLength = -1;
- }
-
- public FixedWidthReader(Reader reader, int[] valueWidths,
- boolean failOnInconsistentLineWidth) {
- this(new BufferedReader(reader), valueWidths,
- failOnInconsistentLineWidth);
- }
-
- public FixedWidthReader(BufferedReader reader, int[] valueWidths,
- boolean failOnInconsistentLineWidth) {
- _reader = reader;
- _fixedValueWidth = -1;
- _valueWidths = valueWidths;
- _failOnInconsistentLineWidth = failOnInconsistentLineWidth;
- _rowNumber = 0;
-
- constantWidth = false;
- int expectedLineLength = 0;
- if (_fixedValueWidth == -1) {
- for (int i = 0; i < _valueWidths.length; i++) {
- expectedLineLength += _valueWidths[i];
- }
- }
- this.expectedLineLength = expectedLineLength;
- }
-
- /***
- * Reads the next line in the file.
- *
- * @return an array of values in the next line, or null if the end of the
- * file has been reached.
- *
- * @throws IllegalStateException
- * if an exception occurs while reading the file.
- */
- public String[] readLine() throws IllegalStateException {
-
- try {
- final List<String> values = new ArrayList<String>();
- final String line = _reader.readLine();
- if (line == null) {
- return null;
- }
-
- StringBuilder nextValue = new StringBuilder();
-
- int valueIndex = 0;
-
- final CharacterIterator it = new StringCharacterIterator(line);
- for (char c = it.first(); c != CharacterIterator.DONE; c = it
- .next()) {
- nextValue.append(c);
-
- final int valueWidth;
- if (constantWidth) {
- valueWidth = _fixedValueWidth;
- } else {
- if (valueIndex >= _valueWidths.length) {
- if (_failOnInconsistentLineWidth) {
- String[] result = values.toArray(new String[values
- .size()]);
- throw new InconsistentValueWidthException(result,
- line, _rowNumber + 1);
- } else {
- // silently ignore the inconsistency
- break;
- }
- }
- valueWidth = _valueWidths[valueIndex];
- }
-
- if (nextValue.length() == valueWidth) {
- // write the value
- values.add(nextValue.toString().trim());
- nextValue = new StringBuilder();
- valueIndex++;
- }
- }
-
- if (nextValue.length() > 0) {
- values.add(nextValue.toString().trim());
- }
-
- String[] result = values.toArray(new String[values.size()]);
-
- if (!_failOnInconsistentLineWidth && !constantWidth) {
- if (result.length != _valueWidths.length) {
- String[] correctedResult = new String[_valueWidths.length];
- for (int i = 0; i < result.length
- && i < _valueWidths.length; i++) {
- correctedResult[i] = result[i];
- }
- result = correctedResult;
- }
- }
-
- if (_failOnInconsistentLineWidth) {
- _rowNumber++;
- if (constantWidth) {
- if (line.length() % _fixedValueWidth != 0) {
- throw new InconsistentValueWidthException(result, line,
- _rowNumber);
- }
- } else {
- if (result.length != values.size()) {
- throw new InconsistentValueWidthException(result, line,
- _rowNumber);
- }
-
- if (line.length() != expectedLineLength) {
- throw new InconsistentValueWidthException(result, line,
- _rowNumber);
- }
- }
- }
-
- return result;
- } catch (IOException e) {
- throw new IllegalStateException(e);
- }
- }
-
- @Override
- public void close() throws IOException {
- _reader.close();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/InconsistentValueWidthException.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/InconsistentValueWidthException.java b/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/InconsistentValueWidthException.java
deleted file mode 100644
index 46b021a..0000000
--- a/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/InconsistentValueWidthException.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * 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.fixedwidth;
-
-import org.eobjects.metamodel.InconsistentRowFormatException;
-import org.eobjects.metamodel.data.Row;
-
-/**
- * Exception thrown when inconsistent widths of a Fixed Width Value file
- *
- * @author Kasper Sørensen
- */
-public final class InconsistentValueWidthException extends
- InconsistentRowFormatException {
-
- private static final long serialVersionUID = 1L;
- private final String[] _sourceResult;
- private final String _sourceLine;
-
- public InconsistentValueWidthException(String[] result, String line,
- int rowNumber) {
- super(null, rowNumber);
- _sourceResult = result;
- _sourceLine = line;
- }
-
- public InconsistentValueWidthException(Row proposedRow,
- InconsistentValueWidthException cause) {
- super(proposedRow, cause.getRowNumber(), cause);
- _sourceResult = cause.getSourceResult();
- _sourceLine = cause.getSourceLine();
- }
-
- /**
- * Gets the source line as represented in the Fixed Width file
- *
- * @return the source line as a string
- */
- public String getSourceLine() {
- return _sourceLine;
- }
-
- /**
- * Gets the parsed result as read by the Fixed Width reader.
- *
- * @return the gracefully parsed line
- */
- public String[] getSourceResult() {
- return _sourceResult;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/package-info.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/package-info.java b/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/package-info.java
deleted file mode 100644
index eaeb00b..0000000
--- a/fixedwidth/src/main/java/org/eobjects/metamodel/fixedwidth/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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.
- */
-/**
- * Module package for Fixed width value files
- */
-package org.eobjects.metamodel.fixedwidth;
-
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthConfigurationTest.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthConfigurationTest.java b/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthConfigurationTest.java
new file mode 100644
index 0000000..ff9cb12
--- /dev/null
+++ b/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthConfigurationTest.java
@@ -0,0 +1,44 @@
+/**
+ * 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.fixedwidth;
+
+import org.eobjects.metamodel.fixedwidth.FixedWidthConfiguration;
+
+import junit.framework.TestCase;
+
+public class FixedWidthConfigurationTest extends TestCase {
+
+ public void testToString() throws Exception {
+ assertEquals(
+ "FixedWidthConfiguration[encoding=UTF8, fixedValueWidth=10, valueWidths=[], columnNameLineNumber=1, failOnInconsistentLineWidth=true]",
+ new FixedWidthConfiguration(1, "UTF8", 10, true).toString());
+ }
+
+ public void testEquals() throws Exception {
+ FixedWidthConfiguration conf1 = new FixedWidthConfiguration(1, "UTF8",
+ 10, true);
+ FixedWidthConfiguration conf2 = new FixedWidthConfiguration(1, "UTF8",
+ 10, true);
+ assertEquals(conf1, conf2);
+
+ FixedWidthConfiguration conf3 = new FixedWidthConfiguration(1, "UTF8",
+ 10, false);
+ assertFalse(conf1.equals(conf3));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthDataContextTest.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthDataContextTest.java b/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthDataContextTest.java
new file mode 100644
index 0000000..cf95c84
--- /dev/null
+++ b/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthDataContextTest.java
@@ -0,0 +1,227 @@
+/**
+ * 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.fixedwidth;
+
+import java.io.File;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.fixedwidth.FixedWidthConfiguration;
+import org.eobjects.metamodel.fixedwidth.FixedWidthDataContext;
+import org.eobjects.metamodel.fixedwidth.InconsistentValueWidthException;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+public class FixedWidthDataContextTest extends TestCase {
+
+ public void testEmptyFile() throws Exception {
+ DataContext dc = new FixedWidthDataContext(new File("src/test/resources/empty_file.txt"),
+ new FixedWidthConfiguration(10));
+ assertEquals(1, dc.getDefaultSchema().getTableCount());
+
+ Table table = dc.getDefaultSchema().getTables()[0];
+ assertEquals("empty_file", table.getName());
+ assertEquals(0, table.getColumnCount());
+ }
+
+ public void testEmptyFileNoHeaderLine() throws Exception {
+ DataContext dc = new FixedWidthDataContext(new File("src/test/resources/empty_file.txt"),
+ new FixedWidthConfiguration(FixedWidthConfiguration.NO_COLUMN_NAME_LINE, "UTF8", 10));
+ assertEquals(1, dc.getDefaultSchema().getTableCount());
+
+ Table table = dc.getDefaultSchema().getTables()[0];
+ assertEquals("empty_file", table.getName());
+ assertEquals(0, table.getColumnCount());
+ }
+
+ public void testUnexistingHeaderLine() throws Exception {
+ DataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple1.txt"),
+ new FixedWidthConfiguration(20, "UTF8", 10));
+ assertEquals(1, dc.getDefaultSchema().getTableCount());
+
+ Table table = dc.getDefaultSchema().getTables()[0];
+ assertEquals("example_simple1", table.getName());
+ assertEquals(0, table.getColumnCount());
+ }
+
+ public void testExampleSimple1() throws Exception {
+ FixedWidthConfiguration conf = new FixedWidthConfiguration(10);
+ FixedWidthDataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple1.txt"), conf);
+
+ String[] schemaNames = dc.getSchemaNames();
+ assertEquals(2, schemaNames.length);
+ assertEquals("[information_schema, example_simple1.txt]", Arrays.toString(schemaNames));
+
+ Schema schema = dc.getDefaultSchema();
+ assertEquals("Schema[name=example_simple1.txt]", schema.toString());
+
+ assertEquals(1, schema.getTableCount());
+
+ Table table = schema.getTableByName("example_simple1");
+ assertEquals("Table[name=example_simple1,type=TABLE,remarks=null]", table.toString());
+
+ assertEquals("[greeting, greeter]", Arrays.toString(table.getColumnNames()));
+ assertEquals(10, table.getColumnByName("greeting").getColumnSize().intValue());
+ assertEquals(10, table.getColumnByName("greeter").getColumnSize().intValue());
+
+ Query q = dc.query().from(table).select(table.getColumns()).toQuery();
+ DataSet ds = dc.executeQuery(q);
+
+ assertTrue(ds.next());
+ assertEquals("[hello, world]", Arrays.toString(ds.getRow().getValues()));
+ assertTrue(ds.next());
+ assertEquals("[hi, there]", Arrays.toString(ds.getRow().getValues()));
+ assertTrue(ds.next());
+ assertEquals("[howdy, partner]", Arrays.toString(ds.getRow().getValues()));
+ assertFalse(ds.next());
+ }
+
+ public void testFailOnInconsistentWidth() throws Exception {
+ FixedWidthConfiguration conf = new FixedWidthConfiguration(FixedWidthConfiguration.NO_COLUMN_NAME_LINE, "UTF8",
+ 10, true);
+ FixedWidthDataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple1.txt"), conf);
+
+ String[] schemaNames = dc.getSchemaNames();
+ assertEquals(2, schemaNames.length);
+ assertEquals("[information_schema, example_simple1.txt]", Arrays.toString(schemaNames));
+
+ Schema schema = dc.getDefaultSchema();
+ assertEquals("Schema[name=example_simple1.txt]", schema.toString());
+
+ assertEquals(1, schema.getTableCount());
+
+ Table table = schema.getTableByName("example_simple1");
+ assertEquals("Table[name=example_simple1,type=TABLE,remarks=null]", table.toString());
+
+ assertEquals("[A, B]", Arrays.toString(table.getColumnNames()));
+
+ Query q = dc.query().from(table).select(table.getColumns()).toQuery();
+ DataSet ds = dc.executeQuery(q);
+
+ assertTrue(ds.next());
+ assertEquals("greeting", ds.getRow().getValue(0));
+ assertEquals("greeter", ds.getRow().getValue(1));
+
+ try {
+ ds.next();
+ fail("Exception expected");
+ } catch (InconsistentValueWidthException e) {
+ assertEquals("Inconsistent row format of row no. 2.", e.getMessage());
+ assertEquals("[hello, world]", Arrays.toString(e.getProposedRow().getValues()));
+ }
+ assertTrue(ds.next());
+ assertEquals("[hi, there]", Arrays.toString(ds.getRow().getValues()));
+ assertTrue(ds.next());
+ assertEquals("[howdy, partner]", Arrays.toString(ds.getRow().getValues()));
+ assertFalse(ds.next());
+ }
+
+ public void testVaryingValueLengthsCorrect() throws Exception {
+ DataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple2.txt"),
+ new FixedWidthConfiguration(new int[] { 1, 8, 7 }));
+ Table table = dc.getDefaultSchema().getTables()[0];
+ assertEquals("[i, greeting, greeter]", Arrays.toString(table.getColumnNames()));
+
+ assertEquals(1, table.getColumnByName("i").getColumnSize().intValue());
+ assertEquals(8, table.getColumnByName("greeting").getColumnSize().intValue());
+ assertEquals(7, table.getColumnByName("greeter").getColumnSize().intValue());
+
+ Query q = dc.query().from(table).select(table.getColumns()).toQuery();
+ DataSet ds = dc.executeQuery(q);
+
+ assertTrue(ds.next());
+ assertEquals("[1, hello, world]", Arrays.toString(ds.getRow().getValues()));
+ assertTrue(ds.next());
+ assertEquals("[2, hi, there]", Arrays.toString(ds.getRow().getValues()));
+ assertTrue(ds.next());
+ assertEquals("[3, howdy, partner]", Arrays.toString(ds.getRow().getValues()));
+ assertFalse(ds.next());
+ }
+
+ public void testVaryingValueLengthsTooShortLength() throws Exception {
+ DataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple2.txt"),
+ new FixedWidthConfiguration(0, "UTF8", new int[] { 1, 5, 7 }, true));
+ try {
+ dc.getDefaultSchema().getTables();
+ fail("Exception expected");
+ } catch (InconsistentValueWidthException e) {
+ assertEquals("Inconsistent row format of row no. 1.", e.getMessage());
+ assertEquals("igreetinggreeter", e.getSourceLine());
+ assertEquals("[i, greet, inggree]", Arrays.toString(e.getSourceResult()));
+ }
+ }
+
+ public void testVaryingValueLengthsTooShortLengthErrorTolerant() throws Exception {
+ DataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple2.txt"),
+ new FixedWidthConfiguration(FixedWidthConfiguration.DEFAULT_COLUMN_NAME_LINE, "UTF8", new int[] { 1, 5,
+ 7 }, false));
+
+ Table table = dc.getDefaultSchema().getTables()[0];
+ assertEquals("[i, greet, inggree]", Arrays.toString(table.getColumnNames()));
+
+ Query q = dc.query().from(table).select(table.getColumns()).toQuery();
+ DataSet ds = dc.executeQuery(q);
+
+ assertTrue(ds.next());
+ assertEquals("[1, hello, worl]", Arrays.toString(ds.getRow().getValues()));
+ assertTrue(ds.next());
+ assertEquals("[2, hi, ther]", Arrays.toString(ds.getRow().getValues()));
+ assertTrue(ds.next());
+ assertEquals("[3, howdy, part]", Arrays.toString(ds.getRow().getValues()));
+ assertFalse(ds.next());
+ }
+
+ public void testVaryingValueLengthsTooLongLength() throws Exception {
+ DataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple2.txt"),
+ new FixedWidthConfiguration(0, "UTF8", new int[] { 1, 8, 9 }, true));
+
+ try {
+ dc.getDefaultSchema().getTables();
+ fail("Exception expected");
+ } catch (InconsistentValueWidthException e) {
+ assertEquals("Inconsistent row format of row no. 1.", e.getMessage());
+ assertEquals("igreetinggreeter", e.getSourceLine());
+ assertEquals("[i, greeting, greeter]", Arrays.toString(e.getSourceResult()));
+ }
+ }
+
+ public void testVaryingValueLengthsTooLongLengthErrorTolerant() throws Exception {
+ DataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple2.txt"),
+ new FixedWidthConfiguration(FixedWidthConfiguration.DEFAULT_COLUMN_NAME_LINE, "UTF8", new int[] { 1, 8,
+ 9 }, false));
+
+ Table table = dc.getDefaultSchema().getTables()[0];
+ assertEquals("[i, greeting, greeter]", Arrays.toString(table.getColumnNames()));
+
+ Query q = dc.query().from(table).select(table.getColumns()).toQuery();
+ DataSet ds = dc.executeQuery(q);
+
+ assertTrue(ds.next());
+ assertEquals("[1, hello, world]", Arrays.toString(ds.getRow().getValues()));
+ assertTrue(ds.next());
+ assertEquals("[2, hi, there]", Arrays.toString(ds.getRow().getValues()));
+ assertTrue(ds.next());
+ assertEquals("[3, howdy, partner]", Arrays.toString(ds.getRow().getValues()));
+ assertFalse(ds.next());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/fixedwidth/src/test/java/org/eobjects/metamodel/fixedwidth/FixedWidthConfigurationTest.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/test/java/org/eobjects/metamodel/fixedwidth/FixedWidthConfigurationTest.java b/fixedwidth/src/test/java/org/eobjects/metamodel/fixedwidth/FixedWidthConfigurationTest.java
deleted file mode 100644
index 8cf6cd1..0000000
--- a/fixedwidth/src/test/java/org/eobjects/metamodel/fixedwidth/FixedWidthConfigurationTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * 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.fixedwidth;
-
-import org.eobjects.metamodel.fixedwidth.FixedWidthConfiguration;
-
-import junit.framework.TestCase;
-
-public class FixedWidthConfigurationTest extends TestCase {
-
- public void testToString() throws Exception {
- assertEquals(
- "FixedWidthConfiguration[encoding=UTF8, fixedValueWidth=10, valueWidths=[], columnNameLineNumber=1, failOnInconsistentLineWidth=true]",
- new FixedWidthConfiguration(1, "UTF8", 10, true).toString());
- }
-
- public void testEquals() throws Exception {
- FixedWidthConfiguration conf1 = new FixedWidthConfiguration(1, "UTF8",
- 10, true);
- FixedWidthConfiguration conf2 = new FixedWidthConfiguration(1, "UTF8",
- 10, true);
- assertEquals(conf1, conf2);
-
- FixedWidthConfiguration conf3 = new FixedWidthConfiguration(1, "UTF8",
- 10, false);
- assertFalse(conf1.equals(conf3));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/fixedwidth/src/test/java/org/eobjects/metamodel/fixedwidth/FixedWidthDataContextTest.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/test/java/org/eobjects/metamodel/fixedwidth/FixedWidthDataContextTest.java b/fixedwidth/src/test/java/org/eobjects/metamodel/fixedwidth/FixedWidthDataContextTest.java
deleted file mode 100644
index cf95c84..0000000
--- a/fixedwidth/src/test/java/org/eobjects/metamodel/fixedwidth/FixedWidthDataContextTest.java
+++ /dev/null
@@ -1,227 +0,0 @@
-/**
- * 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.fixedwidth;
-
-import java.io.File;
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.fixedwidth.FixedWidthConfiguration;
-import org.eobjects.metamodel.fixedwidth.FixedWidthDataContext;
-import org.eobjects.metamodel.fixedwidth.InconsistentValueWidthException;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-public class FixedWidthDataContextTest extends TestCase {
-
- public void testEmptyFile() throws Exception {
- DataContext dc = new FixedWidthDataContext(new File("src/test/resources/empty_file.txt"),
- new FixedWidthConfiguration(10));
- assertEquals(1, dc.getDefaultSchema().getTableCount());
-
- Table table = dc.getDefaultSchema().getTables()[0];
- assertEquals("empty_file", table.getName());
- assertEquals(0, table.getColumnCount());
- }
-
- public void testEmptyFileNoHeaderLine() throws Exception {
- DataContext dc = new FixedWidthDataContext(new File("src/test/resources/empty_file.txt"),
- new FixedWidthConfiguration(FixedWidthConfiguration.NO_COLUMN_NAME_LINE, "UTF8", 10));
- assertEquals(1, dc.getDefaultSchema().getTableCount());
-
- Table table = dc.getDefaultSchema().getTables()[0];
- assertEquals("empty_file", table.getName());
- assertEquals(0, table.getColumnCount());
- }
-
- public void testUnexistingHeaderLine() throws Exception {
- DataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple1.txt"),
- new FixedWidthConfiguration(20, "UTF8", 10));
- assertEquals(1, dc.getDefaultSchema().getTableCount());
-
- Table table = dc.getDefaultSchema().getTables()[0];
- assertEquals("example_simple1", table.getName());
- assertEquals(0, table.getColumnCount());
- }
-
- public void testExampleSimple1() throws Exception {
- FixedWidthConfiguration conf = new FixedWidthConfiguration(10);
- FixedWidthDataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple1.txt"), conf);
-
- String[] schemaNames = dc.getSchemaNames();
- assertEquals(2, schemaNames.length);
- assertEquals("[information_schema, example_simple1.txt]", Arrays.toString(schemaNames));
-
- Schema schema = dc.getDefaultSchema();
- assertEquals("Schema[name=example_simple1.txt]", schema.toString());
-
- assertEquals(1, schema.getTableCount());
-
- Table table = schema.getTableByName("example_simple1");
- assertEquals("Table[name=example_simple1,type=TABLE,remarks=null]", table.toString());
-
- assertEquals("[greeting, greeter]", Arrays.toString(table.getColumnNames()));
- assertEquals(10, table.getColumnByName("greeting").getColumnSize().intValue());
- assertEquals(10, table.getColumnByName("greeter").getColumnSize().intValue());
-
- Query q = dc.query().from(table).select(table.getColumns()).toQuery();
- DataSet ds = dc.executeQuery(q);
-
- assertTrue(ds.next());
- assertEquals("[hello, world]", Arrays.toString(ds.getRow().getValues()));
- assertTrue(ds.next());
- assertEquals("[hi, there]", Arrays.toString(ds.getRow().getValues()));
- assertTrue(ds.next());
- assertEquals("[howdy, partner]", Arrays.toString(ds.getRow().getValues()));
- assertFalse(ds.next());
- }
-
- public void testFailOnInconsistentWidth() throws Exception {
- FixedWidthConfiguration conf = new FixedWidthConfiguration(FixedWidthConfiguration.NO_COLUMN_NAME_LINE, "UTF8",
- 10, true);
- FixedWidthDataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple1.txt"), conf);
-
- String[] schemaNames = dc.getSchemaNames();
- assertEquals(2, schemaNames.length);
- assertEquals("[information_schema, example_simple1.txt]", Arrays.toString(schemaNames));
-
- Schema schema = dc.getDefaultSchema();
- assertEquals("Schema[name=example_simple1.txt]", schema.toString());
-
- assertEquals(1, schema.getTableCount());
-
- Table table = schema.getTableByName("example_simple1");
- assertEquals("Table[name=example_simple1,type=TABLE,remarks=null]", table.toString());
-
- assertEquals("[A, B]", Arrays.toString(table.getColumnNames()));
-
- Query q = dc.query().from(table).select(table.getColumns()).toQuery();
- DataSet ds = dc.executeQuery(q);
-
- assertTrue(ds.next());
- assertEquals("greeting", ds.getRow().getValue(0));
- assertEquals("greeter", ds.getRow().getValue(1));
-
- try {
- ds.next();
- fail("Exception expected");
- } catch (InconsistentValueWidthException e) {
- assertEquals("Inconsistent row format of row no. 2.", e.getMessage());
- assertEquals("[hello, world]", Arrays.toString(e.getProposedRow().getValues()));
- }
- assertTrue(ds.next());
- assertEquals("[hi, there]", Arrays.toString(ds.getRow().getValues()));
- assertTrue(ds.next());
- assertEquals("[howdy, partner]", Arrays.toString(ds.getRow().getValues()));
- assertFalse(ds.next());
- }
-
- public void testVaryingValueLengthsCorrect() throws Exception {
- DataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple2.txt"),
- new FixedWidthConfiguration(new int[] { 1, 8, 7 }));
- Table table = dc.getDefaultSchema().getTables()[0];
- assertEquals("[i, greeting, greeter]", Arrays.toString(table.getColumnNames()));
-
- assertEquals(1, table.getColumnByName("i").getColumnSize().intValue());
- assertEquals(8, table.getColumnByName("greeting").getColumnSize().intValue());
- assertEquals(7, table.getColumnByName("greeter").getColumnSize().intValue());
-
- Query q = dc.query().from(table).select(table.getColumns()).toQuery();
- DataSet ds = dc.executeQuery(q);
-
- assertTrue(ds.next());
- assertEquals("[1, hello, world]", Arrays.toString(ds.getRow().getValues()));
- assertTrue(ds.next());
- assertEquals("[2, hi, there]", Arrays.toString(ds.getRow().getValues()));
- assertTrue(ds.next());
- assertEquals("[3, howdy, partner]", Arrays.toString(ds.getRow().getValues()));
- assertFalse(ds.next());
- }
-
- public void testVaryingValueLengthsTooShortLength() throws Exception {
- DataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple2.txt"),
- new FixedWidthConfiguration(0, "UTF8", new int[] { 1, 5, 7 }, true));
- try {
- dc.getDefaultSchema().getTables();
- fail("Exception expected");
- } catch (InconsistentValueWidthException e) {
- assertEquals("Inconsistent row format of row no. 1.", e.getMessage());
- assertEquals("igreetinggreeter", e.getSourceLine());
- assertEquals("[i, greet, inggree]", Arrays.toString(e.getSourceResult()));
- }
- }
-
- public void testVaryingValueLengthsTooShortLengthErrorTolerant() throws Exception {
- DataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple2.txt"),
- new FixedWidthConfiguration(FixedWidthConfiguration.DEFAULT_COLUMN_NAME_LINE, "UTF8", new int[] { 1, 5,
- 7 }, false));
-
- Table table = dc.getDefaultSchema().getTables()[0];
- assertEquals("[i, greet, inggree]", Arrays.toString(table.getColumnNames()));
-
- Query q = dc.query().from(table).select(table.getColumns()).toQuery();
- DataSet ds = dc.executeQuery(q);
-
- assertTrue(ds.next());
- assertEquals("[1, hello, worl]", Arrays.toString(ds.getRow().getValues()));
- assertTrue(ds.next());
- assertEquals("[2, hi, ther]", Arrays.toString(ds.getRow().getValues()));
- assertTrue(ds.next());
- assertEquals("[3, howdy, part]", Arrays.toString(ds.getRow().getValues()));
- assertFalse(ds.next());
- }
-
- public void testVaryingValueLengthsTooLongLength() throws Exception {
- DataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple2.txt"),
- new FixedWidthConfiguration(0, "UTF8", new int[] { 1, 8, 9 }, true));
-
- try {
- dc.getDefaultSchema().getTables();
- fail("Exception expected");
- } catch (InconsistentValueWidthException e) {
- assertEquals("Inconsistent row format of row no. 1.", e.getMessage());
- assertEquals("igreetinggreeter", e.getSourceLine());
- assertEquals("[i, greeting, greeter]", Arrays.toString(e.getSourceResult()));
- }
- }
-
- public void testVaryingValueLengthsTooLongLengthErrorTolerant() throws Exception {
- DataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple2.txt"),
- new FixedWidthConfiguration(FixedWidthConfiguration.DEFAULT_COLUMN_NAME_LINE, "UTF8", new int[] { 1, 8,
- 9 }, false));
-
- Table table = dc.getDefaultSchema().getTables()[0];
- assertEquals("[i, greeting, greeter]", Arrays.toString(table.getColumnNames()));
-
- Query q = dc.query().from(table).select(table.getColumns()).toQuery();
- DataSet ds = dc.executeQuery(q);
-
- assertTrue(ds.next());
- assertEquals("[1, hello, world]", Arrays.toString(ds.getRow().getValues()));
- assertTrue(ds.next());
- assertEquals("[2, hi, there]", Arrays.toString(ds.getRow().getValues()));
- assertTrue(ds.next());
- assertEquals("[3, howdy, partner]", Arrays.toString(ds.getRow().getValues()));
- assertFalse(ds.next());
- }
-}
[56/61] Renamed all import and package statements from 'org.eobjects'
to 'org.apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/FalsePredicate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/FalsePredicate.java b/core/src/main/java/org/apache/metamodel/util/FalsePredicate.java
index 01be8eb..f1f4a8e 100644
--- a/core/src/main/java/org/apache/metamodel/util/FalsePredicate.java
+++ b/core/src/main/java/org/apache/metamodel/util/FalsePredicate.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.io.Serializable;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/FileHelper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/FileHelper.java b/core/src/main/java/org/apache/metamodel/util/FileHelper.java
index 229baeb..7c5ca5d 100644
--- a/core/src/main/java/org/apache/metamodel/util/FileHelper.java
+++ b/core/src/main/java/org/apache/metamodel/util/FileHelper.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/FileResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/FileResource.java b/core/src/main/java/org/apache/metamodel/util/FileResource.java
index bf17c8f..12fe80d 100644
--- a/core/src/main/java/org/apache/metamodel/util/FileResource.java
+++ b/core/src/main/java/org/apache/metamodel/util/FileResource.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.io.File;
import java.io.InputStream;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/FormatHelper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/FormatHelper.java b/core/src/main/java/org/apache/metamodel/util/FormatHelper.java
index 3b954dc..f087d10 100644
--- a/core/src/main/java/org/apache/metamodel/util/FormatHelper.java
+++ b/core/src/main/java/org/apache/metamodel/util/FormatHelper.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.text.DateFormat;
import java.text.DecimalFormat;
@@ -25,8 +25,8 @@ import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Date;
-import org.eobjects.metamodel.query.QueryParameter;
-import org.eobjects.metamodel.schema.ColumnType;
+import org.apache.metamodel.query.QueryParameter;
+import org.apache.metamodel.schema.ColumnType;
/**
* Helper class for formatting
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/Func.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/Func.java b/core/src/main/java/org/apache/metamodel/util/Func.java
index c576456..cac9c87 100644
--- a/core/src/main/java/org/apache/metamodel/util/Func.java
+++ b/core/src/main/java/org/apache/metamodel/util/Func.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
/**
* Represents an abstract function, which is an executable piece of
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/HasName.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/HasName.java b/core/src/main/java/org/apache/metamodel/util/HasName.java
index 647848f..ea94d0c 100644
--- a/core/src/main/java/org/apache/metamodel/util/HasName.java
+++ b/core/src/main/java/org/apache/metamodel/util/HasName.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
/**
* Represents anything with a (String based) name.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/HasNameMapper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/HasNameMapper.java b/core/src/main/java/org/apache/metamodel/util/HasNameMapper.java
index 3b22a32..9b23dc3 100644
--- a/core/src/main/java/org/apache/metamodel/util/HasNameMapper.java
+++ b/core/src/main/java/org/apache/metamodel/util/HasNameMapper.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.io.Serializable;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/ImmutableDate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/ImmutableDate.java b/core/src/main/java/org/apache/metamodel/util/ImmutableDate.java
index 4ed34a6..fe5991e 100644
--- a/core/src/main/java/org/apache/metamodel/util/ImmutableDate.java
+++ b/core/src/main/java/org/apache/metamodel/util/ImmutableDate.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.text.DateFormat;
import java.util.Date;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/ImmutableRef.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/ImmutableRef.java b/core/src/main/java/org/apache/metamodel/util/ImmutableRef.java
index e8653cf..5b97db9 100644
--- a/core/src/main/java/org/apache/metamodel/util/ImmutableRef.java
+++ b/core/src/main/java/org/apache/metamodel/util/ImmutableRef.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
/**
* Simple/hard implementation of the {@link Ref} interface.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/InMemoryResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/InMemoryResource.java b/core/src/main/java/org/apache/metamodel/util/InMemoryResource.java
index 3a8d138..64bf531 100644
--- a/core/src/main/java/org/apache/metamodel/util/InMemoryResource.java
+++ b/core/src/main/java/org/apache/metamodel/util/InMemoryResource.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/InclusionPredicate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/InclusionPredicate.java b/core/src/main/java/org/apache/metamodel/util/InclusionPredicate.java
index 03bc689..d8aab91 100644
--- a/core/src/main/java/org/apache/metamodel/util/InclusionPredicate.java
+++ b/core/src/main/java/org/apache/metamodel/util/InclusionPredicate.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.util.Collection;
import java.util.Collections;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/LazyRef.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/LazyRef.java b/core/src/main/java/org/apache/metamodel/util/LazyRef.java
index ab39c66..0fb8739 100644
--- a/core/src/main/java/org/apache/metamodel/util/LazyRef.java
+++ b/core/src/main/java/org/apache/metamodel/util/LazyRef.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicBoolean;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/Month.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/Month.java b/core/src/main/java/org/apache/metamodel/util/Month.java
index 3380e5f..eccb6cb 100644
--- a/core/src/main/java/org/apache/metamodel/util/Month.java
+++ b/core/src/main/java/org/apache/metamodel/util/Month.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.util.Calendar;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/MutableRef.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/MutableRef.java b/core/src/main/java/org/apache/metamodel/util/MutableRef.java
index 81f8ea6..41eb2fb 100644
--- a/core/src/main/java/org/apache/metamodel/util/MutableRef.java
+++ b/core/src/main/java/org/apache/metamodel/util/MutableRef.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
/**
* Represents a mutable reference to any object
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/NumberComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/NumberComparator.java b/core/src/main/java/org/apache/metamodel/util/NumberComparator.java
index 5a1ba02..4442c65 100644
--- a/core/src/main/java/org/apache/metamodel/util/NumberComparator.java
+++ b/core/src/main/java/org/apache/metamodel/util/NumberComparator.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.util.Comparator;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/ObjectComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/ObjectComparator.java b/core/src/main/java/org/apache/metamodel/util/ObjectComparator.java
index 9b15452..697cf46 100644
--- a/core/src/main/java/org/apache/metamodel/util/ObjectComparator.java
+++ b/core/src/main/java/org/apache/metamodel/util/ObjectComparator.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.util.Comparator;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/Predicate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/Predicate.java b/core/src/main/java/org/apache/metamodel/util/Predicate.java
index 4268c66..fa0b8c7 100644
--- a/core/src/main/java/org/apache/metamodel/util/Predicate.java
+++ b/core/src/main/java/org/apache/metamodel/util/Predicate.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
/**
* A predicate is a special type of {@link Func}, used typically for
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/Ref.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/Ref.java b/core/src/main/java/org/apache/metamodel/util/Ref.java
index 0e9985f..c9b0d1e 100644
--- a/core/src/main/java/org/apache/metamodel/util/Ref.java
+++ b/core/src/main/java/org/apache/metamodel/util/Ref.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
/**
* Represents an abstract reference. This interface enables use of both regular,
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/Resource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/Resource.java b/core/src/main/java/org/apache/metamodel/util/Resource.java
index 8da25d6..9b5ed53 100644
--- a/core/src/main/java/org/apache/metamodel/util/Resource.java
+++ b/core/src/main/java/org/apache/metamodel/util/Resource.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.io.InputStream;
import java.io.OutputStream;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/ResourceException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/ResourceException.java b/core/src/main/java/org/apache/metamodel/util/ResourceException.java
index 4f61677..09c966b 100644
--- a/core/src/main/java/org/apache/metamodel/util/ResourceException.java
+++ b/core/src/main/java/org/apache/metamodel/util/ResourceException.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
-import org.eobjects.metamodel.MetaModelException;
+import org.apache.metamodel.MetaModelException;
/**
* Exception type for errors that occur while dealing with {@link Resource}s.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/SerializableRef.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/SerializableRef.java b/core/src/main/java/org/apache/metamodel/util/SerializableRef.java
index 3ae688e..d3b56de 100644
--- a/core/src/main/java/org/apache/metamodel/util/SerializableRef.java
+++ b/core/src/main/java/org/apache/metamodel/util/SerializableRef.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.io.Serializable;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/SharedExecutorService.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/SharedExecutorService.java b/core/src/main/java/org/apache/metamodel/util/SharedExecutorService.java
index 37b5aa5..3fd19af 100644
--- a/core/src/main/java/org/apache/metamodel/util/SharedExecutorService.java
+++ b/core/src/main/java/org/apache/metamodel/util/SharedExecutorService.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/SimpleTableDef.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/SimpleTableDef.java b/core/src/main/java/org/apache/metamodel/util/SimpleTableDef.java
index 1739e95..be6c7e4 100644
--- a/core/src/main/java/org/apache/metamodel/util/SimpleTableDef.java
+++ b/core/src/main/java/org/apache/metamodel/util/SimpleTableDef.java
@@ -16,18 +16,18 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.io.Serializable;
import java.util.Arrays;
-import org.eobjects.metamodel.DataContext;
-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.Table;
-import org.eobjects.metamodel.schema.TableType;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.schema.TableType;
/**
* Represents a table definition to be used in scenarios where a
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/TimeComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/TimeComparator.java b/core/src/main/java/org/apache/metamodel/util/TimeComparator.java
index 5601deb..e7596a7 100644
--- a/core/src/main/java/org/apache/metamodel/util/TimeComparator.java
+++ b/core/src/main/java/org/apache/metamodel/util/TimeComparator.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.text.DateFormat;
import java.text.DateFormatSymbols;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/ToStringComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/ToStringComparator.java b/core/src/main/java/org/apache/metamodel/util/ToStringComparator.java
index cfca4c5..ed74f8b 100644
--- a/core/src/main/java/org/apache/metamodel/util/ToStringComparator.java
+++ b/core/src/main/java/org/apache/metamodel/util/ToStringComparator.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.util.Comparator;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/TruePredicate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/TruePredicate.java b/core/src/main/java/org/apache/metamodel/util/TruePredicate.java
index 5def8d3..f0d4745 100644
--- a/core/src/main/java/org/apache/metamodel/util/TruePredicate.java
+++ b/core/src/main/java/org/apache/metamodel/util/TruePredicate.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.io.Serializable;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/UnicodeWriter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/UnicodeWriter.java b/core/src/main/java/org/apache/metamodel/util/UnicodeWriter.java
index c95f381..4867b52 100644
--- a/core/src/main/java/org/apache/metamodel/util/UnicodeWriter.java
+++ b/core/src/main/java/org/apache/metamodel/util/UnicodeWriter.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.io.File;
import java.io.FileOutputStream;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/UrlResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/UrlResource.java b/core/src/main/java/org/apache/metamodel/util/UrlResource.java
index b195b95..7030854 100644
--- a/core/src/main/java/org/apache/metamodel/util/UrlResource.java
+++ b/core/src/main/java/org/apache/metamodel/util/UrlResource.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.io.InputStream;
import java.io.OutputStream;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/Weekday.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/Weekday.java b/core/src/main/java/org/apache/metamodel/util/Weekday.java
index d9ab224..f13e025 100644
--- a/core/src/main/java/org/apache/metamodel/util/Weekday.java
+++ b/core/src/main/java/org/apache/metamodel/util/Weekday.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.util.Calendar;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/WildcardPattern.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/WildcardPattern.java b/core/src/main/java/org/apache/metamodel/util/WildcardPattern.java
index 36f388a..648c2ca 100644
--- a/core/src/main/java/org/apache/metamodel/util/WildcardPattern.java
+++ b/core/src/main/java/org/apache/metamodel/util/WildcardPattern.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.io.Serializable;
import java.util.StringTokenizer;
-import org.eobjects.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FilterItem;
/**
* Represents a pattern with a wildcard character. These are typically used in
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/package-info.java b/core/src/main/java/org/apache/metamodel/util/package-info.java
index 0423170..58143e3 100644
--- a/core/src/main/java/org/apache/metamodel/util/package-info.java
+++ b/core/src/main/java/org/apache/metamodel/util/package-info.java
@@ -19,5 +19,5 @@
/**
* Utilities and convenient classes
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/AbstractDataContextTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/AbstractDataContextTest.java b/core/src/test/java/org/apache/metamodel/AbstractDataContextTest.java
index 4320a5b..8493a08 100644
--- a/core/src/test/java/org/apache/metamodel/AbstractDataContextTest.java
+++ b/core/src/test/java/org/apache/metamodel/AbstractDataContextTest.java
@@ -16,19 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.util.Arrays;
import junit.framework.TestCase;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-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.Table;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public class AbstractDataContextTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/CompositeDataContextTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/CompositeDataContextTest.java b/core/src/test/java/org/apache/metamodel/CompositeDataContextTest.java
index 0a2e0f7..61e0dcc 100644
--- a/core/src/test/java/org/apache/metamodel/CompositeDataContextTest.java
+++ b/core/src/test/java/org/apache/metamodel/CompositeDataContextTest.java
@@ -16,18 +16,18 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.util.Arrays;
import java.util.List;
import junit.framework.TestCase;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.CompositeSchema;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.CompositeSchema;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public class CompositeDataContextTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/MetaModelHelperTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/MetaModelHelperTest.java b/core/src/test/java/org/apache/metamodel/MetaModelHelperTest.java
index 50c1ad1..540aa95 100644
--- a/core/src/test/java/org/apache/metamodel/MetaModelHelperTest.java
+++ b/core/src/test/java/org/apache/metamodel/MetaModelHelperTest.java
@@ -16,33 +16,33 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetHeader;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.EmptyDataSet;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.SimpleDataSetHeader;
-import org.eobjects.metamodel.data.SubSelectionDataSet;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.JoinType;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.OrderByItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-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.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSetHeader;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.EmptyDataSet;
+import org.apache.metamodel.data.InMemoryDataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.data.SimpleDataSetHeader;
+import org.apache.metamodel.data.SubSelectionDataSet;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.JoinType;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.OrderByItem;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public class MetaModelHelperTest extends MetaModelTestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/MetaModelTestCase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/MetaModelTestCase.java b/core/src/test/java/org/apache/metamodel/MetaModelTestCase.java
index 6f3e5b1..3e1e5a9 100644
--- a/core/src/test/java/org/apache/metamodel/MetaModelTestCase.java
+++ b/core/src/test/java/org/apache/metamodel/MetaModelTestCase.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.io.File;
import java.util.ArrayList;
@@ -26,21 +26,21 @@ import java.util.List;
import junit.framework.TestCase;
import org.easymock.EasyMock;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.EmptyDataSet;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.SimpleDataSetHeader;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableRelationship;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.TableType;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.EmptyDataSet;
+import org.apache.metamodel.data.InMemoryDataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.data.SimpleDataSetHeader;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableRelationship;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.TableType;
/**
* Convenient super-class to use for unittesting
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/MockDataContext.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/MockDataContext.java b/core/src/test/java/org/apache/metamodel/MockDataContext.java
index 5d95034..d54a306 100644
--- a/core/src/test/java/org/apache/metamodel/MockDataContext.java
+++ b/core/src/test/java/org/apache/metamodel/MockDataContext.java
@@ -16,26 +16,26 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.util.ArrayList;
import java.util.List;
-import org.eobjects.metamodel.data.CachingDataSetHeader;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetHeader;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.EmptyDataSet;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-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.Table;
+import org.apache.metamodel.data.CachingDataSetHeader;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSetHeader;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.EmptyDataSet;
+import org.apache.metamodel.data.InMemoryDataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public class MockDataContext extends QueryPostprocessDataContext {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/MockUpdateableDataContext.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/MockUpdateableDataContext.java b/core/src/test/java/org/apache/metamodel/MockUpdateableDataContext.java
index f1b7f49..b006a7c 100644
--- a/core/src/test/java/org/apache/metamodel/MockUpdateableDataContext.java
+++ b/core/src/test/java/org/apache/metamodel/MockUpdateableDataContext.java
@@ -16,33 +16,33 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.data.CachingDataSetHeader;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.EmptyDataSet;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.delete.AbstractRowDeletionBuilder;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.AbstractRowInsertionBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-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.Table;
+import org.apache.metamodel.create.TableCreationBuilder;
+import org.apache.metamodel.data.CachingDataSetHeader;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.EmptyDataSet;
+import org.apache.metamodel.data.InMemoryDataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.delete.AbstractRowDeletionBuilder;
+import org.apache.metamodel.delete.RowDeletionBuilder;
+import org.apache.metamodel.drop.TableDropBuilder;
+import org.apache.metamodel.insert.AbstractRowInsertionBuilder;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public class MockUpdateableDataContext extends QueryPostprocessDataContext implements UpdateableDataContext {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/QueryPostprocessDataContextTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/QueryPostprocessDataContextTest.java b/core/src/test/java/org/apache/metamodel/QueryPostprocessDataContextTest.java
index 0562bc5..3933855 100644
--- a/core/src/test/java/org/apache/metamodel/QueryPostprocessDataContextTest.java
+++ b/core/src/test/java/org/apache/metamodel/QueryPostprocessDataContextTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.nio.channels.UnsupportedAddressTypeException;
import java.util.ArrayList;
@@ -25,28 +25,28 @@ import java.util.List;
import javax.swing.table.TableModel;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetTableModel;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.GroupByItem;
-import org.eobjects.metamodel.query.JoinType;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.OrderByItem;
-import org.eobjects.metamodel.query.QueryParameter;
-import org.eobjects.metamodel.query.OrderByItem.Direction;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSetTableModel;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.CompiledQuery;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.query.GroupByItem;
+import org.apache.metamodel.query.JoinType;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.OrderByItem;
+import org.apache.metamodel.query.QueryParameter;
+import org.apache.metamodel.query.OrderByItem.Direction;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Relationship;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public class QueryPostprocessDataContextTest extends MetaModelTestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/SchemaNameComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/SchemaNameComparatorTest.java b/core/src/test/java/org/apache/metamodel/SchemaNameComparatorTest.java
index f03ff11..ac0fc8b 100644
--- a/core/src/test/java/org/apache/metamodel/SchemaNameComparatorTest.java
+++ b/core/src/test/java/org/apache/metamodel/SchemaNameComparatorTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.util.Comparator;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/convert/ColumnTypeDetectorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/convert/ColumnTypeDetectorTest.java b/core/src/test/java/org/apache/metamodel/convert/ColumnTypeDetectorTest.java
index e36df03..3e26846 100644
--- a/core/src/test/java/org/apache/metamodel/convert/ColumnTypeDetectorTest.java
+++ b/core/src/test/java/org/apache/metamodel/convert/ColumnTypeDetectorTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/convert/ConvertedDataSetInterceptorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/convert/ConvertedDataSetInterceptorTest.java b/core/src/test/java/org/apache/metamodel/convert/ConvertedDataSetInterceptorTest.java
index 4e1b0db..04a5e45 100644
--- a/core/src/test/java/org/apache/metamodel/convert/ConvertedDataSetInterceptorTest.java
+++ b/core/src/test/java/org/apache/metamodel/convert/ConvertedDataSetInterceptorTest.java
@@ -16,21 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
import java.util.HashMap;
import java.util.Map;
import junit.framework.TestCase;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MockUpdateableDataContext;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MockUpdateableDataContext;
+import org.apache.metamodel.UpdateableDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.InMemoryDataSet;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
public class ConvertedDataSetInterceptorTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/convert/ConvertedRowInsertionInterceptorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/convert/ConvertedRowInsertionInterceptorTest.java b/core/src/test/java/org/apache/metamodel/convert/ConvertedRowInsertionInterceptorTest.java
index 9f4fbcb..0e10379 100644
--- a/core/src/test/java/org/apache/metamodel/convert/ConvertedRowInsertionInterceptorTest.java
+++ b/core/src/test/java/org/apache/metamodel/convert/ConvertedRowInsertionInterceptorTest.java
@@ -16,17 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
import java.util.List;
import junit.framework.TestCase;
-import org.eobjects.metamodel.MockUpdateableDataContext;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.MockUpdateableDataContext;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.UpdateableDataContext;
+import org.apache.metamodel.schema.Column;
public class ConvertedRowInsertionInterceptorTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/convert/ConvertersTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/convert/ConvertersTest.java b/core/src/test/java/org/apache/metamodel/convert/ConvertersTest.java
index 61e1495..c68dfd2 100644
--- a/core/src/test/java/org/apache/metamodel/convert/ConvertersTest.java
+++ b/core/src/test/java/org/apache/metamodel/convert/ConvertersTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
import java.util.Arrays;
import java.util.List;
@@ -24,14 +24,14 @@ import java.util.Map;
import junit.framework.TestCase;
-import org.eobjects.metamodel.MockUpdateableDataContext;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MockUpdateableDataContext;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.UpdateableDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
public class ConvertersTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/convert/StringToBooleanConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/convert/StringToBooleanConverterTest.java b/core/src/test/java/org/apache/metamodel/convert/StringToBooleanConverterTest.java
index 7f14f68..63c3cd9 100644
--- a/core/src/test/java/org/apache/metamodel/convert/StringToBooleanConverterTest.java
+++ b/core/src/test/java/org/apache/metamodel/convert/StringToBooleanConverterTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/convert/StringToDateConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/convert/StringToDateConverterTest.java b/core/src/test/java/org/apache/metamodel/convert/StringToDateConverterTest.java
index dc936f3..a3cfcf0 100644
--- a/core/src/test/java/org/apache/metamodel/convert/StringToDateConverterTest.java
+++ b/core/src/test/java/org/apache/metamodel/convert/StringToDateConverterTest.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
import java.text.DateFormat;
import java.util.Date;
import junit.framework.TestCase;
-import org.eobjects.metamodel.util.DateUtils;
-import org.eobjects.metamodel.util.Month;
+import org.apache.metamodel.util.DateUtils;
+import org.apache.metamodel.util.Month;
public class StringToDateConverterTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/convert/StringToDoubleConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/convert/StringToDoubleConverterTest.java b/core/src/test/java/org/apache/metamodel/convert/StringToDoubleConverterTest.java
index 854326e..f9502c7 100644
--- a/core/src/test/java/org/apache/metamodel/convert/StringToDoubleConverterTest.java
+++ b/core/src/test/java/org/apache/metamodel/convert/StringToDoubleConverterTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/convert/StringToIntegerConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/convert/StringToIntegerConverterTest.java b/core/src/test/java/org/apache/metamodel/convert/StringToIntegerConverterTest.java
index d077cf4..b1cfca4 100644
--- a/core/src/test/java/org/apache/metamodel/convert/StringToIntegerConverterTest.java
+++ b/core/src/test/java/org/apache/metamodel/convert/StringToIntegerConverterTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/create/AbstractCreateTableBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/create/AbstractCreateTableBuilderTest.java b/core/src/test/java/org/apache/metamodel/create/AbstractCreateTableBuilderTest.java
index b5a44aa..40815ce 100644
--- a/core/src/test/java/org/apache/metamodel/create/AbstractCreateTableBuilderTest.java
+++ b/core/src/test/java/org/apache/metamodel/create/AbstractCreateTableBuilderTest.java
@@ -16,19 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.create;
+package org.apache.metamodel.create;
import junit.framework.TestCase;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.schema.ColumnType;
-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.Table;
-import org.eobjects.metamodel.util.MutableRef;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.MutableRef;
public class AbstractCreateTableBuilderTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/create/SyntaxExamplesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/create/SyntaxExamplesTest.java b/core/src/test/java/org/apache/metamodel/create/SyntaxExamplesTest.java
index 264fd91..2261969 100644
--- a/core/src/test/java/org/apache/metamodel/create/SyntaxExamplesTest.java
+++ b/core/src/test/java/org/apache/metamodel/create/SyntaxExamplesTest.java
@@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.create;
+package org.apache.metamodel.create;
import junit.framework.TestCase;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public abstract class SyntaxExamplesTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/data/DataSetIteratorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/data/DataSetIteratorTest.java b/core/src/test/java/org/apache/metamodel/data/DataSetIteratorTest.java
index 96443d2..0a3a4c5 100644
--- a/core/src/test/java/org/apache/metamodel/data/DataSetIteratorTest.java
+++ b/core/src/test/java/org/apache/metamodel/data/DataSetIteratorTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import org.easymock.EasyMock;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/data/DataSetTableModelTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/data/DataSetTableModelTest.java b/core/src/test/java/org/apache/metamodel/data/DataSetTableModelTest.java
index b125f8f..6ab60eb 100644
--- a/core/src/test/java/org/apache/metamodel/data/DataSetTableModelTest.java
+++ b/core/src/test/java/org/apache/metamodel/data/DataSetTableModelTest.java
@@ -16,16 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import java.util.ArrayList;
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.MutableColumn;
+import org.apache.metamodel.MetaModelHelper;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.MutableColumn;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/data/DefaultRowTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/data/DefaultRowTest.java b/core/src/test/java/org/apache/metamodel/data/DefaultRowTest.java
index 7ab78c1..e19cc29 100644
--- a/core/src/test/java/org/apache/metamodel/data/DefaultRowTest.java
+++ b/core/src/test/java/org/apache/metamodel/data/DefaultRowTest.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.lang.reflect.Field;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.util.FileHelper;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.util.FileHelper;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/data/FirstRowDataSetTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/data/FirstRowDataSetTest.java b/core/src/test/java/org/apache/metamodel/data/FirstRowDataSetTest.java
index a733687..5528eb8 100644
--- a/core/src/test/java/org/apache/metamodel/data/FirstRowDataSetTest.java
+++ b/core/src/test/java/org/apache/metamodel/data/FirstRowDataSetTest.java
@@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import java.util.ArrayList;
import java.util.List;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.MutableColumn;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.MutableColumn;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/data/RowPublisherDataSetTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/data/RowPublisherDataSetTest.java b/core/src/test/java/org/apache/metamodel/data/RowPublisherDataSetTest.java
index 7e8b882..129141d 100644
--- a/core/src/test/java/org/apache/metamodel/data/RowPublisherDataSetTest.java
+++ b/core/src/test/java/org/apache/metamodel/data/RowPublisherDataSetTest.java
@@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import junit.framework.TestCase;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.util.Action;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.util.Action;
public class RowPublisherDataSetTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/data/RowTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/data/RowTest.java b/core/src/test/java/org/apache/metamodel/data/RowTest.java
index 4c8628e..daa846a 100644
--- a/core/src/test/java/org/apache/metamodel/data/RowTest.java
+++ b/core/src/test/java/org/apache/metamodel/data/RowTest.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
-import org.eobjects.metamodel.MetaModelTestCase;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelTestCase;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public class RowTest extends MetaModelTestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/data/StyleBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/data/StyleBuilderTest.java b/core/src/test/java/org/apache/metamodel/data/StyleBuilderTest.java
index 5ad7e41..29092ac 100644
--- a/core/src/test/java/org/apache/metamodel/data/StyleBuilderTest.java
+++ b/core/src/test/java/org/apache/metamodel/data/StyleBuilderTest.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
-import org.eobjects.metamodel.data.Style.Color;
+import org.apache.metamodel.data.Style.Color;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/delete/AbstractRowDeletionCallbackTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/delete/AbstractRowDeletionCallbackTest.java b/core/src/test/java/org/apache/metamodel/delete/AbstractRowDeletionCallbackTest.java
index d37c102..f0774f0 100644
--- a/core/src/test/java/org/apache/metamodel/delete/AbstractRowDeletionCallbackTest.java
+++ b/core/src/test/java/org/apache/metamodel/delete/AbstractRowDeletionCallbackTest.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.delete;
+package org.apache.metamodel.delete;
import junit.framework.TestCase;
-import org.eobjects.metamodel.MockUpdateableDataContext;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MockUpdateableDataContext;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.schema.Table;
public class AbstractRowDeletionCallbackTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/insert/AbstractInsertBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/insert/AbstractInsertBuilderTest.java b/core/src/test/java/org/apache/metamodel/insert/AbstractInsertBuilderTest.java
index 27249aa..cf22c04 100644
--- a/core/src/test/java/org/apache/metamodel/insert/AbstractInsertBuilderTest.java
+++ b/core/src/test/java/org/apache/metamodel/insert/AbstractInsertBuilderTest.java
@@ -16,18 +16,18 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.insert;
+package org.apache.metamodel.insert;
import java.util.Arrays;
import junit.framework.TestCase;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.util.MutableRef;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.util.MutableRef;
public class AbstractInsertBuilderTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/insert/SyntaxExamplesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/insert/SyntaxExamplesTest.java b/core/src/test/java/org/apache/metamodel/insert/SyntaxExamplesTest.java
index e2ebb50..94231d1 100644
--- a/core/src/test/java/org/apache/metamodel/insert/SyntaxExamplesTest.java
+++ b/core/src/test/java/org/apache/metamodel/insert/SyntaxExamplesTest.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.insert;
+package org.apache.metamodel.insert;
import junit.framework.TestCase;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateableDataContext;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
public abstract class SyntaxExamplesTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/intercept/InterceptableDataContextTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/intercept/InterceptableDataContextTest.java b/core/src/test/java/org/apache/metamodel/intercept/InterceptableDataContextTest.java
index 96fc5dc..e5ee2f1 100644
--- a/core/src/test/java/org/apache/metamodel/intercept/InterceptableDataContextTest.java
+++ b/core/src/test/java/org/apache/metamodel/intercept/InterceptableDataContextTest.java
@@ -16,20 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
import java.util.Arrays;
import junit.framework.TestCase;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MockUpdateableDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.MaxRowsDataSet;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MockUpdateableDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.MaxRowsDataSet;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public class InterceptableDataContextTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/intercept/InterceptorListTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/intercept/InterceptorListTest.java b/core/src/test/java/org/apache/metamodel/intercept/InterceptorListTest.java
index 04fcecd..87e6685 100644
--- a/core/src/test/java/org/apache/metamodel/intercept/InterceptorListTest.java
+++ b/core/src/test/java/org/apache/metamodel/intercept/InterceptorListTest.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MockUpdateableDataContext;
-import org.eobjects.metamodel.convert.ConvertedDataSetInterceptor;
-import org.eobjects.metamodel.data.DataSet;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MockUpdateableDataContext;
+import org.apache.metamodel.convert.ConvertedDataSetInterceptor;
+import org.apache.metamodel.data.DataSet;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/intercept/InterceptorsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/intercept/InterceptorsTest.java b/core/src/test/java/org/apache/metamodel/intercept/InterceptorsTest.java
index 2420370..885e2f6 100644
--- a/core/src/test/java/org/apache/metamodel/intercept/InterceptorsTest.java
+++ b/core/src/test/java/org/apache/metamodel/intercept/InterceptorsTest.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
-import org.eobjects.metamodel.MockUpdateableDataContext;
+import org.apache.metamodel.MockUpdateableDataContext;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/query/DefaultCompiledQueryTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/DefaultCompiledQueryTest.java b/core/src/test/java/org/apache/metamodel/query/DefaultCompiledQueryTest.java
index 7d85f5c..4f4b56e 100644
--- a/core/src/test/java/org/apache/metamodel/query/DefaultCompiledQueryTest.java
+++ b/core/src/test/java/org/apache/metamodel/query/DefaultCompiledQueryTest.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.TableType;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.TableType;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/query/FilterItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/FilterItemTest.java b/core/src/test/java/org/apache/metamodel/query/FilterItemTest.java
index 9ed783c..818424a 100644
--- a/core/src/test/java/org/apache/metamodel/query/FilterItemTest.java
+++ b/core/src/test/java/org/apache/metamodel/query/FilterItemTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
import java.util.ArrayList;
import java.util.Arrays;
@@ -25,24 +25,24 @@ import java.util.List;
import junit.framework.TestCase;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.data.CachingDataSetHeader;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetHeader;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.SimpleDataSetHeader;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-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.Table;
-import org.eobjects.metamodel.schema.TableType;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.QueryPostprocessDataContext;
+import org.apache.metamodel.data.CachingDataSetHeader;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSetHeader;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.InMemoryDataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.data.SimpleDataSetHeader;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.schema.TableType;
public class FilterItemTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/query/FromClauseTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/FromClauseTest.java b/core/src/test/java/org/apache/metamodel/query/FromClauseTest.java
index 074a3b4..2c99ddb 100644
--- a/core/src/test/java/org/apache/metamodel/query/FromClauseTest.java
+++ b/core/src/test/java/org/apache/metamodel/query/FromClauseTest.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
-import org.eobjects.metamodel.MetaModelTestCase;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelTestCase;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public class FromClauseTest extends MetaModelTestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/query/FromItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/FromItemTest.java b/core/src/test/java/org/apache/metamodel/query/FromItemTest.java
index fb4c09e..4967841 100644
--- a/core/src/test/java/org/apache/metamodel/query/FromItemTest.java
+++ b/core/src/test/java/org/apache/metamodel/query/FromItemTest.java
@@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
-import org.eobjects.metamodel.MetaModelTestCase;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelTestCase;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Relationship;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public class FromItemTest extends MetaModelTestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/query/FunctionTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/FunctionTypeTest.java b/core/src/test/java/org/apache/metamodel/query/FunctionTypeTest.java
index 1161550..124020a 100644
--- a/core/src/test/java/org/apache/metamodel/query/FunctionTypeTest.java
+++ b/core/src/test/java/org/apache/metamodel/query/FunctionTypeTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/query/GroupByItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/GroupByItemTest.java b/core/src/test/java/org/apache/metamodel/query/GroupByItemTest.java
index f21d650..82909f1 100644
--- a/core/src/test/java/org/apache/metamodel/query/GroupByItemTest.java
+++ b/core/src/test/java/org/apache/metamodel/query/GroupByItemTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/query/OperatorTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/OperatorTypeTest.java b/core/src/test/java/org/apache/metamodel/query/OperatorTypeTest.java
index 2efee46..1a3f1f1 100644
--- a/core/src/test/java/org/apache/metamodel/query/OperatorTypeTest.java
+++ b/core/src/test/java/org/apache/metamodel/query/OperatorTypeTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/query/OrderByItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/OrderByItemTest.java b/core/src/test/java/org/apache/metamodel/query/OrderByItemTest.java
index 7433177..a84f9ce 100644
--- a/core/src/test/java/org/apache/metamodel/query/OrderByItemTest.java
+++ b/core/src/test/java/org/apache/metamodel/query/OrderByItemTest.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
-import org.eobjects.metamodel.query.OrderByItem.Direction;
+import org.apache.metamodel.query.OrderByItem.Direction;
import junit.framework.TestCase;
public class OrderByItemTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/query/QueryTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/QueryTest.java b/core/src/test/java/org/apache/metamodel/query/QueryTest.java
index 92e43e5..dd12657 100644
--- a/core/src/test/java/org/apache/metamodel/query/QueryTest.java
+++ b/core/src/test/java/org/apache/metamodel/query/QueryTest.java
@@ -16,19 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
-
-import org.eobjects.metamodel.MetaModelTestCase;
-import org.eobjects.metamodel.query.OrderByItem.Direction;
-import org.eobjects.metamodel.query.builder.InitFromBuilderImpl;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-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.Table;
-import org.eobjects.metamodel.schema.TableType;
+package org.apache.metamodel.query;
+
+import org.apache.metamodel.MetaModelTestCase;
+import org.apache.metamodel.query.OrderByItem.Direction;
+import org.apache.metamodel.query.builder.InitFromBuilderImpl;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.schema.TableType;
public class QueryTest extends MetaModelTestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/query/SelectClauseTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/SelectClauseTest.java b/core/src/test/java/org/apache/metamodel/query/SelectClauseTest.java
index 3ef125b..c4b68c5 100644
--- a/core/src/test/java/org/apache/metamodel/query/SelectClauseTest.java
+++ b/core/src/test/java/org/apache/metamodel/query/SelectClauseTest.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Table;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/query/SelectItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/SelectItemTest.java b/core/src/test/java/org/apache/metamodel/query/SelectItemTest.java
index 5896d9a..57f3bcc 100644
--- a/core/src/test/java/org/apache/metamodel/query/SelectItemTest.java
+++ b/core/src/test/java/org/apache/metamodel/query/SelectItemTest.java
@@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
-import org.eobjects.metamodel.MetaModelTestCase;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelTestCase;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public class SelectItemTest extends MetaModelTestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/query/builder/GroupedQueryBuilderImplTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/builder/GroupedQueryBuilderImplTest.java b/core/src/test/java/org/apache/metamodel/query/builder/GroupedQueryBuilderImplTest.java
index 4b3b399..238889f 100644
--- a/core/src/test/java/org/apache/metamodel/query/builder/GroupedQueryBuilderImplTest.java
+++ b/core/src/test/java/org/apache/metamodel/query/builder/GroupedQueryBuilderImplTest.java
@@ -16,21 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
import junit.framework.TestCase;
import org.easymock.EasyMock;
-import org.eobjects.metamodel.AbstractDataContext;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-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.apache.metamodel.AbstractDataContext;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public class GroupedQueryBuilderImplTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/query/builder/SyntaxExamplesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/builder/SyntaxExamplesTest.java b/core/src/test/java/org/apache/metamodel/query/builder/SyntaxExamplesTest.java
index 0f04584..8876df9 100644
--- a/core/src/test/java/org/apache/metamodel/query/builder/SyntaxExamplesTest.java
+++ b/core/src/test/java/org/apache/metamodel/query/builder/SyntaxExamplesTest.java
@@ -16,18 +16,18 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
import junit.framework.TestCase;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MockDataContext;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MockDataContext;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Table;
public class SyntaxExamplesTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/query/builder/WhereBuilderImplTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/builder/WhereBuilderImplTest.java b/core/src/test/java/org/apache/metamodel/query/builder/WhereBuilderImplTest.java
index 4d45f61..68c7f72 100644
--- a/core/src/test/java/org/apache/metamodel/query/builder/WhereBuilderImplTest.java
+++ b/core/src/test/java/org/apache/metamodel/query/builder/WhereBuilderImplTest.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
import java.util.Arrays;
import java.util.Collection;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
import junit.framework.TestCase;
public class WhereBuilderImplTest extends TestCase {
[34/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptorList.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptorList.java b/core/src/main/java/org/eobjects/metamodel/intercept/InterceptorList.java
deleted file mode 100644
index 4d73097..0000000
--- a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptorList.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * 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.intercept;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Represents a list of interceptors
- *
- * @author Kasper Sørensen
- *
- * @param <E>
- * the thing to intercept
- *
- * @see Interceptor
- */
-public final class InterceptorList<E> {
-
- private final List<Interceptor<E>> _interceptors = new ArrayList<Interceptor<E>>();
-
- public void add(Interceptor<E> interceptor) {
- _interceptors.add(interceptor);
- }
-
- public void remove(Interceptor<E> interceptor) {
- _interceptors.remove(interceptor);
- }
-
- /**
- * Gets the first (if any) interceptor of a specific type.
- *
- * @param interceptorClazz
- * @return
- */
- public <I extends Interceptor<E>> I getInterceptorOfType(
- Class<I> interceptorClazz) {
- for (Interceptor<?> interceptor : _interceptors) {
- if (interceptorClazz.isAssignableFrom(interceptor.getClass())) {
- @SuppressWarnings("unchecked")
- I result = (I) interceptor;
- return result;
- }
- }
- return null;
- }
-
- public boolean isEmpty() {
- return _interceptors.isEmpty();
- }
-
- protected E interceptAll(E input) {
- for (Interceptor<E> interceptor : _interceptors) {
- input = interceptor.intercept(input);
- }
- return input;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/intercept/Interceptors.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/intercept/Interceptors.java b/core/src/main/java/org/eobjects/metamodel/intercept/Interceptors.java
deleted file mode 100644
index 83d843a..0000000
--- a/core/src/main/java/org/eobjects/metamodel/intercept/Interceptors.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * 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.intercept;
-
-import org.eobjects.metamodel.DataContext;
-
-public final class Interceptors {
-
- private Interceptors() {
- // prevent instantiation
- }
-
- public static InterceptableDataContext intercept(DataContext dc) {
- if (dc instanceof InterceptableDataContext) {
- return (InterceptableDataContext) dc;
- }
- return new InterceptableDataContext(dc);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/intercept/QueryInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/intercept/QueryInterceptor.java b/core/src/main/java/org/eobjects/metamodel/intercept/QueryInterceptor.java
deleted file mode 100644
index d5e072c..0000000
--- a/core/src/main/java/org/eobjects/metamodel/intercept/QueryInterceptor.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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.intercept;
-
-import org.eobjects.metamodel.query.Query;
-
-/**
- * An {@link Interceptor} for Queries, allowing to touch or modify a query
- * before execution.
- *
- * @author Kasper Sørensen
- */
-public interface QueryInterceptor extends Interceptor<Query> {
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/intercept/RowDeletionInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/intercept/RowDeletionInterceptor.java b/core/src/main/java/org/eobjects/metamodel/intercept/RowDeletionInterceptor.java
deleted file mode 100644
index 764730e..0000000
--- a/core/src/main/java/org/eobjects/metamodel/intercept/RowDeletionInterceptor.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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.intercept;
-
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-
-/**
- * An {@link Interceptor} for {@link RowDeletionBuilder}, allowing for
- * interception of "delete from table" operations before they are executed.
- *
- * @author Kasper Sørensen
- */
-public interface RowDeletionInterceptor extends Interceptor<RowDeletionBuilder> {
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/intercept/RowInsertionInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/intercept/RowInsertionInterceptor.java b/core/src/main/java/org/eobjects/metamodel/intercept/RowInsertionInterceptor.java
deleted file mode 100644
index ebe01f7..0000000
--- a/core/src/main/java/org/eobjects/metamodel/intercept/RowInsertionInterceptor.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * 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.intercept;
-
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-
-/**
- * An {@link Interceptor} for {@link RowInsertionBuilder}, allowing for
- * interception of "insert into table" operations before they are executed.
- *
- * @author Kasper Sørensen
- */
-public interface RowInsertionInterceptor extends
- Interceptor<RowInsertionBuilder> {
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/intercept/RowUpdationInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/intercept/RowUpdationInterceptor.java b/core/src/main/java/org/eobjects/metamodel/intercept/RowUpdationInterceptor.java
deleted file mode 100644
index 1a68192..0000000
--- a/core/src/main/java/org/eobjects/metamodel/intercept/RowUpdationInterceptor.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * 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.intercept;
-
-import org.eobjects.metamodel.update.RowUpdationBuilder;
-
-/**
- * An {@link Interceptor} for {@link RowUpdationBuilder}, allowing for
- * interception of "update table" operations before they are executed.
- *
- * @author Kasper Sørensen
- */
-public interface RowUpdationInterceptor extends
- Interceptor<RowUpdationBuilder> {
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/intercept/SchemaInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/intercept/SchemaInterceptor.java b/core/src/main/java/org/eobjects/metamodel/intercept/SchemaInterceptor.java
deleted file mode 100644
index e951771..0000000
--- a/core/src/main/java/org/eobjects/metamodel/intercept/SchemaInterceptor.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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.intercept;
-
-import org.eobjects.metamodel.schema.Schema;
-
-/**
- * An {@link Interceptor} for {@link Schema}s, which allows for intercepting
- * schema objects before they are returned to the user.
- *
- * @author Kasper Sørensen
- */
-public interface SchemaInterceptor extends Interceptor<Schema> {
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/intercept/TableCreationInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/intercept/TableCreationInterceptor.java b/core/src/main/java/org/eobjects/metamodel/intercept/TableCreationInterceptor.java
deleted file mode 100644
index 44ef714..0000000
--- a/core/src/main/java/org/eobjects/metamodel/intercept/TableCreationInterceptor.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * 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.intercept;
-
-import org.eobjects.metamodel.create.TableCreationBuilder;
-
-/**
- * An {@link Interceptor} for {@link TableCreationBuilder}s, which allows for
- * intercepting "create table" operations before they are executed.
- *
- * @author Kasper Sørensen
- */
-public interface TableCreationInterceptor extends
- Interceptor<TableCreationBuilder> {
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/intercept/TableDropInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/intercept/TableDropInterceptor.java b/core/src/main/java/org/eobjects/metamodel/intercept/TableDropInterceptor.java
deleted file mode 100644
index e0d268f..0000000
--- a/core/src/main/java/org/eobjects/metamodel/intercept/TableDropInterceptor.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * 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.intercept;
-
-import org.eobjects.metamodel.drop.TableDropBuilder;
-
-/**
- * An {@link Interceptor} for {@link TableDropBuilder}s, which allows for
- * intercepting "drop table" operations before they are executed.
- *
- * @author Kasper Sørensen
- */
-public interface TableDropInterceptor extends
- Interceptor<TableDropBuilder> {
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/package-info.java b/core/src/main/java/org/eobjects/metamodel/package-info.java
deleted file mode 100644
index 9846c01..0000000
--- a/core/src/main/java/org/eobjects/metamodel/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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.
- */
-/**
- * Root package for MetaModel
- */
-package org.eobjects.metamodel;
-
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/AbstractQueryClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/AbstractQueryClause.java b/core/src/main/java/org/eobjects/metamodel/query/AbstractQueryClause.java
deleted file mode 100644
index c06cf27..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/AbstractQueryClause.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/**
- * 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.query;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eobjects.metamodel.util.BaseObject;
-
-/**
- * Represents an abstract clause in a query. Clauses contains IQueryItems and
- * provide basic ways of adding, modifying and removing these.
- *
- * @param <E>
- * the type of query item this QueryClause handles
- *
- * @see Query
- */
-public abstract class AbstractQueryClause<E extends QueryItem> extends BaseObject implements QueryClause<E> {
-
- private static final long serialVersionUID = 3987346267433022231L;
-
- public static final String PREFIX_SELECT = "SELECT ";
- public static final String PREFIX_FROM = " FROM ";
- public static final String PREFIX_WHERE = " WHERE ";
- public static final String PREFIX_GROUP_BY = " GROUP BY ";
- public static final String PREFIX_HAVING = " HAVING ";
- public static final String PREFIX_ORDER_BY = " ORDER BY ";
- public static final String DELIM_COMMA = ", ";
- public static final String DELIM_AND = " AND ";
-
- private final Query _query;
- private final List<E> _items = new ArrayList<E>();
- private final String _prefix;
- private final String _delim;
-
- public AbstractQueryClause(Query query, String prefix, String delim) {
- _query = query;
- _prefix = prefix;
- _delim = delim;
- }
-
- @Override
- public QueryClause<E> setItems(E... items) {
- _items.clear();
- return addItems(items);
- }
-
- @Override
- public QueryClause<E> addItems(E... items) {
- for (E item : items) {
- addItem(item);
- }
- return this;
- }
-
- @Override
- public QueryClause<E> addItems(Iterable<E> items) {
- for (E item : items) {
- addItem(item);
- }
- return this;
- }
-
- public QueryClause<E> addItem(int index, E item) {
- if (item.getQuery() == null) {
- item.setQuery(_query);
- }
- _items.add(index, item);
- return this;
- };
-
- @Override
- public QueryClause<E> addItem(E item) {
- return addItem(getItemCount(), item);
- }
-
- @Override
- public int getItemCount() {
- return _items.size();
- }
-
- @Override
- public boolean isEmpty() {
- return getItemCount() == 0;
- }
-
- @Override
- public E getItem(int index) {
- return _items.get(index);
- }
-
- @Override
- public List<E> getItems() {
- return _items;
- }
-
- @Override
- public QueryClause<E> removeItem(int index) {
- _items.remove(index);
- return this;
- }
-
- @Override
- public QueryClause<E> removeItem(E item) {
- _items.remove(item);
- return this;
- }
-
- @Override
- public QueryClause<E> removeItems() {
- _items.clear();
- return this;
- }
-
- @Override
- public String toSql() {
- return toSql(false);
- }
-
- @Override
- public String toSql(boolean includeSchemaInColumnPaths) {
- if (_items.size() == 0) {
- return "";
- }
- final StringBuilder sb = new StringBuilder(_prefix);
- for (int i = 0; i < _items.size(); i++) {
- final E item = _items.get(i);
- if (i != 0) {
- sb.append(_delim);
- }
- final String sql = item.toSql(includeSchemaInColumnPaths);
- sb.append(sql);
- }
- return sb.toString();
- }
-
- @Override
- public String toString() {
- return toSql();
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- identifiers.add(_items);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/AverageAggregateBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/AverageAggregateBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/AverageAggregateBuilder.java
deleted file mode 100644
index 3b2d949..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/AverageAggregateBuilder.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * 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.query;
-
-import org.eobjects.metamodel.util.AggregateBuilder;
-import org.eobjects.metamodel.util.NumberComparator;
-
-final class AverageAggregateBuilder implements AggregateBuilder<Double> {
-
- public double _average;
- public int _numValues;
-
- @Override
- public void add(Object o) {
- if (o == null) {
- return;
- }
- Number number = NumberComparator.toNumber(o);
- if (number == null) {
- throw new IllegalArgumentException("Could not convert to number: "
- + o);
- }
- double total = _average * _numValues + number.doubleValue();
- _numValues++;
- _average = total / _numValues;
- }
-
- @Override
- public Double getAggregate() {
- return _average;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/CompiledQuery.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/CompiledQuery.java b/core/src/main/java/org/eobjects/metamodel/query/CompiledQuery.java
deleted file mode 100644
index cd242b9..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/CompiledQuery.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * 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.query;
-
-import java.io.Closeable;
-import java.util.List;
-
-import org.eobjects.metamodel.DataContext;
-
-/**
- * A {@link CompiledQuery} is a {@link Query} which has been compiled, typically
- * by the data source itself, to provide optimized execution speed. Compiled
- * queries are produced using the {@link DataContext#compileQuery(Query)} method.
- *
- * Typically the compilation itself takes a bit of time, but firing the compiled
- * query is faster than regular queries. This means that for repeated executions
- * of the same query, it is usually faster to use compiled queries.
- *
- * To make {@link CompiledQuery} useful for more than just one specific query,
- * variations of the query can be fired, as long as the variations can be
- * expressed as a {@link QueryParameter} for instance in the WHERE clause of the
- * query.
- *
- * @see DataContext#compileQuery(Query)
- * @see QueryParameter
- */
-public interface CompiledQuery extends Closeable {
-
- /**
- * Gets the {@link QueryParameter}s associated with the compiled query.
- * Values for these parameters are expected when the query is executed.
- *
- * @return a list of query parameters
- */
- public List<QueryParameter> getParameters();
-
- /**
- * A representation of the query as SQL.
- *
- * @return a SQL string.
- */
- public String toSql();
-
- /**
- * Closes any resources related to the compiled query.
- */
- @Override
- public void close();
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/CountAggregateBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/CountAggregateBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/CountAggregateBuilder.java
deleted file mode 100644
index c5bca84..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/CountAggregateBuilder.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.query;
-
-import org.eobjects.metamodel.util.AggregateBuilder;
-
-final class CountAggregateBuilder implements AggregateBuilder<Long> {
-
- private long counter = 0;
-
- @Override
- public void add(Object o) {
- if (o != null) {
- counter++;
- }
- }
-
- @Override
- public Long getAggregate() {
- return counter;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/DefaultCompiledQuery.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/DefaultCompiledQuery.java b/core/src/main/java/org/eobjects/metamodel/query/DefaultCompiledQuery.java
deleted file mode 100644
index 147f5c1..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/DefaultCompiledQuery.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/**
- * 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.query;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * Represents a default implementation of the {@link CompiledQuery} interface.
- * This implementation does not actually do anything to prepare the query, but
- * allows creating a clone of the originating query with the parameters replaced
- * by values.
- */
-public class DefaultCompiledQuery implements CompiledQuery {
-
- private final Query _query;
- private final List<QueryParameter> _parameters;
-
- public DefaultCompiledQuery(Query query) {
- _query = query;
- _parameters = createParameterList();
- }
-
- /**
- * Clones the query while replacing query parameters with corresponding
- * values.
- *
- * @param values
- * @return
- */
- public Query cloneWithParameterValues(Object[] values) {
- final AtomicInteger parameterIndex = new AtomicInteger(0);
- final Query clonedQuery = _query.clone();
- replaceParametersInQuery(values, parameterIndex, _query, clonedQuery);
- return clonedQuery;
- }
-
- private void replaceParametersInQuery(Object[] values, AtomicInteger parameterIndex, Query originalQuery,
- Query newQuery) {
- replaceParametersInFromClause(values, parameterIndex, originalQuery, newQuery);
- replaceParametersInWhereClause(values, parameterIndex, originalQuery, newQuery);
- }
-
- private void replaceParametersInWhereClause(Object[] values, final AtomicInteger parameterIndex,
- Query originalQuery, Query newQuery) {
- // creates a clone of the original query, but rebuilds a completely new
- // where clause based on parameter values
-
- final List<FilterItem> items = originalQuery.getWhereClause().getItems();
- int i = 0;
- for (FilterItem filterItem : items) {
- final FilterItem newFilter = copyFilterItem(filterItem, values, parameterIndex);
- if (filterItem != newFilter) {
- newQuery.getWhereClause().removeItem(i);
- newQuery.getWhereClause().addItem(i, newFilter);
- }
- i++;
- }
- }
-
- private void replaceParametersInFromClause(Object[] values, AtomicInteger parameterIndex, Query originalQuery,
- Query newQuery) {
- final List<FromItem> fromItems = originalQuery.getFromClause().getItems();
- int i = 0;
- for (FromItem fromItem : fromItems) {
- final Query subQuery = fromItem.getSubQuery();
- if (subQuery != null) {
- final Query newSubQuery = newQuery.getFromClause().getItem(i).getSubQuery();
- replaceParametersInQuery(values, parameterIndex, subQuery, newSubQuery);
-
- newQuery.getFromClause().removeItem(i);
- newQuery.getFromClause().addItem(i, new FromItem(newSubQuery).setAlias(fromItem.getAlias()));
- }
- i++;
- }
- }
-
- private FilterItem copyFilterItem(FilterItem item, Object[] values, AtomicInteger parameterIndex) {
- if (item.isCompoundFilter()) {
- final FilterItem[] childItems = item.getChildItems();
- final FilterItem[] newChildItems = new FilterItem[childItems.length];
- for (int i = 0; i < childItems.length; i++) {
- final FilterItem childItem = childItems[i];
- final FilterItem newChildItem = copyFilterItem(childItem, values, parameterIndex);
- newChildItems[i] = newChildItem;
- }
- final FilterItem newFilter = new FilterItem(newChildItems);
- return newFilter;
- } else {
- if (item.getOperand() instanceof QueryParameter) {
- final Object newOperand = values[parameterIndex.getAndIncrement()];
- final FilterItem newFilter = new FilterItem(item.getSelectItem(), item.getOperator(), newOperand);
- return newFilter;
- } else {
- return item;
- }
- }
- }
-
- private List<QueryParameter> createParameterList() {
- final List<QueryParameter> parameters = new ArrayList<QueryParameter>();
-
- buildParameterListInFromClause(parameters, _query);
- buildParameterListInWhereClause(parameters, _query);
- return parameters;
- }
-
- private void buildParameterListInWhereClause(List<QueryParameter> parameters, Query query) {
- List<FilterItem> items = query.getWhereClause().getItems();
- for (FilterItem item : items) {
- buildParameterFromFilterItem(parameters, item);
- }
- }
-
- private void buildParameterListInFromClause(List<QueryParameter> parameters, Query query) {
- List<FromItem> fromItems = query.getFromClause().getItems();
- for (FromItem fromItem : fromItems) {
- Query subQuery = fromItem.getSubQuery();
- if (subQuery != null) {
- buildParameterListInFromClause(parameters, subQuery);
- buildParameterListInWhereClause(parameters, subQuery);
- }
- }
- }
-
- @Override
- public List<QueryParameter> getParameters() {
- return _parameters;
- }
-
- @Override
- public String toSql() {
- return _query.toSql();
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "[" + toSql() + "]";
- }
-
- @Override
- public void close() {
- // do nothing
- }
-
- private void buildParameterFromFilterItem(List<QueryParameter> parameters, FilterItem item) {
- if (item.isCompoundFilter()) {
- FilterItem[] childItems = item.getChildItems();
- for (FilterItem childItem : childItems) {
- buildParameterFromFilterItem(parameters, childItem);
- }
- } else {
- if (item.getOperand() instanceof QueryParameter) {
- parameters.add((QueryParameter) item.getOperand());
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/FilterClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/FilterClause.java b/core/src/main/java/org/eobjects/metamodel/query/FilterClause.java
deleted file mode 100644
index 591fb01..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/FilterClause.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/**
- * 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.query;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eobjects.metamodel.schema.Column;
-
-/**
- * Represents a clause of filters in the query. This type of clause is used for
- * the WHERE and HAVING parts of an SQL query.
- *
- * Each provided FilterItem will be evaluated with the logical AND operator,
- * which requires that all filters are applied. Alternatively, if you wan't to
- * use an OR operator, then use the appropriate constructor of FilterItem to
- * create a composite filter.
- *
- * @see FilterItem
- */
-public class FilterClause extends AbstractQueryClause<FilterItem> {
-
- private static final long serialVersionUID = -9077342278766808934L;
-
- public FilterClause(Query query, String prefix) {
- super(query, prefix, AbstractQueryClause.DELIM_AND);
- }
-
- public List<SelectItem> getEvaluatedSelectItems() {
- List<SelectItem> result = new ArrayList<SelectItem>();
- List<FilterItem> items = getItems();
- for (FilterItem item : items) {
- addEvaluatedSelectItems(result, item);
- }
- return result;
- }
-
- private void addEvaluatedSelectItems(List<SelectItem> result,
- FilterItem item) {
- FilterItem[] orItems = item.getChildItems();
- if (orItems != null) {
- for (FilterItem filterItem : orItems) {
- addEvaluatedSelectItems(result, filterItem);
- }
- }
- SelectItem selectItem = item.getSelectItem();
- if (selectItem != null && !result.contains(selectItem)) {
- result.add(selectItem);
- }
- Object operand = item.getOperand();
- if (operand != null && operand instanceof SelectItem
- && !result.contains(operand)) {
- result.add((SelectItem) operand);
- }
- }
-
- /**
- * Traverses the items and evaluates whether or not the given column is
- * referenced in either of them.
- *
- * @param column
- * @return true if the column is referenced in the clause or false if not
- */
- public boolean isColumnReferenced(Column column) {
- for (FilterItem item : getItems()) {
- if (item.isReferenced(column)) {
- return true;
- }
- }
- 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/eobjects/metamodel/query/FilterItem.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/FilterItem.java b/core/src/main/java/org/eobjects/metamodel/query/FilterItem.java
deleted file mode 100644
index 86fdd20..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/FilterItem.java
+++ /dev/null
@@ -1,542 +0,0 @@
-/**
- * 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.query;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.eobjects.metamodel.data.IRowFilter;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.util.BaseObject;
-import org.eobjects.metamodel.util.CollectionUtils;
-import org.eobjects.metamodel.util.FormatHelper;
-import org.eobjects.metamodel.util.ObjectComparator;
-import org.eobjects.metamodel.util.WildcardPattern;
-
-/**
- * Represents a filter in a query that resides either within a WHERE clause or a
- * HAVING clause
- *
- * @see FilterClause
- * @see OperatorType
- * @see LogicalOperator
- */
-public class FilterItem extends BaseObject implements QueryItem, Cloneable, IRowFilter {
-
- private static final long serialVersionUID = 2435322742894653227L;
-
- private Query _query;
- private final SelectItem _selectItem;
- private final OperatorType _operator;
- private final Object _operand;
- private final List<FilterItem> _childItems;
- private final LogicalOperator _logicalOperator;
- private final String _expression;
- private transient Set<?> _inValues;
-
- /**
- * Private constructor, used for cloning
- */
- private FilterItem(SelectItem selectItem, OperatorType operator, Object operand, List<FilterItem> orItems,
- String expression, LogicalOperator logicalOperator) {
- _selectItem = selectItem;
- _operator = operator;
- _operand = validateOperand(operand);
- _childItems = orItems;
- _expression = expression;
- _logicalOperator = logicalOperator;
- }
-
- private Object validateOperand(Object operand) {
- if (operand instanceof Column) {
- // gracefully convert to a select item.
- operand = new SelectItem((Column) operand);
- }
- return operand;
- }
-
- /**
- * Creates a single filter item based on a SelectItem, an operator and an
- * operand.
- *
- * @param selectItem
- * the selectItem to put constraints on, cannot be null
- * @param operator
- * The operator to use. Can be OperatorType.EQUALS_TO,
- * OperatorType.DIFFERENT_FROM,
- * OperatorType.GREATER_THAN,OperatorType.LESS_THAN
- * @param operand
- * The operand. Can be a constant like null or a String, a
- * Number, a Boolean, a Date, a Time, a DateTime. Or another
- * SelectItem
- * @throws IllegalArgumentException
- * if the SelectItem is null or if the combination of operator
- * and operand does not make sense.
- */
- public FilterItem(SelectItem selectItem, OperatorType operator, Object operand) throws IllegalArgumentException {
- this(selectItem, operator, operand, null, null, null);
- if (_operand == null) {
- require("Can only use EQUALS or DIFFERENT_FROM operator with null-operand",
- _operator == OperatorType.DIFFERENT_FROM || _operator == OperatorType.EQUALS_TO);
- }
- if (_operator == OperatorType.LIKE) {
- ColumnType type = _selectItem.getColumn().getType();
- if (type != null) {
- require("Can only use LIKE operator with strings", type.isLiteral()
- && (_operand instanceof String || _operand instanceof SelectItem));
- }
- }
- require("SelectItem cannot be null", _selectItem != null);
- }
-
- /**
- * Creates a single unvalidated filter item based on a expression.
- * Expression based filters are typically NOT datastore-neutral but are
- * available for special "hacking" needs.
- *
- * Expression based filters can only be used for JDBC based datastores since
- * they are translated directly into SQL.
- *
- * @param expression
- * An expression to use for the filter, for example
- * "YEAR(my_date) = 2008".
- */
- public FilterItem(String expression) {
- this(null, null, null, null, expression, null);
-
- require("Expression cannot be null", _expression != null);
- }
-
- /**
- * Creates a composite filter item based on other filter items. Each
- * provided filter items will be OR'ed meaning that if one of the evaluates
- * as true, then the composite filter will be evaluated as true
- *
- * @param items
- * a list of items to include in the composite
- */
- public FilterItem(List<FilterItem> items) {
- this(LogicalOperator.OR, items);
- }
-
- /**
- * Creates a compound filter item based on other filter items. Each provided
- * filter item will be combined according to the {@link LogicalOperator}.
- *
- * @param logicalOperator
- * the logical operator to apply
- * @param items
- * a list of items to include in the composite
- */
- public FilterItem(LogicalOperator logicalOperator, List<FilterItem> items) {
- this(null, null, null, items, null, logicalOperator);
-
- require("Child items cannot be null", _childItems != null);
- require("Child items cannot be empty", !_childItems.isEmpty());
- }
-
- /**
- * Creates a compound filter item based on other filter items. Each provided
- * filter item will be combined according to the {@link LogicalOperator}.
- *
- * @param logicalOperator
- * the logical operator to apply
- * @param items
- * an array of items to include in the composite
- */
- public FilterItem(LogicalOperator logicalOperator, FilterItem... items) {
- this(logicalOperator, Arrays.asList(items));
- }
-
- /**
- * Creates a compound filter item based on other filter items. Each provided
- * filter items will be OR'ed meaning that if one of the evaluates as true,
- * then the compound filter will be evaluated as true
- *
- * @param items
- * an array of items to include in the composite
- */
- public FilterItem(FilterItem... items) {
- this(Arrays.asList(items));
- }
-
- private void require(String errorMessage, boolean b) {
- if (!b) {
- throw new IllegalArgumentException(errorMessage);
- }
- }
-
- public SelectItem getSelectItem() {
- return _selectItem;
- }
-
- public OperatorType getOperator() {
- return _operator;
- }
-
- public Object getOperand() {
- return _operand;
- }
-
- public String getExpression() {
- return _expression;
- }
-
- public Query getQuery() {
- return _query;
- }
-
- public LogicalOperator getLogicalOperator() {
- return _logicalOperator;
- }
-
- public FilterItem setQuery(Query query) {
- _query = query;
- if (_childItems == null) {
- if (_expression == null) {
- if (_selectItem.getQuery() == null) {
- _selectItem.setQuery(_query);
- }
- if (_operand instanceof SelectItem) {
- SelectItem operand = (SelectItem) _operand;
- if (operand.getQuery() == null) {
- operand.setQuery(_query);
- }
- }
- }
- } else {
- for (FilterItem item : _childItems) {
- if (item.getQuery() == null) {
- item.setQuery(_query);
- }
- }
- }
- return this;
- }
-
- @Override
- public String toSql() {
- return toSql(false);
- }
-
- /**
- * Parses the constraint as a SQL Where-clause item
- */
- @Override
- public String toSql(boolean includeSchemaInColumnPaths) {
- if (_expression != null) {
- return _expression;
- }
-
- StringBuilder sb = new StringBuilder();
- if (_childItems == null) {
- sb.append(_selectItem.getSameQueryAlias(includeSchemaInColumnPaths));
-
- if (_operand == null && _operator == OperatorType.EQUALS_TO) {
- sb.append(" IS NULL");
- } else if (_operand == null && _operator == OperatorType.DIFFERENT_FROM) {
- sb.append(" IS NOT NULL");
- } else {
- final Object operand = appendOperator(sb, _operand, _operator);
-
- if (operand instanceof SelectItem) {
- final String selectItemString = ((SelectItem) operand).getSameQueryAlias(includeSchemaInColumnPaths);
- sb.append(selectItemString);
- } else {
- ColumnType columnType = _selectItem.getExpectedColumnType();
- final String sqlValue = FormatHelper.formatSqlValue(columnType, operand);
- sb.append(sqlValue);
- }
- }
- } else {
- sb.append('(');
- for (int i = 0; i < _childItems.size(); i++) {
- FilterItem item = _childItems.get(i);
- if (i != 0) {
- sb.append(' ');
- sb.append(_logicalOperator.toString());
- sb.append(' ');
- }
- sb.append(item.toSql());
- }
- sb.append(')');
- }
-
- return sb.toString();
- }
-
- @SuppressWarnings("deprecation")
- public static Object appendOperator(StringBuilder sb, Object operand, OperatorType operator) {
- switch (operator) {
- case DIFFERENT_FROM:
- sb.append(" <> ");
- break;
- case EQUALS_TO:
- sb.append(" = ");
- break;
- case LIKE:
- sb.append(" LIKE ");
- break;
- case GREATER_THAN:
- case HIGHER_THAN:
- sb.append(" > ");
- break;
- case LESS_THAN:
- case LOWER_THAN:
- sb.append(" < ");
- break;
- case IN:
- sb.append(" IN ");
- operand = CollectionUtils.toList(operand);
- break;
- default:
- throw new IllegalStateException("Operator could not be determined");
- }
- return operand;
- }
-
- /**
- * Does a "manual" evaluation, useful for CSV data and alike, where queries
- * cannot be created.
- */
- public boolean evaluate(Row row) {
- require("Expression-based filters cannot be manually evaluated", _expression == null);
-
- if (_childItems == null) {
- // Evaluate a single constraint
- Object selectItemValue = row.getValue(_selectItem);
- Object operandValue = _operand;
- if (_operand instanceof SelectItem) {
- SelectItem selectItem = (SelectItem) _operand;
- operandValue = row.getValue(selectItem);
- }
- if (operandValue == null) {
- if (_operator == OperatorType.DIFFERENT_FROM) {
- return (selectItemValue != null);
- } else if (_operator == OperatorType.EQUALS_TO) {
- return (selectItemValue == null);
- } else {
- return false;
- }
- } else if (selectItemValue == null) {
- if (_operator == OperatorType.DIFFERENT_FROM) {
- return true;
- } else {
- return false;
- }
- } else {
- return compare(selectItemValue, operandValue);
- }
- } else {
-
- // Evaluate several constraints
- if (_logicalOperator == LogicalOperator.AND) {
- // require all results to be true
- for (FilterItem item : _childItems) {
- boolean result = item.evaluate(row);
- if (!result) {
- return false;
- }
- }
- return true;
- } else {
- // require at least one result to be true
- for (FilterItem item : _childItems) {
- boolean result = item.evaluate(row);
- if (result) {
- return true;
- }
- }
- return false;
- }
- }
- }
-
- @SuppressWarnings("deprecation")
- private boolean compare(Object selectItemValue, Object operandValue) {
- Comparator<Object> comparator = ObjectComparator.getComparator();
- if (_operator == OperatorType.DIFFERENT_FROM) {
- return comparator.compare(selectItemValue, operandValue) != 0;
- } else if (_operator == OperatorType.EQUALS_TO) {
- return comparator.compare(selectItemValue, operandValue) == 0;
- } else if (_operator == OperatorType.GREATER_THAN || _operator == OperatorType.HIGHER_THAN) {
- return comparator.compare(selectItemValue, operandValue) > 0;
- } else if (_operator == OperatorType.LESS_THAN || _operator == OperatorType.LOWER_THAN) {
- return comparator.compare(selectItemValue, operandValue) < 0;
- } else if (_operator == OperatorType.LIKE) {
- WildcardPattern matcher = new WildcardPattern((String) operandValue, '%');
- return matcher.matches((String) selectItemValue);
- } else if (_operator == OperatorType.IN) {
- Set<?> inValues = getInValues();
- return inValues.contains(selectItemValue);
- } else {
- throw new IllegalStateException("Operator could not be determined");
- }
- }
-
- /**
- * Lazy initializes a set (for fast searching) of IN values.
- *
- * @return a hash set appropriate for IN clause evaluation
- */
- private Set<?> getInValues() {
- if (_inValues == null) {
- if (_operand instanceof Set) {
- _inValues = (Set<?>) _operand;
- } else {
- List<?> list = CollectionUtils.toList(_operand);
- _inValues = new HashSet<Object>(list);
- }
- }
- return _inValues;
- }
-
- @Override
- protected FilterItem clone() {
- final List<FilterItem> orItems;
- if (_childItems == null) {
- orItems = null;
- } else {
- orItems = new ArrayList<FilterItem>(_childItems);
- }
-
- final Object operand;
- if (_operand instanceof SelectItem) {
- operand = ((SelectItem) _operand).clone();
- } else {
- operand = _operand;
- }
-
- final SelectItem selectItem;
- if (_selectItem == null) {
- selectItem = null;
- } else {
- selectItem = _selectItem.clone();
- }
-
- return new FilterItem(selectItem, _operator, operand, orItems, _expression, _logicalOperator);
- }
-
- public boolean isReferenced(Column column) {
- if (column != null) {
- if (_selectItem != null) {
- if (_selectItem.isReferenced(column)) {
- return true;
- }
- }
- if (_operand != null && _operand instanceof SelectItem) {
- if (((SelectItem) _operand).isReferenced(column)) {
- return true;
- }
- }
- if (_childItems != null) {
- for (FilterItem item : _childItems) {
- if (item.isReferenced(column)) {
- return true;
- }
- }
- }
- }
- return false;
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- identifiers.add(_expression);
- identifiers.add(_operand);
- identifiers.add(_childItems);
- identifiers.add(_operator);
- identifiers.add(_selectItem);
- identifiers.add(_logicalOperator);
- }
-
- /**
- * Gets the {@link FilterItem}s that this filter item consists of, if it is
- * a compound filter item.
- *
- * @return
- * @deprecated use {@link #getChildItems()} instead
- */
- @Deprecated
- public FilterItem[] getOrItems() {
- return getChildItems();
- }
-
- /**
- * Gets the number of child items, if this is a compound filter item.
- *
- * @return
- * @deprecated use {@link #getChildItemCount()} instead.
- */
- @Deprecated
- public int getOrItemCount() {
- return getChildItemCount();
- }
-
- /**
- * Get the number of child items, if this is a compound filter item.
- *
- * @return
- */
- public int getChildItemCount() {
- if (_childItems == null) {
- return 0;
- }
- return _childItems.size();
- }
-
- /**
- * Gets the {@link FilterItem}s that this filter item consists of, if it is
- * a compound filter item.
- *
- * @return
- */
- public FilterItem[] getChildItems() {
- if (_childItems == null) {
- return null;
- }
- return _childItems.toArray(new FilterItem[_childItems.size()]);
- }
-
- /**
- * Determines whether this {@link FilterItem} is a compound filter or not
- * (ie. if it has child items or not)
- *
- * @return
- */
- public boolean isCompoundFilter() {
- return _childItems != null;
- }
-
- @Override
- public String toString() {
- return toSql();
- }
-
- @Override
- public boolean accept(Row row) {
- return evaluate(row);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/FromClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/FromClause.java b/core/src/main/java/org/eobjects/metamodel/query/FromClause.java
deleted file mode 100644
index 950c246..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/FromClause.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/**
- * 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.query;
-
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * Represents the FROM clause of a query containing FromItem's.
- *
- * @see FromItem
- */
-public class FromClause extends AbstractQueryClause<FromItem> {
-
- private static final long serialVersionUID = -8227310702249122115L;
-
- public FromClause(Query query) {
- super(query, AbstractQueryClause.PREFIX_FROM, AbstractQueryClause.DELIM_COMMA);
- }
-
- /**
- * Gets the alias of a table, if it is registered (and visible, ie. not part
- * of a sub-query) in the FromClause
- *
- * @param table
- * the table to get the alias for
- * @return the alias or null if none is found
- */
- public String getAlias(Table table) {
- if (table != null) {
- for (FromItem item : getItems()) {
- String alias = item.getAlias(table);
- if (alias != null) {
- return alias;
- }
- }
- }
- return null;
- }
-
- /**
- * Retrieves a table by it's reference which may be it's alias or it's
- * qualified table name. Typically, this method is used to resolve a
- * SelectItem with a reference like "foo.bar", where "foo" may either be an
- * alias or a table name
- *
- * @param reference
- * @return a FromItem which matches the provided reference string
- */
- public FromItem getItemByReference(String reference) {
- if (reference == null) {
- return null;
- }
- for (final FromItem item : getItems()) {
- FromItem result = getItemByReference(item, reference);
- if (result != null) {
- return result;
- }
- }
- return null;
- }
-
- private FromItem getItemByReference(FromItem item, String reference) {
- final String alias = item.getAlias();
- if (reference.equals(alias)) {
- return item;
- }
-
- final Table table = item.getTable();
- if (alias == null && table != null && reference.equals(table.getName())) {
- return item;
- }
-
- final JoinType join = item.getJoin();
- if (join != null) {
- final FromItem leftResult = getItemByReference(item.getLeftSide(), reference);
- if (leftResult != null) {
- return leftResult;
- }
- final FromItem rightResult = getItemByReference(item.getRightSide(), reference);
- if (rightResult != null) {
- return rightResult;
- }
- }
-
- return null;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/FromItem.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/FromItem.java b/core/src/main/java/org/eobjects/metamodel/query/FromItem.java
deleted file mode 100644
index 2ea22bd..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/FromItem.java
+++ /dev/null
@@ -1,349 +0,0 @@
-/**
- * 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.query;
-
-import java.util.List;
-
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.BaseObject;
-
-/**
- * Represents a FROM item. FROM items can take different forms:
- * <ul>
- * <li>table FROMs (eg. "FROM products p")</li>
- * <lI>join FROMs with an ON clause (eg. "FROM products p INNER JOIN orders o ON
- * p.id = o.product_id")</li>
- * <li>subquery FROMs (eg. "FROM (SELECT * FROM products) p")</li>
- * <li>expression FROM (any string based from item)</li>
- * </ul>
- *
- * @see FromClause
- */
-public class FromItem extends BaseObject implements QueryItem, Cloneable {
-
- private static final long serialVersionUID = -6559220014058975193L;
- private Table _table;
- private String _alias;
- private Query _subQuery;
- private JoinType _join;
- private FromItem _leftSide;
- private FromItem _rightSide;
- private SelectItem[] _leftOn;
- private SelectItem[] _rightOn;
- private Query _query;
- private String _expression;
-
- /**
- * Private constructor, used for cloning
- */
- private FromItem() {
- }
-
- /**
- * Constructor for table FROM clauses
- */
- public FromItem(Table table) {
- _table = table;
- }
-
- /**
- * Constructor for sub-query FROM clauses
- *
- * @param subQuery
- * the subquery to use
- */
- public FromItem(Query subQuery) {
- _subQuery = subQuery;
- }
-
- /**
- * Constructor for join FROM clauses that join two tables using their
- * relationship. The primary table of the relationship will be the left side
- * of the join and the foreign table of the relationship will be the right
- * side of the join.
- *
- * @param join
- * the join type to use
- * @param relationship
- * the relationship to use for joining the tables
- */
- 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]);
- }
- _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]);
- }
- }
-
- /**
- * Constructor for advanced join types with custom relationships
- *
- * @param join
- * the join type to use
- * @param leftSide
- * the left side of the join
- * @param rightSide
- * the right side of the join
- * @param leftOn
- * what left-side select items to use for the ON clause
- * @param rightOn
- * what right-side select items to use for the ON clause
- */
- public FromItem(JoinType join, FromItem leftSide, FromItem rightSide, SelectItem[] leftOn, SelectItem[] rightOn) {
- _join = join;
- _leftSide = leftSide;
- _rightSide = rightSide;
- _leftOn = leftOn;
- _rightOn = rightOn;
- }
-
- /**
- * Creates a single unvalidated from item based on a expression. Expression
- * based from items are typically NOT datastore-neutral but are available
- * for special "hacking" needs.
- *
- * Expression based from items can only be used for JDBC based datastores
- * since they are translated directly into SQL.
- *
- * @param expression
- * An expression to use for the from item, for example "MYTABLE".
- */
- public FromItem(String expression) {
- if (expression == null) {
- throw new IllegalArgumentException("Expression cannot be null");
- }
- _expression = expression;
- }
-
- public String getAlias() {
- return _alias;
- }
-
- public String getSameQueryAlias() {
- if (_alias != null) {
- return _alias;
- }
- if (_table != null) {
- return _table.getQuotedName();
- }
- return null;
- }
-
- public FromItem setAlias(String alias) {
- _alias = alias;
- return this;
- }
-
- public Table getTable() {
- return _table;
- }
-
- public Query getSubQuery() {
- return _subQuery;
- }
-
- public JoinType getJoin() {
- return _join;
- }
-
- public FromItem getLeftSide() {
- return _leftSide;
- }
-
- public FromItem getRightSide() {
- return _rightSide;
- }
-
- public SelectItem[] getLeftOn() {
- return _leftOn;
- }
-
- public SelectItem[] getRightOn() {
- return _rightOn;
- }
-
- public String getExpression() {
- return _expression;
- }
-
- @Override
- public String toSql() {
- return toSql(false);
- }
-
- @Override
- public String toSql(boolean includeSchemaInColumnPaths) {
- final String stringNoAlias = toStringNoAlias(includeSchemaInColumnPaths);
- final StringBuilder sb = new StringBuilder(stringNoAlias);
- if (_join != null && _alias != null) {
- sb.insert(0, '(');
- sb.append(')');
- }
- if (_alias != null) {
- sb.append(' ');
- sb.append(_alias);
- }
- return sb.toString();
- }
-
- public String toStringNoAlias() {
- return toStringNoAlias(false);
- }
-
- public String toStringNoAlias(boolean includeSchemaInColumnPaths) {
- if (_expression != null) {
- return _expression;
- }
- StringBuilder sb = new StringBuilder();
- if (_table != null) {
- if (_table.getSchema() != null && _table.getSchema().getName() != null) {
- sb.append(_table.getSchema().getName());
- sb.append('.');
- }
- sb.append(_table.getQuotedName());
- } else if (_subQuery != null) {
- sb.append('(');
- sb.append(_subQuery.toSql(includeSchemaInColumnPaths));
- sb.append(')');
- } else if (_join != null) {
- String leftSideAlias = _leftSide.getSameQueryAlias();
- String rightSideAlias = _rightSide.getSameQueryAlias();
- sb.append(_leftSide.toSql());
- sb.append(' ');
- sb.append(_join);
- sb.append(" JOIN ");
- sb.append(_rightSide.toSql());
- for (int i = 0; i < _leftOn.length; i++) {
- if (i == 0) {
- sb.append(" ON ");
- } else {
- sb.append(" AND ");
- }
- SelectItem primary = _leftOn[i];
- appendJoinOnItem(sb, leftSideAlias, primary);
-
- sb.append(" = ");
-
- SelectItem foreign = _rightOn[i];
- appendJoinOnItem(sb, rightSideAlias, foreign);
- }
- }
- return sb.toString();
- }
-
- private void appendJoinOnItem(StringBuilder sb, String sideAlias, SelectItem onItem) {
- final FromItem fromItem = onItem.getFromItem();
- if (fromItem != null && fromItem.getSubQuery() != null && fromItem.getAlias() != null) {
- // there's a corner case scenario where an ON item references a
- // subquery being joined. In that case the getSuperQueryAlias()
- // method will include the subquery alias.
- final String superQueryAlias = onItem.getSuperQueryAlias();
- sb.append(superQueryAlias);
- return;
- }
-
- if (sideAlias != null) {
- sb.append(sideAlias);
- sb.append('.');
- }
- final String superQueryAlias = onItem.getSuperQueryAlias();
- sb.append(superQueryAlias);
- }
-
- /**
- * Gets the alias of a table, if it is registered (and visible, ie. not part
- * of a sub-query) in the FromItem
- *
- * @param table
- * the table to get the alias for
- * @return the alias or null if none is found
- */
- public String getAlias(Table table) {
- String result = null;
- if (table != null) {
- // Search recursively through left and right side, unless they
- // are sub-query FromItems
- if (table.equals(_table)) {
- result = _alias;
- } else if (_join != null) {
- result = _rightSide.getAlias(table);
- if (result == null) {
- result = _leftSide.getAlias(table);
- }
- }
- }
- return result;
- }
-
- public Query getQuery() {
- return _query;
- }
-
- public QueryItem setQuery(Query query) {
- _query = query;
- return this;
- }
-
- @Override
- protected FromItem clone() {
- FromItem f = new FromItem();
- f._alias = _alias;
- f._join = _join;
- f._table = _table;
- f._expression = _expression;
- if (_subQuery != null) {
- f._subQuery = _subQuery.clone();
- }
- if (_leftOn != null && _leftSide != null && _rightOn != null && _rightSide != null) {
- f._leftSide = _leftSide.clone();
- f._leftOn = _leftOn.clone();
- f._rightSide = _rightSide.clone();
- f._rightOn = _rightOn.clone();
- }
- return f;
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- identifiers.add(_table);
- identifiers.add(_alias);
- identifiers.add(_subQuery);
- identifiers.add(_join);
- identifiers.add(_leftSide);
- identifiers.add(_rightSide);
- identifiers.add(_leftOn);
- identifiers.add(_rightOn);
- identifiers.add(_expression);
- }
-
- @Override
- public String toString() {
- return toSql();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/FunctionType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/FunctionType.java b/core/src/main/java/org/eobjects/metamodel/query/FunctionType.java
deleted file mode 100644
index c8d79c7..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/FunctionType.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * 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.query;
-
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.util.AggregateBuilder;
-
-/**
- * Represents an aggregate function to use in a SelectItem.
- *
- * @see SelectItem
- */
-public enum FunctionType {
-
- COUNT {
- @Override
- public AggregateBuilder<Long> build() {
- return new CountAggregateBuilder();
- }
- },
- AVG {
- @Override
- public AggregateBuilder<Double> build() {
- return new AverageAggregateBuilder();
- }
- },
- SUM {
- @Override
- public AggregateBuilder<Double> build() {
- return new SumAggregateBuilder();
- }
- },
- MAX {
- @Override
- public AggregateBuilder<Object> build() {
- return new MaxAggregateBuilder();
- }
- },
- MIN {
- @Override
- public AggregateBuilder<Object> build() {
- return new MinAggregateBuilder();
- }
- };
-
- public ColumnType getExpectedColumnType(ColumnType type) {
- switch (this) {
- case COUNT:
- return ColumnType.BIGINT;
- case AVG:
- case SUM:
- return ColumnType.DOUBLE;
- case MAX:
- case MIN:
- return type;
- default:
- return type;
- }
- }
-
- public SelectItem createSelectItem(Column column) {
- return new SelectItem(this, column);
- }
-
- public SelectItem createSelectItem(String expression, String alias) {
- return new SelectItem(this, expression, alias);
- }
-
- public Object evaluate(Iterable<?> values) {
- AggregateBuilder<?> builder = build();
- for (Object object : values) {
- builder.add(object);
- }
- return builder.getAggregate();
- }
-
- /**
- * Executes the function
- *
- * @param values
- * the values to be evaluated. If a value is null it won't be
- * evaluated
- * @return the result of the function execution. The return type class is
- * dependent on the FunctionType and the values provided. COUNT
- * yields a Long, AVG and SUM yields Double values and MAX and MIN
- * yields the type of the provided values.
- */
- public Object evaluate(Object... values) {
- AggregateBuilder<?> builder = build();
- for (Object object : values) {
- builder.add(object);
- }
- return builder.getAggregate();
- }
-
- public abstract AggregateBuilder<?> build();
-
- public static FunctionType get(String functionName) {
- try {
- return valueOf(functionName);
- } catch (IllegalArgumentException e) {
- return null;
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/GroupByClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/GroupByClause.java b/core/src/main/java/org/eobjects/metamodel/query/GroupByClause.java
deleted file mode 100644
index 8e7e6bd..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/GroupByClause.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * 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.query;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Represents the GROUP BY clause of a query that contains GroupByItem's.
- *
- * @see GroupByItem
- */
-public class GroupByClause extends AbstractQueryClause<GroupByItem> {
-
- private static final long serialVersionUID = -3824934110331202101L;
-
- public GroupByClause(Query query) {
- super(query, AbstractQueryClause.PREFIX_GROUP_BY,
- AbstractQueryClause.DELIM_COMMA);
- }
-
- public List<SelectItem> getEvaluatedSelectItems() {
- final List<SelectItem> result = new ArrayList<SelectItem>();
- final List<GroupByItem> items = getItems();
- for (GroupByItem item : items) {
- result.add(item.getSelectItem());
- }
- return result;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/GroupByItem.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/GroupByItem.java b/core/src/main/java/org/eobjects/metamodel/query/GroupByItem.java
deleted file mode 100644
index cf94623..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/GroupByItem.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- * 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.query;
-
-import java.util.List;
-
-import org.eobjects.metamodel.util.BaseObject;
-
-/**
- * Represents a GROUP BY item. GroupByItems always use a select item (that may
- * or not be a part of the query already) for grouping.
- *
- * @see GroupByClause
- */
-public class GroupByItem extends BaseObject implements QueryItem, Cloneable {
-
- private static final long serialVersionUID = 5218878395877852919L;
- private final SelectItem _selectItem;
- private Query _query;
-
- /**
- * Constructs a GROUP BY item based on a select item that should be grouped.
- *
- * @param selectItem
- */
- public GroupByItem(SelectItem selectItem) {
- if (selectItem == null) {
- throw new IllegalArgumentException("SelectItem cannot be null");
- }
- _selectItem = selectItem;
- }
-
- public SelectItem getSelectItem() {
- return _selectItem;
- }
-
- @Override
- public String toSql() {
- return toSql(false);
- }
-
- @Override
- public String toSql(boolean includeSchemaInColumnPaths) {
- final String sameQueryAlias = _selectItem.getSameQueryAlias(includeSchemaInColumnPaths);
- return sameQueryAlias;
- }
-
- @Override
- public String toString() {
- return toSql();
- }
-
- public Query getQuery() {
- return _query;
- }
-
- public GroupByItem setQuery(Query query) {
- _query = query;
- if (_selectItem != null) {
- _selectItem.setQuery(query);
- }
- return this;
- }
-
- @Override
- protected GroupByItem clone() {
- GroupByItem g = new GroupByItem(_selectItem.clone());
- return g;
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- identifiers.add(_selectItem);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/JoinType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/JoinType.java b/core/src/main/java/org/eobjects/metamodel/query/JoinType.java
deleted file mode 100644
index c40ab0e..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/JoinType.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * 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.query;
-
-/**
- * Represents a join type, used in a FromItem.
- *
- * @see FromItem
- */
-public enum JoinType {
-
- INNER, LEFT, RIGHT;
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/LogicalOperator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/LogicalOperator.java b/core/src/main/java/org/eobjects/metamodel/query/LogicalOperator.java
deleted file mode 100644
index 6a3f13b..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/LogicalOperator.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * 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.query;
-
-/**
- * Represents a logical operator (AND or OR) to use when defining compound
- * {@link FilterItem}s.
- */
-public enum LogicalOperator {
-
- AND, OR
-}
[28/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/ImmutableRef.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/ImmutableRef.java b/core/src/main/java/org/eobjects/metamodel/util/ImmutableRef.java
deleted file mode 100644
index 0e74dc4..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/ImmutableRef.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * 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.util;
-
-/**
- * Simple/hard implementation of the {@link Ref} interface.
- *
- * @author Kasper Sørensen
- *
- * @param <E>
- */
-public final class ImmutableRef<E> implements Ref<E> {
-
- private final E _object;
-
- public ImmutableRef(E object) {
- _object = object;
- }
-
- @Override
- public E get() {
- return _object;
- }
-
- public static <E> Ref<E> of(E object) {
- return new ImmutableRef<E>(object);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/InMemoryResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/InMemoryResource.java b/core/src/main/java/org/eobjects/metamodel/util/InMemoryResource.java
deleted file mode 100644
index 808d4b0..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/InMemoryResource.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/**
- * 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.util;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Serializable;
-
-/**
- * An entirely in-memory kept {@link Resource}.
- */
-public class InMemoryResource implements Resource, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private final String _path;
- private byte[] _contents;
- private long _lastModified;
-
- /**
- * Constructs a new {@link InMemoryResource} with a path/name
- *
- * @param path
- */
- public InMemoryResource(String path) {
- this(path, new byte[0], -1);
- }
-
- /**
- * Constructs a new {@link InMemoryResource} with a path/name and some
- * initial contents.
- *
- * @param path
- * @param contents
- * @param lastModified
- */
- public InMemoryResource(String path, byte[] contents, long lastModified) {
- _path = path;
- _contents = contents;
- _lastModified = lastModified;
- }
-
- @Override
- public String toString() {
- return "InMemoryResource[" + _path + "]";
- }
-
- @Override
- public String getName() {
- String name = _path;
- final int lastSlash = name.lastIndexOf('/');
- final int lastBackSlash = name.lastIndexOf('\\');
- final int lastIndex = Math.max(lastSlash, lastBackSlash);
- if (lastIndex != -1) {
- final String lastPart = name.substring(lastIndex + 1);
- if (!"".equals(lastPart)) {
- return lastPart;
- }
- }
- return name;
- }
-
- /**
- * Gets the path of this resource
- *
- * @return
- */
- public String getPath() {
- return _path;
- }
-
- @Override
- public boolean isReadOnly() {
- return false;
- }
-
- @Override
- public boolean isExists() {
- return true;
- }
-
- @Override
- public long getSize() {
- return _contents.length;
- }
-
- @Override
- public long getLastModified() {
- return _lastModified;
- }
-
- @Override
- public void write(Action<OutputStream> writeCallback) throws ResourceException {
- try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- writeCallback.run(baos);
- _contents = baos.toByteArray();
- _lastModified = System.currentTimeMillis();
- } catch (Exception e) {
- throw new ResourceException(this, e);
- }
- }
-
- @Override
- public void append(Action<OutputStream> appendCallback) throws ResourceException {
- try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- baos.write(_contents);
- appendCallback.run(baos);
- _contents = baos.toByteArray();
- _lastModified = System.currentTimeMillis();
- } catch (Exception e) {
- throw new ResourceException(this, e);
- }
- }
-
- @Override
- public InputStream read() throws ResourceException {
- return new ByteArrayInputStream(_contents);
- }
-
- @Override
- public void read(Action<InputStream> readCallback) throws ResourceException {
- final InputStream inputStream = read();
- try {
- readCallback.run(inputStream);
- } catch (Exception e) {
- throw new ResourceException(this, e);
- }
- }
-
- @Override
- public <E> E read(Func<InputStream, E> readCallback) throws ResourceException {
- final InputStream inputStream = read();
- try {
- return readCallback.eval(inputStream);
- } catch (Exception e) {
- throw new ResourceException(this, e);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/InclusionPredicate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/InclusionPredicate.java b/core/src/main/java/org/eobjects/metamodel/util/InclusionPredicate.java
deleted file mode 100644
index 03bc689..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/InclusionPredicate.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * 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.util;
-
-import java.util.Collection;
-import java.util.Collections;
-
-/**
- * A predicate that uses an inclusion list ("white list") of elements to
- * determine whether to evaluate true or false.
- *
- * @param <E>
- */
-public class InclusionPredicate<E> implements Predicate<E> {
-
- private final Collection<E> _inclusionList;
-
- public InclusionPredicate(Collection<E> inclusionList) {
- _inclusionList = inclusionList;
- }
-
- @Override
- public Boolean eval(E arg) {
- if (_inclusionList.contains(arg)) {
- return true;
- }
- return false;
- }
-
- public Collection<E> getInclusionList() {
- return Collections.unmodifiableCollection(_inclusionList);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/LazyRef.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/LazyRef.java b/core/src/main/java/org/eobjects/metamodel/util/LazyRef.java
deleted file mode 100644
index b916a90..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/LazyRef.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/**
- * 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.util;
-
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Represents a lazy loaded reference.
- *
- * @author Kasper Sørensen
- *
- * @param <E>
- */
-public abstract class LazyRef<E> implements Ref<E> {
-
- private static final Logger logger = LoggerFactory.getLogger(LazyRef.class);
-
- private final AtomicBoolean _fetched = new AtomicBoolean(false);
- private volatile Throwable _error;
- private E _object;
-
- @Override
- public final E get() {
- if (!_fetched.get()) {
- synchronized (_fetched) {
- if (!_fetched.get()) {
- try {
- _object = fetch();
- } catch (Throwable t) {
- _error = t;
- if (t instanceof RuntimeException) {
- throw (RuntimeException) t;
- }
- logger.warn("Failed to fetch value: " + this + ". Reporting error.", t);
- } finally {
- _fetched.set(true);
- }
- }
- }
- }
- return _object;
- }
-
- protected abstract E fetch() throws Throwable;
-
- /**
- * Gets whether the lazy loaded reference has been loaded or not.
- *
- * @return a boolean indicating whether or not the reference has been loaded
- * or not
- */
- public boolean isFetched() {
- return _fetched.get();
- }
-
- /**
- * Gets any error that occurred while fetching the lazy loaded value.
- *
- * @return
- */
- public Throwable getError() {
- return _error;
- }
-
- /**
- * Requests an asynchronous load of the lazy reference. If not already
- * loaded, this will cause another thread to load the reference, typically
- * to make it immediately available for later evaluation.
- *
- * @param errorAction
- * an optional error action to invoke if an exception is thrown
- * during loading of the reference.
- */
- public void requestLoad(final Action<Throwable> errorAction) {
- if (!isFetched()) {
- ExecutorService executorService = SharedExecutorService.get();
- executorService.submit(new Runnable() {
- @Override
- public void run() {
- try {
- get();
- } catch (RuntimeException e) {
- // do nothing, the exception will be handled via _error
- // below
- }
- if (_error != null && errorAction != null) {
- try {
- errorAction.run(_error);
- } catch (Exception e) {
- logger.error("Error handling action failed!", e);
- }
- }
- }
- });
- }
- }
-
- /**
- * Requests an asynchronous load of the lazy reference. If not already
- * loaded, this will cause another thread to load the reference, typically
- * to make it immediately available for later evaluation.
- */
- public void requestLoad() {
- requestLoad(null);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/Month.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/Month.java b/core/src/main/java/org/eobjects/metamodel/util/Month.java
deleted file mode 100644
index 3380e5f..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/Month.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/**
- * 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.util;
-
-import java.util.Calendar;
-
-/**
- * Provides a handy and type-safe enum around the months otherwise defined as
- * int constants in java.util.Calendar.
- *
- * @author Kasper Sørensen
- *
- */
-public enum Month implements HasName {
-
- JANUARY(Calendar.JANUARY),
-
- FEBRUARY(Calendar.FEBRUARY),
-
- MARCH(Calendar.MARCH),
-
- APRIL(Calendar.APRIL),
-
- MAY(Calendar.MAY),
-
- JUNE(Calendar.JUNE),
-
- JULY(Calendar.JULY),
-
- AUGUST(Calendar.AUGUST),
-
- SEPTEMBER(Calendar.SEPTEMBER),
-
- OCTOBER(Calendar.OCTOBER),
-
- NOVEMBER(Calendar.NOVEMBER),
-
- DECEMBER(Calendar.DECEMBER);
-
- private int calendarConstant;
-
- private Month(int calendarConstant) {
- this.calendarConstant = calendarConstant;
- }
-
- public int getCalendarConstant() {
- return calendarConstant;
- }
-
- public static Month getByCalendarConstant(int calendarConstant) {
- for (Month month : values()) {
- if (month.getCalendarConstant() == calendarConstant) {
- return month;
- }
- }
- return null;
- }
-
- public Month next() {
- if (this == DECEMBER) {
- return JANUARY;
- }
- return values()[ordinal() + 1];
- }
-
- public Month previous() {
- if (this == JANUARY) {
- return DECEMBER;
- }
- return values()[ordinal() - 1];
- }
-
- @Override
- public String getName() {
- final String capitalized = toString();
- return capitalized.charAt(0) + capitalized.substring(1).toLowerCase();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/MutableRef.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/MutableRef.java b/core/src/main/java/org/eobjects/metamodel/util/MutableRef.java
deleted file mode 100644
index 3b6175b..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/MutableRef.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * 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.util;
-
-/**
- * Represents a mutable reference to any object
- *
- * @author Kasper Sørensen
- *
- * @param <E>
- */
-public final class MutableRef<E> implements Ref<E> {
-
- private E _object;
-
- public MutableRef() {
- }
-
- public MutableRef(E object) {
- _object = object;
- }
-
- @Override
- public E get() {
- return _object;
- }
-
- public void set(E object) {
- _object = object;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/NumberComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/NumberComparator.java b/core/src/main/java/org/eobjects/metamodel/util/NumberComparator.java
deleted file mode 100644
index 5a1ba02..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/NumberComparator.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/**
- * 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.util;
-
-import java.util.Comparator;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Comparator that can compare numbers of various kinds (short, integer, float,
- * double etc)
- */
-public final class NumberComparator implements Comparator<Object> {
-
- private static final Logger logger = LoggerFactory
- .getLogger(NumberComparator.class);
-
- private static final Comparator<Object> _instance = new NumberComparator();
-
- public static Comparator<Object> getComparator() {
- return _instance;
- }
-
- private NumberComparator() {
- }
-
- public static Comparable<Object> getComparable(Object o) {
- final Number n = toNumber(o);
- return new Comparable<Object>() {
-
- @Override
- public boolean equals(Object obj) {
- return _instance.equals(obj);
- }
-
- public int compareTo(Object o) {
- return _instance.compare(n, o);
- }
-
- @Override
- public String toString() {
- return "NumberComparable[number=" + n + "]";
- }
-
- };
- }
-
- public int compare(Object o1, Object o2) {
- if (o1 == null && o2 == null) {
- return 0;
- }
- if (o1 == null) {
- return -1;
- }
- if (o2 == null) {
- return 1;
- }
- Number n1 = toNumber(o1);
- Number n2 = toNumber(o2);
- return Double.valueOf(n1.doubleValue()).compareTo(n2.doubleValue());
- }
-
- public static Number toNumber(Object value) {
- if (value == null) {
- return null;
- } else if (value instanceof Number) {
- return (Number) value;
- } else if (value instanceof Boolean) {
- if (Boolean.TRUE.equals(value)) {
- return 1;
- } else {
- return 0;
- }
- } else {
- String stringValue = value.toString();
- try {
- return Integer.parseInt(stringValue);
- } catch (NumberFormatException e1) {
- try {
- return Double.parseDouble(stringValue);
- } catch (NumberFormatException e2) {
- logger.warn(
- "Could not convert '{}' to number, returning null",
- value);
- return null;
- }
- }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/ObjectComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/ObjectComparator.java b/core/src/main/java/org/eobjects/metamodel/util/ObjectComparator.java
deleted file mode 100644
index 9b15452..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/ObjectComparator.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/**
- * 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.util;
-
-import java.util.Comparator;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * General purpose comparator to use for objects of various kinds. Prevents
- * NullPointerExceptions and tries to use comparable interface if available and
- * appropriate on incoming objects.
- */
-public final class ObjectComparator implements Comparator<Object> {
-
- private static final Logger logger = LoggerFactory
- .getLogger(ObjectComparator.class);
-
- private static final Comparator<Object> _instance = new ObjectComparator();
-
- public static Comparator<Object> getComparator() {
- return _instance;
- }
-
- private ObjectComparator() {
- }
-
- public static Comparable<Object> getComparable(final Object o) {
- return new Comparable<Object>() {
-
- @Override
- public boolean equals(Object obj) {
- return _instance.equals(obj);
- }
-
- public int compareTo(Object o2) {
- return _instance.compare(o, o2);
- }
-
- @Override
- public String toString() {
- return "ObjectComparable[object=" + o + "]";
- }
- };
- }
-
- @SuppressWarnings("unchecked")
- public int compare(final Object o1, final Object o2) {
- logger.debug("compare({},{})", o1, o2);
- if (o1 == null && o2 == null) {
- return 0;
- }
- if (o1 == null) {
- return -1;
- }
- if (o2 == null) {
- return 1;
- }
- if (o1 instanceof Number && o1 instanceof Number) {
- return NumberComparator.getComparator().compare(o1, o2);
- }
- if (TimeComparator.isTimeBased(o1) && TimeComparator.isTimeBased(o2)) {
- return TimeComparator.getComparator().compare(o1, o2);
- }
- if (BooleanComparator.isBoolean(o1) && BooleanComparator.isBoolean(o2)) {
- return BooleanComparator.getComparator().compare(o1, o2);
- }
- if (o1 instanceof Comparable && o2 instanceof Comparable) {
- @SuppressWarnings("rawtypes")
- Comparable c1 = (Comparable) o1;
- @SuppressWarnings("rawtypes")
- Comparable c2 = (Comparable) o2;
- // We can only count on using the comparable interface if o1 and o2
- // are within of the same class or if one is a subclass of the other
- if (c1.getClass().isAssignableFrom(c2.getClass())) {
- return c1.compareTo(o2);
- }
- if (o2.getClass().isAssignableFrom(c1.getClass())) {
- return -1 * c2.compareTo(o1);
- }
- }
- logger.info("Using ToStringComparator because no apparent better comparison method could be found");
- return ToStringComparator.getComparator().compare(o1, o2);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/Predicate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/Predicate.java b/core/src/main/java/org/eobjects/metamodel/util/Predicate.java
deleted file mode 100644
index 4268c66..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/Predicate.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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.util;
-
-/**
- * A predicate is a special type of {@link Func}, used typically for
- * inclusion/exclusion criteria.
- *
- * @author Kasper Sørensen
- *
- * @param <E>
- */
-public interface Predicate<E> extends Func<E, Boolean> {
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/Ref.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/Ref.java b/core/src/main/java/org/eobjects/metamodel/util/Ref.java
deleted file mode 100644
index 79fc36d..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/Ref.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * 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.util;
-
-/**
- * Represents an abstract reference. This interface enables use of both regular,
- * hard references, soft references and deferred/lazy references.
- *
- * @author Kasper Sørensen
- *
- * @param <E>
- */
-public interface Ref<E> {
-
- public E get();
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/Resource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/Resource.java b/core/src/main/java/org/eobjects/metamodel/util/Resource.java
deleted file mode 100644
index b7a4493..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/Resource.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/**
- * 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.util;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-
-/**
- * Represents a resource from which we can read and write bytes
- */
-public interface Resource extends HasName {
-
- /**
- * Gets the name of the resource, typically a filename or other identifying
- * string
- */
- @Override
- public String getName();
-
- /**
- * Determines if the file is read only, or if writes are also possible.
- *
- * @return
- */
- public boolean isReadOnly();
-
- /**
- * Determines if the resource referenced by this object exists or not.
- *
- * @return
- */
- public boolean isExists();
-
- /**
- * Gets the size (in number of bytes) of this resource's data. An
- * approximated number is allowed.
- *
- * If the size is not determinable without actually reading through the
- * whole contents of the resource, -1 is returned.
- *
- * @return
- */
- public long getSize();
-
- /**
- * Gets the last modified timestamp value (measured in milliseconds since
- * the epoch (00:00:00 GMT, January 1, 1970)) of the resource, if available.
- * If the last modified date is not available, -1 is returned.
- *
- * @return
- */
- public long getLastModified();
-
- /**
- * Opens up an {@link OutputStream} to write to the resource, and allows a
- * callback to perform writing actions on it.
- *
- * @param writeCallback
- * a callback which should define what to write to the resource.
- *
- * @throws ResourceException
- * if an error occurs while writing
- */
- public void write(Action<OutputStream> writeCallback) throws ResourceException;
-
- /**
- * Opens up an {@link InputStream} to append (write at the end of the
- * existing stream) to the resource.
- *
- * @param appendCallback
- * a callback which should define what to append to the resource.
- * @throws ResourceException
- * if an error occurs while appending
- */
- public void append(Action<OutputStream> appendCallback) throws ResourceException;
-
- /**
- * Opens up an {@link InputStream} to read from the resource. Consumers of
- * this method are expected to invoke the {@link InputStream#close()} method
- * manually.
- *
- * If possible, the other read(...) methods are preferred over this one,
- * since they guarantee proper closing of the resource's handles.
- *
- * @return
- * @throws ResourceException
- */
- public InputStream read() throws ResourceException;
-
- /**
- * Opens up an {@link InputStream} to read from the resource, and allows a
- * callback to perform writing actions on it.
- *
- * @param readCallback
- *
- * @throws ResourceException
- * if an error occurs while reading
- */
- public void read(Action<InputStream> readCallback) throws ResourceException;
-
- /**
- * Opens up an {@link InputStream} to read from the resource, and allows a
- * callback function to perform writing actions on it and return the
- * function's result.
- *
- * @param readCallback
- * @return the result of the function
- *
- * @throws ResourceException
- * if an error occurs while reading
- */
- public <E> E read(Func<InputStream, E> readCallback) throws ResourceException;
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/ResourceException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/ResourceException.java b/core/src/main/java/org/eobjects/metamodel/util/ResourceException.java
deleted file mode 100644
index 2cca99b..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/ResourceException.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * 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.util;
-
-import org.eobjects.metamodel.MetaModelException;
-
-/**
- * Exception type for errors that occur while dealing with {@link Resource}s.
- */
-public class ResourceException extends MetaModelException {
-
- private static final long serialVersionUID = 1L;
-
- private final Resource _resource;
-
- public ResourceException(Resource resource, Exception cause) {
- super(cause);
- _resource = resource;
- }
-
- public ResourceException(Resource resource,String message, Exception cause) {
- super(message, cause);
- _resource = resource;
- }
-
- public ResourceException(Resource resource,String message) {
- super(message);
- _resource = resource;
- }
-
- public Resource getResource() {
- return _resource;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/SerializableRef.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/SerializableRef.java b/core/src/main/java/org/eobjects/metamodel/util/SerializableRef.java
deleted file mode 100644
index fac401e..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/SerializableRef.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * 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.util;
-
-import java.io.Serializable;
-
-/**
- * A serializable reference to an object which may or may not be serializable.
- * Using this reference there is safety that if the object IS serializable, it
- * will be serialized, or otherwise it will be gracefully ignored.
- *
- * @param <E>
- */
-public final class SerializableRef<E> implements Ref<E>, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private final E _serializableObj;
- private final transient E _transientObj;
-
- public SerializableRef(E obj) {
- if (obj instanceof Serializable) {
- _serializableObj = obj;
- _transientObj = null;
- } else {
- _serializableObj = null;
- _transientObj = obj;
- }
- }
-
- @Override
- public E get() {
- if (_serializableObj == null) {
- return _transientObj;
- }
- return _serializableObj;
- }
-
- public boolean isSerializing() {
- return _serializableObj != null;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((_serializableObj == null) ? 0 : _serializableObj.hashCode());
- result = prime * result + ((_transientObj == null) ? 0 : _transientObj.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- SerializableRef<?> other = (SerializableRef<?>) obj;
- if (_serializableObj == null) {
- if (other._serializableObj != null)
- return false;
- } else if (!_serializableObj.equals(other._serializableObj))
- return false;
- if (_transientObj == null) {
- if (other._transientObj != null)
- return false;
- } else if (!_transientObj.equals(other._transientObj))
- return false;
- return true;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/SharedExecutorService.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/SharedExecutorService.java b/core/src/main/java/org/eobjects/metamodel/util/SharedExecutorService.java
deleted file mode 100644
index e8f4e40..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/SharedExecutorService.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * 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.util;
-
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * A shared {@link ExecutorService} for use on ad-hoc tasks that can be
- * optimized by running operations in parallel.
- *
- * Note that since this {@link ExecutorService} is shared, it is not recommended
- * to use it for dedicated tasks or daemon-like long-running tasks.
- *
- * @author Kasper Sørensen
- */
-public final class SharedExecutorService {
-
- /**
- * A custom thread factory that creates daemon threads.
- */
- private static final class ThreadFactoryImpl implements ThreadFactory {
-
- private static final AtomicInteger counter = new AtomicInteger(0);
-
- private final ThreadGroup _threadGroup;
-
- public ThreadFactoryImpl() {
- SecurityManager s = System.getSecurityManager();
- _threadGroup = (s != null) ? s.getThreadGroup() : Thread
- .currentThread().getThreadGroup();
- }
-
- @Override
- public Thread newThread(Runnable r) {
- Thread thread = new Thread(_threadGroup, r,
- "MetaModel.SharedExecutorService.Thread."
- + counter.incrementAndGet());
- thread.setDaemon(true);
- thread.setPriority(Thread.NORM_PRIORITY);
- return thread;
- }
- }
-
- private static final ExecutorService executor = Executors
- .newCachedThreadPool(new ThreadFactoryImpl());
-
- private SharedExecutorService() {
- // prevent instantiation
- }
-
- /**
- * Gets the shared {@link ExecutorService}.
- *
- * @return an {@link ExecutorService} for shared usage.
- */
- public static final ExecutorService get() {
- return executor;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/SimpleTableDef.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/SimpleTableDef.java b/core/src/main/java/org/eobjects/metamodel/util/SimpleTableDef.java
deleted file mode 100644
index 1739e95..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/SimpleTableDef.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/**
- * 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.util;
-
-import java.io.Serializable;
-import java.util.Arrays;
-
-import org.eobjects.metamodel.DataContext;
-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.Table;
-import org.eobjects.metamodel.schema.TableType;
-
-/**
- * Represents a table definition to be used in scenarios where a
- * {@link DataContext} is unable to detect/discover the table structure and
- * needs some basic input around expected table structures.
- *
- * @author Kasper Sørensen
- */
-public class SimpleTableDef implements Serializable, HasName {
-
- private static final long serialVersionUID = 1L;
-
- private final String _name;
- private final String[] _columnNames;
- private final ColumnType[] _columnTypes;
-
- /**
- * Constructs a {@link SimpleTableDef} using a {@link Table} as a prototype.
- *
- * @param table
- */
- public SimpleTableDef(Table table) {
- _name = table.getName();
- _columnNames = new String[table.getColumnCount()];
- _columnTypes = new ColumnType[table.getColumnCount()];
- for (int i = 0; i < table.getColumnCount(); i++) {
- Column column = table.getColumn(i);
- _columnNames[i] = column.getName();
- _columnTypes[i] = column.getType();
- }
- }
-
- /**
- * Constructs a {@link SimpleTableDef}.
- *
- * @param name
- * the name of the table
- * @param columnNames
- * the names of the columns to include in the table
- */
- public SimpleTableDef(String name, String[] columnNames) {
- this(name, columnNames, null);
- }
-
- /**
- * Constructs a {@link SimpleTableDef}.
- *
- * @param name
- * the name of table
- * @param columnNames
- * the names of the columns to include in the table
- * @param columnTypes
- * the column types of the columns specified.
- */
- public SimpleTableDef(String name, String[] columnNames, ColumnType[] columnTypes) {
- _name = name;
- _columnNames = columnNames;
- if (columnTypes == null) {
- columnTypes = new ColumnType[columnNames.length];
- for (int i = 0; i < columnTypes.length; i++) {
- columnTypes[i] = ColumnType.VARCHAR;
- }
- } else {
- if (columnNames.length != columnTypes.length) {
- throw new IllegalArgumentException(
- "Property names and column types cannot have different lengths (found " + columnNames.length
- + " and " + columnTypes.length + ")");
- }
- }
- _columnTypes = columnTypes;
- }
-
- /**
- * Gets the name of the table
- *
- * @return the name of the table
- */
- public String getName() {
- return _name;
- }
-
- /**
- * Gets the names of the columns in the table
- *
- * @return the names of the columns in the table
- */
- public String[] getColumnNames() {
- return _columnNames;
- }
-
- /**
- * Gets the types of the columns in the table
- *
- * @return the types of the columns in the table
- */
- public ColumnType[] getColumnTypes() {
- return _columnTypes;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((_name == null) ? 0 : _name.hashCode());
- result = prime * result + Arrays.hashCode(_columnTypes);
- result = prime * result + Arrays.hashCode(_columnNames);
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- SimpleTableDef other = (SimpleTableDef) obj;
- if (_name == null) {
- if (other._name != null)
- return false;
- } else if (!_name.equals(other._name))
- return false;
- if (!Arrays.equals(_columnTypes, other._columnTypes))
- return false;
- if (!Arrays.equals(_columnNames, other._columnNames))
- return false;
- return true;
- }
-
- @Override
- public String toString() {
- return "SimpleDbTableDef[name=" + _name + ",columnNames=" + Arrays.toString(_columnNames) + ",columnTypes="
- + Arrays.toString(_columnTypes) + "]";
- }
-
- /**
- * Creates a {@link MutableTable} based on this {@link SimpleTableDef}. Note
- * that the created table will not have any schema set.
- *
- * @return a table representation of this table definition.
- */
- public MutableTable toTable() {
- String name = getName();
- String[] columnNames = getColumnNames();
- ColumnType[] columnTypes = getColumnTypes();
-
- MutableTable table = new MutableTable(name, TableType.TABLE);
-
- for (int i = 0; i < columnNames.length; i++) {
- table.addColumn(new MutableColumn(columnNames[i], columnTypes[i], table, i, true));
- }
- return table;
- }
-
- /**
- * Gets the index of a column name, or -1 if the column name does not exist
- *
- * @param columnName
- * @return
- */
- public int indexOf(String columnName) {
- if (columnName == null) {
- throw new IllegalArgumentException("Column name cannot be null");
- }
- for (int i = 0; i < _columnNames.length; i++) {
- if (columnName.equals(_columnNames[i])) {
- return i;
- }
- }
- return -1;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/TimeComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/TimeComparator.java b/core/src/main/java/org/eobjects/metamodel/util/TimeComparator.java
deleted file mode 100644
index 5601deb..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/TimeComparator.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/**
- * 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.util;
-
-import java.text.DateFormat;
-import java.text.DateFormatSymbols;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.Locale;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Compares dates of various formats. Since this class has unchecked generic
- * conversion it can compare java.util.Date, java.sql.Date, java.sql.Time,
- * java.util.Calendar, Date-formatted strings etc.
- */
-public final class TimeComparator implements Comparator<Object> {
-
- private static final Logger logger = LoggerFactory.getLogger(TimeComparator.class);
-
- private static final String[] prototypePatterns = { "yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd HH:mm:ss",
- "yyyy-MM-dd HH:mm", "HH:mm:ss.SSS", "yyyy-MM-dd", "dd-MM-yyyy", "yy-MM-dd", "MM-dd-yyyy", "HH:mm:ss",
- "HH:mm" };
-
- private static final Comparator<Object> _instance = new TimeComparator();
-
- public static Comparator<Object> getComparator() {
- return _instance;
- }
-
- private TimeComparator() {
- }
-
- public static Comparable<Object> getComparable(final Object o) {
- final Date dt1 = toDate(o);
- return new Comparable<Object>() {
-
- @Override
- public boolean equals(Object obj) {
- return _instance.equals(obj);
- }
-
- public int compareTo(Object o) {
- return _instance.compare(dt1, o);
- }
-
- @Override
- public String toString() {
- return "TimeComparable[time=" + dt1 + "]";
- }
- };
- }
-
- public int compare(final Object o1, final Object o2) {
- if (o1 == null && o2 == null) {
- return 0;
- }
- if (o1 == null) {
- return -1;
- }
- if (o2 == null) {
- return 1;
- }
- try {
- Date dt1 = toDate(o1);
- Date dt2 = toDate(o2);
- return dt1.compareTo(dt2);
- } catch (Exception e) {
- logger.error("Could not compare {} and {}", o1, o2);
- throw new RuntimeException(e);
- }
- }
-
- public static Date toDate(final Object value) {
- Date result = null;
- if (value == null) {
- result = null;
- } else if (value instanceof Date) {
- result = (Date) value;
- } else if (value instanceof Calendar) {
- result = ((Calendar) value).getTime();
- } else if (value instanceof String) {
- result = convertFromString((String) value);
- } else if (value instanceof Number) {
- result = convertFromNumber((Number) value);
- }
-
- if (result == null) {
- logger.warn("Could not convert '{}' to date, returning null", value);
- }
-
- return result;
- }
-
- public static boolean isTimeBased(Object o) {
- if (o instanceof Date || o instanceof Calendar) {
- return true;
- }
- return false;
- }
-
- private static Date convertFromString(final String value) {
- try {
- long longValue = Long.parseLong(value);
- return convertFromNumber(longValue);
- } catch (NumberFormatException e) {
- // do nothing, proceed to dateFormat parsing
- }
-
- // try with Date.toString() date format first
- try {
- DateFormatSymbols dateFormatSymbols = DateFormatSymbols.getInstance(Locale.US);
- SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", dateFormatSymbols);
- return dateFormat.parse(value);
- } catch (ParseException e) {
- // do noting
- }
-
- for (String prototypePattern : prototypePatterns) {
- if (prototypePattern.length() == value.length()) {
- DateFormat dateFormat;
- try {
- dateFormat = DateUtils.createDateFormat(prototypePattern);
- return dateFormat.parse(value);
- } catch (Exception e) {
- // proceed to next formatter
- }
-
- if (prototypePattern.indexOf('-') != -1) {
- // try with '.' in stead of '-'
- try {
- dateFormat = DateUtils.createDateFormat(prototypePattern.replaceAll("\\-", "\\."));
- return dateFormat.parse(value);
- } catch (Exception e) {
- // proceed to next formatter
- }
-
- // try with '/' in stead of '-'
- try {
- dateFormat = DateUtils.createDateFormat(prototypePattern.replaceAll("\\-", "\\/"));
- return dateFormat.parse(value);
- } catch (Exception e) {
- // proceed to next formatter
- }
- }
- }
-
- }
-
- return null;
- }
-
- private static Date convertFromNumber(Number value) {
- Number numberValue = (Number) value;
- long longValue = numberValue.longValue();
-
- String stringValue = Long.toString(longValue);
- // test if the number is actually a format of the type yyyyMMdd
- if (stringValue.length() == 8 && (stringValue.startsWith("1") || stringValue.startsWith("2"))) {
- try {
- return DateUtils.createDateFormat("yyyyMMdd").parse(stringValue);
- } catch (Exception e) {
- // do nothing, proceed to next method of conversion
- }
- }
-
- // test if the number is actually a format of the type yyMMdd
- if (stringValue.length() == 6) {
- try {
- return DateUtils.createDateFormat("yyMMdd").parse(stringValue);
- } catch (Exception e) {
- // do nothing, proceed to next method of conversion
- }
- }
-
- if (longValue > 5000000) {
- // this number is most probably amount of milliseconds since
- // 1970
- return new Date(longValue);
- } else {
- // this number is most probably the amount of days since
- // 1970
- return new Date(longValue * 1000 * 60 * 60 * 24);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/ToStringComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/ToStringComparator.java b/core/src/main/java/org/eobjects/metamodel/util/ToStringComparator.java
deleted file mode 100644
index cfca4c5..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/ToStringComparator.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * 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.util;
-
-import java.util.Comparator;
-
-/**
- * Uses the toString method for comparison of objects
- */
-public final class ToStringComparator implements Comparator<Object> {
-
- private static Comparator<Object> _instance = new ToStringComparator();
-
- public static Comparator<Object> getComparator() {
- return _instance;
- }
-
- private ToStringComparator() {
- }
-
- public static Comparable<Object> getComparable(final Object o) {
- final String s = o.toString();
- return new Comparable<Object>() {
-
- @Override
- public boolean equals(Object obj) {
- return _instance.equals(obj);
- }
-
- public int compareTo(Object o2) {
- return _instance.compare(s, o2);
- }
-
- @Override
- public String toString() {
- return "ToStringComparable[string=" + s + "]";
- }
- };
- }
-
- public int compare(Object o1, Object o2) {
- if (o1 == null && o2 == null) {
- return -1;
- }
- if (o1 == null) {
- return -1;
- }
- if (o2 == null) {
- return 1;
- }
- return o1.toString().compareTo(o2.toString());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/TruePredicate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/TruePredicate.java b/core/src/main/java/org/eobjects/metamodel/util/TruePredicate.java
deleted file mode 100644
index f99ed6d..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/TruePredicate.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * 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.util;
-
-import java.io.Serializable;
-
-/**
- * A predicate that is always true
- *
- * @param <E>
- */
-public final class TruePredicate<E> implements Predicate<E>, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public Boolean eval(E arg) {
- return true;
- }
-
- @Override
- public int hashCode() {
- return Boolean.TRUE.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- return obj != null && obj.getClass() == TruePredicate.class;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/UnicodeWriter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/UnicodeWriter.java b/core/src/main/java/org/eobjects/metamodel/util/UnicodeWriter.java
deleted file mode 100644
index c95f381..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/UnicodeWriter.java
+++ /dev/null
@@ -1,236 +0,0 @@
-/**
- * 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.util;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-
-/**
- * Writes Unicode text to an output stream. If the specified encoding is a
- * Unicode, then the text is preceeded by the proper Unicode BOM. If it is any
- * other encoding, this class behaves just like <code>OutputStreamWriter</code>.
- * This class is here because Java's <code>OutputStreamWriter</code> apparently
- * doesn't believe in writing BOMs.
- * <p>
- *
- * For optimum performance, it is recommended that you wrap all instances of
- * <code>UnicodeWriter</code> with a <code>java.io.BufferedWriter</code>.
- *
- * This file is a redistribution of Rubert Futrell from FifeSoft UnicodeWriter
- * (also LGPL licensed).
- *
- * <pre>
- * UnicodeWriter.java - Writes Unicode output with the proper BOM.
- * Copyright (C) 2004 Robert Futrell
- * robert_futrell at users.sourceforge.net
- * http://fifesoft.com/rsyntaxtextarea
- * </pre>
- *
- * @author Robert Futrell
- * @version 0.7
- */
-public class UnicodeWriter extends Writer {
-
- public static final byte[] UTF8_BOM = new byte[] { (byte) 0xEF,
- (byte) 0xBB, (byte) 0xBF };
-
- public static final byte[] UTF16LE_BOM = new byte[] { (byte) 0xFF,
- (byte) 0xFE };
-
- public static final byte[] UTF16BE_BOM = new byte[] { (byte) 0xFE,
- (byte) 0xFF };
-
- public static final byte[] UTF32LE_BOM = new byte[] { (byte) 0xFF,
- (byte) 0xFE, (byte) 0x00, (byte) 0x00 };
-
- public static final byte[] UTF32BE_BOM = new byte[] { (byte) 0x00,
- (byte) 0x00, (byte) 0xFE, (byte) 0xFF };
-
- /**
- * The writer actually doing the writing.
- */
- private final OutputStreamWriter writer;
-
- /**
- * This is a utility constructor since the vast majority of the time, this
- * class will be used to write Unicode files.
- *
- * @param fileName
- * The file to which to write the Unicode output.
- * @param encoding
- * The encoding to use.
- * @throws UnsupportedEncodingException
- * If the specified encoding is not supported.
- * @throws IOException
- * If an IO exception occurs.
- */
- public UnicodeWriter(String fileName, String encoding)
- throws UnsupportedEncodingException, IOException {
- this(new FileOutputStream(fileName), encoding);
- }
-
- /**
- * This is a utility constructor since the vast majority of the time, this
- * class will be used to write Unicode files.
- *
- * @param file
- * The file to which to write the Unicode output.
- * @param encoding
- * The encoding to use.
- * @throws UnsupportedEncodingException
- * If the specified encoding is not supported.
- * @throws IOException
- * If an IO exception occurs.
- */
- public UnicodeWriter(File file, String encoding)
- throws UnsupportedEncodingException, IOException {
- this(new FileOutputStream(file), encoding);
- }
-
- /**
- * Creates a new writer.
- *
- * @param outputStream
- * The output stream to write.
- * @param encoding
- * The encoding to use.
- * @throws UnsupportedEncodingException
- * If the specified encoding is not supported.
- * @throws IOException
- * If an IO exception occurs.
- */
- public UnicodeWriter(OutputStream outputStream, String encoding)
- throws UnsupportedEncodingException, IOException {
- writer = createWriter(outputStream, encoding);
- }
-
- /**
- * Closes this writer.
- *
- * @throws IOException
- * If an IO exception occurs.
- */
- @Override
- public void close() throws IOException {
- writer.close();
- }
-
- /**
- * Flushes the stream.
- *
- * @throws IOException
- * If an IO exception occurs.
- */
- @Override
- public void flush() throws IOException {
- writer.flush();
- }
-
- /**
- * Initializes the internal output stream and writes the BOM if the
- * specified encoding is a Unicode encoding.
- *
- * @param outputStream
- * The output stream we are writing.
- * @param encoding
- * The encoding in which to write.
- * @throws UnsupportedEncodingException
- * If the specified encoding isn't supported.
- * @throws IOException
- * If an I/O error occurs while writing a BOM.
- */
- private OutputStreamWriter createWriter(OutputStream outputStream,
- String encoding) throws UnsupportedEncodingException, IOException {
- OutputStreamWriter writer = new OutputStreamWriter(outputStream,
- encoding);
-
- // Write the proper BOM if they specified a Unicode encoding.
- // NOTE: Creating an OutputStreamWriter with encoding "UTF-16"
- // DOES write out the BOM; "UTF-16LE", "UTF-16BE", "UTF-32", "UTF-32LE"
- // and "UTF-32BE" don't.
- if ("UTF-8".equalsIgnoreCase(encoding)) {
- outputStream.write(UTF8_BOM, 0, UTF8_BOM.length);
- } else if ("UTF-16LE".equalsIgnoreCase(encoding)) {
- outputStream.write(UTF16LE_BOM, 0, UTF16LE_BOM.length);
- } else if (/* "UTF-16".equalsIgnoreCase(encoding) || */
- "UTF-16BE".equalsIgnoreCase(encoding)) {
- outputStream.write(UTF16BE_BOM, 0, UTF16BE_BOM.length);
- } else if ("UTF-32LE".equalsIgnoreCase(encoding)) {
- outputStream.write(UTF32LE_BOM, 0, UTF32LE_BOM.length);
- } else if ("UTF-32".equalsIgnoreCase(encoding)
- || "UTF-32BE".equalsIgnoreCase(encoding)) {
- outputStream.write(UTF32BE_BOM, 0, UTF32BE_BOM.length);
- }
-
- return writer;
- }
-
- /**
- * Writes a portion of an array of characters.
- *
- * @param cbuf
- * The buffer of characters.
- * @param off
- * The offset from which to start writing characters.
- * @param len
- * The number of characters to write.
- * @throws IOException
- * If an I/O error occurs.
- */
- @Override
- public void write(char[] cbuf, int off, int len) throws IOException {
- writer.write(cbuf, off, len);
- }
-
- /**
- * Writes a single character.
- *
- * @param c
- * An integer specifying the character to write.
- * @throws IOException
- * If an IO error occurs.
- */
- @Override
- public void write(int c) throws IOException {
- writer.write(c);
- }
-
- /**
- * Writes a portion of a string.
- *
- * @param str
- * The string from which to write.
- * @param off
- * The offset from which to start writing characters.
- * @param len
- * The number of characters to write.
- * @throws IOException
- * If an IO error occurs.
- */
- @Override
- public void write(String str, int off, int len) throws IOException {
- writer.write(str, off, len);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/UrlResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/UrlResource.java b/core/src/main/java/org/eobjects/metamodel/util/UrlResource.java
deleted file mode 100644
index c79980a..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/UrlResource.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/**
- * 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.util;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Serializable;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-
-/**
- * Resource based on URL or URI.
- */
-public class UrlResource implements Resource, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private final URI _uri;
-
- public UrlResource(URL url) {
- try {
- _uri = url.toURI();
- } catch (URISyntaxException e) {
- throw new IllegalStateException(e);
- }
- }
-
- public UrlResource(URI uri) {
- _uri = uri;
- }
-
- public UrlResource(String urlString) {
- try {
- _uri = new URI(urlString);
- } catch (URISyntaxException e) {
- throw new IllegalStateException(e);
- }
- }
-
- @Override
- public String toString() {
- return "UrlResource[" + _uri + "]";
- }
-
- /**
- * Gets the URI associated with this resource.
- *
- * @return
- */
- public URI getUri() {
- return _uri;
- }
-
- @Override
- public String getName() {
- final String name = _uri.toString();
- final int lastSlash = name.lastIndexOf('/');
- final int lastBackSlash = name.lastIndexOf('\\');
- final int lastIndex = Math.max(lastSlash, lastBackSlash);
- if (lastIndex != -1) {
- final String lastPart = name.substring(lastIndex + 1);
- if (!"".equals(lastPart)) {
- return lastPart;
- }
- }
- return name;
- }
-
- @Override
- public boolean isReadOnly() {
- return true;
- }
-
- @Override
- public void write(Action<OutputStream> writeCallback) throws ResourceException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void append(Action<OutputStream> appendCallback) throws ResourceException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void read(Action<InputStream> readCallback) throws ResourceException {
- final InputStream in = read();
- try {
- readCallback.run(in);
- } catch (Exception e) {
- throw new ResourceException(this, "Error occurred in read callback", e);
- } finally {
- FileHelper.safeClose(in);
- }
- }
-
- @Override
- public <E> E read(Func<InputStream, E> readCallback) throws ResourceException {
- final InputStream in = read();
- try {
- E result = readCallback.eval(in);
- return result;
- } catch (Exception e) {
- throw new ResourceException(this, "Error occurred in read callback", e);
- } finally {
- FileHelper.safeClose(in);
- }
- }
-
- @Override
- public boolean isExists() {
- return true;
- }
-
- @Override
- public long getSize() {
- return -1;
- }
-
- @Override
- public long getLastModified() {
- return -1;
- }
-
- @Override
- public InputStream read() throws ResourceException {
- try {
- return _uri.toURL().openStream();
- } catch (Exception e) {
- throw new ResourceException(this, "Failed to open InputStream", e);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/Weekday.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/Weekday.java b/core/src/main/java/org/eobjects/metamodel/util/Weekday.java
deleted file mode 100644
index d9ab224..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/Weekday.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/**
- * 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.util;
-
-import java.util.Calendar;
-
-/**
- * Provides a handy and type-safe enum around the weekdays otherwise defined as
- * int constants in java.util.Calendar.
- *
- * @author Kasper Sørensen
- */
-public enum Weekday implements HasName {
-
- MONDAY(Calendar.MONDAY),
-
- TUESDAY(Calendar.TUESDAY),
-
- WEDNESDAY(Calendar.WEDNESDAY),
-
- THURSDAY(Calendar.THURSDAY),
-
- FRIDAY(Calendar.FRIDAY),
-
- SATURDAY(Calendar.SATURDAY),
-
- SUNDAY(Calendar.SUNDAY);
-
- private int calendarConstant;
-
- private Weekday(int calendarConstant) {
- this.calendarConstant = calendarConstant;
- }
-
- public int getCalendarConstant() {
- return calendarConstant;
- }
-
- public static Weekday getByCalendarConstant(int calendarConstant) {
- for (Weekday weekday : values()) {
- if (weekday.getCalendarConstant() == calendarConstant) {
- return weekday;
- }
- }
- return null;
- }
-
- public Weekday next() {
- if (this == SUNDAY) {
- return MONDAY;
- }
- return values()[ordinal() + 1];
- }
-
- public Weekday previous() {
- if (this == MONDAY) {
- return SUNDAY;
- }
- return values()[ordinal() - 1];
- }
-
- @Override
- public String getName() {
- final String capitalized = toString();
- return capitalized.charAt(0) + capitalized.substring(1).toLowerCase();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/WildcardPattern.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/WildcardPattern.java b/core/src/main/java/org/eobjects/metamodel/util/WildcardPattern.java
deleted file mode 100644
index 36f388a..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/WildcardPattern.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * 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.util;
-
-import java.io.Serializable;
-import java.util.StringTokenizer;
-
-import org.eobjects.metamodel.query.FilterItem;
-
-/**
- * Represents a pattern with a wildcard character. These are typically used in
- * FilterItems with the LIKE operator.
- *
- * @see FilterItem
- */
-public final class WildcardPattern implements Serializable {
-
- private static final long serialVersionUID = 857462137797209624L;
- private String _pattern;
- private char _wildcard;
- private boolean _endsWithDelim;
-
- public WildcardPattern(String pattern, char wildcard) {
- _pattern = pattern;
- _wildcard = wildcard;
- _endsWithDelim = (_pattern.charAt(pattern.length() - 1) == _wildcard);
- }
-
- public boolean matches(String value) {
- if (value == null) {
- return false;
- }
- StringTokenizer st = new StringTokenizer(_pattern,
- Character.toString(_wildcard));
- int charIndex = 0;
- while (st.hasMoreTokens()) {
- String token = st.nextToken();
- charIndex = value.indexOf(token, charIndex);
- if (charIndex == -1) {
- return false;
- }
- charIndex = charIndex + token.length();
- }
- if (!_endsWithDelim) {
- // Unless the last char of the pattern is a wildcard, we need to
- // have reached the end of the string
- if (charIndex != value.length()) {
- return false;
- }
- }
- return true;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/package-info.java b/core/src/main/java/org/eobjects/metamodel/util/package-info.java
deleted file mode 100644
index 5130e4d..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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.
- */
-/**
- * Utilities and convenient classes
- */
-package org.eobjects.metamodel.util;
-
[03/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/test/integrationtests/org/apache/metamodel/PostgresqlTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/apache/metamodel/PostgresqlTest.java b/jdbc/src/test/integrationtests/org/apache/metamodel/PostgresqlTest.java
new file mode 100644
index 0000000..9c8cf34
--- /dev/null
+++ b/jdbc/src/test/integrationtests/org/apache/metamodel/PostgresqlTest.java
@@ -0,0 +1,810 @@
+package org.eobjects.metamodel;
+
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.swing.table.TableModel;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.DataSetTableModel;
+import org.eobjects.metamodel.insert.RowInsertionBuilder;
+import org.eobjects.metamodel.jdbc.JdbcDataContext;
+import org.eobjects.metamodel.jdbc.JdbcTestTemplates;
+import org.eobjects.metamodel.jdbc.QuerySplitter;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.FunctionType;
+import org.eobjects.metamodel.query.OperatorType;
+import org.eobjects.metamodel.query.OrderByItem;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.Relationship;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.junit.Ignore;
+
+/**
+ * Test case that tests postgresql interaction. The test requires the
+ * "dellstore2" sample database that can be found at pgfoundry.
+ *
+ * @see http://pgfoundry.org/projects/dbsamples/
+ */
+public class PostgresqlTest extends TestCase {
+
+ private static final String CONNECTION_STRING = "jdbc:postgresql://localhost/dellstore2";
+ private static final String USERNAME = "eobjects";
+ private static final String PASSWORD = "eobjects";
+ private Connection _connection;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ Class.forName("org.postgresql.Driver");
+ _connection = DriverManager.getConnection(CONNECTION_STRING, USERNAME, PASSWORD);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ _connection.close();
+ }
+
+ public void testInterpretationOfNull() throws Exception {
+ JdbcTestTemplates.interpretationOfNulls(_connection);
+ }
+
+ private JdbcDataContext createLimitAndOffsetTestData() {
+ final JdbcDataContext dc = new JdbcDataContext(_connection);
+
+ if (dc.getTableByQualifiedLabel("test_table") != null) {
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.dropTable("test_table").execute();
+ }
+ });
+ }
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ Table table = callback.createTable(dc.getDefaultSchema(), "test_table").withColumn("foo")
+ .ofType(ColumnType.INTEGER).withColumn("bar").ofType(ColumnType.VARCHAR).execute();
+ callback.insertInto(table).value("foo", 1).value("bar", "hello").execute();
+ callback.insertInto(table).value("foo", 2).value("bar", "there").execute();
+ callback.insertInto(table).value("foo", 3).value("bar", "world").execute();
+ }
+ });
+
+ dc.refreshSchemas();
+
+ return dc;
+ }
+
+ public void testLimit() throws Exception {
+ JdbcDataContext dc = createLimitAndOffsetTestData();
+ Schema schema = dc.getDefaultSchema();
+ Table productsTable = schema.getTableByName("test_table");
+
+ DataSet ds = dc.query().from(productsTable).select("foo").limit(2).execute();
+ assertTrue(ds.next());
+ assertEquals("Row[values=[1]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[2]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ ds.close();
+ }
+
+ public void testOffset() throws Exception {
+ JdbcDataContext dc = createLimitAndOffsetTestData();
+ Schema schema = dc.getDefaultSchema();
+ Table productsTable = schema.getTableByName("test_table");
+
+ DataSet ds = dc.query().from(productsTable).select("foo").offset(1).execute();
+ assertTrue(ds.next());
+ assertEquals("Row[values=[2]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[3]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ ds.close();
+ }
+
+ public void testLimitAndOffset() throws Exception {
+ JdbcDataContext dc = createLimitAndOffsetTestData();
+ Schema schema = dc.getDefaultSchema();
+ Table productsTable = schema.getTableByName("test_table");
+
+ DataSet ds = dc.query().from(productsTable).select("foo").limit(1).offset(1).execute();
+ assertTrue(ds.next());
+ assertEquals("Row[values=[2]]", ds.getRow().toString());
+ assertFalse(ds.next());
+
+ ds.close();
+ }
+
+ public void testQuotedInsertSyntax() throws Exception {
+ try {
+ _connection.createStatement().execute("DROP TABLE my_table");
+ } catch (Exception e) {
+ // do nothing
+ }
+
+ JdbcDataContext dc = new JdbcDataContext(_connection);
+ final Schema schema = dc.getDefaultSchema();
+
+ // create table
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ Table table = cb.createTable(schema, "my_table").withColumn("id").asPrimaryKey()
+ .ofType(ColumnType.INTEGER).ofNativeType("SERIAL").nullable(false).withColumn("name")
+ .ofType(ColumnType.VARCHAR).ofSize(10).withColumn("foo").ofType(ColumnType.BOOLEAN)
+ .nullable(true).withColumn("bar").ofType(ColumnType.BOOLEAN).nullable(true).execute();
+
+ assertEquals("my_table", table.getName());
+ }
+ });
+
+ assertTrue(dc.getColumnByQualifiedLabel("my_table.id").isPrimaryKey());
+ assertFalse(dc.getColumnByQualifiedLabel("my_table.name").isPrimaryKey());
+
+ // insert records
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ RowInsertionBuilder builder = callback.insertInto("my_table").value("name", "row 1").value("foo", true);
+
+ try {
+ Method method = builder.getClass().getDeclaredMethod("createSqlStatement");
+ method.setAccessible(true);
+ Object result = method.invoke(builder);
+ assertEquals("INSERT INTO \"public\".\"my_table\" (name,foo) VALUES (?,?)", result.toString());
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ builder.execute();
+
+ callback.insertInto("my_table").value("name", "row 2").value("foo", false).execute();
+ }
+ });
+
+ // query
+ DataSet ds = dc.query().from("my_table").select("name").where("foo").eq(true).execute();
+ assertTrue(ds.next());
+ assertEquals("Row[values=[row 1]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ ds.close();
+
+ // drop
+ dc.executeUpdate(new UpdateScript() {
+
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.dropTable("my_table").execute();
+ }
+ });
+ }
+
+ public void testInsertOfDifferentTypes() throws Exception {
+ try {
+ _connection.createStatement().execute("DROP TABLE my_table");
+ } catch (Exception e) {
+ // do nothing
+ }
+
+ JdbcDataContext dc = new JdbcDataContext(_connection);
+ final Schema schema = dc.getDefaultSchema();
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ Table table = cb.createTable(schema, "my_table").withColumn("id").ofType(ColumnType.INTEGER)
+ .ofNativeType("SERIAL").nullable(false).withColumn("name").ofType(ColumnType.VARCHAR)
+ .ofSize(10).withColumn("foo").ofType(ColumnType.BOOLEAN).nullable(true).withColumn("bar")
+ .ofType(ColumnType.BOOLEAN).nullable(true).execute();
+
+ assertEquals("my_table", table.getName());
+ }
+ });
+
+ try {
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.insertInto("my_table").value("name", "row 1").value("foo", true).execute();
+
+ callback.insertInto("my_table").value("name", "row 2").value("bar", true).execute();
+
+ callback.insertInto("my_table").value("name", "row 3").value("foo", true).execute();
+
+ callback.insertInto("my_table").value("name", "row 4").value("foo", true).execute();
+
+ callback.insertInto("my_table").value("name", "row 5").value("bar", true).execute();
+
+ callback.insertInto("my_table").value("name", "row 6").value("foo", true).value("bar", true)
+ .execute();
+
+ callback.insertInto("my_table").value("name", "row 7").value("foo", true).value("bar", true)
+ .execute();
+
+ callback.insertInto("my_table").value("name", "row 8").value("foo", false).value("bar", false)
+ .execute();
+ }
+ });
+
+ DataSet ds = dc.query().from("my_table").select("id").and("name").execute();
+ assertTrue(ds.next());
+ assertEquals("Row[values=[1, row 1]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[2, row 2]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[3, row 3]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[4, row 4]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[5, row 5]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[6, row 6]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[7, row 7]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[8, row 8]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ ds.close();
+ } finally {
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.dropTable("my_table").execute();
+ }
+ });
+ }
+ }
+
+ /**
+ * Tests some inconsistencies dealing with booleans.
+ *
+ * @see http://eobjects.org/trac/ticket/829
+ */
+ public void testBoolean() throws Exception {
+ JdbcDataContext dc = new JdbcDataContext(_connection);
+
+ final Schema schema = dc.getDefaultSchema();
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ Table table = cb.createTable(schema, "my_table").withColumn("id").ofType(ColumnType.INTEGER)
+ .ofNativeType("SERIAL").nullable(false).withColumn("some_bool").ofType(ColumnType.BOOLEAN)
+ .nullable(false).execute();
+ assertEquals("my_table", table.getName());
+
+ cb.insertInto(table).value("id", 1).value("some_bool", true).execute();
+ cb.insertInto(table).value("id", 2).value("some_bool", false).execute();
+ }
+ });
+
+ DataSet ds = dc.query().from("my_table").select("some_bool").execute();
+
+ assertTrue(ds.next());
+ assertEquals("Row[values=[true]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[false]]", ds.getRow().toString());
+ assertFalse(ds.next());
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ cb.dropTable("my_table").execute();
+ }
+ });
+ }
+
+ public void testBlob() throws Exception {
+ JdbcDataContext dc = new JdbcDataContext(_connection);
+ final Schema schema = dc.getDefaultSchema();
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ Table table = cb.createTable(schema, "my_table").withColumn("id").ofType(ColumnType.INTEGER)
+ .ofNativeType("SERIAL").nullable(false).withColumn("some_bytes").ofType(ColumnType.BLOB)
+ .execute();
+ assertEquals("my_table", table.getName());
+ }
+ });
+
+ try {
+ dc.refreshSchemas();
+ final Column column = dc.getColumnByQualifiedLabel("my_table.some_bytes");
+ assertEquals("Column[name=some_bytes,columnNumber=1,type=BINARY,nullable=true,"
+ + "nativeType=bytea,columnSize=2147483647]", column.toString());
+
+ final Table table = column.getTable();
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.insertInto(table).value(column, new byte[] { 1, 2, 3 }).execute();
+ callback.insertInto(table).value(column, "hello world".getBytes()).execute();
+ }
+ });
+
+ byte[] bytes;
+
+ DataSet ds = dc.query().from(table).select(table.getColumns()).execute();
+
+ assertTrue(ds.next());
+ assertEquals(1, ds.getRow().getValue(0));
+ bytes = (byte[]) ds.getRow().getValue(1);
+ assertEquals(3, bytes.length);
+ assertEquals(1, bytes[0]);
+ assertEquals(2, bytes[1]);
+ assertEquals(3, bytes[2]);
+
+ assertTrue(ds.next());
+ assertEquals(2, ds.getRow().getValue(0));
+ bytes = (byte[]) ds.getRow().getValue(1);
+
+ assertEquals("hello world", new String(bytes));
+ assertFalse(ds.next());
+
+ } finally {
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ cb.dropTable("my_table").execute();
+ }
+ });
+ }
+ }
+
+ public void testCreateTableAndWriteRecords() throws Exception {
+ JdbcDataContext dc = new JdbcDataContext(_connection);
+ final Schema schema = dc.getDefaultSchema();
+ try {
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ Table table = cb.createTable(schema, "my_table").withColumn("id").ofType(ColumnType.INTEGER)
+ .ofNativeType("SERIAL").nullable(false).withColumn("person name").ofSize(255)
+ .withColumn("age").ofType(ColumnType.INTEGER).execute();
+ assertEquals("[id, person name, age]", Arrays.toString(table.getColumnNames()));
+ assertEquals(
+ "Column[name=id,columnNumber=0,type=INTEGER,nullable=false,nativeType=serial,columnSize=10]",
+ table.getColumnByName("id").toString());
+ assertEquals(
+ "Column[name=person name,columnNumber=1,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=255]",
+ table.getColumnByName("person name").toString());
+ assertEquals(
+ "Column[name=age,columnNumber=2,type=INTEGER,nullable=true,nativeType=int4,columnSize=10]",
+ table.getColumnByName("age").toString());
+
+ cb.insertInto(table).value("person name", "John Doe").value("age", 42).execute();
+ cb.insertInto(table).value("age", 43).value("person name", "Jane Doe").execute();
+
+ }
+ });
+
+ final Table table = schema.getTableByName("my_table");
+ Query query = dc.query().from(table).select(table.getColumns()).toQuery();
+ DataSet ds = dc.executeQuery(query);
+ assertTrue(ds.next());
+ assertEquals("Row[values=[1, John Doe, 42]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[2, Jane Doe, 43]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ ds.close();
+
+ dc.executeUpdate(new UpdateScript() {
+
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.update(table).value("age", 102).where("id").eq(1).execute();
+ callback.deleteFrom(table).where("id").eq(2).execute();
+ }
+ });
+
+ ds = dc.executeQuery(query);
+ assertTrue(ds.next());
+ assertEquals("Row[values=[1, John Doe, 102]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ ds.close();
+ } finally {
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.dropTable("my_table").execute();
+ }
+ });
+ assertNull(dc.getTableByQualifiedLabel("my_table"));
+ }
+ }
+
+ public void testCreateTableInsertValueFloatForIntColumn() throws Exception {
+ JdbcDataContext dc = new JdbcDataContext(_connection);
+ final Schema schema = dc.getDefaultSchema();
+ try {
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ Table table = cb.createTable(schema, "my_table").withColumn("id").ofType(ColumnType.INTEGER)
+ .ofNativeType("SERIAL").nullable(false).withColumn("person name").ofSize(255)
+ .withColumn("age").ofType(ColumnType.INTEGER).execute();
+ assertEquals("[id, person name, age]", Arrays.toString(table.getColumnNames()));
+ assertEquals(
+ "Column[name=id,columnNumber=0,type=INTEGER,nullable=false,nativeType=serial,columnSize=10]",
+ table.getColumnByName("id").toString());
+ assertEquals(
+ "Column[name=person name,columnNumber=1,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=255]",
+ table.getColumnByName("person name").toString());
+ assertEquals(
+ "Column[name=age,columnNumber=2,type=INTEGER,nullable=true,nativeType=int4,columnSize=10]",
+ table.getColumnByName("age").toString());
+
+ cb.insertInto(table).value("person name", "John Doe").value("age", 42.4673).execute();
+ cb.insertInto(table).value("age", 43.5673).value("person name", "Jane Doe").execute();
+ }
+ });
+
+ Table table = schema.getTableByName("my_table");
+ Query query = dc.query().from(table).select(table.getColumns()).toQuery();
+ DataSet ds = dc.executeQuery(query);
+ assertTrue(ds.next());
+ // Float value input will be rounded down into integer number.
+ assertEquals("Row[values=[1, John Doe, 42]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ // The age will be incremented as float value input will be rounded
+ // up.
+ assertEquals("Row[values=[2, Jane Doe, 44]]", ds.getRow().toString());
+ assertFalse(ds.next());
+
+ ds.close();
+ } finally {
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ cb.dropTable("my_table").execute();
+ }
+ });
+ }
+ }
+
+ public void testInsertFailureForStringValueForIntegerColumn() throws Exception {
+ JdbcDataContext dc = new JdbcDataContext(_connection);
+ final Schema schema = dc.getDefaultSchema();
+ try {
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ Table table = cb.createTable(schema, "my_table").withColumn("id").ofType(ColumnType.INTEGER)
+ .ofNativeType("SERIAL").nullable(false).withColumn("person name").ofSize(255)
+ .withColumn("age").ofType(ColumnType.INTEGER).execute();
+ assertEquals("[id, person name, age]", Arrays.toString(table.getColumnNames()));
+ assertEquals(
+ "Column[name=id,columnNumber=0,type=INTEGER,nullable=false,nativeType=serial,columnSize=10]",
+ table.getColumnByName("id").toString());
+ assertEquals(
+ "Column[name=person name,columnNumber=1,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=255]",
+ table.getColumnByName("person name").toString());
+ assertEquals(
+ "Column[name=age,columnNumber=2,type=INTEGER,nullable=true,nativeType=int4,columnSize=10]",
+ table.getColumnByName("age").toString());
+
+ cb.insertInto(table).value("person name", "John Doe").value("age", "42").execute();
+ }
+ });
+
+ } catch (Exception e) {
+ assertEquals(
+ "Could not execute batch: INSERT INTO \"public\".\"my_table\" (\"person name\",age) VALUES ('John Doe','42'): Batch entry 0 INSERT INTO \"public\".\"my_table\" (\"person name\",age) VALUES ('John Doe','42') was aborted. Call getNextException to see the cause.",
+ e.getMessage());
+ } finally {
+ dc.refreshSchemas();
+ if (dc.getTableByQualifiedLabel("my_table") != null) {
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ cb.dropTable("my_table").execute();
+ }
+ });
+ }
+ }
+ }
+
+ public void testDatabaseProductName() throws Exception {
+ String databaseProductName = _connection.getMetaData().getDatabaseProductName();
+ assertEquals(JdbcDataContext.DATABASE_PRODUCT_POSTGRESQL, databaseProductName);
+ }
+
+ public void testGetDefaultSchema() throws Exception {
+ DataContext dc = new JdbcDataContext(_connection);
+ Schema schema = dc.getDefaultSchema();
+ assertEquals("public", schema.getName());
+ }
+
+ public void testGetSchema() throws Exception {
+ DataContext dc = new JdbcDataContext(_connection);
+ Schema[] schemas = dc.getSchemas();
+ assertTrue(schemas.length >= 3);
+
+ assertNotNull(dc.getSchemaByName("information_schema"));
+ assertNotNull(dc.getSchemaByName("pg_catalog"));
+ assertNotNull(dc.getSchemaByName("public"));
+
+ Schema schema = dc.getSchemaByName("public");
+
+ assertEquals("[Table[name=categories,type=TABLE,remarks=null], "
+ + "Table[name=cust_hist,type=TABLE,remarks=null], " + "Table[name=customers,type=TABLE,remarks=null], "
+ + "Table[name=inventory,type=TABLE,remarks=null], "
+ + "Table[name=orderlines,type=TABLE,remarks=null], " + "Table[name=orders,type=TABLE,remarks=null], "
+ + "Table[name=products,type=TABLE,remarks=null], " + "Table[name=reorder,type=TABLE,remarks=null]]",
+ Arrays.toString(schema.getTables()));
+
+ Table productsTable = schema.getTableByName("products");
+ assertEquals(
+ "[Column[name=prod_id,columnNumber=0,type=INTEGER,nullable=false,nativeType=serial,columnSize=10], "
+ + "Column[name=category,columnNumber=1,type=INTEGER,nullable=false,nativeType=int4,columnSize=10], "
+ + "Column[name=title,columnNumber=2,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
+ + "Column[name=actor,columnNumber=3,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
+ + "Column[name=price,columnNumber=4,type=NUMERIC,nullable=false,nativeType=numeric,columnSize=12], "
+ + "Column[name=special,columnNumber=5,type=SMALLINT,nullable=true,nativeType=int2,columnSize=5], "
+ + "Column[name=common_prod_id,columnNumber=6,type=INTEGER,nullable=false,nativeType=int4,columnSize=10]]",
+ Arrays.toString(productsTable.getColumns()));
+ Table customersTable = schema.getTableByName("customers");
+ assertEquals(
+ "[Column[name=customerid,columnNumber=0,type=INTEGER,nullable=false,nativeType=serial,columnSize=10], "
+ + "Column[name=firstname,columnNumber=1,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
+ + "Column[name=lastname,columnNumber=2,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
+ + "Column[name=address1,columnNumber=3,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
+ + "Column[name=address2,columnNumber=4,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=50], "
+ + "Column[name=city,columnNumber=5,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
+ + "Column[name=state,columnNumber=6,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=50], "
+ + "Column[name=zip,columnNumber=7,type=INTEGER,nullable=true,nativeType=int4,columnSize=10], "
+ + "Column[name=country,columnNumber=8,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
+ + "Column[name=region,columnNumber=9,type=SMALLINT,nullable=false,nativeType=int2,columnSize=5], "
+ + "Column[name=email,columnNumber=10,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=50], "
+ + "Column[name=phone,columnNumber=11,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=50], "
+ + "Column[name=creditcardtype,columnNumber=12,type=INTEGER,nullable=false,nativeType=int4,columnSize=10], "
+ + "Column[name=creditcard,columnNumber=13,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
+ + "Column[name=creditcardexpiration,columnNumber=14,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
+ + "Column[name=username,columnNumber=15,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
+ + "Column[name=password,columnNumber=16,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
+ + "Column[name=age,columnNumber=17,type=SMALLINT,nullable=true,nativeType=int2,columnSize=5], "
+ + "Column[name=income,columnNumber=18,type=INTEGER,nullable=true,nativeType=int4,columnSize=10], "
+ + "Column[name=gender,columnNumber=19,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=1]]",
+ Arrays.toString(customersTable.getColumns()));
+ Relationship[] relations = customersTable.getRelationships();
+ assertEquals(2, relations.length);
+ assertEquals(
+ "[Relationship[primaryTable=customers,primaryColumns=[customerid],foreignTable=cust_hist,foreignColumns=[customerid]], "
+ + "Relationship[primaryTable=customers,primaryColumns=[customerid],foreignTable=orders,foreignColumns=[customerid]]]",
+ Arrays.toString(relations));
+ assertEquals("Table[name=customers,type=TABLE,remarks=null]", relations[0].getPrimaryTable().toString());
+ assertEquals("Table[name=cust_hist,type=TABLE,remarks=null]", relations[0].getForeignTable().toString());
+ assertEquals("Table[name=customers,type=TABLE,remarks=null]", relations[1].getPrimaryTable().toString());
+ assertEquals("Table[name=orders,type=TABLE,remarks=null]", relations[1].getForeignTable().toString());
+
+ Table ordersTable = schema.getTableByName("orderlines");
+ assertEquals(
+ "[Column[name=orderlineid,columnNumber=0,type=INTEGER,nullable=false,nativeType=int4,columnSize=10], "
+ + "Column[name=orderid,columnNumber=1,type=INTEGER,nullable=false,nativeType=int4,columnSize=10], "
+ + "Column[name=prod_id,columnNumber=2,type=INTEGER,nullable=false,nativeType=int4,columnSize=10], "
+ + "Column[name=quantity,columnNumber=3,type=SMALLINT,nullable=false,nativeType=int2,columnSize=5], "
+ + "Column[name=orderdate,columnNumber=4,type=DATE,nullable=false,nativeType=date,columnSize=13]]",
+ Arrays.toString(ordersTable.getColumns()));
+ }
+
+ public void testExecuteQueryInPublicSchema() throws Exception {
+ DataContext dc = new JdbcDataContext(_connection);
+ Query q = new Query();
+ Schema schema = dc.getSchemaByName("public");
+ Table productsTable = schema.getTableByName("products");
+ q.from(productsTable);
+
+ Column titleColumn = productsTable.getColumnByName("title");
+ Column productPriceColumn = productsTable.getColumnByName("price");
+ q.select(titleColumn, productPriceColumn);
+ q.getSelectClause().getItem(0).setAlias("product-title");
+
+ DataSet data = dc.executeQuery(q);
+ TableModel tableModel = new DataSetTableModel(data);
+ assertEquals(2, tableModel.getColumnCount());
+ assertEquals(10000, tableModel.getRowCount());
+
+ assertEquals("ACADEMY ACADEMY", tableModel.getValueAt(0, 0).toString());
+ assertEquals("25.99", tableModel.getValueAt(0, 1).toString());
+
+ assertEquals("ACADEMY HORN", tableModel.getValueAt(432, 0).toString());
+ assertEquals("16.99", tableModel.getValueAt(6346, 1).toString());
+
+ assertEquals("ALADDIN ZORRO", tableModel.getValueAt(9999, 0).toString());
+ assertEquals("10.99", tableModel.getValueAt(9999, 1).toString());
+
+ data = null;
+ tableModel = null;
+
+ Column prodIdColumn = productsTable.getColumnByName("prod_id");
+ Table orderlinesTable = schema.getTableByName("orderlines");
+ Column commonProdIdColumn = orderlinesTable.getColumnByName("prod_id");
+ Column quantityColumn = orderlinesTable.getColumnByName("quantity");
+
+ q.from(orderlinesTable);
+ q.where(new FilterItem(new SelectItem(prodIdColumn), OperatorType.EQUALS_TO, new SelectItem(commonProdIdColumn)));
+ q.groupBy(titleColumn);
+ q.getSelectClause().removeItem(q.getSelectClause().getSelectItem(productPriceColumn));
+ SelectItem quantitySum = new SelectItem(FunctionType.SUM, quantityColumn).setAlias("orderAmount");
+ q.select(quantitySum);
+ q.having(new FilterItem(quantitySum, OperatorType.GREATER_THAN, 25));
+ q.orderBy(new OrderByItem(q.getSelectClause().getItem(0)));
+
+ assertEquals("SELECT \"products\".\"title\" AS product-title, SUM(\"orderlines\".\"quantity\") AS orderAmount "
+ + "FROM public.\"products\", public.\"orderlines\" "
+ + "WHERE \"products\".\"prod_id\" = \"orderlines\".\"prod_id\" " + "GROUP BY \"products\".\"title\" "
+ + "HAVING SUM(\"orderlines\".\"quantity\") > 25 " + "ORDER BY \"products\".\"title\" ASC", q.toString());
+ data = dc.executeQuery(q);
+ tableModel = new DataSetTableModel(data);
+ assertEquals(2, tableModel.getColumnCount());
+ assertEquals(136, tableModel.getRowCount());
+
+ assertEquals("ACADEMY ALABAMA", tableModel.getValueAt(0, 0).toString());
+ assertEquals("27", tableModel.getValueAt(0, 1).toString());
+
+ assertEquals("AIRPORT MOURNING", tableModel.getValueAt(99, 0).toString());
+ assertEquals("29", tableModel.getValueAt(99, 1).toString());
+
+ assertEquals("ALADDIN WORKER", tableModel.getValueAt(135, 0).toString());
+ assertEquals("27", tableModel.getValueAt(135, 1).toString());
+ }
+
+ public void testWhiteSpaceColumns() throws Exception {
+ DatabaseMetaData metaData = _connection.getMetaData();
+ assertEquals("\"", metaData.getIdentifierQuoteString());
+ }
+
+ public void testCreateTableAndInsert1MRecords() throws Exception {
+ JdbcDataContext dc = new JdbcDataContext(_connection);
+ final Schema schema = dc.getDefaultSchema();
+ try {
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ Table table = cb.createTable(schema, "my_table").withColumn("id").ofType(ColumnType.INTEGER)
+ .ofNativeType("SERIAL").nullable(false).withColumn("person name").ofSize(255)
+ .withColumn("age").ofType(ColumnType.INTEGER).execute();
+ assertEquals("[id, person name, age]", Arrays.toString(table.getColumnNames()));
+ assertEquals(
+ "Column[name=id,columnNumber=0,type=INTEGER,nullable=false,nativeType=serial,columnSize=10]",
+ table.getColumnByName("id").toString());
+ assertEquals(
+ "Column[name=person name,columnNumber=1,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=255]",
+ table.getColumnByName("person name").toString());
+ assertEquals(
+ "Column[name=age,columnNumber=2,type=INTEGER,nullable=true,nativeType=int4,columnSize=10]",
+ table.getColumnByName("age").toString());
+
+ for (int i = 0; i < 1000000; i++) {
+ cb.insertInto(table).value("person name", "John Doe").value("age", i + 10).execute();
+ }
+
+ }
+ });
+
+ Table table = schema.getTableByName("my_table");
+ Query query = dc.query().from(table).selectCount().toQuery();
+ DataSet ds = dc.executeQuery(query);
+ assertTrue(ds.next());
+ assertEquals("Row[values=[1000000]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ ds.close();
+ } finally {
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ cb.dropTable("my_table").execute();
+ }
+ });
+ }
+ }
+
+ public void testCharOfSizeOne() throws Exception {
+ JdbcTestTemplates.meaningOfOneSizeChar(_connection);
+ }
+
+ /**
+ * Splits a huge query into 146 pieces and executes them to test that the
+ * collective result are equal to the original one in size
+ */
+ @Ignore
+ public void testSplitHugeQueryExecute146() throws Exception {
+ DataContext dc = new JdbcDataContext(_connection);
+ Query q = new Query();
+ Schema schema = dc.getSchemaByName("public");
+ Table productsTable = schema.getTableByName("products");
+ Table customerTable = schema.getTableByName("customers");
+ q.from(productsTable, "p").from(customerTable, "c");
+
+ Column titleColumn = productsTable.getColumnByName("title");
+ Column priceColumn = productsTable.getColumnByName("price");
+ Column cityColumn = customerTable.getColumnByName("city");
+ Column ageColumn = customerTable.getColumnByName("age");
+ q.select(titleColumn, priceColumn, cityColumn);
+
+ q.where(new FilterItem(new SelectItem(priceColumn), OperatorType.GREATER_THAN, 27));
+ q.where(new FilterItem(new SelectItem(ageColumn), OperatorType.GREATER_THAN, 55));
+
+ assertEquals(
+ "SELECT p.\"title\", p.\"price\", c.\"city\" FROM public.\"products\" p, public.\"customers\" c WHERE p.\"price\" > 27 AND c.\"age\" > 55",
+ q.toString());
+
+ QuerySplitter qs = new QuerySplitter(dc, q);
+ qs.setMaxRows(100000);
+ assertEquals(14072278, qs.getRowCount());
+
+ List<Query> splitQueries = qs.splitQuery();
+ assertEquals(146, splitQueries.size());
+ assertEquals(
+ "SELECT p.\"title\", p.\"price\", c.\"city\" FROM public.\"products\" p, public.\"customers\" c WHERE p.\"price\" > 27 AND c.\"age\" > 55 AND (c.\"customerid\" < 143 OR c.\"customerid\" IS NULL) AND (p.\"category\" < 8 OR p.\"category\" IS NULL)",
+ splitQueries.get(0).toString());
+ assertEquals(
+ "SELECT p.\"title\", p.\"price\", c.\"city\" FROM public.\"products\" p, public.\"customers\" c WHERE p.\"price\" > 27 AND c.\"age\" > 55 AND (c.\"customerid\" > 19739 OR c.\"customerid\" = 19739)",
+ splitQueries.get(145).toString());
+
+ assertEquals(
+ "[45954, 55752, 52122, 55480, 49770, 53410, 60434, 51590, 97284, 94336, 86966, 76648, 98758, 84018, 98758, 95810, 92862, 91388, 39798, 79596, "
+ + "91388, 48642, 60434, 106128, 94336, 94336, 86966, 79596, 85492, 94336, 104654, 97284, 84018, 101706, 109076, 89914, 110550, 107602, 98758, "
+ + "112024, 100232, 101706, 95810, 92862, 107602, 100232, 86966, 98758, 106128, 91388, 107602, 104654, 107602, 81070, 114972, 79596, 100232, 97284, "
+ + "103180, 98758, 113498, 103180, 89914, 104654, 97284, 109076, 114972, 103180, 86966, 106128, 101706, 95810, 103180, 88440, 112024, 91388, 106128, "
+ + "82544, 122342, 98758, 104654, 103180, 104654, 89914, 106128, 88440, 103180, 100232, 98758, 100232, 89914, 101706, 100232, 107602, 88440, 89914, "
+ + "91388, 103180, 100232, 104654, 120868, 106128, 100232, 107602, 97284, 103180, 106128, 91388, 100232, 106128, 100232, 109076, 94336, 106128, 94336, "
+ + "106128, 104654, 116446, 98758, 113498, 107602, 104654, 107602, 88440, 100232, 92862, 89914, 110550, 109076, 100232, 92862, 100232, 104654, 103180, "
+ + "89914, 103180, 103180, 107602, 85492, 112024, 85492, 101706, 92862, 86966, 104654, 201938]",
+ Arrays.toString(getCounts(dc, splitQueries)));
+ assertSameCount(dc, qs, splitQueries);
+
+ DataSet data = qs.executeQueries(splitQueries);
+ int count = 0;
+ while (data.next()) {
+ count++;
+ }
+ data.close();
+ assertEquals(14072278, count);
+ System.out.println("Successfully iterated 14072278 rows! :)");
+ }
+
+ /**
+ * Utility method for asserting that a query and it's splitted queries have
+ * the same total count
+ */
+ private void assertSameCount(DataContext dc, QuerySplitter qs, List<Query> queries) {
+ long count1 = qs.getRowCount();
+ long count2 = 0;
+ for (Query q : queries) {
+ count2 += getCount(dc, q);
+ }
+ assertEquals(count1, count2);
+ }
+
+ public long[] getCounts(DataContext dc, List<Query> queries) {
+ long[] result = new long[queries.size()];
+ for (int i = 0; i < result.length; i++) {
+ result[i] = getCount(dc, queries.get(i));
+ }
+ return result;
+ }
+
+ /**
+ * Gets the count of a query
+ */
+ private long getCount(DataContext dc, Query query) {
+ return new QuerySplitter(dc, query).getRowCount();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/test/integrationtests/org/apache/metamodel/SQLServerJtdsDriverTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/apache/metamodel/SQLServerJtdsDriverTest.java b/jdbc/src/test/integrationtests/org/apache/metamodel/SQLServerJtdsDriverTest.java
new file mode 100644
index 0000000..a488549
--- /dev/null
+++ b/jdbc/src/test/integrationtests/org/apache/metamodel/SQLServerJtdsDriverTest.java
@@ -0,0 +1,208 @@
+package org.eobjects.metamodel;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.jdbc.JdbcDataContext;
+import org.eobjects.metamodel.jdbc.JdbcTestTemplates;
+import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
+import org.eobjects.metamodel.jdbc.dialects.SQLServerQueryRewriter;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.schema.TableType;
+
+/**
+ * Test case that tests MS SQL Server interaction. The test uses the
+ * "AdventureWorks" sample database which can be downloaded from codeplex.
+ *
+ * This testcase uses the JTDS driver.
+ *
+ * @link{http://www.codeplex.com/MSFTDBProdSamples
+ * */
+public class SQLServerJtdsDriverTest extends TestCase {
+
+ private Connection _connection;
+ private String _databaseName = "AdventureWorks";
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ Class.forName("net.sourceforge.jtds.jdbc.Driver");
+ _connection = DriverManager.getConnection(
+ "jdbc:jtds:sqlserver://localhost:1433/AdventureWorks;instance=SQLEXPRESS", "eobjects", "eobjects");
+
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ _connection.close();
+ }
+
+ public void testWorkingWithDates() throws Exception {
+ assertFalse(_connection.isReadOnly());
+
+ JdbcDataContext dc = new JdbcDataContext(_connection);
+ final Schema schema = dc.getSchemaByName("Person");
+
+ JdbcTestTemplates.createInsertAndUpdateDateTypes(dc, schema, "test_table");
+ }
+
+ public void testAutomaticConversionWhenInsertingString() throws Exception {
+ assertNotNull(_connection);
+
+ try {
+ // clean up, if nescesary
+ _connection.createStatement().execute("DROP TABLE Person.test_table");
+ } catch (SQLException e) {
+ // do nothing
+ }
+
+ assertFalse(_connection.isReadOnly());
+
+ JdbcDataContext dc = new JdbcDataContext(_connection);
+ final Schema schema = dc.getSchemaByName("Person");
+ assertEquals("Person", schema.getName());
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ Table table = cb.createTable(schema, "test_table").withColumn("id").asPrimaryKey()
+ .ofType(ColumnType.INTEGER).withColumn("birthdate").ofType(ColumnType.DATE).execute();
+
+ cb.insertInto(table).value("id", "1").execute();
+ cb.insertInto(table).value("id", 2).value("birthdate", "2011-12-21").execute();
+ }
+ });
+
+ Table table = schema.getTableByName("test_table");
+
+ assertTrue(table.getColumnByName("id").isPrimaryKey());
+ assertFalse(table.getColumnByName("birthdate").isPrimaryKey());
+
+ // the jdbc driver represents the date as a VARCHAR
+ assertEquals(
+ "[Column[name=id,columnNumber=0,type=INTEGER,nullable=false,nativeType=int,columnSize=10], "
+ + "Column[name=birthdate,columnNumber=1,type=VARCHAR,nullable=true,nativeType=date,columnSize=10]]",
+ Arrays.toString(table.getColumns()));
+
+ DataSet ds = dc.query().from(table).select("id").and("birthdate").execute();
+ assertTrue(ds.next());
+ assertEquals("Row[values=[1, null]]", ds.getRow().toString());
+ assertEquals("java.lang.Integer", ds.getRow().getValue(0).getClass().getName());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[2, 2011-12-21]]", ds.getRow().toString());
+ assertEquals("java.lang.String", ds.getRow().getValue(1).getClass().getName());
+ assertFalse(ds.next());
+ ds.close();
+
+ _connection.createStatement().execute("DROP TABLE Person.test_table");
+ }
+
+ public void testQueryUsingExpressions() throws Exception {
+ JdbcDataContext strategy = new JdbcDataContext(_connection,
+ new TableType[] { TableType.TABLE, TableType.VIEW }, _databaseName);
+ Query q = new Query().select("Name").from("Production.Product").where("COlor IS NOT NULL").setMaxRows(5);
+ DataSet dataSet = strategy.executeQuery(q);
+ assertEquals("[Name]", Arrays.toString(dataSet.getSelectItems()));
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[LL Crankarm]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertFalse(dataSet.next());
+ }
+
+ public void testGetSchemaNormalTableTypes() throws Exception {
+ JdbcDataContext dc = new JdbcDataContext(_connection, new TableType[] { TableType.TABLE, TableType.VIEW },
+ _databaseName);
+ Schema[] schemas = dc.getSchemas();
+
+ assertEquals(8, schemas.length);
+ assertEquals("Schema[name=HumanResources]", schemas[0].toString());
+ assertEquals(13, schemas[0].getTableCount());
+ assertEquals("Schema[name=INFORMATION_SCHEMA]", schemas[1].toString());
+ assertEquals(20, schemas[1].getTableCount());
+ assertEquals("Schema[name=Person]", schemas[2].toString());
+ assertEquals(8, schemas[2].getTableCount());
+ assertEquals("Schema[name=Production]", schemas[3].toString());
+ assertEquals(28, schemas[3].getTableCount());
+ assertEquals("Schema[name=Purchasing]", schemas[4].toString());
+ assertEquals(8, schemas[4].getTableCount());
+ assertEquals("Schema[name=Sales]", schemas[5].toString());
+ assertEquals(27, schemas[5].getTableCount());
+
+ }
+
+ public void testGetSchemaAllTableTypes() throws Exception {
+ JdbcDataContext strategy = new JdbcDataContext(_connection, new TableType[] { TableType.OTHER,
+ TableType.GLOBAL_TEMPORARY }, _databaseName);
+ Schema schema = strategy.getDefaultSchema();
+ assertEquals("dbo", schema.getName());
+
+ assertEquals("[Sales, HumanResources, dbo, Purchasing, sys, Production, INFORMATION_SCHEMA, Person]",
+ Arrays.toString(strategy.getSchemaNames()));
+ }
+
+ public void testQueryRewriterQuoteAliases() throws Exception {
+ JdbcDataContext dc = new JdbcDataContext(_connection, TableType.DEFAULT_TABLE_TYPES, _databaseName);
+ IQueryRewriter queryRewriter = dc.getQueryRewriter();
+ assertSame(SQLServerQueryRewriter.class, queryRewriter.getClass());
+
+ Schema schema = dc.getSchemaByName("Sales");
+ Table customersTable = schema.getTableByName("CUSTOMER");
+
+ Query q = new Query().from(customersTable, "cus-tomers").select(
+ new SelectItem(customersTable.getColumnByName("AccountNumber")).setAlias("c|o|d|e"));
+ q.setMaxRows(5);
+
+ assertEquals("SELECT cus-tomers.\"AccountNumber\" AS c|o|d|e FROM Sales.\"Customer\" cus-tomers", q.toString());
+
+ String queryString = queryRewriter.rewriteQuery(q);
+ assertEquals(
+ "SELECT TOP 5 \"cus-tomers\".\"AccountNumber\" AS \"c|o|d|e\" FROM Sales.\"Customer\" \"cus-tomers\"",
+ queryString);
+
+ // We have to test that no additional quoting characters are added every
+ // time we run the rewriting
+ queryString = queryRewriter.rewriteQuery(q);
+ queryString = queryRewriter.rewriteQuery(q);
+ assertEquals(
+ "SELECT TOP 5 \"cus-tomers\".\"AccountNumber\" AS \"c|o|d|e\" FROM Sales.\"Customer\" \"cus-tomers\"",
+ queryString);
+
+ // Test that the original query is still the same (ie. it has been
+ // cloned for execution)
+ assertEquals("SELECT cus-tomers.\"AccountNumber\" AS c|o|d|e FROM Sales.\"Customer\" cus-tomers", q.toString());
+
+ DataSet data = dc.executeQuery(q);
+ assertNotNull(data);
+ data.close();
+ }
+
+ public void testQuotedString() throws Exception {
+ JdbcDataContext dc = new JdbcDataContext(_connection, TableType.DEFAULT_TABLE_TYPES, _databaseName);
+ IQueryRewriter queryRewriter = dc.getQueryRewriter();
+ assertSame(SQLServerQueryRewriter.class, queryRewriter.getClass());
+
+ Query q = dc.query().from("Production", "Product").select("Name").where("Color").eq("R'ed").toQuery();
+
+ DataSet ds = dc.executeQuery(q);
+ assertNotNull(ds);
+ assertFalse(ds.next());
+ ds.close();
+
+ assertEquals(
+ "SELECT Production.\"Product\".\"Name\" FROM Production.\"Product\" WHERE Production.\"Product\".\"Color\" = 'R''ed'",
+ queryRewriter.rewriteQuery(q));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/test/integrationtests/org/apache/metamodel/SQLServerMicrosoftDriverTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/apache/metamodel/SQLServerMicrosoftDriverTest.java b/jdbc/src/test/integrationtests/org/apache/metamodel/SQLServerMicrosoftDriverTest.java
new file mode 100644
index 0000000..ee0a664
--- /dev/null
+++ b/jdbc/src/test/integrationtests/org/apache/metamodel/SQLServerMicrosoftDriverTest.java
@@ -0,0 +1,141 @@
+package org.eobjects.metamodel;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.jdbc.JdbcDataContext;
+import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
+import org.eobjects.metamodel.jdbc.dialects.SQLServerQueryRewriter;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.schema.TableType;
+
+/**
+ * Test case that tests MS SQL Server interaction. The test uses the
+ * "AdventureWorks" sample database which can be downloaded from codeplex.
+ *
+ * This testcase uses the official MS SQL Server driver.
+ *
+ * @link{http://www.codeplex.com/MSFTDBProdSamples
+ * */
+public class SQLServerMicrosoftDriverTest extends TestCase {
+
+ private Connection _connection;
+ private String _databaseName = "AdventureWorks";
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
+ _connection = DriverManager.getConnection("jdbc:sqlserver://localhost\\SQLEXPRESS;databaseName="
+ + _databaseName, "eobjects", "eobjects");
+ _connection.setReadOnly(true);
+
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ _connection.close();
+ }
+
+ public void testQueryUsingExpressions() throws Exception {
+ JdbcDataContext strategy = new JdbcDataContext(_connection,
+ new TableType[] { TableType.TABLE, TableType.VIEW }, _databaseName);
+ Query q = new Query().select("Name").from("Production.Product").where("COlor IS NOT NULL").setMaxRows(5);
+ DataSet dataSet = strategy.executeQuery(q);
+ assertEquals("[Name]", Arrays.toString(dataSet.getSelectItems()));
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[LL Crankarm]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertFalse(dataSet.next());
+ }
+
+ public void testGetSchemaNormalTableTypes() throws Exception {
+ JdbcDataContext dc = new JdbcDataContext(_connection, new TableType[] { TableType.TABLE, TableType.VIEW },
+ _databaseName);
+ Schema[] schemas = dc.getSchemas();
+
+ assertEquals(8, schemas.length);
+ assertEquals("Schema[name=HumanResources]", schemas[0].toString());
+ assertEquals(13, schemas[0].getTableCount());
+ assertEquals("Schema[name=INFORMATION_SCHEMA]", schemas[1].toString());
+ assertEquals(20, schemas[1].getTableCount());
+ assertEquals("Schema[name=Person]", schemas[2].toString());
+ assertEquals(8, schemas[2].getTableCount());
+ assertEquals("Schema[name=Production]", schemas[3].toString());
+ assertEquals(28, schemas[3].getTableCount());
+ assertEquals("Schema[name=Purchasing]", schemas[4].toString());
+ assertEquals(8, schemas[4].getTableCount());
+ assertEquals("Schema[name=Sales]", schemas[5].toString());
+ assertEquals(27, schemas[5].getTableCount());
+
+ }
+
+ public void testGetSchemaAllTableTypes() throws Exception {
+ JdbcDataContext strategy = new JdbcDataContext(_connection, new TableType[] { TableType.OTHER,
+ TableType.GLOBAL_TEMPORARY }, _databaseName);
+
+ assertEquals("[Sales, HumanResources, dbo, Purchasing, sys, Production, INFORMATION_SCHEMA, Person]",
+ Arrays.toString(strategy.getSchemaNames()));
+
+ assertEquals("Schema[name=dbo]", strategy.getDefaultSchema().toString());
+ }
+
+ public void testQueryRewriterQuoteAliases() throws Exception {
+ JdbcDataContext strategy = new JdbcDataContext(_connection, TableType.DEFAULT_TABLE_TYPES, _databaseName);
+ IQueryRewriter queryRewriter = strategy.getQueryRewriter();
+ assertSame(SQLServerQueryRewriter.class, queryRewriter.getClass());
+
+ Schema schema = strategy.getSchemaByName("Sales");
+ Table customersTable = schema.getTableByName("CUSTOMER");
+
+ Query q = new Query().from(customersTable, "cus-tomers").select(
+ new SelectItem(customersTable.getColumnByName("AccountNumber")).setAlias("c|o|d|e"));
+ q.setMaxRows(5);
+
+ assertEquals("SELECT cus-tomers.\"AccountNumber\" AS c|o|d|e FROM Sales.\"Customer\" cus-tomers", q.toString());
+
+ String queryString = queryRewriter.rewriteQuery(q);
+ assertEquals(
+ "SELECT TOP 5 \"cus-tomers\".\"AccountNumber\" AS \"c|o|d|e\" FROM Sales.\"Customer\" \"cus-tomers\"",
+ queryString);
+
+ // We have to test that no additional quoting characters are added every
+ // time we run the rewriting
+ queryString = queryRewriter.rewriteQuery(q);
+ queryString = queryRewriter.rewriteQuery(q);
+ assertEquals(
+ "SELECT TOP 5 \"cus-tomers\".\"AccountNumber\" AS \"c|o|d|e\" FROM Sales.\"Customer\" \"cus-tomers\"",
+ queryString);
+
+ // Test that the original query is still the same (ie. it has been
+ // cloned for execution)
+ assertEquals("SELECT cus-tomers.\"AccountNumber\" AS c|o|d|e FROM Sales.\"Customer\" cus-tomers", q.toString());
+
+ DataSet data = strategy.executeQuery(q);
+ assertNotNull(data);
+ data.close();
+ }
+
+ public void testQuotedString() throws Exception {
+ JdbcDataContext dc = new JdbcDataContext(_connection, TableType.DEFAULT_TABLE_TYPES, _databaseName);
+ IQueryRewriter queryRewriter = dc.getQueryRewriter();
+ assertSame(SQLServerQueryRewriter.class, queryRewriter.getClass());
+
+ Query q = dc.query().from("Production", "Product").select("Name").where("Color").eq("R'ed").toQuery();
+
+ assertEquals(
+ "SELECT \"Product\".\"Name\" FROM Production.\"Product\" Product WHERE Product.\"Color\" = 'R''ed'",
+ queryRewriter.rewriteQuery(q));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/test/integrationtests/org/eobjects/metamodel/DB2Test.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/eobjects/metamodel/DB2Test.java b/jdbc/src/test/integrationtests/org/eobjects/metamodel/DB2Test.java
deleted file mode 100644
index 82e5819..0000000
--- a/jdbc/src/test/integrationtests/org/eobjects/metamodel/DB2Test.java
+++ /dev/null
@@ -1,107 +0,0 @@
-package org.eobjects.metamodel;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.jdbc.JdbcTestTemplates;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * DB2 integration test. This is a read-only integration test, meant to be
- * modified for whatever server is available (even within Human Inference).
- */
-public class DB2Test extends TestCase {
-
- private static final String URL = "jdbc:db2://TODO:50000/TODO";
-
- private static final String USERNAME = "TODO";
- private static final String PASSWORD = "TODO";
- private Connection _connection;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- Class.forName("com.ibm.db2.jcc.DB2Driver");
- _connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- _connection.close();
- }
-
-
- public void testInterpretationOfNull() throws Exception {
- JdbcTestTemplates.interpretationOfNulls(_connection);
- }
-
- public void testDefaultSchema() throws Exception {
- JdbcDataContext dc = new JdbcDataContext(_connection);
- Schema schema = dc.getDefaultSchema();
- assertEquals(USERNAME.toUpperCase(), schema.getName());
-
- Table countryTable = schema.getTableByName("COUNTRY");
- assertNotNull(countryTable);
-
- DataSet ds = dc.query().from(countryTable).selectCount().execute();
- assertTrue(ds.next());
- assertEquals("Row[values=[1008]]", ds.getRow().toString());
- assertFalse(ds.next());
- ds.close();
- }
-
- public void testMaxRowsOnly() throws Exception {
- JdbcDataContext dc = new JdbcDataContext(_connection);
- Schema schema = dc.getDefaultSchema();
- String[] tableNames = schema.getTableNames();
- System.out.println("Tables: " + Arrays.toString(tableNames));
-
- Table countryTable = schema.getTableByName("COUNTRY");
- assertNotNull(countryTable);
-
- Query query = dc.query().from(countryTable).select("COUNTRYCODE").limit(200).toQuery();
- assertEquals("SELECT DB2INST1.\"COUNTRY\".\"COUNTRYCODE\" FROM DB2INST1.\"COUNTRY\" "
- + "FETCH FIRST 200 ROWS ONLY", dc.getQueryRewriter().rewriteQuery(query));
-
- DataSet ds = dc.executeQuery(query);
- for (int i = 0; i < 200; i++) {
- assertTrue(ds.next());
- assertEquals(1, ds.getRow().getValues().length);
- }
- assertFalse(ds.next());
- ds.close();
- }
-
- public void testMaxRowsAndOffset() throws Exception {
- JdbcDataContext dc = new JdbcDataContext(_connection);
- Schema schema = dc.getDefaultSchema();
- String[] tableNames = schema.getTableNames();
- System.out.println("Tables: " + Arrays.toString(tableNames));
-
- Table countryTable = schema.getTableByName("COUNTRY");
- assertNotNull(countryTable);
-
- Query query = dc.query().from(countryTable).select("COUNTRYCODE").limit(200).offset(200).toQuery();
- assertEquals(
- "SELECT metamodel_subquery.\"COUNTRYCODE\" FROM ("
- + "SELECT DB2INST1.\"COUNTRY\".\"COUNTRYCODE\", ROW_NUMBER() OVER() AS metamodel_row_number FROM DB2INST1.\"COUNTRY\""
- + ") metamodel_subquery WHERE metamodel_row_number BETWEEN 201 AND 400", dc.getQueryRewriter()
- .rewriteQuery(query));
-
- DataSet ds = dc.executeQuery(query);
- for (int i = 0; i < 200; i++) {
- assertTrue(ds.next());
- assertEquals(1, ds.getRow().getValues().length);
- }
- assertFalse(ds.next());
- ds.close();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/test/integrationtests/org/eobjects/metamodel/FirebirdTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/eobjects/metamodel/FirebirdTest.java b/jdbc/src/test/integrationtests/org/eobjects/metamodel/FirebirdTest.java
deleted file mode 100644
index ec1ba32..0000000
--- a/jdbc/src/test/integrationtests/org/eobjects/metamodel/FirebirdTest.java
+++ /dev/null
@@ -1,115 +0,0 @@
-package org.eobjects.metamodel;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.Date;
-
-import javax.swing.table.TableModel;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetTableModel;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.JoinType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * Integrationtests for Firebird SQL.
- *
- * This test uses the "employee" sampledata shipped with Firebird. The JDBC
- * driver ("jaybird") is not available in the Maven repository so you will have
- * to download and attach it to the eclipse project yourself.
- *
- * @see http://www.firebirdsql.org/manual/qsg10-connecting.html
- * @see http://www.firebirdsql.org/index.php?op=files&id=jaybird
- */
-public class FirebirdTest extends TestCase {
-
- private static final String CONNECTION_STRING = "jdbc:firebirdsql:127.0.0.1:employee.fdb";
- private static final String USERNAME = "SYSDBA";
- private static final String PASSWORD = "eobjects";
- private Connection _connection;
- private DataContext _dataContext;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- Class.forName("org.firebirdsql.jdbc.FBDriver");
- _connection = DriverManager.getConnection(CONNECTION_STRING, USERNAME, PASSWORD);
- _connection.setReadOnly(true);
- _dataContext = new JdbcDataContext(_connection);
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- _connection.close();
- }
-
- public void testGetSchemas() throws Exception {
- Schema[] schemas = _dataContext.getSchemas();
- assertEquals(1, schemas.length);
- Schema schema = _dataContext.getDefaultSchema();
- assertEquals("{JdbcTable[name=COUNTRY,type=TABLE,remarks=<null>],"
- + "JdbcTable[name=CUSTOMER,type=TABLE,remarks=<null>],"
- + "JdbcTable[name=DEPARTMENT,type=TABLE,remarks=<null>],"
- + "JdbcTable[name=EMPLOYEE,type=TABLE,remarks=<null>],"
- + "JdbcTable[name=EMPLOYEE_PROJECT,type=TABLE,remarks=<null>],"
- + "JdbcTable[name=JOB,type=TABLE,remarks=<null>],"
- + "JdbcTable[name=PHONE_LIST,type=VIEW,remarks=<null>],"
- + "JdbcTable[name=PROJECT,type=TABLE,remarks=<null>],"
- + "JdbcTable[name=PROJ_DEPT_BUDGET,type=TABLE,remarks=<null>],"
- + "JdbcTable[name=SALARY_HISTORY,type=TABLE,remarks=<null>],"
- + "JdbcTable[name=SALES,type=TABLE,remarks=<null>]}", Arrays.toString(schema.getTables()));
-
- assertEquals(
- "{Relationship[primaryTable=COUNTRY,primaryColumns={COUNTRY},foreignTable=CUSTOMER,foreignColumns={COUNTRY}],"
- + "Relationship[primaryTable=COUNTRY,primaryColumns={COUNTRY},foreignTable=JOB,foreignColumns={JOB_COUNTRY}],"
- + "Relationship[primaryTable=CUSTOMER,primaryColumns={CUST_NO},foreignTable=SALES,foreignColumns={CUST_NO}],"
- + "Relationship[primaryTable=DEPARTMENT,primaryColumns={DEPT_NO},foreignTable=DEPARTMENT,foreignColumns={HEAD_DEPT}],"
- + "Relationship[primaryTable=DEPARTMENT,primaryColumns={DEPT_NO},foreignTable=EMPLOYEE,foreignColumns={DEPT_NO}],"
- + "Relationship[primaryTable=DEPARTMENT,primaryColumns={DEPT_NO},foreignTable=PROJ_DEPT_BUDGET,foreignColumns={DEPT_NO}],"
- + "Relationship[primaryTable=EMPLOYEE,primaryColumns={EMP_NO},foreignTable=DEPARTMENT,foreignColumns={MNGR_NO}],"
- + "Relationship[primaryTable=EMPLOYEE,primaryColumns={EMP_NO},foreignTable=EMPLOYEE_PROJECT,foreignColumns={EMP_NO}],"
- + "Relationship[primaryTable=EMPLOYEE,primaryColumns={EMP_NO},foreignTable=PROJECT,foreignColumns={TEAM_LEADER}],"
- + "Relationship[primaryTable=EMPLOYEE,primaryColumns={EMP_NO},foreignTable=SALARY_HISTORY,foreignColumns={EMP_NO}],"
- + "Relationship[primaryTable=EMPLOYEE,primaryColumns={EMP_NO},foreignTable=SALES,foreignColumns={SALES_REP}],"
- + "Relationship[primaryTable=JOB,primaryColumns={JOB_CODE},foreignTable=EMPLOYEE,foreignColumns={JOB_CODE}],"
- + "Relationship[primaryTable=JOB,primaryColumns={JOB_GRADE},foreignTable=EMPLOYEE,foreignColumns={JOB_GRADE}],"
- + "Relationship[primaryTable=JOB,primaryColumns={JOB_COUNTRY},foreignTable=EMPLOYEE,foreignColumns={JOB_COUNTRY}],"
- + "Relationship[primaryTable=PROJECT,primaryColumns={PROJ_ID},foreignTable=EMPLOYEE_PROJECT,foreignColumns={PROJ_ID}],"
- + "Relationship[primaryTable=PROJECT,primaryColumns={PROJ_ID},foreignTable=PROJ_DEPT_BUDGET,foreignColumns={PROJ_ID}]}",
- Arrays.toString(schema.getRelationships()));
- }
-
- public void testExecuteQuery() throws Exception {
- Schema schema = _dataContext.getDefaultSchema();
- Table departmentTable = schema.getTableByName("DEPARTMENT");
- Table employeeTable = schema.getTableByName("EMPLOYEE");
- Query q = new Query().from(new FromItem(JoinType.INNER, departmentTable.getRelationships(employeeTable)[0]));
- q.select(departmentTable.getColumns()[1]);
- q.select(new SelectItem(employeeTable.getColumns()[4]).setAlias("hire-date"));
- assertEquals(
- "SELECT \"DEPARTMENT\".\"DEPARTMENT\", \"EMPLOYEE\".\"HIRE_DATE\" AS hire-date FROM \"EMPLOYEE\" INNER JOIN \"DEPARTMENT\" ON \"EMPLOYEE\".\"EMP_NO\" = \"DEPARTMENT\".\"MNGR_NO\"",
- q.toString());
-
- DataSet data = _dataContext.executeQuery(q);
- assertNotNull(data);
-
- TableModel tableModel = new DataSetTableModel(data);
- assertEquals(2, tableModel.getColumnCount());
- assertEquals(17, tableModel.getRowCount());
- assertEquals("Quality Assurance", tableModel.getValueAt(4, 0).toString());
-
- Date date = (Date) tableModel.getValueAt(4, 1);
- assertEquals("1989-04-17 00:00:00.000000", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS").format(date));
-
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/test/integrationtests/org/eobjects/metamodel/MysqlTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/eobjects/metamodel/MysqlTest.java b/jdbc/src/test/integrationtests/org/eobjects/metamodel/MysqlTest.java
deleted file mode 100644
index 4bd814d..0000000
--- a/jdbc/src/test/integrationtests/org/eobjects/metamodel/MysqlTest.java
+++ /dev/null
@@ -1,334 +0,0 @@
-package org.eobjects.metamodel;
-
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Arrays;
-import java.util.List;
-
-import javax.swing.table.TableModel;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetTableModel;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.jdbc.JdbcTestTemplates;
-import org.eobjects.metamodel.jdbc.QuerySplitter;
-import org.eobjects.metamodel.jdbc.dialects.MysqlQueryRewriter;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.schema.TableType;
-
-/**
- * Test case that tests mysql interaction. The test requires the "sakila" sample
- * database that can be found at dev.mysql.com.
- *
- * @see http://dev.mysql.com/doc/sakila/en/sakila.html#sakila-installation
- */
-public class MysqlTest extends TestCase {
-
- private static final String CONNECTION_STRING = "jdbc:mysql://localhost/sakila?defaultFetchSize=" + Integer.MIN_VALUE;
- private static final String USERNAME = "eobjects";
- private static final String PASSWORD = "eobjects";
- private Connection _connection;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- Class.forName("com.mysql.jdbc.Driver");
- _connection = DriverManager.getConnection(CONNECTION_STRING, USERNAME, PASSWORD);
- }
-
- public void testInterpretationOfNull() throws Exception {
- JdbcTestTemplates.interpretationOfNulls(_connection);
- }
-
- public void testDatabaseProductName() throws Exception {
- String databaseProductName = _connection.getMetaData().getDatabaseProductName();
- assertEquals(JdbcDataContext.DATABASE_PRODUCT_MYSQL, databaseProductName);
- }
-
- public void testAutomaticConversionWhenInsertingString() throws Exception {
- assertNotNull(_connection);
-
- Statement st = _connection.createStatement();
- try {
- // clean up, if nescesary
- st.execute("DROP TABLE test_table");
- st.close();
- } catch (SQLException e) {
- // do nothing
- }
-
- assertFalse(_connection.isReadOnly());
-
- JdbcDataContext dc = new JdbcDataContext(_connection);
- final Schema schema = dc.getDefaultSchema();
- assertEquals("sakila", schema.getName());
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- Table table = cb.createTable(schema, "test_table").withColumn("id").ofType(ColumnType.INTEGER)
- .asPrimaryKey().withColumn("birthdate").ofType(ColumnType.DATE).execute();
-
- cb.insertInto(table).value("id", "1").execute();
- cb.insertInto(table).value("id", 2).value("birthdate", "2011-12-21").execute();
- }
- });
-
- assertTrue(dc.getColumnByQualifiedLabel("test_table.id").isPrimaryKey());
- assertFalse(dc.getColumnByQualifiedLabel("test_table.birthdate").isPrimaryKey());
-
- DataSet ds = dc.query().from("test_table").select("id").and("birthdate").execute();
- assertTrue(ds.next());
- assertEquals("Row[values=[1, null]]", ds.getRow().toString());
- assertEquals("java.lang.Integer", ds.getRow().getValue(0).getClass().getName());
- assertTrue(ds.next());
- assertEquals("Row[values=[2, 2011-12-21]]", ds.getRow().toString());
- assertEquals("java.sql.Date", ds.getRow().getValue(1).getClass().getName());
- assertFalse(ds.next());
- ds.close();
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.dropTable("test_table").execute();
- }
- });
- }
-
- public void testCharOfSizeOne() throws Exception {
- JdbcTestTemplates.meaningOfOneSizeChar(_connection);
- }
-
- public void testAlternativeConnectionString() throws Exception {
- _connection = DriverManager.getConnection("jdbc:mysql://localhost", USERNAME, PASSWORD);
- DataContext dc = new JdbcDataContext(_connection, TableType.DEFAULT_TABLE_TYPES, "sakila");
- Schema[] schemas = dc.getSchemas();
- assertEquals("[Schema[name=mysql], Schema[name=performance_schema], Schema[name=portal], "
- + "Schema[name=sakila], Schema[name=world]]", Arrays.toString(schemas));
-
- Table table = dc.getSchemaByName("sakila").getTableByName("film");
- Query q = new Query().from(table).select(table.getColumns());
- DataSet data = dc.executeQuery(q);
- TableModel tableModel = new DataSetTableModel(data);
- assertEquals(13, tableModel.getColumnCount());
- assertEquals(1000, tableModel.getRowCount());
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- _connection.close();
- }
-
- public void testGetCatalogNames() throws Exception {
- JdbcDataContext strategy = new JdbcDataContext(_connection);
- assertTrue(strategy.getQueryRewriter() instanceof MysqlQueryRewriter);
- String[] catalogNames = strategy.getCatalogNames();
- assertEquals("[information_schema, mysql, performance_schema, portal, sakila, world]",
- Arrays.toString(catalogNames));
- }
-
- public void testGetDefaultSchema() throws Exception {
- DataContext dc = new JdbcDataContext(_connection);
- Schema schema = dc.getDefaultSchema();
- assertEquals("sakila", schema.getName());
- }
-
- public void testExecuteQuery() throws Exception {
- DataContext dc = new JdbcDataContext(_connection);
- Schema schema = dc.getDefaultSchema();
- Table actorTable = schema.getTableByName("actor");
- assertEquals(
- "[Column[name=actor_id,columnNumber=0,type=SMALLINT,nullable=false,nativeType=SMALLINT UNSIGNED,columnSize=5], Column[name=first_name,columnNumber=1,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=45], Column[name=last_name,columnNumber=2,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=45], Column[name=last_update,columnNumber=3,type=TIMESTAMP,nullable=false,nativeType=TIMESTAMP,columnSize=19]]",
- Arrays.toString(actorTable.getColumns()));
- Table filmTable = schema.getTableByName("film");
- assertEquals(
- "[Column[name=film_id,columnNumber=0,type=SMALLINT,nullable=false,nativeType=SMALLINT UNSIGNED,columnSize=5], Column[name=title,columnNumber=1,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=255], Column[name=description,columnNumber=2,type=LONGVARCHAR,nullable=true,nativeType=TEXT,columnSize=65535], Column[name=release_year,columnNumber=3,type=DATE,nullable=true,nativeType=YEAR,columnSize=0], Column[name=language_id,columnNumber=4,type=TINYINT,nullable=false,nativeType=TINYINT UNSIGNED,columnSize=3], Column[name=original_language_id,columnNumber=5,type=TINYINT,nullable=true,nativeType=TINYINT UNSIGNED,columnSize=3], Column[name=rental_duration,columnNumber=6,type=TINYINT,nullable=false,nativeType=TINYINT UNSIGNED,columnSize=3], Column[name=rental_rate,columnNumber=7,type=DECIMAL,nullable=false,nativeType=DECIMAL,columnSize=4], Column[name=length,columnNumber=8,type=SMALLINT,nullable=true,nativeType=SMALLINT UNSIGNED,columnSize=5], Column[name=replacement_cost,columnNu
mber=9,type=DECIMAL,nullable=false,nativeType=DECIMAL,columnSize=5], Column[name=rating,columnNumber=10,type=CHAR,nullable=true,nativeType=ENUM,columnSize=5], Column[name=special_features,columnNumber=11,type=CHAR,nullable=true,nativeType=SET,columnSize=54], Column[name=last_update,columnNumber=12,type=TIMESTAMP,nullable=false,nativeType=TIMESTAMP,columnSize=19]]",
- Arrays.toString(filmTable.getColumns()));
- Table filmActorJoinTable = schema.getTableByName("film_actor");
- assertEquals(
- "[Column[name=actor_id,columnNumber=0,type=SMALLINT,nullable=false,nativeType=SMALLINT UNSIGNED,columnSize=5], "
- + "Column[name=film_id,columnNumber=1,type=SMALLINT,nullable=false,nativeType=SMALLINT UNSIGNED,columnSize=5], "
- + "Column[name=last_update,columnNumber=2,type=TIMESTAMP,nullable=false,nativeType=TIMESTAMP,columnSize=19]]",
- Arrays.toString(filmActorJoinTable.getColumns()));
-
- Query q = new Query();
- q.from(new FromItem(actorTable).setAlias("a"));
- q.select(actorTable.getColumns());
- q.getSelectClause().getItem(0).setAlias("foo-bar");
- assertEquals(
- "SELECT a.`actor_id` AS foo-bar, a.`first_name`, a.`last_name`, a.`last_update` FROM sakila.`actor` a",
- q.toString());
- FilterItem f1 = new FilterItem(q.getSelectClause().getItem(0), OperatorType.EQUALS_TO, 5);
- FilterItem f2 = new FilterItem(q.getSelectClause().getItem(0), OperatorType.EQUALS_TO, 8);
- q.where(new FilterItem(f1, f2));
-
- DataSet dataSet = dc.executeQuery(q);
- TableModel tableModel = new DataSetTableModel(dataSet);
- assertEquals(4, tableModel.getColumnCount());
- assertEquals(2, tableModel.getRowCount());
- assertEquals("LOLLOBRIGIDA", tableModel.getValueAt(0, 2));
-
- q.setMaxRows(1);
- dataSet = dc.executeQuery(q);
- tableModel = new DataSetTableModel(dataSet);
- assertEquals(4, tableModel.getColumnCount());
- assertEquals(1, tableModel.getRowCount());
- assertEquals("LOLLOBRIGIDA", tableModel.getValueAt(0, 2));
-
- q.setMaxRows(1);
- q.setFirstRow(2);
- dataSet = dc.executeQuery(q);
- tableModel = new DataSetTableModel(dataSet);
- assertEquals(4, tableModel.getColumnCount());
- assertEquals(1, tableModel.getRowCount());
- assertEquals("JOHANSSON", tableModel.getValueAt(0, 2));
-
- q.getWhereClause().removeItems();
- q.setMaxRows(25);
- q.setFirstRow(1);
- dataSet = dc.executeQuery(q);
- tableModel = new DataSetTableModel(dataSet);
- assertEquals(4, tableModel.getColumnCount());
- assertEquals(25, tableModel.getRowCount());
- assertEquals("GUINESS", tableModel.getValueAt(0, 2).toString());
- }
-
- // Test to query the film table (caused troubles in DataCleaner)
- public void testFilmQuery() throws Exception {
- DataContext dc = new JdbcDataContext(_connection);
- Table table = dc.getDefaultSchema().getTableByName("film");
- Query q = new Query().select(table.getColumns()).from(table).setMaxRows(400);
- dc.executeQuery(q);
- }
-
- public void testGetSchema() throws Exception {
- DataContext dc = new JdbcDataContext(_connection);
- Schema[] schemas = dc.getSchemas();
- assertEquals(5, schemas.length);
- Schema schema = dc.getDefaultSchema();
-
- assertEquals("[Table[name=actor,type=TABLE,remarks=], " + "Table[name=address,type=TABLE,remarks=], "
- + "Table[name=category,type=TABLE,remarks=], " + "Table[name=city,type=TABLE,remarks=], "
- + "Table[name=country,type=TABLE,remarks=], " + "Table[name=customer,type=TABLE,remarks=], "
- + "Table[name=film,type=TABLE,remarks=], " + "Table[name=film_actor,type=TABLE,remarks=], "
- + "Table[name=film_category,type=TABLE,remarks=], " + "Table[name=film_text,type=TABLE,remarks=], "
- + "Table[name=inventory,type=TABLE,remarks=], " + "Table[name=language,type=TABLE,remarks=], "
- + "Table[name=payment,type=TABLE,remarks=], " + "Table[name=rental,type=TABLE,remarks=], "
- + "Table[name=staff,type=TABLE,remarks=], " + "Table[name=store,type=TABLE,remarks=], "
- + "Table[name=actor_info,type=VIEW,remarks=], " + "Table[name=customer_list,type=VIEW,remarks=], "
- + "Table[name=film_list,type=VIEW,remarks=], "
- + "Table[name=nicer_but_slower_film_list,type=VIEW,remarks=], "
- + "Table[name=sales_by_film_category,type=VIEW,remarks=], "
- + "Table[name=sales_by_store,type=VIEW,remarks=], " + "Table[name=staff_list,type=VIEW,remarks=]]",
- Arrays.toString(schema.getTables()));
-
- Table filmTable = schema.getTableByName("film");
- assertEquals(
- "[Column[name=film_id,columnNumber=0,type=SMALLINT,nullable=false,nativeType=SMALLINT UNSIGNED,columnSize=5], "
- + "Column[name=title,columnNumber=1,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=255], "
- + "Column[name=description,columnNumber=2,type=LONGVARCHAR,nullable=true,nativeType=TEXT,columnSize=65535], "
- + "Column[name=release_year,columnNumber=3,type=DATE,nullable=true,nativeType=YEAR,columnSize=0], "
- + "Column[name=language_id,columnNumber=4,type=TINYINT,nullable=false,nativeType=TINYINT UNSIGNED,columnSize=3], "
- + "Column[name=original_language_id,columnNumber=5,type=TINYINT,nullable=true,nativeType=TINYINT UNSIGNED,columnSize=3], "
- + "Column[name=rental_duration,columnNumber=6,type=TINYINT,nullable=false,nativeType=TINYINT UNSIGNED,columnSize=3], "
- + "Column[name=rental_rate,columnNumber=7,type=DECIMAL,nullable=false,nativeType=DECIMAL,columnSize=4], "
- + "Column[name=length,columnNumber=8,type=SMALLINT,nullable=true,nativeType=SMALLINT UNSIGNED,columnSize=5], "
- + "Column[name=replacement_cost,columnNumber=9,type=DECIMAL,nullable=false,nativeType=DECIMAL,columnSize=5], "
- + "Column[name=rating,columnNumber=10,type=CHAR,nullable=true,nativeType=ENUM,columnSize=5], "
- + "Column[name=special_features,columnNumber=11,type=CHAR,nullable=true,nativeType=SET,columnSize=54], "
- + "Column[name=last_update,columnNumber=12,type=TIMESTAMP,nullable=false,nativeType=TIMESTAMP,columnSize=19]]",
- Arrays.toString(filmTable.getColumns()));
- assertEquals(
- "[Relationship[primaryTable=language,primaryColumns=[language_id],foreignTable=film,foreignColumns=[language_id]], Relationship[primaryTable=language,primaryColumns=[language_id],foreignTable=film,foreignColumns=[original_language_id]], Relationship[primaryTable=film,primaryColumns=[film_id],foreignTable=film_actor,foreignColumns=[film_id]], Relationship[primaryTable=film,primaryColumns=[film_id],foreignTable=film_category,foreignColumns=[film_id]], Relationship[primaryTable=film,primaryColumns=[film_id],foreignTable=inventory,foreignColumns=[film_id]]]",
- Arrays.toString(filmTable.getRelationships()));
-
- dc = new JdbcDataContext(_connection, TableType.DEFAULT_TABLE_TYPES, "sakila");
- schemas = dc.getSchemas();
- assertEquals(6, schemas.length);
- assertEquals("[Table[name=actor,type=TABLE,remarks=], " + "Table[name=address,type=TABLE,remarks=], "
- + "Table[name=category,type=TABLE,remarks=], " + "Table[name=city,type=TABLE,remarks=], "
- + "Table[name=country,type=TABLE,remarks=], " + "Table[name=customer,type=TABLE,remarks=], "
- + "Table[name=film,type=TABLE,remarks=], " + "Table[name=film_actor,type=TABLE,remarks=], "
- + "Table[name=film_category,type=TABLE,remarks=], " + "Table[name=film_text,type=TABLE,remarks=], "
- + "Table[name=inventory,type=TABLE,remarks=], " + "Table[name=language,type=TABLE,remarks=], "
- + "Table[name=payment,type=TABLE,remarks=], " + "Table[name=rental,type=TABLE,remarks=], "
- + "Table[name=staff,type=TABLE,remarks=], " + "Table[name=store,type=TABLE,remarks=], "
- + "Table[name=actor_info,type=VIEW,remarks=], " + "Table[name=customer_list,type=VIEW,remarks=], "
- + "Table[name=film_list,type=VIEW,remarks=], "
- + "Table[name=nicer_but_slower_film_list,type=VIEW,remarks=], "
- + "Table[name=sales_by_film_category,type=VIEW,remarks=], "
- + "Table[name=sales_by_store,type=VIEW,remarks=], " + "Table[name=staff_list,type=VIEW,remarks=]]",
- Arrays.toString(schema.getTables()));
-
- Table staffView = schema.getTableByName("staff_list");
- assertEquals(
- "[Column[name=ID,columnNumber=0,type=TINYINT,nullable=false,nativeType=TINYINT UNSIGNED,columnSize=3], "
- + "Column[name=name,columnNumber=1,type=VARCHAR,nullable=true,nativeType=VARCHAR,columnSize=91], "
- + "Column[name=address,columnNumber=2,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=50], "
- + "Column[name=zip code,columnNumber=3,type=VARCHAR,nullable=true,nativeType=VARCHAR,columnSize=10], "
- + "Column[name=phone,columnNumber=4,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=20], "
- + "Column[name=city,columnNumber=5,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=50], "
- + "Column[name=country,columnNumber=6,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=50], "
- + "Column[name=SID,columnNumber=7,type=TINYINT,nullable=false,nativeType=TINYINT UNSIGNED,columnSize=3]]",
- Arrays.toString(staffView.getColumns()));
- }
-
- public void testSplitQuery() throws Exception {
- DataContext dc = new JdbcDataContext(_connection, TableType.DEFAULT_TABLE_TYPES, "sakila");
- Schema schema = dc.getSchemaByName("sakila");
- Table staffListTable = schema.getTableByName("staff_list");
- assertNotNull(staffListTable);
- Table paymentTable = schema.getTableByName("payment");
- assertNotNull(paymentTable);
- Column countryColumn = staffListTable.getColumnByName("country");
- assertNotNull(countryColumn);
- Column paymentColumn = paymentTable.getColumns()[0];
- assertNotNull(paymentColumn);
- Query q = new Query().from(staffListTable, "sl").from(paymentTable, "e").select(countryColumn, paymentColumn);
- assertEquals("SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e",
- q.toString());
-
- QuerySplitter qs = new QuerySplitter(dc, q);
- assertEquals(32098, qs.getRowCount());
- List<Query> splitQueries = qs.setMaxRows(8000).splitQuery();
- assertEquals(7, splitQueries.size());
- assertEquals(
- "[SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` < 4013 OR e.`rental_id` IS NULL) AND (e.`customer_id` < 300 OR e.`customer_id` IS NULL), SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` < 4013 OR e.`rental_id` IS NULL) AND (e.`customer_id` > 300 OR e.`customer_id` = 300), SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` > 4013 OR e.`rental_id` = 4013) AND (e.`rental_id` < 8025 OR e.`rental_id` = 4013) AND (e.`payment_id` < 8025 OR e.`payment_id` IS NULL), SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` > 4013 OR e.`rental_id` = 4013) AND (e.`rental_id` < 8025 OR e.`rental_id` = 4013) AND (e.`payment_id` > 8025 OR e.`payment_id` = 8025), SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` > 8025 OR e.`re
ntal_id` = 8025) AND (e.`rental_id` < 12037 OR e.`rental_id` = 8025) AND (e.`amount` < 6 OR e.`amount` IS NULL), SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` > 8025 OR e.`rental_id` = 8025) AND (e.`rental_id` < 12037 OR e.`rental_id` = 8025) AND (e.`amount` > 6 OR e.`amount` = 6), SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` > 12037 OR e.`rental_id` = 12037)]",
- Arrays.toString(splitQueries.toArray()));
-
- DataSet data = qs.executeQueries();
- int count = 0;
- while (data.next()) {
- count++;
- }
- data.close();
- assertEquals(32098, count);
- }
-
- public void testQueryWithSingleQuote() throws Exception {
- DataContext dc = new JdbcDataContext(_connection, TableType.DEFAULT_TABLE_TYPES, "sakila");
- Query q = dc.query().from("category").selectCount().where("name").eq("kasper's horror movies").toQuery();
- DataSet ds = dc.executeQuery(q);
- assertTrue(ds.next());
- assertEquals(0, ((Number) ds.getRow().getValue(0)).intValue());
- assertFalse(ds.next());
- }
-
- public void testWhiteSpaceColumns() throws Exception {
- DatabaseMetaData metaData = _connection.getMetaData();
- assertEquals("`", metaData.getIdentifierQuoteString());
- }
-}
\ No newline at end of file
[15/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/test/java/org/apache/metamodel/csv/CsvDataContextTest.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/apache/metamodel/csv/CsvDataContextTest.java b/csv/src/test/java/org/apache/metamodel/csv/CsvDataContextTest.java
new file mode 100644
index 0000000..a8b4d8e
--- /dev/null
+++ b/csv/src/test/java/org/apache/metamodel/csv/CsvDataContextTest.java
@@ -0,0 +1,744 @@
+/**
+ * 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.csv;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import javax.swing.table.TableModel;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.QueryPostprocessDataContext;
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.convert.Converters;
+import org.eobjects.metamodel.convert.StringToBooleanConverter;
+import org.eobjects.metamodel.convert.StringToIntegerConverter;
+import org.eobjects.metamodel.convert.TypeConverter;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.DataSetTableModel;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.FunctionType;
+import org.eobjects.metamodel.query.OperatorType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.FileHelper;
+import org.eobjects.metamodel.util.MutableRef;
+
+public class CsvDataContextTest extends TestCase {
+
+ private final CsvConfiguration semicolonConfiguration = new CsvConfiguration(
+ CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, "UTF-8", ';', '\'', CsvConfiguration.DEFAULT_ESCAPE_CHAR);
+
+ public void testEmptyFile() throws Exception {
+ DataContext dc = new CsvDataContext(new File("src/test/resources/empty_file.csv"));
+ assertEquals(1, dc.getDefaultSchema().getTableCount());
+
+ Table table = dc.getDefaultSchema().getTables()[0];
+ assertEquals("empty_file", table.getName());
+ assertEquals(0, table.getColumnCount());
+ }
+
+ public void testAppendToFileWithoutLineBreak() throws Exception {
+ File targetFile = new File("target/csv_no_linebreak");
+ FileHelper.copy(new File("src/test/resources/csv_no_linebreak.csv"), targetFile);
+
+ assertTrue(targetFile.exists());
+
+ assertEquals("foo,bar!LINEBREAK!hello,world!LINEBREAK!hi,there", FileHelper.readFileAsString(targetFile)
+ .replaceAll("\n", "!LINEBREAK!"));
+
+ final CsvDataContext dc = new CsvDataContext(targetFile);
+ final Table table = dc.getDefaultSchema().getTables()[0];
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.insertInto(table).value(0, "1234").value(1, "5678").execute();
+ }
+ });
+
+ assertEquals("foo,bar!LINEBREAK!hello,world!LINEBREAK!hi,there!LINEBREAK!\"1234\",\"5678\"", FileHelper
+ .readFileAsString(targetFile).replaceAll("\n", "!LINEBREAK!"));
+ }
+
+ public void testEmptyFileNoHeaderLine() throws Exception {
+ DataContext dc = new CsvDataContext(new File("src/test/resources/empty_file.csv"), new CsvConfiguration(
+ CsvConfiguration.NO_COLUMN_NAME_LINE));
+ assertEquals(1, dc.getDefaultSchema().getTableCount());
+
+ Table table = dc.getDefaultSchema().getTables()[0];
+ assertEquals("empty_file", table.getName());
+ assertEquals(0, table.getColumnCount());
+ }
+
+ public void testUnexistingHeaderLine() throws Exception {
+ DataContext dc = new CsvDataContext(new File("src/test/resources/csv_people.csv"), new CsvConfiguration(20));
+ assertEquals(1, dc.getDefaultSchema().getTableCount());
+
+ Table table = dc.getDefaultSchema().getTables()[0];
+ assertEquals("csv_people", table.getName());
+ assertEquals(0, table.getColumnCount());
+ }
+
+ public void testInconsistentColumns() throws Exception {
+ CsvConfiguration conf = new CsvConfiguration(CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, "UTF8", ',', '"', '\\',
+ true);
+ DataContext dc = new CsvDataContext(new File("src/test/resources/csv_inconsistent_columns.csv"), conf);
+ DataSet ds = dc.query().from("csv_inconsistent_columns").select("hello").and("world").execute();
+ assertTrue(ds.next());
+ assertTrue(ds.next());
+
+ try {
+ ds.next();
+ fail("Exception expected");
+ } catch (InconsistentRowLengthException e) {
+ assertEquals("Inconsistent length of row no. 3. Expected 2 columns but found 3.", e.getMessage());
+ Row proposedRow = e.getProposedRow();
+ assertEquals("[5, 6]", Arrays.toString(proposedRow.getValues()));
+
+ String[] sourceLine = e.getSourceLine();
+ assertEquals("[5, 6, 7]", Arrays.toString(sourceLine));
+ }
+
+ assertTrue(ds.next());
+
+ try {
+ ds.next();
+ fail("Exception expected");
+ } catch (InconsistentRowLengthException e) {
+ assertEquals("Inconsistent length of row no. 5. Expected 2 columns but found 1.", e.getMessage());
+ Row proposedRow = e.getProposedRow();
+ assertEquals("[10, null]", Arrays.toString(proposedRow.getValues()));
+
+ String[] sourceLine = e.getSourceLine();
+ assertEquals("[10]", Arrays.toString(sourceLine));
+ }
+
+ assertTrue(ds.next());
+ assertFalse(ds.next());
+ }
+
+ public void testApproximatedCountSmallFile() throws Exception {
+ DataContext dc = new CsvDataContext(new File("src/test/resources/csv_people.csv"));
+
+ Table table = dc.getDefaultSchema().getTables()[0];
+ Query q = dc.query().from(table).selectCount().toQuery();
+ SelectItem selectItem = q.getSelectClause().getItem(0);
+ selectItem.setFunctionApproximationAllowed(true);
+
+ DataSet ds = dc.executeQuery(q);
+ assertTrue(ds.next());
+ Object[] values = ds.getRow().getValues();
+ assertEquals(1, values.length);
+ assertEquals(9, ((Long) ds.getRow().getValue(selectItem)).intValue());
+ assertEquals(9, ((Long) values[0]).intValue());
+ assertFalse(ds.next());
+ }
+
+ public void testFilterOnNumberColumn() throws Exception {
+ CsvDataContext dc = new CsvDataContext(new File("src/test/resources/csv_people.csv"));
+ Table table = dc.getDefaultSchema().getTables()[0];
+
+ Query q = dc.query().from(table).select("name").where("age").greaterThan(18).toQuery();
+ List<Object[]> result = dc.executeQuery(q).toObjectArrays();
+ assertEquals(2, result.size());
+ assertEquals("[michael]", Arrays.toString(result.get(0)));
+ assertEquals("[hillary]", Arrays.toString(result.get(1)));
+ }
+
+ public void testGetFromInputStream() throws Exception {
+ DataContext dc = null;
+
+ // repeat this step a few times to test temp-file creation, see Ticket
+ // #437
+ for (int i = 0; i < 5; i++) {
+ File file = new File("src/test/resources/tickets.csv");
+ FileInputStream inputStream = new FileInputStream(file);
+ dc = new CsvDataContext(inputStream, new CsvConfiguration());
+ }
+
+ Schema schema = dc.getDefaultSchema();
+ String name = schema.getName();
+ assertTrue(name.startsWith("metamodel"));
+ assertTrue(name.endsWith("csv"));
+
+ // Test two seperate reads to ensure that the temp file is working
+ // properly and persistent.
+ doTicketFileTests(dc);
+ doTicketFileTests(dc);
+ }
+
+ public void testMultilineExample() throws Exception {
+ File file = new File("src/test/resources/tickets.csv");
+ DataContext dc = new CsvDataContext(file);
+ Schema schema = dc.getDefaultSchema();
+ Table table = schema.getTableByName("tickets");
+ Column descColumn = table.getColumnByName("_description");
+
+ assertNotNull(table);
+ assertNotNull(descColumn);
+
+ doTicketFileTests(dc);
+ }
+
+ public void doTicketFileTests(DataContext dc) {
+ Table table = dc.getDefaultSchema().getTables()[0];
+ Query q = dc.query().from(table).select(table.getColumns()).toQuery();
+
+ DataSet dataSet = dc.executeQuery(q);
+ List<Object[]> objectArrays = dataSet.toObjectArrays();
+ assertEquals(13, objectArrays.get(0).length);
+ assertEquals(36, objectArrays.size());
+ assertEquals("2", objectArrays.get(0)[0].toString());
+
+ Object description = objectArrays.get(0)[11];
+ assertTrue(description instanceof String);
+ assertEquals(
+ "We should have a look at the Value Distribution and Time Analysis profiles. They consume very large amounts of memory because they basicly save all values in maps for analysis.\n"
+ + "\n"
+ + "One way of improving this could be through caching. Another way could be through more appropriate (less verbose) storing of intermediate data (this looks obvious in Time Analysis profile). A third way could be by letting the profiles create queries themselves (related to metadata profiling, #222).",
+ (String) description);
+ }
+
+ public void testHighColumnNameLineNumber() throws Exception {
+ File file = new File("src/test/resources/csv_people.csv");
+ QueryPostprocessDataContext dc = new CsvDataContext(file, new CsvConfiguration(3));
+ Schema[] schemas = dc.getSchemas();
+ assertEquals(2, schemas.length);
+ Schema schema = dc.getDefaultSchema();
+ assertEquals("csv_people.csv", schema.getName());
+ assertEquals(1, schema.getTableCount());
+ Table table = schema.getTables()[0];
+ assertEquals("csv_people", table.getName());
+
+ assertEquals(4, table.getColumnCount());
+ assertEquals(0, table.getRelationshipCount());
+
+ Column[] columns = table.getColumns();
+ assertEquals("2", columns[0].getName());
+ assertEquals("michael", columns[1].getName());
+ assertEquals("male", columns[2].getName());
+ assertEquals("19", columns[3].getName());
+
+ Query query = dc.query().from(table).select(table.getColumnByName("michael")).toQuery();
+
+ DataSet dataSet = dc.executeQuery(query);
+ assertTrue(dataSet.next());
+ assertEquals("peter", dataSet.getRow().getValue(0));
+ assertTrue(dataSet.next());
+ assertEquals("bob", dataSet.getRow().getValue(0));
+ assertTrue(dataSet.next());
+ assertEquals("barbara, barb", dataSet.getRow().getValue(0));
+ }
+
+ public void testNoColumnNames() throws Exception {
+ File file = new File("src/test/resources/csv_people.csv");
+ QueryPostprocessDataContext dc = new CsvDataContext(file, new CsvConfiguration(
+ CsvConfiguration.NO_COLUMN_NAME_LINE));
+ Schema[] schemas = dc.getSchemas();
+ assertEquals(2, schemas.length);
+ Schema schema = dc.getDefaultSchema();
+ assertEquals("csv_people.csv", schema.getName());
+ assertEquals(1, schema.getTableCount());
+ Table table = schema.getTables()[0];
+ assertEquals("csv_people", table.getName());
+
+ assertEquals(4, table.getColumnCount());
+ assertEquals(0, table.getRelationshipCount());
+
+ Column[] columns = table.getColumns();
+ assertEquals("A", columns[0].getName());
+ assertEquals("B", columns[1].getName());
+ assertEquals("C", columns[2].getName());
+ assertEquals("D", columns[3].getName());
+
+ Query query = dc.query().from(table).select(table.getColumnByName("B")).toQuery();
+
+ DataSet dataSet = dc.executeQuery(query);
+ assertTrue(dataSet.next());
+ assertEquals("name", dataSet.getRow().getValue(0));
+ assertTrue(dataSet.next());
+ assertEquals("mike", dataSet.getRow().getValue(0));
+ assertTrue(dataSet.next());
+ assertEquals("michael", dataSet.getRow().getValue(0));
+ }
+
+ public void testGetSchemas() throws Exception {
+ File file = new File("src/test/resources/csv_people.csv");
+ QueryPostprocessDataContext dc = new CsvDataContext(file);
+ Schema[] schemas = dc.getSchemas();
+ assertEquals(2, schemas.length);
+ Schema schema = dc.getDefaultSchema();
+ assertEquals("csv_people.csv", schema.getName());
+ assertEquals(1, schema.getTableCount());
+ Table table = schema.getTables()[0];
+ assertEquals("csv_people", table.getName());
+
+ assertEquals(4, table.getColumnCount());
+ assertEquals(0, table.getRelationshipCount());
+
+ Column[] columns = table.getColumns();
+ assertEquals("id", columns[0].getName());
+ assertEquals("name", columns[1].getName());
+ assertEquals("gender", columns[2].getName());
+ assertEquals("age", columns[3].getName());
+ }
+
+ public void testWhereItemNotInSelectClause() throws Exception {
+ File file = new File("src/test/resources/csv_people.csv");
+ QueryPostprocessDataContext dc = new CsvDataContext(file);
+ Table table = dc.getDefaultSchema().getTableByName("csv_people");
+
+ Query q = new Query();
+ q.from(table);
+ q.where(new FilterItem(new SelectItem(table.getColumnByName("id")), OperatorType.EQUALS_TO, 1));
+ q.select(table.getColumnByName("name"));
+ DataSet data = dc.executeQuery(q);
+ assertTrue(data.next());
+ assertEquals("Row[values=[mike]]", data.getRow().toString());
+ assertFalse(data.next());
+ }
+
+ public void testWhereColumnInValues() throws Exception {
+ File file = new File("src/test/resources/csv_people.csv");
+ QueryPostprocessDataContext dc = new CsvDataContext(file);
+ Table table = dc.getDefaultSchema().getTableByName("csv_people");
+
+ Query q = dc.query().from(table).as("t").select("name").and("age").where("age").in("18", "20").toQuery();
+ assertEquals("SELECT t.name, t.age FROM csv_people.csv.csv_people t WHERE t.age IN ('18' , '20')", q.toSql());
+
+ DataSet ds = dc.executeQuery(q);
+ assertTrue(ds.next());
+ assertEquals("Row[values=[mike, 18]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[peter, 18]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[barbara, barb, 18]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[charlotte, 18]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[hillary, 20]]", ds.getRow().toString());
+ assertFalse(ds.next());
+
+ ds.close();
+ }
+
+ public void testGroupByQuery() throws Exception {
+ DataContext dc = new CsvDataContext(new File("src/test/resources/csv_people.csv"));
+ Table table = dc.getDefaultSchema().getTableByName("csv_people");
+
+ Query q = new Query();
+ q.from(table);
+ q.groupBy(table.getColumnByName("gender"));
+ q.select(new SelectItem(table.getColumnByName("gender")),
+ new SelectItem(FunctionType.MAX, table.getColumnByName("age")),
+ new SelectItem(FunctionType.MIN, table.getColumnByName("age")), new SelectItem(FunctionType.COUNT, "*",
+ "total"), new SelectItem(FunctionType.MIN, table.getColumnByName("id")).setAlias("firstId"));
+ DataSet data = dc.executeQuery(q);
+ assertEquals(
+ "[csv_people.gender, MAX(csv_people.age), MIN(csv_people.age), COUNT(*) AS total, MIN(csv_people.id) AS firstId]",
+ Arrays.toString(data.getSelectItems()));
+
+ String[] expectations = new String[] { "Row[values=[female, 20, 17, 5, 5]]", "Row[values=[male, 19, 17, 4, 1]]" };
+
+ assertTrue(data.next());
+ assertTrue(Arrays.asList(expectations).contains(data.getRow().toString()));
+ assertTrue(data.next());
+ assertTrue(Arrays.asList(expectations).contains(data.getRow().toString()));
+ assertFalse(data.next());
+ }
+
+ public void testMaterializeTable() throws Exception {
+ File file = new File("src/test/resources/csv_people.csv");
+ CsvDataContext dc = new CsvDataContext(file);
+ Table table = dc.getSchemas()[0].getTables()[0];
+ DataSet dataSet = dc.materializeMainSchemaTable(table, table.getColumns(), -1);
+ assertNull(dataSet.getRow());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[1, mike, male, 18]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[2, michael, male, 19]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[3, peter, male, 18]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[5, barbara, barb, female, 18]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[9, carrie, female, 17]]", dataSet.getRow().toString());
+ assertFalse(dataSet.next());
+
+ dataSet = dc.materializeMainSchemaTable(table, table.getColumns(), 1);
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[1, mike, male, 18]]", dataSet.getRow().toString());
+ assertFalse(dataSet.next());
+ }
+
+ public void testAlternativeDelimitors() throws Exception {
+ File file = new File("src/test/resources/csv_semicolon_singlequote.csv");
+ CsvDataContext dc = new CsvDataContext(file, semicolonConfiguration);
+ Table table = dc.getSchemas()[0].getTables()[0];
+ DataSet dataSet = dc.materializeMainSchemaTable(table, table.getColumns(), -1);
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[1, mike, male, 18]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[2, michael, male, 19]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[3, peter, male, 18]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[5, barbara; barb, female, 18]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[9, carrie, female, 17]]", dataSet.getRow().toString());
+ assertFalse(dataSet.next());
+ assertNull(dataSet.getRow());
+ }
+
+ public void testMaxRows() throws Exception {
+ File file = new File("src/test/resources/csv_semicolon_singlequote.csv");
+ CsvDataContext dc = new CsvDataContext(file, semicolonConfiguration);
+ Table table = dc.getDefaultSchema().getTables()[0];
+ Query query = new Query().from(table).select(table.getColumns()).setMaxRows(5);
+ DataSet dataSet = dc.executeQuery(query);
+
+ TableModel tableModel = new DataSetTableModel(dataSet);
+ assertEquals(5, tableModel.getRowCount());
+ }
+
+ public void testQueryOnlyAggregate() throws Exception {
+ File file = new File("src/test/resources/csv_people.csv");
+ QueryPostprocessDataContext dc = new CsvDataContext(file);
+ Table table = dc.getDefaultSchema().getTables()[0];
+
+ Query q = new Query().selectCount().from(table);
+ assertEquals("SELECT COUNT(*) FROM csv_people.csv.csv_people", q.toString());
+
+ List<Object[]> data = dc.executeQuery(q).toObjectArrays();
+ assertEquals(1, data.size());
+ Object[] row = data.get(0);
+ assertEquals(1, row.length);
+ assertEquals("[9]", Arrays.toString(row));
+
+ q.select(table.getColumns()[0]);
+ assertEquals("SELECT COUNT(*), csv_people.id FROM csv_people.csv.csv_people", q.toString());
+ data = dc.executeQuery(q).toObjectArrays();
+ assertEquals(9, data.size());
+ row = data.get(0);
+ assertEquals(2, row.length);
+ assertEquals("[9, 1]", Arrays.toString(row));
+
+ row = data.get(1);
+ assertEquals(2, row.length);
+ assertEquals("[9, 2]", Arrays.toString(row));
+
+ row = data.get(2);
+ assertEquals(2, row.length);
+ assertEquals("[9, 3]", Arrays.toString(row));
+
+ row = data.get(8);
+ assertEquals(2, row.length);
+ assertEquals("[9, 9]", Arrays.toString(row));
+ }
+
+ public void testOffsetAndMaxrows() throws Exception {
+ DataContext dc = new CsvDataContext(new File("src/test/resources/csv_people.csv"));
+
+ Table table = dc.getDefaultSchema().getTables()[0];
+ Query q = dc.query().from(table).select(table.getColumnByName("name")).toQuery();
+ q.setFirstRow(3);
+ q.setMaxRows(2);
+
+ DataSet ds;
+
+ ds = dc.executeQuery(q);
+ assertEquals(1, ds.getSelectItems().length);
+ assertTrue(ds.next());
+ assertEquals("peter", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("bob", ds.getRow().getValue(0).toString());
+ assertFalse(ds.next());
+ ds.close();
+
+ // try with iterator
+ ds = dc.executeQuery(q);
+ int i = 0;
+ for (Row row : ds) {
+ assertNotNull(row);
+ i++;
+ }
+ assertEquals(2, i);
+ }
+
+ public void testTruncateDeleteAllRecordsFromInconsistentFile() throws Exception {
+ File file = new File("target/csv_delete_all_records.txt");
+ FileHelper.copy(new File("src/test/resources/csv_to_be_truncated.csv"), file);
+
+ CsvDataContext dc = new CsvDataContext(file, new CsvConfiguration(1, "UTF8", ',', '"', '\\', true));
+ assertEquals("[id, name, gender, age]", Arrays.toString(dc.getDefaultSchema().getTable(0).getColumnNames()));
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.deleteFrom("csv_delete_all_records").execute();
+ }
+ });
+
+ DataSet ds = dc.query().from("csv_delete_all_records").selectCount().execute();
+ assertTrue(ds.next());
+ assertEquals(0, ((Number) ds.getRow().getValue(0)).intValue());
+ assertFalse(ds.next());
+
+ String fileAsString = FileHelper.readFileAsString(file);
+ assertEquals("\"id\",\"name\",\"gender\",\"age\"", fileAsString);
+ }
+
+ public void testWriteSimpleTableInNewFile() throws Exception {
+ final File file = new File("target/csv_write_ex1.txt");
+ file.delete();
+ assertFalse(file.exists());
+ CsvDataContext dc = new CsvDataContext(file);
+ final Schema schema = dc.getDefaultSchema();
+ assertEquals(0, schema.getTableCount());
+
+ final MutableRef<Table> tableRef = new MutableRef<Table>();
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ Table table = cb.createTable(schema, "foobar").withColumn("foo").withColumn("bar").execute();
+ tableRef.set(table);
+ assertEquals(schema, table.getSchema());
+ assertEquals(schema.getTables()[0], table);
+ assertTrue(file.exists());
+
+ assertEquals("[foo, bar]", Arrays.toString(table.getColumnNames()));
+
+ cb.insertInto(table).value(0, "f").value(1, "b").execute();
+ cb.insertInto(table).value(0, "o").value(table.getColumnByName("bar"), "a").execute();
+ cb.insertInto(table).value(0, "o").value("bar", "r").execute();
+ }
+ });
+
+ // query the file to check results
+ final Table readTable = schema.getTables()[0];
+ assertEquals(tableRef.get(), readTable);
+ assertEquals("[foo, bar]", Arrays.toString(readTable.getColumnNames()));
+
+ final Query query = dc.query().from(readTable).select("bar").and("foo").toQuery();
+ DataSet ds = dc.executeQuery(query);
+
+ assertTrue(ds.next());
+ assertEquals("Row[values=[b, f]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[a, o]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[r, o]]", ds.getRow().toString());
+ assertFalse(ds.next());
+
+ // do the same trick on an existing file
+ dc = new CsvDataContext(file);
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ cb.insertInto(tableRef.get()).value("foo", "hello").value("bar", "world").execute();
+ }
+ });
+
+ ds = dc.executeQuery(query);
+
+ assertTrue(ds.next());
+ assertEquals("Row[values=[b, f]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[a, o]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[r, o]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[world, hello]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ ds.close();
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.deleteFrom(readTable).where("bar").eq("a").execute();
+ callback.deleteFrom(readTable).where("bar").eq("r").execute();
+ }
+ });
+
+ ds = dc.executeQuery(query);
+ assertTrue(ds.next());
+ assertEquals("Row[values=[b, f]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[world, hello]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ ds.close();
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.update(readTable).value("foo", "universe").execute();
+ callback.update(readTable).value("bar", "c").where("bar").isEquals("b").execute();
+ }
+ });
+
+ ds = dc.executeQuery(query);
+ assertTrue(ds.next());
+ assertEquals("Row[values=[world, universe]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[c, universe]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ ds.close();
+
+ // drop table
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.dropTable(readTable).execute();
+ }
+ });
+
+ assertFalse(file.exists());
+ }
+
+ public void testOnlyNumberOneSymbol() throws Exception {
+ DataContext dc = new CsvDataContext(new File("src/test/resources/csv_only_number_one.csv"));
+ Map<Column, TypeConverter<?, ?>> converters = Converters.autoDetectConverters(dc, dc.getDefaultSchema()
+ .getTables()[0], 1000);
+
+ assertEquals(1, converters.size());
+ assertEquals(StringToBooleanConverter.class, converters.values().iterator().next().getClass());
+
+ dc = Converters.addTypeConverters(dc, converters);
+
+ Table table = dc.getDefaultSchema().getTables()[0];
+ MutableColumn col = (MutableColumn) table.getColumns()[0];
+ Query q = dc.query().from(table).select(col).toQuery();
+ assertEquals("SELECT csv_only_number_one.number FROM csv_only_number_one.csv.csv_only_number_one", q.toSql());
+
+ DataSet ds = dc.executeQuery(q);
+ while (ds.next()) {
+ assertEquals(true, ds.getRow().getValue(0));
+ }
+ ds.close();
+
+ dc = Converters.addTypeConverter(dc, col, new StringToIntegerConverter());
+
+ ds = dc.executeQuery(q);
+ while (ds.next()) {
+ assertEquals(1, ds.getRow().getValue(0));
+ }
+ ds.close();
+ }
+
+ public void testWriteOddConfiguration() throws Exception {
+ final File file = new File("target/csv_write_ex2.txt");
+ file.delete();
+ assertFalse(file.exists());
+
+ final CsvDataContext dc = new CsvDataContext(file, new CsvConfiguration(
+ CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, "UTF8", '|', '?', '!'));
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ Table table = cb.createTable(dc.getDefaultSchema(), "table").withColumn("id").withColumn("name")
+ .execute();
+ cb.insertInto(table).value("id", 1).value("name", "Kasper").execute();
+ cb.insertInto(table).value("id", 2).value("name", "Kas|per?").execute();
+ }
+ });
+
+ String[] lines = FileHelper.readFileAsString(file).split("\n");
+ assertEquals(3, lines.length);
+ assertEquals("?id?|?name?", lines[0]);
+ assertEquals("?1?|?Kasper?", lines[1]);
+ assertEquals("?2?|?Kas|per!??", lines[2]);
+ }
+
+ public void testCannotWriteToReadOnly() throws Exception {
+ final CsvDataContext dc = new CsvDataContext(new FileInputStream("src/test/resources/empty_file.csv"),
+ new CsvConfiguration());
+ try {
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ cb.createTable(dc.getDefaultSchema(), "foo");
+ }
+ });
+ fail("Exception expected");
+ } catch (IllegalStateException e) {
+ assertEquals("This CSV DataContext is not writable, as it based on a read-only resource.", e.getMessage());
+ }
+
+ // try {
+ // dc.executeUpdate(new Update() {
+ // @Override
+ // public void run(UpdateCallback cb) {
+ // cb.insertInto(dc.getDefaultSchema().getTables()[0]);
+ // }
+ // });
+ // fail("Exception expected");
+ // } catch (IllegalStateException e) {
+ // assertEquals(
+ // "This CSV DataContext is not writable, as it based on a read-only resource.",
+ // e.getMessage());
+ // }
+ }
+
+ // public void testOnlyWriteToOwnSchemasAndTables() throws Exception {
+ // CsvDataContext dc = new CsvDataContext(new File(
+ // "src/test/resources/empty_file.csv"), new CsvConfiguration());
+ // try {
+ // dc.executeUpdate(new Update() {
+ // @Override
+ // public void run(UpdateCallback cb) {
+ // cb.createTable(new MutableSchema("bar"), "foo");
+ // }
+ // );
+ // fail("Exception expected");
+ // } catch (IllegalArgumentException e) {
+ // assertEquals("Not a valid CSV schema: Schema[name=bar]",
+ // e.getMessage());
+ // }
+ //
+ // try {
+ // dc.insertInto(new MutableTable("bla"));
+ // fail("Exception expected");
+ // } catch (IllegalArgumentException e) {
+ // assertEquals(
+ // "Not a valid CSV table: Table[name=bla,type=null,remarks=null]",
+ // e.getMessage());
+ // }
+ // }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/test/java/org/apache/metamodel/csv/DefaultExampleValueGenerator.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/apache/metamodel/csv/DefaultExampleValueGenerator.java b/csv/src/test/java/org/apache/metamodel/csv/DefaultExampleValueGenerator.java
new file mode 100644
index 0000000..b84e93a
--- /dev/null
+++ b/csv/src/test/java/org/apache/metamodel/csv/DefaultExampleValueGenerator.java
@@ -0,0 +1,31 @@
+/**
+ * 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.csv;
+
+import org.junit.Ignore;
+
+@Ignore
+final class DefaultExampleValueGenerator implements ExampleValueGenerator {
+
+ @Override
+ public String generate(int row, int col) {
+ return "r" + row + "c" + col;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/test/java/org/apache/metamodel/csv/ExampleDataGenerator.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/apache/metamodel/csv/ExampleDataGenerator.java b/csv/src/test/java/org/apache/metamodel/csv/ExampleDataGenerator.java
new file mode 100644
index 0000000..e2da7bf
--- /dev/null
+++ b/csv/src/test/java/org/apache/metamodel/csv/ExampleDataGenerator.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.csv;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.junit.Ignore;
+
+/**
+ * Simple program used for creating large CSV datasets for performance/memory
+ * testing
+ */
+@Ignore
+class ExampleDataGenerator {
+
+ private final int _rows;
+ private final int _cols;
+ private final ExampleValueGenerator _valueGenerator;
+
+ public static void main(String[] args) {
+ // Convenience main method. Customize if needed.
+ ExampleDataGenerator gen = new ExampleDataGenerator(374635, 4, new RandomizedExampleValueGenerator(3));
+ gen.createFile( new File("test1.csv"));
+ gen.createFile( new File("test2.csv"));
+ gen.createFile( new File("test3.csv"));
+ }
+
+ public ExampleDataGenerator(int rows, int cols) {
+ this(rows, cols, new DefaultExampleValueGenerator());
+ }
+
+ public ExampleDataGenerator(int rows, int cols,
+ ExampleValueGenerator valueGenerator) {
+ _rows = rows;
+ _cols = cols;
+ _valueGenerator = valueGenerator;
+ }
+
+ public void createFile(File file) {
+ BufferedWriter writer = null;
+ try {
+ writer = new BufferedWriter(new FileWriter(file));
+
+ for (int j = 0; j < _cols; j++) {
+ if (j != 0) {
+ writer.write(',');
+ }
+ writer.write("col" + j);
+ }
+
+ for (int i = 0; i < _rows; i++) {
+ if (i % 500000 == 0) {
+ System.out.println("i: " + i);
+ }
+ writer.write('\n');
+ for (int j = 0; j < _cols; j++) {
+ if (j != 0) {
+ writer.write(',');
+ }
+ final String value = _valueGenerator.generate(i, j);
+ writer.write(value);
+ }
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (writer != null) {
+ try {
+ writer.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/test/java/org/apache/metamodel/csv/ExampleValueGenerator.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/apache/metamodel/csv/ExampleValueGenerator.java b/csv/src/test/java/org/apache/metamodel/csv/ExampleValueGenerator.java
new file mode 100644
index 0000000..d7420f0
--- /dev/null
+++ b/csv/src/test/java/org/apache/metamodel/csv/ExampleValueGenerator.java
@@ -0,0 +1,27 @@
+/**
+ * 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.csv;
+
+import org.junit.Ignore;
+
+@Ignore
+interface ExampleValueGenerator {
+
+ public String generate(int row, int col);
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/test/java/org/apache/metamodel/csv/RandomizedExampleValueGenerator.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/apache/metamodel/csv/RandomizedExampleValueGenerator.java b/csv/src/test/java/org/apache/metamodel/csv/RandomizedExampleValueGenerator.java
new file mode 100644
index 0000000..b616f67
--- /dev/null
+++ b/csv/src/test/java/org/apache/metamodel/csv/RandomizedExampleValueGenerator.java
@@ -0,0 +1,92 @@
+/**
+ * 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.csv;
+
+import java.util.Random;
+
+import org.junit.Ignore;
+
+@Ignore
+final class RandomizedExampleValueGenerator implements ExampleValueGenerator {
+
+ private final char[] diacriticChars = new char[] { 'æ', 'ø', 'å', 'ä', 'õ',
+ 'â', 'á', 'í', 'ì', 'ẽ', 'ŝ', 'é', 'ç' };
+ private final char[] strangeChars = new char[] { '*', '.', '~', '`', '@',
+ '[', ']', '#', '-' };
+ private final Random random = new Random();
+ private final int letterMin = 'a';
+ private final int letterMax = 'z';
+ private final int letterDiff = letterMax - letterMin;
+ private final int _tokenLength;
+
+ public RandomizedExampleValueGenerator() {
+ this(20);
+ }
+
+ public RandomizedExampleValueGenerator(int tokenLength) {
+ _tokenLength = tokenLength;
+ }
+
+ @Override
+ public String generate(int row, int col) {
+ int length = random.nextInt(_tokenLength);
+ if (length < 3) {
+ if (random.nextInt(1000) == 0) {
+ length = 0;
+ } else {
+ length = 1 + random.nextInt(5);
+ }
+ }
+ char[] chars = new char[length];
+ for (int i = 0; i < length; i++) {
+ chars[i] = nextChar();
+ }
+ return String.valueOf(chars);
+ }
+
+ private char nextChar() {
+ int unusualCharRandom = random.nextInt(10000);
+ if (unusualCharRandom < 91) {
+ return ' ';
+ } else if (unusualCharRandom < 109) {
+ return getRandom(diacriticChars);
+ } else if (unusualCharRandom < 113) {
+ return getRandom(strangeChars);
+ }
+ final int r = random.nextInt(letterDiff);
+ char c = (char) (r + letterMin);
+ if (random.nextInt(6) == 0) {
+ c = Character.toUpperCase(c);
+ }
+ return c;
+ }
+
+ private char getRandom(char[] chars) {
+ final int index = random.nextInt(chars.length);
+ return chars[index];
+ }
+
+ public static void main(String[] args) {
+ RandomizedExampleValueGenerator gen = new RandomizedExampleValueGenerator();
+ for (int i = 0; i < 1000; i++) {
+ System.out.println(gen.generate(0, 0));
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/test/java/org/apache/metamodel/csv/UnicodeWriterTest.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/apache/metamodel/csv/UnicodeWriterTest.java b/csv/src/test/java/org/apache/metamodel/csv/UnicodeWriterTest.java
new file mode 100644
index 0000000..a82b732
--- /dev/null
+++ b/csv/src/test/java/org/apache/metamodel/csv/UnicodeWriterTest.java
@@ -0,0 +1,51 @@
+/**
+ * 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.csv;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.Writer;
+
+import org.eobjects.metamodel.util.UnicodeWriter;
+import org.junit.Test;
+
+public class UnicodeWriterTest {
+
+ @Test
+ public void test() throws IOException {
+ File file = new File("target/unicodeWriterTest.txt");
+ Writer writer = new UnicodeWriter(file, "UTF-8");
+ writer.write("Hello");
+ writer.close();
+
+ FileInputStream is = new FileInputStream(file);
+ byte[] bytes = new byte[100];
+ assertEquals(8, is.read(bytes));
+
+ assertEquals(UnicodeWriter.UTF8_BOM[0], bytes[0]);
+ assertEquals(UnicodeWriter.UTF8_BOM[1], bytes[1]);
+ assertEquals(UnicodeWriter.UTF8_BOM[2], bytes[2]);
+ assertEquals((byte) 'H', bytes[3]);
+
+ is.close();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/test/java/org/apache/metamodel/intercept/InterceptionCsvIntegrationTest.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/apache/metamodel/intercept/InterceptionCsvIntegrationTest.java b/csv/src/test/java/org/apache/metamodel/intercept/InterceptionCsvIntegrationTest.java
new file mode 100644
index 0000000..3939cfe
--- /dev/null
+++ b/csv/src/test/java/org/apache/metamodel/intercept/InterceptionCsvIntegrationTest.java
@@ -0,0 +1,85 @@
+/**
+ * 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.intercept;
+
+import java.io.File;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.UpdateableDataContext;
+import org.eobjects.metamodel.create.TableCreationBuilder;
+import org.eobjects.metamodel.csv.CsvDataContext;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.insert.RowInsertionBuilder;
+import org.eobjects.metamodel.schema.Table;
+
+public class InterceptionCsvIntegrationTest extends TestCase {
+
+ public void testScenario() throws Exception {
+ final UpdateableDataContext source = new CsvDataContext(new File(
+ "target/test_interception_scenario.txt"));
+ final InterceptableDataContext dc = Interceptors.intercept(source);
+
+ dc.addTableCreationInterceptor(new TableCreationInterceptor() {
+ @Override
+ public TableCreationBuilder intercept(TableCreationBuilder input) {
+ return input.withColumn("foobar");
+ }
+ });
+
+ dc.addRowInsertionInterceptor(new RowInsertionInterceptor() {
+ @Override
+ public RowInsertionBuilder intercept(RowInsertionBuilder input) {
+ return input.value("foobar", "elite!");
+ }
+ });
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ Table table = callback
+ .createTable(dc.getDefaultSchema(), "table")
+ .withColumn("col1").withColumn("col2").execute();
+
+ callback.insertInto(table).value("col1", "hello")
+ .value("col2", "world").execute();
+ callback.insertInto(table).value("col1", "123")
+ .value("col2", "567").execute();
+ }
+ });
+
+ assertEquals("[test_interception_scenario]",
+ Arrays.toString(dc.getDefaultSchema().getTableNames()));
+ Table table = dc.getDefaultSchema().getTables()[0];
+ assertEquals("[col1, col2, foobar]",
+ Arrays.toString(table.getColumnNames()));
+
+ DataSet ds = dc.query().from(table).select(table.getColumns())
+ .execute();
+ assertTrue(ds.next());
+ assertEquals("Row[values=[hello, world, elite!]]", ds.getRow()
+ .toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[123, 567, elite!]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/test/java/org/eobjects/metamodel/csv/CsvBigFileMemoryTest.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/eobjects/metamodel/csv/CsvBigFileMemoryTest.java b/csv/src/test/java/org/eobjects/metamodel/csv/CsvBigFileMemoryTest.java
deleted file mode 100644
index 7e60184..0000000
--- a/csv/src/test/java/org/eobjects/metamodel/csv/CsvBigFileMemoryTest.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/**
- * 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.csv;
-
-import java.io.File;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.csv.CsvConfiguration;
-import org.eobjects.metamodel.csv.CsvDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Table;
-
-import junit.framework.TestCase;
-
-public class CsvBigFileMemoryTest extends TestCase {
-
- private final int hugeFileRows = 3000;
- private final int hugeFileCols = 2000;
-
- private File getHugeFile() {
- final File file = new File("target/huge_csv.csv");
- if (!file.exists()) {
-
- final ExampleDataGenerator exampleDataGenerator = new ExampleDataGenerator(
- hugeFileRows, hugeFileCols);
- exampleDataGenerator.createFile(file);
- }
- return file;
- }
-
- /**
- * Runs a performance test based on the data created by the
- * ExampleDataCreator utility.
- *
- * @see ExampleDataGenerator
- * @throws Exception
- */
- public void testHugeFile() throws Exception {
- final File file = getHugeFile();
-
- final long timeAtStart = System.currentTimeMillis();
- System.out.println("time at start: " + timeAtStart);
-
- final DataContext dc = new CsvDataContext(file, new CsvConfiguration());
- final Table t = dc.getDefaultSchema().getTables()[0];
-
- final long timeAfterDataContext = System.currentTimeMillis();
- System.out.println("time after DataContext: " + timeAfterDataContext);
-
- final Query q = new Query().select(t.getColumns()).from(t);
- DataSet ds = dc.executeQuery(q);
-
- long timeAfterQuery = System.currentTimeMillis();
- System.out.println("time after query: " + timeAfterQuery);
-
- while (ds.next()) {
- assertEquals(hugeFileCols, ds.getRow().getValues().length);
- }
- ds.close();
-
- long timeAfterDataSet = System.currentTimeMillis();
- System.out.println("time after dataSet: " + timeAfterDataSet);
-
- if (!file.delete()) {
- file.deleteOnExit();
- }
- }
-
- public void testApproximatedCountHugeFile() throws Exception {
- DataContext dc = new CsvDataContext(getHugeFile());
-
- Table table = dc.getDefaultSchema().getTables()[0];
- Query q = dc.query().from(table).selectCount().toQuery();
- SelectItem selectItem = q.getSelectClause().getItem(0);
- selectItem.setFunctionApproximationAllowed(true);
-
- DataSet ds = dc.executeQuery(q);
- assertTrue(ds.next());
- Object[] values = ds.getRow().getValues();
- assertEquals(1, values.length);
- assertEquals(3332, ((Long) ds.getRow().getValue(selectItem)).intValue());
- assertEquals(3332, ((Long) values[0]).intValue());
- assertFalse(ds.next());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/test/java/org/eobjects/metamodel/csv/CsvConfigurationTest.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/eobjects/metamodel/csv/CsvConfigurationTest.java b/csv/src/test/java/org/eobjects/metamodel/csv/CsvConfigurationTest.java
deleted file mode 100644
index 2948762..0000000
--- a/csv/src/test/java/org/eobjects/metamodel/csv/CsvConfigurationTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * 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.csv;
-
-import junit.framework.TestCase;
-
-public class CsvConfigurationTest extends TestCase {
-
- public void testToString() throws Exception {
- CsvConfiguration conf = new CsvConfiguration(0, "UTF8", ',', '"', '\\',
- true);
- assertEquals(
- "CsvConfiguration[columnNameLineNumber=0, encoding=UTF8, separatorChar=,, quoteChar=\", escapeChar=\\, failOnInconsistentRowLength=true]",
- conf.toString());
- }
-
- public void testEquals() throws Exception {
- CsvConfiguration conf1 = new CsvConfiguration(0, "UTF8", ',', '"',
- '\\', true);
- CsvConfiguration conf2 = new CsvConfiguration(0, "UTF8", ',', '"',
- '\\', true);
-
- assertEquals(conf1, conf2);
-
- CsvConfiguration conf3 = new CsvConfiguration(1, "UTF8", ',', '"',
- '\\', true);
- assertFalse(conf1.equals(conf3));
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/test/java/org/eobjects/metamodel/csv/CsvDataContextTest.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/eobjects/metamodel/csv/CsvDataContextTest.java b/csv/src/test/java/org/eobjects/metamodel/csv/CsvDataContextTest.java
deleted file mode 100644
index a8b4d8e..0000000
--- a/csv/src/test/java/org/eobjects/metamodel/csv/CsvDataContextTest.java
+++ /dev/null
@@ -1,744 +0,0 @@
-/**
- * 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.csv;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-import javax.swing.table.TableModel;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.convert.Converters;
-import org.eobjects.metamodel.convert.StringToBooleanConverter;
-import org.eobjects.metamodel.convert.StringToIntegerConverter;
-import org.eobjects.metamodel.convert.TypeConverter;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetTableModel;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.FileHelper;
-import org.eobjects.metamodel.util.MutableRef;
-
-public class CsvDataContextTest extends TestCase {
-
- private final CsvConfiguration semicolonConfiguration = new CsvConfiguration(
- CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, "UTF-8", ';', '\'', CsvConfiguration.DEFAULT_ESCAPE_CHAR);
-
- public void testEmptyFile() throws Exception {
- DataContext dc = new CsvDataContext(new File("src/test/resources/empty_file.csv"));
- assertEquals(1, dc.getDefaultSchema().getTableCount());
-
- Table table = dc.getDefaultSchema().getTables()[0];
- assertEquals("empty_file", table.getName());
- assertEquals(0, table.getColumnCount());
- }
-
- public void testAppendToFileWithoutLineBreak() throws Exception {
- File targetFile = new File("target/csv_no_linebreak");
- FileHelper.copy(new File("src/test/resources/csv_no_linebreak.csv"), targetFile);
-
- assertTrue(targetFile.exists());
-
- assertEquals("foo,bar!LINEBREAK!hello,world!LINEBREAK!hi,there", FileHelper.readFileAsString(targetFile)
- .replaceAll("\n", "!LINEBREAK!"));
-
- final CsvDataContext dc = new CsvDataContext(targetFile);
- final Table table = dc.getDefaultSchema().getTables()[0];
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.insertInto(table).value(0, "1234").value(1, "5678").execute();
- }
- });
-
- assertEquals("foo,bar!LINEBREAK!hello,world!LINEBREAK!hi,there!LINEBREAK!\"1234\",\"5678\"", FileHelper
- .readFileAsString(targetFile).replaceAll("\n", "!LINEBREAK!"));
- }
-
- public void testEmptyFileNoHeaderLine() throws Exception {
- DataContext dc = new CsvDataContext(new File("src/test/resources/empty_file.csv"), new CsvConfiguration(
- CsvConfiguration.NO_COLUMN_NAME_LINE));
- assertEquals(1, dc.getDefaultSchema().getTableCount());
-
- Table table = dc.getDefaultSchema().getTables()[0];
- assertEquals("empty_file", table.getName());
- assertEquals(0, table.getColumnCount());
- }
-
- public void testUnexistingHeaderLine() throws Exception {
- DataContext dc = new CsvDataContext(new File("src/test/resources/csv_people.csv"), new CsvConfiguration(20));
- assertEquals(1, dc.getDefaultSchema().getTableCount());
-
- Table table = dc.getDefaultSchema().getTables()[0];
- assertEquals("csv_people", table.getName());
- assertEquals(0, table.getColumnCount());
- }
-
- public void testInconsistentColumns() throws Exception {
- CsvConfiguration conf = new CsvConfiguration(CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, "UTF8", ',', '"', '\\',
- true);
- DataContext dc = new CsvDataContext(new File("src/test/resources/csv_inconsistent_columns.csv"), conf);
- DataSet ds = dc.query().from("csv_inconsistent_columns").select("hello").and("world").execute();
- assertTrue(ds.next());
- assertTrue(ds.next());
-
- try {
- ds.next();
- fail("Exception expected");
- } catch (InconsistentRowLengthException e) {
- assertEquals("Inconsistent length of row no. 3. Expected 2 columns but found 3.", e.getMessage());
- Row proposedRow = e.getProposedRow();
- assertEquals("[5, 6]", Arrays.toString(proposedRow.getValues()));
-
- String[] sourceLine = e.getSourceLine();
- assertEquals("[5, 6, 7]", Arrays.toString(sourceLine));
- }
-
- assertTrue(ds.next());
-
- try {
- ds.next();
- fail("Exception expected");
- } catch (InconsistentRowLengthException e) {
- assertEquals("Inconsistent length of row no. 5. Expected 2 columns but found 1.", e.getMessage());
- Row proposedRow = e.getProposedRow();
- assertEquals("[10, null]", Arrays.toString(proposedRow.getValues()));
-
- String[] sourceLine = e.getSourceLine();
- assertEquals("[10]", Arrays.toString(sourceLine));
- }
-
- assertTrue(ds.next());
- assertFalse(ds.next());
- }
-
- public void testApproximatedCountSmallFile() throws Exception {
- DataContext dc = new CsvDataContext(new File("src/test/resources/csv_people.csv"));
-
- Table table = dc.getDefaultSchema().getTables()[0];
- Query q = dc.query().from(table).selectCount().toQuery();
- SelectItem selectItem = q.getSelectClause().getItem(0);
- selectItem.setFunctionApproximationAllowed(true);
-
- DataSet ds = dc.executeQuery(q);
- assertTrue(ds.next());
- Object[] values = ds.getRow().getValues();
- assertEquals(1, values.length);
- assertEquals(9, ((Long) ds.getRow().getValue(selectItem)).intValue());
- assertEquals(9, ((Long) values[0]).intValue());
- assertFalse(ds.next());
- }
-
- public void testFilterOnNumberColumn() throws Exception {
- CsvDataContext dc = new CsvDataContext(new File("src/test/resources/csv_people.csv"));
- Table table = dc.getDefaultSchema().getTables()[0];
-
- Query q = dc.query().from(table).select("name").where("age").greaterThan(18).toQuery();
- List<Object[]> result = dc.executeQuery(q).toObjectArrays();
- assertEquals(2, result.size());
- assertEquals("[michael]", Arrays.toString(result.get(0)));
- assertEquals("[hillary]", Arrays.toString(result.get(1)));
- }
-
- public void testGetFromInputStream() throws Exception {
- DataContext dc = null;
-
- // repeat this step a few times to test temp-file creation, see Ticket
- // #437
- for (int i = 0; i < 5; i++) {
- File file = new File("src/test/resources/tickets.csv");
- FileInputStream inputStream = new FileInputStream(file);
- dc = new CsvDataContext(inputStream, new CsvConfiguration());
- }
-
- Schema schema = dc.getDefaultSchema();
- String name = schema.getName();
- assertTrue(name.startsWith("metamodel"));
- assertTrue(name.endsWith("csv"));
-
- // Test two seperate reads to ensure that the temp file is working
- // properly and persistent.
- doTicketFileTests(dc);
- doTicketFileTests(dc);
- }
-
- public void testMultilineExample() throws Exception {
- File file = new File("src/test/resources/tickets.csv");
- DataContext dc = new CsvDataContext(file);
- Schema schema = dc.getDefaultSchema();
- Table table = schema.getTableByName("tickets");
- Column descColumn = table.getColumnByName("_description");
-
- assertNotNull(table);
- assertNotNull(descColumn);
-
- doTicketFileTests(dc);
- }
-
- public void doTicketFileTests(DataContext dc) {
- Table table = dc.getDefaultSchema().getTables()[0];
- Query q = dc.query().from(table).select(table.getColumns()).toQuery();
-
- DataSet dataSet = dc.executeQuery(q);
- List<Object[]> objectArrays = dataSet.toObjectArrays();
- assertEquals(13, objectArrays.get(0).length);
- assertEquals(36, objectArrays.size());
- assertEquals("2", objectArrays.get(0)[0].toString());
-
- Object description = objectArrays.get(0)[11];
- assertTrue(description instanceof String);
- assertEquals(
- "We should have a look at the Value Distribution and Time Analysis profiles. They consume very large amounts of memory because they basicly save all values in maps for analysis.\n"
- + "\n"
- + "One way of improving this could be through caching. Another way could be through more appropriate (less verbose) storing of intermediate data (this looks obvious in Time Analysis profile). A third way could be by letting the profiles create queries themselves (related to metadata profiling, #222).",
- (String) description);
- }
-
- public void testHighColumnNameLineNumber() throws Exception {
- File file = new File("src/test/resources/csv_people.csv");
- QueryPostprocessDataContext dc = new CsvDataContext(file, new CsvConfiguration(3));
- Schema[] schemas = dc.getSchemas();
- assertEquals(2, schemas.length);
- Schema schema = dc.getDefaultSchema();
- assertEquals("csv_people.csv", schema.getName());
- assertEquals(1, schema.getTableCount());
- Table table = schema.getTables()[0];
- assertEquals("csv_people", table.getName());
-
- assertEquals(4, table.getColumnCount());
- assertEquals(0, table.getRelationshipCount());
-
- Column[] columns = table.getColumns();
- assertEquals("2", columns[0].getName());
- assertEquals("michael", columns[1].getName());
- assertEquals("male", columns[2].getName());
- assertEquals("19", columns[3].getName());
-
- Query query = dc.query().from(table).select(table.getColumnByName("michael")).toQuery();
-
- DataSet dataSet = dc.executeQuery(query);
- assertTrue(dataSet.next());
- assertEquals("peter", dataSet.getRow().getValue(0));
- assertTrue(dataSet.next());
- assertEquals("bob", dataSet.getRow().getValue(0));
- assertTrue(dataSet.next());
- assertEquals("barbara, barb", dataSet.getRow().getValue(0));
- }
-
- public void testNoColumnNames() throws Exception {
- File file = new File("src/test/resources/csv_people.csv");
- QueryPostprocessDataContext dc = new CsvDataContext(file, new CsvConfiguration(
- CsvConfiguration.NO_COLUMN_NAME_LINE));
- Schema[] schemas = dc.getSchemas();
- assertEquals(2, schemas.length);
- Schema schema = dc.getDefaultSchema();
- assertEquals("csv_people.csv", schema.getName());
- assertEquals(1, schema.getTableCount());
- Table table = schema.getTables()[0];
- assertEquals("csv_people", table.getName());
-
- assertEquals(4, table.getColumnCount());
- assertEquals(0, table.getRelationshipCount());
-
- Column[] columns = table.getColumns();
- assertEquals("A", columns[0].getName());
- assertEquals("B", columns[1].getName());
- assertEquals("C", columns[2].getName());
- assertEquals("D", columns[3].getName());
-
- Query query = dc.query().from(table).select(table.getColumnByName("B")).toQuery();
-
- DataSet dataSet = dc.executeQuery(query);
- assertTrue(dataSet.next());
- assertEquals("name", dataSet.getRow().getValue(0));
- assertTrue(dataSet.next());
- assertEquals("mike", dataSet.getRow().getValue(0));
- assertTrue(dataSet.next());
- assertEquals("michael", dataSet.getRow().getValue(0));
- }
-
- public void testGetSchemas() throws Exception {
- File file = new File("src/test/resources/csv_people.csv");
- QueryPostprocessDataContext dc = new CsvDataContext(file);
- Schema[] schemas = dc.getSchemas();
- assertEquals(2, schemas.length);
- Schema schema = dc.getDefaultSchema();
- assertEquals("csv_people.csv", schema.getName());
- assertEquals(1, schema.getTableCount());
- Table table = schema.getTables()[0];
- assertEquals("csv_people", table.getName());
-
- assertEquals(4, table.getColumnCount());
- assertEquals(0, table.getRelationshipCount());
-
- Column[] columns = table.getColumns();
- assertEquals("id", columns[0].getName());
- assertEquals("name", columns[1].getName());
- assertEquals("gender", columns[2].getName());
- assertEquals("age", columns[3].getName());
- }
-
- public void testWhereItemNotInSelectClause() throws Exception {
- File file = new File("src/test/resources/csv_people.csv");
- QueryPostprocessDataContext dc = new CsvDataContext(file);
- Table table = dc.getDefaultSchema().getTableByName("csv_people");
-
- Query q = new Query();
- q.from(table);
- q.where(new FilterItem(new SelectItem(table.getColumnByName("id")), OperatorType.EQUALS_TO, 1));
- q.select(table.getColumnByName("name"));
- DataSet data = dc.executeQuery(q);
- assertTrue(data.next());
- assertEquals("Row[values=[mike]]", data.getRow().toString());
- assertFalse(data.next());
- }
-
- public void testWhereColumnInValues() throws Exception {
- File file = new File("src/test/resources/csv_people.csv");
- QueryPostprocessDataContext dc = new CsvDataContext(file);
- Table table = dc.getDefaultSchema().getTableByName("csv_people");
-
- Query q = dc.query().from(table).as("t").select("name").and("age").where("age").in("18", "20").toQuery();
- assertEquals("SELECT t.name, t.age FROM csv_people.csv.csv_people t WHERE t.age IN ('18' , '20')", q.toSql());
-
- DataSet ds = dc.executeQuery(q);
- assertTrue(ds.next());
- assertEquals("Row[values=[mike, 18]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[peter, 18]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[barbara, barb, 18]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[charlotte, 18]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[hillary, 20]]", ds.getRow().toString());
- assertFalse(ds.next());
-
- ds.close();
- }
-
- public void testGroupByQuery() throws Exception {
- DataContext dc = new CsvDataContext(new File("src/test/resources/csv_people.csv"));
- Table table = dc.getDefaultSchema().getTableByName("csv_people");
-
- Query q = new Query();
- q.from(table);
- q.groupBy(table.getColumnByName("gender"));
- q.select(new SelectItem(table.getColumnByName("gender")),
- new SelectItem(FunctionType.MAX, table.getColumnByName("age")),
- new SelectItem(FunctionType.MIN, table.getColumnByName("age")), new SelectItem(FunctionType.COUNT, "*",
- "total"), new SelectItem(FunctionType.MIN, table.getColumnByName("id")).setAlias("firstId"));
- DataSet data = dc.executeQuery(q);
- assertEquals(
- "[csv_people.gender, MAX(csv_people.age), MIN(csv_people.age), COUNT(*) AS total, MIN(csv_people.id) AS firstId]",
- Arrays.toString(data.getSelectItems()));
-
- String[] expectations = new String[] { "Row[values=[female, 20, 17, 5, 5]]", "Row[values=[male, 19, 17, 4, 1]]" };
-
- assertTrue(data.next());
- assertTrue(Arrays.asList(expectations).contains(data.getRow().toString()));
- assertTrue(data.next());
- assertTrue(Arrays.asList(expectations).contains(data.getRow().toString()));
- assertFalse(data.next());
- }
-
- public void testMaterializeTable() throws Exception {
- File file = new File("src/test/resources/csv_people.csv");
- CsvDataContext dc = new CsvDataContext(file);
- Table table = dc.getSchemas()[0].getTables()[0];
- DataSet dataSet = dc.materializeMainSchemaTable(table, table.getColumns(), -1);
- assertNull(dataSet.getRow());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[1, mike, male, 18]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[2, michael, male, 19]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[3, peter, male, 18]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[5, barbara, barb, female, 18]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[9, carrie, female, 17]]", dataSet.getRow().toString());
- assertFalse(dataSet.next());
-
- dataSet = dc.materializeMainSchemaTable(table, table.getColumns(), 1);
- assertTrue(dataSet.next());
- assertEquals("Row[values=[1, mike, male, 18]]", dataSet.getRow().toString());
- assertFalse(dataSet.next());
- }
-
- public void testAlternativeDelimitors() throws Exception {
- File file = new File("src/test/resources/csv_semicolon_singlequote.csv");
- CsvDataContext dc = new CsvDataContext(file, semicolonConfiguration);
- Table table = dc.getSchemas()[0].getTables()[0];
- DataSet dataSet = dc.materializeMainSchemaTable(table, table.getColumns(), -1);
- assertTrue(dataSet.next());
- assertEquals("Row[values=[1, mike, male, 18]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[2, michael, male, 19]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[3, peter, male, 18]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[5, barbara; barb, female, 18]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[9, carrie, female, 17]]", dataSet.getRow().toString());
- assertFalse(dataSet.next());
- assertNull(dataSet.getRow());
- }
-
- public void testMaxRows() throws Exception {
- File file = new File("src/test/resources/csv_semicolon_singlequote.csv");
- CsvDataContext dc = new CsvDataContext(file, semicolonConfiguration);
- Table table = dc.getDefaultSchema().getTables()[0];
- Query query = new Query().from(table).select(table.getColumns()).setMaxRows(5);
- DataSet dataSet = dc.executeQuery(query);
-
- TableModel tableModel = new DataSetTableModel(dataSet);
- assertEquals(5, tableModel.getRowCount());
- }
-
- public void testQueryOnlyAggregate() throws Exception {
- File file = new File("src/test/resources/csv_people.csv");
- QueryPostprocessDataContext dc = new CsvDataContext(file);
- Table table = dc.getDefaultSchema().getTables()[0];
-
- Query q = new Query().selectCount().from(table);
- assertEquals("SELECT COUNT(*) FROM csv_people.csv.csv_people", q.toString());
-
- List<Object[]> data = dc.executeQuery(q).toObjectArrays();
- assertEquals(1, data.size());
- Object[] row = data.get(0);
- assertEquals(1, row.length);
- assertEquals("[9]", Arrays.toString(row));
-
- q.select(table.getColumns()[0]);
- assertEquals("SELECT COUNT(*), csv_people.id FROM csv_people.csv.csv_people", q.toString());
- data = dc.executeQuery(q).toObjectArrays();
- assertEquals(9, data.size());
- row = data.get(0);
- assertEquals(2, row.length);
- assertEquals("[9, 1]", Arrays.toString(row));
-
- row = data.get(1);
- assertEquals(2, row.length);
- assertEquals("[9, 2]", Arrays.toString(row));
-
- row = data.get(2);
- assertEquals(2, row.length);
- assertEquals("[9, 3]", Arrays.toString(row));
-
- row = data.get(8);
- assertEquals(2, row.length);
- assertEquals("[9, 9]", Arrays.toString(row));
- }
-
- public void testOffsetAndMaxrows() throws Exception {
- DataContext dc = new CsvDataContext(new File("src/test/resources/csv_people.csv"));
-
- Table table = dc.getDefaultSchema().getTables()[0];
- Query q = dc.query().from(table).select(table.getColumnByName("name")).toQuery();
- q.setFirstRow(3);
- q.setMaxRows(2);
-
- DataSet ds;
-
- ds = dc.executeQuery(q);
- assertEquals(1, ds.getSelectItems().length);
- assertTrue(ds.next());
- assertEquals("peter", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("bob", ds.getRow().getValue(0).toString());
- assertFalse(ds.next());
- ds.close();
-
- // try with iterator
- ds = dc.executeQuery(q);
- int i = 0;
- for (Row row : ds) {
- assertNotNull(row);
- i++;
- }
- assertEquals(2, i);
- }
-
- public void testTruncateDeleteAllRecordsFromInconsistentFile() throws Exception {
- File file = new File("target/csv_delete_all_records.txt");
- FileHelper.copy(new File("src/test/resources/csv_to_be_truncated.csv"), file);
-
- CsvDataContext dc = new CsvDataContext(file, new CsvConfiguration(1, "UTF8", ',', '"', '\\', true));
- assertEquals("[id, name, gender, age]", Arrays.toString(dc.getDefaultSchema().getTable(0).getColumnNames()));
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.deleteFrom("csv_delete_all_records").execute();
- }
- });
-
- DataSet ds = dc.query().from("csv_delete_all_records").selectCount().execute();
- assertTrue(ds.next());
- assertEquals(0, ((Number) ds.getRow().getValue(0)).intValue());
- assertFalse(ds.next());
-
- String fileAsString = FileHelper.readFileAsString(file);
- assertEquals("\"id\",\"name\",\"gender\",\"age\"", fileAsString);
- }
-
- public void testWriteSimpleTableInNewFile() throws Exception {
- final File file = new File("target/csv_write_ex1.txt");
- file.delete();
- assertFalse(file.exists());
- CsvDataContext dc = new CsvDataContext(file);
- final Schema schema = dc.getDefaultSchema();
- assertEquals(0, schema.getTableCount());
-
- final MutableRef<Table> tableRef = new MutableRef<Table>();
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- Table table = cb.createTable(schema, "foobar").withColumn("foo").withColumn("bar").execute();
- tableRef.set(table);
- assertEquals(schema, table.getSchema());
- assertEquals(schema.getTables()[0], table);
- assertTrue(file.exists());
-
- assertEquals("[foo, bar]", Arrays.toString(table.getColumnNames()));
-
- cb.insertInto(table).value(0, "f").value(1, "b").execute();
- cb.insertInto(table).value(0, "o").value(table.getColumnByName("bar"), "a").execute();
- cb.insertInto(table).value(0, "o").value("bar", "r").execute();
- }
- });
-
- // query the file to check results
- final Table readTable = schema.getTables()[0];
- assertEquals(tableRef.get(), readTable);
- assertEquals("[foo, bar]", Arrays.toString(readTable.getColumnNames()));
-
- final Query query = dc.query().from(readTable).select("bar").and("foo").toQuery();
- DataSet ds = dc.executeQuery(query);
-
- assertTrue(ds.next());
- assertEquals("Row[values=[b, f]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[a, o]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[r, o]]", ds.getRow().toString());
- assertFalse(ds.next());
-
- // do the same trick on an existing file
- dc = new CsvDataContext(file);
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- cb.insertInto(tableRef.get()).value("foo", "hello").value("bar", "world").execute();
- }
- });
-
- ds = dc.executeQuery(query);
-
- assertTrue(ds.next());
- assertEquals("Row[values=[b, f]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[a, o]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[r, o]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[world, hello]]", ds.getRow().toString());
- assertFalse(ds.next());
- ds.close();
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.deleteFrom(readTable).where("bar").eq("a").execute();
- callback.deleteFrom(readTable).where("bar").eq("r").execute();
- }
- });
-
- ds = dc.executeQuery(query);
- assertTrue(ds.next());
- assertEquals("Row[values=[b, f]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[world, hello]]", ds.getRow().toString());
- assertFalse(ds.next());
- ds.close();
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.update(readTable).value("foo", "universe").execute();
- callback.update(readTable).value("bar", "c").where("bar").isEquals("b").execute();
- }
- });
-
- ds = dc.executeQuery(query);
- assertTrue(ds.next());
- assertEquals("Row[values=[world, universe]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[c, universe]]", ds.getRow().toString());
- assertFalse(ds.next());
- ds.close();
-
- // drop table
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.dropTable(readTable).execute();
- }
- });
-
- assertFalse(file.exists());
- }
-
- public void testOnlyNumberOneSymbol() throws Exception {
- DataContext dc = new CsvDataContext(new File("src/test/resources/csv_only_number_one.csv"));
- Map<Column, TypeConverter<?, ?>> converters = Converters.autoDetectConverters(dc, dc.getDefaultSchema()
- .getTables()[0], 1000);
-
- assertEquals(1, converters.size());
- assertEquals(StringToBooleanConverter.class, converters.values().iterator().next().getClass());
-
- dc = Converters.addTypeConverters(dc, converters);
-
- Table table = dc.getDefaultSchema().getTables()[0];
- MutableColumn col = (MutableColumn) table.getColumns()[0];
- Query q = dc.query().from(table).select(col).toQuery();
- assertEquals("SELECT csv_only_number_one.number FROM csv_only_number_one.csv.csv_only_number_one", q.toSql());
-
- DataSet ds = dc.executeQuery(q);
- while (ds.next()) {
- assertEquals(true, ds.getRow().getValue(0));
- }
- ds.close();
-
- dc = Converters.addTypeConverter(dc, col, new StringToIntegerConverter());
-
- ds = dc.executeQuery(q);
- while (ds.next()) {
- assertEquals(1, ds.getRow().getValue(0));
- }
- ds.close();
- }
-
- public void testWriteOddConfiguration() throws Exception {
- final File file = new File("target/csv_write_ex2.txt");
- file.delete();
- assertFalse(file.exists());
-
- final CsvDataContext dc = new CsvDataContext(file, new CsvConfiguration(
- CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, "UTF8", '|', '?', '!'));
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- Table table = cb.createTable(dc.getDefaultSchema(), "table").withColumn("id").withColumn("name")
- .execute();
- cb.insertInto(table).value("id", 1).value("name", "Kasper").execute();
- cb.insertInto(table).value("id", 2).value("name", "Kas|per?").execute();
- }
- });
-
- String[] lines = FileHelper.readFileAsString(file).split("\n");
- assertEquals(3, lines.length);
- assertEquals("?id?|?name?", lines[0]);
- assertEquals("?1?|?Kasper?", lines[1]);
- assertEquals("?2?|?Kas|per!??", lines[2]);
- }
-
- public void testCannotWriteToReadOnly() throws Exception {
- final CsvDataContext dc = new CsvDataContext(new FileInputStream("src/test/resources/empty_file.csv"),
- new CsvConfiguration());
- try {
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- cb.createTable(dc.getDefaultSchema(), "foo");
- }
- });
- fail("Exception expected");
- } catch (IllegalStateException e) {
- assertEquals("This CSV DataContext is not writable, as it based on a read-only resource.", e.getMessage());
- }
-
- // try {
- // dc.executeUpdate(new Update() {
- // @Override
- // public void run(UpdateCallback cb) {
- // cb.insertInto(dc.getDefaultSchema().getTables()[0]);
- // }
- // });
- // fail("Exception expected");
- // } catch (IllegalStateException e) {
- // assertEquals(
- // "This CSV DataContext is not writable, as it based on a read-only resource.",
- // e.getMessage());
- // }
- }
-
- // public void testOnlyWriteToOwnSchemasAndTables() throws Exception {
- // CsvDataContext dc = new CsvDataContext(new File(
- // "src/test/resources/empty_file.csv"), new CsvConfiguration());
- // try {
- // dc.executeUpdate(new Update() {
- // @Override
- // public void run(UpdateCallback cb) {
- // cb.createTable(new MutableSchema("bar"), "foo");
- // }
- // );
- // fail("Exception expected");
- // } catch (IllegalArgumentException e) {
- // assertEquals("Not a valid CSV schema: Schema[name=bar]",
- // e.getMessage());
- // }
- //
- // try {
- // dc.insertInto(new MutableTable("bla"));
- // fail("Exception expected");
- // } catch (IllegalArgumentException e) {
- // assertEquals(
- // "Not a valid CSV table: Table[name=bla,type=null,remarks=null]",
- // e.getMessage());
- // }
- // }
-}
\ No newline at end of file
[58/61] Renamed all import and package statements from 'org.eobjects'
to 'org.apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 25bad2b..2c4b0c9 100644
--- a/core/src/main/java/org/apache/metamodel/data/CachingDataSetHeader.java
+++ b/core/src/main/java/org/apache/metamodel/data/CachingDataSetHeader.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.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;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
/**
* Most common implementation of {@link DataSetHeader}. This implementation is
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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
index d35b5ff..f0895bd 100644
--- a/core/src/main/java/org/apache/metamodel/data/ColorImpl.java
+++ b/core/src/main/java/org/apache/metamodel/data/ColorImpl.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import java.util.List;
-import org.eobjects.metamodel.data.Style.Color;
-import org.eobjects.metamodel.util.BaseObject;
+import org.apache.metamodel.data.Style.Color;
+import org.apache.metamodel.util.BaseObject;
final class ColorImpl extends BaseObject implements Color {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 dc471b8..178f593 100644
--- a/core/src/main/java/org/apache/metamodel/data/DataSet.java
+++ b/core/src/main/java/org/apache/metamodel/data/DataSet.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import java.io.Closeable;
import java.util.Iterator;
@@ -24,7 +24,7 @@ import java.util.List;
import javax.swing.table.TableModel;
-import org.eobjects.metamodel.query.SelectItem;
+import org.apache.metamodel.query.SelectItem;
/**
* Represents a tabular DataSet where values are bound to columns and rows. A
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 186c7b9..79e8c6c 100644
--- a/core/src/main/java/org/apache/metamodel/data/DataSetHeader.java
+++ b/core/src/main/java/org/apache/metamodel/data/DataSetHeader.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import java.io.Serializable;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
/**
* Represents the header of a {@link DataSet}, which define the
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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
index 82481c5..15a22c6 100644
--- a/core/src/main/java/org/apache/metamodel/data/DataSetIterator.java
+++ b/core/src/main/java/org/apache/metamodel/data/DataSetIterator.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import java.util.Iterator;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 53fb2be..e60424a 100644
--- a/core/src/main/java/org/apache/metamodel/data/DataSetTableModel.java
+++ b/core/src/main/java/org/apache/metamodel/data/DataSetTableModel.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import java.util.ArrayList;
import java.util.Arrays;
@@ -25,8 +25,8 @@ 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;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.util.EqualsBuilder;
/**
* {@link TableModel} implementation which wraps a {@link DataSet} and presents its data.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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
index 3fee3b8..c528bc3 100644
--- a/core/src/main/java/org/apache/metamodel/data/DefaultRow.java
+++ b/core/src/main/java/org/apache/metamodel/data/DefaultRow.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import java.util.Arrays;
import java.util.List;
-import org.eobjects.metamodel.query.SelectItem;
+import org.apache.metamodel.query.SelectItem;
/**
* Default Row implementation. Holds values in memory.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 46ece93..422d35f 100644
--- a/core/src/main/java/org/apache/metamodel/data/EmptyDataSet.java
+++ b/core/src/main/java/org/apache/metamodel/data/EmptyDataSet.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import java.util.List;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
/**
* An empty data set.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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
index ca406ed..1f034eb 100644
--- a/core/src/main/java/org/apache/metamodel/data/FilteredDataSet.java
+++ b/core/src/main/java/org/apache/metamodel/data/FilteredDataSet.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
/**
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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
index 6662eb5..e3fb172 100644
--- a/core/src/main/java/org/apache/metamodel/data/FirstRowDataSet.java
+++ b/core/src/main/java/org/apache/metamodel/data/FirstRowDataSet.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
/**
* Wraps another DataSet and enforces a first row offset.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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
index ac46eea..e4271ab 100644
--- a/core/src/main/java/org/apache/metamodel/data/IRowFilter.java
+++ b/core/src/main/java/org/apache/metamodel/data/IRowFilter.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
/**
* A filter that is executed client-side because filter criteria are either more
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 7e21412..2a77045 100644
--- a/core/src/main/java/org/apache/metamodel/data/InMemoryDataSet.java
+++ b/core/src/main/java/org/apache/metamodel/data/InMemoryDataSet.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import java.util.Arrays;
import java.util.List;
-import org.eobjects.metamodel.query.SelectItem;
+import org.apache.metamodel.query.SelectItem;
/**
* DataSet implementation based on in-memory data.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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
index adecaed..6baf023 100644
--- a/core/src/main/java/org/apache/metamodel/data/MaxRowsDataSet.java
+++ b/core/src/main/java/org/apache/metamodel/data/MaxRowsDataSet.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
/**
* Wraps another DataSet and enforces a maximum number of rows constraint
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 47e95c0..d636343 100644
--- a/core/src/main/java/org/apache/metamodel/data/Row.java
+++ b/core/src/main/java/org/apache/metamodel/data/Row.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import java.io.Serializable;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
/**
* Represents a row of data in a DataSet. Each row is a mapping between
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/data/RowBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/RowBuilder.java b/core/src/main/java/org/apache/metamodel/data/RowBuilder.java
index 0602ec5..2843418 100644
--- a/core/src/main/java/org/apache/metamodel/data/RowBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/data/RowBuilder.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.update.RowUpdationBuilder;
/**
* Abstract interface for objects that build rows, either for eg. insert or
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/data/RowPublisher.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/RowPublisher.java b/core/src/main/java/org/apache/metamodel/data/RowPublisher.java
index fe7678b..648d464 100644
--- a/core/src/main/java/org/apache/metamodel/data/RowPublisher.java
+++ b/core/src/main/java/org/apache/metamodel/data/RowPublisher.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
/**
* An object on which a push-style data reader can publish records to a
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/data/RowPublisherDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/RowPublisherDataSet.java b/core/src/main/java/org/apache/metamodel/data/RowPublisherDataSet.java
index addbeae..8717136 100644
--- a/core/src/main/java/org/apache/metamodel/data/RowPublisherDataSet.java
+++ b/core/src/main/java/org/apache/metamodel/data/RowPublisherDataSet.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.util.Action;
-import org.eobjects.metamodel.util.SharedExecutorService;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.util.Action;
+import org.apache.metamodel.util.SharedExecutorService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/data/RowPublisherImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/RowPublisherImpl.java b/core/src/main/java/org/apache/metamodel/data/RowPublisherImpl.java
index 6fe2a0d..ad90afe 100644
--- a/core/src/main/java/org/apache/metamodel/data/RowPublisherImpl.java
+++ b/core/src/main/java/org/apache/metamodel/data/RowPublisherImpl.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
@@ -24,7 +24,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
-import org.eobjects.metamodel.MetaModelException;
+import org.apache.metamodel.MetaModelException;
/**
* Row publisher implementation used by {@link RowPublisherDataSet}.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 1e7e461..a3c9e40 100644
--- a/core/src/main/java/org/apache/metamodel/data/SimpleDataSetHeader.java
+++ b/core/src/main/java/org/apache/metamodel/data/SimpleDataSetHeader.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import java.util.Arrays;
import java.util.List;
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.MetaModelHelper;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
/**
* Simple implementation of {@link DataSetHeader} which does no magic to improve
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/data/Style.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/Style.java b/core/src/main/java/org/apache/metamodel/data/Style.java
index f8ee46f..a03be43 100644
--- a/core/src/main/java/org/apache/metamodel/data/Style.java
+++ b/core/src/main/java/org/apache/metamodel/data/Style.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import java.io.Serializable;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/data/StyleBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/StyleBuilder.java b/core/src/main/java/org/apache/metamodel/data/StyleBuilder.java
index ac4c6c7..dbd1774 100644
--- a/core/src/main/java/org/apache/metamodel/data/StyleBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/data/StyleBuilder.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import java.util.Map;
import java.util.WeakHashMap;
-import org.eobjects.metamodel.data.Style.Color;
-import org.eobjects.metamodel.data.Style.SizeUnit;
-import org.eobjects.metamodel.data.Style.TextAlignment;
-import org.eobjects.metamodel.util.EqualsBuilder;
+import org.apache.metamodel.data.Style.Color;
+import org.apache.metamodel.data.Style.SizeUnit;
+import org.apache.metamodel.data.Style.TextAlignment;
+import org.apache.metamodel.util.EqualsBuilder;
/**
* Builder class for {@link Style} and related objects, like {@link Color}.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/data/StyleImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/StyleImpl.java b/core/src/main/java/org/apache/metamodel/data/StyleImpl.java
index e00e1a9..ef6ba31 100644
--- a/core/src/main/java/org/apache/metamodel/data/StyleImpl.java
+++ b/core/src/main/java/org/apache/metamodel/data/StyleImpl.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import java.util.List;
-import org.eobjects.metamodel.util.BaseObject;
+import org.apache.metamodel.util.BaseObject;
/**
* Default immutable implementation of {@link Style}.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/data/SubSelectionDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/SubSelectionDataSet.java b/core/src/main/java/org/apache/metamodel/data/SubSelectionDataSet.java
index 1a1df90..64a0d30 100644
--- a/core/src/main/java/org/apache/metamodel/data/SubSelectionDataSet.java
+++ b/core/src/main/java/org/apache/metamodel/data/SubSelectionDataSet.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
-import org.eobjects.metamodel.query.SelectItem;
+import org.apache.metamodel.query.SelectItem;
/**
* {@link DataSet} wrapper for doing subselection.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/data/WhereClauseBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/WhereClauseBuilder.java b/core/src/main/java/org/apache/metamodel/data/WhereClauseBuilder.java
index 4865bad..b2864b3 100644
--- a/core/src/main/java/org/apache/metamodel/data/WhereClauseBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/data/WhereClauseBuilder.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.builder.FilterBuilder;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.builder.FilterBuilder;
+import org.apache.metamodel.schema.Column;
/**
* An interface for builder components that formulate a WHERE clause, either for
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/data/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/package-info.java b/core/src/main/java/org/apache/metamodel/data/package-info.java
index 572f5a3..12f15aa 100644
--- a/core/src/main/java/org/apache/metamodel/data/package-info.java
+++ b/core/src/main/java/org/apache/metamodel/data/package-info.java
@@ -19,5 +19,5 @@
/**
* API for data sets
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/delete/AbstractRowDeletionBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/delete/AbstractRowDeletionBuilder.java b/core/src/main/java/org/apache/metamodel/delete/AbstractRowDeletionBuilder.java
index 7354f52..6f205d6 100644
--- a/core/src/main/java/org/apache/metamodel/delete/AbstractRowDeletionBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/delete/AbstractRowDeletionBuilder.java
@@ -16,19 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.delete;
+package org.apache.metamodel.delete;
import java.util.ArrayList;
import java.util.List;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.FilterClause;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.query.builder.AbstractFilterBuilder;
-import org.eobjects.metamodel.query.builder.FilterBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.FilterClause;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.query.builder.AbstractFilterBuilder;
+import org.apache.metamodel.query.builder.FilterBuilder;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
/**
* Abstract {@link RowDeletionBuilder} implementation
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/delete/DeleteFrom.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/delete/DeleteFrom.java b/core/src/main/java/org/apache/metamodel/delete/DeleteFrom.java
index 59d1adf..00da301 100644
--- a/core/src/main/java/org/apache/metamodel/delete/DeleteFrom.java
+++ b/core/src/main/java/org/apache/metamodel/delete/DeleteFrom.java
@@ -16,22 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.delete;
+package org.apache.metamodel.delete;
import java.util.ArrayList;
import java.util.List;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.WhereClauseBuilder;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.query.builder.AbstractFilterBuilder;
-import org.eobjects.metamodel.query.builder.FilterBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.UpdateableDataContext;
+import org.apache.metamodel.data.WhereClauseBuilder;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.query.builder.AbstractFilterBuilder;
+import org.apache.metamodel.query.builder.FilterBuilder;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
/**
* Represents a single DELETE FROM operation to be applied to a
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/delete/RowDeletable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/delete/RowDeletable.java b/core/src/main/java/org/apache/metamodel/delete/RowDeletable.java
index 43be6d8..aefc1dc 100644
--- a/core/src/main/java/org/apache/metamodel/delete/RowDeletable.java
+++ b/core/src/main/java/org/apache/metamodel/delete/RowDeletable.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.delete;
+package org.apache.metamodel.delete;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.schema.Table;
public interface RowDeletable {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/delete/RowDeletionBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/delete/RowDeletionBuilder.java b/core/src/main/java/org/apache/metamodel/delete/RowDeletionBuilder.java
index 90ce319..1c51eda 100644
--- a/core/src/main/java/org/apache/metamodel/delete/RowDeletionBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/delete/RowDeletionBuilder.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.delete;
+package org.apache.metamodel.delete;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.WhereClauseBuilder;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.data.WhereClauseBuilder;
+import org.apache.metamodel.schema.Table;
/**
* Builder object for row deletions in a {@link Table}.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/delete/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/delete/package-info.java b/core/src/main/java/org/apache/metamodel/delete/package-info.java
index 37b96f7..2861784 100644
--- a/core/src/main/java/org/apache/metamodel/delete/package-info.java
+++ b/core/src/main/java/org/apache/metamodel/delete/package-info.java
@@ -19,5 +19,5 @@
/**
* API for deleting rows
*/
-package org.eobjects.metamodel.delete;
+package org.apache.metamodel.delete;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/drop/AbstractTableDropBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/drop/AbstractTableDropBuilder.java b/core/src/main/java/org/apache/metamodel/drop/AbstractTableDropBuilder.java
index 2fa26a5..a7a124b 100644
--- a/core/src/main/java/org/apache/metamodel/drop/AbstractTableDropBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/drop/AbstractTableDropBuilder.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.drop;
+package org.apache.metamodel.drop;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.schema.Table;
/**
* Abstract {@link TableDropBuilder} implementation
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/drop/DropTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/drop/DropTable.java b/core/src/main/java/org/apache/metamodel/drop/DropTable.java
index f150c50..11f5c27 100644
--- a/core/src/main/java/org/apache/metamodel/drop/DropTable.java
+++ b/core/src/main/java/org/apache/metamodel/drop/DropTable.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.drop;
+package org.apache.metamodel.drop;
-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.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.UpdateableDataContext;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
/**
* Represents a single DROP TABLE operation to be applied to a
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/drop/TableDropBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/drop/TableDropBuilder.java b/core/src/main/java/org/apache/metamodel/drop/TableDropBuilder.java
index 34bce59..fa2f7c8 100644
--- a/core/src/main/java/org/apache/metamodel/drop/TableDropBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/drop/TableDropBuilder.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.drop;
+package org.apache.metamodel.drop;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.schema.Table;
public interface TableDropBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/drop/TableDroppable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/drop/TableDroppable.java b/core/src/main/java/org/apache/metamodel/drop/TableDroppable.java
index d5c8260..416b41c 100644
--- a/core/src/main/java/org/apache/metamodel/drop/TableDroppable.java
+++ b/core/src/main/java/org/apache/metamodel/drop/TableDroppable.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.drop;
+package org.apache.metamodel.drop;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public interface TableDroppable {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/drop/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/drop/package-info.java b/core/src/main/java/org/apache/metamodel/drop/package-info.java
index 7f51816..c960ed4 100644
--- a/core/src/main/java/org/apache/metamodel/drop/package-info.java
+++ b/core/src/main/java/org/apache/metamodel/drop/package-info.java
@@ -19,5 +19,5 @@
/**
* API for dropping tables
*/
-package org.eobjects.metamodel.drop;
+package org.apache.metamodel.drop;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 c57c26d..ecd8bac 100644
--- a/core/src/main/java/org/apache/metamodel/insert/AbstractRowInsertionBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/insert/AbstractRowInsertionBuilder.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.insert;
+package org.apache.metamodel.insert;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.data.AbstractRowBuilder;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.data.AbstractRowBuilder;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
/**
* Abstract implementation of the {@link RowInsertionBuilder} interface,
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/insert/InsertInto.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/insert/InsertInto.java b/core/src/main/java/org/apache/metamodel/insert/InsertInto.java
index df793b9..d554c72 100644
--- a/core/src/main/java/org/apache/metamodel/insert/InsertInto.java
+++ b/core/src/main/java/org/apache/metamodel/insert/InsertInto.java
@@ -16,17 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.insert;
+package org.apache.metamodel.insert;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.AbstractRowBuilder;
-import org.eobjects.metamodel.data.RowBuilder;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.UpdateableDataContext;
+import org.apache.metamodel.data.AbstractRowBuilder;
+import org.apache.metamodel.data.RowBuilder;
+import org.apache.metamodel.data.Style;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
/**
* Represents a single INSERT INTO operation to be applied to a
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/insert/RowInsertable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/insert/RowInsertable.java b/core/src/main/java/org/apache/metamodel/insert/RowInsertable.java
index bcb3aaa..a3ffcea 100644
--- a/core/src/main/java/org/apache/metamodel/insert/RowInsertable.java
+++ b/core/src/main/java/org/apache/metamodel/insert/RowInsertable.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.insert;
+package org.apache.metamodel.insert;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.schema.Table;
/**
* An interface for objects that support inserting rows into tables.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/insert/RowInsertionBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/insert/RowInsertionBuilder.java b/core/src/main/java/org/apache/metamodel/insert/RowInsertionBuilder.java
index 05714a3..c964ca8 100644
--- a/core/src/main/java/org/apache/metamodel/insert/RowInsertionBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/insert/RowInsertionBuilder.java
@@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.insert;
+package org.apache.metamodel.insert;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.RowBuilder;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.data.RowBuilder;
+import org.apache.metamodel.schema.Table;
/**
* Builder object for row insertion, into a {@link Table}.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/insert/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/insert/package-info.java b/core/src/main/java/org/apache/metamodel/insert/package-info.java
index 5a78f04..2d06e6c 100644
--- a/core/src/main/java/org/apache/metamodel/insert/package-info.java
+++ b/core/src/main/java/org/apache/metamodel/insert/package-info.java
@@ -19,5 +19,5 @@
/**
* API for inserting rows
*/
-package org.eobjects.metamodel.insert;
+package org.apache.metamodel.insert;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/intercept/DataSetInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/DataSetInterceptor.java b/core/src/main/java/org/apache/metamodel/intercept/DataSetInterceptor.java
index 3661374..12f39fb 100644
--- a/core/src/main/java/org/apache/metamodel/intercept/DataSetInterceptor.java
+++ b/core/src/main/java/org/apache/metamodel/intercept/DataSetInterceptor.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
-import org.eobjects.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSet;
/**
* An {@link Interceptor} for {@link DataSet}s, allowing to touch, enrich or
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/intercept/InterceptableColumnCreationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/InterceptableColumnCreationBuilder.java b/core/src/main/java/org/apache/metamodel/intercept/InterceptableColumnCreationBuilder.java
index 1ce3092..7cc8686 100644
--- a/core/src/main/java/org/apache/metamodel/intercept/InterceptableColumnCreationBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/intercept/InterceptableColumnCreationBuilder.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.create.ColumnCreationBuilder;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.create.ColumnCreationBuilder;
+import org.apache.metamodel.create.TableCreationBuilder;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Table;
final class InterceptableColumnCreationBuilder implements ColumnCreationBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 63a6dc2..a356b9a 100644
--- a/core/src/main/java/org/apache/metamodel/intercept/InterceptableDataContext.java
+++ b/core/src/main/java/org/apache/metamodel/intercept/InterceptableDataContext.java
@@ -16,26 +16,26 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.builder.InitFromBuilder;
-import org.eobjects.metamodel.query.builder.InitFromBuilderImpl;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
-import org.eobjects.metamodel.util.HasNameMapper;
+package org.apache.metamodel.intercept;
+
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.UpdateableDataContext;
+import org.apache.metamodel.create.TableCreationBuilder;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.delete.RowDeletionBuilder;
+import org.apache.metamodel.drop.TableDropBuilder;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.query.CompiledQuery;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.builder.InitFromBuilder;
+import org.apache.metamodel.query.builder.InitFromBuilderImpl;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.update.RowUpdationBuilder;
+import org.apache.metamodel.util.HasNameMapper;
public class InterceptableDataContext implements UpdateableDataContext {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowDeletionBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowDeletionBuilder.java b/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowDeletionBuilder.java
index 8a1d516..3fd2523 100644
--- a/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowDeletionBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowDeletionBuilder.java
@@ -16,16 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.query.builder.AbstractFilterBuilder;
-import org.eobjects.metamodel.query.builder.FilterBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.delete.RowDeletionBuilder;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.query.builder.AbstractFilterBuilder;
+import org.apache.metamodel.query.builder.FilterBuilder;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
final class InterceptableRowDeletionBuilder implements RowDeletionBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowInsertionBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowInsertionBuilder.java b/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowInsertionBuilder.java
index 3a0228b..e1f4385 100644
--- a/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowInsertionBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowInsertionBuilder.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.data.Style;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
final class InterceptableRowInsertionBuilder implements RowInsertionBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowUpdationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowUpdationBuilder.java b/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowUpdationBuilder.java
index d5dbc16..1971e5a 100644
--- a/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowUpdationBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/intercept/InterceptableRowUpdationBuilder.java
@@ -16,18 +16,18 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.query.builder.AbstractFilterBuilder;
-import org.eobjects.metamodel.query.builder.FilterBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
+package org.apache.metamodel.intercept;
+
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.data.Style;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.query.builder.AbstractFilterBuilder;
+import org.apache.metamodel.query.builder.FilterBuilder;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.update.RowUpdationBuilder;
final class InterceptableRowUpdationBuilder implements RowUpdationBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/intercept/InterceptableTableCreationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/InterceptableTableCreationBuilder.java b/core/src/main/java/org/apache/metamodel/intercept/InterceptableTableCreationBuilder.java
index 0976113..6c4ee9b 100644
--- a/core/src/main/java/org/apache/metamodel/intercept/InterceptableTableCreationBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/intercept/InterceptableTableCreationBuilder.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.create.ColumnCreationBuilder;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.create.ColumnCreationBuilder;
+import org.apache.metamodel.create.TableCreationBuilder;
+import org.apache.metamodel.schema.Table;
final class InterceptableTableCreationBuilder implements TableCreationBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/intercept/InterceptableTableDropBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/InterceptableTableDropBuilder.java b/core/src/main/java/org/apache/metamodel/intercept/InterceptableTableDropBuilder.java
index cb275a2..e83eb83 100644
--- a/core/src/main/java/org/apache/metamodel/intercept/InterceptableTableDropBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/intercept/InterceptableTableDropBuilder.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.drop.TableDropBuilder;
+import org.apache.metamodel.schema.Table;
final class InterceptableTableDropBuilder implements TableDropBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/intercept/InterceptableUpdateCallback.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/InterceptableUpdateCallback.java b/core/src/main/java/org/apache/metamodel/intercept/InterceptableUpdateCallback.java
index 1538374..1c9b80f 100644
--- a/core/src/main/java/org/apache/metamodel/intercept/InterceptableUpdateCallback.java
+++ b/core/src/main/java/org/apache/metamodel/intercept/InterceptableUpdateCallback.java
@@ -16,17 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
-import org.eobjects.metamodel.AbstractUpdateCallback;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
+import org.apache.metamodel.AbstractUpdateCallback;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.create.TableCreationBuilder;
+import org.apache.metamodel.delete.RowDeletionBuilder;
+import org.apache.metamodel.drop.TableDropBuilder;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.update.RowUpdationBuilder;
/**
* {@link UpdateCallback} wrapper that allows adding interceptors for certain operations.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/intercept/InterceptableUpdateScript.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/InterceptableUpdateScript.java b/core/src/main/java/org/apache/metamodel/intercept/InterceptableUpdateScript.java
index c5796c3..2cccc11 100644
--- a/core/src/main/java/org/apache/metamodel/intercept/InterceptableUpdateScript.java
+++ b/core/src/main/java/org/apache/metamodel/intercept/InterceptableUpdateScript.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.create.TableCreationBuilder;
+import org.apache.metamodel.delete.RowDeletionBuilder;
+import org.apache.metamodel.drop.TableDropBuilder;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.update.RowUpdationBuilder;
final class InterceptableUpdateScript implements UpdateScript {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/intercept/Interceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/Interceptor.java b/core/src/main/java/org/apache/metamodel/intercept/Interceptor.java
index 2eb2c4a..6e951f3 100644
--- a/core/src/main/java/org/apache/metamodel/intercept/Interceptor.java
+++ b/core/src/main/java/org/apache/metamodel/intercept/Interceptor.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
/**
* Defines a high-level interface for interceptors in MetaModel.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/intercept/InterceptorList.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/InterceptorList.java b/core/src/main/java/org/apache/metamodel/intercept/InterceptorList.java
index 32c1e0e..9d78481 100644
--- a/core/src/main/java/org/apache/metamodel/intercept/InterceptorList.java
+++ b/core/src/main/java/org/apache/metamodel/intercept/InterceptorList.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
import java.util.ArrayList;
import java.util.List;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/intercept/Interceptors.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/Interceptors.java b/core/src/main/java/org/apache/metamodel/intercept/Interceptors.java
index 2111fa2..bd0acb3 100644
--- a/core/src/main/java/org/apache/metamodel/intercept/Interceptors.java
+++ b/core/src/main/java/org/apache/metamodel/intercept/Interceptors.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
-import org.eobjects.metamodel.DataContext;
+import org.apache.metamodel.DataContext;
public final class Interceptors {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/intercept/QueryInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/QueryInterceptor.java b/core/src/main/java/org/apache/metamodel/intercept/QueryInterceptor.java
index b1299cf..28c6807 100644
--- a/core/src/main/java/org/apache/metamodel/intercept/QueryInterceptor.java
+++ b/core/src/main/java/org/apache/metamodel/intercept/QueryInterceptor.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
-import org.eobjects.metamodel.query.Query;
+import org.apache.metamodel.query.Query;
/**
* An {@link Interceptor} for Queries, allowing to touch or modify a query
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/intercept/RowDeletionInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/RowDeletionInterceptor.java b/core/src/main/java/org/apache/metamodel/intercept/RowDeletionInterceptor.java
index 4891185..8572353 100644
--- a/core/src/main/java/org/apache/metamodel/intercept/RowDeletionInterceptor.java
+++ b/core/src/main/java/org/apache/metamodel/intercept/RowDeletionInterceptor.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
+import org.apache.metamodel.delete.RowDeletionBuilder;
/**
* An {@link Interceptor} for {@link RowDeletionBuilder}, allowing for
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/intercept/RowInsertionInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/RowInsertionInterceptor.java b/core/src/main/java/org/apache/metamodel/intercept/RowInsertionInterceptor.java
index c652e47..345b96a 100644
--- a/core/src/main/java/org/apache/metamodel/intercept/RowInsertionInterceptor.java
+++ b/core/src/main/java/org/apache/metamodel/intercept/RowInsertionInterceptor.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.insert.RowInsertionBuilder;
/**
* An {@link Interceptor} for {@link RowInsertionBuilder}, allowing for
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/intercept/RowUpdationInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/RowUpdationInterceptor.java b/core/src/main/java/org/apache/metamodel/intercept/RowUpdationInterceptor.java
index 5a9cded..a6126af 100644
--- a/core/src/main/java/org/apache/metamodel/intercept/RowUpdationInterceptor.java
+++ b/core/src/main/java/org/apache/metamodel/intercept/RowUpdationInterceptor.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
+import org.apache.metamodel.update.RowUpdationBuilder;
/**
* An {@link Interceptor} for {@link RowUpdationBuilder}, allowing for
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/intercept/SchemaInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/SchemaInterceptor.java b/core/src/main/java/org/apache/metamodel/intercept/SchemaInterceptor.java
index 3ff3489..fcc0e96 100644
--- a/core/src/main/java/org/apache/metamodel/intercept/SchemaInterceptor.java
+++ b/core/src/main/java/org/apache/metamodel/intercept/SchemaInterceptor.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
-import org.eobjects.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Schema;
/**
* An {@link Interceptor} for {@link Schema}s, which allows for intercepting
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/intercept/TableCreationInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/TableCreationInterceptor.java b/core/src/main/java/org/apache/metamodel/intercept/TableCreationInterceptor.java
index af55dde..e4f3f6f 100644
--- a/core/src/main/java/org/apache/metamodel/intercept/TableCreationInterceptor.java
+++ b/core/src/main/java/org/apache/metamodel/intercept/TableCreationInterceptor.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
-import org.eobjects.metamodel.create.TableCreationBuilder;
+import org.apache.metamodel.create.TableCreationBuilder;
/**
* An {@link Interceptor} for {@link TableCreationBuilder}s, which allows for
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/intercept/TableDropInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/TableDropInterceptor.java b/core/src/main/java/org/apache/metamodel/intercept/TableDropInterceptor.java
index d148ec1..83e5813 100644
--- a/core/src/main/java/org/apache/metamodel/intercept/TableDropInterceptor.java
+++ b/core/src/main/java/org/apache/metamodel/intercept/TableDropInterceptor.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
-import org.eobjects.metamodel.drop.TableDropBuilder;
+import org.apache.metamodel.drop.TableDropBuilder;
/**
* An {@link Interceptor} for {@link TableDropBuilder}s, which allows for
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/package-info.java b/core/src/main/java/org/apache/metamodel/package-info.java
index 74b215c..ab54c58 100644
--- a/core/src/main/java/org/apache/metamodel/package-info.java
+++ b/core/src/main/java/org/apache/metamodel/package-info.java
@@ -19,5 +19,5 @@
/**
* Root package for MetaModel
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/AbstractQueryClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/AbstractQueryClause.java b/core/src/main/java/org/apache/metamodel/query/AbstractQueryClause.java
index c06cf27..13d8ec5 100644
--- a/core/src/main/java/org/apache/metamodel/query/AbstractQueryClause.java
+++ b/core/src/main/java/org/apache/metamodel/query/AbstractQueryClause.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
import java.util.ArrayList;
import java.util.List;
-import org.eobjects.metamodel.util.BaseObject;
+import org.apache.metamodel.util.BaseObject;
/**
* Represents an abstract clause in a query. Clauses contains IQueryItems and
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/AverageAggregateBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/AverageAggregateBuilder.java b/core/src/main/java/org/apache/metamodel/query/AverageAggregateBuilder.java
index 3b2d949..44a2341 100644
--- a/core/src/main/java/org/apache/metamodel/query/AverageAggregateBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/AverageAggregateBuilder.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
-import org.eobjects.metamodel.util.AggregateBuilder;
-import org.eobjects.metamodel.util.NumberComparator;
+import org.apache.metamodel.util.AggregateBuilder;
+import org.apache.metamodel.util.NumberComparator;
final class AverageAggregateBuilder implements AggregateBuilder<Double> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/CompiledQuery.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/CompiledQuery.java b/core/src/main/java/org/apache/metamodel/query/CompiledQuery.java
index cd242b9..7588291 100644
--- a/core/src/main/java/org/apache/metamodel/query/CompiledQuery.java
+++ b/core/src/main/java/org/apache/metamodel/query/CompiledQuery.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
import java.io.Closeable;
import java.util.List;
-import org.eobjects.metamodel.DataContext;
+import org.apache.metamodel.DataContext;
/**
* A {@link CompiledQuery} is a {@link Query} which has been compiled, typically
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/CountAggregateBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/CountAggregateBuilder.java b/core/src/main/java/org/apache/metamodel/query/CountAggregateBuilder.java
index c5bca84..af8c297 100644
--- a/core/src/main/java/org/apache/metamodel/query/CountAggregateBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/CountAggregateBuilder.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
-import org.eobjects.metamodel.util.AggregateBuilder;
+import org.apache.metamodel.util.AggregateBuilder;
final class CountAggregateBuilder implements AggregateBuilder<Long> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/DefaultCompiledQuery.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/DefaultCompiledQuery.java b/core/src/main/java/org/apache/metamodel/query/DefaultCompiledQuery.java
index c1f3dab..4cd497a 100644
--- a/core/src/main/java/org/apache/metamodel/query/DefaultCompiledQuery.java
+++ b/core/src/main/java/org/apache/metamodel/query/DefaultCompiledQuery.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
import java.util.ArrayList;
import java.util.List;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/FilterClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/FilterClause.java b/core/src/main/java/org/apache/metamodel/query/FilterClause.java
index 591fb01..fe981a1 100644
--- a/core/src/main/java/org/apache/metamodel/query/FilterClause.java
+++ b/core/src/main/java/org/apache/metamodel/query/FilterClause.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
import java.util.ArrayList;
import java.util.List;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.schema.Column;
/**
* Represents a clause of filters in the query. This type of clause is used for
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/FilterItem.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/FilterItem.java b/core/src/main/java/org/apache/metamodel/query/FilterItem.java
index 86fdd20..4a6d0af 100644
--- a/core/src/main/java/org/apache/metamodel/query/FilterItem.java
+++ b/core/src/main/java/org/apache/metamodel/query/FilterItem.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
import java.util.ArrayList;
import java.util.Arrays;
@@ -25,15 +25,15 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import org.eobjects.metamodel.data.IRowFilter;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.util.BaseObject;
-import org.eobjects.metamodel.util.CollectionUtils;
-import org.eobjects.metamodel.util.FormatHelper;
-import org.eobjects.metamodel.util.ObjectComparator;
-import org.eobjects.metamodel.util.WildcardPattern;
+import org.apache.metamodel.data.IRowFilter;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.util.BaseObject;
+import org.apache.metamodel.util.CollectionUtils;
+import org.apache.metamodel.util.FormatHelper;
+import org.apache.metamodel.util.ObjectComparator;
+import org.apache.metamodel.util.WildcardPattern;
/**
* Represents a filter in a query that resides either within a WHERE clause or a
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/FromClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/FromClause.java b/core/src/main/java/org/apache/metamodel/query/FromClause.java
index 950c246..808886d 100644
--- a/core/src/main/java/org/apache/metamodel/query/FromClause.java
+++ b/core/src/main/java/org/apache/metamodel/query/FromClause.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.schema.Table;
/**
* Represents the FROM clause of a query containing FromItem's.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 2ea22bd..8ee07fa 100644
--- a/core/src/main/java/org/apache/metamodel/query/FromItem.java
+++ b/core/src/main/java/org/apache/metamodel/query/FromItem.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
import java.util.List;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.BaseObject;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Relationship;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.BaseObject;
/**
* Represents a FROM item. FROM items can take different forms:
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/FunctionType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/FunctionType.java b/core/src/main/java/org/apache/metamodel/query/FunctionType.java
index c8d79c7..a7d50fd 100644
--- a/core/src/main/java/org/apache/metamodel/query/FunctionType.java
+++ b/core/src/main/java/org/apache/metamodel/query/FunctionType.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.util.AggregateBuilder;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.util.AggregateBuilder;
/**
* Represents an aggregate function to use in a SelectItem.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/GroupByClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/GroupByClause.java b/core/src/main/java/org/apache/metamodel/query/GroupByClause.java
index 8e7e6bd..c0ab660 100644
--- a/core/src/main/java/org/apache/metamodel/query/GroupByClause.java
+++ b/core/src/main/java/org/apache/metamodel/query/GroupByClause.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
import java.util.ArrayList;
import java.util.List;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/GroupByItem.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/GroupByItem.java b/core/src/main/java/org/apache/metamodel/query/GroupByItem.java
index cf94623..dcdba1e 100644
--- a/core/src/main/java/org/apache/metamodel/query/GroupByItem.java
+++ b/core/src/main/java/org/apache/metamodel/query/GroupByItem.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
import java.util.List;
-import org.eobjects.metamodel.util.BaseObject;
+import org.apache.metamodel.util.BaseObject;
/**
* Represents a GROUP BY item. GroupByItems always use a select item (that may
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/JoinType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/JoinType.java b/core/src/main/java/org/apache/metamodel/query/JoinType.java
index c40ab0e..730556e 100644
--- a/core/src/main/java/org/apache/metamodel/query/JoinType.java
+++ b/core/src/main/java/org/apache/metamodel/query/JoinType.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
/**
* Represents a join type, used in a FromItem.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/LogicalOperator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/LogicalOperator.java b/core/src/main/java/org/apache/metamodel/query/LogicalOperator.java
index a17cb1e..d3681d9 100644
--- a/core/src/main/java/org/apache/metamodel/query/LogicalOperator.java
+++ b/core/src/main/java/org/apache/metamodel/query/LogicalOperator.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
/**
* Represents a logical operator (AND or OR) to use when defining compound
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/MaxAggregateBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/MaxAggregateBuilder.java b/core/src/main/java/org/apache/metamodel/query/MaxAggregateBuilder.java
index 93591f1..fc3cc42 100644
--- a/core/src/main/java/org/apache/metamodel/query/MaxAggregateBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/MaxAggregateBuilder.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
-import org.eobjects.metamodel.util.AggregateBuilder;
-import org.eobjects.metamodel.util.ObjectComparator;
+import org.apache.metamodel.util.AggregateBuilder;
+import org.apache.metamodel.util.ObjectComparator;
final class MaxAggregateBuilder implements AggregateBuilder<Object> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/MinAggregateBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/MinAggregateBuilder.java b/core/src/main/java/org/apache/metamodel/query/MinAggregateBuilder.java
index 5321b22..b4c7507 100644
--- a/core/src/main/java/org/apache/metamodel/query/MinAggregateBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/MinAggregateBuilder.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
-import org.eobjects.metamodel.util.AggregateBuilder;
-import org.eobjects.metamodel.util.ObjectComparator;
+import org.apache.metamodel.util.AggregateBuilder;
+import org.apache.metamodel.util.ObjectComparator;
final class MinAggregateBuilder implements AggregateBuilder<Object> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/OperatorType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/OperatorType.java b/core/src/main/java/org/apache/metamodel/query/OperatorType.java
index 3f4782e..a2d68b9 100644
--- a/core/src/main/java/org/apache/metamodel/query/OperatorType.java
+++ b/core/src/main/java/org/apache/metamodel/query/OperatorType.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
/**
* Defines the types of operators that can be used in filters.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/OrderByClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/OrderByClause.java b/core/src/main/java/org/apache/metamodel/query/OrderByClause.java
index 8ce04ec..58a7a6b 100644
--- a/core/src/main/java/org/apache/metamodel/query/OrderByClause.java
+++ b/core/src/main/java/org/apache/metamodel/query/OrderByClause.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
import java.util.ArrayList;
import java.util.List;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/OrderByItem.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/OrderByItem.java b/core/src/main/java/org/apache/metamodel/query/OrderByItem.java
index a52aa1d..3fde53c 100644
--- a/core/src/main/java/org/apache/metamodel/query/OrderByItem.java
+++ b/core/src/main/java/org/apache/metamodel/query/OrderByItem.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
import java.util.List;
-import org.eobjects.metamodel.util.BaseObject;
+import org.apache.metamodel.util.BaseObject;
/**
* Represents an ORDER BY item. An OrderByItem sorts the resulting DataSet
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 0986b6b..1b0f6d3 100644
--- a/core/src/main/java/org/apache/metamodel/query/Query.java
+++ b/core/src/main/java/org/apache/metamodel/query/Query.java
@@ -16,27 +16,27 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.query.OrderByItem.Direction;
-import org.eobjects.metamodel.query.parser.QueryParserException;
-import org.eobjects.metamodel.query.parser.QueryPartCollectionProcessor;
-import org.eobjects.metamodel.query.parser.QueryPartParser;
-import org.eobjects.metamodel.query.parser.QueryPartProcessor;
-import org.eobjects.metamodel.query.parser.SelectItemParser;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.BaseObject;
-import org.eobjects.metamodel.util.BooleanComparator;
-import org.eobjects.metamodel.util.FormatHelper;
-import org.eobjects.metamodel.util.NumberComparator;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.query.OrderByItem.Direction;
+import org.apache.metamodel.query.parser.QueryParserException;
+import org.apache.metamodel.query.parser.QueryPartCollectionProcessor;
+import org.apache.metamodel.query.parser.QueryPartParser;
+import org.apache.metamodel.query.parser.QueryPartProcessor;
+import org.apache.metamodel.query.parser.SelectItemParser;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.BaseObject;
+import org.apache.metamodel.util.BooleanComparator;
+import org.apache.metamodel.util.FormatHelper;
+import org.apache.metamodel.util.NumberComparator;
/**
* Represents a query to retrieve data by. A query is made up of six clauses,
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/QueryClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/QueryClause.java b/core/src/main/java/org/apache/metamodel/query/QueryClause.java
index e3dddc8..33b09f3 100644
--- a/core/src/main/java/org/apache/metamodel/query/QueryClause.java
+++ b/core/src/main/java/org/apache/metamodel/query/QueryClause.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
import java.io.Serializable;
import java.util.List;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/QueryItem.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/QueryItem.java b/core/src/main/java/org/apache/metamodel/query/QueryItem.java
index ab79959..a6b6fc1 100644
--- a/core/src/main/java/org/apache/metamodel/query/QueryItem.java
+++ b/core/src/main/java/org/apache/metamodel/query/QueryItem.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
import java.io.Serializable;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/QueryParameter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/QueryParameter.java b/core/src/main/java/org/apache/metamodel/query/QueryParameter.java
index c8c0401..524fa06 100644
--- a/core/src/main/java/org/apache/metamodel/query/QueryParameter.java
+++ b/core/src/main/java/org/apache/metamodel/query/QueryParameter.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
-import org.eobjects.metamodel.DataContext;
+import org.apache.metamodel.DataContext;
/**
* Represents a query parameter, in SQL represented with a '?' symbol.
[31/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/WhereBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/WhereBuilderImpl.java b/core/src/main/java/org/eobjects/metamodel/query/builder/WhereBuilderImpl.java
deleted file mode 100644
index 7e1db14..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/WhereBuilderImpl.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/**
- * 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.query.builder;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.QueryParameter;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-
-final class WhereBuilderImpl extends AbstractQueryFilterBuilder<SatisfiedWhereBuilder<GroupedQueryBuilder>> implements
- WhereBuilder<GroupedQueryBuilder>, SatisfiedWhereBuilder<GroupedQueryBuilder> {
-
- private final Query _query;
- private final List<FilterItem> _orFilters;
- private FilterItem _parentOrFilter;
-
- public WhereBuilderImpl(Column column, Query query, GroupedQueryBuilder queryBuilder) {
- super(new SelectItem(column), queryBuilder);
- _query = query;
- _orFilters = new ArrayList<FilterItem>();
- }
-
- public WhereBuilderImpl(Column column, Query query, FilterItem parentOrFilter, List<FilterItem> orFilters,
- GroupedQueryBuilder queryBuilder) {
- super(new SelectItem(column), queryBuilder);
- _query = query;
- _parentOrFilter = parentOrFilter;
- _orFilters = orFilters;
- }
-
- @Override
- protected SatisfiedWhereBuilder<GroupedQueryBuilder> applyFilter(FilterItem filter) {
- if (_parentOrFilter == null) {
- _query.where(filter);
- } else {
- if (_parentOrFilter.getChildItemCount() == 1) {
- _query.getWhereClause().removeItem(_orFilters.get(0));
- _query.getWhereClause().addItem(_parentOrFilter);
- }
- }
- _orFilters.add(filter);
- return this;
- }
-
- @Override
- public WhereBuilder<GroupedQueryBuilder> or(String columnName) {
- Column column = findColumn(columnName);
- return or(column);
- }
-
- @Override
- public WhereBuilder<GroupedQueryBuilder> or(Column column) {
- if (_parentOrFilter == null) {
- _parentOrFilter = new FilterItem(_orFilters);
- }
- return new WhereBuilderImpl(column, _query, _parentOrFilter, _orFilters, getQueryBuilder());
- }
-
- @Override
- public WhereBuilder<GroupedQueryBuilder> and(String columnName) {
- Column column = findColumn(columnName);
- return and(column);
- }
-
- @Override
- public WhereBuilder<GroupedQueryBuilder> and(Column column) {
- return getQueryBuilder().where(column);
- }
-
- @Override
- public SatisfiedWhereBuilder<GroupedQueryBuilder> eq(QueryParameter queryParameter) {
- return isEquals(queryParameter);
- }
-
- @Override
- public SatisfiedWhereBuilder<GroupedQueryBuilder> isEquals(QueryParameter queryParameter) {
- if (queryParameter == null) {
- throw new IllegalArgumentException("query parameter cannot be null");
- }
- return _filterBuilder.applyFilter(OperatorType.EQUALS_TO, queryParameter);
- }
-
- @Override
- public SatisfiedWhereBuilder<GroupedQueryBuilder> differentFrom(QueryParameter queryParameter) {
- return ne(queryParameter);
- }
-
- @Override
- public SatisfiedWhereBuilder<GroupedQueryBuilder> ne(QueryParameter queryParameter) {
- if (queryParameter == null) {
- throw new IllegalArgumentException("query parameter cannot be null");
- }
- return _filterBuilder.applyFilter(OperatorType.DIFFERENT_FROM, queryParameter);
- }
-
- @Override
- public SatisfiedWhereBuilder<GroupedQueryBuilder> greaterThan(QueryParameter queryParameter) {
- return gt(queryParameter);
- }
-
- @Override
- public SatisfiedWhereBuilder<GroupedQueryBuilder> gt(QueryParameter queryParameter) {
- if (queryParameter == null) {
- throw new IllegalArgumentException("query parameter cannot be null");
- }
- return _filterBuilder.applyFilter(OperatorType.GREATER_THAN, queryParameter);
- }
-
- @Override
- public SatisfiedWhereBuilder<GroupedQueryBuilder> lessThan(QueryParameter queryParameter) {
- return lt(queryParameter);
- }
-
- @Override
- public SatisfiedWhereBuilder<GroupedQueryBuilder> lt(QueryParameter queryParameter) {
- if (queryParameter == null) {
- throw new IllegalArgumentException("query parameter cannot be null");
- }
- return _filterBuilder.applyFilter(OperatorType.LESS_THAN, queryParameter);
- }
-
- @Override
- public SatisfiedWhereBuilder<GroupedQueryBuilder> like(QueryParameter queryParameter) {
- if (queryParameter == null) {
- throw new IllegalArgumentException("query parameter cannot be null");
- }
- return _filterBuilder.applyFilter(OperatorType.LIKE, queryParameter);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/package-info.java b/core/src/main/java/org/eobjects/metamodel/query/builder/package-info.java
deleted file mode 100644
index 6226c85..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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 query building
- */
-package org.eobjects.metamodel.query.builder;
-
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/package-info.java b/core/src/main/java/org/eobjects/metamodel/query/package-info.java
deleted file mode 100644
index 48d9b8e..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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 querying
- */
-package org.eobjects.metamodel.query;
-
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/parser/FromItemParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/parser/FromItemParser.java b/core/src/main/java/org/eobjects/metamodel/query/parser/FromItemParser.java
deleted file mode 100644
index 78fff2e..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/parser/FromItemParser.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/**
- * 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.query.parser;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.JoinType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Table;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-final class FromItemParser implements QueryPartProcessor {
-
- private static final Logger logger = LoggerFactory.getLogger(FromItemParser.class);
-
- private final Query _query;
- private final DataContext _dataContext;
-
- public FromItemParser(DataContext dataContext, Query query) {
- _dataContext = dataContext;
- _query = query;
- }
-
- @Override
- public void parse(String delim, String itemToken) {
- final FromItem fromItem;
-
- final int parenthesisStart = itemToken.indexOf('(');
- if (parenthesisStart != -1) {
- if (parenthesisStart != 0) {
- throw new QueryParserException("Not capable of parsing FROM token: " + itemToken
- + ". Expected parenthesis to start at first character.");
- }
- final int parenthesisEnd = itemToken.indexOf(')', parenthesisStart);
- if (parenthesisEnd == -1) {
- throw new QueryParserException("Not capable of parsing FROM token: " + itemToken
- + ". Expected end parenthesis.");
- }
-
- final String subQueryString = itemToken.substring(parenthesisStart + 1, parenthesisEnd);
- logger.debug("Parsing sub-query: {}", subQueryString);
-
- final Query subQuery = new QueryParser(_dataContext, subQueryString).parse();
- fromItem = new FromItem(subQuery);
-
- final String alias = itemToken.substring(parenthesisEnd + 1).trim();
- if (!alias.isEmpty()) {
- fromItem.setAlias(alias);
- }
- } else if (itemToken.toUpperCase().indexOf(" JOIN ") != -1) {
- fromItem = parseJoinItem(itemToken);
- } else {
- fromItem = parseTableItem(itemToken);
- }
-
- _query.from(fromItem);
- }
-
- private FromItem parseTableItem(String itemToken) {
- final String[] tokens = itemToken.split(" ");
- final String alias;
- if (tokens.length == 2) {
- alias = tokens[1];
- } else if (tokens.length == 1) {
- alias = null;
- } else {
- throw new QueryParserException("Not capable of parsing FROM token: " + itemToken);
- }
-
- final Table table = _dataContext.getTableByQualifiedLabel(tokens[0]);
- if (table == null) {
- throw new QueryParserException("Not capable of parsing FROM token: " + itemToken);
- }
-
- final FromItem result = new FromItem(table);
- result.setAlias(alias);
- result.setQuery(_query);
- return result;
- }
-
- // this method will be documented based on this example itemToken: FOO f
- // INNER JOIN BAR b ON f.id = b.id
- private FromItem parseJoinItem(final String itemToken) {
- final int indexOfJoin = itemToken.toUpperCase().indexOf(" JOIN ");
-
- // firstPart = "FOO f INNER"
- final String firstPart = itemToken.substring(0, indexOfJoin).trim();
-
- // secondPart = "BAR b ON f.id = b.id"
- final String secondPart = itemToken.substring(indexOfJoin + " JOIN ".length()).trim();
-
- final int indexOfJoinType = firstPart.lastIndexOf(" ");
-
- // joinTypeString = "INNER"
- final String joinTypeString = firstPart.substring(indexOfJoinType).trim().toUpperCase();
- final JoinType joinType = JoinType.valueOf(joinTypeString);
-
- // firstTableToken = "FOO f"
- final String firstTableToken = firstPart.substring(0, indexOfJoinType).trim();
-
- final int indexOfOn = secondPart.toUpperCase().indexOf(" ON ");
-
- // secondTableToken = "BAR b"
- final String secondTableToken = secondPart.substring(0, indexOfOn).trim();
-
- final FromItem leftSide = parseTableItem(firstTableToken);
- final FromItem rightSide = parseTableItem(secondTableToken);
-
- // onClausess = ["f.id = b.id"]
- final String[] onClauses = secondPart.substring(indexOfOn + " ON ".length()).split(" AND ");
- final SelectItem[] leftOn = new SelectItem[onClauses.length];
- final SelectItem[] rightOn = new SelectItem[onClauses.length];
- for (int i = 0; i < onClauses.length; i++) {
- final String onClause = onClauses[i];
- final int indexOfEquals = onClause.indexOf("=");
- // leftPart = "f.id"
- final String leftPart = onClause.substring(0, indexOfEquals).trim();
- // rightPart = "b.id"
- final String rightPart = onClause.substring(indexOfEquals + 1).trim();
-
- leftOn[i] = findSelectItem(leftPart, leftSide, rightSide);
- rightOn[i] = findSelectItem(rightPart, leftSide, rightSide);
- }
-
- final FromItem result = new FromItem(joinType, leftSide, rightSide, leftOn, rightOn);
- result.setQuery(_query);
- return result;
- }
-
- private SelectItem findSelectItem(String token, FromItem leftSide, FromItem rightSide) {
- // first look in the original query
- SelectItemParser selectItemParser = new SelectItemParser(_query, false);
- SelectItem result = selectItemParser.findSelectItem(token);
-
- if (result == null) {
- // fail over and try with the from items available in the join that
- // is being built.
- final Query temporaryQuery = new Query().from(leftSide, rightSide);
- selectItemParser = new SelectItemParser(temporaryQuery, false);
- result = selectItemParser.findSelectItem(token);
-
- if (result == null) {
- throw new QueryParserException("Not capable of parsing ON token: " + token);
- }
-
- // set the query on the involved query parts (since they have been
- // temporarily moved to the searched query).
- leftSide.setQuery(_query);
- rightSide.setQuery(_query);
- result.setQuery(_query);
- }
- return result;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/parser/GroupByItemParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/parser/GroupByItemParser.java b/core/src/main/java/org/eobjects/metamodel/query/parser/GroupByItemParser.java
deleted file mode 100644
index fc7e776..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/parser/GroupByItemParser.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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.query.parser;
-
-import org.eobjects.metamodel.query.Query;
-
-final class GroupByItemParser implements QueryPartProcessor {
-
- private final Query _query;
-
- public GroupByItemParser(Query query) {
- _query = query;
- }
-
- @Override
- public void parse(String delim, String itemToken) {
- _query.groupBy(itemToken);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/parser/HavingItemParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/parser/HavingItemParser.java b/core/src/main/java/org/eobjects/metamodel/query/parser/HavingItemParser.java
deleted file mode 100644
index 5f4a559..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/parser/HavingItemParser.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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.query.parser;
-
-import org.eobjects.metamodel.query.Query;
-
-final class HavingItemParser implements QueryPartProcessor {
-
- private final Query _query;
-
- public HavingItemParser(Query query) {
- _query = query;
- }
-
- @Override
- public void parse(String delim, String itemToken) {
- _query.having(itemToken);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/parser/OrderByItemParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/parser/OrderByItemParser.java b/core/src/main/java/org/eobjects/metamodel/query/parser/OrderByItemParser.java
deleted file mode 100644
index 8c3ebf0..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/parser/OrderByItemParser.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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.query.parser;
-
-import org.eobjects.metamodel.query.Query;
-
-final class OrderByItemParser implements QueryPartProcessor {
-
- private final Query _query;
-
- public OrderByItemParser(Query query) {
- _query = query;
- }
-
- @Override
- public void parse(String delim, String itemToken) {
- _query.orderBy(itemToken);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/parser/QueryParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/parser/QueryParser.java b/core/src/main/java/org/eobjects/metamodel/query/parser/QueryParser.java
deleted file mode 100644
index a5f0e03..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/parser/QueryParser.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/**
- * 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.query.parser;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.query.Query;
-
-/**
- * A parser class of for full SQL-like queries.
- */
-public class QueryParser {
-
- private final DataContext _dataContext;
- private final String _queryString;
- private final String _queryStringUpperCase;
-
- public QueryParser(DataContext dataContext, String queryString) {
- if (dataContext == null) {
- throw new IllegalArgumentException("DataContext cannot be null");
- }
- if (queryString == null) {
- throw new IllegalArgumentException("Query string cannot be null");
- }
- _dataContext = dataContext;
- _queryString = prepareQuery(queryString);
- _queryStringUpperCase = _queryString.toUpperCase();
- }
-
- /**
- * Performs any preparations (not changing any semantics) to the query
- * string
- *
- * @param queryString
- * @return
- */
- private String prepareQuery(String queryString) {
- queryString = queryString.replaceAll("[\n\r\t]", " ");
- queryString = queryString.replaceAll(" ", " ");
- queryString = queryString.trim();
- return queryString;
- }
-
- public Query parse() throws QueryParserException {
- final Query query = new Query();
-
- // collect focal point query clauses
- int[] selectIndices = indexesOf("SELECT ", null);
- int[] fromIndices = indexesOf(" FROM ", selectIndices);
- int[] whereIndices = indexesOf(" WHERE ", fromIndices);
- int[] groupByIndices = indexesOf(" GROUP BY ", whereIndices);
- int[] havingIndices = indexesOf(" HAVING ", groupByIndices);
- int[] orderByIndices = indexesOf(" ORDER BY", havingIndices);
- int[] limitIndices = indexesOf(" LIMIT ", orderByIndices);
- int[] offsetIndices = indexesOf(" OFFSET ", limitIndices);
-
- // a few validations, minimum requirements
- if (selectIndices == null) {
- throw new QueryParserException("SELECT not found in query: " + _queryString);
- }
- if (fromIndices == null) {
- throw new QueryParserException("FROM not found in query: " + _queryString);
- }
-
- // parse FROM
- {
- final String fromClause = getSubstring(
- getLastEndIndex(fromIndices),
- getNextStartIndex(whereIndices, groupByIndices, havingIndices, orderByIndices, limitIndices,
- offsetIndices));
- parseFromClause(query, fromClause);
- }
-
- {
- String selectClause = getSubstring(getLastEndIndex(selectIndices), fromIndices[0]);
- if (selectClause.startsWith("DISTINCT ")) {
- query.selectDistinct();
- selectClause = selectClause.substring("DISTINCT ".length());
- }
- parseSelectClause(query, selectClause);
- }
-
- if (whereIndices != null) {
- final String whereClause = getSubstring(getLastEndIndex(whereIndices),
- getNextStartIndex(groupByIndices, havingIndices, orderByIndices, limitIndices, offsetIndices));
- if (whereClause != null) {
- parseWhereClause(query, whereClause);
- }
- }
-
- if (groupByIndices != null) {
- final String groupByClause = getSubstring(getLastEndIndex(groupByIndices, whereIndices),
- getNextStartIndex(havingIndices, orderByIndices, limitIndices, offsetIndices));
- if (groupByClause != null) {
- parseGroupByClause(query, groupByClause);
- }
- }
-
- if (havingIndices != null) {
- final String havingClause = getSubstring(
- getLastEndIndex(havingIndices, groupByIndices, whereIndices, fromIndices, selectIndices),
- getNextStartIndex(orderByIndices, limitIndices, offsetIndices));
- if (havingClause != null) {
- parseHavingClause(query, havingClause);
- }
- }
-
- if (orderByIndices != null) {
- final String orderByClause = getSubstring(
- getLastEndIndex(orderByIndices, havingIndices, groupByIndices, whereIndices, fromIndices,
- selectIndices), getNextStartIndex(limitIndices, offsetIndices));
- if (orderByClause != null) {
- parseOrderByClause(query, orderByClause);
- }
- }
-
- if (limitIndices != null) {
- final String limitClause = getSubstring(
- getLastEndIndex(limitIndices, orderByIndices, havingIndices, groupByIndices, whereIndices,
- fromIndices, selectIndices), getNextStartIndex(offsetIndices));
- if (limitClause != null) {
- parseLimitClause(query, limitClause);
- }
- }
-
- if (offsetIndices != null) {
- final String offsetClause = getSubstring(
- getLastEndIndex(offsetIndices, limitIndices, orderByIndices, havingIndices, groupByIndices,
- whereIndices, fromIndices, selectIndices), getNextStartIndex());
- if (offsetClause != null) {
- parseOffsetClause(query, offsetClause);
- }
- }
-
- return query;
- }
-
- private void parseFromClause(Query query, String fromClause) {
- QueryPartParser clauseParser = new QueryPartParser(new FromItemParser(_dataContext, query), fromClause, ",");
- clauseParser.parse();
- }
-
- private void parseSelectClause(Query query, String selectClause) {
- QueryPartParser clauseParser = new QueryPartParser(new SelectItemParser(query, false), selectClause, ",");
- clauseParser.parse();
- }
-
- private void parseWhereClause(Query query, String whereClause) {
- // only parse "AND" delimitors, since "OR" will be taken care of as
- // compound filter items at 2nd level parsing
- QueryPartParser clauseParser = new QueryPartParser(new WhereItemParser(query), whereClause, " AND ");
- clauseParser.parse();
- }
-
- private void parseGroupByClause(Query query, String groupByClause) {
- QueryPartParser clauseParser = new QueryPartParser(new GroupByItemParser(query), groupByClause, ",");
- clauseParser.parse();
- }
-
- private void parseHavingClause(Query query, String havingClause) {
- // only parse "AND" delimitors, since "OR" will be taken care of as
- // compound filter items at 2nd level parsing
- QueryPartParser clauseParser = new QueryPartParser(new HavingItemParser(query), havingClause, " AND ");
- clauseParser.parse();
- }
-
- private void parseOrderByClause(Query query, String orderByClause) {
- QueryPartParser clauseParser = new QueryPartParser(new OrderByItemParser(query), orderByClause, ",");
- clauseParser.parse();
- }
-
- private void parseLimitClause(Query query, String limitClause) {
- limitClause = limitClause.trim();
- if (!limitClause.isEmpty()) {
- try {
- int limit = Integer.parseInt(limitClause);
- query.setMaxRows(limit);
- } catch (NumberFormatException e) {
- throw new QueryParserException("Could not parse LIMIT value: " + limitClause);
- }
- }
- }
-
- private void parseOffsetClause(Query query, String offsetClause) {
- offsetClause = offsetClause.trim();
- if (!offsetClause.isEmpty()) {
- try {
- final int offset = Integer.parseInt(offsetClause);
- // ofset is 0-based, but first-row is 1-based
- final int firstRow = offset + 1;
- query.setFirstRow(firstRow);
- } catch (NumberFormatException e) {
- throw new QueryParserException("Could not parse OFFSET value: " + offsetClause);
- }
- }
- }
-
- private String getSubstring(Integer from, int to) {
- if (from == null) {
- return null;
- }
- if (from.intValue() == to) {
- return null;
- }
- return _queryString.substring(from, to);
- }
-
- private int getNextStartIndex(int[]... indicesArray) {
- for (int[] indices : indicesArray) {
- if (indices != null) {
- return indices[0];
- }
- }
- return _queryString.length();
- }
-
- private Integer getLastEndIndex(int[]... indicesArray) {
- for (int[] indices : indicesArray) {
- if (indices != null) {
- return indices[1];
- }
- }
- return null;
- }
-
- /**
- * Finds the start and end indexes of a string in the query. The string
- * parameter of this method is expected to be in upper case, while the query
- * itself is tolerant of case differences.
- *
- * @param string
- * @param previousIndices
- * @return
- */
- protected int[] indexesOf(String string, int[] previousIndices) {
- final int startIndex;
- if (previousIndices == null) {
- startIndex = _queryStringUpperCase.indexOf(string);
- } else {
- startIndex = _queryStringUpperCase.indexOf(string, previousIndices[1]);
- }
- if (startIndex == -1) {
- return null;
- }
- int endIndex = startIndex + string.length();
- return new int[] { startIndex, endIndex };
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/parser/QueryParserException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/parser/QueryParserException.java b/core/src/main/java/org/eobjects/metamodel/query/parser/QueryParserException.java
deleted file mode 100644
index 54bd94d..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/parser/QueryParserException.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * 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.query.parser;
-
-import org.eobjects.metamodel.MetaModelException;
-
-/**
- * Subtype of {@link MetaModelException} which indicate a problem in parsing a
- * query passed to the {@link QueryParser}.
- */
-public class QueryParserException extends MetaModelException {
-
- private static final long serialVersionUID = 1L;
-
- public QueryParserException() {
- super();
- }
-
- public QueryParserException(Exception cause) {
- super(cause);
- }
-
- public QueryParserException(String message, Exception cause) {
- super(message, cause);
- }
-
- public QueryParserException(String message) {
- super(message);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/parser/QueryPartCollectionProcessor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/parser/QueryPartCollectionProcessor.java b/core/src/main/java/org/eobjects/metamodel/query/parser/QueryPartCollectionProcessor.java
deleted file mode 100644
index ac45a49..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/parser/QueryPartCollectionProcessor.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * 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.query.parser;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Simple implementation of {@link QueryPartProcessor} which simply adds all
- * elements to a collection. Use {@link #getTokens()} to retrieve the 'processed'
- * tokens and {@link #getDelims()} for the corresponding delimitors.
- */
-public class QueryPartCollectionProcessor implements QueryPartProcessor {
-
- private final List<String> _delims;
- private final List<String> _tokens;
-
- public QueryPartCollectionProcessor() {
- _tokens = new ArrayList<String>();
- _delims = new ArrayList<String>();
- }
-
- @Override
- public void parse(String delim, String token) {
- _delims.add(delim);
- _tokens.add(token);
- }
-
- public List<String> getDelims() {
- return _delims;
- }
-
- public List<String> getTokens() {
- return _tokens;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/parser/QueryPartParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/parser/QueryPartParser.java b/core/src/main/java/org/eobjects/metamodel/query/parser/QueryPartParser.java
deleted file mode 100644
index 15050ea..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/parser/QueryPartParser.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/**
- * 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.query.parser;
-
-/**
- * Parser of query parts. This parser is aware of parenthesis symbols '(' and
- * ')' and only yields tokens that have balanced parentheses. Delimitors are
- * configurable.
- */
-public final class QueryPartParser {
-
- private final QueryPartProcessor _processor;
- private final String _clause;
- private final String[] _ItemDelims;
-
- public QueryPartParser(QueryPartProcessor processor, String clause, String... itemDelims) {
- if (clause == null) {
- throw new IllegalArgumentException("Clause cannot be null");
- }
- if (itemDelims == null || itemDelims.length == 0) {
- throw new IllegalArgumentException("Item delimitors cannot be null or empty");
- }
- _processor = processor;
- _clause = clause;
- _ItemDelims = itemDelims;
- }
-
- public void parse() {
- if (_clause.isEmpty()) {
- return;
- }
-
- int parenthesisCount = 0;
- int offset = 0;
- boolean singleOuterParenthesis = _clause.charAt(0) == '(' && _clause.charAt(_clause.length() - 1) == ')';
-
- String previousDelim = null;
- DelimOccurrence nextDelimOccurrence = getNextDelim(0);
- if (nextDelimOccurrence != null) {
- for (int i = 0; i < _clause.length(); i++) {
- char c = _clause.charAt(i);
- if (c == '(') {
- parenthesisCount++;
- } else if (c == ')') {
- parenthesisCount--;
- if (singleOuterParenthesis && parenthesisCount == 0 && i != _clause.length() - 1) {
- singleOuterParenthesis = false;
- }
- }
- if (i == nextDelimOccurrence.index) {
- if (parenthesisCount == 0) {
- // token bounds has been identified
- String itemToken = _clause.substring(offset, i);
- parseItem(previousDelim, itemToken);
- offset = i + nextDelimOccurrence.delim.length();
- previousDelim = nextDelimOccurrence.delim;
- }
- nextDelimOccurrence = getNextDelim(nextDelimOccurrence.index + 1);
- if (nextDelimOccurrence == null) {
- break;
- }
- }
- }
- }
-
- if (singleOuterParenthesis) {
- String newClause = _clause.substring(1, _clause.length() - 1);
- // re-run based on new clause
- QueryPartParser newParser = new QueryPartParser(_processor, newClause, _ItemDelims);
- newParser.parse();
- return;
- }
-
- // last token will occur outside loop
- if (offset != _clause.length()) {
- final String token = _clause.substring(offset);
- parseItem(previousDelim, token);
- }
- }
-
- private static class DelimOccurrence {
- public int index;
- public String delim;
- }
-
- private DelimOccurrence getNextDelim(int offset) {
- DelimOccurrence result = null;
- for (int i = 0; i < _ItemDelims.length; i++) {
- String delim = _ItemDelims[i];
- int index = _clause.indexOf(delim, offset);
- if (index != -1) {
- if (result == null || index == Math.min(result.index, index)) {
- result = new DelimOccurrence();
- result.index = index;
- result.delim = delim;
- }
- }
- }
- return result;
- }
-
- private void parseItem(String delim, String token) {
- if (token != null) {
- token = token.trim();
- if (!token.isEmpty()) {
- _processor.parse(delim, token);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/parser/QueryPartProcessor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/parser/QueryPartProcessor.java b/core/src/main/java/org/eobjects/metamodel/query/parser/QueryPartProcessor.java
deleted file mode 100644
index 27a5d88..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/parser/QueryPartProcessor.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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.query.parser;
-
-/**
- * Callback of the {@link QueryPartParser}, which recieves notifications
- * whenever a token is identified/parsed. A {@link QueryPartProcessor} is used
- * to perform the actual processing of identified tokens.
- */
-public interface QueryPartProcessor {
-
- /**
- * Method invoked whenever the {@link QueryPartParser} identifies a token.
- *
- * @param delim
- * the (previous) delimitor identified before the token. This
- * will always be null in case of the first token.
- * @param token
- * the token identified.
- */
- public void parse(String delim, String token);
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/parser/SelectItemParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/parser/SelectItemParser.java b/core/src/main/java/org/eobjects/metamodel/query/parser/SelectItemParser.java
deleted file mode 100644
index 2810a4a..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/parser/SelectItemParser.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/**
- * 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.query.parser;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-
-public final class SelectItemParser implements QueryPartProcessor {
-
- public static class MultipleSelectItemsParsedException extends IllegalArgumentException {
-
- private static final long serialVersionUID = 1L;
-
- private final FromItem _fromItem;
-
- public MultipleSelectItemsParsedException(FromItem fromItem) {
- _fromItem = fromItem;
- }
-
- public FromItem getFromItem() {
- return _fromItem;
- }
- }
-
- private final Query _query;
- private final boolean _allowExpressionBasedSelectItems;
-
- public SelectItemParser(Query query, boolean allowExpressionBasedSelectItems) {
- _query = query;
- _allowExpressionBasedSelectItems = allowExpressionBasedSelectItems;
- }
-
- @Override
- public void parse(String delim, String itemToken) throws MetaModelException {
- if ("*".equals(itemToken)) {
- _query.selectAll();
- return;
- }
-
- String alias = null;
- final int indexOfAlias = itemToken.toUpperCase().lastIndexOf(" AS ");
- if (indexOfAlias != -1) {
- alias = itemToken.substring(indexOfAlias + " AS ".length());
- itemToken = itemToken.substring(0, indexOfAlias);
- }
-
- try {
- final SelectItem selectItem = findSelectItem(itemToken);
- if (selectItem == null) {
- throw new QueryParserException("Not capable of parsing SELECT token: " + itemToken);
- }
-
- if (alias != null) {
- selectItem.setAlias(alias);
- }
-
- _query.select(selectItem);
- } catch (MultipleSelectItemsParsedException e) {
- FromItem fromItem = e.getFromItem();
- if (fromItem != null) {
- _query.selectAll(fromItem);
- } else {
- throw e;
- }
- }
- }
-
- /**
- * Finds/creates a SelectItem based on the given expression. Unlike the
- * {@link #parse(String, String)} method, this method will not actually add
- * the selectitem to the query.
- *
- * @param expression
- * @return
- *
- * @throws MultipleSelectItemsParsedException
- * if an expression yielding multiple select-items (such as "*")
- * was passed in the expression
- */
- public SelectItem findSelectItem(String expression) throws MultipleSelectItemsParsedException {
- if ("*".equals(expression)) {
- throw new MultipleSelectItemsParsedException(null);
- }
-
- if ("COUNT(*)".equalsIgnoreCase(expression)) {
- return SelectItem.getCountAllItem();
- }
-
- final FunctionType function;
- final int startParenthesis = expression.indexOf('(');
- if (startParenthesis > 0 && expression.endsWith(")")) {
- String functionName = expression.substring(0, startParenthesis);
- function = FunctionType.get(functionName);
- if (function != null) {
- expression = expression.substring(startParenthesis + 1, expression.length() - 1).trim();
- if (function == FunctionType.COUNT && "*".equals(expression)) {
- return SelectItem.getCountAllItem();
- }
- }
- } else {
- function = null;
- }
-
- int lastIndexOfDot = expression.lastIndexOf(".");
-
- String columnName = null;
- FromItem fromItem = null;
-
- if (lastIndexOfDot != -1) {
- String prefix = expression.substring(0, lastIndexOfDot);
- columnName = expression.substring(lastIndexOfDot + 1);
- fromItem = _query.getFromClause().getItemByReference(prefix);
- }
-
- if (fromItem == null) {
- if (_query.getFromClause().getItemCount() == 1) {
- fromItem = _query.getFromClause().getItem(0);
- columnName = expression;
- } else {
- fromItem = null;
- columnName = null;
- }
- }
-
- if (fromItem != null) {
- if ("*".equals(columnName)) {
- throw new MultipleSelectItemsParsedException(fromItem);
- } else if (fromItem.getTable() != null) {
- Column column = fromItem.getTable().getColumnByName(columnName);
- if (column != null) {
- SelectItem selectItem = new SelectItem(function, column, fromItem);
- return selectItem;
- }
- } else if (fromItem.getSubQuery() != null) {
- final Query subQuery = fromItem.getSubQuery();
- final SelectItem subQuerySelectItem = new SelectItemParser(subQuery, _allowExpressionBasedSelectItems).findSelectItem(columnName);
- if (subQuerySelectItem == null) {
- return null;
- }
- return new SelectItem(subQuerySelectItem, fromItem);
- }
- }
-
- if (_allowExpressionBasedSelectItems) {
- return new SelectItem(function, expression, null);
- }
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/parser/WhereItemParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/parser/WhereItemParser.java b/core/src/main/java/org/eobjects/metamodel/query/parser/WhereItemParser.java
deleted file mode 100644
index 764fbdc..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/parser/WhereItemParser.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * 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.query.parser;
-
-import org.eobjects.metamodel.query.Query;
-
-final class WhereItemParser implements QueryPartProcessor {
-
- private final Query _query;
-
- public WhereItemParser(Query query) {
- _query = query;
- }
-
- @Override
- public void parse(String delim, String itemToken) {
- _query.where(itemToken);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/AbstractColumn.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/AbstractColumn.java b/core/src/main/java/org/eobjects/metamodel/schema/AbstractColumn.java
deleted file mode 100644
index 85cc2e4..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/AbstractColumn.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/**
- * 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.schema;
-
-/**
- * Abstract {@link Column} implementation. Implements most common and trivial
- * methods.
- *
- * @author Kasper Sørensen
- */
-public abstract class AbstractColumn implements Column {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public final String getQuotedName() {
- String quote = getQuote();
- if (quote == null) {
- return getName();
- }
- return quote + getName() + quote;
- }
-
- @Override
- public final String getQualifiedLabel() {
- StringBuilder sb = new StringBuilder();
- Table table = getTable();
- if (table != null) {
- sb.append(table.getQualifiedLabel());
- sb.append('.');
- }
- sb.append(getName());
- return sb.toString();
- }
-
- @Override
- public final int compareTo(Column that) {
- int diff = getQualifiedLabel().compareTo(that.getQualifiedLabel());
- if (diff == 0) {
- diff = toString().compareTo(that.toString());
- }
- return diff;
- }
-
- @Override
- public final String toString() {
- return "Column[name=" + getName() + ",columnNumber=" + getColumnNumber() + ",type=" + getType() + ",nullable="
- + isNullable() + ",nativeType=" + getNativeType() + ",columnSize=" + getColumnSize() + "]";
- }
-
- @Override
- public int hashCode() {
- return getName().hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (obj == this) {
- return true;
- }
- if (obj instanceof Column) {
- Column other = (Column) obj;
- if (!getName().equals(other.getName())) {
- return false;
- }
- if (getType() != other.getType()) {
- return false;
- }
-
- final Table table1 = getTable();
- final Table table2 = other.getTable();
- if (table1 == null) {
- if (table2 != null) {
- return false;
- }
- } else {
- if (!table1.equals(table2)) {
- return false;
- }
- }
- return true;
- }
- 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/eobjects/metamodel/schema/AbstractRelationship.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/AbstractRelationship.java b/core/src/main/java/org/eobjects/metamodel/schema/AbstractRelationship.java
deleted file mode 100644
index c1d5646..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/AbstractRelationship.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/**
- * 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.schema;
-
-import java.util.List;
-
-import org.eobjects.metamodel.util.BaseObject;
-
-public abstract class AbstractRelationship extends BaseObject implements
- Relationship {
-
- private static final long serialVersionUID = 1L;
-
- protected static Table checkSameTable(Column[] columns) {
- if (columns == null || columns.length == 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];
- if (i == 0) {
- table = column.getTable();
- } else {
- if (table != column.getTable()) {
- throw new IllegalArgumentException(
- "Key-columns did not have same table");
- }
- }
- }
- return table;
- }
-
- @Override
- public Table getForeignTable() {
- return getForeignColumns()[0].getTable();
- }
-
- @Override
- public Table getPrimaryTable() {
- return getPrimaryColumns()[0].getTable();
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("Relationship[");
- sb.append("primaryTable=" + getPrimaryTable().getName());
- Column[] columns = getPrimaryColumns();
- sb.append(",primaryColumns=[");
- for (int i = 0; i < columns.length; i++) {
- if (i != 0) {
- sb.append(", ");
- }
- sb.append(columns[i].getName());
- }
- sb.append("]");
- sb.append(",foreignTable=" + getForeignTable().getName());
- columns = getForeignColumns();
- sb.append(",foreignColumns=[");
- for (int i = 0; i < columns.length; i++) {
- if (i != 0) {
- sb.append(", ");
- }
- sb.append(columns[i].getName());
- }
- sb.append("]");
- sb.append("]");
- return sb.toString();
- }
-
- public int compareTo(Relationship that) {
- return toString().compareTo(that.toString());
- }
-
- @Override
- protected final void decorateIdentity(List<Object> identifiers) {
- identifiers.add(getPrimaryColumns());
- identifiers.add(getForeignColumns());
- }
-
- @Override
- protected final boolean classEquals(BaseObject obj) {
- return obj instanceof Relationship;
- }
-
- @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])) {
- return true;
- }
- }
- }
- 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/eobjects/metamodel/schema/AbstractSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/AbstractSchema.java b/core/src/main/java/org/eobjects/metamodel/schema/AbstractSchema.java
deleted file mode 100644
index 79ccb09..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/AbstractSchema.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/**
- * 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.schema;
-
-import java.util.ArrayList;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.eobjects.metamodel.util.Action;
-import org.eobjects.metamodel.util.CollectionUtils;
-import org.eobjects.metamodel.util.EqualsBuilder;
-import org.eobjects.metamodel.util.HasNameMapper;
-import org.eobjects.metamodel.util.Predicate;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Abstract implementation of the {@link Schema} interface. Implements most
- * common and trivial methods.
- *
- * @author Kasper Sørensen
- */
-public abstract class AbstractSchema implements Schema {
-
- private static final long serialVersionUID = 1L;
-
- private static final Logger logger = LoggerFactory.getLogger(AbstractSchema.class);
-
- @Override
- public final String getQuotedName() {
- String quote = getQuote();
- if (quote == null) {
- return getName();
- }
- return quote + getName() + quote;
- }
-
- @Override
- public Relationship[] getRelationships() {
- final Set<Relationship> result = new LinkedHashSet<Relationship>();
- CollectionUtils.forEach(getTables(), new Action<Table>() {
- @Override
- public void run(Table table) {
- Relationship[] relations = table.getRelationships();
- for (int i = 0; i < relations.length; i++) {
- Relationship relation = relations[i];
- result.add(relation);
- }
- }
- });
- return result.toArray(new Relationship[result.size()]);
- }
-
- @Override
- public Table getTable(int index) throws IndexOutOfBoundsException {
- Table[] tables = getTables();
- return tables[index];
- }
-
- @Override
- public final String getQualifiedLabel() {
- return getName();
- }
-
- @Override
- public final int getTableCount(TableType type) {
- return getTables(type).length;
- }
-
- @Override
- public final int getRelationshipCount() {
- return getRelationships().length;
- }
-
- @Override
- public final int getTableCount() {
- return getTables().length;
- }
-
- @Override
- public final Table[] getTables(final TableType type) {
- return CollectionUtils.filter(getTables(), new Predicate<Table>() {
- @Override
- public Boolean eval(Table table) {
- return table.getType() == type;
- }
- }).toArray(new Table[0]);
- }
-
- @Override
- public final Table getTableByName(String tableName) {
- if (tableName == null) {
- return null;
- }
-
- final List<Table> foundTables = new ArrayList<Table>(1);
- // Search for table matches, case insensitive.
- for (Table table : getTables()) {
- if (tableName.equalsIgnoreCase(table.getName())) {
- foundTables.add(table);
- }
- }
-
- final int numTables = foundTables.size();
- if (logger.isDebugEnabled()) {
- logger.debug("Found {} tables(s) matching '{}': {}", new Object[] { numTables, tableName, foundTables });
- }
-
- if (numTables == 0) {
- return null;
- } else if (numTables == 1) {
- return foundTables.get(0);
- }
-
- // If more matches are found, search case sensitive
- for (Table table : foundTables) {
- if (tableName.equals(table.getName())) {
- return table;
- }
- }
-
- // if none matches case sensitive, pick the first one.
- return foundTables.get(0);
- }
-
- @Override
- public final String[] getTableNames() {
- Table[] tables = getTables();
- return CollectionUtils.map(tables, new HasNameMapper()).toArray(new String[tables.length]);
- }
-
- @Override
- public final String toString() {
- return "Schema[name=" + getName() + "]";
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (obj == this) {
- return true;
- }
- if (obj instanceof Schema) {
- Schema other = (Schema) obj;
- EqualsBuilder eb = new EqualsBuilder();
- eb.append(getName(), other.getName());
- eb.append(getQuote(), other.getQuote());
- if (eb.isEquals()) {
- try {
- int tableCount1 = getTableCount();
- int tableCount2 = other.getTableCount();
- eb.append(tableCount1, tableCount2);
- } catch (Exception e) {
- // might occur when schemas are disconnected. Omit this check then.
- }
- }
- return eb.isEquals();
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- String name = getName();
- if (name == null) {
- return -1;
- }
- return name.hashCode();
- }
-
- @Override
- public final int compareTo(Schema that) {
- int diff = getQualifiedLabel().compareTo(that.getQualifiedLabel());
- if (diff == 0) {
- diff = toString().compareTo(that.toString());
- }
- return diff;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/AbstractTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/AbstractTable.java b/core/src/main/java/org/eobjects/metamodel/schema/AbstractTable.java
deleted file mode 100644
index 3728751..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/AbstractTable.java
+++ /dev/null
@@ -1,329 +0,0 @@
-/**
- * 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.schema;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.util.Action;
-import org.eobjects.metamodel.util.CollectionUtils;
-import org.eobjects.metamodel.util.HasNameMapper;
-import org.eobjects.metamodel.util.Predicate;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Abstract {@link Table} implementation. Includes most common/trivial methods.
- *
- * @author Kasper Sørensen
- */
-public abstract class AbstractTable implements Table {
-
- private static final long serialVersionUID = 1L;
-
- private static final Logger logger = LoggerFactory.getLogger(AbstractTable.class);
-
- @Override
- public final int getColumnCount() {
- return getColumns().length;
- }
-
- @Override
- public Column getColumn(int index) throws IndexOutOfBoundsException {
- Column[] columns = getColumns();
- return columns[index];
- }
-
- @Override
- public final Column getColumnByName(final String columnName) {
- if (columnName == null) {
- return null;
- }
-
- final List<Column> foundColumns = new ArrayList<Column>(1);
-
- // Search for column matches, case insensitive.
- for (Column column : getColumns()) {
- final String candidateName = column.getName();
- if (columnName.equalsIgnoreCase(candidateName)) {
- foundColumns.add(column);
- }
- }
-
- final int numColumns = foundColumns.size();
-
- if (logger.isDebugEnabled()) {
- logger.debug("Found {} column(s) matching '{}': {}", new Object[] { numColumns, columnName, foundColumns });
- }
-
- if (numColumns == 0) {
- return null;
- } else if (numColumns == 1) {
- // if there's only one, return it.
- return foundColumns.get(0);
- }
-
- // If more matches are found, search case sensitive
- for (Column column : foundColumns) {
- if (columnName.equals(column.getName())) {
- return column;
- }
- }
-
- // if none matches case sensitive, pick the first one.
- return foundColumns.get(0);
- }
-
- @Override
- public final int getRelationshipCount() {
- return getRelationships().length;
- }
-
- @Override
- public final Column[] getNumberColumns() {
- return CollectionUtils.filter(getColumns(), new Predicate<Column>() {
- @Override
- public Boolean eval(Column col) {
- ColumnType type = col.getType();
- return type != null && type.isNumber();
- }
- }).toArray(new Column[0]);
- }
-
- @Override
- public final Column[] getLiteralColumns() {
- return CollectionUtils.filter(getColumns(), new Predicate<Column>() {
- @Override
- public Boolean eval(Column col) {
- ColumnType type = col.getType();
- return type != null && type.isLiteral();
- }
- }).toArray(new Column[0]);
- }
-
- @Override
- public final Column[] getTimeBasedColumns() {
- return CollectionUtils.filter(getColumns(), new Predicate<Column>() {
- @Override
- public Boolean eval(Column col) {
- ColumnType type = col.getType();
- return type != null && type.isTimeBased();
- }
- }).toArray(new Column[0]);
- }
-
- @Override
- public final Column[] getBooleanColumns() {
- return CollectionUtils.filter(getColumns(), new Predicate<Column>() {
- @Override
- public Boolean eval(Column col) {
- ColumnType type = col.getType();
- return type != null && type.isBoolean();
- }
- }).toArray(new Column[0]);
- }
-
- @Override
- public final Column[] getIndexedColumns() {
- return CollectionUtils.filter(getColumns(), new Predicate<Column>() {
- @Override
- public Boolean eval(Column col) {
- return col.isIndexed();
- }
- }).toArray(new Column[0]);
- }
-
- @Override
- public final Relationship[] getForeignKeyRelationships() {
- return CollectionUtils.filter(getRelationships(), new Predicate<Relationship>() {
- @Override
- public Boolean eval(Relationship arg) {
- return AbstractTable.this.equals(arg.getForeignTable());
- }
- }).toArray(new Relationship[0]);
- }
-
- @Override
- public final Relationship[] getPrimaryKeyRelationships() {
- return CollectionUtils.filter(getRelationships(), new Predicate<Relationship>() {
- @Override
- public Boolean eval(Relationship arg) {
- return AbstractTable.this.equals(arg.getPrimaryTable());
- }
- }).toArray(new Relationship[0]);
- }
-
- @Override
- public final Column[] getForeignKeys() {
- final Set<Column> columns = new HashSet<Column>();
- final Relationship[] relationships = getForeignKeyRelationships();
- CollectionUtils.forEach(relationships, new Action<Relationship>() {
- @Override
- public void run(Relationship arg) {
- Column[] foreignColumns = arg.getForeignColumns();
- for (Column column : foreignColumns) {
- columns.add(column);
- }
- }
- });
- return columns.toArray(new Column[columns.size()]);
- }
-
- @Override
- public final Column[] getPrimaryKeys() {
- final List<Column> primaryKeyColumns = new ArrayList<Column>();
- final Column[] columnsInTable = getColumns();
- for (Column column : columnsInTable) {
- if (column.isPrimaryKey()) {
- primaryKeyColumns.add(column);
- }
- }
- return primaryKeyColumns.toArray(new Column[primaryKeyColumns.size()]);
- }
-
- @Override
- public final String[] getColumnNames() {
- Column[] columns = getColumns();
- return CollectionUtils.map(columns, new HasNameMapper()).toArray(new String[columns.length]);
- }
-
- @Override
- public final Column[] getColumnsOfType(ColumnType columnType) {
- Column[] columns = getColumns();
- return MetaModelHelper.getColumnsByType(columns, columnType);
- }
-
- @Override
- public final Column[] getColumnsOfSuperType(final SuperColumnType superColumnType) {
- Column[] columns = getColumns();
- return MetaModelHelper.getColumnsBySuperType(columns, superColumnType);
- }
-
- @Override
- public final Relationship[] getRelationships(final Table otherTable) {
- Relationship[] relationships = getRelationships();
-
- return CollectionUtils.filter(relationships, new Predicate<Relationship>() {
- @Override
- public Boolean eval(Relationship relation) {
- if (relation.getForeignTable() == otherTable && relation.getPrimaryTable() == AbstractTable.this) {
- return true;
- } else if (relation.getForeignTable() == AbstractTable.this && relation.getPrimaryTable() == otherTable) {
- return true;
- }
- return false;
- }
- }).toArray(new Relationship[0]);
- }
-
- @Override
- public final String getQuotedName() {
- String quote = getQuote();
- if (quote == null) {
- return getName();
- }
- return quote + getName() + quote;
- }
-
- @Override
- public final String getQualifiedLabel() {
- StringBuilder sb = new StringBuilder();
- Schema schema = getSchema();
- if (schema != null && schema.getName() != null) {
- sb.append(schema.getQualifiedLabel());
- sb.append('.');
- }
- sb.append(getName());
- return sb.toString();
- }
-
- @Override
- public final String toString() {
- return "Table[name=" + getName() + ",type=" + getType() + ",remarks=" + getRemarks() + "]";
- }
-
- @Override
- public int hashCode() {
- return getName().hashCode();
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (obj == null) {
- return false;
- }
- if (obj == this) {
- return true;
- }
- if (obj instanceof Table) {
- final Table other = (Table) obj;
- if (!getQualifiedLabel().equals(other.getQualifiedLabel())) {
- return false;
- }
- if (getType() != other.getType()) {
- return false;
- }
- final Schema sch1 = getSchema();
- final Schema sch2 = other.getSchema();
- if (sch1 != null) {
- if (!sch1.equals(sch2)) {
- return false;
- }
- } else {
- if (sch2 != null) {
- return false;
- }
- }
-
- try {
- final String[] columnNames1 = getColumnNames();
- final String[] columnNames2 = other.getColumnNames();
-
- if (columnNames1 != null && columnNames1.length != 0) {
- if (columnNames2 != null && columnNames2.length != 0) {
- if (!Arrays.equals(columnNames1, columnNames2)) {
- return false;
- }
- }
- }
- } catch (Exception e) {
- // going "down stream" may throw exceptions, e.g. due to
- // de-serialization issues. We will be tolerant to such
- // exceptions
- logger.debug("Caught (and ignoring) exception while comparing column names of tables", e);
- }
-
- return true;
- }
- return false;
- }
-
- @Override
- public final int compareTo(Table that) {
- int diff = getQualifiedLabel().compareTo(that.getQualifiedLabel());
- if (diff == 0) {
- diff = toString().compareTo(that.toString());
- }
- return diff;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/Column.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/Column.java b/core/src/main/java/org/eobjects/metamodel/schema/Column.java
deleted file mode 100644
index 1208368..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/Column.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * 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.schema;
-
-import java.io.Serializable;
-
-/**
- * Represents a column and it's metadata description. Columns reside within a
- * Table and can be used as keys for relationships between tables.
- *
- * @see Table
- *
- * @author Kasper Sørensen
- */
-public interface Column extends Comparable<Column>, Serializable, NamedStructure {
-
- /**
- * Gets the name of this Column
- *
- * @return the name of this Column
- */
- @Override
- public String getName();
-
- /**
- * Returns the column number or index. Note: This column number is 0-based
- * whereas the JDBC is 1-based.
- *
- * @return the number of this column.
- */
- public int getColumnNumber();
-
- /**
- * Gets the type of the column
- *
- * @return this column's type.
- */
- public ColumnType getType();
-
- /**
- * Gets the table for which this column belong
- *
- * @return this column's table.
- */
- public Table getTable();
-
- /**
- * Determines whether or not this column accepts null values.
- *
- * @return true if this column accepts null values, false if not and null if
- * not known.
- */
- public Boolean isNullable();
-
- /**
- * Gets any remarks/comments to this column.
- *
- * @return any remarks/comments to this column.
- */
- public String getRemarks();
-
- /**
- * Gets the data type size of this column.
- *
- * @return the data type size of this column or null if the size is not
- * determined or known.
- */
- public Integer getColumnSize();
-
- /**
- * Gets the native type of this column. A native type is the name of the
- * data type as defined in the datastore.
- *
- * @return the name of the native type.
- */
- public String getNativeType();
-
- /**
- * Determines if this column is indexed.
- *
- * @return true if this column is indexed or false if not (or not known)
- */
- public boolean isIndexed();
-
- /**
- * Determines if this column is (one of) the primary key(s) of its table.
- *
- * @return true if this column is a primary key, or false if not (or if this
- * is not determinable).
- */
- public boolean isPrimaryKey();
-}
\ No newline at end of file
[48/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
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
[42/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/parser/QueryPartProcessor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/QueryPartProcessor.java b/core/src/main/java/org/apache/metamodel/query/parser/QueryPartProcessor.java
new file mode 100644
index 0000000..27a5d88
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/parser/QueryPartProcessor.java
@@ -0,0 +1,38 @@
+/**
+ * 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.query.parser;
+
+/**
+ * Callback of the {@link QueryPartParser}, which recieves notifications
+ * whenever a token is identified/parsed. A {@link QueryPartProcessor} is used
+ * to perform the actual processing of identified tokens.
+ */
+public interface QueryPartProcessor {
+
+ /**
+ * Method invoked whenever the {@link QueryPartParser} identifies a token.
+ *
+ * @param delim
+ * the (previous) delimitor identified before the token. This
+ * will always be null in case of the first token.
+ * @param token
+ * the token identified.
+ */
+ public void parse(String delim, String token);
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/parser/SelectItemParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/SelectItemParser.java b/core/src/main/java/org/apache/metamodel/query/parser/SelectItemParser.java
new file mode 100644
index 0000000..2810a4a
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/parser/SelectItemParser.java
@@ -0,0 +1,170 @@
+/**
+ * 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.query.parser;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.FunctionType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+
+public final class SelectItemParser implements QueryPartProcessor {
+
+ public static class MultipleSelectItemsParsedException extends IllegalArgumentException {
+
+ private static final long serialVersionUID = 1L;
+
+ private final FromItem _fromItem;
+
+ public MultipleSelectItemsParsedException(FromItem fromItem) {
+ _fromItem = fromItem;
+ }
+
+ public FromItem getFromItem() {
+ return _fromItem;
+ }
+ }
+
+ private final Query _query;
+ private final boolean _allowExpressionBasedSelectItems;
+
+ public SelectItemParser(Query query, boolean allowExpressionBasedSelectItems) {
+ _query = query;
+ _allowExpressionBasedSelectItems = allowExpressionBasedSelectItems;
+ }
+
+ @Override
+ public void parse(String delim, String itemToken) throws MetaModelException {
+ if ("*".equals(itemToken)) {
+ _query.selectAll();
+ return;
+ }
+
+ String alias = null;
+ final int indexOfAlias = itemToken.toUpperCase().lastIndexOf(" AS ");
+ if (indexOfAlias != -1) {
+ alias = itemToken.substring(indexOfAlias + " AS ".length());
+ itemToken = itemToken.substring(0, indexOfAlias);
+ }
+
+ try {
+ final SelectItem selectItem = findSelectItem(itemToken);
+ if (selectItem == null) {
+ throw new QueryParserException("Not capable of parsing SELECT token: " + itemToken);
+ }
+
+ if (alias != null) {
+ selectItem.setAlias(alias);
+ }
+
+ _query.select(selectItem);
+ } catch (MultipleSelectItemsParsedException e) {
+ FromItem fromItem = e.getFromItem();
+ if (fromItem != null) {
+ _query.selectAll(fromItem);
+ } else {
+ throw e;
+ }
+ }
+ }
+
+ /**
+ * Finds/creates a SelectItem based on the given expression. Unlike the
+ * {@link #parse(String, String)} method, this method will not actually add
+ * the selectitem to the query.
+ *
+ * @param expression
+ * @return
+ *
+ * @throws MultipleSelectItemsParsedException
+ * if an expression yielding multiple select-items (such as "*")
+ * was passed in the expression
+ */
+ public SelectItem findSelectItem(String expression) throws MultipleSelectItemsParsedException {
+ if ("*".equals(expression)) {
+ throw new MultipleSelectItemsParsedException(null);
+ }
+
+ if ("COUNT(*)".equalsIgnoreCase(expression)) {
+ return SelectItem.getCountAllItem();
+ }
+
+ final FunctionType function;
+ final int startParenthesis = expression.indexOf('(');
+ if (startParenthesis > 0 && expression.endsWith(")")) {
+ String functionName = expression.substring(0, startParenthesis);
+ function = FunctionType.get(functionName);
+ if (function != null) {
+ expression = expression.substring(startParenthesis + 1, expression.length() - 1).trim();
+ if (function == FunctionType.COUNT && "*".equals(expression)) {
+ return SelectItem.getCountAllItem();
+ }
+ }
+ } else {
+ function = null;
+ }
+
+ int lastIndexOfDot = expression.lastIndexOf(".");
+
+ String columnName = null;
+ FromItem fromItem = null;
+
+ if (lastIndexOfDot != -1) {
+ String prefix = expression.substring(0, lastIndexOfDot);
+ columnName = expression.substring(lastIndexOfDot + 1);
+ fromItem = _query.getFromClause().getItemByReference(prefix);
+ }
+
+ if (fromItem == null) {
+ if (_query.getFromClause().getItemCount() == 1) {
+ fromItem = _query.getFromClause().getItem(0);
+ columnName = expression;
+ } else {
+ fromItem = null;
+ columnName = null;
+ }
+ }
+
+ if (fromItem != null) {
+ if ("*".equals(columnName)) {
+ throw new MultipleSelectItemsParsedException(fromItem);
+ } else if (fromItem.getTable() != null) {
+ Column column = fromItem.getTable().getColumnByName(columnName);
+ if (column != null) {
+ SelectItem selectItem = new SelectItem(function, column, fromItem);
+ return selectItem;
+ }
+ } else if (fromItem.getSubQuery() != null) {
+ final Query subQuery = fromItem.getSubQuery();
+ final SelectItem subQuerySelectItem = new SelectItemParser(subQuery, _allowExpressionBasedSelectItems).findSelectItem(columnName);
+ if (subQuerySelectItem == null) {
+ return null;
+ }
+ return new SelectItem(subQuerySelectItem, fromItem);
+ }
+ }
+
+ if (_allowExpressionBasedSelectItems) {
+ return new SelectItem(function, expression, null);
+ }
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/parser/WhereItemParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/WhereItemParser.java b/core/src/main/java/org/apache/metamodel/query/parser/WhereItemParser.java
new file mode 100644
index 0000000..764fbdc
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/parser/WhereItemParser.java
@@ -0,0 +1,35 @@
+/**
+ * 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.query.parser;
+
+import org.eobjects.metamodel.query.Query;
+
+final class WhereItemParser implements QueryPartProcessor {
+
+ private final Query _query;
+
+ public WhereItemParser(Query query) {
+ _query = query;
+ }
+
+ @Override
+ public void parse(String delim, String itemToken) {
+ _query.where(itemToken);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/schema/AbstractColumn.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/AbstractColumn.java b/core/src/main/java/org/apache/metamodel/schema/AbstractColumn.java
new file mode 100644
index 0000000..85cc2e4
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/AbstractColumn.java
@@ -0,0 +1,104 @@
+/**
+ * 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.schema;
+
+/**
+ * Abstract {@link Column} implementation. Implements most common and trivial
+ * methods.
+ *
+ * @author Kasper Sørensen
+ */
+public abstract class AbstractColumn implements Column {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public final String getQuotedName() {
+ String quote = getQuote();
+ if (quote == null) {
+ return getName();
+ }
+ return quote + getName() + quote;
+ }
+
+ @Override
+ public final String getQualifiedLabel() {
+ StringBuilder sb = new StringBuilder();
+ Table table = getTable();
+ if (table != null) {
+ sb.append(table.getQualifiedLabel());
+ sb.append('.');
+ }
+ sb.append(getName());
+ return sb.toString();
+ }
+
+ @Override
+ public final int compareTo(Column that) {
+ int diff = getQualifiedLabel().compareTo(that.getQualifiedLabel());
+ if (diff == 0) {
+ diff = toString().compareTo(that.toString());
+ }
+ return diff;
+ }
+
+ @Override
+ public final String toString() {
+ return "Column[name=" + getName() + ",columnNumber=" + getColumnNumber() + ",type=" + getType() + ",nullable="
+ + isNullable() + ",nativeType=" + getNativeType() + ",columnSize=" + getColumnSize() + "]";
+ }
+
+ @Override
+ public int hashCode() {
+ return getName().hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (obj == this) {
+ return true;
+ }
+ if (obj instanceof Column) {
+ Column other = (Column) obj;
+ if (!getName().equals(other.getName())) {
+ return false;
+ }
+ if (getType() != other.getType()) {
+ return false;
+ }
+
+ final Table table1 = getTable();
+ final Table table2 = other.getTable();
+ if (table1 == null) {
+ if (table2 != null) {
+ return false;
+ }
+ } else {
+ if (!table1.equals(table2)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ 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/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
new file mode 100644
index 0000000..c1d5646
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/AbstractRelationship.java
@@ -0,0 +1,119 @@
+/**
+ * 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.schema;
+
+import java.util.List;
+
+import org.eobjects.metamodel.util.BaseObject;
+
+public abstract class AbstractRelationship extends BaseObject implements
+ Relationship {
+
+ private static final long serialVersionUID = 1L;
+
+ protected static Table checkSameTable(Column[] columns) {
+ if (columns == null || columns.length == 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];
+ if (i == 0) {
+ table = column.getTable();
+ } else {
+ if (table != column.getTable()) {
+ throw new IllegalArgumentException(
+ "Key-columns did not have same table");
+ }
+ }
+ }
+ return table;
+ }
+
+ @Override
+ public Table getForeignTable() {
+ return getForeignColumns()[0].getTable();
+ }
+
+ @Override
+ public Table getPrimaryTable() {
+ return getPrimaryColumns()[0].getTable();
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Relationship[");
+ sb.append("primaryTable=" + getPrimaryTable().getName());
+ Column[] columns = getPrimaryColumns();
+ sb.append(",primaryColumns=[");
+ for (int i = 0; i < columns.length; i++) {
+ if (i != 0) {
+ sb.append(", ");
+ }
+ sb.append(columns[i].getName());
+ }
+ sb.append("]");
+ sb.append(",foreignTable=" + getForeignTable().getName());
+ columns = getForeignColumns();
+ sb.append(",foreignColumns=[");
+ for (int i = 0; i < columns.length; i++) {
+ if (i != 0) {
+ sb.append(", ");
+ }
+ sb.append(columns[i].getName());
+ }
+ sb.append("]");
+ sb.append("]");
+ return sb.toString();
+ }
+
+ public int compareTo(Relationship that) {
+ return toString().compareTo(that.toString());
+ }
+
+ @Override
+ protected final void decorateIdentity(List<Object> identifiers) {
+ identifiers.add(getPrimaryColumns());
+ identifiers.add(getForeignColumns());
+ }
+
+ @Override
+ protected final boolean classEquals(BaseObject obj) {
+ return obj instanceof Relationship;
+ }
+
+ @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])) {
+ return true;
+ }
+ }
+ }
+ 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/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
new file mode 100644
index 0000000..79ccb09
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/AbstractSchema.java
@@ -0,0 +1,198 @@
+/**
+ * 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.schema;
+
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eobjects.metamodel.util.Action;
+import org.eobjects.metamodel.util.CollectionUtils;
+import org.eobjects.metamodel.util.EqualsBuilder;
+import org.eobjects.metamodel.util.HasNameMapper;
+import org.eobjects.metamodel.util.Predicate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract implementation of the {@link Schema} interface. Implements most
+ * common and trivial methods.
+ *
+ * @author Kasper Sørensen
+ */
+public abstract class AbstractSchema implements Schema {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = LoggerFactory.getLogger(AbstractSchema.class);
+
+ @Override
+ public final String getQuotedName() {
+ String quote = getQuote();
+ if (quote == null) {
+ return getName();
+ }
+ return quote + getName() + quote;
+ }
+
+ @Override
+ public Relationship[] getRelationships() {
+ final Set<Relationship> result = new LinkedHashSet<Relationship>();
+ CollectionUtils.forEach(getTables(), new Action<Table>() {
+ @Override
+ public void run(Table table) {
+ Relationship[] relations = table.getRelationships();
+ for (int i = 0; i < relations.length; i++) {
+ Relationship relation = relations[i];
+ result.add(relation);
+ }
+ }
+ });
+ return result.toArray(new Relationship[result.size()]);
+ }
+
+ @Override
+ public Table getTable(int index) throws IndexOutOfBoundsException {
+ Table[] tables = getTables();
+ return tables[index];
+ }
+
+ @Override
+ public final String getQualifiedLabel() {
+ return getName();
+ }
+
+ @Override
+ public final int getTableCount(TableType type) {
+ return getTables(type).length;
+ }
+
+ @Override
+ public final int getRelationshipCount() {
+ return getRelationships().length;
+ }
+
+ @Override
+ public final int getTableCount() {
+ return getTables().length;
+ }
+
+ @Override
+ public final Table[] getTables(final TableType type) {
+ return CollectionUtils.filter(getTables(), new Predicate<Table>() {
+ @Override
+ public Boolean eval(Table table) {
+ return table.getType() == type;
+ }
+ }).toArray(new Table[0]);
+ }
+
+ @Override
+ public final Table getTableByName(String tableName) {
+ if (tableName == null) {
+ return null;
+ }
+
+ final List<Table> foundTables = new ArrayList<Table>(1);
+ // Search for table matches, case insensitive.
+ for (Table table : getTables()) {
+ if (tableName.equalsIgnoreCase(table.getName())) {
+ foundTables.add(table);
+ }
+ }
+
+ final int numTables = foundTables.size();
+ if (logger.isDebugEnabled()) {
+ logger.debug("Found {} tables(s) matching '{}': {}", new Object[] { numTables, tableName, foundTables });
+ }
+
+ if (numTables == 0) {
+ return null;
+ } else if (numTables == 1) {
+ return foundTables.get(0);
+ }
+
+ // If more matches are found, search case sensitive
+ for (Table table : foundTables) {
+ if (tableName.equals(table.getName())) {
+ return table;
+ }
+ }
+
+ // if none matches case sensitive, pick the first one.
+ return foundTables.get(0);
+ }
+
+ @Override
+ public final String[] getTableNames() {
+ Table[] tables = getTables();
+ return CollectionUtils.map(tables, new HasNameMapper()).toArray(new String[tables.length]);
+ }
+
+ @Override
+ public final String toString() {
+ return "Schema[name=" + getName() + "]";
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (obj == this) {
+ return true;
+ }
+ if (obj instanceof Schema) {
+ Schema other = (Schema) obj;
+ EqualsBuilder eb = new EqualsBuilder();
+ eb.append(getName(), other.getName());
+ eb.append(getQuote(), other.getQuote());
+ if (eb.isEquals()) {
+ try {
+ int tableCount1 = getTableCount();
+ int tableCount2 = other.getTableCount();
+ eb.append(tableCount1, tableCount2);
+ } catch (Exception e) {
+ // might occur when schemas are disconnected. Omit this check then.
+ }
+ }
+ return eb.isEquals();
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ String name = getName();
+ if (name == null) {
+ return -1;
+ }
+ return name.hashCode();
+ }
+
+ @Override
+ public final int compareTo(Schema that) {
+ int diff = getQualifiedLabel().compareTo(that.getQualifiedLabel());
+ if (diff == 0) {
+ diff = toString().compareTo(that.toString());
+ }
+ return diff;
+ }
+}
\ 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/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
new file mode 100644
index 0000000..3728751
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/AbstractTable.java
@@ -0,0 +1,329 @@
+/**
+ * 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.schema;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eobjects.metamodel.MetaModelHelper;
+import org.eobjects.metamodel.util.Action;
+import org.eobjects.metamodel.util.CollectionUtils;
+import org.eobjects.metamodel.util.HasNameMapper;
+import org.eobjects.metamodel.util.Predicate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract {@link Table} implementation. Includes most common/trivial methods.
+ *
+ * @author Kasper Sørensen
+ */
+public abstract class AbstractTable implements Table {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = LoggerFactory.getLogger(AbstractTable.class);
+
+ @Override
+ public final int getColumnCount() {
+ return getColumns().length;
+ }
+
+ @Override
+ public Column getColumn(int index) throws IndexOutOfBoundsException {
+ Column[] columns = getColumns();
+ return columns[index];
+ }
+
+ @Override
+ public final Column getColumnByName(final String columnName) {
+ if (columnName == null) {
+ return null;
+ }
+
+ final List<Column> foundColumns = new ArrayList<Column>(1);
+
+ // Search for column matches, case insensitive.
+ for (Column column : getColumns()) {
+ final String candidateName = column.getName();
+ if (columnName.equalsIgnoreCase(candidateName)) {
+ foundColumns.add(column);
+ }
+ }
+
+ final int numColumns = foundColumns.size();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Found {} column(s) matching '{}': {}", new Object[] { numColumns, columnName, foundColumns });
+ }
+
+ if (numColumns == 0) {
+ return null;
+ } else if (numColumns == 1) {
+ // if there's only one, return it.
+ return foundColumns.get(0);
+ }
+
+ // If more matches are found, search case sensitive
+ for (Column column : foundColumns) {
+ if (columnName.equals(column.getName())) {
+ return column;
+ }
+ }
+
+ // if none matches case sensitive, pick the first one.
+ return foundColumns.get(0);
+ }
+
+ @Override
+ public final int getRelationshipCount() {
+ return getRelationships().length;
+ }
+
+ @Override
+ public final Column[] getNumberColumns() {
+ return CollectionUtils.filter(getColumns(), new Predicate<Column>() {
+ @Override
+ public Boolean eval(Column col) {
+ ColumnType type = col.getType();
+ return type != null && type.isNumber();
+ }
+ }).toArray(new Column[0]);
+ }
+
+ @Override
+ public final Column[] getLiteralColumns() {
+ return CollectionUtils.filter(getColumns(), new Predicate<Column>() {
+ @Override
+ public Boolean eval(Column col) {
+ ColumnType type = col.getType();
+ return type != null && type.isLiteral();
+ }
+ }).toArray(new Column[0]);
+ }
+
+ @Override
+ public final Column[] getTimeBasedColumns() {
+ return CollectionUtils.filter(getColumns(), new Predicate<Column>() {
+ @Override
+ public Boolean eval(Column col) {
+ ColumnType type = col.getType();
+ return type != null && type.isTimeBased();
+ }
+ }).toArray(new Column[0]);
+ }
+
+ @Override
+ public final Column[] getBooleanColumns() {
+ return CollectionUtils.filter(getColumns(), new Predicate<Column>() {
+ @Override
+ public Boolean eval(Column col) {
+ ColumnType type = col.getType();
+ return type != null && type.isBoolean();
+ }
+ }).toArray(new Column[0]);
+ }
+
+ @Override
+ public final Column[] getIndexedColumns() {
+ return CollectionUtils.filter(getColumns(), new Predicate<Column>() {
+ @Override
+ public Boolean eval(Column col) {
+ return col.isIndexed();
+ }
+ }).toArray(new Column[0]);
+ }
+
+ @Override
+ public final Relationship[] getForeignKeyRelationships() {
+ return CollectionUtils.filter(getRelationships(), new Predicate<Relationship>() {
+ @Override
+ public Boolean eval(Relationship arg) {
+ return AbstractTable.this.equals(arg.getForeignTable());
+ }
+ }).toArray(new Relationship[0]);
+ }
+
+ @Override
+ public final Relationship[] getPrimaryKeyRelationships() {
+ return CollectionUtils.filter(getRelationships(), new Predicate<Relationship>() {
+ @Override
+ public Boolean eval(Relationship arg) {
+ return AbstractTable.this.equals(arg.getPrimaryTable());
+ }
+ }).toArray(new Relationship[0]);
+ }
+
+ @Override
+ public final Column[] getForeignKeys() {
+ final Set<Column> columns = new HashSet<Column>();
+ final Relationship[] relationships = getForeignKeyRelationships();
+ CollectionUtils.forEach(relationships, new Action<Relationship>() {
+ @Override
+ public void run(Relationship arg) {
+ Column[] foreignColumns = arg.getForeignColumns();
+ for (Column column : foreignColumns) {
+ columns.add(column);
+ }
+ }
+ });
+ return columns.toArray(new Column[columns.size()]);
+ }
+
+ @Override
+ public final Column[] getPrimaryKeys() {
+ final List<Column> primaryKeyColumns = new ArrayList<Column>();
+ final Column[] columnsInTable = getColumns();
+ for (Column column : columnsInTable) {
+ if (column.isPrimaryKey()) {
+ primaryKeyColumns.add(column);
+ }
+ }
+ return primaryKeyColumns.toArray(new Column[primaryKeyColumns.size()]);
+ }
+
+ @Override
+ public final String[] getColumnNames() {
+ Column[] columns = getColumns();
+ return CollectionUtils.map(columns, new HasNameMapper()).toArray(new String[columns.length]);
+ }
+
+ @Override
+ public final Column[] getColumnsOfType(ColumnType columnType) {
+ Column[] columns = getColumns();
+ return MetaModelHelper.getColumnsByType(columns, columnType);
+ }
+
+ @Override
+ public final Column[] getColumnsOfSuperType(final SuperColumnType superColumnType) {
+ Column[] columns = getColumns();
+ return MetaModelHelper.getColumnsBySuperType(columns, superColumnType);
+ }
+
+ @Override
+ public final Relationship[] getRelationships(final Table otherTable) {
+ Relationship[] relationships = getRelationships();
+
+ return CollectionUtils.filter(relationships, new Predicate<Relationship>() {
+ @Override
+ public Boolean eval(Relationship relation) {
+ if (relation.getForeignTable() == otherTable && relation.getPrimaryTable() == AbstractTable.this) {
+ return true;
+ } else if (relation.getForeignTable() == AbstractTable.this && relation.getPrimaryTable() == otherTable) {
+ return true;
+ }
+ return false;
+ }
+ }).toArray(new Relationship[0]);
+ }
+
+ @Override
+ public final String getQuotedName() {
+ String quote = getQuote();
+ if (quote == null) {
+ return getName();
+ }
+ return quote + getName() + quote;
+ }
+
+ @Override
+ public final String getQualifiedLabel() {
+ StringBuilder sb = new StringBuilder();
+ Schema schema = getSchema();
+ if (schema != null && schema.getName() != null) {
+ sb.append(schema.getQualifiedLabel());
+ sb.append('.');
+ }
+ sb.append(getName());
+ return sb.toString();
+ }
+
+ @Override
+ public final String toString() {
+ return "Table[name=" + getName() + ",type=" + getType() + ",remarks=" + getRemarks() + "]";
+ }
+
+ @Override
+ public int hashCode() {
+ return getName().hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (obj == this) {
+ return true;
+ }
+ if (obj instanceof Table) {
+ final Table other = (Table) obj;
+ if (!getQualifiedLabel().equals(other.getQualifiedLabel())) {
+ return false;
+ }
+ if (getType() != other.getType()) {
+ return false;
+ }
+ final Schema sch1 = getSchema();
+ final Schema sch2 = other.getSchema();
+ if (sch1 != null) {
+ if (!sch1.equals(sch2)) {
+ return false;
+ }
+ } else {
+ if (sch2 != null) {
+ return false;
+ }
+ }
+
+ try {
+ final String[] columnNames1 = getColumnNames();
+ final String[] columnNames2 = other.getColumnNames();
+
+ if (columnNames1 != null && columnNames1.length != 0) {
+ if (columnNames2 != null && columnNames2.length != 0) {
+ if (!Arrays.equals(columnNames1, columnNames2)) {
+ return false;
+ }
+ }
+ }
+ } catch (Exception e) {
+ // going "down stream" may throw exceptions, e.g. due to
+ // de-serialization issues. We will be tolerant to such
+ // exceptions
+ logger.debug("Caught (and ignoring) exception while comparing column names of tables", e);
+ }
+
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public final int compareTo(Table that) {
+ int diff = getQualifiedLabel().compareTo(that.getQualifiedLabel());
+ if (diff == 0) {
+ diff = toString().compareTo(that.toString());
+ }
+ return diff;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/schema/Column.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/Column.java b/core/src/main/java/org/apache/metamodel/schema/Column.java
new file mode 100644
index 0000000..1208368
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/Column.java
@@ -0,0 +1,108 @@
+/**
+ * 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.schema;
+
+import java.io.Serializable;
+
+/**
+ * Represents a column and it's metadata description. Columns reside within a
+ * Table and can be used as keys for relationships between tables.
+ *
+ * @see Table
+ *
+ * @author Kasper Sørensen
+ */
+public interface Column extends Comparable<Column>, Serializable, NamedStructure {
+
+ /**
+ * Gets the name of this Column
+ *
+ * @return the name of this Column
+ */
+ @Override
+ public String getName();
+
+ /**
+ * Returns the column number or index. Note: This column number is 0-based
+ * whereas the JDBC is 1-based.
+ *
+ * @return the number of this column.
+ */
+ public int getColumnNumber();
+
+ /**
+ * Gets the type of the column
+ *
+ * @return this column's type.
+ */
+ public ColumnType getType();
+
+ /**
+ * Gets the table for which this column belong
+ *
+ * @return this column's table.
+ */
+ public Table getTable();
+
+ /**
+ * Determines whether or not this column accepts null values.
+ *
+ * @return true if this column accepts null values, false if not and null if
+ * not known.
+ */
+ public Boolean isNullable();
+
+ /**
+ * Gets any remarks/comments to this column.
+ *
+ * @return any remarks/comments to this column.
+ */
+ public String getRemarks();
+
+ /**
+ * Gets the data type size of this column.
+ *
+ * @return the data type size of this column or null if the size is not
+ * determined or known.
+ */
+ public Integer getColumnSize();
+
+ /**
+ * Gets the native type of this column. A native type is the name of the
+ * data type as defined in the datastore.
+ *
+ * @return the name of the native type.
+ */
+ public String getNativeType();
+
+ /**
+ * Determines if this column is indexed.
+ *
+ * @return true if this column is indexed or false if not (or not known)
+ */
+ public boolean isIndexed();
+
+ /**
+ * Determines if this column is (one of) the primary key(s) of its table.
+ *
+ * @return true if this column is a primary key, or false if not (or if this
+ * is not determinable).
+ */
+ public boolean isPrimaryKey();
+}
\ 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/schema/ColumnType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/ColumnType.java b/core/src/main/java/org/apache/metamodel/schema/ColumnType.java
new file mode 100644
index 0000000..ea938e6
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/ColumnType.java
@@ -0,0 +1,292 @@
+/**
+ * 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.schema;
+
+import static org.eobjects.metamodel.schema.SuperColumnType.BINARY_TYPE;
+import static org.eobjects.metamodel.schema.SuperColumnType.BOOLEAN_TYPE;
+import static org.eobjects.metamodel.schema.SuperColumnType.LITERAL_TYPE;
+import static org.eobjects.metamodel.schema.SuperColumnType.NUMBER_TYPE;
+import static org.eobjects.metamodel.schema.SuperColumnType.OTHER_TYPE;
+import static org.eobjects.metamodel.schema.SuperColumnType.TIME_TYPE;
+
+import java.lang.reflect.Field;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import org.eobjects.metamodel.util.NumberComparator;
+import org.eobjects.metamodel.util.ObjectComparator;
+import org.eobjects.metamodel.util.TimeComparator;
+import org.eobjects.metamodel.util.ToStringComparator;
+
+/**
+ * Represents the data-type of columns. Most of the elements in this enum are
+ * based on the JDBC {@link Types} class, but with a few additions.
+ */
+public enum ColumnType {
+
+ /**
+ * Literal
+ */
+ CHAR(LITERAL_TYPE), VARCHAR(LITERAL_TYPE), LONGVARCHAR(LITERAL_TYPE), CLOB(LITERAL_TYPE), NCHAR(LITERAL_TYPE), NVARCHAR(
+ LITERAL_TYPE), LONGNVARCHAR(LITERAL_TYPE), NCLOB(LITERAL_TYPE),
+
+ /**
+ * Numbers
+ */
+ TINYINT(NUMBER_TYPE), SMALLINT(NUMBER_TYPE), INTEGER(NUMBER_TYPE), BIGINT(NUMBER_TYPE), FLOAT(NUMBER_TYPE), REAL(
+ NUMBER_TYPE), DOUBLE(NUMBER_TYPE), NUMERIC(NUMBER_TYPE), DECIMAL(NUMBER_TYPE),
+
+ /**
+ * Time based
+ */
+ DATE(TIME_TYPE), TIME(TIME_TYPE), TIMESTAMP(TIME_TYPE),
+
+ /**
+ * Booleans
+ */
+ BIT(BOOLEAN_TYPE), BOOLEAN(BOOLEAN_TYPE),
+
+ /**
+ * Binary types
+ */
+ BINARY(BINARY_TYPE), VARBINARY(BINARY_TYPE), LONGVARBINARY(BINARY_TYPE), BLOB(BINARY_TYPE),
+
+ /**
+ * Other types (as defined in {@link Types}).
+ */
+ NULL(OTHER_TYPE), OTHER(OTHER_TYPE), JAVA_OBJECT(OTHER_TYPE), DISTINCT(OTHER_TYPE), STRUCT(OTHER_TYPE), ARRAY(
+ OTHER_TYPE), REF(OTHER_TYPE), DATALINK(OTHER_TYPE), ROWID(OTHER_TYPE), SQLXML(OTHER_TYPE),
+
+ /**
+ * Additional types (added by MetaModel for non-JDBC datastores)
+ */
+ LIST(OTHER_TYPE), MAP(OTHER_TYPE);
+
+ private SuperColumnType _superType;
+
+ private ColumnType(SuperColumnType superType) {
+ if (superType == null) {
+ throw new IllegalArgumentException("SuperColumnType cannot be null");
+ }
+ _superType = superType;
+ }
+
+ public Comparator<Object> getComparator() {
+ if (isTimeBased()) {
+ return TimeComparator.getComparator();
+ }
+ if (isNumber()) {
+ return NumberComparator.getComparator();
+ }
+ if (isLiteral()) {
+ return ToStringComparator.getComparator();
+ }
+ return ObjectComparator.getComparator();
+ }
+
+ public boolean isBoolean() {
+ return _superType == BOOLEAN_TYPE;
+ }
+
+ public boolean isBinary() {
+ return _superType == BINARY_TYPE;
+ }
+
+ public boolean isNumber() {
+ return _superType == NUMBER_TYPE;
+ }
+
+ public boolean isTimeBased() {
+ return _superType == TIME_TYPE;
+ }
+
+ public boolean isLiteral() {
+ return _superType == LITERAL_TYPE;
+ }
+
+ public boolean isLargeObject() {
+ switch (this) {
+ case BLOB:
+ case CLOB:
+ case NCLOB:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * @return a java class that is appropriate for handling column values of
+ * this column type
+ */
+ public Class<?> getJavaEquivalentClass() {
+ switch (this) {
+ case TINYINT:
+ case SMALLINT:
+ return Short.class;
+ case INTEGER:
+ return Integer.class;
+ case BIGINT:
+ return BigInteger.class;
+ case DECIMAL:
+ case NUMERIC:
+ case FLOAT:
+ case REAL:
+ case DOUBLE:
+ return Double.class;
+ case DATE:
+ case TIME:
+ case TIMESTAMP:
+ return Date.class;
+ case BLOB:
+ return Blob.class;
+ case CLOB:
+ case NCLOB:
+ return Clob.class;
+ case MAP:
+ return Map.class;
+ case LIST:
+ return List.class;
+ default:
+ // All other types have fitting java equivalent classes in the super
+ // type
+ return _superType.getJavaEquivalentClass();
+ }
+ }
+
+ public SuperColumnType getSuperType() {
+ return _superType;
+ }
+
+ /**
+ * Finds the ColumnType enum corresponding to the incoming JDBC
+ * type-constant
+ */
+ public static ColumnType convertColumnType(int jdbcType) {
+ try {
+ Field[] fields = JdbcTypes.class.getFields();
+ // We assume that the JdbcTypes class only consists of constant
+ // integer types, so we make no assertions here
+ for (int i = 0; i < fields.length; i++) {
+ Field field = fields[i];
+ int value = (Integer) field.getInt(null);
+ if (value == jdbcType) {
+ String fieldName = field.getName();
+ ColumnType[] enumConstants = ColumnType.class.getEnumConstants();
+ for (int j = 0; j < enumConstants.length; j++) {
+ ColumnType columnType = enumConstants[j];
+ if (fieldName.equals(columnType.toString())) {
+ return columnType;
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new IllegalStateException("Could not access fields in JdbcTypes", e);
+ }
+ return OTHER;
+ }
+
+ /**
+ * Gets the JDBC type as per the {@link Types} class.
+ *
+ * @return an int representing one of the constants in the {@link Types}
+ * class.
+ * @throws IllegalStateException
+ * in case getting the JDBC type was unsuccesful.
+ */
+ public int getJdbcType() throws IllegalStateException {
+ final String name = this.toString();
+ try {
+ // We assume that the JdbcTypes class only consists of constant
+ // integer types, so we make no assertions here
+ final Field[] fields = JdbcTypes.class.getFields();
+ for (int i = 0; i < fields.length; i++) {
+ Field field = fields[i];
+ String fieldName = field.getName();
+ if (fieldName.equals(name)) {
+ int value = (Integer) field.getInt(null);
+ return value;
+ }
+ }
+ throw new IllegalStateException("No JdbcType found with field name: " + name);
+ } catch (Exception e) {
+ throw new IllegalStateException("Could not access fields in JdbcTypes", e);
+ }
+ }
+
+ /**
+ * Finds the ColumnType enum corresponding to the incoming Java class.
+ *
+ * @param cls
+ * @return
+ */
+ public static ColumnType convertColumnType(Class<?> cls) {
+ if (cls == null) {
+ throw new IllegalArgumentException("Class cannot be null");
+ }
+
+ final ColumnType type;
+ if (cls == String.class) {
+ type = ColumnType.VARCHAR;
+ } else if (cls == Boolean.class || cls == boolean.class) {
+ type = ColumnType.BOOLEAN;
+ } else if (cls == Character.class || cls == char.class || cls == Character[].class || cls == char[].class) {
+ type = ColumnType.CHAR;
+ } else if (cls == Byte.class || cls == byte.class) {
+ type = ColumnType.TINYINT;
+ } else if (cls == Short.class || cls == short.class) {
+ type = ColumnType.SMALLINT;
+ } else if (cls == Integer.class || cls == int.class) {
+ type = ColumnType.INTEGER;
+ } else if (cls == Long.class || cls == long.class || cls == BigInteger.class) {
+ type = ColumnType.BIGINT;
+ } else if (cls == Float.class || cls == float.class) {
+ type = ColumnType.FLOAT;
+ } else if (cls == Double.class || cls == double.class) {
+ type = ColumnType.DOUBLE;
+ } else if (cls == BigDecimal.class) {
+ type = ColumnType.DECIMAL;
+ } else if (Map.class.isAssignableFrom(cls)) {
+ type = ColumnType.MAP;
+ } else if (List.class.isAssignableFrom(cls)) {
+ type = ColumnType.LIST;
+ } else if (cls == java.sql.Date.class) {
+ type = ColumnType.DATE;
+ } else if (cls == Timestamp.class) {
+ type = ColumnType.TIMESTAMP;
+ } else if (cls == Time.class) {
+ type = ColumnType.TIME;
+ } else if (Date.class.isAssignableFrom(cls)) {
+ type = ColumnType.TIMESTAMP;
+ } else {
+ type = ColumnType.OTHER;
+ }
+ return type;
+ }
+}
\ 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/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
new file mode 100644
index 0000000..f4f75e1
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/CompositeSchema.java
@@ -0,0 +1,91 @@
+/**
+ * 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.schema;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.util.CollectionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A composite schema, comprising tables from several {@link DataContext}s.
+ *
+ * @author Kasper Sørensen
+ */
+public class CompositeSchema extends AbstractSchema {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = LoggerFactory.getLogger(CompositeSchema.class);
+
+ private final String name;
+ private final Collection<? extends Schema> delegates;
+
+ public CompositeSchema(String name, Collection<? extends Schema> delegates) {
+ super();
+ this.name = name;
+ this.delegates = delegates;
+ if (logger.isWarnEnabled()) {
+ Set<String> names = new HashSet<String>();
+ for (Table table : getTables()) {
+ if (names.contains(table.getName())) {
+ logger.warn("Name-clash detected for Table {}.", table.getName());
+ logger.warn("getTableByName(\"{}\") will return just the first table.", table.getName());
+ } else {
+ names.add(table.getName());
+ }
+ }
+ if (!names.isEmpty()) {
+ logger.warn("The following table names clashes in composite schema: " + names);
+ }
+ }
+ }
+
+ @Override
+ public Relationship[] getRelationships() {
+ Relationship[] result = new Relationship[0];
+ for (Schema delegate : delegates) {
+ result = CollectionUtils.array(result, delegate.getRelationships());
+ }
+ return result;
+ }
+
+ @Override
+ public Table[] getTables() {
+ Table[] result = new Table[0];
+ for (Schema delegate : delegates) {
+ result = CollectionUtils.array(result, delegate.getTables());
+ }
+ return result;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getQuote() {
+ return null;
+ }
+}
\ 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/schema/ImmutableColumn.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/ImmutableColumn.java b/core/src/main/java/org/apache/metamodel/schema/ImmutableColumn.java
new file mode 100644
index 0000000..3236c00
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/ImmutableColumn.java
@@ -0,0 +1,173 @@
+/**
+ * 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.schema;
+
+import java.io.Serializable;
+
+/**
+ * Immutable implementation of the Column interface.
+ *
+ * It is not intended to be instantiated on it's own. Rather, use the
+ * constructor in ImmutableSchema.
+ *
+ * @see ImmutableSchema
+ *
+ * @author Kasper Sørensen
+ */
+public final class ImmutableColumn extends AbstractColumn implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private final int columnNumber;
+ private final ColumnType type;
+ private final Table table;
+ private final Boolean nullable;
+ private final String remarks;
+ private final Integer columnSize;
+ private final String nativeType;
+ private final boolean indexed;
+ private final boolean primaryKey;
+ private final String name;
+ private final String quote;
+
+ /**
+ * Constructs a new {@link ImmutableColumn}.
+ *
+ * @param name
+ * the name of the column
+ * @param type
+ * the type of the column
+ * @param table
+ * the table which the constructed column will pertain to
+ * @param columnNumber
+ * the column number of the column
+ * @param columnSize
+ * the size of the column
+ * @param nativeType
+ * the native type of the column
+ * @param nullable
+ * whether the column's values are nullable
+ * @param remarks
+ * the remarks of the column
+ * @param indexed
+ * whether the column is indexed or not
+ * @param quote
+ * the quote character(s) of the column
+ * @param primaryKey
+ * whether the column is a primary key or not
+ */
+ public ImmutableColumn(String name, ColumnType type, Table table, int columnNumber, Integer columnSize,
+ String nativeType, Boolean nullable, String remarks, boolean indexed, String quote, boolean primaryKey) {
+ this.name = name;
+ this.type = type;
+ this.table = table;
+ this.columnNumber = columnNumber;
+ this.columnSize = columnSize;
+ this.nativeType = nativeType;
+ this.nullable = nullable;
+ this.remarks = remarks;
+ this.indexed = indexed;
+ this.quote = quote;
+ this.primaryKey = primaryKey;
+ }
+
+ /**
+ * Constructs an {@link ImmutableColumn} based on an existing column and a
+ * table.
+ *
+ * @param column
+ * the column to immitate
+ * @param table
+ * the table that the constructed column will pertain to
+ */
+ public ImmutableColumn(Column column, Table table) {
+ this.name = column.getName();
+ this.type = column.getType();
+ this.table = table;
+ this.columnNumber = column.getColumnNumber();
+ this.columnSize = column.getColumnSize();
+ this.nativeType = column.getNativeType();
+ this.nullable = column.isNullable();
+ this.remarks = column.getRemarks();
+ this.indexed = column.isIndexed();
+ this.quote = column.getQuote();
+ this.primaryKey = column.isPrimaryKey();
+ }
+
+ protected ImmutableColumn(Column column, ImmutableTable table) {
+ this(column.getName(), column.getType(), table, column.getColumnNumber(), column.getColumnSize(), column
+ .getNativeType(), column.isNullable(), column.getRemarks(), column.isIndexed(), column.getQuote(),
+ column.isPrimaryKey());
+ }
+
+ @Override
+ public int getColumnNumber() {
+ return columnNumber;
+ }
+
+ @Override
+ public ColumnType getType() {
+ return type;
+ }
+
+ @Override
+ public Table getTable() {
+ return table;
+ }
+
+ @Override
+ public Boolean isNullable() {
+ return nullable;
+ }
+
+ @Override
+ public String getRemarks() {
+ return remarks;
+ }
+
+ @Override
+ public Integer getColumnSize() {
+ return columnSize;
+ }
+
+ @Override
+ public String getNativeType() {
+ return nativeType;
+ }
+
+ @Override
+ public boolean isIndexed() {
+ return indexed;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public boolean isPrimaryKey() {
+ return primaryKey;
+ }
+
+ @Override
+ public String getQuote() {
+ return quote;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/schema/ImmutableRelationship.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/ImmutableRelationship.java b/core/src/main/java/org/apache/metamodel/schema/ImmutableRelationship.java
new file mode 100644
index 0000000..43f2cf0
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/ImmutableRelationship.java
@@ -0,0 +1,82 @@
+/**
+ * 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.schema;
+
+import java.io.Serializable;
+
+public final class ImmutableRelationship extends AbstractRelationship implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private final Column[] primaryColumns;
+ private final Column[] foreignColumns;
+
+ public static void create(Relationship origRelationship,
+ ImmutableSchema schema) {
+ ImmutableTable primaryTable = getSimilarTable(
+ origRelationship.getPrimaryTable(), schema);
+ assert primaryTable != null;
+ Column[] primaryColumns = getSimilarColumns(
+ origRelationship.getPrimaryColumns(), primaryTable);
+ checkSameTable(primaryColumns);
+
+ ImmutableTable foreignTable = getSimilarTable(
+ origRelationship.getForeignTable(), schema);
+ assert foreignTable != null;
+ Column[] foreignColumns = getSimilarColumns(
+ origRelationship.getForeignColumns(), foreignTable);
+ checkSameTable(foreignColumns);
+
+ ImmutableRelationship relationship = new ImmutableRelationship(
+ primaryColumns, foreignColumns);
+ primaryTable.addRelationship(relationship);
+ foreignTable.addRelationship(relationship);
+ }
+
+ private static Column[] getSimilarColumns(Column[] columns, Table table) {
+ Column[] result = new Column[columns.length];
+ for (int i = 0; i < columns.length; i++) {
+ String name = columns[i].getName();
+ result[i] = table.getColumnByName(name);
+ }
+ return result;
+ }
+
+ private static ImmutableTable getSimilarTable(Table table,
+ ImmutableSchema schema) {
+ String name = table.getName();
+ return (ImmutableTable) schema.getTableByName(name);
+ }
+
+ private ImmutableRelationship(Column[] primaryColumns,
+ Column[] foreignColumns) {
+ this.primaryColumns = primaryColumns;
+ this.foreignColumns = foreignColumns;
+ }
+
+ @Override
+ public Column[] getPrimaryColumns() {
+ return primaryColumns;
+ }
+
+ @Override
+ public Column[] getForeignColumns() {
+ return foreignColumns;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/schema/ImmutableSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/ImmutableSchema.java b/core/src/main/java/org/apache/metamodel/schema/ImmutableSchema.java
new file mode 100644
index 0000000..8ac8a79
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/ImmutableSchema.java
@@ -0,0 +1,72 @@
+/**
+ * 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.schema;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * An immutable implementation of the {@link Schema} interface.
+ *
+ * @author Kasper Sørensen
+ */
+public final class ImmutableSchema extends AbstractSchema implements
+ Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private final List<ImmutableTable> tables = new ArrayList<ImmutableTable>();
+ private String name;
+ private String quote;
+
+ private ImmutableSchema(String name, String quote) {
+ super();
+ this.name = name;
+ this.quote = quote;
+ }
+
+ public ImmutableSchema(Schema schema) {
+ this(schema.getName(), schema.getQuote());
+ Table[] origTables = schema.getTables();
+ for (Table table : origTables) {
+ tables.add(new ImmutableTable(table, this));
+ }
+
+ Relationship[] origRelationships = schema.getRelationships();
+ for (Relationship relationship : origRelationships) {
+ ImmutableRelationship.create(relationship, this);
+ }
+ }
+
+ @Override
+ public Table[] getTables() {
+ return tables.toArray(new Table[tables.size()]);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getQuote() {
+ return quote;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/schema/ImmutableTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/ImmutableTable.java b/core/src/main/java/org/apache/metamodel/schema/ImmutableTable.java
new file mode 100644
index 0000000..a4d6d81
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/ImmutableTable.java
@@ -0,0 +1,106 @@
+/**
+ * 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.schema;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * An immutable implementation of the Table interface.
+ *
+ * It is not intended to be instantiated on it's own. Rather, use the
+ * constructor in ImmutableSchema.
+ *
+ * @see ImmutableSchema
+ *
+ * @author Kasper Sørensen
+ */
+final class ImmutableTable extends AbstractTable implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private final List<ImmutableColumn> columns = new ArrayList<ImmutableColumn>();
+ private final List<ImmutableRelationship> relationships = new ArrayList<ImmutableRelationship>();
+ private final ImmutableSchema schema;
+ private final TableType type;
+ private final String remarks;
+ private final String name;
+ private final String quote;
+
+ protected ImmutableTable(String name, TableType type, ImmutableSchema schema,
+ String remarks, String quote) {
+ this.name = name;
+ this.type = type;
+ this.schema = schema;
+ this.remarks = remarks;
+ this.quote = quote;
+ }
+
+ protected ImmutableTable(Table table, ImmutableSchema schema) {
+ this(table.getName(), table.getType(), schema, table.getRemarks(),
+ table.getQuote());
+ Column[] origColumns = table.getColumns();
+ for (Column column : origColumns) {
+ columns.add(new ImmutableColumn(column, this));
+ }
+ }
+
+ protected void addRelationship(ImmutableRelationship relationship) {
+ if (!relationships.contains(relationship)) {
+ relationships.add(relationship);
+ }
+ }
+
+ @Override
+ public Column[] getColumns() {
+ return columns.toArray(new Column[columns.size()]);
+ }
+
+ @Override
+ public Schema getSchema() {
+ return schema;
+ }
+
+ @Override
+ public TableType getType() {
+ return type;
+ }
+
+ @Override
+ public Relationship[] getRelationships() {
+ return relationships.toArray(new Relationship[relationships.size()]);
+ }
+
+ @Override
+ public String getRemarks() {
+ return remarks;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getQuote() {
+ return quote;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/schema/JdbcTypes.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/JdbcTypes.java b/core/src/main/java/org/apache/metamodel/schema/JdbcTypes.java
new file mode 100644
index 0000000..4531921
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/JdbcTypes.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.schema;
+
+/**
+ * This is a copy of the content (comments removed) of Java 6.0's
+ * java.sql.Types. It is backwards compatible with older versions, but have
+ * additional types (confirmed by JavaTypesTest). It is being used to convert
+ * JDBC types to ColumnType enumerations.
+ */
+final class JdbcTypes {
+
+ // Prevent instantiation
+ private JdbcTypes() {
+ }
+
+ public final static int BIT = -7;
+ public final static int TINYINT = -6;
+ public final static int SMALLINT = 5;
+ public final static int INTEGER = 4;
+ public final static int BIGINT = -5;
+ public final static int FLOAT = 6;
+ public final static int REAL = 7;
+ public final static int DOUBLE = 8;
+ public final static int NUMERIC = 2;
+ public final static int DECIMAL = 3;
+ public final static int CHAR = 1;
+ public final static int VARCHAR = 12;
+ public final static int LONGVARCHAR = -1;
+ public final static int DATE = 91;
+ public final static int TIME = 92;
+ public final static int TIMESTAMP = 93;
+ public final static int BINARY = -2;
+ public final static int VARBINARY = -3;
+ public final static int LONGVARBINARY = -4;
+ public final static int NULL = 0;
+ public final static int OTHER = 1111;
+ public final static int JAVA_OBJECT = 2000;
+ public final static int DISTINCT = 2001;
+ public final static int STRUCT = 2002;
+ public final static int ARRAY = 2003;
+ public final static int BLOB = 2004;
+ public final static int CLOB = 2005;
+ public final static int REF = 2006;
+ public final static int DATALINK = 70;
+ public final static int BOOLEAN = 16;
+ public final static int ROWID = -8;
+ public static final int NCHAR = -15;
+ public static final int NVARCHAR = -9;
+ public static final int LONGNVARCHAR = -16;
+ public static final int NCLOB = 2011;
+ public static final int SQLXML = 2009;
+}
\ 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/schema/MutableColumn.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/MutableColumn.java b/core/src/main/java/org/apache/metamodel/schema/MutableColumn.java
new file mode 100644
index 0000000..d4c464d
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/MutableColumn.java
@@ -0,0 +1,185 @@
+/**
+ * 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.schema;
+
+import java.io.Serializable;
+
+/**
+ * Represents a column and it's metadata description. Columns reside within a
+ * Table and can be used as keys for relationships between tables.
+ *
+ * @see MutableTable
+ * @see Relationship
+ */
+public class MutableColumn extends AbstractColumn implements Serializable {
+
+ private static final long serialVersionUID = -353183696233890927L;
+ private int _columnNumber;
+ private String _name;
+ private ColumnType _type;
+ private Table _table;
+ private Boolean _nullable = null;
+ private String _remarks;
+ private boolean _indexed = false;
+ private boolean _primaryKey = false;
+ private Integer _columnSize = null;
+ private String _nativeType = null;
+ private String _quoteString = null;
+
+ public MutableColumn() {
+ super();
+ }
+
+ public MutableColumn(String name) {
+ this();
+ setName(name);
+ }
+
+ public MutableColumn(String name, ColumnType type) {
+ this(name);
+ setType(type);
+ }
+
+ public MutableColumn(String name, ColumnType type, Table table, int columnNumber, Boolean nullable) {
+ this(name, type);
+ setColumnNumber(columnNumber);
+ setTable(table);
+ setNullable(nullable);
+ }
+
+ public MutableColumn(String name, ColumnType type, Table table, int columnNumber, Integer columnSize,
+ String nativeType, Boolean nullable, String remarks, boolean indexed, String quote) {
+ this(name, type, table, columnNumber, nullable);
+ setColumnSize(columnSize);
+ setNativeType(nativeType);
+ setRemarks(remarks);
+ setIndexed(indexed);
+ setQuote(quote);
+ }
+
+ @Override
+ public int getColumnNumber() {
+ return _columnNumber;
+ }
+
+ public MutableColumn setColumnNumber(int columnNumber) {
+ _columnNumber = columnNumber;
+ return this;
+ }
+
+ @Override
+ public String getName() {
+ return _name;
+ }
+
+ public MutableColumn setName(String name) {
+ _name = name;
+ return this;
+ }
+
+ @Override
+ public ColumnType getType() {
+ return _type;
+ }
+
+ public MutableColumn setType(ColumnType type) {
+ _type = type;
+ return this;
+ }
+
+ @Override
+ public Table getTable() {
+ return _table;
+ }
+
+ public MutableColumn setTable(Table table) {
+ _table = table;
+ return this;
+ }
+
+ @Override
+ public Boolean isNullable() {
+ return _nullable;
+ }
+
+ public MutableColumn setNullable(Boolean nullable) {
+ _nullable = nullable;
+ return this;
+ }
+
+ @Override
+ public String getRemarks() {
+ return _remarks;
+ }
+
+ public MutableColumn setRemarks(String remarks) {
+ _remarks = remarks;
+ return this;
+ }
+
+ @Override
+ public Integer getColumnSize() {
+ return _columnSize;
+ }
+
+ public MutableColumn setColumnSize(Integer columnSize) {
+ _columnSize = columnSize;
+ return this;
+ }
+
+ @Override
+ public String getNativeType() {
+ return _nativeType;
+ }
+
+ public MutableColumn setNativeType(String nativeType) {
+ _nativeType = nativeType;
+ return this;
+ }
+
+ @Override
+ public boolean isIndexed() {
+ return _indexed;
+ }
+
+ public MutableColumn setIndexed(boolean indexed) {
+ _indexed = indexed;
+ return this;
+ }
+
+ @Override
+ public String getQuote() {
+ return _quoteString;
+ }
+
+ public MutableColumn setQuote(String quoteString) {
+ _quoteString = quoteString;
+ return this;
+ }
+
+ @Override
+ public boolean isPrimaryKey() {
+ return _primaryKey;
+ }
+
+ public MutableColumn setPrimaryKey(boolean primaryKey) {
+ _primaryKey = primaryKey;
+ return 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/schema/MutableRelationship.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/MutableRelationship.java b/core/src/main/java/org/apache/metamodel/schema/MutableRelationship.java
new file mode 100644
index 0000000..8762222
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/MutableRelationship.java
@@ -0,0 +1,132 @@
+/**
+ * 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.schema;
+
+import java.io.Serializable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Immutable implementation of the Relationship interface.
+ *
+ * The immutability help ensure integrity of object-relationships. To create
+ * relationsips use the <code>createRelationship</code> method.
+ *
+ * @author Kasper Sørensen
+ */
+public class MutableRelationship extends AbstractRelationship implements
+ Serializable, Relationship {
+
+ private static final long serialVersionUID = 238786848828528822L;
+ private static final Logger logger = LoggerFactory
+ .getLogger(MutableRelationship.class);
+
+ private final Column[] _primaryColumns;
+ private final Column[] _foreignColumns;
+
+ /**
+ * Factory method to create relations between two tables by specifying which
+ * columns from the tables that enforce the relationship.
+ *
+ * @param primaryColumns
+ * the columns from the primary key table
+ * @param foreignColumns
+ * the columns from the foreign key table
+ * @return the relation created
+ */
+ public static Relationship createRelationship(Column[] primaryColumns,
+ Column[] foreignColumns) {
+ Table primaryTable = checkSameTable(primaryColumns);
+ Table foreignTable = checkSameTable(foreignColumns);
+ MutableRelationship relation = new MutableRelationship(primaryColumns,
+ foreignColumns);
+
+ if (primaryTable instanceof MutableTable) {
+ try {
+ ((MutableTable) primaryTable).addRelationship(relation);
+ } catch (UnsupportedOperationException e) {
+ // this is an allowed behaviour - not all tables need to support
+ // this method.
+ logger.debug(
+ "primary table ({}) threw exception when adding relationship",
+ primaryTable);
+ }
+
+ // Ticket #144: Some tables have relations with them selves and then
+ // the
+ // relationship should only be added once.
+ if (foreignTable != primaryTable
+ && foreignTable instanceof MutableTable) {
+ try {
+ ((MutableTable) foreignTable).addRelationship(relation);
+ } catch (UnsupportedOperationException e) {
+ // this is an allowed behaviour - not all tables need to
+ // support this method.
+ logger.debug(
+ "foreign table ({}) threw exception when adding relationship",
+ foreignTable);
+ }
+ }
+ }
+ return relation;
+ }
+
+ public void remove() {
+ Table primaryTable = getPrimaryTable();
+ if (primaryTable instanceof MutableTable) {
+ ((MutableTable) primaryTable).removeRelationship(this);
+ }
+ Table foreignTable = getForeignTable();
+ if (foreignTable instanceof MutableTable) {
+ ((MutableTable) foreignTable).removeRelationship(this);
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ remove();
+ }
+
+ public static Relationship createRelationship(Column primaryColumn,
+ Column foreignColumn) {
+ return createRelationship(new Column[] { primaryColumn },
+ new Column[] { foreignColumn });
+ }
+
+ /**
+ * Prevent external instantiation
+ */
+ private MutableRelationship(Column[] primaryColumns, Column[] foreignColumns) {
+ _primaryColumns = primaryColumns;
+ _foreignColumns = foreignColumns;
+ }
+
+ @Override
+ public Column[] getPrimaryColumns() {
+ return _primaryColumns;
+ }
+
+ @Override
+ public Column[] getForeignColumns() {
+ return _foreignColumns;
+ }
+
+}
\ 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/schema/MutableSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/MutableSchema.java b/core/src/main/java/org/apache/metamodel/schema/MutableSchema.java
new file mode 100644
index 0000000..71d05d2
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/MutableSchema.java
@@ -0,0 +1,106 @@
+/**
+ * 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.schema;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Represents a schema and it's metadata. Schemas represent a collection of
+ * tables.
+ *
+ * @see Table
+ */
+public class MutableSchema extends AbstractSchema implements Serializable,
+ Schema {
+
+ private static final long serialVersionUID = 4465197783868238863L;
+
+ private String _name;
+ private final List<MutableTable> _tables;
+
+ public MutableSchema() {
+ super();
+ _tables = new ArrayList<MutableTable>();
+ }
+
+ public MutableSchema(String name) {
+ this();
+ _name = name;
+ }
+
+ public MutableSchema(String name, MutableTable... tables) {
+ this(name);
+ setTables(tables);
+ }
+
+ @Override
+ public String getName() {
+ return _name;
+ }
+
+ public MutableSchema setName(String name) {
+ _name = name;
+ return this;
+ }
+
+ @Override
+ public MutableTable[] getTables() {
+ MutableTable[] array = new MutableTable[_tables.size()];
+ return _tables.toArray(array);
+ }
+
+ public MutableSchema setTables(Collection<? extends MutableTable> tables) {
+ clearTables();
+ for (MutableTable table : tables) {
+ _tables.add(table);
+ }
+ return this;
+ }
+
+ public MutableSchema setTables(MutableTable... tables) {
+ clearTables();
+ for (MutableTable table : tables) {
+ _tables.add(table);
+ }
+ return this;
+ }
+
+ public MutableSchema clearTables() {
+ _tables.clear();
+ return this;
+ }
+
+ public MutableSchema addTable(MutableTable table) {
+ _tables.add(table);
+ return this;
+ }
+
+ public MutableSchema removeTable(Table table) {
+ _tables.remove(table);
+ return this;
+ }
+
+ @Override
+ public String getQuote() {
+ return null;
+ }
+}
\ No newline at end of file
[02/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/test/integrationtests/org/eobjects/metamodel/OracleTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/eobjects/metamodel/OracleTest.java b/jdbc/src/test/integrationtests/org/eobjects/metamodel/OracleTest.java
deleted file mode 100644
index 4717873..0000000
--- a/jdbc/src/test/integrationtests/org/eobjects/metamodel/OracleTest.java
+++ /dev/null
@@ -1,222 +0,0 @@
-package org.eobjects.metamodel;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.util.Arrays;
-
-import javax.swing.table.TableModel;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetTableModel;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.JoinType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.schema.TableType;
-
-/**
- * Test case that tests oracle interaction. An express edition of the oracle
- * database can be used to run these tests.
- *
- * The test requires the "human resources" schema that is provided ass a sample
- * schema for Oracle default installations.
- *
- * The script for installing it can be found in:
- *
- * <pre>
- * $ORACLE_HOME / demo / schema / human_resources / hr_main.sql
- * </pre>
- *
- * Install with something like:
- *
- * <pre>
- * $ORACLE_HOME/bin/sqlplus -S "/ as sysdba" @hr_main.sql
- * </pre>
- *
- * The JDBC driver is not available in the Maven repository so you will have to
- * download and attach it to the eclipse project yourself.
- *
- * @see http://www.oracle.com/technology/products/bi/samples
- * @see http
- * ://www.oracle.com/technology/software/products/database/xe/index.html
- */
-public class OracleTest extends TestCase {
-
- private static final String CONNECTION_STRING = "jdbc:oracle:thin:@localhost:1521:XE";
- private static final String USERNAME = "HR";
- private static final String PASSWORD = "eobjects";
- private Connection _connection;
- private DataContext _dataContext;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- Class.forName("oracle.jdbc.OracleDriver");
- _connection = DriverManager.getConnection(CONNECTION_STRING, USERNAME,
- PASSWORD);
- _connection.setReadOnly(true);
- _dataContext = new JdbcDataContext(_connection);
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- _connection.close();
- }
-
- /**
- * Ticket #170: getIndexInfo causes SQLException. We test that resultsets
- * are closed properly.
- */
- public void testIndexInfo() throws Exception {
- Schema schema = new JdbcDataContext(_connection,
- new TableType[] { TableType.TABLE }, null)
- .getSchemaByName("SYS");
- assertEquals(12, schema.getTableCount());
- }
-
- public void testGetSchemaNames() throws Exception {
- DataContext dc = new JdbcDataContext(_connection);
- String[] schemaNames = dc.getSchemaNames();
-
- String concatSchemas = Arrays.toString(schemaNames);
-
- // In order to allow the database to be used for other purposes than
- // this integration test, we will not make an exact assertion as to
- // which schema names exist, but just assert that HR and the default
- // oracle schemas exist.
- assertTrue(concatSchemas.indexOf("foobar_schema_that_does_not_exist") == -1);
- assertTrue(concatSchemas.indexOf("HR") != -1);
- assertTrue(concatSchemas.indexOf("SYSTEM") != -1);
- assertTrue(concatSchemas.indexOf("XDB") != -1);
- assertTrue(schemaNames.length > 8);
-
- Schema schema = dc.getDefaultSchema();
- assertEquals("HR", schema.getName());
- }
-
- /**
- * Really only tests the JDBC implementation, used to help localize the
- * cause for Ticket #144
- */
- public void testGetImportedKeys() throws Exception {
- ResultSet rs = _connection.getMetaData().getImportedKeys(null, "HR",
- "EMPLOYEES");
- int count = 0;
- while (rs.next()) {
- count++;
- assertEquals("HR", rs.getString(2));
- String pkTableName = rs.getString(3);
- String pkColumnName = rs.getString(4);
- String fkTableName = rs.getString(7);
- assertEquals("EMPLOYEES", fkTableName);
- String fkColumnName = rs.getString(8);
- System.out.println("Found primary key relation: pkTableName="
- + pkTableName + ",pkColumnName=" + pkColumnName
- + ",fkTableName=" + fkTableName + ",fkColumnName="
- + fkColumnName);
- }
- rs.close();
- assertEquals(3, count);
-
- rs = _connection.getMetaData().getImportedKeys(null, "HR",
- "DEPARTMENTS");
- count = 0;
- while (rs.next()) {
- count++;
- assertEquals("HR", rs.getString(2));
- String pkTableName = rs.getString(3);
- String pkColumnName = rs.getString(4);
- String fkTableName = rs.getString(7);
- assertEquals("DEPARTMENTS", fkTableName);
- String fkColumnName = rs.getString(8);
- System.out.println("Found primary key relation: pkTableName="
- + pkTableName + ",pkColumnName=" + pkColumnName
- + ",fkTableName=" + fkTableName + ",fkColumnName="
- + fkColumnName);
- }
- rs.close();
- assertEquals(2, count);
- }
-
- public void testGetSchema() throws Exception {
- Schema schema = _dataContext.getSchemaByName("HR");
- assertNotNull(schema);
- assertEquals(
- "{JdbcTable[name=COUNTRIES,type=TABLE,remarks=<null>],"
- + "JdbcTable[name=DEPARTMENTS,type=TABLE,remarks=<null>]"
- + ",JdbcTable[name=EMPLOYEES,type=TABLE,remarks=<null>]"
- + ",JdbcTable[name=JOBS,type=TABLE,remarks=<null>]"
- + ",JdbcTable[name=JOB_HISTORY,type=TABLE,remarks=<null>]"
- + ",JdbcTable[name=LOCATIONS,type=TABLE,remarks=<null>]"
- + ",JdbcTable[name=REGIONS,type=TABLE,remarks=<null>]"
- + ",JdbcTable[name=EMP_DETAILS_VIEW,type=VIEW,remarks=<null>]}",
- Arrays.toString(schema.getTables()));
-
- Relationship[] employeeRelationships = schema.getTableByName(
- "EMPLOYEES").getRelationships();
- assertEquals(
- "{Relationship[primaryTable=EMPLOYEES,primaryColumns={EMPLOYEE_ID},foreignTable=DEPARTMENTS,foreignColumns={MANAGER_ID}],"
- + "Relationship[primaryTable=DEPARTMENTS,primaryColumns={DEPARTMENT_ID},foreignTable=EMPLOYEES,foreignColumns={DEPARTMENT_ID}],"
- + "Relationship[primaryTable=EMPLOYEES,primaryColumns={EMPLOYEE_ID},foreignTable=EMPLOYEES,foreignColumns={MANAGER_ID}],"
- + "Relationship[primaryTable=JOBS,primaryColumns={JOB_ID},foreignTable=EMPLOYEES,foreignColumns={JOB_ID}],"
- + "Relationship[primaryTable=EMPLOYEES,primaryColumns={EMPLOYEE_ID},foreignTable=JOB_HISTORY,foreignColumns={EMPLOYEE_ID}]}",
- Arrays.toString(employeeRelationships));
-
- assertEquals(
- "{JdbcColumn[name=EMPLOYEE_ID,columnNumber=0,type=DECIMAL,nullable=false,nativeType=NUMBER,columnSize=6],"
- + "JdbcColumn[name=FIRST_NAME,columnNumber=1,type=VARCHAR,nullable=true,nativeType=VARCHAR2,columnSize=20],"
- + "JdbcColumn[name=LAST_NAME,columnNumber=2,type=VARCHAR,nullable=false,nativeType=VARCHAR2,columnSize=25],"
- + "JdbcColumn[name=EMAIL,columnNumber=3,type=VARCHAR,nullable=false,nativeType=VARCHAR2,columnSize=25],"
- + "JdbcColumn[name=PHONE_NUMBER,columnNumber=4,type=VARCHAR,nullable=true,nativeType=VARCHAR2,columnSize=20],"
- + "JdbcColumn[name=HIRE_DATE,columnNumber=5,type=DATE,nullable=false,nativeType=DATE,columnSize=7],"
- + "JdbcColumn[name=JOB_ID,columnNumber=6,type=VARCHAR,nullable=false,nativeType=VARCHAR2,columnSize=10],"
- + "JdbcColumn[name=SALARY,columnNumber=7,type=DECIMAL,nullable=true,nativeType=NUMBER,columnSize=8],"
- + "JdbcColumn[name=COMMISSION_PCT,columnNumber=8,type=DECIMAL,nullable=true,nativeType=NUMBER,columnSize=2],"
- + "JdbcColumn[name=MANAGER_ID,columnNumber=9,type=DECIMAL,nullable=true,nativeType=NUMBER,columnSize=6],"
- + "JdbcColumn[name=DEPARTMENT_ID,columnNumber=10,type=DECIMAL,nullable=true,nativeType=NUMBER,columnSize=4]}",
- Arrays.toString(schema.getTableByName("EMPLOYEES").getColumns()));
-
- assertEquals(
- "{JdbcColumn[name=DEPARTMENT_ID,columnNumber=0,type=DECIMAL,nullable=false,nativeType=NUMBER,columnSize=4],"
- + "JdbcColumn[name=DEPARTMENT_NAME,columnNumber=1,type=VARCHAR,nullable=false,nativeType=VARCHAR2,columnSize=30],"
- + "JdbcColumn[name=MANAGER_ID,columnNumber=2,type=DECIMAL,nullable=true,nativeType=NUMBER,columnSize=6],"
- + "JdbcColumn[name=LOCATION_ID,columnNumber=3,type=DECIMAL,nullable=true,nativeType=NUMBER,columnSize=4]}",
- Arrays.toString(schema.getTableByName("DEPARTMENTS")
- .getColumns()));
- }
-
- public void testExecuteQuery() throws Exception {
- Schema schema = _dataContext.getSchemaByName("HR");
- Table employeeTable = schema.getTableByName("EMPLOYEES");
- Table departmentsTable = schema.getTableByName("DEPARTMENTS");
- Relationship relationship = employeeTable
- .getRelationships(departmentsTable)[0];
- assertEquals(
- "Relationship[primaryTable=EMPLOYEES,primaryColumns={EMPLOYEE_ID},foreignTable=DEPARTMENTS,foreignColumns={MANAGER_ID}]",
- relationship.toString());
-
- Query q = new Query().from(new FromItem(JoinType.INNER, relationship))
- .select(employeeTable.getColumnByName("EMAIL"),
- departmentsTable.getColumnByName("DEPARTMENT_NAME"));
- q.getSelectClause().getItem(0).setAlias("e-mail");
-
- assertEquals(
- "SELECT \"EMPLOYEES\".\"EMAIL\" AS e-mail, \"DEPARTMENTS\".\"DEPARTMENT_NAME\" FROM HR.\"EMPLOYEES\" INNER JOIN HR.\"DEPARTMENTS\" ON \"EMPLOYEES\".\"EMPLOYEE_ID\" = \"DEPARTMENTS\".\"MANAGER_ID\"",
- q.toString());
-
- DataSet data = _dataContext.executeQuery(q);
- assertNotNull(data);
- TableModel tableModel = new DataSetTableModel(data);
- assertEquals(2, tableModel.getColumnCount());
- assertEquals(11, tableModel.getRowCount());
- assertEquals("JWHALEN", tableModel.getValueAt(0, 0).toString());
- assertEquals("Administration", tableModel.getValueAt(0, 1).toString());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/test/integrationtests/org/eobjects/metamodel/PostgresqlTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/eobjects/metamodel/PostgresqlTest.java b/jdbc/src/test/integrationtests/org/eobjects/metamodel/PostgresqlTest.java
deleted file mode 100644
index 9c8cf34..0000000
--- a/jdbc/src/test/integrationtests/org/eobjects/metamodel/PostgresqlTest.java
+++ /dev/null
@@ -1,810 +0,0 @@
-package org.eobjects.metamodel;
-
-import java.lang.reflect.Method;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.DriverManager;
-import java.util.Arrays;
-import java.util.List;
-
-import javax.swing.table.TableModel;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetTableModel;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.jdbc.JdbcTestTemplates;
-import org.eobjects.metamodel.jdbc.QuerySplitter;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.OrderByItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.junit.Ignore;
-
-/**
- * Test case that tests postgresql interaction. The test requires the
- * "dellstore2" sample database that can be found at pgfoundry.
- *
- * @see http://pgfoundry.org/projects/dbsamples/
- */
-public class PostgresqlTest extends TestCase {
-
- private static final String CONNECTION_STRING = "jdbc:postgresql://localhost/dellstore2";
- private static final String USERNAME = "eobjects";
- private static final String PASSWORD = "eobjects";
- private Connection _connection;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- Class.forName("org.postgresql.Driver");
- _connection = DriverManager.getConnection(CONNECTION_STRING, USERNAME, PASSWORD);
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- _connection.close();
- }
-
- public void testInterpretationOfNull() throws Exception {
- JdbcTestTemplates.interpretationOfNulls(_connection);
- }
-
- private JdbcDataContext createLimitAndOffsetTestData() {
- final JdbcDataContext dc = new JdbcDataContext(_connection);
-
- if (dc.getTableByQualifiedLabel("test_table") != null) {
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.dropTable("test_table").execute();
- }
- });
- }
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- Table table = callback.createTable(dc.getDefaultSchema(), "test_table").withColumn("foo")
- .ofType(ColumnType.INTEGER).withColumn("bar").ofType(ColumnType.VARCHAR).execute();
- callback.insertInto(table).value("foo", 1).value("bar", "hello").execute();
- callback.insertInto(table).value("foo", 2).value("bar", "there").execute();
- callback.insertInto(table).value("foo", 3).value("bar", "world").execute();
- }
- });
-
- dc.refreshSchemas();
-
- return dc;
- }
-
- public void testLimit() throws Exception {
- JdbcDataContext dc = createLimitAndOffsetTestData();
- Schema schema = dc.getDefaultSchema();
- Table productsTable = schema.getTableByName("test_table");
-
- DataSet ds = dc.query().from(productsTable).select("foo").limit(2).execute();
- assertTrue(ds.next());
- assertEquals("Row[values=[1]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[2]]", ds.getRow().toString());
- assertFalse(ds.next());
- ds.close();
- }
-
- public void testOffset() throws Exception {
- JdbcDataContext dc = createLimitAndOffsetTestData();
- Schema schema = dc.getDefaultSchema();
- Table productsTable = schema.getTableByName("test_table");
-
- DataSet ds = dc.query().from(productsTable).select("foo").offset(1).execute();
- assertTrue(ds.next());
- assertEquals("Row[values=[2]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[3]]", ds.getRow().toString());
- assertFalse(ds.next());
- ds.close();
- }
-
- public void testLimitAndOffset() throws Exception {
- JdbcDataContext dc = createLimitAndOffsetTestData();
- Schema schema = dc.getDefaultSchema();
- Table productsTable = schema.getTableByName("test_table");
-
- DataSet ds = dc.query().from(productsTable).select("foo").limit(1).offset(1).execute();
- assertTrue(ds.next());
- assertEquals("Row[values=[2]]", ds.getRow().toString());
- assertFalse(ds.next());
-
- ds.close();
- }
-
- public void testQuotedInsertSyntax() throws Exception {
- try {
- _connection.createStatement().execute("DROP TABLE my_table");
- } catch (Exception e) {
- // do nothing
- }
-
- JdbcDataContext dc = new JdbcDataContext(_connection);
- final Schema schema = dc.getDefaultSchema();
-
- // create table
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- Table table = cb.createTable(schema, "my_table").withColumn("id").asPrimaryKey()
- .ofType(ColumnType.INTEGER).ofNativeType("SERIAL").nullable(false).withColumn("name")
- .ofType(ColumnType.VARCHAR).ofSize(10).withColumn("foo").ofType(ColumnType.BOOLEAN)
- .nullable(true).withColumn("bar").ofType(ColumnType.BOOLEAN).nullable(true).execute();
-
- assertEquals("my_table", table.getName());
- }
- });
-
- assertTrue(dc.getColumnByQualifiedLabel("my_table.id").isPrimaryKey());
- assertFalse(dc.getColumnByQualifiedLabel("my_table.name").isPrimaryKey());
-
- // insert records
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- RowInsertionBuilder builder = callback.insertInto("my_table").value("name", "row 1").value("foo", true);
-
- try {
- Method method = builder.getClass().getDeclaredMethod("createSqlStatement");
- method.setAccessible(true);
- Object result = method.invoke(builder);
- assertEquals("INSERT INTO \"public\".\"my_table\" (name,foo) VALUES (?,?)", result.toString());
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-
- builder.execute();
-
- callback.insertInto("my_table").value("name", "row 2").value("foo", false).execute();
- }
- });
-
- // query
- DataSet ds = dc.query().from("my_table").select("name").where("foo").eq(true).execute();
- assertTrue(ds.next());
- assertEquals("Row[values=[row 1]]", ds.getRow().toString());
- assertFalse(ds.next());
- ds.close();
-
- // drop
- dc.executeUpdate(new UpdateScript() {
-
- @Override
- public void run(UpdateCallback callback) {
- callback.dropTable("my_table").execute();
- }
- });
- }
-
- public void testInsertOfDifferentTypes() throws Exception {
- try {
- _connection.createStatement().execute("DROP TABLE my_table");
- } catch (Exception e) {
- // do nothing
- }
-
- JdbcDataContext dc = new JdbcDataContext(_connection);
- final Schema schema = dc.getDefaultSchema();
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- Table table = cb.createTable(schema, "my_table").withColumn("id").ofType(ColumnType.INTEGER)
- .ofNativeType("SERIAL").nullable(false).withColumn("name").ofType(ColumnType.VARCHAR)
- .ofSize(10).withColumn("foo").ofType(ColumnType.BOOLEAN).nullable(true).withColumn("bar")
- .ofType(ColumnType.BOOLEAN).nullable(true).execute();
-
- assertEquals("my_table", table.getName());
- }
- });
-
- try {
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.insertInto("my_table").value("name", "row 1").value("foo", true).execute();
-
- callback.insertInto("my_table").value("name", "row 2").value("bar", true).execute();
-
- callback.insertInto("my_table").value("name", "row 3").value("foo", true).execute();
-
- callback.insertInto("my_table").value("name", "row 4").value("foo", true).execute();
-
- callback.insertInto("my_table").value("name", "row 5").value("bar", true).execute();
-
- callback.insertInto("my_table").value("name", "row 6").value("foo", true).value("bar", true)
- .execute();
-
- callback.insertInto("my_table").value("name", "row 7").value("foo", true).value("bar", true)
- .execute();
-
- callback.insertInto("my_table").value("name", "row 8").value("foo", false).value("bar", false)
- .execute();
- }
- });
-
- DataSet ds = dc.query().from("my_table").select("id").and("name").execute();
- assertTrue(ds.next());
- assertEquals("Row[values=[1, row 1]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[2, row 2]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[3, row 3]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[4, row 4]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[5, row 5]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[6, row 6]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[7, row 7]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[8, row 8]]", ds.getRow().toString());
- assertFalse(ds.next());
- ds.close();
- } finally {
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.dropTable("my_table").execute();
- }
- });
- }
- }
-
- /**
- * Tests some inconsistencies dealing with booleans.
- *
- * @see http://eobjects.org/trac/ticket/829
- */
- public void testBoolean() throws Exception {
- JdbcDataContext dc = new JdbcDataContext(_connection);
-
- final Schema schema = dc.getDefaultSchema();
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- Table table = cb.createTable(schema, "my_table").withColumn("id").ofType(ColumnType.INTEGER)
- .ofNativeType("SERIAL").nullable(false).withColumn("some_bool").ofType(ColumnType.BOOLEAN)
- .nullable(false).execute();
- assertEquals("my_table", table.getName());
-
- cb.insertInto(table).value("id", 1).value("some_bool", true).execute();
- cb.insertInto(table).value("id", 2).value("some_bool", false).execute();
- }
- });
-
- DataSet ds = dc.query().from("my_table").select("some_bool").execute();
-
- assertTrue(ds.next());
- assertEquals("Row[values=[true]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[false]]", ds.getRow().toString());
- assertFalse(ds.next());
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- cb.dropTable("my_table").execute();
- }
- });
- }
-
- public void testBlob() throws Exception {
- JdbcDataContext dc = new JdbcDataContext(_connection);
- final Schema schema = dc.getDefaultSchema();
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- Table table = cb.createTable(schema, "my_table").withColumn("id").ofType(ColumnType.INTEGER)
- .ofNativeType("SERIAL").nullable(false).withColumn("some_bytes").ofType(ColumnType.BLOB)
- .execute();
- assertEquals("my_table", table.getName());
- }
- });
-
- try {
- dc.refreshSchemas();
- final Column column = dc.getColumnByQualifiedLabel("my_table.some_bytes");
- assertEquals("Column[name=some_bytes,columnNumber=1,type=BINARY,nullable=true,"
- + "nativeType=bytea,columnSize=2147483647]", column.toString());
-
- final Table table = column.getTable();
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.insertInto(table).value(column, new byte[] { 1, 2, 3 }).execute();
- callback.insertInto(table).value(column, "hello world".getBytes()).execute();
- }
- });
-
- byte[] bytes;
-
- DataSet ds = dc.query().from(table).select(table.getColumns()).execute();
-
- assertTrue(ds.next());
- assertEquals(1, ds.getRow().getValue(0));
- bytes = (byte[]) ds.getRow().getValue(1);
- assertEquals(3, bytes.length);
- assertEquals(1, bytes[0]);
- assertEquals(2, bytes[1]);
- assertEquals(3, bytes[2]);
-
- assertTrue(ds.next());
- assertEquals(2, ds.getRow().getValue(0));
- bytes = (byte[]) ds.getRow().getValue(1);
-
- assertEquals("hello world", new String(bytes));
- assertFalse(ds.next());
-
- } finally {
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- cb.dropTable("my_table").execute();
- }
- });
- }
- }
-
- public void testCreateTableAndWriteRecords() throws Exception {
- JdbcDataContext dc = new JdbcDataContext(_connection);
- final Schema schema = dc.getDefaultSchema();
- try {
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- Table table = cb.createTable(schema, "my_table").withColumn("id").ofType(ColumnType.INTEGER)
- .ofNativeType("SERIAL").nullable(false).withColumn("person name").ofSize(255)
- .withColumn("age").ofType(ColumnType.INTEGER).execute();
- assertEquals("[id, person name, age]", Arrays.toString(table.getColumnNames()));
- assertEquals(
- "Column[name=id,columnNumber=0,type=INTEGER,nullable=false,nativeType=serial,columnSize=10]",
- table.getColumnByName("id").toString());
- assertEquals(
- "Column[name=person name,columnNumber=1,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=255]",
- table.getColumnByName("person name").toString());
- assertEquals(
- "Column[name=age,columnNumber=2,type=INTEGER,nullable=true,nativeType=int4,columnSize=10]",
- table.getColumnByName("age").toString());
-
- cb.insertInto(table).value("person name", "John Doe").value("age", 42).execute();
- cb.insertInto(table).value("age", 43).value("person name", "Jane Doe").execute();
-
- }
- });
-
- final Table table = schema.getTableByName("my_table");
- Query query = dc.query().from(table).select(table.getColumns()).toQuery();
- DataSet ds = dc.executeQuery(query);
- assertTrue(ds.next());
- assertEquals("Row[values=[1, John Doe, 42]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[2, Jane Doe, 43]]", ds.getRow().toString());
- assertFalse(ds.next());
- ds.close();
-
- dc.executeUpdate(new UpdateScript() {
-
- @Override
- public void run(UpdateCallback callback) {
- callback.update(table).value("age", 102).where("id").eq(1).execute();
- callback.deleteFrom(table).where("id").eq(2).execute();
- }
- });
-
- ds = dc.executeQuery(query);
- assertTrue(ds.next());
- assertEquals("Row[values=[1, John Doe, 102]]", ds.getRow().toString());
- assertFalse(ds.next());
- ds.close();
- } finally {
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.dropTable("my_table").execute();
- }
- });
- assertNull(dc.getTableByQualifiedLabel("my_table"));
- }
- }
-
- public void testCreateTableInsertValueFloatForIntColumn() throws Exception {
- JdbcDataContext dc = new JdbcDataContext(_connection);
- final Schema schema = dc.getDefaultSchema();
- try {
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- Table table = cb.createTable(schema, "my_table").withColumn("id").ofType(ColumnType.INTEGER)
- .ofNativeType("SERIAL").nullable(false).withColumn("person name").ofSize(255)
- .withColumn("age").ofType(ColumnType.INTEGER).execute();
- assertEquals("[id, person name, age]", Arrays.toString(table.getColumnNames()));
- assertEquals(
- "Column[name=id,columnNumber=0,type=INTEGER,nullable=false,nativeType=serial,columnSize=10]",
- table.getColumnByName("id").toString());
- assertEquals(
- "Column[name=person name,columnNumber=1,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=255]",
- table.getColumnByName("person name").toString());
- assertEquals(
- "Column[name=age,columnNumber=2,type=INTEGER,nullable=true,nativeType=int4,columnSize=10]",
- table.getColumnByName("age").toString());
-
- cb.insertInto(table).value("person name", "John Doe").value("age", 42.4673).execute();
- cb.insertInto(table).value("age", 43.5673).value("person name", "Jane Doe").execute();
- }
- });
-
- Table table = schema.getTableByName("my_table");
- Query query = dc.query().from(table).select(table.getColumns()).toQuery();
- DataSet ds = dc.executeQuery(query);
- assertTrue(ds.next());
- // Float value input will be rounded down into integer number.
- assertEquals("Row[values=[1, John Doe, 42]]", ds.getRow().toString());
- assertTrue(ds.next());
- // The age will be incremented as float value input will be rounded
- // up.
- assertEquals("Row[values=[2, Jane Doe, 44]]", ds.getRow().toString());
- assertFalse(ds.next());
-
- ds.close();
- } finally {
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- cb.dropTable("my_table").execute();
- }
- });
- }
- }
-
- public void testInsertFailureForStringValueForIntegerColumn() throws Exception {
- JdbcDataContext dc = new JdbcDataContext(_connection);
- final Schema schema = dc.getDefaultSchema();
- try {
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- Table table = cb.createTable(schema, "my_table").withColumn("id").ofType(ColumnType.INTEGER)
- .ofNativeType("SERIAL").nullable(false).withColumn("person name").ofSize(255)
- .withColumn("age").ofType(ColumnType.INTEGER).execute();
- assertEquals("[id, person name, age]", Arrays.toString(table.getColumnNames()));
- assertEquals(
- "Column[name=id,columnNumber=0,type=INTEGER,nullable=false,nativeType=serial,columnSize=10]",
- table.getColumnByName("id").toString());
- assertEquals(
- "Column[name=person name,columnNumber=1,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=255]",
- table.getColumnByName("person name").toString());
- assertEquals(
- "Column[name=age,columnNumber=2,type=INTEGER,nullable=true,nativeType=int4,columnSize=10]",
- table.getColumnByName("age").toString());
-
- cb.insertInto(table).value("person name", "John Doe").value("age", "42").execute();
- }
- });
-
- } catch (Exception e) {
- assertEquals(
- "Could not execute batch: INSERT INTO \"public\".\"my_table\" (\"person name\",age) VALUES ('John Doe','42'): Batch entry 0 INSERT INTO \"public\".\"my_table\" (\"person name\",age) VALUES ('John Doe','42') was aborted. Call getNextException to see the cause.",
- e.getMessage());
- } finally {
- dc.refreshSchemas();
- if (dc.getTableByQualifiedLabel("my_table") != null) {
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- cb.dropTable("my_table").execute();
- }
- });
- }
- }
- }
-
- public void testDatabaseProductName() throws Exception {
- String databaseProductName = _connection.getMetaData().getDatabaseProductName();
- assertEquals(JdbcDataContext.DATABASE_PRODUCT_POSTGRESQL, databaseProductName);
- }
-
- public void testGetDefaultSchema() throws Exception {
- DataContext dc = new JdbcDataContext(_connection);
- Schema schema = dc.getDefaultSchema();
- assertEquals("public", schema.getName());
- }
-
- public void testGetSchema() throws Exception {
- DataContext dc = new JdbcDataContext(_connection);
- Schema[] schemas = dc.getSchemas();
- assertTrue(schemas.length >= 3);
-
- assertNotNull(dc.getSchemaByName("information_schema"));
- assertNotNull(dc.getSchemaByName("pg_catalog"));
- assertNotNull(dc.getSchemaByName("public"));
-
- Schema schema = dc.getSchemaByName("public");
-
- assertEquals("[Table[name=categories,type=TABLE,remarks=null], "
- + "Table[name=cust_hist,type=TABLE,remarks=null], " + "Table[name=customers,type=TABLE,remarks=null], "
- + "Table[name=inventory,type=TABLE,remarks=null], "
- + "Table[name=orderlines,type=TABLE,remarks=null], " + "Table[name=orders,type=TABLE,remarks=null], "
- + "Table[name=products,type=TABLE,remarks=null], " + "Table[name=reorder,type=TABLE,remarks=null]]",
- Arrays.toString(schema.getTables()));
-
- Table productsTable = schema.getTableByName("products");
- assertEquals(
- "[Column[name=prod_id,columnNumber=0,type=INTEGER,nullable=false,nativeType=serial,columnSize=10], "
- + "Column[name=category,columnNumber=1,type=INTEGER,nullable=false,nativeType=int4,columnSize=10], "
- + "Column[name=title,columnNumber=2,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
- + "Column[name=actor,columnNumber=3,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
- + "Column[name=price,columnNumber=4,type=NUMERIC,nullable=false,nativeType=numeric,columnSize=12], "
- + "Column[name=special,columnNumber=5,type=SMALLINT,nullable=true,nativeType=int2,columnSize=5], "
- + "Column[name=common_prod_id,columnNumber=6,type=INTEGER,nullable=false,nativeType=int4,columnSize=10]]",
- Arrays.toString(productsTable.getColumns()));
- Table customersTable = schema.getTableByName("customers");
- assertEquals(
- "[Column[name=customerid,columnNumber=0,type=INTEGER,nullable=false,nativeType=serial,columnSize=10], "
- + "Column[name=firstname,columnNumber=1,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
- + "Column[name=lastname,columnNumber=2,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
- + "Column[name=address1,columnNumber=3,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
- + "Column[name=address2,columnNumber=4,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=50], "
- + "Column[name=city,columnNumber=5,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
- + "Column[name=state,columnNumber=6,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=50], "
- + "Column[name=zip,columnNumber=7,type=INTEGER,nullable=true,nativeType=int4,columnSize=10], "
- + "Column[name=country,columnNumber=8,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
- + "Column[name=region,columnNumber=9,type=SMALLINT,nullable=false,nativeType=int2,columnSize=5], "
- + "Column[name=email,columnNumber=10,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=50], "
- + "Column[name=phone,columnNumber=11,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=50], "
- + "Column[name=creditcardtype,columnNumber=12,type=INTEGER,nullable=false,nativeType=int4,columnSize=10], "
- + "Column[name=creditcard,columnNumber=13,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
- + "Column[name=creditcardexpiration,columnNumber=14,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
- + "Column[name=username,columnNumber=15,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
- + "Column[name=password,columnNumber=16,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
- + "Column[name=age,columnNumber=17,type=SMALLINT,nullable=true,nativeType=int2,columnSize=5], "
- + "Column[name=income,columnNumber=18,type=INTEGER,nullable=true,nativeType=int4,columnSize=10], "
- + "Column[name=gender,columnNumber=19,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=1]]",
- Arrays.toString(customersTable.getColumns()));
- Relationship[] relations = customersTable.getRelationships();
- assertEquals(2, relations.length);
- assertEquals(
- "[Relationship[primaryTable=customers,primaryColumns=[customerid],foreignTable=cust_hist,foreignColumns=[customerid]], "
- + "Relationship[primaryTable=customers,primaryColumns=[customerid],foreignTable=orders,foreignColumns=[customerid]]]",
- Arrays.toString(relations));
- assertEquals("Table[name=customers,type=TABLE,remarks=null]", relations[0].getPrimaryTable().toString());
- assertEquals("Table[name=cust_hist,type=TABLE,remarks=null]", relations[0].getForeignTable().toString());
- assertEquals("Table[name=customers,type=TABLE,remarks=null]", relations[1].getPrimaryTable().toString());
- assertEquals("Table[name=orders,type=TABLE,remarks=null]", relations[1].getForeignTable().toString());
-
- Table ordersTable = schema.getTableByName("orderlines");
- assertEquals(
- "[Column[name=orderlineid,columnNumber=0,type=INTEGER,nullable=false,nativeType=int4,columnSize=10], "
- + "Column[name=orderid,columnNumber=1,type=INTEGER,nullable=false,nativeType=int4,columnSize=10], "
- + "Column[name=prod_id,columnNumber=2,type=INTEGER,nullable=false,nativeType=int4,columnSize=10], "
- + "Column[name=quantity,columnNumber=3,type=SMALLINT,nullable=false,nativeType=int2,columnSize=5], "
- + "Column[name=orderdate,columnNumber=4,type=DATE,nullable=false,nativeType=date,columnSize=13]]",
- Arrays.toString(ordersTable.getColumns()));
- }
-
- public void testExecuteQueryInPublicSchema() throws Exception {
- DataContext dc = new JdbcDataContext(_connection);
- Query q = new Query();
- Schema schema = dc.getSchemaByName("public");
- Table productsTable = schema.getTableByName("products");
- q.from(productsTable);
-
- Column titleColumn = productsTable.getColumnByName("title");
- Column productPriceColumn = productsTable.getColumnByName("price");
- q.select(titleColumn, productPriceColumn);
- q.getSelectClause().getItem(0).setAlias("product-title");
-
- DataSet data = dc.executeQuery(q);
- TableModel tableModel = new DataSetTableModel(data);
- assertEquals(2, tableModel.getColumnCount());
- assertEquals(10000, tableModel.getRowCount());
-
- assertEquals("ACADEMY ACADEMY", tableModel.getValueAt(0, 0).toString());
- assertEquals("25.99", tableModel.getValueAt(0, 1).toString());
-
- assertEquals("ACADEMY HORN", tableModel.getValueAt(432, 0).toString());
- assertEquals("16.99", tableModel.getValueAt(6346, 1).toString());
-
- assertEquals("ALADDIN ZORRO", tableModel.getValueAt(9999, 0).toString());
- assertEquals("10.99", tableModel.getValueAt(9999, 1).toString());
-
- data = null;
- tableModel = null;
-
- Column prodIdColumn = productsTable.getColumnByName("prod_id");
- Table orderlinesTable = schema.getTableByName("orderlines");
- Column commonProdIdColumn = orderlinesTable.getColumnByName("prod_id");
- Column quantityColumn = orderlinesTable.getColumnByName("quantity");
-
- q.from(orderlinesTable);
- q.where(new FilterItem(new SelectItem(prodIdColumn), OperatorType.EQUALS_TO, new SelectItem(commonProdIdColumn)));
- q.groupBy(titleColumn);
- q.getSelectClause().removeItem(q.getSelectClause().getSelectItem(productPriceColumn));
- SelectItem quantitySum = new SelectItem(FunctionType.SUM, quantityColumn).setAlias("orderAmount");
- q.select(quantitySum);
- q.having(new FilterItem(quantitySum, OperatorType.GREATER_THAN, 25));
- q.orderBy(new OrderByItem(q.getSelectClause().getItem(0)));
-
- assertEquals("SELECT \"products\".\"title\" AS product-title, SUM(\"orderlines\".\"quantity\") AS orderAmount "
- + "FROM public.\"products\", public.\"orderlines\" "
- + "WHERE \"products\".\"prod_id\" = \"orderlines\".\"prod_id\" " + "GROUP BY \"products\".\"title\" "
- + "HAVING SUM(\"orderlines\".\"quantity\") > 25 " + "ORDER BY \"products\".\"title\" ASC", q.toString());
- data = dc.executeQuery(q);
- tableModel = new DataSetTableModel(data);
- assertEquals(2, tableModel.getColumnCount());
- assertEquals(136, tableModel.getRowCount());
-
- assertEquals("ACADEMY ALABAMA", tableModel.getValueAt(0, 0).toString());
- assertEquals("27", tableModel.getValueAt(0, 1).toString());
-
- assertEquals("AIRPORT MOURNING", tableModel.getValueAt(99, 0).toString());
- assertEquals("29", tableModel.getValueAt(99, 1).toString());
-
- assertEquals("ALADDIN WORKER", tableModel.getValueAt(135, 0).toString());
- assertEquals("27", tableModel.getValueAt(135, 1).toString());
- }
-
- public void testWhiteSpaceColumns() throws Exception {
- DatabaseMetaData metaData = _connection.getMetaData();
- assertEquals("\"", metaData.getIdentifierQuoteString());
- }
-
- public void testCreateTableAndInsert1MRecords() throws Exception {
- JdbcDataContext dc = new JdbcDataContext(_connection);
- final Schema schema = dc.getDefaultSchema();
- try {
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- Table table = cb.createTable(schema, "my_table").withColumn("id").ofType(ColumnType.INTEGER)
- .ofNativeType("SERIAL").nullable(false).withColumn("person name").ofSize(255)
- .withColumn("age").ofType(ColumnType.INTEGER).execute();
- assertEquals("[id, person name, age]", Arrays.toString(table.getColumnNames()));
- assertEquals(
- "Column[name=id,columnNumber=0,type=INTEGER,nullable=false,nativeType=serial,columnSize=10]",
- table.getColumnByName("id").toString());
- assertEquals(
- "Column[name=person name,columnNumber=1,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=255]",
- table.getColumnByName("person name").toString());
- assertEquals(
- "Column[name=age,columnNumber=2,type=INTEGER,nullable=true,nativeType=int4,columnSize=10]",
- table.getColumnByName("age").toString());
-
- for (int i = 0; i < 1000000; i++) {
- cb.insertInto(table).value("person name", "John Doe").value("age", i + 10).execute();
- }
-
- }
- });
-
- Table table = schema.getTableByName("my_table");
- Query query = dc.query().from(table).selectCount().toQuery();
- DataSet ds = dc.executeQuery(query);
- assertTrue(ds.next());
- assertEquals("Row[values=[1000000]]", ds.getRow().toString());
- assertFalse(ds.next());
- ds.close();
- } finally {
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- cb.dropTable("my_table").execute();
- }
- });
- }
- }
-
- public void testCharOfSizeOne() throws Exception {
- JdbcTestTemplates.meaningOfOneSizeChar(_connection);
- }
-
- /**
- * Splits a huge query into 146 pieces and executes them to test that the
- * collective result are equal to the original one in size
- */
- @Ignore
- public void testSplitHugeQueryExecute146() throws Exception {
- DataContext dc = new JdbcDataContext(_connection);
- Query q = new Query();
- Schema schema = dc.getSchemaByName("public");
- Table productsTable = schema.getTableByName("products");
- Table customerTable = schema.getTableByName("customers");
- q.from(productsTable, "p").from(customerTable, "c");
-
- Column titleColumn = productsTable.getColumnByName("title");
- Column priceColumn = productsTable.getColumnByName("price");
- Column cityColumn = customerTable.getColumnByName("city");
- Column ageColumn = customerTable.getColumnByName("age");
- q.select(titleColumn, priceColumn, cityColumn);
-
- q.where(new FilterItem(new SelectItem(priceColumn), OperatorType.GREATER_THAN, 27));
- q.where(new FilterItem(new SelectItem(ageColumn), OperatorType.GREATER_THAN, 55));
-
- assertEquals(
- "SELECT p.\"title\", p.\"price\", c.\"city\" FROM public.\"products\" p, public.\"customers\" c WHERE p.\"price\" > 27 AND c.\"age\" > 55",
- q.toString());
-
- QuerySplitter qs = new QuerySplitter(dc, q);
- qs.setMaxRows(100000);
- assertEquals(14072278, qs.getRowCount());
-
- List<Query> splitQueries = qs.splitQuery();
- assertEquals(146, splitQueries.size());
- assertEquals(
- "SELECT p.\"title\", p.\"price\", c.\"city\" FROM public.\"products\" p, public.\"customers\" c WHERE p.\"price\" > 27 AND c.\"age\" > 55 AND (c.\"customerid\" < 143 OR c.\"customerid\" IS NULL) AND (p.\"category\" < 8 OR p.\"category\" IS NULL)",
- splitQueries.get(0).toString());
- assertEquals(
- "SELECT p.\"title\", p.\"price\", c.\"city\" FROM public.\"products\" p, public.\"customers\" c WHERE p.\"price\" > 27 AND c.\"age\" > 55 AND (c.\"customerid\" > 19739 OR c.\"customerid\" = 19739)",
- splitQueries.get(145).toString());
-
- assertEquals(
- "[45954, 55752, 52122, 55480, 49770, 53410, 60434, 51590, 97284, 94336, 86966, 76648, 98758, 84018, 98758, 95810, 92862, 91388, 39798, 79596, "
- + "91388, 48642, 60434, 106128, 94336, 94336, 86966, 79596, 85492, 94336, 104654, 97284, 84018, 101706, 109076, 89914, 110550, 107602, 98758, "
- + "112024, 100232, 101706, 95810, 92862, 107602, 100232, 86966, 98758, 106128, 91388, 107602, 104654, 107602, 81070, 114972, 79596, 100232, 97284, "
- + "103180, 98758, 113498, 103180, 89914, 104654, 97284, 109076, 114972, 103180, 86966, 106128, 101706, 95810, 103180, 88440, 112024, 91388, 106128, "
- + "82544, 122342, 98758, 104654, 103180, 104654, 89914, 106128, 88440, 103180, 100232, 98758, 100232, 89914, 101706, 100232, 107602, 88440, 89914, "
- + "91388, 103180, 100232, 104654, 120868, 106128, 100232, 107602, 97284, 103180, 106128, 91388, 100232, 106128, 100232, 109076, 94336, 106128, 94336, "
- + "106128, 104654, 116446, 98758, 113498, 107602, 104654, 107602, 88440, 100232, 92862, 89914, 110550, 109076, 100232, 92862, 100232, 104654, 103180, "
- + "89914, 103180, 103180, 107602, 85492, 112024, 85492, 101706, 92862, 86966, 104654, 201938]",
- Arrays.toString(getCounts(dc, splitQueries)));
- assertSameCount(dc, qs, splitQueries);
-
- DataSet data = qs.executeQueries(splitQueries);
- int count = 0;
- while (data.next()) {
- count++;
- }
- data.close();
- assertEquals(14072278, count);
- System.out.println("Successfully iterated 14072278 rows! :)");
- }
-
- /**
- * Utility method for asserting that a query and it's splitted queries have
- * the same total count
- */
- private void assertSameCount(DataContext dc, QuerySplitter qs, List<Query> queries) {
- long count1 = qs.getRowCount();
- long count2 = 0;
- for (Query q : queries) {
- count2 += getCount(dc, q);
- }
- assertEquals(count1, count2);
- }
-
- public long[] getCounts(DataContext dc, List<Query> queries) {
- long[] result = new long[queries.size()];
- for (int i = 0; i < result.length; i++) {
- result[i] = getCount(dc, queries.get(i));
- }
- return result;
- }
-
- /**
- * Gets the count of a query
- */
- private long getCount(DataContext dc, Query query) {
- return new QuerySplitter(dc, query).getRowCount();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/test/integrationtests/org/eobjects/metamodel/SQLServerJtdsDriverTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/eobjects/metamodel/SQLServerJtdsDriverTest.java b/jdbc/src/test/integrationtests/org/eobjects/metamodel/SQLServerJtdsDriverTest.java
deleted file mode 100644
index a488549..0000000
--- a/jdbc/src/test/integrationtests/org/eobjects/metamodel/SQLServerJtdsDriverTest.java
+++ /dev/null
@@ -1,208 +0,0 @@
-package org.eobjects.metamodel;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.jdbc.JdbcTestTemplates;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.SQLServerQueryRewriter;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.schema.TableType;
-
-/**
- * Test case that tests MS SQL Server interaction. The test uses the
- * "AdventureWorks" sample database which can be downloaded from codeplex.
- *
- * This testcase uses the JTDS driver.
- *
- * @link{http://www.codeplex.com/MSFTDBProdSamples
- * */
-public class SQLServerJtdsDriverTest extends TestCase {
-
- private Connection _connection;
- private String _databaseName = "AdventureWorks";
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- Class.forName("net.sourceforge.jtds.jdbc.Driver");
- _connection = DriverManager.getConnection(
- "jdbc:jtds:sqlserver://localhost:1433/AdventureWorks;instance=SQLEXPRESS", "eobjects", "eobjects");
-
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- _connection.close();
- }
-
- public void testWorkingWithDates() throws Exception {
- assertFalse(_connection.isReadOnly());
-
- JdbcDataContext dc = new JdbcDataContext(_connection);
- final Schema schema = dc.getSchemaByName("Person");
-
- JdbcTestTemplates.createInsertAndUpdateDateTypes(dc, schema, "test_table");
- }
-
- public void testAutomaticConversionWhenInsertingString() throws Exception {
- assertNotNull(_connection);
-
- try {
- // clean up, if nescesary
- _connection.createStatement().execute("DROP TABLE Person.test_table");
- } catch (SQLException e) {
- // do nothing
- }
-
- assertFalse(_connection.isReadOnly());
-
- JdbcDataContext dc = new JdbcDataContext(_connection);
- final Schema schema = dc.getSchemaByName("Person");
- assertEquals("Person", schema.getName());
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- Table table = cb.createTable(schema, "test_table").withColumn("id").asPrimaryKey()
- .ofType(ColumnType.INTEGER).withColumn("birthdate").ofType(ColumnType.DATE).execute();
-
- cb.insertInto(table).value("id", "1").execute();
- cb.insertInto(table).value("id", 2).value("birthdate", "2011-12-21").execute();
- }
- });
-
- Table table = schema.getTableByName("test_table");
-
- assertTrue(table.getColumnByName("id").isPrimaryKey());
- assertFalse(table.getColumnByName("birthdate").isPrimaryKey());
-
- // the jdbc driver represents the date as a VARCHAR
- assertEquals(
- "[Column[name=id,columnNumber=0,type=INTEGER,nullable=false,nativeType=int,columnSize=10], "
- + "Column[name=birthdate,columnNumber=1,type=VARCHAR,nullable=true,nativeType=date,columnSize=10]]",
- Arrays.toString(table.getColumns()));
-
- DataSet ds = dc.query().from(table).select("id").and("birthdate").execute();
- assertTrue(ds.next());
- assertEquals("Row[values=[1, null]]", ds.getRow().toString());
- assertEquals("java.lang.Integer", ds.getRow().getValue(0).getClass().getName());
- assertTrue(ds.next());
- assertEquals("Row[values=[2, 2011-12-21]]", ds.getRow().toString());
- assertEquals("java.lang.String", ds.getRow().getValue(1).getClass().getName());
- assertFalse(ds.next());
- ds.close();
-
- _connection.createStatement().execute("DROP TABLE Person.test_table");
- }
-
- public void testQueryUsingExpressions() throws Exception {
- JdbcDataContext strategy = new JdbcDataContext(_connection,
- new TableType[] { TableType.TABLE, TableType.VIEW }, _databaseName);
- Query q = new Query().select("Name").from("Production.Product").where("COlor IS NOT NULL").setMaxRows(5);
- DataSet dataSet = strategy.executeQuery(q);
- assertEquals("[Name]", Arrays.toString(dataSet.getSelectItems()));
- assertTrue(dataSet.next());
- assertEquals("Row[values=[LL Crankarm]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertFalse(dataSet.next());
- }
-
- public void testGetSchemaNormalTableTypes() throws Exception {
- JdbcDataContext dc = new JdbcDataContext(_connection, new TableType[] { TableType.TABLE, TableType.VIEW },
- _databaseName);
- Schema[] schemas = dc.getSchemas();
-
- assertEquals(8, schemas.length);
- assertEquals("Schema[name=HumanResources]", schemas[0].toString());
- assertEquals(13, schemas[0].getTableCount());
- assertEquals("Schema[name=INFORMATION_SCHEMA]", schemas[1].toString());
- assertEquals(20, schemas[1].getTableCount());
- assertEquals("Schema[name=Person]", schemas[2].toString());
- assertEquals(8, schemas[2].getTableCount());
- assertEquals("Schema[name=Production]", schemas[3].toString());
- assertEquals(28, schemas[3].getTableCount());
- assertEquals("Schema[name=Purchasing]", schemas[4].toString());
- assertEquals(8, schemas[4].getTableCount());
- assertEquals("Schema[name=Sales]", schemas[5].toString());
- assertEquals(27, schemas[5].getTableCount());
-
- }
-
- public void testGetSchemaAllTableTypes() throws Exception {
- JdbcDataContext strategy = new JdbcDataContext(_connection, new TableType[] { TableType.OTHER,
- TableType.GLOBAL_TEMPORARY }, _databaseName);
- Schema schema = strategy.getDefaultSchema();
- assertEquals("dbo", schema.getName());
-
- assertEquals("[Sales, HumanResources, dbo, Purchasing, sys, Production, INFORMATION_SCHEMA, Person]",
- Arrays.toString(strategy.getSchemaNames()));
- }
-
- public void testQueryRewriterQuoteAliases() throws Exception {
- JdbcDataContext dc = new JdbcDataContext(_connection, TableType.DEFAULT_TABLE_TYPES, _databaseName);
- IQueryRewriter queryRewriter = dc.getQueryRewriter();
- assertSame(SQLServerQueryRewriter.class, queryRewriter.getClass());
-
- Schema schema = dc.getSchemaByName("Sales");
- Table customersTable = schema.getTableByName("CUSTOMER");
-
- Query q = new Query().from(customersTable, "cus-tomers").select(
- new SelectItem(customersTable.getColumnByName("AccountNumber")).setAlias("c|o|d|e"));
- q.setMaxRows(5);
-
- assertEquals("SELECT cus-tomers.\"AccountNumber\" AS c|o|d|e FROM Sales.\"Customer\" cus-tomers", q.toString());
-
- String queryString = queryRewriter.rewriteQuery(q);
- assertEquals(
- "SELECT TOP 5 \"cus-tomers\".\"AccountNumber\" AS \"c|o|d|e\" FROM Sales.\"Customer\" \"cus-tomers\"",
- queryString);
-
- // We have to test that no additional quoting characters are added every
- // time we run the rewriting
- queryString = queryRewriter.rewriteQuery(q);
- queryString = queryRewriter.rewriteQuery(q);
- assertEquals(
- "SELECT TOP 5 \"cus-tomers\".\"AccountNumber\" AS \"c|o|d|e\" FROM Sales.\"Customer\" \"cus-tomers\"",
- queryString);
-
- // Test that the original query is still the same (ie. it has been
- // cloned for execution)
- assertEquals("SELECT cus-tomers.\"AccountNumber\" AS c|o|d|e FROM Sales.\"Customer\" cus-tomers", q.toString());
-
- DataSet data = dc.executeQuery(q);
- assertNotNull(data);
- data.close();
- }
-
- public void testQuotedString() throws Exception {
- JdbcDataContext dc = new JdbcDataContext(_connection, TableType.DEFAULT_TABLE_TYPES, _databaseName);
- IQueryRewriter queryRewriter = dc.getQueryRewriter();
- assertSame(SQLServerQueryRewriter.class, queryRewriter.getClass());
-
- Query q = dc.query().from("Production", "Product").select("Name").where("Color").eq("R'ed").toQuery();
-
- DataSet ds = dc.executeQuery(q);
- assertNotNull(ds);
- assertFalse(ds.next());
- ds.close();
-
- assertEquals(
- "SELECT Production.\"Product\".\"Name\" FROM Production.\"Product\" WHERE Production.\"Product\".\"Color\" = 'R''ed'",
- queryRewriter.rewriteQuery(q));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/test/integrationtests/org/eobjects/metamodel/SQLServerMicrosoftDriverTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/eobjects/metamodel/SQLServerMicrosoftDriverTest.java b/jdbc/src/test/integrationtests/org/eobjects/metamodel/SQLServerMicrosoftDriverTest.java
deleted file mode 100644
index ee0a664..0000000
--- a/jdbc/src/test/integrationtests/org/eobjects/metamodel/SQLServerMicrosoftDriverTest.java
+++ /dev/null
@@ -1,141 +0,0 @@
-package org.eobjects.metamodel;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
-import org.eobjects.metamodel.jdbc.dialects.SQLServerQueryRewriter;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.schema.TableType;
-
-/**
- * Test case that tests MS SQL Server interaction. The test uses the
- * "AdventureWorks" sample database which can be downloaded from codeplex.
- *
- * This testcase uses the official MS SQL Server driver.
- *
- * @link{http://www.codeplex.com/MSFTDBProdSamples
- * */
-public class SQLServerMicrosoftDriverTest extends TestCase {
-
- private Connection _connection;
- private String _databaseName = "AdventureWorks";
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- _connection = DriverManager.getConnection("jdbc:sqlserver://localhost\\SQLEXPRESS;databaseName="
- + _databaseName, "eobjects", "eobjects");
- _connection.setReadOnly(true);
-
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- _connection.close();
- }
-
- public void testQueryUsingExpressions() throws Exception {
- JdbcDataContext strategy = new JdbcDataContext(_connection,
- new TableType[] { TableType.TABLE, TableType.VIEW }, _databaseName);
- Query q = new Query().select("Name").from("Production.Product").where("COlor IS NOT NULL").setMaxRows(5);
- DataSet dataSet = strategy.executeQuery(q);
- assertEquals("[Name]", Arrays.toString(dataSet.getSelectItems()));
- assertTrue(dataSet.next());
- assertEquals("Row[values=[LL Crankarm]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertFalse(dataSet.next());
- }
-
- public void testGetSchemaNormalTableTypes() throws Exception {
- JdbcDataContext dc = new JdbcDataContext(_connection, new TableType[] { TableType.TABLE, TableType.VIEW },
- _databaseName);
- Schema[] schemas = dc.getSchemas();
-
- assertEquals(8, schemas.length);
- assertEquals("Schema[name=HumanResources]", schemas[0].toString());
- assertEquals(13, schemas[0].getTableCount());
- assertEquals("Schema[name=INFORMATION_SCHEMA]", schemas[1].toString());
- assertEquals(20, schemas[1].getTableCount());
- assertEquals("Schema[name=Person]", schemas[2].toString());
- assertEquals(8, schemas[2].getTableCount());
- assertEquals("Schema[name=Production]", schemas[3].toString());
- assertEquals(28, schemas[3].getTableCount());
- assertEquals("Schema[name=Purchasing]", schemas[4].toString());
- assertEquals(8, schemas[4].getTableCount());
- assertEquals("Schema[name=Sales]", schemas[5].toString());
- assertEquals(27, schemas[5].getTableCount());
-
- }
-
- public void testGetSchemaAllTableTypes() throws Exception {
- JdbcDataContext strategy = new JdbcDataContext(_connection, new TableType[] { TableType.OTHER,
- TableType.GLOBAL_TEMPORARY }, _databaseName);
-
- assertEquals("[Sales, HumanResources, dbo, Purchasing, sys, Production, INFORMATION_SCHEMA, Person]",
- Arrays.toString(strategy.getSchemaNames()));
-
- assertEquals("Schema[name=dbo]", strategy.getDefaultSchema().toString());
- }
-
- public void testQueryRewriterQuoteAliases() throws Exception {
- JdbcDataContext strategy = new JdbcDataContext(_connection, TableType.DEFAULT_TABLE_TYPES, _databaseName);
- IQueryRewriter queryRewriter = strategy.getQueryRewriter();
- assertSame(SQLServerQueryRewriter.class, queryRewriter.getClass());
-
- Schema schema = strategy.getSchemaByName("Sales");
- Table customersTable = schema.getTableByName("CUSTOMER");
-
- Query q = new Query().from(customersTable, "cus-tomers").select(
- new SelectItem(customersTable.getColumnByName("AccountNumber")).setAlias("c|o|d|e"));
- q.setMaxRows(5);
-
- assertEquals("SELECT cus-tomers.\"AccountNumber\" AS c|o|d|e FROM Sales.\"Customer\" cus-tomers", q.toString());
-
- String queryString = queryRewriter.rewriteQuery(q);
- assertEquals(
- "SELECT TOP 5 \"cus-tomers\".\"AccountNumber\" AS \"c|o|d|e\" FROM Sales.\"Customer\" \"cus-tomers\"",
- queryString);
-
- // We have to test that no additional quoting characters are added every
- // time we run the rewriting
- queryString = queryRewriter.rewriteQuery(q);
- queryString = queryRewriter.rewriteQuery(q);
- assertEquals(
- "SELECT TOP 5 \"cus-tomers\".\"AccountNumber\" AS \"c|o|d|e\" FROM Sales.\"Customer\" \"cus-tomers\"",
- queryString);
-
- // Test that the original query is still the same (ie. it has been
- // cloned for execution)
- assertEquals("SELECT cus-tomers.\"AccountNumber\" AS c|o|d|e FROM Sales.\"Customer\" cus-tomers", q.toString());
-
- DataSet data = strategy.executeQuery(q);
- assertNotNull(data);
- data.close();
- }
-
- public void testQuotedString() throws Exception {
- JdbcDataContext dc = new JdbcDataContext(_connection, TableType.DEFAULT_TABLE_TYPES, _databaseName);
- IQueryRewriter queryRewriter = dc.getQueryRewriter();
- assertSame(SQLServerQueryRewriter.class, queryRewriter.getClass());
-
- Query q = dc.query().from("Production", "Product").select("Name").where("Color").eq("R'ed").toQuery();
-
- assertEquals(
- "SELECT \"Product\".\"Name\" FROM Production.\"Product\" Product WHERE Product.\"Color\" = 'R''ed'",
- queryRewriter.rewriteQuery(q));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/test/java/org/apache/metamodel/dbmains/PostgresqlMain.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/dbmains/PostgresqlMain.java b/jdbc/src/test/java/org/apache/metamodel/dbmains/PostgresqlMain.java
new file mode 100644
index 0000000..cc01766
--- /dev/null
+++ b/jdbc/src/test/java/org/apache/metamodel/dbmains/PostgresqlMain.java
@@ -0,0 +1,92 @@
+/**
+ * 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.dbmains;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.jdbc.JdbcDataContext;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+public class PostgresqlMain {
+
+ private static final String CONNECTION_STRING = "jdbc:postgresql://localhost/dellstore2";
+ private static final String USERNAME = "eobjects";
+ private static final String PASSWORD = "eobjects";
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ Connection connection = null;
+ try {
+ Class.forName("org.postgresql.Driver");
+ connection = DriverManager.getConnection(CONNECTION_STRING,
+ USERNAME, PASSWORD);
+
+ JdbcDataContext dc = new JdbcDataContext(connection);
+ final Schema schema = dc.getDefaultSchema();
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ Table table = cb.createTable(schema, "my_table")
+ .withColumn("id").ofType(ColumnType.INTEGER)
+ .ofNativeType("SERIAL").nullable(false)
+ .withColumn("person name").ofSize(255)
+ .withColumn("age").ofType(ColumnType.INTEGER)
+ .execute();
+
+ for (int i = 0; i < 1000000; i++) {
+ cb.insertInto(table).value("person name", "John Doe")
+ .value("age", i + 10).execute();
+ }
+
+ }
+ });
+
+ Table table = schema.getTableByName("my_table");
+ Query query = dc.query().from(table).selectCount().toQuery();
+ DataSet ds = dc.executeQuery(query);
+ ds.close();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (connection != null) {
+ connection.createStatement().execute("DROP TABLE my_table");
+ }
+ } catch (SQLException e) {
+ throw new MetaModelException(
+ "Failed to execute INSERT statement", e);
+ }
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/test/java/org/apache/metamodel/dialects/AbstractQueryRewriterTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/dialects/AbstractQueryRewriterTest.java b/jdbc/src/test/java/org/apache/metamodel/dialects/AbstractQueryRewriterTest.java
new file mode 100644
index 0000000..f880401
--- /dev/null
+++ b/jdbc/src/test/java/org/apache/metamodel/dialects/AbstractQueryRewriterTest.java
@@ -0,0 +1,66 @@
+/**
+ * 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.dialects;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.jdbc.dialects.AbstractQueryRewriter;
+import org.eobjects.metamodel.jdbc.dialects.DefaultQueryRewriter;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.OperatorType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.schema.MutableTable;
+
+public class AbstractQueryRewriterTest extends TestCase {
+
+ public void testRewriteQuery() throws Exception {
+ Query q = new Query().selectCount().from(new MutableTable("foobar"))
+ .where(new MutableColumn("foob"), OperatorType.EQUALS_TO, null).groupBy(new MutableColumn("col1"))
+ .having(new FilterItem(new SelectItem(new MutableColumn("col2")), OperatorType.GREATER_THAN, 40))
+ .orderBy(new MutableColumn("bla"));
+ assertEquals("SELECT COUNT(*) FROM foobar WHERE foob IS NULL GROUP BY col1 HAVING col2 > 40 ORDER BY bla ASC",
+ q.toString());
+
+ AbstractQueryRewriter rewriter = new DefaultQueryRewriter(null) {
+
+ };
+
+ assertEquals("SELECT COUNT(*) FROM foobar WHERE foob IS NULL GROUP BY col1 HAVING col2 > 40 ORDER BY bla ASC",
+ rewriter.rewriteQuery(q));
+
+ rewriter = new DefaultQueryRewriter(null) {
+ @Override
+ protected String rewriteFromItem(Query query, FromItem item) {
+ return "mytable";
+ }
+ };
+
+ assertEquals("SELECT COUNT(*) FROM mytable WHERE foob IS NULL GROUP BY col1 HAVING col2 > 40 ORDER BY bla ASC",
+ rewriter.rewriteQuery(q));
+
+ q.getSelectClause().setDistinct(true);
+
+ assertEquals(
+ "SELECT DISTINCT COUNT(*) FROM mytable WHERE foob IS NULL GROUP BY col1 HAVING col2 > 40 ORDER BY bla ASC",
+ rewriter.rewriteQuery(q));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/test/java/org/apache/metamodel/dialects/DB2QueryRewriterTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/dialects/DB2QueryRewriterTest.java b/jdbc/src/test/java/org/apache/metamodel/dialects/DB2QueryRewriterTest.java
new file mode 100644
index 0000000..c511b7c
--- /dev/null
+++ b/jdbc/src/test/java/org/apache/metamodel/dialects/DB2QueryRewriterTest.java
@@ -0,0 +1,150 @@
+/**
+ * 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.dialects;
+
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.jdbc.dialects.DB2QueryRewriter;
+import org.eobjects.metamodel.query.FunctionType;
+import org.eobjects.metamodel.query.OperatorType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.schema.MutableSchema;
+import org.eobjects.metamodel.schema.MutableTable;
+import org.eobjects.metamodel.schema.TableType;
+
+public class DB2QueryRewriterTest extends TestCase {
+
+ private MutableSchema schema;
+ private MutableTable table;
+ private MutableColumn col;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ schema = new MutableSchema("sch");
+ table = new MutableTable("foo").setSchema(schema);
+ schema.addTable(table);
+ col = new MutableColumn("bar").setTable(table);
+ table.addColumn(col);
+ }
+
+ public void testRewriteMaxRowsNoFirstRow() throws Exception {
+ Query q = new Query().from(table).select(col).setMaxRows(400);
+ String str = new DB2QueryRewriter(null).rewriteQuery(q);
+ assertEquals("SELECT sch.foo.bar FROM sch.foo FETCH FIRST 400 ROWS ONLY", str);
+ }
+
+ public void testRewriteMaxRowsFirstRowIsOne() throws Exception {
+ Query q = new Query().from(table).select(col).setMaxRows(200).setFirstRow(1);
+ String str = new DB2QueryRewriter(null).rewriteQuery(q);
+ assertEquals("SELECT sch.foo.bar FROM sch.foo FETCH FIRST 200 ROWS ONLY", str);
+ }
+
+ public void testRewriteFirstRow() throws Exception {
+ Query q = new Query().from(table).select(col).setFirstRow(401);
+ String str = new DB2QueryRewriter(null).rewriteQuery(q);
+
+ assertEquals(
+ "SELECT metamodel_subquery.bar FROM (SELECT sch.foo.bar, ROW_NUMBER() OVER() AS metamodel_row_number FROM sch.foo) metamodel_subquery WHERE metamodel_row_number > 400",
+ str);
+ }
+
+ public void testRewriteFirstRowAndMaxRows() throws Exception {
+ Query q = new Query().from(table).select(col).setFirstRow(401).setMaxRows(400);
+ String str = new DB2QueryRewriter(null).rewriteQuery(q);
+ assertEquals(
+ "SELECT metamodel_subquery.bar FROM (SELECT sch.foo.bar, ROW_NUMBER() OVER() AS metamodel_row_number FROM sch.foo) metamodel_subquery WHERE metamodel_row_number BETWEEN 401 AND 800",
+ str);
+ }
+
+ public void testRewriteColumnType() throws Exception {
+ assertEquals("SMALLINT", new DB2QueryRewriter(null).rewriteColumnType(ColumnType.BOOLEAN));
+
+ assertEquals("VARCHAR", new DB2QueryRewriter(null).rewriteColumnType(ColumnType.VARCHAR));
+ }
+
+ public void testRewriteSelectItems() throws Exception {
+
+ Query q = new Query().from(table).select(col).where(col, OperatorType.EQUALS_TO, "foob");
+ String queryString = new DB2QueryRewriter(null).rewriteQuery(q);
+ assertEquals("SELECT sch.foo.bar FROM sch.foo WHERE sch.foo.bar = 'foob'", queryString);
+ }
+
+ public void testEscapeFilterItemQuotes() throws Exception {
+ Query q = new Query().from(table).select(col).where(col, OperatorType.EQUALS_TO, "foo'bar");
+ String queryString = new DB2QueryRewriter(null).rewriteQuery(q);
+ assertEquals("SELECT sch.foo.bar FROM sch.foo WHERE sch.foo.bar = 'foo\\'bar'", queryString);
+
+ q = new Query().from(table).select(col)
+ .where(col, OperatorType.IN, Arrays.asList("foo'bar", "foo", "bar", "eobject's"));
+ queryString = new DB2QueryRewriter(null).rewriteQuery(q);
+ assertEquals("SELECT sch.foo.bar FROM sch.foo WHERE sch.foo.bar IN ('foo\\'bar' , 'foo' , 'bar' , 'eobject\\'s')",
+ queryString);
+ }
+
+ public void testFullyQualifiedColumnNames() throws Exception {
+ final MutableSchema schema = new MutableSchema("sch");
+ final MutableTable table = new MutableTable("tab", TableType.TABLE, schema);
+ final MutableColumn nameColumn = new MutableColumn("name", ColumnType.VARCHAR).setTable(table);
+ final MutableColumn ageColumn = new MutableColumn("age", ColumnType.INTEGER).setTable(table);
+ schema.addTable(table);
+ table.addColumn(nameColumn);
+ table.addColumn(ageColumn);
+
+ final Query q = new Query();
+ q.select(ageColumn).selectCount();
+ q.from(table);
+ q.where(ageColumn, OperatorType.GREATER_THAN, 18);
+ q.groupBy(ageColumn);
+ q.having(FunctionType.COUNT, nameColumn, OperatorType.LESS_THAN, 100);
+ q.orderBy(ageColumn);
+
+ final String sql = new DB2QueryRewriter(null).rewriteQuery(q);
+
+ assertEquals("SELECT sch.tab.age, COUNT(*) FROM sch.tab WHERE sch.tab.age > 18 "
+ + "GROUP BY sch.tab.age HAVING COUNT(sch.tab.name) < 100 ORDER BY sch.tab.age ASC", sql);
+ }
+
+ public void testFullyQualifiedColumnNamesWithFilterItemContainingTimestamp() throws Exception {
+ final MutableSchema schema = new MutableSchema("sch");
+ final MutableTable table = new MutableTable("tab", TableType.TABLE, schema);
+ final MutableColumn nameColumn = new MutableColumn("name", ColumnType.VARCHAR).setTable(table);
+ final MutableColumn dateColumn = new MutableColumn("age", ColumnType.TIMESTAMP).setTable(table);
+ schema.addTable(table);
+ table.addColumn(nameColumn);
+ table.addColumn(dateColumn);
+
+ final Query q = new Query();
+ q.select(dateColumn).selectCount();
+ q.from(table);
+ q.where(dateColumn, OperatorType.GREATER_THAN, "2012-10-31 08:09:54");
+ q.groupBy(dateColumn);
+ q.having(FunctionType.COUNT, nameColumn, OperatorType.LESS_THAN, 100);
+ q.orderBy(dateColumn);
+
+ final String sql = new DB2QueryRewriter(null).rewriteQuery(q);
+
+ assertEquals("SELECT sch.tab.age, COUNT(*) FROM sch.tab WHERE sch.tab.age > TIMESTAMP ('2012-10-31 08:09:54') "
+ + "GROUP BY sch.tab.age HAVING COUNT(sch.tab.name) < 100 ORDER BY sch.tab.age ASC", sql);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/test/java/org/apache/metamodel/dialects/MysqlQueryRewriterTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/dialects/MysqlQueryRewriterTest.java b/jdbc/src/test/java/org/apache/metamodel/dialects/MysqlQueryRewriterTest.java
new file mode 100644
index 0000000..c643337
--- /dev/null
+++ b/jdbc/src/test/java/org/apache/metamodel/dialects/MysqlQueryRewriterTest.java
@@ -0,0 +1,46 @@
+/**
+ * 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.dialects;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.jdbc.dialects.MysqlQueryRewriter;
+import org.eobjects.metamodel.query.OperatorType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.schema.MutableTable;
+
+public class MysqlQueryRewriterTest extends TestCase {
+
+ public void testRewriteLimit() throws Exception {
+ Query q = new Query().from(new MutableTable("foo"))
+ .select(new MutableColumn("bar")).setMaxRows(25).setFirstRow(6);
+ String queryString = new MysqlQueryRewriter(null).rewriteQuery(q);
+ assertEquals("SELECT bar FROM foo LIMIT 25 OFFSET 5", queryString);
+ }
+
+ public void testRewriteFilterOperandQuote() throws Exception {
+ MutableColumn col = new MutableColumn("bar");
+ Query q = new Query().from(new MutableTable("foo")).select(col)
+ .where(col, OperatorType.EQUALS_TO, "M'jellow strain'ger");
+ String queryString = new MysqlQueryRewriter(null).rewriteQuery(q);
+ assertEquals("SELECT bar FROM foo WHERE bar = 'M\\'jellow strain\\'ger'",
+ queryString);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/test/java/org/apache/metamodel/dialects/PostgresqlQueryRewriterTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/metamodel/dialects/PostgresqlQueryRewriterTest.java b/jdbc/src/test/java/org/apache/metamodel/dialects/PostgresqlQueryRewriterTest.java
new file mode 100644
index 0000000..1bc8c58
--- /dev/null
+++ b/jdbc/src/test/java/org/apache/metamodel/dialects/PostgresqlQueryRewriterTest.java
@@ -0,0 +1,58 @@
+/**
+ * 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.dialects;
+
+import java.sql.Types;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.jdbc.dialects.PostgresqlQueryRewriter;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.schema.MutableSchema;
+import org.eobjects.metamodel.schema.MutableTable;
+
+public class PostgresqlQueryRewriterTest extends TestCase {
+
+ public void testRewriteLimit() throws Exception {
+ MutableTable table = new MutableTable("foo");
+ table.setSchema(new MutableSchema("MY_SCHEMA"));
+ table.setQuote("\"");
+ MutableColumn column = new MutableColumn("bar");
+ column.setQuote("\"");
+ column.setTable(table);
+ Query q = new Query().from(table).select(column).setMaxRows(25).setFirstRow(5);
+ String queryString = new PostgresqlQueryRewriter(null).rewriteQuery(q);
+ assertEquals("SELECT \"foo\".\"bar\" FROM \"MY_SCHEMA\".\"foo\" LIMIT 25 OFFSET 4", queryString);
+ }
+
+ public void testRewriteFromItem() throws Exception {
+ PostgresqlQueryRewriter rewriter = new PostgresqlQueryRewriter(null);
+
+ assertEquals("\"public\".foo",
+ rewriter.rewriteFromItem(new FromItem(new MutableTable("foo").setSchema(new MutableSchema("public")))));
+ }
+
+ public void testGetColumnType() throws Exception {
+ PostgresqlQueryRewriter rewriter = new PostgresqlQueryRewriter(null);
+ assertEquals(ColumnType.BOOLEAN, rewriter.getColumnType(Types.BIT, "bool", -1));
+ }
+}
\ No newline at end of file
[61/61] git commit: Fixed usage of 'org.eobjects' namespace to
'org.apache' in xml files and site content.
Posted by ka...@apache.org.
Fixed usage of 'org.eobjects' namespace to 'org.apache' in xml files and
site content.
Project: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/commit/660e6936
Tree: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/tree/660e6936
Diff: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/diff/660e6936
Branch: refs/heads/namespace-rename
Commit: 660e69368bd04d10bd3b6c3513e47f0d2b97a532
Parents: 69ad6cd
Author: kaspers <ka...@kaspers-think.humaninference.com>
Authored: Fri Jul 19 11:09:50 2013 +0200
Committer: kaspers <ka...@kaspers-think.humaninference.com>
Committed: Fri Jul 19 11:09:50 2013 +0200
----------------------------------------------------------------------
.../metamodel/jdbc/SplitQueriesDataSet.java | 2 +-
jdbc/src/test/resources/log4j.xml | 40 +-
jdbc/src/test/resources/logconfig.txt | 8 +-
pom.xml | 770 +++++++++----------
src/site/apt/download.apt.vm | 6 +-
src/site/apt/index.apt.vm | 142 ++--
sugarcrm/src/jaxws/binding/bindings.xml | 32 +-
.../com/sugarcrm/ws/soap/Sugarsoap_handler.xml | 18 +-
8 files changed, 509 insertions(+), 509 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/660e6936/jdbc/src/main/java/org/apache/metamodel/jdbc/SplitQueriesDataSet.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/SplitQueriesDataSet.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/SplitQueriesDataSet.java
index b019b35..f9c3697 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/SplitQueriesDataSet.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/SplitQueriesDataSet.java
@@ -36,7 +36,7 @@ import org.apache.metamodel.query.SelectItem;
/**
* DataSet for split queries. Queries will be executed as needed, not at once.
*
- * @see org.eobjects.metamodel.jdbc.QuerySplitter
+ * @see org.apache.metamodel.jdbc.QuerySplitter
*/
final class SplitQueriesDataSet extends AbstractDataSet {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/660e6936/jdbc/src/test/resources/log4j.xml
----------------------------------------------------------------------
diff --git a/jdbc/src/test/resources/log4j.xml b/jdbc/src/test/resources/log4j.xml
index e7d7360..79b98a6 100644
--- a/jdbc/src/test/resources/log4j.xml
+++ b/jdbc/src/test/resources/log4j.xml
@@ -1,21 +1,21 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
-<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
-
- <appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
- <param name="Target" value="System.out" />
- <layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%-5p %d{HH:mm:ss} %c{1} - %m%n" />
- </layout>
- </appender>
-
- <logger name="org.eobjects">
- <level value="debug" />
- </logger>
-
- <root>
- <priority value="warn" />
- <appender-ref ref="consoleAppender" />
- </root>
-
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+ <appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out" />
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%-5p %d{HH:mm:ss} %c{1} - %m%n" />
+ </layout>
+ </appender>
+
+ <logger name="org.apache.metamodel">
+ <level value="debug" />
+ </logger>
+
+ <root>
+ <priority value="warn" />
+ <appender-ref ref="consoleAppender" />
+ </root>
+
</log4j:configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/660e6936/jdbc/src/test/resources/logconfig.txt
----------------------------------------------------------------------
diff --git a/jdbc/src/test/resources/logconfig.txt b/jdbc/src/test/resources/logconfig.txt
index 8f0b0c8..89424cb 100644
--- a/jdbc/src/test/resources/logconfig.txt
+++ b/jdbc/src/test/resources/logconfig.txt
@@ -1,4 +1,4 @@
-handlers = java.util.logging.ConsoleHandler
-.level = WARN
-org.eobjects.ConsoleHandler.level = WARN
-org.eobjects.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
\ No newline at end of file
+handlers = java.util.logging.ConsoleHandler
+.level = WARN
+org.apache.ConsoleHandler.level = WARN
+org.apache.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/660e6936/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 875ad2f..e47fa69 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,385 +1,385 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <sshwagon.version>2.3</sshwagon.version>
- <javadoc.version>2.9</javadoc.version>
- <slf4j.version>1.7.4</slf4j.version>
- <junit.version>4.11</junit.version>
- <easymock.version>3.1</easymock.version>
- <httpcomponents.version>4.2.3</httpcomponents.version>
- <!-- Version printed in the docs -->
- <siteDownloadVersion>${project.version}</siteDownloadVersion>
- </properties>
- <parent>
- <groupId>org.apache</groupId>
- <artifactId>apache</artifactId>
- <version>13</version>
- </parent>
- <scm>
- <url>https://git-wip-us.apache.org/repos/asf?p=incubator-metamodel.git</url>
- </scm>
- <groupId>org.apache.metamodel</groupId>
- <artifactId>MetaModel</artifactId>
- <version>3.4.4-SNAPSHOT</version>
- <name>MetaModel</name>
- <description>MetaModel is a library that encapsulates the differences and enhances
- the capabilities of different datastores. Rich querying abilities are
- offered to datastores that do not otherwise support advanced querying
- and a unified view of the datastore structure is offered through a
- single model of the schemas, tables, columns and relationships.</description>
- <url>http://metamodel.incubator.apache.org</url>
- <inceptionYear>2007</inceptionYear>
- <packaging>pom</packaging>
- <modules>
- <module>core</module>
- <module>pojo</module>
- <module>fixedwidth</module>
- <module>excel</module>
- <module>csv</module>
- <module>xml</module>
- <module>access</module>
- <module>jdbc</module>
- <module>mongodb</module>
- <module>couchdb</module>
- <module>openoffice</module>
- <module>salesforce</module>
- <module>sugarcrm</module>
- <module>full</module>
- </modules>
- <issueManagement>
- <system>Jira</system>
- <url>https://issues.apache.org/jira/browse/METAMODEL</url>
- </issueManagement>
- <mailingLists>
- <mailingList>
- <name>Development</name>
- <post>dev@metamodel.incubator.apache.org</post>
- <subscribe>dev-subscribe@metamodel.incubator.apache.org</subscribe>
- <unsubscribe>dev-unsubscribe@metamodel.incubator.apache.org</unsubscribe>
- <archive>http://mail-archives.apache.org/mod_mbox/incubator-metamodel-dev/</archive>
- </mailingList>
- <mailingList>
- <name>Commits</name>
- <post>commits@metamodel.incubator.apache.org</post>
- <subscribe>commits-subscribe@metamodel.incubator.apache.org</subscribe>
- <unsubscribe>commits-unsubscribe@metamodel.incubator.apache.org</unsubscribe>
- <archive>http://mail-archives.apache.org/mod_mbox/incubator-metamodel-commits/</archive>
- </mailingList>
- </mailingLists>
- <organization>
- <name>The Apache Software Foundation</name>
- <url>http://www.apache.org/</url>
- </organization>
- <developers>
- <developer>
- <id>kasper</id>
- <name>Kasper Sørensen</name>
- <email>kasper.sorensen@humaninference.com</email>
- <url>http://kasper.eobjects.org</url>
- <organization>Human Inference</organization>
- <organizationUrl>http://www.humaninference.com</organizationUrl>
- </developer>
- </developers>
- <contributors>
- <contributor>
- <name>Saurabh Gupta</name>
- <organization>Xebia India</organization>
- </contributor>
- <contributor>
- <name>Balendra Singh</name>
- <organization>Xebia India</organization>
- </contributor>
- <contributor>
- <name>Sameer Arora</name>
- <organization>Xebia India</organization>
- </contributor>
- </contributors>
- <licenses>
- <license>
- <name>The Apache Software License, Version 2.0</name>
- <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
- </license>
- </licenses>
- <build>
- <plugins>
- <plugin>
- <!-- Ensures java 6 compatibility -->
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- <encoding>utf-8</encoding>
- </configuration>
- </plugin>
- <plugin>
- <!-- Ensure inclusion of license header in all main java files -->
- <groupId>com.google.code.maven-license-plugin</groupId>
- <artifactId>maven-license-plugin</artifactId>
- <version>1.4.0</version>
- <inherited>false</inherited>
- <configuration>
- <header>HEADER.txt</header>
- <aggregate>true</aggregate>
- <includes>
- <include>**/src/**/java/org/**</include>
- </includes>
- </configuration>
- <executions>
- <execution>
- <id>verify-license-headers</id>
- <phase>verify</phase>
- <goals>
- <goal>check</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-release-plugin</artifactId>
- <configuration>
- <autoVersionSubmodules>true</autoVersionSubmodules>
- </configuration>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- </plugin>
-
- <plugin>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-maven3-plugin</artifactId>
- <version>2.8</version>
- </plugin>
-
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>cobertura-maven-plugin</artifactId>
- <version>2.5.2</version>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-site-plugin</artifactId>
- <dependencies>
- <dependency>
- <!-- Provide support for scp based deployment of site -->
- <groupId>org.apache.maven.wagon</groupId>
- <artifactId>wagon-ssh</artifactId>
- <version>${sshwagon.version}</version>
- </dependency>
- </dependencies>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <executions>
- <execution>
- <!-- create aggregate report when "mvn site" is invoked. -->
- <id>aggregate</id>
- <goals>
- <goal>aggregate</goal>
- </goals>
- <phase>site</phase>
- <configuration>
- <excludePackageNames>org.xBaseJ:org.xBaseJ.*:org.eobjects.metamodel.jdbc.dialects:org.eobjects.metamodel.detect</excludePackageNames>
- </configuration>
- </execution>
- </executions>
- </plugin>
-
- <plugin>
- <!-- enforce certain banned dependencies -->
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-enforcer-plugin</artifactId>
- <executions>
- <execution>
- <id>enforce-versions</id>
- <goals>
- <goal>enforce</goal>
- </goals>
- <configuration>
- <rules>
- <bannedDependencies>
- <excludes>
- <exclude>commons-logging:commons-logging</exclude>
- </excludes>
- </bannedDependencies>
- </rules>
- </configuration>
- </execution>
- </executions>
- </plugin>
-
- </plugins>
-
- <extensions>
- <extension>
- <!-- Provide support for scp based deployment of site -->
- <groupId>org.apache.maven.wagon</groupId>
- <artifactId>wagon-ssh</artifactId>
- <version>${sshwagon.version}</version>
- </extension>
- </extensions>
-
- <pluginManagement>
- <plugins>
- <plugin>
- <!-- Ignore instructions for m2e (overrides eclipse warning) -->
- <groupId>org.eclipse.m2e</groupId>
- <artifactId>lifecycle-mapping</artifactId>
- <version>1.0.0</version>
- <configuration>
- <lifecycleMappingMetadata>
- <pluginExecutions>
- <pluginExecution>
- <pluginExecutionFilter>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-enforcer-plugin</artifactId>
- <versionRange>[1.0,)</versionRange>
- <goals>
- <goal>enforce</goal>
- </goals>
- </pluginExecutionFilter>
- <action>
- <ignore />
- </action>
- </pluginExecution>
- </pluginExecutions>
- </lifecycleMappingMetadata>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <version>${javadoc.version}</version>
- <reportSets>
- <reportSet>
- <id>aggregate</id>
- <reports>
- <report>aggregate</report>
- </reports>
- </reportSet>
- </reportSets>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <version>2.6</version>
- <configuration>
- <dependencyDetailsEnabled>false</dependencyDetailsEnabled>
- <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
- </configuration>
- </plugin>
- </plugins>
- </reporting>
-
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- <version>${httpcomponents.version}</version>
- <exclusions>
- <exclusion>
- <artifactId>commons-logging</artifactId>
- <groupId>commons-logging</groupId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpcore</artifactId>
- <version>${httpcomponents.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient-cache</artifactId>
- <version>${httpcomponents.version}</version>
- </dependency>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.6</version>
- </dependency>
- <dependency>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- <version>1.7</version>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>2.4</version>
- </dependency>
- <dependency>
- <groupId>commons-pool</groupId>
- <artifactId>commons-pool</artifactId>
- <version>1.6</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>${slf4j.version}</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>jcl-over-slf4j</artifactId>
- <version>${slf4j.version}</version>
- </dependency>
- <dependency>
- <groupId>org.codehaus.jackson</groupId>
- <artifactId>jackson-core-asl</artifactId>
- <version>1.9.12</version>
- </dependency>
- <dependency>
- <groupId>org.codehaus.jackson</groupId>
- <artifactId>jackson-mapper-asl</artifactId>
- <version>1.9.12</version>
- </dependency>
- <dependency>
- <groupId>hsqldb</groupId>
- <artifactId>hsqldb</artifactId>
- <version>1.8.0.10</version>
- </dependency>
-
- <!-- Test dependencies -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>${junit.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- <version>${easymock.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-nop</artifactId>
- <version>${slf4j.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>${slf4j.version}</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
-</project>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <sshwagon.version>2.3</sshwagon.version>
+ <javadoc.version>2.9</javadoc.version>
+ <slf4j.version>1.7.4</slf4j.version>
+ <junit.version>4.11</junit.version>
+ <easymock.version>3.1</easymock.version>
+ <httpcomponents.version>4.2.3</httpcomponents.version>
+ <!-- Version printed in the docs -->
+ <siteDownloadVersion>${project.version}</siteDownloadVersion>
+ </properties>
+ <parent>
+ <groupId>org.apache</groupId>
+ <artifactId>apache</artifactId>
+ <version>13</version>
+ </parent>
+ <scm>
+ <url>https://git-wip-us.apache.org/repos/asf?p=incubator-metamodel.git</url>
+ </scm>
+ <groupId>org.apache.metamodel</groupId>
+ <artifactId>MetaModel</artifactId>
+ <version>3.4.4-SNAPSHOT</version>
+ <name>MetaModel</name>
+ <description>MetaModel is a library that encapsulates the differences and enhances
+ the capabilities of different datastores. Rich querying abilities are
+ offered to datastores that do not otherwise support advanced querying
+ and a unified view of the datastore structure is offered through a
+ single model of the schemas, tables, columns and relationships.</description>
+ <url>http://metamodel.incubator.apache.org</url>
+ <inceptionYear>2007</inceptionYear>
+ <packaging>pom</packaging>
+ <modules>
+ <module>core</module>
+ <module>pojo</module>
+ <module>fixedwidth</module>
+ <module>excel</module>
+ <module>csv</module>
+ <module>xml</module>
+ <module>access</module>
+ <module>jdbc</module>
+ <module>mongodb</module>
+ <module>couchdb</module>
+ <module>openoffice</module>
+ <module>salesforce</module>
+ <module>sugarcrm</module>
+ <module>full</module>
+ </modules>
+ <issueManagement>
+ <system>Jira</system>
+ <url>https://issues.apache.org/jira/browse/METAMODEL</url>
+ </issueManagement>
+ <mailingLists>
+ <mailingList>
+ <name>Development</name>
+ <post>dev@metamodel.incubator.apache.org</post>
+ <subscribe>dev-subscribe@metamodel.incubator.apache.org</subscribe>
+ <unsubscribe>dev-unsubscribe@metamodel.incubator.apache.org</unsubscribe>
+ <archive>http://mail-archives.apache.org/mod_mbox/incubator-metamodel-dev/</archive>
+ </mailingList>
+ <mailingList>
+ <name>Commits</name>
+ <post>commits@metamodel.incubator.apache.org</post>
+ <subscribe>commits-subscribe@metamodel.incubator.apache.org</subscribe>
+ <unsubscribe>commits-unsubscribe@metamodel.incubator.apache.org</unsubscribe>
+ <archive>http://mail-archives.apache.org/mod_mbox/incubator-metamodel-commits/</archive>
+ </mailingList>
+ </mailingLists>
+ <organization>
+ <name>The Apache Software Foundation</name>
+ <url>http://www.apache.org/</url>
+ </organization>
+ <developers>
+ <developer>
+ <id>kasper</id>
+ <name>Kasper Sørensen</name>
+ <email>kasper.sorensen@humaninference.com</email>
+ <url>http://kasper.eobjects.org</url>
+ <organization>Human Inference</organization>
+ <organizationUrl>http://www.humaninference.com</organizationUrl>
+ </developer>
+ </developers>
+ <contributors>
+ <contributor>
+ <name>Saurabh Gupta</name>
+ <organization>Xebia India</organization>
+ </contributor>
+ <contributor>
+ <name>Balendra Singh</name>
+ <organization>Xebia India</organization>
+ </contributor>
+ <contributor>
+ <name>Sameer Arora</name>
+ <organization>Xebia India</organization>
+ </contributor>
+ </contributors>
+ <licenses>
+ <license>
+ <name>The Apache Software License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ </license>
+ </licenses>
+ <build>
+ <plugins>
+ <plugin>
+ <!-- Ensures java 6 compatibility -->
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ <encoding>utf-8</encoding>
+ </configuration>
+ </plugin>
+ <plugin>
+ <!-- Ensure inclusion of license header in all main java files -->
+ <groupId>com.google.code.maven-license-plugin</groupId>
+ <artifactId>maven-license-plugin</artifactId>
+ <version>1.4.0</version>
+ <inherited>false</inherited>
+ <configuration>
+ <header>HEADER.txt</header>
+ <aggregate>true</aggregate>
+ <includes>
+ <include>**/src/**/java/org/**</include>
+ </includes>
+ </configuration>
+ <executions>
+ <execution>
+ <id>verify-license-headers</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-release-plugin</artifactId>
+ <configuration>
+ <autoVersionSubmodules>true</autoVersionSubmodules>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-maven3-plugin</artifactId>
+ <version>2.8</version>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>cobertura-maven-plugin</artifactId>
+ <version>2.5.2</version>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-site-plugin</artifactId>
+ <dependencies>
+ <dependency>
+ <!-- Provide support for scp based deployment of site -->
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-ssh</artifactId>
+ <version>${sshwagon.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <executions>
+ <execution>
+ <!-- create aggregate report when "mvn site" is invoked. -->
+ <id>aggregate</id>
+ <goals>
+ <goal>aggregate</goal>
+ </goals>
+ <phase>site</phase>
+ <configuration>
+ <excludePackageNames>org.apache.metamodel.jdbc.dialects:org.apache.metamodel.detect</excludePackageNames>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <!-- enforce certain banned dependencies -->
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>enforce-versions</id>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ <configuration>
+ <rules>
+ <bannedDependencies>
+ <excludes>
+ <exclude>commons-logging:commons-logging</exclude>
+ </excludes>
+ </bannedDependencies>
+ </rules>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+
+ <extensions>
+ <extension>
+ <!-- Provide support for scp based deployment of site -->
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-ssh</artifactId>
+ <version>${sshwagon.version}</version>
+ </extension>
+ </extensions>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <!-- Ignore instructions for m2e (overrides eclipse warning) -->
+ <groupId>org.eclipse.m2e</groupId>
+ <artifactId>lifecycle-mapping</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <versionRange>[1.0,)</versionRange>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore />
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>${javadoc.version}</version>
+ <reportSets>
+ <reportSet>
+ <id>aggregate</id>
+ <reports>
+ <report>aggregate</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>2.6</version>
+ <configuration>
+ <dependencyDetailsEnabled>false</dependencyDetailsEnabled>
+ <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>${httpcomponents.version}</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>commons-logging</artifactId>
+ <groupId>commons-logging</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpcore</artifactId>
+ <version>${httpcomponents.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient-cache</artifactId>
+ <version>${httpcomponents.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.6</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.7</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-pool</groupId>
+ <artifactId>commons-pool</artifactId>
+ <version>1.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-core-asl</artifactId>
+ <version>1.9.12</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-mapper-asl</artifactId>
+ <version>1.9.12</version>
+ </dependency>
+ <dependency>
+ <groupId>hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>1.8.0.10</version>
+ </dependency>
+
+ <!-- Test dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>${easymock.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-nop</artifactId>
+ <version>${slf4j.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>${slf4j.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/660e6936/src/site/apt/download.apt.vm
----------------------------------------------------------------------
diff --git a/src/site/apt/download.apt.vm b/src/site/apt/download.apt.vm
index abfd348..8a0e3ab 100644
--- a/src/site/apt/download.apt.vm
+++ b/src/site/apt/download.apt.vm
@@ -18,7 +18,7 @@ Use in Maven
+-------------------------------+
<dependency>
- <groupId>org.eobjects.metamodel</groupId>
+ <groupId>org.apache.metamodel</groupId>
<artifactId>MetaModel-full</artifactId>
<version>${siteDownloadVersion}</version>
</dependency>
@@ -27,13 +27,13 @@ Use in Maven
Apache Ivy:
+-------------------------------+
-<dependency org="org.eobjects.metamodel" name="MetaModel-full" rev="${siteDownloadVersion}"/>
+<dependency org="org.apache.metamodel" name="MetaModel-full" rev="${siteDownloadVersion}"/>
+-------------------------------+
Groovy Grape:
+-------------------------------+
@Grapes(
- @Grab(group='org.eobjects.metamodel', module='MetaModel-full', version='${siteDownloadVersion}')
+ @Grab(group='org.apache.metamodel', module='MetaModel-full', version='${siteDownloadVersion}')
)
+-------------------------------+
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/660e6936/src/site/apt/index.apt.vm
----------------------------------------------------------------------
diff --git a/src/site/apt/index.apt.vm b/src/site/apt/index.apt.vm
index ace1e63..af24eae 100644
--- a/src/site/apt/index.apt.vm
+++ b/src/site/apt/index.apt.vm
@@ -1,72 +1,72 @@
- ------
- Home
- ------
-
-eobjects.org MetaModel
-
- MetaModel is a library that <<encapsulates>> the <differences> and <<enhances>>
- the <capabilities> of different datastores. Rich <<querying>> abilities are
- offered to datastores that do not otherwise support advanced querying
- and a <<unified view>> of the datastore structure is offered through a
- single model of the schemas, tables, columns and relationships.
-
-[modules.png] Modules in MetaModel
-
-
-
-* Sounds interesting? Read on for a few quick steps to get you started!
-
-Query with MetaModel
-
- With MetaModel you use a type-safe SQL-like API for querying any datastore:
-
-+-------------------------------+
-DataContext dataContext = DataContextFactory.create[Type-of-DataContext](...);
-DataSet dataSet = dataContext.query()
- .from("libraries")
- .select("name")
- .where("language").equals("Java")
- .and("enhances_data_access").equals(true)
- .execute();
-+-------------------------------+
-
- The MetaModel query API allows you to use the power of SQL, even on data formats such as CSV files, Excel spreadsheets, NoSQL databases and more.
-
-Update with MetaModel
-
- MetaModel lets you do CRUD operations on arbitrary datamodels, also in a type-safe manner. Batch updates and transactions are logically modelled as UpdateScript closures.
-
-+-------------------------------+
-dataContext.executeUpdate(new UpdateScript() {
- public void run(UpdateCallback callback) {
- // CREATE a table
- Table table = callback.createTable("foo").withColumn("bar").ofType(INTEGER)
- .withColumn("baz").ofType(VARCHAR).execute();
-
- // INSERT INTO table
- callback.insertInto(table).value("bar", 1).value("baz", "hello").execute();
- callback.insertInto(table).value("bar", 2).value("baz", "world").execute();
-
- // UPDATE table
- callback.update(table).value("baz","universe").where("bar").equals(2).execute();
-
- // DELETE FROM table
- callback.deleteFrom(table).where("bar").equals(1).execute();
- }
-});
-+-------------------------------+
-
- The rest of the API should reveal itself through using the DataContext (but don't be affraid to check out the
- {{{./example_simple_queries.html} examples}} and the {{{./apidocs} Javadoc API documentation}})!
-
-Install MetaModel
-
- Include MetaModel as a dependency in your project (if you're not using Maven, refer to the {{{./download.html}download page}} for alternatives):
-
-+-------------------------------+
-<dependency>
- <groupId>org.eobjects.metamodel</groupId>
- <artifactId>MetaModel-full</artifactId>
- <version>${siteDownloadVersion}</version>
-</dependency>
+ ------
+ Home
+ ------
+
+eobjects.org MetaModel
+
+ MetaModel is a library that <<encapsulates>> the <differences> and <<enhances>>
+ the <capabilities> of different datastores. Rich <<querying>> abilities are
+ offered to datastores that do not otherwise support advanced querying
+ and a <<unified view>> of the datastore structure is offered through a
+ single model of the schemas, tables, columns and relationships.
+
+[modules.png] Modules in MetaModel
+
+
+
+* Sounds interesting? Read on for a few quick steps to get you started!
+
+Query with MetaModel
+
+ With MetaModel you use a type-safe SQL-like API for querying any datastore:
+
++-------------------------------+
+DataContext dataContext = DataContextFactory.create[Type-of-DataContext](...);
+DataSet dataSet = dataContext.query()
+ .from("libraries")
+ .select("name")
+ .where("language").equals("Java")
+ .and("enhances_data_access").equals(true)
+ .execute();
++-------------------------------+
+
+ The MetaModel query API allows you to use the power of SQL, even on data formats such as CSV files, Excel spreadsheets, NoSQL databases and more.
+
+Update with MetaModel
+
+ MetaModel lets you do CRUD operations on arbitrary datamodels, also in a type-safe manner. Batch updates and transactions are logically modelled as UpdateScript closures.
+
++-------------------------------+
+dataContext.executeUpdate(new UpdateScript() {
+ public void run(UpdateCallback callback) {
+ // CREATE a table
+ Table table = callback.createTable("foo").withColumn("bar").ofType(INTEGER)
+ .withColumn("baz").ofType(VARCHAR).execute();
+
+ // INSERT INTO table
+ callback.insertInto(table).value("bar", 1).value("baz", "hello").execute();
+ callback.insertInto(table).value("bar", 2).value("baz", "world").execute();
+
+ // UPDATE table
+ callback.update(table).value("baz","universe").where("bar").equals(2).execute();
+
+ // DELETE FROM table
+ callback.deleteFrom(table).where("bar").equals(1).execute();
+ }
+});
++-------------------------------+
+
+ The rest of the API should reveal itself through using the DataContext (but don't be affraid to check out the
+ {{{./example_simple_queries.html} examples}} and the {{{./apidocs} Javadoc API documentation}})!
+
+Install MetaModel
+
+ Include MetaModel as a dependency in your project (if you're not using Maven, refer to the {{{./download.html}download page}} for alternatives):
+
++-------------------------------+
+<dependency>
+ <groupId>org.apache.metamodel</groupId>
+ <artifactId>MetaModel-full</artifactId>
+ <version>${siteDownloadVersion}</version>
+</dependency>
+-------------------------------+
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/660e6936/sugarcrm/src/jaxws/binding/bindings.xml
----------------------------------------------------------------------
diff --git a/sugarcrm/src/jaxws/binding/bindings.xml b/sugarcrm/src/jaxws/binding/bindings.xml
index 22ce63d..88cbd33 100644
--- a/sugarcrm/src/jaxws/binding/bindings.xml
+++ b/sugarcrm/src/jaxws/binding/bindings.xml
@@ -1,17 +1,17 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<jaxws:bindings version="2.0"
- xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
- xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb">
-
- <jaxws:bindings>
- <handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
- <handler-chain>
- <handler>
- <handler-name>LoggingMessageHandler</handler-name>
- <handler-class>org.eobjects.metamodel.sugarcrm.LoggingMessageHandler</handler-class>
- </handler>
- </handler-chain>
- </handler-chains>
- </jaxws:bindings>
-
+<?xml version="1.0" encoding="UTF-8"?>
+<jaxws:bindings version="2.0"
+ xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb">
+
+ <jaxws:bindings>
+ <handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
+ <handler-chain>
+ <handler>
+ <handler-name>LoggingMessageHandler</handler-name>
+ <handler-class>org.apache.metamodel.sugarcrm.LoggingMessageHandler</handler-class>
+ </handler>
+ </handler-chain>
+ </handler-chains>
+ </jaxws:bindings>
+
</jaxws:bindings>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/660e6936/sugarcrm/src/main/resources/com/sugarcrm/ws/soap/Sugarsoap_handler.xml
----------------------------------------------------------------------
diff --git a/sugarcrm/src/main/resources/com/sugarcrm/ws/soap/Sugarsoap_handler.xml b/sugarcrm/src/main/resources/com/sugarcrm/ws/soap/Sugarsoap_handler.xml
index 3982ee7..fc05131 100644
--- a/sugarcrm/src/main/resources/com/sugarcrm/ws/soap/Sugarsoap_handler.xml
+++ b/sugarcrm/src/main/resources/com/sugarcrm/ws/soap/Sugarsoap_handler.xml
@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<javaee:handler-chains
- xmlns:javaee="http://java.sun.com/xml/ns/javaee"
- xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <javaee:handler-chain>
- <javaee:handler>
- <javaee:handler-class>org.eobjects.metamodel.sugarcrm.LoggingMessageHandler</javaee:handler-class>
- </javaee:handler>
- </javaee:handler-chain>
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<javaee:handler-chains
+ xmlns:javaee="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+ <javaee:handler-chain>
+ <javaee:handler>
+ <javaee:handler-class>org.apache.metamodel.sugarcrm.LoggingMessageHandler</javaee:handler-class>
+ </javaee:handler>
+ </javaee:handler-chain>
</javaee:handler-chains>
\ No newline at end of file
[19/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/schema/MutableSchemaTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/schema/MutableSchemaTest.java b/core/src/test/java/org/eobjects/metamodel/schema/MutableSchemaTest.java
deleted file mode 100644
index 8eca7b2..0000000
--- a/core/src/test/java/org/eobjects/metamodel/schema/MutableSchemaTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * 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.schema;
-
-import junit.framework.TestCase;
-
-public class MutableSchemaTest extends TestCase {
-
- /**
- * Tests that the following (general) rules apply to the object:
- *
- * <li>the hashcode is the same when run twice on an unaltered object</li>
- * <li>if o1.equals(o2) then this condition must be true: o1.hashCode() ==
- * 02.hashCode()
- */
- public void testEqualsAndHashCode() throws Exception {
- MutableSchema schema1 = new MutableSchema("foo");
- MutableSchema schema2 = new MutableSchema("foo");
-
- assertTrue(schema1.equals(schema2));
- assertTrue(schema1.hashCode() == schema2.hashCode());
-
- schema2.addTable(new MutableTable("foo"));
- assertFalse(schema1.equals(schema2));
- assertTrue(schema1.hashCode() == schema2.hashCode());
-
- schema2 = new MutableSchema("foo");
- assertTrue(schema1.equals(schema2));
- assertTrue(schema1.hashCode() == schema2.hashCode());
- }
-
- public void testGetTableByName() throws Exception {
- MutableSchema s = new MutableSchema("foobar");
- s.addTable(new MutableTable("Foo"));
- s.addTable(new MutableTable("FOO"));
- s.addTable(new MutableTable("bar"));
-
- assertEquals("Foo", s.getTableByName("Foo").getName());
- assertEquals("FOO", s.getTableByName("FOO").getName());
- assertEquals("bar", s.getTableByName("bar").getName());
-
- // picking the first alternative that matches case insensitively
- assertEquals("Foo", s.getTableByName("fOO").getName());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/schema/MutableTableTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/schema/MutableTableTest.java b/core/src/test/java/org/eobjects/metamodel/schema/MutableTableTest.java
deleted file mode 100644
index 4efb0d6..0000000
--- a/core/src/test/java/org/eobjects/metamodel/schema/MutableTableTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- * 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.schema;
-
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-public class MutableTableTest extends TestCase {
-
- /**
- * Tests that the following (general) rules apply to the object:
- *
- * <li>the hashcode is the same when run twice on an unaltered object</li>
- * <li>if o1.equals(o2) then this condition must be true: o1.hashCode() ==
- * 02.hashCode()
- */
- public void testEqualsAndHashCode() throws Exception {
- MutableTable table1 = new MutableTable("Foo").addColumn(new MutableColumn("col1"));
- MutableTable table2 = new MutableTable("Foo").addColumn(new MutableColumn("col1"));
-
- assertFalse(table2.equals(null));
- assertEquals(table1.hashCode(), table2.hashCode());
- assertEquals(table1, table2);
-
- table2.addColumn(new MutableColumn("bar"));
- assertFalse(table1.equals(table2));
-
- int table1hash = table1.hashCode();
- int table2hash = table2.hashCode();
- assertTrue(table1hash + "==" + table2hash, table1hash == table2hash);
- }
-
- public void testGetColumnsOfType() throws Exception {
- MutableTable t = new MutableTable("foo");
- t.addColumn(new MutableColumn("b").setType(ColumnType.VARCHAR));
- t.addColumn(new MutableColumn("a").setType(ColumnType.VARCHAR));
- t.addColumn(new MutableColumn("r").setType(ColumnType.INTEGER));
-
- Column[] cols = t.getColumnsOfType(ColumnType.VARCHAR);
- assertEquals(2, cols.length);
- assertEquals("b", cols[0].getName());
- assertEquals("a", cols[1].getName());
-
- cols = t.getColumnsOfType(ColumnType.INTEGER);
- assertEquals(1, cols.length);
- assertEquals("r", cols[0].getName());
-
- cols = t.getColumnsOfType(ColumnType.FLOAT);
- assertEquals(0, cols.length);
- }
-
- public void testGetIndexedColumns() throws Exception {
- MutableTable t = new MutableTable("foo");
- t.addColumn(new MutableColumn("b").setIndexed(true));
- t.addColumn(new MutableColumn("a").setIndexed(false));
- t.addColumn(new MutableColumn("r").setIndexed(true));
- Column[] indexedColumns = t.getIndexedColumns();
- assertEquals(
- "[Column[name=b,columnNumber=0,type=null,nullable=null,nativeType=null,columnSize=null], Column[name=r,columnNumber=0,type=null,nullable=null,nativeType=null,columnSize=null]]",
- Arrays.toString(indexedColumns));
- for (Column column : indexedColumns) {
- assertTrue(column.isIndexed());
- }
- }
-
- public void testGetColumnByName() throws Exception {
- MutableTable t = new MutableTable("foobar");
- t.addColumn(new MutableColumn("Foo"));
- t.addColumn(new MutableColumn("FOO"));
- t.addColumn(new MutableColumn("bar"));
-
- assertEquals("Foo", t.getColumnByName("Foo").getName());
- assertEquals("FOO", t.getColumnByName("FOO").getName());
- assertEquals("bar", t.getColumnByName("bar").getName());
-
- // picking the first alternative that matches case insensitively
- assertEquals("Foo", t.getColumnByName("fOO").getName());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/schema/SchemaModelTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/schema/SchemaModelTest.java b/core/src/test/java/org/eobjects/metamodel/schema/SchemaModelTest.java
deleted file mode 100644
index 380d9d1..0000000
--- a/core/src/test/java/org/eobjects/metamodel/schema/SchemaModelTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/**
- * 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.schema;
-
-import java.util.Arrays;
-
-import org.eobjects.metamodel.MetaModelTestCase;
-
-public class SchemaModelTest extends MetaModelTestCase {
-
- public void testGetExampleSchema() throws Exception {
- Schema schema = getExampleSchema();
- assertEquals("MetaModelSchema", schema.getName());
- assertEquals("Schema[name=MetaModelSchema]", schema.toString());
- assertEquals(5, schema.getRelationships().length);
-
- assertEquals(4, schema.getTableCount());
- assertEquals(3, schema.getTableCount(TableType.TABLE));
- assertEquals(1, schema.getTableCount(TableType.VIEW));
-
- assertNull(schema.getTableByName("foobar"));
- assertNull(schema.getTableByName(null));
-
- Table contributorTable = schema.getTableByName(TABLE_CONTRIBUTOR);
- assertEquals(3, contributorTable.getColumnCount());
- assertEquals(2, contributorTable.getRelationshipCount());
-
- Table projectTable = schema.getTableByName(TABLE_PROJECT);
- assertEquals(4, projectTable.getColumnCount());
- assertEquals(2, projectTable.getRelationshipCount());
- assertNotNull(projectTable.getColumnByName("project_id"));
-
- assertEquals("[project_id, name, lines_of_code, parent_project_id]",
- Arrays.toString(projectTable.getColumnNames()));
-
- assertEquals(
- "[Column[name=project_id,columnNumber=0,type=INTEGER,nullable=false,nativeType=null,columnSize=null], "
- + "Column[name=lines_of_code,columnNumber=2,type=BIGINT,nullable=true,nativeType=null,columnSize=null], "
- + "Column[name=parent_project_id,columnNumber=3,type=INTEGER,nullable=true,nativeType=null,columnSize=null]]",
- Arrays.toString(projectTable.getNumberColumns()));
-
- assertEquals("[Column[name=name,columnNumber=1,type=VARCHAR,nullable=false,nativeType=null,columnSize=null]]",
- Arrays.toString(projectTable.getLiteralColumns()));
-
- assertEquals("[]", Arrays.toString(projectTable.getTimeBasedColumns()));
-
- assertNull(projectTable.getColumnByName("foobar"));
- assertNull(projectTable.getColumnByName(null));
-
- Table roleTable = schema.getTableByName(TABLE_ROLE);
- assertEquals(3, roleTable.getColumnCount());
- assertEquals(3, roleTable.getRelationshipCount());
-
- Table projectContributorView = schema.getTableByName(TABLE_PROJECT_CONTRIBUTOR);
- assertEquals(3, projectContributorView.getColumnCount());
- assertEquals(3, projectContributorView.getRelationshipCount());
-
- Relationship[] projectContributorToContributorRelations = projectContributorView
- .getRelationships(contributorTable);
- assertEquals(1, projectContributorToContributorRelations.length);
- Relationship[] contributorToProjectContributorRelations = contributorTable
- .getRelationships(projectContributorView);
- assertEquals(1, contributorToProjectContributorRelations.length);
- assertTrue(Arrays.equals(projectContributorToContributorRelations, contributorToProjectContributorRelations));
-
- assertEquals(
- "Relationship[primaryTable=contributor,primaryColumns=[name],foreignTable=project_contributor,foreignColumns=[contributor]]",
- projectContributorToContributorRelations[0].toString());
-
- ((MutableRelationship) projectContributorToContributorRelations[0]).remove();
- projectContributorToContributorRelations = projectContributorView.getRelationships(contributorTable);
- assertEquals(0, projectContributorToContributorRelations.length);
- contributorToProjectContributorRelations = contributorTable.getRelationships(projectContributorView);
- assertEquals(0, contributorToProjectContributorRelations.length);
-
- // Get primary keys / Get foreign keys test
- assertEquals(
- "[Column[name=contributor_id,columnNumber=0,type=INTEGER,nullable=false,nativeType=null,columnSize=null]]",
- Arrays.toString(contributorTable.getPrimaryKeys()));
- assertEquals("[]", Arrays.toString(contributorTable.getForeignKeys()));
-
- assertEquals(
- "[Column[name=contributor_id,columnNumber=0,type=INTEGER,nullable=false,nativeType=null,columnSize=null], Column[name=project_id,columnNumber=1,type=INTEGER,nullable=false,nativeType=null,columnSize=null]]",
- Arrays.toString(roleTable.getPrimaryKeys()));
- Column[] foreignKeys = roleTable.getForeignKeys();
- assertEquals(2, foreignKeys.length);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/schema/TableTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/schema/TableTypeTest.java b/core/src/test/java/org/eobjects/metamodel/schema/TableTypeTest.java
deleted file mode 100644
index 127c54b..0000000
--- a/core/src/test/java/org/eobjects/metamodel/schema/TableTypeTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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.schema;
-
-import junit.framework.TestCase;
-
-public class TableTypeTest extends TestCase {
-
- public void testGetTableType() throws Exception {
- assertSame(TableType.TABLE, TableType.getTableType("table"));
- assertSame(TableType.VIEW, TableType.getTableType("view"));
- assertSame(TableType.GLOBAL_TEMPORARY, TableType
- .getTableType("GLOBAL_TEMPORARY"));
- assertSame(TableType.SYSTEM_TABLE, TableType
- .getTableType("system_table"));
- assertSame(TableType.LOCAL_TEMPORARY, TableType
- .getTableType("LOCAL_TEMPORARY"));
- assertSame(TableType.ALIAS, TableType.getTableType("alIAs"));
- assertSame(TableType.SYNONYM, TableType.getTableType("synonym"));
- assertSame(TableType.OTHER, TableType.getTableType("foobar"));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/AlphabeticSequenceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/AlphabeticSequenceTest.java b/core/src/test/java/org/eobjects/metamodel/util/AlphabeticSequenceTest.java
deleted file mode 100644
index 36039c4..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/AlphabeticSequenceTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * 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.util;
-
-import junit.framework.TestCase;
-
-public class AlphabeticSequenceTest extends TestCase {
-
- public void testNoArgsConstructor() throws Exception {
- AlphabeticSequence seq = new AlphabeticSequence();
- assertEquals("A", seq.next());
- }
-
- public void testNext() throws Exception {
- AlphabeticSequence seq = new AlphabeticSequence("A");
- assertEquals("A", seq.current());
- assertEquals("B", seq.next());
- assertEquals("C", seq.next());
- assertEquals("D", seq.next());
- assertEquals("E", seq.next());
- assertEquals("F", seq.next());
- assertEquals("G", seq.next());
- assertEquals("H", seq.next());
- assertEquals("I", seq.next());
- assertEquals("J", seq.next());
- assertEquals("K", seq.next());
- assertEquals("L", seq.next());
- assertEquals("M", seq.next());
- assertEquals("N", seq.next());
- assertEquals("O", seq.next());
- assertEquals("P", seq.next());
- assertEquals("Q", seq.next());
- assertEquals("R", seq.next());
- assertEquals("S", seq.next());
- assertEquals("T", seq.next());
- assertEquals("U", seq.next());
- assertEquals("V", seq.next());
- assertEquals("W", seq.next());
- assertEquals("X", seq.next());
- assertEquals("Y", seq.next());
- assertEquals("Z", seq.next());
- assertEquals("AA", seq.next());
-
- seq = new AlphabeticSequence("AZ");
- assertEquals("BA", seq.next());
-
- seq = new AlphabeticSequence("ZZ");
- assertEquals("AAA", seq.next());
-
- seq = new AlphabeticSequence("ABZ");
- assertEquals("ACA", seq.next());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/BaseObjectTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/BaseObjectTest.java b/core/src/test/java/org/eobjects/metamodel/util/BaseObjectTest.java
deleted file mode 100644
index e147bc1..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/BaseObjectTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * 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.util;
-
-import java.util.List;
-
-import junit.framework.TestCase;
-
-public class BaseObjectTest extends TestCase {
-
- class MyClass extends BaseObject {
- private int[] ints;
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- identifiers.add(ints);
- }
- }
-
- public void testHashCodeForPrimitiveArray() throws Exception {
- MyClass o1 = new MyClass();
- o1.ints = new int[] { 1, 2, 3 };
- MyClass o2 = new MyClass();
- o2.ints = new int[] { 4, 5, 6 };
- MyClass o3 = new MyClass();
- o3.ints = new int[] { 1, 2, 3 };
-
- assertTrue(o1.hashCode() == o1.hashCode());
- assertTrue(o1.hashCode() == o3.hashCode());
- assertFalse(o1.hashCode() == o2.hashCode());
- assertFalse(o3.hashCode() == o2.hashCode());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/BooleanComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/BooleanComparatorTest.java b/core/src/test/java/org/eobjects/metamodel/util/BooleanComparatorTest.java
deleted file mode 100644
index 1c099fd..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/BooleanComparatorTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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.util;
-
-import java.util.Comparator;
-
-import junit.framework.TestCase;
-
-public class BooleanComparatorTest extends TestCase {
-
- public void testCompare() throws Exception {
- Comparator<Object> c = BooleanComparator.getComparator();
- assertEquals(1, c.compare(true, false));
- assertEquals(-1, c.compare(false, true));
- assertEquals(0, c.compare(true, true));
- assertEquals(0, c.compare(false, false));
-
- assertEquals(1, c.compare("true", "false"));
- assertEquals(1, c.compare("1", "false"));
- assertEquals(1, c.compare("true", "0"));
- assertEquals(1, c.compare("true", "false"));
-
- assertEquals(1, c.compare(1, 0));
-
- assertEquals(1, c.compare(1, "false"));
- assertEquals(1, c.compare("yes", false));
- assertEquals(1, c.compare("y", false));
- assertEquals(1, c.compare("TRUE", false));
- }
-
- public void testComparable() throws Exception {
- Comparable<Object> comparable = BooleanComparator.getComparable(true);
- assertEquals(1, comparable.compareTo(false));
- assertEquals(1, comparable.compareTo(0));
- assertEquals(1, comparable.compareTo("false"));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/ClasspathResourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/ClasspathResourceTest.java b/core/src/test/java/org/eobjects/metamodel/util/ClasspathResourceTest.java
deleted file mode 100644
index 0b94d5d..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/ClasspathResourceTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * 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.util;
-
-import java.io.InputStream;
-
-import junit.framework.TestCase;
-
-public class ClasspathResourceTest extends TestCase {
-
- public void testGetName() throws Exception {
- ClasspathResource resource = new ClasspathResource("folder/foo");
- assertEquals("foo", resource.getName());
- assertTrue(resource.isExists());
- assertTrue(resource.isReadOnly());
-
- resource = new ClasspathResource("/folder/foo");
- assertEquals("foo", resource.getName());
- assertTrue(resource.isExists());
- assertTrue(resource.isReadOnly());
-
- String result = resource.read(new Func<InputStream, String>() {
- @Override
- public String eval(InputStream inputStream) {
- return FileHelper.readInputStreamAsString(inputStream, "UTF8");
- }
- });
- assertEquals("bar-baz", result);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/CollectionUtilsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/CollectionUtilsTest.java b/core/src/test/java/org/eobjects/metamodel/util/CollectionUtilsTest.java
deleted file mode 100644
index d3c5ebf..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/CollectionUtilsTest.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/**
- * 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.util;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-public class CollectionUtilsTest extends TestCase {
-
- public void testArray1() throws Exception {
- String[] result = CollectionUtils.array(new String[] { "foo", "bar" },
- "hello", "world");
- assertEquals("[foo, bar, hello, world]", Arrays.toString(result));
- }
-
- public void testArray2() throws Exception {
- Object[] existingArray = new Object[] { 'c' };
- Object[] result = CollectionUtils.array(existingArray, "foo", 1, "bar");
-
- assertEquals("[c, foo, 1, bar]", Arrays.toString(result));
- }
-
- public void testConcat() throws Exception {
- List<String> list1 = new ArrayList<String>();
- list1.add("hello");
- list1.add("hello");
- list1.add("world");
- List<String> list2 = new ArrayList<String>();
- list2.add("howdy");
- list2.add("world");
- List<String> list3 = new ArrayList<String>();
- list3.add("hi");
- list3.add("world");
-
- List<String> result = CollectionUtils.concat(true, list1, list2, list3);
- assertEquals("[hello, world, howdy, hi]", result.toString());
- assertEquals(4, result.size());
-
- result = CollectionUtils.concat(false, list1, list2, list3);
- assertEquals("[hello, hello, world, howdy, world, hi, world]",
- result.toString());
- assertEquals(7, result.size());
- }
-
- public void testMap() throws Exception {
- List<String> strings = new ArrayList<String>();
- strings.add("hi");
- strings.add("world");
-
- List<Integer> ints = CollectionUtils.map(strings,
- new Func<String, Integer>() {
- @Override
- public Integer eval(String arg) {
- return arg.length();
- }
- });
- assertEquals("[2, 5]", ints.toString());
- }
-
- public void testFilter() throws Exception {
- List<String> list = new ArrayList<String>();
- list.add("foo");
- list.add("bar");
- list.add("3");
- list.add("2");
-
- list = CollectionUtils.filter(list, new Predicate<String>() {
- @Override
- public Boolean eval(String arg) {
- return arg.length() > 1;
- }
- });
-
- assertEquals(2, list.size());
- assertEquals("[foo, bar]", list.toString());
- }
-
- public void testArrayRemove() throws Exception {
- String[] arr = new String[] { "a", "b", "c", "d", "e" };
- arr = CollectionUtils.arrayRemove(arr, "c");
- assertEquals("[a, b, d, e]", Arrays.toString(arr));
-
- arr = CollectionUtils.arrayRemove(arr, "e");
- assertEquals("[a, b, d]", Arrays.toString(arr));
-
- arr = CollectionUtils.arrayRemove(arr, "e");
- assertEquals("[a, b, d]", Arrays.toString(arr));
-
- arr = CollectionUtils.arrayRemove(arr, "a");
- assertEquals("[b, d]", Arrays.toString(arr));
- }
-
- public void testToList() throws Exception {
- assertTrue(CollectionUtils.toList(null).isEmpty());
- assertEquals("[foo]", CollectionUtils.toList("foo").toString());
- assertEquals("[foo, bar]",
- CollectionUtils.toList(new String[] { "foo", "bar" })
- .toString());
-
- List<Integer> ints = Arrays.asList(1, 2, 3);
- assertSame(ints, CollectionUtils.toList(ints));
-
- assertEquals("[1, 2, 3]", CollectionUtils.toList(ints.iterator())
- .toString());
- assertEquals("[1, 2, 3]",
- CollectionUtils.toList(new HashSet<Integer>(ints)).toString());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/DateUtilsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/DateUtilsTest.java b/core/src/test/java/org/eobjects/metamodel/util/DateUtilsTest.java
deleted file mode 100644
index b1bd885..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/DateUtilsTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * 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.util;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import junit.framework.TestCase;
-
-public class DateUtilsTest extends TestCase {
-
- public void testGet() throws Exception {
- SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-
- Date christmasDay = DateUtils.get(2010, Month.DECEMBER, 24);
- assertEquals("2010-12-24 00:00:00", f.format(christmasDay));
- assertEquals(Weekday.FRIDAY, DateUtils.getWeekday(christmasDay));
-
- Date date2 = DateUtils.get(christmasDay, 1);
- assertEquals("2010-12-25 00:00:00", f.format(date2));
-
- Date date3 = DateUtils.get(christmasDay, 10);
- assertEquals("2011-01-03 00:00:00", f.format(date3));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/EqualsBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/EqualsBuilderTest.java b/core/src/test/java/org/eobjects/metamodel/util/EqualsBuilderTest.java
deleted file mode 100644
index 78649a8..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/EqualsBuilderTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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.util;
-
-import junit.framework.TestCase;
-
-public class EqualsBuilderTest extends TestCase {
-
- public void testEquals() throws Exception {
- assertTrue(EqualsBuilder.equals(null, null));
- assertTrue(EqualsBuilder.equals("hello", "hello"));
- assertFalse(EqualsBuilder.equals("hello", null));
- assertFalse(EqualsBuilder.equals(null, "hello"));
- assertFalse(EqualsBuilder.equals("world", "hello"));
-
- MyCloneable o1 = new MyCloneable();
- assertTrue(EqualsBuilder.equals(o1, o1));
- MyCloneable o2 = o1.clone();
- assertFalse(EqualsBuilder.equals(o1, o2));
- }
-
- static final class MyCloneable implements Cloneable {
- @Override
- public boolean equals(Object obj) {
- return false;
- }
-
- @Override
- public MyCloneable clone() {
- try {
- return (MyCloneable) super.clone();
- } catch (CloneNotSupportedException e) {
- throw new UnsupportedOperationException();
- }
- }
- };
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/ExclusionPredicateTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/ExclusionPredicateTest.java b/core/src/test/java/org/eobjects/metamodel/util/ExclusionPredicateTest.java
deleted file mode 100644
index f2d9237..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/ExclusionPredicateTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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.util;
-
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-public class ExclusionPredicateTest extends TestCase {
-
- public void testEval() throws Exception {
- ExclusionPredicate<String> predicate = new ExclusionPredicate<String>(Arrays.asList("foo","bar","baz"));
-
- assertFalse(predicate.eval("foo"));
- assertFalse(predicate.eval("bar"));
- assertFalse(predicate.eval("baz"));
-
- assertTrue(predicate.eval("hello world"));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/FileHelperTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/FileHelperTest.java b/core/src/test/java/org/eobjects/metamodel/util/FileHelperTest.java
deleted file mode 100644
index f51553f..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/FileHelperTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * 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.util;
-
-import java.io.File;
-
-import junit.framework.TestCase;
-
-public class FileHelperTest extends TestCase {
-
- public void testGetTempDir() throws Exception {
- File tempDir = FileHelper.getTempDir();
- String property = System.getProperty("java.io.tmpdir");
- assertEquals(normalize(property), normalize(tempDir.getPath()));
- }
-
- private String normalize(String path) {
- if (path == null) {
- return null;
- }
- if (path.endsWith(File.separator)) {
- path = path.substring(0, path.length() - 1);
- }
- return path;
- }
-
- public void testWriteAndRead() throws Exception {
- File file = new File("target/tmp/FileHelperTest.testWriteAndRead.txt");
- if (file.exists()) {
- file.delete();
- }
- file.getParentFile().mkdirs();
- assertTrue(file.createNewFile());
- FileHelper.writeStringAsFile(file, "foo\nbar");
- String content = FileHelper.readFileAsString(file);
- assertEquals("foo\nbar", content);
- assertTrue(file.delete());
- }
-
- public void testByteOrderMarksInputStream() throws Exception {
- String str1 = FileHelper.readFileAsString(new File("src/test/resources/unicode-text-utf16.txt"));
- assertEquals("hello", str1);
-
- String str2 = FileHelper.readFileAsString(new File("src/test/resources/unicode-text-utf8.txt"));
- assertEquals(str1, str2);
-
- String str3 = FileHelper.readFileAsString(new File("src/test/resources/unicode-text-utf16le.txt"));
- assertEquals(str2, str3);
-
- String str4 = FileHelper.readFileAsString(new File("src/test/resources/unicode-text-utf16be.txt"));
- assertEquals(str3, str4);
- }
-
- public void testCannotAppendAndInsertBom() throws Exception {
- try {
- FileHelper.getWriter(new File("foo"), "foo", true, true);
- fail("Exception expected");
- } catch (IllegalArgumentException e) {
- assertEquals("Can not insert BOM into appending writer", e.getMessage());
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/FormatHelperTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/FormatHelperTest.java b/core/src/test/java/org/eobjects/metamodel/util/FormatHelperTest.java
deleted file mode 100644
index eebe345..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/FormatHelperTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * 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.util;
-
-import java.text.NumberFormat;
-import java.util.Arrays;
-
-import org.eobjects.metamodel.schema.ColumnType;
-
-import junit.framework.TestCase;
-
-public class FormatHelperTest extends TestCase {
-
- public void testNumberFormat() throws Exception {
- NumberFormat format = FormatHelper.getUiNumberFormat();
- assertEquals("987643.21", format.format(987643.213456343));
- assertEquals("0.22", format.format(0.218456343));
- assertEquals("20.1", format.format(20.1));
- }
-
- @SuppressWarnings("unchecked")
- public void testFormatSqlValue() throws Exception {
- assertEquals("'foo'", FormatHelper.formatSqlValue(null, "foo"));
- assertEquals("1", FormatHelper.formatSqlValue(null, 1));
- assertEquals("NULL", FormatHelper.formatSqlValue(null, null));
- assertEquals(
- "TIMESTAMP '2011-07-24 00:00:00'",
- FormatHelper.formatSqlValue(ColumnType.TIMESTAMP,
- DateUtils.get(2011, Month.JULY, 24)));
- assertEquals(
- "DATE '2011-07-24'",
- FormatHelper.formatSqlValue(ColumnType.DATE,
- DateUtils.get(2011, Month.JULY, 24)));
- assertEquals(
- "TIME '00:00:00'",
- FormatHelper.formatSqlValue(ColumnType.TIME,
- DateUtils.get(2011, Month.JULY, 24)));
- assertEquals(
- "('foo' , 1 , 'bar' , 0.1234)",
- FormatHelper.formatSqlValue(null,
- Arrays.asList("foo", 1, "bar", 0.1234)));
- assertEquals(
- "('foo' , 1 , 'bar' , 0.1234)",
- FormatHelper.formatSqlValue(null, new Object[] { "foo", 1,
- "bar", 0.1234 }));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/InMemoryResourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/InMemoryResourceTest.java b/core/src/test/java/org/eobjects/metamodel/util/InMemoryResourceTest.java
deleted file mode 100644
index ee2995d..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/InMemoryResourceTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/**
- * 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.util;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import junit.framework.TestCase;
-
-public class InMemoryResourceTest extends TestCase {
-
- public void testScenario() throws Exception {
- InMemoryResource r = new InMemoryResource("foo/bar");
- assertEquals("bar", r.getName());
- assertEquals(-1, r.getLastModified());
- assertEquals(0, r.getSize());
- assertFalse(r.isReadOnly());
- assertTrue(r.isExists());
-
- r.write(new Action<OutputStream>() {
- @Override
- public void run(OutputStream out) throws Exception {
- out.write(1);
- out.write(2);
- out.write(3);
- }
- });
-
- assertEquals(3, r.getSize());
-
- r.read(new Action<InputStream>() {
- @Override
- public void run(InputStream in) throws Exception {
- assertEquals(1, in.read());
- assertEquals(2, in.read());
- assertEquals(3, in.read());
- assertEquals(-1, in.read());
- }
- });
-
- r.append(new Action<OutputStream>() {
- @Override
- public void run(OutputStream out) throws Exception {
- out.write(4);
- out.write(5);
- out.write(6);
- }
- });
-
- r.read(new Action<InputStream>() {
- @Override
- public void run(InputStream in) throws Exception {
- assertEquals(1, in.read());
- assertEquals(2, in.read());
- assertEquals(3, in.read());
- assertEquals(4, in.read());
- assertEquals(5, in.read());
- assertEquals(6, in.read());
- assertEquals(-1, in.read());
- }
- });
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/InclusionPredicateTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/InclusionPredicateTest.java b/core/src/test/java/org/eobjects/metamodel/util/InclusionPredicateTest.java
deleted file mode 100644
index 0225aff..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/InclusionPredicateTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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.util;
-
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-public class InclusionPredicateTest extends TestCase {
-
- public void testEval() throws Exception {
- InclusionPredicate<String> predicate = new InclusionPredicate<String>(Arrays.asList("foo","bar","baz"));
-
- assertTrue(predicate.eval("foo"));
- assertTrue(predicate.eval("bar"));
- assertTrue(predicate.eval("baz"));
-
- assertFalse(predicate.eval("hello world"));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/LazyRefTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/LazyRefTest.java b/core/src/test/java/org/eobjects/metamodel/util/LazyRefTest.java
deleted file mode 100644
index f68fb96..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/LazyRefTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- * 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.util;
-
-import java.util.concurrent.atomic.AtomicInteger;
-
-import junit.framework.TestCase;
-
-public class LazyRefTest extends TestCase {
-
- public void testRequestLoad() throws Exception {
- LazyRef<Integer> lazyRef = new LazyRef<Integer>() {
- private final AtomicInteger counter = new AtomicInteger();
-
- @Override
- protected Integer fetch() {
- return counter.incrementAndGet();
- }
- };
-
- lazyRef.requestLoad();
- Thread.sleep(20);
- Integer integer = lazyRef.get();
- assertEquals(1, integer.intValue());
- }
-
- public void testErrorHandling() throws Exception {
- LazyRef<Object> ref = new LazyRef<Object>() {
- @Override
- protected Object fetch() throws Throwable {
- throw new Exception("foo");
- }
- };
-
- assertNull(ref.get());
- assertEquals("foo", ref.getError().getMessage());
-
- // now with a runtime exception (retain previous behaviour in this
- // regard)
- ref = new LazyRef<Object>() {
- @Override
- protected Object fetch() throws Throwable {
- throw new IllegalStateException("bar");
- }
- };
-
- try {
- ref.get();
- fail("Exception expected");
- } catch (IllegalStateException e) {
- assertEquals("bar", e.getMessage());
- }
- }
-
- public void testGet() throws Exception {
- final AtomicInteger counter = new AtomicInteger();
- LazyRef<String> lazyRef = new LazyRef<String>() {
- @Override
- protected String fetch() {
- counter.incrementAndGet();
- return "foo";
- }
- };
-
- assertFalse(lazyRef.isFetched());
- assertEquals(0, counter.get());
-
- assertEquals("foo", lazyRef.get());
- assertEquals("foo", lazyRef.get());
- assertEquals("foo", lazyRef.get());
-
- assertTrue(lazyRef.isFetched());
- assertEquals(1, counter.get());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/MonthTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/MonthTest.java b/core/src/test/java/org/eobjects/metamodel/util/MonthTest.java
deleted file mode 100644
index 528caed..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/MonthTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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.util;
-
-import junit.framework.TestCase;
-
-public class MonthTest extends TestCase {
-
- public void testGetName() throws Exception {
- assertEquals("December", Month.DECEMBER.getName());
- }
-
- public void testNext() throws Exception {
- assertEquals(Month.APRIL, Month.MARCH.next());
- assertEquals(Month.JANUARY, Month.DECEMBER.next());
- }
-
- public void testPrevious() throws Exception {
- assertEquals(Month.FEBRUARY, Month.MARCH.previous());
- assertEquals(Month.DECEMBER, Month.JANUARY.previous());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/NumberComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/NumberComparatorTest.java b/core/src/test/java/org/eobjects/metamodel/util/NumberComparatorTest.java
deleted file mode 100644
index 211c967..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/NumberComparatorTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * 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.util;
-
-import java.util.Comparator;
-
-import junit.framework.TestCase;
-
-public class NumberComparatorTest extends TestCase {
-
- public void testDoubleAndIntegerComparison() throws Exception {
- Comparator<Object> comparator = NumberComparator.getComparator();
- assertEquals(0, comparator.compare(1, 1.0));
- }
-
- public void testComparable() throws Exception {
- Comparable<Object> comparable = NumberComparator.getComparable("125");
- assertEquals(0, comparable.compareTo(125));
- assertEquals(-1, comparable.compareTo(126));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/ObjectComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/ObjectComparatorTest.java b/core/src/test/java/org/eobjects/metamodel/util/ObjectComparatorTest.java
deleted file mode 100644
index 925318c..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/ObjectComparatorTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * 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.util;
-
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.TreeSet;
-
-import junit.framework.TestCase;
-
-public class ObjectComparatorTest extends TestCase {
-
- public void testString() throws Exception {
- Comparator<Object> c = ObjectComparator.getComparator();
- assertTrue(c.compare("aaaa", "bbbb") < 0);
-
- assertTrue(c.compare("w", "y") < 0);
- }
-
- public void testComparable() throws Exception {
- Comparable<Object> comparable = ObjectComparator.getComparable("aaaa");
- assertEquals(-1, comparable.compareTo("bbbb"));
- }
-
- public void testNull() throws Exception {
- Comparator<Object> comparator = ObjectComparator.getComparator();
- assertEquals(0, comparator.compare(null, null));
- assertEquals(1, comparator.compare("h", null));
- assertEquals(-1, comparator.compare(null, "h"));
-
- TreeSet<Object> set = new TreeSet<Object>(comparator);
- set.add("Hello");
- set.add(null);
- set.add(null);
- set.add(DateUtils.get(2010, Month.SEPTEMBER, 27));
- set.add(DateUtils.get(2010, Month.SEPTEMBER, 28));
- set.add(DateUtils.get(2010, Month.SEPTEMBER, 26));
-
- assertEquals(5, set.size());
- Iterator<Object> it = set.iterator();
- assertEquals(null, it.next());
- assertEquals("Hello", it.next());
- assertEquals(DateUtils.get(2010, Month.SEPTEMBER, 26), it.next());
- assertEquals(DateUtils.get(2010, Month.SEPTEMBER, 27), it.next());
- assertEquals(DateUtils.get(2010, Month.SEPTEMBER, 28), it.next());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/SerializableRefTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/SerializableRefTest.java b/core/src/test/java/org/eobjects/metamodel/util/SerializableRefTest.java
deleted file mode 100644
index 6e1c05e..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/SerializableRefTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * 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.util;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.StringTokenizer;
-
-import junit.framework.TestCase;
-
-public class SerializableRefTest extends TestCase {
-
- public void testSerialize() throws Exception {
- SerializableRef<String> ref = new SerializableRef<String>("Foobar");
- assertNotNull(ref.get());
-
- SerializableRef<String> copy = copy(ref);
- assertEquals("Foobar", copy.get());
- }
-
- public void testDontSerialize() throws Exception {
- SerializableRef<StringTokenizer> ref = new SerializableRef<StringTokenizer>(new StringTokenizer("foobar"));
- assertNotNull(ref.get());
-
- SerializableRef<StringTokenizer> copy = copy(ref);
- assertNull(copy.get());
- }
-
- @SuppressWarnings("unchecked")
- private <E> SerializableRef<E> copy(SerializableRef<E> ref) throws Exception {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream os = new ObjectOutputStream(baos);
- os.writeObject(ref);
- os.flush();
- os.close();
-
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- ObjectInputStream is = new ObjectInputStream(bais);
- Object obj = is.readObject();
- is.close();
- return (SerializableRef<E>) obj;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/SimpleRefTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/SimpleRefTest.java b/core/src/test/java/org/eobjects/metamodel/util/SimpleRefTest.java
deleted file mode 100644
index fcc89c3..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/SimpleRefTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * 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.util;
-
-import junit.framework.TestCase;
-
-public class SimpleRefTest extends TestCase {
-
- public void testGet() throws Exception {
- Ref<String> lazyRef = new ImmutableRef<String>("foo");
-
- assertEquals("foo", lazyRef.get());
-
- lazyRef = ImmutableRef.of("foo");
-
- assertEquals("foo", lazyRef.get());
- assertEquals("foo", lazyRef.get());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/TimeComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/TimeComparatorTest.java b/core/src/test/java/org/eobjects/metamodel/util/TimeComparatorTest.java
deleted file mode 100644
index 4b43dcb..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/TimeComparatorTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/**
- * 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.util;
-
-import java.text.DateFormat;
-import java.util.Comparator;
-import java.util.Date;
-
-import junit.framework.TestCase;
-
-public class TimeComparatorTest extends TestCase {
-
- public void testCompare() throws Exception {
- Comparator<Object> c = TimeComparator.getComparator();
- Date d1 = new Date();
- Thread.sleep(100);
- Date d2 = new Date();
- assertEquals(0, c.compare(d1, d1));
- assertEquals(-1, c.compare(d1, d2));
- assertEquals(1, c.compare(d2, d1));
-
- assertEquals(1, c.compare(d2, "2005-10-08"));
- assertEquals(1, c.compare("2006-11-09", "2005-10-08"));
- }
-
- public void testComparable() throws Exception {
- Comparable<Object> comparable = TimeComparator
- .getComparable(new Date());
- Thread.sleep(100);
- assertEquals(-1, comparable.compareTo(new Date()));
- }
-
- public void testToDate() throws Exception {
- DateFormat dateFormat = DateUtils
- .createDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
-
- assertEquals("2008-11-04 00:00:00.000",
- dateFormat.format(TimeComparator.toDate("08-11-04")));
-
- assertEquals("2010-09-21 14:06:00.000",
- dateFormat.format(TimeComparator.toDate("2010-09-21 14:06")));
-
- assertEquals("2010-09-21 14:06:13.000",
- dateFormat.format(TimeComparator.toDate("2010-09-21 14:06:13")));
-
- assertEquals("2010-09-21 14:06:13.009",
- dateFormat.format(TimeComparator
- .toDate("2010-09-21 14:06:13.009")));
-
- assertEquals("2000-12-31 02:30:05.100",
- dateFormat.format(TimeComparator
- .toDate("2000-12-31 02:30:05.100")));
- }
-
- public void testToDateOfDateToString() throws Exception {
- Date date = new Date();
- String dateString = date.toString();
- Date convertedDate = TimeComparator.toDate(dateString);
-
- String convertedToString = convertedDate.toString();
- assertEquals(dateString, convertedToString);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/ToStringComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/ToStringComparatorTest.java b/core/src/test/java/org/eobjects/metamodel/util/ToStringComparatorTest.java
deleted file mode 100644
index 684c714..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/ToStringComparatorTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * 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.util;
-
-import java.util.Comparator;
-
-import junit.framework.TestCase;
-import org.eobjects.metamodel.util.ToStringComparator;
-
-public class ToStringComparatorTest extends TestCase {
-
- private Comparator<Object> comparator = ToStringComparator.getComparator();
-
- public void testNotNull() throws Exception {
- assertEquals(4, comparator.compare("foo", "bar"));
- assertEquals(-4, comparator.compare("bar", "foo"));
- }
-
- public void testNull() throws Exception {
- int result = comparator.compare(null, null);
- assertEquals(-1, result);
-
- result = comparator.compare(1, null);
- assertEquals(1, result);
-
- result = comparator.compare(null, 1);
- assertEquals(-1, result);
- }
-
- public void testComparable() throws Exception {
- Comparable<Object> comparable = ToStringComparator
- .getComparable("aaaa");
- assertEquals(-1, comparable.compareTo("bbbb"));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/UrlResourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/UrlResourceTest.java b/core/src/test/java/org/eobjects/metamodel/util/UrlResourceTest.java
deleted file mode 100644
index a94eee2..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/UrlResourceTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * 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.util;
-
-import junit.framework.TestCase;
-
-public class UrlResourceTest extends TestCase {
-
- public void testGetName() throws Exception {
- UrlResource resource = new UrlResource("http://eobjects.org/foo.txt");
- assertEquals("foo.txt", resource.getName());
-
- resource = new UrlResource("http://eobjects.org/");
- assertEquals("http://eobjects.org/", resource.getName());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/WeekdayTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/WeekdayTest.java b/core/src/test/java/org/eobjects/metamodel/util/WeekdayTest.java
deleted file mode 100644
index f5f7bb6..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/WeekdayTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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.util;
-
-import junit.framework.TestCase;
-
-public class WeekdayTest extends TestCase {
-
- public void testGetName() throws Exception {
- assertEquals("Monday", Weekday.MONDAY.getName());
- }
-
- public void testNext() throws Exception {
- assertEquals(Weekday.TUESDAY, Weekday.MONDAY.next());
- assertEquals(Weekday.MONDAY, Weekday.SUNDAY.next());
- }
-
- public void testPrevious() throws Exception {
- assertEquals(Weekday.SUNDAY, Weekday.MONDAY.previous());
- assertEquals(Weekday.SATURDAY, Weekday.SUNDAY.previous());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/WildcardPatternTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/WildcardPatternTest.java b/core/src/test/java/org/eobjects/metamodel/util/WildcardPatternTest.java
deleted file mode 100644
index 13da97b..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/WildcardPatternTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * 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.util;
-
-import junit.framework.TestCase;
-
-public class WildcardPatternTest extends TestCase {
-
- public void testMatches() throws Exception {
- WildcardPattern pattern = new WildcardPattern("foo%bar", '%');
- assertTrue(pattern.matches("foobar"));
- assertTrue(pattern.matches("foofoobar"));
- assertFalse(pattern.matches("foobarbar"));
- assertFalse(pattern.matches("w00p"));
-
- pattern = new WildcardPattern("*foo*bar", '*');
- assertTrue(pattern.matches("foobar"));
- assertTrue(pattern.matches("foofoobar"));
- assertFalse(pattern.matches("foobarbar"));
- assertFalse(pattern.matches("w00p"));
-
- pattern = new WildcardPattern("foo%bar%", '%');
- assertTrue(pattern.matches("foobar"));
- assertTrue(pattern.matches("foofoobar"));
- assertTrue(pattern.matches("foobarbar"));
- assertFalse(pattern.matches("w00p"));
-
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataContext.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataContext.java b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataContext.java
new file mode 100644
index 0000000..ac626e6
--- /dev/null
+++ b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataContext.java
@@ -0,0 +1,254 @@
+/**
+ * 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.couchdb;
+
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.codehaus.jackson.JsonNode;
+import org.ektorp.CouchDbConnector;
+import org.ektorp.CouchDbInstance;
+import org.ektorp.StreamingViewResult;
+import org.ektorp.ViewQuery;
+import org.ektorp.ViewResult.Row;
+import org.ektorp.http.HttpClient;
+import org.ektorp.http.StdHttpClient;
+import org.ektorp.impl.StdCouchDbInstance;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.MetaModelHelper;
+import org.eobjects.metamodel.QueryPostprocessDataContext;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.UpdateableDataContext;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.MutableSchema;
+import org.eobjects.metamodel.schema.MutableTable;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.SimpleTableDef;
+
+/**
+ * DataContext implementation for CouchDB
+ */
+public class CouchDbDataContext extends QueryPostprocessDataContext implements UpdateableDataContext {
+
+ public static final int DEFAULT_PORT = 5984;
+
+ public static final String FIELD_ID = "_id";
+ public static final String FIELD_REV = "_rev";
+
+ private static final String SCHEMA_NAME = "CouchDB";
+
+ private final CouchDbInstance _couchDbInstance;
+ private final SimpleTableDef[] _tableDefs;
+
+ public CouchDbDataContext(StdHttpClient.Builder httpClientBuilder, SimpleTableDef... tableDefs) {
+ this(httpClientBuilder.build(), tableDefs);
+ }
+
+ public CouchDbDataContext(StdHttpClient.Builder httpClientBuilder) {
+ this(httpClientBuilder.build());
+ }
+
+ public CouchDbDataContext(HttpClient httpClient, SimpleTableDef... tableDefs) {
+ this(new StdCouchDbInstance(httpClient), tableDefs);
+ }
+
+ public CouchDbDataContext(HttpClient httpClient) {
+ this(new StdCouchDbInstance(httpClient));
+ }
+
+ public CouchDbDataContext(CouchDbInstance couchDbInstance) {
+ this(couchDbInstance, detectSchema(couchDbInstance));
+ }
+
+ public CouchDbDataContext(CouchDbInstance couchDbInstance, SimpleTableDef... tableDefs) {
+ // the instance represents a handle to the whole couchdb cluster
+ _couchDbInstance = couchDbInstance;
+ _tableDefs = tableDefs;
+ }
+
+ public static SimpleTableDef[] detectSchema(CouchDbInstance couchDbInstance) {
+ final List<SimpleTableDef> tableDefs = new ArrayList<SimpleTableDef>();
+ final List<String> databaseNames = couchDbInstance.getAllDatabases();
+ for (final String databaseName : databaseNames) {
+
+ if (databaseName.startsWith("_")) {
+ // don't add system tables
+ continue;
+ }
+
+ CouchDbConnector connector = couchDbInstance.createConnector(databaseName, false);
+
+ SimpleTableDef tableDef = detectTable(connector);
+ tableDefs.add(tableDef);
+ }
+ return tableDefs.toArray(new SimpleTableDef[tableDefs.size()]);
+ }
+
+ public static SimpleTableDef detectTable(CouchDbConnector connector) {
+ final SortedMap<String, Set<ColumnType>> columnsAndTypes = new TreeMap<String, Set<ColumnType>>();
+
+ final StreamingViewResult streamingView = connector.queryForStreamingView(new ViewQuery().allDocs().includeDocs(true)
+ .limit(1000));
+ try {
+ final Iterator<Row> rowIterator = streamingView.iterator();
+ while (rowIterator.hasNext()) {
+ Row row = rowIterator.next();
+ JsonNode doc = row.getDocAsNode();
+
+ final Iterator<Entry<String, JsonNode>> fieldIterator = doc.getFields();
+ while (fieldIterator.hasNext()) {
+ Entry<String, JsonNode> entry = fieldIterator.next();
+ String key = entry.getKey();
+
+ Set<ColumnType> types = columnsAndTypes.get(key);
+
+ if (types == null) {
+ types = EnumSet.noneOf(ColumnType.class);
+ columnsAndTypes.put(key, types);
+ }
+
+ JsonNode value = entry.getValue();
+ if (value == null || value.isNull()) {
+ // do nothing
+ } else if (value.isTextual()) {
+ types.add(ColumnType.VARCHAR);
+ } else if (value.isArray()) {
+ types.add(ColumnType.LIST);
+ } else if (value.isObject()) {
+ types.add(ColumnType.MAP);
+ } else if (value.isBoolean()) {
+ types.add(ColumnType.BOOLEAN);
+ } else if (value.isInt()) {
+ types.add(ColumnType.INTEGER);
+ } else if (value.isLong()) {
+ types.add(ColumnType.BIGINT);
+ } else if (value.isDouble()) {
+ types.add(ColumnType.DOUBLE);
+ }
+ }
+
+ }
+ } finally {
+ streamingView.close();
+ }
+
+ final String[] columnNames = new String[columnsAndTypes.size()];
+ final ColumnType[] columnTypes = new ColumnType[columnsAndTypes.size()];
+
+ int i = 0;
+ for (Entry<String, Set<ColumnType>> columnAndTypes : columnsAndTypes.entrySet()) {
+ final String columnName = columnAndTypes.getKey();
+ final Set<ColumnType> columnTypeSet = columnAndTypes.getValue();
+ final ColumnType columnType;
+ if (columnTypeSet.isEmpty()) {
+ columnType = ColumnType.OTHER;
+ } else if (columnTypeSet.size() == 1) {
+ columnType = columnTypeSet.iterator().next();
+ } else {
+ // TODO: Select best type?
+ columnType = ColumnType.OTHER;
+ }
+ columnNames[i] = columnName;
+ columnTypes[i] = columnType;
+ i++;
+ }
+
+ final SimpleTableDef tableDef = new SimpleTableDef(connector.getDatabaseName(), columnNames, columnTypes);
+ return tableDef;
+ }
+
+ public CouchDbInstance getCouchDbInstance() {
+ return _couchDbInstance;
+ }
+
+ @Override
+ protected Schema getMainSchema() throws MetaModelException {
+ final MutableSchema schema = new MutableSchema(SCHEMA_NAME);
+ for (final SimpleTableDef tableDef : _tableDefs) {
+ final MutableTable table = tableDef.toTable().setSchema(schema);
+ CouchDbTableCreationBuilder.addMandatoryColumns(table);
+ schema.addTable(table);
+ }
+ return schema;
+ }
+
+ @Override
+ protected String getMainSchemaName() throws MetaModelException {
+ return SCHEMA_NAME;
+ }
+
+ @Override
+ protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int firstRow, int maxRows) {
+ // the connector represents a handle to the the couchdb "database".
+ final String databaseName = table.getName();
+ final CouchDbConnector connector = _couchDbInstance.createConnector(databaseName, false);
+
+ ViewQuery query = new ViewQuery().allDocs().includeDocs(true);
+
+ if (maxRows > 0) {
+ query = query.limit(maxRows);
+ }
+ if (firstRow > 1) {
+ final int skip = firstRow - 1;
+ query = query.skip(skip);
+ }
+
+ final StreamingViewResult streamingView = connector.queryForStreamingView(query);
+
+ final SelectItem[] selectItems = MetaModelHelper.createSelectItems(columns);
+ return new CouchDbDataSet(selectItems, streamingView);
+ }
+
+ @Override
+ protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+ return materializeMainSchemaTable(table, columns, 1, maxRows);
+ }
+
+ @Override
+ protected Number executeCountQuery(Table table, List<FilterItem> whereItems, boolean functionApproximationAllowed) {
+ if (whereItems.isEmpty()) {
+ String databaseName = table.getName();
+ CouchDbConnector connector = _couchDbInstance.createConnector(databaseName, false);
+ long docCount = connector.getDbInfo().getDocCount();
+ return docCount;
+ }
+ return null;
+ }
+
+ @Override
+ public void executeUpdate(UpdateScript script) {
+ CouchDbUpdateCallback callback = new CouchDbUpdateCallback(this);
+ try {
+ script.run(callback);
+ } finally {
+ callback.close();
+ }
+ }
+}
[21/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/convert/StringToDoubleConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/convert/StringToDoubleConverterTest.java b/core/src/test/java/org/eobjects/metamodel/convert/StringToDoubleConverterTest.java
deleted file mode 100644
index a44fa1d..0000000
--- a/core/src/test/java/org/eobjects/metamodel/convert/StringToDoubleConverterTest.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.convert;
-
-import junit.framework.TestCase;
-
-public class StringToDoubleConverterTest extends TestCase {
-
- private StringToDoubleConverter conv = new StringToDoubleConverter();
-
- public void testToVirtual() throws Exception {
- assertNull(conv.toVirtualValue(null));
- assertNull(conv.toVirtualValue(""));
- assertEquals(123d, conv.toVirtualValue("123").doubleValue());
- assertEquals(123.0d, conv.toVirtualValue("123.0").doubleValue());
- }
-
- public void testToPhysical() throws Exception {
- assertNull(conv.toPhysicalValue(null));
- assertEquals("123.0", conv.toPhysicalValue(123d));
- assertEquals("123.0", conv.toPhysicalValue(123.0d));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/convert/StringToIntegerConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/convert/StringToIntegerConverterTest.java b/core/src/test/java/org/eobjects/metamodel/convert/StringToIntegerConverterTest.java
deleted file mode 100644
index 41c301e..0000000
--- a/core/src/test/java/org/eobjects/metamodel/convert/StringToIntegerConverterTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * 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.convert;
-
-import junit.framework.TestCase;
-
-public class StringToIntegerConverterTest extends TestCase {
-
- private StringToIntegerConverter conv = new StringToIntegerConverter();
-
- public void testToVirtual() throws Exception {
- assertNull(conv.toVirtualValue(null));
- assertNull(conv.toVirtualValue(""));
- assertEquals(123, conv.toVirtualValue("123").intValue());
- }
-
- public void testToPhysical() throws Exception {
- assertNull(conv.toPhysicalValue(null));
- assertEquals("123", conv.toPhysicalValue(123));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/create/AbstractCreateTableBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/create/AbstractCreateTableBuilderTest.java b/core/src/test/java/org/eobjects/metamodel/create/AbstractCreateTableBuilderTest.java
deleted file mode 100644
index b5a44aa..0000000
--- a/core/src/test/java/org/eobjects/metamodel/create/AbstractCreateTableBuilderTest.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/**
- * 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 junit.framework.TestCase;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.schema.ColumnType;
-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.Table;
-import org.eobjects.metamodel.util.MutableRef;
-
-public class AbstractCreateTableBuilderTest extends TestCase {
-
- public void testExecute() throws Exception {
- final MutableRef<Boolean> executed = new MutableRef<Boolean>(false);
-
- Schema schema = new MutableSchema("schema");
- AbstractTableCreationBuilder<UpdateCallback> builder = new AbstractTableCreationBuilder<UpdateCallback>(null,
- schema, "tablename") {
- @Override
- public Table execute() throws MetaModelException {
- executed.set(true);
- return getTable();
- }
- };
-
- assertFalse(executed.get().booleanValue());
-
- builder.withColumn("foo").ofType(ColumnType.VARCHAR).asPrimaryKey().ofNativeType("vch").ofSize(1234)
- .nullable(true);
- builder.withColumn("bar").withColumn("baz").nullable(false);
- Table table = builder.execute();
-
- assertTrue(executed.get().booleanValue());
-
- assertEquals("tablename", table.getName());
- assertEquals(3, table.getColumnCount());
- assertEquals(
- "Column[name=foo,columnNumber=0,type=VARCHAR,nullable=true,nativeType=vch,columnSize=1234]",
- table.getColumns()[0].toString());
- assertEquals(
- "Column[name=bar,columnNumber=1,type=null,nullable=null,nativeType=null,columnSize=null]",
- table.getColumns()[1].toString());
- assertEquals(
- "Column[name=baz,columnNumber=2,type=null,nullable=false,nativeType=null,columnSize=null]",
- table.getColumns()[2].toString());
-
- assertEquals("CREATE TABLE schema.tablename (foo VARCHAR(1234) PRIMARY KEY,bar,baz NOT NULL)", builder.toSql());
- }
-
- public void testLike() throws Exception {
- final MutableRef<Boolean> executed = new MutableRef<Boolean>(false);
-
- Schema schema = new MutableSchema("schema");
- AbstractTableCreationBuilder<UpdateCallback> builder = new AbstractTableCreationBuilder<UpdateCallback>(null,
- schema, "tablename") {
- @Override
- public Table execute() throws MetaModelException {
- executed.set(true);
- return toTable();
- }
- };
-
- assertFalse(executed.get().booleanValue());
-
- MutableTable likeTable = new MutableTable("blablablabla");
- likeTable.addColumn(new MutableColumn("foo", ColumnType.VARCHAR, likeTable, 0, 1234, "vch", true, null, false,
- null));
- likeTable.addColumn(new MutableColumn("bar"));
- likeTable.addColumn(new MutableColumn("baz"));
-
- builder.like(likeTable);
- Table table = builder.execute();
-
- assertTrue(executed.get().booleanValue());
-
- assertEquals("tablename", table.getName());
- assertEquals(3, table.getColumnCount());
- assertEquals(
- "Column[name=foo,columnNumber=0,type=VARCHAR,nullable=true,nativeType=vch,columnSize=1234]",
- table.getColumns()[0].toString());
- assertEquals(
- "Column[name=bar,columnNumber=1,type=null,nullable=null,nativeType=null,columnSize=null]",
- table.getColumns()[1].toString());
- assertEquals(
- "Column[name=baz,columnNumber=2,type=null,nullable=null,nativeType=null,columnSize=null]",
- table.getColumns()[2].toString());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/create/SyntaxExamplesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/create/SyntaxExamplesTest.java b/core/src/test/java/org/eobjects/metamodel/create/SyntaxExamplesTest.java
deleted file mode 100644
index 264fd91..0000000
--- a/core/src/test/java/org/eobjects/metamodel/create/SyntaxExamplesTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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 junit.framework.TestCase;
-
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-public abstract class SyntaxExamplesTest extends TestCase {
-
- private TableCreatable dc;
- private Table table;
- private Column col;
- private Schema schema;
-
- public void testCreateLikeExistingStructure() throws Exception {
- dc.createTable(schema, "foo").like(table).withColumn("bar").like(col)
- .nullable(false).execute();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/data/DataSetIteratorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/data/DataSetIteratorTest.java b/core/src/test/java/org/eobjects/metamodel/data/DataSetIteratorTest.java
deleted file mode 100644
index 96443d2..0000000
--- a/core/src/test/java/org/eobjects/metamodel/data/DataSetIteratorTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * 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 org.easymock.EasyMock;
-
-import junit.framework.TestCase;
-
-public class DataSetIteratorTest extends TestCase {
-
- public void testHasNextAndNextAndClose() throws Exception {
- DataSet ds = EasyMock.createMock(DataSet.class);
- Row row = EasyMock.createMock(Row.class);
-
- EasyMock.expect(ds.next()).andReturn(true);
- EasyMock.expect(ds.getRow()).andReturn(row);
- EasyMock.expect(ds.next()).andReturn(true);
- EasyMock.expect(ds.getRow()).andReturn(row);
- EasyMock.expect(ds.next()).andReturn(false);
- ds.close();
-
- EasyMock.replay(ds, row);
-
- DataSetIterator it = new DataSetIterator(ds);
-
- // multiple hasNext calls does not iterate before next is called
- assertTrue(it.hasNext());
- assertTrue(it.hasNext());
- assertTrue(it.hasNext());
-
- assertSame(row, it.next());
-
- assertTrue(it.hasNext());
- assertTrue(it.hasNext());
-
- assertSame(row, it.next());
- assertFalse(it.hasNext());
- assertFalse(it.hasNext());
- assertFalse(it.hasNext());
-
- assertNull(it.next());
-
- EasyMock.verify(ds, row);
- }
-
- public void testRemove() throws Exception {
- DataSet ds = EasyMock.createMock(DataSet.class);
- DataSetIterator it = new DataSetIterator(ds);
-
- try {
- it.remove();
- fail("Exception expected");
- } catch (UnsupportedOperationException e) {
- assertEquals("DataSet is read-only, remove() is not supported.",
- e.getMessage());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/data/DataSetTableModelTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/data/DataSetTableModelTest.java b/core/src/test/java/org/eobjects/metamodel/data/DataSetTableModelTest.java
deleted file mode 100644
index b125f8f..0000000
--- a/core/src/test/java/org/eobjects/metamodel/data/DataSetTableModelTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * 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.List;
-
-import javax.swing.table.TableModel;
-
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.MutableColumn;
-
-import junit.framework.TestCase;
-
-public class DataSetTableModelTest extends TestCase {
-
- public void testToTableModel() throws Exception {
- SelectItem[] selectItems = MetaModelHelper.createSelectItems(new MutableColumn("CUSTOMERNUMBER"),
- new MutableColumn("CUSTOMERNAME"), new MutableColumn("CONTACTLASTNAME"));
- CachingDataSetHeader header = new CachingDataSetHeader(selectItems);
- List<Row> rows = new ArrayList<Row>();
- rows.add(new DefaultRow(header, new Object[] { 1, "John", "Doe" }));
- rows.add(new DefaultRow(header, new Object[] { 2, "John", "Taylor" }));
- DataSet data = new InMemoryDataSet(header, rows);
-
- @SuppressWarnings("deprecation")
- TableModel tableModel = data.toTableModel();
- data.close();
-
- assertEquals(3, tableModel.getColumnCount());
- assertEquals("CUSTOMERNUMBER", tableModel.getColumnName(0));
- assertEquals("CUSTOMERNAME", tableModel.getColumnName(1));
- assertEquals("CONTACTLASTNAME", tableModel.getColumnName(2));
- assertEquals(2, tableModel.getRowCount());
-
- // Take a small sample from the data
- assertEquals("Taylor", tableModel.getValueAt(1, 2).toString());
-
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/data/DefaultRowTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/data/DefaultRowTest.java b/core/src/test/java/org/eobjects/metamodel/data/DefaultRowTest.java
deleted file mode 100644
index 0cac74f..0000000
--- a/core/src/test/java/org/eobjects/metamodel/data/DefaultRowTest.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/**
- * 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.FileInputStream;
-import java.io.ObjectInputStream;
-import java.lang.reflect.Field;
-
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.util.FileHelper;
-
-import junit.framework.TestCase;
-
-public class DefaultRowTest extends TestCase {
-
- SelectItem[] items = new SelectItem[] { new SelectItem(new MutableColumn("foo")),
- new SelectItem(new MutableColumn("bar")) };
- Object[] values = new Object[] { "foo", "bar" };
-
- public void testDeserializeBackwardsCompatible() throws Exception {
- Object obj;
- FileInputStream fileIn = new FileInputStream("src/test/resources/metamodel-3.0-default-row.ser");
- try {
- ObjectInputStream ois = new ObjectInputStream(fileIn);
- obj = ois.readObject();
- ois.close();
- } finally {
- FileHelper.safeClose(fileIn);
- }
-
- assertTrue(obj instanceof Row);
- assertTrue(obj instanceof DefaultRow);
-
- Row row = (Row) obj;
- assertEquals(2, row.size());
- SelectItem[] selectItems = row.getSelectItems();
- assertEquals("foo", selectItems[0].toString());
- assertEquals("bar", selectItems[1].toString());
-
- assertEquals("foo", row.getValue(0));
- assertEquals("bar", row.getValue(1));
-
- assertEquals(Style.NO_STYLE, row.getStyle(0));
- assertEquals(Style.NO_STYLE, row.getStyle(1));
- }
-
- public void testGetValueOfColumn() throws Exception {
- DefaultRow row = new DefaultRow(new SimpleDataSetHeader(items), values);
- assertEquals("foo", row.getValue(new MutableColumn("foo")));
- assertNull(row.getValue(new MutableColumn("hello world")));
- }
-
- public void testCustomStyles() throws Exception {
- Style[] styles = new Style[] { Style.NO_STYLE, new StyleBuilder().bold().create() };
- DefaultRow row = new DefaultRow(new SimpleDataSetHeader(items), values, styles);
-
- Field field = DefaultRow.class.getDeclaredField("_styles");
- assertNotNull(field);
-
- field.setAccessible(true);
- assertNotNull(field.get(row));
-
- assertEquals(Style.NO_STYLE, row.getStyle(0));
- assertEquals("font-weight: bold;", row.getStyle(1).toCSS());
- }
-
- public void testNoStylesReference() throws Exception {
- Style[] styles = new Style[] { Style.NO_STYLE, Style.NO_STYLE };
- DefaultRow row = new DefaultRow(new SimpleDataSetHeader(items), values, styles);
-
- Field field = DefaultRow.class.getDeclaredField("_styles");
- assertNotNull(field);
-
- field.setAccessible(true);
- assertNull(field.get(row));
-
- assertEquals(Style.NO_STYLE, row.getStyle(0));
- assertEquals(Style.NO_STYLE, row.getStyle(items[0]));
- assertEquals(Style.NO_STYLE, row.getStyle(items[0].getColumn()));
- }
-
- public void testNullStyle() throws Exception {
- Style[] styles = new Style[] { Style.NO_STYLE, null };
-
- try {
- new DefaultRow(new SimpleDataSetHeader(items), values, styles);
- fail("Exception expected");
- } catch (IllegalArgumentException e) {
- assertEquals("Elements in the style array cannot be null", e.getMessage());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/data/FirstRowDataSetTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/data/FirstRowDataSetTest.java b/core/src/test/java/org/eobjects/metamodel/data/FirstRowDataSetTest.java
deleted file mode 100644
index 645dbbe..0000000
--- a/core/src/test/java/org/eobjects/metamodel/data/FirstRowDataSetTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/**
- * 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.List;
-
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.MutableColumn;
-
-import junit.framework.TestCase;
-
-public class FirstRowDataSetTest extends TestCase {
-
- private List<Row> rows;
- private SelectItem[] items = new SelectItem[] { new SelectItem(new MutableColumn("foobar")) };
- private DataSetHeader header = new SimpleDataSetHeader(items);
- private InMemoryDataSet dataSet;
-
- protected void setUp() throws Exception {
- rows = new ArrayList<Row>();
- rows.add(new DefaultRow(header, new Object[] { 1 }));
- rows.add(new DefaultRow(header, new Object[] { 2 }));
- rows.add(new DefaultRow(header, new Object[] { 3 }));
- rows.add(new DefaultRow(header, new Object[] { 4 }));
- rows.add(new DefaultRow(header, new Object[] { 5 }));
- dataSet = new InMemoryDataSet(header, rows);
- };
-
- public void testHighestPossibleOffset() throws Exception {
- FirstRowDataSet ds = new FirstRowDataSet(dataSet, 5);
- assertTrue(ds.next());
- assertEquals(5, ds.getRow().getValue(0));
- assertFalse(ds.next());
-
- ds.close();
- }
-
- public void testOffsetHigherThanSize() throws Exception {
- FirstRowDataSet ds = new FirstRowDataSet(dataSet, 8);
- assertFalse(ds.next());
-
- ds.close();
- }
-
- public void testOneOffset() throws Exception {
- FirstRowDataSet ds = new FirstRowDataSet(dataSet, 1);
- assertTrue(ds.next());
- assertEquals(1, ds.getRow().getValue(0));
- ds.close();
- }
-
- public void testVanillaScenario() throws Exception {
- FirstRowDataSet ds = new FirstRowDataSet(dataSet, 2);
- assertTrue(ds.next());
- assertEquals(2, ds.getRow().getValue(0));
- assertTrue(ds.next());
- assertEquals(3, ds.getRow().getValue(0));
- assertTrue(ds.next());
- assertEquals(4, ds.getRow().getValue(0));
- assertTrue(ds.next());
- assertEquals(5, ds.getRow().getValue(0));
- assertFalse(ds.next());
-
- ds.close();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/data/RowPublisherDataSetTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/data/RowPublisherDataSetTest.java b/core/src/test/java/org/eobjects/metamodel/data/RowPublisherDataSetTest.java
deleted file mode 100644
index 03b078e..0000000
--- a/core/src/test/java/org/eobjects/metamodel/data/RowPublisherDataSetTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- * 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 junit.framework.TestCase;
-
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.util.Action;
-
-public class RowPublisherDataSetTest extends TestCase {
-
- public void testMaxSize() throws Exception {
- SelectItem[] selectItems = new SelectItem[2];
- selectItems[0] = new SelectItem(new MutableColumn("foos"));
- selectItems[1] = new SelectItem(new MutableColumn("bars"));
- DataSet ds = new RowPublisherDataSet(selectItems, 5,
- new Action<RowPublisher>() {
- @Override
- public void run(RowPublisher publisher) throws Exception {
-
- // we want to exceed the buffer size
- int iterations = RowPublisherImpl.BUFFER_SIZE * 2;
-
- for (int i = 0; i < iterations; i++) {
- publisher.publish(new Object[] { "foo" + i,
- "bar" + i });
- }
- }
- });
-
- assertTrue(ds.next());
- assertEquals("Row[values=[foo0, bar0]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertTrue(ds.next());
- assertTrue(ds.next());
- assertTrue(ds.next());
- assertEquals("Row[values=[foo4, bar4]]", ds.getRow().toString());
- assertFalse(ds.next());
-
- ds.close();
- }
-
- public void testExceptionInAction() throws Exception {
- SelectItem[] selectItems = new SelectItem[2];
- selectItems[0] = new SelectItem(new MutableColumn("foos"));
- selectItems[1] = new SelectItem(new MutableColumn("bars"));
- DataSet ds = new RowPublisherDataSet(selectItems, 5,
- new Action<RowPublisher>() {
- @Override
- public void run(RowPublisher publisher) throws Exception {
- publisher.publish(new Object[] { "foo0", "bar0" });
- publisher.publish(new Object[] { "foo1", "bar1" });
- throw new IllegalStateException("foobar!");
- }
- });
-
- assertTrue(ds.next());
- assertEquals("Row[values=[foo0, bar0]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[foo1, bar1]]", ds.getRow().toString());
-
- try {
- ds.next();
- fail("Exception expected");
- } catch (Exception e) {
- assertEquals("foobar!", e.getMessage());
- assertEquals(IllegalStateException.class, e.getClass());
- } finally {
- ds.close();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/data/RowTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/data/RowTest.java b/core/src/test/java/org/eobjects/metamodel/data/RowTest.java
deleted file mode 100644
index 4c8628e..0000000
--- a/core/src/test/java/org/eobjects/metamodel/data/RowTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * 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 org.eobjects.metamodel.MetaModelTestCase;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-public class RowTest extends MetaModelTestCase {
-
- public void testRow() throws Exception {
- Schema schema = getExampleSchema();
- Table projectTable = schema.getTableByName(TABLE_PROJECT);
- SelectItem item = new SelectItem(projectTable.getColumns()[0]);
- SelectItem[] items = { item };
- DataSetHeader header = new CachingDataSetHeader(items);
- Object[] values = { "foobar" };
- Row row = new DefaultRow(header, values);
- assertEquals("Row[values=[foobar]]", row.toString());
- assertEquals("foobar", row.getValue(0));
- assertEquals("foobar", row.getValues()[0]);
- assertEquals("foobar", row.getValue(item));
- assertEquals(item, row.getSelectItems()[0]);
- }
-
- public void testGetSubSelection() throws Exception {
- Schema schema = getExampleSchema();
- Table projectTable = schema.getTableByName(TABLE_PROJECT);
- SelectItem item1 = new SelectItem(projectTable.getColumns()[0]);
- SelectItem item2 = new SelectItem(projectTable.getColumns()[0]);
- SelectItem[] items = { item1, item2 };
- DataSetHeader header = new CachingDataSetHeader(items);
- Object[] values = { "foo", "bar" };
- Row row = new DefaultRow(header, values);
- row = row.getSubSelection(new SimpleDataSetHeader(new SelectItem[] { item1 }));
- assertEquals(1, row.getSelectItems().length);
- assertEquals(1, row.getValues().length);
- assertEquals("foo", row.getValue(0));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/data/StyleBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/data/StyleBuilderTest.java b/core/src/test/java/org/eobjects/metamodel/data/StyleBuilderTest.java
deleted file mode 100644
index e75c5b0..0000000
--- a/core/src/test/java/org/eobjects/metamodel/data/StyleBuilderTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * 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 org.eobjects.metamodel.data.Style.Color;
-
-import junit.framework.TestCase;
-
-public class StyleBuilderTest extends TestCase {
-
- public void testDefaultColors() throws Exception {
- StyleBuilder sb = new StyleBuilder();
-
- sb.foreground(1, 1, 1);
- assertEquals("color: rgb(1,1,1);", sb.create().toCSS());
-
- sb.foreground(0, 0, 0);
- assertEquals("", sb.create().toCSS());
-
- sb.background(0, 0, 0);
- assertEquals("background-color: rgb(0,0,0);", sb.create().toCSS());
-
- sb.background(255, 255, 255);
- assertEquals("", sb.create().toCSS());
- }
-
- public void testCreateNoStyle() throws Exception {
- Style style = new StyleBuilder().create();
- assertEquals(Style.NO_STYLE, style);
- assertSame(Style.NO_STYLE, style);
- }
-
- public void testCreateColor() throws Exception {
- Color col1 = StyleBuilder.createColor("eeEE00");
- assertEquals("Color[238,238,0]", col1.toString());
-
- Color col2 = StyleBuilder.createColor(238, 238, 0);
-
- // cache should ensure that these two colors are not only equal, but
- // also the same!
- assertEquals(col1, col2);
- assertSame(col1, col2);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/delete/AbstractRowDeletionCallbackTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/delete/AbstractRowDeletionCallbackTest.java b/core/src/test/java/org/eobjects/metamodel/delete/AbstractRowDeletionCallbackTest.java
deleted file mode 100644
index d5447ba..0000000
--- a/core/src/test/java/org/eobjects/metamodel/delete/AbstractRowDeletionCallbackTest.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- * 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.delete;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.MockUpdateableDataContext;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.schema.Table;
-
-public class AbstractRowDeletionCallbackTest extends TestCase {
-
- public void testDelete() throws Exception {
- final MockUpdateableDataContext dc = new MockUpdateableDataContext();
- final Table table = dc.getDefaultSchema().getTables()[0];
- DataSet ds = dc.query().from(table).selectCount().execute();
- assertTrue(ds.next());
- assertEquals("3", ds.getRow().getValue(0).toString());
- assertFalse(ds.next());
- ds.close();
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.update(table).value("bar", "baz").execute();
- callback.update(table).value("foo", "4").where("foo").eq("3").execute();
- }
- });
-
- ds = dc.query().from(table).select(table.getColumns()).execute();
- assertTrue(ds.next());
- assertEquals("Row[values=[1, baz]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[2, baz]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[4, baz]]", ds.getRow().toString());
- assertFalse(ds.next());
- ds.close();
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- RowDeletionBuilder delete = callback.deleteFrom(table);
- assertEquals("DELETE FROM schema.table", delete.toSql());
- delete.execute();
-
- assertEquals("DELETE FROM schema.table WHERE table.bar = 'baz'", callback.deleteFrom(table).where("bar")
- .eq("baz").toSql());
- }
- });
-
- ds = dc.query().from(table).selectCount().execute();
- assertTrue(ds.next());
- assertEquals("0", ds.getRow().getValue(0).toString());
- assertFalse(ds.next());
- ds.close();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/insert/AbstractInsertBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/insert/AbstractInsertBuilderTest.java b/core/src/test/java/org/eobjects/metamodel/insert/AbstractInsertBuilderTest.java
deleted file mode 100644
index 27249aa..0000000
--- a/core/src/test/java/org/eobjects/metamodel/insert/AbstractInsertBuilderTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * 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.insert;
-
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.util.MutableRef;
-
-public class AbstractInsertBuilderTest extends TestCase {
-
- public void testInsertValues() throws Exception {
- final MutableRef<Boolean> executed = new MutableRef<Boolean>(false);
- final MutableTable table = new MutableTable("foo");
- table.addColumn(new MutableColumn("foo"));
- table.addColumn(new MutableColumn("bar"));
- table.addColumn(new MutableColumn("baz"));
- RowInsertionBuilder insertBuilder = new AbstractRowInsertionBuilder<UpdateCallback>(
- null, table) {
- @Override
- public void execute() throws MetaModelException {
- assertEquals("[1, 2, 3]", Arrays.toString(getValues()));
- executed.set(true);
- }
- };
-
- assertFalse(executed.get().booleanValue());
-
- insertBuilder.value(0, 1).value("bar", 2)
- .value(table.getColumnByName("baz"), 3).execute();
-
- assertTrue(executed.get());
-
- assertEquals("Row[values=[1, 2, 3]]", insertBuilder.toRow().toString());
-
- }
-
- public void testIllegalArguments() throws Exception {
- final MutableTable table = new MutableTable("foo");
- table.addColumn(new MutableColumn("foo"));
- RowInsertionBuilder insertBuilder = new AbstractRowInsertionBuilder<UpdateCallback>(
- null, table) {
- @Override
- public void execute() throws MetaModelException {
- }
- };
-
- try {
- insertBuilder.value((Column)null, "foo");
- fail("Exception expected");
- } catch (IllegalArgumentException e) {
- assertEquals("Column cannot be null", e.getMessage());
- }
-
- try {
- insertBuilder.value("hmm", "foo");
- fail("Exception expected");
- } catch (IllegalArgumentException e) {
- assertEquals("No such column in table: hmm, available columns are: [Column[name=foo,columnNumber=0,type=null,nullable=null,nativeType=null,columnSize=null]]", e.getMessage());
- }
-
- try {
- insertBuilder.value(4, "foo");
- fail("Exception expected");
- } catch (ArrayIndexOutOfBoundsException e) {
- assertTrue("4".equals(e.getMessage())
- || "Array index out of range: 4".equals(e.getMessage()));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/insert/SyntaxExamplesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/insert/SyntaxExamplesTest.java b/core/src/test/java/org/eobjects/metamodel/insert/SyntaxExamplesTest.java
deleted file mode 100644
index e2ebb50..0000000
--- a/core/src/test/java/org/eobjects/metamodel/insert/SyntaxExamplesTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * 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.insert;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-
-public abstract class SyntaxExamplesTest extends TestCase {
-
- private UpdateableDataContext dc;
- private Table table;
- private Column col;
-
- public void testInsertMultipleRows() throws Exception {
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- cb.insertInto(table).value(col, "foo").execute();
- cb.insertInto(table).value(col, "bar").execute();
- }
- });
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/intercept/InterceptableDataContextTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/intercept/InterceptableDataContextTest.java b/core/src/test/java/org/eobjects/metamodel/intercept/InterceptableDataContextTest.java
deleted file mode 100644
index 9eb93c1..0000000
--- a/core/src/test/java/org/eobjects/metamodel/intercept/InterceptableDataContextTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/**
- * 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.intercept;
-
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MockUpdateableDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.MaxRowsDataSet;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-public class InterceptableDataContextTest extends TestCase {
-
- private final MockUpdateableDataContext delegateDataContext = new MockUpdateableDataContext();
- private final Table table = delegateDataContext.getDefaultSchema()
- .getTables()[0];
-
- public void testInterceptSchema() throws Exception {
- // without an interceptor
- {
- DataContext dc = new InterceptableDataContext(delegateDataContext);
-
- Schema schema = dc.getDefaultSchema();
- Schema[] schemas = dc.getSchemas();
-
- assertEquals("schema", schema.getName());
- assertEquals(MutableSchema.class, schema.getClass());
- assertEquals("[information_schema, schema]",
- Arrays.toString(dc.getSchemaNames()));
- assertEquals(2, schemas.length);
- assertEquals("information_schema", schemas[0].getName());
- assertEquals("schema", schemas[1].getName());
- }
-
- // with an interceptor
- {
- DataContext dc = new InterceptableDataContext(delegateDataContext)
- .addSchemaInterceptor(new SchemaInterceptor() {
- @Override
- public Schema intercept(Schema input) {
- return new MutableSchema(input.getName() + " foo!");
- }
- });
-
- Schema schema = dc.getDefaultSchema();
- Schema[] schemas = dc.getSchemas();
-
- assertEquals("schema foo!", schema.getName());
- assertEquals(MutableSchema.class, schema.getClass());
- assertEquals("[information_schema foo!, schema foo!]",
- Arrays.toString(dc.getSchemaNames()));
- assertEquals(2, schemas.length);
- assertEquals("information_schema foo!", schemas[0].getName());
- assertEquals("schema foo!", schemas[1].getName());
- }
- }
-
- public void testInterceptDataSet() throws Exception {
- DataContext dc = new InterceptableDataContext(delegateDataContext)
- .addDataSetInterceptor(new DataSetInterceptor() {
- @Override
- public DataSet intercept(DataSet dataSet) {
- return new MaxRowsDataSet(dataSet, 1);
- }
- });
-
- DataSet ds = dc.query().from(table).select("foo").execute();
- assertEquals(MaxRowsDataSet.class, ds.getClass());
- assertEquals(1, ds.toObjectArrays().size());
- }
-
- public void testInterceptQuery() throws Exception {
-
- DataContext dc = new InterceptableDataContext(delegateDataContext)
- .addQueryInterceptor(new QueryInterceptor() {
- @Override
- public Query intercept(Query input) {
- return input.select(table.getColumnByName("foo"));
- }
- }).addQueryInterceptor(new QueryInterceptor() {
- @Override
- public Query intercept(Query input) {
- return input.select(table.getColumnByName("bar"));
-
- }
- });
-
- DataSet ds = dc.executeQuery(new Query().from(table));
- assertEquals("[table.foo, table.bar]", Arrays.toString(ds.getSelectItems()));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/intercept/InterceptorListTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/intercept/InterceptorListTest.java b/core/src/test/java/org/eobjects/metamodel/intercept/InterceptorListTest.java
deleted file mode 100644
index 8b965e1..0000000
--- a/core/src/test/java/org/eobjects/metamodel/intercept/InterceptorListTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * 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.intercept;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MockUpdateableDataContext;
-import org.eobjects.metamodel.convert.ConvertedDataSetInterceptor;
-import org.eobjects.metamodel.data.DataSet;
-
-import junit.framework.TestCase;
-
-public class InterceptorListTest extends TestCase {
-
- public void testGetInterceptorOfType() throws Exception {
- DataContext dc = new MockUpdateableDataContext();
- InterceptableDataContext interceptor = Interceptors.intercept(dc);
-
- InterceptorList<DataSet> list = interceptor.getDataSetInterceptors();
- ConvertedDataSetInterceptor convertedDataSetInterceptor = new ConvertedDataSetInterceptor();
- list.add(convertedDataSetInterceptor);
-
- assertSame(convertedDataSetInterceptor, list.getInterceptorOfType(DataSetInterceptor.class));
- assertSame(convertedDataSetInterceptor, list.getInterceptorOfType(ConvertedDataSetInterceptor.class));
-
- class NoopDataSetInterceptor implements DataSetInterceptor {
- @Override
- public DataSet intercept(DataSet dataSet) {
- return dataSet;
- }
- };
-
- NoopDataSetInterceptor noopDataSetInterceptor = new NoopDataSetInterceptor();
- list.add(noopDataSetInterceptor);
-
- assertSame(convertedDataSetInterceptor, list.getInterceptorOfType(DataSetInterceptor.class));
- assertSame(convertedDataSetInterceptor, list.getInterceptorOfType(ConvertedDataSetInterceptor.class));
- assertSame(noopDataSetInterceptor, list.getInterceptorOfType(NoopDataSetInterceptor.class));
-
- list.remove(convertedDataSetInterceptor);
-
- assertSame(noopDataSetInterceptor, list.getInterceptorOfType(DataSetInterceptor.class));
- assertNull(list.getInterceptorOfType(ConvertedDataSetInterceptor.class));
- assertSame(noopDataSetInterceptor, list.getInterceptorOfType(NoopDataSetInterceptor.class));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/intercept/InterceptorsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/intercept/InterceptorsTest.java b/core/src/test/java/org/eobjects/metamodel/intercept/InterceptorsTest.java
deleted file mode 100644
index d662c70..0000000
--- a/core/src/test/java/org/eobjects/metamodel/intercept/InterceptorsTest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * 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.intercept;
-
-import org.eobjects.metamodel.MockUpdateableDataContext;
-
-import junit.framework.TestCase;
-
-public class InterceptorsTest extends TestCase {
-
- public void testReuseInterceptor() throws Exception {
- MockUpdateableDataContext original = new MockUpdateableDataContext();
- InterceptableDataContext interceptor1 = Interceptors.intercept(original);
- InterceptableDataContext interceptor2 = Interceptors.intercept(interceptor1);
- assertSame(interceptor1, interceptor2);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/query/DefaultCompiledQueryTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/DefaultCompiledQueryTest.java b/core/src/test/java/org/eobjects/metamodel/query/DefaultCompiledQueryTest.java
deleted file mode 100644
index 7d85f5c..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/DefaultCompiledQueryTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * 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.query;
-
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.TableType;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class DefaultCompiledQueryTest {
-
- Query query;
-
- @Before
- public void setup() {
- query = new Query();
-
- MutableTable datastoreTable = new MutableTable("datastore", TableType.TABLE);
-
- MutableColumn dataSourceIdColumn = new MutableColumn("dataSourceIdColumn", ColumnType.VARCHAR);
- MutableColumn dataSourceNameColumn = new MutableColumn("dataSourceNameColumn", ColumnType.VARCHAR);
- MutableColumn versionColumn = new MutableColumn("versionColumn", ColumnType.INTEGER);
- MutableColumn changeSetColumn = new MutableColumn("changeSetColumn", ColumnType.INTEGER);
-
- SelectItem countSelectItem = new SelectItem(FunctionType.COUNT, dataSourceIdColumn);
- SelectItem dsIdSelectItem = new SelectItem(dataSourceIdColumn).setAlias("innerDataSourceRecordId");
- Query leftQuery = new Query();
- leftQuery.select(dsIdSelectItem);
- leftQuery.groupBy(dataSourceIdColumn);
- leftQuery.having(new FilterItem(countSelectItem.toSql() + " " + OperatorType.EQUALS_TO.toSql() + " 2"));
- leftQuery.where(dataSourceNameColumn, OperatorType.EQUALS_TO, new QueryParameter());
- leftQuery.from(datastoreTable);
- FromItem leftFrom = new FromItem(leftQuery);
- leftFrom.setAlias("innerDS");
-
- query.select(changeSetColumn);
- query.from(leftFrom, new FromItem(datastoreTable));
- query.where(versionColumn, OperatorType.EQUALS_TO, 2);
- query.where(changeSetColumn, OperatorType.EQUALS_TO, new QueryParameter());
- // Checks if max count is 2 in order to assert that this record has not
- // been a part of any changeSets previously and not processed by GR
- // creation in the current run.
- query.where(new SelectItem(dsIdSelectItem, leftFrom), OperatorType.EQUALS_TO, dsIdSelectItem);
- query.where(dataSourceNameColumn, OperatorType.EQUALS_TO, new QueryParameter());
- }
-
- @Test
- public void testGetParameterLogic() {
-
- DefaultCompiledQuery defaultCompiledQuery = new DefaultCompiledQuery(query);
- Assert.assertEquals(3, defaultCompiledQuery.getParameters().size());
-
- Assert.assertEquals(
- "DefaultCompiledQuery["
- + "SELECT changeSetColumn FROM (SELECT dataSourceIdColumn AS innerDataSourceRecordId FROM datastore WHERE dataSourceNameColumn = ? GROUP BY dataSourceIdColumn HAVING COUNT(dataSourceIdColumn) = 2) innerDS, datastore "
- + "WHERE versionColumn = 2 AND changeSetColumn = ? AND innerDS.innerDataSourceRecordId = dataSourceIdColumn AND dataSourceNameColumn = ?]",
- defaultCompiledQuery.toString());
-
- defaultCompiledQuery.close();
- }
-
- @Test
- public void testCloneWithParameterValues() {
- DefaultCompiledQuery defaultCompiledQuery = new DefaultCompiledQuery(query);
- Query resultQuery = defaultCompiledQuery.cloneWithParameterValues(new Object[] { "BE", 1, "BE" });
- defaultCompiledQuery.close();
-
- defaultCompiledQuery = new DefaultCompiledQuery(resultQuery);
- Assert.assertEquals(0, defaultCompiledQuery.getParameters().size());
- defaultCompiledQuery.close();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/query/FilterItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/FilterItemTest.java b/core/src/test/java/org/eobjects/metamodel/query/FilterItemTest.java
deleted file mode 100644
index 9ed783c..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/FilterItemTest.java
+++ /dev/null
@@ -1,413 +0,0 @@
-/**
- * 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.query;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.data.CachingDataSetHeader;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetHeader;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.SimpleDataSetHeader;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-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.Table;
-import org.eobjects.metamodel.schema.TableType;
-
-public class FilterItemTest extends TestCase {
-
- public void testExpressionBasedFilter() throws Exception {
- FilterItem filterItem = new FilterItem("foobar");
- assertEquals("foobar", filterItem.getExpression());
-
- try {
- filterItem.evaluate(null);
- fail("Exception should have been thrown");
- } catch (Exception e) {
- assertEquals("Expression-based filters cannot be manually evaluated", e.getMessage());
- }
-
- Column col1 = new MutableColumn("Col1", ColumnType.VARCHAR);
- assertEquals("SELECT Col1 WHERE foobar", new Query().select(col1).where(filterItem).toString());
-
- assertEquals("SELECT Col1 WHERE YEAR(Col1) = 2008", new Query().select(col1).where("YEAR(Col1) = 2008")
- .toString());
- }
-
- public void testToSqlWhereItem() throws Exception {
- MutableColumn col1 = new MutableColumn("Col1", ColumnType.VARCHAR);
- SelectItem selectItem = new SelectItem(col1);
- FilterItem c = new FilterItem(selectItem, OperatorType.DIFFERENT_FROM, null);
- assertEquals("Col1 IS NOT NULL", c.toString());
-
- try {
- c = new FilterItem(selectItem, OperatorType.GREATER_THAN, null);
- fail("Exception should have been thrown");
- } catch (IllegalArgumentException e) {
- assertEquals("Can only use EQUALS or DIFFERENT_FROM operator with null-operand", e.getMessage());
- }
-
- c = new FilterItem(selectItem, OperatorType.DIFFERENT_FROM, "foo");
- assertEquals("Col1 <> 'foo'", c.toString());
-
- c = new FilterItem(selectItem, OperatorType.DIFFERENT_FROM, "'bar'");
-
- // this will be rewritten so it's not an issue even though it look like
- // it needs an escape-char
- assertEquals("Col1 <> ''bar''", c.toSql());
-
- c = new FilterItem(selectItem, OperatorType.DIFFERENT_FROM, "foo's bar");
- // the same applies here
- assertEquals("Col1 <> 'foo's bar'", c.toSql());
-
- col1.setType(ColumnType.FLOAT);
- c = new FilterItem(selectItem, OperatorType.EQUALS_TO, 423);
- assertEquals("Col1 = 423", c.toString());
-
- c = new FilterItem(selectItem, OperatorType.EQUALS_TO, 423426235423.42);
- assertEquals("Col1 = 423426235423.42", c.toString());
-
- c = new FilterItem(selectItem, OperatorType.EQUALS_TO, true);
- assertEquals("Col1 = 1", c.toString());
-
- Column timeColumn = new MutableColumn("TimeCol", ColumnType.TIME);
- selectItem = new SelectItem(timeColumn);
- c = new FilterItem(selectItem, OperatorType.GREATER_THAN, "02:30:05.000");
- assertEquals("TimeCol > TIME '02:30:05'", c.toString());
-
- Column dateColumn = new MutableColumn("DateCol", ColumnType.DATE);
- c = new FilterItem(new SelectItem(dateColumn), OperatorType.GREATER_THAN, "2000-12-31");
- assertEquals("DateCol > DATE '2000-12-31'", c.toString());
- }
-
- public void testToStringTimeStamp() throws Exception {
- Column timestampColumn = new MutableColumn("TimestampCol", ColumnType.TIMESTAMP);
- FilterItem c = new FilterItem(new SelectItem(timestampColumn), OperatorType.LESS_THAN,
- "2000-12-31 02:30:05.007");
- assertEquals("TimestampCol < TIMESTAMP '2000-12-31 02:30:05'", c.toString());
-
- c = new FilterItem(new SelectItem(timestampColumn), OperatorType.LESS_THAN, "2000-12-31 02:30:05");
- assertEquals("TimestampCol < TIMESTAMP '2000-12-31 02:30:05'", c.toString());
-
- Column dateColumn = new MutableColumn("DateCol", ColumnType.DATE);
- c = new FilterItem(new SelectItem(timestampColumn), OperatorType.GREATER_THAN, new SelectItem(dateColumn));
- assertEquals("TimestampCol > DateCol", c.toString());
- }
-
- public void testEvaluateStrings() throws Exception {
- Column col1 = new MutableColumn("Col1", ColumnType.VARCHAR);
- Column col2 = new MutableColumn("Col2", ColumnType.VARCHAR);
- SelectItem s1 = new SelectItem(col1);
- SelectItem s2 = new SelectItem(col2);
- SelectItem[] selectItems = new SelectItem[] { s1, s2 };
- SimpleDataSetHeader header = new SimpleDataSetHeader(selectItems);
- Row row;
- FilterItem c;
-
- row = new DefaultRow(header, new Object[] { "foo", "bar" });
- c = new FilterItem(s1, OperatorType.DIFFERENT_FROM, s2);
- assertTrue(c.evaluate(row));
-
- row = new DefaultRow(header, new Object[] { "aaa", "bbb" });
- c = new FilterItem(s1, OperatorType.GREATER_THAN, s2);
- assertFalse(c.evaluate(row));
-
- c = new FilterItem(s1, OperatorType.LESS_THAN, s2);
- assertTrue(c.evaluate(row));
-
- row = new DefaultRow(header, new Object[] { "aaa", "aaa" });
- c = new FilterItem(s1, OperatorType.EQUALS_TO, s2);
- assertTrue(c.evaluate(row));
-
- c = new FilterItem(s1, OperatorType.LIKE, s2);
- row = new DefaultRow(header, new Object[] { "foobar", "fo%b%r" });
- assertTrue(c.evaluate(row));
-
- row = new DefaultRow(header, new Object[] { "foobbdbafsdfr", "fo%b%r" });
- assertTrue(c.evaluate(row));
- }
-
- public void testEvaluateNull() throws Exception {
- Column col1 = new MutableColumn("Col1", ColumnType.INTEGER);
- Column col2 = new MutableColumn("Col2", ColumnType.DECIMAL);
- SelectItem s1 = new SelectItem(col1);
- SelectItem s2 = new SelectItem(col2);
- SelectItem[] selectItems = new SelectItem[] { s1, s2 };
- CachingDataSetHeader header = new CachingDataSetHeader(selectItems);
-
- FilterItem c = new FilterItem(s1, OperatorType.EQUALS_TO, null);
-
- Row row = new DefaultRow(header, new Object[] { 1, 1 });
- assertFalse(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { null, 1 });
- assertTrue(c.evaluate(row));
-
- c = new FilterItem(s1, OperatorType.EQUALS_TO, 1);
-
- row = new DefaultRow(header, new Object[] { 1, 1 });
- assertTrue(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { null, 1 });
- assertFalse(c.evaluate(row));
-
- c = new FilterItem(s1, OperatorType.DIFFERENT_FROM, 5);
-
- row = new DefaultRow(header, new Object[] { 1, 1 });
- assertTrue(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { null, 1 });
- assertTrue(c.evaluate(row));
-
- c = new FilterItem(s1, OperatorType.GREATER_THAN, s2);
-
- row = new DefaultRow(header, new Object[] { 5, 1 });
- assertTrue(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { null, 1 });
- assertFalse(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { 1, null });
- assertFalse(c.evaluate(row));
-
- c = new FilterItem(s1, OperatorType.EQUALS_TO, s2);
- row = new DefaultRow(header, new Object[] { 1, null });
- assertFalse(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { null, null });
- assertTrue(c.evaluate(row));
- }
-
- public void testEvaluateDates() throws Exception {
- Column col1 = new MutableColumn("Col1", ColumnType.DATE);
- SelectItem s1 = new SelectItem(col1);
- SelectItem[] selectItems = new SelectItem[] { s1 };
- CachingDataSetHeader header = new CachingDataSetHeader(selectItems);
-
- long currentTimeMillis = System.currentTimeMillis();
- FilterItem c = new FilterItem(s1, OperatorType.LESS_THAN, new java.sql.Date(currentTimeMillis));
-
- Row row = new DefaultRow(header, new Object[] { new java.sql.Date(currentTimeMillis) });
- assertFalse(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { new java.sql.Date(currentTimeMillis + 10000000) });
- assertFalse(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { new java.sql.Date(currentTimeMillis - 10000000) });
- assertTrue(c.evaluate(row));
- }
-
- public void testEvaluateBooleans() throws Exception {
- Column col1 = new MutableColumn("Col1", ColumnType.BIT);
- SelectItem s1 = new SelectItem(col1);
- SelectItem[] selectItems = new SelectItem[] { s1 };
- DataSetHeader header = new SimpleDataSetHeader(selectItems);
-
- FilterItem c = new FilterItem(s1, OperatorType.EQUALS_TO, true);
-
- Row row = new DefaultRow(header, new Object[] { true });
- assertTrue(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { false });
- assertFalse(c.evaluate(row));
-
- c = new FilterItem(s1, OperatorType.EQUALS_TO, false);
- row = new DefaultRow(header, new Object[] { true });
- assertFalse(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { false });
- assertTrue(c.evaluate(row));
-
- c = new FilterItem(s1, OperatorType.GREATER_THAN, false);
- row = new DefaultRow(header, new Object[] { true });
- assertTrue(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { false });
- assertFalse(c.evaluate(row));
- }
-
- /**
- * Tests that the following (general) rules apply to the object:
- *
- * <li>the hashcode is the same when run twice on an unaltered object</li>
- * <li>if o1.equals(o2) then this condition must be true: o1.hashCode() ==
- * 02.hashCode()
- */
- public void testEqualsAndHashCode() throws Exception {
- Column col1 = new MutableColumn("Col1", ColumnType.BIT);
-
- FilterItem c1 = new FilterItem(new SelectItem(col1), OperatorType.EQUALS_TO, true);
- FilterItem c2 = new FilterItem(new SelectItem(col1), OperatorType.EQUALS_TO, true);
- assertEquals(c1, c2);
- assertEquals(c1.hashCode(), c2.hashCode());
-
- c2 = new FilterItem(new SelectItem(col1), OperatorType.GREATER_THAN, true);
- assertFalse(c1.equals(c2));
- assertFalse(c1.hashCode() == c2.hashCode());
-
- Column col2 = new MutableColumn("Col2", ColumnType.VARBINARY);
- c2 = new FilterItem(new SelectItem(col2), OperatorType.EQUALS_TO, true);
- assertFalse(c1.equals(c2));
- assertFalse(c1.hashCode() == c2.hashCode());
- }
-
- public void testOrFilterItem() throws Exception {
- Column col1 = new MutableColumn("Col1", ColumnType.VARCHAR);
-
- SelectItem s1 = new SelectItem(col1);
- FilterItem c1 = new FilterItem(s1, OperatorType.EQUALS_TO, "foo");
- FilterItem c2 = new FilterItem(s1, OperatorType.EQUALS_TO, "bar");
- FilterItem c3 = new FilterItem(s1, OperatorType.EQUALS_TO, "foobar");
-
- FilterItem filter = new FilterItem(c1, c2, c3);
- assertEquals("(Col1 = 'foo' OR Col1 = 'bar' OR Col1 = 'foobar')", filter.toString());
-
- DataSetHeader header = new SimpleDataSetHeader(new SelectItem[] { s1 });
-
- assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "foo" })));
- assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "bar" })));
- assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "foobar" })));
-
- assertFalse(filter.evaluate(new DefaultRow(header, new Object[] { "foob" })));
- }
-
- public void testAndFilterItem() throws Exception {
- Column col1 = new MutableColumn("Col1", ColumnType.VARCHAR);
-
- SelectItem s1 = new SelectItem(col1);
- FilterItem c1 = new FilterItem(s1, OperatorType.LIKE, "foo%");
- FilterItem c2 = new FilterItem(s1, OperatorType.LIKE, "%bar");
- FilterItem c3 = new FilterItem(s1, OperatorType.DIFFERENT_FROM, "foobar");
-
- FilterItem filter = new FilterItem(LogicalOperator.AND, c1, c2, c3);
- assertEquals("(Col1 LIKE 'foo%' AND Col1 LIKE '%bar' AND Col1 <> 'foobar')", filter.toString());
-
- SelectItem[] items = new SelectItem[] { s1 };
- CachingDataSetHeader header = new CachingDataSetHeader(items);
- assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "foo bar" })));
- assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "foosenbar" })));
- assertFalse(filter.evaluate(new DefaultRow(header, new Object[] { "foo" })));
- assertFalse(filter.evaluate(new DefaultRow(header, new Object[] { "hello world" })));
- assertFalse(filter.evaluate(new DefaultRow(header, new Object[] { "foobar" })));
- }
-
- // Ticket #410
- public void testOrFilterItemWithoutSelectingActualItmes() throws Exception {
-
- // define the schema
- final MutableSchema schema = new MutableSchema("s");
- MutableTable table = new MutableTable("persons", TableType.TABLE, schema);
- schema.addTable(table);
- final Column col1 = new MutableColumn("name", ColumnType.VARCHAR, table, 1, true);
- final Column col2 = new MutableColumn("role", ColumnType.VARCHAR, table, 2, true);
- final Column col3 = new MutableColumn("column_number", ColumnType.INTEGER, table, 3, true);
- table.addColumn(col1);
- table.addColumn(col2);
- table.addColumn(col3);
-
- Query q = new Query();
- q.select(col3);
- q.from(col1.getTable());
-
- SelectItem selectItem1 = new SelectItem(col1);
- SelectItem selectItem2 = new SelectItem(col2);
-
- FilterItem item1 = new FilterItem(selectItem1, OperatorType.EQUALS_TO, "kasper");
- FilterItem item2 = new FilterItem(selectItem2, OperatorType.EQUALS_TO, "user");
-
- q.where(new FilterItem(item1, item2));
-
- assertEquals(
- "SELECT persons.column_number FROM s.persons WHERE (persons.name = 'kasper' OR persons.role = 'user')",
- q.toString());
-
- DataContext dc = new QueryPostprocessDataContext() {
-
- @Override
- public DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
- assertEquals(3, columns.length);
- assertEquals("column_number", columns[0].getName());
- assertEquals("name", columns[1].getName());
- assertEquals("role", columns[2].getName());
- SelectItem[] selectItems = new SelectItem[] { new SelectItem(col1), new SelectItem(col2),
- new SelectItem(col3) };
- DataSetHeader header = new CachingDataSetHeader(selectItems);
- List<Row> rows = new LinkedList<Row>();
- rows.add(new DefaultRow(header, new Object[] { "foo", "bar", 1 }));
- rows.add(new DefaultRow(header, new Object[] { "kasper", "developer", 2 }));
- rows.add(new DefaultRow(header, new Object[] { "admin", "admin", 3 }));
- rows.add(new DefaultRow(header, new Object[] { "elikeon", "user", 4 }));
- rows.add(new DefaultRow(header, new Object[] { "someuser", "user", 5 }));
- rows.add(new DefaultRow(header, new Object[] { "hmm", "what-the", 6 }));
-
- return new InMemoryDataSet(header, rows);
- }
-
- @Override
- protected String getMainSchemaName() throws MetaModelException {
- return "s";
- }
-
- @Override
- protected Schema getMainSchema() throws MetaModelException {
- return schema;
- }
- };
-
- DataSet result = dc.executeQuery(q);
- List<Object[]> objectArrays = result.toObjectArrays();
- assertEquals(3, objectArrays.size());
- assertEquals(2, objectArrays.get(0)[0]);
- assertEquals(4, objectArrays.get(1)[0]);
- assertEquals(5, objectArrays.get(2)[0]);
- }
-
- public void testInOperandSql() throws Exception {
- SelectItem selectItem = new SelectItem(new MutableColumn("foo", ColumnType.VARCHAR, null, 1, null, null, true,
- null, false, null));
- Object operand = new String[] { "foo", "bar" };
- assertEquals("foo IN ('foo' , 'bar')", new FilterItem(selectItem, OperatorType.IN, operand).toSql());
-
- operand = Arrays.asList("foo", "bar", "baz");
- assertEquals("foo IN ('foo' , 'bar' , 'baz')", new FilterItem(selectItem, OperatorType.IN, operand).toSql());
-
- operand = "foo";
- assertEquals("foo IN ('foo')", new FilterItem(selectItem, OperatorType.IN, operand).toSql());
-
- operand = new ArrayList<Object>();
- assertEquals("foo IN ()", new FilterItem(selectItem, OperatorType.IN, operand).toSql());
- }
-
- public void testInOperandEvaluate() throws Exception {
- SelectItem selectItem = new SelectItem(new MutableColumn("foo", ColumnType.VARCHAR, null, 1, null, null, true,
- null, false, null));
- Object operand = new String[] { "foo", "bar" };
-
- FilterItem filterItem = new FilterItem(selectItem, OperatorType.IN, operand);
- SelectItem[] selectItems = new SelectItem[] { selectItem };
- DataSetHeader header = new CachingDataSetHeader(selectItems);
-
- assertTrue(filterItem.evaluate(new DefaultRow(header, new Object[] { "foo" })));
- assertTrue(filterItem.evaluate(new DefaultRow(header, new Object[] { "bar" })));
- assertFalse(filterItem.evaluate(new DefaultRow(header, new Object[] { "foobar" })));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/query/FromClauseTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/FromClauseTest.java b/core/src/test/java/org/eobjects/metamodel/query/FromClauseTest.java
deleted file mode 100644
index 074a3b4..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/FromClauseTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * 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.query;
-
-import org.eobjects.metamodel.MetaModelTestCase;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-public class FromClauseTest extends MetaModelTestCase {
-
- public void testGetItemByReference() throws Exception {
- Schema exampleSchema = getExampleSchema();
- Table table = exampleSchema.getTableByName(TABLE_CONTRIBUTOR);
-
- Query query = new Query();
- query.from(table, "foobar");
-
- assertNull(query.getFromClause().getItemByReference("foob"));
- assertNull(query.getFromClause().getItemByReference(TABLE_CONTRIBUTOR));
- assertEquals("MetaModelSchema.contributor foobar", query
- .getFromClause().getItemByReference("foobar").toString());
-
- query = new Query();
- query.from(table);
- assertNull(query.getFromClause().getItemByReference("foob"));
- assertEquals("MetaModelSchema.contributor", query.getFromClause()
- .getItemByReference(TABLE_CONTRIBUTOR).toString());
- assertNull(query.getFromClause().getItemByReference("foobar"));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/query/FromItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/FromItemTest.java b/core/src/test/java/org/eobjects/metamodel/query/FromItemTest.java
deleted file mode 100644
index fb4c09e..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/FromItemTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * 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.query;
-
-import org.eobjects.metamodel.MetaModelTestCase;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-public class FromItemTest extends MetaModelTestCase {
-
- private Schema _schema = getExampleSchema();
-
- public void testExpressionBased() throws Exception {
- FromItem fromItem = new FromItem("foobar");
- assertEquals("foobar", fromItem.toString());
- fromItem.setAlias("f");
- assertEquals("foobar f", fromItem.toString());
-
- assertEquals("SELECT COUNT(*) FROM foobar", new Query().selectCount().from(
- "foobar").toString());
- }
-
- public void testRelationJoinToString() throws Exception {
- Table contributorTable = _schema.getTableByName(TABLE_CONTRIBUTOR);
- Table roleTable = _schema.getTableByName(TABLE_ROLE);
- Relationship[] relationships = roleTable
- .getRelationships(contributorTable);
- FromItem from = new FromItem(JoinType.INNER, relationships[0]);
- assertEquals(
- "MetaModelSchema.contributor INNER JOIN MetaModelSchema.role ON contributor.contributor_id = role.contributor_id",
- from.toString());
-
- from.setAlias("myJoin");
- assertEquals(
- "(MetaModelSchema.contributor INNER JOIN MetaModelSchema.role ON contributor.contributor_id = role.contributor_id) myJoin",
- from.toString());
-
- from.getLeftSide().setAlias("a");
- assertEquals(
- "(MetaModelSchema.contributor a INNER JOIN MetaModelSchema.role ON a.contributor_id = role.contributor_id) myJoin",
- from.toString());
- }
-
- public void testSubQueryJoinToString() throws Exception {
- Table projectTable = _schema.getTableByName(TABLE_PROJECT);
- Table roleTable = _schema.getTableByName(TABLE_ROLE);
-
- Column projectIdColumn = projectTable
- .getColumnByName(COLUMN_PROJECT_PROJECT_ID);
-
- FromItem leftSide = new FromItem(projectTable);
- leftSide.setAlias("a");
- SelectItem[] leftOn = new SelectItem[] { new SelectItem(projectIdColumn) };
-
- Column[] columns = roleTable.getColumns();
-
- Query subQuery = new Query();
- FromItem subQueryFrom = new FromItem(roleTable);
- subQuery.from(subQueryFrom);
- subQuery.select(columns);
- SelectItem subQuerySelectItem = subQuery.getSelectClause().getItems()
- .get(1);
- FromItem rightSide = new FromItem(subQuery);
- rightSide.setAlias("b");
- SelectItem[] rightOn = new SelectItem[] { subQuerySelectItem };
- FromItem from = new FromItem(JoinType.LEFT, leftSide, rightSide,
- leftOn, rightOn);
-
- assertEquals(
- "MetaModelSchema.project a LEFT JOIN (SELECT role.contributor_id, role.project_id, role.name FROM MetaModelSchema.role) b ON a.project_id = b.project_id",
- from.toString());
-
- subQueryFrom.setAlias("c");
- assertEquals(
- "MetaModelSchema.project a LEFT JOIN (SELECT c.contributor_id, c.project_id, c.name FROM MetaModelSchema.role c) b ON a.project_id = b.project_id",
- from.toString());
-
- subQuerySelectItem.setAlias("foobar");
- assertEquals(
- "MetaModelSchema.project a LEFT JOIN (SELECT c.contributor_id, c.project_id AS foobar, c.name FROM MetaModelSchema.role c) b ON a.project_id = b.foobar",
- from.toString());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/query/FunctionTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/FunctionTypeTest.java b/core/src/test/java/org/eobjects/metamodel/query/FunctionTypeTest.java
deleted file mode 100644
index 1161550..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/FunctionTypeTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * 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.query;
-
-import junit.framework.TestCase;
-
-public class FunctionTypeTest extends TestCase {
-
- public void testEvaluateNumbers() throws Exception {
- assertEquals(2.5, FunctionType.AVG.evaluate(1.5, 2, null, 3, 3.5));
- assertEquals(10.0, FunctionType.SUM.evaluate(1.5, 2, null, 3, 3.5));
- assertEquals(4l, FunctionType.COUNT.evaluate(1.5, 2, null, 3, 3.5));
- assertEquals(1.5, FunctionType.MIN.evaluate(1.5, 2, null, 3, 3.5));
- assertEquals(3.5, FunctionType.MAX.evaluate(1.5, 2, null, 3, 3.5));
- }
-
- public void testEvaluateStrings() throws Exception {
- assertEquals(2.5, FunctionType.AVG.evaluate("1.5", "2", null, "3",
- "3.5"));
- assertEquals(10.0, FunctionType.SUM.evaluate("1.5", "2", null, "3",
- "3.5"));
- assertEquals(2l, FunctionType.COUNT.evaluate("foo", "BAR", null));
- assertEquals("a", FunctionType.MIN.evaluate("abc", "a", null, "bcd"));
- assertEquals("bcd", FunctionType.MAX.evaluate("abc", "a", null, "bcd"));
- }
-}
\ No newline at end of file
[59/61] git commit: Renamed all import and package statements from
'org.eobjects' to 'org.apache'.
Posted by ka...@apache.org.
Renamed all import and package statements from 'org.eobjects' to
'org.apache'.
Project: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/commit/587d518a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/tree/587d518a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/diff/587d518a
Branch: refs/heads/namespace-rename
Commit: 587d518a880e5353ddc329e78781f391dab5960c
Parents: e2e2b37
Author: kaspers <ka...@kaspers-think.humaninference.com>
Authored: Fri Jul 19 10:13:28 2013 +0200
Committer: kaspers <ka...@kaspers-think.humaninference.com>
Committed: Fri Jul 19 10:13:28 2013 +0200
----------------------------------------------------------------------
.../metamodel/access/AccessDataContext.java | 38 +++++------
.../apache/metamodel/access/package-info.java | 2 +-
.../metamodel/access/AccessDataContextTest.java | 16 ++---
.../apache/metamodel/AbstractDataContext.java | 22 +++----
.../metamodel/AbstractUpdateCallback.java | 16 ++---
.../org/apache/metamodel/BatchUpdateScript.java | 2 +-
.../apache/metamodel/CompositeDataContext.java | 16 ++---
.../metamodel/CompositeQueryDelegate.java | 12 ++--
.../java/org/apache/metamodel/DataContext.java | 20 +++---
.../metamodel/DeleteAndInsertBuilder.java | 22 +++----
.../InconsistentRowFormatException.java | 6 +-
.../apache/metamodel/MetaModelException.java | 2 +-
.../org/apache/metamodel/MetaModelHelper.java | 60 +++++++++---------
.../metamodel/QueryPostprocessDataContext.java | 66 ++++++++++----------
.../metamodel/QueryPostprocessDelegate.java | 4 +-
.../apache/metamodel/SchemaNameComparator.java | 2 +-
.../org/apache/metamodel/UpdateCallback.java | 12 ++--
.../java/org/apache/metamodel/UpdateScript.java | 4 +-
.../apache/metamodel/UpdateableDataContext.java | 2 +-
.../metamodel/convert/ColumnTypeDetector.java | 6 +-
.../metamodel/convert/ConvertedDataSet.java | 10 +--
.../convert/ConvertedDataSetInterceptor.java | 10 +--
.../ConvertedRowInsertionInterceptor.java | 8 +--
.../ConvertedRowUpdationInterceptor.java | 8 +--
.../apache/metamodel/convert/Converters.java | 28 ++++-----
.../convert/HasReadTypeConverters.java | 6 +-
.../convert/StringToBooleanConverter.java | 4 +-
.../convert/StringToDateConverter.java | 6 +-
.../convert/StringToDoubleConverter.java | 2 +-
.../convert/StringToIntegerConverter.java | 2 +-
.../apache/metamodel/convert/TypeConverter.java | 2 +-
.../apache/metamodel/convert/package-info.java | 2 +-
.../metamodel/create/AbstractColumnBuilder.java | 8 +--
.../create/AbstractTableCreationBuilder.java | 18 +++---
.../apache/metamodel/create/ColumnBuilder.java | 8 +--
.../metamodel/create/ColumnCreationBuilder.java | 4 +-
.../create/ColumnCreationBuilderImpl.java | 8 +--
.../apache/metamodel/create/CreateTable.java | 20 +++---
.../create/CreateTableColumnBuilder.java | 8 +--
.../apache/metamodel/create/TableCreatable.java | 4 +-
.../metamodel/create/TableCreationBuilder.java | 8 +--
.../apache/metamodel/create/package-info.java | 2 +-
.../apache/metamodel/data/AbstractDataSet.java | 10 +--
.../org/apache/metamodel/data/AbstractRow.java | 6 +-
.../metamodel/data/AbstractRowBuilder.java | 6 +-
.../metamodel/data/CachingDataSetHeader.java | 6 +-
.../org/apache/metamodel/data/ColorImpl.java | 6 +-
.../java/org/apache/metamodel/data/DataSet.java | 4 +-
.../apache/metamodel/data/DataSetHeader.java | 6 +-
.../apache/metamodel/data/DataSetIterator.java | 2 +-
.../metamodel/data/DataSetTableModel.java | 6 +-
.../org/apache/metamodel/data/DefaultRow.java | 4 +-
.../org/apache/metamodel/data/EmptyDataSet.java | 6 +-
.../apache/metamodel/data/FilteredDataSet.java | 2 +-
.../apache/metamodel/data/FirstRowDataSet.java | 2 +-
.../org/apache/metamodel/data/IRowFilter.java | 2 +-
.../apache/metamodel/data/InMemoryDataSet.java | 4 +-
.../apache/metamodel/data/MaxRowsDataSet.java | 2 +-
.../java/org/apache/metamodel/data/Row.java | 6 +-
.../org/apache/metamodel/data/RowBuilder.java | 10 +--
.../org/apache/metamodel/data/RowPublisher.java | 2 +-
.../metamodel/data/RowPublisherDataSet.java | 8 +--
.../apache/metamodel/data/RowPublisherImpl.java | 4 +-
.../metamodel/data/SimpleDataSetHeader.java | 8 +--
.../java/org/apache/metamodel/data/Style.java | 2 +-
.../org/apache/metamodel/data/StyleBuilder.java | 10 +--
.../org/apache/metamodel/data/StyleImpl.java | 4 +-
.../metamodel/data/SubSelectionDataSet.java | 4 +-
.../metamodel/data/WhereClauseBuilder.java | 8 +--
.../org/apache/metamodel/data/package-info.java | 2 +-
.../delete/AbstractRowDeletionBuilder.java | 18 +++---
.../org/apache/metamodel/delete/DeleteFrom.java | 24 +++----
.../apache/metamodel/delete/RowDeletable.java | 4 +-
.../metamodel/delete/RowDeletionBuilder.java | 10 +--
.../apache/metamodel/delete/package-info.java | 2 +-
.../drop/AbstractTableDropBuilder.java | 4 +-
.../org/apache/metamodel/drop/DropTable.java | 14 ++---
.../apache/metamodel/drop/TableDropBuilder.java | 6 +-
.../apache/metamodel/drop/TableDroppable.java | 6 +-
.../org/apache/metamodel/drop/package-info.java | 2 +-
.../insert/AbstractRowInsertionBuilder.java | 14 ++---
.../org/apache/metamodel/insert/InsertInto.java | 20 +++---
.../apache/metamodel/insert/RowInsertable.java | 4 +-
.../metamodel/insert/RowInsertionBuilder.java | 12 ++--
.../apache/metamodel/insert/package-info.java | 2 +-
.../metamodel/intercept/DataSetInterceptor.java | 4 +-
.../InterceptableColumnCreationBuilder.java | 14 ++---
.../intercept/InterceptableDataContext.java | 40 ++++++------
.../InterceptableRowDeletionBuilder.java | 18 +++---
.../InterceptableRowInsertionBuilder.java | 14 ++---
.../InterceptableRowUpdationBuilder.java | 24 +++----
.../InterceptableTableCreationBuilder.java | 10 +--
.../InterceptableTableDropBuilder.java | 8 +--
.../intercept/InterceptableUpdateCallback.java | 20 +++---
.../intercept/InterceptableUpdateScript.java | 16 ++---
.../apache/metamodel/intercept/Interceptor.java | 2 +-
.../metamodel/intercept/InterceptorList.java | 2 +-
.../metamodel/intercept/Interceptors.java | 4 +-
.../metamodel/intercept/QueryInterceptor.java | 4 +-
.../intercept/RowDeletionInterceptor.java | 4 +-
.../intercept/RowInsertionInterceptor.java | 4 +-
.../intercept/RowUpdationInterceptor.java | 4 +-
.../metamodel/intercept/SchemaInterceptor.java | 4 +-
.../intercept/TableCreationInterceptor.java | 4 +-
.../intercept/TableDropInterceptor.java | 4 +-
.../java/org/apache/metamodel/package-info.java | 2 +-
.../metamodel/query/AbstractQueryClause.java | 4 +-
.../query/AverageAggregateBuilder.java | 6 +-
.../apache/metamodel/query/CompiledQuery.java | 4 +-
.../metamodel/query/CountAggregateBuilder.java | 4 +-
.../metamodel/query/DefaultCompiledQuery.java | 2 +-
.../apache/metamodel/query/FilterClause.java | 4 +-
.../org/apache/metamodel/query/FilterItem.java | 20 +++---
.../org/apache/metamodel/query/FromClause.java | 4 +-
.../org/apache/metamodel/query/FromItem.java | 10 +--
.../apache/metamodel/query/FunctionType.java | 8 +--
.../apache/metamodel/query/GroupByClause.java | 2 +-
.../org/apache/metamodel/query/GroupByItem.java | 4 +-
.../org/apache/metamodel/query/JoinType.java | 2 +-
.../apache/metamodel/query/LogicalOperator.java | 2 +-
.../metamodel/query/MaxAggregateBuilder.java | 6 +-
.../metamodel/query/MinAggregateBuilder.java | 6 +-
.../apache/metamodel/query/OperatorType.java | 2 +-
.../apache/metamodel/query/OrderByClause.java | 2 +-
.../org/apache/metamodel/query/OrderByItem.java | 4 +-
.../java/org/apache/metamodel/query/Query.java | 32 +++++-----
.../org/apache/metamodel/query/QueryClause.java | 2 +-
.../org/apache/metamodel/query/QueryItem.java | 2 +-
.../apache/metamodel/query/QueryParameter.java | 4 +-
.../apache/metamodel/query/SelectClause.java | 4 +-
.../org/apache/metamodel/query/SelectItem.java | 14 ++---
.../metamodel/query/SumAggregateBuilder.java | 6 +-
.../query/builder/AbstractFilterBuilder.java | 10 +--
.../builder/AbstractQueryFilterBuilder.java | 8 +--
.../query/builder/ColumnSelectBuilder.java | 2 +-
.../query/builder/ColumnSelectBuilderImpl.java | 8 +--
.../query/builder/CountSelectBuilder.java | 2 +-
.../query/builder/CountSelectBuilderImpl.java | 6 +-
.../metamodel/query/builder/FilterBuilder.java | 4 +-
.../query/builder/FunctionSelectBuilder.java | 2 +-
.../builder/FunctionSelectBuilderImpl.java | 10 +--
.../query/builder/GroupedQueryBuilder.java | 6 +-
.../builder/GroupedQueryBuilderCallback.java | 16 ++---
.../query/builder/GroupedQueryBuilderImpl.java | 24 +++----
.../metamodel/query/builder/HavingBuilder.java | 2 +-
.../query/builder/HavingBuilderImpl.java | 12 ++--
.../query/builder/InitFromBuilder.java | 6 +-
.../query/builder/InitFromBuilderImpl.java | 12 ++--
.../query/builder/JoinFromBuilder.java | 4 +-
.../query/builder/JoinFromBuilderImpl.java | 16 ++---
.../query/builder/SatisfiedFromBuilder.java | 8 +--
.../builder/SatisfiedFromBuilderCallback.java | 16 ++---
.../query/builder/SatisfiedHavingBuilder.java | 6 +-
.../query/builder/SatisfiedOrderByBuilder.java | 4 +-
.../builder/SatisfiedOrderByBuilderImpl.java | 14 ++---
.../query/builder/SatisfiedQueryBuilder.java | 18 +++---
.../query/builder/SatisfiedSelectBuilder.java | 6 +-
.../builder/SatisfiedSelectBuilderImpl.java | 6 +-
.../query/builder/SatisfiedWhereBuilder.java | 4 +-
.../query/builder/TableFromBuilder.java | 4 +-
.../query/builder/TableFromBuilderImpl.java | 12 ++--
.../metamodel/query/builder/WhereBuilder.java | 6 +-
.../query/builder/WhereBuilderImpl.java | 14 ++---
.../metamodel/query/builder/package-info.java | 2 +-
.../apache/metamodel/query/package-info.java | 2 +-
.../metamodel/query/parser/FromItemParser.java | 16 ++---
.../query/parser/GroupByItemParser.java | 4 +-
.../query/parser/HavingItemParser.java | 4 +-
.../query/parser/OrderByItemParser.java | 4 +-
.../metamodel/query/parser/QueryParser.java | 6 +-
.../query/parser/QueryParserException.java | 4 +-
.../parser/QueryPartCollectionProcessor.java | 2 +-
.../metamodel/query/parser/QueryPartParser.java | 2 +-
.../query/parser/QueryPartProcessor.java | 2 +-
.../query/parser/SelectItemParser.java | 16 ++---
.../metamodel/query/parser/WhereItemParser.java | 4 +-
.../apache/metamodel/schema/AbstractColumn.java | 2 +-
.../metamodel/schema/AbstractRelationship.java | 4 +-
.../apache/metamodel/schema/AbstractSchema.java | 12 ++--
.../apache/metamodel/schema/AbstractTable.java | 12 ++--
.../org/apache/metamodel/schema/Column.java | 2 +-
.../org/apache/metamodel/schema/ColumnType.java | 22 +++----
.../metamodel/schema/CompositeSchema.java | 6 +-
.../metamodel/schema/ImmutableColumn.java | 2 +-
.../metamodel/schema/ImmutableRelationship.java | 2 +-
.../metamodel/schema/ImmutableSchema.java | 2 +-
.../apache/metamodel/schema/ImmutableTable.java | 2 +-
.../org/apache/metamodel/schema/JdbcTypes.java | 2 +-
.../apache/metamodel/schema/MutableColumn.java | 2 +-
.../metamodel/schema/MutableRelationship.java | 2 +-
.../apache/metamodel/schema/MutableSchema.java | 2 +-
.../apache/metamodel/schema/MutableTable.java | 2 +-
.../apache/metamodel/schema/NamedStructure.java | 4 +-
.../apache/metamodel/schema/Relationship.java | 2 +-
.../org/apache/metamodel/schema/Schema.java | 4 +-
.../metamodel/schema/SuperColumnType.java | 2 +-
.../java/org/apache/metamodel/schema/Table.java | 2 +-
.../org/apache/metamodel/schema/TableType.java | 2 +-
.../apache/metamodel/schema/package-info.java | 2 +-
.../update/AbstractRowUpdationBuilder.java | 18 +++---
.../apache/metamodel/update/RowUpdateable.java | 4 +-
.../metamodel/update/RowUpdationBuilder.java | 12 ++--
.../org/apache/metamodel/update/Update.java | 28 ++++-----
.../apache/metamodel/update/package-info.java | 2 +-
.../java/org/apache/metamodel/util/Action.java | 2 +-
.../apache/metamodel/util/AggregateBuilder.java | 2 +-
.../metamodel/util/AlphabeticSequence.java | 2 +-
.../org/apache/metamodel/util/BaseObject.java | 2 +-
.../metamodel/util/BooleanComparator.java | 2 +-
.../metamodel/util/ClasspathResource.java | 2 +-
.../apache/metamodel/util/CollectionUtils.java | 2 +-
.../org/apache/metamodel/util/ConstantFunc.java | 2 +-
.../org/apache/metamodel/util/DateUtils.java | 2 +-
.../apache/metamodel/util/EqualsBuilder.java | 2 +-
.../metamodel/util/ExclusionPredicate.java | 2 +-
.../apache/metamodel/util/FalsePredicate.java | 2 +-
.../org/apache/metamodel/util/FileHelper.java | 2 +-
.../org/apache/metamodel/util/FileResource.java | 2 +-
.../org/apache/metamodel/util/FormatHelper.java | 6 +-
.../java/org/apache/metamodel/util/Func.java | 2 +-
.../java/org/apache/metamodel/util/HasName.java | 2 +-
.../apache/metamodel/util/HasNameMapper.java | 2 +-
.../apache/metamodel/util/ImmutableDate.java | 2 +-
.../org/apache/metamodel/util/ImmutableRef.java | 2 +-
.../apache/metamodel/util/InMemoryResource.java | 2 +-
.../metamodel/util/InclusionPredicate.java | 2 +-
.../java/org/apache/metamodel/util/LazyRef.java | 2 +-
.../java/org/apache/metamodel/util/Month.java | 2 +-
.../org/apache/metamodel/util/MutableRef.java | 2 +-
.../apache/metamodel/util/NumberComparator.java | 2 +-
.../apache/metamodel/util/ObjectComparator.java | 2 +-
.../org/apache/metamodel/util/Predicate.java | 2 +-
.../java/org/apache/metamodel/util/Ref.java | 2 +-
.../org/apache/metamodel/util/Resource.java | 2 +-
.../metamodel/util/ResourceException.java | 4 +-
.../apache/metamodel/util/SerializableRef.java | 2 +-
.../metamodel/util/SharedExecutorService.java | 2 +-
.../apache/metamodel/util/SimpleTableDef.java | 16 ++---
.../apache/metamodel/util/TimeComparator.java | 2 +-
.../metamodel/util/ToStringComparator.java | 2 +-
.../apache/metamodel/util/TruePredicate.java | 2 +-
.../apache/metamodel/util/UnicodeWriter.java | 2 +-
.../org/apache/metamodel/util/UrlResource.java | 2 +-
.../java/org/apache/metamodel/util/Weekday.java | 2 +-
.../apache/metamodel/util/WildcardPattern.java | 4 +-
.../org/apache/metamodel/util/package-info.java | 2 +-
.../metamodel/AbstractDataContextTest.java | 18 +++---
.../metamodel/CompositeDataContextTest.java | 12 ++--
.../apache/metamodel/MetaModelHelperTest.java | 44 ++++++-------
.../org/apache/metamodel/MetaModelTestCase.java | 32 +++++-----
.../org/apache/metamodel/MockDataContext.java | 32 +++++-----
.../metamodel/MockUpdateableDataContext.java | 44 ++++++-------
.../QueryPostprocessDataContextTest.java | 46 +++++++-------
.../metamodel/SchemaNameComparatorTest.java | 2 +-
.../convert/ColumnTypeDetectorTest.java | 2 +-
.../ConvertedDataSetInterceptorTest.java | 18 +++---
.../ConvertedRowInsertionInterceptorTest.java | 12 ++--
.../metamodel/convert/ConvertersTest.java | 18 +++---
.../convert/StringToBooleanConverterTest.java | 2 +-
.../convert/StringToDateConverterTest.java | 6 +-
.../convert/StringToDoubleConverterTest.java | 2 +-
.../convert/StringToIntegerConverterTest.java | 2 +-
.../create/AbstractCreateTableBuilderTest.java | 20 +++---
.../metamodel/create/SyntaxExamplesTest.java | 8 +--
.../metamodel/data/DataSetIteratorTest.java | 2 +-
.../metamodel/data/DataSetTableModelTest.java | 8 +--
.../apache/metamodel/data/DefaultRowTest.java | 8 +--
.../metamodel/data/FirstRowDataSetTest.java | 6 +-
.../metamodel/data/RowPublisherDataSetTest.java | 8 +--
.../java/org/apache/metamodel/data/RowTest.java | 10 +--
.../apache/metamodel/data/StyleBuilderTest.java | 4 +-
.../delete/AbstractRowDeletionCallbackTest.java | 12 ++--
.../insert/AbstractInsertBuilderTest.java | 14 ++---
.../metamodel/insert/SyntaxExamplesTest.java | 12 ++--
.../intercept/InterceptableDataContextTest.java | 18 +++---
.../intercept/InterceptorListTest.java | 10 +--
.../metamodel/intercept/InterceptorsTest.java | 4 +-
.../query/DefaultCompiledQueryTest.java | 10 +--
.../apache/metamodel/query/FilterItemTest.java | 38 +++++------
.../apache/metamodel/query/FromClauseTest.java | 8 +--
.../apache/metamodel/query/FromItemTest.java | 12 ++--
.../metamodel/query/FunctionTypeTest.java | 2 +-
.../apache/metamodel/query/GroupByItemTest.java | 2 +-
.../metamodel/query/OperatorTypeTest.java | 2 +-
.../apache/metamodel/query/OrderByItemTest.java | 4 +-
.../org/apache/metamodel/query/QueryTest.java | 26 ++++----
.../metamodel/query/SelectClauseTest.java | 10 +--
.../apache/metamodel/query/SelectItemTest.java | 12 ++--
.../builder/GroupedQueryBuilderImplTest.java | 22 +++----
.../query/builder/SyntaxExamplesTest.java | 18 +++---
.../query/builder/WhereBuilderImplTest.java | 8 +--
.../metamodel/query/parser/QueryParserTest.java | 28 ++++-----
.../query/parser/QueryPartParserTest.java | 2 +-
.../apache/metamodel/schema/ColumnTypeTest.java | 2 +-
.../apache/metamodel/schema/DataTypeTest.java | 2 +-
.../metamodel/schema/ImmutableSchemaTest.java | 4 +-
.../org/apache/metamodel/schema/Java5Types.java | 2 +-
.../org/apache/metamodel/schema/Java6Types.java | 2 +-
.../apache/metamodel/schema/JavaTypesTest.java | 2 +-
.../metamodel/schema/MutableColumnTest.java | 2 +-
.../metamodel/schema/MutableSchemaTest.java | 2 +-
.../metamodel/schema/MutableTableTest.java | 2 +-
.../metamodel/schema/SchemaModelTest.java | 4 +-
.../apache/metamodel/schema/TableTypeTest.java | 2 +-
.../metamodel/util/AlphabeticSequenceTest.java | 2 +-
.../apache/metamodel/util/BaseObjectTest.java | 2 +-
.../metamodel/util/BooleanComparatorTest.java | 2 +-
.../metamodel/util/ClasspathResourceTest.java | 2 +-
.../metamodel/util/CollectionUtilsTest.java | 2 +-
.../apache/metamodel/util/DateUtilsTest.java | 2 +-
.../metamodel/util/EqualsBuilderTest.java | 2 +-
.../metamodel/util/ExclusionPredicateTest.java | 2 +-
.../apache/metamodel/util/FileHelperTest.java | 2 +-
.../apache/metamodel/util/FormatHelperTest.java | 4 +-
.../metamodel/util/InMemoryResourceTest.java | 2 +-
.../metamodel/util/InclusionPredicateTest.java | 2 +-
.../org/apache/metamodel/util/LazyRefTest.java | 2 +-
.../org/apache/metamodel/util/MonthTest.java | 2 +-
.../metamodel/util/NumberComparatorTest.java | 2 +-
.../metamodel/util/ObjectComparatorTest.java | 2 +-
.../metamodel/util/SerializableRefTest.java | 2 +-
.../apache/metamodel/util/SimpleRefTest.java | 2 +-
.../metamodel/util/TimeComparatorTest.java | 2 +-
.../metamodel/util/ToStringComparatorTest.java | 4 +-
.../apache/metamodel/util/UrlResourceTest.java | 2 +-
.../org/apache/metamodel/util/WeekdayTest.java | 2 +-
.../metamodel/util/WildcardPatternTest.java | 2 +-
.../metamodel/couchdb/CouchDbDataContext.java | 32 +++++-----
.../metamodel/couchdb/CouchDbDataSet.java | 10 +--
.../couchdb/CouchDbInsertionBuilder.java | 10 +--
.../couchdb/CouchDbRowDeletionBuilder.java | 14 ++---
.../couchdb/CouchDbRowUpdationBuilder.java | 14 ++---
.../couchdb/CouchDbTableCreationBuilder.java | 18 +++---
.../couchdb/CouchDbTableDropBuilder.java | 10 +--
.../couchdb/CouchDbUpdateCallback.java | 20 +++---
.../apache/metamodel/couchdb/package-info.java | 2 +-
.../couchdb/CouchDbDataContextTest.java | 24 +++----
.../apache/metamodel/csv/CsvConfiguration.java | 6 +-
.../metamodel/csv/CsvCreateTableBuilder.java | 10 +--
.../apache/metamodel/csv/CsvDataContext.java | 28 ++++-----
.../org/apache/metamodel/csv/CsvDataSet.java | 14 ++---
.../apache/metamodel/csv/CsvDeleteBuilder.java | 20 +++---
.../apache/metamodel/csv/CsvInsertBuilder.java | 6 +-
.../org/apache/metamodel/csv/CsvSchema.java | 6 +-
.../java/org/apache/metamodel/csv/CsvTable.java | 20 +++---
.../metamodel/csv/CsvTableDropBuilder.java | 6 +-
.../apache/metamodel/csv/CsvUpdateCallback.java | 32 +++++-----
.../org/apache/metamodel/csv/CsvWriter.java | 4 +-
.../csv/InconsistentRowLengthException.java | 8 +--
.../org/apache/metamodel/csv/package-info.java | 2 +-
.../metamodel/csv/CsvBigFileMemoryTest.java | 16 ++---
.../metamodel/csv/CsvConfigurationTest.java | 2 +-
.../metamodel/csv/CsvDataContextTest.java | 46 +++++++-------
.../csv/DefaultExampleValueGenerator.java | 2 +-
.../metamodel/csv/ExampleDataGenerator.java | 2 +-
.../metamodel/csv/ExampleValueGenerator.java | 2 +-
.../csv/RandomizedExampleValueGenerator.java | 2 +-
.../apache/metamodel/csv/UnicodeWriterTest.java | 4 +-
.../InterceptionCsvIntegrationTest.java | 18 +++---
.../excel/DefaultSpreadsheetReaderDelegate.java | 26 ++++----
.../metamodel/excel/ExcelConfiguration.java | 4 +-
.../metamodel/excel/ExcelDataContext.java | 32 +++++-----
.../metamodel/excel/ExcelDeleteBuilder.java | 18 +++---
.../metamodel/excel/ExcelDropTableBuilder.java | 12 ++--
.../metamodel/excel/ExcelInsertBuilder.java | 20 +++---
.../excel/ExcelTableCreationBuilder.java | 16 ++---
.../metamodel/excel/ExcelUpdateCallback.java | 22 +++----
.../org/apache/metamodel/excel/ExcelUtils.java | 34 +++++-----
.../excel/SpreadsheetReaderDelegate.java | 12 ++--
.../org/apache/metamodel/excel/XlsDataSet.java | 10 +--
.../apache/metamodel/excel/XlsxRowCallback.java | 4 +-
.../metamodel/excel/XlsxRowPublisherAction.java | 12 ++--
.../metamodel/excel/XlsxSheetToRowsHandler.java | 10 +--
.../excel/XlsxSpreadsheetReaderDelegate.java | 30 ++++-----
.../excel/XlsxStopParsingException.java | 2 +-
.../excel/XlsxWorkbookToTablesHandler.java | 12 ++--
.../metamodel/excel/ZeroBasedRowIterator.java | 2 +-
.../apache/metamodel/excel/package-info.java | 2 +-
.../DefaultSpreadsheetReaderDelegateTest.java | 16 ++---
.../metamodel/excel/ExcelConfigurationTest.java | 4 +-
.../metamodel/excel/ExcelDataContextTest.java | 32 +++++-----
.../excel/ExcelUpdateCallbackTest.java | 6 +-
.../excel/ZeroBasedRowIteratorTest.java | 4 +-
.../fixedwidth/FixedWidthConfiguration.java | 8 +--
.../fixedwidth/FixedWidthDataContext.java | 32 +++++-----
.../metamodel/fixedwidth/FixedWidthDataSet.java | 12 ++--
.../metamodel/fixedwidth/FixedWidthReader.java | 2 +-
.../InconsistentValueWidthException.java | 6 +-
.../metamodel/fixedwidth/package-info.java | 2 +-
.../fixedwidth/FixedWidthConfigurationTest.java | 4 +-
.../fixedwidth/FixedWidthDataContextTest.java | 18 +++---
.../apache/metamodel/DataContextFactory.java | 34 +++++-----
.../metamodel/DataContextFactoryTest.java | 6 +-
.../metamodel/jdbc/FetchSizeCalculator.java | 10 +--
.../metamodel/jdbc/JdbcBatchUpdateCallback.java | 6 +-
.../org/apache/metamodel/jdbc/JdbcColumn.java | 8 +--
.../metamodel/jdbc/JdbcCompiledQuery.java | 12 ++--
.../metamodel/jdbc/JdbcCompiledQueryLease.java | 2 +-
.../jdbc/JdbcCompiledQueryLeaseFactory.java | 2 +-
.../metamodel/jdbc/JdbcCreateTableBuilder.java | 16 ++---
.../apache/metamodel/jdbc/JdbcDataContext.java | 44 ++++++-------
.../org/apache/metamodel/jdbc/JdbcDataSet.java | 20 +++---
.../metamodel/jdbc/JdbcDeleteBuilder.java | 18 +++---
.../metamodel/jdbc/JdbcDropTableBuilder.java | 14 ++---
.../metamodel/jdbc/JdbcInsertBuilder.java | 16 ++---
.../metamodel/jdbc/JdbcMetadataLoader.java | 18 +++---
.../org/apache/metamodel/jdbc/JdbcSchema.java | 8 +--
.../jdbc/JdbcSimpleUpdateCallback.java | 8 +--
.../org/apache/metamodel/jdbc/JdbcTable.java | 12 ++--
.../metamodel/jdbc/JdbcUpdateBuilder.java | 20 +++---
.../metamodel/jdbc/JdbcUpdateCallback.java | 20 +++---
.../org/apache/metamodel/jdbc/JdbcUtils.java | 22 +++----
.../apache/metamodel/jdbc/MetadataLoader.java | 2 +-
.../apache/metamodel/jdbc/QuerySplitter.java | 30 ++++-----
.../metamodel/jdbc/SplitQueriesDataSet.java | 16 ++---
.../org/apache/metamodel/jdbc/SqlKeywords.java | 2 +-
.../jdbc/dialects/AbstractQueryRewriter.java | 32 +++++-----
.../jdbc/dialects/DB2QueryRewriter.java | 20 +++---
.../jdbc/dialects/DefaultQueryRewriter.java | 16 ++---
.../jdbc/dialects/H2QueryRewriter.java | 4 +-
.../jdbc/dialects/HsqldbQueryRewriter.java | 16 ++---
.../metamodel/jdbc/dialects/IQueryRewriter.java | 12 ++--
.../jdbc/dialects/LimitOffsetQueryRewriter.java | 6 +-
.../jdbc/dialects/MysqlQueryRewriter.java | 4 +-
.../jdbc/dialects/PostgresqlQueryRewriter.java | 14 ++---
.../jdbc/dialects/SQLServerQueryRewriter.java | 8 +--
.../org/apache/metamodel/jdbc/package-info.java | 2 +-
.../org/apache/metamodel/DB2Test.java | 14 ++---
.../org/apache/metamodel/FirebirdTest.java | 20 +++---
.../org/apache/metamodel/MysqlTest.java | 32 +++++-----
.../org/apache/metamodel/OracleTest.java | 22 +++----
.../org/apache/metamodel/PostgresqlTest.java | 36 +++++------
.../metamodel/SQLServerJtdsDriverTest.java | 24 +++----
.../metamodel/SQLServerMicrosoftDriverTest.java | 20 +++---
.../metamodel/dbmains/PostgresqlMain.java | 20 +++---
.../dialects/AbstractQueryRewriterTest.java | 20 +++---
.../dialects/DB2QueryRewriterTest.java | 20 +++---
.../dialects/MysqlQueryRewriterTest.java | 12 ++--
.../dialects/PostgresqlQueryRewriterTest.java | 16 ++---
.../dialects/SQLServerQueryRewriterTest.java | 16 ++---
.../jdbc/CloseableConnectionWrapper.java | 2 +-
.../org/apache/metamodel/jdbc/DerbyTest.java | 28 ++++-----
.../metamodel/jdbc/FetchSizeCalculatorTest.java | 14 ++---
.../metamodel/jdbc/FilteredDataSetTest.java | 16 ++---
.../apache/metamodel/jdbc/H2databaseTest.java | 40 ++++++------
.../org/apache/metamodel/jdbc/HsqldbTest.java | 36 +++++------
.../apache/metamodel/jdbc/JdbcColumnTest.java | 10 +--
.../metamodel/jdbc/JdbcDataContextTest.java | 42 ++++++-------
.../metamodel/jdbc/JdbcDeleteBuilderTest.java | 6 +-
.../metamodel/jdbc/JdbcInsertBuilderTest.java | 6 +-
.../apache/metamodel/jdbc/JdbcSchemaTest.java | 8 +--
.../org/apache/metamodel/jdbc/JdbcTestCase.java | 2 +-
.../metamodel/jdbc/JdbcTestTemplates.java | 28 ++++-----
.../metamodel/jdbc/JdbcUpdateBuilderTest.java | 6 +-
.../apache/metamodel/jdbc/JdbcUtilsTest.java | 4 +-
.../metamodel/jdbc/QuerySplitterTest.java | 22 +++----
.../org/apache/metamodel/jdbc/SqliteTest.java | 28 ++++-----
.../mongodb/DefaultWriteConcernAdvisor.java | 2 +-
.../metamodel/mongodb/MongoDbDataContext.java | 36 +++++------
.../metamodel/mongodb/MongoDbDataSet.java | 12 ++--
.../metamodel/mongodb/MongoDbDeleteBuilder.java | 8 +--
.../mongodb/MongoDbDropTableBuilder.java | 10 +--
.../mongodb/MongoDbInsertionBuilder.java | 12 ++--
.../mongodb/MongoDbTableCreationBuilder.java | 18 +++---
.../metamodel/mongodb/MongoDbTableDef.java | 6 +-
.../mongodb/MongoDbUpdateCallback.java | 18 +++---
.../mongodb/SimpleWriteConcernAdvisor.java | 2 +-
.../metamodel/mongodb/WriteConcernAdvisor.java | 2 +-
.../apache/metamodel/mongodb/package-info.java | 2 +-
.../mongodb/MongoDbDataContextTest.java | 22 +++----
.../metamodel/mongodb/MongoDbDataCopyer.java | 24 +++----
.../openoffice/OpenOfficeDataContext.java | 18 +++---
.../metamodel/openoffice/package-info.java | 2 +-
.../openoffice/OpenOfficeDataContextTest.java | 14 ++---
.../metamodel/pojo/ArrayTableDataProvider.java | 4 +-
.../metamodel/pojo/MapTableDataProvider.java | 4 +-
.../metamodel/pojo/ObjectTableDataProvider.java | 6 +-
.../apache/metamodel/pojo/PojoDataContext.java | 32 +++++-----
.../org/apache/metamodel/pojo/PojoDataSet.java | 12 ++--
.../metamodel/pojo/PojoUpdateCallback.java | 40 ++++++------
.../metamodel/pojo/TableDataProvider.java | 6 +-
.../org/apache/metamodel/pojo/FoobarBean.java | 2 +-
.../pojo/ObjectTableDataProviderTest.java | 4 +-
.../metamodel/pojo/PojoDataContextTest.java | 16 ++---
.../salesforce/SalesforceDataContext.java | 32 +++++-----
.../metamodel/salesforce/SalesforceDataSet.java | 18 +++---
.../salesforce/SalesforceDeleteBuilder.java | 10 +--
.../salesforce/SalesforceInsertBuilder.java | 10 +--
.../metamodel/salesforce/SalesforceSchema.java | 10 +--
.../metamodel/salesforce/SalesforceTable.java | 20 +++---
.../salesforce/SalesforceUpdateBuilder.java | 12 ++--
.../salesforce/SalesforceUpdateCallback.java | 28 ++++-----
.../metamodel/salesforce/SalesforceUtils.java | 2 +-
.../salesforce/SalesforceDataContextTest.java | 32 +++++-----
.../salesforce/SalesforceTestCase.java | 2 +-
.../sugarcrm/LoggingMessageHandler.java | 2 +-
.../metamodel/sugarcrm/SugarCrmDataContext.java | 20 +++---
.../metamodel/sugarcrm/SugarCrmDataSet.java | 22 +++----
.../metamodel/sugarcrm/SugarCrmSchema.java | 8 +--
.../metamodel/sugarcrm/SugarCrmTable.java | 20 +++---
.../metamodel/sugarcrm/SugarCrmXmlHelper.java | 4 +-
.../sugarcrm/SugarCrmDataContextTest.java | 20 +++---
.../metamodel/sugarcrm/SugarCrmTestCase.java | 2 +-
.../apache/metamodel/xml/XmlDataContext.java | 2 +-
.../apache/metamodel/xml/XmlDomDataContext.java | 60 +++++++++---------
.../metamodel/xml/XmlSaxContentHandler.java | 4 +-
.../apache/metamodel/xml/XmlSaxDataContext.java | 38 +++++------
.../apache/metamodel/xml/XmlSaxTableDef.java | 4 +-
.../metamodel/xml/XmlStopParsingException.java | 2 +-
.../org/apache/metamodel/xml/package-info.java | 2 +-
.../metamodel/xml/XmlDomDataContextTest.java | 20 +++---
.../metamodel/xml/XmlSaxContentHandlerTest.java | 8 +--
.../metamodel/xml/XmlSaxDataContextTest.java | 14 ++---
513 files changed, 2571 insertions(+), 2571 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/access/src/main/java/org/apache/metamodel/access/AccessDataContext.java
----------------------------------------------------------------------
diff --git a/access/src/main/java/org/apache/metamodel/access/AccessDataContext.java b/access/src/main/java/org/apache/metamodel/access/AccessDataContext.java
index 0b3875a..310611a 100644
--- a/access/src/main/java/org/apache/metamodel/access/AccessDataContext.java
+++ b/access/src/main/java/org/apache/metamodel/access/AccessDataContext.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.access;
+package org.apache.metamodel.access;
import java.io.File;
import java.io.IOException;
@@ -25,24 +25,24 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.data.CachingDataSetHeader;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetHeader;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-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.Table;
-import org.eobjects.metamodel.schema.TableType;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.QueryPostprocessDataContext;
+import org.apache.metamodel.data.CachingDataSetHeader;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSetHeader;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.InMemoryDataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.schema.TableType;
import com.healthmarketscience.jackcess.Database;
import com.healthmarketscience.jackcess.Index;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/access/src/main/java/org/apache/metamodel/access/package-info.java
----------------------------------------------------------------------
diff --git a/access/src/main/java/org/apache/metamodel/access/package-info.java b/access/src/main/java/org/apache/metamodel/access/package-info.java
index d64d867..bd4a54f 100644
--- a/access/src/main/java/org/apache/metamodel/access/package-info.java
+++ b/access/src/main/java/org/apache/metamodel/access/package-info.java
@@ -19,5 +19,5 @@
/**
* Module package for MS Access database files
*/
-package org.eobjects.metamodel.access;
+package org.apache.metamodel.access;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/access/src/test/java/org/eobjects/metamodel/access/AccessDataContextTest.java
----------------------------------------------------------------------
diff --git a/access/src/test/java/org/eobjects/metamodel/access/AccessDataContextTest.java b/access/src/test/java/org/eobjects/metamodel/access/AccessDataContextTest.java
index 51dd39e..9050e1a 100644
--- a/access/src/test/java/org/eobjects/metamodel/access/AccessDataContextTest.java
+++ b/access/src/test/java/org/eobjects/metamodel/access/AccessDataContextTest.java
@@ -16,20 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.access;
+package org.apache.metamodel.access;
import java.util.Arrays;
import java.util.Date;
import junit.framework.TestCase;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public class AccessDataContextTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 3300e17..77ab3c1 100644
--- a/core/src/main/java/org/apache/metamodel/AbstractDataContext.java
+++ b/core/src/main/java/org/apache/metamodel/AbstractDataContext.java
@@ -16,23 +16,23 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.util.Arrays;
import java.util.Comparator;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.DefaultCompiledQuery;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.builder.InitFromBuilder;
-import org.eobjects.metamodel.query.builder.InitFromBuilderImpl;
-import org.eobjects.metamodel.query.parser.QueryParser;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.CompiledQuery;
+import org.apache.metamodel.query.DefaultCompiledQuery;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.builder.InitFromBuilder;
+import org.apache.metamodel.query.builder.InitFromBuilderImpl;
+import org.apache.metamodel.query.parser.QueryParser;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
/**
* Abstract implementation of the DataContext interface. Provides convenient
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 602a412..896dd48 100644
--- a/core/src/main/java/org/apache/metamodel/AbstractUpdateCallback.java
+++ b/core/src/main/java/org/apache/metamodel/AbstractUpdateCallback.java
@@ -16,17 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.util.Arrays;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
+import org.apache.metamodel.create.TableCreationBuilder;
+import org.apache.metamodel.delete.RowDeletionBuilder;
+import org.apache.metamodel.drop.TableDropBuilder;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.update.RowUpdationBuilder;
/**
* Abstract implementation of the {@link UpdateCallback} interface. Implements
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/BatchUpdateScript.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/BatchUpdateScript.java b/core/src/main/java/org/apache/metamodel/BatchUpdateScript.java
index d7b567c..1f8a97f 100644
--- a/core/src/main/java/org/apache/metamodel/BatchUpdateScript.java
+++ b/core/src/main/java/org/apache/metamodel/BatchUpdateScript.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
/**
* Indicator sub-interface of {@link UpdateScript}. Implementing your updates
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 82d6c01..4c9db10 100644
--- a/core/src/main/java/org/apache/metamodel/CompositeDataContext.java
+++ b/core/src/main/java/org/apache/metamodel/CompositeDataContext.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.util.ArrayList;
import java.util.Arrays;
@@ -28,13 +28,13 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.CompositeSchema;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.Func;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.CompositeSchema;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.Func;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 70b19f1..9a3517a 100644
--- a/core/src/main/java/org/apache/metamodel/CompositeQueryDelegate.java
+++ b/core/src/main/java/org/apache/metamodel/CompositeQueryDelegate.java
@@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.Func;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.Func;
final class CompositeQueryDelegate extends QueryPostprocessDelegate {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 b536d7d..bdd3a6e 100644
--- a/core/src/main/java/org/apache/metamodel/DataContext.java
+++ b/core/src/main/java/org/apache/metamodel/DataContext.java
@@ -16,16 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.QueryParameter;
-import org.eobjects.metamodel.query.builder.InitFromBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+package org.apache.metamodel;
+
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.CompiledQuery;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.QueryParameter;
+import org.apache.metamodel.query.builder.InitFromBuilder;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
/**
* A DataContext represents the central entry point for interactions with
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 36e4b3e..1b4670b 100644
--- a/core/src/main/java/org/apache/metamodel/DeleteAndInsertBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/DeleteAndInsertBuilder.java
@@ -16,21 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.util.List;
import java.util.ListIterator;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.SimpleDataSetHeader;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.AbstractRowUpdationBuilder;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.data.SimpleDataSetHeader;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.update.AbstractRowUpdationBuilder;
+import org.apache.metamodel.update.RowUpdationBuilder;
/**
* Simple implementation of the {@link RowUpdationBuilder} interface, which
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/InconsistentRowFormatException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/InconsistentRowFormatException.java b/core/src/main/java/org/apache/metamodel/InconsistentRowFormatException.java
index b3baff9..490b725 100644
--- a/core/src/main/java/org/apache/metamodel/InconsistentRowFormatException.java
+++ b/core/src/main/java/org/apache/metamodel/InconsistentRowFormatException.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.Row;
/**
* Abstract exception type that represents exceptions that occur when reading a
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/MetaModelException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/MetaModelException.java b/core/src/main/java/org/apache/metamodel/MetaModelException.java
index 787b8c5..dca6c23 100644
--- a/core/src/main/java/org/apache/metamodel/MetaModelException.java
+++ b/core/src/main/java/org/apache/metamodel/MetaModelException.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
/**
* Unchecked exception used to signal errors occuring in MetaModel.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 a105973..c4dbd8d 100644
--- a/core/src/main/java/org/apache/metamodel/MetaModelHelper.java
+++ b/core/src/main/java/org/apache/metamodel/MetaModelHelper.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.util.ArrayList;
import java.util.Arrays;
@@ -29,35 +29,35 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import org.eobjects.metamodel.data.CachingDataSetHeader;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetHeader;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.EmptyDataSet;
-import org.eobjects.metamodel.data.FilteredDataSet;
-import org.eobjects.metamodel.data.IRowFilter;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.SimpleDataSetHeader;
-import org.eobjects.metamodel.data.SubSelectionDataSet;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.GroupByItem;
-import org.eobjects.metamodel.query.OrderByItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.query.parser.QueryParser;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.SuperColumnType;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.AggregateBuilder;
-import org.eobjects.metamodel.util.CollectionUtils;
-import org.eobjects.metamodel.util.EqualsBuilder;
-import org.eobjects.metamodel.util.Func;
-import org.eobjects.metamodel.util.ObjectComparator;
-import org.eobjects.metamodel.util.Predicate;
+import org.apache.metamodel.data.CachingDataSetHeader;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSetHeader;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.EmptyDataSet;
+import org.apache.metamodel.data.FilteredDataSet;
+import org.apache.metamodel.data.IRowFilter;
+import org.apache.metamodel.data.InMemoryDataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.data.SimpleDataSetHeader;
+import org.apache.metamodel.data.SubSelectionDataSet;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.GroupByItem;
+import org.apache.metamodel.query.OrderByItem;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.query.parser.QueryParser;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.SuperColumnType;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.AggregateBuilder;
+import org.apache.metamodel.util.CollectionUtils;
+import org.apache.metamodel.util.EqualsBuilder;
+import org.apache.metamodel.util.Func;
+import org.apache.metamodel.util.ObjectComparator;
+import org.apache.metamodel.util.Predicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 d84da6a..1cdca87 100644
--- a/core/src/main/java/org/apache/metamodel/QueryPostprocessDataContext.java
+++ b/core/src/main/java/org/apache/metamodel/QueryPostprocessDataContext.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.util.ArrayList;
import java.util.Arrays;
@@ -24,38 +24,38 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.eobjects.metamodel.convert.ConvertedDataSetInterceptor;
-import org.eobjects.metamodel.convert.Converters;
-import org.eobjects.metamodel.convert.HasReadTypeConverters;
-import org.eobjects.metamodel.convert.TypeConverter;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetHeader;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.EmptyDataSet;
-import org.eobjects.metamodel.data.FirstRowDataSet;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.data.MaxRowsDataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.SimpleDataSetHeader;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.GroupByItem;
-import org.eobjects.metamodel.query.JoinType;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.OrderByItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableRelationship;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.schema.TableType;
-import org.eobjects.metamodel.util.CollectionUtils;
+import org.apache.metamodel.convert.ConvertedDataSetInterceptor;
+import org.apache.metamodel.convert.Converters;
+import org.apache.metamodel.convert.HasReadTypeConverters;
+import org.apache.metamodel.convert.TypeConverter;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSetHeader;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.EmptyDataSet;
+import org.apache.metamodel.data.FirstRowDataSet;
+import org.apache.metamodel.data.InMemoryDataSet;
+import org.apache.metamodel.data.MaxRowsDataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.data.SimpleDataSetHeader;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.GroupByItem;
+import org.apache.metamodel.query.JoinType;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.OrderByItem;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableRelationship;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Relationship;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.schema.TableType;
+import org.apache.metamodel.util.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/QueryPostprocessDelegate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/QueryPostprocessDelegate.java b/core/src/main/java/org/apache/metamodel/QueryPostprocessDelegate.java
index 7d8dde3..0d69333 100644
--- a/core/src/main/java/org/apache/metamodel/QueryPostprocessDelegate.java
+++ b/core/src/main/java/org/apache/metamodel/QueryPostprocessDelegate.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
-import org.eobjects.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Schema;
/**
* A simple subclass of {@link QueryPostprocessDataContext} which provides less
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/SchemaNameComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/SchemaNameComparator.java b/core/src/main/java/org/apache/metamodel/SchemaNameComparator.java
index 14a2f82..cf36ecb 100644
--- a/core/src/main/java/org/apache/metamodel/SchemaNameComparator.java
+++ b/core/src/main/java/org/apache/metamodel/SchemaNameComparator.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
import java.util.Comparator;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/UpdateCallback.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/UpdateCallback.java b/core/src/main/java/org/apache/metamodel/UpdateCallback.java
index c19f03f..fffe755 100644
--- a/core/src/main/java/org/apache/metamodel/UpdateCallback.java
+++ b/core/src/main/java/org/apache/metamodel/UpdateCallback.java
@@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
-import org.eobjects.metamodel.create.TableCreatable;
-import org.eobjects.metamodel.delete.RowDeletable;
-import org.eobjects.metamodel.drop.TableDroppable;
-import org.eobjects.metamodel.insert.RowInsertable;
-import org.eobjects.metamodel.update.RowUpdateable;
+import org.apache.metamodel.create.TableCreatable;
+import org.apache.metamodel.delete.RowDeletable;
+import org.apache.metamodel.drop.TableDroppable;
+import org.apache.metamodel.insert.RowInsertable;
+import org.apache.metamodel.update.RowUpdateable;
/**
* An {@link UpdateCallback} is used by an {@link UpdateScript} to perform
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/UpdateScript.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/UpdateScript.java b/core/src/main/java/org/apache/metamodel/UpdateScript.java
index b10318e..101303f 100644
--- a/core/src/main/java/org/apache/metamodel/UpdateScript.java
+++ b/core/src/main/java/org/apache/metamodel/UpdateScript.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
-import org.eobjects.metamodel.util.Action;
+import org.apache.metamodel.util.Action;
/**
* Represents any updating operation or update script that can be executed on a
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/UpdateableDataContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/UpdateableDataContext.java b/core/src/main/java/org/apache/metamodel/UpdateableDataContext.java
index 3153f75..5042451 100644
--- a/core/src/main/java/org/apache/metamodel/UpdateableDataContext.java
+++ b/core/src/main/java/org/apache/metamodel/UpdateableDataContext.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel;
+package org.apache.metamodel;
/**
* Represents a {@link DataContext} that supports updating write-operations.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/convert/ColumnTypeDetector.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/ColumnTypeDetector.java b/core/src/main/java/org/apache/metamodel/convert/ColumnTypeDetector.java
index 1355c95..7ff75f2 100644
--- a/core/src/main/java/org/apache/metamodel/convert/ColumnTypeDetector.java
+++ b/core/src/main/java/org/apache/metamodel/convert/ColumnTypeDetector.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
-import org.eobjects.metamodel.util.BooleanComparator;
-import org.eobjects.metamodel.util.TimeComparator;
+import org.apache.metamodel.util.BooleanComparator;
+import org.apache.metamodel.util.TimeComparator;
/**
* A class capable of detecting/narrowing a string column type to something more
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/convert/ConvertedDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/ConvertedDataSet.java b/core/src/main/java/org/apache/metamodel/convert/ConvertedDataSet.java
index ff0cf79..ffd85ab 100644
--- a/core/src/main/java/org/apache/metamodel/convert/ConvertedDataSet.java
+++ b/core/src/main/java/org/apache/metamodel/convert/ConvertedDataSet.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
-import org.eobjects.metamodel.data.AbstractDataSet;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.Row;
+import org.apache.metamodel.data.AbstractDataSet;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.Row;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 159c469..d5746de 100644
--- a/core/src/main/java/org/apache/metamodel/convert/ConvertedDataSetInterceptor.java
+++ b/core/src/main/java/org/apache/metamodel/convert/ConvertedDataSetInterceptor.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
import java.util.HashMap;
import java.util.Map;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.intercept.DataSetInterceptor;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.intercept.DataSetInterceptor;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
/**
* A {@link DataSetInterceptor} used for intercepting values in {@link DataSet}s
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/convert/ConvertedRowInsertionInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/ConvertedRowInsertionInterceptor.java b/core/src/main/java/org/apache/metamodel/convert/ConvertedRowInsertionInterceptor.java
index b7ea3ad..2ef21b0 100644
--- a/core/src/main/java/org/apache/metamodel/convert/ConvertedRowInsertionInterceptor.java
+++ b/core/src/main/java/org/apache/metamodel/convert/ConvertedRowInsertionInterceptor.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
import java.util.HashMap;
import java.util.Map;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.intercept.RowInsertionInterceptor;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.intercept.RowInsertionInterceptor;
+import org.apache.metamodel.schema.Column;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/convert/ConvertedRowUpdationInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/ConvertedRowUpdationInterceptor.java b/core/src/main/java/org/apache/metamodel/convert/ConvertedRowUpdationInterceptor.java
index 6a42107..cfe92af 100644
--- a/core/src/main/java/org/apache/metamodel/convert/ConvertedRowUpdationInterceptor.java
+++ b/core/src/main/java/org/apache/metamodel/convert/ConvertedRowUpdationInterceptor.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
import java.util.HashMap;
import java.util.Map;
-import org.eobjects.metamodel.intercept.RowUpdationInterceptor;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
+import org.apache.metamodel.intercept.RowUpdationInterceptor;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.update.RowUpdationBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 7b7b43c..1be0e13 100644
--- a/core/src/main/java/org/apache/metamodel/convert/Converters.java
+++ b/core/src/main/java/org/apache/metamodel/convert/Converters.java
@@ -16,26 +16,26 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.RowBuilder;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.intercept.InterceptableDataContext;
-import org.eobjects.metamodel.intercept.Interceptors;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.SuperColumnType;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelHelper;
+import org.apache.metamodel.UpdateableDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.data.RowBuilder;
+import org.apache.metamodel.data.Style;
+import org.apache.metamodel.intercept.InterceptableDataContext;
+import org.apache.metamodel.intercept.Interceptors;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.SuperColumnType;
+import org.apache.metamodel.schema.Table;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/convert/HasReadTypeConverters.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/HasReadTypeConverters.java b/core/src/main/java/org/apache/metamodel/convert/HasReadTypeConverters.java
index 5f63c1e..e85e777 100644
--- a/core/src/main/java/org/apache/metamodel/convert/HasReadTypeConverters.java
+++ b/core/src/main/java/org/apache/metamodel/convert/HasReadTypeConverters.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.schema.Column;
/**
* Defines an interface for objects that are aware of {@link TypeConverter}s,
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/convert/StringToBooleanConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/StringToBooleanConverter.java b/core/src/main/java/org/apache/metamodel/convert/StringToBooleanConverter.java
index fb546a4..6faa459 100644
--- a/core/src/main/java/org/apache/metamodel/convert/StringToBooleanConverter.java
+++ b/core/src/main/java/org/apache/metamodel/convert/StringToBooleanConverter.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
-import org.eobjects.metamodel.util.BooleanComparator;
+import org.apache.metamodel.util.BooleanComparator;
/**
* A {@link TypeConverter} that converts String values (on the physical layer)
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/convert/StringToDateConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/StringToDateConverter.java b/core/src/main/java/org/apache/metamodel/convert/StringToDateConverter.java
index 1684a31..ba1e5cb 100644
--- a/core/src/main/java/org/apache/metamodel/convert/StringToDateConverter.java
+++ b/core/src/main/java/org/apache/metamodel/convert/StringToDateConverter.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
-import org.eobjects.metamodel.util.Func;
-import org.eobjects.metamodel.util.TimeComparator;
+import org.apache.metamodel.util.Func;
+import org.apache.metamodel.util.TimeComparator;
/**
* A {@link TypeConverter} that converts String values (on the physical layer)
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/convert/StringToDoubleConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/StringToDoubleConverter.java b/core/src/main/java/org/apache/metamodel/convert/StringToDoubleConverter.java
index 6ce6406..d10cea0 100644
--- a/core/src/main/java/org/apache/metamodel/convert/StringToDoubleConverter.java
+++ b/core/src/main/java/org/apache/metamodel/convert/StringToDoubleConverter.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
/**
* A {@link TypeConverter} that converts String values (on the physical layer)
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/convert/StringToIntegerConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/StringToIntegerConverter.java b/core/src/main/java/org/apache/metamodel/convert/StringToIntegerConverter.java
index 4aafe7d..cdc9f82 100644
--- a/core/src/main/java/org/apache/metamodel/convert/StringToIntegerConverter.java
+++ b/core/src/main/java/org/apache/metamodel/convert/StringToIntegerConverter.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
/**
* A {@link TypeConverter} that converts String values (on the physical layer)
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/convert/TypeConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/TypeConverter.java b/core/src/main/java/org/apache/metamodel/convert/TypeConverter.java
index 542449e..2b54c72 100644
--- a/core/src/main/java/org/apache/metamodel/convert/TypeConverter.java
+++ b/core/src/main/java/org/apache/metamodel/convert/TypeConverter.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
/**
* Defines an interface for converting values from and to their physical
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/convert/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/package-info.java b/core/src/main/java/org/apache/metamodel/convert/package-info.java
index 0adf2aa..1d1ce41 100644
--- a/core/src/main/java/org/apache/metamodel/convert/package-info.java
+++ b/core/src/main/java/org/apache/metamodel/convert/package-info.java
@@ -19,5 +19,5 @@
/**
* DataContext decorator for implicit conversion of value types after querying and before insertion.
*/
-package org.eobjects.metamodel.convert;
+package org.apache.metamodel.convert;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/create/AbstractColumnBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/create/AbstractColumnBuilder.java b/core/src/main/java/org/apache/metamodel/create/AbstractColumnBuilder.java
index 26fee26..408eecd 100644
--- a/core/src/main/java/org/apache/metamodel/create/AbstractColumnBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/create/AbstractColumnBuilder.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.create;
+package org.apache.metamodel.create;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
/**
* Convenience implementation of all {@link ColumnBuilder} methods
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 d833b1e..61fd359 100644
--- a/core/src/main/java/org/apache/metamodel/create/AbstractTableCreationBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/create/AbstractTableCreationBuilder.java
@@ -16,16 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.create;
+package org.apache.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.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.schema.TableType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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
index 1d6a7c2..031d23e 100644
--- a/core/src/main/java/org/apache/metamodel/create/ColumnBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/create/ColumnBuilder.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.create;
+package org.apache.metamodel.create;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
/**
* Abstract interface for components that build columns.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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
index 4792e85..314e820 100644
--- a/core/src/main/java/org/apache/metamodel/create/ColumnCreationBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/create/ColumnCreationBuilder.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.create;
+package org.apache.metamodel.create;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.schema.Column;
/**
* Builder object for creating {@link Column}s. This class also extendsthe
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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
index 1aba1d4..0034c10 100644
--- a/core/src/main/java/org/apache/metamodel/create/ColumnCreationBuilderImpl.java
+++ b/core/src/main/java/org/apache/metamodel/create/ColumnCreationBuilderImpl.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.create;
+package org.apache.metamodel.create;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.Table;
/**
* Implementation of the {@link ColumnCreationBuilder}.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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
index c40c823..b189bd2 100644
--- a/core/src/main/java/org/apache/metamodel/create/CreateTable.java
+++ b/core/src/main/java/org/apache/metamodel/create/CreateTable.java
@@ -16,17 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.create;
+package org.apache.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;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.UpdateableDataContext;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.TableType;
/**
* Represents a single CREATE TABLE operation to be applied to a
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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
index 240abb2..8cd1e0d 100644
--- a/core/src/main/java/org/apache/metamodel/create/CreateTableColumnBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/create/CreateTableColumnBuilder.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.create;
+package org.apache.metamodel.create;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.schema.MutableColumn;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.schema.MutableColumn;
/**
* Column builder for {@link CreateTable}.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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
index 2b42133..672741b 100644
--- a/core/src/main/java/org/apache/metamodel/create/TableCreatable.java
+++ b/core/src/main/java/org/apache/metamodel/create/TableCreatable.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.create;
+package org.apache.metamodel.create;
-import org.eobjects.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Schema;
/**
* Interface for objects that support creating new tables.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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
index c3dfefd..c39ca4d 100644
--- a/core/src/main/java/org/apache/metamodel/create/TableCreationBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/create/TableCreationBuilder.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.create;
+package org.apache.metamodel.create;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.schema.Table;
/**
* Builder object for {@link Table} creation.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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
index 44c5ed9..fbb1f3b 100644
--- a/core/src/main/java/org/apache/metamodel/create/package-info.java
+++ b/core/src/main/java/org/apache/metamodel/create/package-info.java
@@ -19,5 +19,5 @@
/**
* API for creating tables
*/
-package org.eobjects.metamodel.create;
+package org.apache.metamodel.create;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 98b9416..ac04a93 100644
--- a/core/src/main/java/org/apache/metamodel/data/AbstractDataSet.java
+++ b/core/src/main/java/org/apache/metamodel/data/AbstractDataSet.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import java.util.ArrayList;
import java.util.Arrays;
@@ -25,10 +25,10 @@ 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;
+import org.apache.metamodel.MetaModelHelper;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.util.BaseObject;
/**
* Abstract DataSet implementation. Provides convenient implementations of
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 74340fe..b736592 100644
--- a/core/src/main/java/org/apache/metamodel/data/AbstractRow.java
+++ b/core/src/main/java/org/apache/metamodel/data/AbstractRow.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import java.util.Arrays;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
/**
* An abstract row that decorates another row. Useful for virtual data that may
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 32f6d33..fef04c9 100644
--- a/core/src/main/java/org/apache/metamodel/data/AbstractRowBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/data/AbstractRowBuilder.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.data;
+package org.apache.metamodel.data;
import java.util.Arrays;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
/**
* Abstract {@link RowBuilder} implementation.
[25/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/data/FirstRowDataSetTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/data/FirstRowDataSetTest.java b/core/src/test/java/org/apache/metamodel/data/FirstRowDataSetTest.java
new file mode 100644
index 0000000..a733687
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/data/FirstRowDataSetTest.java
@@ -0,0 +1,83 @@
+/**
+ * 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.List;
+
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.MutableColumn;
+
+import junit.framework.TestCase;
+
+public class FirstRowDataSetTest extends TestCase {
+
+ private List<Row> rows;
+ private SelectItem[] items = new SelectItem[] { new SelectItem(new MutableColumn("foobar")) };
+ private DataSetHeader header = new SimpleDataSetHeader(items);
+ private InMemoryDataSet dataSet;
+
+ protected void setUp() throws Exception {
+ rows = new ArrayList<Row>();
+ rows.add(new DefaultRow(header, new Object[] { 1 }));
+ rows.add(new DefaultRow(header, new Object[] { 2 }));
+ rows.add(new DefaultRow(header, new Object[] { 3 }));
+ rows.add(new DefaultRow(header, new Object[] { 4 }));
+ rows.add(new DefaultRow(header, new Object[] { 5 }));
+ dataSet = new InMemoryDataSet(header, rows);
+ };
+
+ public void testHighestPossibleOffset() throws Exception {
+ FirstRowDataSet ds = new FirstRowDataSet(dataSet, 5);
+ assertTrue(ds.next());
+ assertEquals(5, ds.getRow().getValue(0));
+ assertFalse(ds.next());
+
+ ds.close();
+ }
+
+ public void testOffsetHigherThanSize() throws Exception {
+ FirstRowDataSet ds = new FirstRowDataSet(dataSet, 8);
+ assertFalse(ds.next());
+
+ ds.close();
+ }
+
+ public void testOneOffset() throws Exception {
+ FirstRowDataSet ds = new FirstRowDataSet(dataSet, 1);
+ assertTrue(ds.next());
+ assertEquals(1, ds.getRow().getValue(0));
+ ds.close();
+ }
+
+ public void testVanillaScenario() throws Exception {
+ FirstRowDataSet ds = new FirstRowDataSet(dataSet, 2);
+ assertTrue(ds.next());
+ assertEquals(2, ds.getRow().getValue(0));
+ assertTrue(ds.next());
+ assertEquals(3, ds.getRow().getValue(0));
+ assertTrue(ds.next());
+ assertEquals(4, ds.getRow().getValue(0));
+ assertTrue(ds.next());
+ assertEquals(5, ds.getRow().getValue(0));
+ assertFalse(ds.next());
+
+ ds.close();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/data/RowPublisherDataSetTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/data/RowPublisherDataSetTest.java b/core/src/test/java/org/apache/metamodel/data/RowPublisherDataSetTest.java
new file mode 100644
index 0000000..7e8b882
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/data/RowPublisherDataSetTest.java
@@ -0,0 +1,89 @@
+/**
+ * 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 junit.framework.TestCase;
+
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.util.Action;
+
+public class RowPublisherDataSetTest extends TestCase {
+
+ public void testMaxSize() throws Exception {
+ SelectItem[] selectItems = new SelectItem[2];
+ selectItems[0] = new SelectItem(new MutableColumn("foos"));
+ selectItems[1] = new SelectItem(new MutableColumn("bars"));
+ DataSet ds = new RowPublisherDataSet(selectItems, 5,
+ new Action<RowPublisher>() {
+ @Override
+ public void run(RowPublisher publisher) throws Exception {
+
+ // we want to exceed the buffer size
+ int iterations = RowPublisherImpl.BUFFER_SIZE * 2;
+
+ for (int i = 0; i < iterations; i++) {
+ publisher.publish(new Object[] { "foo" + i,
+ "bar" + i });
+ }
+ }
+ });
+
+ assertTrue(ds.next());
+ assertEquals("Row[values=[foo0, bar0]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertTrue(ds.next());
+ assertTrue(ds.next());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[foo4, bar4]]", ds.getRow().toString());
+ assertFalse(ds.next());
+
+ ds.close();
+ }
+
+ public void testExceptionInAction() throws Exception {
+ SelectItem[] selectItems = new SelectItem[2];
+ selectItems[0] = new SelectItem(new MutableColumn("foos"));
+ selectItems[1] = new SelectItem(new MutableColumn("bars"));
+ DataSet ds = new RowPublisherDataSet(selectItems, 5,
+ new Action<RowPublisher>() {
+ @Override
+ public void run(RowPublisher publisher) throws Exception {
+ publisher.publish(new Object[] { "foo0", "bar0" });
+ publisher.publish(new Object[] { "foo1", "bar1" });
+ throw new IllegalStateException("foobar!");
+ }
+ });
+
+ assertTrue(ds.next());
+ assertEquals("Row[values=[foo0, bar0]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[foo1, bar1]]", ds.getRow().toString());
+
+ try {
+ ds.next();
+ fail("Exception expected");
+ } catch (Exception e) {
+ assertEquals("foobar!", e.getMessage());
+ assertEquals(IllegalStateException.class, e.getClass());
+ } finally {
+ ds.close();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/data/RowTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/data/RowTest.java b/core/src/test/java/org/apache/metamodel/data/RowTest.java
new file mode 100644
index 0000000..4c8628e
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/data/RowTest.java
@@ -0,0 +1,57 @@
+/**
+ * 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 org.eobjects.metamodel.MetaModelTestCase;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+public class RowTest extends MetaModelTestCase {
+
+ public void testRow() throws Exception {
+ Schema schema = getExampleSchema();
+ Table projectTable = schema.getTableByName(TABLE_PROJECT);
+ SelectItem item = new SelectItem(projectTable.getColumns()[0]);
+ SelectItem[] items = { item };
+ DataSetHeader header = new CachingDataSetHeader(items);
+ Object[] values = { "foobar" };
+ Row row = new DefaultRow(header, values);
+ assertEquals("Row[values=[foobar]]", row.toString());
+ assertEquals("foobar", row.getValue(0));
+ assertEquals("foobar", row.getValues()[0]);
+ assertEquals("foobar", row.getValue(item));
+ assertEquals(item, row.getSelectItems()[0]);
+ }
+
+ public void testGetSubSelection() throws Exception {
+ Schema schema = getExampleSchema();
+ Table projectTable = schema.getTableByName(TABLE_PROJECT);
+ SelectItem item1 = new SelectItem(projectTable.getColumns()[0]);
+ SelectItem item2 = new SelectItem(projectTable.getColumns()[0]);
+ SelectItem[] items = { item1, item2 };
+ DataSetHeader header = new CachingDataSetHeader(items);
+ Object[] values = { "foo", "bar" };
+ Row row = new DefaultRow(header, values);
+ row = row.getSubSelection(new SimpleDataSetHeader(new SelectItem[] { item1 }));
+ assertEquals(1, row.getSelectItems().length);
+ assertEquals(1, row.getValues().length);
+ assertEquals("foo", row.getValue(0));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/data/StyleBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/data/StyleBuilderTest.java b/core/src/test/java/org/apache/metamodel/data/StyleBuilderTest.java
new file mode 100644
index 0000000..5ad7e41
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/data/StyleBuilderTest.java
@@ -0,0 +1,60 @@
+/**
+ * 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 org.eobjects.metamodel.data.Style.Color;
+
+import junit.framework.TestCase;
+
+public class StyleBuilderTest extends TestCase {
+
+ public void testDefaultColors() throws Exception {
+ StyleBuilder sb = new StyleBuilder();
+
+ sb.foreground(1, 1, 1);
+ assertEquals("color: rgb(1,1,1);", sb.create().toCSS());
+
+ sb.foreground(0, 0, 0);
+ assertEquals("", sb.create().toCSS());
+
+ sb.background(0, 0, 0);
+ assertEquals("background-color: rgb(0,0,0);", sb.create().toCSS());
+
+ sb.background(255, 255, 255);
+ assertEquals("", sb.create().toCSS());
+ }
+
+ public void testCreateNoStyle() throws Exception {
+ Style style = new StyleBuilder().create();
+ assertEquals(Style.NO_STYLE, style);
+ assertSame(Style.NO_STYLE, style);
+ }
+
+ public void testCreateColor() throws Exception {
+ Color col1 = StyleBuilder.createColor("eeEE00");
+ assertEquals("Color[238,238,0]", col1.toString());
+
+ Color col2 = StyleBuilder.createColor(238, 238, 0);
+
+ // cache should ensure that these two colors are not only equal, but
+ // also the same!
+ assertEquals(col1, col2);
+ assertSame(col1, col2);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/delete/AbstractRowDeletionCallbackTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/delete/AbstractRowDeletionCallbackTest.java b/core/src/test/java/org/apache/metamodel/delete/AbstractRowDeletionCallbackTest.java
new file mode 100644
index 0000000..d37c102
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/delete/AbstractRowDeletionCallbackTest.java
@@ -0,0 +1,76 @@
+/**
+ * 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.delete;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.MockUpdateableDataContext;
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.schema.Table;
+
+public class AbstractRowDeletionCallbackTest extends TestCase {
+
+ public void testDelete() throws Exception {
+ final MockUpdateableDataContext dc = new MockUpdateableDataContext();
+ final Table table = dc.getDefaultSchema().getTables()[0];
+ DataSet ds = dc.query().from(table).selectCount().execute();
+ assertTrue(ds.next());
+ assertEquals("3", ds.getRow().getValue(0).toString());
+ assertFalse(ds.next());
+ ds.close();
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.update(table).value("bar", "baz").execute();
+ callback.update(table).value("foo", "4").where("foo").eq("3").execute();
+ }
+ });
+
+ ds = dc.query().from(table).select(table.getColumns()).execute();
+ assertTrue(ds.next());
+ assertEquals("Row[values=[1, baz]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[2, baz]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[4, baz]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ ds.close();
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ RowDeletionBuilder delete = callback.deleteFrom(table);
+ assertEquals("DELETE FROM schema.table", delete.toSql());
+ delete.execute();
+
+ assertEquals("DELETE FROM schema.table WHERE table.bar = 'baz'", callback.deleteFrom(table).where("bar")
+ .eq("baz").toSql());
+ }
+ });
+
+ ds = dc.query().from(table).selectCount().execute();
+ assertTrue(ds.next());
+ assertEquals("0", ds.getRow().getValue(0).toString());
+ assertFalse(ds.next());
+ ds.close();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/insert/AbstractInsertBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/insert/AbstractInsertBuilderTest.java b/core/src/test/java/org/apache/metamodel/insert/AbstractInsertBuilderTest.java
new file mode 100644
index 0000000..27249aa
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/insert/AbstractInsertBuilderTest.java
@@ -0,0 +1,92 @@
+/**
+ * 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.insert;
+
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.schema.MutableTable;
+import org.eobjects.metamodel.util.MutableRef;
+
+public class AbstractInsertBuilderTest extends TestCase {
+
+ public void testInsertValues() throws Exception {
+ final MutableRef<Boolean> executed = new MutableRef<Boolean>(false);
+ final MutableTable table = new MutableTable("foo");
+ table.addColumn(new MutableColumn("foo"));
+ table.addColumn(new MutableColumn("bar"));
+ table.addColumn(new MutableColumn("baz"));
+ RowInsertionBuilder insertBuilder = new AbstractRowInsertionBuilder<UpdateCallback>(
+ null, table) {
+ @Override
+ public void execute() throws MetaModelException {
+ assertEquals("[1, 2, 3]", Arrays.toString(getValues()));
+ executed.set(true);
+ }
+ };
+
+ assertFalse(executed.get().booleanValue());
+
+ insertBuilder.value(0, 1).value("bar", 2)
+ .value(table.getColumnByName("baz"), 3).execute();
+
+ assertTrue(executed.get());
+
+ assertEquals("Row[values=[1, 2, 3]]", insertBuilder.toRow().toString());
+
+ }
+
+ public void testIllegalArguments() throws Exception {
+ final MutableTable table = new MutableTable("foo");
+ table.addColumn(new MutableColumn("foo"));
+ RowInsertionBuilder insertBuilder = new AbstractRowInsertionBuilder<UpdateCallback>(
+ null, table) {
+ @Override
+ public void execute() throws MetaModelException {
+ }
+ };
+
+ try {
+ insertBuilder.value((Column)null, "foo");
+ fail("Exception expected");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Column cannot be null", e.getMessage());
+ }
+
+ try {
+ insertBuilder.value("hmm", "foo");
+ fail("Exception expected");
+ } catch (IllegalArgumentException e) {
+ assertEquals("No such column in table: hmm, available columns are: [Column[name=foo,columnNumber=0,type=null,nullable=null,nativeType=null,columnSize=null]]", e.getMessage());
+ }
+
+ try {
+ insertBuilder.value(4, "foo");
+ fail("Exception expected");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ assertTrue("4".equals(e.getMessage())
+ || "Array index out of range: 4".equals(e.getMessage()));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/insert/SyntaxExamplesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/insert/SyntaxExamplesTest.java b/core/src/test/java/org/apache/metamodel/insert/SyntaxExamplesTest.java
new file mode 100644
index 0000000..e2ebb50
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/insert/SyntaxExamplesTest.java
@@ -0,0 +1,44 @@
+/**
+ * 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.insert;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.UpdateableDataContext;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+
+public abstract class SyntaxExamplesTest extends TestCase {
+
+ private UpdateableDataContext dc;
+ private Table table;
+ private Column col;
+
+ public void testInsertMultipleRows() throws Exception {
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ cb.insertInto(table).value(col, "foo").execute();
+ cb.insertInto(table).value(col, "bar").execute();
+ }
+ });
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/intercept/InterceptableDataContextTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/intercept/InterceptableDataContextTest.java b/core/src/test/java/org/apache/metamodel/intercept/InterceptableDataContextTest.java
new file mode 100644
index 0000000..96fc5dc
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/intercept/InterceptableDataContextTest.java
@@ -0,0 +1,113 @@
+/**
+ * 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.intercept;
+
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.MockUpdateableDataContext;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.MaxRowsDataSet;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.MutableSchema;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+public class InterceptableDataContextTest extends TestCase {
+
+ private final MockUpdateableDataContext delegateDataContext = new MockUpdateableDataContext();
+ private final Table table = delegateDataContext.getDefaultSchema()
+ .getTables()[0];
+
+ public void testInterceptSchema() throws Exception {
+ // without an interceptor
+ {
+ DataContext dc = new InterceptableDataContext(delegateDataContext);
+
+ Schema schema = dc.getDefaultSchema();
+ Schema[] schemas = dc.getSchemas();
+
+ assertEquals("schema", schema.getName());
+ assertEquals(MutableSchema.class, schema.getClass());
+ assertEquals("[information_schema, schema]",
+ Arrays.toString(dc.getSchemaNames()));
+ assertEquals(2, schemas.length);
+ assertEquals("information_schema", schemas[0].getName());
+ assertEquals("schema", schemas[1].getName());
+ }
+
+ // with an interceptor
+ {
+ DataContext dc = new InterceptableDataContext(delegateDataContext)
+ .addSchemaInterceptor(new SchemaInterceptor() {
+ @Override
+ public Schema intercept(Schema input) {
+ return new MutableSchema(input.getName() + " foo!");
+ }
+ });
+
+ Schema schema = dc.getDefaultSchema();
+ Schema[] schemas = dc.getSchemas();
+
+ assertEquals("schema foo!", schema.getName());
+ assertEquals(MutableSchema.class, schema.getClass());
+ assertEquals("[information_schema foo!, schema foo!]",
+ Arrays.toString(dc.getSchemaNames()));
+ assertEquals(2, schemas.length);
+ assertEquals("information_schema foo!", schemas[0].getName());
+ assertEquals("schema foo!", schemas[1].getName());
+ }
+ }
+
+ public void testInterceptDataSet() throws Exception {
+ DataContext dc = new InterceptableDataContext(delegateDataContext)
+ .addDataSetInterceptor(new DataSetInterceptor() {
+ @Override
+ public DataSet intercept(DataSet dataSet) {
+ return new MaxRowsDataSet(dataSet, 1);
+ }
+ });
+
+ DataSet ds = dc.query().from(table).select("foo").execute();
+ assertEquals(MaxRowsDataSet.class, ds.getClass());
+ assertEquals(1, ds.toObjectArrays().size());
+ }
+
+ public void testInterceptQuery() throws Exception {
+
+ DataContext dc = new InterceptableDataContext(delegateDataContext)
+ .addQueryInterceptor(new QueryInterceptor() {
+ @Override
+ public Query intercept(Query input) {
+ return input.select(table.getColumnByName("foo"));
+ }
+ }).addQueryInterceptor(new QueryInterceptor() {
+ @Override
+ public Query intercept(Query input) {
+ return input.select(table.getColumnByName("bar"));
+
+ }
+ });
+
+ DataSet ds = dc.executeQuery(new Query().from(table));
+ assertEquals("[table.foo, table.bar]", Arrays.toString(ds.getSelectItems()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/intercept/InterceptorListTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/intercept/InterceptorListTest.java b/core/src/test/java/org/apache/metamodel/intercept/InterceptorListTest.java
new file mode 100644
index 0000000..04fcecd
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/intercept/InterceptorListTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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.intercept;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.MockUpdateableDataContext;
+import org.eobjects.metamodel.convert.ConvertedDataSetInterceptor;
+import org.eobjects.metamodel.data.DataSet;
+
+import junit.framework.TestCase;
+
+public class InterceptorListTest extends TestCase {
+
+ public void testGetInterceptorOfType() throws Exception {
+ DataContext dc = new MockUpdateableDataContext();
+ InterceptableDataContext interceptor = Interceptors.intercept(dc);
+
+ InterceptorList<DataSet> list = interceptor.getDataSetInterceptors();
+ ConvertedDataSetInterceptor convertedDataSetInterceptor = new ConvertedDataSetInterceptor();
+ list.add(convertedDataSetInterceptor);
+
+ assertSame(convertedDataSetInterceptor, list.getInterceptorOfType(DataSetInterceptor.class));
+ assertSame(convertedDataSetInterceptor, list.getInterceptorOfType(ConvertedDataSetInterceptor.class));
+
+ class NoopDataSetInterceptor implements DataSetInterceptor {
+ @Override
+ public DataSet intercept(DataSet dataSet) {
+ return dataSet;
+ }
+ };
+
+ NoopDataSetInterceptor noopDataSetInterceptor = new NoopDataSetInterceptor();
+ list.add(noopDataSetInterceptor);
+
+ assertSame(convertedDataSetInterceptor, list.getInterceptorOfType(DataSetInterceptor.class));
+ assertSame(convertedDataSetInterceptor, list.getInterceptorOfType(ConvertedDataSetInterceptor.class));
+ assertSame(noopDataSetInterceptor, list.getInterceptorOfType(NoopDataSetInterceptor.class));
+
+ list.remove(convertedDataSetInterceptor);
+
+ assertSame(noopDataSetInterceptor, list.getInterceptorOfType(DataSetInterceptor.class));
+ assertNull(list.getInterceptorOfType(ConvertedDataSetInterceptor.class));
+ assertSame(noopDataSetInterceptor, list.getInterceptorOfType(NoopDataSetInterceptor.class));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/intercept/InterceptorsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/intercept/InterceptorsTest.java b/core/src/test/java/org/apache/metamodel/intercept/InterceptorsTest.java
new file mode 100644
index 0000000..2420370
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/intercept/InterceptorsTest.java
@@ -0,0 +1,33 @@
+/**
+ * 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.intercept;
+
+import org.eobjects.metamodel.MockUpdateableDataContext;
+
+import junit.framework.TestCase;
+
+public class InterceptorsTest extends TestCase {
+
+ public void testReuseInterceptor() throws Exception {
+ MockUpdateableDataContext original = new MockUpdateableDataContext();
+ InterceptableDataContext interceptor1 = Interceptors.intercept(original);
+ InterceptableDataContext interceptor2 = Interceptors.intercept(interceptor1);
+ assertSame(interceptor1, interceptor2);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/query/DefaultCompiledQueryTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/DefaultCompiledQueryTest.java b/core/src/test/java/org/apache/metamodel/query/DefaultCompiledQueryTest.java
new file mode 100644
index 0000000..7d85f5c
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/query/DefaultCompiledQueryTest.java
@@ -0,0 +1,92 @@
+/**
+ * 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.query;
+
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.schema.MutableTable;
+import org.eobjects.metamodel.schema.TableType;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class DefaultCompiledQueryTest {
+
+ Query query;
+
+ @Before
+ public void setup() {
+ query = new Query();
+
+ MutableTable datastoreTable = new MutableTable("datastore", TableType.TABLE);
+
+ MutableColumn dataSourceIdColumn = new MutableColumn("dataSourceIdColumn", ColumnType.VARCHAR);
+ MutableColumn dataSourceNameColumn = new MutableColumn("dataSourceNameColumn", ColumnType.VARCHAR);
+ MutableColumn versionColumn = new MutableColumn("versionColumn", ColumnType.INTEGER);
+ MutableColumn changeSetColumn = new MutableColumn("changeSetColumn", ColumnType.INTEGER);
+
+ SelectItem countSelectItem = new SelectItem(FunctionType.COUNT, dataSourceIdColumn);
+ SelectItem dsIdSelectItem = new SelectItem(dataSourceIdColumn).setAlias("innerDataSourceRecordId");
+ Query leftQuery = new Query();
+ leftQuery.select(dsIdSelectItem);
+ leftQuery.groupBy(dataSourceIdColumn);
+ leftQuery.having(new FilterItem(countSelectItem.toSql() + " " + OperatorType.EQUALS_TO.toSql() + " 2"));
+ leftQuery.where(dataSourceNameColumn, OperatorType.EQUALS_TO, new QueryParameter());
+ leftQuery.from(datastoreTable);
+ FromItem leftFrom = new FromItem(leftQuery);
+ leftFrom.setAlias("innerDS");
+
+ query.select(changeSetColumn);
+ query.from(leftFrom, new FromItem(datastoreTable));
+ query.where(versionColumn, OperatorType.EQUALS_TO, 2);
+ query.where(changeSetColumn, OperatorType.EQUALS_TO, new QueryParameter());
+ // Checks if max count is 2 in order to assert that this record has not
+ // been a part of any changeSets previously and not processed by GR
+ // creation in the current run.
+ query.where(new SelectItem(dsIdSelectItem, leftFrom), OperatorType.EQUALS_TO, dsIdSelectItem);
+ query.where(dataSourceNameColumn, OperatorType.EQUALS_TO, new QueryParameter());
+ }
+
+ @Test
+ public void testGetParameterLogic() {
+
+ DefaultCompiledQuery defaultCompiledQuery = new DefaultCompiledQuery(query);
+ Assert.assertEquals(3, defaultCompiledQuery.getParameters().size());
+
+ Assert.assertEquals(
+ "DefaultCompiledQuery["
+ + "SELECT changeSetColumn FROM (SELECT dataSourceIdColumn AS innerDataSourceRecordId FROM datastore WHERE dataSourceNameColumn = ? GROUP BY dataSourceIdColumn HAVING COUNT(dataSourceIdColumn) = 2) innerDS, datastore "
+ + "WHERE versionColumn = 2 AND changeSetColumn = ? AND innerDS.innerDataSourceRecordId = dataSourceIdColumn AND dataSourceNameColumn = ?]",
+ defaultCompiledQuery.toString());
+
+ defaultCompiledQuery.close();
+ }
+
+ @Test
+ public void testCloneWithParameterValues() {
+ DefaultCompiledQuery defaultCompiledQuery = new DefaultCompiledQuery(query);
+ Query resultQuery = defaultCompiledQuery.cloneWithParameterValues(new Object[] { "BE", 1, "BE" });
+ defaultCompiledQuery.close();
+
+ defaultCompiledQuery = new DefaultCompiledQuery(resultQuery);
+ Assert.assertEquals(0, defaultCompiledQuery.getParameters().size());
+ defaultCompiledQuery.close();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/query/FilterItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/FilterItemTest.java b/core/src/test/java/org/apache/metamodel/query/FilterItemTest.java
new file mode 100644
index 0000000..9ed783c
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/query/FilterItemTest.java
@@ -0,0 +1,413 @@
+/**
+ * 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.query;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.QueryPostprocessDataContext;
+import org.eobjects.metamodel.data.CachingDataSetHeader;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.DataSetHeader;
+import org.eobjects.metamodel.data.DefaultRow;
+import org.eobjects.metamodel.data.InMemoryDataSet;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.data.SimpleDataSetHeader;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+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.Table;
+import org.eobjects.metamodel.schema.TableType;
+
+public class FilterItemTest extends TestCase {
+
+ public void testExpressionBasedFilter() throws Exception {
+ FilterItem filterItem = new FilterItem("foobar");
+ assertEquals("foobar", filterItem.getExpression());
+
+ try {
+ filterItem.evaluate(null);
+ fail("Exception should have been thrown");
+ } catch (Exception e) {
+ assertEquals("Expression-based filters cannot be manually evaluated", e.getMessage());
+ }
+
+ Column col1 = new MutableColumn("Col1", ColumnType.VARCHAR);
+ assertEquals("SELECT Col1 WHERE foobar", new Query().select(col1).where(filterItem).toString());
+
+ assertEquals("SELECT Col1 WHERE YEAR(Col1) = 2008", new Query().select(col1).where("YEAR(Col1) = 2008")
+ .toString());
+ }
+
+ public void testToSqlWhereItem() throws Exception {
+ MutableColumn col1 = new MutableColumn("Col1", ColumnType.VARCHAR);
+ SelectItem selectItem = new SelectItem(col1);
+ FilterItem c = new FilterItem(selectItem, OperatorType.DIFFERENT_FROM, null);
+ assertEquals("Col1 IS NOT NULL", c.toString());
+
+ try {
+ c = new FilterItem(selectItem, OperatorType.GREATER_THAN, null);
+ fail("Exception should have been thrown");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Can only use EQUALS or DIFFERENT_FROM operator with null-operand", e.getMessage());
+ }
+
+ c = new FilterItem(selectItem, OperatorType.DIFFERENT_FROM, "foo");
+ assertEquals("Col1 <> 'foo'", c.toString());
+
+ c = new FilterItem(selectItem, OperatorType.DIFFERENT_FROM, "'bar'");
+
+ // this will be rewritten so it's not an issue even though it look like
+ // it needs an escape-char
+ assertEquals("Col1 <> ''bar''", c.toSql());
+
+ c = new FilterItem(selectItem, OperatorType.DIFFERENT_FROM, "foo's bar");
+ // the same applies here
+ assertEquals("Col1 <> 'foo's bar'", c.toSql());
+
+ col1.setType(ColumnType.FLOAT);
+ c = new FilterItem(selectItem, OperatorType.EQUALS_TO, 423);
+ assertEquals("Col1 = 423", c.toString());
+
+ c = new FilterItem(selectItem, OperatorType.EQUALS_TO, 423426235423.42);
+ assertEquals("Col1 = 423426235423.42", c.toString());
+
+ c = new FilterItem(selectItem, OperatorType.EQUALS_TO, true);
+ assertEquals("Col1 = 1", c.toString());
+
+ Column timeColumn = new MutableColumn("TimeCol", ColumnType.TIME);
+ selectItem = new SelectItem(timeColumn);
+ c = new FilterItem(selectItem, OperatorType.GREATER_THAN, "02:30:05.000");
+ assertEquals("TimeCol > TIME '02:30:05'", c.toString());
+
+ Column dateColumn = new MutableColumn("DateCol", ColumnType.DATE);
+ c = new FilterItem(new SelectItem(dateColumn), OperatorType.GREATER_THAN, "2000-12-31");
+ assertEquals("DateCol > DATE '2000-12-31'", c.toString());
+ }
+
+ public void testToStringTimeStamp() throws Exception {
+ Column timestampColumn = new MutableColumn("TimestampCol", ColumnType.TIMESTAMP);
+ FilterItem c = new FilterItem(new SelectItem(timestampColumn), OperatorType.LESS_THAN,
+ "2000-12-31 02:30:05.007");
+ assertEquals("TimestampCol < TIMESTAMP '2000-12-31 02:30:05'", c.toString());
+
+ c = new FilterItem(new SelectItem(timestampColumn), OperatorType.LESS_THAN, "2000-12-31 02:30:05");
+ assertEquals("TimestampCol < TIMESTAMP '2000-12-31 02:30:05'", c.toString());
+
+ Column dateColumn = new MutableColumn("DateCol", ColumnType.DATE);
+ c = new FilterItem(new SelectItem(timestampColumn), OperatorType.GREATER_THAN, new SelectItem(dateColumn));
+ assertEquals("TimestampCol > DateCol", c.toString());
+ }
+
+ public void testEvaluateStrings() throws Exception {
+ Column col1 = new MutableColumn("Col1", ColumnType.VARCHAR);
+ Column col2 = new MutableColumn("Col2", ColumnType.VARCHAR);
+ SelectItem s1 = new SelectItem(col1);
+ SelectItem s2 = new SelectItem(col2);
+ SelectItem[] selectItems = new SelectItem[] { s1, s2 };
+ SimpleDataSetHeader header = new SimpleDataSetHeader(selectItems);
+ Row row;
+ FilterItem c;
+
+ row = new DefaultRow(header, new Object[] { "foo", "bar" });
+ c = new FilterItem(s1, OperatorType.DIFFERENT_FROM, s2);
+ assertTrue(c.evaluate(row));
+
+ row = new DefaultRow(header, new Object[] { "aaa", "bbb" });
+ c = new FilterItem(s1, OperatorType.GREATER_THAN, s2);
+ assertFalse(c.evaluate(row));
+
+ c = new FilterItem(s1, OperatorType.LESS_THAN, s2);
+ assertTrue(c.evaluate(row));
+
+ row = new DefaultRow(header, new Object[] { "aaa", "aaa" });
+ c = new FilterItem(s1, OperatorType.EQUALS_TO, s2);
+ assertTrue(c.evaluate(row));
+
+ c = new FilterItem(s1, OperatorType.LIKE, s2);
+ row = new DefaultRow(header, new Object[] { "foobar", "fo%b%r" });
+ assertTrue(c.evaluate(row));
+
+ row = new DefaultRow(header, new Object[] { "foobbdbafsdfr", "fo%b%r" });
+ assertTrue(c.evaluate(row));
+ }
+
+ public void testEvaluateNull() throws Exception {
+ Column col1 = new MutableColumn("Col1", ColumnType.INTEGER);
+ Column col2 = new MutableColumn("Col2", ColumnType.DECIMAL);
+ SelectItem s1 = new SelectItem(col1);
+ SelectItem s2 = new SelectItem(col2);
+ SelectItem[] selectItems = new SelectItem[] { s1, s2 };
+ CachingDataSetHeader header = new CachingDataSetHeader(selectItems);
+
+ FilterItem c = new FilterItem(s1, OperatorType.EQUALS_TO, null);
+
+ Row row = new DefaultRow(header, new Object[] { 1, 1 });
+ assertFalse(c.evaluate(row));
+ row = new DefaultRow(header, new Object[] { null, 1 });
+ assertTrue(c.evaluate(row));
+
+ c = new FilterItem(s1, OperatorType.EQUALS_TO, 1);
+
+ row = new DefaultRow(header, new Object[] { 1, 1 });
+ assertTrue(c.evaluate(row));
+ row = new DefaultRow(header, new Object[] { null, 1 });
+ assertFalse(c.evaluate(row));
+
+ c = new FilterItem(s1, OperatorType.DIFFERENT_FROM, 5);
+
+ row = new DefaultRow(header, new Object[] { 1, 1 });
+ assertTrue(c.evaluate(row));
+ row = new DefaultRow(header, new Object[] { null, 1 });
+ assertTrue(c.evaluate(row));
+
+ c = new FilterItem(s1, OperatorType.GREATER_THAN, s2);
+
+ row = new DefaultRow(header, new Object[] { 5, 1 });
+ assertTrue(c.evaluate(row));
+ row = new DefaultRow(header, new Object[] { null, 1 });
+ assertFalse(c.evaluate(row));
+ row = new DefaultRow(header, new Object[] { 1, null });
+ assertFalse(c.evaluate(row));
+
+ c = new FilterItem(s1, OperatorType.EQUALS_TO, s2);
+ row = new DefaultRow(header, new Object[] { 1, null });
+ assertFalse(c.evaluate(row));
+ row = new DefaultRow(header, new Object[] { null, null });
+ assertTrue(c.evaluate(row));
+ }
+
+ public void testEvaluateDates() throws Exception {
+ Column col1 = new MutableColumn("Col1", ColumnType.DATE);
+ SelectItem s1 = new SelectItem(col1);
+ SelectItem[] selectItems = new SelectItem[] { s1 };
+ CachingDataSetHeader header = new CachingDataSetHeader(selectItems);
+
+ long currentTimeMillis = System.currentTimeMillis();
+ FilterItem c = new FilterItem(s1, OperatorType.LESS_THAN, new java.sql.Date(currentTimeMillis));
+
+ Row row = new DefaultRow(header, new Object[] { new java.sql.Date(currentTimeMillis) });
+ assertFalse(c.evaluate(row));
+ row = new DefaultRow(header, new Object[] { new java.sql.Date(currentTimeMillis + 10000000) });
+ assertFalse(c.evaluate(row));
+ row = new DefaultRow(header, new Object[] { new java.sql.Date(currentTimeMillis - 10000000) });
+ assertTrue(c.evaluate(row));
+ }
+
+ public void testEvaluateBooleans() throws Exception {
+ Column col1 = new MutableColumn("Col1", ColumnType.BIT);
+ SelectItem s1 = new SelectItem(col1);
+ SelectItem[] selectItems = new SelectItem[] { s1 };
+ DataSetHeader header = new SimpleDataSetHeader(selectItems);
+
+ FilterItem c = new FilterItem(s1, OperatorType.EQUALS_TO, true);
+
+ Row row = new DefaultRow(header, new Object[] { true });
+ assertTrue(c.evaluate(row));
+ row = new DefaultRow(header, new Object[] { false });
+ assertFalse(c.evaluate(row));
+
+ c = new FilterItem(s1, OperatorType.EQUALS_TO, false);
+ row = new DefaultRow(header, new Object[] { true });
+ assertFalse(c.evaluate(row));
+ row = new DefaultRow(header, new Object[] { false });
+ assertTrue(c.evaluate(row));
+
+ c = new FilterItem(s1, OperatorType.GREATER_THAN, false);
+ row = new DefaultRow(header, new Object[] { true });
+ assertTrue(c.evaluate(row));
+ row = new DefaultRow(header, new Object[] { false });
+ assertFalse(c.evaluate(row));
+ }
+
+ /**
+ * Tests that the following (general) rules apply to the object:
+ *
+ * <li>the hashcode is the same when run twice on an unaltered object</li>
+ * <li>if o1.equals(o2) then this condition must be true: o1.hashCode() ==
+ * 02.hashCode()
+ */
+ public void testEqualsAndHashCode() throws Exception {
+ Column col1 = new MutableColumn("Col1", ColumnType.BIT);
+
+ FilterItem c1 = new FilterItem(new SelectItem(col1), OperatorType.EQUALS_TO, true);
+ FilterItem c2 = new FilterItem(new SelectItem(col1), OperatorType.EQUALS_TO, true);
+ assertEquals(c1, c2);
+ assertEquals(c1.hashCode(), c2.hashCode());
+
+ c2 = new FilterItem(new SelectItem(col1), OperatorType.GREATER_THAN, true);
+ assertFalse(c1.equals(c2));
+ assertFalse(c1.hashCode() == c2.hashCode());
+
+ Column col2 = new MutableColumn("Col2", ColumnType.VARBINARY);
+ c2 = new FilterItem(new SelectItem(col2), OperatorType.EQUALS_TO, true);
+ assertFalse(c1.equals(c2));
+ assertFalse(c1.hashCode() == c2.hashCode());
+ }
+
+ public void testOrFilterItem() throws Exception {
+ Column col1 = new MutableColumn("Col1", ColumnType.VARCHAR);
+
+ SelectItem s1 = new SelectItem(col1);
+ FilterItem c1 = new FilterItem(s1, OperatorType.EQUALS_TO, "foo");
+ FilterItem c2 = new FilterItem(s1, OperatorType.EQUALS_TO, "bar");
+ FilterItem c3 = new FilterItem(s1, OperatorType.EQUALS_TO, "foobar");
+
+ FilterItem filter = new FilterItem(c1, c2, c3);
+ assertEquals("(Col1 = 'foo' OR Col1 = 'bar' OR Col1 = 'foobar')", filter.toString());
+
+ DataSetHeader header = new SimpleDataSetHeader(new SelectItem[] { s1 });
+
+ assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "foo" })));
+ assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "bar" })));
+ assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "foobar" })));
+
+ assertFalse(filter.evaluate(new DefaultRow(header, new Object[] { "foob" })));
+ }
+
+ public void testAndFilterItem() throws Exception {
+ Column col1 = new MutableColumn("Col1", ColumnType.VARCHAR);
+
+ SelectItem s1 = new SelectItem(col1);
+ FilterItem c1 = new FilterItem(s1, OperatorType.LIKE, "foo%");
+ FilterItem c2 = new FilterItem(s1, OperatorType.LIKE, "%bar");
+ FilterItem c3 = new FilterItem(s1, OperatorType.DIFFERENT_FROM, "foobar");
+
+ FilterItem filter = new FilterItem(LogicalOperator.AND, c1, c2, c3);
+ assertEquals("(Col1 LIKE 'foo%' AND Col1 LIKE '%bar' AND Col1 <> 'foobar')", filter.toString());
+
+ SelectItem[] items = new SelectItem[] { s1 };
+ CachingDataSetHeader header = new CachingDataSetHeader(items);
+ assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "foo bar" })));
+ assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "foosenbar" })));
+ assertFalse(filter.evaluate(new DefaultRow(header, new Object[] { "foo" })));
+ assertFalse(filter.evaluate(new DefaultRow(header, new Object[] { "hello world" })));
+ assertFalse(filter.evaluate(new DefaultRow(header, new Object[] { "foobar" })));
+ }
+
+ // Ticket #410
+ public void testOrFilterItemWithoutSelectingActualItmes() throws Exception {
+
+ // define the schema
+ final MutableSchema schema = new MutableSchema("s");
+ MutableTable table = new MutableTable("persons", TableType.TABLE, schema);
+ schema.addTable(table);
+ final Column col1 = new MutableColumn("name", ColumnType.VARCHAR, table, 1, true);
+ final Column col2 = new MutableColumn("role", ColumnType.VARCHAR, table, 2, true);
+ final Column col3 = new MutableColumn("column_number", ColumnType.INTEGER, table, 3, true);
+ table.addColumn(col1);
+ table.addColumn(col2);
+ table.addColumn(col3);
+
+ Query q = new Query();
+ q.select(col3);
+ q.from(col1.getTable());
+
+ SelectItem selectItem1 = new SelectItem(col1);
+ SelectItem selectItem2 = new SelectItem(col2);
+
+ FilterItem item1 = new FilterItem(selectItem1, OperatorType.EQUALS_TO, "kasper");
+ FilterItem item2 = new FilterItem(selectItem2, OperatorType.EQUALS_TO, "user");
+
+ q.where(new FilterItem(item1, item2));
+
+ assertEquals(
+ "SELECT persons.column_number FROM s.persons WHERE (persons.name = 'kasper' OR persons.role = 'user')",
+ q.toString());
+
+ DataContext dc = new QueryPostprocessDataContext() {
+
+ @Override
+ public DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+ assertEquals(3, columns.length);
+ assertEquals("column_number", columns[0].getName());
+ assertEquals("name", columns[1].getName());
+ assertEquals("role", columns[2].getName());
+ SelectItem[] selectItems = new SelectItem[] { new SelectItem(col1), new SelectItem(col2),
+ new SelectItem(col3) };
+ DataSetHeader header = new CachingDataSetHeader(selectItems);
+ List<Row> rows = new LinkedList<Row>();
+ rows.add(new DefaultRow(header, new Object[] { "foo", "bar", 1 }));
+ rows.add(new DefaultRow(header, new Object[] { "kasper", "developer", 2 }));
+ rows.add(new DefaultRow(header, new Object[] { "admin", "admin", 3 }));
+ rows.add(new DefaultRow(header, new Object[] { "elikeon", "user", 4 }));
+ rows.add(new DefaultRow(header, new Object[] { "someuser", "user", 5 }));
+ rows.add(new DefaultRow(header, new Object[] { "hmm", "what-the", 6 }));
+
+ return new InMemoryDataSet(header, rows);
+ }
+
+ @Override
+ protected String getMainSchemaName() throws MetaModelException {
+ return "s";
+ }
+
+ @Override
+ protected Schema getMainSchema() throws MetaModelException {
+ return schema;
+ }
+ };
+
+ DataSet result = dc.executeQuery(q);
+ List<Object[]> objectArrays = result.toObjectArrays();
+ assertEquals(3, objectArrays.size());
+ assertEquals(2, objectArrays.get(0)[0]);
+ assertEquals(4, objectArrays.get(1)[0]);
+ assertEquals(5, objectArrays.get(2)[0]);
+ }
+
+ public void testInOperandSql() throws Exception {
+ SelectItem selectItem = new SelectItem(new MutableColumn("foo", ColumnType.VARCHAR, null, 1, null, null, true,
+ null, false, null));
+ Object operand = new String[] { "foo", "bar" };
+ assertEquals("foo IN ('foo' , 'bar')", new FilterItem(selectItem, OperatorType.IN, operand).toSql());
+
+ operand = Arrays.asList("foo", "bar", "baz");
+ assertEquals("foo IN ('foo' , 'bar' , 'baz')", new FilterItem(selectItem, OperatorType.IN, operand).toSql());
+
+ operand = "foo";
+ assertEquals("foo IN ('foo')", new FilterItem(selectItem, OperatorType.IN, operand).toSql());
+
+ operand = new ArrayList<Object>();
+ assertEquals("foo IN ()", new FilterItem(selectItem, OperatorType.IN, operand).toSql());
+ }
+
+ public void testInOperandEvaluate() throws Exception {
+ SelectItem selectItem = new SelectItem(new MutableColumn("foo", ColumnType.VARCHAR, null, 1, null, null, true,
+ null, false, null));
+ Object operand = new String[] { "foo", "bar" };
+
+ FilterItem filterItem = new FilterItem(selectItem, OperatorType.IN, operand);
+ SelectItem[] selectItems = new SelectItem[] { selectItem };
+ DataSetHeader header = new CachingDataSetHeader(selectItems);
+
+ assertTrue(filterItem.evaluate(new DefaultRow(header, new Object[] { "foo" })));
+ assertTrue(filterItem.evaluate(new DefaultRow(header, new Object[] { "bar" })));
+ assertFalse(filterItem.evaluate(new DefaultRow(header, new Object[] { "foobar" })));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/query/FromClauseTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/FromClauseTest.java b/core/src/test/java/org/apache/metamodel/query/FromClauseTest.java
new file mode 100644
index 0000000..074a3b4
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/query/FromClauseTest.java
@@ -0,0 +1,46 @@
+/**
+ * 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.query;
+
+import org.eobjects.metamodel.MetaModelTestCase;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+public class FromClauseTest extends MetaModelTestCase {
+
+ public void testGetItemByReference() throws Exception {
+ Schema exampleSchema = getExampleSchema();
+ Table table = exampleSchema.getTableByName(TABLE_CONTRIBUTOR);
+
+ Query query = new Query();
+ query.from(table, "foobar");
+
+ assertNull(query.getFromClause().getItemByReference("foob"));
+ assertNull(query.getFromClause().getItemByReference(TABLE_CONTRIBUTOR));
+ assertEquals("MetaModelSchema.contributor foobar", query
+ .getFromClause().getItemByReference("foobar").toString());
+
+ query = new Query();
+ query.from(table);
+ assertNull(query.getFromClause().getItemByReference("foob"));
+ assertEquals("MetaModelSchema.contributor", query.getFromClause()
+ .getItemByReference(TABLE_CONTRIBUTOR).toString());
+ assertNull(query.getFromClause().getItemByReference("foobar"));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/query/FromItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/FromItemTest.java b/core/src/test/java/org/apache/metamodel/query/FromItemTest.java
new file mode 100644
index 0000000..fb4c09e
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/query/FromItemTest.java
@@ -0,0 +1,101 @@
+/**
+ * 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.query;
+
+import org.eobjects.metamodel.MetaModelTestCase;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Relationship;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+public class FromItemTest extends MetaModelTestCase {
+
+ private Schema _schema = getExampleSchema();
+
+ public void testExpressionBased() throws Exception {
+ FromItem fromItem = new FromItem("foobar");
+ assertEquals("foobar", fromItem.toString());
+ fromItem.setAlias("f");
+ assertEquals("foobar f", fromItem.toString());
+
+ assertEquals("SELECT COUNT(*) FROM foobar", new Query().selectCount().from(
+ "foobar").toString());
+ }
+
+ public void testRelationJoinToString() throws Exception {
+ Table contributorTable = _schema.getTableByName(TABLE_CONTRIBUTOR);
+ Table roleTable = _schema.getTableByName(TABLE_ROLE);
+ Relationship[] relationships = roleTable
+ .getRelationships(contributorTable);
+ FromItem from = new FromItem(JoinType.INNER, relationships[0]);
+ assertEquals(
+ "MetaModelSchema.contributor INNER JOIN MetaModelSchema.role ON contributor.contributor_id = role.contributor_id",
+ from.toString());
+
+ from.setAlias("myJoin");
+ assertEquals(
+ "(MetaModelSchema.contributor INNER JOIN MetaModelSchema.role ON contributor.contributor_id = role.contributor_id) myJoin",
+ from.toString());
+
+ from.getLeftSide().setAlias("a");
+ assertEquals(
+ "(MetaModelSchema.contributor a INNER JOIN MetaModelSchema.role ON a.contributor_id = role.contributor_id) myJoin",
+ from.toString());
+ }
+
+ public void testSubQueryJoinToString() throws Exception {
+ Table projectTable = _schema.getTableByName(TABLE_PROJECT);
+ Table roleTable = _schema.getTableByName(TABLE_ROLE);
+
+ Column projectIdColumn = projectTable
+ .getColumnByName(COLUMN_PROJECT_PROJECT_ID);
+
+ FromItem leftSide = new FromItem(projectTable);
+ leftSide.setAlias("a");
+ SelectItem[] leftOn = new SelectItem[] { new SelectItem(projectIdColumn) };
+
+ Column[] columns = roleTable.getColumns();
+
+ Query subQuery = new Query();
+ FromItem subQueryFrom = new FromItem(roleTable);
+ subQuery.from(subQueryFrom);
+ subQuery.select(columns);
+ SelectItem subQuerySelectItem = subQuery.getSelectClause().getItems()
+ .get(1);
+ FromItem rightSide = new FromItem(subQuery);
+ rightSide.setAlias("b");
+ SelectItem[] rightOn = new SelectItem[] { subQuerySelectItem };
+ FromItem from = new FromItem(JoinType.LEFT, leftSide, rightSide,
+ leftOn, rightOn);
+
+ assertEquals(
+ "MetaModelSchema.project a LEFT JOIN (SELECT role.contributor_id, role.project_id, role.name FROM MetaModelSchema.role) b ON a.project_id = b.project_id",
+ from.toString());
+
+ subQueryFrom.setAlias("c");
+ assertEquals(
+ "MetaModelSchema.project a LEFT JOIN (SELECT c.contributor_id, c.project_id, c.name FROM MetaModelSchema.role c) b ON a.project_id = b.project_id",
+ from.toString());
+
+ subQuerySelectItem.setAlias("foobar");
+ assertEquals(
+ "MetaModelSchema.project a LEFT JOIN (SELECT c.contributor_id, c.project_id AS foobar, c.name FROM MetaModelSchema.role c) b ON a.project_id = b.foobar",
+ from.toString());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/query/FunctionTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/FunctionTypeTest.java b/core/src/test/java/org/apache/metamodel/query/FunctionTypeTest.java
new file mode 100644
index 0000000..1161550
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/query/FunctionTypeTest.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.query;
+
+import junit.framework.TestCase;
+
+public class FunctionTypeTest extends TestCase {
+
+ public void testEvaluateNumbers() throws Exception {
+ assertEquals(2.5, FunctionType.AVG.evaluate(1.5, 2, null, 3, 3.5));
+ assertEquals(10.0, FunctionType.SUM.evaluate(1.5, 2, null, 3, 3.5));
+ assertEquals(4l, FunctionType.COUNT.evaluate(1.5, 2, null, 3, 3.5));
+ assertEquals(1.5, FunctionType.MIN.evaluate(1.5, 2, null, 3, 3.5));
+ assertEquals(3.5, FunctionType.MAX.evaluate(1.5, 2, null, 3, 3.5));
+ }
+
+ public void testEvaluateStrings() throws Exception {
+ assertEquals(2.5, FunctionType.AVG.evaluate("1.5", "2", null, "3",
+ "3.5"));
+ assertEquals(10.0, FunctionType.SUM.evaluate("1.5", "2", null, "3",
+ "3.5"));
+ assertEquals(2l, FunctionType.COUNT.evaluate("foo", "BAR", null));
+ assertEquals("a", FunctionType.MIN.evaluate("abc", "a", null, "bcd"));
+ assertEquals("bcd", FunctionType.MAX.evaluate("abc", "a", null, "bcd"));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/query/GroupByItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/GroupByItemTest.java b/core/src/test/java/org/apache/metamodel/query/GroupByItemTest.java
new file mode 100644
index 0000000..f21d650
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/query/GroupByItemTest.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.query;
+
+import junit.framework.TestCase;
+
+public class GroupByItemTest extends TestCase {
+
+ public void testSimpleGroupBy() throws Exception {
+ SelectItem selectItem = new SelectItem("foo", "bar");
+ GroupByItem item = new GroupByItem(selectItem);
+ assertEquals("bar", item.toString());
+ }
+
+ public void testGroupByClause() throws Exception {
+ GroupByClause clause = new GroupByClause(new Query());
+ SelectItem selectItem = new SelectItem("foo", "foo");
+ GroupByItem item = new GroupByItem(selectItem);
+ clause.addItems(item);
+ selectItem = new SelectItem("bar", "bar");
+ item = new GroupByItem(selectItem);
+ clause.addItems(item);
+
+ assertEquals(" GROUP BY foo, bar", clause.toString());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/query/OperatorTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/OperatorTypeTest.java b/core/src/test/java/org/apache/metamodel/query/OperatorTypeTest.java
new file mode 100644
index 0000000..2efee46
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/query/OperatorTypeTest.java
@@ -0,0 +1,34 @@
+/**
+ * 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.query;
+
+import junit.framework.TestCase;
+
+public class OperatorTypeTest extends TestCase {
+
+ public void testConvertOperatorType() throws Exception {
+ assertEquals(OperatorType.EQUALS_TO, OperatorType.convertOperatorType("="));
+ assertEquals(OperatorType.GREATER_THAN, OperatorType.convertOperatorType(">"));
+ assertEquals(OperatorType.LESS_THAN, OperatorType.convertOperatorType("<"));
+ assertEquals(OperatorType.DIFFERENT_FROM, OperatorType.convertOperatorType("<>"));
+ assertEquals(OperatorType.LIKE, OperatorType.convertOperatorType("LIKE"));
+ assertEquals(OperatorType.IN, OperatorType.convertOperatorType("IN"));
+ assertEquals(null, OperatorType.convertOperatorType("foo"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/query/OrderByItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/OrderByItemTest.java b/core/src/test/java/org/apache/metamodel/query/OrderByItemTest.java
new file mode 100644
index 0000000..7433177
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/query/OrderByItemTest.java
@@ -0,0 +1,33 @@
+/**
+ * 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.query;
+
+import org.eobjects.metamodel.query.OrderByItem.Direction;
+import junit.framework.TestCase;
+
+public class OrderByItemTest extends TestCase {
+
+ public void testSimpleOrderBy() throws Exception {
+ SelectItem selectItem = new SelectItem("foo", "foo");
+ OrderByItem item = new OrderByItem(selectItem, Direction.DESC);
+ assertEquals("foo DESC", item.toString());
+ item = new OrderByItem(selectItem, Direction.ASC);
+ assertEquals("foo ASC", item.toString());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/query/QueryTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/QueryTest.java b/core/src/test/java/org/apache/metamodel/query/QueryTest.java
new file mode 100644
index 0000000..92e43e5
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/query/QueryTest.java
@@ -0,0 +1,245 @@
+/**
+ * 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.query;
+
+import org.eobjects.metamodel.MetaModelTestCase;
+import org.eobjects.metamodel.query.OrderByItem.Direction;
+import org.eobjects.metamodel.query.builder.InitFromBuilderImpl;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+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.Table;
+import org.eobjects.metamodel.schema.TableType;
+
+public class QueryTest extends MetaModelTestCase {
+
+ private Schema _schema = getExampleSchema();
+
+ public void testSimpleQuery() throws Exception {
+ Table contributorTable = _schema.getTableByName(TABLE_CONTRIBUTOR);
+
+ Query q = new Query();
+ q.selectCount().from(contributorTable);
+ assertEquals("SELECT COUNT(*) FROM MetaModelSchema.contributor", q.toString());
+ }
+
+ public void testCloneGroupBy() throws Exception {
+ Table table = _schema.getTableByName(TABLE_PROJECT);
+ Column column = table.getColumnByName(COLUMN_PROJECT_NAME);
+ Query q = new Query().from(table).selectCount().select(column).groupBy(column);
+ assertEquals(q.toString(), q.clone().toString());
+
+ q.having(new FilterItem(SelectItem.getCountAllItem(), OperatorType.GREATER_THAN, 20));
+ assertEquals(q.toString(), q.clone().toString());
+ }
+
+ public void testFromItemAlias() throws Exception {
+ Query q = new Query();
+ Table contributorTable = _schema.getTableByName(TABLE_CONTRIBUTOR);
+ Column nameColumn = contributorTable.getColumnByName(COLUMN_CONTRIBUTOR_NAME);
+ Column countryColumn = contributorTable.getColumnByName(COLUMN_CONTRIBUTOR_COUNTRY);
+
+ FromItem fromContributor = new FromItem(contributorTable);
+ q.from(fromContributor);
+ q.select(nameColumn, countryColumn);
+ assertEquals("SELECT contributor.name, contributor.country FROM MetaModelSchema.contributor", q.toString());
+
+ fromContributor.setAlias("c");
+
+ assertEquals("SELECT c.name, c.country FROM MetaModelSchema.contributor c", q.toString());
+
+ q.groupBy(new GroupByItem(q.getSelectClause().getSelectItem(nameColumn)));
+ q.groupBy(new GroupByItem(q.getSelectClause().getSelectItem(countryColumn)));
+ q.select(new SelectItem(FunctionType.COUNT, "*", "total"));
+ assertEquals(2, q.getGroupByClause().getItems().size());
+ assertEquals(
+ "SELECT c.name, c.country, COUNT(*) AS total FROM MetaModelSchema.contributor c GROUP BY c.name, c.country",
+ q.toString());
+
+ Column contributorIdColumn = contributorTable.getColumnByName(COLUMN_CONTRIBUTOR_CONTRIBUTOR_ID);
+ q.where(contributorIdColumn, OperatorType.EQUALS_TO, 1);
+ assertEquals(
+ "SELECT c.name, c.country, COUNT(*) AS total FROM MetaModelSchema.contributor c WHERE c.contributor_id = 1 GROUP BY c.name, c.country",
+ q.toString());
+
+ q.where(contributorIdColumn, OperatorType.DIFFERENT_FROM, q.getSelectClause().getSelectItem(nameColumn));
+ assertEquals(
+ "SELECT c.name, c.country, COUNT(*) AS total FROM MetaModelSchema.contributor c WHERE c.contributor_id = 1 AND c.contributor_id <> c.name GROUP BY c.name, c.country",
+ q.toString());
+ }
+
+ public void testAddOrderBy() throws Exception {
+ Table contributorTable = _schema.getTableByName(TABLE_CONTRIBUTOR);
+ Column nameColumn = contributorTable.getColumnByName(COLUMN_CONTRIBUTOR_NAME);
+ Column countryColumn = contributorTable.getColumnByName(COLUMN_CONTRIBUTOR_COUNTRY);
+ FromItem fromContributor = new FromItem(contributorTable);
+ fromContributor.setAlias("a");
+
+ Query q = new Query();
+ q.select(nameColumn, countryColumn).from(fromContributor).orderBy(nameColumn)
+ .orderBy(countryColumn, Direction.DESC);
+ assertEquals(2, q.getOrderByClause().getItems().size());
+ assertEquals("SELECT a.name, a.country FROM MetaModelSchema.contributor a ORDER BY a.name ASC, a.country DESC",
+ q.toString());
+ }
+
+ public void testCloneJoinAndOrderBy() throws Exception {
+ Query q1 = new Query();
+ Table contributorTable = _schema.getTableByName(TABLE_CONTRIBUTOR);
+ Table roleTable = _schema.getTableByName(TABLE_ROLE);
+ FromItem fromItem = new FromItem(JoinType.INNER, contributorTable.getRelationships(roleTable)[0]);
+ q1.from(fromItem);
+
+ Column nameColumn = contributorTable.getColumnByName(COLUMN_CONTRIBUTOR_NAME);
+ Column countryColumn = contributorTable.getColumnByName(COLUMN_CONTRIBUTOR_COUNTRY);
+ Column roleNameColumn = roleTable.getColumnByName(COLUMN_ROLE_ROLE_NAME);
+ q1.select(nameColumn, countryColumn, roleNameColumn);
+ q1.orderBy(roleNameColumn);
+ String q1string = q1.toString();
+ assertEquals(
+ "SELECT contributor.name, contributor.country, role.name FROM MetaModelSchema.contributor INNER JOIN MetaModelSchema.role ON contributor.contributor_id = role.contributor_id ORDER BY role.name ASC",
+ q1string);
+
+ Query q2 = q1.clone();
+ assertEquals(q1string, q2.toString());
+
+ q2.getSelectClause().removeItem(1);
+ assertEquals(q1string, q1.toString());
+ assertEquals(
+ "SELECT contributor.name, role.name FROM MetaModelSchema.contributor INNER JOIN MetaModelSchema.role ON contributor.contributor_id = role.contributor_id ORDER BY role.name ASC",
+ q2.toString());
+
+ FromItem sqFromItem = new FromItem(q2).setAlias("sq");
+ SelectItem sqSelectItem = new SelectItem(q2.getSelectClause().getItem(1), sqFromItem).setAlias("foo");
+ Query q3 = new Query().from(sqFromItem);
+ q3.orderBy(new OrderByItem(sqSelectItem));
+ q3.select(sqSelectItem);
+ assertEquals(
+ "SELECT sq.name AS foo FROM (SELECT contributor.name, role.name FROM MetaModelSchema.contributor INNER JOIN MetaModelSchema.role ON contributor.contributor_id = role.contributor_id ORDER BY role.name ASC) sq ORDER BY foo ASC",
+ q3.toString());
+ Query q4 = q3.clone();
+ assertEquals(
+ "SELECT sq.name AS foo FROM (SELECT contributor.name, role.name FROM MetaModelSchema.contributor INNER JOIN MetaModelSchema.role ON contributor.contributor_id = role.contributor_id ORDER BY role.name ASC) sq ORDER BY foo ASC",
+ q4.toString());
+
+ assertTrue(q3.equals(q4));
+ }
+
+ public void testDistinctEquals() throws Exception {
+ Query q = new Query();
+ SelectClause sc1 = new SelectClause(q);
+ SelectClause sc2 = new SelectClause(q);
+ assertTrue(sc1.equals(sc2));
+ sc2.setDistinct(true);
+ assertFalse(sc1.equals(sc2));
+ sc1.setDistinct(true);
+ assertTrue(sc1.equals(sc2));
+ }
+
+ public void testSetMaxRows() throws Exception {
+ assertEquals(1, new Query().setMaxRows(1).getMaxRows().intValue());
+ try {
+ new Query().setMaxRows(0);
+ fail("Exception expected");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Max rows cannot be zero", e.getMessage());
+ }
+ try {
+ new Query().setMaxRows(-1);
+ fail("Exception expected");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Max rows cannot be negative", e.getMessage());
+ }
+ }
+
+ public void testSetFirstRow() throws Exception {
+ assertEquals(2, new Query().setFirstRow(2).getFirstRow().intValue());
+ assertEquals(1, new Query().setFirstRow(1).getFirstRow().intValue());
+
+ try {
+ new Query().setFirstRow(0);
+ fail("Exception expected");
+ } catch (IllegalArgumentException e) {
+ assertEquals("First row cannot be negative or zero", e.getMessage());
+ }
+
+ try {
+ new Query().setFirstRow(-1);
+ fail("Exception expected");
+ } catch (IllegalArgumentException e) {
+ assertEquals("First row cannot be negative or zero", e.getMessage());
+ }
+ }
+
+ public void testEqualsAndHashCode() throws Exception {
+ MutableSchema schema = new MutableSchema("schema");
+ MutableTable table = new MutableTable("table").setSchema(schema);
+ schema.addTable(table);
+
+ Column col1 = new MutableColumn("col1").setTable(table);
+ Column col2 = new MutableColumn("col2").setTable(table);
+ Column col3 = new MutableColumn("col3").setTable(table);
+ table.addColumn(col1);
+ table.addColumn(col2);
+ table.addColumn(col3);
+
+ Query q1 = new Query().select(col1, col2).from(table).where(col3, OperatorType.EQUALS_TO, "m'jello");
+
+ Query q2 = new InitFromBuilderImpl(null).from(table).select(col1).and(col2).where(col3).eq("m'jello").toQuery();
+
+ assertEquals(q1, q2);
+ }
+
+ public void testHavingClauseReferencingFunctionAndOperand() throws Exception {
+ MutableColumn idColumn = new MutableColumn("id", ColumnType.VARCHAR);
+ SelectItem countSelectItem = new SelectItem(FunctionType.COUNT, idColumn);
+ SelectItem idSelectItem = new SelectItem(idColumn).setAlias("innerIdColumn");
+
+ Query q = new Query();
+ q.select(idSelectItem);
+ q.groupBy(idColumn);
+ q.having(new FilterItem(countSelectItem, OperatorType.EQUALS_TO, 2));
+
+ assertEquals("SELECT id AS innerIdColumn GROUP BY id HAVING COUNT(id) = 2", q.toSql());
+ }
+
+ public void testToSqlWithFullyQualifiedColumnNames() throws Exception {
+ final MutableSchema schema = new MutableSchema("sch");
+ final MutableTable table = new MutableTable("tab", TableType.TABLE, schema);
+ final MutableColumn nameColumn = new MutableColumn("name", ColumnType.VARCHAR).setTable(table);
+ final MutableColumn ageColumn = new MutableColumn("age", ColumnType.INTEGER).setTable(table);
+ schema.addTable(table);
+ table.addColumn(nameColumn);
+ table.addColumn(ageColumn);
+
+ final Query q = new Query();
+ q.select(ageColumn).selectCount();
+ q.from(table);
+ q.where(ageColumn, OperatorType.GREATER_THAN, 18);
+ q.groupBy(ageColumn);
+ q.having(FunctionType.COUNT, nameColumn, OperatorType.LESS_THAN, 100);
+ q.orderBy(ageColumn);
+
+ assertEquals("SELECT sch.tab.age, COUNT(*) FROM sch.tab WHERE sch.tab.age > 18 "
+ + "GROUP BY sch.tab.age HAVING COUNT(sch.tab.name) < 100 ORDER BY sch.tab.age ASC", q.toSql(true));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/query/SelectClauseTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/SelectClauseTest.java b/core/src/test/java/org/apache/metamodel/query/SelectClauseTest.java
new file mode 100644
index 0000000..3ef125b
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/query/SelectClauseTest.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.query;
+
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.schema.MutableTable;
+import org.eobjects.metamodel.schema.Table;
+
+import junit.framework.TestCase;
+
+public class SelectClauseTest extends TestCase {
+
+ public void testDistinctAddition() throws Exception {
+ Table table = new MutableTable("foo");
+ Column col = new MutableColumn("bar").setTable(table);
+
+ Query q = new Query();
+ q.selectDistinct();
+ q.from(table);
+ q.select(col);
+
+ assertEquals("SELECT DISTINCT foo.bar FROM foo", q.toSql());
+ }
+}
[13/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/apache/metamodel/excel/XlsxSheetToRowsHandler.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/XlsxSheetToRowsHandler.java b/excel/src/main/java/org/apache/metamodel/excel/XlsxSheetToRowsHandler.java
new file mode 100644
index 0000000..b43c5d6
--- /dev/null
+++ b/excel/src/main/java/org/apache/metamodel/excel/XlsxSheetToRowsHandler.java
@@ -0,0 +1,341 @@
+/**
+ * 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.excel;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
+import org.apache.poi.ss.usermodel.BuiltinFormats;
+import org.apache.poi.ss.usermodel.DataFormatter;
+import org.apache.poi.ss.usermodel.DateUtil;
+import org.apache.poi.ss.usermodel.FillPatternType;
+import org.apache.poi.ss.usermodel.FontUnderline;
+import org.apache.poi.xssf.eventusermodel.XSSFReader;
+import org.apache.poi.xssf.model.SharedStringsTable;
+import org.apache.poi.xssf.model.StylesTable;
+import org.apache.poi.xssf.usermodel.XSSFCellStyle;
+import org.apache.poi.xssf.usermodel.XSSFColor;
+import org.apache.poi.xssf.usermodel.XSSFFont;
+import org.apache.poi.xssf.usermodel.XSSFRichTextString;
+import org.eobjects.metamodel.data.Style;
+import org.eobjects.metamodel.data.Style.SizeUnit;
+import org.eobjects.metamodel.data.StyleBuilder;
+import org.eobjects.metamodel.util.DateUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * XML handler for transforming a sheet into rows. Uses an
+ * {@link XlsxRowCallback} to publish identified rows.
+ *
+ * @author Kasper Sørensen
+ */
+final class XlsxSheetToRowsHandler extends DefaultHandler {
+
+ private static final Logger logger = LoggerFactory
+ .getLogger(XlsxSheetToRowsHandler.class);
+
+ private static enum XssfDataType {
+ BOOL, ERROR, FORMULA, INLINESTR, SSTINDEX, NUMBER,
+ }
+
+ // global variables
+ private final XlsxRowCallback _callback;
+ private final ExcelConfiguration _configuration;
+ private final StylesTable _stylesTable;
+ private final SharedStringsTable _sharedStringTable;
+
+ // variables used to hold information about the current rows
+ private int _rowNumber;
+ private final List<String> _rowValues;
+ private final List<Style> _styles;
+
+ // variables used to hold information about the current visited cells
+ private final StringBuilder _value;
+ private final StyleBuilder _style;
+ private boolean _inCell;
+ private boolean _inFormula;
+ private int _columnNumber;
+ private XssfDataType _dataType;
+ private int _formatIndex;
+ private String _formatString;
+
+ public XlsxSheetToRowsHandler(XlsxRowCallback callback,
+ XSSFReader xssfReader, ExcelConfiguration configuration)
+ throws Exception {
+ _callback = callback;
+ _configuration = configuration;
+
+ _sharedStringTable = xssfReader.getSharedStringsTable();
+ _stylesTable = xssfReader.getStylesTable();
+
+ _value = new StringBuilder();
+ _style = new StyleBuilder();
+ _rowValues = new ArrayList<String>();
+ _styles = new ArrayList<Style>();
+ _rowNumber = -1;
+ _inCell = false;
+ _inFormula = false;
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName,
+ Attributes attributes) throws SAXException {
+ if ("row".equals(qName)) {
+ // element is a row
+
+ // excel row numbers are 1-based
+ int rowNumber = Integer.parseInt(attributes.getValue("r"));
+ rowNumber = rowNumber - 1;
+
+ if (_configuration.isSkipEmptyLines()) {
+ _rowNumber++;
+ } else {
+ while (_rowNumber + 1 < rowNumber) {
+ // empty lines are not skipped, so dispatch empty lines
+ _rowNumber++;
+ List<String> emptyValues = Collections.emptyList();
+ List<Style> emptyStyles = Collections.emptyList();
+ _callback.row(_rowNumber, emptyValues, emptyStyles);
+ }
+ _rowNumber = rowNumber;
+ }
+ } else if ("c".equals(qName)) {
+ // element is a cell
+
+ _inCell = true;
+
+ final String r = attributes.getValue("r");
+ int firstDigit = -1;
+ for (int c = 0; c < r.length(); ++c) {
+ if (Character.isDigit(r.charAt(c))) {
+ firstDigit = c;
+ break;
+ }
+ }
+ _columnNumber = nameToColumn(r.substring(0, firstDigit));
+
+ // Set up defaults.
+ _dataType = XssfDataType.NUMBER;
+ _formatIndex = -1;
+ _formatString = null;
+
+ final String cellType = attributes.getValue("t");
+ if ("b".equals(cellType)) {
+ _dataType = XssfDataType.BOOL;
+ } else if ("e".equals(cellType)) {
+ _dataType = XssfDataType.ERROR;
+ } else if ("inlineStr".equals(cellType)) {
+ _dataType = XssfDataType.INLINESTR;
+ } else if ("s".equals(cellType)) {
+ _dataType = XssfDataType.SSTINDEX;
+ } else if ("str".equals(cellType)) {
+ _dataType = XssfDataType.FORMULA;
+ }
+
+ String cellStyleStr = attributes.getValue("s");
+ if (cellStyleStr != null) {
+ // It's a number, but almost certainly one
+ // with a special style or format
+ int styleIndex = Integer.parseInt(cellStyleStr);
+ XSSFCellStyle style = _stylesTable.getStyleAt(styleIndex);
+
+ configureStyle(style);
+
+ if (_dataType == XssfDataType.NUMBER) {
+ this._formatIndex = style.getDataFormat();
+ this._formatString = style.getDataFormatString();
+ if (this._formatString == null) {
+ this._formatString = BuiltinFormats
+ .getBuiltinFormat(this._formatIndex);
+ }
+ }
+ }
+ } else if (_inCell && "f".equals(qName)) {
+ // skip the actual formula line
+ _inFormula = true;
+ }
+ }
+
+ private void configureStyle(XSSFCellStyle style) {
+ XSSFFont font = style.getFont();
+ if (font.getBold()) {
+ _style.bold();
+ }
+ if (font.getItalic()) {
+ _style.italic();
+ }
+ if (font.getUnderline() != FontUnderline.NONE.getByteValue()) {
+ _style.underline();
+ }
+
+ if (style.getFillPatternEnum() == FillPatternType.SOLID_FOREGROUND) {
+ XSSFColor fillForegroundXSSFColor = style
+ .getFillForegroundXSSFColor();
+ String argb = fillForegroundXSSFColor.getARGBHex();
+ if (argb != null) {
+ _style.background(argb.substring(2));
+ }
+ }
+
+ final XSSFFont stdFont = _stylesTable.getStyleAt(0).getFont();
+ final short fontHeight = style.getFont().getFontHeightInPoints();
+ if (stdFont.getFontHeightInPoints() != fontHeight) {
+ _style.fontSize(fontHeight, SizeUnit.PT);
+ }
+
+ XSSFColor fontColor = style.getFont().getXSSFColor();
+ if (fontColor != null) {
+ String argbHex = fontColor.getARGBHex();
+ if (argbHex != null) {
+ _style.foreground(argbHex.substring(2));
+ }
+ }
+
+ switch (style.getAlignmentEnum()) {
+ case LEFT:
+ _style.leftAligned();
+ break;
+ case RIGHT:
+ _style.rightAligned();
+ break;
+ case CENTER:
+ _style.centerAligned();
+ break;
+ case JUSTIFY:
+ _style.justifyAligned();
+ break;
+ }
+
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName)
+ throws SAXException {
+ if ("row".equals(qName)) {
+ // element was a row
+ boolean next = _callback.row(_rowNumber, _rowValues, _styles);
+ if (!next) {
+ throw new XlsxStopParsingException();
+ }
+ _rowValues.clear();
+ _styles.clear();
+ } else if ("c".equals(qName)) {
+ // element was a cell
+
+ _inCell = false;
+
+ while (_rowValues.size() < _columnNumber) {
+ _rowValues.add(null);
+ _styles.add(Style.NO_STYLE);
+ }
+
+ _rowValues.add(createValue());
+ _styles.add(_style.create());
+ _value.setLength(0);
+ _style.reset();
+ } else if (_inFormula && "f".equals(qName)) {
+ // skip the actual formula line
+ _inFormula = false;
+ }
+ }
+
+ private String createValue() {
+ if (_value.length() == 0) {
+ return null;
+ }
+
+ switch (_dataType) {
+
+ case BOOL:
+ char first = _value.charAt(0);
+ return first == '0' ? "false" : "true";
+ case ERROR:
+ logger.warn("Error-cell occurred: {}", _value);
+ return _value.toString();
+ case FORMULA:
+ return _value.toString();
+ case INLINESTR:
+ XSSFRichTextString rtsi = new XSSFRichTextString(_value.toString());
+ return rtsi.toString();
+ case SSTINDEX:
+ String sstIndex = _value.toString();
+ int idx = Integer.parseInt(sstIndex);
+ XSSFRichTextString rtss = new XSSFRichTextString(
+ _sharedStringTable.getEntryAt(idx));
+ return rtss.toString();
+ case NUMBER:
+ final String numberString = _value.toString();
+ if (_formatString != null) {
+ DataFormatter formatter = getDataFormatter();
+ if (HSSFDateUtil.isADateFormat(_formatIndex, _formatString)) {
+ Date date = DateUtil.getJavaDate(Double
+ .parseDouble(numberString));
+ return DateUtils.createDateFormat().format(date);
+ }
+ return formatter.formatRawCellContents(
+ Double.parseDouble(numberString), _formatIndex,
+ _formatString);
+ } else {
+ if (numberString.endsWith(".0")) {
+ // xlsx only stores doubles, so integers get ".0" appended
+ // to them
+ return numberString.substring(0, numberString.length() - 2);
+ }
+ return numberString;
+ }
+ default:
+ logger.error("Unsupported data type: {}", _dataType);
+ return "";
+ }
+ }
+
+ private DataFormatter getDataFormatter() {
+ return new DataFormatter();
+ }
+
+ @Override
+ public void characters(char[] ch, int start, int length)
+ throws SAXException {
+ if (_inCell && !_inFormula) {
+ _value.append(ch, start, length);
+ }
+ }
+
+ /**
+ * Converts an Excel column name like "C" to a zero-based index.
+ *
+ * @param name
+ * @return Index corresponding to the specified name
+ */
+ private int nameToColumn(String name) {
+ int column = -1;
+ for (int i = 0; i < name.length(); ++i) {
+ int c = name.charAt(i);
+ column = (column + 1) * 26 + c - 'A';
+ }
+ return column;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/apache/metamodel/excel/XlsxSpreadsheetReaderDelegate.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/XlsxSpreadsheetReaderDelegate.java b/excel/src/main/java/org/apache/metamodel/excel/XlsxSpreadsheetReaderDelegate.java
new file mode 100644
index 0000000..dadd978
--- /dev/null
+++ b/excel/src/main/java/org/apache/metamodel/excel/XlsxSpreadsheetReaderDelegate.java
@@ -0,0 +1,192 @@
+/**
+ * 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.excel;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.xssf.eventusermodel.XSSFReader;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.RowPublisherDataSet;
+import org.eobjects.metamodel.data.Style;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+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.Table;
+import org.eobjects.metamodel.util.AlphabeticSequence;
+import org.eobjects.metamodel.util.FileHelper;
+import org.eobjects.metamodel.util.Ref;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+
+/**
+ * {@link SpreadsheetReaderDelegate} implementation for the "new" XLSX format.
+ * This implementation is very efficient as it uses SAX XML parsing which does
+ * not bloat memory usage in the same way that POI's user model does.
+ *
+ * @author Kasper Sørensen
+ */
+final class XlsxSpreadsheetReaderDelegate implements SpreadsheetReaderDelegate {
+
+ private static final Logger logger = LoggerFactory.getLogger(XlsxSpreadsheetReaderDelegate.class);
+
+ private final ExcelConfiguration _configuration;
+ private final Map<String, String> _tableNamesToInternalIds;
+
+ public XlsxSpreadsheetReaderDelegate(ExcelConfiguration configuration) {
+ _configuration = configuration;
+ _tableNamesToInternalIds = new HashMap<String, String>();
+ }
+
+ @Override
+ public DataSet executeQuery(InputStream inputStream, Table table, Column[] columns, int maxRows) throws Exception {
+ final OPCPackage pkg = OPCPackage.open(inputStream);
+ final XSSFReader xssfReader = new XSSFReader(pkg);
+ final String relationshipId = _tableNamesToInternalIds.get(table.getName());
+
+ return buildDataSet(columns, maxRows, relationshipId, xssfReader);
+ }
+
+ @Override
+ public Schema createSchema(InputStream inputStream, String schemaName) throws Exception {
+ final MutableSchema schema = new MutableSchema(schemaName);
+ final OPCPackage pkg = OPCPackage.open(inputStream);
+ final XSSFReader xssfReader = new XSSFReader(pkg);
+
+ final XlsxWorkbookToTablesHandler workbookToTables = new XlsxWorkbookToTablesHandler(schema,
+ _tableNamesToInternalIds);
+ buildTables(xssfReader, workbookToTables);
+
+ for (Entry<String, String> entry : _tableNamesToInternalIds.entrySet()) {
+
+ final String tableName = entry.getKey();
+ final String relationshipId = entry.getValue();
+
+ final MutableTable table = (MutableTable) schema.getTableByName(tableName);
+
+ buildColumns(table, relationshipId, xssfReader);
+ }
+ return schema;
+ }
+
+ @Override
+ public void notifyTablesModified(Ref<InputStream> inputStreamRef) {
+ InputStream inputStream = inputStreamRef.get();
+ final XlsxWorkbookToTablesHandler workbookToTables = new XlsxWorkbookToTablesHandler(null,
+ _tableNamesToInternalIds);
+ try {
+ final OPCPackage pkg = OPCPackage.open(inputStream);
+ final XSSFReader xssfReader = new XSSFReader(pkg);
+ buildTables(xssfReader, workbookToTables);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ } finally {
+ FileHelper.safeClose(inputStream);
+ }
+ }
+
+ private DataSet buildDataSet(final Column[] columns, int maxRows, final String relationshipId,
+ final XSSFReader xssfReader) throws Exception {
+
+ List<SelectItem> selectItems = new ArrayList<SelectItem>(columns.length);
+ for (Column column : columns) {
+ selectItems.add(new SelectItem(column));
+ }
+ final XlsxRowPublisherAction publishAction = new XlsxRowPublisherAction(_configuration, columns,
+ relationshipId, xssfReader);
+
+ return new RowPublisherDataSet(selectItems.toArray(new SelectItem[selectItems.size()]), maxRows, publishAction);
+ }
+
+ private void buildColumns(final MutableTable table, final String relationshipId, final XSSFReader xssfReader)
+ throws Exception {
+ final InputStream sheetData = xssfReader.getSheet(relationshipId);
+
+ final XlsxRowCallback rowCallback = new XlsxRowCallback() {
+ @Override
+ public boolean row(int rowNumber, List<String> values, List<Style> styles) {
+ final int columnNameLineNumber = _configuration.getColumnNameLineNumber();
+ if (columnNameLineNumber == ExcelConfiguration.NO_COLUMN_NAME_LINE) {
+ AlphabeticSequence alphabeticSequence = new AlphabeticSequence();
+ List<String> generatedColumnNames = new ArrayList<String>(values.size());
+ for (String originalColumnName : values) {
+ String columnName = alphabeticSequence.next();
+ if (originalColumnName == null) {
+ columnName = null;
+ }
+ generatedColumnNames.add(columnName);
+ }
+ buildColumns(table, generatedColumnNames);
+ return false;
+ } else {
+ final int zeroBasedLineNumber = columnNameLineNumber - 1;
+ if (rowNumber >= zeroBasedLineNumber) {
+ buildColumns(table, values);
+ return false;
+ }
+ }
+ return true;
+ }
+ };
+ final XlsxSheetToRowsHandler handler = new XlsxSheetToRowsHandler(rowCallback, xssfReader, _configuration);
+
+ final XMLReader sheetParser = ExcelUtils.createXmlReader();
+ sheetParser.setContentHandler(handler);
+ try {
+ sheetParser.parse(new InputSource(sheetData));
+ } catch (XlsxStopParsingException e) {
+ logger.debug("Parsing stop signal thrown");
+ } finally {
+ FileHelper.safeClose(sheetData);
+ }
+ }
+
+ protected void buildColumns(final MutableTable table, final List<String> columnNames) {
+ int columnNumber = 0;
+ for (String columnName : columnNames) {
+ if (columnName != null || !_configuration.isSkipEmptyColumns()) {
+ if (columnName == null) {
+ columnName = "[Column " + (columnNumber + 1) + "]";
+ }
+ table.addColumn(new MutableColumn(columnName, ColumnType.VARCHAR, table, columnNumber, true));
+ }
+ columnNumber++;
+ }
+ }
+
+ private void buildTables(final XSSFReader xssfReader, final XlsxWorkbookToTablesHandler workbookToTables)
+ throws Exception {
+ final InputStream workbookData = xssfReader.getWorkbookData();
+ final XMLReader workbookParser = ExcelUtils.createXmlReader();
+ workbookParser.setContentHandler(workbookToTables);
+ workbookParser.parse(new InputSource(workbookData));
+ FileHelper.safeClose(workbookData);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/apache/metamodel/excel/XlsxStopParsingException.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/XlsxStopParsingException.java b/excel/src/main/java/org/apache/metamodel/excel/XlsxStopParsingException.java
new file mode 100644
index 0000000..47d8078
--- /dev/null
+++ b/excel/src/main/java/org/apache/metamodel/excel/XlsxStopParsingException.java
@@ -0,0 +1,33 @@
+/**
+ * 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.excel;
+
+import org.xml.sax.SAXException;
+
+/**
+ * Exception thrown when all elements of interest in a spreadsheet have been
+ * parsed.
+ *
+ * @author Kasper Sørensen
+ */
+final class XlsxStopParsingException extends SAXException {
+
+ private static final long serialVersionUID = 1L;
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/apache/metamodel/excel/XlsxWorkbookToTablesHandler.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/XlsxWorkbookToTablesHandler.java b/excel/src/main/java/org/apache/metamodel/excel/XlsxWorkbookToTablesHandler.java
new file mode 100644
index 0000000..fa65bf8
--- /dev/null
+++ b/excel/src/main/java/org/apache/metamodel/excel/XlsxWorkbookToTablesHandler.java
@@ -0,0 +1,66 @@
+/**
+ * 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.excel;
+
+import java.util.Map;
+
+import org.eobjects.metamodel.schema.MutableSchema;
+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.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * XML handler for transforming a workbook document into {@link Table}s in a
+ * MetaModel {@link Schema}.
+ *
+ * @author Kasper Sørensen
+ */
+final class XlsxWorkbookToTablesHandler extends DefaultHandler {
+
+ private final MutableSchema _schema;
+ private final Map<String, String> _tableNamesToRelationshipIds;
+
+ public XlsxWorkbookToTablesHandler(MutableSchema schema,
+ Map<String, String> tableNamesToRelationshipIds) {
+ _schema = schema;
+ _tableNamesToRelationshipIds = tableNamesToRelationshipIds;
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName,
+ Attributes attributes) throws SAXException {
+ if ("sheet".equals(qName)) {
+ String name = attributes.getValue("name");
+ assert name != null;
+ String relationId = attributes.getValue("r:id");
+ assert relationId != null;
+
+ if (_schema != null) {
+ MutableTable table = new MutableTable(name, TableType.TABLE,
+ _schema);
+ _schema.addTable(table);
+ }
+ _tableNamesToRelationshipIds.put(name, relationId);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/apache/metamodel/excel/ZeroBasedRowIterator.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/ZeroBasedRowIterator.java b/excel/src/main/java/org/apache/metamodel/excel/ZeroBasedRowIterator.java
new file mode 100644
index 0000000..d897ec4
--- /dev/null
+++ b/excel/src/main/java/org/apache/metamodel/excel/ZeroBasedRowIterator.java
@@ -0,0 +1,58 @@
+/**
+ * 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.excel;
+
+import java.util.Iterator;
+
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+
+/**
+ * An iterator implementation that iterates from the first logical (as opposed
+ * to physical, which is the default in POI) row in a spreadsheet.
+ *
+ * @author Kasper Sørensen
+ */
+final class ZeroBasedRowIterator implements Iterator<Row> {
+
+ private final Sheet _sheet;
+ private volatile int _rowNumber;
+
+ public ZeroBasedRowIterator(Sheet sheet) {
+ _sheet = sheet;
+ _rowNumber = -1;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return _rowNumber < _sheet.getLastRowNum();
+ }
+
+ @Override
+ public Row next() {
+ _rowNumber++;
+ return _sheet.getRow(_rowNumber);
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException("remove() is not supported");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/apache/metamodel/excel/package-info.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/package-info.java b/excel/src/main/java/org/apache/metamodel/excel/package-info.java
new file mode 100644
index 0000000..9bf3d30
--- /dev/null
+++ b/excel/src/main/java/org/apache/metamodel/excel/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.
+ */
+/**
+ * Module package for MS Excel spreadsheet files
+ */
+package org.eobjects.metamodel.excel;
+
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/eobjects/metamodel/excel/DefaultSpreadsheetReaderDelegate.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/eobjects/metamodel/excel/DefaultSpreadsheetReaderDelegate.java b/excel/src/main/java/org/eobjects/metamodel/excel/DefaultSpreadsheetReaderDelegate.java
deleted file mode 100644
index dc4a331..0000000
--- a/excel/src/main/java/org/eobjects/metamodel/excel/DefaultSpreadsheetReaderDelegate.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/**
- * 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.excel;
-
-import java.io.InputStream;
-import java.util.Iterator;
-
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.EmptyDataSet;
-import org.eobjects.metamodel.data.MaxRowsDataSet;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-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.Table;
-import org.eobjects.metamodel.util.AlphabeticSequence;
-import org.eobjects.metamodel.util.Ref;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * The default {@link SpreadsheetReaderDelegate}, which uses POI's main user
- * model to read spreadsheets: the Workbook class.
- *
- * @author Kasper Sørensen
- */
-final class DefaultSpreadsheetReaderDelegate implements SpreadsheetReaderDelegate {
-
- private static final Logger logger = LoggerFactory.getLogger(DefaultSpreadsheetReaderDelegate.class);
-
- private final ExcelConfiguration _configuration;
-
- public DefaultSpreadsheetReaderDelegate(ExcelConfiguration configuration) {
- _configuration = configuration;
- }
-
- @Override
- public Schema createSchema(InputStream inputStream, String schemaName) {
- final MutableSchema schema = new MutableSchema(schemaName);
- final Workbook wb = ExcelUtils.readWorkbook(inputStream);
-
- for (int i = 0; i < wb.getNumberOfSheets(); i++) {
- final Sheet currentSheet = wb.getSheetAt(i);
- final MutableTable table = createTable(wb, currentSheet);
- table.setSchema(schema);
- schema.addTable(table);
- }
-
- return schema;
- }
-
- @Override
- public DataSet executeQuery(InputStream inputStream, Table table, Column[] columns, int maxRows) {
- final Workbook wb = ExcelUtils.readWorkbook(inputStream);
- final Sheet sheet = wb.getSheet(table.getName());
-
- if (sheet == null || sheet.getPhysicalNumberOfRows() == 0) {
- return new EmptyDataSet(columns);
- }
-
- DataSet dataSet = ExcelUtils.getDataSet(wb, sheet, table, _configuration);
-
- if (maxRows > 0) {
- dataSet = new MaxRowsDataSet(dataSet, maxRows);
- }
- return dataSet;
- }
-
- @Override
- public void notifyTablesModified(Ref<InputStream> inputStreamRef) {
- // do nothing
- }
-
- private MutableTable createTable(final Workbook wb, final Sheet sheet) {
- final MutableTable table = new MutableTable(sheet.getSheetName());
-
- if (sheet.getPhysicalNumberOfRows() <= 0) {
- // no physical rows in sheet
- return table;
- }
-
- final Iterator<Row> rowIterator = ExcelUtils.getRowIterator(sheet, _configuration, false);
-
- if (!rowIterator.hasNext()) {
- // no physical rows in sheet
- return table;
- }
-
-
- Row row = null;
-
- if (_configuration.isSkipEmptyLines()) {
- while (row == null && rowIterator.hasNext()) {
- row = rowIterator.next();
- }
- } else {
- row = rowIterator.next();
- }
-
- final int columnNameLineNumber = _configuration.getColumnNameLineNumber();
- if (columnNameLineNumber == ExcelConfiguration.NO_COLUMN_NAME_LINE) {
-
- // get to the first non-empty line (no matter if lines are skipped
- // or not we need to read ahead to figure out how many columns there
- // are!)
- while (row == null && rowIterator.hasNext()) {
- row = rowIterator.next();
- }
-
- // build columns by using alphabetic sequences
- // (A,B,C...)
- AlphabeticSequence sequence = new AlphabeticSequence();
-
- final int offset = getColumnOffset(row);
- for (int i = 0; i < offset; i++) {
- sequence.next();
- }
-
- for (int j = offset; j < row.getLastCellNum(); j++) {
- Column column = new MutableColumn(sequence.next(), ColumnType.VARCHAR, table, j, true);
- table.addColumn(column);
- }
- } else {
-
- boolean hasColumns = true;
-
- // iterate to the column name line number (if above 1)
- for (int j = 1; j < columnNameLineNumber; j++) {
- if (rowIterator.hasNext()) {
- row = rowIterator.next();
- } else {
- hasColumns = false;
- break;
- }
- }
-
- if (hasColumns) {
- createColumns(table, wb, row);
- }
- }
-
- return table;
- }
-
- /**
- * Builds columns based on row/cell values.
- *
- * @param table
- * @param wb
- * @param row
- */
- private void createColumns(MutableTable table, Workbook wb, Row row) {
- if (row == null) {
- logger.warn("Cannot create columns based on null row!");
- return;
- }
- final short rowLength = row.getLastCellNum();
-
- final int offset = getColumnOffset(row);
-
- // build columns based on cell values.
- for (int j = offset; j < rowLength; j++) {
- Cell cell = row.getCell(j);
- String columnName = ExcelUtils.getCellValue(wb, cell);
- if (columnName == null || "".equals(columnName)) {
- columnName = "[Column " + (j + 1) + "]";
- }
- Column column = new MutableColumn(columnName, ColumnType.VARCHAR, table, j, true);
- table.addColumn(column);
- }
- }
-
- /**
- * Gets the column offset (first column to include). This is dependent on
- * the row used for column processing and whether the skip empty columns
- * property is set.
- *
- * @param row
- * @return
- */
- private int getColumnOffset(Row row) {
- final int offset;
- if (_configuration.isSkipEmptyColumns()) {
- offset = row.getFirstCellNum();
- } else {
- offset = 0;
- }
- return offset;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelConfiguration.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelConfiguration.java b/excel/src/main/java/org/eobjects/metamodel/excel/ExcelConfiguration.java
deleted file mode 100644
index 6ea490c..0000000
--- a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelConfiguration.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * 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.excel;
-
-import java.io.Serializable;
-import java.util.List;
-
-import org.eobjects.metamodel.util.BaseObject;
-
-/**
- * Represents the configuration for reading/parsing Excel spreadsheets.
- *
- * @see ExcelDataContext
- *
- * @author Kasper Sørensen
- */
-public final class ExcelConfiguration extends BaseObject implements
- Serializable {
-
- private static final long serialVersionUID = 1L;
-
- public static final int NO_COLUMN_NAME_LINE = 0;
- public static final int DEFAULT_COLUMN_NAME_LINE = 1;
-
- private final int columnNameLineNumber;
- private final boolean skipEmptyLines;
- private final boolean skipEmptyColumns;
-
- public ExcelConfiguration() {
- this(DEFAULT_COLUMN_NAME_LINE, true, false);
- }
-
- public ExcelConfiguration(int columnNameLineNumber, boolean skipEmptyLines,
- boolean skipEmptyColumns) {
- this.columnNameLineNumber = columnNameLineNumber;
- this.skipEmptyLines = skipEmptyLines;
- this.skipEmptyColumns = skipEmptyColumns;
- }
-
- /**
- * The line number (1 based) from which to get the names of the columns.
- * Note that this line number is affected by the skipEmptyLines property! If
- * skipEmptyLines is set to true, the line numbers will begin from the first
- * non-empty line.
- *
- * @return the line number of the column headers/names.
- */
- public int getColumnNameLineNumber() {
- return columnNameLineNumber;
- }
-
- /**
- * Defines if empty lines in the excel spreadsheet should be skipped while
- * reading the spreadsheet.
- *
- * @return a boolean indicating whether or not to skip empty lines.
- */
- public boolean isSkipEmptyLines() {
- return skipEmptyLines;
- }
-
- /**
- * Defines if empty columns in the excel spreadsheet should be skipped while
- * reading the spreadsheet.
- *
- * @return a boolean indicating whether or not to skip empty columns.
- */
- public boolean isSkipEmptyColumns() {
- return skipEmptyColumns;
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- identifiers.add(columnNameLineNumber);
- identifiers.add(skipEmptyLines);
- identifiers.add(skipEmptyColumns);
- }
-
- @Override
- public String toString() {
- return "ExcelConfiguration[columnNameLineNumber="
- + columnNameLineNumber + ", skipEmptyLines=" + skipEmptyLines
- + ", skipEmptyColumns=" + skipEmptyColumns + "]";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelDataContext.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelDataContext.java b/excel/src/main/java/org/eobjects/metamodel/excel/ExcelDataContext.java
deleted file mode 100644
index 6726d8b..0000000
--- a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelDataContext.java
+++ /dev/null
@@ -1,259 +0,0 @@
-/**
- * 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.excel;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PushbackInputStream;
-
-import org.apache.poi.POIXMLDocument;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.FileHelper;
-import org.eobjects.metamodel.util.FileResource;
-import org.eobjects.metamodel.util.LazyRef;
-import org.eobjects.metamodel.util.Ref;
-import org.eobjects.metamodel.util.Resource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * {@link DataContext} implementation to use for Excel spreadsheets.
- *
- * This DataContext supports both the "old" .xls format and the "new" .xlsx
- * format, and saves the user the trouble of figuring out which one to use,
- * simply by detecting it at runtime and delegating to the appropriate
- * implementation.
- */
-public final class ExcelDataContext extends QueryPostprocessDataContext implements UpdateableDataContext {
-
- private static final Logger logger = LoggerFactory.getLogger(ExcelDataContext.class);
-
- private final Object WRITE_LOCK = new Object();
-
- private final Resource _resource;
- private final ExcelConfiguration _configuration;
- private SpreadsheetReaderDelegate _spreadsheetReaderDelegate;
-
- /**
- * Constructs an Excel DataContext based on a file, with default
- * configuration
- *
- * @param file
- */
- public ExcelDataContext(File file) {
- this(file, new ExcelConfiguration());
- }
-
- /**
- * Constructs an Excel DataContext based on a resource and a custom
- * configuration.
- *
- * @param file
- * @param configuration
- */
- public ExcelDataContext(File file, ExcelConfiguration configuration) {
- if (file == null) {
- throw new IllegalArgumentException("File cannot be null");
- }
- if (configuration == null) {
- throw new IllegalArgumentException("ExcelConfiguration cannot be null");
- }
- if (file.exists() && !file.canRead()) {
- throw new IllegalArgumentException("Cannot read from file");
- }
- _resource = new FileResource(file);
- _configuration = configuration;
- }
-
- public ExcelDataContext(Resource resource, ExcelConfiguration configuration) {
- if (resource == null) {
- throw new IllegalArgumentException("Resource cannot be null");
- }
- if (configuration == null) {
- throw new IllegalArgumentException("ExcelConfiguration cannot be null");
- }
- _resource = resource;
- _configuration = configuration;
- }
-
- /**
- * Gets the Excel configuration used.
- *
- * @return an excel configuration.
- */
- public ExcelConfiguration getConfiguration() {
- return _configuration;
- }
-
- /**
- * Gets the Excel file being read.
- *
- * @return a file.
- * @deprecated
- */
- @Deprecated
- public File getFile() {
- if (_resource instanceof FileResource) {
- return ((FileResource) _resource).getFile();
- }
- return null;
- }
-
- /**
- * Gets the Excel resource being read
- *
- * @return
- */
- public Resource getResource() {
- return _resource;
- }
-
- @Override
- protected String getMainSchemaName() throws MetaModelException {
- return _resource.getName();
- }
-
- @Override
- public DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
-
- Ref<InputStream> inputStreamRef = getInputStreamRef();
- InputStream inputStream = null;
- try {
- SpreadsheetReaderDelegate delegate = getSpreadsheetReaderDelegate(inputStreamRef);
- inputStream = inputStreamRef.get();
- DataSet dataSet = delegate.executeQuery(inputStream, table, columns, maxRows);
- return dataSet;
- } catch (Exception e) {
- if (e instanceof RuntimeException) {
- throw (RuntimeException) e;
- }
- throw new MetaModelException("Unexpected exception while materializing main schema table", e);
- } finally {
- FileHelper.safeClose(inputStream);
- }
- }
-
- @Override
- protected Schema getMainSchema() throws MetaModelException {
- if (!_resource.isExists()) {
- logger.info("Resource does not exist, returning empty schema");
- return new MutableSchema(getMainSchemaName());
- }
- Ref<InputStream> inputStreamRef = getInputStreamRef();
- InputStream inputStream = null;
- try {
- SpreadsheetReaderDelegate delegate = getSpreadsheetReaderDelegate(inputStreamRef);
- inputStream = inputStreamRef.get();
- Schema schema = delegate.createSchema(inputStream, getMainSchemaName());
- assert getMainSchemaName().equals(schema.getName());
- return schema;
- } catch (Exception e) {
- if (e instanceof RuntimeException) {
- throw (RuntimeException) e;
- }
- throw new MetaModelException("Unexpected exception while building main schema", e);
- } finally {
- FileHelper.safeClose(inputStream);
- }
- }
-
- /**
- * Convenient method for testing and inspecting internal state.
- *
- * @return the class of the spreadsheet reader delegate.
- */
- protected Class<? extends SpreadsheetReaderDelegate> getSpreadsheetReaderDelegateClass() {
- if (_spreadsheetReaderDelegate != null) {
- return _spreadsheetReaderDelegate.getClass();
- }
- return null;
- }
-
- private SpreadsheetReaderDelegate getSpreadsheetReaderDelegate(Ref<InputStream> inputStream) throws MetaModelException {
- if (_spreadsheetReaderDelegate == null) {
- synchronized (this) {
- if (_spreadsheetReaderDelegate == null) {
- try {
- if (POIXMLDocument.hasOOXMLHeader(inputStream.get())) {
- _spreadsheetReaderDelegate = new XlsxSpreadsheetReaderDelegate(_configuration);
- } else {
- _spreadsheetReaderDelegate = new DefaultSpreadsheetReaderDelegate(_configuration);
- }
- } catch (IOException e) {
- logger.error("Could not identify spreadsheet type, using default", e);
- _spreadsheetReaderDelegate = new DefaultSpreadsheetReaderDelegate(_configuration);
- }
- }
- }
- }
- return _spreadsheetReaderDelegate;
- }
-
- private InputStream getInputStream() throws MetaModelException {
- InputStream inputStream = _resource.read();
- if (!inputStream.markSupported()) {
- inputStream = new PushbackInputStream(inputStream, 8);
- }
- return inputStream;
- }
-
- private LazyRef<InputStream> getInputStreamRef() throws MetaModelException {
- final LazyRef<InputStream> inputStreamRef = new LazyRef<InputStream>() {
- @Override
- public InputStream fetch() {
- InputStream inputStream = getInputStream();
- return inputStream;
- }
- };
- return inputStreamRef;
- }
-
- protected void notifyTablesModified() {
- LazyRef<InputStream> inputStreamRef = getInputStreamRef();
- try {
- getSpreadsheetReaderDelegate(inputStreamRef).notifyTablesModified(inputStreamRef);
- } finally {
- if (inputStreamRef.isFetched()) {
- FileHelper.safeClose(inputStreamRef.get());
- }
- }
- }
-
- @Override
- public void executeUpdate(UpdateScript update) {
- ExcelUpdateCallback updateCallback = new ExcelUpdateCallback(this);
- synchronized (WRITE_LOCK) {
- try {
- update.run(updateCallback);
- } finally {
- updateCallback.close();
- }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelDeleteBuilder.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelDeleteBuilder.java b/excel/src/main/java/org/eobjects/metamodel/excel/ExcelDeleteBuilder.java
deleted file mode 100644
index cd2a0cc..0000000
--- a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelDeleteBuilder.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * 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.excel;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.data.DataSetHeader;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.SimpleDataSetHeader;
-import org.eobjects.metamodel.delete.AbstractRowDeletionBuilder;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Table;
-
-final class ExcelDeleteBuilder extends AbstractRowDeletionBuilder {
-
- private final ExcelUpdateCallback _updateCallback;
-
- public ExcelDeleteBuilder(ExcelUpdateCallback updateCallback, Table table) {
- super(table);
- _updateCallback = updateCallback;
- }
-
- @Override
- public void execute() throws MetaModelException {
- // close the update callback will flush any changes
- _updateCallback.close();
-
- // read the workbook without streaming, since this will not wrap it in a
- // streaming workbook implementation (which do not support random
- // accessing rows).
- final Workbook workbook = _updateCallback.getWorkbook(false);
-
- final String tableName = getTable().getName();
- final SelectItem[] selectItems = MetaModelHelper.createSelectItems(getTable().getColumns());
- final DataSetHeader header = new SimpleDataSetHeader(selectItems);
- final Sheet sheet = workbook.getSheet(tableName);
-
- final Iterator<Row> rowIterator = ExcelUtils.getRowIterator(sheet, _updateCallback.getConfiguration(), true);
- final List<Row> rowsToDelete = new ArrayList<Row>();
- while (rowIterator.hasNext()) {
- final Row excelRow = rowIterator.next();
- final DefaultRow row = ExcelUtils.createRow(workbook, excelRow, header);
-
- final boolean deleteRow = deleteRow(row);
- if (deleteRow) {
- rowsToDelete.add(excelRow);
- }
- }
-
- // reverse the list to not mess up any row numbers
- Collections.reverse(rowsToDelete);
-
- for (Row row : rowsToDelete) {
- sheet.removeRow(row);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelDropTableBuilder.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelDropTableBuilder.java b/excel/src/main/java/org/eobjects/metamodel/excel/ExcelDropTableBuilder.java
deleted file mode 100644
index abcb222..0000000
--- a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelDropTableBuilder.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * 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.excel;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.drop.AbstractTableDropBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.Table;
-
-final class ExcelDropTableBuilder extends AbstractTableDropBuilder implements TableDropBuilder {
-
- private ExcelUpdateCallback _updateCallback;
-
- public ExcelDropTableBuilder(ExcelUpdateCallback updateCallback, Table table) {
- super(table);
- _updateCallback = updateCallback;
- }
-
- @Override
- public void execute() throws MetaModelException {
- final Table table = getTable();
- _updateCallback.removeSheet(table.getName());
- final MutableSchema schema = (MutableSchema) table.getSchema();
- schema.removeTable(table);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelInsertBuilder.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelInsertBuilder.java b/excel/src/main/java/org/eobjects/metamodel/excel/ExcelInsertBuilder.java
deleted file mode 100644
index 24bf3b1..0000000
--- a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelInsertBuilder.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/**
- * 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.excel;
-
-import java.util.Date;
-
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.Font;
-import org.apache.poi.ss.usermodel.Row;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.data.Style.Color;
-import org.eobjects.metamodel.data.Style.SizeUnit;
-import org.eobjects.metamodel.data.Style.TextAlignment;
-import org.eobjects.metamodel.insert.AbstractRowInsertionBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.LazyRef;
-
-/**
- * {@link RowInsertionBuilder} for excel spreadsheets.
- *
- * @author Kasper Sørensen
- */
-final class ExcelInsertBuilder extends
- AbstractRowInsertionBuilder<ExcelUpdateCallback> {
-
- public ExcelInsertBuilder(ExcelUpdateCallback updateCallback, Table table) {
- super(updateCallback, table);
- }
-
- @Override
- public void execute() {
- final Object[] values = getValues();
- final Style[] styles = getStyles();
-
- final Row row = getUpdateCallback().createRow(getTable().getName());
-
- final Column[] columns = getColumns();
- for (int i = 0; i < columns.length; i++) {
- Object value = values[i];
- if (value != null) {
- int columnNumber = columns[i].getColumnNumber();
- Cell cell = row.createCell(columnNumber);
-
- // use a lazyref and the isFetched method to only create style
- // if nescesary
- LazyRef<CellStyle> cellStyle = new LazyRef<CellStyle>() {
- @Override
- protected CellStyle fetch() {
- return getUpdateCallback().createCellStyle();
- }
- };
-
- if (value instanceof Number) {
- cell.setCellValue(((Number) value).doubleValue());
- } else if (value instanceof Boolean) {
- cell.setCellValue((Boolean) value);
- } else if (value instanceof Date) {
- cell.setCellValue((Date) value);
- } else {
- cell.setCellValue(value.toString());
- }
-
- Style style = styles[i];
- if (style != null && !Style.NO_STYLE.equals(style)) {
- LazyRef<Font> font = new LazyRef<Font>() {
- @Override
- protected Font fetch() {
- return getUpdateCallback().createFont();
- }
-
- };
- if (style.isBold()) {
- font.get().setBoldweight(Font.BOLDWEIGHT_BOLD);
- }
- if (style.isItalic()) {
- font.get().setItalic(true);
- }
- if (style.isUnderline()) {
- font.get().setUnderline(Font.U_SINGLE);
- }
- if (style.getFontSize() != null) {
- Integer fontSize = style.getFontSize();
- SizeUnit sizeUnit = style.getFontSizeUnit();
- if (sizeUnit == SizeUnit.PERCENT) {
- fontSize = convertFontPercentageToPt(fontSize);
- }
- font.get().setFontHeightInPoints(fontSize.shortValue());
- }
- Color foregroundColor = style.getForegroundColor();
- if (foregroundColor != null) {
- short index = getUpdateCallback().getColorIndex(
- foregroundColor);
- font.get().setColor(index);
- }
- if (font.isFetched()) {
- cellStyle.get().setFont(font.get());
- }
- if (style.getAlignment() != null) {
- cellStyle.get().setAlignment(
- getAlignment(style.getAlignment()));
- }
-
- final Color backgroundColor = style.getBackgroundColor();
- if (backgroundColor != null) {
- cellStyle.get().setFillPattern(
- CellStyle.SOLID_FOREGROUND);
- cellStyle.get().setFillForegroundColor(
- getUpdateCallback().getColorIndex(
- backgroundColor));
- }
- }
-
- if (value instanceof Date) {
- if (cellStyle.isFetched()) {
- cellStyle.get().setDataFormat(
- getUpdateCallback().getDateCellFormat());
- } else {
- cellStyle = new LazyRef<CellStyle>() {
- @Override
- protected CellStyle fetch() {
- return getUpdateCallback().getDateCellStyle();
- }
- };
- // trigger the fetch
- cellStyle.get();
- }
- }
-
- if (cellStyle.isFetched()) {
- cell.setCellStyle(cellStyle.get());
- }
- }
- }
- }
-
- /**
- * Converts a percentage based font size to excel "pt" scale.
- *
- * @param percentage
- * @return
- */
- private Integer convertFontPercentageToPt(Integer percentage) {
- Double d = percentage.intValue() * 11.0 / 100;
- return d.intValue();
- }
-
- private short getAlignment(TextAlignment alignment) {
- switch (alignment) {
- case LEFT:
- return CellStyle.ALIGN_LEFT;
- case RIGHT:
- return CellStyle.ALIGN_RIGHT;
- case CENTER:
- return CellStyle.ALIGN_CENTER;
- case JUSTIFY:
- return CellStyle.ALIGN_JUSTIFY;
- default:
- throw new IllegalArgumentException("Unknown alignment type: "
- + alignment);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelTableCreationBuilder.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelTableCreationBuilder.java b/excel/src/main/java/org/eobjects/metamodel/excel/ExcelTableCreationBuilder.java
deleted file mode 100644
index a031fde..0000000
--- a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelTableCreationBuilder.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * 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.excel;
-
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.eobjects.metamodel.create.AbstractTableCreationBuilder;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * {@link TableCreationBuilder} implementation for Excel spreadsheets.
- *
- * @author Kasper Sørensen
- */
-final class ExcelTableCreationBuilder extends AbstractTableCreationBuilder<ExcelUpdateCallback> {
-
- public ExcelTableCreationBuilder(ExcelUpdateCallback updateCallback, Schema schema, String name) {
- super(updateCallback, schema, name);
- }
-
- @Override
- public Table execute() {
- final ExcelUpdateCallback updateCallback = getUpdateCallback();
- final MutableTable table = getTable();
-
- final Sheet sheet = updateCallback.createSheet(table.getName());
-
- final int lineNumber = updateCallback.getConfiguration().getColumnNameLineNumber();
- if (lineNumber != ExcelConfiguration.NO_COLUMN_NAME_LINE) {
- final int zeroBasedLineNumber = lineNumber - 1;
- final Row row = sheet.createRow(zeroBasedLineNumber);
- final Column[] columns = table.getColumns();
- for (int i = 0; i < columns.length; i++) {
- final Column column = columns[i];
- final int columnNumber = column.getColumnNumber();
- row.createCell(columnNumber).setCellValue(column.getName());
- }
- }
-
- final MutableSchema schema = (MutableSchema) table.getSchema();
- schema.addTable((MutableTable) table);
- return table;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelUpdateCallback.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelUpdateCallback.java b/excel/src/main/java/org/eobjects/metamodel/excel/ExcelUpdateCallback.java
deleted file mode 100644
index 9564ba9..0000000
--- a/excel/src/main/java/org/eobjects/metamodel/excel/ExcelUpdateCallback.java
+++ /dev/null
@@ -1,238 +0,0 @@
-/**
- * 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.excel;
-
-import org.apache.poi.hssf.usermodel.HSSFPalette;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.util.HSSFColor;
-import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.Font;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.xssf.streaming.SXSSFSheet;
-import org.apache.poi.xssf.streaming.SXSSFWorkbook;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.eobjects.metamodel.AbstractUpdateCallback;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Style.Color;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-final class ExcelUpdateCallback extends AbstractUpdateCallback implements UpdateCallback {
-
- private final ExcelDataContext _dataContext;
- private final ExcelConfiguration _configuration;
- private boolean _sheetsModified;
- private Workbook _workbook;
- private Short _dateCellFormat;
- private CellStyle _dateCellStyle;
-
- public ExcelUpdateCallback(ExcelDataContext dataContext) {
- super(dataContext);
- _sheetsModified = false;
- _configuration = dataContext.getConfiguration();
- _dataContext = dataContext;
- }
-
- @Override
- public TableCreationBuilder createTable(Schema schema, String name) throws IllegalArgumentException,
- IllegalStateException {
- return new ExcelTableCreationBuilder(this, schema, name);
- }
-
- @Override
- public RowInsertionBuilder insertInto(Table table) throws IllegalArgumentException, IllegalStateException {
- return new ExcelInsertBuilder(this, table);
- }
-
- protected ExcelConfiguration getConfiguration() {
- return _configuration;
- }
-
- @Override
- public ExcelDataContext getDataContext() {
- return _dataContext;
- }
-
- protected void close() {
- if (_workbook != null) {
- ExcelUtils.writeWorkbook(_dataContext, _workbook);
-
- _workbook = null;
- _dateCellFormat = null;
- _dateCellStyle = null;
- }
- if (_sheetsModified) {
- _dataContext.notifyTablesModified();
- _sheetsModified = false;
- }
- }
-
- protected Workbook getWorkbook(boolean streamingAllowed) {
- if (_workbook == null || (!streamingAllowed && _workbook instanceof SXSSFWorkbook)) {
- if (_workbook != null) {
- ExcelUtils.writeWorkbook(_dataContext, _workbook);
- }
- _workbook = ExcelUtils.readWorkbook(_dataContext);
- if (streamingAllowed && _workbook instanceof XSSFWorkbook) {
- _workbook = new SXSSFWorkbook((XSSFWorkbook) _workbook);
- }
- }
- return _workbook;
- }
-
- protected Sheet createSheet(String name) {
- Sheet sheet = getWorkbook(true).createSheet(name);
- _sheetsModified = true;
- return sheet;
- }
-
- protected void removeSheet(String name) {
- int index = getWorkbook(true).getSheetIndex(name);
- if (index != -1) {
- getWorkbook(true).removeSheetAt(index);
- _sheetsModified = true;
- }
- }
-
- protected Row createRow(String name) {
- if (_sheetsModified) {
- close();
- }
- Sheet sheet = getWorkbook(true).getSheet(name);
- int lastRowNum = getLastRowNum(sheet);
- Row row = sheet.createRow(lastRowNum + 1);
- return row;
- }
-
- private int getLastRowNum(Sheet sheet) {
- final int lastRowNum = sheet.getLastRowNum();
- if (lastRowNum == 0 && sheet instanceof SXSSFSheet) {
- // streaming sheets have bad behaviour in this scenario - since no
- // rows are in cache, it will return 0!
- DataSet ds = _dataContext.query().from(sheet.getSheetName()).selectCount().execute();
- ds.next();
- final Number count = (Number) ds.getRow().getValue(0);
- final int columnNameLineNumber = _configuration.getColumnNameLineNumber();
- int oneBasedResult = count.intValue()
- + (columnNameLineNumber == ExcelConfiguration.NO_COLUMN_NAME_LINE ? 0 : columnNameLineNumber);
- return oneBasedResult - 1;
- }
- return lastRowNum;
- }
-
- /**
- * Creates a new cell style in the spreadsheet
- *
- * @return
- */
- public CellStyle createCellStyle() {
- Workbook workbook = getWorkbook(true);
- return workbook.createCellStyle();
- }
-
- public Font createFont() {
- Workbook workbook = getWorkbook(true);
- return workbook.createFont();
- }
-
- protected Sheet getSheet(String name) {
- return getWorkbook(true).getSheet(name);
- }
-
- /**
- * Gets the index identifier for the date format
- *
- * @return
- */
- public short getDateCellFormat() {
- if (_dateCellFormat == null) {
- Workbook workbook = getWorkbook(true);
- _dateCellFormat = workbook.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm");
- }
- return _dateCellFormat;
- }
-
- /**
- * Gets a shared, reusable cell style for "pure date" cells (eg. no other
- * styling applied)
- *
- * @return
- */
- public CellStyle getDateCellStyle() {
- if (_dateCellStyle == null) {
- _dateCellStyle = createCellStyle();
- _dateCellStyle.setDataFormat(getDateCellFormat());
- }
- return _dateCellStyle;
- }
-
- public short getColorIndex(Color color) {
- Workbook workbook = getWorkbook(true);
- if (workbook instanceof HSSFWorkbook) {
- HSSFPalette palette = ((HSSFWorkbook) workbook).getCustomPalette();
- byte r = toRgb(color.getRed());
- byte g = toRgb(color.getGreen());
- byte b = toRgb(color.getBlue());
-
- HSSFColor index = palette.findColor(r, g, b);
- if (index == null) {
- index = palette.findSimilarColor(r, g, b);
- }
- return index.getIndex();
- }
- throw new IllegalStateException("Unexpected workbook type: " + workbook.getClass());
- }
-
- private byte toRgb(int i) {
- assert i >= 0;
- assert i <= 255;
-
- if (i > 127) {
- i = i - 256;
- }
- return (byte) i;
- }
-
- @Override
- public boolean isDropTableSupported() {
- return true;
- }
-
- @Override
- public TableDropBuilder dropTable(Table table) throws UnsupportedOperationException {
- return new ExcelDropTableBuilder(this, table);
- }
-
- @Override
- public boolean isDeleteSupported() {
- return true;
- }
-
- @Override
- public RowDeletionBuilder deleteFrom(Table table) throws UnsupportedOperationException {
- return new ExcelDeleteBuilder(this, table);
- }
-}
[17/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/test/java/org/eobjects/metamodel/couchdb/CouchDbDataContextTest.java
----------------------------------------------------------------------
diff --git a/couchdb/src/test/java/org/eobjects/metamodel/couchdb/CouchDbDataContextTest.java b/couchdb/src/test/java/org/eobjects/metamodel/couchdb/CouchDbDataContextTest.java
deleted file mode 100644
index 403a64c..0000000
--- a/couchdb/src/test/java/org/eobjects/metamodel/couchdb/CouchDbDataContextTest.java
+++ /dev/null
@@ -1,354 +0,0 @@
-/**
- * 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.couchdb;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.ektorp.CouchDbConnector;
-import org.ektorp.DbAccessException;
-import org.ektorp.http.HttpClient;
-import org.ektorp.http.StdHttpClient;
-import org.ektorp.impl.StdCouchDbInstance;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.drop.DropTable;
-import org.eobjects.metamodel.insert.InsertInto;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.SimpleTableDef;
-
-public class CouchDbDataContextTest extends TestCase {
-
- private static final String TEST_DATABASE_NAME = "eobjects_metamodel_test";
-
- private boolean serverAvailable;
-
- private HttpClient httpClient;
- private StdCouchDbInstance couchDbInstance;
- private CouchDbConnector connector;
- private SimpleTableDef predefinedTableDef;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- httpClient = new StdHttpClient.Builder().host("localhost").build();
-
- // set up a simple database
- couchDbInstance = new StdCouchDbInstance(httpClient);
-
- try {
- if (couchDbInstance.getAllDatabases().contains(TEST_DATABASE_NAME)) {
- throw new IllegalStateException("Couch DB instance already has a database called " + TEST_DATABASE_NAME);
- }
- connector = couchDbInstance.createConnector(TEST_DATABASE_NAME, true);
- System.out.println("Running CouchDB integration tests");
- serverAvailable = true;
- } catch (DbAccessException e) {
- System.out.println("!!! WARNING: Skipping CouchDB tests because local server is not available");
- e.printStackTrace();
- serverAvailable = false;
- }
-
- final String[] columnNames = new String[] { "name", "gender", "age" };
- final ColumnType[] columnTypes = new ColumnType[] { ColumnType.VARCHAR, ColumnType.CHAR, ColumnType.INTEGER };
- predefinedTableDef = new SimpleTableDef(TEST_DATABASE_NAME, columnNames, columnTypes);
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
-
- connector = null;
-
- if (serverAvailable) {
- couchDbInstance.deleteDatabase(TEST_DATABASE_NAME);
- }
-
- httpClient.shutdown();
- }
-
- public void testWorkingWithMapsAndLists() throws Exception {
- if (!serverAvailable) {
- return;
- }
-
- connector = couchDbInstance.createConnector("test_table_map_and_list", true);
-
- final CouchDbDataContext dc = new CouchDbDataContext(couchDbInstance, new SimpleTableDef("test_table_map_and_list",
- new String[] { "id", "foo", "bar" }, new ColumnType[] { ColumnType.INTEGER, ColumnType.MAP, ColumnType.LIST }));
- Table table = null;
- try {
- table = dc.getTableByQualifiedLabel("test_table_map_and_list");
- Map<String, Object> exampleMap = new LinkedHashMap<String, Object>();
- exampleMap.put("hello", Arrays.asList("world", "welt", "verden"));
- exampleMap.put("foo", "bar");
-
- List<Map<String, Object>> exampleList = new ArrayList<Map<String, Object>>();
- exampleList.add(new LinkedHashMap<String, Object>());
- Map<String, Object> exampleMap2 = new LinkedHashMap<String, Object>();
- exampleMap2.put("meta", "model");
- exampleMap2.put("couch", "db");
- exampleList.add(exampleMap2);
-
- dc.executeUpdate(new InsertInto(table).value("id", 1).value("foo", exampleMap).value("bar", exampleList));
-
- DataSet ds = dc.query().from(table).select("id","foo","bar").execute();
- assertTrue(ds.next());
- Row row = ds.getRow();
- assertFalse(ds.next());
- ds.close();
-
- assertEquals(
- "Row[values=[1, {hello=[world, welt, verden], foo=bar}, [{}, {meta=model, couch=db}]]]",
- row.toString());
- assertTrue(row.getValue(0) instanceof Integer);
- assertTrue(row.getValue(1) instanceof Map);
- assertTrue(row.getValue(2) instanceof List);
-
- } finally {
- dc.executeUpdate(new DropTable(table));
- }
-
- }
-
- public void testCreateUpdateDeleteScenario() throws Exception {
- if (!serverAvailable) {
- return;
- }
-
- final CouchDbDataContext dc = new CouchDbDataContext(couchDbInstance);
-
- // first delete the manually created database!
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.dropTable(TEST_DATABASE_NAME).execute();
- }
- });
-
- assertNull(dc.getDefaultSchema().getTableByName(TEST_DATABASE_NAME));
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- Table table = callback.createTable(dc.getDefaultSchema(), TEST_DATABASE_NAME).withColumn("foo")
- .ofType(ColumnType.VARCHAR).withColumn("greeting").ofType(ColumnType.VARCHAR).execute();
- assertEquals("[_id, _rev, foo, greeting]", Arrays.toString(table.getColumnNames()));
- }
- });
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.insertInto(TEST_DATABASE_NAME).value("foo", "bar").value("greeting", "hello").execute();
- callback.insertInto(TEST_DATABASE_NAME).value("foo", "baz").value("greeting", "hi").execute();
- }
- });
-
- DataSet ds = dc.query().from(TEST_DATABASE_NAME).select("_id", "foo", "greeting").execute();
- assertTrue(ds.next());
- assertNotNull(ds.getRow().getValue(0));
- assertEquals("bar", ds.getRow().getValue(1));
- assertEquals("hello", ds.getRow().getValue(2));
- assertTrue(ds.next());
- assertNotNull(ds.getRow().getValue(0));
- assertEquals("baz", ds.getRow().getValue(1));
- assertEquals("hi", ds.getRow().getValue(2));
- assertFalse(ds.next());
- ds.close();
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.update(TEST_DATABASE_NAME).value("greeting", "howdy").where("foo").isEquals("baz").execute();
-
- callback.update(TEST_DATABASE_NAME).value("foo", "foo").where("foo").isEquals("bar").execute();
- }
- });
-
- ds = dc.query().from(TEST_DATABASE_NAME).select("_id", "foo", "greeting").execute();
- assertTrue(ds.next());
- assertNotNull(ds.getRow().getValue(0));
- assertEquals("foo", ds.getRow().getValue(1));
- assertEquals("hello", ds.getRow().getValue(2));
- assertTrue(ds.next());
- assertNotNull(ds.getRow().getValue(0));
- assertEquals("baz", ds.getRow().getValue(1));
- assertEquals("howdy", ds.getRow().getValue(2));
- assertFalse(ds.next());
- ds.close();
- }
-
- public void testBasicQuery() throws Exception {
- if (!serverAvailable) {
- return;
- }
-
- // insert a few records
- {
- HashMap<String, Object> map;
-
- map = new HashMap<String, Object>();
- map.put("name", "John Doe");
- map.put("age", 30);
- connector.create(map);
-
- map = new HashMap<String, Object>();
- map.put("name", "Jane Doe");
- map.put("gender", 'F');
- connector.create(map);
- }
-
- // create datacontext using detected schema
- SimpleTableDef tableDef = CouchDbDataContext.detectTable(connector);
- CouchDbDataContext dc = new CouchDbDataContext(couchDbInstance, tableDef);
-
- // verify schema and execute query
- Schema schema = dc.getMainSchema();
- assertEquals("[eobjects_metamodel_test]", Arrays.toString(schema.getTableNames()));
-
- assertEquals("[_id, _rev, age, gender, name]",
- Arrays.toString(schema.getTableByName(TEST_DATABASE_NAME).getColumnNames()));
- Column idColumn = schema.getTableByName(TEST_DATABASE_NAME).getColumnByName("_id");
- assertEquals("Column[name=_id,columnNumber=0,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]",
- idColumn.toString());
- assertTrue(idColumn.isPrimaryKey());
-
- assertEquals("Column[name=_rev,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]", schema
- .getTableByName(TEST_DATABASE_NAME).getColumnByName("_rev").toString());
-
- DataSet ds;
-
- ds = dc.query().from(TEST_DATABASE_NAME).select("name").and("age").execute();
- assertTrue(ds.next());
- assertEquals("Row[values=[John Doe, 30]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[Jane Doe, null]]", ds.getRow().toString());
- assertFalse(ds.next());
- ds.close();
-
- ds = dc.query().from(TEST_DATABASE_NAME).select("name").and("gender").where("age").isNull().execute();
- assertTrue(ds.next());
- assertEquals("Row[values=[Jane Doe, F]]", ds.getRow().toString());
- assertFalse(ds.next());
- ds.close();
- }
-
- public void testFirstRowAndLastRow() throws Exception {
- if (!serverAvailable) {
- return;
- }
-
- // insert a few records
- {
- HashMap<String, Object> map;
-
- map = new HashMap<String, Object>();
- map.put("name", "John Doe");
- map.put("age", 30);
- connector.create(map);
-
- map = new HashMap<String, Object>();
- map.put("name", "Jane Doe");
- map.put("gender", 'F');
- connector.create(map);
- }
-
- // create datacontext using detected schema
- SimpleTableDef tableDef = CouchDbDataContext.detectTable(connector);
- CouchDbDataContext dc = new CouchDbDataContext(couchDbInstance, tableDef);
-
- DataSet ds1 = dc.query().from(TEST_DATABASE_NAME).select("name").and("age").firstRow(2).execute();
- DataSet ds2 = dc.query().from(TEST_DATABASE_NAME).select("name").and("age").maxRows(1).execute();
-
- assertTrue("Class: " + ds1.getClass().getName(), ds1 instanceof CouchDbDataSet);
- assertTrue("Class: " + ds2.getClass().getName(), ds2 instanceof CouchDbDataSet);
-
- assertTrue(ds1.next());
- assertTrue(ds2.next());
-
- final Row row1 = ds1.getRow();
- final Row row2 = ds2.getRow();
-
- assertFalse(ds1.next());
- assertFalse(ds2.next());
-
- assertEquals("Row[values=[Jane Doe, null]]", row1.toString());
- assertEquals("Row[values=[John Doe, 30]]", row2.toString());
-
- ds1.close();
- ds2.close();
- }
-
- public void testInsert() throws Exception {
- if (!serverAvailable) {
- return;
- }
-
- // create datacontext using predefined table def
- CouchDbDataContext dc = new CouchDbDataContext(httpClient, predefinedTableDef);
- Table table = dc.getTableByQualifiedLabel(TEST_DATABASE_NAME);
- assertNotNull(table);
-
- assertEquals("[_id, _rev, name, gender, age]", Arrays.toString(table.getColumnNames()));
-
- DataSet ds;
-
- // assert not rows in DB
- ds = dc.query().from(TEST_DATABASE_NAME).selectCount().execute();
- assertTrue(ds.next());
- assertEquals(0, ((Number) ds.getRow().getValue(0)).intValue());
- assertFalse(ds.next());
- ds.close();
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.insertInto(TEST_DATABASE_NAME).value("name", "foo").value("gender", 'M').execute();
- callback.insertInto(TEST_DATABASE_NAME).value("name", "bar").value("age", 32).execute();
- }
- });
-
- // now count should be 2
- ds = dc.query().from(TEST_DATABASE_NAME).selectCount().execute();
- assertTrue(ds.next());
- assertEquals(2, ((Number) ds.getRow().getValue(0)).intValue());
- assertFalse(ds.next());
- ds.close();
-
- ds = dc.query().from(TEST_DATABASE_NAME).select("name", "gender", "age").execute();
- assertTrue(ds.next());
- assertEquals("Row[values=[foo, M, null]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[bar, null, 32]]", ds.getRow().toString());
- assertFalse(ds.next());
- ds.close();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/apache/metamodel/csv/CsvConfiguration.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvConfiguration.java b/csv/src/main/java/org/apache/metamodel/csv/CsvConfiguration.java
new file mode 100644
index 0000000..8e34913
--- /dev/null
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvConfiguration.java
@@ -0,0 +1,160 @@
+/**
+ * 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.csv;
+
+import java.io.Serializable;
+import java.util.List;
+
+import org.eobjects.metamodel.util.BaseObject;
+import org.eobjects.metamodel.util.FileHelper;
+
+/**
+ * Represents the configuration for reading/parsing CSV files.
+ *
+ * @author Kasper Sørensen
+ */
+public final class CsvConfiguration extends BaseObject implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The value is '\\uFFFF', the "not a character" value which should not
+ * occur in any valid Unicode string. This special char can be used to
+ * disable either quote chars or escape chars.
+ */
+ public static final char NOT_A_CHAR = '\uFFFF';
+ public static final int NO_COLUMN_NAME_LINE = 0;
+ public static final int DEFAULT_COLUMN_NAME_LINE = 1;
+ public static final char DEFAULT_SEPARATOR_CHAR = ',';
+ public static final char DEFAULT_QUOTE_CHAR = '"';
+ public static final char DEFAULT_ESCAPE_CHAR = '\\';
+
+ private final int columnNameLineNumber;
+ private final String encoding;
+ private final char separatorChar;
+ private final char quoteChar;
+ private final char escapeChar;
+ private final boolean failOnInconsistentRowLength;
+
+ public CsvConfiguration() {
+ this(DEFAULT_COLUMN_NAME_LINE);
+ }
+
+ public CsvConfiguration(int columnNameLineNumber) {
+ this(columnNameLineNumber, FileHelper.DEFAULT_ENCODING,
+ DEFAULT_SEPARATOR_CHAR, DEFAULT_QUOTE_CHAR, DEFAULT_ESCAPE_CHAR);
+ }
+
+ public CsvConfiguration(int columnNameLineNumber, String encoding,
+ char separatorChar, char quoteChar, char escapeChar) {
+ this(columnNameLineNumber, encoding, separatorChar, quoteChar,
+ escapeChar, false);
+ }
+
+ public CsvConfiguration(int columnNameLineNumber, String encoding,
+ char separatorChar, char quoteChar, char escapeChar,
+ boolean failOnInconsistentRowLength) {
+ this.columnNameLineNumber = columnNameLineNumber;
+ this.encoding = encoding;
+ this.separatorChar = separatorChar;
+ this.quoteChar = quoteChar;
+ this.escapeChar = escapeChar;
+ this.failOnInconsistentRowLength = failOnInconsistentRowLength;
+ }
+
+ /**
+ * Determines whether to fail (by throwing an
+ * {@link InconsistentRowLengthException}) if a line in the CSV file has
+ * inconsistent amounts of columns.
+ *
+ * If set to false (default) MetaModel will gracefully fill in missing null
+ * values in or ignore additional values in a line.
+ *
+ * @return a boolean indicating whether to fail or gracefully compensate for
+ * inconsistent lines in the CSV files.
+ */
+ public boolean isFailOnInconsistentRowLength() {
+ return failOnInconsistentRowLength;
+ }
+
+ /**
+ * The line number (1 based) from which to get the names of the columns.
+ *
+ * @return the line number (1 based)
+ */
+ public int getColumnNameLineNumber() {
+ return columnNameLineNumber;
+ }
+
+ /**
+ * Gets the file encoding to use for reading the file.
+ *
+ * @return the text encoding of the file.
+ */
+ public String getEncoding() {
+ return encoding;
+ }
+
+ /**
+ * Gets the separator char (typically comma or semicolon) for separating
+ * values.
+ *
+ * @return the separator char
+ */
+ public char getSeparatorChar() {
+ return separatorChar;
+ }
+
+ /**
+ * Gets the quote char, used for encapsulating values.
+ *
+ * @return the quote char
+ */
+ public char getQuoteChar() {
+ return quoteChar;
+ }
+
+ /**
+ * Gets the escape char, used for escaping eg. quote chars inside values.
+ *
+ * @return the escape char
+ */
+ public char getEscapeChar() {
+ return escapeChar;
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ identifiers.add(columnNameLineNumber);
+ identifiers.add(encoding);
+ identifiers.add(separatorChar);
+ identifiers.add(quoteChar);
+ identifiers.add(escapeChar);
+ identifiers.add(failOnInconsistentRowLength);
+ }
+
+ @Override
+ public String toString() {
+ return "CsvConfiguration[columnNameLineNumber=" + columnNameLineNumber
+ + ", encoding=" + encoding + ", separatorChar=" + separatorChar
+ + ", quoteChar=" + quoteChar + ", escapeChar=" + escapeChar
+ + ", failOnInconsistentRowLength="
+ + failOnInconsistentRowLength + "]";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/apache/metamodel/csv/CsvCreateTableBuilder.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvCreateTableBuilder.java b/csv/src/main/java/org/apache/metamodel/csv/CsvCreateTableBuilder.java
new file mode 100644
index 0000000..906d2e1
--- /dev/null
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvCreateTableBuilder.java
@@ -0,0 +1,51 @@
+/**
+ * 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.csv;
+
+import org.eobjects.metamodel.create.AbstractTableCreationBuilder;
+import org.eobjects.metamodel.schema.MutableTable;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+final class CsvCreateTableBuilder extends
+ AbstractTableCreationBuilder<CsvUpdateCallback> {
+
+ public CsvCreateTableBuilder(CsvUpdateCallback updateCallback,
+ Schema schema, String name) {
+ super(updateCallback, schema, name);
+ if (!(schema instanceof CsvSchema)) {
+ throw new IllegalArgumentException("Not a valid CSV schema: "
+ + schema);
+ }
+ }
+
+ @Override
+ public Table execute() {
+ CsvUpdateCallback csvUpdateCallback = getUpdateCallback();
+
+ MutableTable table = getTable();
+ String[] columnNames = table.getColumnNames();
+ csvUpdateCallback.writeRow(columnNames, false);
+
+ CsvSchema schema = (CsvSchema) table.getSchema();
+ CsvTable csvTable = new CsvTable(schema, table.getColumnNames());
+ schema.setTable(csvTable);
+ return csvTable;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/apache/metamodel/csv/CsvDataContext.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvDataContext.java b/csv/src/main/java/org/apache/metamodel/csv/CsvDataContext.java
new file mode 100644
index 0000000..6409596
--- /dev/null
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvDataContext.java
@@ -0,0 +1,393 @@
+/**
+ * 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.csv;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.util.List;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.QueryPostprocessDataContext;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.UpdateableDataContext;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.FileHelper;
+import org.eobjects.metamodel.util.FileResource;
+import org.eobjects.metamodel.util.Func;
+import org.eobjects.metamodel.util.Resource;
+import org.eobjects.metamodel.util.UrlResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import au.com.bytecode.opencsv.CSVReader;
+
+/**
+ * DataContext implementation for reading CSV files.
+ */
+public final class CsvDataContext extends QueryPostprocessDataContext implements UpdateableDataContext {
+
+ private static final Logger logger = LoggerFactory.getLogger(CsvDataContext.class);
+
+ private final Object WRITE_LOCK = new Object();
+
+ private final Resource _resource;
+ private final CsvConfiguration _configuration;
+ private final boolean _writable;
+
+ /**
+ * Constructs a CSV DataContext based on a file
+ *
+ * @param file
+ * @param configuration
+ */
+ public CsvDataContext(File file, CsvConfiguration configuration) {
+ if (file == null) {
+ throw new IllegalArgumentException("File cannot be null");
+ }
+ if (configuration == null) {
+ throw new IllegalArgumentException("CsvConfiguration cannot be null");
+ }
+ _resource = new FileResource(file);
+ _configuration = configuration;
+ _writable = true;
+ }
+
+ public CsvDataContext(Resource resource, CsvConfiguration configuration) {
+ if (resource == null) {
+ throw new IllegalArgumentException("File cannot be null");
+ }
+ if (configuration == null) {
+ throw new IllegalArgumentException("CsvConfiguration cannot be null");
+ }
+ _resource = resource;
+ _configuration = configuration;
+ _writable = !resource.isReadOnly();
+ }
+
+ /**
+ * Constructs a CSV DataContext based on a {@link URL}
+ *
+ * @param url
+ * @param configuration
+ */
+ public CsvDataContext(URL url, CsvConfiguration configuration) {
+ _resource = new UrlResource(url);
+ _configuration = configuration;
+ _writable = false;
+ }
+
+ /**
+ * Constructs a CSV DataContext based on a file
+ *
+ * @param file
+ */
+ public CsvDataContext(File file) {
+ this(file, new CsvConfiguration());
+ }
+
+ /**
+ * Constructs a CSV DataContext based on an {@link InputStream}
+ *
+ * @param inputStream
+ * @param configuration
+ */
+ public CsvDataContext(InputStream inputStream, CsvConfiguration configuration) {
+ File file = createFileFromInputStream(inputStream, configuration.getEncoding());
+ _configuration = configuration;
+ _writable = false;
+ _resource = new FileResource(file);
+ }
+
+ /**
+ * @deprecated use {@link #CsvDataContext(File, CsvConfiguration)} instead.
+ */
+ @Deprecated
+ public CsvDataContext(File file, char separatorChar) {
+ this(file, separatorChar, CsvConfiguration.DEFAULT_QUOTE_CHAR);
+ }
+
+ /**
+ * @deprecated use {@link #CsvDataContext(File, CsvConfiguration)} instead.
+ */
+ @Deprecated
+ public CsvDataContext(File file, char separatorChar, char quoteChar) {
+ this(file, new CsvConfiguration(CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, FileHelper.DEFAULT_ENCODING,
+ separatorChar, quoteChar, CsvConfiguration.DEFAULT_ESCAPE_CHAR));
+ }
+
+ /**
+ * @deprecated use {@link #CsvDataContext(File, CsvConfiguration)} instead.
+ */
+ @Deprecated
+ public CsvDataContext(File file, char separatorChar, char quoteChar, String encoding) {
+ this(file, new CsvConfiguration(CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, encoding, separatorChar, quoteChar,
+ CsvConfiguration.DEFAULT_ESCAPE_CHAR));
+ }
+
+ /**
+ * @deprecated use {@link #CsvDataContext(URL, CsvConfiguration)} instead.
+ */
+ @Deprecated
+ public CsvDataContext(URL url, char separatorChar, char quoteChar) {
+ this(url, separatorChar, quoteChar, FileHelper.DEFAULT_ENCODING);
+ }
+
+ /**
+ * @deprecated use {@link #CsvDataContext(URL, CsvConfiguration)} instead.
+ */
+ @Deprecated
+ public CsvDataContext(URL url, char separatorChar, char quoteChar, String encoding) {
+ this(url, new CsvConfiguration(CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, encoding, separatorChar, quoteChar,
+ CsvConfiguration.DEFAULT_ESCAPE_CHAR));
+ }
+
+ /**
+ * @deprecated use {@link #CsvDataContext(InputStream, CsvConfiguration)}
+ * instead.
+ */
+ @Deprecated
+ public CsvDataContext(InputStream inputStream, char separatorChar, char quoteChar) {
+ this(inputStream, new CsvConfiguration(CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, FileHelper.DEFAULT_ENCODING,
+ separatorChar, quoteChar, CsvConfiguration.DEFAULT_ESCAPE_CHAR));
+ }
+
+ /**
+ * @deprecated use {@link #CsvDataContext(InputStream, CsvConfiguration)}
+ * instead.
+ */
+ @Deprecated
+ public CsvDataContext(InputStream inputStream, char separatorChar, char quoteChar, String encoding) {
+ this(inputStream, new CsvConfiguration(CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, encoding, separatorChar,
+ quoteChar, CsvConfiguration.DEFAULT_ESCAPE_CHAR));
+ }
+
+ /**
+ * Gets the CSV configuration used
+ *
+ * @return a CSV configuration
+ */
+ public CsvConfiguration getConfiguration() {
+ return _configuration;
+ }
+
+ /**
+ * Gets the CSV file being read
+ *
+ * @return a file
+ *
+ * @deprecated use {@link #getResource()} instead.
+ */
+ @Deprecated
+ public File getFile() {
+ if (_resource instanceof FileResource) {
+ return ((FileResource) _resource).getFile();
+ }
+ return null;
+ }
+
+ /**
+ * Gets the resource that is being read from.
+ *
+ * @return
+ */
+ public Resource getResource() {
+ return _resource;
+ }
+
+ private static File createFileFromInputStream(InputStream inputStream, String encoding) {
+ final File file;
+ final File tempDir = FileHelper.getTempDir();
+
+ File fileCandidate = null;
+ boolean usableName = false;
+ int index = 0;
+
+ while (!usableName) {
+ index++;
+ fileCandidate = new File(tempDir, "metamodel" + index + ".csv");
+ usableName = !fileCandidate.exists();
+ }
+ file = fileCandidate;
+
+ final BufferedWriter writer = FileHelper.getBufferedWriter(file, encoding);
+ final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
+
+ try {
+ file.createNewFile();
+ file.deleteOnExit();
+
+ boolean firstLine = true;
+
+ for (String line = reader.readLine(); line != null; line = reader.readLine()) {
+ if (firstLine) {
+ firstLine = false;
+ } else {
+ writer.write('\n');
+ }
+ writer.write(line);
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ } finally {
+ FileHelper.safeClose(writer, reader);
+ }
+
+ return file;
+ }
+
+ @Override
+ protected Number executeCountQuery(Table table, List<FilterItem> whereItems, boolean functionApproximationAllowed) {
+ if (!functionApproximationAllowed) {
+ return null;
+ }
+
+ return _resource.read(new Func<InputStream, Number>() {
+ @Override
+ public Number eval(InputStream inputStream) {
+ try {
+ final long length = _resource.getSize();
+ // read up to 5 megs of the file and approximate number of
+ // lines
+ // based on that.
+
+ final int sampleSize = (int) Math.min(length, 1024 * 1024 * 5);
+ final int chunkSize = Math.min(sampleSize, 1024 * 1024);
+
+ int readSize = 0;
+ int newlines = 0;
+ int carriageReturns = 0;
+ byte[] byteBuffer = new byte[chunkSize];
+ char[] charBuffer = new char[chunkSize];
+
+ while (readSize < sampleSize) {
+ final int read = inputStream.read(byteBuffer);
+ if (read == -1) {
+ break;
+ } else {
+ readSize += read;
+ }
+
+ Reader reader = getReader(byteBuffer, _configuration.getEncoding());
+ reader.read(charBuffer);
+ for (char c : charBuffer) {
+ if ('\n' == c) {
+ newlines++;
+ } else if ('\r' == c) {
+ carriageReturns++;
+ }
+ }
+ }
+
+ int lines = Math.max(newlines, carriageReturns);
+
+ logger.info("Found {} lines breaks in {} bytes", lines, sampleSize);
+
+ long approxCount = (long) (lines * length / sampleSize);
+ return approxCount;
+ } catch (IOException e) {
+ logger.error("Unexpected error during COUNT(*) approximation", e);
+ throw new IllegalStateException(e);
+ }
+ }
+ });
+ }
+
+ private Reader getReader(byte[] byteBuffer, String encoding) throws UnsupportedEncodingException {
+ try {
+ return new InputStreamReader(new ByteArrayInputStream(byteBuffer), encoding);
+ } catch (UnsupportedEncodingException e1) {
+ // this may happen on more exotic encodings, but since this reader
+ // is only meant for finding newlines, we'll try again with UTF8
+ try {
+ return new InputStreamReader(new ByteArrayInputStream(byteBuffer), "UTF8");
+ } catch (UnsupportedEncodingException e2) {
+ throw e1;
+ }
+ }
+ }
+
+ @Override
+ public DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+ final int lineNumber = _configuration.getColumnNameLineNumber();
+ final CSVReader reader = createCsvReader(lineNumber);
+ final int columnCount = table.getColumnCount();
+ final boolean failOnInconsistentRowLength = _configuration.isFailOnInconsistentRowLength();
+ if (maxRows < 0) {
+ return new CsvDataSet(reader, columns, null, columnCount, failOnInconsistentRowLength);
+ } else {
+ return new CsvDataSet(reader, columns, maxRows, columnCount, failOnInconsistentRowLength);
+ }
+ }
+
+ protected CSVReader createCsvReader(int skipLines) {
+ final Reader fileReader = FileHelper.getReader(_resource.read(), _configuration.getEncoding());
+ final CSVReader csvReader = new CSVReader(fileReader, _configuration.getSeparatorChar(),
+ _configuration.getQuoteChar(), _configuration.getEscapeChar(), skipLines);
+ return csvReader;
+ }
+
+ @Override
+ protected CsvSchema getMainSchema() throws MetaModelException {
+ CsvSchema schema = new CsvSchema(getMainSchemaName(), this);
+ if (_resource.isExists()) {
+ schema.setTable(new CsvTable(schema));
+ }
+ return schema;
+ }
+
+ @Override
+ protected String getMainSchemaName() {
+ return _resource.getName();
+ }
+
+ protected boolean isWritable() {
+ return _writable;
+ }
+
+ private void checkWritable() {
+ if (!isWritable()) {
+ throw new IllegalStateException(
+ "This CSV DataContext is not writable, as it based on a read-only resource.");
+ }
+ }
+
+ @Override
+ public void executeUpdate(UpdateScript update) {
+ checkWritable();
+ CsvUpdateCallback callback = new CsvUpdateCallback(this);
+ synchronized (WRITE_LOCK) {
+ try {
+ update.run(callback);
+ } finally {
+ callback.close();
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/apache/metamodel/csv/CsvDataSet.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvDataSet.java b/csv/src/main/java/org/apache/metamodel/csv/CsvDataSet.java
new file mode 100644
index 0000000..ae31865
--- /dev/null
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvDataSet.java
@@ -0,0 +1,127 @@
+/**
+ * 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.csv;
+
+import java.io.IOException;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.data.AbstractDataSet;
+import org.eobjects.metamodel.data.DefaultRow;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.util.FileHelper;
+
+import au.com.bytecode.opencsv.CSVReader;
+
+/**
+ * Streaming DataSet implementation for CSV support
+ *
+ * @author Kasper Sørensen
+ */
+final class CsvDataSet extends AbstractDataSet {
+
+ private final CSVReader _reader;
+ private final boolean _failOnInconsistentRowLength;
+ private final int _columnsInTable;
+ private volatile int _rowNumber;
+ private volatile Integer _rowsRemaining;
+ private volatile Row _row;
+
+ public CsvDataSet(CSVReader reader, Column[] columns, Integer maxRows,
+ int columnsInTable, boolean failOnInconsistentRowLength) {
+ super(columns);
+ _reader = reader;
+ _columnsInTable = columnsInTable;
+ _failOnInconsistentRowLength = failOnInconsistentRowLength;
+ _rowNumber = 0;
+ _rowsRemaining = maxRows;
+ }
+
+ @Override
+ public void close() {
+ FileHelper.safeClose(_reader);
+ _row = null;
+ _rowsRemaining = null;
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ // close is always safe to invoke
+ close();
+ }
+
+ @Override
+ public Row getRow() throws MetaModelException {
+ return _row;
+ }
+
+ @Override
+ public boolean next() {
+ if (_rowsRemaining != null && _rowsRemaining > 0) {
+ _rowsRemaining--;
+ return nextInternal();
+ } else if (_rowsRemaining == null) {
+ return nextInternal();
+ } else {
+ return false;
+ }
+ }
+
+ private boolean nextInternal() {
+ if (_reader == null) {
+ return false;
+ }
+ final String[] csvValues;
+ try {
+ csvValues = _reader.readNext();
+ } catch (IOException e) {
+ throw new IllegalStateException("Exception reading from file", e);
+ }
+ if (csvValues == null) {
+ close();
+ return false;
+ }
+
+ final int size = getHeader().size();
+ final Object[] rowValues = new Object[size];
+ for (int i = 0; i < size; i++) {
+ Column column = getHeader().getSelectItem(i).getColumn();
+ int columnNumber = column.getColumnNumber();
+ if (columnNumber < csvValues.length) {
+ rowValues[i] = csvValues[columnNumber];
+ } else {
+ // Ticket #125: Missing values should be enterpreted as
+ // null.
+ rowValues[i] = null;
+ }
+ }
+ _row = new DefaultRow(getHeader(), rowValues);
+
+ if (_failOnInconsistentRowLength) {
+ _rowNumber++;
+ if (_columnsInTable != csvValues.length) {
+ throw new InconsistentRowLengthException(_columnsInTable, _row,
+ csvValues, _rowNumber);
+ }
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/apache/metamodel/csv/CsvDeleteBuilder.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvDeleteBuilder.java b/csv/src/main/java/org/apache/metamodel/csv/CsvDeleteBuilder.java
new file mode 100644
index 0000000..52c18e0
--- /dev/null
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvDeleteBuilder.java
@@ -0,0 +1,103 @@
+/**
+ * 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.csv;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.delete.AbstractRowDeletionBuilder;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.Action;
+import org.eobjects.metamodel.util.FileHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class CsvDeleteBuilder extends AbstractRowDeletionBuilder {
+
+ private static final Logger logger = LoggerFactory.getLogger(CsvDeleteBuilder.class);
+
+ private final CsvUpdateCallback _updateCallback;
+
+ public CsvDeleteBuilder(CsvUpdateCallback updateCallback, Table table) {
+ super(table);
+ _updateCallback = updateCallback;
+ }
+
+ @Override
+ public void execute() throws MetaModelException {
+ final File tempFile = FileHelper.createTempFile("metamodel_deletion", "csv");
+
+ final CsvConfiguration configuration = _updateCallback.getConfiguration();
+
+ final CsvDataContext copyDataContext = new CsvDataContext(tempFile, configuration);
+ copyDataContext.executeUpdate(new UpdateScript() {
+
+ @Override
+ public void run(UpdateCallback callback) {
+ final Table originalTable = getTable();
+ final Table copyTable = callback.createTable(copyDataContext.getDefaultSchema(), originalTable.getName())
+ .like(originalTable).execute();
+
+ if (isTruncateTableOperation()) {
+ // no need to iterate old records, they should all be
+ // removed
+ return;
+ }
+
+ final DataSet dataSet = _updateCallback.getDataContext().query().from(originalTable)
+ .select(originalTable.getColumns()).execute();
+ try {
+ while (dataSet.next()) {
+ final Row row = dataSet.getRow();
+ if (!deleteRow(row)) {
+ callback.insertInto(copyTable).like(row).execute();
+ }
+ }
+ } finally {
+ dataSet.close();
+ }
+ }
+ });
+
+ // copy the copy (which does not have deleted records) to overwrite the
+ // original
+ final InputStream in = FileHelper.getInputStream(tempFile);
+ try {
+ _updateCallback.getResource().write(new Action<OutputStream>() {
+ @Override
+ public void run(OutputStream out) throws Exception {
+ FileHelper.copy(in, out);
+ }
+ });
+ } finally {
+ FileHelper.safeClose(in);
+ }
+
+ final boolean deleted = tempFile.delete();
+ if (!deleted) {
+ logger.warn("Could not delete temporary copy-file: {}", tempFile);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/apache/metamodel/csv/CsvInsertBuilder.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvInsertBuilder.java b/csv/src/main/java/org/apache/metamodel/csv/CsvInsertBuilder.java
new file mode 100644
index 0000000..718de8e
--- /dev/null
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvInsertBuilder.java
@@ -0,0 +1,40 @@
+/**
+ * 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.csv;
+
+import org.eobjects.metamodel.insert.AbstractRowInsertionBuilder;
+import org.eobjects.metamodel.schema.Table;
+
+final class CsvInsertBuilder extends AbstractRowInsertionBuilder<CsvUpdateCallback> {
+
+ public CsvInsertBuilder(CsvUpdateCallback updateCallback, Table table) {
+ super(updateCallback, table);
+ }
+
+ @Override
+ public void execute() {
+ Object[] values = getValues();
+ String[] stringValues = new String[values.length];
+ for (int i = 0; i < stringValues.length; i++) {
+ stringValues[i] = values[i] == null ? "" : values[i].toString();
+ }
+ getUpdateCallback().writeRow(stringValues, true);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/apache/metamodel/csv/CsvSchema.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvSchema.java b/csv/src/main/java/org/apache/metamodel/csv/CsvSchema.java
new file mode 100644
index 0000000..c6d2ba9
--- /dev/null
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvSchema.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.csv;
+
+import org.eobjects.metamodel.schema.AbstractSchema;
+import org.eobjects.metamodel.schema.Table;
+
+final class CsvSchema extends AbstractSchema {
+
+ private static final long serialVersionUID = 1L;
+
+ private final String _name;
+ private final transient CsvDataContext _dataContext;
+ private CsvTable _table;
+
+ public CsvSchema(String name, CsvDataContext dataContext) {
+ super();
+ _name = name;
+ _dataContext = dataContext;
+ }
+
+ protected void setTable(CsvTable table) {
+ _table = table;
+ }
+
+ @Override
+ public String getName() {
+ return _name;
+ }
+
+ protected CsvDataContext getDataContext() {
+ return _dataContext;
+ }
+
+ @Override
+ public String getQuote() {
+ return null;
+ }
+
+ @Override
+ public Table[] getTables() {
+ if (_table == null) {
+ return new Table[0];
+ }
+ return new Table[] { _table };
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/apache/metamodel/csv/CsvTable.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvTable.java b/csv/src/main/java/org/apache/metamodel/csv/CsvTable.java
new file mode 100644
index 0000000..eb9bdc0
--- /dev/null
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvTable.java
@@ -0,0 +1,149 @@
+/**
+ * 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.csv;
+
+import java.io.IOException;
+
+import org.eobjects.metamodel.schema.AbstractTable;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.schema.Relationship;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.TableType;
+import org.eobjects.metamodel.util.AlphabeticSequence;
+import org.eobjects.metamodel.util.FileHelper;
+
+import au.com.bytecode.opencsv.CSVReader;
+
+final class CsvTable extends AbstractTable {
+
+ private static final long serialVersionUID = 1L;
+
+ private final CsvSchema _schema;
+ private Column[] _columns;
+
+ /**
+ * Constructor for creating a new CSV table which has not yet been written.
+ *
+ * @param schema
+ * @param columnNames
+ */
+ public CsvTable(CsvSchema schema, String[] columnNames) {
+ this(schema);
+ _columns = buildColumns(columnNames);
+ }
+
+ /**
+ * Constructor for reading an existing CSV table.
+ *
+ * @param schema
+ */
+ public CsvTable(CsvSchema schema) {
+ _schema = schema;
+ }
+
+ @Override
+ public String getName() {
+ String schemaName = _schema.getName();
+ return schemaName.substring(0, schemaName.length() - 4);
+ }
+
+ @Override
+ public Column[] getColumns() {
+ if (_columns == null) {
+ synchronized (this) {
+ if (_columns == null) {
+ _columns = buildColumns();
+ }
+ }
+ }
+ return _columns;
+ }
+
+ private Column[] buildColumns() {
+ CSVReader reader = null;
+ try {
+ reader = _schema.getDataContext().createCsvReader(0);
+
+ final int columnNameLineNumber = _schema.getDataContext().getConfiguration().getColumnNameLineNumber();
+ for (int i = 1; i < columnNameLineNumber; i++) {
+ reader.readNext();
+ }
+ final String[] columnHeaders = reader.readNext();
+
+ reader.close();
+ return buildColumns(columnHeaders);
+ } catch (IOException e) {
+ throw new IllegalStateException("Exception reading from resource: " + _schema.getDataContext().getResource().getName(), e);
+ } finally {
+ FileHelper.safeClose(reader);
+ }
+ }
+
+ private Column[] buildColumns(final String[] columnNames) {
+ if (columnNames == null) {
+ return new Column[0];
+ }
+
+ final CsvConfiguration configuration = _schema.getDataContext().getConfiguration();
+ final int columnNameLineNumber = configuration.getColumnNameLineNumber();
+ final boolean nullable = !configuration.isFailOnInconsistentRowLength();
+
+ final Column[] columns = new Column[columnNames.length];
+ final AlphabeticSequence sequence = new AlphabeticSequence();
+ for (int i = 0; i < columnNames.length; i++) {
+ final String columnName;
+ if (columnNameLineNumber == CsvConfiguration.NO_COLUMN_NAME_LINE) {
+ columnName = sequence.next();
+ } else {
+ columnName = columnNames[i];
+ }
+ Column column = new MutableColumn(columnName, ColumnType.VARCHAR, this, i, null, null, nullable, null,
+ false, null);
+ columns[i] = column;
+ }
+ return columns;
+ }
+
+ @Override
+ public Schema getSchema() {
+ return _schema;
+ }
+
+ @Override
+ public TableType getType() {
+ return TableType.TABLE;
+ }
+
+ @Override
+ public Relationship[] getRelationships() {
+ return new Relationship[0];
+ }
+
+ @Override
+ public String getRemarks() {
+ return null;
+ }
+
+ @Override
+ public String getQuote() {
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/apache/metamodel/csv/CsvTableDropBuilder.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvTableDropBuilder.java b/csv/src/main/java/org/apache/metamodel/csv/CsvTableDropBuilder.java
new file mode 100644
index 0000000..0685fb4
--- /dev/null
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvTableDropBuilder.java
@@ -0,0 +1,38 @@
+/**
+ * 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.csv;
+
+import org.eobjects.metamodel.drop.AbstractTableDropBuilder;
+import org.eobjects.metamodel.schema.Table;
+
+final class CsvTableDropBuilder extends AbstractTableDropBuilder {
+
+ private final CsvUpdateCallback _updateCallback;
+
+ public CsvTableDropBuilder(CsvUpdateCallback updateCallback, Table table) {
+ super(table);
+ _updateCallback = updateCallback;
+ }
+
+ @Override
+ public void execute() {
+ _updateCallback.dropTable();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/apache/metamodel/csv/CsvUpdateCallback.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvUpdateCallback.java b/csv/src/main/java/org/apache/metamodel/csv/CsvUpdateCallback.java
new file mode 100644
index 0000000..72e276c
--- /dev/null
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvUpdateCallback.java
@@ -0,0 +1,249 @@
+/**
+ * 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.csv;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.RandomAccessFile;
+import java.io.Writer;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+import java.nio.charset.Charset;
+
+import org.eobjects.metamodel.AbstractUpdateCallback;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.create.TableCreationBuilder;
+import org.eobjects.metamodel.delete.RowDeletionBuilder;
+import org.eobjects.metamodel.drop.TableDropBuilder;
+import org.eobjects.metamodel.insert.RowInsertionBuilder;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.update.RowUpdationBuilder;
+import org.eobjects.metamodel.util.Action;
+import org.eobjects.metamodel.util.EqualsBuilder;
+import org.eobjects.metamodel.util.FileHelper;
+import org.eobjects.metamodel.util.FileResource;
+import org.eobjects.metamodel.util.Resource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class CsvUpdateCallback extends AbstractUpdateCallback implements UpdateCallback {
+
+ private static final Logger logger = LoggerFactory.getLogger(CsvUpdateCallback.class);
+
+ private final CsvConfiguration _configuration;
+ private final Resource _resource;
+ private Writer _writer;
+
+ public CsvUpdateCallback(CsvDataContext dataContext) {
+ super(dataContext);
+ _resource = dataContext.getResource();
+ _configuration = dataContext.getConfiguration();
+ }
+
+ @Override
+ public TableCreationBuilder createTable(Schema schema, String name) throws IllegalArgumentException, IllegalStateException {
+ return new CsvCreateTableBuilder(this, schema, name);
+ }
+
+ @Override
+ public RowInsertionBuilder insertInto(Table table) throws IllegalArgumentException, IllegalStateException {
+ validateTable(table);
+ return new CsvInsertBuilder(this, table);
+ }
+
+ public CsvConfiguration getConfiguration() {
+ return _configuration;
+ }
+
+ public Resource getResource() {
+ return _resource;
+ }
+
+ private void validateTable(Table table) {
+ if (!(table instanceof CsvTable)) {
+ throw new IllegalArgumentException("Not a valid CSV table: " + table);
+ }
+ }
+
+ protected synchronized void writeRow(final String[] stringValues, final boolean append) {
+ final CsvWriter _csvWriter = new CsvWriter(_configuration);
+ final String line = _csvWriter.buildLine(stringValues);
+ if (_resource instanceof FileResource) {
+ // optimized handling for file-based resources
+ final File file = ((FileResource) _resource).getFile();
+ final Writer writer = getFileWriter(file, append);
+ try {
+ writer.write(line);
+ } catch (IOException e) {
+ throw new MetaModelException("Failed to write line to file: " + line, e);
+ }
+ } else {
+ // generic handling for any kind of resource
+ final Action<OutputStream> action = new Action<OutputStream>() {
+ @Override
+ public void run(OutputStream out) throws Exception {
+ final String encoding = _configuration.getEncoding();
+ final OutputStreamWriter writer = new OutputStreamWriter(out, encoding);
+ writer.write(line);
+ writer.flush();
+ }
+ };
+ if (append) {
+ _resource.append(action);
+ } else {
+ _resource.write(action);
+ }
+ }
+ }
+
+ private Writer getFileWriter(File file, boolean append) {
+ if (_writer == null || !append) {
+ final boolean needsLineBreak = needsLineBreak(file, _configuration);
+
+ final Writer writer = FileHelper.getWriter(file, _configuration.getEncoding(), append);
+ if (needsLineBreak) {
+ try {
+ writer.write('\n');
+ } catch (IOException e) {
+ logger.debug("Failed to insert newline", e);
+ }
+ }
+ _writer = writer;
+ }
+ return _writer;
+ }
+
+ protected static boolean needsLineBreak(File file, CsvConfiguration configuration) {
+ if (!file.exists() || file.length() == 0) {
+ return false;
+ }
+
+ try {
+ // find the bytes a newline would match under the encoding
+ final byte[] bytesInLineBreak;
+ {
+ ByteBuffer encodedLineBreak = Charset.forName(configuration.getEncoding()).encode("\n");
+ bytesInLineBreak = new byte[encodedLineBreak.capacity()];
+ encodedLineBreak.get(bytesInLineBreak);
+ }
+
+ // find the last bytes of the file
+ final byte[] bytesFromFile = new byte[bytesInLineBreak.length];
+ {
+ final RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");
+ try {
+ FileChannel channel = randomAccessFile.getChannel();
+ try {
+ long length = randomAccessFile.length();
+
+ channel = channel.position(length - bytesInLineBreak.length);
+ channel.read(ByteBuffer.wrap(bytesFromFile));
+ } finally {
+ channel.close();
+ }
+ } finally {
+ randomAccessFile.close();
+ }
+ }
+
+ // if the two byte arrays match, then the newline is not needed.
+ if (EqualsBuilder.equals(bytesInLineBreak, bytesFromFile)) {
+ return false;
+ }
+ return true;
+ } catch (Exception e) {
+ logger.error("Error occurred while checking if file needs linebreak, omitting check", e);
+ }
+ return false;
+ }
+
+ /**
+ * Closes all open handles
+ */
+ protected void close() {
+ if (_writer != null) {
+ try {
+ _writer.flush();
+ } catch (IOException e) {
+ logger.warn("Failed to flush CSV writer", e);
+ }
+ try {
+ _writer.close();
+ } catch (IOException e) {
+ logger.error("Failed to close CSV writer", e);
+ } finally {
+ _writer = null;
+ }
+ }
+ }
+
+ @Override
+ public RowUpdationBuilder update(Table table) throws IllegalArgumentException, IllegalStateException {
+ close();
+ return super.update(table);
+ }
+
+ @Override
+ public boolean isDropTableSupported() {
+ return true;
+ }
+
+ @Override
+ public TableDropBuilder dropTable(Table table) {
+ validateTable(table);
+ return new CsvTableDropBuilder(this, table);
+ }
+
+ /**
+ * Callback method used by {@link CsvTableDropBuilder} when execute is
+ * called
+ */
+ protected void dropTable() {
+ close();
+ if (_resource instanceof FileResource) {
+ final File file = ((FileResource) _resource).getFile();
+ final boolean success = file.delete();
+ if (!success) {
+ throw new MetaModelException("Could not delete (drop) file: " + file);
+ }
+ } else {
+ _resource.write(new Action<OutputStream>() {
+ @Override
+ public void run(OutputStream arg) throws Exception {
+ // do nothing, just write an empty file
+ }
+ });
+ }
+ }
+
+ @Override
+ public boolean isDeleteSupported() {
+ return true;
+ }
+
+ @Override
+ public RowDeletionBuilder deleteFrom(Table table) {
+ validateTable(table);
+ return new CsvDeleteBuilder(this, table);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/apache/metamodel/csv/CsvWriter.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvWriter.java b/csv/src/main/java/org/apache/metamodel/csv/CsvWriter.java
new file mode 100644
index 0000000..7b35847
--- /dev/null
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvWriter.java
@@ -0,0 +1,94 @@
+/**
+ * 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.csv;
+
+import org.eobjects.metamodel.util.Resource;
+
+/**
+ * This class is an adaptation of the CSVWriter class of OpenCSV. We've made the
+ * writer work without having the output stream as state (suiting for
+ * {@link Resource} usage).
+ */
+public final class CsvWriter {
+
+ public static final int INITIAL_STRING_SIZE = 128;
+
+ private final CsvConfiguration _configuration;
+
+ public CsvWriter(CsvConfiguration configuration) {
+ _configuration = configuration;
+ }
+
+ /**
+ * Builds a line for the CSV file output
+ *
+ * @param nextLine
+ * a string array with each comma-separated element as a separate
+ * entry.
+ */
+ public String buildLine(String[] nextLine) {
+ final StringBuilder sb = new StringBuilder(INITIAL_STRING_SIZE);
+ for (int i = 0; i < nextLine.length; i++) {
+
+ if (i != 0) {
+ sb.append(_configuration.getSeparatorChar());
+ }
+
+ final String nextElement = nextLine[i];
+ if (nextElement == null) {
+ continue;
+ }
+ final char quoteChar = _configuration.getQuoteChar();
+ if (quoteChar != CsvConfiguration.NOT_A_CHAR) {
+ sb.append(quoteChar);
+ }
+
+ sb.append(stringContainsSpecialCharacters(nextElement) ? processLine(nextElement) : nextElement);
+
+ if (quoteChar != CsvConfiguration.NOT_A_CHAR) {
+ sb.append(quoteChar);
+ }
+ }
+
+ sb.append('\n');
+ return sb.toString();
+
+ }
+
+ private boolean stringContainsSpecialCharacters(String line) {
+ return line.indexOf(_configuration.getQuoteChar()) != -1 || line.indexOf(_configuration.getEscapeChar()) != -1;
+ }
+
+ private StringBuilder processLine(String nextElement) {
+ final StringBuilder sb = new StringBuilder(INITIAL_STRING_SIZE);
+ for (int j = 0; j < nextElement.length(); j++) {
+ final char nextChar = nextElement.charAt(j);
+ final char escapeChar = _configuration.getEscapeChar();
+ if (escapeChar != CsvConfiguration.NOT_A_CHAR && nextChar == _configuration.getQuoteChar()) {
+ sb.append(escapeChar).append(nextChar);
+ } else if (escapeChar != CsvConfiguration.NOT_A_CHAR && nextChar == escapeChar) {
+ sb.append(escapeChar).append(nextChar);
+ } else {
+ sb.append(nextChar);
+ }
+ }
+
+ return sb;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/apache/metamodel/csv/InconsistentRowLengthException.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/InconsistentRowLengthException.java b/csv/src/main/java/org/apache/metamodel/csv/InconsistentRowLengthException.java
new file mode 100644
index 0000000..60c093f
--- /dev/null
+++ b/csv/src/main/java/org/apache/metamodel/csv/InconsistentRowLengthException.java
@@ -0,0 +1,101 @@
+/**
+ * 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.csv;
+
+import org.eobjects.metamodel.InconsistentRowFormatException;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.Row;
+
+/**
+ * Exception thrown when a line in a CSV file has an inconsistent amount of
+ * columns compared to the previous lines (and headers). The exception will be
+ * thrown when {@link DataSet#next()} is called.
+ *
+ * Note that this exception is only thrown if the
+ * {@link CsvConfiguration#isFailOnInconsistentRowLength()} property is true.
+ * Enabling it allows a somewhat different approach to iterating through a
+ * resulting DataSet. For example something like:
+ *
+ * <pre>
+ * while (true) {
+ * try {
+ * if (!dataSet.next) {
+ * break;
+ * }
+ * Row row = dataSet.getRow();
+ * handleRegularRow(row);
+ * } catch (InconsistentRowLengthException e) {
+ * handleIrregularRow(e.getSourceLine());
+ * }
+ * }
+ * </pre>
+ *
+ * @author Kasper Sørensen
+ */
+public final class InconsistentRowLengthException extends
+ InconsistentRowFormatException {
+
+ private static final long serialVersionUID = 1L;
+
+ private final int _columnsInTable;
+ private final String[] _line;
+
+ public InconsistentRowLengthException(int columnsInTable, Row proposedRow,
+ String[] line, int rowNumber) {
+ super(proposedRow, rowNumber);
+ _columnsInTable = columnsInTable;
+ _line = line;
+ }
+
+ @Override
+ public String getMessage() {
+ return "Inconsistent length of row no. " + getRowNumber()
+ + ". Expected " + getColumnsInTable() + " columns but found "
+ + getColumnsInLine() + ".";
+ }
+
+ /**
+ * Gets the source line, as parsed by the CSV parser (regardless of table
+ * metadata).
+ *
+ * @return an array of string values.
+ */
+ public String[] getSourceLine() {
+ return _line;
+ }
+
+ /**
+ * Gets the amount of columns in the parsed line.
+ *
+ * @return an int representing the amount of values in the inconsistent
+ * line.
+ */
+ public int getColumnsInLine() {
+ return _line.length;
+ }
+
+ /**
+ * Gets the expected amounts of columns, as defined by the table metadata.
+ *
+ * @return an int representing the amount of columns defined in the table.
+ */
+ public int getColumnsInTable() {
+ return _columnsInTable;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/apache/metamodel/csv/package-info.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/package-info.java b/csv/src/main/java/org/apache/metamodel/csv/package-info.java
new file mode 100644
index 0000000..241c74e
--- /dev/null
+++ b/csv/src/main/java/org/apache/metamodel/csv/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.
+ */
+/**
+ * Module package for Comma Separated Values (CSV) files
+ */
+package org.eobjects.metamodel.csv;
+
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/eobjects/metamodel/csv/CsvConfiguration.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/eobjects/metamodel/csv/CsvConfiguration.java b/csv/src/main/java/org/eobjects/metamodel/csv/CsvConfiguration.java
deleted file mode 100644
index c67615b..0000000
--- a/csv/src/main/java/org/eobjects/metamodel/csv/CsvConfiguration.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/**
- * 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.csv;
-
-import java.io.Serializable;
-import java.util.List;
-
-import org.eobjects.metamodel.util.BaseObject;
-import org.eobjects.metamodel.util.FileHelper;
-
-/**
- * Represents the configuration for reading/parsing CSV files.
- *
- * @author Kasper Sørensen
- */
-public final class CsvConfiguration extends BaseObject implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * The value is '\\uFFFF', the "not a character" value which should not
- * occur in any valid Unicode string. This special char can be used to
- * disable either quote chars or escape chars.
- */
- public static final char NOT_A_CHAR = '\uFFFF';
- public static final int NO_COLUMN_NAME_LINE = 0;
- public static final int DEFAULT_COLUMN_NAME_LINE = 1;
- public static final char DEFAULT_SEPARATOR_CHAR = ',';
- public static final char DEFAULT_QUOTE_CHAR = '"';
- public static final char DEFAULT_ESCAPE_CHAR = '\\';
-
- private final int columnNameLineNumber;
- private final String encoding;
- private final char separatorChar;
- private final char quoteChar;
- private final char escapeChar;
- private final boolean failOnInconsistentRowLength;
-
- public CsvConfiguration() {
- this(DEFAULT_COLUMN_NAME_LINE);
- }
-
- public CsvConfiguration(int columnNameLineNumber) {
- this(columnNameLineNumber, FileHelper.DEFAULT_ENCODING,
- DEFAULT_SEPARATOR_CHAR, DEFAULT_QUOTE_CHAR, DEFAULT_ESCAPE_CHAR);
- }
-
- public CsvConfiguration(int columnNameLineNumber, String encoding,
- char separatorChar, char quoteChar, char escapeChar) {
- this(columnNameLineNumber, encoding, separatorChar, quoteChar,
- escapeChar, false);
- }
-
- public CsvConfiguration(int columnNameLineNumber, String encoding,
- char separatorChar, char quoteChar, char escapeChar,
- boolean failOnInconsistentRowLength) {
- this.columnNameLineNumber = columnNameLineNumber;
- this.encoding = encoding;
- this.separatorChar = separatorChar;
- this.quoteChar = quoteChar;
- this.escapeChar = escapeChar;
- this.failOnInconsistentRowLength = failOnInconsistentRowLength;
- }
-
- /**
- * Determines whether to fail (by throwing an
- * {@link InconsistentRowLengthException}) if a line in the CSV file has
- * inconsistent amounts of columns.
- *
- * If set to false (default) MetaModel will gracefully fill in missing null
- * values in or ignore additional values in a line.
- *
- * @return a boolean indicating whether to fail or gracefully compensate for
- * inconsistent lines in the CSV files.
- */
- public boolean isFailOnInconsistentRowLength() {
- return failOnInconsistentRowLength;
- }
-
- /**
- * The line number (1 based) from which to get the names of the columns.
- *
- * @return the line number (1 based)
- */
- public int getColumnNameLineNumber() {
- return columnNameLineNumber;
- }
-
- /**
- * Gets the file encoding to use for reading the file.
- *
- * @return the text encoding of the file.
- */
- public String getEncoding() {
- return encoding;
- }
-
- /**
- * Gets the separator char (typically comma or semicolon) for separating
- * values.
- *
- * @return the separator char
- */
- public char getSeparatorChar() {
- return separatorChar;
- }
-
- /**
- * Gets the quote char, used for encapsulating values.
- *
- * @return the quote char
- */
- public char getQuoteChar() {
- return quoteChar;
- }
-
- /**
- * Gets the escape char, used for escaping eg. quote chars inside values.
- *
- * @return the escape char
- */
- public char getEscapeChar() {
- return escapeChar;
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- identifiers.add(columnNameLineNumber);
- identifiers.add(encoding);
- identifiers.add(separatorChar);
- identifiers.add(quoteChar);
- identifiers.add(escapeChar);
- identifiers.add(failOnInconsistentRowLength);
- }
-
- @Override
- public String toString() {
- return "CsvConfiguration[columnNameLineNumber=" + columnNameLineNumber
- + ", encoding=" + encoding + ", separatorChar=" + separatorChar
- + ", quoteChar=" + quoteChar + ", escapeChar=" + escapeChar
- + ", failOnInconsistentRowLength="
- + failOnInconsistentRowLength + "]";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/main/java/org/eobjects/metamodel/csv/CsvCreateTableBuilder.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/eobjects/metamodel/csv/CsvCreateTableBuilder.java b/csv/src/main/java/org/eobjects/metamodel/csv/CsvCreateTableBuilder.java
deleted file mode 100644
index 30e0a54..0000000
--- a/csv/src/main/java/org/eobjects/metamodel/csv/CsvCreateTableBuilder.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * 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.csv;
-
-import org.eobjects.metamodel.create.AbstractTableCreationBuilder;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-final class CsvCreateTableBuilder extends
- AbstractTableCreationBuilder<CsvUpdateCallback> {
-
- public CsvCreateTableBuilder(CsvUpdateCallback updateCallback,
- Schema schema, String name) {
- super(updateCallback, schema, name);
- if (!(schema instanceof CsvSchema)) {
- throw new IllegalArgumentException("Not a valid CSV schema: "
- + schema);
- }
- }
-
- @Override
- public Table execute() {
- CsvUpdateCallback csvUpdateCallback = getUpdateCallback();
-
- MutableTable table = getTable();
- String[] columnNames = table.getColumnNames();
- csvUpdateCallback.writeRow(columnNames, false);
-
- CsvSchema schema = (CsvSchema) table.getSchema();
- CsvTable csvTable = new CsvTable(schema, table.getColumnNames());
- schema.setTable(csvTable);
- return csvTable;
- }
-}
[20/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/query/GroupByItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/GroupByItemTest.java b/core/src/test/java/org/eobjects/metamodel/query/GroupByItemTest.java
deleted file mode 100644
index f21d650..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/GroupByItemTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * 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.query;
-
-import junit.framework.TestCase;
-
-public class GroupByItemTest extends TestCase {
-
- public void testSimpleGroupBy() throws Exception {
- SelectItem selectItem = new SelectItem("foo", "bar");
- GroupByItem item = new GroupByItem(selectItem);
- assertEquals("bar", item.toString());
- }
-
- public void testGroupByClause() throws Exception {
- GroupByClause clause = new GroupByClause(new Query());
- SelectItem selectItem = new SelectItem("foo", "foo");
- GroupByItem item = new GroupByItem(selectItem);
- clause.addItems(item);
- selectItem = new SelectItem("bar", "bar");
- item = new GroupByItem(selectItem);
- clause.addItems(item);
-
- assertEquals(" GROUP BY foo, bar", clause.toString());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/query/OperatorTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/OperatorTypeTest.java b/core/src/test/java/org/eobjects/metamodel/query/OperatorTypeTest.java
deleted file mode 100644
index 2efee46..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/OperatorTypeTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * 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.query;
-
-import junit.framework.TestCase;
-
-public class OperatorTypeTest extends TestCase {
-
- public void testConvertOperatorType() throws Exception {
- assertEquals(OperatorType.EQUALS_TO, OperatorType.convertOperatorType("="));
- assertEquals(OperatorType.GREATER_THAN, OperatorType.convertOperatorType(">"));
- assertEquals(OperatorType.LESS_THAN, OperatorType.convertOperatorType("<"));
- assertEquals(OperatorType.DIFFERENT_FROM, OperatorType.convertOperatorType("<>"));
- assertEquals(OperatorType.LIKE, OperatorType.convertOperatorType("LIKE"));
- assertEquals(OperatorType.IN, OperatorType.convertOperatorType("IN"));
- assertEquals(null, OperatorType.convertOperatorType("foo"));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/query/OrderByItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/OrderByItemTest.java b/core/src/test/java/org/eobjects/metamodel/query/OrderByItemTest.java
deleted file mode 100644
index 7433177..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/OrderByItemTest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * 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.query;
-
-import org.eobjects.metamodel.query.OrderByItem.Direction;
-import junit.framework.TestCase;
-
-public class OrderByItemTest extends TestCase {
-
- public void testSimpleOrderBy() throws Exception {
- SelectItem selectItem = new SelectItem("foo", "foo");
- OrderByItem item = new OrderByItem(selectItem, Direction.DESC);
- assertEquals("foo DESC", item.toString());
- item = new OrderByItem(selectItem, Direction.ASC);
- assertEquals("foo ASC", item.toString());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/query/QueryTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/QueryTest.java b/core/src/test/java/org/eobjects/metamodel/query/QueryTest.java
deleted file mode 100644
index 92e43e5..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/QueryTest.java
+++ /dev/null
@@ -1,245 +0,0 @@
-/**
- * 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.query;
-
-import org.eobjects.metamodel.MetaModelTestCase;
-import org.eobjects.metamodel.query.OrderByItem.Direction;
-import org.eobjects.metamodel.query.builder.InitFromBuilderImpl;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-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.Table;
-import org.eobjects.metamodel.schema.TableType;
-
-public class QueryTest extends MetaModelTestCase {
-
- private Schema _schema = getExampleSchema();
-
- public void testSimpleQuery() throws Exception {
- Table contributorTable = _schema.getTableByName(TABLE_CONTRIBUTOR);
-
- Query q = new Query();
- q.selectCount().from(contributorTable);
- assertEquals("SELECT COUNT(*) FROM MetaModelSchema.contributor", q.toString());
- }
-
- public void testCloneGroupBy() throws Exception {
- Table table = _schema.getTableByName(TABLE_PROJECT);
- Column column = table.getColumnByName(COLUMN_PROJECT_NAME);
- Query q = new Query().from(table).selectCount().select(column).groupBy(column);
- assertEquals(q.toString(), q.clone().toString());
-
- q.having(new FilterItem(SelectItem.getCountAllItem(), OperatorType.GREATER_THAN, 20));
- assertEquals(q.toString(), q.clone().toString());
- }
-
- public void testFromItemAlias() throws Exception {
- Query q = new Query();
- Table contributorTable = _schema.getTableByName(TABLE_CONTRIBUTOR);
- Column nameColumn = contributorTable.getColumnByName(COLUMN_CONTRIBUTOR_NAME);
- Column countryColumn = contributorTable.getColumnByName(COLUMN_CONTRIBUTOR_COUNTRY);
-
- FromItem fromContributor = new FromItem(contributorTable);
- q.from(fromContributor);
- q.select(nameColumn, countryColumn);
- assertEquals("SELECT contributor.name, contributor.country FROM MetaModelSchema.contributor", q.toString());
-
- fromContributor.setAlias("c");
-
- assertEquals("SELECT c.name, c.country FROM MetaModelSchema.contributor c", q.toString());
-
- q.groupBy(new GroupByItem(q.getSelectClause().getSelectItem(nameColumn)));
- q.groupBy(new GroupByItem(q.getSelectClause().getSelectItem(countryColumn)));
- q.select(new SelectItem(FunctionType.COUNT, "*", "total"));
- assertEquals(2, q.getGroupByClause().getItems().size());
- assertEquals(
- "SELECT c.name, c.country, COUNT(*) AS total FROM MetaModelSchema.contributor c GROUP BY c.name, c.country",
- q.toString());
-
- Column contributorIdColumn = contributorTable.getColumnByName(COLUMN_CONTRIBUTOR_CONTRIBUTOR_ID);
- q.where(contributorIdColumn, OperatorType.EQUALS_TO, 1);
- assertEquals(
- "SELECT c.name, c.country, COUNT(*) AS total FROM MetaModelSchema.contributor c WHERE c.contributor_id = 1 GROUP BY c.name, c.country",
- q.toString());
-
- q.where(contributorIdColumn, OperatorType.DIFFERENT_FROM, q.getSelectClause().getSelectItem(nameColumn));
- assertEquals(
- "SELECT c.name, c.country, COUNT(*) AS total FROM MetaModelSchema.contributor c WHERE c.contributor_id = 1 AND c.contributor_id <> c.name GROUP BY c.name, c.country",
- q.toString());
- }
-
- public void testAddOrderBy() throws Exception {
- Table contributorTable = _schema.getTableByName(TABLE_CONTRIBUTOR);
- Column nameColumn = contributorTable.getColumnByName(COLUMN_CONTRIBUTOR_NAME);
- Column countryColumn = contributorTable.getColumnByName(COLUMN_CONTRIBUTOR_COUNTRY);
- FromItem fromContributor = new FromItem(contributorTable);
- fromContributor.setAlias("a");
-
- Query q = new Query();
- q.select(nameColumn, countryColumn).from(fromContributor).orderBy(nameColumn)
- .orderBy(countryColumn, Direction.DESC);
- assertEquals(2, q.getOrderByClause().getItems().size());
- assertEquals("SELECT a.name, a.country FROM MetaModelSchema.contributor a ORDER BY a.name ASC, a.country DESC",
- q.toString());
- }
-
- public void testCloneJoinAndOrderBy() throws Exception {
- Query q1 = new Query();
- Table contributorTable = _schema.getTableByName(TABLE_CONTRIBUTOR);
- Table roleTable = _schema.getTableByName(TABLE_ROLE);
- FromItem fromItem = new FromItem(JoinType.INNER, contributorTable.getRelationships(roleTable)[0]);
- q1.from(fromItem);
-
- Column nameColumn = contributorTable.getColumnByName(COLUMN_CONTRIBUTOR_NAME);
- Column countryColumn = contributorTable.getColumnByName(COLUMN_CONTRIBUTOR_COUNTRY);
- Column roleNameColumn = roleTable.getColumnByName(COLUMN_ROLE_ROLE_NAME);
- q1.select(nameColumn, countryColumn, roleNameColumn);
- q1.orderBy(roleNameColumn);
- String q1string = q1.toString();
- assertEquals(
- "SELECT contributor.name, contributor.country, role.name FROM MetaModelSchema.contributor INNER JOIN MetaModelSchema.role ON contributor.contributor_id = role.contributor_id ORDER BY role.name ASC",
- q1string);
-
- Query q2 = q1.clone();
- assertEquals(q1string, q2.toString());
-
- q2.getSelectClause().removeItem(1);
- assertEquals(q1string, q1.toString());
- assertEquals(
- "SELECT contributor.name, role.name FROM MetaModelSchema.contributor INNER JOIN MetaModelSchema.role ON contributor.contributor_id = role.contributor_id ORDER BY role.name ASC",
- q2.toString());
-
- FromItem sqFromItem = new FromItem(q2).setAlias("sq");
- SelectItem sqSelectItem = new SelectItem(q2.getSelectClause().getItem(1), sqFromItem).setAlias("foo");
- Query q3 = new Query().from(sqFromItem);
- q3.orderBy(new OrderByItem(sqSelectItem));
- q3.select(sqSelectItem);
- assertEquals(
- "SELECT sq.name AS foo FROM (SELECT contributor.name, role.name FROM MetaModelSchema.contributor INNER JOIN MetaModelSchema.role ON contributor.contributor_id = role.contributor_id ORDER BY role.name ASC) sq ORDER BY foo ASC",
- q3.toString());
- Query q4 = q3.clone();
- assertEquals(
- "SELECT sq.name AS foo FROM (SELECT contributor.name, role.name FROM MetaModelSchema.contributor INNER JOIN MetaModelSchema.role ON contributor.contributor_id = role.contributor_id ORDER BY role.name ASC) sq ORDER BY foo ASC",
- q4.toString());
-
- assertTrue(q3.equals(q4));
- }
-
- public void testDistinctEquals() throws Exception {
- Query q = new Query();
- SelectClause sc1 = new SelectClause(q);
- SelectClause sc2 = new SelectClause(q);
- assertTrue(sc1.equals(sc2));
- sc2.setDistinct(true);
- assertFalse(sc1.equals(sc2));
- sc1.setDistinct(true);
- assertTrue(sc1.equals(sc2));
- }
-
- public void testSetMaxRows() throws Exception {
- assertEquals(1, new Query().setMaxRows(1).getMaxRows().intValue());
- try {
- new Query().setMaxRows(0);
- fail("Exception expected");
- } catch (IllegalArgumentException e) {
- assertEquals("Max rows cannot be zero", e.getMessage());
- }
- try {
- new Query().setMaxRows(-1);
- fail("Exception expected");
- } catch (IllegalArgumentException e) {
- assertEquals("Max rows cannot be negative", e.getMessage());
- }
- }
-
- public void testSetFirstRow() throws Exception {
- assertEquals(2, new Query().setFirstRow(2).getFirstRow().intValue());
- assertEquals(1, new Query().setFirstRow(1).getFirstRow().intValue());
-
- try {
- new Query().setFirstRow(0);
- fail("Exception expected");
- } catch (IllegalArgumentException e) {
- assertEquals("First row cannot be negative or zero", e.getMessage());
- }
-
- try {
- new Query().setFirstRow(-1);
- fail("Exception expected");
- } catch (IllegalArgumentException e) {
- assertEquals("First row cannot be negative or zero", e.getMessage());
- }
- }
-
- public void testEqualsAndHashCode() throws Exception {
- MutableSchema schema = new MutableSchema("schema");
- MutableTable table = new MutableTable("table").setSchema(schema);
- schema.addTable(table);
-
- Column col1 = new MutableColumn("col1").setTable(table);
- Column col2 = new MutableColumn("col2").setTable(table);
- Column col3 = new MutableColumn("col3").setTable(table);
- table.addColumn(col1);
- table.addColumn(col2);
- table.addColumn(col3);
-
- Query q1 = new Query().select(col1, col2).from(table).where(col3, OperatorType.EQUALS_TO, "m'jello");
-
- Query q2 = new InitFromBuilderImpl(null).from(table).select(col1).and(col2).where(col3).eq("m'jello").toQuery();
-
- assertEquals(q1, q2);
- }
-
- public void testHavingClauseReferencingFunctionAndOperand() throws Exception {
- MutableColumn idColumn = new MutableColumn("id", ColumnType.VARCHAR);
- SelectItem countSelectItem = new SelectItem(FunctionType.COUNT, idColumn);
- SelectItem idSelectItem = new SelectItem(idColumn).setAlias("innerIdColumn");
-
- Query q = new Query();
- q.select(idSelectItem);
- q.groupBy(idColumn);
- q.having(new FilterItem(countSelectItem, OperatorType.EQUALS_TO, 2));
-
- assertEquals("SELECT id AS innerIdColumn GROUP BY id HAVING COUNT(id) = 2", q.toSql());
- }
-
- public void testToSqlWithFullyQualifiedColumnNames() throws Exception {
- final MutableSchema schema = new MutableSchema("sch");
- final MutableTable table = new MutableTable("tab", TableType.TABLE, schema);
- final MutableColumn nameColumn = new MutableColumn("name", ColumnType.VARCHAR).setTable(table);
- final MutableColumn ageColumn = new MutableColumn("age", ColumnType.INTEGER).setTable(table);
- schema.addTable(table);
- table.addColumn(nameColumn);
- table.addColumn(ageColumn);
-
- final Query q = new Query();
- q.select(ageColumn).selectCount();
- q.from(table);
- q.where(ageColumn, OperatorType.GREATER_THAN, 18);
- q.groupBy(ageColumn);
- q.having(FunctionType.COUNT, nameColumn, OperatorType.LESS_THAN, 100);
- q.orderBy(ageColumn);
-
- assertEquals("SELECT sch.tab.age, COUNT(*) FROM sch.tab WHERE sch.tab.age > 18 "
- + "GROUP BY sch.tab.age HAVING COUNT(sch.tab.name) < 100 ORDER BY sch.tab.age ASC", q.toSql(true));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/query/SelectClauseTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/SelectClauseTest.java b/core/src/test/java/org/eobjects/metamodel/query/SelectClauseTest.java
deleted file mode 100644
index 2422a9b..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/SelectClauseTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * 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.query;
-
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Table;
-
-import junit.framework.TestCase;
-
-public class SelectClauseTest extends TestCase {
-
- public void testDistinctAddition() throws Exception {
- Table table = new MutableTable("foo");
- Column col = new MutableColumn("bar").setTable(table);
-
- Query q = new Query();
- q.selectDistinct();
- q.from(table);
- q.select(col);
-
- assertEquals("SELECT DISTINCT foo.bar FROM foo", q.toSql());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/query/SelectItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/SelectItemTest.java b/core/src/test/java/org/eobjects/metamodel/query/SelectItemTest.java
deleted file mode 100644
index 5896d9a..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/SelectItemTest.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * 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.query;
-
-import org.eobjects.metamodel.MetaModelTestCase;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-public class SelectItemTest extends MetaModelTestCase {
-
- private Schema _schema = getExampleSchema();
-
- public void testSelectColumnInFromItem() throws Exception {
- final Table projectTable = _schema.getTableByName(TABLE_PROJECT);
- final Column column1 = projectTable.getColumns()[0];
- final Column column2 = projectTable.getColumns()[1];
-
- Query q = new Query().from(projectTable, "a").from(projectTable, "b");
- q.select(column1, q.getFromClause().getItem(1));
- q.select(column2, q.getFromClause().getItem(0));
-
- assertEquals("SELECT b.project_id, a.name FROM MetaModelSchema.project a, MetaModelSchema.project b", q.toSql());
- }
-
- public void testToSql() throws Exception {
- SelectItem selectItem = new SelectItem(_schema.getTableByName(TABLE_PROJECT).getColumns()[0]);
- assertEquals("project.project_id", selectItem.toSql());
- }
-
- public void testSubQuerySelectItem() throws Exception {
- Table projectTable = _schema.getTableByName(TABLE_PROJECT);
- Table roleTable = _schema.getTableByName(TABLE_ROLE);
-
- Column projectIdColumn = projectTable.getColumnByName(COLUMN_PROJECT_PROJECT_ID);
-
- FromItem leftSide = new FromItem(projectTable);
- leftSide.setAlias("a");
- SelectItem[] leftOn = new SelectItem[] { new SelectItem(projectIdColumn) };
-
- Query subQuery = new Query();
- FromItem subQueryFrom = new FromItem(roleTable);
- subQueryFrom.setAlias("c");
- subQuery.from(subQueryFrom);
- Column[] columns = roleTable.getColumns();
- subQuery.select(columns);
-
- SelectItem subQuerySelectItem = subQuery.getSelectClause().getSelectItem(columns[1]);
- FromItem rightSide = new FromItem(subQuery);
- rightSide.setAlias("b");
- SelectItem[] rightOn = new SelectItem[] { subQuerySelectItem };
- FromItem from = new FromItem(JoinType.LEFT, leftSide, rightSide, leftOn, rightOn);
-
- assertEquals(
- "MetaModelSchema.project a LEFT JOIN (SELECT c.contributor_id, c.project_id, c.name FROM MetaModelSchema.role c) b ON a.project_id = b.project_id",
- from.toString());
-
- Query q = new Query();
- q.from(from);
- try {
- new SelectItem(subQuerySelectItem, from);
- fail("Exception should have been thrown!");
- } catch (IllegalArgumentException e) {
- assertEquals("Only sub-query based FromItems allowed.", e.getMessage());
- }
-
- q.select(new SelectItem(subQuerySelectItem, rightSide));
- assertEquals(
- "SELECT b.project_id FROM MetaModelSchema.project a LEFT JOIN (SELECT c.contributor_id, c.project_id, c.name FROM MetaModelSchema.role c) b ON a.project_id = b.project_id",
- q.toString());
- }
-
- public void testGetSuperQueryAlias() throws Exception {
- SelectItem item = new SelectItem(FunctionType.COUNT, "*", "").setAlias(null);
- assertEquals("COUNT(*)", item.getSameQueryAlias());
- assertEquals("COUNT(*)", item.getSuperQueryAlias());
-
- item = new SelectItem(FunctionType.SUM, new MutableColumn("foo"));
- assertEquals("SUM(foo)", item.getSameQueryAlias());
- assertEquals("SUM(foo)", item.getSuperQueryAlias());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/query/builder/GroupedQueryBuilderImplTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/builder/GroupedQueryBuilderImplTest.java b/core/src/test/java/org/eobjects/metamodel/query/builder/GroupedQueryBuilderImplTest.java
deleted file mode 100644
index 4b3b399..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/builder/GroupedQueryBuilderImplTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * 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.query.builder;
-
-import junit.framework.TestCase;
-
-import org.easymock.EasyMock;
-import org.eobjects.metamodel.AbstractDataContext;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-public class GroupedQueryBuilderImplTest extends TestCase {
-
- public void testFindColumnWithAlias() throws Exception {
- DataContext dataContext = EasyMock.createMock(DataContext.class);
-
- MutableTable table1 = new MutableTable("foo");
- table1.addColumn(new MutableColumn("col1").setTable(table1));
- table1.addColumn(new MutableColumn("col2").setTable(table1));
- table1.addColumn(new MutableColumn("col3").setTable(table1));
-
- MutableTable table2 = new MutableTable("bar");
- table2.addColumn(new MutableColumn("col1").setTable(table2));
- table2.addColumn(new MutableColumn("col2").setTable(table2));
- table2.addColumn(new MutableColumn("col3").setTable(table2));
-
- Query query = new Query().from(table1, "f").from(table2, "b");
- GroupedQueryBuilderImpl gqbi = new GroupedQueryBuilderImpl(dataContext,
- query);
-
- Column col = gqbi.findColumn("b.col2");
- assertEquals("bar.col2", col.getQualifiedLabel());
-
- col = gqbi.findColumn("f.col2");
- assertEquals("foo.col2", col.getQualifiedLabel());
-
- try {
- col = gqbi.findColumn("f.col4");
- fail("Exception expected");
- } catch (IllegalArgumentException e) {
- assertEquals("Could not find column: f.col4", e.getMessage());
- }
- }
-
- // test-case to recreate the problems reported at
- // http://eobjects.org/trac/discussion/7/134
- public void testLeftJoinQueries() throws Exception {
- DataContext dc = new AbstractDataContext() {
-
- @Override
- public DataSet executeQuery(Query query) throws MetaModelException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected String[] getSchemaNamesInternal() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected String getDefaultSchemaName() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected Schema getSchemaByNameInternal(String name) {
- throw new UnsupportedOperationException();
- }
- };
- Table tableAB = new MutableTable("tableAB");
- Table tableC = new MutableTable("tableC");
-
- Column colA = new MutableColumn("colA", null, tableAB, 0, true);
- Column colB = new MutableColumn("colB", null, tableAB, 1, true);
- Column colC = new MutableColumn("colC", null, tableC, 0, true);
-
- Query q = dc.query().from(tableAB).leftJoin(tableC).on(colB, colC)
- .select(colA).as("a").select(colB).as("b").select(colC).as("c")
- .toQuery();
-
- assertEquals(
- "SELECT tableAB.colA AS a, tableAB.colB AS b, tableC.colC AS c FROM tableAB LEFT JOIN tableC ON tableAB.colB = tableC.colC",
- q.toSql());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/query/builder/SyntaxExamplesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/builder/SyntaxExamplesTest.java b/core/src/test/java/org/eobjects/metamodel/query/builder/SyntaxExamplesTest.java
deleted file mode 100644
index 0f04584..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/builder/SyntaxExamplesTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * 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.query.builder;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MockDataContext;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Table;
-
-public class SyntaxExamplesTest extends TestCase {
-
- private DataContext dc;
- private Table table1;
- private Table table2;
- private Column col1;
- private Column col2;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- dc = new MockDataContext("sch", "tab1", "foo");
- MutableSchema schema = (MutableSchema) dc.getDefaultSchema();
- table1 = schema.getTables()[0];
- schema.addTable(new MutableTable("tab2").setSchema(schema));
- table2 = schema.getTableByName("tab2");
- col1 = table1.getColumns()[0];
- col2 = table1.getColumns()[1];
- }
-
- public void testSchema() throws Exception {
- assertEquals("tab1", table1.getName());
- assertEquals("sch.tab1", table1.getQualifiedLabel());
- }
-
- public void testFromAlias() throws Exception {
- dc.query().from(table1).as("t");
- }
-
- public void testFromJoin() throws Exception {
- dc.query().from(table1).innerJoin(table2).on(col1, col2).select(col1);
- }
-
- public void testWhereOr() throws Exception {
- dc.query().from(table1).as("t").select(col2).where(col1).isNotNull().or(col1).isNull().orderBy(col1).asc();
- }
-
- public void testGroupBy() throws Exception {
- dc.query().from(table1).selectCount().select(col1).groupBy(col1).having(FunctionType.SUM, col1).greaterThan(3)
- .orderBy(col1).asc();
- }
-
- public void testMultipleTables() throws Exception {
- Query q = dc.query().from(table1).as("t1").and(table2).as("t2").select(col1).where(col1).greaterThan(col2)
- .orderBy(col2).desc().toQuery();
- assertEquals("SELECT t1.foo FROM sch.tab1 t1, sch.tab2 t2 " + "WHERE t1.foo > t1.bar ORDER BY t1.bar DESC",
- q.toSql());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/query/builder/WhereBuilderImplTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/builder/WhereBuilderImplTest.java b/core/src/test/java/org/eobjects/metamodel/query/builder/WhereBuilderImplTest.java
deleted file mode 100644
index 4d45f61..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/builder/WhereBuilderImplTest.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * 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.query.builder;
-
-import java.util.Arrays;
-import java.util.Collection;
-
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-import junit.framework.TestCase;
-
-public class WhereBuilderImplTest extends TestCase {
-
- private MutableColumn col1 = new MutableColumn("col1", ColumnType.BOOLEAN);
- private MutableColumn col2 = new MutableColumn("col2");
- private WhereBuilderImpl whereBuilder;
- private Query query;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- query = new Query();
- GroupedQueryBuilder queryBuilder = new GroupedQueryBuilderImpl(null,
- query);
- whereBuilder = new WhereBuilderImpl(col1, query, queryBuilder);
- }
-
- public void testOr() throws Exception {
- whereBuilder.eq(true).or(col2).like("%testcase%");
-
- assertEquals(" WHERE (col1 = TRUE OR col2 LIKE '%testcase%')",
- query.toSql());
- }
-
- public void testAnd() throws Exception {
- whereBuilder.differentFrom(true).and(col2).eq(1).or(col2).eq(2)
- .or(col2).eq(3).and(new MutableColumn("col3")).eq(4);
-
- assertEquals(
- " WHERE col1 <> TRUE AND (col2 = 1 OR col2 = 2 OR col2 = 3) AND col3 = 4",
- query.toSql());
- }
-
- public void testInStringArray() throws Exception {
- whereBuilder.eq(true).or(col2).in("foo", "bar");
-
- assertEquals(" WHERE (col1 = TRUE OR col2 IN ('foo' , 'bar'))",
- query.toSql());
- }
-
- public void testInNumberArray() throws Exception {
- whereBuilder.eq(true).or(col2).in(3, 1);
-
- assertEquals(" WHERE (col1 = TRUE OR col2 IN (3 , 1))", query.toSql());
- }
-
- public void testInCollection() throws Exception {
- Collection<?> col = Arrays.asList("foo", "bar");
- whereBuilder.eq(true).or(col2).in(col);
-
- assertEquals(" WHERE (col1 = TRUE OR col2 IN ('foo' , 'bar'))",
- query.toSql());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/query/parser/QueryParserTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/parser/QueryParserTest.java b/core/src/test/java/org/eobjects/metamodel/query/parser/QueryParserTest.java
deleted file mode 100644
index 786b79e..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/parser/QueryParserTest.java
+++ /dev/null
@@ -1,320 +0,0 @@
-/**
- * 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.query.parser;
-
-import java.util.Arrays;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.MockDataContext;
-import org.eobjects.metamodel.query.FilterClause;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.OrderByItem;
-import org.eobjects.metamodel.query.OrderByItem.Direction;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-
-public class QueryParserTest extends TestCase {
-
- private MockDataContext dc;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- dc = new MockDataContext("sch", "tbl", "foo");
-
- // set 'baz' column to an integer column (to influence query generation)
- MutableColumn col = (MutableColumn) dc.getColumnByQualifiedLabel("tbl.baz");
- col.setType(ColumnType.INTEGER);
- };
-
- public void testQueryInLowerCase() throws Exception {
- Query q = MetaModelHelper.parseQuery(dc,
- "select a.foo as f from sch.tbl a inner join sch.tbl b on a.foo=b.foo order by a.foo asc");
- assertEquals("SELECT a.foo AS f FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo ORDER BY a.foo ASC",
- q.toSql());
- }
-
- public void testSelectEverythingFromTable() throws Exception {
- Query q = MetaModelHelper.parseQuery(dc, "SELECT * FROM sch.tbl");
- assertEquals("SELECT tbl.foo, tbl.bar, tbl.baz FROM sch.tbl", q.toSql());
- }
-
- public void testSelectEverythingFromJoin() throws Exception {
- Query q = MetaModelHelper.parseQuery(dc, "SELECT * FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo");
- assertEquals(
- "SELECT a.foo, a.bar, a.baz, b.foo, b.bar, b.baz FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo",
- q.toSql());
-
- q = MetaModelHelper.parseQuery(dc, "SELECT a.foo, b.* FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo");
- assertEquals("SELECT a.foo, b.foo, b.bar, b.baz FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo",
- q.toSql());
- }
-
- public void testSelectColumnWithDotInName() throws Exception {
- MutableColumn col = (MutableColumn) dc.getTableByQualifiedLabel("tbl").getColumn(0);
- col.setName("fo.o");
-
- Query q = MetaModelHelper.parseQuery(dc, "SELECT fo.o AS f FROM sch.tbl");
- assertEquals("SELECT tbl.fo.o AS f FROM sch.tbl", q.toSql());
- }
-
- public void testSelectAlias() throws Exception {
- Query q = MetaModelHelper.parseQuery(dc, "SELECT foo AS f FROM sch.tbl");
- assertEquals("SELECT tbl.foo AS f FROM sch.tbl", q.toSql());
-
- q = MetaModelHelper.parseQuery(dc, "SELECT a.foo AS foobarbaz FROM sch.tbl a WHERE foobarbaz = '123'");
- assertEquals("SELECT a.foo AS foobarbaz FROM sch.tbl a WHERE foobarbaz = '123'", q.toSql());
- }
-
- public void testSelectDistinct() throws Exception {
- Query q = MetaModelHelper.parseQuery(dc, "SELECT DISTINCT foo, bar AS f FROM sch.tbl");
- assertEquals("SELECT DISTINCT tbl.foo, tbl.bar AS f FROM sch.tbl", q.toSql());
- }
-
- public void testSimpleSelectFrom() throws Exception {
- Query q = MetaModelHelper.parseQuery(dc, "SELECT foo\nFROM sch.tbl");
- assertEquals("SELECT tbl.foo FROM sch.tbl", q.toSql());
-
- assertEquals(1, q.getFromClause().getItemCount());
- FromItem fromItem = q.getFromClause().getItem(0);
- assertNull("FROM item was an expression based item, which indicates it was not parsed",
- fromItem.getExpression());
- assertNotNull(fromItem.getTable());
- assertEquals("tbl", fromItem.getTable().getName());
-
- assertEquals(1, q.getSelectClause().getItemCount());
- SelectItem selectItem = q.getSelectClause().getItem(0);
- assertNull("SELECT item was an expression based item, which indicates it was not parsed",
- selectItem.getExpression());
- assertNotNull(selectItem.getColumn());
- assertEquals("foo", selectItem.getColumn().getName());
-
- assertNull(q.getFirstRow());
- assertNull(q.getMaxRows());
- }
-
- public void testCarthesianProduct() throws Exception {
- Query q = MetaModelHelper.parseQuery(dc,
- " SELECT a.foo,b.bar FROM sch.tbl a, sch.tbl b \t WHERE a.foo = b.foo");
- assertEquals("SELECT a.foo, b.bar FROM sch.tbl a, sch.tbl b WHERE a.foo = b.foo", q.toSql());
-
- List<FromItem> fromItems = q.getFromClause().getItems();
- assertNotNull(fromItems.get(0).getTable());
- assertNotNull(fromItems.get(1).getTable());
-
- List<FilterItem> whereItems = q.getWhereClause().getItems();
- assertNotNull(whereItems.get(0).getSelectItem().getColumn());
- assertNotNull(whereItems.get(0).getSelectItem().getFromItem().getTable());
- }
-
- public void testJoin() throws Exception {
- Query q = MetaModelHelper.parseQuery(dc,
- "SELECT a.foo,b.bar FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo");
- assertEquals("SELECT a.foo, b.bar FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo", q.toSql());
-
- q = MetaModelHelper.parseQuery(dc,
- "SELECT COUNT(*) FROM sch.tbl a LEFT JOIN sch.tbl b ON a.foo = b.foo AND a.bar = b.baz");
- assertEquals("SELECT COUNT(*) FROM sch.tbl a LEFT JOIN sch.tbl b ON a.foo = b.foo AND a.bar = b.baz", q.toSql());
- }
-
- public void testSimpleSelectFromWhere() throws Exception {
- Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE bar = 'baz' AND baz > 5");
- assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.bar = 'baz' AND tbl.baz > 5", q.toSql());
-
- FilterClause whereClause = q.getWhereClause();
- assertEquals(2, whereClause.getItemCount());
- assertNull("WHERE item was an expression based item, which indicates it was not parsed", whereClause.getItem(0)
- .getExpression());
- assertEquals(2, whereClause.getItemCount());
- assertNull("WHERE item was an expression based item, which indicates it was not parsed", whereClause.getItem(1)
- .getExpression());
-
- assertEquals("baz", whereClause.getItem(0).getOperand());
- assertEquals(Integer.class, whereClause.getItem(1).getOperand().getClass());
- }
-
- public void testWhereStringEscaped() throws Exception {
- Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE bar = 'ba\\'z'");
- assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.bar = 'ba'z'", q.toSql());
- }
-
- public void testWhereOperandIsBoolean() throws Exception {
- // set 'baz' column to an integer column (to influence query generation)
- MutableColumn col = (MutableColumn) dc.getColumnByQualifiedLabel("tbl.baz");
- col.setType(ColumnType.BOOLEAN);
-
- Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE baz = TRUE");
- assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.baz = TRUE", q.toSql());
- }
-
- public void testWhereOperandIsDate() throws Exception {
- // set 'baz' column to an integer column (to influence query generation)
- MutableColumn col = (MutableColumn) dc.getColumnByQualifiedLabel("tbl.baz");
- col.setType(ColumnType.TIME);
-
- Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE baz = 10:24");
- assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.baz = TIME '10:24:00'", q.toSql());
- }
-
- public void testCoumpoundWhereClause() throws Exception {
- Query q = MetaModelHelper
- .parseQuery(dc, "SELECT foo FROM sch.tbl WHERE (bar = 'baz' OR (baz > 5 AND baz < 7))");
- assertEquals("SELECT tbl.foo FROM sch.tbl WHERE (tbl.bar = 'baz' OR (tbl.baz > 5 AND tbl.baz < 7))", q.toSql());
-
- FilterClause wc = q.getWhereClause();
- assertEquals(1, wc.getItemCount());
- FilterItem item = wc.getItem(0);
- assertTrue(item.isCompoundFilter());
-
- FilterItem[] childItems = item.getChildItems();
- assertEquals(2, childItems.length);
-
- FilterItem bazConditions = childItems[1];
- assertTrue(bazConditions.isCompoundFilter());
- }
-
- public void testWhereSomethingIsNull() throws Exception {
- Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE bar IS NULL");
- assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.bar IS NULL", q.toSql());
-
- assertEquals(1, q.getWhereClause().getItemCount());
- assertNull("WHERE item was an expression based item, which indicates it was not parsed", q.getWhereClause()
- .getItem(0).getExpression());
- assertNull(q.getWhereClause().getItem(0).getOperand());
- assertEquals(OperatorType.EQUALS_TO, q.getWhereClause().getItem(0).getOperator());
- }
-
- public void testWhereSomethingIsNotNull() throws Exception {
- Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE bar IS NOT NULL");
- assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.bar IS NOT NULL", q.toSql());
-
- assertEquals(1, q.getWhereClause().getItemCount());
- assertNull("WHERE item was an expression based item, which indicates it was not parsed", q.getWhereClause()
- .getItem(0).getExpression());
- assertNull(q.getWhereClause().getItem(0).getOperand());
- assertEquals(OperatorType.DIFFERENT_FROM, q.getWhereClause().getItem(0).getOperator());
- }
-
- public void testLimitAndOffset() throws Exception {
- Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl LIMIT 1234 OFFSET 5");
- assertEquals("SELECT tbl.foo FROM sch.tbl", q.toSql());
- assertEquals(1234, q.getMaxRows().intValue());
- assertEquals(6, q.getFirstRow().intValue());
- }
-
- public void testWhereIn() throws Exception {
- Query q = MetaModelHelper.parseQuery(dc, "SELECT foo FROM sch.tbl WHERE foo IN ('a','b',5)");
- assertEquals("SELECT tbl.foo FROM sch.tbl WHERE tbl.foo IN ('a' , 'b' , '5')", q.toSql());
-
- FilterItem whereItem = q.getWhereClause().getItem(0);
- assertEquals(OperatorType.IN, whereItem.getOperator());
- Object operand = whereItem.getOperand();
- assertTrue(operand instanceof List);
- assertEquals("a", ((List<?>) operand).get(0));
- assertEquals("b", ((List<?>) operand).get(1));
- assertEquals(5, ((List<?>) operand).get(2));
- }
-
- public void testSimpleSubQuery() throws Exception {
- Query q = MetaModelHelper.parseQuery(dc, "SELECT f.foo AS fo FROM (SELECT * FROM sch.tbl) f");
- assertEquals("SELECT f.foo AS fo FROM (SELECT tbl.foo, tbl.bar, tbl.baz FROM sch.tbl) f", q.toSql());
- }
-
- public void testSelectEverythingFromSubQuery() throws Exception {
- Query q = MetaModelHelper.parseQuery(dc, "SELECT * FROM (SELECT foo, bar FROM sch.tbl) f");
- assertEquals("SELECT f.foo, f.bar FROM (SELECT tbl.foo, tbl.bar FROM sch.tbl) f", q.toSql());
- }
-
- public void testGetIndicesVanillaScenario() throws Exception {
- QueryParser qp = new QueryParser(dc, "SELECT ... FROM ... BAR BAZ");
- assertEquals("[0, 7]", Arrays.toString(qp.indexesOf("SELECT ", null)));
- assertEquals("[10, 16]", Arrays.toString(qp.indexesOf(" FROM ", null)));
- }
-
- public void testGetIndicesIgnoreWhiteSpaceAndCaseDifferences() throws Exception {
- QueryParser qp = new QueryParser(dc, " \t\r\n select ... from ... BAR BAZ");
- assertEquals("[0, 7]", Arrays.toString(qp.indexesOf("SELECT ", null)));
- assertEquals("[10, 16]", Arrays.toString(qp.indexesOf(" FROM ", null)));
- }
-
- public void testInvalidQueries() throws Exception {
- try {
- MetaModelHelper.parseQuery(dc, "foobar");
- fail("Exception expected");
- } catch (MetaModelException e) {
- assertEquals("SELECT not found in query: foobar", e.getMessage());
- }
-
- try {
- MetaModelHelper.parseQuery(dc, "SELECT foobar");
- fail("Exception expected");
- } catch (MetaModelException e) {
- assertEquals("FROM not found in query: SELECT foobar", e.getMessage());
- }
- }
-
- public void testFullQuery() throws Exception {
- Query q = MetaModelHelper.parseQuery(dc,
- "SELECT foo, COUNT(* ), MAX( baz ) FROM sch.tbl WHERE bar = 'baz' AND foo = bar AND baz > 5 "
- + "GROUP BY foo HAVING COUNT(*) > 2 ORDER BY foo LIMIT 20 OFFSET 10");
- assertEquals(
- "SELECT tbl.foo, COUNT(*), MAX(tbl.baz) FROM sch.tbl WHERE tbl.bar = 'baz' AND tbl.foo = tbl.bar AND tbl.baz > 5 "
- + "GROUP BY tbl.foo HAVING COUNT(*) > 2 ORDER BY tbl.foo ASC", q.toSql());
- assertEquals(20, q.getMaxRows().intValue());
- assertEquals(11, q.getFirstRow().intValue());
-
- // SELECT ...
- // tbl.foo
- assertNotNull("SelectItem 1 should be a column", q.getSelectClause().getItem(0).getColumn());
-
- // COUNT(*)
- assertNotNull("SelectItem 2 should be a Function", q.getSelectClause().getItem(1).getFunction());
- assertNotNull("SelectItem 2 should be a Function of '*'", q.getSelectClause().getItem(1).getExpression());
-
- // MAX(tbl.baz)
- assertNotNull("SelectItem 3 should be a Function", q.getSelectClause().getItem(2).getFunction());
- assertNotNull("SelectItem 4 should be a Function of a column", q.getSelectClause().getItem(2).getColumn());
-
- // FROM tbl.foo
- assertNotNull(q.getFromClause().getItem(0).getTable());
-
- // GROUP BY tbl.foo
- assertNotNull(q.getGroupByClause().getItem(0).getSelectItem().getColumn());
-
- // HAVING COUNT(*) > 2
- FilterItem havingItem = q.getHavingClause().getItem(0);
- assertNull(havingItem.getExpression());
- assertNotNull(havingItem.getSelectItem().getFunction());
- assertEquals("*", havingItem.getSelectItem().getExpression());
-
- // ORDER BY tbl.foo ASC
- OrderByItem orderByItem = q.getOrderByClause().getItem(0);
- assertNull(orderByItem.getSelectItem().getExpression());
- assertNotNull(orderByItem.getSelectItem().getColumn());
- assertEquals(Direction.ASC, orderByItem.getDirection());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/query/parser/QueryPartParserTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/parser/QueryPartParserTest.java b/core/src/test/java/org/eobjects/metamodel/query/parser/QueryPartParserTest.java
deleted file mode 100644
index 0066f9c..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/parser/QueryPartParserTest.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/**
- * 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.query.parser;
-
-import java.util.List;
-
-import junit.framework.TestCase;
-
-public class QueryPartParserTest extends TestCase {
-
- public void testParseNone() throws Exception {
- QueryPartCollectionProcessor itemParser = new QueryPartCollectionProcessor();
-
- new QueryPartParser(itemParser, " ", ",").parse();
-
- List<String> items = itemParser.getTokens();
- assertEquals(0, items.size());
- assertEquals("[]", items.toString());
- }
-
- public void testParseSingle() throws Exception {
- QueryPartCollectionProcessor itemParser = new QueryPartCollectionProcessor();
-
- new QueryPartParser(itemParser, "foo ", ",").parse();
-
- List<String> items = itemParser.getTokens();
- assertEquals(1, items.size());
- assertEquals("[foo]", items.toString());
- assertEquals("[null]", itemParser.getDelims().toString());
- }
-
- public void testParseMultiple() throws Exception {
- QueryPartCollectionProcessor itemParser = new QueryPartCollectionProcessor();
-
- new QueryPartParser(itemParser, "foo , bar", ",").parse();
-
- List<String> items = itemParser.getTokens();
- assertEquals(2, items.size());
- assertEquals("[foo, bar]", items.toString());
- }
-
- public void testParseWithParenthesis() throws Exception {
- QueryPartCollectionProcessor itemParser = new QueryPartCollectionProcessor();
-
- new QueryPartParser(itemParser, "foo , bar (a,b,c),(doh)", ",").parse();
-
- List<String> items = itemParser.getTokens();
- assertEquals("[foo, bar (a,b,c), (doh)]", items.toString());
- assertEquals(3, items.size());
- }
-
- public void testMultipleDelims() throws Exception {
- QueryPartCollectionProcessor itemParser = new QueryPartCollectionProcessor();
-
- new QueryPartParser(itemParser, "foo AND bar OR baz AND (foo( AND bar) OR baz)", " AND ", " OR ").parse();
-
- List<String> items = itemParser.getTokens();
- assertEquals(4, items.size());
- assertEquals("[foo, bar, baz, (foo( AND bar) OR baz)]", items.toString());
- assertEquals("[null, AND , OR , AND ]", itemParser.getDelims().toString());
- }
-
- public void testEmptyClause() throws Exception {
- QueryPartCollectionProcessor itemParser = new QueryPartCollectionProcessor();
-
- new QueryPartParser(itemParser, "", ",").parse();
- assertEquals(0, itemParser.getTokens().size());
- }
-
- public void testEmptyParenthesis() throws Exception {
- QueryPartCollectionProcessor itemParser = new QueryPartCollectionProcessor();
-
- new QueryPartParser(itemParser, "()", ",").parse();
- assertEquals(0, itemParser.getTokens().size());
- }
-
- public void testMultiParenthesisLevels() throws Exception {
- QueryPartCollectionProcessor itemParser = new QueryPartCollectionProcessor();
-
- new QueryPartParser(itemParser, "(((Hello world)))", ",").parse();
- assertEquals(1, itemParser.getTokens().size());
- assertEquals("Hello world", itemParser.getTokens().get(0));
- }
-
- public void testOuterParenthesis() throws Exception {
- QueryPartCollectionProcessor itemParser = new QueryPartCollectionProcessor();
-
- new QueryPartParser(itemParser, "(foo,bar)", ",").parse();
-
- List<String> items = itemParser.getTokens();
- assertEquals(2, items.size());
- assertEquals("[foo, bar]", items.toString());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/schema/ColumnTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/schema/ColumnTypeTest.java b/core/src/test/java/org/eobjects/metamodel/schema/ColumnTypeTest.java
deleted file mode 100644
index 54b0689..0000000
--- a/core/src/test/java/org/eobjects/metamodel/schema/ColumnTypeTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * 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.schema;
-
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.sql.Types;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-
-import junit.framework.TestCase;
-
-public class ColumnTypeTest extends TestCase {
-
- public void testConvertColumnTypeFromJdbcTypes() throws Exception {
- ColumnType type = ColumnType.convertColumnType(Types.VARCHAR);
- assertEquals(ColumnType.VARCHAR, type);
-
- type = ColumnType.convertColumnType(Types.DATE);
- assertEquals(ColumnType.DATE, type);
-
- type = ColumnType.convertColumnType(Types.TIME);
- assertEquals(ColumnType.TIME, type);
-
- type = ColumnType.convertColumnType(Types.TIMESTAMP);
- assertEquals(ColumnType.TIMESTAMP, type);
-
- type = ColumnType.convertColumnType(42397443);
- assertEquals(ColumnType.OTHER, type);
-
- type = ColumnType.convertColumnType(-42397443);
- assertEquals(ColumnType.OTHER, type);
- }
-
- public void testConvertColumnTypeFromJavaClass() throws Exception {
- ColumnType type = ColumnType.convertColumnType(String.class);
- assertEquals(ColumnType.VARCHAR, type);
-
- type = ColumnType.convertColumnType(Time.class);
- assertEquals(ColumnType.TIME, type);
-
- type = ColumnType.convertColumnType(Timestamp.class);
- assertEquals(ColumnType.TIMESTAMP, type);
-
- type = ColumnType.convertColumnType(java.sql.Date.class);
- assertEquals(ColumnType.DATE, type);
-
- type = ColumnType.convertColumnType(Date.class);
- assertEquals(ColumnType.TIMESTAMP, type);
-
- type = ColumnType.convertColumnType(Integer.class);
- assertEquals(ColumnType.INTEGER, type);
-
- type = ColumnType.convertColumnType(Object.class);
- assertEquals(ColumnType.OTHER, type);
-
- type = ColumnType.convertColumnType(Map.class);
- assertEquals(ColumnType.MAP, type);
- type = ColumnType.convertColumnType(HashMap.class);
- assertEquals(ColumnType.MAP, type);
- type = ColumnType.convertColumnType(TreeMap.class);
- assertEquals(ColumnType.MAP, type);
-
- type = ColumnType.convertColumnType(List.class);
- assertEquals(ColumnType.LIST, type);
- type = ColumnType.convertColumnType(ArrayList.class);
- assertEquals(ColumnType.LIST, type);
- type = ColumnType.convertColumnType(LinkedList.class);
- assertEquals(ColumnType.LIST, type);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/schema/DataTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/schema/DataTypeTest.java b/core/src/test/java/org/eobjects/metamodel/schema/DataTypeTest.java
deleted file mode 100644
index 087062d..0000000
--- a/core/src/test/java/org/eobjects/metamodel/schema/DataTypeTest.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * 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.schema;
-
-import junit.framework.TestCase;
-
-public class DataTypeTest extends TestCase {
-
- public void testIsLiteral() throws Exception {
- assertTrue(ColumnType.NCHAR.isLiteral());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/schema/ImmutableSchemaTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/schema/ImmutableSchemaTest.java b/core/src/test/java/org/eobjects/metamodel/schema/ImmutableSchemaTest.java
deleted file mode 100644
index 476af09..0000000
--- a/core/src/test/java/org/eobjects/metamodel/schema/ImmutableSchemaTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * 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.schema;
-
-import org.eobjects.metamodel.MetaModelTestCase;
-
-public class ImmutableSchemaTest extends MetaModelTestCase {
-
- public void testConstructor() throws Exception {
- Schema mutableSchema = getExampleSchema();
- assertTrue(mutableSchema instanceof MutableSchema);
-
- ImmutableSchema immutableSchema = new ImmutableSchema(mutableSchema);
-
- assertEquals(mutableSchema.getRelationshipCount(), immutableSchema.getRelationshipCount());
-
- assertEquals(immutableSchema, mutableSchema);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/schema/Java5Types.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/schema/Java5Types.java b/core/src/test/java/org/eobjects/metamodel/schema/Java5Types.java
deleted file mode 100644
index 8f44fa9..0000000
--- a/core/src/test/java/org/eobjects/metamodel/schema/Java5Types.java
+++ /dev/null
@@ -1,246 +0,0 @@
-/**
- * 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.schema;
-
-/**
- * This is a copy of the content of Java 5.0's java.sql.Types
- */
-class Java5Types {
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>BIT</code>.
- */
- public final static int BIT = -7;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>TINYINT</code>.
- */
- public final static int TINYINT = -6;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>SMALLINT</code>.
- */
- public final static int SMALLINT = 5;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>INTEGER</code>.
- */
- public final static int INTEGER = 4;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>BIGINT</code>.
- */
- public final static int BIGINT = -5;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>FLOAT</code>.
- */
- public final static int FLOAT = 6;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>REAL</code>.
- */
- public final static int REAL = 7;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>DOUBLE</code>.
- */
- public final static int DOUBLE = 8;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>NUMERIC</code>.
- */
- public final static int NUMERIC = 2;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>DECIMAL</code>.
- */
- public final static int DECIMAL = 3;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>CHAR</code>.
- */
- public final static int CHAR = 1;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>VARCHAR</code>.
- */
- public final static int VARCHAR = 12;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>LONGVARCHAR</code>.
- */
- public final static int LONGVARCHAR = -1;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>DATE</code>.
- */
- public final static int DATE = 91;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>TIME</code>.
- */
- public final static int TIME = 92;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>TIMESTAMP</code>.
- */
- public final static int TIMESTAMP = 93;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>BINARY</code>.
- */
- public final static int BINARY = -2;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>VARBINARY</code>.
- */
- public final static int VARBINARY = -3;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type
- * <code>LONGVARBINARY</code>.
- */
- public final static int LONGVARBINARY = -4;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>NULL</code>.
- */
- public final static int NULL = 0;
-
- /**
- * The constant in the Java programming language that indicates that the SQL
- * type is database-specific and gets mapped to a Java object that can be
- * accessed via the methods <code>getObject</code> and
- * <code>setObject</code>.
- */
- public final static int OTHER = 1111;
-
- /**
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>JAVA_OBJECT</code>.
- *
- * @since 1.2
- */
- public final static int JAVA_OBJECT = 2000;
-
- /**
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>DISTINCT</code>.
- *
- * @since 1.2
- */
- public final static int DISTINCT = 2001;
-
- /**
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>STRUCT</code>.
- *
- * @since 1.2
- */
- public final static int STRUCT = 2002;
-
- /**
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>ARRAY</code>.
- *
- * @since 1.2
- */
- public final static int ARRAY = 2003;
-
- /**
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>BLOB</code>.
- *
- * @since 1.2
- */
- public final static int BLOB = 2004;
-
- /**
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>CLOB</code>.
- *
- * @since 1.2
- */
- public final static int CLOB = 2005;
-
- /**
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>REF</code>.
- *
- * @since 1.2
- */
- public final static int REF = 2006;
-
- /**
- * The constant in the Java programming language, somtimes referred to as a
- * type code, that identifies the generic SQL type <code>DATALINK</code>.
- *
- * @since 1.4
- */
- public final static int DATALINK = 70;
-
- /**
- * The constant in the Java programming language, somtimes referred to as a
- * type code, that identifies the generic SQL type <code>BOOLEAN</code>.
- *
- * @since 1.4
- */
- public final static int BOOLEAN = 16;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/schema/Java6Types.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/schema/Java6Types.java b/core/src/test/java/org/eobjects/metamodel/schema/Java6Types.java
deleted file mode 100644
index d48600a..0000000
--- a/core/src/test/java/org/eobjects/metamodel/schema/Java6Types.java
+++ /dev/null
@@ -1,297 +0,0 @@
-/**
- * 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.schema;
-
-/**
- * This is a copy of the content of Java 6.0's java.sql.Types
- */
-class Java6Types {
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>BIT</code>.
- */
- public final static int BIT = -7;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>TINYINT</code>.
- */
- public final static int TINYINT = -6;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>SMALLINT</code>.
- */
- public final static int SMALLINT = 5;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>INTEGER</code>.
- */
- public final static int INTEGER = 4;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>BIGINT</code>.
- */
- public final static int BIGINT = -5;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>FLOAT</code>.
- */
- public final static int FLOAT = 6;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>REAL</code>.
- */
- public final static int REAL = 7;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>DOUBLE</code>.
- */
- public final static int DOUBLE = 8;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>NUMERIC</code>.
- */
- public final static int NUMERIC = 2;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>DECIMAL</code>.
- */
- public final static int DECIMAL = 3;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>CHAR</code>.
- */
- public final static int CHAR = 1;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>VARCHAR</code>.
- */
- public final static int VARCHAR = 12;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>LONGVARCHAR</code>.
- */
- public final static int LONGVARCHAR = -1;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>DATE</code>.
- */
- public final static int DATE = 91;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>TIME</code>.
- */
- public final static int TIME = 92;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>TIMESTAMP</code>.
- */
- public final static int TIMESTAMP = 93;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>BINARY</code>.
- */
- public final static int BINARY = -2;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>VARBINARY</code>.
- */
- public final static int VARBINARY = -3;
-
- /**
- * <P>
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type
- * <code>LONGVARBINARY</code>.
- */
- public final static int LONGVARBINARY = -4;
-
- /**
- * <P>
- * The constant in the Java programming language that identifies the generic
- * SQL value <code>NULL</code>.
- */
- public final static int NULL = 0;
-
- /**
- * The constant in the Java programming language that indicates that the SQL
- * type is database-specific and gets mapped to a Java object that can be
- * accessed via the methods <code>getObject</code> and
- * <code>setObject</code>.
- */
- public final static int OTHER = 1111;
-
- /**
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>JAVA_OBJECT</code>.
- *
- * @since 1.2
- */
- public final static int JAVA_OBJECT = 2000;
-
- /**
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>DISTINCT</code>.
- *
- * @since 1.2
- */
- public final static int DISTINCT = 2001;
-
- /**
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>STRUCT</code>.
- *
- * @since 1.2
- */
- public final static int STRUCT = 2002;
-
- /**
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>ARRAY</code>.
- *
- * @since 1.2
- */
- public final static int ARRAY = 2003;
-
- /**
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>BLOB</code>.
- *
- * @since 1.2
- */
- public final static int BLOB = 2004;
-
- /**
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>CLOB</code>.
- *
- * @since 1.2
- */
- public final static int CLOB = 2005;
-
- /**
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>REF</code>.
- *
- * @since 1.2
- */
- public final static int REF = 2006;
-
- /**
- * The constant in the Java programming language, somtimes referred to as a
- * type code, that identifies the generic SQL type <code>DATALINK</code>.
- *
- * @since 1.4
- */
- public final static int DATALINK = 70;
-
- /**
- * The constant in the Java programming language, somtimes referred to as a
- * type code, that identifies the generic SQL type <code>BOOLEAN</code>.
- *
- * @since 1.4
- */
- public final static int BOOLEAN = 16;
-
- // ------------------------- JDBC 4.0 -----------------------------------
-
- /**
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>ROWID</code>
- *
- * @since 1.6
- *
- */
- public final static int ROWID = -8;
-
- /**
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>NCHAR</code>
- *
- * @since 1.6
- */
- public static final int NCHAR = -15;
-
- /**
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>NVARCHAR</code>.
- *
- * @since 1.6
- */
- public static final int NVARCHAR = -9;
-
- /**
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>LONGNVARCHAR</code>.
- *
- * @since 1.6
- */
- public static final int LONGNVARCHAR = -16;
-
- /**
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>NCLOB</code>.
- *
- * @since 1.6
- */
- public static final int NCLOB = 2011;
-
- /**
- * The constant in the Java programming language, sometimes referred to as a
- * type code, that identifies the generic SQL type <code>XML</code>.
- *
- * @since 1.6
- */
- public static final int SQLXML = 2009;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/schema/JavaTypesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/schema/JavaTypesTest.java b/core/src/test/java/org/eobjects/metamodel/schema/JavaTypesTest.java
deleted file mode 100644
index 2d5eb9c..0000000
--- a/core/src/test/java/org/eobjects/metamodel/schema/JavaTypesTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * 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.schema;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-
-import junit.framework.TestCase;
-
-public class JavaTypesTest extends TestCase {
-
- /**
- * Tests that the constant values of java 6 is backwards compatible with
- * java 5
- */
- public void testConstantValues() throws Exception {
- Class<Java5Types> types5 = Java5Types.class;
- Class<JdbcTypes> types6 = JdbcTypes.class;
- Field[] fields = types5.getFields();
- for (int i = 0; i < fields.length; i++) {
- Field field5 = fields[i];
- String fieldName = field5.getName();
- int mod = field5.getModifiers();
- if (Modifier.isFinal(mod) && Modifier.isPublic(mod)
- && Modifier.isStatic(mod)) {
- int value5 = field5.getInt(null);
- Field field6 = types6.getField(fieldName);
- int value6 = field6.getInt(null);
- assertEquals("Value of field " + fieldName
- + " was not the same", value5, value6);
- }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/schema/MutableColumnTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/schema/MutableColumnTest.java b/core/src/test/java/org/eobjects/metamodel/schema/MutableColumnTest.java
deleted file mode 100644
index a2b3ca6..0000000
--- a/core/src/test/java/org/eobjects/metamodel/schema/MutableColumnTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * 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.schema;
-
-import junit.framework.TestCase;
-
-public class MutableColumnTest extends TestCase {
-
- /**
- * Tests that the following (general) rules apply to the object:
- *
- * <li>the hashcode is the same when run twice on an unaltered object</li>
- * <li>if o1.equals(o2) then this condition must be true: o1.hashCode() ==
- * 02.hashCode()
- */
- public void testEqualsAndHashCode() throws Exception {
- Column column1 = new MutableColumn("foo");
- Column column2 = new MutableColumn("foo");
-
- assertEquals(column1.hashCode(), column2.hashCode());
- assertEquals(column1, column2);
-
- column2 = new MutableColumn("bar");
- assertFalse(column1.equals(column2));
-
- column2 = new MutableColumn("foo", ColumnType.VARBINARY);
- assertFalse(column1.equals(column2));
-
- column1 = new MutableColumn("foo", ColumnType.VARBINARY);
- assertTrue(column1.equals(column2));
- }
-
- public void testQualifiedLabel() throws Exception {
- MutableSchema s = new MutableSchema("FOO_SCHEMA");
- MutableTable t = new MutableTable("FOO_TABLE");
- MutableColumn c = new MutableColumn("FOO_COLUMN");
-
- assertEquals("FOO_COLUMN", c.getQualifiedLabel());
- t.addColumn(c);
- c.setTable(t);
- assertEquals("FOO_TABLE.FOO_COLUMN", c.getQualifiedLabel());
- s.addTable(t);
- t.setSchema(s);
- assertEquals("FOO_SCHEMA.FOO_TABLE.FOO_COLUMN", c.getQualifiedLabel());
-
- s.setName("new_schema_name");
- assertEquals("new_schema_name.FOO_TABLE.FOO_COLUMN",
- c.getQualifiedLabel());
- }
-}
\ No newline at end of file
[27/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/AbstractDataContextTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/AbstractDataContextTest.java b/core/src/test/java/org/apache/metamodel/AbstractDataContextTest.java
new file mode 100644
index 0000000..4320a5b
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/AbstractDataContextTest.java
@@ -0,0 +1,247 @@
+/**
+ * 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;
+
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.Column;
+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.Table;
+
+public class AbstractDataContextTest extends TestCase {
+
+ private class MyDataContext extends AbstractDataContext {
+ @Override
+ public DataSet executeQuery(Query query) throws MetaModelException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected String[] getSchemaNamesInternal() {
+ return new String[] { "barfoo", "foobar", "foo.bar" };
+ }
+
+ @Override
+ protected String getDefaultSchemaName() {
+ return "foobar";
+ }
+
+ @Override
+ protected Schema getSchemaByNameInternal(String name) {
+ if ("barfoo".equals(name) || "foobar".equals(name)
+ || "foo.bar".equals(name)) {
+ return createSchema(name);
+ }
+ throw new IllegalStateException("No such schema: " + name);
+ }
+
+ private Schema createSchema(String name) {
+ MutableSchema schema = new MutableSchema(name);
+ MutableTable t1 = new MutableTable("table");
+ MutableColumn col1 = new MutableColumn("col1");
+ MutableColumn col2 = new MutableColumn("col2");
+ t1.addColumn(col1).addColumn(col2);
+ col1.setTable(t1);
+ col2.setTable(t1);
+ MutableTable t2 = new MutableTable("tab.le");
+ MutableColumn col3 = new MutableColumn("col3");
+ MutableColumn col4 = new MutableColumn("col4");
+ t2.addColumn(col3).addColumn(col4);
+ col3.setTable(t2);
+ col4.setTable(t2);
+ schema.addTable(t1).addTable(t2);
+ t1.setSchema(schema);
+ t2.setSchema(schema);
+ return schema;
+ }
+
+ }
+
+
+ public void testGetColumnByQualifiedLabel() throws Exception {
+ MyDataContext dc = new MyDataContext();
+ Column result;
+
+ result = dc.getColumnByQualifiedLabel("foobar.tab.le.col1");
+ result = dc.getColumnByQualifiedLabel("blabla.tab.le.col4");
+ result = dc.getColumnByQualifiedLabel("FOOBAR.TABLE.COL3");
+ assertNull(result);
+
+ result = dc.getColumnByQualifiedLabel("foobar.table.col1");
+ assertEquals("col1", result.getName());
+ assertEquals("table", result.getTable().getName());
+ assertEquals("foobar", result.getTable().getSchema().getName());
+
+ result = dc.getColumnByQualifiedLabel("foo.bar.table.col1");
+ assertEquals("col1", result.getName());
+ assertEquals("table", result.getTable().getName());
+ assertEquals("foo.bar", result.getTable().getSchema().getName());
+
+ result = dc.getColumnByQualifiedLabel("foobar.tab.le.col3");
+ assertEquals("col3", result.getName());
+ assertEquals("tab.le", result.getTable().getName());
+ assertEquals("foobar", result.getTable().getSchema().getName());
+
+ result = dc.getColumnByQualifiedLabel("FOO.BAR.tab.le.col3");
+ assertEquals("col3", result.getName());
+ assertEquals("tab.le", result.getTable().getName());
+ assertEquals("foo.bar", result.getTable().getSchema().getName());
+
+ result = dc.getColumnByQualifiedLabel("tab.le.col3");
+ assertEquals("col3", result.getName());
+ assertEquals("tab.le", result.getTable().getName());
+ assertEquals("foobar", result.getTable().getSchema().getName());
+ }
+
+ public void testGetTableByQualfiedLabelSchemaNameInTableName() throws Exception {
+ AbstractDataContext dc = new AbstractDataContext() {
+ @Override
+ public DataSet executeQuery(Query query) throws MetaModelException {
+ return null;
+ }
+
+ @Override
+ protected String[] getSchemaNamesInternal() {
+ return new String[] {"test"};
+ }
+
+ @Override
+ protected Schema getSchemaByNameInternal(String name) {
+ MutableSchema sch = new MutableSchema("test");
+ sch.addTable(new MutableTable("test_table1").setSchema(sch));
+ sch.addTable(new MutableTable("test_table2").setSchema(sch));
+ sch.addTable(new MutableTable("test_table3").setSchema(sch));
+ return sch;
+ }
+
+ @Override
+ protected String getDefaultSchemaName() {
+ return "test";
+ }
+ };
+
+ assertEquals("test_table1", dc.getTableByQualifiedLabel("test_table1").getName());
+ assertEquals("test_table2", dc.getTableByQualifiedLabel("test_table2").getName());
+ assertEquals("test_table3", dc.getTableByQualifiedLabel("test_table3").getName());
+ }
+
+ public void testGetTableByQualifiedLabel() throws Exception {
+ MyDataContext dc = new MyDataContext();
+
+ Table result;
+
+ result = dc.getTableByQualifiedLabel("FOOBAR.table");
+ assertEquals("table", result.getName());
+ assertEquals("foobar", result.getSchema().getName());
+
+ result = dc.getTableByQualifiedLabel("table");
+ assertEquals("table", result.getName());
+ assertEquals("foobar", result.getSchema().getName());
+
+ result = dc.getTableByQualifiedLabel("foo.bar.table");
+ assertEquals("table", result.getName());
+ assertEquals("foo.bar", result.getSchema().getName());
+
+ result = dc.getTableByQualifiedLabel("foobar.tab.le");
+ assertEquals("tab.le", result.getName());
+ assertEquals("foobar", result.getSchema().getName());
+
+ result = dc.getTableByQualifiedLabel("foo.bar.tab.le");
+ assertEquals("tab.le", result.getName());
+ assertEquals("foo.bar", result.getSchema().getName());
+
+ result = dc.getTableByQualifiedLabel("foo.table");
+ assertNull(result);
+ }
+
+ public void testGetSchemas() throws Exception {
+ MyDataContext dc = new MyDataContext();
+ Schema[] schemas = dc.getSchemas();
+ assertEquals(
+ "[Schema[name=barfoo], Schema[name=foo.bar], Schema[name=foobar]]",
+ Arrays.toString(schemas));
+
+ dc.refreshSchemas();
+ schemas = dc.getSchemas();
+ assertEquals(
+ "[Schema[name=barfoo], Schema[name=foo.bar], Schema[name=foobar]]",
+ Arrays.toString(schemas));
+ }
+
+ public void testGetColumnByQualifiedLabelWithNameOverlaps()
+ throws Exception {
+ AbstractDataContext dc = new AbstractDataContext() {
+
+ @Override
+ public DataSet executeQuery(Query query) throws MetaModelException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected String[] getSchemaNamesInternal() {
+ return new String[] { "sch" };
+ }
+
+ @Override
+ protected Schema getSchemaByNameInternal(String name) {
+ MutableSchema schema = new MutableSchema("sch");
+ MutableTable table1 = new MutableTable("tab");
+ MutableTable table2 = new MutableTable("tab_le");
+ MutableTable table3 = new MutableTable("table");
+ MutableTable table4 = new MutableTable("tabl_e");
+ schema.addTable(table1.addColumn(new MutableColumn("col")
+ .setTable(table1)));
+ schema.addTable(table2.addColumn(new MutableColumn("col")
+ .setTable(table2)));
+ schema.addTable(table3.addColumn(new MutableColumn("col")
+ .setTable(table3)));
+ schema.addTable(table4.addColumn(new MutableColumn("col")
+ .setTable(table4)));
+ return schema;
+ }
+
+ @Override
+ protected String getDefaultSchemaName() {
+ return "sch";
+ }
+ };
+
+ assertEquals("tab.col", dc.getColumnByQualifiedLabel("sch.tab.col")
+ .getQualifiedLabel());
+ assertEquals("table.col", dc.getColumnByQualifiedLabel("sch.table.col")
+ .getQualifiedLabel());
+ assertEquals("tab_le.col", dc.getColumnByQualifiedLabel(
+ "sch.tab_le.col").getQualifiedLabel());
+ assertEquals("tabl_e.col", dc.getColumnByQualifiedLabel(
+ "sch.tabl_e.col").getQualifiedLabel());
+ }
+
+ public void testGetColumnByQualifiedLabelCaseInsensitive() throws Exception {
+ MyDataContext dc = new MyDataContext();
+ Column result = dc.getColumnByQualifiedLabel("FOOBAR.TABLE.COL1");
+ assertNotNull(result);
+ assertEquals("col1", result.getName());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/CompositeDataContextTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/CompositeDataContextTest.java b/core/src/test/java/org/apache/metamodel/CompositeDataContextTest.java
new file mode 100644
index 0000000..0a2e0f7
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/CompositeDataContextTest.java
@@ -0,0 +1,117 @@
+/**
+ * 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;
+
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.CompositeSchema;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+public class CompositeDataContextTest extends TestCase {
+
+ /**
+ * A "typical scenario": Use a database and a CSV file to create a query
+ * that joins tables from each
+ */
+ public void testBaseCaseCompositeQuery() throws Exception {
+ DataContext dc1 = new MockDataContext("schema1", "table1", "");
+ DataContext dc2 = new MockDataContext("schema2", "table2", "");
+
+ DataContext composite = new CompositeDataContext(dc1, dc2);
+
+ assertEquals("[schema1, schema2]",
+ Arrays.toString(composite.getSchemaNames()));
+ assertSame(dc1.getDefaultSchema(), composite.getDefaultSchema());
+
+ DataSet ds = composite.query()
+ .from(dc1.getDefaultSchema().getTables()[0]).select("foo")
+ .execute();
+ List<Object[]> objectArrays = ds.toObjectArrays();
+ assertEquals("1", objectArrays.get(0)[0]);
+ assertEquals("2", objectArrays.get(1)[0]);
+ assertEquals(4, objectArrays.size());
+ }
+
+ public void testSchemaNameClashes() throws Exception {
+ DataContext dc1 = new MockDataContext("schema", "table1", "");
+ DataContext dc2 = new MockDataContext("schema", "table2", "");
+
+ DataContext composite = new CompositeDataContext(dc1, dc2);
+
+ assertEquals("[schema]",
+ Arrays.toString(composite.getSchemaNames()));
+
+ Schema schema = composite.getDefaultSchema();
+ assertEquals(4, schema.getTableCount());
+ assertEquals("[table1, an_empty_table, table2, an_empty_table]",
+ Arrays.toString(schema.getTableNames()));
+ assertTrue(schema instanceof CompositeSchema);
+ }
+
+ public void testJoinSameTableNames() throws Exception {
+ DataContext dc1 = new MockDataContext("schema", "table", "dc1");
+ DataContext dc2 = new MockDataContext("schema", "table", "dc2");
+
+ DataContext composite = new CompositeDataContext(dc1, dc2);
+
+ assertEquals("[schema]",
+ Arrays.toString(composite.getSchemaNames()));
+
+ Schema schema = composite.getDefaultSchema();
+ assertEquals(4, schema.getTableCount());
+ assertEquals("[table, an_empty_table, table, an_empty_table]", Arrays.toString(schema.getTableNames()));
+ assertTrue(schema instanceof CompositeSchema);
+ Table[] tables = schema.getTables();
+ Table table1 = tables[0];
+ Table table2 = tables[2];
+ assertNotSame(table1, table2);
+
+ Query q = composite
+ .query()
+ .from(table1)
+ .leftJoin(table2)
+ .on(table1.getColumnByName("foo"),
+ table2.getColumnByName("foo"))
+ .select(table1.getColumnByName("foo"),
+ table2.getColumnByName("foo"),
+ table1.getColumnByName("bar"),
+ table2.getColumnByName("baz")).toQuery();
+ assertEquals(
+ "SELECT table.foo, table.foo, table.bar, table.baz "
+ + "FROM schema.table LEFT JOIN schema.table ON table.foo = table.foo",
+ q.toSql());
+
+ DataSet ds = composite.executeQuery(q);
+ assertTrue(ds.next());
+ assertEquals("Row[values=[1, 1, hello, world]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[2, 2, dc1, world]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[3, 3, hi, dc2]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[4, 4, yo, world]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/MetaModelHelperTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/MetaModelHelperTest.java b/core/src/test/java/org/apache/metamodel/MetaModelHelperTest.java
new file mode 100644
index 0000000..50c1ad1
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/MetaModelHelperTest.java
@@ -0,0 +1,327 @@
+/**
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.DataSetHeader;
+import org.eobjects.metamodel.data.DefaultRow;
+import org.eobjects.metamodel.data.EmptyDataSet;
+import org.eobjects.metamodel.data.InMemoryDataSet;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.data.SimpleDataSetHeader;
+import org.eobjects.metamodel.data.SubSelectionDataSet;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.JoinType;
+import org.eobjects.metamodel.query.OperatorType;
+import org.eobjects.metamodel.query.OrderByItem;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+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;
+
+public class MetaModelHelperTest extends MetaModelTestCase {
+
+ public void testLeftJoin() throws Exception {
+ SelectItem si1 = new SelectItem(new MutableColumn("person_id", ColumnType.INTEGER));
+ SelectItem si2 = new SelectItem(new MutableColumn("person_name", ColumnType.VARCHAR));
+ SelectItem si3 = new SelectItem(new MutableColumn("person_age", ColumnType.INTEGER));
+ SelectItem si4 = new SelectItem(new MutableColumn("person_role_id", ColumnType.INTEGER));
+ SelectItem si5 = new SelectItem(new MutableColumn("role_id", ColumnType.INTEGER));
+ SelectItem si6 = new SelectItem(new MutableColumn("role_name", ColumnType.VARCHAR));
+ SelectItem si7 = new SelectItem(new MutableColumn("role_code", ColumnType.VARCHAR));
+ List<Object[]> data1 = new ArrayList<Object[]>();
+ data1.add(new Object[] { 1, "peter", 18, 1 });
+ data1.add(new Object[] { 2, "tom", 19, 2 });
+ data1.add(new Object[] { 3, "betty", 19, null });
+ data1.add(new Object[] { 4, "barbara", 17, 3 });
+ data1.add(new Object[] { 5, "susie", 18, 4 });
+
+ List<Object[]> data2 = new ArrayList<Object[]>();
+ data2.add(new Object[] { 1, "class president", "clpr" });
+ data2.add(new Object[] { 2, "bad boy", "bb" });
+ data2.add(new Object[] { 4, "trying harder", "try" });
+
+ DataSet ds1 = createDataSet(new SelectItem[] { si1, si2, si3, si4 }, data1);
+ DataSet ds2 = createDataSet(new SelectItem[] { si5, si6, si7 }, data2);
+ FilterItem[] onConditions = new FilterItem[1];
+ onConditions[0] = new FilterItem(si4, OperatorType.EQUALS_TO, si5);
+
+ DataSet result = MetaModelHelper.getLeftJoin(ds1, ds2, onConditions);
+ List<Object[]> objectArrays = result.toObjectArrays();
+ assertEquals("[1, peter, 18, 1, 1, class president, clpr]", Arrays.toString(objectArrays.get(0)));
+ assertEquals("[2, tom, 19, 2, 2, bad boy, bb]", Arrays.toString(objectArrays.get(1)));
+ assertEquals("[3, betty, 19, null, null, null, null]", Arrays.toString(objectArrays.get(2)));
+ assertEquals("[4, barbara, 17, 3, null, null, null]", Arrays.toString(objectArrays.get(3)));
+ assertEquals("[5, susie, 18, 4, 4, trying harder, try]", Arrays.toString(objectArrays.get(4)));
+ assertEquals(5, objectArrays.size());
+ }
+
+ public void testRightJoin() throws Exception {
+ SelectItem si1 = new SelectItem(new MutableColumn("person_id", ColumnType.INTEGER));
+ SelectItem si2 = new SelectItem(new MutableColumn("person_name", ColumnType.VARCHAR));
+ SelectItem si3 = new SelectItem(new MutableColumn("person_age", ColumnType.INTEGER));
+ SelectItem si4 = new SelectItem(new MutableColumn("person_role_id", ColumnType.INTEGER));
+ SelectItem si5 = new SelectItem(new MutableColumn("role_id", ColumnType.INTEGER));
+ SelectItem si6 = new SelectItem(new MutableColumn("role_name", ColumnType.VARCHAR));
+ SelectItem si7 = new SelectItem(new MutableColumn("role_code", ColumnType.VARCHAR));
+ List<Object[]> data1 = new ArrayList<Object[]>();
+ data1.add(new Object[] { 1, "peter", 18, 1 });
+ data1.add(new Object[] { 2, "tom", 19, 2 });
+ data1.add(new Object[] { 3, "betty", 19, null });
+ data1.add(new Object[] { 4, "barbara", 17, 3 });
+
+ List<Object[]> data2 = new ArrayList<Object[]>();
+ data2.add(new Object[] { 1, "class president", "clpr" });
+ data2.add(new Object[] { 2, "bad boy", "bb" });
+ data2.add(new Object[] { 4, "trying harder", "try" });
+
+ DataSet ds1 = createDataSet(new SelectItem[] { si1, si2, si3, si4 }, data1);
+ DataSet ds2 = createDataSet(new SelectItem[] { si5, si6, si7 }, data2);
+ FilterItem[] onConditions = new FilterItem[1];
+ onConditions[0] = new FilterItem(si4, OperatorType.EQUALS_TO, si5);
+
+ DataSet result = MetaModelHelper.getRightJoin(ds1, ds2, onConditions);
+ List<Object[]> objectArrays = result.toObjectArrays();
+ assertEquals("[1, peter, 18, 1, 1, class president, clpr]", Arrays.toString(objectArrays.get(0)));
+ assertEquals("[2, tom, 19, 2, 2, bad boy, bb]", Arrays.toString(objectArrays.get(1)));
+ assertEquals("[null, null, null, null, 4, trying harder, try]", Arrays.toString(objectArrays.get(2)));
+ assertEquals(3, objectArrays.size());
+ }
+
+ public void testSimpleCarthesianProduct() throws Exception {
+ DataSet dataSet = MetaModelHelper.getCarthesianProduct(createDataSet1(), createDataSet2());
+
+ assertEquals(2, dataSet.getSelectItems().length);
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[f, b]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[f, a]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[o, r]]", dataSet.getRow().toString());
+ assertFalse(dataSet.next());
+ }
+
+ public void testTripleCarthesianProduct() throws Exception {
+ DataSet dataSet = MetaModelHelper.getCarthesianProduct(createDataSet1(), createDataSet2(), createDataSet3());
+ assertEquals(4, dataSet.getSelectItems().length);
+ for (int i = 0; i < 3 * 3 * 2; i++) {
+ assertTrue("Assertion failed at i=" + i, dataSet.next());
+ }
+ assertFalse(dataSet.next());
+ }
+
+ public void testTripleCarthesianProductWithWhereItems() throws Exception {
+ DataSet ds1 = createDataSet1();
+ DataSet ds2 = createDataSet2();
+ DataSet[] dataSets = new DataSet[] { ds1, ds2, };
+ FilterItem w1 = new FilterItem(ds1.getSelectItems()[0], OperatorType.EQUALS_TO, "f");
+ DataSet dataSet = MetaModelHelper.getCarthesianProduct(dataSets, w1);
+ assertEquals(2, dataSet.getSelectItems().length);
+ for (int i = 0; i < 1 * 3; i++) {
+ assertTrue("Assertion failed at i=" + i, dataSet.next());
+ assertEquals("f", dataSet.getRow().getValue(0));
+ }
+ assertFalse(dataSet.next());
+ }
+
+ public void testGetCarthesianProductNoRows() throws Exception {
+ DataSet dataSet = MetaModelHelper.getCarthesianProduct(createDataSet4(), createDataSet2(), createDataSet3());
+ assertEquals(4, dataSet.getSelectItems().length);
+ assertFalse(dataSet.next());
+
+ dataSet = MetaModelHelper.getCarthesianProduct(createDataSet1(), createDataSet4(), createDataSet3());
+ assertEquals(4, dataSet.getSelectItems().length);
+ assertFalse(dataSet.next());
+
+ dataSet = MetaModelHelper.getCarthesianProduct(createDataSet1(), createDataSet2(), createDataSet4());
+ assertEquals(3, dataSet.getSelectItems().length);
+ assertFalse(dataSet.next());
+ }
+
+ public void testGetOrdered() throws Exception {
+ DataSet dataSet = createDataSet3();
+ List<OrderByItem> orderByItems = new ArrayList<OrderByItem>();
+ orderByItems.add(new OrderByItem(dataSet.getSelectItems()[0]));
+
+ dataSet = MetaModelHelper.getOrdered(dataSet, orderByItems);
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[w00p, true]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[yippie, false]]", dataSet.getRow().toString());
+ assertFalse(dataSet.next());
+ }
+
+ private DataSet createDataSet1() {
+ List<Object[]> data1 = new ArrayList<Object[]>();
+ data1.add(new Object[] { "f" });
+ data1.add(new Object[] { "o" });
+ data1.add(new Object[] { "o" });
+ DataSet dataSet1 = createDataSet(
+ new SelectItem[] { new SelectItem(new MutableColumn("foo", ColumnType.VARCHAR)) }, data1);
+ return dataSet1;
+ }
+
+ private DataSet createDataSet2() {
+ List<Object[]> data2 = new ArrayList<Object[]>();
+ data2.add(new Object[] { "b" });
+ data2.add(new Object[] { "a" });
+ data2.add(new Object[] { "r" });
+ DataSet dataSet2 = createDataSet(new SelectItem[] { new SelectItem("bar", "bar") }, data2);
+ return dataSet2;
+ }
+
+ private DataSet createDataSet3() {
+ List<Object[]> data3 = new ArrayList<Object[]>();
+ data3.add(new Object[] { "w00p", true });
+ data3.add(new Object[] { "yippie", false });
+ DataSet dataSet3 = createDataSet(new SelectItem[] { new SelectItem("expression", "e"),
+ new SelectItem("webish?", "w") }, data3);
+ return dataSet3;
+ }
+
+ private DataSet createDataSet4() {
+ List<Object[]> data4 = new ArrayList<Object[]>();
+ DataSet dataSet4 = createDataSet(new SelectItem[] { new SelectItem("abc", "abc") }, data4);
+ return dataSet4;
+ }
+
+ public void testGetTables() throws Exception {
+ MutableTable table1 = new MutableTable("table1");
+ MutableTable table2 = new MutableTable("table2");
+ MutableColumn t1column1 = new MutableColumn("t1c1", ColumnType.BIGINT);
+ MutableColumn t2column1 = new MutableColumn("t2c1", ColumnType.BIGINT);
+ MutableColumn t2column2 = new MutableColumn("t2c2", ColumnType.BIGINT);
+ table1.addColumn(t1column1);
+ t1column1.setTable(table1);
+ table2.addColumn(t2column1);
+ t2column1.setTable(table2);
+ table2.addColumn(t2column2);
+ t2column2.setTable(table2);
+
+ ArrayList<Table> tableList = new ArrayList<Table>();
+ tableList.add(table1);
+
+ ArrayList<Column> columnList = new ArrayList<Column>();
+ columnList.add(t2column1);
+
+ Table[] tables = MetaModelHelper.getTables(tableList, columnList);
+ assertEquals(2, tables.length);
+ assertTrue(Arrays.asList(tables).contains(table1));
+ assertTrue(Arrays.asList(tables).contains(table2));
+ }
+
+ public void testGetTableColumns() throws Exception {
+ MutableTable table1 = new MutableTable("table1");
+ MutableColumn column1 = new MutableColumn("c1", ColumnType.BIGINT);
+ MutableColumn column2 = new MutableColumn("c2", ColumnType.BIGINT);
+ MutableColumn column3 = new MutableColumn("c3", ColumnType.BIGINT);
+ table1.addColumn(column1);
+ column1.setTable(table1);
+ table1.addColumn(column2);
+ column2.setTable(table1);
+ table1.addColumn(column3);
+ column3.setTable(table1);
+
+ ArrayList<Column> columnList = new ArrayList<Column>();
+
+ Column[] columns = MetaModelHelper.getTableColumns(table1, columnList);
+ assertEquals(0, columns.length);
+
+ columnList.add(column1);
+ columnList.add(column3);
+
+ columns = MetaModelHelper.getTableColumns(table1, columnList);
+ assertEquals(2, columns.length);
+ assertSame(column1, columns[0]);
+ assertSame(column3, columns[1]);
+ }
+
+ public void testGetTableFromItems() throws Exception {
+ Schema schema = getExampleSchema();
+ Table contributorTable = schema.getTableByName(TABLE_CONTRIBUTOR);
+ Table projectTable = schema.getTableByName(TABLE_PROJECT);
+ Table projectContributorTable = schema.getTableByName(TABLE_PROJECT_CONTRIBUTOR);
+
+ FromItem sqFromItem = new FromItem(new Query().from(projectTable).from(projectContributorTable));
+ FromItem fromItem = new FromItem(JoinType.INNER, new FromItem(contributorTable), sqFromItem, new SelectItem[0],
+ new SelectItem[0]);
+ Query q = new Query().from(fromItem);
+
+ FromItem[] fromItems = MetaModelHelper.getTableFromItems(q);
+ assertEquals(3, fromItems.length);
+ assertEquals("[MetaModelSchema.contributor, MetaModelSchema.project, MetaModelSchema.project_contributor]",
+ Arrays.toString(fromItems));
+ }
+
+ public void testGetSelectionNoRows() throws Exception {
+ SelectItem item1 = new SelectItem("foo", "f");
+ SelectItem item2 = new SelectItem("bar", "b");
+ SelectItem item3 = new SelectItem("baz", "bz");
+ List<SelectItem> selectItems1 = Arrays.asList(item1, item2, item3);
+ List<SelectItem> selectItems2 = Arrays.asList(item2, item1);
+
+ DataSet ds = MetaModelHelper.getSelection(selectItems2, new EmptyDataSet(selectItems1));
+ assertEquals(SubSelectionDataSet.class, ds.getClass());
+
+ assertEquals("[bar AS b, foo AS f]", Arrays.toString(ds.getSelectItems()));
+ }
+
+ public void testLeftJoinNoRowsOrSingleRow() throws Exception {
+ SelectItem item1 = new SelectItem("foo", "f");
+ SelectItem item2 = new SelectItem("bar", "b");
+ SelectItem item3 = new SelectItem("baz", "z");
+ List<SelectItem> selectItems1 = Arrays.asList(item1, item2);
+ List<SelectItem> selectItems2 = Arrays.asList(item3);
+
+ DataSet ds1 = new EmptyDataSet(selectItems1);
+ DataSet ds2 = new EmptyDataSet(selectItems2);
+
+ DataSet joinedDs = MetaModelHelper.getLeftJoin(ds1, ds2, new FilterItem[] { new FilterItem(item2,
+ OperatorType.EQUALS_TO, item3) });
+
+ assertEquals(SubSelectionDataSet.class, joinedDs.getClass());
+ assertEquals("[foo AS f, bar AS b, baz AS z]", Arrays.toString(joinedDs.getSelectItems()));
+
+ DataSetHeader header1 = new SimpleDataSetHeader(selectItems1);
+ Row row = new DefaultRow(header1, new Object[] { 1, 2 }, null);
+ ds1 = new InMemoryDataSet(header1, row);
+
+ joinedDs = MetaModelHelper.getLeftJoin(ds1, ds2, new FilterItem[] { new FilterItem(item2,
+ OperatorType.EQUALS_TO, item3) });
+ assertEquals("[foo AS f, bar AS b, baz AS z]", Arrays.toString(joinedDs.getSelectItems()));
+ assertTrue(joinedDs.next());
+ assertEquals("Row[values=[1, 2, null]]", joinedDs.getRow().toString());
+ assertFalse(joinedDs.next());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/MetaModelTestCase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/MetaModelTestCase.java b/core/src/test/java/org/apache/metamodel/MetaModelTestCase.java
new file mode 100644
index 0000000..6f3e5b1
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/MetaModelTestCase.java
@@ -0,0 +1,199 @@
+/**
+ * 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;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.easymock.EasyMock;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.DefaultRow;
+import org.eobjects.metamodel.data.EmptyDataSet;
+import org.eobjects.metamodel.data.InMemoryDataSet;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.data.SimpleDataSetHeader;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.schema.MutableRelationship;
+import org.eobjects.metamodel.schema.MutableSchema;
+import org.eobjects.metamodel.schema.MutableTable;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.TableType;
+
+/**
+ * Convenient super-class to use for unittesting
+ */
+public abstract class MetaModelTestCase extends TestCase {
+
+ public static final String COLUMN_CONTRIBUTOR_COUNTRY = "country";
+ public static final String COLUMN_CONTRIBUTOR_NAME = "name";
+ public static final String COLUMN_CONTRIBUTOR_CONTRIBUTOR_ID = "contributor_id";
+
+ public static final String COLUMN_PROJECT_PROJECT_ID = "project_id";
+ public static final String COLUMN_PROJECT_NAME = "name";
+ public static final String COLUMN_PROJECT_LINES_OF_CODE = "lines_of_code";
+ public static final String COLUMN_PROJECT_PARENT_PROJECT_ID = "parent_project_id";
+
+ public static final String COLUMN_ROLE_PROJECT_ID = "project_id";
+ public static final String COLUMN_ROLE_CONTRIBUTOR_ID = "contributor_id";
+ public static final String COLUMN_ROLE_ROLE_NAME = "name";
+
+ public static final String COLUMN_PROJECT_CONTRIBUTOR_CONTRIBUTOR = "contributor";
+ public static final String COLUMN_PROJECT_CONTRIBUTOR_ROLE = "role";
+ public static final String COLUMN_PROJECT_CONTRIBUTOR_PROJECT = "project";
+
+ public static final String TABLE_PROJECT_CONTRIBUTOR = "project_contributor";
+ public static final String TABLE_ROLE = "role";
+ public static final String TABLE_PROJECT = "project";
+ public static final String TABLE_CONTRIBUTOR = "contributor";
+
+ /**
+ * Creates an example schema with three tables and a view:
+ * <ul>
+ * <li>contributor[contributor_id,name,country] (TABLE)</li>
+ * <li>project[project_id,name,lines_of_code,parent_project_id] (TABLE)</li>
+ * <li>role[contributor_id,project_id,role_name] (TABLE)</li>
+ * <li>project_contributor[contributor,project,role] (VIEW)</li>
+ * </ul>
+ * The example schema is good for testing purposes and possess various
+ * features of the schema model:
+ * <ul>
+ * <li>Relations between tables: one-Contributor-to-many-Role's and
+ * many-Role's-to-one-Project</li>
+ * <li>Recursive relations: A project can have a parent project</li>
+ * <li>Views: The ProjectContributor view</li>
+ * </ul>
+ */
+ protected Schema getExampleSchema() {
+ MutableSchema schema = new MutableSchema("MetaModelSchema");
+
+ MutableTable table1 = new MutableTable(TABLE_CONTRIBUTOR, TableType.TABLE, schema);
+ Column column1 = new MutableColumn(COLUMN_CONTRIBUTOR_CONTRIBUTOR_ID, ColumnType.INTEGER, table1, 0, false)
+ .setIndexed(true).setPrimaryKey(true);
+ Column column2 = new MutableColumn(COLUMN_CONTRIBUTOR_NAME, ColumnType.VARCHAR, table1, 1, false);
+ Column column3 = new MutableColumn(COLUMN_CONTRIBUTOR_COUNTRY, ColumnType.VARCHAR, table1, 2, true);
+ table1.setColumns(column1, column2, column3);
+
+ MutableTable table2 = new MutableTable(TABLE_PROJECT, TableType.TABLE, schema);
+ Column column4 = new MutableColumn(COLUMN_PROJECT_PROJECT_ID, ColumnType.INTEGER, table2, 0, false)
+ .setPrimaryKey(true);
+ Column column5 = new MutableColumn(COLUMN_PROJECT_NAME, ColumnType.VARCHAR, table2, 1, false);
+ Column column6 = new MutableColumn(COLUMN_PROJECT_LINES_OF_CODE, ColumnType.BIGINT, table2, 2, true);
+ Column column7 = new MutableColumn(COLUMN_PROJECT_PARENT_PROJECT_ID, ColumnType.INTEGER, table2, 3, true);
+ table2.setColumns(column4, column5, column6, column7);
+
+ MutableTable table3 = new MutableTable(TABLE_ROLE, TableType.TABLE, schema);
+ Column column8 = new MutableColumn(COLUMN_ROLE_CONTRIBUTOR_ID, ColumnType.INTEGER, table3, 0, false)
+ .setPrimaryKey(true);
+ Column column9 = new MutableColumn(COLUMN_ROLE_PROJECT_ID, ColumnType.INTEGER, table3, 1, false)
+ .setPrimaryKey(true);
+ Column column10 = new MutableColumn(COLUMN_ROLE_ROLE_NAME, ColumnType.VARCHAR, table3, 2, false);
+ table3.setColumns(column8, column9, column10);
+
+ MutableTable table4 = new MutableTable(TABLE_PROJECT_CONTRIBUTOR, TableType.VIEW, schema);
+ Column column11 = new MutableColumn(COLUMN_PROJECT_CONTRIBUTOR_CONTRIBUTOR, ColumnType.VARCHAR, table4, 0,
+ false);
+ Column column12 = new MutableColumn(COLUMN_PROJECT_CONTRIBUTOR_PROJECT, ColumnType.VARCHAR, table4, 1, false);
+ Column column13 = new MutableColumn(COLUMN_PROJECT_CONTRIBUTOR_ROLE, ColumnType.VARCHAR, table4, 2, false);
+ ArrayList<Column> columnList = new ArrayList<Column>();
+ columnList.add(column11);
+ columnList.add(column12);
+ columnList.add(column13);
+ table4.setColumns(columnList);
+
+ // one-Contributor-to-many-Role's
+ MutableRelationship.createRelationship(new Column[] { column1 }, new Column[] { column8 });
+
+ // one-Project-to-many-Role's
+ MutableRelationship.createRelationship(new Column[] { column4 }, new Column[] { column9 });
+
+ // view relation [contributor -> contributor_name]
+ MutableRelationship.createRelationship(new Column[] { column2 }, new Column[] { column11 });
+
+ // view relation [project -> project_name]
+ MutableRelationship.createRelationship(new Column[] { column5 }, new Column[] { column12 });
+
+ // view relation [role -> role_name]
+ MutableRelationship.createRelationship(new Column[] { column10 }, new Column[] { column13 });
+
+ schema.setTables(table1, table2, table3, table4);
+ return schema;
+ }
+
+ protected static DataSet createDataSet(SelectItem[] selectItems, List<Object[]> data) {
+ if (data.isEmpty()) {
+ return new EmptyDataSet(selectItems);
+ }
+
+ SimpleDataSetHeader header = new SimpleDataSetHeader(selectItems);
+
+ List<Row> rows = new ArrayList<Row>();
+ for (Object[] objects : data) {
+ rows.add(new DefaultRow(header, objects));
+ }
+ return new InMemoryDataSet(header, rows);
+ }
+
+ private List<Object> _mocks = new ArrayList<Object>();
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ _mocks.clear();
+ }
+
+ public <T extends Object> T createMock(Class<T> clazz) {
+ T mock = EasyMock.createMock(clazz);
+ _mocks.add(mock);
+ return mock;
+ }
+
+ public void verifyMocks() {
+ EasyMock.verify(_mocks.toArray());
+ }
+
+ public void replayMocks() {
+ EasyMock.replay(_mocks.toArray());
+ }
+
+ public void assertEquals(DataSet ds1, DataSet ds2) {
+ assertEquals(Arrays.toString(ds1.getSelectItems()), Arrays.toString(ds2.getSelectItems()));
+ boolean ds1next = true;
+ while (ds1next) {
+ ds1next = ds1.next();
+ boolean ds2next = ds2.next();
+ assertEquals("DataSet 1 next=" + ds1next, ds1next, ds2next);
+ if (ds1next) {
+ Row row1 = ds1.getRow();
+ Row row2 = ds2.getRow();
+ assertEquals(row1, row2);
+ }
+ }
+ }
+
+ protected File getTestResourceAsFile(String filename) {
+ return new File("src/test/resources/" + filename);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/MockDataContext.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/MockDataContext.java b/core/src/test/java/org/apache/metamodel/MockDataContext.java
new file mode 100644
index 0000000..5d95034
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/MockDataContext.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;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eobjects.metamodel.data.CachingDataSetHeader;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.DataSetHeader;
+import org.eobjects.metamodel.data.DefaultRow;
+import org.eobjects.metamodel.data.EmptyDataSet;
+import org.eobjects.metamodel.data.InMemoryDataSet;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+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.Table;
+
+public class MockDataContext extends QueryPostprocessDataContext {
+
+ private final String _schemaName;
+ private final String _tableName;
+ private final String _value;
+
+ public MockDataContext(String schemaName, String tableName, String value) {
+ _schemaName = schemaName;
+ _tableName = tableName;
+ _value = value;
+ }
+
+ @Override
+ protected Schema getMainSchema() throws MetaModelException {
+
+ final MutableSchema schema = new MutableSchema(_schemaName);
+ final MutableTable primaryTable = new MutableTable(_tableName).setSchema(schema);
+ primaryTable.addColumn(new MutableColumn("foo").setColumnNumber(0).setType(ColumnType.VARCHAR).setTable(primaryTable));
+ primaryTable.addColumn(new MutableColumn("bar").setColumnNumber(1).setType(ColumnType.VARCHAR).setTable(primaryTable));
+ primaryTable.addColumn(new MutableColumn("baz").setColumnNumber(2).setType(ColumnType.VARCHAR).setTable(primaryTable));
+
+ final MutableTable emptyTable = new MutableTable("an_empty_table").setSchema(schema);
+ emptyTable.addColumn(new MutableColumn("foo").setColumnNumber(0).setType(ColumnType.VARCHAR).setTable(emptyTable));
+ emptyTable.addColumn(new MutableColumn("bar").setColumnNumber(1).setType(ColumnType.VARCHAR).setTable(emptyTable));
+
+ schema.addTable(primaryTable);
+ schema.addTable(emptyTable);
+
+ return schema;
+ }
+
+ @Override
+ protected String getMainSchemaName() throws MetaModelException {
+ return _schemaName;
+ }
+
+ @Override
+ protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+ if (_tableName.equals(table.getName())) {
+ final SelectItem[] allSelectItems = MetaModelHelper.createSelectItems(table.getColumns());
+ final DataSetHeader header = new CachingDataSetHeader(allSelectItems);
+ final List<Row> data = new ArrayList<Row>();
+ data.add(new DefaultRow(header, new Object[] { "1", "hello", "world" }, null));
+ data.add(new DefaultRow(header, new Object[] { "2", _value, "world" }, null));
+ data.add(new DefaultRow(header, new Object[] { "3", "hi", _value }, null));
+ data.add(new DefaultRow(header, new Object[] { "4", "yo", "world" }, null));
+
+ DataSet ds = new InMemoryDataSet(header, data);
+
+ SelectItem[] columnSelectItems = MetaModelHelper.createSelectItems(columns);
+ ds = MetaModelHelper.getSelection(columnSelectItems, ds);
+
+ return ds;
+ } else if ("an_empty_table".equals(table.getName())) {
+ return new EmptyDataSet(columns);
+ }
+ throw new UnsupportedOperationException();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/apache/metamodel/MockUpdateableDataContext.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/MockUpdateableDataContext.java b/core/src/test/java/org/apache/metamodel/MockUpdateableDataContext.java
new file mode 100644
index 0000000..f1b7f49
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/MockUpdateableDataContext.java
@@ -0,0 +1,181 @@
+/**
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eobjects.metamodel.create.TableCreationBuilder;
+import org.eobjects.metamodel.data.CachingDataSetHeader;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.DefaultRow;
+import org.eobjects.metamodel.data.EmptyDataSet;
+import org.eobjects.metamodel.data.InMemoryDataSet;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.delete.AbstractRowDeletionBuilder;
+import org.eobjects.metamodel.delete.RowDeletionBuilder;
+import org.eobjects.metamodel.drop.TableDropBuilder;
+import org.eobjects.metamodel.insert.AbstractRowInsertionBuilder;
+import org.eobjects.metamodel.insert.RowInsertionBuilder;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+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.Table;
+
+public class MockUpdateableDataContext extends QueryPostprocessDataContext implements UpdateableDataContext {
+
+ private final List<Object[]> _values = new ArrayList<Object[]>();
+
+ private final MutableTable _table;
+ private final MutableSchema _schema;
+
+ public MockUpdateableDataContext() {
+ _values.add(new Object[] { "1", "hello" });
+ _values.add(new Object[] { "2", "there" });
+ _values.add(new Object[] { "3", "world" });
+
+ _table = new MutableTable("table");
+ _table.addColumn(new MutableColumn("foo", ColumnType.VARCHAR).setTable(_table).setColumnNumber(0));
+ _table.addColumn(new MutableColumn("bar", ColumnType.VARCHAR).setTable(_table).setColumnNumber(1));
+ _schema = new MutableSchema("schema", _table);
+ _table.setSchema(_schema);
+ }
+
+ public MutableTable getTable() {
+ return _table;
+ }
+
+ @Override
+ protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+
+ List<Row> rows = new ArrayList<Row>();
+ SelectItem[] items = MetaModelHelper.createSelectItems(columns);
+ CachingDataSetHeader header = new CachingDataSetHeader(items);
+
+ for (final Object[] values : _values) {
+ Object[] rowValues = new Object[columns.length];
+ for (int i = 0; i < columns.length; i++) {
+ int columnNumber = columns[i].getColumnNumber();
+ rowValues[i] = values[columnNumber];
+ }
+ rows.add(new DefaultRow(header, rowValues));
+ }
+
+ if (rows.isEmpty()) {
+ return new EmptyDataSet(items);
+ }
+ return new InMemoryDataSet(header, rows);
+ }
+
+ @Override
+ protected String getMainSchemaName() throws MetaModelException {
+ return _schema.getName();
+ }
+
+ @Override
+ protected Schema getMainSchema() throws MetaModelException {
+ return _schema;
+ }
+
+ @Override
+ public void executeUpdate(UpdateScript update) {
+ update.run(new AbstractUpdateCallback(this) {
+
+ @Override
+ public boolean isDeleteSupported() {
+ return true;
+ }
+
+ @Override
+ public RowDeletionBuilder deleteFrom(Table table) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException {
+ return new AbstractRowDeletionBuilder(table) {
+ @Override
+ public void execute() throws MetaModelException {
+ delete(getWhereItems());
+ }
+ };
+ }
+
+ @Override
+ public RowInsertionBuilder insertInto(Table table) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException {
+ return new AbstractRowInsertionBuilder<UpdateCallback>(this, table) {
+
+ @Override
+ public void execute() throws MetaModelException {
+ Object[] values = toRow().getValues();
+ _values.add(values);
+ }
+ };
+ }
+
+ @Override
+ public boolean isDropTableSupported() {
+ return false;
+ }
+
+ @Override
+ public boolean isCreateTableSupported() {
+ return false;
+ }
+
+ @Override
+ public TableDropBuilder dropTable(Table table) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public TableCreationBuilder createTable(Schema schema, String name) throws IllegalArgumentException,
+ IllegalStateException {
+ throw new UnsupportedOperationException();
+ }
+ });
+ }
+
+ private void delete(List<FilterItem> whereItems) {
+ final SelectItem[] selectItems = MetaModelHelper.createSelectItems(_table.getColumns());
+ final CachingDataSetHeader header = new CachingDataSetHeader(selectItems);
+ for (Iterator<Object[]> it = _values.iterator(); it.hasNext();) {
+ Object[] values = (Object[]) it.next();
+ DefaultRow row = new DefaultRow(header, values);
+ boolean delete = true;
+ for (FilterItem filterItem : whereItems) {
+ if (!filterItem.evaluate(row)) {
+ delete = false;
+ break;
+ }
+ }
+ if (delete) {
+ it.remove();
+ }
+ }
+ }
+
+ public List<Object[]> getValues() {
+ return _values;
+ }
+}
[35/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/delete/DeleteFrom.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/delete/DeleteFrom.java b/core/src/main/java/org/eobjects/metamodel/delete/DeleteFrom.java
deleted file mode 100644
index 6e6751e..0000000
--- a/core/src/main/java/org/eobjects/metamodel/delete/DeleteFrom.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/**
- * 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.delete;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.WhereClauseBuilder;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.query.builder.AbstractFilterBuilder;
-import org.eobjects.metamodel.query.builder.FilterBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * Represents a single DELETE FROM 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 delete from
- * implementation. Some {@link DataContext}s may even optimize specifically
- * based on the knowledge that there will only be a single delete from statement
- * executed.
- */
-public final class DeleteFrom implements UpdateScript, WhereClauseBuilder<DeleteFrom> {
-
- private final List<FilterItem> _whereItems;
- private final Table _table;
-
- public DeleteFrom(Table table) {
- _table = table;
- _whereItems = new ArrayList<FilterItem>();
- }
-
- @Override
- public void run(UpdateCallback callback) {
- callback.deleteFrom(_table).where(_whereItems).execute();
- }
-
- @Override
- public FilterBuilder<DeleteFrom> where(Column column) {
- SelectItem selectItem = new SelectItem(column);
- return new AbstractFilterBuilder<DeleteFrom>(selectItem) {
- @Override
- protected DeleteFrom applyFilter(FilterItem filter) {
- return where(filter);
- }
- };
- }
-
- @Override
- public FilterBuilder<DeleteFrom> where(String columnName) {
- Column column = _table.getColumnByName(columnName);
- if (column == null) {
- throw new IllegalArgumentException("No such column: " + columnName);
- }
- return where(column);
- }
-
- @Override
- public DeleteFrom where(FilterItem... filterItems) {
- for (FilterItem filterItem : filterItems) {
- _whereItems.add(filterItem);
- }
- return this;
- }
-
- @Override
- public DeleteFrom where(Iterable<FilterItem> filterItems) {
- for (FilterItem filterItem : filterItems) {
- _whereItems.add(filterItem);
- }
- return this;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/delete/RowDeletable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/delete/RowDeletable.java b/core/src/main/java/org/eobjects/metamodel/delete/RowDeletable.java
deleted file mode 100644
index 0c25c04..0000000
--- a/core/src/main/java/org/eobjects/metamodel/delete/RowDeletable.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * 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.delete;
-
-import org.eobjects.metamodel.schema.Table;
-
-public interface RowDeletable {
-
- /**
- * Determines whether row delete is supported
- *
- * @return true if row delete is supported
- */
- public boolean isDeleteSupported();
-
- /**
- * Initiates a row deletion builder.
- *
- * @param table
- * @return
- * @throws IllegalArgumentException
- * @throws IllegalStateException
- * @throws UnsupportedOperationException
- */
- public RowDeletionBuilder deleteFrom(Table table) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException;
-
- /**
- * Initiates a row deletion builder.
- *
- * @param tableName
- * @return
- * @throws IllegalArgumentException
- * @throws IllegalStateException
- * @throws UnsupportedOperationException
- */
- public RowDeletionBuilder deleteFrom(String tableName) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException;
-
- /**
- * Initiates a row deletion builder.
- *
- * @param schemaName
- * @param tableName
- * @return
- * @throws IllegalArgumentException
- * @throws IllegalStateException
- * @throws UnsupportedOperationException
- */
- public RowDeletionBuilder deleteFrom(String schemaName, String tableName) throws IllegalArgumentException,
- IllegalStateException, UnsupportedOperationException;
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/delete/RowDeletionBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/delete/RowDeletionBuilder.java b/core/src/main/java/org/eobjects/metamodel/delete/RowDeletionBuilder.java
deleted file mode 100644
index 308b096..0000000
--- a/core/src/main/java/org/eobjects/metamodel/delete/RowDeletionBuilder.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * 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.delete;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.WhereClauseBuilder;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * Builder object for row deletions in a {@link Table}.
- *
- * @author Kasper Sørensen
- */
-public interface RowDeletionBuilder extends WhereClauseBuilder<RowDeletionBuilder> {
-
- /**
- * Gets the table that this delete statement pertains to.
- *
- * @return the table that this delete statement pertains to.
- */
- public Table getTable();
-
- /**
- * Gets a SQL representation of this delete 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 delete operation.
- */
- public String toSql();
-
- /**
- * Commits the row deletion operation. This operation will delete rows in
- * the {@link DataContext}.
- *
- * @throws MetaModelException
- * if the operation was rejected
- */
- public void execute() throws MetaModelException;
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/delete/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/delete/package-info.java b/core/src/main/java/org/eobjects/metamodel/delete/package-info.java
deleted file mode 100644
index a84729f..0000000
--- a/core/src/main/java/org/eobjects/metamodel/delete/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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 deleting rows
- */
-package org.eobjects.metamodel.delete;
-
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/drop/AbstractTableDropBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/drop/AbstractTableDropBuilder.java b/core/src/main/java/org/eobjects/metamodel/drop/AbstractTableDropBuilder.java
deleted file mode 100644
index ac56795..0000000
--- a/core/src/main/java/org/eobjects/metamodel/drop/AbstractTableDropBuilder.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * 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.drop;
-
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * Abstract {@link TableDropBuilder} implementation
- */
-public abstract class AbstractTableDropBuilder implements TableDropBuilder {
-
- private final Table _table;
-
- public AbstractTableDropBuilder(Table table) {
- if (table == null) {
- throw new IllegalArgumentException("Table cannot be null");
- }
- _table = table;
- }
-
- @Override
- public final Table getTable() {
- return _table;
- }
-
- @Override
- public String toString() {
- return toSql();
- }
-
- @Override
- public String toSql() {
- return "DROP TABLE " + _table.getQualifiedLabel();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/drop/DropTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/drop/DropTable.java b/core/src/main/java/org/eobjects/metamodel/drop/DropTable.java
deleted file mode 100644
index 042208b..0000000
--- a/core/src/main/java/org/eobjects/metamodel/drop/DropTable.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * 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.drop;
-
-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.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * Represents a single DROP 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 drop table
- * implementation. Some {@link DataContext}s may even optimize specifically
- * based on the knowledge that there will only be a single table dropped.
- */
-public final class DropTable implements UpdateScript {
-
- private final String _schemaName;
- private final String _tableName;
-
- public DropTable(Table table) {
- this(table.getSchema().getName(), table.getName());
- }
-
- public DropTable(String tableName) {
- this((String) null, tableName);
- }
-
- public DropTable(Schema schema, String tableName) {
- this(schema.getName(), tableName);
- }
-
- public DropTable(String schemaName, String tableName) {
- _schemaName = schemaName;
- _tableName = tableName;
- }
-
- @Override
- public void run(UpdateCallback callback) {
- final TableDropBuilder dropBuilder;
- if (_schemaName == null) {
- dropBuilder = callback.dropTable(_tableName);
- } else {
- dropBuilder = callback.dropTable(_schemaName, _tableName);
- }
- dropBuilder.execute();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/drop/TableDropBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/drop/TableDropBuilder.java b/core/src/main/java/org/eobjects/metamodel/drop/TableDropBuilder.java
deleted file mode 100644
index d1ac018..0000000
--- a/core/src/main/java/org/eobjects/metamodel/drop/TableDropBuilder.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * 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.drop;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.schema.Table;
-
-public interface TableDropBuilder {
-
- /**
- * Gets the table that this drop statement pertains to
- *
- * @return the table that this drop statement pertains to
- */
- public Table getTable();
-
- /**
- * Gets a SQL representation of this drop 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 drop table operation.
- */
- public String toSql();
-
- /**
- * Executes the drop table operation
- *
- * @throws MetaModelException
- * if the operation was rejected
- */
- public void execute() throws MetaModelException;
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/drop/TableDroppable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/drop/TableDroppable.java b/core/src/main/java/org/eobjects/metamodel/drop/TableDroppable.java
deleted file mode 100644
index 427bebb..0000000
--- a/core/src/main/java/org/eobjects/metamodel/drop/TableDroppable.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * 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.drop;
-
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-public interface TableDroppable {
-
- /**
- * Determines whether table drop is supported
- *
- * @return true if table drop is supported
- */
- public boolean isDropTableSupported();
-
- public TableDropBuilder dropTable(Schema schema, String tableName) throws IllegalArgumentException,
- IllegalStateException, UnsupportedOperationException;
-
- public TableDropBuilder dropTable(String schemaName, String tableName) throws IllegalArgumentException,
- IllegalStateException, UnsupportedOperationException;
-
- public TableDropBuilder dropTable(String tableName) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException;
-
- public TableDropBuilder dropTable(Table table) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException;
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/drop/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/drop/package-info.java b/core/src/main/java/org/eobjects/metamodel/drop/package-info.java
deleted file mode 100644
index 6c5e201..0000000
--- a/core/src/main/java/org/eobjects/metamodel/drop/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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 dropping tables
- */
-package org.eobjects.metamodel.drop;
-
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/insert/AbstractRowInsertionBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/insert/AbstractRowInsertionBuilder.java b/core/src/main/java/org/eobjects/metamodel/insert/AbstractRowInsertionBuilder.java
deleted file mode 100644
index 3308d1d..0000000
--- a/core/src/main/java/org/eobjects/metamodel/insert/AbstractRowInsertionBuilder.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * 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.insert;
-
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.data.AbstractRowBuilder;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * Abstract implementation of the {@link RowInsertionBuilder} interface,
- * provided as a convenience to {@link RowInsertable} implementations. Handles
- * all the building operations, but not the commit operation.
- *
- * @author Kasper Sørensen
- */
-public abstract class AbstractRowInsertionBuilder<U extends UpdateCallback> extends
- AbstractRowBuilder<RowInsertionBuilder> implements RowInsertionBuilder {
-
- private final U _updateCallback;
- private final Table _table;
-
- public AbstractRowInsertionBuilder(U updateCallback, Table table) {
- super(table);
- _updateCallback = updateCallback;
- _table = table;
- }
-
- @Override
- public Table getTable() {
- return _table;
- }
-
- protected U getUpdateCallback() {
- return _updateCallback;
- }
-
- @Override
- public RowInsertionBuilder like(Row row) {
- SelectItem[] selectItems = row.getSelectItems();
- for (int i = 0; i < selectItems.length; i++) {
- SelectItem selectItem = selectItems[i];
- Column column = selectItem.getColumn();
- if (column != null) {
- if (_table == column.getTable()) {
- value(column, row.getValue(i));
- } else {
- value(column.getName(), row.getValue(i));
- }
- }
- }
- return this;
- }
-
- @Override
- public String toSql() {
- StringBuilder sb = new StringBuilder();
- sb.append("INSERT INTO ");
- sb.append(_table.getQualifiedLabel());
- sb.append("(");
- Column[] columns = getColumns();
- for (int i = 0; i < columns.length; i++) {
- if (i != 0) {
- sb.append(',');
- }
- sb.append(columns[i].getName());
- }
- sb.append(") VALUES (");
- Object[] values = getValues();
- for (int i = 0; i < values.length; i++) {
- Object value = values[i];
- final String stringValue;
- if (value == null) {
- stringValue = "NULL";
- } else if (value instanceof String) {
- stringValue = "\"" + value + "\"";
- } else {
- stringValue = value.toString();
- }
- sb.append(stringValue);
- }
- sb.append(")");
- return sb.toString();
- }
-
- @Override
- public String toString() {
- return toSql();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/insert/InsertInto.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/insert/InsertInto.java b/core/src/main/java/org/eobjects/metamodel/insert/InsertInto.java
deleted file mode 100644
index 6dd057d..0000000
--- a/core/src/main/java/org/eobjects/metamodel/insert/InsertInto.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * 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.insert;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.AbstractRowBuilder;
-import org.eobjects.metamodel.data.RowBuilder;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * Represents a single INSERT INTO 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
- * single-record insertion implementation. Some {@link DataContext}s may even
- * optimize specifically based on the knowledge that there will only be a single
- * record inserted.
- */
-public final class InsertInto extends AbstractRowBuilder<InsertInto> implements UpdateScript, RowBuilder<InsertInto> {
-
- private final Table _table;
-
- public InsertInto(Table table) {
- super(table);
- _table = table;
- }
-
- @Override
- public void run(UpdateCallback callback) {
- RowInsertionBuilder insertBuilder = callback.insertInto(getTable());
-
- final Column[] columns = getColumns();
- final Object[] values = getValues();
- final Style[] styles = getStyles();
- final boolean[] explicitNulls = getExplicitNulls();
-
- for (int i = 0; i < columns.length; i++) {
- Object value = values[i];
- Column column = columns[i];
- Style style = styles[i];
- if (value == null) {
- if (explicitNulls[i]) {
- insertBuilder = insertBuilder.value(column, value, style);
- }
- } else {
- insertBuilder = insertBuilder.value(column, value, style);
- }
- }
-
- insertBuilder.execute();
- }
-
- @Override
- public Table getTable() {
- return _table;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/insert/RowInsertable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/insert/RowInsertable.java b/core/src/main/java/org/eobjects/metamodel/insert/RowInsertable.java
deleted file mode 100644
index 94c812b..0000000
--- a/core/src/main/java/org/eobjects/metamodel/insert/RowInsertable.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * 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.insert;
-
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * An interface for objects that support inserting rows into tables.
- *
- * @author Kasper Sørensen
- */
-public interface RowInsertable {
-
- /**
- * Determines whether row insertion is supported
- *
- * @return true if row insertion is supported
- */
- public boolean isInsertSupported();
-
- /**
- * Initiates the building of a row insertion operation.
- *
- * @param table
- * the table to insert a row into
- * @return a builder object on which values can be added and the statement
- * can be 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.
- * @throws UnsupportedOperationException
- * in case {@link #isInsertSupported()} is false
- */
- public RowInsertionBuilder insertInto(Table table) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException;
-
- /**
- * Initiates the building of a row insertion operation.
- *
- * @param tableName
- * the name of the table to insert a row into
- * @return a builder object on which values can be added and the statement
- * can be committed.
- * @throws IllegalArgumentException
- * if the tableName argument is null or invalid.
- * @throws IllegalStateException
- * if the connection to the DataContext is read-only or another
- * access restriction is preventing the operation.
- * @throws UnsupportedOperationException
- * in case {@link #isInsertSupported()} is false
- */
- public RowInsertionBuilder insertInto(String tableName) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException;
-
- /**
- * Initiates the building of a row insertion operation.
- *
- * @param schemaName
- * the name of the schema
- * @param tableName
- * the name of the table to insert a row into
- * @return a builder object on which values can be added and the statement
- * can be committed.
- * @throws IllegalArgumentException
- * if the tableName argument is null or invalid.
- * @throws IllegalStateException
- * if the connection to the DataContext is read-only or another
- * access restriction is preventing the operation.
- * @throws UnsupportedOperationException
- * in case {@link #isInsertSupported()} is false
- */
- public RowInsertionBuilder insertInto(String schemaName, String tableName) throws IllegalArgumentException,
- IllegalStateException, UnsupportedOperationException;
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/insert/RowInsertionBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/insert/RowInsertionBuilder.java b/core/src/main/java/org/eobjects/metamodel/insert/RowInsertionBuilder.java
deleted file mode 100644
index b2f0617..0000000
--- a/core/src/main/java/org/eobjects/metamodel/insert/RowInsertionBuilder.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * 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.insert;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.RowBuilder;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * Builder object for row insertion, into a {@link Table}.
- *
- * @author Kasper Sørensen
- */
-public interface RowInsertionBuilder extends RowBuilder<RowInsertionBuilder> {
-
- /**
- * Gets the table that this insert pertains to.
- *
- * @return the table that this insert pertains to.
- */
- @Override
- public Table getTable();
-
- /**
- * Sets all values like the provided row (for easy duplication of a row).
- *
- * @param row
- * the row from which to take values
- * @return the builder itself
- */
- public RowInsertionBuilder like(Row row);
-
- /**
- * Commits the row insertion operation. This operation will write the row to
- * the {@link DataContext}.
- *
- * @throws MetaModelException
- * if the operation was rejected
- */
- public void execute() throws MetaModelException;
-
- /**
- * Gets a SQL representation of this insert 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 insert operation.
- */
- public String toSql();
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/insert/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/insert/package-info.java b/core/src/main/java/org/eobjects/metamodel/insert/package-info.java
deleted file mode 100644
index 09f8b81..0000000
--- a/core/src/main/java/org/eobjects/metamodel/insert/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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 inserting rows
- */
-package org.eobjects.metamodel.insert;
-
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/intercept/DataSetInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/intercept/DataSetInterceptor.java b/core/src/main/java/org/eobjects/metamodel/intercept/DataSetInterceptor.java
deleted file mode 100644
index 77d61fa..0000000
--- a/core/src/main/java/org/eobjects/metamodel/intercept/DataSetInterceptor.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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.intercept;
-
-import org.eobjects.metamodel.data.DataSet;
-
-/**
- * An {@link Interceptor} for {@link DataSet}s, allowing to touch, enrich or
- * modify a dataset before it is returned to the user.
- *
- * @author Kasper Sørensen
- */
-public interface DataSetInterceptor extends Interceptor<DataSet> {
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableColumnCreationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableColumnCreationBuilder.java b/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableColumnCreationBuilder.java
deleted file mode 100644
index be95494..0000000
--- a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableColumnCreationBuilder.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/**
- * 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.intercept;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.create.ColumnCreationBuilder;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Table;
-
-final class InterceptableColumnCreationBuilder implements ColumnCreationBuilder {
-
- private final ColumnCreationBuilder _columnCreationBuilder;
- private final InterceptableTableCreationBuilder _tableCreationBuilder;
-
- public InterceptableColumnCreationBuilder(
- ColumnCreationBuilder columnCreationBuilder,
- InterceptableTableCreationBuilder tableCreationBuilder) {
- _columnCreationBuilder = columnCreationBuilder;
- _tableCreationBuilder = tableCreationBuilder;
- }
-
- @Override
- public String toSql() {
- return _tableCreationBuilder.toSql();
- }
-
- @Override
- public TableCreationBuilder like(Table table) {
- return _tableCreationBuilder.like(table);
- }
-
- @Override
- public ColumnCreationBuilder withColumn(String name) {
- _columnCreationBuilder.withColumn(name);
- return this;
- }
-
- @Override
- public Table toTable() {
- return _tableCreationBuilder.toTable();
- }
-
- @Override
- public Table execute() throws MetaModelException {
- return _tableCreationBuilder.execute();
- }
-
- @Override
- public ColumnCreationBuilder like(Column column) {
- _columnCreationBuilder.like(column);
- return this;
- }
-
- @Override
- public ColumnCreationBuilder asPrimaryKey() {
- _columnCreationBuilder.asPrimaryKey();
- return this;
- }
-
- @Override
- public ColumnCreationBuilder ofType(ColumnType type) {
- _columnCreationBuilder.ofType(type);
- return this;
- }
-
- @Override
- public ColumnCreationBuilder ofNativeType(String nativeType) {
- _columnCreationBuilder.ofNativeType(nativeType);
- return this;
- }
-
- @Override
- public ColumnCreationBuilder ofSize(int size) {
- _columnCreationBuilder.ofSize(size);
- return this;
- }
-
- @Override
- public ColumnCreationBuilder nullable(boolean nullable) {
- _columnCreationBuilder.nullable(nullable);
- return this;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableDataContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableDataContext.java b/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableDataContext.java
deleted file mode 100644
index 41ec82e..0000000
--- a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableDataContext.java
+++ /dev/null
@@ -1,284 +0,0 @@
-/**
- * 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.intercept;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.builder.InitFromBuilder;
-import org.eobjects.metamodel.query.builder.InitFromBuilderImpl;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
-import org.eobjects.metamodel.util.HasNameMapper;
-
-public class InterceptableDataContext implements UpdateableDataContext {
-
- private final DataContext _delegate;
- private final InterceptorList<DataSet> _dataSetInterceptors;
- private final InterceptorList<Query> _queryInterceptors;
- private final InterceptorList<Schema> _schemaInterceptors;
- private final InterceptorList<RowInsertionBuilder> _rowInsertionInterceptors;
- private final InterceptorList<RowUpdationBuilder> _rowUpdationInterceptors;
- private final InterceptorList<RowDeletionBuilder> _rowDeletionInterceptors;
- private final InterceptorList<TableCreationBuilder> _tableCreationInterceptors;
- private final InterceptorList<TableDropBuilder> _tableDropInterceptors;
-
- protected InterceptableDataContext(DataContext delegate) {
- _delegate = delegate;
- _dataSetInterceptors = new InterceptorList<DataSet>();
- _queryInterceptors = new InterceptorList<Query>();
- _schemaInterceptors = new InterceptorList<Schema>();
- _rowInsertionInterceptors = new InterceptorList<RowInsertionBuilder>();
- _rowUpdationInterceptors = new InterceptorList<RowUpdationBuilder>();
- _rowDeletionInterceptors = new InterceptorList<RowDeletionBuilder>();
- _tableCreationInterceptors = new InterceptorList<TableCreationBuilder>();
- _tableDropInterceptors = new InterceptorList<TableDropBuilder>();
- }
-
- public InterceptableDataContext addTableCreationInterceptor(TableCreationInterceptor interceptor) {
- _tableCreationInterceptors.add(interceptor);
- return this;
- }
-
- public InterceptableDataContext removeTableCreationInterceptor(TableCreationInterceptor interceptor) {
- _tableCreationInterceptors.remove(interceptor);
- return this;
- }
-
- public InterceptableDataContext addTableDropInterceptor(TableDropInterceptor interceptor) {
- _tableDropInterceptors.add(interceptor);
- return this;
- }
-
- public InterceptableDataContext removeTableDropInterceptor(TableDropInterceptor interceptor) {
- _tableDropInterceptors.remove(interceptor);
- return this;
- }
-
- public InterceptableDataContext addRowInsertionInterceptor(RowInsertionInterceptor interceptor) {
- _rowInsertionInterceptors.add(interceptor);
- return this;
- }
-
- public InterceptableDataContext removeRowInsertionInterceptor(RowInsertionInterceptor interceptor) {
- _rowInsertionInterceptors.remove(interceptor);
- return this;
- }
-
- public InterceptableDataContext addRowUpdationInterceptor(RowUpdationInterceptor interceptor) {
- _rowUpdationInterceptors.add(interceptor);
- return this;
- }
-
- public InterceptableDataContext removeRowUpdationInterceptor(RowUpdationInterceptor interceptor) {
- _rowUpdationInterceptors.remove(interceptor);
- return this;
- }
-
- public InterceptableDataContext addRowDeletionInterceptor(RowDeletionInterceptor interceptor) {
- _rowDeletionInterceptors.add(interceptor);
- return this;
- }
-
- public InterceptableDataContext removeRowDeletionInterceptor(RowDeletionInterceptor interceptor) {
- _rowDeletionInterceptors.remove(interceptor);
- return this;
- }
-
- public InterceptableDataContext addQueryInterceptor(QueryInterceptor interceptor) {
- _queryInterceptors.add(interceptor);
- return this;
- }
-
- public InterceptableDataContext removeQueryInterceptor(QueryInterceptor interceptor) {
- _queryInterceptors.remove(interceptor);
- return this;
- }
-
- public InterceptableDataContext addSchemaInterceptor(SchemaInterceptor interceptor) {
- _schemaInterceptors.add(interceptor);
- return this;
- }
-
- public InterceptableDataContext removeSchemaInterceptor(SchemaInterceptor interceptor) {
- _schemaInterceptors.remove(interceptor);
- return this;
- }
-
- public InterceptableDataContext addDataSetInterceptor(DataSetInterceptor interceptor) {
- _dataSetInterceptors.add(interceptor);
- return this;
- }
-
- public InterceptableDataContext removeDataSetInterceptor(DataSetInterceptor interceptor) {
- _dataSetInterceptors.remove(interceptor);
- return this;
- }
-
- public InterceptorList<DataSet> getDataSetInterceptors() {
- return _dataSetInterceptors;
- }
-
- public InterceptorList<Query> getQueryInterceptors() {
- return _queryInterceptors;
- }
-
- public InterceptorList<RowInsertionBuilder> getRowInsertionInterceptors() {
- return _rowInsertionInterceptors;
- }
-
- public InterceptorList<RowUpdationBuilder> getRowUpdationInterceptors() {
- return _rowUpdationInterceptors;
- }
-
- public InterceptorList<RowDeletionBuilder> getRowDeletionInterceptors() {
- return _rowDeletionInterceptors;
- }
-
- public InterceptorList<Schema> getSchemaInterceptors() {
- return _schemaInterceptors;
- }
-
- public InterceptorList<TableCreationBuilder> getTableCreationInterceptors() {
- return _tableCreationInterceptors;
- }
-
- public DataContext getDelegate() {
- return _delegate;
- }
-
- @Override
- public DataSet executeQuery(Query query) throws MetaModelException {
- query = _queryInterceptors.interceptAll(query);
- DataSet dataSet = _delegate.executeQuery(query);
- dataSet = _dataSetInterceptors.interceptAll(dataSet);
- return dataSet;
- }
-
- @Override
- public UpdateableDataContext refreshSchemas() {
- _delegate.refreshSchemas();
- return this;
- }
-
- @Override
- public Schema[] getSchemas() throws MetaModelException {
- Schema[] schemas = _delegate.getSchemas();
- if (!_schemaInterceptors.isEmpty()) {
- for (int i = 0; i < schemas.length; i++) {
- schemas[i] = _schemaInterceptors.interceptAll(schemas[i]);
- }
- }
- return schemas;
- }
-
- @Override
- public 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().eval(schemas[i]);
- }
- return schemaNames;
- }
-
- @Override
- public Schema getDefaultSchema() throws MetaModelException {
- Schema schema = _delegate.getDefaultSchema();
- schema = _schemaInterceptors.interceptAll(schema);
- return schema;
- }
-
- @Override
- public Schema getSchemaByName(String name) throws MetaModelException {
- Schema schema = _delegate.getSchemaByName(name);
- schema = _schemaInterceptors.interceptAll(schema);
- return schema;
- }
-
- @Override
- public InitFromBuilder query() {
- return new InitFromBuilderImpl(this);
- }
-
- @Override
- public Column getColumnByQualifiedLabel(String columnName) {
- return _delegate.getColumnByQualifiedLabel(columnName);
- }
-
- @Override
- public Table getTableByQualifiedLabel(String tableName) {
- return _delegate.getTableByQualifiedLabel(tableName);
- }
-
- @Override
- public void executeUpdate(UpdateScript update) {
- if (!(_delegate instanceof UpdateableDataContext)) {
- throw new UnsupportedOperationException("Delegate is not an UpdateableDataContext");
- }
- final UpdateableDataContext delegate = (UpdateableDataContext) _delegate;
-
- if (_tableCreationInterceptors.isEmpty() && _tableDropInterceptors.isEmpty()
- && _rowInsertionInterceptors.isEmpty() && _rowUpdationInterceptors.isEmpty()
- && _rowDeletionInterceptors.isEmpty()) {
- delegate.executeUpdate(update);
- return;
- }
-
- UpdateScript interceptableUpdateScript = new InterceptableUpdateScript(this, update,
- _tableCreationInterceptors, _tableDropInterceptors, _rowInsertionInterceptors,
- _rowUpdationInterceptors, _rowDeletionInterceptors);
- delegate.executeUpdate(interceptableUpdateScript);
- }
-
- @Override
- public Query parseQuery(String queryString) throws MetaModelException {
- return _delegate.parseQuery(queryString);
- }
-
- @Override
- public DataSet executeQuery(String queryString) throws MetaModelException {
- final Query query = parseQuery(queryString);
- final DataSet dataSet = executeQuery(query);
- return dataSet;
- }
-
- @Override
- public CompiledQuery compileQuery(Query query) {
- return _delegate.compileQuery(query);
- }
-
- @Override
- public DataSet executeQuery(CompiledQuery compiledQuery, Object... values) {
- return _delegate.executeQuery(compiledQuery, values);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableRowDeletionBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableRowDeletionBuilder.java b/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableRowDeletionBuilder.java
deleted file mode 100644
index 2cd32a7..0000000
--- a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableRowDeletionBuilder.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * 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.intercept;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.query.builder.AbstractFilterBuilder;
-import org.eobjects.metamodel.query.builder.FilterBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-
-final class InterceptableRowDeletionBuilder implements RowDeletionBuilder {
-
- private final RowDeletionBuilder _rowDeletionBuilder;
- private final InterceptorList<RowDeletionBuilder> _rowDeletionInterceptors;
-
- public InterceptableRowDeletionBuilder(RowDeletionBuilder rowDeletionBuilder,
- InterceptorList<RowDeletionBuilder> rowDeletionInterceptors) {
- _rowDeletionBuilder = rowDeletionBuilder;
- _rowDeletionInterceptors = rowDeletionInterceptors;
- }
-
- @Override
- public FilterBuilder<RowDeletionBuilder> where(Column column) {
- final SelectItem selectItem = new SelectItem(column);
- return new AbstractFilterBuilder<RowDeletionBuilder>(selectItem) {
- @Override
- protected RowDeletionBuilder applyFilter(FilterItem filter) {
- return where(filter);
- }
- };
- }
-
- @Override
- public FilterBuilder<RowDeletionBuilder> where(String columnName) {
- Column column = getTable().getColumnByName(columnName);
- return where(column);
- }
-
- @Override
- public RowDeletionBuilder where(FilterItem... filterItems) {
- _rowDeletionBuilder.where(filterItems);
- return this;
- }
-
- @Override
- public RowDeletionBuilder where(Iterable<FilterItem> filterItems) {
- _rowDeletionBuilder.where(filterItems);
- return this;
- }
-
- @Override
- public Table getTable() {
- return _rowDeletionBuilder.getTable();
- }
-
- @Override
- public String toSql() {
- return _rowDeletionBuilder.toSql();
- }
-
- @Override
- public void execute() throws MetaModelException {
- RowDeletionBuilder rowDeletionBuilder = _rowDeletionBuilder;
- rowDeletionBuilder = _rowDeletionInterceptors.interceptAll(rowDeletionBuilder);
- rowDeletionBuilder.execute();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableRowInsertionBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableRowInsertionBuilder.java b/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableRowInsertionBuilder.java
deleted file mode 100644
index a8179db..0000000
--- a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableRowInsertionBuilder.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- * 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.intercept;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-
-final class InterceptableRowInsertionBuilder implements RowInsertionBuilder {
-
- private final RowInsertionBuilder _rowInsertionBuilder;
- private final InterceptorList<RowInsertionBuilder> _rowInsertionInterceptors;
-
- public InterceptableRowInsertionBuilder(
- RowInsertionBuilder rowInsertionBuilder,
- InterceptorList<RowInsertionBuilder> rowInsertionInterceptors) {
- _rowInsertionBuilder = rowInsertionBuilder;
- _rowInsertionInterceptors = rowInsertionInterceptors;
- }
-
- @Override
- public String toSql() {
- return _rowInsertionBuilder.toSql();
- }
-
- @Override
- public RowInsertionBuilder value(int columnIndex, Object value) {
- _rowInsertionBuilder.value(columnIndex, value);
- return this;
- }
-
- @Override
- public RowInsertionBuilder value(int columnIndex, Object value, Style style) {
- _rowInsertionBuilder.value(columnIndex, value, style);
- return this;
- }
-
- @Override
- public RowInsertionBuilder value(Column column, Object value) {
- _rowInsertionBuilder.value(column, value);
- return this;
- }
-
- @Override
- public RowInsertionBuilder value(Column column, Object value, Style style) {
- _rowInsertionBuilder.value(column, value, style);
- return this;
- }
-
- @Override
- public RowInsertionBuilder value(String columnName, Object value) {
- _rowInsertionBuilder.value(columnName, value);
- return this;
- }
-
- @Override
- public RowInsertionBuilder like(Row row) {
- _rowInsertionBuilder.like(row);
- return this;
- }
-
- @Override
- public RowInsertionBuilder value(String columnName, Object value,
- Style style) {
- _rowInsertionBuilder.value(columnName, value, style);
- return this;
- }
-
- @Override
- public void execute() throws MetaModelException {
- RowInsertionBuilder rowInsertionBuilder = _rowInsertionBuilder;
- rowInsertionBuilder = _rowInsertionInterceptors
- .interceptAll(rowInsertionBuilder);
- rowInsertionBuilder.execute();
- }
-
- @Override
- public Row toRow() {
- return _rowInsertionBuilder.toRow();
- }
-
- @Override
- public Table getTable() {
- return _rowInsertionBuilder.getTable();
- }
-
- @Override
- public boolean isSet(Column column) {
- return _rowInsertionBuilder.isSet(column);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableRowUpdationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableRowUpdationBuilder.java b/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableRowUpdationBuilder.java
deleted file mode 100644
index a8ead41..0000000
--- a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableRowUpdationBuilder.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/**
- * 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.intercept;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.query.builder.AbstractFilterBuilder;
-import org.eobjects.metamodel.query.builder.FilterBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
-
-final class InterceptableRowUpdationBuilder implements RowUpdationBuilder {
-
- private final RowUpdationBuilder _rowUpdationBuilder;
- private final InterceptorList<RowUpdationBuilder> _rowUpdationInterceptors;
-
- public InterceptableRowUpdationBuilder(RowUpdationBuilder rowUpdationBuilder,
- InterceptorList<RowUpdationBuilder> rowUpdationInterceptors) {
- _rowUpdationBuilder = rowUpdationBuilder;
- _rowUpdationInterceptors = rowUpdationInterceptors;
- }
-
- @Override
- public RowUpdationBuilder value(int columnIndex, Object value) {
- _rowUpdationBuilder.value(columnIndex, value);
- return this;
- }
-
- @Override
- public RowUpdationBuilder value(int columnIndex, Object value, Style style) {
- _rowUpdationBuilder.value(columnIndex, value, style);
- return this;
- }
-
- @Override
- public RowUpdationBuilder value(Column column, Object value) {
- _rowUpdationBuilder.value(column, value);
- return this;
- }
-
- @Override
- public RowUpdationBuilder value(Column column, Object value, Style style) {
- _rowUpdationBuilder.value(column, value, style);
- return this;
- }
-
- @Override
- public RowUpdationBuilder value(String columnName, Object value) {
- _rowUpdationBuilder.value(columnName, value);
- return this;
- }
-
- @Override
- public RowUpdationBuilder value(String columnName, Object value, Style style) {
- _rowUpdationBuilder.value(columnName, value, style);
- return this;
- }
-
- @Override
- public Row toRow() {
- return _rowUpdationBuilder.toRow();
- }
-
- @Override
- public boolean isSet(Column column) {
- return _rowUpdationBuilder.isSet(column);
- }
-
- @Override
- public FilterBuilder<RowUpdationBuilder> where(Column column) {
- final SelectItem selectItem = new SelectItem(column);
- return new AbstractFilterBuilder<RowUpdationBuilder>(selectItem) {
- @Override
- protected RowUpdationBuilder applyFilter(FilterItem filter) {
- where(filter);
- return InterceptableRowUpdationBuilder.this;
- }
- };
- }
-
- @Override
- public FilterBuilder<RowUpdationBuilder> where(String columnName) {
- Column column = getTable().getColumnByName(columnName);
- return where(column);
- }
-
- @Override
- public RowUpdationBuilder where(FilterItem... filterItems) {
- _rowUpdationBuilder.where(filterItems);
- return this;
- }
-
- @Override
- public RowUpdationBuilder where(Iterable<FilterItem> filterItems) {
- _rowUpdationBuilder.where(filterItems);
- return this;
- }
-
- @Override
- public String toSql() {
- return _rowUpdationBuilder.toSql();
- }
-
- @Override
- public Table getTable() {
- return _rowUpdationBuilder.getTable();
- }
-
- @Override
- public void execute() throws MetaModelException {
- RowUpdationBuilder rowUpdationBuilder = _rowUpdationBuilder;
- rowUpdationBuilder = _rowUpdationInterceptors.interceptAll(rowUpdationBuilder);
- rowUpdationBuilder.execute();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableTableCreationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableTableCreationBuilder.java b/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableTableCreationBuilder.java
deleted file mode 100644
index dd85590..0000000
--- a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableTableCreationBuilder.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * 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.intercept;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.create.ColumnCreationBuilder;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.schema.Table;
-
-final class InterceptableTableCreationBuilder implements TableCreationBuilder {
-
- private final TableCreationBuilder _tabelCreationBuilder;
- private final InterceptorList<TableCreationBuilder> _tableCreationInterceptors;
-
- public InterceptableTableCreationBuilder(
- TableCreationBuilder tabelCreationBuilder,
- InterceptorList<TableCreationBuilder> tableCreationInterceptors) {
- _tabelCreationBuilder = tabelCreationBuilder;
- _tableCreationInterceptors = tableCreationInterceptors;
- }
-
- @Override
- public String toSql() {
- return _tabelCreationBuilder.toSql();
- }
-
- @Override
- public TableCreationBuilder like(Table table) {
- _tabelCreationBuilder.like(table);
- return this;
- }
-
- @Override
- public ColumnCreationBuilder withColumn(String name) {
- ColumnCreationBuilder columnCreationBuilder = _tabelCreationBuilder
- .withColumn(name);
- return new InterceptableColumnCreationBuilder(columnCreationBuilder,
- this);
- }
-
- @Override
- public Table toTable() {
- return _tabelCreationBuilder.toTable();
- }
-
- @Override
- public Table execute() throws MetaModelException {
- TableCreationBuilder tableCreationBuilder = _tabelCreationBuilder;
- tableCreationBuilder = _tableCreationInterceptors
- .interceptAll(tableCreationBuilder);
- return tableCreationBuilder.execute();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableTableDropBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableTableDropBuilder.java b/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableTableDropBuilder.java
deleted file mode 100644
index 445b10d..0000000
--- a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableTableDropBuilder.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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.intercept;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.schema.Table;
-
-final class InterceptableTableDropBuilder implements TableDropBuilder {
-
- private final TableDropBuilder _tableDropBuilder;
- private final InterceptorList<TableDropBuilder> _tableDropInterceptors;
-
- public InterceptableTableDropBuilder(TableDropBuilder tableDropBuilder,
- InterceptorList<TableDropBuilder> tableDropInterceptors) {
- _tableDropBuilder = tableDropBuilder;
- _tableDropInterceptors = tableDropInterceptors;
- }
-
- @Override
- public Table getTable() {
- return _tableDropBuilder.getTable();
- }
-
- @Override
- public String toSql() {
- return _tableDropBuilder.toSql();
- }
-
- @Override
- public void execute() throws MetaModelException {
- TableDropBuilder tableDropBuilder = _tableDropBuilder;
- tableDropBuilder = _tableDropInterceptors.interceptAll(_tableDropBuilder);
- tableDropBuilder.execute();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableUpdateCallback.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableUpdateCallback.java b/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableUpdateCallback.java
deleted file mode 100644
index f5a27ed..0000000
--- a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableUpdateCallback.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/**
- * 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.intercept;
-
-import org.eobjects.metamodel.AbstractUpdateCallback;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
-
-/**
- * {@link UpdateCallback} wrapper that allows adding interceptors for certain operations.
- */
-final class InterceptableUpdateCallback extends AbstractUpdateCallback implements UpdateCallback {
-
- private final UpdateCallback _updateCallback;
- private final InterceptorList<TableCreationBuilder> _tableCreationInterceptors;
- private final InterceptorList<TableDropBuilder> _tableDropInterceptors;
- private final InterceptorList<RowInsertionBuilder> _rowInsertionInterceptors;
- private final InterceptorList<RowUpdationBuilder> _rowUpdationInterceptors;
- private final InterceptorList<RowDeletionBuilder> _rowDeletionInterceptors;
-
- public InterceptableUpdateCallback(InterceptableDataContext dataContext, UpdateCallback updateCallback,
- InterceptorList<TableCreationBuilder> tableCreationInterceptors,
- InterceptorList<TableDropBuilder> tableDropInterceptors,
- InterceptorList<RowInsertionBuilder> rowInsertionInterceptors,
- InterceptorList<RowUpdationBuilder> rowUpdationInterceptors,
- InterceptorList<RowDeletionBuilder> rowDeletionInterceptors) {
- super(dataContext);
- _updateCallback = updateCallback;
- _tableCreationInterceptors = tableCreationInterceptors;
- _tableDropInterceptors = tableDropInterceptors;
- _rowInsertionInterceptors = rowInsertionInterceptors;
- _rowUpdationInterceptors = rowUpdationInterceptors;
- _rowDeletionInterceptors = rowDeletionInterceptors;
- }
-
- @Override
- public TableCreationBuilder createTable(Schema schema, String name) throws IllegalArgumentException,
- IllegalStateException {
- TableCreationBuilder tabelCreationBuilder = _updateCallback.createTable(schema, name);
- if (_tableCreationInterceptors.isEmpty()) {
- return tabelCreationBuilder;
- }
- return new InterceptableTableCreationBuilder(tabelCreationBuilder, _tableCreationInterceptors);
- }
-
- @Override
- public RowInsertionBuilder insertInto(Table table) throws IllegalArgumentException, IllegalStateException {
- RowInsertionBuilder rowInsertionBuilder = _updateCallback.insertInto(table);
- if (_rowInsertionInterceptors.isEmpty()) {
- return rowInsertionBuilder;
- }
- return new InterceptableRowInsertionBuilder(rowInsertionBuilder, _rowInsertionInterceptors);
- }
-
- @Override
- public boolean isCreateTableSupported() {
- return _updateCallback.isCreateTableSupported();
- }
-
- @Override
- public boolean isDropTableSupported() {
- return _updateCallback.isDropTableSupported();
- }
-
- @Override
- public TableDropBuilder dropTable(Table table) {
- TableDropBuilder tableDropBuilder = _updateCallback.dropTable(table);
- if (_tableDropInterceptors.isEmpty()) {
- return tableDropBuilder;
- }
- return new InterceptableTableDropBuilder(tableDropBuilder, _tableDropInterceptors);
- }
-
- @Override
- public boolean isInsertSupported() {
- return _updateCallback.isInsertSupported();
- }
-
- @Override
- public boolean isUpdateSupported() {
- return _updateCallback.isUpdateSupported();
- }
-
- @Override
- public RowUpdationBuilder update(Table table) {
- RowUpdationBuilder rowUpdationBuilder = _updateCallback.update(table);
- if (_rowUpdationInterceptors.isEmpty()) {
- return rowUpdationBuilder;
- }
- return new InterceptableRowUpdationBuilder(rowUpdationBuilder, _rowUpdationInterceptors);
- }
-
- @Override
- public boolean isDeleteSupported() {
- return _updateCallback.isDeleteSupported();
- }
-
- @Override
- public RowDeletionBuilder deleteFrom(Table table) {
- RowDeletionBuilder rowDeletionBuilder = _updateCallback.deleteFrom(table);
- if (_rowDeletionInterceptors.isEmpty()) {
- return rowDeletionBuilder;
- }
- return new InterceptableRowDeletionBuilder(rowDeletionBuilder, _rowDeletionInterceptors);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableUpdateScript.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableUpdateScript.java b/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableUpdateScript.java
deleted file mode 100644
index 2c11d6b..0000000
--- a/core/src/main/java/org/eobjects/metamodel/intercept/InterceptableUpdateScript.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * 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.intercept;
-
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
-
-final class InterceptableUpdateScript implements UpdateScript {
-
- private final InterceptableDataContext _interceptableDataContext;
- private final UpdateScript _updateScript;
- private final InterceptorList<TableCreationBuilder> _tableCreationInterceptors;
- private final InterceptorList<TableDropBuilder> _tableDropInterceptors;
- private final InterceptorList<RowInsertionBuilder> _rowInsertionInterceptors;
- private final InterceptorList<RowUpdationBuilder> _rowUpdationInterceptors;
- private final InterceptorList<RowDeletionBuilder> _rowDeletionInterceptors;
-
- public InterceptableUpdateScript(InterceptableDataContext interceptableDataContext, UpdateScript updateScript,
- InterceptorList<TableCreationBuilder> tableCreationInterceptors,
- InterceptorList<TableDropBuilder> tableDropInterceptors,
- InterceptorList<RowInsertionBuilder> rowInsertionInterceptors,
- InterceptorList<RowUpdationBuilder> rowUpdationInterceptors,
- InterceptorList<RowDeletionBuilder> rowDeletionInterceptors) {
- _interceptableDataContext = interceptableDataContext;
- _updateScript = updateScript;
- _tableCreationInterceptors = tableCreationInterceptors;
- _tableDropInterceptors = tableDropInterceptors;
- _rowInsertionInterceptors = rowInsertionInterceptors;
- _rowUpdationInterceptors = rowUpdationInterceptors;
- _rowDeletionInterceptors = rowDeletionInterceptors;
- }
-
- @Override
- public void run(UpdateCallback callback) {
- UpdateCallback interceptableUpdateCallback = new InterceptableUpdateCallback(_interceptableDataContext,
- callback, _tableCreationInterceptors, _tableDropInterceptors, _rowInsertionInterceptors,
- _rowUpdationInterceptors, _rowDeletionInterceptors);
- _updateScript.run(interceptableUpdateCallback);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/intercept/Interceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/intercept/Interceptor.java b/core/src/main/java/org/eobjects/metamodel/intercept/Interceptor.java
deleted file mode 100644
index 36f503b..0000000
--- a/core/src/main/java/org/eobjects/metamodel/intercept/Interceptor.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * 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.intercept;
-
-/**
- * Defines a high-level interface for interceptors in MetaModel.
- *
- * An intereptor can touch, modify, enhance or do other operations on certain
- * object types as they are passed around for execution in MetaModel. There are
- * 5 types of concrete interceptors:
- *
- * @see QueryInterceptor
- * @see DataSetInterceptor
- * @see RowInsertionInterceptor
- * @see TableCreationInterceptor
- * @see SchemaInterceptor
- *
- * @author Kasper Sørensen
- *
- * @param <E>
- * the type of object to intercept
- */
-public interface Interceptor<E> {
-
- /**
- * Interception method invoked by MetaModel when the intercepted object is
- * being activated.
- *
- * @param input
- * the intercepted object
- * @return the intercepted object, or a modification of this if the object
- * is to be replaced by the interceptor. The returned object must
- * not be null.
- */
- public E intercept(E input);
-}
[14/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/test/java/org/eobjects/metamodel/csv/DefaultExampleValueGenerator.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/eobjects/metamodel/csv/DefaultExampleValueGenerator.java b/csv/src/test/java/org/eobjects/metamodel/csv/DefaultExampleValueGenerator.java
deleted file mode 100644
index d836fef..0000000
--- a/csv/src/test/java/org/eobjects/metamodel/csv/DefaultExampleValueGenerator.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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.csv;
-
-import org.junit.Ignore;
-
-@Ignore
-final class DefaultExampleValueGenerator implements ExampleValueGenerator {
-
- @Override
- public String generate(int row, int col) {
- return "r" + row + "c" + col;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/test/java/org/eobjects/metamodel/csv/ExampleDataGenerator.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/eobjects/metamodel/csv/ExampleDataGenerator.java b/csv/src/test/java/org/eobjects/metamodel/csv/ExampleDataGenerator.java
deleted file mode 100644
index e2da7bf..0000000
--- a/csv/src/test/java/org/eobjects/metamodel/csv/ExampleDataGenerator.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- * 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.csv;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-
-import org.junit.Ignore;
-
-/**
- * Simple program used for creating large CSV datasets for performance/memory
- * testing
- */
-@Ignore
-class ExampleDataGenerator {
-
- private final int _rows;
- private final int _cols;
- private final ExampleValueGenerator _valueGenerator;
-
- public static void main(String[] args) {
- // Convenience main method. Customize if needed.
- ExampleDataGenerator gen = new ExampleDataGenerator(374635, 4, new RandomizedExampleValueGenerator(3));
- gen.createFile( new File("test1.csv"));
- gen.createFile( new File("test2.csv"));
- gen.createFile( new File("test3.csv"));
- }
-
- public ExampleDataGenerator(int rows, int cols) {
- this(rows, cols, new DefaultExampleValueGenerator());
- }
-
- public ExampleDataGenerator(int rows, int cols,
- ExampleValueGenerator valueGenerator) {
- _rows = rows;
- _cols = cols;
- _valueGenerator = valueGenerator;
- }
-
- public void createFile(File file) {
- BufferedWriter writer = null;
- try {
- writer = new BufferedWriter(new FileWriter(file));
-
- for (int j = 0; j < _cols; j++) {
- if (j != 0) {
- writer.write(',');
- }
- writer.write("col" + j);
- }
-
- for (int i = 0; i < _rows; i++) {
- if (i % 500000 == 0) {
- System.out.println("i: " + i);
- }
- writer.write('\n');
- for (int j = 0; j < _cols; j++) {
- if (j != 0) {
- writer.write(',');
- }
- final String value = _valueGenerator.generate(i, j);
- writer.write(value);
- }
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (writer != null) {
- try {
- writer.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/test/java/org/eobjects/metamodel/csv/ExampleValueGenerator.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/eobjects/metamodel/csv/ExampleValueGenerator.java b/csv/src/test/java/org/eobjects/metamodel/csv/ExampleValueGenerator.java
deleted file mode 100644
index 9e45e98..0000000
--- a/csv/src/test/java/org/eobjects/metamodel/csv/ExampleValueGenerator.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * 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.csv;
-
-import org.junit.Ignore;
-
-@Ignore
-interface ExampleValueGenerator {
-
- public String generate(int row, int col);
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/test/java/org/eobjects/metamodel/csv/RandomizedExampleValueGenerator.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/eobjects/metamodel/csv/RandomizedExampleValueGenerator.java b/csv/src/test/java/org/eobjects/metamodel/csv/RandomizedExampleValueGenerator.java
deleted file mode 100644
index 2a6dfaa..0000000
--- a/csv/src/test/java/org/eobjects/metamodel/csv/RandomizedExampleValueGenerator.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * 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.csv;
-
-import java.util.Random;
-
-import org.junit.Ignore;
-
-@Ignore
-final class RandomizedExampleValueGenerator implements ExampleValueGenerator {
-
- private final char[] diacriticChars = new char[] { 'æ', 'ø', 'å', 'ä', 'õ',
- 'â', 'á', 'í', 'ì', 'ẽ', 'ŝ', 'é', 'ç' };
- private final char[] strangeChars = new char[] { '*', '.', '~', '`', '@',
- '[', ']', '#', '-' };
- private final Random random = new Random();
- private final int letterMin = 'a';
- private final int letterMax = 'z';
- private final int letterDiff = letterMax - letterMin;
- private final int _tokenLength;
-
- public RandomizedExampleValueGenerator() {
- this(20);
- }
-
- public RandomizedExampleValueGenerator(int tokenLength) {
- _tokenLength = tokenLength;
- }
-
- @Override
- public String generate(int row, int col) {
- int length = random.nextInt(_tokenLength);
- if (length < 3) {
- if (random.nextInt(1000) == 0) {
- length = 0;
- } else {
- length = 1 + random.nextInt(5);
- }
- }
- char[] chars = new char[length];
- for (int i = 0; i < length; i++) {
- chars[i] = nextChar();
- }
- return String.valueOf(chars);
- }
-
- private char nextChar() {
- int unusualCharRandom = random.nextInt(10000);
- if (unusualCharRandom < 91) {
- return ' ';
- } else if (unusualCharRandom < 109) {
- return getRandom(diacriticChars);
- } else if (unusualCharRandom < 113) {
- return getRandom(strangeChars);
- }
- final int r = random.nextInt(letterDiff);
- char c = (char) (r + letterMin);
- if (random.nextInt(6) == 0) {
- c = Character.toUpperCase(c);
- }
- return c;
- }
-
- private char getRandom(char[] chars) {
- final int index = random.nextInt(chars.length);
- return chars[index];
- }
-
- public static void main(String[] args) {
- RandomizedExampleValueGenerator gen = new RandomizedExampleValueGenerator();
- for (int i = 0; i < 1000; i++) {
- System.out.println(gen.generate(0, 0));
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/test/java/org/eobjects/metamodel/csv/UnicodeWriterTest.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/eobjects/metamodel/csv/UnicodeWriterTest.java b/csv/src/test/java/org/eobjects/metamodel/csv/UnicodeWriterTest.java
deleted file mode 100644
index a82b732..0000000
--- a/csv/src/test/java/org/eobjects/metamodel/csv/UnicodeWriterTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * 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.csv;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.Writer;
-
-import org.eobjects.metamodel.util.UnicodeWriter;
-import org.junit.Test;
-
-public class UnicodeWriterTest {
-
- @Test
- public void test() throws IOException {
- File file = new File("target/unicodeWriterTest.txt");
- Writer writer = new UnicodeWriter(file, "UTF-8");
- writer.write("Hello");
- writer.close();
-
- FileInputStream is = new FileInputStream(file);
- byte[] bytes = new byte[100];
- assertEquals(8, is.read(bytes));
-
- assertEquals(UnicodeWriter.UTF8_BOM[0], bytes[0]);
- assertEquals(UnicodeWriter.UTF8_BOM[1], bytes[1]);
- assertEquals(UnicodeWriter.UTF8_BOM[2], bytes[2]);
- assertEquals((byte) 'H', bytes[3]);
-
- is.close();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/csv/src/test/java/org/eobjects/metamodel/intercept/InterceptionCsvIntegrationTest.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/eobjects/metamodel/intercept/InterceptionCsvIntegrationTest.java b/csv/src/test/java/org/eobjects/metamodel/intercept/InterceptionCsvIntegrationTest.java
deleted file mode 100644
index 6e587d2..0000000
--- a/csv/src/test/java/org/eobjects/metamodel/intercept/InterceptionCsvIntegrationTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * 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.intercept;
-
-import java.io.File;
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.csv.CsvDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Table;
-
-public class InterceptionCsvIntegrationTest extends TestCase {
-
- public void testScenario() throws Exception {
- final UpdateableDataContext source = new CsvDataContext(new File(
- "target/test_interception_scenario.txt"));
- final InterceptableDataContext dc = Interceptors.intercept(source);
-
- dc.addTableCreationInterceptor(new TableCreationInterceptor() {
- @Override
- public TableCreationBuilder intercept(TableCreationBuilder input) {
- return input.withColumn("foobar");
- }
- });
-
- dc.addRowInsertionInterceptor(new RowInsertionInterceptor() {
- @Override
- public RowInsertionBuilder intercept(RowInsertionBuilder input) {
- return input.value("foobar", "elite!");
- }
- });
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- Table table = callback
- .createTable(dc.getDefaultSchema(), "table")
- .withColumn("col1").withColumn("col2").execute();
-
- callback.insertInto(table).value("col1", "hello")
- .value("col2", "world").execute();
- callback.insertInto(table).value("col1", "123")
- .value("col2", "567").execute();
- }
- });
-
- assertEquals("[test_interception_scenario]",
- Arrays.toString(dc.getDefaultSchema().getTableNames()));
- Table table = dc.getDefaultSchema().getTables()[0];
- assertEquals("[col1, col2, foobar]",
- Arrays.toString(table.getColumnNames()));
-
- DataSet ds = dc.query().from(table).select(table.getColumns())
- .execute();
- assertTrue(ds.next());
- assertEquals("Row[values=[hello, world, elite!]]", ds.getRow()
- .toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[123, 567, elite!]]", ds.getRow().toString());
- assertFalse(ds.next());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegate.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegate.java b/excel/src/main/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegate.java
new file mode 100644
index 0000000..f4c6dd7
--- /dev/null
+++ b/excel/src/main/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegate.java
@@ -0,0 +1,212 @@
+/**
+ * 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.excel;
+
+import java.io.InputStream;
+import java.util.Iterator;
+
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.EmptyDataSet;
+import org.eobjects.metamodel.data.MaxRowsDataSet;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+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.Table;
+import org.eobjects.metamodel.util.AlphabeticSequence;
+import org.eobjects.metamodel.util.Ref;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The default {@link SpreadsheetReaderDelegate}, which uses POI's main user
+ * model to read spreadsheets: the Workbook class.
+ *
+ * @author Kasper Sørensen
+ */
+final class DefaultSpreadsheetReaderDelegate implements SpreadsheetReaderDelegate {
+
+ private static final Logger logger = LoggerFactory.getLogger(DefaultSpreadsheetReaderDelegate.class);
+
+ private final ExcelConfiguration _configuration;
+
+ public DefaultSpreadsheetReaderDelegate(ExcelConfiguration configuration) {
+ _configuration = configuration;
+ }
+
+ @Override
+ public Schema createSchema(InputStream inputStream, String schemaName) {
+ final MutableSchema schema = new MutableSchema(schemaName);
+ final Workbook wb = ExcelUtils.readWorkbook(inputStream);
+
+ for (int i = 0; i < wb.getNumberOfSheets(); i++) {
+ final Sheet currentSheet = wb.getSheetAt(i);
+ final MutableTable table = createTable(wb, currentSheet);
+ table.setSchema(schema);
+ schema.addTable(table);
+ }
+
+ return schema;
+ }
+
+ @Override
+ public DataSet executeQuery(InputStream inputStream, Table table, Column[] columns, int maxRows) {
+ final Workbook wb = ExcelUtils.readWorkbook(inputStream);
+ final Sheet sheet = wb.getSheet(table.getName());
+
+ if (sheet == null || sheet.getPhysicalNumberOfRows() == 0) {
+ return new EmptyDataSet(columns);
+ }
+
+ DataSet dataSet = ExcelUtils.getDataSet(wb, sheet, table, _configuration);
+
+ if (maxRows > 0) {
+ dataSet = new MaxRowsDataSet(dataSet, maxRows);
+ }
+ return dataSet;
+ }
+
+ @Override
+ public void notifyTablesModified(Ref<InputStream> inputStreamRef) {
+ // do nothing
+ }
+
+ private MutableTable createTable(final Workbook wb, final Sheet sheet) {
+ final MutableTable table = new MutableTable(sheet.getSheetName());
+
+ if (sheet.getPhysicalNumberOfRows() <= 0) {
+ // no physical rows in sheet
+ return table;
+ }
+
+ final Iterator<Row> rowIterator = ExcelUtils.getRowIterator(sheet, _configuration, false);
+
+ if (!rowIterator.hasNext()) {
+ // no physical rows in sheet
+ return table;
+ }
+
+
+ Row row = null;
+
+ if (_configuration.isSkipEmptyLines()) {
+ while (row == null && rowIterator.hasNext()) {
+ row = rowIterator.next();
+ }
+ } else {
+ row = rowIterator.next();
+ }
+
+ final int columnNameLineNumber = _configuration.getColumnNameLineNumber();
+ if (columnNameLineNumber == ExcelConfiguration.NO_COLUMN_NAME_LINE) {
+
+ // get to the first non-empty line (no matter if lines are skipped
+ // or not we need to read ahead to figure out how many columns there
+ // are!)
+ while (row == null && rowIterator.hasNext()) {
+ row = rowIterator.next();
+ }
+
+ // build columns by using alphabetic sequences
+ // (A,B,C...)
+ AlphabeticSequence sequence = new AlphabeticSequence();
+
+ final int offset = getColumnOffset(row);
+ for (int i = 0; i < offset; i++) {
+ sequence.next();
+ }
+
+ for (int j = offset; j < row.getLastCellNum(); j++) {
+ Column column = new MutableColumn(sequence.next(), ColumnType.VARCHAR, table, j, true);
+ table.addColumn(column);
+ }
+ } else {
+
+ boolean hasColumns = true;
+
+ // iterate to the column name line number (if above 1)
+ for (int j = 1; j < columnNameLineNumber; j++) {
+ if (rowIterator.hasNext()) {
+ row = rowIterator.next();
+ } else {
+ hasColumns = false;
+ break;
+ }
+ }
+
+ if (hasColumns) {
+ createColumns(table, wb, row);
+ }
+ }
+
+ return table;
+ }
+
+ /**
+ * Builds columns based on row/cell values.
+ *
+ * @param table
+ * @param wb
+ * @param row
+ */
+ private void createColumns(MutableTable table, Workbook wb, Row row) {
+ if (row == null) {
+ logger.warn("Cannot create columns based on null row!");
+ return;
+ }
+ final short rowLength = row.getLastCellNum();
+
+ final int offset = getColumnOffset(row);
+
+ // build columns based on cell values.
+ for (int j = offset; j < rowLength; j++) {
+ Cell cell = row.getCell(j);
+ String columnName = ExcelUtils.getCellValue(wb, cell);
+ if (columnName == null || "".equals(columnName)) {
+ columnName = "[Column " + (j + 1) + "]";
+ }
+ Column column = new MutableColumn(columnName, ColumnType.VARCHAR, table, j, true);
+ table.addColumn(column);
+ }
+ }
+
+ /**
+ * Gets the column offset (first column to include). This is dependent on
+ * the row used for column processing and whether the skip empty columns
+ * property is set.
+ *
+ * @param row
+ * @return
+ */
+ private int getColumnOffset(Row row) {
+ final int offset;
+ if (_configuration.isSkipEmptyColumns()) {
+ offset = row.getFirstCellNum();
+ } else {
+ offset = 0;
+ }
+ return offset;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/apache/metamodel/excel/ExcelConfiguration.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/ExcelConfiguration.java b/excel/src/main/java/org/apache/metamodel/excel/ExcelConfiguration.java
new file mode 100644
index 0000000..b63140c
--- /dev/null
+++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelConfiguration.java
@@ -0,0 +1,101 @@
+/**
+ * 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.excel;
+
+import java.io.Serializable;
+import java.util.List;
+
+import org.eobjects.metamodel.util.BaseObject;
+
+/**
+ * Represents the configuration for reading/parsing Excel spreadsheets.
+ *
+ * @see ExcelDataContext
+ *
+ * @author Kasper Sørensen
+ */
+public final class ExcelConfiguration extends BaseObject implements
+ Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ public static final int NO_COLUMN_NAME_LINE = 0;
+ public static final int DEFAULT_COLUMN_NAME_LINE = 1;
+
+ private final int columnNameLineNumber;
+ private final boolean skipEmptyLines;
+ private final boolean skipEmptyColumns;
+
+ public ExcelConfiguration() {
+ this(DEFAULT_COLUMN_NAME_LINE, true, false);
+ }
+
+ public ExcelConfiguration(int columnNameLineNumber, boolean skipEmptyLines,
+ boolean skipEmptyColumns) {
+ this.columnNameLineNumber = columnNameLineNumber;
+ this.skipEmptyLines = skipEmptyLines;
+ this.skipEmptyColumns = skipEmptyColumns;
+ }
+
+ /**
+ * The line number (1 based) from which to get the names of the columns.
+ * Note that this line number is affected by the skipEmptyLines property! If
+ * skipEmptyLines is set to true, the line numbers will begin from the first
+ * non-empty line.
+ *
+ * @return the line number of the column headers/names.
+ */
+ public int getColumnNameLineNumber() {
+ return columnNameLineNumber;
+ }
+
+ /**
+ * Defines if empty lines in the excel spreadsheet should be skipped while
+ * reading the spreadsheet.
+ *
+ * @return a boolean indicating whether or not to skip empty lines.
+ */
+ public boolean isSkipEmptyLines() {
+ return skipEmptyLines;
+ }
+
+ /**
+ * Defines if empty columns in the excel spreadsheet should be skipped while
+ * reading the spreadsheet.
+ *
+ * @return a boolean indicating whether or not to skip empty columns.
+ */
+ public boolean isSkipEmptyColumns() {
+ return skipEmptyColumns;
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ identifiers.add(columnNameLineNumber);
+ identifiers.add(skipEmptyLines);
+ identifiers.add(skipEmptyColumns);
+ }
+
+ @Override
+ public String toString() {
+ return "ExcelConfiguration[columnNameLineNumber="
+ + columnNameLineNumber + ", skipEmptyLines=" + skipEmptyLines
+ + ", skipEmptyColumns=" + skipEmptyColumns + "]";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/apache/metamodel/excel/ExcelDataContext.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/ExcelDataContext.java b/excel/src/main/java/org/apache/metamodel/excel/ExcelDataContext.java
new file mode 100644
index 0000000..6726d8b
--- /dev/null
+++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelDataContext.java
@@ -0,0 +1,259 @@
+/**
+ * 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.excel;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PushbackInputStream;
+
+import org.apache.poi.POIXMLDocument;
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.QueryPostprocessDataContext;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.UpdateableDataContext;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.MutableSchema;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.FileHelper;
+import org.eobjects.metamodel.util.FileResource;
+import org.eobjects.metamodel.util.LazyRef;
+import org.eobjects.metamodel.util.Ref;
+import org.eobjects.metamodel.util.Resource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * {@link DataContext} implementation to use for Excel spreadsheets.
+ *
+ * This DataContext supports both the "old" .xls format and the "new" .xlsx
+ * format, and saves the user the trouble of figuring out which one to use,
+ * simply by detecting it at runtime and delegating to the appropriate
+ * implementation.
+ */
+public final class ExcelDataContext extends QueryPostprocessDataContext implements UpdateableDataContext {
+
+ private static final Logger logger = LoggerFactory.getLogger(ExcelDataContext.class);
+
+ private final Object WRITE_LOCK = new Object();
+
+ private final Resource _resource;
+ private final ExcelConfiguration _configuration;
+ private SpreadsheetReaderDelegate _spreadsheetReaderDelegate;
+
+ /**
+ * Constructs an Excel DataContext based on a file, with default
+ * configuration
+ *
+ * @param file
+ */
+ public ExcelDataContext(File file) {
+ this(file, new ExcelConfiguration());
+ }
+
+ /**
+ * Constructs an Excel DataContext based on a resource and a custom
+ * configuration.
+ *
+ * @param file
+ * @param configuration
+ */
+ public ExcelDataContext(File file, ExcelConfiguration configuration) {
+ if (file == null) {
+ throw new IllegalArgumentException("File cannot be null");
+ }
+ if (configuration == null) {
+ throw new IllegalArgumentException("ExcelConfiguration cannot be null");
+ }
+ if (file.exists() && !file.canRead()) {
+ throw new IllegalArgumentException("Cannot read from file");
+ }
+ _resource = new FileResource(file);
+ _configuration = configuration;
+ }
+
+ public ExcelDataContext(Resource resource, ExcelConfiguration configuration) {
+ if (resource == null) {
+ throw new IllegalArgumentException("Resource cannot be null");
+ }
+ if (configuration == null) {
+ throw new IllegalArgumentException("ExcelConfiguration cannot be null");
+ }
+ _resource = resource;
+ _configuration = configuration;
+ }
+
+ /**
+ * Gets the Excel configuration used.
+ *
+ * @return an excel configuration.
+ */
+ public ExcelConfiguration getConfiguration() {
+ return _configuration;
+ }
+
+ /**
+ * Gets the Excel file being read.
+ *
+ * @return a file.
+ * @deprecated
+ */
+ @Deprecated
+ public File getFile() {
+ if (_resource instanceof FileResource) {
+ return ((FileResource) _resource).getFile();
+ }
+ return null;
+ }
+
+ /**
+ * Gets the Excel resource being read
+ *
+ * @return
+ */
+ public Resource getResource() {
+ return _resource;
+ }
+
+ @Override
+ protected String getMainSchemaName() throws MetaModelException {
+ return _resource.getName();
+ }
+
+ @Override
+ public DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+
+ Ref<InputStream> inputStreamRef = getInputStreamRef();
+ InputStream inputStream = null;
+ try {
+ SpreadsheetReaderDelegate delegate = getSpreadsheetReaderDelegate(inputStreamRef);
+ inputStream = inputStreamRef.get();
+ DataSet dataSet = delegate.executeQuery(inputStream, table, columns, maxRows);
+ return dataSet;
+ } catch (Exception e) {
+ if (e instanceof RuntimeException) {
+ throw (RuntimeException) e;
+ }
+ throw new MetaModelException("Unexpected exception while materializing main schema table", e);
+ } finally {
+ FileHelper.safeClose(inputStream);
+ }
+ }
+
+ @Override
+ protected Schema getMainSchema() throws MetaModelException {
+ if (!_resource.isExists()) {
+ logger.info("Resource does not exist, returning empty schema");
+ return new MutableSchema(getMainSchemaName());
+ }
+ Ref<InputStream> inputStreamRef = getInputStreamRef();
+ InputStream inputStream = null;
+ try {
+ SpreadsheetReaderDelegate delegate = getSpreadsheetReaderDelegate(inputStreamRef);
+ inputStream = inputStreamRef.get();
+ Schema schema = delegate.createSchema(inputStream, getMainSchemaName());
+ assert getMainSchemaName().equals(schema.getName());
+ return schema;
+ } catch (Exception e) {
+ if (e instanceof RuntimeException) {
+ throw (RuntimeException) e;
+ }
+ throw new MetaModelException("Unexpected exception while building main schema", e);
+ } finally {
+ FileHelper.safeClose(inputStream);
+ }
+ }
+
+ /**
+ * Convenient method for testing and inspecting internal state.
+ *
+ * @return the class of the spreadsheet reader delegate.
+ */
+ protected Class<? extends SpreadsheetReaderDelegate> getSpreadsheetReaderDelegateClass() {
+ if (_spreadsheetReaderDelegate != null) {
+ return _spreadsheetReaderDelegate.getClass();
+ }
+ return null;
+ }
+
+ private SpreadsheetReaderDelegate getSpreadsheetReaderDelegate(Ref<InputStream> inputStream) throws MetaModelException {
+ if (_spreadsheetReaderDelegate == null) {
+ synchronized (this) {
+ if (_spreadsheetReaderDelegate == null) {
+ try {
+ if (POIXMLDocument.hasOOXMLHeader(inputStream.get())) {
+ _spreadsheetReaderDelegate = new XlsxSpreadsheetReaderDelegate(_configuration);
+ } else {
+ _spreadsheetReaderDelegate = new DefaultSpreadsheetReaderDelegate(_configuration);
+ }
+ } catch (IOException e) {
+ logger.error("Could not identify spreadsheet type, using default", e);
+ _spreadsheetReaderDelegate = new DefaultSpreadsheetReaderDelegate(_configuration);
+ }
+ }
+ }
+ }
+ return _spreadsheetReaderDelegate;
+ }
+
+ private InputStream getInputStream() throws MetaModelException {
+ InputStream inputStream = _resource.read();
+ if (!inputStream.markSupported()) {
+ inputStream = new PushbackInputStream(inputStream, 8);
+ }
+ return inputStream;
+ }
+
+ private LazyRef<InputStream> getInputStreamRef() throws MetaModelException {
+ final LazyRef<InputStream> inputStreamRef = new LazyRef<InputStream>() {
+ @Override
+ public InputStream fetch() {
+ InputStream inputStream = getInputStream();
+ return inputStream;
+ }
+ };
+ return inputStreamRef;
+ }
+
+ protected void notifyTablesModified() {
+ LazyRef<InputStream> inputStreamRef = getInputStreamRef();
+ try {
+ getSpreadsheetReaderDelegate(inputStreamRef).notifyTablesModified(inputStreamRef);
+ } finally {
+ if (inputStreamRef.isFetched()) {
+ FileHelper.safeClose(inputStreamRef.get());
+ }
+ }
+ }
+
+ @Override
+ public void executeUpdate(UpdateScript update) {
+ ExcelUpdateCallback updateCallback = new ExcelUpdateCallback(this);
+ synchronized (WRITE_LOCK) {
+ try {
+ update.run(updateCallback);
+ } finally {
+ updateCallback.close();
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/apache/metamodel/excel/ExcelDeleteBuilder.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/ExcelDeleteBuilder.java b/excel/src/main/java/org/apache/metamodel/excel/ExcelDeleteBuilder.java
new file mode 100644
index 0000000..4b9308c
--- /dev/null
+++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelDeleteBuilder.java
@@ -0,0 +1,81 @@
+/**
+ * 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.excel;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.MetaModelHelper;
+import org.eobjects.metamodel.data.DataSetHeader;
+import org.eobjects.metamodel.data.DefaultRow;
+import org.eobjects.metamodel.data.SimpleDataSetHeader;
+import org.eobjects.metamodel.delete.AbstractRowDeletionBuilder;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Table;
+
+final class ExcelDeleteBuilder extends AbstractRowDeletionBuilder {
+
+ private final ExcelUpdateCallback _updateCallback;
+
+ public ExcelDeleteBuilder(ExcelUpdateCallback updateCallback, Table table) {
+ super(table);
+ _updateCallback = updateCallback;
+ }
+
+ @Override
+ public void execute() throws MetaModelException {
+ // close the update callback will flush any changes
+ _updateCallback.close();
+
+ // read the workbook without streaming, since this will not wrap it in a
+ // streaming workbook implementation (which do not support random
+ // accessing rows).
+ final Workbook workbook = _updateCallback.getWorkbook(false);
+
+ final String tableName = getTable().getName();
+ final SelectItem[] selectItems = MetaModelHelper.createSelectItems(getTable().getColumns());
+ final DataSetHeader header = new SimpleDataSetHeader(selectItems);
+ final Sheet sheet = workbook.getSheet(tableName);
+
+ final Iterator<Row> rowIterator = ExcelUtils.getRowIterator(sheet, _updateCallback.getConfiguration(), true);
+ final List<Row> rowsToDelete = new ArrayList<Row>();
+ while (rowIterator.hasNext()) {
+ final Row excelRow = rowIterator.next();
+ final DefaultRow row = ExcelUtils.createRow(workbook, excelRow, header);
+
+ final boolean deleteRow = deleteRow(row);
+ if (deleteRow) {
+ rowsToDelete.add(excelRow);
+ }
+ }
+
+ // reverse the list to not mess up any row numbers
+ Collections.reverse(rowsToDelete);
+
+ for (Row row : rowsToDelete) {
+ sheet.removeRow(row);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/apache/metamodel/excel/ExcelDropTableBuilder.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/ExcelDropTableBuilder.java b/excel/src/main/java/org/apache/metamodel/excel/ExcelDropTableBuilder.java
new file mode 100644
index 0000000..b303622
--- /dev/null
+++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelDropTableBuilder.java
@@ -0,0 +1,44 @@
+/**
+ * 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.excel;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.drop.AbstractTableDropBuilder;
+import org.eobjects.metamodel.drop.TableDropBuilder;
+import org.eobjects.metamodel.schema.MutableSchema;
+import org.eobjects.metamodel.schema.Table;
+
+final class ExcelDropTableBuilder extends AbstractTableDropBuilder implements TableDropBuilder {
+
+ private ExcelUpdateCallback _updateCallback;
+
+ public ExcelDropTableBuilder(ExcelUpdateCallback updateCallback, Table table) {
+ super(table);
+ _updateCallback = updateCallback;
+ }
+
+ @Override
+ public void execute() throws MetaModelException {
+ final Table table = getTable();
+ _updateCallback.removeSheet(table.getName());
+ final MutableSchema schema = (MutableSchema) table.getSchema();
+ schema.removeTable(table);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/apache/metamodel/excel/ExcelInsertBuilder.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/ExcelInsertBuilder.java b/excel/src/main/java/org/apache/metamodel/excel/ExcelInsertBuilder.java
new file mode 100644
index 0000000..3a61a2f
--- /dev/null
+++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelInsertBuilder.java
@@ -0,0 +1,181 @@
+/**
+ * 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.excel;
+
+import java.util.Date;
+
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.Row;
+import org.eobjects.metamodel.data.Style;
+import org.eobjects.metamodel.data.Style.Color;
+import org.eobjects.metamodel.data.Style.SizeUnit;
+import org.eobjects.metamodel.data.Style.TextAlignment;
+import org.eobjects.metamodel.insert.AbstractRowInsertionBuilder;
+import org.eobjects.metamodel.insert.RowInsertionBuilder;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.LazyRef;
+
+/**
+ * {@link RowInsertionBuilder} for excel spreadsheets.
+ *
+ * @author Kasper Sørensen
+ */
+final class ExcelInsertBuilder extends
+ AbstractRowInsertionBuilder<ExcelUpdateCallback> {
+
+ public ExcelInsertBuilder(ExcelUpdateCallback updateCallback, Table table) {
+ super(updateCallback, table);
+ }
+
+ @Override
+ public void execute() {
+ final Object[] values = getValues();
+ final Style[] styles = getStyles();
+
+ final Row row = getUpdateCallback().createRow(getTable().getName());
+
+ final Column[] columns = getColumns();
+ for (int i = 0; i < columns.length; i++) {
+ Object value = values[i];
+ if (value != null) {
+ int columnNumber = columns[i].getColumnNumber();
+ Cell cell = row.createCell(columnNumber);
+
+ // use a lazyref and the isFetched method to only create style
+ // if nescesary
+ LazyRef<CellStyle> cellStyle = new LazyRef<CellStyle>() {
+ @Override
+ protected CellStyle fetch() {
+ return getUpdateCallback().createCellStyle();
+ }
+ };
+
+ if (value instanceof Number) {
+ cell.setCellValue(((Number) value).doubleValue());
+ } else if (value instanceof Boolean) {
+ cell.setCellValue((Boolean) value);
+ } else if (value instanceof Date) {
+ cell.setCellValue((Date) value);
+ } else {
+ cell.setCellValue(value.toString());
+ }
+
+ Style style = styles[i];
+ if (style != null && !Style.NO_STYLE.equals(style)) {
+ LazyRef<Font> font = new LazyRef<Font>() {
+ @Override
+ protected Font fetch() {
+ return getUpdateCallback().createFont();
+ }
+
+ };
+ if (style.isBold()) {
+ font.get().setBoldweight(Font.BOLDWEIGHT_BOLD);
+ }
+ if (style.isItalic()) {
+ font.get().setItalic(true);
+ }
+ if (style.isUnderline()) {
+ font.get().setUnderline(Font.U_SINGLE);
+ }
+ if (style.getFontSize() != null) {
+ Integer fontSize = style.getFontSize();
+ SizeUnit sizeUnit = style.getFontSizeUnit();
+ if (sizeUnit == SizeUnit.PERCENT) {
+ fontSize = convertFontPercentageToPt(fontSize);
+ }
+ font.get().setFontHeightInPoints(fontSize.shortValue());
+ }
+ Color foregroundColor = style.getForegroundColor();
+ if (foregroundColor != null) {
+ short index = getUpdateCallback().getColorIndex(
+ foregroundColor);
+ font.get().setColor(index);
+ }
+ if (font.isFetched()) {
+ cellStyle.get().setFont(font.get());
+ }
+ if (style.getAlignment() != null) {
+ cellStyle.get().setAlignment(
+ getAlignment(style.getAlignment()));
+ }
+
+ final Color backgroundColor = style.getBackgroundColor();
+ if (backgroundColor != null) {
+ cellStyle.get().setFillPattern(
+ CellStyle.SOLID_FOREGROUND);
+ cellStyle.get().setFillForegroundColor(
+ getUpdateCallback().getColorIndex(
+ backgroundColor));
+ }
+ }
+
+ if (value instanceof Date) {
+ if (cellStyle.isFetched()) {
+ cellStyle.get().setDataFormat(
+ getUpdateCallback().getDateCellFormat());
+ } else {
+ cellStyle = new LazyRef<CellStyle>() {
+ @Override
+ protected CellStyle fetch() {
+ return getUpdateCallback().getDateCellStyle();
+ }
+ };
+ // trigger the fetch
+ cellStyle.get();
+ }
+ }
+
+ if (cellStyle.isFetched()) {
+ cell.setCellStyle(cellStyle.get());
+ }
+ }
+ }
+ }
+
+ /**
+ * Converts a percentage based font size to excel "pt" scale.
+ *
+ * @param percentage
+ * @return
+ */
+ private Integer convertFontPercentageToPt(Integer percentage) {
+ Double d = percentage.intValue() * 11.0 / 100;
+ return d.intValue();
+ }
+
+ private short getAlignment(TextAlignment alignment) {
+ switch (alignment) {
+ case LEFT:
+ return CellStyle.ALIGN_LEFT;
+ case RIGHT:
+ return CellStyle.ALIGN_RIGHT;
+ case CENTER:
+ return CellStyle.ALIGN_CENTER;
+ case JUSTIFY:
+ return CellStyle.ALIGN_JUSTIFY;
+ default:
+ throw new IllegalArgumentException("Unknown alignment type: "
+ + alignment);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/apache/metamodel/excel/ExcelTableCreationBuilder.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/ExcelTableCreationBuilder.java b/excel/src/main/java/org/apache/metamodel/excel/ExcelTableCreationBuilder.java
new file mode 100644
index 0000000..7a579e5
--- /dev/null
+++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelTableCreationBuilder.java
@@ -0,0 +1,65 @@
+/**
+ * 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.excel;
+
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.eobjects.metamodel.create.AbstractTableCreationBuilder;
+import org.eobjects.metamodel.create.TableCreationBuilder;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.MutableSchema;
+import org.eobjects.metamodel.schema.MutableTable;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * {@link TableCreationBuilder} implementation for Excel spreadsheets.
+ *
+ * @author Kasper Sørensen
+ */
+final class ExcelTableCreationBuilder extends AbstractTableCreationBuilder<ExcelUpdateCallback> {
+
+ public ExcelTableCreationBuilder(ExcelUpdateCallback updateCallback, Schema schema, String name) {
+ super(updateCallback, schema, name);
+ }
+
+ @Override
+ public Table execute() {
+ final ExcelUpdateCallback updateCallback = getUpdateCallback();
+ final MutableTable table = getTable();
+
+ final Sheet sheet = updateCallback.createSheet(table.getName());
+
+ final int lineNumber = updateCallback.getConfiguration().getColumnNameLineNumber();
+ if (lineNumber != ExcelConfiguration.NO_COLUMN_NAME_LINE) {
+ final int zeroBasedLineNumber = lineNumber - 1;
+ final Row row = sheet.createRow(zeroBasedLineNumber);
+ final Column[] columns = table.getColumns();
+ for (int i = 0; i < columns.length; i++) {
+ final Column column = columns[i];
+ final int columnNumber = column.getColumnNumber();
+ row.createCell(columnNumber).setCellValue(column.getName());
+ }
+ }
+
+ final MutableSchema schema = (MutableSchema) table.getSchema();
+ schema.addTable((MutableTable) table);
+ return table;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/apache/metamodel/excel/ExcelUpdateCallback.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/ExcelUpdateCallback.java b/excel/src/main/java/org/apache/metamodel/excel/ExcelUpdateCallback.java
new file mode 100644
index 0000000..533a878
--- /dev/null
+++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelUpdateCallback.java
@@ -0,0 +1,238 @@
+/**
+ * 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.excel;
+
+import org.apache.poi.hssf.usermodel.HSSFPalette;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.streaming.SXSSFSheet;
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.eobjects.metamodel.AbstractUpdateCallback;
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.create.TableCreationBuilder;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.Style.Color;
+import org.eobjects.metamodel.delete.RowDeletionBuilder;
+import org.eobjects.metamodel.drop.TableDropBuilder;
+import org.eobjects.metamodel.insert.RowInsertionBuilder;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+final class ExcelUpdateCallback extends AbstractUpdateCallback implements UpdateCallback {
+
+ private final ExcelDataContext _dataContext;
+ private final ExcelConfiguration _configuration;
+ private boolean _sheetsModified;
+ private Workbook _workbook;
+ private Short _dateCellFormat;
+ private CellStyle _dateCellStyle;
+
+ public ExcelUpdateCallback(ExcelDataContext dataContext) {
+ super(dataContext);
+ _sheetsModified = false;
+ _configuration = dataContext.getConfiguration();
+ _dataContext = dataContext;
+ }
+
+ @Override
+ public TableCreationBuilder createTable(Schema schema, String name) throws IllegalArgumentException,
+ IllegalStateException {
+ return new ExcelTableCreationBuilder(this, schema, name);
+ }
+
+ @Override
+ public RowInsertionBuilder insertInto(Table table) throws IllegalArgumentException, IllegalStateException {
+ return new ExcelInsertBuilder(this, table);
+ }
+
+ protected ExcelConfiguration getConfiguration() {
+ return _configuration;
+ }
+
+ @Override
+ public ExcelDataContext getDataContext() {
+ return _dataContext;
+ }
+
+ protected void close() {
+ if (_workbook != null) {
+ ExcelUtils.writeWorkbook(_dataContext, _workbook);
+
+ _workbook = null;
+ _dateCellFormat = null;
+ _dateCellStyle = null;
+ }
+ if (_sheetsModified) {
+ _dataContext.notifyTablesModified();
+ _sheetsModified = false;
+ }
+ }
+
+ protected Workbook getWorkbook(boolean streamingAllowed) {
+ if (_workbook == null || (!streamingAllowed && _workbook instanceof SXSSFWorkbook)) {
+ if (_workbook != null) {
+ ExcelUtils.writeWorkbook(_dataContext, _workbook);
+ }
+ _workbook = ExcelUtils.readWorkbook(_dataContext);
+ if (streamingAllowed && _workbook instanceof XSSFWorkbook) {
+ _workbook = new SXSSFWorkbook((XSSFWorkbook) _workbook);
+ }
+ }
+ return _workbook;
+ }
+
+ protected Sheet createSheet(String name) {
+ Sheet sheet = getWorkbook(true).createSheet(name);
+ _sheetsModified = true;
+ return sheet;
+ }
+
+ protected void removeSheet(String name) {
+ int index = getWorkbook(true).getSheetIndex(name);
+ if (index != -1) {
+ getWorkbook(true).removeSheetAt(index);
+ _sheetsModified = true;
+ }
+ }
+
+ protected Row createRow(String name) {
+ if (_sheetsModified) {
+ close();
+ }
+ Sheet sheet = getWorkbook(true).getSheet(name);
+ int lastRowNum = getLastRowNum(sheet);
+ Row row = sheet.createRow(lastRowNum + 1);
+ return row;
+ }
+
+ private int getLastRowNum(Sheet sheet) {
+ final int lastRowNum = sheet.getLastRowNum();
+ if (lastRowNum == 0 && sheet instanceof SXSSFSheet) {
+ // streaming sheets have bad behaviour in this scenario - since no
+ // rows are in cache, it will return 0!
+ DataSet ds = _dataContext.query().from(sheet.getSheetName()).selectCount().execute();
+ ds.next();
+ final Number count = (Number) ds.getRow().getValue(0);
+ final int columnNameLineNumber = _configuration.getColumnNameLineNumber();
+ int oneBasedResult = count.intValue()
+ + (columnNameLineNumber == ExcelConfiguration.NO_COLUMN_NAME_LINE ? 0 : columnNameLineNumber);
+ return oneBasedResult - 1;
+ }
+ return lastRowNum;
+ }
+
+ /**
+ * Creates a new cell style in the spreadsheet
+ *
+ * @return
+ */
+ public CellStyle createCellStyle() {
+ Workbook workbook = getWorkbook(true);
+ return workbook.createCellStyle();
+ }
+
+ public Font createFont() {
+ Workbook workbook = getWorkbook(true);
+ return workbook.createFont();
+ }
+
+ protected Sheet getSheet(String name) {
+ return getWorkbook(true).getSheet(name);
+ }
+
+ /**
+ * Gets the index identifier for the date format
+ *
+ * @return
+ */
+ public short getDateCellFormat() {
+ if (_dateCellFormat == null) {
+ Workbook workbook = getWorkbook(true);
+ _dateCellFormat = workbook.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm");
+ }
+ return _dateCellFormat;
+ }
+
+ /**
+ * Gets a shared, reusable cell style for "pure date" cells (eg. no other
+ * styling applied)
+ *
+ * @return
+ */
+ public CellStyle getDateCellStyle() {
+ if (_dateCellStyle == null) {
+ _dateCellStyle = createCellStyle();
+ _dateCellStyle.setDataFormat(getDateCellFormat());
+ }
+ return _dateCellStyle;
+ }
+
+ public short getColorIndex(Color color) {
+ Workbook workbook = getWorkbook(true);
+ if (workbook instanceof HSSFWorkbook) {
+ HSSFPalette palette = ((HSSFWorkbook) workbook).getCustomPalette();
+ byte r = toRgb(color.getRed());
+ byte g = toRgb(color.getGreen());
+ byte b = toRgb(color.getBlue());
+
+ HSSFColor index = palette.findColor(r, g, b);
+ if (index == null) {
+ index = palette.findSimilarColor(r, g, b);
+ }
+ return index.getIndex();
+ }
+ throw new IllegalStateException("Unexpected workbook type: " + workbook.getClass());
+ }
+
+ private byte toRgb(int i) {
+ assert i >= 0;
+ assert i <= 255;
+
+ if (i > 127) {
+ i = i - 256;
+ }
+ return (byte) i;
+ }
+
+ @Override
+ public boolean isDropTableSupported() {
+ return true;
+ }
+
+ @Override
+ public TableDropBuilder dropTable(Table table) throws UnsupportedOperationException {
+ return new ExcelDropTableBuilder(this, table);
+ }
+
+ @Override
+ public boolean isDeleteSupported() {
+ return true;
+ }
+
+ @Override
+ public RowDeletionBuilder deleteFrom(Table table) throws UnsupportedOperationException {
+ return new ExcelDeleteBuilder(this, table);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java b/excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java
new file mode 100644
index 0000000..e31d61d
--- /dev/null
+++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java
@@ -0,0 +1,419 @@
+/**
+ * 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.excel;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.text.NumberFormat;
+import java.util.Date;
+import java.util.Iterator;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
+import org.apache.poi.hssf.usermodel.HSSFFont;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.ss.formula.FormulaParseException;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.Color;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.FontUnderline;
+import org.apache.poi.ss.usermodel.FormulaError;
+import org.apache.poi.ss.usermodel.FormulaEvaluator;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
+import org.apache.poi.xssf.usermodel.XSSFCell;
+import org.apache.poi.xssf.usermodel.XSSFColor;
+import org.apache.poi.xssf.usermodel.XSSFFont;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.MetaModelHelper;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.DataSetHeader;
+import org.eobjects.metamodel.data.DefaultRow;
+import org.eobjects.metamodel.data.EmptyDataSet;
+import org.eobjects.metamodel.data.Style;
+import org.eobjects.metamodel.data.Style.SizeUnit;
+import org.eobjects.metamodel.data.StyleBuilder;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.Action;
+import org.eobjects.metamodel.util.DateUtils;
+import org.eobjects.metamodel.util.FormatHelper;
+import org.eobjects.metamodel.util.Func;
+import org.eobjects.metamodel.util.Resource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.XMLReader;
+
+/**
+ * Convenience/reusable methods for Excel workbook handling.
+ *
+ * @author Kasper Sørensen
+ */
+final class ExcelUtils {
+
+ private static final Logger logger = LoggerFactory.getLogger(ExcelUtils.class);
+
+ private static final NumberFormat _numberFormat = FormatHelper.getUiNumberFormat();
+
+ private ExcelUtils() {
+ // prevent instantiation
+ }
+
+ public static XMLReader createXmlReader() {
+ try {
+ SAXParserFactory saxFactory = SAXParserFactory.newInstance();
+ SAXParser saxParser = saxFactory.newSAXParser();
+ XMLReader sheetParser = saxParser.getXMLReader();
+ return sheetParser;
+ } catch (Exception e) {
+ throw new MetaModelException(e);
+ }
+ }
+
+ /**
+ * Initializes a workbook instance based on a inputstream.
+ *
+ * @return a workbook instance based on the inputstream.
+ */
+ public static Workbook readWorkbook(InputStream inputStream) {
+ try {
+ return WorkbookFactory.create(inputStream);
+ } catch (Exception e) {
+ logger.error("Could not open workbook", e);
+ throw new IllegalStateException("Could not open workbook", e);
+ }
+ }
+
+ public static Workbook readWorkbook(Resource resource) {
+ return resource.read(new Func<InputStream, Workbook>() {
+ @Override
+ public Workbook eval(InputStream inputStream) {
+ return readWorkbook(inputStream);
+ }
+ });
+ }
+
+ public static boolean isXlsxFile(Resource resource) {
+ if (resource == null) {
+ return false;
+ }
+ return resource.getName().toLowerCase().endsWith(".xlsx");
+ }
+
+ /**
+ * Initializes a workbook instance based on a {@link ExcelDataContext}.
+ *
+ * @return a workbook instance based on the ExcelDataContext.
+ */
+ public static Workbook readWorkbook(ExcelDataContext dataContext) {
+ Resource resource = dataContext.getResource();
+ if (!resource.isExists()) {
+ if (isXlsxFile(resource)) {
+ return new SXSSFWorkbook(1000);
+ } else {
+ return new HSSFWorkbook();
+ }
+ }
+ return readWorkbook(resource);
+ }
+
+ public static void writeWorkbook(ExcelDataContext dataContext, final Workbook wb) {
+ final Resource resource = dataContext.getResource();
+ resource.write(new Action<OutputStream>() {
+ @Override
+ public void run(OutputStream outputStream) throws Exception {
+ wb.write(outputStream);
+ }
+ });
+ }
+
+ public static String getCellValue(Workbook wb, Cell cell) {
+ if (cell == null) {
+ return null;
+ }
+
+ final String cellCoordinate = "(" + cell.getRowIndex() + "," + cell.getColumnIndex() + ")";
+
+ final String result;
+
+ switch (cell.getCellType()) {
+ case Cell.CELL_TYPE_BLANK:
+ result = null;
+ break;
+ case Cell.CELL_TYPE_BOOLEAN:
+ result = Boolean.toString(cell.getBooleanCellValue());
+ break;
+ case Cell.CELL_TYPE_ERROR:
+ String errorResult;
+ try {
+ byte errorCode = cell.getErrorCellValue();
+ FormulaError formulaError = FormulaError.forInt(errorCode);
+ errorResult = formulaError.getString();
+ } catch (RuntimeException e) {
+ logger.debug("Getting error code for {} failed!: {}", cellCoordinate, e.getMessage());
+ if (cell instanceof XSSFCell) {
+ // hack to get error string, which is available
+ String value = ((XSSFCell) cell).getErrorCellString();
+ errorResult = value;
+ } else {
+ logger.error("Couldn't handle unexpected error scenario in cell: " + cellCoordinate, e);
+ throw e;
+ }
+ }
+ result = errorResult;
+ break;
+ case Cell.CELL_TYPE_FORMULA:
+ // result = cell.getCellFormula();
+ result = getFormulaCellValue(wb, cell);
+ break;
+ case Cell.CELL_TYPE_NUMERIC:
+ if (HSSFDateUtil.isCellDateFormatted(cell)) {
+ Date date = cell.getDateCellValue();
+ if (date == null) {
+ result = null;
+ } else {
+ result = DateUtils.createDateFormat().format(date);
+ }
+ } else {
+ // TODO: Consider not formatting it, but simple using
+ // Double.toString(...)
+ result = _numberFormat.format(cell.getNumericCellValue());
+ }
+ break;
+ case Cell.CELL_TYPE_STRING:
+ result = cell.getRichStringCellValue().getString();
+ break;
+ default:
+ throw new IllegalStateException("Unknown cell type: " + cell.getCellType());
+ }
+
+ logger.debug("cell {} resolved to value: {}", cellCoordinate, result);
+
+ return result;
+ }
+
+ private static String getFormulaCellValue(Workbook wb, Cell cell) {
+ // first try with a cached/precalculated value
+ try {
+ double numericCellValue = cell.getNumericCellValue();
+ // TODO: Consider not formatting it, but simple using
+ // Double.toString(...)
+ return _numberFormat.format(numericCellValue);
+ } catch (Exception e) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Failed to fetch cached/precalculated formula value of cell: " + cell, e);
+ }
+ }
+
+ // evaluate cell first, if possible
+ try {
+ if (logger.isInfoEnabled()) {
+ logger.info("cell({},{}) is a formula. Attempting to evaluate: {}",
+ new Object[] { cell.getRowIndex(), cell.getColumnIndex(), cell.getCellFormula() });
+ }
+
+ final FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
+
+ // calculates the formula and puts it's value back into the cell
+ final Cell evaluatedCell = evaluator.evaluateInCell(cell);
+
+ return getCellValue(wb, evaluatedCell);
+ } catch (RuntimeException e) {
+ logger.warn("Exception occurred while evaluating formula at position ({},{}): {}", new Object[] { cell.getRowIndex(),
+ cell.getColumnIndex(), e.getMessage() });
+ // Some exceptions we simply log - result will be then be the
+ // actual formula
+ if (e instanceof FormulaParseException) {
+ logger.error("Parse exception occurred while evaluating cell formula: " + cell, e);
+ } else if (e instanceof IllegalArgumentException) {
+ logger.error("Illegal formula argument occurred while evaluating cell formula: " + cell, e);
+ } else {
+ logger.error("Unexpected exception occurred while evaluating cell formula: " + cell, e);
+ }
+ }
+
+ // last resort: return the string formula
+ return cell.getCellFormula();
+ }
+
+ public static Style getCellStyle(Workbook workbook, Cell cell) {
+ if (cell == null) {
+ return Style.NO_STYLE;
+ }
+ final CellStyle cellStyle = cell.getCellStyle();
+
+ final short fontIndex = cellStyle.getFontIndex();
+ final Font font = workbook.getFontAt(fontIndex);
+ final StyleBuilder styleBuilder = new StyleBuilder();
+
+ // Font bold, italic, underline
+ if (font.getBoldweight() >= Font.BOLDWEIGHT_BOLD) {
+ styleBuilder.bold();
+ }
+ if (font.getItalic()) {
+ styleBuilder.italic();
+ }
+ if (font.getUnderline() != FontUnderline.NONE.getByteValue()) {
+ styleBuilder.underline();
+ }
+
+ // Font size
+ final Font stdFont = workbook.getFontAt((short) 0);
+ final short fontSize = font.getFontHeightInPoints();
+ if (stdFont.getFontHeightInPoints() != fontSize) {
+ styleBuilder.fontSize(fontSize, SizeUnit.PT);
+ }
+
+ // Font color
+ final short colorIndex = font.getColor();
+ if (font instanceof HSSFFont) {
+ if (colorIndex != HSSFFont.COLOR_NORMAL) {
+ final HSSFWorkbook wb = (HSSFWorkbook) workbook;
+ HSSFColor color = wb.getCustomPalette().getColor(colorIndex);
+ if (color != null) {
+ short[] triplet = color.getTriplet();
+ styleBuilder.foreground(triplet);
+ }
+ }
+ } else if (font instanceof XSSFFont) {
+ XSSFFont xssfFont = (XSSFFont) font;
+
+ XSSFColor color = xssfFont.getXSSFColor();
+ if (color != null) {
+ String argbHex = color.getARGBHex();
+ if (argbHex != null) {
+ styleBuilder.foreground(argbHex.substring(2));
+ }
+ }
+ } else {
+ throw new IllegalStateException("Unexpected font type: " + (font == null ? "null" : font.getClass()) + ")");
+ }
+
+ // Background color
+ if (cellStyle.getFillPattern() == 1) {
+ Color color = cellStyle.getFillForegroundColorColor();
+ if (color instanceof HSSFColor) {
+ short[] triplet = ((HSSFColor) color).getTriplet();
+ if (triplet != null) {
+ styleBuilder.background(triplet);
+ }
+ } else if (color instanceof XSSFColor) {
+ String argb = ((XSSFColor) color).getARGBHex();
+ if (argb != null) {
+ styleBuilder.background(argb.substring(2));
+ }
+ } else {
+ throw new IllegalStateException("Unexpected color type: " + (color == null ? "null" : color.getClass()) + ")");
+ }
+ }
+
+ // alignment
+ switch (cellStyle.getAlignment()) {
+ case CellStyle.ALIGN_LEFT:
+ styleBuilder.leftAligned();
+ break;
+ case CellStyle.ALIGN_RIGHT:
+ styleBuilder.rightAligned();
+ break;
+ case CellStyle.ALIGN_CENTER:
+ styleBuilder.centerAligned();
+ break;
+ case CellStyle.ALIGN_JUSTIFY:
+ styleBuilder.justifyAligned();
+ break;
+ }
+
+ return styleBuilder.create();
+ }
+
+ public static Iterator<Row> getRowIterator(Sheet sheet, ExcelConfiguration configuration, boolean jumpToDataRows) {
+ final Iterator<Row> iterator;
+ if (configuration.isSkipEmptyLines()) {
+ iterator = sheet.rowIterator();
+ } else {
+ iterator = new ZeroBasedRowIterator(sheet);
+ }
+
+ if (jumpToDataRows) {
+ final int columnNameLineNumber = configuration.getColumnNameLineNumber();
+ if (columnNameLineNumber != ExcelConfiguration.NO_COLUMN_NAME_LINE) {
+ // iterate past the column headers
+ if (iterator.hasNext()) {
+ iterator.next();
+ }
+ for (int i = 1; i < columnNameLineNumber; i++) {
+ if (iterator.hasNext()) {
+ iterator.next();
+ } else {
+ // no more rows!
+ break;
+ }
+ }
+ }
+ }
+
+ return iterator;
+ }
+
+ /**
+ * Creates a MetaModel row based on an Excel row
+ *
+ * @param workbook
+ * @param row
+ * @param selectItems
+ * select items of the columns in the table
+ * @return
+ */
+ public static DefaultRow createRow(Workbook workbook, Row row, DataSetHeader header) {
+ final int size = header.size();
+ final String[] values = new String[size];
+ final Style[] styles = new Style[size];
+ if (row != null) {
+ for (int i = 0; i < size; i++) {
+ final int columnNumber = header.getSelectItem(i).getColumn().getColumnNumber();
+ final Cell cell = row.getCell(columnNumber);
+ final String value = ExcelUtils.getCellValue(workbook, cell);
+ final Style style = ExcelUtils.getCellStyle(workbook, cell);
+ values[i] = value;
+ styles[i] = style;
+ }
+ }
+
+ return new DefaultRow(header, values, styles);
+ }
+
+ public static DataSet getDataSet(Workbook workbook, Sheet sheet, Table table, ExcelConfiguration configuration) {
+ final SelectItem[] selectItems = MetaModelHelper.createSelectItems(table.getColumns());
+ final Iterator<Row> rowIterator = getRowIterator(sheet, configuration, true);
+ if (!rowIterator.hasNext()) {
+ // no more rows!
+ return new EmptyDataSet(selectItems);
+ }
+
+ final DataSet dataSet = new XlsDataSet(selectItems, workbook, rowIterator);
+ return dataSet;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/apache/metamodel/excel/SpreadsheetReaderDelegate.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/SpreadsheetReaderDelegate.java b/excel/src/main/java/org/apache/metamodel/excel/SpreadsheetReaderDelegate.java
new file mode 100644
index 0000000..9cdbe42
--- /dev/null
+++ b/excel/src/main/java/org/apache/metamodel/excel/SpreadsheetReaderDelegate.java
@@ -0,0 +1,45 @@
+/**
+ * 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.excel;
+
+import java.io.InputStream;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.Ref;
+
+/**
+ * Delegate for spreadsheet-implementation specific operations in an
+ * {@link ExcelDataContext}.
+ *
+ * @author Kasper Sørensen
+ */
+interface SpreadsheetReaderDelegate {
+
+ public void notifyTablesModified(Ref<InputStream> inputStreamRef);
+
+ public Schema createSchema(InputStream inputStream, String schemaName)
+ throws Exception;
+
+ public DataSet executeQuery(InputStream inputStream, Table table,
+ Column[] columns, int maxRows) throws Exception;
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/apache/metamodel/excel/XlsDataSet.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/XlsDataSet.java b/excel/src/main/java/org/apache/metamodel/excel/XlsDataSet.java
new file mode 100644
index 0000000..133233f
--- /dev/null
+++ b/excel/src/main/java/org/apache/metamodel/excel/XlsDataSet.java
@@ -0,0 +1,78 @@
+/**
+ * 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.excel;
+
+import java.util.Iterator;
+
+import org.apache.poi.ss.usermodel.Workbook;
+import org.eobjects.metamodel.data.AbstractDataSet;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.query.SelectItem;
+
+/**
+ * Stream {@link DataSet} implementation for Excel support.
+ *
+ * @author Kasper Sørensen
+ */
+final class XlsDataSet extends AbstractDataSet {
+
+ private final Iterator<org.apache.poi.ss.usermodel.Row> _rowIterator;
+ private final Workbook _workbook;
+
+ private volatile org.apache.poi.ss.usermodel.Row _row;
+ private volatile boolean _closed;
+
+ /**
+ * Creates an XLS dataset
+ *
+ * @param selectItems
+ * the selectitems representing the columns of the table
+ * @param workbook
+ * @param rowIterator
+ */
+ public XlsDataSet(SelectItem[] selectItems, Workbook workbook,
+ Iterator<org.apache.poi.ss.usermodel.Row> rowIterator) {
+ super(selectItems);
+ _workbook = workbook;
+ _rowIterator = rowIterator;
+ _closed = false;
+ }
+
+ @Override
+ public boolean next() {
+ if (_rowIterator.hasNext()) {
+ _row = _rowIterator.next();
+ return true;
+ } else {
+ _row = null;
+ _closed = true;
+ return false;
+ }
+ }
+
+ @Override
+ public Row getRow() {
+ if (_closed) {
+ return null;
+ }
+
+ return ExcelUtils.createRow(_workbook, _row, getHeader());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/apache/metamodel/excel/XlsxRowCallback.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/XlsxRowCallback.java b/excel/src/main/java/org/apache/metamodel/excel/XlsxRowCallback.java
new file mode 100644
index 0000000..630a512
--- /dev/null
+++ b/excel/src/main/java/org/apache/metamodel/excel/XlsxRowCallback.java
@@ -0,0 +1,33 @@
+/**
+ * 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.excel;
+
+import java.util.List;
+
+import org.eobjects.metamodel.data.Style;
+
+/**
+ * Callback for read rows in an XLSX spreadsheet.
+ *
+ * @author Kasper Sørensen
+ */
+interface XlsxRowCallback {
+
+ public boolean row(int rowNumber, List<String> values, List<Style> styles);
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/main/java/org/apache/metamodel/excel/XlsxRowPublisherAction.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/XlsxRowPublisherAction.java b/excel/src/main/java/org/apache/metamodel/excel/XlsxRowPublisherAction.java
new file mode 100644
index 0000000..85bbd58
--- /dev/null
+++ b/excel/src/main/java/org/apache/metamodel/excel/XlsxRowPublisherAction.java
@@ -0,0 +1,103 @@
+/**
+ * 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.excel;
+
+import java.io.InputStream;
+import java.util.List;
+
+import org.apache.poi.xssf.eventusermodel.XSSFReader;
+import org.eobjects.metamodel.data.RowPublisher;
+import org.eobjects.metamodel.data.Style;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.util.Action;
+import org.eobjects.metamodel.util.FileHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+
+class XlsxRowPublisherAction implements Action<RowPublisher> {
+
+ private static final Logger logger = LoggerFactory
+ .getLogger(XlsxRowPublisherAction.class);
+
+ private final ExcelConfiguration _configuration;
+ private final Column[] _columns;
+ private final String _relationshipId;
+ private final XSSFReader _xssfReader;
+
+ public XlsxRowPublisherAction(ExcelConfiguration configuration,
+ Column[] columns, String relationshipId, XSSFReader xssfReader) {
+ _configuration = configuration;
+ _columns = columns;
+ _relationshipId = relationshipId;
+ _xssfReader = xssfReader;
+ }
+
+ @Override
+ public void run(final RowPublisher publisher) throws Exception {
+ final InputStream sheetData = _xssfReader.getSheet(_relationshipId);
+
+ final XlsxRowCallback rowCallback = new XlsxRowCallback() {
+ @Override
+ public boolean row(int rowNumber, List<String> values,
+ List<Style> styles) {
+ if (_configuration.getColumnNameLineNumber() != ExcelConfiguration.NO_COLUMN_NAME_LINE) {
+ final int zeroBasedLineNumber = _configuration.getColumnNameLineNumber() - 1;
+ if (rowNumber <= zeroBasedLineNumber) {
+ // skip header rows
+ return true;
+ }
+ }
+
+ Object[] rowData = new Object[_columns.length];
+ Style[] styleData = new Style[_columns.length];
+ for (int i = 0; i < _columns.length; i++) {
+ int columnNumber = _columns[i].getColumnNumber();
+ if (columnNumber < values.size()) {
+ rowData[i] = values.get(columnNumber);
+ styleData[i] = styles.get(columnNumber);
+ } else {
+ rowData[i] = null;
+ styleData[i] = Style.NO_STYLE;
+ }
+ }
+
+ return publisher.publish(rowData, styleData);
+ }
+ };
+ final XlsxSheetToRowsHandler handler = new XlsxSheetToRowsHandler(
+ rowCallback, _xssfReader, _configuration);
+
+ final XMLReader sheetParser = ExcelUtils.createXmlReader();
+ sheetParser.setContentHandler(handler);
+ sheetParser.setErrorHandler(handler);
+ try {
+ sheetParser.parse(new InputSource(sheetData));
+ } catch (XlsxStopParsingException e) {
+ logger.debug("Parsing stop signal thrown");
+ } catch (Exception e) {
+ logger.warn("Unexpected error occurred while parsing", e);
+ throw e;
+ } finally {
+ publisher.finished();
+ FileHelper.safeClose(sheetData);
+ }
+ }
+}
\ No newline at end of file
[44/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/SelectClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/SelectClause.java b/core/src/main/java/org/apache/metamodel/query/SelectClause.java
new file mode 100644
index 0000000..82688a5
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/SelectClause.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.query;
+
+import java.util.List;
+
+import org.eobjects.metamodel.schema.Column;
+
+/**
+ * Represents the SELECT clause of a query containing SelectItems.
+ *
+ * @see SelectItem
+ */
+public class SelectClause extends AbstractQueryClause<SelectItem> {
+
+ private static final long serialVersionUID = -2458447191169901181L;
+ private boolean _distinct = false;
+
+ public SelectClause(Query query) {
+ super(query, AbstractQueryClause.PREFIX_SELECT, AbstractQueryClause.DELIM_COMMA);
+ }
+
+ public SelectItem getSelectItem(Column column) {
+ if (column != null) {
+ for (SelectItem item : getItems()) {
+ if (column.equals(item.getColumn())) {
+ return item;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public String toSql(boolean includeSchemaInColumnPaths) {
+ if (getItems().size() == 0) {
+ return "";
+ }
+
+ final String sql = super.toSql(includeSchemaInColumnPaths);
+ StringBuilder sb = new StringBuilder(sql);
+ if (_distinct) {
+ sb.insert(AbstractQueryClause.PREFIX_SELECT.length(), "DISTINCT ");
+ }
+ return sb.toString();
+ }
+
+ public boolean isDistinct() {
+ return _distinct;
+ }
+
+ public void setDistinct(boolean distinct) {
+ _distinct = distinct;
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ super.decorateIdentity(identifiers);
+ identifiers.add(_distinct);
+ }
+}
\ 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/query/SelectItem.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/SelectItem.java b/core/src/main/java/org/apache/metamodel/query/SelectItem.java
new file mode 100644
index 0000000..a9b1707
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/SelectItem.java
@@ -0,0 +1,517 @@
+/**
+ * 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.query;
+
+import java.util.List;
+
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.BaseObject;
+import org.eobjects.metamodel.util.EqualsBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Represents a SELECT item. SelectItems can take different forms:
+ * <ul>
+ * <li>column SELECTs (selects a column from a table)</li>
+ * <li>column function SELECTs (aggregates the values of a column)</li>
+ * <li>expression SELECTs (retrieves data based on an expression (only supported
+ * for JDBC datastores)</li>
+ * <li>expression function SELECTs (retrieves databased on a function and an
+ * expression, only COUNT(*) is supported for non-JDBC datastores))</li>
+ * <li>SELECTs from subqueries (works just like column selects, but in stead of
+ * pointing to a column, it retrieves data from the select item of a subquery)</li>
+ * </ul>
+ *
+ * @see SelectClause
+ */
+public class SelectItem extends BaseObject implements QueryItem, Cloneable {
+
+ private static final long serialVersionUID = 317475105509663973L;
+ private static final Logger logger = LoggerFactory.getLogger(SelectItem.class);
+
+ // immutable fields (essense)
+ private final Column _column;
+ private final FunctionType _function;
+ private final String _expression;
+ private final SelectItem _subQuerySelectItem;
+ private final FromItem _fromItem;
+
+ // mutable fields (tweaking)
+ private boolean _functionApproximationAllowed;
+ private Query _query;
+ private String _alias;
+
+ /**
+ * All-arguments constructor
+ *
+ * @param column
+ * @param fromItem
+ * @param function
+ * @param expression
+ * @param subQuerySelectItem
+ * @param alias
+ * @param functionApproximationAllowed
+ */
+ private SelectItem(Column column, FromItem fromItem, FunctionType function, String expression,
+ SelectItem subQuerySelectItem, String alias, boolean functionApproximationAllowed) {
+ super();
+ _column = column;
+ _fromItem = fromItem;
+ _function = function;
+ _expression = expression;
+ _subQuerySelectItem = subQuerySelectItem;
+ _alias = alias;
+ _functionApproximationAllowed = functionApproximationAllowed;
+ }
+
+ /**
+ * Generates a COUNT(*) select item
+ */
+ public static SelectItem getCountAllItem() {
+ return new SelectItem(FunctionType.COUNT, "*", null);
+ }
+
+ public static boolean isCountAllItem(SelectItem item) {
+ if (item != null && item.getFunction() == FunctionType.COUNT && item.getExpression() == "*") {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Creates a simple SelectItem that selects from a column
+ *
+ * @param column
+ */
+ public SelectItem(Column column) {
+ this(null, column);
+ }
+
+ /**
+ * Creates a SelectItem that uses a function on a column, for example
+ * SUM(price) or MAX(age)
+ *
+ * @param function
+ * @param column
+ */
+ public SelectItem(FunctionType function, Column column) {
+ this(function, column, null);
+ }
+
+ /**
+ * Creates a SelectItem that references a column from a particular
+ * {@link FromItem}, for example a.price or p.age
+ *
+ * @param column
+ * @param fromItem
+ */
+ public SelectItem(Column column, FromItem fromItem) {
+ this(null, column, fromItem);
+ if (fromItem != null) {
+ Table fromItemTable = fromItem.getTable();
+ if (fromItemTable != null) {
+ Table columnTable = column.getTable();
+ if (columnTable != null && !columnTable.equals(fromItemTable)) {
+ throw new IllegalArgumentException("Column's table '" + columnTable.getName()
+ + "' is not equal to referenced table: " + fromItemTable);
+ }
+ }
+ }
+ }
+
+ /**
+ * Creates a SelectItem that uses a function on a column from a particular
+ * {@link FromItem}, for example SUM(a.price) or MAX(p.age)
+ *
+ * @param function
+ * @param column
+ * @param fromItem
+ */
+ public SelectItem(FunctionType function, Column column, FromItem fromItem) {
+ this(column, fromItem, function, null, null, null, false);
+ if (column == null) {
+ throw new IllegalArgumentException("column=null");
+ }
+ }
+
+ /**
+ * Creates a SelectItem based on an expression. All expression-based
+ * SelectItems must have aliases.
+ *
+ * @param expression
+ * @param alias
+ */
+ public SelectItem(String expression, String alias) {
+ this(null, expression, alias);
+ }
+
+ /**
+ * Creates a SelectItem based on a function and an expression. All
+ * expression-based SelectItems must have aliases.
+ *
+ * @param function
+ * @param expression
+ * @param alias
+ */
+ public SelectItem(FunctionType function, String expression, String alias) {
+ this(null, null, function, expression, null, alias, false);
+ if (expression == null) {
+ throw new IllegalArgumentException("expression=null");
+ }
+ }
+
+ /**
+ * Creates a SelectItem that references another select item in a subquery
+ *
+ * @param subQuerySelectItem
+ * @param subQueryFromItem
+ * the FromItem that holds the sub-query
+ */
+ public SelectItem(SelectItem subQuerySelectItem, FromItem subQueryFromItem) {
+ this(null, subQueryFromItem, null, null, subQuerySelectItem, null, false);
+ if (subQueryFromItem.getSubQuery() == null) {
+ throw new IllegalArgumentException("Only sub-query based FromItems allowed.");
+ }
+ if (subQuerySelectItem.getQuery() != null
+ && !subQuerySelectItem.getQuery().equals(subQueryFromItem.getSubQuery())) {
+ throw new IllegalArgumentException("The SelectItem must exist in the sub-query");
+ }
+ }
+
+ public String getAlias() {
+ return _alias;
+ }
+
+ public SelectItem setAlias(String alias) {
+ _alias = alias;
+ return this;
+ }
+
+ public FunctionType getFunction() {
+ return _function;
+ }
+
+ /**
+ * @return if this is a function based SelectItem where function calculation
+ * is allowed to be approximated (if the datastore type has an
+ * approximate calculation method). Approximated function results
+ * are as the name implies not exact, but might be valuable as an
+ * optimization in some cases.
+ */
+ public boolean isFunctionApproximationAllowed() {
+ return _functionApproximationAllowed;
+ }
+
+ public void setFunctionApproximationAllowed(boolean functionApproximationAllowed) {
+ _functionApproximationAllowed = functionApproximationAllowed;
+ }
+
+ public Column getColumn() {
+ return _column;
+ }
+
+ /**
+ * Tries to infer the {@link ColumnType} of this {@link SelectItem}. For
+ * expression based select items, this is not possible, and the method will
+ * return null.
+ *
+ * @return
+ */
+ public ColumnType getExpectedColumnType() {
+ if (_subQuerySelectItem != null) {
+ return _subQuerySelectItem.getExpectedColumnType();
+ }
+ if (_function != null) {
+ if (_column != null) {
+ return _function.getExpectedColumnType(_column.getType());
+ } else {
+ return _function.getExpectedColumnType(null);
+ }
+ }
+ if (_column != null) {
+ return _column.getType();
+ }
+ return null;
+ }
+
+ public String getExpression() {
+ return _expression;
+ }
+
+ public SelectItem setQuery(Query query) {
+ _query = query;
+ return this;
+ }
+
+ public Query getQuery() {
+ return _query;
+ }
+
+ public SelectItem getSubQuerySelectItem() {
+ return _subQuerySelectItem;
+ }
+
+ /**
+ * @deprecated use {@link #getFromItem()} instead
+ */
+ @Deprecated
+ public FromItem getSubQueryFromItem() {
+ return _fromItem;
+ }
+
+ public FromItem getFromItem() {
+ return _fromItem;
+ }
+
+ /**
+ * @return the name that this SelectItem can be referenced with, if
+ * referenced from a super-query. This will usually be the alias,
+ * but if there is no alias, then the column name will be used.
+ */
+ public String getSuperQueryAlias() {
+ return getSuperQueryAlias(true);
+ }
+
+ /**
+ * @return the name that this SelectItem can be referenced with, if
+ * referenced from a super-query. This will usually be the alias,
+ * but if there is no alias, then the column name will be used.
+ *
+ * @param includeQuotes
+ * indicates whether or not the output should include quotes, if
+ * the select item's column has quotes associated (typically
+ * true, but false if used for presentation)
+ */
+ public String getSuperQueryAlias(boolean includeQuotes) {
+ if (_alias != null) {
+ return _alias;
+ } else if (_column != null) {
+ final StringBuilder sb = new StringBuilder();
+ if (_function != null) {
+ sb.append(_function.toString());
+ sb.append('(');
+ }
+ if (includeQuotes) {
+ sb.append(_column.getQuotedName());
+ } else {
+ sb.append(_column.getName());
+ }
+ if (_function != null) {
+ sb.append(')');
+ }
+ return sb.toString();
+ } else {
+ logger.debug("Could not resolve a reasonable super-query alias for SelectItem: {}", toSql());
+ return toStringNoAlias().toString();
+ }
+ }
+
+ public String getSameQueryAlias() {
+ return getSameQueryAlias(false);
+ }
+
+ /**
+ * @return an alias that can be used in WHERE, GROUP BY and ORDER BY clauses
+ * in the same query
+ */
+ public String getSameQueryAlias(boolean includeSchemaInColumnPath) {
+ if (_column != null) {
+ StringBuilder sb = new StringBuilder();
+ String columnPrefix = getToStringColumnPrefix(includeSchemaInColumnPath);
+ sb.append(columnPrefix);
+ sb.append(_column.getQuotedName());
+ if (_function != null) {
+ sb.insert(0, _function + "(");
+ sb.append(")");
+ }
+ return sb.toString();
+ }
+ String alias = getAlias();
+ if (alias == null) {
+ alias = toStringNoAlias(includeSchemaInColumnPath).toString();
+ logger.debug("Could not resolve a reasonable same-query alias for SelectItem: {}", toSql());
+ }
+ return alias;
+ }
+
+ @Override
+ public String toSql() {
+ return toSql(false);
+ }
+
+ @Override
+ public String toSql(boolean includeSchemaInColumnPath) {
+ StringBuilder sb = toStringNoAlias(includeSchemaInColumnPath);
+ if (_alias != null) {
+ sb.append(" AS ");
+ sb.append(_alias);
+ }
+ return sb.toString();
+ }
+
+ public StringBuilder toStringNoAlias() {
+ return toStringNoAlias(false);
+ }
+
+ public StringBuilder toStringNoAlias(boolean includeSchemaInColumnPath) {
+ StringBuilder sb = new StringBuilder();
+ if (_column != null) {
+ sb.append(getToStringColumnPrefix(includeSchemaInColumnPath));
+ sb.append(_column.getQuotedName());
+ }
+ if (_expression != null) {
+ sb.append(_expression);
+ }
+ if (_fromItem != null && _subQuerySelectItem != null) {
+ if (_fromItem.getAlias() != null) {
+ sb.append(_fromItem.getAlias() + '.');
+ }
+ sb.append(_subQuerySelectItem.getSuperQueryAlias());
+ }
+ if (_function != null) {
+ sb.insert(0, _function + "(");
+ sb.append(")");
+ }
+ return sb;
+ }
+
+ private String getToStringColumnPrefix(boolean includeSchemaInColumnPath) {
+ StringBuilder sb = new StringBuilder();
+ if (_fromItem != null && _fromItem.getAlias() != null) {
+ sb.append(_fromItem.getAlias());
+ sb.append('.');
+ } else {
+ final Table table = _column.getTable();
+ String tableLabel;
+ if (_query == null) {
+ tableLabel = null;
+ } else {
+ tableLabel = _query.getFromClause().getAlias(table);
+ }
+ if (table != null) {
+ if (tableLabel == null) {
+ tableLabel = table.getQuotedName();
+ if (includeSchemaInColumnPath) {
+ Schema schema = table.getSchema();
+ if (schema != null) {
+ tableLabel = schema.getQuotedName() + "." + tableLabel;
+ }
+ }
+ }
+ sb.append(tableLabel);
+ sb.append('.');
+ }
+ }
+ return sb.toString();
+ }
+
+ public boolean equalsIgnoreAlias(SelectItem that) {
+ return equalsIgnoreAlias(that, false);
+ }
+
+ public boolean equalsIgnoreAlias(SelectItem that, boolean exactColumnCompare) {
+ if (that == null) {
+ return false;
+ }
+ if (that == this) {
+ return true;
+ }
+
+ EqualsBuilder eb = new EqualsBuilder();
+ if (exactColumnCompare) {
+ eb.append(this._column == that._column);
+ eb.append(this._fromItem, that._fromItem);
+ } else {
+ eb.append(this._column, that._column);
+ }
+ eb.append(this._function, that._function);
+ eb.append(this._functionApproximationAllowed, that._functionApproximationAllowed);
+ eb.append(this._expression, that._expression);
+ if (_subQuerySelectItem != null) {
+ eb.append(_subQuerySelectItem.equalsIgnoreAlias(that._subQuerySelectItem));
+ } else {
+ if (that._subQuerySelectItem != null) {
+ eb.append(false);
+ }
+ }
+ return eb.isEquals();
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ identifiers.add(_expression);
+ identifiers.add(_alias);
+ identifiers.add(_column);
+ identifiers.add(_function);
+ identifiers.add(_functionApproximationAllowed);
+ identifiers.add(_fromItem);
+ identifiers.add(_subQuerySelectItem);
+ }
+
+ @Override
+ protected SelectItem clone() {
+ final SelectItem subQuerySelectItem = (_subQuerySelectItem == null ? null : _subQuerySelectItem.clone());
+ final FromItem fromItem = (_fromItem == null ? null : _fromItem.clone());
+ final SelectItem s = new SelectItem(_column, fromItem, _function, _expression, subQuerySelectItem, _alias,
+ _functionApproximationAllowed);
+ return s;
+ }
+
+ /**
+ * Creates a copy of the {@link SelectItem}, with a different
+ * {@link FunctionType}.
+ *
+ * @param function
+ * @return
+ */
+ public SelectItem replaceFunction(FunctionType function) {
+ return new SelectItem(_column, _fromItem, function, _expression, _subQuerySelectItem, _alias,
+ _functionApproximationAllowed);
+ }
+
+ /**
+ * Investigates whether or not this SelectItem references a particular
+ * column. This will search for direct references and indirect references
+ * via subqueries.
+ *
+ * @param column
+ * @return a boolean that is true if the specified column is referenced by
+ * this SelectItem and false otherwise.
+ */
+ public boolean isReferenced(Column column) {
+ if (column != null) {
+ if (column.equals(_column)) {
+ return true;
+ }
+ if (_subQuerySelectItem != null) {
+ return _subQuerySelectItem.isReferenced(column);
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return toSql();
+ }
+}
\ 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/query/SumAggregateBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/SumAggregateBuilder.java b/core/src/main/java/org/apache/metamodel/query/SumAggregateBuilder.java
new file mode 100644
index 0000000..2cf8811
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/SumAggregateBuilder.java
@@ -0,0 +1,45 @@
+/**
+ * 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.query;
+
+import org.eobjects.metamodel.util.AggregateBuilder;
+import org.eobjects.metamodel.util.NumberComparator;
+
+final class SumAggregateBuilder implements AggregateBuilder<Double> {
+
+ private double sum;
+
+ @Override
+ public void add(Object o) {
+ if (o == null) {
+ return;
+ }
+ Number number = NumberComparator.toNumber(o);
+ if (number == null) {
+ throw new IllegalArgumentException("Could not convert to number: " + o);
+ }
+ sum += number.doubleValue();
+ }
+
+ @Override
+ public Double getAggregate() {
+ return sum;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/builder/AbstractFilterBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/AbstractFilterBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/AbstractFilterBuilder.java
new file mode 100644
index 0000000..2d3bd25
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/AbstractFilterBuilder.java
@@ -0,0 +1,459 @@
+/**
+ * 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.query.builder;
+
+import java.util.Collection;
+import java.util.Date;
+
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.OperatorType;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+
+/**
+ * Abstract implementation of {@link FilterBuilder} interface. All built filters
+ * are channeled to the {@link #applyFilter(FilterItem)} method which needs to
+ * be implemented by concrete implementations.
+ */
+public abstract class AbstractFilterBuilder<B> implements FilterBuilder<B> {
+
+ private final SelectItem _selectItem;
+
+ public AbstractFilterBuilder(SelectItem selectItem) {
+ this._selectItem = selectItem;
+ }
+
+ protected abstract B applyFilter(FilterItem filter);
+
+ /**
+ * Provides a way to
+ *
+ * @param queryParameter
+ * @return
+ */
+ public B applyFilter(OperatorType operator, Object operand) {
+ return applyFilter(new FilterItem(_selectItem, operator, operand));
+ }
+
+ @Override
+ public B in(Collection<?> values) {
+ return applyFilter(new FilterItem(_selectItem, OperatorType.IN, values));
+ }
+
+ @Override
+ public B in(Number... numbers) {
+ return applyFilter(new FilterItem(_selectItem, OperatorType.IN, numbers));
+ }
+
+ @Override
+ public B in(String... strings) {
+ return applyFilter(new FilterItem(_selectItem, OperatorType.IN, strings));
+ }
+
+ @Override
+ public B isNull() {
+ return applyFilter(new FilterItem(_selectItem, OperatorType.EQUALS_TO, null));
+ }
+
+ @Override
+ public B isNotNull() {
+ return applyFilter(new FilterItem(_selectItem, OperatorType.DIFFERENT_FROM, null));
+ }
+
+ @Override
+ public B isEquals(Column column) {
+ if (column == null) {
+ throw new IllegalArgumentException("column cannot be null");
+ }
+ return applyFilter(new FilterItem(_selectItem, OperatorType.EQUALS_TO, new SelectItem(column)));
+ }
+
+ @Override
+ public B isEquals(Date date) {
+ if (date == null) {
+ throw new IllegalArgumentException("date cannot be null");
+ }
+ return applyFilter(new FilterItem(_selectItem, OperatorType.EQUALS_TO, date));
+ }
+
+ @Override
+ public B isEquals(Number number) {
+ if (number == null) {
+ throw new IllegalArgumentException("number cannot be null");
+ }
+ return applyFilter(new FilterItem(_selectItem, OperatorType.EQUALS_TO, number));
+ }
+
+ @Override
+ public B isEquals(String string) {
+ if (string == null) {
+ throw new IllegalArgumentException("string cannot be null");
+ }
+ return applyFilter(new FilterItem(_selectItem, OperatorType.EQUALS_TO, string));
+ }
+
+ @Override
+ public B isEquals(Boolean bool) {
+ if (bool == null) {
+ throw new IllegalArgumentException("bool cannot be null");
+ }
+ return applyFilter(new FilterItem(_selectItem, OperatorType.EQUALS_TO, bool));
+ }
+
+ @Override
+ public B isEquals(Object obj) {
+ if (obj == null) {
+ return isNull();
+ }
+ if (obj instanceof Boolean) {
+ return isEquals((Boolean) obj);
+ }
+ if (obj instanceof Number) {
+ return isEquals((Number) obj);
+ }
+ if (obj instanceof Date) {
+ return isEquals((Date) obj);
+ }
+ if (obj instanceof String) {
+ return isEquals((String) obj);
+ }
+ throw new UnsupportedOperationException("Argument must be a Boolean, Number, Date or String. Found: " + obj);
+ }
+
+ @Override
+ public B differentFrom(Column column) {
+ if (column == null) {
+ throw new IllegalArgumentException("column cannot be null");
+ }
+ return applyFilter(new FilterItem(_selectItem, OperatorType.DIFFERENT_FROM, new SelectItem(column)));
+ }
+
+ @Override
+ public B differentFrom(Date date) {
+ if (date == null) {
+ throw new IllegalArgumentException("date cannot be null");
+ }
+ return applyFilter(new FilterItem(_selectItem, OperatorType.DIFFERENT_FROM, date));
+ }
+
+ @Override
+ public B differentFrom(Number number) {
+ if (number == null) {
+ throw new IllegalArgumentException("number cannot be null");
+ }
+ return applyFilter(new FilterItem(_selectItem, OperatorType.DIFFERENT_FROM, number));
+ }
+
+ @Override
+ public B differentFrom(String string) {
+ if (string == null) {
+ throw new IllegalArgumentException("string cannot be null");
+ }
+ return applyFilter(new FilterItem(_selectItem, OperatorType.DIFFERENT_FROM, string));
+ }
+
+ @Override
+ public B differentFrom(Boolean bool) {
+ if (bool == null) {
+ throw new IllegalArgumentException("bool cannot be null");
+ }
+ return applyFilter(new FilterItem(_selectItem, OperatorType.DIFFERENT_FROM, bool));
+ }
+
+ @Override
+ public B differentFrom(Object obj) {
+ if (obj == null) {
+ return isNotNull();
+ }
+ if (obj instanceof Boolean) {
+ return differentFrom((Boolean) obj);
+ }
+ if (obj instanceof Number) {
+ return differentFrom((Number) obj);
+ }
+ if (obj instanceof Date) {
+ return differentFrom((Date) obj);
+ }
+ if (obj instanceof String) {
+ return differentFrom((String) obj);
+ }
+ throw new UnsupportedOperationException("Argument must be a Boolean, Number, Date or String. Found: " + obj);
+ }
+
+ @Deprecated
+ @Override
+ public B higherThan(Column arg) {
+ return greaterThan(arg);
+ }
+
+ @Override
+ public B greaterThan(Column column) {
+ if (column == null) {
+ throw new IllegalArgumentException("column cannot be null");
+ }
+ return applyFilter(new FilterItem(_selectItem, OperatorType.GREATER_THAN, new SelectItem(column)));
+ }
+
+ @Deprecated
+ @Override
+ public B higherThan(Date arg) {
+ return greaterThan(arg);
+ }
+
+ @Override
+ public B greaterThan(Date date) {
+ if (date == null) {
+ throw new IllegalArgumentException("date cannot be null");
+ }
+ return applyFilter(new FilterItem(_selectItem, OperatorType.GREATER_THAN, date));
+ }
+
+ @Deprecated
+ @Override
+ public B higherThan(Number arg) {
+ return greaterThan(arg);
+ }
+
+ @Override
+ public B greaterThan(Number number) {
+ if (number == null) {
+ throw new IllegalArgumentException("number cannot be null");
+ }
+ return applyFilter(new FilterItem(_selectItem, OperatorType.GREATER_THAN, number));
+ }
+
+ @Deprecated
+ @Override
+ public B higherThan(String arg) {
+ return greaterThan(arg);
+ }
+
+ @Override
+ public B greaterThan(String string) {
+ if (string == null) {
+ throw new IllegalArgumentException("string cannot be null");
+ }
+ return applyFilter(new FilterItem(_selectItem, OperatorType.GREATER_THAN, string));
+ }
+
+ @Override
+ public B lessThan(Column column) {
+ if (column == null) {
+ throw new IllegalArgumentException("column cannot be null");
+ }
+ return applyFilter(new FilterItem(_selectItem, OperatorType.LESS_THAN, new SelectItem(column)));
+ }
+
+ @Override
+ public B lessThan(Date date) {
+ if (date == null) {
+ throw new IllegalArgumentException("date cannot be null");
+ }
+ return applyFilter(new FilterItem(_selectItem, OperatorType.LESS_THAN, date));
+ }
+
+ @Override
+ public B lessThan(Number number) {
+ if (number == null) {
+ throw new IllegalArgumentException("number cannot be null");
+ }
+ return applyFilter(new FilterItem(_selectItem, OperatorType.LESS_THAN, number));
+ }
+
+ @Override
+ public B lessThan(String string) {
+ if (string == null) {
+ throw new IllegalArgumentException("string cannot be null");
+ }
+ return applyFilter(new FilterItem(_selectItem, OperatorType.LESS_THAN, string));
+ }
+
+ @Override
+ public B lessThan(Object obj) {
+ if (obj instanceof Number) {
+ return lessThan((Number) obj);
+ }
+ if (obj instanceof Date) {
+ return lessThan((Date) obj);
+ }
+ if (obj instanceof String) {
+ return lessThan((String) obj);
+ }
+ throw new UnsupportedOperationException("Argument must be a Number, Date or String. Found: " + obj);
+ }
+
+ @Override
+ public B greaterThan(Object obj) {
+ if (obj instanceof Number) {
+ return greaterThan((Number) obj);
+ }
+ if (obj instanceof Date) {
+ return greaterThan((Date) obj);
+ }
+ if (obj instanceof String) {
+ return greaterThan((String) obj);
+ }
+ throw new UnsupportedOperationException("Argument must be a Number, Date or String. Found: " + obj);
+ }
+
+ @Override
+ public B like(String string) {
+ if (string == null) {
+ throw new IllegalArgumentException("string cannot be null");
+ }
+ return applyFilter(new FilterItem(_selectItem, OperatorType.LIKE, string));
+ }
+
+ @Override
+ public B gt(Column column) {
+ return greaterThan(column);
+ }
+
+ @Override
+ public B gt(Date date) {
+ return greaterThan(date);
+ }
+
+ @Override
+ public B gt(Number number) {
+ return greaterThan(number);
+ }
+
+ @Override
+ public B gt(String string) {
+ return greaterThan(string);
+ }
+
+ @Override
+ public B lt(Column column) {
+ return lessThan(column);
+ }
+
+ public B lt(Date date) {
+ return lessThan(date);
+ };
+
+ public B lt(Number number) {
+ return lessThan(number);
+ };
+
+ public B lt(String string) {
+ return lessThan(string);
+ };
+
+ @Override
+ public B eq(Boolean bool) {
+ return isEquals(bool);
+ }
+
+ @Override
+ public B eq(Column column) {
+ return isEquals(column);
+ }
+
+ @Override
+ public B eq(Date date) {
+ return isEquals(date);
+ }
+
+ @Override
+ public B eq(Number number) {
+ return isEquals(number);
+ }
+
+ @Override
+ public B eq(String string) {
+ return isEquals(string);
+ }
+
+ @Override
+ public B eq(Object obj) {
+ return isEquals(obj);
+ }
+
+ @Override
+ public B ne(Boolean bool) {
+ return differentFrom(bool);
+ }
+
+ @Override
+ public B ne(Column column) {
+ return differentFrom(column);
+ }
+
+ @Override
+ public B ne(Date date) {
+ return differentFrom(date);
+ }
+
+ @Override
+ public B ne(Number number) {
+ return differentFrom(number);
+ }
+
+ @Override
+ public B ne(String string) {
+ return differentFrom(string);
+ }
+
+ @Override
+ public B ne(Object obj) {
+ return differentFrom(obj);
+ }
+
+ @Override
+ @Deprecated
+ public B equals(Boolean bool) {
+ return isEquals(bool);
+ }
+
+ @Override
+ @Deprecated
+ public B equals(Column column) {
+ return isEquals(column);
+ }
+
+ @Override
+ @Deprecated
+ public B equals(Date date) {
+ return isEquals(date);
+ }
+
+ @Override
+ @Deprecated
+ public B equals(Number number) {
+ return isEquals(number);
+ }
+
+ @Override
+ @Deprecated
+ public B equals(String string) {
+ return isEquals(string);
+ }
+
+ @Override
+ public B lt(Object obj) {
+ return lessThan(obj);
+ }
+
+ @Override
+ public B gt(Object obj) {
+ return greaterThan(obj);
+ }
+}
\ 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/query/builder/AbstractQueryFilterBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/AbstractQueryFilterBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/AbstractQueryFilterBuilder.java
new file mode 100644
index 0000000..a015292
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/AbstractQueryFilterBuilder.java
@@ -0,0 +1,344 @@
+/**
+ * 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.query.builder;
+
+import java.util.Collection;
+import java.util.Date;
+
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+
+abstract class AbstractQueryFilterBuilder<B> extends GroupedQueryBuilderCallback implements FilterBuilder<B> {
+
+ protected final AbstractFilterBuilder<B> _filterBuilder;
+
+ public AbstractQueryFilterBuilder(SelectItem selectItem, GroupedQueryBuilder queryBuilder) {
+ super(queryBuilder);
+ _filterBuilder = new AbstractFilterBuilder<B>(selectItem) {
+ @Override
+ protected B applyFilter(FilterItem filter) {
+ return AbstractQueryFilterBuilder.this.applyFilter(filter);
+ }
+ };
+ }
+
+ protected abstract B applyFilter(FilterItem filter);
+
+ @Override
+ public B in(Collection<?> values) {
+ return _filterBuilder.in(values);
+ }
+
+ @Override
+ public B in(Number... numbers) {
+ return _filterBuilder.in(numbers);
+ }
+
+ @Override
+ public B in(String... strings) {
+ return _filterBuilder.in(strings);
+ }
+
+ @Override
+ public B isNull() {
+ return _filterBuilder.isNull();
+ }
+
+ @Override
+ public B isNotNull() {
+ return _filterBuilder.isNotNull();
+ }
+
+ @Override
+ public B isEquals(Column column) {
+ return _filterBuilder.isEquals(column);
+ }
+
+ @Override
+ public B isEquals(Date date) {
+ return _filterBuilder.isEquals(date);
+ }
+
+ @Override
+ public B isEquals(Number number) {
+ return _filterBuilder.isEquals(number);
+ }
+
+ @Override
+ public B isEquals(String string) {
+ return _filterBuilder.isEquals(string);
+ }
+
+ @Override
+ public B isEquals(Boolean bool) {
+ return _filterBuilder.isEquals(bool);
+ }
+
+ @Override
+ public B isEquals(Object obj) {
+ return _filterBuilder.isEquals(obj);
+ }
+
+ @Override
+ public B differentFrom(Column column) {
+ return _filterBuilder.differentFrom(column);
+ }
+
+ @Override
+ public B differentFrom(Date date) {
+ return _filterBuilder.differentFrom(date);
+ }
+
+ @Override
+ public B differentFrom(Number number) {
+ return _filterBuilder.differentFrom(number);
+ }
+
+ @Override
+ public B differentFrom(String string) {
+ return _filterBuilder.differentFrom(string);
+ }
+
+ @Override
+ public B differentFrom(Boolean bool) {
+ return _filterBuilder.differentFrom(bool);
+ }
+
+ @Override
+ public B differentFrom(Object obj) {
+ return _filterBuilder.differentFrom(obj);
+ }
+
+ @Deprecated
+ @Override
+ public B higherThan(Column arg) {
+ return _filterBuilder.higherThan(arg);
+ }
+
+ public B greaterThan(Column column) {
+ return _filterBuilder.greaterThan(column);
+ }
+
+ @Override
+ public B greaterThan(Object obj) {
+ return _filterBuilder.greaterThan(obj);
+ }
+
+ @Deprecated
+ @Override
+ public B higherThan(Date arg) {
+ return _filterBuilder.higherThan(arg);
+ }
+
+ @Override
+ public B greaterThan(Date date) {
+ return _filterBuilder.greaterThan(date);
+ }
+
+ @Deprecated
+ @Override
+ public B higherThan(Number arg) {
+ return _filterBuilder.higherThan(arg);
+ }
+
+ @Override
+ public B greaterThan(Number number) {
+ return _filterBuilder.greaterThan(number);
+ }
+
+ @Deprecated
+ @Override
+ public B higherThan(String arg) {
+ return _filterBuilder.higherThan(arg);
+ }
+
+ @Override
+ public B greaterThan(String string) {
+ return _filterBuilder.greaterThan(string);
+ }
+
+ @Override
+ public B lessThan(Column column) {
+ return _filterBuilder.lessThan(column);
+ }
+
+ @Override
+ public B lessThan(Date date) {
+ return _filterBuilder.lessThan(date);
+ }
+
+ @Override
+ public B lessThan(Number number) {
+ return _filterBuilder.lessThan(number);
+ }
+
+ @Override
+ public B lessThan(String string) {
+ return _filterBuilder.lessThan(string);
+ }
+
+ @Override
+ public B lessThan(Object obj) {
+ return _filterBuilder.lessThan(obj);
+ }
+
+ @Override
+ public B like(String string) {
+ return _filterBuilder.like(string);
+ }
+
+ @Override
+ public B gt(Column column) {
+ return greaterThan(column);
+ }
+
+ @Override
+ public B gt(Date date) {
+ return greaterThan(date);
+ }
+
+ @Override
+ public B gt(Number number) {
+ return greaterThan(number);
+ }
+
+ @Override
+ public B gt(String string) {
+ return greaterThan(string);
+ }
+
+ @Override
+ public B lt(Column column) {
+ return lessThan(column);
+ }
+
+ public B lt(Date date) {
+ return lessThan(date);
+ };
+
+ public B lt(Number number) {
+ return lessThan(number);
+ };
+
+ public B lt(String string) {
+ return lessThan(string);
+ };
+
+ @Override
+ public B eq(Boolean bool) {
+ return isEquals(bool);
+ }
+
+ @Override
+ public B eq(Column column) {
+ return isEquals(column);
+ }
+
+ @Override
+ public B eq(Date date) {
+ return isEquals(date);
+ }
+
+ @Override
+ public B eq(Number number) {
+ return isEquals(number);
+ }
+
+ @Override
+ public B eq(String string) {
+ return isEquals(string);
+ }
+
+ @Override
+ public B eq(Object obj) {
+ return isEquals(obj);
+ }
+
+ @Override
+ public B ne(Boolean bool) {
+ return differentFrom(bool);
+ }
+
+ @Override
+ public B ne(Column column) {
+ return differentFrom(column);
+ }
+
+ @Override
+ public B ne(Date date) {
+ return differentFrom(date);
+ }
+
+ @Override
+ public B ne(Number number) {
+ return differentFrom(number);
+ }
+
+ @Override
+ public B ne(String string) {
+ return differentFrom(string);
+ }
+
+ @Override
+ public B ne(Object obj) {
+ return differentFrom(obj);
+ }
+
+ @Override
+ @Deprecated
+ public B equals(Boolean bool) {
+ return isEquals(bool);
+ }
+
+ @Override
+ @Deprecated
+ public B equals(Column column) {
+ return isEquals(column);
+ }
+
+ @Override
+ @Deprecated
+ public B equals(Date date) {
+ return isEquals(date);
+ }
+
+ @Override
+ @Deprecated
+ public B equals(Number number) {
+ return isEquals(number);
+ }
+
+ @Override
+ @Deprecated
+ public B equals(String string) {
+ return isEquals(string);
+ }
+
+ @Override
+ public B lt(Object obj) {
+ return lessThan(obj);
+ }
+
+ @Override
+ public B gt(Object obj) {
+ return greaterThan(obj);
+ }
+
+}
\ 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/query/builder/ColumnSelectBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/ColumnSelectBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/ColumnSelectBuilder.java
new file mode 100644
index 0000000..00208cf
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/ColumnSelectBuilder.java
@@ -0,0 +1,25 @@
+/**
+ * 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.query.builder;
+
+public interface ColumnSelectBuilder<B extends SatisfiedQueryBuilder<?>>
+ extends SatisfiedSelectBuilder<B> {
+
+ public B as(String alias);
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/builder/ColumnSelectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/ColumnSelectBuilderImpl.java b/core/src/main/java/org/apache/metamodel/query/builder/ColumnSelectBuilderImpl.java
new file mode 100644
index 0000000..161a36f
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/ColumnSelectBuilderImpl.java
@@ -0,0 +1,54 @@
+/**
+ * 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.query.builder;
+
+import java.util.List;
+
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+
+final class ColumnSelectBuilderImpl extends SatisfiedSelectBuilderImpl
+ implements ColumnSelectBuilder<GroupedQueryBuilder> {
+
+ private SelectItem selectItem;
+
+ public ColumnSelectBuilderImpl(Column column, Query query,
+ GroupedQueryBuilder queryBuilder) {
+ super(queryBuilder);
+ this.selectItem = new SelectItem(column);
+
+ query.select(selectItem);
+ }
+
+ @Override
+ public GroupedQueryBuilder as(String alias) {
+ if (alias == null) {
+ throw new IllegalArgumentException("alias cannot be null");
+ }
+ selectItem.setAlias(alias);
+ return getQueryBuilder();
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ super.decorateIdentity(identifiers);
+ identifiers.add(selectItem);
+ }
+}
\ 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/query/builder/CountSelectBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/CountSelectBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/CountSelectBuilder.java
new file mode 100644
index 0000000..61dd73d
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/CountSelectBuilder.java
@@ -0,0 +1,25 @@
+/**
+ * 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.query.builder;
+
+public interface CountSelectBuilder<B extends SatisfiedQueryBuilder<?>> extends
+ SatisfiedSelectBuilder<B> {
+
+ public B as(String alias);
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/builder/CountSelectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/CountSelectBuilderImpl.java b/core/src/main/java/org/apache/metamodel/query/builder/CountSelectBuilderImpl.java
new file mode 100644
index 0000000..e2114b2
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/CountSelectBuilderImpl.java
@@ -0,0 +1,51 @@
+/**
+ * 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.query.builder;
+
+import java.util.List;
+
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+
+final class CountSelectBuilderImpl extends SatisfiedSelectBuilderImpl implements
+ CountSelectBuilder<GroupedQueryBuilder> {
+
+ private SelectItem selectItem;
+
+ public CountSelectBuilderImpl(Query query, GroupedQueryBuilder queryBuilder) {
+ super(queryBuilder);
+ this.selectItem = SelectItem.getCountAllItem();
+ query.select(selectItem);
+ }
+
+ @Override
+ public GroupedQueryBuilder as(String alias) {
+ if (alias == null) {
+ throw new IllegalArgumentException("alias cannot be null");
+ }
+ selectItem.setAlias(alias);
+ return getQueryBuilder();
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ super.decorateIdentity(identifiers);
+ identifiers.add(selectItem);
+ }
+}
\ 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/query/builder/FilterBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/FilterBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/FilterBuilder.java
new file mode 100644
index 0000000..01a09cc
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/FilterBuilder.java
@@ -0,0 +1,355 @@
+/**
+ * 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.query.builder;
+
+import java.util.Collection;
+import java.util.Date;
+
+import org.eobjects.metamodel.schema.Column;
+
+/**
+ * Interface for builder callbacks that "respond" to filter condition building.
+ *
+ * @param <B>
+ * the builder type to return once filter has been created.
+ */
+public interface FilterBuilder<B> {
+
+ /**
+ * Not null
+ */
+ public B isNull();
+
+ /**
+ * Is not null
+ */
+ public B isNotNull();
+
+ /**
+ * In ...
+ */
+ public B in(Collection<?> values);
+
+ /**
+ * In ...
+ */
+ public B in(Number... numbers);
+
+ /**
+ * In ...
+ */
+ public B in(String... strings);
+
+ /**
+ * Like ...
+ *
+ * (use '%' as wildcard).
+ */
+ public B like(String string);
+
+ /**
+ * Equal to ...
+ */
+ public B eq(Column column);
+
+ /**
+ * Equal to ...
+ */
+ public B eq(Date date);
+
+ /**
+ * Equal to ...
+ */
+ public B eq(Number number);
+
+ /**
+ * Equal to ...
+ */
+ public B eq(String string);
+
+ /**
+ * Equal to ...
+ */
+ public B eq(Boolean bool);
+
+ /**
+ * Equal to ...
+ */
+ public B eq(Object obj);
+
+ /**
+ * Equal to ...
+ */
+ public B isEquals(Column column);
+
+ /**
+ * Equal to ...
+ */
+ public B isEquals(Date date);
+
+ /**
+ * Equal to ...
+ */
+ public B isEquals(Number number);
+
+ /**
+ * Equal to ...
+ */
+ public B isEquals(String string);
+
+ /**
+ * Equal to ...
+ */
+ public B isEquals(Boolean bool);
+
+ /**
+ * Equal to ...
+ */
+ public B isEquals(Object obj);
+
+ /**
+ * Equal to ...
+ *
+ * @deprecated use 'eq' or 'isEquals' instead.
+ */
+ @Deprecated
+ public B equals(Column column);
+
+ /**
+ * Equal to ...
+ *
+ * @deprecated use 'eq' or 'isEquals' instead.
+ */
+ @Deprecated
+ public B equals(Date date);
+
+ /**
+ * Equal to ...
+ *
+ * @deprecated use 'eq' or 'isEquals' instead.
+ */
+ @Deprecated
+ public B equals(Number number);
+
+ /**
+ * Equal to ...
+ *
+ * @deprecated use 'eq' or 'isEquals' instead.
+ */
+ @Deprecated
+ public B equals(String string);
+
+ /**
+ * Equal to ...
+ *
+ * @deprecated use 'eq' or 'isEquals' instead.
+ */
+ @Deprecated
+ public B equals(Boolean bool);
+
+ /**
+ * Not equal to ...
+ */
+ public B differentFrom(Column column);
+
+ /**
+ * Not equal to ...
+ */
+ public B differentFrom(Date date);
+
+ /**
+ * Not equal to ...
+ */
+ public B differentFrom(Number number);
+
+ /**
+ * Not equal to ...
+ */
+ public B differentFrom(String string);
+
+ /**
+ * Not equal to ...
+ */
+ public B differentFrom(Boolean bool);
+
+ /**
+ * Not equal to ...
+ */
+ public B differentFrom(Object obj);
+
+ /**
+ * Not equal to ...
+ */
+ public B ne(Column column);
+
+ /**
+ * Not equal to ...
+ */
+ public B ne(Date date);
+
+ /**
+ * Not equal to ...
+ */
+ public B ne(Number number);
+
+ /**
+ * Not equal to ...
+ */
+ public B ne(String string);
+
+ /**
+ * Not equal to ...
+ */
+ public B ne(Boolean bool);
+
+ /**
+ * Not equal to ...
+ */
+ public B ne(Object obj);
+
+ /**
+ * Greater than ...
+ *
+ * @deprecated use {@link #greaterThan(Column)} instead
+ */
+ @Deprecated
+ public B higherThan(Column column);
+
+ /**
+ * Greater than ...
+ */
+ public B greaterThan(Column column);
+
+ /**
+ * Greater than ...
+ */
+ public B gt(Column column);
+
+ /**
+ * Greater than ...
+ */
+ public B greaterThan(Object obj);
+
+ /**
+ * Greater than ...
+ */
+ public B gt(Object obj);
+
+ /**
+ * Greater than ...
+ *
+ * @deprecated use {@link #greaterThan(Date)} instead
+ */
+ @Deprecated
+ public B higherThan(Date date);
+
+ /**
+ * Greater than ...
+ */
+ public B greaterThan(Date date);
+
+ /**
+ * Greater than ...
+ */
+ public B gt(Date date);
+
+ /**
+ * @deprecated use {@link #greaterThan(Number)} instead
+ */
+ @Deprecated
+ public B higherThan(Number number);
+
+ /**
+ * Greater than ...
+ */
+ public B greaterThan(Number number);
+
+ /**
+ * Greater than ...
+ */
+ public B gt(Number number);
+
+ /**
+ * Greater than ...
+ *
+ * @deprecated use {@link #greaterThan(String)} instead
+ */
+ @Deprecated
+ public B higherThan(String string);
+
+ /**
+ * Greater than ...
+ */
+ public B greaterThan(String string);
+
+ /**
+ * Greater than ...
+ */
+ public B gt(String string);
+
+ /**
+ * Less than ...
+ */
+ public B lessThan(Column column);
+
+ /**
+ * Less than ...
+ */
+ public B lt(Column column);
+
+ /**
+ * Less than ...
+ */
+ public B lessThan(Date date);
+
+ /**
+ * Less than ...
+ */
+ public B lessThan(Number number);
+
+ /**
+ * Less than ...
+ */
+ public B lessThan(String string);
+
+ /**
+ * Less than ...
+ */
+ public B lessThan(Object obj);
+
+ /**
+ * Less than ...
+ */
+ public B lt(Object obj);
+
+ /**
+ * Less than ...
+ */
+ public B lt(Date date);
+
+ /**
+ * Less than ...
+ */
+ public B lt(Number number);
+
+ /**
+ * Less than ...
+ */
+ public B lt(String string);
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/builder/FunctionSelectBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/FunctionSelectBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/FunctionSelectBuilder.java
new file mode 100644
index 0000000..516ce5e
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/FunctionSelectBuilder.java
@@ -0,0 +1,25 @@
+/**
+ * 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.query.builder;
+
+public interface FunctionSelectBuilder<B extends SatisfiedQueryBuilder<?>>
+ extends SatisfiedSelectBuilder<B> {
+
+ public B as(String alias);
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/builder/FunctionSelectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/FunctionSelectBuilderImpl.java b/core/src/main/java/org/apache/metamodel/query/builder/FunctionSelectBuilderImpl.java
new file mode 100644
index 0000000..68e9b39
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/FunctionSelectBuilderImpl.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.query.builder;
+
+import java.util.List;
+
+import org.eobjects.metamodel.query.FunctionType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+
+final class FunctionSelectBuilderImpl extends SatisfiedSelectBuilderImpl
+ implements FunctionSelectBuilder<GroupedQueryBuilder> {
+
+ private SelectItem selectItem;
+
+ public FunctionSelectBuilderImpl(FunctionType functionType, Column column,
+ Query query, GroupedQueryBuilder queryBuilder) {
+ super(queryBuilder);
+
+ this.selectItem = new SelectItem(functionType, column);
+
+ query.select(selectItem);
+ }
+
+ @Override
+ public GroupedQueryBuilder as(String alias) {
+ if (alias == null) {
+ throw new IllegalArgumentException("alias cannot be null");
+ }
+ selectItem.setAlias(alias);
+ return getQueryBuilder();
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ super.decorateIdentity(identifiers);
+ identifiers.add(selectItem);
+ }
+}
\ 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/query/builder/GroupedQueryBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilder.java
new file mode 100644
index 0000000..d798d9b
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilder.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.query.builder;
+
+import org.eobjects.metamodel.query.FunctionType;
+import org.eobjects.metamodel.schema.Column;
+
+/**
+ * Represents a built query that has a GROUP BY clause.
+ *
+ * @author Kasper Sørensen
+ *
+ */
+public interface GroupedQueryBuilder extends
+ SatisfiedQueryBuilder<GroupedQueryBuilder> {
+
+ public HavingBuilder having(FunctionType functionType, Column column);
+
+ public SatisfiedOrderByBuilder<GroupedQueryBuilder> orderBy(
+ FunctionType function, Column column);
+}
\ 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/query/builder/GroupedQueryBuilderCallback.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilderCallback.java b/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilderCallback.java
new file mode 100644
index 0000000..6db7feb
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilderCallback.java
@@ -0,0 +1,168 @@
+/**
+ * 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.query.builder;
+
+import java.util.List;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.query.CompiledQuery;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.FunctionType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.util.BaseObject;
+
+abstract class GroupedQueryBuilderCallback extends BaseObject implements GroupedQueryBuilder {
+
+ private GroupedQueryBuilder queryBuilder;
+
+ public GroupedQueryBuilderCallback(GroupedQueryBuilder queryBuilder) {
+ this.queryBuilder = queryBuilder;
+ }
+
+ protected GroupedQueryBuilder getQueryBuilder() {
+ return queryBuilder;
+ }
+
+ @Override
+ public SatisfiedQueryBuilder<GroupedQueryBuilder> firstRow(int firstRow) {
+ return getQueryBuilder().firstRow(firstRow);
+ }
+
+ @Override
+ public SatisfiedQueryBuilder<GroupedQueryBuilder> limit(int maxRows) {
+ return getQueryBuilder().limit(maxRows);
+ }
+
+ @Override
+ public SatisfiedQueryBuilder<GroupedQueryBuilder> offset(int offset) {
+ return getQueryBuilder().offset(offset);
+ }
+
+ @Override
+ public SatisfiedQueryBuilder<GroupedQueryBuilder> maxRows(int maxRows) {
+ return getQueryBuilder().maxRows(maxRows);
+ }
+
+ @Override
+ public SatisfiedSelectBuilder<GroupedQueryBuilder> select(Column... columns) {
+ return getQueryBuilder().select(columns);
+ }
+
+ @Override
+ public final Column findColumn(String columnName) throws IllegalArgumentException {
+ return getQueryBuilder().findColumn(columnName);
+ }
+
+ @Override
+ public ColumnSelectBuilder<GroupedQueryBuilder> select(Column column) {
+ return getQueryBuilder().select(column);
+ }
+
+ @Override
+ public FunctionSelectBuilder<GroupedQueryBuilder> select(FunctionType functionType, Column column) {
+ return getQueryBuilder().select(functionType, column);
+ }
+
+ @Override
+ public ColumnSelectBuilder<GroupedQueryBuilder> select(String columnName) {
+ return getQueryBuilder().select(columnName);
+ }
+
+ @Override
+ public CountSelectBuilder<GroupedQueryBuilder> selectCount() {
+ return getQueryBuilder().selectCount();
+ }
+
+ @Override
+ public WhereBuilder<GroupedQueryBuilder> where(Column column) {
+ return getQueryBuilder().where(column);
+ }
+
+ @Override
+ public SatisfiedOrderByBuilder<GroupedQueryBuilder> orderBy(Column column) {
+ return getQueryBuilder().orderBy(column);
+ }
+
+ @Override
+ public GroupedQueryBuilder groupBy(String columnName) {
+ return getQueryBuilder().groupBy(columnName);
+ }
+
+ @Override
+ public GroupedQueryBuilder groupBy(Column column) {
+ return getQueryBuilder().groupBy(column);
+ }
+
+ @Override
+ public Query toQuery() {
+ return getQueryBuilder().toQuery();
+ }
+
+ @Override
+ public CompiledQuery compile() {
+ return getQueryBuilder().compile();
+ }
+
+ @Override
+ public HavingBuilder having(FunctionType functionType, Column column) {
+ return getQueryBuilder().having(functionType, column);
+ }
+
+ @Override
+ public GroupedQueryBuilder groupBy(Column... columns) {
+ getQueryBuilder().groupBy(columns);
+ return this;
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ identifiers.add(queryBuilder);
+ }
+
+ @Override
+ public DataSet execute() {
+ return queryBuilder.execute();
+ }
+
+ @Override
+ public WhereBuilder<GroupedQueryBuilder> where(String columnName) {
+ return getQueryBuilder().where(columnName);
+ }
+
+ @Override
+ public SatisfiedQueryBuilder<GroupedQueryBuilder> where(FilterItem... filters) {
+ return getQueryBuilder().where(filters);
+ }
+
+ @Override
+ public SatisfiedQueryBuilder<GroupedQueryBuilder> where(Iterable<FilterItem> filters) {
+ return getQueryBuilder().where(filters);
+ }
+
+ @Override
+ public SatisfiedOrderByBuilder<GroupedQueryBuilder> orderBy(String columnName) {
+ return getQueryBuilder().orderBy(columnName);
+ }
+
+ @Override
+ public SatisfiedOrderByBuilder<GroupedQueryBuilder> orderBy(FunctionType function, Column column) {
+ return getQueryBuilder().orderBy(function, column);
+ }
+}
\ 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/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
new file mode 100644
index 0000000..bd5248c
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilderImpl.java
@@ -0,0 +1,332 @@
+/**
+ * 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.query.builder;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.query.CompiledQuery;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.FunctionType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.BaseObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Main implementation of the {@link GroupedQueryBuilder} interface.
+ */
+final class GroupedQueryBuilderImpl extends BaseObject implements GroupedQueryBuilder {
+
+ private static final Logger logger = LoggerFactory.getLogger(GroupedQueryBuilderImpl.class);
+
+ private final Query _query;
+ private final DataContext _dataContext;
+
+ public GroupedQueryBuilderImpl(DataContext dataContext, Query query) {
+ if (query == null) {
+ throw new IllegalArgumentException("query cannot be null");
+ }
+ _dataContext = dataContext;
+ _query = query;
+ }
+
+ @Override
+ public ColumnSelectBuilder<GroupedQueryBuilder> select(Column column) {
+ if (column == null) {
+ throw new IllegalArgumentException("column cannot be null");
+ }
+ return new ColumnSelectBuilderImpl(column, _query, this);
+ }
+
+ @Override
+ public FunctionSelectBuilder<GroupedQueryBuilder> select(FunctionType function, Column column) {
+ if (function == null) {
+ throw new IllegalArgumentException("function cannot be null");
+ }
+ if (column == null) {
+ throw new IllegalArgumentException("column cannot be null");
+ }
+ return new FunctionSelectBuilderImpl(function, column, _query, this);
+ }
+
+ @Override
+ public SatisfiedQueryBuilder<GroupedQueryBuilder> where(FilterItem... filters) {
+ _query.where(filters);
+ return this;
+ }
+
+ @Override
+ public SatisfiedQueryBuilder<GroupedQueryBuilder> where(Iterable<FilterItem> filters) {
+ _query.where(filters);
+ return this;
+ }
+
+ @Override
+ public ColumnSelectBuilder<GroupedQueryBuilder> select(String columnName) {
+ Column column = findColumn(columnName);
+ return select(column);
+ }
+
+ @Override
+ public CountSelectBuilder<GroupedQueryBuilder> selectCount() {
+ return new CountSelectBuilderImpl(_query, this);
+ }
+
+ @Override
+ public SatisfiedSelectBuilder<GroupedQueryBuilder> select(Column... columns) {
+ if (columns == null) {
+ throw new IllegalArgumentException("column cannot be null");
+ }
+ _query.select(columns);
+ return new SatisfiedSelectBuilderImpl(this);
+ }
+
+ @Override
+ public WhereBuilder<GroupedQueryBuilder> where(Column column) {
+ if (column == null) {
+ throw new IllegalArgumentException("column cannot be null");
+ }
+ return new WhereBuilderImpl(column, _query, this);
+ }
+
+ @Override
+ public WhereBuilder<GroupedQueryBuilder> where(String columnName) {
+ Column column = findColumn(columnName);
+ return where(column);
+ }
+
+ @Override
+ public Column findColumn(final String columnName) throws IllegalArgumentException {
+ if (columnName == null) {
+ throw new IllegalArgumentException("columnName cannot be null");
+ }
+
+ final List<FromItem> fromItems = _query.getFromClause().getItems();
+ final List<SelectItem> selectItems = _query.getSelectClause().getItems();
+
+ int dotIndex = columnName.indexOf('.');
+ if (dotIndex != -1) {
+ // check aliases of from items
+ final String aliasPart = columnName.substring(0, dotIndex);
+ final String columnPart = columnName.substring(dotIndex + 1);
+
+ for (FromItem fromItem : fromItems) {
+ Column column = null;
+ column = findColumnInAliasedTable(column, fromItem, aliasPart, columnPart);
+ if (column != null) {
+ return column;
+ }
+ }
+ }
+
+ // check columns already in select clause
+ for (SelectItem item : selectItems) {
+ Column column = item.getColumn();
+ if (column != null) {
+ if (columnName.equals(column.getName())) {
+ return column;
+ }
+ }
+ }
+
+ for (FromItem fromItem : fromItems) {
+ Table table = fromItem.getTable();
+ if (table != null) {
+ Column column = table.getColumnByName(columnName);
+ if (column != null) {
+ return column;
+ }
+ }
+ }
+
+ Column column = _dataContext.getColumnByQualifiedLabel(columnName);
+ if (column != null) {
+ return column;
+ }
+
+ final IllegalArgumentException exception = new IllegalArgumentException("Could not find column: " + columnName);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("findColumn('" + columnName + "') could not resolve a column", exception);
+ for (FromItem fromItem : fromItems) {
+ final Table table = fromItem.getTable();
+ if (table != null) {
+ logger.debug("Table available in FROM item: {}. Column names: {}", table,
+ Arrays.toString(table.getColumnNames()));
+ }
+ }
+ }
+
+ throw exception;
+ }
+
+ private Column findColumnInAliasedTable(Column column, FromItem fromItem, String aliasPart, String columnPart) {
+ if (column != null) {
+ // ensure that if the column has already been found, return it
+ return column;
+ }
+
+ Table table = fromItem.getTable();
+ if (table != null) {
+ String alias = fromItem.getAlias();
+ if (alias != null && alias.equals(aliasPart)) {
+ column = table.getColumnByName(columnPart);
+ }
+ } else {
+ FromItem leftSide = fromItem.getLeftSide();
+ column = findColumnInAliasedTable(column, leftSide, aliasPart, columnPart);
+ FromItem rightSide = fromItem.getRightSide();
+ column = findColumnInAliasedTable(column, rightSide, aliasPart, columnPart);
+ if (column != null) {
+ Query subQuery = fromItem.getSubQuery();
+ if (subQuery != null) {
+ List<FromItem> items = subQuery.getFromClause().getItems();
+ for (FromItem subQueryFromItem : items) {
+ column = findColumnInAliasedTable(column, subQueryFromItem, aliasPart, columnPart);
+ }
+ }
+ }
+ }
+
+ return column;
+ }
+
+ @Override
+ public SatisfiedOrderByBuilder<GroupedQueryBuilder> orderBy(String columnName) {
+ return orderBy(findColumn(columnName));
+ }
+
+ @Override
+ public SatisfiedOrderByBuilder<GroupedQueryBuilder> orderBy(Column column) {
+ if (column == null) {
+ throw new IllegalArgumentException("column cannot be null");
+ }
+ return new SatisfiedOrderByBuilderImpl(column, _query, this);
+ }
+
+ @Override
+ public SatisfiedOrderByBuilder<GroupedQueryBuilder> orderBy(FunctionType function, Column column) {
+ if (function == null) {
+ throw new IllegalArgumentException("function cannot be null");
+ }
+ if (column == null) {
+ throw new IllegalArgumentException("column cannot be null");
+ }
+ return new SatisfiedOrderByBuilderImpl(function, column, _query, this);
+ }
+
+ @Override
+ public GroupedQueryBuilder groupBy(Column column) {
+ if (column == null) {
+ throw new IllegalArgumentException("column cannot be null");
+ }
+ _query.groupBy(column);
+ return this;
+ }
+
+ @Override
+ public GroupedQueryBuilder groupBy(String columnName) {
+ Column column = findColumn(columnName);
+ return groupBy(column);
+ }
+
+ @Override
+ public GroupedQueryBuilder groupBy(Column... columns) {
+ if (columns == null) {
+ throw new IllegalArgumentException("columns cannot be null");
+ }
+ _query.groupBy(columns);
+ return this;
+ }
+
+ @Override
+ public HavingBuilder having(FunctionType function, Column column) {
+ if (function == null) {
+ throw new IllegalArgumentException("function cannot be null");
+ }
+ if (column == null) {
+ throw new IllegalArgumentException("column cannot be null");
+ }
+ return new HavingBuilderImpl(function, column, _query, this);
+ }
+
+ @Override
+ public SatisfiedQueryBuilder<GroupedQueryBuilder> limit(int maxRows) {
+ _query.setMaxRows(maxRows);
+ return this;
+ }
+
+ @Override
+ public SatisfiedQueryBuilder<GroupedQueryBuilder> maxRows(int maxRows) {
+ _query.setMaxRows(maxRows);
+ return this;
+ }
+
+ @Override
+ public SatisfiedQueryBuilder<GroupedQueryBuilder> firstRow(int firstRow) {
+ if (firstRow >= 0) {
+ _query.setFirstRow(firstRow);
+ } else {
+ _query.setFirstRow(null);
+ }
+ return this;
+ }
+
+ @Override
+ public SatisfiedQueryBuilder<GroupedQueryBuilder> offset(int offset) {
+ if (offset >= 0) {
+ _query.setFirstRow(offset + 1);
+ } else {
+ _query.setFirstRow(null);
+ }
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return _query.toSql();
+ }
+
+ @Override
+ public Query toQuery() {
+ return _query.clone();
+ }
+
+ @Override
+ public CompiledQuery compile() {
+ return _dataContext.compileQuery(_query);
+ }
+
+ @Override
+ public DataSet execute() {
+ return _dataContext.executeQuery(_query);
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ identifiers.add(_query);
+ }
+}
\ 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/query/builder/HavingBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/HavingBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/HavingBuilder.java
new file mode 100644
index 0000000..1596ada
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/HavingBuilder.java
@@ -0,0 +1,26 @@
+/**
+ * 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.query.builder;
+
+/**
+ * Builder interface for having items.
+ */
+public interface HavingBuilder extends FilterBuilder<SatisfiedHavingBuilder> {
+
+}
\ 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/query/builder/HavingBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/HavingBuilderImpl.java b/core/src/main/java/org/apache/metamodel/query/builder/HavingBuilderImpl.java
new file mode 100644
index 0000000..13b197d
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/HavingBuilderImpl.java
@@ -0,0 +1,87 @@
+/**
+ * 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.query.builder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.FunctionType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+
+final class HavingBuilderImpl extends
+ AbstractQueryFilterBuilder<SatisfiedHavingBuilder> implements
+ HavingBuilder, SatisfiedHavingBuilder {
+
+ private final Query _query;
+ private final List<FilterItem> _orFilters;
+ private FilterItem _parentOrFilter;
+
+ public HavingBuilderImpl(FunctionType function, Column column, Query query,
+ GroupedQueryBuilder queryBuilder) {
+ super(new SelectItem(function, column), queryBuilder);
+ _query = query;
+ _orFilters = new ArrayList<FilterItem>();
+ }
+
+ public HavingBuilderImpl(FunctionType function, Column column, Query query,
+ FilterItem parentOrFilter, List<FilterItem> orFilters,
+ GroupedQueryBuilder queryBuilder) {
+ super(new SelectItem(function, column), queryBuilder);
+ _query = query;
+ _orFilters = orFilters;
+ _parentOrFilter = parentOrFilter;
+ }
+
+ @Override
+ protected SatisfiedHavingBuilder applyFilter(FilterItem filter) {
+ if (_parentOrFilter == null) {
+ _query.having(filter);
+ } else {
+ if (_parentOrFilter.getChildItemCount() == 1) {
+ _query.getHavingClause().removeItem(_orFilters.get(0));
+ _query.getHavingClause().addItem(_parentOrFilter);
+ }
+ }
+ _orFilters.add(filter);
+ return this;
+ }
+
+ @Override
+ public HavingBuilder or(FunctionType function, Column column) {
+ if (function == null) {
+ throw new IllegalArgumentException("function cannot be null");
+ }
+ if (column == null) {
+ throw new IllegalArgumentException("column cannot be null");
+ }
+ if (_parentOrFilter == null) {
+ _parentOrFilter = new FilterItem(_orFilters);
+ }
+ return new HavingBuilderImpl(function, column, _query, _parentOrFilter,
+ _orFilters, getQueryBuilder());
+ }
+
+ @Override
+ public HavingBuilder and(FunctionType function, Column column) {
+ return getQueryBuilder().having(function, column);
+ }
+}
\ No newline at end of file
[43/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/builder/InitFromBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/InitFromBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/InitFromBuilder.java
new file mode 100644
index 0000000..fcbdbcf
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/InitFromBuilder.java
@@ -0,0 +1,39 @@
+/**
+ * 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.query.builder;
+
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * The initial interface used when building a query. A query starts by stating
+ * the FROM clause.
+ *
+ * @author Kasper Sørensen
+ */
+public interface InitFromBuilder {
+
+ public TableFromBuilder from(Table table);
+
+ public TableFromBuilder from(Schema schema, String tableName);
+
+ public TableFromBuilder from(String schemaName, String tableName);
+
+ public TableFromBuilder from(String tableName);
+}
\ 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/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
new file mode 100644
index 0000000..3d523a8
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/InitFromBuilderImpl.java
@@ -0,0 +1,89 @@
+/**
+ * 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.query.builder;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.BaseObject;
+
+public final class InitFromBuilderImpl extends BaseObject implements InitFromBuilder {
+
+ private DataContext dataContext;
+ private Query query;
+
+ public InitFromBuilderImpl(DataContext dataContext) {
+ this.dataContext = dataContext;
+ this.query = new Query();
+ }
+
+ @Override
+ public TableFromBuilder from(Table table) {
+ if (table == null) {
+ throw new IllegalArgumentException("table cannot be null");
+ }
+ return new TableFromBuilderImpl(table, query, dataContext);
+ }
+
+ @Override
+ public TableFromBuilder from(String schemaName, String tableName) {
+ if (schemaName == null) {
+ throw new IllegalArgumentException("schemaName cannot be null");
+ }
+ if (tableName == null) {
+ throw new IllegalArgumentException("tableName cannot be null");
+ }
+ Schema schema = dataContext.getSchemaByName(schemaName);
+ if (schema == null) {
+ schema = dataContext.getDefaultSchema();
+ }
+ return from(schema, tableName);
+ }
+
+ @Override
+ public TableFromBuilder from(Schema schema, String tableName) {
+ 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()));
+ }
+ return from(table);
+ }
+
+ @Override
+ public TableFromBuilder from(String tableName) {
+ if (tableName == null) {
+ throw new IllegalArgumentException("tableName cannot be null");
+ }
+ Table table = dataContext.getTableByQualifiedLabel(tableName);
+ if (table == null) {
+ throw new IllegalArgumentException("No such table: " + tableName);
+ }
+ return from(table);
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ identifiers.add(query);
+ }
+}
\ 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/query/builder/JoinFromBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/JoinFromBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/JoinFromBuilder.java
new file mode 100644
index 0000000..1cad5fc
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/JoinFromBuilder.java
@@ -0,0 +1,26 @@
+/**
+ * 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.query.builder;
+
+import org.eobjects.metamodel.schema.Column;
+
+public interface JoinFromBuilder extends SatisfiedFromBuilder {
+
+ public SatisfiedFromBuilder on(Column left, Column right);
+}
\ 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/query/builder/JoinFromBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/JoinFromBuilderImpl.java b/core/src/main/java/org/apache/metamodel/query/builder/JoinFromBuilderImpl.java
new file mode 100644
index 0000000..6e9520c
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/JoinFromBuilderImpl.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.query.builder;
+
+import java.util.List;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.JoinType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+
+final class JoinFromBuilderImpl extends SatisfiedFromBuilderCallback implements
+ JoinFromBuilder {
+
+ private JoinType joinType;
+ private FromItem leftItem;
+ private FromItem rightItem;
+
+ public JoinFromBuilderImpl(Query query, FromItem leftItem,
+ Table rightTable, JoinType joinType, DataContext dataContext) {
+ super(query, dataContext);
+ this.joinType = joinType;
+ this.leftItem = leftItem;
+ this.rightItem = new FromItem(rightTable);
+ }
+
+ @Override
+ public SatisfiedFromBuilder on(Column left, Column right) {
+ if (left == null) {
+ throw new IllegalArgumentException("left cannot be null");
+ }
+ if (right == null) {
+ throw new IllegalArgumentException("right cannot be null");
+ }
+ getQuery().getFromClause().removeItem(leftItem);
+
+ SelectItem[] leftOn = new SelectItem[] { new SelectItem(left) };
+ SelectItem[] rightOn = new SelectItem[] { new SelectItem(right) };
+ FromItem fromItem = new FromItem(joinType, leftItem, rightItem, leftOn,
+ rightOn);
+
+ getQuery().from(fromItem);
+
+ return this;
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ super.decorateIdentity(identifiers);
+ identifiers.add(joinType);
+ identifiers.add(leftItem);
+ identifiers.add(rightItem);
+ }
+}
\ 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/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
new file mode 100644
index 0000000..6cc2611
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedFromBuilder.java
@@ -0,0 +1,52 @@
+/**
+ * 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.query.builder;
+
+import org.eobjects.metamodel.query.FunctionType;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * Represents a builder where the FROM part is satisfied, ie. a SELECT clause is
+ * now buildable.
+ *
+ * @author Kasper Sørensen
+ */
+public interface SatisfiedFromBuilder {
+
+ public TableFromBuilder and(Table table);
+
+ public TableFromBuilder and(String schemaName, String tableName);
+
+ public TableFromBuilder and(String tableName);
+
+ public ColumnSelectBuilder<?> select(Column column);
+
+ public FunctionSelectBuilder<?> select(FunctionType functionType, Column column);
+
+ public CountSelectBuilder<?> selectCount();
+
+ public SatisfiedSelectBuilder<?> select(Column... columns);
+
+ public SatisfiedSelectBuilder<?> selectAll();
+
+ public ColumnSelectBuilder<?> select(String columnName);
+
+ public SatisfiedSelectBuilder<?> select(String... columnNames);
+}
\ 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/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
new file mode 100644
index 0000000..d6798c2
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedFromBuilderCallback.java
@@ -0,0 +1,161 @@
+/**
+ * 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.query.builder;
+
+import java.util.List;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.query.FunctionType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.BaseObject;
+
+abstract class SatisfiedFromBuilderCallback extends BaseObject implements SatisfiedFromBuilder {
+
+ private Query query;
+ private DataContext dataContext;
+
+ public SatisfiedFromBuilderCallback(Query query, DataContext dataContext) {
+ this.query = query;
+ this.dataContext = dataContext;
+ }
+
+ protected Query getQuery() {
+ return query;
+ }
+
+ protected DataContext getDataContext() {
+ return dataContext;
+ }
+
+ @Override
+ public TableFromBuilder and(Table table) {
+ if (table == null) {
+ throw new IllegalArgumentException("table cannot be null");
+ }
+
+ return new TableFromBuilderImpl(table, query, dataContext);
+ }
+
+ @Override
+ public ColumnSelectBuilder<?> select(Column column) {
+ if (column == null) {
+ throw new IllegalArgumentException("column cannot be null");
+ }
+
+ GroupedQueryBuilder queryBuilder = new GroupedQueryBuilderImpl(dataContext, query);
+ return new ColumnSelectBuilderImpl(column, query, queryBuilder);
+ }
+
+ @Override
+ public SatisfiedSelectBuilder<?> selectAll() {
+ getQuery().selectAll();
+ GroupedQueryBuilder queryBuilder = new GroupedQueryBuilderImpl(dataContext, query);
+ return new SatisfiedSelectBuilderImpl(queryBuilder);
+ }
+
+ @Override
+ public FunctionSelectBuilder<?> select(FunctionType functionType, Column column) {
+ if (functionType == null) {
+ throw new IllegalArgumentException("functionType cannot be null");
+ }
+ if (column == null) {
+ throw new IllegalArgumentException("column cannot be null");
+ }
+
+ GroupedQueryBuilder queryBuilder = new GroupedQueryBuilderImpl(dataContext, query);
+ return new FunctionSelectBuilderImpl(functionType, column, query, queryBuilder);
+ }
+
+ @Override
+ public CountSelectBuilder<?> selectCount() {
+ GroupedQueryBuilder queryBuilder = new GroupedQueryBuilderImpl(dataContext, query);
+ return new CountSelectBuilderImpl(query, queryBuilder);
+ }
+
+ @Override
+ public TableFromBuilder and(String schemaName, String tableName) {
+ if (schemaName == null) {
+ throw new IllegalArgumentException("schemaName cannot be null");
+ }
+ if (tableName == null) {
+ throw new IllegalArgumentException("tableName cannot be null");
+ }
+
+ Schema schema = dataContext.getSchemaByName(schemaName);
+ if (schema == null) {
+ schema = dataContext.getDefaultSchema();
+ }
+ return and(schema, tableName);
+ }
+
+ private TableFromBuilder and(Schema schema, String tableName) {
+ Table table = schema.getTableByName(tableName);
+ return and(table);
+ }
+
+ @Override
+ public TableFromBuilder and(String tableName) {
+ if (tableName == null) {
+ throw new IllegalArgumentException("tableName cannot be null");
+ }
+ return and(dataContext.getDefaultSchema(), tableName);
+ }
+
+ @Override
+ public SatisfiedSelectBuilder<?> select(Column... columns) {
+ if (columns == null) {
+ throw new IllegalArgumentException("columns cannot be null");
+ }
+ query.select(columns);
+ GroupedQueryBuilder queryBuilder = new GroupedQueryBuilderImpl(dataContext, query);
+ return new SatisfiedSelectBuilderImpl(queryBuilder);
+ }
+
+ @Override
+ public SatisfiedSelectBuilder<?> select(String... columnNames) {
+ if (columnNames == null) {
+ throw new IllegalArgumentException("columnNames cannot be null");
+ }
+ for (String columnName : columnNames) {
+ select(columnName);
+ }
+ GroupedQueryBuilder queryBuilder = new GroupedQueryBuilderImpl(dataContext, query);
+ return new SatisfiedSelectBuilderImpl(queryBuilder);
+ }
+
+ @Override
+ public ColumnSelectBuilder<?> select(String columnName) {
+ if (columnName == null) {
+ throw new IllegalArgumentException("columnName cannot be null");
+ }
+
+ GroupedQueryBuilderImpl queryBuilder = new GroupedQueryBuilderImpl(dataContext, query);
+ Column column = queryBuilder.findColumn(columnName);
+ return select(column);
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ identifiers.add(query);
+ }
+
+}
\ 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/query/builder/SatisfiedHavingBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedHavingBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedHavingBuilder.java
new file mode 100644
index 0000000..b5c6efe
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedHavingBuilder.java
@@ -0,0 +1,29 @@
+/**
+ * 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.query.builder;
+
+import org.eobjects.metamodel.query.FunctionType;
+import org.eobjects.metamodel.schema.Column;
+
+public interface SatisfiedHavingBuilder extends GroupedQueryBuilder {
+
+ public HavingBuilder or(FunctionType functionType, Column column);
+
+ public HavingBuilder and(FunctionType functionType, Column column);
+}
\ 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/query/builder/SatisfiedOrderByBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedOrderByBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedOrderByBuilder.java
new file mode 100644
index 0000000..a7023cf
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedOrderByBuilder.java
@@ -0,0 +1,31 @@
+/**
+ * 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.query.builder;
+
+import org.eobjects.metamodel.schema.Column;
+
+public interface SatisfiedOrderByBuilder<B extends SatisfiedQueryBuilder<?>>
+ extends SatisfiedQueryBuilder<B> {
+
+ public B asc();
+
+ public B desc();
+
+ public SatisfiedOrderByBuilder<B> and(Column column);
+}
\ 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/query/builder/SatisfiedOrderByBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedOrderByBuilderImpl.java b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedOrderByBuilderImpl.java
new file mode 100644
index 0000000..5ebe755
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedOrderByBuilderImpl.java
@@ -0,0 +1,64 @@
+/**
+ * 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.query.builder;
+
+import org.eobjects.metamodel.query.FunctionType;
+import org.eobjects.metamodel.query.OrderByItem;
+import org.eobjects.metamodel.query.OrderByItem.Direction;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+
+final class SatisfiedOrderByBuilderImpl extends GroupedQueryBuilderCallback
+ implements SatisfiedOrderByBuilder<GroupedQueryBuilder> {
+
+ private OrderByItem orderByitem;
+
+ public SatisfiedOrderByBuilderImpl(Column column, Query query,
+ GroupedQueryBuilder queryBuilder) {
+ super(queryBuilder);
+ orderByitem = new OrderByItem(new SelectItem(column));
+ query.orderBy(orderByitem);
+ }
+
+ public SatisfiedOrderByBuilderImpl(FunctionType function, Column column,
+ Query query, GroupedQueryBuilder queryBuilder) {
+ super(queryBuilder);
+ orderByitem = new OrderByItem(new SelectItem(function, column));
+ query.orderBy(orderByitem);
+ }
+
+ @Override
+ public GroupedQueryBuilder asc() {
+ orderByitem.setDirection(Direction.ASC);
+ return getQueryBuilder();
+ }
+
+ @Override
+ public GroupedQueryBuilder desc() {
+ orderByitem.setDirection(Direction.DESC);
+ return getQueryBuilder();
+ }
+
+ @Override
+ public SatisfiedOrderByBuilder<GroupedQueryBuilder> and(Column column) {
+ return getQueryBuilder().orderBy(column);
+ }
+
+}
\ 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/query/builder/SatisfiedQueryBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedQueryBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedQueryBuilder.java
new file mode 100644
index 0000000..dd98935
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedQueryBuilder.java
@@ -0,0 +1,133 @@
+/**
+ * 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.query.builder;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.query.CompiledQuery;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.FunctionType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.Column;
+
+/**
+ * Represents a built query that is satisfied and ready for querying or further
+ * building.
+ *
+ * @author Kasper Sørensen
+ *
+ * @param <B>
+ */
+public interface SatisfiedQueryBuilder<B extends SatisfiedQueryBuilder<?>> {
+
+ public ColumnSelectBuilder<B> select(Column column);
+
+ public SatisfiedSelectBuilder<B> select(Column... columns);
+
+ /**
+ * Sets the offset (number of rows to skip) of the query that is being
+ * built.
+ *
+ * Note that this number is a 0-based variant of invoking
+ * {@link #firstRow(int)}.
+ *
+ * @param offset
+ * the number of rows to skip
+ * @return
+ */
+ public SatisfiedQueryBuilder<B> offset(int offset);
+
+ /**
+ * Sets the first row of the query that is being built.
+ *
+ * Note that this is a 1-based variant of invoking {@link #limit(int)}.
+ *
+ * @param firstRow
+ * @return
+ */
+ public SatisfiedQueryBuilder<B> firstRow(int firstRow);
+
+ /**
+ * Sets the limit (aka. max rows) of the query that is being built.
+ *
+ * @param maxRows
+ * @return
+ */
+ public SatisfiedQueryBuilder<B> limit(int limit);
+
+ /**
+ * Sets the max rows (aka. limit) of the query that is being built.
+ *
+ * @param maxRows
+ * @return
+ */
+ public SatisfiedQueryBuilder<B> maxRows(int maxRows);
+
+ public FunctionSelectBuilder<B> select(FunctionType functionType, Column column);
+
+ public CountSelectBuilder<B> selectCount();
+
+ public ColumnSelectBuilder<B> select(String columnName);
+
+ public WhereBuilder<B> where(Column column);
+
+ public WhereBuilder<B> where(String columnName);
+
+ public SatisfiedQueryBuilder<B> where(FilterItem... filters);
+
+ public SatisfiedQueryBuilder<B> where(Iterable<FilterItem> filters);
+
+ public SatisfiedOrderByBuilder<B> orderBy(String columnName);
+
+ public SatisfiedOrderByBuilder<B> orderBy(Column column);
+
+ public GroupedQueryBuilder groupBy(String columnName);
+
+ public GroupedQueryBuilder groupBy(Column column);
+
+ public B groupBy(Column... columns);
+
+ /**
+ * Gets the built query as a {@link Query} object. Typically the returned
+ * query will be a clone of the built query to prevent conflicting
+ * mutations.
+ *
+ * @return a {@link Query} object representing the built query.
+ */
+ public Query toQuery();
+
+ public CompiledQuery compile();
+
+ /**
+ * Executes the built query. This call is similar to calling
+ * {@link #toQuery()} and then {@link DataContext#executeQuery(Query)}.
+ *
+ * @return the {@link DataSet} that is returned by executing the query.
+ */
+ public DataSet execute();
+
+ /**
+ * Finds a column by name within the already defined FROM items
+ *
+ * @param columnName
+ * @return
+ * @throws IllegalArgumentException
+ */
+ public Column findColumn(String columnName) throws IllegalArgumentException;
+}
\ 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/query/builder/SatisfiedSelectBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedSelectBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedSelectBuilder.java
new file mode 100644
index 0000000..886b763
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedSelectBuilder.java
@@ -0,0 +1,35 @@
+/**
+ * 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.query.builder;
+
+import org.eobjects.metamodel.query.FunctionType;
+import org.eobjects.metamodel.schema.Column;
+
+public interface SatisfiedSelectBuilder<B extends SatisfiedQueryBuilder<?>>
+ extends SatisfiedQueryBuilder<B> {
+
+ public ColumnSelectBuilder<B> and(Column column);
+
+ public SatisfiedSelectBuilder<B> and(Column ... columns);
+
+ public FunctionSelectBuilder<B> and(FunctionType function,
+ Column column);
+
+ public SatisfiedSelectBuilder<B> and(String columnName);
+}
\ 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/query/builder/SatisfiedSelectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedSelectBuilderImpl.java b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedSelectBuilderImpl.java
new file mode 100644
index 0000000..2fe66ce
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedSelectBuilderImpl.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.query.builder;
+
+import org.eobjects.metamodel.query.FunctionType;
+import org.eobjects.metamodel.schema.Column;
+
+class SatisfiedSelectBuilderImpl extends GroupedQueryBuilderCallback implements
+ SatisfiedSelectBuilder<GroupedQueryBuilder> {
+
+ public SatisfiedSelectBuilderImpl(GroupedQueryBuilder queryBuilder) {
+ super(queryBuilder);
+ }
+
+ @Override
+ public ColumnSelectBuilder<GroupedQueryBuilder> and(Column column) {
+ if (column == null) {
+ throw new IllegalArgumentException("column cannot be null");
+ }
+ return getQueryBuilder().select(column);
+ }
+
+ @Override
+ public SatisfiedSelectBuilder<GroupedQueryBuilder> and(Column... columns) {
+ if (columns == null) {
+ throw new IllegalArgumentException("columns cannot be null");
+ }
+ return getQueryBuilder().select(columns);
+ }
+
+ @Override
+ public FunctionSelectBuilder<GroupedQueryBuilder> and(
+ FunctionType functionType, Column column) {
+ if (functionType == null) {
+ throw new IllegalArgumentException("functionType cannot be null");
+ }
+ if (column == null) {
+ throw new IllegalArgumentException("column cannot be null");
+ }
+ return getQueryBuilder().select(functionType, column);
+ }
+
+ @Override
+ public SatisfiedSelectBuilder<GroupedQueryBuilder> and(String columnName) {
+ if (columnName == null) {
+ throw new IllegalArgumentException("columnName cannot be null");
+ }
+ return getQueryBuilder().select(columnName);
+ }
+
+}
\ 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/query/builder/SatisfiedWhereBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedWhereBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedWhereBuilder.java
new file mode 100644
index 0000000..d236ed2
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedWhereBuilder.java
@@ -0,0 +1,33 @@
+/**
+ * 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.query.builder;
+
+import org.eobjects.metamodel.schema.Column;
+
+public interface SatisfiedWhereBuilder<B extends SatisfiedQueryBuilder<?>>
+ extends SatisfiedQueryBuilder<B> {
+
+ public WhereBuilder<B> or(String columnName);
+
+ public WhereBuilder<B> or(Column column);
+
+ public WhereBuilder<B> and(String columnName);
+
+ public WhereBuilder<B> and(Column column);
+}
\ 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/query/builder/TableFromBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/TableFromBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/TableFromBuilder.java
new file mode 100644
index 0000000..d030653
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/TableFromBuilder.java
@@ -0,0 +1,33 @@
+/**
+ * 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.query.builder;
+
+import org.eobjects.metamodel.schema.Table;
+
+public interface TableFromBuilder extends
+ SatisfiedFromBuilder {
+
+ public JoinFromBuilder innerJoin(Table table);
+
+ public JoinFromBuilder leftJoin(Table table);
+
+ public JoinFromBuilder rightJoin(Table table);
+
+ public TableFromBuilder as(String alias);
+}
\ 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/query/builder/TableFromBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/TableFromBuilderImpl.java b/core/src/main/java/org/apache/metamodel/query/builder/TableFromBuilderImpl.java
new file mode 100644
index 0000000..4460d8e
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/TableFromBuilderImpl.java
@@ -0,0 +1,83 @@
+/**
+ * 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.query.builder;
+
+import java.util.List;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.JoinType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.Table;
+
+final class TableFromBuilderImpl extends SatisfiedFromBuilderCallback implements
+ TableFromBuilder {
+
+ private FromItem fromItem;
+
+ public TableFromBuilderImpl(Table table, Query query,
+ DataContext dataContext) {
+ super(query, dataContext);
+
+ fromItem = new FromItem(table);
+ query.from(fromItem);
+ }
+
+ @Override
+ public JoinFromBuilder innerJoin(Table table) {
+ if (table == null) {
+ throw new IllegalArgumentException("table cannot be null");
+ }
+ return new JoinFromBuilderImpl(getQuery(), fromItem, table,
+ JoinType.INNER, getDataContext());
+ }
+
+ @Override
+ public JoinFromBuilder leftJoin(Table table) {
+ if (table == null) {
+ throw new IllegalArgumentException("table cannot be null");
+ }
+ return new JoinFromBuilderImpl(getQuery(), fromItem, table,
+ JoinType.LEFT, getDataContext());
+ }
+
+ @Override
+ public JoinFromBuilder rightJoin(Table table) {
+ if (table == null) {
+ throw new IllegalArgumentException("table cannot be null");
+ }
+ return new JoinFromBuilderImpl(getQuery(), fromItem, table,
+ JoinType.RIGHT, getDataContext());
+ }
+
+ @Override
+ public TableFromBuilder as(String alias) {
+ if (alias == null) {
+ throw new IllegalArgumentException("alias cannot be null");
+ }
+ fromItem.setAlias(alias);
+ return this;
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ super.decorateIdentity(identifiers);
+ identifiers.add(fromItem);
+ }
+}
\ 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/query/builder/WhereBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/WhereBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/WhereBuilder.java
new file mode 100644
index 0000000..3055214
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/WhereBuilder.java
@@ -0,0 +1,86 @@
+/**
+ * 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.query.builder;
+
+import org.eobjects.metamodel.query.CompiledQuery;
+import org.eobjects.metamodel.query.QueryParameter;
+
+/**
+ * Builder interface for WHERE items.
+ *
+ * In addition to the {@link FilterBuilder}, the WHERE builder allows using
+ * {@link QueryParameter}s as operands in the generated filters.
+ *
+ * @param <B>
+ */
+public interface WhereBuilder<B extends SatisfiedQueryBuilder<?>> extends FilterBuilder<SatisfiedWhereBuilder<B>> {
+
+ /**
+ * Equals to a query parameter. Can be used with {@link CompiledQuery}
+ * objects.
+ */
+ public SatisfiedWhereBuilder<B> eq(QueryParameter queryParameter);
+
+ /**
+ * Equals to a query parameter. Can be used with {@link CompiledQuery}
+ * objects.
+ */
+ public SatisfiedWhereBuilder<B> isEquals(QueryParameter queryParameter);
+
+ /**
+ * Not equals to a query parameter. Can be used with {@link CompiledQuery}
+ * objects.
+ */
+ public SatisfiedWhereBuilder<B> differentFrom(QueryParameter queryParameter);
+
+ /**
+ * Not equals to a query parameter. Can be used with {@link CompiledQuery}
+ * objects.
+ */
+ public SatisfiedWhereBuilder<B> ne(QueryParameter queryParameter);
+
+ /**
+ * Greater than a query parameter. Can be used with {@link CompiledQuery}
+ * objects.
+ */
+ public SatisfiedWhereBuilder<B> greaterThan(QueryParameter queryParameter);
+
+ /**
+ * Greater than a query parameter. Can be used with {@link CompiledQuery}
+ * objects.
+ */
+ public SatisfiedWhereBuilder<B> gt(QueryParameter queryParameter);
+
+ /**
+ * Less than a query parameter. Can be used with {@link CompiledQuery}
+ * objects.
+ */
+ public SatisfiedWhereBuilder<B> lessThan(QueryParameter queryParameter);
+
+ /**
+ * Less than a query parameter. Can be used with {@link CompiledQuery}
+ * objects.
+ */
+ public SatisfiedWhereBuilder<B> lt(QueryParameter queryParameter);
+
+ /**
+ * Like a query parameter. Can be used with {@link CompiledQuery} objects.
+ */
+ public SatisfiedWhereBuilder<B> like(QueryParameter queryParameter);
+}
\ 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/query/builder/WhereBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/WhereBuilderImpl.java b/core/src/main/java/org/apache/metamodel/query/builder/WhereBuilderImpl.java
new file mode 100644
index 0000000..7e1db14
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/WhereBuilderImpl.java
@@ -0,0 +1,151 @@
+/**
+ * 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.query.builder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.OperatorType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.QueryParameter;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+
+final class WhereBuilderImpl extends AbstractQueryFilterBuilder<SatisfiedWhereBuilder<GroupedQueryBuilder>> implements
+ WhereBuilder<GroupedQueryBuilder>, SatisfiedWhereBuilder<GroupedQueryBuilder> {
+
+ private final Query _query;
+ private final List<FilterItem> _orFilters;
+ private FilterItem _parentOrFilter;
+
+ public WhereBuilderImpl(Column column, Query query, GroupedQueryBuilder queryBuilder) {
+ super(new SelectItem(column), queryBuilder);
+ _query = query;
+ _orFilters = new ArrayList<FilterItem>();
+ }
+
+ public WhereBuilderImpl(Column column, Query query, FilterItem parentOrFilter, List<FilterItem> orFilters,
+ GroupedQueryBuilder queryBuilder) {
+ super(new SelectItem(column), queryBuilder);
+ _query = query;
+ _parentOrFilter = parentOrFilter;
+ _orFilters = orFilters;
+ }
+
+ @Override
+ protected SatisfiedWhereBuilder<GroupedQueryBuilder> applyFilter(FilterItem filter) {
+ if (_parentOrFilter == null) {
+ _query.where(filter);
+ } else {
+ if (_parentOrFilter.getChildItemCount() == 1) {
+ _query.getWhereClause().removeItem(_orFilters.get(0));
+ _query.getWhereClause().addItem(_parentOrFilter);
+ }
+ }
+ _orFilters.add(filter);
+ return this;
+ }
+
+ @Override
+ public WhereBuilder<GroupedQueryBuilder> or(String columnName) {
+ Column column = findColumn(columnName);
+ return or(column);
+ }
+
+ @Override
+ public WhereBuilder<GroupedQueryBuilder> or(Column column) {
+ if (_parentOrFilter == null) {
+ _parentOrFilter = new FilterItem(_orFilters);
+ }
+ return new WhereBuilderImpl(column, _query, _parentOrFilter, _orFilters, getQueryBuilder());
+ }
+
+ @Override
+ public WhereBuilder<GroupedQueryBuilder> and(String columnName) {
+ Column column = findColumn(columnName);
+ return and(column);
+ }
+
+ @Override
+ public WhereBuilder<GroupedQueryBuilder> and(Column column) {
+ return getQueryBuilder().where(column);
+ }
+
+ @Override
+ public SatisfiedWhereBuilder<GroupedQueryBuilder> eq(QueryParameter queryParameter) {
+ return isEquals(queryParameter);
+ }
+
+ @Override
+ public SatisfiedWhereBuilder<GroupedQueryBuilder> isEquals(QueryParameter queryParameter) {
+ if (queryParameter == null) {
+ throw new IllegalArgumentException("query parameter cannot be null");
+ }
+ return _filterBuilder.applyFilter(OperatorType.EQUALS_TO, queryParameter);
+ }
+
+ @Override
+ public SatisfiedWhereBuilder<GroupedQueryBuilder> differentFrom(QueryParameter queryParameter) {
+ return ne(queryParameter);
+ }
+
+ @Override
+ public SatisfiedWhereBuilder<GroupedQueryBuilder> ne(QueryParameter queryParameter) {
+ if (queryParameter == null) {
+ throw new IllegalArgumentException("query parameter cannot be null");
+ }
+ return _filterBuilder.applyFilter(OperatorType.DIFFERENT_FROM, queryParameter);
+ }
+
+ @Override
+ public SatisfiedWhereBuilder<GroupedQueryBuilder> greaterThan(QueryParameter queryParameter) {
+ return gt(queryParameter);
+ }
+
+ @Override
+ public SatisfiedWhereBuilder<GroupedQueryBuilder> gt(QueryParameter queryParameter) {
+ if (queryParameter == null) {
+ throw new IllegalArgumentException("query parameter cannot be null");
+ }
+ return _filterBuilder.applyFilter(OperatorType.GREATER_THAN, queryParameter);
+ }
+
+ @Override
+ public SatisfiedWhereBuilder<GroupedQueryBuilder> lessThan(QueryParameter queryParameter) {
+ return lt(queryParameter);
+ }
+
+ @Override
+ public SatisfiedWhereBuilder<GroupedQueryBuilder> lt(QueryParameter queryParameter) {
+ if (queryParameter == null) {
+ throw new IllegalArgumentException("query parameter cannot be null");
+ }
+ return _filterBuilder.applyFilter(OperatorType.LESS_THAN, queryParameter);
+ }
+
+ @Override
+ public SatisfiedWhereBuilder<GroupedQueryBuilder> like(QueryParameter queryParameter) {
+ if (queryParameter == null) {
+ throw new IllegalArgumentException("query parameter cannot be null");
+ }
+ return _filterBuilder.applyFilter(OperatorType.LIKE, queryParameter);
+ }
+
+}
\ 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/query/builder/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/package-info.java b/core/src/main/java/org/apache/metamodel/query/builder/package-info.java
new file mode 100644
index 0000000..87e58db
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/builder/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 query building
+ */
+package org.eobjects.metamodel.query.builder;
+
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/package-info.java b/core/src/main/java/org/apache/metamodel/query/package-info.java
new file mode 100644
index 0000000..f71ce82
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/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 querying
+ */
+package org.eobjects.metamodel.query;
+
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/parser/FromItemParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/FromItemParser.java b/core/src/main/java/org/apache/metamodel/query/parser/FromItemParser.java
new file mode 100644
index 0000000..78fff2e
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/parser/FromItemParser.java
@@ -0,0 +1,173 @@
+/**
+ * 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.query.parser;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.JoinType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Table;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class FromItemParser implements QueryPartProcessor {
+
+ private static final Logger logger = LoggerFactory.getLogger(FromItemParser.class);
+
+ private final Query _query;
+ private final DataContext _dataContext;
+
+ public FromItemParser(DataContext dataContext, Query query) {
+ _dataContext = dataContext;
+ _query = query;
+ }
+
+ @Override
+ public void parse(String delim, String itemToken) {
+ final FromItem fromItem;
+
+ final int parenthesisStart = itemToken.indexOf('(');
+ if (parenthesisStart != -1) {
+ if (parenthesisStart != 0) {
+ throw new QueryParserException("Not capable of parsing FROM token: " + itemToken
+ + ". Expected parenthesis to start at first character.");
+ }
+ final int parenthesisEnd = itemToken.indexOf(')', parenthesisStart);
+ if (parenthesisEnd == -1) {
+ throw new QueryParserException("Not capable of parsing FROM token: " + itemToken
+ + ". Expected end parenthesis.");
+ }
+
+ final String subQueryString = itemToken.substring(parenthesisStart + 1, parenthesisEnd);
+ logger.debug("Parsing sub-query: {}", subQueryString);
+
+ final Query subQuery = new QueryParser(_dataContext, subQueryString).parse();
+ fromItem = new FromItem(subQuery);
+
+ final String alias = itemToken.substring(parenthesisEnd + 1).trim();
+ if (!alias.isEmpty()) {
+ fromItem.setAlias(alias);
+ }
+ } else if (itemToken.toUpperCase().indexOf(" JOIN ") != -1) {
+ fromItem = parseJoinItem(itemToken);
+ } else {
+ fromItem = parseTableItem(itemToken);
+ }
+
+ _query.from(fromItem);
+ }
+
+ private FromItem parseTableItem(String itemToken) {
+ final String[] tokens = itemToken.split(" ");
+ final String alias;
+ if (tokens.length == 2) {
+ alias = tokens[1];
+ } else if (tokens.length == 1) {
+ alias = null;
+ } else {
+ throw new QueryParserException("Not capable of parsing FROM token: " + itemToken);
+ }
+
+ final Table table = _dataContext.getTableByQualifiedLabel(tokens[0]);
+ if (table == null) {
+ throw new QueryParserException("Not capable of parsing FROM token: " + itemToken);
+ }
+
+ final FromItem result = new FromItem(table);
+ result.setAlias(alias);
+ result.setQuery(_query);
+ return result;
+ }
+
+ // this method will be documented based on this example itemToken: FOO f
+ // INNER JOIN BAR b ON f.id = b.id
+ private FromItem parseJoinItem(final String itemToken) {
+ final int indexOfJoin = itemToken.toUpperCase().indexOf(" JOIN ");
+
+ // firstPart = "FOO f INNER"
+ final String firstPart = itemToken.substring(0, indexOfJoin).trim();
+
+ // secondPart = "BAR b ON f.id = b.id"
+ final String secondPart = itemToken.substring(indexOfJoin + " JOIN ".length()).trim();
+
+ final int indexOfJoinType = firstPart.lastIndexOf(" ");
+
+ // joinTypeString = "INNER"
+ final String joinTypeString = firstPart.substring(indexOfJoinType).trim().toUpperCase();
+ final JoinType joinType = JoinType.valueOf(joinTypeString);
+
+ // firstTableToken = "FOO f"
+ final String firstTableToken = firstPart.substring(0, indexOfJoinType).trim();
+
+ final int indexOfOn = secondPart.toUpperCase().indexOf(" ON ");
+
+ // secondTableToken = "BAR b"
+ final String secondTableToken = secondPart.substring(0, indexOfOn).trim();
+
+ final FromItem leftSide = parseTableItem(firstTableToken);
+ final FromItem rightSide = parseTableItem(secondTableToken);
+
+ // onClausess = ["f.id = b.id"]
+ final String[] onClauses = secondPart.substring(indexOfOn + " ON ".length()).split(" AND ");
+ final SelectItem[] leftOn = new SelectItem[onClauses.length];
+ final SelectItem[] rightOn = new SelectItem[onClauses.length];
+ for (int i = 0; i < onClauses.length; i++) {
+ final String onClause = onClauses[i];
+ final int indexOfEquals = onClause.indexOf("=");
+ // leftPart = "f.id"
+ final String leftPart = onClause.substring(0, indexOfEquals).trim();
+ // rightPart = "b.id"
+ final String rightPart = onClause.substring(indexOfEquals + 1).trim();
+
+ leftOn[i] = findSelectItem(leftPart, leftSide, rightSide);
+ rightOn[i] = findSelectItem(rightPart, leftSide, rightSide);
+ }
+
+ final FromItem result = new FromItem(joinType, leftSide, rightSide, leftOn, rightOn);
+ result.setQuery(_query);
+ return result;
+ }
+
+ private SelectItem findSelectItem(String token, FromItem leftSide, FromItem rightSide) {
+ // first look in the original query
+ SelectItemParser selectItemParser = new SelectItemParser(_query, false);
+ SelectItem result = selectItemParser.findSelectItem(token);
+
+ if (result == null) {
+ // fail over and try with the from items available in the join that
+ // is being built.
+ final Query temporaryQuery = new Query().from(leftSide, rightSide);
+ selectItemParser = new SelectItemParser(temporaryQuery, false);
+ result = selectItemParser.findSelectItem(token);
+
+ if (result == null) {
+ throw new QueryParserException("Not capable of parsing ON token: " + token);
+ }
+
+ // set the query on the involved query parts (since they have been
+ // temporarily moved to the searched query).
+ leftSide.setQuery(_query);
+ rightSide.setQuery(_query);
+ result.setQuery(_query);
+ }
+ return result;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/parser/GroupByItemParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/GroupByItemParser.java b/core/src/main/java/org/apache/metamodel/query/parser/GroupByItemParser.java
new file mode 100644
index 0000000..fc7e776
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/parser/GroupByItemParser.java
@@ -0,0 +1,36 @@
+/**
+ * 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.query.parser;
+
+import org.eobjects.metamodel.query.Query;
+
+final class GroupByItemParser implements QueryPartProcessor {
+
+ private final Query _query;
+
+ public GroupByItemParser(Query query) {
+ _query = query;
+ }
+
+ @Override
+ public void parse(String delim, String itemToken) {
+ _query.groupBy(itemToken);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/parser/HavingItemParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/HavingItemParser.java b/core/src/main/java/org/apache/metamodel/query/parser/HavingItemParser.java
new file mode 100644
index 0000000..5f4a559
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/parser/HavingItemParser.java
@@ -0,0 +1,36 @@
+/**
+ * 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.query.parser;
+
+import org.eobjects.metamodel.query.Query;
+
+final class HavingItemParser implements QueryPartProcessor {
+
+ private final Query _query;
+
+ public HavingItemParser(Query query) {
+ _query = query;
+ }
+
+ @Override
+ public void parse(String delim, String itemToken) {
+ _query.having(itemToken);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/parser/OrderByItemParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/OrderByItemParser.java b/core/src/main/java/org/apache/metamodel/query/parser/OrderByItemParser.java
new file mode 100644
index 0000000..8c3ebf0
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/parser/OrderByItemParser.java
@@ -0,0 +1,36 @@
+/**
+ * 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.query.parser;
+
+import org.eobjects.metamodel.query.Query;
+
+final class OrderByItemParser implements QueryPartProcessor {
+
+ private final Query _query;
+
+ public OrderByItemParser(Query query) {
+ _query = query;
+ }
+
+ @Override
+ public void parse(String delim, String itemToken) {
+ _query.orderBy(itemToken);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/parser/QueryParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/QueryParser.java b/core/src/main/java/org/apache/metamodel/query/parser/QueryParser.java
new file mode 100644
index 0000000..a5f0e03
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/parser/QueryParser.java
@@ -0,0 +1,264 @@
+/**
+ * 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.query.parser;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.query.Query;
+
+/**
+ * A parser class of for full SQL-like queries.
+ */
+public class QueryParser {
+
+ private final DataContext _dataContext;
+ private final String _queryString;
+ private final String _queryStringUpperCase;
+
+ public QueryParser(DataContext dataContext, String queryString) {
+ if (dataContext == null) {
+ throw new IllegalArgumentException("DataContext cannot be null");
+ }
+ if (queryString == null) {
+ throw new IllegalArgumentException("Query string cannot be null");
+ }
+ _dataContext = dataContext;
+ _queryString = prepareQuery(queryString);
+ _queryStringUpperCase = _queryString.toUpperCase();
+ }
+
+ /**
+ * Performs any preparations (not changing any semantics) to the query
+ * string
+ *
+ * @param queryString
+ * @return
+ */
+ private String prepareQuery(String queryString) {
+ queryString = queryString.replaceAll("[\n\r\t]", " ");
+ queryString = queryString.replaceAll(" ", " ");
+ queryString = queryString.trim();
+ return queryString;
+ }
+
+ public Query parse() throws QueryParserException {
+ final Query query = new Query();
+
+ // collect focal point query clauses
+ int[] selectIndices = indexesOf("SELECT ", null);
+ int[] fromIndices = indexesOf(" FROM ", selectIndices);
+ int[] whereIndices = indexesOf(" WHERE ", fromIndices);
+ int[] groupByIndices = indexesOf(" GROUP BY ", whereIndices);
+ int[] havingIndices = indexesOf(" HAVING ", groupByIndices);
+ int[] orderByIndices = indexesOf(" ORDER BY", havingIndices);
+ int[] limitIndices = indexesOf(" LIMIT ", orderByIndices);
+ int[] offsetIndices = indexesOf(" OFFSET ", limitIndices);
+
+ // a few validations, minimum requirements
+ if (selectIndices == null) {
+ throw new QueryParserException("SELECT not found in query: " + _queryString);
+ }
+ if (fromIndices == null) {
+ throw new QueryParserException("FROM not found in query: " + _queryString);
+ }
+
+ // parse FROM
+ {
+ final String fromClause = getSubstring(
+ getLastEndIndex(fromIndices),
+ getNextStartIndex(whereIndices, groupByIndices, havingIndices, orderByIndices, limitIndices,
+ offsetIndices));
+ parseFromClause(query, fromClause);
+ }
+
+ {
+ String selectClause = getSubstring(getLastEndIndex(selectIndices), fromIndices[0]);
+ if (selectClause.startsWith("DISTINCT ")) {
+ query.selectDistinct();
+ selectClause = selectClause.substring("DISTINCT ".length());
+ }
+ parseSelectClause(query, selectClause);
+ }
+
+ if (whereIndices != null) {
+ final String whereClause = getSubstring(getLastEndIndex(whereIndices),
+ getNextStartIndex(groupByIndices, havingIndices, orderByIndices, limitIndices, offsetIndices));
+ if (whereClause != null) {
+ parseWhereClause(query, whereClause);
+ }
+ }
+
+ if (groupByIndices != null) {
+ final String groupByClause = getSubstring(getLastEndIndex(groupByIndices, whereIndices),
+ getNextStartIndex(havingIndices, orderByIndices, limitIndices, offsetIndices));
+ if (groupByClause != null) {
+ parseGroupByClause(query, groupByClause);
+ }
+ }
+
+ if (havingIndices != null) {
+ final String havingClause = getSubstring(
+ getLastEndIndex(havingIndices, groupByIndices, whereIndices, fromIndices, selectIndices),
+ getNextStartIndex(orderByIndices, limitIndices, offsetIndices));
+ if (havingClause != null) {
+ parseHavingClause(query, havingClause);
+ }
+ }
+
+ if (orderByIndices != null) {
+ final String orderByClause = getSubstring(
+ getLastEndIndex(orderByIndices, havingIndices, groupByIndices, whereIndices, fromIndices,
+ selectIndices), getNextStartIndex(limitIndices, offsetIndices));
+ if (orderByClause != null) {
+ parseOrderByClause(query, orderByClause);
+ }
+ }
+
+ if (limitIndices != null) {
+ final String limitClause = getSubstring(
+ getLastEndIndex(limitIndices, orderByIndices, havingIndices, groupByIndices, whereIndices,
+ fromIndices, selectIndices), getNextStartIndex(offsetIndices));
+ if (limitClause != null) {
+ parseLimitClause(query, limitClause);
+ }
+ }
+
+ if (offsetIndices != null) {
+ final String offsetClause = getSubstring(
+ getLastEndIndex(offsetIndices, limitIndices, orderByIndices, havingIndices, groupByIndices,
+ whereIndices, fromIndices, selectIndices), getNextStartIndex());
+ if (offsetClause != null) {
+ parseOffsetClause(query, offsetClause);
+ }
+ }
+
+ return query;
+ }
+
+ private void parseFromClause(Query query, String fromClause) {
+ QueryPartParser clauseParser = new QueryPartParser(new FromItemParser(_dataContext, query), fromClause, ",");
+ clauseParser.parse();
+ }
+
+ private void parseSelectClause(Query query, String selectClause) {
+ QueryPartParser clauseParser = new QueryPartParser(new SelectItemParser(query, false), selectClause, ",");
+ clauseParser.parse();
+ }
+
+ private void parseWhereClause(Query query, String whereClause) {
+ // only parse "AND" delimitors, since "OR" will be taken care of as
+ // compound filter items at 2nd level parsing
+ QueryPartParser clauseParser = new QueryPartParser(new WhereItemParser(query), whereClause, " AND ");
+ clauseParser.parse();
+ }
+
+ private void parseGroupByClause(Query query, String groupByClause) {
+ QueryPartParser clauseParser = new QueryPartParser(new GroupByItemParser(query), groupByClause, ",");
+ clauseParser.parse();
+ }
+
+ private void parseHavingClause(Query query, String havingClause) {
+ // only parse "AND" delimitors, since "OR" will be taken care of as
+ // compound filter items at 2nd level parsing
+ QueryPartParser clauseParser = new QueryPartParser(new HavingItemParser(query), havingClause, " AND ");
+ clauseParser.parse();
+ }
+
+ private void parseOrderByClause(Query query, String orderByClause) {
+ QueryPartParser clauseParser = new QueryPartParser(new OrderByItemParser(query), orderByClause, ",");
+ clauseParser.parse();
+ }
+
+ private void parseLimitClause(Query query, String limitClause) {
+ limitClause = limitClause.trim();
+ if (!limitClause.isEmpty()) {
+ try {
+ int limit = Integer.parseInt(limitClause);
+ query.setMaxRows(limit);
+ } catch (NumberFormatException e) {
+ throw new QueryParserException("Could not parse LIMIT value: " + limitClause);
+ }
+ }
+ }
+
+ private void parseOffsetClause(Query query, String offsetClause) {
+ offsetClause = offsetClause.trim();
+ if (!offsetClause.isEmpty()) {
+ try {
+ final int offset = Integer.parseInt(offsetClause);
+ // ofset is 0-based, but first-row is 1-based
+ final int firstRow = offset + 1;
+ query.setFirstRow(firstRow);
+ } catch (NumberFormatException e) {
+ throw new QueryParserException("Could not parse OFFSET value: " + offsetClause);
+ }
+ }
+ }
+
+ private String getSubstring(Integer from, int to) {
+ if (from == null) {
+ return null;
+ }
+ if (from.intValue() == to) {
+ return null;
+ }
+ return _queryString.substring(from, to);
+ }
+
+ private int getNextStartIndex(int[]... indicesArray) {
+ for (int[] indices : indicesArray) {
+ if (indices != null) {
+ return indices[0];
+ }
+ }
+ return _queryString.length();
+ }
+
+ private Integer getLastEndIndex(int[]... indicesArray) {
+ for (int[] indices : indicesArray) {
+ if (indices != null) {
+ return indices[1];
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Finds the start and end indexes of a string in the query. The string
+ * parameter of this method is expected to be in upper case, while the query
+ * itself is tolerant of case differences.
+ *
+ * @param string
+ * @param previousIndices
+ * @return
+ */
+ protected int[] indexesOf(String string, int[] previousIndices) {
+ final int startIndex;
+ if (previousIndices == null) {
+ startIndex = _queryStringUpperCase.indexOf(string);
+ } else {
+ startIndex = _queryStringUpperCase.indexOf(string, previousIndices[1]);
+ }
+ if (startIndex == -1) {
+ return null;
+ }
+ int endIndex = startIndex + string.length();
+ return new int[] { startIndex, endIndex };
+ }
+
+}
\ 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/query/parser/QueryParserException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/QueryParserException.java b/core/src/main/java/org/apache/metamodel/query/parser/QueryParserException.java
new file mode 100644
index 0000000..ad3f42c
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/parser/QueryParserException.java
@@ -0,0 +1,46 @@
+/**
+ * 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.query.parser;
+
+import org.eobjects.metamodel.MetaModelException;
+
+/**
+ * Subtype of {@link MetaModelException} which indicate a problem in parsing a
+ * query passed to the {@link QueryParser}.
+ */
+public class QueryParserException extends MetaModelException {
+
+ private static final long serialVersionUID = 1L;
+
+ public QueryParserException() {
+ super();
+ }
+
+ public QueryParserException(Exception cause) {
+ super(cause);
+ }
+
+ public QueryParserException(String message, Exception cause) {
+ super(message, cause);
+ }
+
+ public QueryParserException(String message) {
+ super(message);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/parser/QueryPartCollectionProcessor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/QueryPartCollectionProcessor.java b/core/src/main/java/org/apache/metamodel/query/parser/QueryPartCollectionProcessor.java
new file mode 100644
index 0000000..ac45a49
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/parser/QueryPartCollectionProcessor.java
@@ -0,0 +1,52 @@
+/**
+ * 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.query.parser;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Simple implementation of {@link QueryPartProcessor} which simply adds all
+ * elements to a collection. Use {@link #getTokens()} to retrieve the 'processed'
+ * tokens and {@link #getDelims()} for the corresponding delimitors.
+ */
+public class QueryPartCollectionProcessor implements QueryPartProcessor {
+
+ private final List<String> _delims;
+ private final List<String> _tokens;
+
+ public QueryPartCollectionProcessor() {
+ _tokens = new ArrayList<String>();
+ _delims = new ArrayList<String>();
+ }
+
+ @Override
+ public void parse(String delim, String token) {
+ _delims.add(delim);
+ _tokens.add(token);
+ }
+
+ public List<String> getDelims() {
+ return _delims;
+ }
+
+ public List<String> getTokens() {
+ return _tokens;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/query/parser/QueryPartParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/QueryPartParser.java b/core/src/main/java/org/apache/metamodel/query/parser/QueryPartParser.java
new file mode 100644
index 0000000..15050ea
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/query/parser/QueryPartParser.java
@@ -0,0 +1,126 @@
+/**
+ * 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.query.parser;
+
+/**
+ * Parser of query parts. This parser is aware of parenthesis symbols '(' and
+ * ')' and only yields tokens that have balanced parentheses. Delimitors are
+ * configurable.
+ */
+public final class QueryPartParser {
+
+ private final QueryPartProcessor _processor;
+ private final String _clause;
+ private final String[] _ItemDelims;
+
+ public QueryPartParser(QueryPartProcessor processor, String clause, String... itemDelims) {
+ if (clause == null) {
+ throw new IllegalArgumentException("Clause cannot be null");
+ }
+ if (itemDelims == null || itemDelims.length == 0) {
+ throw new IllegalArgumentException("Item delimitors cannot be null or empty");
+ }
+ _processor = processor;
+ _clause = clause;
+ _ItemDelims = itemDelims;
+ }
+
+ public void parse() {
+ if (_clause.isEmpty()) {
+ return;
+ }
+
+ int parenthesisCount = 0;
+ int offset = 0;
+ boolean singleOuterParenthesis = _clause.charAt(0) == '(' && _clause.charAt(_clause.length() - 1) == ')';
+
+ String previousDelim = null;
+ DelimOccurrence nextDelimOccurrence = getNextDelim(0);
+ if (nextDelimOccurrence != null) {
+ for (int i = 0; i < _clause.length(); i++) {
+ char c = _clause.charAt(i);
+ if (c == '(') {
+ parenthesisCount++;
+ } else if (c == ')') {
+ parenthesisCount--;
+ if (singleOuterParenthesis && parenthesisCount == 0 && i != _clause.length() - 1) {
+ singleOuterParenthesis = false;
+ }
+ }
+ if (i == nextDelimOccurrence.index) {
+ if (parenthesisCount == 0) {
+ // token bounds has been identified
+ String itemToken = _clause.substring(offset, i);
+ parseItem(previousDelim, itemToken);
+ offset = i + nextDelimOccurrence.delim.length();
+ previousDelim = nextDelimOccurrence.delim;
+ }
+ nextDelimOccurrence = getNextDelim(nextDelimOccurrence.index + 1);
+ if (nextDelimOccurrence == null) {
+ break;
+ }
+ }
+ }
+ }
+
+ if (singleOuterParenthesis) {
+ String newClause = _clause.substring(1, _clause.length() - 1);
+ // re-run based on new clause
+ QueryPartParser newParser = new QueryPartParser(_processor, newClause, _ItemDelims);
+ newParser.parse();
+ return;
+ }
+
+ // last token will occur outside loop
+ if (offset != _clause.length()) {
+ final String token = _clause.substring(offset);
+ parseItem(previousDelim, token);
+ }
+ }
+
+ private static class DelimOccurrence {
+ public int index;
+ public String delim;
+ }
+
+ private DelimOccurrence getNextDelim(int offset) {
+ DelimOccurrence result = null;
+ for (int i = 0; i < _ItemDelims.length; i++) {
+ String delim = _ItemDelims[i];
+ int index = _clause.indexOf(delim, offset);
+ if (index != -1) {
+ if (result == null || index == Math.min(result.index, index)) {
+ result = new DelimOccurrence();
+ result.index = index;
+ result.delim = delim;
+ }
+ }
+ }
+ return result;
+ }
+
+ private void parseItem(String delim, String token) {
+ if (token != null) {
+ token = token.trim();
+ if (!token.isEmpty()) {
+ _processor.parse(delim, token);
+ }
+ }
+ }
+}
[38/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/MetaModelHelper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/MetaModelHelper.java b/core/src/main/java/org/eobjects/metamodel/MetaModelHelper.java
deleted file mode 100644
index a105973..0000000
--- a/core/src/main/java/org/eobjects/metamodel/MetaModelHelper.java
+++ /dev/null
@@ -1,775 +0,0 @@
-/**
- * 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;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.eobjects.metamodel.data.CachingDataSetHeader;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetHeader;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.EmptyDataSet;
-import org.eobjects.metamodel.data.FilteredDataSet;
-import org.eobjects.metamodel.data.IRowFilter;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.SimpleDataSetHeader;
-import org.eobjects.metamodel.data.SubSelectionDataSet;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.GroupByItem;
-import org.eobjects.metamodel.query.OrderByItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.query.parser.QueryParser;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.SuperColumnType;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.AggregateBuilder;
-import org.eobjects.metamodel.util.CollectionUtils;
-import org.eobjects.metamodel.util.EqualsBuilder;
-import org.eobjects.metamodel.util.Func;
-import org.eobjects.metamodel.util.ObjectComparator;
-import org.eobjects.metamodel.util.Predicate;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class contains various helper functionality to common tasks in
- * MetaModel, eg.:
- *
- * <ul>
- * <li>Easy-access for traversing common schema items</li>
- * <li>Manipulate data in memory. These methods are primarily used to enable
- * queries for non-queryable data sources like CSV files and spreadsheets.</li>
- * <li>Query rewriting, traversing and manipulation.</li>
- * </ul>
- *
- * The class is mainly intended for internal use within the framework
- * operations, but is kept stable, so it can also be used by framework users.
- */
-public final class MetaModelHelper {
-
- private final static Logger logger = LoggerFactory.getLogger(MetaModelHelper.class);
-
- private MetaModelHelper() {
- // Prevent instantiation
- }
-
- /**
- * Creates an array of tables where all occurences of tables in the provided
- * list of tables and columns are included
- */
- public static Table[] getTables(Collection<Table> tableList, Iterable<Column> columnList) {
- HashSet<Table> set = new HashSet<Table>();
- set.addAll(tableList);
- for (Column column : columnList) {
- set.add(column.getTable());
- }
- return set.toArray(new Table[set.size()]);
- }
-
- /**
- * Determines if a schema is an information schema
- *
- * @param schema
- * @return
- */
- public static boolean isInformationSchema(Schema schema) {
- String name = schema.getName();
- return isInformationSchema(name);
- }
-
- /**
- * Determines if a schema name is the name of an information schema
- *
- * @param name
- * @return
- */
- public static boolean isInformationSchema(String name) {
- if (name == null) {
- return false;
- }
- return QueryPostprocessDataContext.INFORMATION_SCHEMA_NAME.equals(name.toLowerCase());
- }
-
- /**
- * Converts a list of columns to a corresponding array of tables
- *
- * @param columns
- * the columns that the tables will be extracted from
- * @return an array containing the tables of the provided columns.
- */
- public static Table[] getTables(Iterable<Column> columns) {
- ArrayList<Table> result = new ArrayList<Table>();
- for (Column column : columns) {
- Table table = column.getTable();
- if (!result.contains(table)) {
- result.add(table);
- }
- }
- return result.toArray(new Table[result.size()]);
- }
-
- /**
- * Creates a subset array of columns, where only columns that are contained
- * within the specified table are included.
- *
- * @param table
- * @param columns
- * @return an array containing the columns that exist in the table
- */
- public static Column[] getTableColumns(Table table, Iterable<Column> columns) {
- if (table == null) {
- return new Column[0];
- }
- final List<Column> result = new ArrayList<Column>();
- for (Column column : columns) {
- final boolean sameTable = table.equals(column.getTable());
- if (sameTable) {
- result.add(column);
- }
- }
- return result.toArray(new Column[result.size()]);
- }
-
- /**
- * Creates a subset array of columns, where only columns that are contained
- * within the specified table are included.
- *
- * @param table
- * @param columns
- * @return an array containing the columns that exist in the table
- */
- public static Column[] getTableColumns(Table table, Column[] columns) {
- return getTableColumns(table, Arrays.asList(columns));
- }
-
- public static DataSet getCarthesianProduct(DataSet... fromDataSets) {
- return getCarthesianProduct(fromDataSets, new FilterItem[0]);
- }
-
- public static DataSet getCarthesianProduct(DataSet[] fromDataSets, Iterable<FilterItem> whereItems) {
- // First check if carthesian product is even nescesary
- if (fromDataSets.length == 1) {
- return getFiltered(fromDataSets[0], whereItems);
- }
-
- List<SelectItem> selectItems = new ArrayList<SelectItem>();
- for (DataSet dataSet : fromDataSets) {
- for (int i = 0; i < dataSet.getSelectItems().length; i++) {
- SelectItem item = dataSet.getSelectItems()[i];
- selectItems.add(item);
- }
- }
-
- int selectItemOffset = 0;
- List<Object[]> data = new ArrayList<Object[]>();
- for (int fromDataSetIndex = 0; fromDataSetIndex < fromDataSets.length; fromDataSetIndex++) {
- DataSet fromDataSet = fromDataSets[fromDataSetIndex];
- SelectItem[] fromSelectItems = fromDataSet.getSelectItems();
- if (fromDataSetIndex == 0) {
- while (fromDataSet.next()) {
- Object[] values = fromDataSet.getRow().getValues();
- Object[] row = new Object[selectItems.size()];
- System.arraycopy(values, 0, row, selectItemOffset, values.length);
- data.add(row);
- }
- fromDataSet.close();
- } else {
- List<Object[]> fromDataRows = new ArrayList<Object[]>();
- while (fromDataSet.next()) {
- fromDataRows.add(fromDataSet.getRow().getValues());
- }
- fromDataSet.close();
- for (int i = 0; i < data.size(); i = i + fromDataRows.size()) {
- Object[] originalRow = data.get(i);
- data.remove(i);
- for (int j = 0; j < fromDataRows.size(); j++) {
- Object[] newRow = fromDataRows.get(j);
- System.arraycopy(newRow, 0, originalRow, selectItemOffset, newRow.length);
- data.add(i + j, originalRow.clone());
- }
- }
- }
- selectItemOffset += fromSelectItems.length;
- }
-
- if (data.isEmpty()) {
- return new EmptyDataSet(selectItems);
- }
-
- final DataSetHeader header = new CachingDataSetHeader(selectItems);
- final List<Row> rows = new ArrayList<Row>(data.size());
- for (Object[] objects : data) {
- rows.add(new DefaultRow(header, objects, null));
- }
-
- DataSet result = new InMemoryDataSet(header, rows);
- if (whereItems != null) {
- result = getFiltered(result, whereItems);
- }
- return result;
- }
-
- public static DataSet getCarthesianProduct(DataSet[] fromDataSets, FilterItem... filterItems) {
- return getCarthesianProduct(fromDataSets, Arrays.asList(filterItems));
- }
-
- public static DataSet getFiltered(DataSet dataSet, Iterable<FilterItem> filterItems) {
- List<IRowFilter> filters = CollectionUtils.map(filterItems, new Func<FilterItem, IRowFilter>() {
- @Override
- public IRowFilter eval(FilterItem filterItem) {
- return filterItem;
- }
- });
- if (filters.isEmpty()) {
- return dataSet;
- }
-
- return new FilteredDataSet(dataSet, filters.toArray(new IRowFilter[filters.size()]));
- }
-
- public static DataSet getFiltered(DataSet dataSet, FilterItem... filterItems) {
- return getFiltered(dataSet, Arrays.asList(filterItems));
- }
-
- public static DataSet getSelection(final List<SelectItem> selectItems, final DataSet dataSet) {
- final SelectItem[] dataSetSelectItems = dataSet.getSelectItems();
-
- // check if the selection is already the same
- if (selectItems.size() == dataSetSelectItems.length) {
- boolean same = true;
- int i = 0;
- for (SelectItem selectItem : selectItems) {
- if (!EqualsBuilder.equals(selectItem, dataSetSelectItems[i])) {
- same = false;
- break;
- }
- i++;
- }
-
- if (same) {
- // return the dataSet unmodified
- return dataSet;
- }
- }
-
- SelectItem[] selectItemsArray = selectItems.toArray(new SelectItem[selectItems.size()]);
- return new SubSelectionDataSet(selectItemsArray, dataSet);
- }
-
- public static DataSet getSelection(SelectItem[] selectItems, DataSet dataSet) {
- return getSelection(Arrays.asList(selectItems), dataSet);
- }
-
- public static DataSet getGrouped(List<SelectItem> selectItems, DataSet dataSet, Collection<GroupByItem> groupByItems) {
- return getGrouped(selectItems, dataSet, groupByItems.toArray(new GroupByItem[groupByItems.size()]));
- }
-
- public static DataSet getGrouped(List<SelectItem> selectItems, DataSet dataSet, GroupByItem[] groupByItems) {
- DataSet result = dataSet;
- if (groupByItems != null && groupByItems.length > 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 DataSetHeader groupByHeader = new CachingDataSetHeader(groupBySelects);
-
- // Creates a list of SelectItems that have functions
- List<SelectItem> functionItems = getFunctionSelectItems(selectItems);
-
- // Loop through the dataset and identify groups
- while (dataSet.next()) {
- Row row = dataSet.getRow();
-
- // Subselect a row prototype with only the unique values that
- // define the group
- Row uniqueRow = row.getSubSelection(groupByHeader);
-
- // function input is the values used for calculating aggregate
- // functions in the group
- Map<SelectItem, List<Object>> functionInput;
- if (!uniqueRows.containsKey(uniqueRow)) {
- // If this group already exist, use an existing function
- // input
- functionInput = new HashMap<SelectItem, List<Object>>();
- for (SelectItem item : functionItems) {
- functionInput.put(item, new ArrayList<Object>());
- }
- uniqueRows.put(uniqueRow, functionInput);
- } else {
- // If this is a new group, create a new function input
- functionInput = uniqueRows.get(uniqueRow);
- }
-
- // Loop through aggregate functions to check for validity
- for (SelectItem item : functionItems) {
- List<Object> objects = functionInput.get(item);
- Column column = item.getColumn();
- if (column != null) {
- Object value = row.getValue(new SelectItem(column));
- objects.add(value);
- } else if (SelectItem.isCountAllItem(item)) {
- // Just use the empty string, since COUNT(*) don't
- // evaluate values (but null values should be prevented)
- objects.add("");
- } else {
- throw new IllegalArgumentException("Expression function not supported: " + item);
- }
- }
- }
-
- dataSet.close();
- final List<Row> resultData = new ArrayList<Row>();
- final DataSetHeader resultHeader = new CachingDataSetHeader(selectItems);
-
- // Loop through the groups to generate aggregates
- for (Entry<Row, Map<SelectItem, List<Object>>> entry : uniqueRows.entrySet()) {
- Row row = entry.getKey();
- Map<SelectItem, List<Object>> functionInput = entry.getValue();
- Object[] resultRow = new Object[selectItems.size()];
- // Loop through select items to generate a row
- int i = 0;
- for (SelectItem item : selectItems) {
- int uniqueRowIndex = row.indexOf(item);
- if (uniqueRowIndex != -1) {
- // If there's already a value for the select item in the
- // row, keep it (it's one of the grouped by columns)
- resultRow[i] = row.getValue(uniqueRowIndex);
- } else {
- // Use the function input to calculate the aggregate
- // value
- List<Object> objects = functionInput.get(item);
- if (objects != null) {
- Object functionResult = item.getFunction().evaluate(objects.toArray());
- resultRow[i] = functionResult;
- } else {
- if (item.getFunction() != null) {
- logger.error("No function input found for SelectItem: {}", item);
- }
- }
- }
- i++;
- }
- resultData.add(new DefaultRow(resultHeader, resultRow, null));
- }
-
- if (resultData.isEmpty()) {
- result = new EmptyDataSet(selectItems);
- } else {
- result = new InMemoryDataSet(resultHeader, resultData);
- }
- }
- result = getSelection(selectItems, result);
- return result;
- }
-
- /**
- * Applies aggregate values to a dataset. This method is to be invoked AFTER
- * any filters have been applied.
- *
- * @param workSelectItems
- * all select items included in the processing of the query
- * (including those originating from other clauses than the
- * SELECT clause).
- * @param dataSet
- * @return
- */
- public static DataSet getAggregated(List<SelectItem> workSelectItems, DataSet dataSet) {
- final List<SelectItem> functionItems = getFunctionSelectItems(workSelectItems);
- if (functionItems.isEmpty()) {
- return dataSet;
- }
-
- final Map<SelectItem, AggregateBuilder<?>> aggregateBuilders = new HashMap<SelectItem, AggregateBuilder<?>>();
- for (SelectItem item : functionItems) {
- aggregateBuilders.put(item, item.getFunction().build());
- }
-
- final DataSetHeader header;
- final boolean onlyAggregates;
- if (functionItems.size() != workSelectItems.size()) {
- onlyAggregates = false;
- header = new CachingDataSetHeader(workSelectItems);
- } else {
- onlyAggregates = true;
- header = new SimpleDataSetHeader(workSelectItems);
- }
-
- final List<Row> resultRows = new ArrayList<Row>();
- while (dataSet.next()) {
- final Row inputRow = dataSet.getRow();
- for (SelectItem item : functionItems) {
- final AggregateBuilder<?> aggregateBuilder = aggregateBuilders.get(item);
- final Column column = item.getColumn();
- if (column != null) {
- Object value = inputRow.getValue(new SelectItem(column));
- aggregateBuilder.add(value);
- } else if (SelectItem.isCountAllItem(item)) {
- // Just use the empty string, since COUNT(*) don't
- // evaluate values (but null values should be prevented)
- aggregateBuilder.add("");
- } else {
- throw new IllegalArgumentException("Expression function not supported: " + item);
- }
- }
-
- // If the result should also contain non-aggregated values, we
- // will keep those in the rows list
- if (!onlyAggregates) {
- final Object[] values = new Object[header.size()];
- for (int i = 0; i < header.size(); i++) {
- final Object value = inputRow.getValue(header.getSelectItem(i));
- if (value != null) {
- values[i] = value;
- }
- }
- resultRows.add(new DefaultRow(header, values));
- }
- }
- dataSet.close();
-
- // Collect the aggregates
- Map<SelectItem, Object> functionResult = new HashMap<SelectItem, Object>();
- for (SelectItem item : functionItems) {
- AggregateBuilder<?> aggregateBuilder = aggregateBuilders.get(item);
- Object result = aggregateBuilder.getAggregate();
- functionResult.put(item, result);
- }
-
- // if there are no result rows (no matching records at all), we still
- // need to return a record with the aggregates
- final boolean noResultRows = resultRows.isEmpty();
-
- if (onlyAggregates || noResultRows) {
- // We will only create a single row with all the aggregates
- Object[] values = new Object[header.size()];
- for (int i = 0; i < header.size(); i++) {
- values[i] = functionResult.get(header.getSelectItem(i));
- }
- Row row = new DefaultRow(header, values);
- resultRows.add(row);
- } else {
- // We will create the aggregates as well as regular values
- for (int i = 0; i < resultRows.size(); i++) {
- Row row = resultRows.get(i);
- Object[] values = row.getValues();
- for (Entry<SelectItem, Object> entry : functionResult.entrySet()) {
- SelectItem item = entry.getKey();
- int itemIndex = row.indexOf(item);
- if (itemIndex != -1) {
- Object value = entry.getValue();
- values[itemIndex] = value;
- }
- }
- resultRows.set(i, new DefaultRow(header, values));
- }
- }
-
- return new InMemoryDataSet(header, resultRows);
- }
-
- public static List<SelectItem> getFunctionSelectItems(Iterable<SelectItem> selectItems) {
- return CollectionUtils.filter(selectItems, new Predicate<SelectItem>() {
- @Override
- public Boolean eval(SelectItem arg) {
- return arg.getFunction() != null;
- }
- });
- }
-
- public static DataSet getOrdered(DataSet dataSet, List<OrderByItem> orderByItems) {
- return getOrdered(dataSet, orderByItems.toArray(new OrderByItem[orderByItems.size()]));
- }
-
- public static DataSet getOrdered(DataSet dataSet, final OrderByItem... orderByItems) {
- if (orderByItems != null && orderByItems.length != 0) {
- final int[] sortIndexes = new int[orderByItems.length];
- for (int i = 0; i < orderByItems.length; i++) {
- OrderByItem item = orderByItems[i];
- int indexOf = dataSet.indexOf(item.getSelectItem());
- sortIndexes[i] = indexOf;
- }
-
- final List<Row> data = readDataSetFull(dataSet);
- if (data.isEmpty()) {
- return new EmptyDataSet(dataSet.getSelectItems());
- }
-
- final Comparator<Object> valueComparator = ObjectComparator.getComparator();
-
- // create a comparator for doing the actual sorting/ordering
- final Comparator<Row> comparator = new Comparator<Row>() {
- public int compare(Row o1, Row o2) {
- for (int i = 0; i < sortIndexes.length; i++) {
- int sortIndex = sortIndexes[i];
- Object sortObj1 = o1.getValue(sortIndex);
- Object sortObj2 = o2.getValue(sortIndex);
- int compare = valueComparator.compare(sortObj1, sortObj2);
- if (compare != 0) {
- OrderByItem orderByItem = orderByItems[i];
- boolean ascending = orderByItem.isAscending();
- if (ascending) {
- return compare;
- } else {
- return compare * -1;
- }
- }
- }
- return 0;
- }
- };
-
- Collections.sort(data, comparator);
-
- dataSet = new InMemoryDataSet(data);
- }
- return dataSet;
- }
-
- public static List<Row> readDataSetFull(DataSet dataSet) {
- final List<Row> result;
- if (dataSet instanceof InMemoryDataSet) {
- // if dataset is an in memory dataset we have a shortcut to avoid
- // creating a new list
- result = ((InMemoryDataSet) dataSet).getRows();
- } else {
- result = new ArrayList<Row>();
- while (dataSet.next()) {
- result.add(dataSet.getRow());
- }
- }
- dataSet.close();
- return result;
- }
-
- /**
- * Examines a query and extracts an array of FromItem's that refer
- * (directly) to tables (hence Joined FromItems and SubQuery FromItems are
- * traversed but not included).
- *
- * @param q
- * the query to examine
- * @return an array of FromItem's that refer directly to tables
- */
- public static FromItem[] getTableFromItems(Query q) {
- List<FromItem> result = new ArrayList<FromItem>();
- List<FromItem> items = q.getFromClause().getItems();
- for (FromItem item : items) {
- result.addAll(getTableFromItems(item));
- }
- return result.toArray(new FromItem[result.size()]);
- }
-
- public static List<FromItem> getTableFromItems(FromItem item) {
- List<FromItem> result = new ArrayList<FromItem>();
- if (item.getTable() != null) {
- result.add(item);
- } else if (item.getSubQuery() != null) {
- FromItem[] sqItems = getTableFromItems(item.getSubQuery());
- for (int i = 0; i < sqItems.length; i++) {
- result.add(sqItems[i]);
- }
- } else if (item.getJoin() != null) {
- FromItem leftSide = item.getLeftSide();
- result.addAll(getTableFromItems(leftSide));
- FromItem rightSide = item.getRightSide();
- result.addAll(getTableFromItems(rightSide));
- } else {
- throw new IllegalStateException("FromItem was neither of Table type, SubQuery type or Join type: " + item);
- }
- return result;
- }
-
- /**
- * Executes a single row query, like "SELECT COUNT(*), MAX(SOME_COLUMN) FROM
- * MY_TABLE" or similar.
- *
- * @param dataContext
- * the DataContext object to use for executing the query
- * @param query
- * the query to execute
- * @return a row object representing the single row returned from the query
- * @throws MetaModelException
- * if less or more than one Row is returned from the query
- */
- public static Row executeSingleRowQuery(DataContext dataContext, Query query) throws MetaModelException {
- DataSet dataSet = dataContext.executeQuery(query);
- boolean next = dataSet.next();
- if (!next) {
- throw new MetaModelException("No rows returned from query: " + query);
- }
- Row row = dataSet.getRow();
- next = dataSet.next();
- if (next) {
- throw new MetaModelException("More than one row returned from query: " + query);
- }
- dataSet.close();
- return row;
- }
-
- /**
- * Performs a left join (aka left outer join) operation on two datasets.
- *
- * @param ds1
- * the left dataset
- * @param ds2
- * the right dataset
- * @param onConditions
- * the conditions to join by
- * @return the left joined result dataset
- */
- public static DataSet getLeftJoin(DataSet ds1, DataSet ds2, FilterItem[] onConditions) {
- if (ds1 == null) {
- throw new IllegalArgumentException("Left DataSet cannot be null");
- }
- 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<Row> resultRows = new ArrayList<Row>();
- List<Row> ds2data = readDataSetFull(ds2);
- if (ds2data.isEmpty()) {
- // no need to join, simply return a new view (with null values) on
- // the previous dataset.
- return getSelection(selectItems, ds1);
- }
-
- final DataSetHeader header = new CachingDataSetHeader(selectItems);
-
- while (ds1.next()) {
-
- // Construct a single-row dataset for making a carthesian product
- // against ds2
- Row ds1row = ds1.getRow();
- List<Row> ds1rows = new ArrayList<Row>();
- ds1rows.add(ds1row);
-
- DataSet carthesianProduct = getCarthesianProduct(new DataSet[] {
- new InMemoryDataSet(new CachingDataSetHeader(si1), ds1rows),
- new InMemoryDataSet(new CachingDataSetHeader(si2), ds2data) }, onConditions);
- List<Row> carthesianRows = readDataSetFull(carthesianProduct);
- if (carthesianRows.size() > 0) {
- resultRows.addAll(carthesianRows);
- } else {
- Object[] values = ds1row.getValues();
- Object[] row = new Object[selectItems.length];
- System.arraycopy(values, 0, row, 0, values.length);
- resultRows.add(new DefaultRow(header, row));
- }
- }
- ds1.close();
-
- if (resultRows.isEmpty()) {
- return new EmptyDataSet(selectItems);
- }
-
- return new InMemoryDataSet(header, resultRows);
- }
-
- /**
- * Performs a right join (aka right outer join) operation on two datasets.
- *
- * @param ds1
- * the left dataset
- * @param ds2
- * the right dataset
- * @param onConditions
- * the conditions to join by
- * @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);
-
- // We will reuse the left join algorithm (but switch the datasets
- // around)
- DataSet dataSet = getLeftJoin(ds2, ds1, onConditions);
-
- dataSet = getSelection(leftOrderedSelects, dataSet);
- return dataSet;
- }
-
- public static SelectItem[] createSelectItems(Column... columns) {
- SelectItem[] items = new SelectItem[columns.length];
- for (int i = 0; i < items.length; i++) {
- items[i] = new SelectItem(columns[i]);
- }
- return items;
- }
-
- 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);
- }
-
- public static Table[] getTables(Column[] columns) {
- return getTables(Arrays.asList(columns));
- }
-
- public static Column[] getColumnsByType(Column[] columns, final ColumnType columnType) {
- return CollectionUtils.filter(columns, new Predicate<Column>() {
- @Override
- public Boolean eval(Column column) {
- return column.getType() == columnType;
- }
- }).toArray(new Column[0]);
- }
-
- public static Column[] getColumnsBySuperType(Column[] columns, final SuperColumnType superColumnType) {
- return CollectionUtils.filter(columns, new Predicate<Column>() {
- @Override
- public Boolean eval(Column column) {
- return column.getType().getSuperType() == superColumnType;
- }
- }).toArray(new Column[0]);
- }
-
- public static Query parseQuery(DataContext dc, String queryString) {
- final QueryParser parser = new QueryParser(dc, queryString);
- return parser.parse();
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/QueryPostprocessDataContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/QueryPostprocessDataContext.java b/core/src/main/java/org/eobjects/metamodel/QueryPostprocessDataContext.java
deleted file mode 100644
index d84da6a..0000000
--- a/core/src/main/java/org/eobjects/metamodel/QueryPostprocessDataContext.java
+++ /dev/null
@@ -1,589 +0,0 @@
-/**
- * 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;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eobjects.metamodel.convert.ConvertedDataSetInterceptor;
-import org.eobjects.metamodel.convert.Converters;
-import org.eobjects.metamodel.convert.HasReadTypeConverters;
-import org.eobjects.metamodel.convert.TypeConverter;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetHeader;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.EmptyDataSet;
-import org.eobjects.metamodel.data.FirstRowDataSet;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.data.MaxRowsDataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.SimpleDataSetHeader;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.GroupByItem;
-import org.eobjects.metamodel.query.JoinType;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.OrderByItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableRelationship;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.schema.TableType;
-import org.eobjects.metamodel.util.CollectionUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Abstract DataContext for data sources that do not support SQL queries
- * natively.
- *
- * Instead this superclass only requires that a subclass can materialize a
- * single table at a time. Then the query will be executed by post processing
- * the datasets client-side.
- */
-public abstract class QueryPostprocessDataContext extends AbstractDataContext implements HasReadTypeConverters {
-
- private static final Logger logger = LoggerFactory.getLogger(QueryPostprocessDataContext.class);
-
- public static final String INFORMATION_SCHEMA_NAME = "information_schema";
-
- private final Map<Column, TypeConverter<?, ?>> _converters;
-
- private Schema _mainSchema;
-
- public QueryPostprocessDataContext() {
- super();
- _converters = new HashMap<Column, TypeConverter<?, ?>>();
- }
-
- @Override
- public DataSet executeQuery(final Query query) {
- final List<SelectItem> selectItems = query.getSelectClause().getItems();
- final List<FromItem> fromItems = query.getFromClause().getItems();
- final List<FilterItem> whereItems = query.getWhereClause().getItems();
- final List<SelectItem> whereSelectItems = query.getWhereClause().getEvaluatedSelectItems();
- final List<GroupByItem> groupByItems = query.getGroupByClause().getItems();
- final List<SelectItem> groupBySelectItems = query.getGroupByClause().getEvaluatedSelectItems();
- final List<SelectItem> havingSelectItems = query.getHavingClause().getEvaluatedSelectItems();
- final List<SelectItem> orderBySelectItems = query.getOrderByClause().getEvaluatedSelectItems();
-
- final List<FilterItem> havingItems = query.getHavingClause().getItems();
- final List<OrderByItem> orderByItems = query.getOrderByClause().getItems();
-
- // check for approximate SELECT COUNT(*) queries
- if (fromItems.size() == 1 && selectItems.size() == 1 && groupByItems.isEmpty() && havingItems.isEmpty()) {
- final SelectItem selectItem = query.getSelectClause().getItem(0);
- if (SelectItem.isCountAllItem(selectItem)) {
- final boolean functionApproximationAllowed = selectItem.isFunctionApproximationAllowed();
- final FromItem fromItem = query.getFromClause().getItem(0);
- final Table table = fromItem.getTable();
- if (table != null) {
- if (isMainSchemaTable(table)) {
- logger.debug("Query is a COUNT query with {} where items. Trying executeCountQuery(...)",
- whereItems.size());
- final Number count = executeCountQuery(table, whereItems, functionApproximationAllowed);
- if (count == null) {
- logger.debug("DataContext did not return any count query results. Proceeding with manual counting.");
- } else {
- List<Row> data = new ArrayList<Row>(1);
- final DataSetHeader header = new SimpleDataSetHeader(new SelectItem[] { selectItem });
- data.add(new DefaultRow(header, new Object[] { count }));
- return new InMemoryDataSet(header, data);
- }
- }
- }
- }
- }
-
- final int firstRow = (query.getFirstRow() == null ? 1 : query.getFirstRow());
- final int maxRows = (query.getMaxRows() == null ? -1 : query.getMaxRows());
-
- // Check for very simple queries with max rows property set (typically
- // preview), see Ticket #187
- previewTable: if (whereItems.isEmpty() && groupByItems.isEmpty() && havingItems.isEmpty()
- && orderByItems.isEmpty() && fromItems.size() == 1) {
-
- final Table table = fromItems.get(0).getTable();
- if (table != null) {
- for (SelectItem item : selectItems) {
- if (item.getFunction() != null || item.getExpression() != null) {
- break previewTable;
- }
- }
-
- DataSet dataSet = materializeTable(table, selectItems, firstRow, maxRows);
- dataSet = MetaModelHelper.getSelection(selectItems, dataSet);
- return dataSet;
- }
- }
-
- // Creates a list for all select items that are needed to execute query
- // (some may only be used as part of a filter, but not shown in result)
- List<SelectItem> workSelectItems = CollectionUtils.concat(true, selectItems, whereSelectItems,
- groupBySelectItems, havingSelectItems, orderBySelectItems);
-
- // Materialize the tables in the from clause
- final DataSet[] fromDataSets = new DataSet[fromItems.size()];
- for (int i = 0; i < fromDataSets.length; i++) {
- FromItem fromItem = fromItems.get(i);
- fromDataSets[i] = materializeFromItem(fromItem, workSelectItems);
- }
-
- // Execute the query using the raw data
- DataSet dataSet = MetaModelHelper.getCarthesianProduct(fromDataSets, whereItems);
-
- // we can now exclude the select items imposed by the WHERE clause (and
- // should, to make the aggregation process faster)
- workSelectItems = CollectionUtils.concat(true, selectItems, groupBySelectItems, havingSelectItems,
- orderBySelectItems);
-
- if (groupByItems.size() > 0) {
- dataSet = MetaModelHelper.getGrouped(workSelectItems, dataSet, groupByItems);
- } else {
- dataSet = MetaModelHelper.getAggregated(workSelectItems, dataSet);
- }
- dataSet = MetaModelHelper.getFiltered(dataSet, havingItems);
-
- if (query.getSelectClause().isDistinct()) {
- dataSet = MetaModelHelper.getSelection(selectItems, dataSet);
- dataSet = MetaModelHelper.getDistinct(dataSet);
- dataSet = MetaModelHelper.getOrdered(dataSet, orderByItems);
- } else {
- dataSet = MetaModelHelper.getOrdered(dataSet, orderByItems);
- dataSet = MetaModelHelper.getSelection(selectItems, dataSet);
- }
-
- if (firstRow > 1) {
- dataSet = new FirstRowDataSet(dataSet, firstRow);
- }
- if (maxRows != -1) {
- dataSet = new MaxRowsDataSet(dataSet, maxRows);
- }
- return dataSet;
- }
-
- /**
- * Executes a simple count query, if possible. This method is provided to
- * allow subclasses to optimize count queries since they are quite common
- * and often a datastore can retrieve the count using some specialized means
- * which is much more performant than counting all records manually.
- *
- * @param table
- * the table on which the count is requested.
- * @param whereItems
- * a (sometimes empty) list of WHERE items.
- * @param functionApproximationAllowed
- * whether approximation is allowed or not.
- * @return the count of the particular table, or null if not available.
- */
- protected Number executeCountQuery(Table table, List<FilterItem> whereItems, boolean functionApproximationAllowed) {
- return null;
- }
-
- protected DataSet materializeFromItem(final FromItem fromItem, final List<SelectItem> selectItems) {
- DataSet dataSet;
- JoinType joinType = fromItem.getJoin();
- if (fromItem.getTable() != null) {
- // We need to materialize a single table
- final Table table = fromItem.getTable();
- final List<SelectItem> selectItemsToMaterialize = new ArrayList<SelectItem>();
-
- for (final SelectItem selectItem : selectItems) {
- final FromItem selectedFromItem = selectItem.getFromItem();
- if (selectedFromItem != null) {
- if (selectedFromItem.equals(fromItem)) {
- selectItemsToMaterialize.add(selectItem.replaceFunction(null));
- }
- } else {
- // the select item does not specify a specific
- // from-item
- final Column selectedColumn = selectItem.getColumn();
- if (selectedColumn != null) {
- // we assume that if the table matches, we will use the
- // column
- if (selectedColumn.getTable() != null && selectedColumn.getTable().equals(table)) {
- selectItemsToMaterialize.add(selectItem.replaceFunction(null));
- }
- }
- }
- }
-
- if (logger.isDebugEnabled()) {
- logger.debug("calling materializeTable(" + table.getName() + "," + selectItemsToMaterialize + ",1,-1");
- }
-
- // Dispatching to the concrete subclass of
- // QueryPostprocessDataContextStrategy
- dataSet = materializeTable(table, selectItemsToMaterialize, 1, -1);
-
- } else if (joinType != null) {
- // We need to (recursively) materialize a joined FromItem
- if (fromItem.getLeftSide() == null || fromItem.getRightSide() == null) {
- throw new IllegalArgumentException("Joined FromItem requires both left and right side: " + fromItem);
- }
- DataSet[] fromItemDataSets = new DataSet[2];
-
- // materialize left side
- List<SelectItem> leftOn = Arrays.asList(fromItem.getLeftOn());
- fromItemDataSets[0] = materializeFromItem(fromItem.getLeftSide(),
- CollectionUtils.concat(true, selectItems, leftOn));
-
- // materialize right side
- List<SelectItem> rightOn = Arrays.asList(fromItem.getRightOn());
- fromItemDataSets[1] = materializeFromItem(fromItem.getRightSide(),
- CollectionUtils.concat(true, selectItems, rightOn));
-
- FilterItem[] onConditions = new FilterItem[leftOn.size()];
- for (int i = 0; i < onConditions.length; i++) {
- FilterItem whereItem = new FilterItem(leftOn.get(i), OperatorType.EQUALS_TO, rightOn.get(i));
- onConditions[i] = whereItem;
- }
- if (joinType == JoinType.INNER) {
- dataSet = MetaModelHelper.getCarthesianProduct(fromItemDataSets, onConditions);
- } else if (joinType == JoinType.LEFT) {
- dataSet = MetaModelHelper.getLeftJoin(fromItemDataSets[0], fromItemDataSets[1], onConditions);
- } else if (joinType == JoinType.RIGHT) {
- dataSet = MetaModelHelper.getRightJoin(fromItemDataSets[0], fromItemDataSets[1], onConditions);
- } else {
- throw new IllegalArgumentException("FromItem type not supported: " + fromItem);
- }
- } else if (fromItem.getSubQuery() != null) {
- // We need to (recursively) materialize a subquery
- dataSet = executeQuery(fromItem.getSubQuery());
- } else {
- throw new IllegalArgumentException("FromItem type not supported: " + fromItem);
- }
- if (dataSet == null) {
- throw new IllegalStateException("FromItem was not succesfully materialized: " + fromItem);
- }
- return dataSet;
- }
-
- protected DataSet materializeTable(final Table table, final List<SelectItem> selectItems, final int firstRow,
- final int maxRows) {
- if (table == null) {
- throw new IllegalArgumentException("Table cannot be null");
- }
-
- if (selectItems == null || selectItems.isEmpty()) {
- // add any column (typically this occurs because of COUNT(*)
- // queries)
- Column[] columns = table.getColumns();
- if (columns.length == 0) {
- logger.warn("Queried table has no columns: {}", table);
- } else {
- selectItems.add(new SelectItem(columns[0]));
- }
- }
-
- if (maxRows == 0) {
- return new EmptyDataSet(selectItems);
- }
-
- final Schema schema = table.getSchema();
- final String schemaName;
- if (schema == null) {
- schemaName = null;
- } else {
- schemaName = schema.getName();
- }
-
- final DataSet dataSet;
- if (INFORMATION_SCHEMA_NAME.equals(schemaName)) {
- final DataSet informationDataSet = materializeInformationSchemaTable(table, selectItems, maxRows);
- if (firstRow > 1) {
- dataSet = new FirstRowDataSet(informationDataSet, firstRow);
- } else {
- dataSet = informationDataSet;
- }
- } else {
- final DataSet tableDataSet = materializeMainSchemaTable(table, selectItems, firstRow, maxRows);
-
- // conversion is done at materialization time, since it enables
- // the refined types to be used also in eg. where clauses.
- dataSet = new ConvertedDataSetInterceptor(_converters).intercept(tableDataSet);
- }
-
- return dataSet;
- }
-
- protected boolean isMainSchemaTable(Table table) {
- Schema schema = table.getSchema();
- if (INFORMATION_SCHEMA_NAME.equals(schema.getName())) {
- return false;
- } else {
- return true;
- }
- }
-
- @Override
- protected final String[] getSchemaNamesInternal() throws MetaModelException {
- final String[] schemaNames = new String[2];
- schemaNames[0] = INFORMATION_SCHEMA_NAME;
- schemaNames[1] = getMainSchemaName();
- return schemaNames;
- }
-
- @Override
- protected String getDefaultSchemaName() throws MetaModelException {
- return getMainSchemaName();
- }
-
- @Override
- protected final Schema getSchemaByNameInternal(final String name) throws MetaModelException {
- final String mainSchemaName = getMainSchemaName();
- if (name == null) {
- if (mainSchemaName == null) {
- return getMainSchema();
- }
- return null;
- }
-
- if (name.equalsIgnoreCase(mainSchemaName)) {
- return getMainSchemaInternal();
- } else if (name.equals(INFORMATION_SCHEMA_NAME)) {
- return getInformationSchema();
- }
-
- logger.warn("Could not find matching schema of name '{}'. Main schema name is: '{}'. Returning null.", name,
- mainSchemaName);
- return null;
- }
-
- private Schema getInformationSchema() {
- // Create schema
- MutableSchema informationSchema = new MutableSchema(INFORMATION_SCHEMA_NAME);
- MutableTable tablesTable = new MutableTable("tables", TableType.TABLE, informationSchema);
- MutableTable columnsTable = new MutableTable("columns", TableType.TABLE, informationSchema);
- MutableTable relationshipsTable = new MutableTable("relationships", TableType.TABLE, informationSchema);
- informationSchema.addTable(tablesTable).addTable(columnsTable).addTable(relationshipsTable);
-
- // Create "tables" table: name, type, num_columns, remarks
- tablesTable.addColumn(new MutableColumn("name", ColumnType.VARCHAR, tablesTable, 0, false));
- tablesTable.addColumn(new MutableColumn("type", ColumnType.VARCHAR, tablesTable, 1, true));
- tablesTable.addColumn(new MutableColumn("num_columns", ColumnType.INTEGER, tablesTable, 2, true));
- tablesTable.addColumn(new MutableColumn("remarks", ColumnType.VARCHAR, tablesTable, 3, true));
-
- // Create "columns" table: name, type, native_type, size, nullable,
- // indexed, table, remarks
- columnsTable.addColumn(new MutableColumn("name", ColumnType.VARCHAR, columnsTable, 0, false));
- columnsTable.addColumn(new MutableColumn("type", ColumnType.VARCHAR, columnsTable, 1, true));
- columnsTable.addColumn(new MutableColumn("native_type", ColumnType.VARCHAR, columnsTable, 2, true));
- columnsTable.addColumn(new MutableColumn("size", ColumnType.INTEGER, columnsTable, 3, true));
- columnsTable.addColumn(new MutableColumn("nullable", ColumnType.BOOLEAN, columnsTable, 4, true));
- columnsTable.addColumn(new MutableColumn("indexed", ColumnType.BOOLEAN, columnsTable, 5, true));
- columnsTable.addColumn(new MutableColumn("table", ColumnType.VARCHAR, columnsTable, 6, false));
- columnsTable.addColumn(new MutableColumn("remarks", ColumnType.VARCHAR, columnsTable, 7, true));
-
- // Create "relationships" table: primary_table, primary_column,
- // foreign_table, foreign_column
- relationshipsTable.addColumn(new MutableColumn("primary_table", ColumnType.VARCHAR, relationshipsTable, 0,
- false));
- relationshipsTable.addColumn(new MutableColumn("primary_column", ColumnType.VARCHAR, relationshipsTable, 1,
- false));
- relationshipsTable.addColumn(new MutableColumn("foreign_table", ColumnType.VARCHAR, relationshipsTable, 2,
- false));
- relationshipsTable.addColumn(new MutableColumn("foreign_column", ColumnType.VARCHAR, relationshipsTable, 3,
- false));
-
- MutableRelationship.createRelationship(tablesTable.getColumnByName("name"),
- columnsTable.getColumnByName("table"));
- MutableRelationship.createRelationship(tablesTable.getColumnByName("name"),
- relationshipsTable.getColumnByName("primary_table"));
- MutableRelationship.createRelationship(tablesTable.getColumnByName("name"),
- relationshipsTable.getColumnByName("foreign_table"));
- MutableRelationship.createRelationship(columnsTable.getColumnByName("name"),
- relationshipsTable.getColumnByName("primary_column"));
- MutableRelationship.createRelationship(columnsTable.getColumnByName("name"),
- relationshipsTable.getColumnByName("foreign_column"));
-
- return informationSchema;
- }
-
- private DataSet materializeInformationSchemaTable(final Table table, final List<SelectItem> selectItems,
- final int maxRows) {
- final String tableName = table.getName();
- final SelectItem[] columnSelectItems = MetaModelHelper.createSelectItems(table.getColumns());
- final SimpleDataSetHeader header = new SimpleDataSetHeader(columnSelectItems);
- final Table[] tables = getMainSchemaInternal().getTables();
- final List<Row> data = new ArrayList<Row>();
- if ("tables".equals(tableName)) {
- // "tables" columns: name, type, num_columns, remarks
- for (Table t : tables) {
- String typeString = null;
- if (t.getType() != null) {
- typeString = t.getType().toString();
- }
- data.add(new DefaultRow(header, new Object[] { t.getName(), typeString, t.getColumnCount(),
- t.getRemarks() }));
- }
- } else if ("columns".equals(tableName)) {
- // "columns" columns: name, type, native_type, size, nullable,
- // indexed, table, remarks
- for (Table t : tables) {
- for (Column c : t.getColumns()) {
- String typeString = null;
- if (t.getType() != null) {
- typeString = c.getType().toString();
- }
- data.add(new DefaultRow(header, new Object[] { c.getName(), typeString, c.getNativeType(),
- c.getColumnSize(), c.isNullable(), c.isIndexed(), t.getName(), c.getRemarks() }));
- }
- }
- } else if ("relationships".equals(tableName)) {
- // "relationships" columns: primary_table, primary_column,
- // foreign_table, foreign_column
- for (Relationship r : getMainSchemaInternal().getRelationships()) {
- Column[] primaryColumns = r.getPrimaryColumns();
- 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];
- data.add(new DefaultRow(header, new Object[] { pTable.getName(), pColumn.getName(),
- fTable.getName(), fColumn.getName() }));
- }
- }
- } else {
- throw new IllegalArgumentException("Cannot materialize non information_schema table: " + table);
- }
-
- DataSet dataSet;
- if (data.isEmpty()) {
- dataSet = new EmptyDataSet(selectItems);
- } else {
- dataSet = new InMemoryDataSet(header, data);
- }
-
- // Handle column subset
- dataSet = MetaModelHelper.getSelection(selectItems, dataSet);
-
- // Handle maxRows
- if (maxRows != -1) {
- dataSet = new MaxRowsDataSet(dataSet, maxRows);
- }
- return dataSet;
- }
-
- protected Schema getMainSchemaInternal() {
- Schema schema = _mainSchema;
- if (schema == null) {
- schema = getMainSchema();
- _mainSchema = schema;
- }
- return schema;
- }
-
- /**
- * Adds a {@link TypeConverter} to this DataContext's query engine (Query
- * Postprocessor) for read operations. Note that this method should NOT be
- * invoked directly by consuming code. Rather use
- * {@link Converters#addTypeConverter(DataContext, Column, TypeConverter)}
- * to ensure conversion on both reads and writes.
- */
- @Override
- public void addConverter(Column column, TypeConverter<?, ?> converter) {
- _converters.put(column, converter);
- }
-
- /**
- * @return the main schema that subclasses of this class produce
- */
- protected abstract Schema getMainSchema() throws MetaModelException;
-
- /**
- * @return the name of the main schema that subclasses of this class produce
- */
- protected abstract String getMainSchemaName() throws MetaModelException;
-
- /**
- * 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)}.
- *
- * @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();
- }
- DataSet dataSet = materializeMainSchemaTable(table, columns, firstRow, maxRows);
-
- dataSet = MetaModelHelper.getSelection(selectItems, dataSet);
-
- return dataSet;
- }
-
- /**
- * 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
- * {@link FirstRowDataSet} if necessary.
- *
- * @param table
- * @param columns
- * @param firstRow
- * @param maxRows
- * @return
- */
- protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int firstRow, int maxRows) {
- final int rowsToMaterialize;
- if (firstRow == 1) {
- rowsToMaterialize = maxRows;
- } else {
- rowsToMaterialize = maxRows + (firstRow - 1);
- }
- DataSet dataSet = materializeMainSchemaTable(table, columns, rowsToMaterialize);
- if (firstRow > 1) {
- dataSet = new FirstRowDataSet(dataSet, firstRow);
- }
- return dataSet;
- }
-
- /**
- * Executes a simple one-table query against a table in the main schema of
- * the subclasses of this class.
- *
- * @param table
- * the table to query
- * @param columns
- * the columns of the table to query
- * @param maxRows
- * the maximum amount of rows needed or -1 if all rows are
- * wanted.
- * @return a dataset with the raw table/column content.
- */
- protected abstract DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/QueryPostprocessDelegate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/QueryPostprocessDelegate.java b/core/src/main/java/org/eobjects/metamodel/QueryPostprocessDelegate.java
deleted file mode 100644
index a69163d..0000000
--- a/core/src/main/java/org/eobjects/metamodel/QueryPostprocessDelegate.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * 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;
-
-import org.eobjects.metamodel.schema.Schema;
-
-/**
- * A simple subclass of {@link QueryPostprocessDataContext} which provides less
- * implementation fuzz when custom querying features (like composite
- * datacontexts or type conversion) is needed.
- *
- * @author Kasper Sørensen
- * @author Ankit Kumar
- */
-public abstract class QueryPostprocessDelegate extends
- QueryPostprocessDataContext {
-
- @Override
- protected String getMainSchemaName() throws MetaModelException {
- throw new UnsupportedOperationException(
- "QueryPostprocessDelegate cannot perform schema exploration");
- }
-
- @Override
- protected Schema getMainSchema() throws MetaModelException {
- throw new UnsupportedOperationException(
- "QueryPostprocessDelegate cannot perform schema exploration");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/SchemaNameComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/SchemaNameComparator.java b/core/src/main/java/org/eobjects/metamodel/SchemaNameComparator.java
deleted file mode 100644
index 14a2f82..0000000
--- a/core/src/main/java/org/eobjects/metamodel/SchemaNameComparator.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * 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;
-
-import java.util.Comparator;
-
-/**
- * Comparator for comparing schema names.
- *
- * @author Kasper Sørensen
- */
-class SchemaNameComparator implements Comparator<String> {
-
- private static Comparator<? super String> _instance = new SchemaNameComparator();
-
- public static Comparator<? super String> getInstance() {
- return _instance;
- }
-
- private SchemaNameComparator() {
- }
-
- public int compare(String o1, String o2) {
- if (o1 == null && o2 == null) {
- return 0;
- }
- if (o1 == null) {
- return -1;
- }
- if (o2 == null) {
- return 1;
- }
- if (MetaModelHelper.isInformationSchema(o1)) {
- return -1;
- }
- if (MetaModelHelper.isInformationSchema(o2)) {
- return 1;
- }
- return o1.compareTo(o2);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/UpdateCallback.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/UpdateCallback.java b/core/src/main/java/org/eobjects/metamodel/UpdateCallback.java
deleted file mode 100644
index 3f23173..0000000
--- a/core/src/main/java/org/eobjects/metamodel/UpdateCallback.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * 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;
-
-import org.eobjects.metamodel.create.TableCreatable;
-import org.eobjects.metamodel.delete.RowDeletable;
-import org.eobjects.metamodel.drop.TableDroppable;
-import org.eobjects.metamodel.insert.RowInsertable;
-import org.eobjects.metamodel.update.RowUpdateable;
-
-/**
- * An {@link UpdateCallback} is used by an {@link UpdateScript} to perform
- * updates on a {@link DataContext}. Multiple updates (eg. insertion of several
- * rows or creation of multiple tables) can (and should) be performed with a
- * single {@link UpdateCallback}. This pattern guarantees that connections
- * and/or file handles are handled correctly, surrounding the
- * {@link UpdateScript} that is being executed.
- *
- * @author Kasper Sørensen
- */
-public interface UpdateCallback extends TableCreatable, TableDroppable, RowInsertable, RowUpdateable, RowDeletable {
-
- /**
- * Gets the DataContext on which the update script is being executed.
- *
- * @return the DataContext on which the update script is being executed.
- */
- public DataContext getDataContext();
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/UpdateScript.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/UpdateScript.java b/core/src/main/java/org/eobjects/metamodel/UpdateScript.java
deleted file mode 100644
index f8dae35..0000000
--- a/core/src/main/java/org/eobjects/metamodel/UpdateScript.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * 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;
-
-import org.eobjects.metamodel.util.Action;
-
-/**
- * Represents any updating operation or update script that can be executed on a
- * {@link UpdateableDataContext}. Users of MetaModel should implement their own
- * {@link UpdateScript} and submit them to the
- * {@link UpdateableDataContext#executeUpdate(UpdateScript)} method for
- * execution.
- *
- * @author Kasper Sørensen
- */
-public interface UpdateScript extends Action<UpdateCallback> {
-
- /**
- * Invoked by MetaModel when the update script should be run. User should
- * implement this method and invoke update operations on the
- * {@link UpdateCallback}.
- */
- @Override
- public void run(UpdateCallback callback);
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/UpdateableDataContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/UpdateableDataContext.java b/core/src/main/java/org/eobjects/metamodel/UpdateableDataContext.java
deleted file mode 100644
index 302a70a..0000000
--- a/core/src/main/java/org/eobjects/metamodel/UpdateableDataContext.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * 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;
-
-/**
- * Represents a {@link DataContext} that supports updating write-operations.
- *
- * @author Kasper Sørensen
- */
-public interface UpdateableDataContext extends DataContext {
-
- /**
- * Submits an {@link UpdateScript} for execution on the {@link DataContext}.
- *
- * Since implementations of the {@link DataContext} vary quite a lot, there
- * is no golden rule as to how an update script will be executed. But the
- * implementors should strive towards handling an {@link UpdateScript} as a
- * single transactional change to the data store.
- *
- * @param update
- * the update script to execute
- */
- public void executeUpdate(UpdateScript update);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/convert/ColumnTypeDetector.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/convert/ColumnTypeDetector.java b/core/src/main/java/org/eobjects/metamodel/convert/ColumnTypeDetector.java
deleted file mode 100644
index 4b88c5a..0000000
--- a/core/src/main/java/org/eobjects/metamodel/convert/ColumnTypeDetector.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- * 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.convert;
-
-import org.eobjects.metamodel.util.BooleanComparator;
-import org.eobjects.metamodel.util.TimeComparator;
-
-/**
- * A class capable of detecting/narrowing a string column type to something more
- * specific. Either: Boolean, Integer, Double or Date.
- */
-final class ColumnTypeDetector {
-
- private boolean _booleanPossible = true;
- private boolean _integerPossible = true;
- private boolean _doublePossible = true;
- private boolean _datePossible = true;
-
- public void registerValue(String stringValue) {
- if (stringValue == null || stringValue.length() == 0) {
- return;
- }
- if (_booleanPossible) {
- try {
- BooleanComparator.parseBoolean(stringValue);
- } catch (IllegalArgumentException e) {
- _booleanPossible = false;
- }
- }
- if (_doublePossible) {
- try {
- Double.parseDouble(stringValue);
- } catch (NumberFormatException e) {
- _doublePossible = false;
- _integerPossible = false;
- }
- // If integer is possible, double will always also be possible,
- // but not nescesarily the other way around
- if (_integerPossible) {
- try {
- Integer.parseInt(stringValue);
- } catch (NumberFormatException e) {
- _integerPossible = false;
- }
- }
- }
- if (_datePossible) {
- if (TimeComparator.toDate(stringValue) == null) {
- _datePossible = false;
- }
- }
- }
-
- public TypeConverter<?, ?> createConverter() {
- if (_booleanPossible) {
- return new StringToBooleanConverter();
- } else if (_integerPossible) {
- return new StringToIntegerConverter();
- } else if (_doublePossible) {
- return new StringToDoubleConverter();
- } else if (_datePossible) {
- return new StringToDateConverter();
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/convert/ConvertedDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/convert/ConvertedDataSet.java b/core/src/main/java/org/eobjects/metamodel/convert/ConvertedDataSet.java
deleted file mode 100644
index 8e35be8..0000000
--- a/core/src/main/java/org/eobjects/metamodel/convert/ConvertedDataSet.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * 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.convert;
-
-import org.eobjects.metamodel.data.AbstractDataSet;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.Row;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A {@link DataSet} wrapper/decorator which converts values using
- * {@link TypeConverter}s before returning them to the user.
- */
-final class ConvertedDataSet extends AbstractDataSet {
-
- private static final Logger logger = LoggerFactory.getLogger(ConvertedDataSet.class);
-
- private final DataSet _dataSet;
- private final TypeConverter<?, ?>[] _converters;
-
- public ConvertedDataSet(DataSet dataSet, TypeConverter<?, ?>[] converters) {
- super(dataSet.getSelectItems());
- _dataSet = dataSet;
- _converters = converters;
- }
-
- @Override
- public boolean next() {
- return _dataSet.next();
- }
-
- @Override
- public Row getRow() {
- Row sourceRow = _dataSet.getRow();
- Object[] values = new Object[_converters.length];
- for (int i = 0; i < values.length; i++) {
- Object value = sourceRow.getValue(i);
-
- @SuppressWarnings("unchecked")
- TypeConverter<Object, ?> converter = (TypeConverter<Object, ?>) _converters[i];
-
- if (converter != null) {
- Object virtualValue = converter.toVirtualValue(value);
- logger.debug("Converted physical value {} to {}", value, virtualValue);
- value = virtualValue;
- }
- values[i] = value;
- }
- return new DefaultRow(getHeader(), values);
- }
-
- @Override
- public void close() {
- _dataSet.close();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/convert/ConvertedDataSetInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/convert/ConvertedDataSetInterceptor.java b/core/src/main/java/org/eobjects/metamodel/convert/ConvertedDataSetInterceptor.java
deleted file mode 100644
index 545ffe6..0000000
--- a/core/src/main/java/org/eobjects/metamodel/convert/ConvertedDataSetInterceptor.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- * 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.convert;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.intercept.DataSetInterceptor;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-
-/**
- * A {@link DataSetInterceptor} used for intercepting values in {@link DataSet}s
- * that need to be converted, according to a set of {@link TypeConverter}s.
- *
- * @see TypeConverter
- * @see Converters
- */
-public class ConvertedDataSetInterceptor implements DataSetInterceptor, HasReadTypeConverters {
-
- private Map<Column, TypeConverter<?, ?>> _converters;
-
- public ConvertedDataSetInterceptor() {
- this(new HashMap<Column, TypeConverter<?, ?>>());
- }
-
- public ConvertedDataSetInterceptor(
- Map<Column, TypeConverter<?, ?>> converters) {
- _converters = converters;
- }
-
- @Override
- public void addConverter(Column column, TypeConverter<?, ?> converter) {
- if (converter == null) {
- _converters.remove(column);
- } else {
- _converters.put(column, converter);
- }
- }
-
- protected Map<Column, TypeConverter<?, ?>> getConverters(DataSet dataSet) {
- return _converters;
- }
-
- @Override
- public final DataSet intercept(DataSet dataSet) {
- Map<Column, TypeConverter<?, ?>> converters = getConverters(dataSet);
- if (converters.isEmpty()) {
- return dataSet;
- }
-
- 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];
- Column column = selectItem.getColumn();
- if (column != null && selectItem.getFunction() == null) {
- TypeConverter<?, ?> converter = converters.get(column);
- if (converter != null) {
- hasConverter = true;
- converterArray[i] = converter;
- }
- }
- }
-
- if (!hasConverter) {
- return dataSet;
- }
-
- return new ConvertedDataSet(dataSet, converterArray);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/convert/ConvertedRowInsertionInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/convert/ConvertedRowInsertionInterceptor.java b/core/src/main/java/org/eobjects/metamodel/convert/ConvertedRowInsertionInterceptor.java
deleted file mode 100644
index 21c2506..0000000
--- a/core/src/main/java/org/eobjects/metamodel/convert/ConvertedRowInsertionInterceptor.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- * 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.convert;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.intercept.RowInsertionInterceptor;
-import org.eobjects.metamodel.schema.Column;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A {@link RowInsertionInterceptor} used for intercepting values in
- * {@link RowInsertionBuilder}s that need to be converted, according to a set of
- * {@link TypeConverter}s.
- *
- * @see TypeConverter
- * @see Converters
- */
-public class ConvertedRowInsertionInterceptor implements RowInsertionInterceptor {
-
- private static final Logger logger = LoggerFactory.getLogger(ConvertedRowInsertionInterceptor.class);
-
- private final Map<Column, TypeConverter<?, ?>> _converters;
-
- public ConvertedRowInsertionInterceptor() {
- this(new HashMap<Column, TypeConverter<?, ?>>());
- }
-
- public ConvertedRowInsertionInterceptor(Map<Column, TypeConverter<?, ?>> converters) {
- _converters = converters;
- }
-
- public void addConverter(Column column, TypeConverter<?, ?> converter) {
- if (converter == null) {
- _converters.remove(column);
- } else {
- _converters.put(column, converter);
- }
- }
-
- @Override
- public RowInsertionBuilder intercept(RowInsertionBuilder insert) {
- if (_converters.isEmpty()) {
- return insert;
- }
-
- logger.debug("Insert statement before conversion: {}", insert);
-
- insert = Converters.convertRow(insert, _converters);
-
- logger.debug("Insert statement after conversion: {}", insert);
-
- return insert;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/convert/ConvertedRowUpdationInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/convert/ConvertedRowUpdationInterceptor.java b/core/src/main/java/org/eobjects/metamodel/convert/ConvertedRowUpdationInterceptor.java
deleted file mode 100644
index 25c1756..0000000
--- a/core/src/main/java/org/eobjects/metamodel/convert/ConvertedRowUpdationInterceptor.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * 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.convert;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eobjects.metamodel.intercept.RowUpdationInterceptor;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class ConvertedRowUpdationInterceptor implements RowUpdationInterceptor {
-
- private static final Logger logger = LoggerFactory.getLogger(ConvertedRowUpdationInterceptor.class);
-
- private final Map<Column, TypeConverter<?, ?>> _converters;
-
- public ConvertedRowUpdationInterceptor() {
- this(new HashMap<Column, TypeConverter<?, ?>>());
- }
-
- public ConvertedRowUpdationInterceptor(Map<Column, TypeConverter<?, ?>> converters) {
- _converters = converters;
- }
-
- public void addConverter(Column column, TypeConverter<?, ?> converter) {
- if (converter == null) {
- _converters.remove(column);
- } else {
- _converters.put(column, converter);
- }
- }
-
- @Override
- public RowUpdationBuilder intercept(RowUpdationBuilder update) {
- if (_converters.isEmpty()) {
- return update;
- }
-
- logger.debug("Update statement after conversion: {}", update);
-
- update = Converters.convertRow(update, _converters);
-
- logger.debug("Update statement after conversion: {}", update);
-
- return update;
- }
-
-}
[47/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/data/RowBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/RowBuilder.java b/core/src/main/java/org/apache/metamodel/data/RowBuilder.java
new file mode 100644
index 0000000..0602ec5
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/RowBuilder.java
@@ -0,0 +1,119 @@
+/**
+ * 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 org.eobjects.metamodel.insert.RowInsertionBuilder;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.update.RowUpdationBuilder;
+
+/**
+ * Abstract interface for objects that build rows, either for eg. insert or
+ * update purposes.
+ *
+ * @see RowInsertionBuilder
+ * @see RowUpdationBuilder
+ *
+ * @param <RB>
+ * the RowBuilder subtype, used for cascading return values
+ */
+public interface RowBuilder<RB extends RowBuilder<?>> {
+
+ /**
+ * Gets the table that this row builder pertains to.
+ *
+ * @return the table that this row builder pertains to.
+ */
+ public Table getTable();
+
+ /**
+ * Sets the value of a column, by column index
+ *
+ * @param columnIndex
+ * @param value
+ * @return
+ */
+ public RB value(int columnIndex, Object value);
+
+ /**
+ * Sets the value of a column, by column index
+ *
+ * @param columnIndex
+ * @param value
+ * @param style
+ * @return
+ */
+ public RB value(int columnIndex, Object value, Style style);
+
+ /**
+ * Sets the value of a column
+ *
+ * @param column
+ * @param value
+ * @return
+ */
+ public RB value(Column column, Object value);
+
+ /**
+ * Sets the value of a column
+ *
+ * @param column
+ * @param value
+ * @param style
+ * @return
+ */
+ public RB value(Column column, Object value, Style style);
+
+ /**
+ * Sets the value of a column, by column name
+ *
+ * @param columnName
+ * @param value
+ * @return
+ */
+ public RB value(String columnName, Object value);
+
+ /**
+ * Sets the value and the style of this value of a column, by column name
+ *
+ * @param columnName
+ * @param value
+ * @param style
+ * @return
+ */
+ public RB value(String columnName, Object value, Style style);
+
+ /**
+ * Gets the built record represented as a {@link Row} object.
+ *
+ * @return a {@link Row} object as it will appear if committed and queried.
+ */
+ public Row toRow();
+
+ /**
+ * Determines if a column's value has been explicitly specified or not. This
+ * can be used to tell explicit NULL values apart from just unspecified
+ * values in a statement.
+ *
+ * @param column
+ * the column to check
+ * @return true if the column's value has been set, or false if not
+ */
+ public boolean isSet(Column column);
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/data/RowPublisher.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/RowPublisher.java b/core/src/main/java/org/apache/metamodel/data/RowPublisher.java
new file mode 100644
index 0000000..fe7678b
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/RowPublisher.java
@@ -0,0 +1,70 @@
+/**
+ * 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;
+
+/**
+ * An object on which a push-style data reader can publish records to a
+ * {@link RowPublisherDataSet}. The {@link RowPublisher} acts as a buffer
+ * between the publishing and consuming part of a dataset scenario. It will
+ * manage a queue of rows and will block calls if the queue is not being
+ * read/emptied as fast as it is being filled.
+ *
+ * @author Kasper Sørensen
+ */
+public interface RowPublisher {
+
+ /**
+ * Publishes a row
+ *
+ * @param row
+ * the {@link Row} to publish.
+ * @return a boolean indicating whether or not the consumer is still
+ * interested in more rows.
+ */
+ public boolean publish(Row row);
+
+ /**
+ * Publishes a row, represented by an array of values.
+ *
+ * @param values
+ * the objects to convert to a row.
+ * @return a boolean indicating whether or not the consumer is still
+ * interested in more rows.
+ */
+ public boolean publish(Object[] values);
+
+ /**
+ * Publishes a row, represented by an array of values and an array of
+ * styles.
+ *
+ * @param values
+ * the objects to convert to a row.
+ * @param styles
+ * the styles that correspond to the values.
+ * @return a boolean indicating whether or not the consumer is still
+ * interested in more rows.
+ */
+ public boolean publish(Object[] values, Style[] styles);
+
+ /**
+ * Invoked to indicate to the consumer that no more rows will be published.
+ */
+ public void finished();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/data/RowPublisherDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/RowPublisherDataSet.java b/core/src/main/java/org/apache/metamodel/data/RowPublisherDataSet.java
new file mode 100644
index 0000000..addbeae
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/RowPublisherDataSet.java
@@ -0,0 +1,111 @@
+/**
+ * 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 org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.util.Action;
+import org.eobjects.metamodel.util.SharedExecutorService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract {@link DataSet} implementation for use in scenarios where a
+ * pull-oriented style of reading data is not supported. This implementation
+ * instead allows a publshing action to publish rows to the dataset in a
+ * blocking manner, and thereby to adapt without having to load all rows into
+ * memory.
+ *
+ * @author Kasper Sørensen
+ */
+public final class RowPublisherDataSet extends AbstractDataSet {
+
+ private static final Logger logger = LoggerFactory
+ .getLogger(RowPublisherDataSet.class);
+
+ private final int _maxRows;
+ private final Action<RowPublisher> _publishAction;
+ private RowPublisherImpl _rowPublisher;
+ private boolean _closed;
+
+ public RowPublisherDataSet(SelectItem[] selectItems, int maxRows,
+ Action<RowPublisher> publishAction) {
+ super(selectItems);
+ _maxRows = maxRows;
+ _publishAction = publishAction;
+ _closed = false;
+ }
+
+ public int getMaxRows() {
+ return _maxRows;
+ }
+
+ @Override
+ public void close() {
+ super.close();
+ _closed = true;
+ _rowPublisher.finished();
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ if (!_closed) {
+ logger.warn(
+ "finalize() invoked, but DataSet is not closed. Invoking close() on {}",
+ this);
+ close();
+ }
+ }
+
+ @Override
+ public boolean next() {
+ if (_rowPublisher == null) {
+ // first time, create the publisher
+ _rowPublisher = new RowPublisherImpl(this);
+ logger.info("Starting separate thread for publishing action: {}",
+ _publishAction);
+ Runnable runnable = new Runnable() {
+ public void run() {
+ boolean successful = false;
+ try {
+ _publishAction.run(_rowPublisher);
+ logger.debug("Publshing action finished!");
+ successful = true;
+ } catch (Exception e) {
+ _rowPublisher.failed(e);
+ }
+ if (successful) {
+ _rowPublisher.finished();
+ }
+ };
+ };
+ SharedExecutorService.get().submit(runnable);
+ }
+ return _rowPublisher.next();
+ }
+
+ @Override
+ public Row getRow() {
+ if (_rowPublisher == null) {
+ return null;
+ }
+ return _rowPublisher.getRow();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/data/RowPublisherImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/RowPublisherImpl.java b/core/src/main/java/org/apache/metamodel/data/RowPublisherImpl.java
new file mode 100644
index 0000000..6fe2a0d
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/RowPublisherImpl.java
@@ -0,0 +1,126 @@
+/**
+ * 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.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.eobjects.metamodel.MetaModelException;
+
+/**
+ * Row publisher implementation used by {@link RowPublisherDataSet}.
+ *
+ * @author Kasper Sørensen
+ */
+class RowPublisherImpl implements RowPublisher {
+
+ public static final int BUFFER_SIZE = 20;
+
+ private final RowPublisherDataSet _dataSet;
+ private final BlockingQueue<Row> _queue;
+ private final AtomicBoolean _finished;
+ private final AtomicInteger _rowCount;
+ private volatile Row _currentRow;
+ private volatile Exception _error;
+
+ public RowPublisherImpl(RowPublisherDataSet dataSet) {
+ _dataSet = dataSet;
+ _queue = new ArrayBlockingQueue<Row>(BUFFER_SIZE);
+ _finished = new AtomicBoolean(false);
+ _rowCount = new AtomicInteger();
+ }
+
+ @Override
+ public boolean publish(Row row) {
+ if (_finished.get()) {
+ return false;
+ }
+ while (!offer(row)) {
+ if (_finished.get()) {
+ return false;
+ }
+ // wait one more cycle
+ }
+ int rowCount = _rowCount.incrementAndGet();
+ if (_dataSet.getMaxRows() > 0 && rowCount >= _dataSet.getMaxRows()) {
+ finished();
+ return false;
+ }
+ return true;
+ }
+
+ private boolean offer(Row row) {
+ try {
+ return _queue.offer(row, 1000, TimeUnit.MICROSECONDS);
+ } catch (InterruptedException e) {
+ // do nothing
+ return false;
+ }
+ }
+
+ @Override
+ public boolean publish(Object[] values) {
+ Row row = new DefaultRow(_dataSet.getHeader(), values);
+ return publish(row);
+ }
+
+ @Override
+ public boolean publish(Object[] values, Style[] styles) {
+ Row row = new DefaultRow(_dataSet.getHeader(), values, styles);
+ return publish(row);
+ }
+
+ @Override
+ public void finished() {
+ _finished.set(true);
+ }
+
+ public boolean next() {
+ if (_queue.isEmpty() && _finished.get()) {
+ return false;
+ }
+ try {
+ _currentRow = _queue.poll(1000, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) {
+ // do nothing
+ }
+ if (_currentRow != null) {
+ return true;
+ }
+ if (_error != null) {
+ if (_error instanceof RuntimeException) {
+ throw (RuntimeException) _error;
+ }
+ throw new MetaModelException(_error);
+ }
+ // "busy" (1 second) wait
+ return next();
+ }
+
+ public Row getRow() {
+ return _currentRow;
+ }
+
+ public void failed(Exception error) {
+ _error = error;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/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
new file mode 100644
index 0000000..1e7e461
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/SimpleDataSetHeader.java
@@ -0,0 +1,132 @@
+/**
+ * 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.MetaModelHelper;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+
+/**
+ * Simple implementation of {@link DataSetHeader} which does no magic to improve
+ * performance.
+ *
+ * Note that except for datasets with very few records, the
+ * {@link CachingDataSetHeader} is preferred.
+ */
+public class SimpleDataSetHeader implements DataSetHeader {
+
+ private static final long serialVersionUID = 1L;
+
+ private final List<SelectItem> _items;
+
+ public SimpleDataSetHeader(List<SelectItem> items) {
+ _items = items;
+ }
+
+ public SimpleDataSetHeader(SelectItem[] selectItems) {
+ this(Arrays.asList(selectItems));
+ }
+
+ public SimpleDataSetHeader(Column[] columns) {
+ this(MetaModelHelper.createSelectItems(columns));
+ }
+
+ @Override
+ public final SelectItem[] getSelectItems() {
+ return _items.toArray(new SelectItem[_items.size()]);
+ }
+
+ @Override
+ public final int size() {
+ return _items.size();
+ }
+
+ @Override
+ public SelectItem getSelectItem(int index) {
+ return _items.get(index);
+ }
+
+ @Override
+ public int indexOf(Column column) {
+ if (column == null) {
+ return -1;
+ }
+ return indexOf(new SelectItem(column));
+ }
+
+ @Override
+ public int indexOf(SelectItem item) {
+ if (item == null) {
+ return -1;
+ }
+ int i = 0;
+ for (SelectItem selectItem : _items) {
+ if (item == selectItem) {
+ return i;
+ }
+ i++;
+ }
+
+ i = 0;
+ for (SelectItem selectItem : _items) {
+ if (item.equalsIgnoreAlias(selectItem, true)) {
+ return i;
+ }
+ i++;
+ }
+
+ i = 0;
+ for (SelectItem selectItem : _items) {
+ if (item.equalsIgnoreAlias(selectItem)) {
+ return i;
+ }
+ i++;
+ }
+
+ return -1;
+ }
+
+ @Override
+ public final int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((_items == null) ? 0 : _items.hashCode());
+ 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;
+ SimpleDataSetHeader other = (SimpleDataSetHeader) obj;
+ if (_items == null) {
+ if (other._items != null)
+ return false;
+ } else if (!_items.equals(other._items))
+ return false;
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/data/Style.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/Style.java b/core/src/main/java/org/apache/metamodel/data/Style.java
new file mode 100644
index 0000000..f8ee46f
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/Style.java
@@ -0,0 +1,156 @@
+/**
+ * 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;
+
+/**
+ * A {@link Style} represents the visual presentation ('styling') attributes of
+ * a value in a {@link Row}. Styling can be used to highlight special values and
+ * format the cells of eg. a spreadsheet.
+ *
+ * Most datastores don't support styling, but some do. Those who do not support
+ * it will just omit it.
+ *
+ * Creation of {@link Style} objects is handled by the {@link StyleBuilder}
+ * class.
+ *
+ * @author Kasper Sørensen
+ */
+public interface Style extends Serializable {
+
+ /**
+ * A style object used for values without styling, "unstyled" values or
+ * "neutrally styled" values.
+ */
+ public static final Style NO_STYLE = new StyleImpl();
+
+ /**
+ * Represents the text alignment of a value.
+ *
+ * @author Kasper Sørensen
+ */
+ public static enum TextAlignment {
+ LEFT, RIGHT, CENTER, JUSTIFY
+ }
+
+ /**
+ * Represents a color used for value highlighting.
+ *
+ * Creation of {@link Color} objects is handled by the static
+ * {@link StyleBuilder}.createColor(...) methods.
+ *
+ * @author Kasper Sørensen
+ */
+ public static interface Color extends Serializable {
+
+ public short getRed();
+
+ public short getGreen();
+
+ public short getBlue();
+ }
+
+ /**
+ * Represents a unit of sizing elements (eg. fonts) in a {@link Style}.
+ *
+ * @author Kasper Sørensen
+ */
+ public static enum SizeUnit {
+ /**
+ * Point unit
+ */
+ PT,
+
+ /**
+ * Pixel unit
+ */
+ PX,
+
+ /**
+ * Percent unit
+ */
+ PERCENT
+ }
+
+ /**
+ * Determines whether or not the value is written in bold text.
+ *
+ * @return true if text is bold
+ */
+ public boolean isBold();
+
+ /**
+ * Determines whether or not the value is written in italic text.
+ *
+ * @return true if text is italic
+ */
+ public boolean isItalic();
+
+ /**
+ * Determines whether or not the value is written with an underline
+ *
+ * @return true if text is underlined
+ */
+ public boolean isUnderline();
+
+ /**
+ * Gets the font size, or null if font size is unspecified.
+ *
+ * @see SizeUnit
+ *
+ * @return an Integer, or null
+ */
+ public Integer getFontSize();
+
+ /**
+ * Gets the unit of the font size.
+ *
+ * @return an enum representing the font size unit used.
+ */
+ public SizeUnit getFontSizeUnit();
+
+ /**
+ * Gets the text alignment, or null if text alignment is unspecified.
+ *
+ * @return a TextAlignment value, or null
+ */
+ public TextAlignment getAlignment();
+
+ /**
+ * Gets the foreground (text) color, or null if the color is unspecified.
+ *
+ * @return a Color object representing the foreground color
+ */
+ public Color getForegroundColor();
+
+ /**
+ * Gets the background color, or null if the color is unspecified.
+ *
+ * @return a Color object representing the background color
+ */
+ public Color getBackgroundColor();
+
+ /**
+ * Creates a Cascading Style Sheets (CSS) representation of this style.
+ *
+ * @return a CSS string
+ */
+ public String toCSS();
+}
\ 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/StyleBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/StyleBuilder.java b/core/src/main/java/org/apache/metamodel/data/StyleBuilder.java
new file mode 100644
index 0000000..ac4c6c7
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/StyleBuilder.java
@@ -0,0 +1,355 @@
+/**
+ * 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.Map;
+import java.util.WeakHashMap;
+
+import org.eobjects.metamodel.data.Style.Color;
+import org.eobjects.metamodel.data.Style.SizeUnit;
+import org.eobjects.metamodel.data.Style.TextAlignment;
+import org.eobjects.metamodel.util.EqualsBuilder;
+
+/**
+ * Builder class for {@link Style} and related objects, like {@link Color}.
+ *
+ * @author Kasper Sørensen
+ */
+public final class StyleBuilder {
+
+ private static final Map<String, Color> _colorCache = new WeakHashMap<String, Color>();
+
+ private boolean _bold;
+ private boolean _italic;
+ private boolean _underline;
+ private Integer _fontSize;
+ private TextAlignment _alignment;
+ private Color _backgroundColor;
+ private Color _foregroundColor;
+ private SizeUnit _fontSizeUnit;
+
+ private final Color _defaultForegroundColor;
+ private final Color _defaultBackgroundColor;
+
+ /**
+ * Constructs a new {@link StyleBuilder} with the default foreground and
+ * background colors.
+ */
+ public StyleBuilder() {
+ this(createColor((short) 0, (short) 0, (short) 0), createColor(
+ (short) 255, (short) 255, (short) 255));
+ }
+
+ /**
+ * Constructs a new {@link StyleBuilder} with a specified default foreground
+ * and background colors. These colors will be disregarded, if posted to the
+ * foreground and background methods.
+ *
+ * @param defaultForegroundColor
+ * @param defaultBackgroundColor
+ */
+ public StyleBuilder(Color defaultForegroundColor,
+ Color defaultBackgroundColor) {
+ _defaultForegroundColor = defaultForegroundColor;
+ _defaultBackgroundColor = defaultBackgroundColor;
+ }
+
+ /**
+ * Resets the state of the built style, which will conceptually match it
+ * with {@link Style#NO_STYLE}.
+ */
+ public void reset() {
+ _bold = false;
+ _italic = false;
+ _underline = false;
+ _fontSize = null;
+ _alignment = null;
+ _backgroundColor = null;
+ _foregroundColor = null;
+ _fontSizeUnit = null;
+ }
+
+ /**
+ * Creates a {@link Style} object based on the build characteristics.
+ *
+ * @return a {@link Style} object based on the build characteristics.
+ */
+ public Style create() {
+ StyleImpl style = new StyleImpl(_bold, _italic, _underline, _fontSize,
+ _fontSizeUnit, _alignment, _backgroundColor, _foregroundColor);
+ if (Style.NO_STYLE.equals(style)) {
+ return Style.NO_STYLE;
+ }
+ return style;
+ }
+
+ /**
+ * Sets the font weight to bold
+ *
+ * @return the {@link StyleBuilder} self (for cascading method calls)
+ */
+ public StyleBuilder bold() {
+ _bold = true;
+ return this;
+ }
+
+ /**
+ * Sets the font style to italic
+ *
+ * @return the {@link StyleBuilder} self (for cascading method calls)
+ */
+ public StyleBuilder italic() {
+ _italic = true;
+ return this;
+ }
+
+ /**
+ * Sets the text decoration to underlined
+ *
+ * @return the {@link StyleBuilder} self (for cascading method calls)
+ */
+ public StyleBuilder underline() {
+ _underline = true;
+ return this;
+ }
+
+ /**
+ * Creates a Color based on a 6-letter RGB hex color code string, eg.
+ * "000000" for black and "FFFFFF" for white.
+ *
+ * @param rgbColorCode
+ * a 6-letter RGB hex color code string
+ * @return a color representing this color code
+ */
+ public static Color createColor(String rgbColorCode) {
+ assert rgbColorCode.length() == 6;
+ String redParth = rgbColorCode.substring(0, 2);
+ String greenParth = rgbColorCode.substring(2, 4);
+ String blueParth = rgbColorCode.substring(4, 6);
+ return createColor(Integer.parseInt(redParth, 16),
+ Integer.parseInt(greenParth, 16),
+ Integer.parseInt(blueParth, 16));
+ }
+
+ /**
+ * Creates a color based on 3 RGB components, represented as ints
+ *
+ * @param r
+ * @param g
+ * @param b
+ * @return a color representing the RGB code
+ */
+ public static Color createColor(int r, int g, int b) {
+ return createColor(toRgbComponent(r), toRgbComponent(g),
+ toRgbComponent(b));
+ }
+
+ /**
+ * Creates a color based on 3 RGB components, represented as shorts
+ *
+ * @param r
+ * @param g
+ * @param b
+ * @return a color representing the RGB code
+ */
+ public static Color createColor(short r, short g, short b) {
+ String cacheId = r + "," + g + "," + b;
+ Color color = _colorCache.get(cacheId);
+ if (color == null) {
+ color = new ColorImpl(r, g, b);
+ _colorCache.put(cacheId, color);
+ }
+ return color;
+ }
+
+ private static short toRgbComponent(int r) {
+ if (r < 0) {
+ // if eg. a byte was passed as a RGB component
+ r = (256 + r);
+ }
+ if (r > 255) {
+ throw new IllegalArgumentException(
+ "RGB component cannot be higher than 255");
+ }
+ return (short) r;
+ }
+
+ /**
+ * Sets the foreground (text) color of the style
+ *
+ * @param rgbColorCode
+ * a 6-letter hex RGB color code, such as FF0000 (red).
+ * @return the {@link StyleBuilder} self (for cascading method calls)
+ */
+ public StyleBuilder foreground(String rgbColorCode) {
+ return foreground(createColor(rgbColorCode));
+ }
+
+ /**
+ * Sets the foreground (text) color of the style
+ *
+ * @param rgb
+ * a triplet array of shorts
+ * @return the {@link StyleBuilder} self (for cascading method calls)
+ */
+ public StyleBuilder foreground(short[] rgb) {
+ assert rgb.length == 3;
+ return foreground(createColor(rgb[0], rgb[1], rgb[2]));
+ }
+
+ /**
+ * Sets the foreground (text) color of the style
+ *
+ * @param r
+ * red amount (0-255)
+ * @param g
+ * green amount (0-255)
+ * @param b
+ * blue amount (0-255)
+ * @return the {@link StyleBuilder} self (for cascading method calls)
+ */
+ public StyleBuilder foreground(int r, int g, int b) {
+ return foreground(createColor(r, g, b));
+ }
+
+ /**
+ * Sets the foreground (text) color of the style
+ *
+ * @param color
+ * the color to use
+ * @return the {@link StyleBuilder} self (for cascading method calls)
+ */
+ public StyleBuilder foreground(Color color) {
+ if (EqualsBuilder.equals(_defaultForegroundColor, color)) {
+ _foregroundColor = null;
+ } else {
+ _foregroundColor = color;
+ }
+ return this;
+ }
+
+ /**
+ * Sets the background (fill) color of the style
+ *
+ * @param rgbColorCode
+ * a 6-letter hex RGB color code, such as FF0000 (red).
+ * @return the {@link StyleBuilder} self (for cascading method calls)
+ */
+ public StyleBuilder background(String rgbColorCode) {
+ return background(createColor(rgbColorCode));
+ }
+
+ /**
+ * Sets the background (fill) color of the style
+ *
+ * @param rgb
+ * a triplet array of shorts
+ * @return the {@link StyleBuilder} self (for cascading method calls)
+ */
+ public StyleBuilder background(short[] rgb) {
+ assert rgb.length == 3;
+ return background(createColor(rgb[0], rgb[1], rgb[2]));
+ }
+
+ /**
+ * Sets the background (fill) color of the style
+ *
+ * @param r
+ * red amount (0-255)
+ * @param g
+ * green amount (0-255)
+ * @param b
+ * blue amount (0-255)
+ * @return the {@link StyleBuilder} self (for cascading method calls)
+ */
+ public StyleBuilder background(int r, int g, int b) {
+ return background(createColor(r, g, b));
+ }
+
+ /**
+ * Sets the background (fill) color of the style
+ *
+ * @param color
+ * the color to use
+ * @return the {@link StyleBuilder} self (for cascading method calls)
+ */
+ public StyleBuilder background(Color color) {
+ if (EqualsBuilder.equals(_defaultBackgroundColor, color)) {
+ _backgroundColor = null;
+ } else {
+ _backgroundColor = color;
+ }
+ return this;
+ }
+
+ /**
+ * Sets the font size of the style
+ *
+ * @param fontSize
+ * the font size
+ * @param sizeUnit
+ * the font size unit
+ * @return the {@link StyleBuilder} self (for cascading method calls)
+ */
+ public StyleBuilder fontSize(int fontSize, SizeUnit sizeUnit) {
+ _fontSize = fontSize;
+ _fontSizeUnit = sizeUnit;
+ return this;
+ }
+
+ /**
+ * Sets the text alignment to center
+ *
+ * @return the {@link StyleBuilder} self (for cascading method calls)
+ */
+ public StyleBuilder centerAligned() {
+ _alignment = TextAlignment.CENTER;
+ return this;
+ }
+
+ /**
+ * Sets the text alignment to left
+ *
+ * @return the {@link StyleBuilder} self (for cascading method calls)
+ */
+ public StyleBuilder leftAligned() {
+ _alignment = TextAlignment.LEFT;
+ return this;
+ }
+
+ /**
+ * Sets the text alignment to right
+ *
+ * @return the {@link StyleBuilder} self (for cascading method calls)
+ */
+ public StyleBuilder rightAligned() {
+ _alignment = TextAlignment.RIGHT;
+ return this;
+ }
+
+ /**
+ * Sets the text alignment to justify
+ *
+ * @return the {@link StyleBuilder} self (for cascading method calls)
+ */
+ public StyleBuilder justifyAligned() {
+ _alignment = TextAlignment.JUSTIFY;
+ return this;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/data/StyleImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/StyleImpl.java b/core/src/main/java/org/apache/metamodel/data/StyleImpl.java
new file mode 100644
index 0000000..e00e1a9
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/StyleImpl.java
@@ -0,0 +1,177 @@
+/**
+ * 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.util.BaseObject;
+
+/**
+ * Default immutable implementation of {@link Style}.
+ *
+ * @author Kasper Sørensen
+ */
+final class StyleImpl extends BaseObject implements Style {
+
+ private static final long serialVersionUID = 1L;
+
+ private final boolean _underline;
+ private final boolean _italic;
+ private final boolean _bold;
+ private final Integer _fontSize;
+ private final TextAlignment _alignment;
+ private final Color _backgroundColor;
+ private final Color _foregroundColor;
+ private final SizeUnit _fontSizeUnit;
+
+ public StyleImpl() {
+ this(false, false, false, null, null, null, null, null);
+ }
+
+ public StyleImpl(boolean bold, boolean italic, boolean underline,
+ Integer fontSize, SizeUnit fontSizeUnit, TextAlignment alignment,
+ Color backgroundColor, Color foregroundColor) {
+ _bold = bold;
+ _italic = italic;
+ _underline = underline;
+ _fontSize = fontSize;
+ _fontSizeUnit = fontSizeUnit;
+ _alignment = alignment;
+ _backgroundColor = backgroundColor;
+ _foregroundColor = foregroundColor;
+ }
+
+ @Override
+ public boolean isBold() {
+ return _bold;
+ }
+
+ @Override
+ public boolean isItalic() {
+ return _italic;
+ }
+
+ @Override
+ public boolean isUnderline() {
+ return _underline;
+ }
+
+ @Override
+ public Integer getFontSize() {
+ return _fontSize;
+ }
+
+ @Override
+ public SizeUnit getFontSizeUnit() {
+ return _fontSizeUnit;
+ }
+
+ @Override
+ public TextAlignment getAlignment() {
+ return _alignment;
+ }
+
+ @Override
+ public Color getForegroundColor() {
+ return _foregroundColor;
+ }
+
+ @Override
+ public Color getBackgroundColor() {
+ return _backgroundColor;
+ }
+
+ @Override
+ public String toCSS() {
+ StringBuilder sb = new StringBuilder();
+ if (_bold) {
+ sb.append("font-weight: bold;");
+ }
+ if (_italic) {
+ sb.append("font-style: italic;");
+ }
+ if (_underline) {
+ sb.append("text-decoration: underline;");
+ }
+ if (_alignment != null) {
+ sb.append("text-align: " + toCSS(_alignment) + ";");
+ }
+ if (_fontSize != null) {
+ sb.append("font-size: " + _fontSize);
+ switch (_fontSizeUnit) {
+ case PT:
+ sb.append("pt");
+ break;
+ case PX:
+ sb.append("px");
+ break;
+ case PERCENT:
+ sb.append("%");
+ break;
+ default:
+ // don't write a size unit
+ }
+ sb.append(';');
+ }
+ if (_foregroundColor != null) {
+ sb.append("color: " + toCSS(_foregroundColor) + ";");
+ }
+ if (_backgroundColor != null) {
+ sb.append("background-color: " + toCSS(_backgroundColor) + ";");
+ }
+ return sb.toString();
+ }
+
+ private String toCSS(Color c) {
+ return "rgb(" + c.getRed() + "," + c.getGreen() + "," + c.getBlue()
+ + ")";
+ }
+
+ @Override
+ public String toString() {
+ return toCSS();
+ }
+
+ private String toCSS(TextAlignment alignment) {
+ switch (alignment) {
+ case LEFT:
+ return "left";
+ case RIGHT:
+ return "right";
+ case CENTER:
+ return "center";
+ case JUSTIFY:
+ return "justify";
+ default:
+ throw new IllegalStateException("Unknown alignment: " + alignment);
+ }
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ identifiers.add(_underline);
+ identifiers.add(_italic);
+ identifiers.add(_bold);
+ identifiers.add(_fontSize);
+ identifiers.add(_fontSizeUnit);
+ identifiers.add(_alignment);
+ identifiers.add(_backgroundColor);
+ identifiers.add(_foregroundColor);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/data/SubSelectionDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/SubSelectionDataSet.java b/core/src/main/java/org/apache/metamodel/data/SubSelectionDataSet.java
new file mode 100644
index 0000000..1a1df90
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/SubSelectionDataSet.java
@@ -0,0 +1,57 @@
+/**
+ * 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 org.eobjects.metamodel.query.SelectItem;
+
+/**
+ * {@link DataSet} wrapper for doing subselection.
+ *
+ * @author Kasper Sørensen
+ */
+public final class SubSelectionDataSet extends AbstractDataSet {
+
+ private final DataSet _dataSet;
+
+ public SubSelectionDataSet(SelectItem[] selectItemsArray, DataSet dataSet) {
+ super(selectItemsArray);
+ _dataSet = dataSet;
+ }
+
+ public DataSet getWrappedDataSet() {
+ return _dataSet;
+ }
+
+ @Override
+ public boolean next() {
+ return _dataSet.next();
+ }
+
+ @Override
+ public Row getRow() {
+ final DataSetHeader header = getHeader();
+ return _dataSet.getRow().getSubSelection(header);
+ }
+
+ @Override
+ public void close() {
+ super.close();
+ _dataSet.close();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/data/WhereClauseBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/WhereClauseBuilder.java b/core/src/main/java/org/apache/metamodel/data/WhereClauseBuilder.java
new file mode 100644
index 0000000..4865bad
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/WhereClauseBuilder.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 org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.builder.FilterBuilder;
+import org.eobjects.metamodel.schema.Column;
+
+/**
+ * An interface for builder components that formulate a WHERE clause, either for
+ * querying, updating, deleting or other purposes.
+ *
+ * @param <T>
+ * the return type of the {@link WhereClauseBuilder}s builder methods
+ */
+public interface WhereClauseBuilder<T> {
+
+ /**
+ * Defines a where item to set as a criteria
+ *
+ * @param column
+ * a column to apply a criteria for
+ * @return a builder object for further building the where item
+ */
+ public FilterBuilder<T> where(Column column);
+
+ /**
+ * Defines a where item to set as a criteria
+ *
+ * @param columnName
+ * the name of the colum to which the criteria will be applied
+ * @return a builder object for further building the where item
+ */
+ public FilterBuilder<T> where(String columnName);
+
+ /**
+ * Applies where items to set criteria
+ *
+ * @param filterItems
+ * the where items to set
+ * @return the builder object itself, for further building of the update
+ */
+ public T where(FilterItem... filterItems);
+
+ /**
+ * Applies where items to set criteria
+ *
+ * @param filterItems
+ * the where items to set
+ * @return the builder object, for further building of the update
+ */
+ public T where(Iterable<FilterItem> filterItems);
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/data/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/package-info.java b/core/src/main/java/org/apache/metamodel/data/package-info.java
new file mode 100644
index 0000000..572f5a3
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/data/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 data sets
+ */
+package org.eobjects.metamodel.data;
+
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/delete/AbstractRowDeletionBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/delete/AbstractRowDeletionBuilder.java b/core/src/main/java/org/apache/metamodel/delete/AbstractRowDeletionBuilder.java
new file mode 100644
index 0000000..7354f52
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/delete/AbstractRowDeletionBuilder.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.delete;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.query.FilterClause;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.query.builder.AbstractFilterBuilder;
+import org.eobjects.metamodel.query.builder.FilterBuilder;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * Abstract {@link RowDeletionBuilder} implementation
+ */
+public abstract class AbstractRowDeletionBuilder implements RowDeletionBuilder {
+
+ private final Table _table;
+ private final List<FilterItem> _whereItems;
+
+ public AbstractRowDeletionBuilder(Table table) {
+ if (table == null) {
+ throw new IllegalArgumentException("Table cannot be null");
+ }
+ _table = table;
+ _whereItems = new ArrayList<FilterItem>();
+ }
+
+ protected List<FilterItem> getWhereItems() {
+ return _whereItems;
+ }
+
+ @Override
+ public FilterBuilder<RowDeletionBuilder> where(Column column) {
+ SelectItem selectItem = new SelectItem(column);
+ return new AbstractFilterBuilder<RowDeletionBuilder>(selectItem) {
+ @Override
+ protected RowDeletionBuilder applyFilter(FilterItem filter) {
+ return where(filter);
+ }
+ };
+ }
+
+ @Override
+ public FilterBuilder<RowDeletionBuilder> where(String columnName) {
+ Column column = _table.getColumnByName(columnName);
+ if (column == null) {
+ throw new IllegalArgumentException("No such column: " + columnName);
+ }
+ return where(column);
+ }
+
+ @Override
+ public RowDeletionBuilder where(FilterItem... filterItems) {
+ for (FilterItem filterItem : filterItems) {
+ _whereItems.add(filterItem);
+ }
+ return this;
+ }
+
+ @Override
+ public RowDeletionBuilder where(Iterable<FilterItem> filterItems) {
+ for (FilterItem filterItem : filterItems) {
+ _whereItems.add(filterItem);
+ }
+ return this;
+ }
+
+ @Override
+ public Table getTable() {
+ return _table;
+ }
+
+ /**
+ * Determines if a row should be deleted or not (can be used by subclasses
+ * as a convenient determinator).
+ *
+ * @param row
+ * @return true if the row should be deleted.
+ */
+ protected boolean deleteRow(Row row) {
+ final List<FilterItem> whereItems = getWhereItems();
+ for (FilterItem filterItem : whereItems) {
+ if (!filterItem.evaluate(row)) {
+ // since filter items are ANDed, if any item does not evaluate
+ // to true, the row is not deleted
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Convenience method to tell subclasses if the delete operation represents
+ * a full table truncate operation. Usually such operations can be optimized
+ * by simply removing the table (and maybe restoring similar headers in a
+ * new table).
+ *
+ * @return
+ */
+ protected boolean isTruncateTableOperation() {
+ final List<FilterItem> whereItems = getWhereItems();
+ return whereItems.isEmpty();
+ }
+
+ @Override
+ public String toString() {
+ return toSql();
+ }
+
+ @Override
+ public String toSql() {
+ return "DELETE FROM " + _table.getQualifiedLabel() + new FilterClause(null, " WHERE ").addItems(_whereItems);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/delete/DeleteFrom.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/delete/DeleteFrom.java b/core/src/main/java/org/apache/metamodel/delete/DeleteFrom.java
new file mode 100644
index 0000000..59d1adf
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/delete/DeleteFrom.java
@@ -0,0 +1,94 @@
+/**
+ * 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.delete;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.UpdateableDataContext;
+import org.eobjects.metamodel.data.WhereClauseBuilder;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.query.builder.AbstractFilterBuilder;
+import org.eobjects.metamodel.query.builder.FilterBuilder;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * Represents a single DELETE FROM 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 delete from
+ * implementation. Some {@link DataContext}s may even optimize specifically
+ * based on the knowledge that there will only be a single delete from statement
+ * executed.
+ */
+public final class DeleteFrom implements UpdateScript, WhereClauseBuilder<DeleteFrom> {
+
+ private final List<FilterItem> _whereItems;
+ private final Table _table;
+
+ public DeleteFrom(Table table) {
+ _table = table;
+ _whereItems = new ArrayList<FilterItem>();
+ }
+
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.deleteFrom(_table).where(_whereItems).execute();
+ }
+
+ @Override
+ public FilterBuilder<DeleteFrom> where(Column column) {
+ SelectItem selectItem = new SelectItem(column);
+ return new AbstractFilterBuilder<DeleteFrom>(selectItem) {
+ @Override
+ protected DeleteFrom applyFilter(FilterItem filter) {
+ return where(filter);
+ }
+ };
+ }
+
+ @Override
+ public FilterBuilder<DeleteFrom> where(String columnName) {
+ Column column = _table.getColumnByName(columnName);
+ if (column == null) {
+ throw new IllegalArgumentException("No such column: " + columnName);
+ }
+ return where(column);
+ }
+
+ @Override
+ public DeleteFrom where(FilterItem... filterItems) {
+ for (FilterItem filterItem : filterItems) {
+ _whereItems.add(filterItem);
+ }
+ return this;
+ }
+
+ @Override
+ public DeleteFrom where(Iterable<FilterItem> filterItems) {
+ for (FilterItem filterItem : filterItems) {
+ _whereItems.add(filterItem);
+ }
+ return this;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/delete/RowDeletable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/delete/RowDeletable.java b/core/src/main/java/org/apache/metamodel/delete/RowDeletable.java
new file mode 100644
index 0000000..43be6d8
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/delete/RowDeletable.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.delete;
+
+import org.eobjects.metamodel.schema.Table;
+
+public interface RowDeletable {
+
+ /**
+ * Determines whether row delete is supported
+ *
+ * @return true if row delete is supported
+ */
+ public boolean isDeleteSupported();
+
+ /**
+ * Initiates a row deletion builder.
+ *
+ * @param table
+ * @return
+ * @throws IllegalArgumentException
+ * @throws IllegalStateException
+ * @throws UnsupportedOperationException
+ */
+ public RowDeletionBuilder deleteFrom(Table table) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException;
+
+ /**
+ * Initiates a row deletion builder.
+ *
+ * @param tableName
+ * @return
+ * @throws IllegalArgumentException
+ * @throws IllegalStateException
+ * @throws UnsupportedOperationException
+ */
+ public RowDeletionBuilder deleteFrom(String tableName) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException;
+
+ /**
+ * Initiates a row deletion builder.
+ *
+ * @param schemaName
+ * @param tableName
+ * @return
+ * @throws IllegalArgumentException
+ * @throws IllegalStateException
+ * @throws UnsupportedOperationException
+ */
+ public RowDeletionBuilder deleteFrom(String schemaName, String tableName) throws IllegalArgumentException,
+ IllegalStateException, UnsupportedOperationException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/delete/RowDeletionBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/delete/RowDeletionBuilder.java b/core/src/main/java/org/apache/metamodel/delete/RowDeletionBuilder.java
new file mode 100644
index 0000000..90ce319
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/delete/RowDeletionBuilder.java
@@ -0,0 +1,57 @@
+/**
+ * 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.delete;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.data.WhereClauseBuilder;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * Builder object for row deletions in a {@link Table}.
+ *
+ * @author Kasper Sørensen
+ */
+public interface RowDeletionBuilder extends WhereClauseBuilder<RowDeletionBuilder> {
+
+ /**
+ * Gets the table that this delete statement pertains to.
+ *
+ * @return the table that this delete statement pertains to.
+ */
+ public Table getTable();
+
+ /**
+ * Gets a SQL representation of this delete 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 delete operation.
+ */
+ public String toSql();
+
+ /**
+ * Commits the row deletion operation. This operation will delete rows in
+ * the {@link DataContext}.
+ *
+ * @throws MetaModelException
+ * if the operation was rejected
+ */
+ public void execute() throws MetaModelException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/delete/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/delete/package-info.java b/core/src/main/java/org/apache/metamodel/delete/package-info.java
new file mode 100644
index 0000000..37b96f7
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/delete/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 deleting rows
+ */
+package org.eobjects.metamodel.delete;
+
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/drop/AbstractTableDropBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/drop/AbstractTableDropBuilder.java b/core/src/main/java/org/apache/metamodel/drop/AbstractTableDropBuilder.java
new file mode 100644
index 0000000..2fa26a5
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/drop/AbstractTableDropBuilder.java
@@ -0,0 +1,51 @@
+/**
+ * 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.drop;
+
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * Abstract {@link TableDropBuilder} implementation
+ */
+public abstract class AbstractTableDropBuilder implements TableDropBuilder {
+
+ private final Table _table;
+
+ public AbstractTableDropBuilder(Table table) {
+ if (table == null) {
+ throw new IllegalArgumentException("Table cannot be null");
+ }
+ _table = table;
+ }
+
+ @Override
+ public final Table getTable() {
+ return _table;
+ }
+
+ @Override
+ public String toString() {
+ return toSql();
+ }
+
+ @Override
+ public String toSql() {
+ return "DROP TABLE " + _table.getQualifiedLabel();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/drop/DropTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/drop/DropTable.java b/core/src/main/java/org/apache/metamodel/drop/DropTable.java
new file mode 100644
index 0000000..f150c50
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/drop/DropTable.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.drop;
+
+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.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * Represents a single DROP 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 drop table
+ * implementation. Some {@link DataContext}s may even optimize specifically
+ * based on the knowledge that there will only be a single table dropped.
+ */
+public final class DropTable implements UpdateScript {
+
+ private final String _schemaName;
+ private final String _tableName;
+
+ public DropTable(Table table) {
+ this(table.getSchema().getName(), table.getName());
+ }
+
+ public DropTable(String tableName) {
+ this((String) null, tableName);
+ }
+
+ public DropTable(Schema schema, String tableName) {
+ this(schema.getName(), tableName);
+ }
+
+ public DropTable(String schemaName, String tableName) {
+ _schemaName = schemaName;
+ _tableName = tableName;
+ }
+
+ @Override
+ public void run(UpdateCallback callback) {
+ final TableDropBuilder dropBuilder;
+ if (_schemaName == null) {
+ dropBuilder = callback.dropTable(_tableName);
+ } else {
+ dropBuilder = callback.dropTable(_schemaName, _tableName);
+ }
+ dropBuilder.execute();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/drop/TableDropBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/drop/TableDropBuilder.java b/core/src/main/java/org/apache/metamodel/drop/TableDropBuilder.java
new file mode 100644
index 0000000..34bce59
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/drop/TableDropBuilder.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eobjects.metamodel.drop;
+
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.schema.Table;
+
+public interface TableDropBuilder {
+
+ /**
+ * Gets the table that this drop statement pertains to
+ *
+ * @return the table that this drop statement pertains to
+ */
+ public Table getTable();
+
+ /**
+ * Gets a SQL representation of this drop 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 drop table operation.
+ */
+ public String toSql();
+
+ /**
+ * Executes the drop table operation
+ *
+ * @throws MetaModelException
+ * if the operation was rejected
+ */
+ public void execute() throws MetaModelException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/drop/TableDroppable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/drop/TableDroppable.java b/core/src/main/java/org/apache/metamodel/drop/TableDroppable.java
new file mode 100644
index 0000000..d5c8260
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/drop/TableDroppable.java
@@ -0,0 +1,44 @@
+/**
+ * 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.drop;
+
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+public interface TableDroppable {
+
+ /**
+ * Determines whether table drop is supported
+ *
+ * @return true if table drop is supported
+ */
+ public boolean isDropTableSupported();
+
+ public TableDropBuilder dropTable(Schema schema, String tableName) throws IllegalArgumentException,
+ IllegalStateException, UnsupportedOperationException;
+
+ public TableDropBuilder dropTable(String schemaName, String tableName) throws IllegalArgumentException,
+ IllegalStateException, UnsupportedOperationException;
+
+ public TableDropBuilder dropTable(String tableName) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException;
+
+ public TableDropBuilder dropTable(Table table) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/drop/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/drop/package-info.java b/core/src/main/java/org/apache/metamodel/drop/package-info.java
new file mode 100644
index 0000000..7f51816
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/drop/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 dropping tables
+ */
+package org.eobjects.metamodel.drop;
+
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/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
new file mode 100644
index 0000000..c57c26d
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/insert/AbstractRowInsertionBuilder.java
@@ -0,0 +1,108 @@
+/**
+ * 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.insert;
+
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.data.AbstractRowBuilder;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * Abstract implementation of the {@link RowInsertionBuilder} interface,
+ * provided as a convenience to {@link RowInsertable} implementations. Handles
+ * all the building operations, but not the commit operation.
+ *
+ * @author Kasper Sørensen
+ */
+public abstract class AbstractRowInsertionBuilder<U extends UpdateCallback> extends
+ AbstractRowBuilder<RowInsertionBuilder> implements RowInsertionBuilder {
+
+ private final U _updateCallback;
+ private final Table _table;
+
+ public AbstractRowInsertionBuilder(U updateCallback, Table table) {
+ super(table);
+ _updateCallback = updateCallback;
+ _table = table;
+ }
+
+ @Override
+ public Table getTable() {
+ return _table;
+ }
+
+ protected U getUpdateCallback() {
+ return _updateCallback;
+ }
+
+ @Override
+ public RowInsertionBuilder like(Row row) {
+ SelectItem[] selectItems = row.getSelectItems();
+ for (int i = 0; i < selectItems.length; i++) {
+ SelectItem selectItem = selectItems[i];
+ Column column = selectItem.getColumn();
+ if (column != null) {
+ if (_table == column.getTable()) {
+ value(column, row.getValue(i));
+ } else {
+ value(column.getName(), row.getValue(i));
+ }
+ }
+ }
+ return this;
+ }
+
+ @Override
+ public String toSql() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("INSERT INTO ");
+ sb.append(_table.getQualifiedLabel());
+ sb.append("(");
+ Column[] columns = getColumns();
+ for (int i = 0; i < columns.length; i++) {
+ if (i != 0) {
+ sb.append(',');
+ }
+ sb.append(columns[i].getName());
+ }
+ sb.append(") VALUES (");
+ Object[] values = getValues();
+ for (int i = 0; i < values.length; i++) {
+ Object value = values[i];
+ final String stringValue;
+ if (value == null) {
+ stringValue = "NULL";
+ } else if (value instanceof String) {
+ stringValue = "\"" + value + "\"";
+ } else {
+ stringValue = value.toString();
+ }
+ sb.append(stringValue);
+ }
+ sb.append(")");
+ return sb.toString();
+ }
+
+ @Override
+ public String toString() {
+ return toSql();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/insert/InsertInto.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/insert/InsertInto.java b/core/src/main/java/org/apache/metamodel/insert/InsertInto.java
new file mode 100644
index 0000000..df793b9
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/insert/InsertInto.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.insert;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.UpdateableDataContext;
+import org.eobjects.metamodel.data.AbstractRowBuilder;
+import org.eobjects.metamodel.data.RowBuilder;
+import org.eobjects.metamodel.data.Style;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * Represents a single INSERT INTO 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
+ * single-record insertion implementation. Some {@link DataContext}s may even
+ * optimize specifically based on the knowledge that there will only be a single
+ * record inserted.
+ */
+public final class InsertInto extends AbstractRowBuilder<InsertInto> implements UpdateScript, RowBuilder<InsertInto> {
+
+ private final Table _table;
+
+ public InsertInto(Table table) {
+ super(table);
+ _table = table;
+ }
+
+ @Override
+ public void run(UpdateCallback callback) {
+ RowInsertionBuilder insertBuilder = callback.insertInto(getTable());
+
+ final Column[] columns = getColumns();
+ final Object[] values = getValues();
+ final Style[] styles = getStyles();
+ final boolean[] explicitNulls = getExplicitNulls();
+
+ for (int i = 0; i < columns.length; i++) {
+ Object value = values[i];
+ Column column = columns[i];
+ Style style = styles[i];
+ if (value == null) {
+ if (explicitNulls[i]) {
+ insertBuilder = insertBuilder.value(column, value, style);
+ }
+ } else {
+ insertBuilder = insertBuilder.value(column, value, style);
+ }
+ }
+
+ insertBuilder.execute();
+ }
+
+ @Override
+ public Table getTable() {
+ return _table;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/insert/RowInsertable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/insert/RowInsertable.java b/core/src/main/java/org/apache/metamodel/insert/RowInsertable.java
new file mode 100644
index 0000000..bcb3aaa
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/insert/RowInsertable.java
@@ -0,0 +1,92 @@
+/**
+ * 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.insert;
+
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * An interface for objects that support inserting rows into tables.
+ *
+ * @author Kasper Sørensen
+ */
+public interface RowInsertable {
+
+ /**
+ * Determines whether row insertion is supported
+ *
+ * @return true if row insertion is supported
+ */
+ public boolean isInsertSupported();
+
+ /**
+ * Initiates the building of a row insertion operation.
+ *
+ * @param table
+ * the table to insert a row into
+ * @return a builder object on which values can be added and the statement
+ * can be 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.
+ * @throws UnsupportedOperationException
+ * in case {@link #isInsertSupported()} is false
+ */
+ public RowInsertionBuilder insertInto(Table table) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException;
+
+ /**
+ * Initiates the building of a row insertion operation.
+ *
+ * @param tableName
+ * the name of the table to insert a row into
+ * @return a builder object on which values can be added and the statement
+ * can be committed.
+ * @throws IllegalArgumentException
+ * if the tableName argument is null or invalid.
+ * @throws IllegalStateException
+ * if the connection to the DataContext is read-only or another
+ * access restriction is preventing the operation.
+ * @throws UnsupportedOperationException
+ * in case {@link #isInsertSupported()} is false
+ */
+ public RowInsertionBuilder insertInto(String tableName) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException;
+
+ /**
+ * Initiates the building of a row insertion operation.
+ *
+ * @param schemaName
+ * the name of the schema
+ * @param tableName
+ * the name of the table to insert a row into
+ * @return a builder object on which values can be added and the statement
+ * can be committed.
+ * @throws IllegalArgumentException
+ * if the tableName argument is null or invalid.
+ * @throws IllegalStateException
+ * if the connection to the DataContext is read-only or another
+ * access restriction is preventing the operation.
+ * @throws UnsupportedOperationException
+ * in case {@link #isInsertSupported()} is false
+ */
+ public RowInsertionBuilder insertInto(String schemaName, String tableName) throws IllegalArgumentException,
+ IllegalStateException, UnsupportedOperationException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/insert/RowInsertionBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/insert/RowInsertionBuilder.java b/core/src/main/java/org/apache/metamodel/insert/RowInsertionBuilder.java
new file mode 100644
index 0000000..05714a3
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/insert/RowInsertionBuilder.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.insert;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.data.RowBuilder;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * Builder object for row insertion, into a {@link Table}.
+ *
+ * @author Kasper Sørensen
+ */
+public interface RowInsertionBuilder extends RowBuilder<RowInsertionBuilder> {
+
+ /**
+ * Gets the table that this insert pertains to.
+ *
+ * @return the table that this insert pertains to.
+ */
+ @Override
+ public Table getTable();
+
+ /**
+ * Sets all values like the provided row (for easy duplication of a row).
+ *
+ * @param row
+ * the row from which to take values
+ * @return the builder itself
+ */
+ public RowInsertionBuilder like(Row row);
+
+ /**
+ * Commits the row insertion operation. This operation will write the row to
+ * the {@link DataContext}.
+ *
+ * @throws MetaModelException
+ * if the operation was rejected
+ */
+ public void execute() throws MetaModelException;
+
+ /**
+ * Gets a SQL representation of this insert 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 insert operation.
+ */
+ public String toSql();
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/insert/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/insert/package-info.java b/core/src/main/java/org/apache/metamodel/insert/package-info.java
new file mode 100644
index 0000000..5a78f04
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/insert/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 inserting rows
+ */
+package org.eobjects.metamodel.insert;
+
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/intercept/DataSetInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/intercept/DataSetInterceptor.java b/core/src/main/java/org/apache/metamodel/intercept/DataSetInterceptor.java
new file mode 100644
index 0000000..3661374
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/intercept/DataSetInterceptor.java
@@ -0,0 +1,31 @@
+/**
+ * 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.intercept;
+
+import org.eobjects.metamodel.data.DataSet;
+
+/**
+ * An {@link Interceptor} for {@link DataSet}s, allowing to touch, enrich or
+ * modify a dataset before it is returned to the user.
+ *
+ * @author Kasper Sørensen
+ */
+public interface DataSetInterceptor extends Interceptor<DataSet> {
+
+}
[18/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataSet.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataSet.java b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataSet.java
new file mode 100644
index 0000000..6f3db01
--- /dev/null
+++ b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataSet.java
@@ -0,0 +1,123 @@
+/**
+ * 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.couchdb;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.codehaus.jackson.JsonNode;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.ektorp.StreamingViewResult;
+import org.eobjects.metamodel.data.AbstractDataSet;
+import org.eobjects.metamodel.data.DefaultRow;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.query.SelectItem;
+
+/**
+ * DataSet implementation for couch db.
+ */
+final class CouchDbDataSet extends AbstractDataSet {
+
+ private final Iterator<org.ektorp.ViewResult.Row> _iterator;
+ private final StreamingViewResult _streamingViewResult;
+ private DefaultRow _row;
+
+ public CouchDbDataSet(SelectItem[] selectItems, StreamingViewResult streamingViewResult) {
+ super(selectItems);
+ _streamingViewResult = streamingViewResult;
+
+ _iterator = _streamingViewResult.iterator();
+ }
+
+ @Override
+ public boolean next() {
+ if (_iterator == null || !_iterator.hasNext()) {
+ return false;
+ }
+
+ final org.ektorp.ViewResult.Row row = _iterator.next();
+ final JsonNode node = row.getDocAsNode();
+ final int size = getHeader().size();
+ final Object[] values = new Object[size];
+ for (int i = 0; i < size; i++) {
+ final String key = getHeader().getSelectItem(i).getColumn().getName();
+ final JsonNode valueNode = node.get(key);
+ final Object value;
+ if (valueNode == null || valueNode.isNull()) {
+ value = null;
+ } else if (valueNode.isTextual()) {
+ value = valueNode.asText();
+ } else if (valueNode.isArray()) {
+ value = toList(valueNode);
+ } else if (valueNode.isObject()) {
+ value = toMap(valueNode);
+ } else if (valueNode.isBoolean()) {
+ value = valueNode.asBoolean();
+ } else if (valueNode.isInt()) {
+ value = valueNode.asInt();
+ } else if (valueNode.isLong()) {
+ value = valueNode.asLong();
+ } else if (valueNode.isDouble()) {
+ value = valueNode.asDouble();
+ } else {
+ value = valueNode;
+ }
+ values[i] = value;
+ }
+
+ _row = new DefaultRow(getHeader(), values);
+
+ return true;
+ }
+
+ private Map<String, Object> toMap(JsonNode valueNode) {
+ if (valueNode == null) {
+ return null;
+ }
+ try {
+ return new ObjectMapper().reader(Map.class).readValue(valueNode);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ private Object toList(JsonNode valueNode) {
+ if (valueNode == null) {
+ return null;
+ }
+ try {
+ return new ObjectMapper().reader(List.class).readValue(valueNode);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ @Override
+ public Row getRow() {
+ return _row;
+ }
+
+ @Override
+ public void close() {
+ super.close();
+ _streamingViewResult.close();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbInsertionBuilder.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbInsertionBuilder.java b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbInsertionBuilder.java
new file mode 100644
index 0000000..7fe2ae6
--- /dev/null
+++ b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbInsertionBuilder.java
@@ -0,0 +1,54 @@
+/**
+ * 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.couchdb;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.ektorp.CouchDbConnector;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.insert.AbstractRowInsertionBuilder;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+
+final class CouchDbInsertionBuilder extends AbstractRowInsertionBuilder<CouchDbUpdateCallback> {
+
+ public CouchDbInsertionBuilder(CouchDbUpdateCallback updateCallback, Table table) {
+ super(updateCallback, table);
+ }
+
+ @Override
+ public void execute() throws MetaModelException {
+ Table table = getTable();
+ String name = table.getName();
+
+ Object[] values = getValues();
+ Column[] columns = getColumns();
+ Map<String, Object> map = new HashMap<String, Object>();
+ for (int i = 0; i < columns.length; i++) {
+ Column column = columns[i];
+ if (isSet(column)) {
+ map.put(column.getName(), values[i]);
+ }
+ }
+
+ CouchDbConnector connector = getUpdateCallback().getConnector(name);
+ connector.addToBulkBuffer(map);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbRowDeletionBuilder.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbRowDeletionBuilder.java b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbRowDeletionBuilder.java
new file mode 100644
index 0000000..fe0fc66
--- /dev/null
+++ b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbRowDeletionBuilder.java
@@ -0,0 +1,62 @@
+/**
+ * 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.couchdb;
+
+import java.util.List;
+
+import org.ektorp.CouchDbConnector;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.delete.AbstractRowDeletionBuilder;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.schema.Table;
+
+final class CouchDbRowDeletionBuilder extends AbstractRowDeletionBuilder {
+
+ private final CouchDbUpdateCallback _updateCallback;
+
+ public CouchDbRowDeletionBuilder(CouchDbUpdateCallback updateCallback, Table table) {
+ super(table);
+ _updateCallback = updateCallback;
+ }
+
+ @Override
+ public void execute() throws MetaModelException {
+ Table table = getTable();
+ List<FilterItem> whereItems = getWhereItems();
+
+ CouchDbConnector connector = _updateCallback.getConnector(table.getName());
+ CouchDbDataContext dataContext = _updateCallback.getDataContext();
+
+ DataSet dataSet = dataContext.query().from(table)
+ .select(CouchDbDataContext.FIELD_ID, CouchDbDataContext.FIELD_REV).where(whereItems).execute();
+ try {
+ while (dataSet.next()) {
+ Row row = dataSet.getRow();
+ String id = (String) row.getValue(0);
+ String revision = (String) row.getValue(1);
+ connector.delete(id, revision);
+ }
+ } finally {
+ dataSet.close();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbRowUpdationBuilder.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbRowUpdationBuilder.java b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbRowUpdationBuilder.java
new file mode 100644
index 0000000..15a4298
--- /dev/null
+++ b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbRowUpdationBuilder.java
@@ -0,0 +1,79 @@
+/**
+ * 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.couchdb;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.ektorp.CouchDbConnector;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.update.AbstractRowUpdationBuilder;
+
+final class CouchDbRowUpdationBuilder extends AbstractRowUpdationBuilder {
+
+ private final CouchDbUpdateCallback _updateCallback;
+
+ public CouchDbRowUpdationBuilder(CouchDbUpdateCallback updateCallback, Table table) {
+ super(table);
+ _updateCallback = updateCallback;
+ }
+
+ @Override
+ public void execute() throws MetaModelException {
+ final Table table = getTable();
+ final CouchDbConnector connector = _updateCallback.getConnector(table.getName());
+
+ // create a map which will act as a prototype for updated objects
+ final Map<String, Object> prototype = new HashMap<String, Object>();
+ final Column[] columns = getColumns();
+ final Object[] values = getValues();
+ for (int i = 0; i < columns.length; i++) {
+ final Column column = columns[i];
+ if (isSet(column)) {
+ final String columnName = column.getName();
+ final Object value = values[i];
+ prototype.put(columnName, value);
+ }
+ }
+
+ final CouchDbDataContext dc = _updateCallback.getDataContext();
+ final DataSet dataSet = dc.query().from(table).select(table.getColumns()).where(getWhereItems()).execute();
+ try {
+ while (dataSet.next()) {
+ final Map<String, Object> map = new HashMap<String, Object>(prototype);
+ final Row row = dataSet.getRow();
+ for (Column column : table.getColumns()) {
+ if (!map.containsKey(column.getName())) {
+ map.put(column.getName(), row.getValue(column));
+ }
+ }
+
+ // copy the prototype and set the not-updated values
+ connector.update(map);
+ }
+ } finally {
+ dataSet.close();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbTableCreationBuilder.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbTableCreationBuilder.java b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbTableCreationBuilder.java
new file mode 100644
index 0000000..df00880
--- /dev/null
+++ b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbTableCreationBuilder.java
@@ -0,0 +1,75 @@
+/**
+ * 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.couchdb;
+
+import org.ektorp.CouchDbInstance;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.create.AbstractTableCreationBuilder;
+import org.eobjects.metamodel.schema.ColumnType;
+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.Table;
+
+final class CouchDbTableCreationBuilder extends AbstractTableCreationBuilder<CouchDbUpdateCallback> {
+
+ public CouchDbTableCreationBuilder(CouchDbUpdateCallback updateCallback, Schema schema, String name) {
+ super(updateCallback, schema, name);
+ }
+
+ @Override
+ public Table execute() throws MetaModelException {
+ MutableTable table = getTable();
+
+ String name = table.getName();
+
+ CouchDbInstance instance = getUpdateCallback().getDataContext().getCouchDbInstance();
+ instance.createDatabase(name);
+
+ addMandatoryColumns(table);
+
+ MutableSchema schema = (MutableSchema) table.getSchema();
+ schema.addTable(table);
+
+ return table;
+ }
+
+ /**
+ * Verifies, and adds if nescesary, the two mandatory columns: _id and _rev.
+ *
+ * @param table
+ */
+ public static void addMandatoryColumns(MutableTable table) {
+ // add or correct ID column
+ {
+ MutableColumn idColumn = (MutableColumn) table.getColumnByName(CouchDbDataContext.FIELD_ID);
+ if (idColumn == null) {
+ idColumn = new MutableColumn(CouchDbDataContext.FIELD_ID, ColumnType.VARCHAR, table, 0, false);
+ table.addColumn(0, idColumn);
+ }
+ idColumn.setPrimaryKey(true);
+ }
+
+ if (table.getColumnByName(CouchDbDataContext.FIELD_REV) == null) {
+ table.addColumn(1, new MutableColumn(CouchDbDataContext.FIELD_REV, ColumnType.VARCHAR, table, 1, false));
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbTableDropBuilder.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbTableDropBuilder.java b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbTableDropBuilder.java
new file mode 100644
index 0000000..91297aa
--- /dev/null
+++ b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbTableDropBuilder.java
@@ -0,0 +1,46 @@
+/**
+ * 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.couchdb;
+
+import org.ektorp.CouchDbInstance;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.drop.AbstractTableDropBuilder;
+import org.eobjects.metamodel.schema.MutableSchema;
+import org.eobjects.metamodel.schema.Table;
+
+final class CouchDbTableDropBuilder extends AbstractTableDropBuilder {
+
+ private final CouchDbUpdateCallback _updateCallback;
+
+ public CouchDbTableDropBuilder(CouchDbUpdateCallback updateCallback, Table table) {
+ super(table);
+ _updateCallback = updateCallback;
+ }
+
+ @Override
+ public void execute() throws MetaModelException {
+ CouchDbInstance instance = _updateCallback.getDataContext().getCouchDbInstance();
+ Table table = getTable();
+ MutableSchema schema = (MutableSchema) table.getSchema();
+ schema.removeTable(table);
+
+ instance.deleteDatabase(table.getName());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbUpdateCallback.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbUpdateCallback.java b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbUpdateCallback.java
new file mode 100644
index 0000000..8207c0d
--- /dev/null
+++ b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbUpdateCallback.java
@@ -0,0 +1,143 @@
+/**
+ * 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.couchdb;
+
+import java.io.Closeable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.ektorp.CouchDbConnector;
+import org.ektorp.CouchDbInstance;
+import org.ektorp.DocumentOperationResult;
+import org.eobjects.metamodel.AbstractUpdateCallback;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.create.TableCreationBuilder;
+import org.eobjects.metamodel.delete.RowDeletionBuilder;
+import org.eobjects.metamodel.drop.TableDropBuilder;
+import org.eobjects.metamodel.insert.RowInsertionBuilder;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.update.RowUpdationBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class CouchDbUpdateCallback extends AbstractUpdateCallback implements Closeable {
+
+ private static final Logger logger = LoggerFactory.getLogger(CouchDbUpdateCallback.class);
+ private final Map<String, CouchDbConnector> _connectors;
+
+ public CouchDbUpdateCallback(CouchDbDataContext couchDbDataContext) {
+ super(couchDbDataContext);
+ _connectors = new HashMap<String, CouchDbConnector>();
+ }
+
+ @Override
+ public CouchDbDataContext getDataContext() {
+ return (CouchDbDataContext) super.getDataContext();
+ }
+
+ @Override
+ public boolean isUpdateSupported() {
+ return true;
+ }
+
+ @Override
+ public RowUpdationBuilder update(Table table) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException {
+ return new CouchDbRowUpdationBuilder(this, table);
+ }
+
+ @Override
+ public boolean isCreateTableSupported() {
+ return true;
+ }
+
+ @Override
+ public TableCreationBuilder createTable(Schema schema, String name) throws IllegalArgumentException,
+ IllegalStateException {
+ return new CouchDbTableCreationBuilder(this, schema, name);
+ }
+
+ @Override
+ public boolean isDropTableSupported() {
+ return true;
+ }
+
+ @Override
+ public TableDropBuilder dropTable(Table table) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException {
+ return new CouchDbTableDropBuilder(this, table);
+ }
+
+ @Override
+ public RowInsertionBuilder insertInto(Table table) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException {
+ return new CouchDbInsertionBuilder(this, table);
+ }
+
+ @Override
+ public boolean isDeleteSupported() {
+ return true;
+ }
+
+ @Override
+ public RowDeletionBuilder deleteFrom(Table table) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException {
+ return new CouchDbRowDeletionBuilder(this, table);
+ }
+
+ @Override
+ public void close() {
+ Collection<CouchDbConnector> connectorSet = _connectors.values();
+ for (CouchDbConnector connector : connectorSet) {
+ List<String> errornousResultsDescriptions = new ArrayList<String>();
+ List<DocumentOperationResult> results = connector.flushBulkBuffer();
+ for (DocumentOperationResult result : results) {
+ if (result.isErroneous()) {
+ String id = result.getId();
+ String error = result.getError();
+ String reason = result.getReason();
+ String revision = result.getRevision();
+ logger.error("Error occurred while flushing bulk buffer: {}, id: {}, revision: {}, reason: {}",
+ new Object[] { error, id, revision, reason });
+ errornousResultsDescriptions.add(error);
+ }
+ }
+
+ if (!errornousResultsDescriptions.isEmpty()) {
+ throw new MetaModelException(errornousResultsDescriptions.size() + " out of " + results.size()
+ + " operations in bulk was errornous: " + errornousResultsDescriptions);
+ }
+ }
+ }
+
+ public CouchDbConnector getConnector(String name) {
+ CouchDbConnector connector = _connectors.get(name);
+ if (connector == null) {
+ CouchDbInstance instance = getDataContext().getCouchDbInstance();
+ connector = instance.createConnector(name, false);
+ _connectors.put(name, connector);
+ }
+ return connector;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/main/java/org/apache/metamodel/couchdb/package-info.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/apache/metamodel/couchdb/package-info.java b/couchdb/src/main/java/org/apache/metamodel/couchdb/package-info.java
new file mode 100644
index 0000000..340fd98
--- /dev/null
+++ b/couchdb/src/main/java/org/apache/metamodel/couchdb/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.
+ */
+/**
+ * Module package for CouchDB support
+ */
+package org.eobjects.metamodel.couchdb;
+
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbDataContext.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbDataContext.java b/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbDataContext.java
deleted file mode 100644
index ac626e6..0000000
--- a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbDataContext.java
+++ /dev/null
@@ -1,254 +0,0 @@
-/**
- * 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.couchdb;
-
-import java.util.ArrayList;
-import java.util.EnumSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-import org.codehaus.jackson.JsonNode;
-import org.ektorp.CouchDbConnector;
-import org.ektorp.CouchDbInstance;
-import org.ektorp.StreamingViewResult;
-import org.ektorp.ViewQuery;
-import org.ektorp.ViewResult.Row;
-import org.ektorp.http.HttpClient;
-import org.ektorp.http.StdHttpClient;
-import org.ektorp.impl.StdCouchDbInstance;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.SimpleTableDef;
-
-/**
- * DataContext implementation for CouchDB
- */
-public class CouchDbDataContext extends QueryPostprocessDataContext implements UpdateableDataContext {
-
- public static final int DEFAULT_PORT = 5984;
-
- public static final String FIELD_ID = "_id";
- public static final String FIELD_REV = "_rev";
-
- private static final String SCHEMA_NAME = "CouchDB";
-
- private final CouchDbInstance _couchDbInstance;
- private final SimpleTableDef[] _tableDefs;
-
- public CouchDbDataContext(StdHttpClient.Builder httpClientBuilder, SimpleTableDef... tableDefs) {
- this(httpClientBuilder.build(), tableDefs);
- }
-
- public CouchDbDataContext(StdHttpClient.Builder httpClientBuilder) {
- this(httpClientBuilder.build());
- }
-
- public CouchDbDataContext(HttpClient httpClient, SimpleTableDef... tableDefs) {
- this(new StdCouchDbInstance(httpClient), tableDefs);
- }
-
- public CouchDbDataContext(HttpClient httpClient) {
- this(new StdCouchDbInstance(httpClient));
- }
-
- public CouchDbDataContext(CouchDbInstance couchDbInstance) {
- this(couchDbInstance, detectSchema(couchDbInstance));
- }
-
- public CouchDbDataContext(CouchDbInstance couchDbInstance, SimpleTableDef... tableDefs) {
- // the instance represents a handle to the whole couchdb cluster
- _couchDbInstance = couchDbInstance;
- _tableDefs = tableDefs;
- }
-
- public static SimpleTableDef[] detectSchema(CouchDbInstance couchDbInstance) {
- final List<SimpleTableDef> tableDefs = new ArrayList<SimpleTableDef>();
- final List<String> databaseNames = couchDbInstance.getAllDatabases();
- for (final String databaseName : databaseNames) {
-
- if (databaseName.startsWith("_")) {
- // don't add system tables
- continue;
- }
-
- CouchDbConnector connector = couchDbInstance.createConnector(databaseName, false);
-
- SimpleTableDef tableDef = detectTable(connector);
- tableDefs.add(tableDef);
- }
- return tableDefs.toArray(new SimpleTableDef[tableDefs.size()]);
- }
-
- public static SimpleTableDef detectTable(CouchDbConnector connector) {
- final SortedMap<String, Set<ColumnType>> columnsAndTypes = new TreeMap<String, Set<ColumnType>>();
-
- final StreamingViewResult streamingView = connector.queryForStreamingView(new ViewQuery().allDocs().includeDocs(true)
- .limit(1000));
- try {
- final Iterator<Row> rowIterator = streamingView.iterator();
- while (rowIterator.hasNext()) {
- Row row = rowIterator.next();
- JsonNode doc = row.getDocAsNode();
-
- final Iterator<Entry<String, JsonNode>> fieldIterator = doc.getFields();
- while (fieldIterator.hasNext()) {
- Entry<String, JsonNode> entry = fieldIterator.next();
- String key = entry.getKey();
-
- Set<ColumnType> types = columnsAndTypes.get(key);
-
- if (types == null) {
- types = EnumSet.noneOf(ColumnType.class);
- columnsAndTypes.put(key, types);
- }
-
- JsonNode value = entry.getValue();
- if (value == null || value.isNull()) {
- // do nothing
- } else if (value.isTextual()) {
- types.add(ColumnType.VARCHAR);
- } else if (value.isArray()) {
- types.add(ColumnType.LIST);
- } else if (value.isObject()) {
- types.add(ColumnType.MAP);
- } else if (value.isBoolean()) {
- types.add(ColumnType.BOOLEAN);
- } else if (value.isInt()) {
- types.add(ColumnType.INTEGER);
- } else if (value.isLong()) {
- types.add(ColumnType.BIGINT);
- } else if (value.isDouble()) {
- types.add(ColumnType.DOUBLE);
- }
- }
-
- }
- } finally {
- streamingView.close();
- }
-
- final String[] columnNames = new String[columnsAndTypes.size()];
- final ColumnType[] columnTypes = new ColumnType[columnsAndTypes.size()];
-
- int i = 0;
- for (Entry<String, Set<ColumnType>> columnAndTypes : columnsAndTypes.entrySet()) {
- final String columnName = columnAndTypes.getKey();
- final Set<ColumnType> columnTypeSet = columnAndTypes.getValue();
- final ColumnType columnType;
- if (columnTypeSet.isEmpty()) {
- columnType = ColumnType.OTHER;
- } else if (columnTypeSet.size() == 1) {
- columnType = columnTypeSet.iterator().next();
- } else {
- // TODO: Select best type?
- columnType = ColumnType.OTHER;
- }
- columnNames[i] = columnName;
- columnTypes[i] = columnType;
- i++;
- }
-
- final SimpleTableDef tableDef = new SimpleTableDef(connector.getDatabaseName(), columnNames, columnTypes);
- return tableDef;
- }
-
- public CouchDbInstance getCouchDbInstance() {
- return _couchDbInstance;
- }
-
- @Override
- protected Schema getMainSchema() throws MetaModelException {
- final MutableSchema schema = new MutableSchema(SCHEMA_NAME);
- for (final SimpleTableDef tableDef : _tableDefs) {
- final MutableTable table = tableDef.toTable().setSchema(schema);
- CouchDbTableCreationBuilder.addMandatoryColumns(table);
- schema.addTable(table);
- }
- return schema;
- }
-
- @Override
- protected String getMainSchemaName() throws MetaModelException {
- return SCHEMA_NAME;
- }
-
- @Override
- protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int firstRow, int maxRows) {
- // the connector represents a handle to the the couchdb "database".
- final String databaseName = table.getName();
- final CouchDbConnector connector = _couchDbInstance.createConnector(databaseName, false);
-
- ViewQuery query = new ViewQuery().allDocs().includeDocs(true);
-
- if (maxRows > 0) {
- query = query.limit(maxRows);
- }
- if (firstRow > 1) {
- final int skip = firstRow - 1;
- query = query.skip(skip);
- }
-
- final StreamingViewResult streamingView = connector.queryForStreamingView(query);
-
- final SelectItem[] selectItems = MetaModelHelper.createSelectItems(columns);
- return new CouchDbDataSet(selectItems, streamingView);
- }
-
- @Override
- protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
- return materializeMainSchemaTable(table, columns, 1, maxRows);
- }
-
- @Override
- protected Number executeCountQuery(Table table, List<FilterItem> whereItems, boolean functionApproximationAllowed) {
- if (whereItems.isEmpty()) {
- String databaseName = table.getName();
- CouchDbConnector connector = _couchDbInstance.createConnector(databaseName, false);
- long docCount = connector.getDbInfo().getDocCount();
- return docCount;
- }
- return null;
- }
-
- @Override
- public void executeUpdate(UpdateScript script) {
- CouchDbUpdateCallback callback = new CouchDbUpdateCallback(this);
- try {
- script.run(callback);
- } finally {
- callback.close();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbDataSet.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbDataSet.java b/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbDataSet.java
deleted file mode 100644
index 6f3db01..0000000
--- a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbDataSet.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/**
- * 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.couchdb;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.codehaus.jackson.JsonNode;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.ektorp.StreamingViewResult;
-import org.eobjects.metamodel.data.AbstractDataSet;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.SelectItem;
-
-/**
- * DataSet implementation for couch db.
- */
-final class CouchDbDataSet extends AbstractDataSet {
-
- private final Iterator<org.ektorp.ViewResult.Row> _iterator;
- private final StreamingViewResult _streamingViewResult;
- private DefaultRow _row;
-
- public CouchDbDataSet(SelectItem[] selectItems, StreamingViewResult streamingViewResult) {
- super(selectItems);
- _streamingViewResult = streamingViewResult;
-
- _iterator = _streamingViewResult.iterator();
- }
-
- @Override
- public boolean next() {
- if (_iterator == null || !_iterator.hasNext()) {
- return false;
- }
-
- final org.ektorp.ViewResult.Row row = _iterator.next();
- final JsonNode node = row.getDocAsNode();
- final int size = getHeader().size();
- final Object[] values = new Object[size];
- for (int i = 0; i < size; i++) {
- final String key = getHeader().getSelectItem(i).getColumn().getName();
- final JsonNode valueNode = node.get(key);
- final Object value;
- if (valueNode == null || valueNode.isNull()) {
- value = null;
- } else if (valueNode.isTextual()) {
- value = valueNode.asText();
- } else if (valueNode.isArray()) {
- value = toList(valueNode);
- } else if (valueNode.isObject()) {
- value = toMap(valueNode);
- } else if (valueNode.isBoolean()) {
- value = valueNode.asBoolean();
- } else if (valueNode.isInt()) {
- value = valueNode.asInt();
- } else if (valueNode.isLong()) {
- value = valueNode.asLong();
- } else if (valueNode.isDouble()) {
- value = valueNode.asDouble();
- } else {
- value = valueNode;
- }
- values[i] = value;
- }
-
- _row = new DefaultRow(getHeader(), values);
-
- return true;
- }
-
- private Map<String, Object> toMap(JsonNode valueNode) {
- if (valueNode == null) {
- return null;
- }
- try {
- return new ObjectMapper().reader(Map.class).readValue(valueNode);
- } catch (Exception e) {
- throw new IllegalStateException(e);
- }
- }
-
- private Object toList(JsonNode valueNode) {
- if (valueNode == null) {
- return null;
- }
- try {
- return new ObjectMapper().reader(List.class).readValue(valueNode);
- } catch (Exception e) {
- throw new IllegalStateException(e);
- }
- }
-
- @Override
- public Row getRow() {
- return _row;
- }
-
- @Override
- public void close() {
- super.close();
- _streamingViewResult.close();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbInsertionBuilder.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbInsertionBuilder.java b/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbInsertionBuilder.java
deleted file mode 100644
index 7b5f298..0000000
--- a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbInsertionBuilder.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * 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.couchdb;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.ektorp.CouchDbConnector;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.insert.AbstractRowInsertionBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-
-final class CouchDbInsertionBuilder extends AbstractRowInsertionBuilder<CouchDbUpdateCallback> {
-
- public CouchDbInsertionBuilder(CouchDbUpdateCallback updateCallback, Table table) {
- super(updateCallback, table);
- }
-
- @Override
- public void execute() throws MetaModelException {
- Table table = getTable();
- String name = table.getName();
-
- Object[] values = getValues();
- Column[] columns = getColumns();
- Map<String, Object> map = new HashMap<String, Object>();
- for (int i = 0; i < columns.length; i++) {
- Column column = columns[i];
- if (isSet(column)) {
- map.put(column.getName(), values[i]);
- }
- }
-
- CouchDbConnector connector = getUpdateCallback().getConnector(name);
- connector.addToBulkBuffer(map);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbRowDeletionBuilder.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbRowDeletionBuilder.java b/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbRowDeletionBuilder.java
deleted file mode 100644
index fe0fc66..0000000
--- a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbRowDeletionBuilder.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * 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.couchdb;
-
-import java.util.List;
-
-import org.ektorp.CouchDbConnector;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.delete.AbstractRowDeletionBuilder;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.schema.Table;
-
-final class CouchDbRowDeletionBuilder extends AbstractRowDeletionBuilder {
-
- private final CouchDbUpdateCallback _updateCallback;
-
- public CouchDbRowDeletionBuilder(CouchDbUpdateCallback updateCallback, Table table) {
- super(table);
- _updateCallback = updateCallback;
- }
-
- @Override
- public void execute() throws MetaModelException {
- Table table = getTable();
- List<FilterItem> whereItems = getWhereItems();
-
- CouchDbConnector connector = _updateCallback.getConnector(table.getName());
- CouchDbDataContext dataContext = _updateCallback.getDataContext();
-
- DataSet dataSet = dataContext.query().from(table)
- .select(CouchDbDataContext.FIELD_ID, CouchDbDataContext.FIELD_REV).where(whereItems).execute();
- try {
- while (dataSet.next()) {
- Row row = dataSet.getRow();
- String id = (String) row.getValue(0);
- String revision = (String) row.getValue(1);
- connector.delete(id, revision);
- }
- } finally {
- dataSet.close();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbRowUpdationBuilder.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbRowUpdationBuilder.java b/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbRowUpdationBuilder.java
deleted file mode 100644
index 15a4298..0000000
--- a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbRowUpdationBuilder.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/**
- * 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.couchdb;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.ektorp.CouchDbConnector;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.AbstractRowUpdationBuilder;
-
-final class CouchDbRowUpdationBuilder extends AbstractRowUpdationBuilder {
-
- private final CouchDbUpdateCallback _updateCallback;
-
- public CouchDbRowUpdationBuilder(CouchDbUpdateCallback updateCallback, Table table) {
- super(table);
- _updateCallback = updateCallback;
- }
-
- @Override
- public void execute() throws MetaModelException {
- final Table table = getTable();
- final CouchDbConnector connector = _updateCallback.getConnector(table.getName());
-
- // create a map which will act as a prototype for updated objects
- final Map<String, Object> prototype = new HashMap<String, Object>();
- final Column[] columns = getColumns();
- final Object[] values = getValues();
- for (int i = 0; i < columns.length; i++) {
- final Column column = columns[i];
- if (isSet(column)) {
- final String columnName = column.getName();
- final Object value = values[i];
- prototype.put(columnName, value);
- }
- }
-
- final CouchDbDataContext dc = _updateCallback.getDataContext();
- final DataSet dataSet = dc.query().from(table).select(table.getColumns()).where(getWhereItems()).execute();
- try {
- while (dataSet.next()) {
- final Map<String, Object> map = new HashMap<String, Object>(prototype);
- final Row row = dataSet.getRow();
- for (Column column : table.getColumns()) {
- if (!map.containsKey(column.getName())) {
- map.put(column.getName(), row.getValue(column));
- }
- }
-
- // copy the prototype and set the not-updated values
- connector.update(map);
- }
- } finally {
- dataSet.close();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbTableCreationBuilder.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbTableCreationBuilder.java b/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbTableCreationBuilder.java
deleted file mode 100644
index df00880..0000000
--- a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbTableCreationBuilder.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- * 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.couchdb;
-
-import org.ektorp.CouchDbInstance;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.create.AbstractTableCreationBuilder;
-import org.eobjects.metamodel.schema.ColumnType;
-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.Table;
-
-final class CouchDbTableCreationBuilder extends AbstractTableCreationBuilder<CouchDbUpdateCallback> {
-
- public CouchDbTableCreationBuilder(CouchDbUpdateCallback updateCallback, Schema schema, String name) {
- super(updateCallback, schema, name);
- }
-
- @Override
- public Table execute() throws MetaModelException {
- MutableTable table = getTable();
-
- String name = table.getName();
-
- CouchDbInstance instance = getUpdateCallback().getDataContext().getCouchDbInstance();
- instance.createDatabase(name);
-
- addMandatoryColumns(table);
-
- MutableSchema schema = (MutableSchema) table.getSchema();
- schema.addTable(table);
-
- return table;
- }
-
- /**
- * Verifies, and adds if nescesary, the two mandatory columns: _id and _rev.
- *
- * @param table
- */
- public static void addMandatoryColumns(MutableTable table) {
- // add or correct ID column
- {
- MutableColumn idColumn = (MutableColumn) table.getColumnByName(CouchDbDataContext.FIELD_ID);
- if (idColumn == null) {
- idColumn = new MutableColumn(CouchDbDataContext.FIELD_ID, ColumnType.VARCHAR, table, 0, false);
- table.addColumn(0, idColumn);
- }
- idColumn.setPrimaryKey(true);
- }
-
- if (table.getColumnByName(CouchDbDataContext.FIELD_REV) == null) {
- table.addColumn(1, new MutableColumn(CouchDbDataContext.FIELD_REV, ColumnType.VARCHAR, table, 1, false));
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbTableDropBuilder.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbTableDropBuilder.java b/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbTableDropBuilder.java
deleted file mode 100644
index 91297aa..0000000
--- a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbTableDropBuilder.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * 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.couchdb;
-
-import org.ektorp.CouchDbInstance;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.drop.AbstractTableDropBuilder;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.Table;
-
-final class CouchDbTableDropBuilder extends AbstractTableDropBuilder {
-
- private final CouchDbUpdateCallback _updateCallback;
-
- public CouchDbTableDropBuilder(CouchDbUpdateCallback updateCallback, Table table) {
- super(table);
- _updateCallback = updateCallback;
- }
-
- @Override
- public void execute() throws MetaModelException {
- CouchDbInstance instance = _updateCallback.getDataContext().getCouchDbInstance();
- Table table = getTable();
- MutableSchema schema = (MutableSchema) table.getSchema();
- schema.removeTable(table);
-
- instance.deleteDatabase(table.getName());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbUpdateCallback.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbUpdateCallback.java b/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbUpdateCallback.java
deleted file mode 100644
index e96b7bc..0000000
--- a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/CouchDbUpdateCallback.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/**
- * 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.couchdb;
-
-import java.io.Closeable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.ektorp.CouchDbConnector;
-import org.ektorp.CouchDbInstance;
-import org.ektorp.DocumentOperationResult;
-import org.eobjects.metamodel.AbstractUpdateCallback;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-final class CouchDbUpdateCallback extends AbstractUpdateCallback implements Closeable {
-
- private static final Logger logger = LoggerFactory.getLogger(CouchDbUpdateCallback.class);
- private final Map<String, CouchDbConnector> _connectors;
-
- public CouchDbUpdateCallback(CouchDbDataContext couchDbDataContext) {
- super(couchDbDataContext);
- _connectors = new HashMap<String, CouchDbConnector>();
- }
-
- @Override
- public CouchDbDataContext getDataContext() {
- return (CouchDbDataContext) super.getDataContext();
- }
-
- @Override
- public boolean isUpdateSupported() {
- return true;
- }
-
- @Override
- public RowUpdationBuilder update(Table table) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException {
- return new CouchDbRowUpdationBuilder(this, table);
- }
-
- @Override
- public boolean isCreateTableSupported() {
- return true;
- }
-
- @Override
- public TableCreationBuilder createTable(Schema schema, String name) throws IllegalArgumentException,
- IllegalStateException {
- return new CouchDbTableCreationBuilder(this, schema, name);
- }
-
- @Override
- public boolean isDropTableSupported() {
- return true;
- }
-
- @Override
- public TableDropBuilder dropTable(Table table) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException {
- return new CouchDbTableDropBuilder(this, table);
- }
-
- @Override
- public RowInsertionBuilder insertInto(Table table) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException {
- return new CouchDbInsertionBuilder(this, table);
- }
-
- @Override
- public boolean isDeleteSupported() {
- return true;
- }
-
- @Override
- public RowDeletionBuilder deleteFrom(Table table) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException {
- return new CouchDbRowDeletionBuilder(this, table);
- }
-
- @Override
- public void close() {
- Collection<CouchDbConnector> connectorSet = _connectors.values();
- for (CouchDbConnector connector : connectorSet) {
- List<String> errornousResultsDescriptions = new ArrayList<String>();
- List<DocumentOperationResult> results = connector.flushBulkBuffer();
- for (DocumentOperationResult result : results) {
- if (result.isErroneous()) {
- String id = result.getId();
- String error = result.getError();
- String reason = result.getReason();
- String revision = result.getRevision();
- logger.error("Error occurred while flushing bulk buffer: {}, id: {}, revision: {}, reason: {}",
- new Object[] { error, id, revision, reason });
- errornousResultsDescriptions.add(error);
- }
- }
-
- if (!errornousResultsDescriptions.isEmpty()) {
- throw new MetaModelException(errornousResultsDescriptions.size() + " out of " + results.size()
- + " operations in bulk was errornous: " + errornousResultsDescriptions);
- }
- }
- }
-
- public CouchDbConnector getConnector(String name) {
- CouchDbConnector connector = _connectors.get(name);
- if (connector == null) {
- CouchDbInstance instance = getDataContext().getCouchDbInstance();
- connector = instance.createConnector(name, false);
- _connectors.put(name, connector);
- }
- return connector;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/package-info.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/package-info.java b/couchdb/src/main/java/org/eobjects/metamodel/couchdb/package-info.java
deleted file mode 100644
index 340fd98..0000000
--- a/couchdb/src/main/java/org/eobjects/metamodel/couchdb/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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.
- */
-/**
- * Module package for CouchDB support
- */
-package org.eobjects.metamodel.couchdb;
-
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/test/java/org/apache/metamodel/couchdb/CouchDbDataContextTest.java
----------------------------------------------------------------------
diff --git a/couchdb/src/test/java/org/apache/metamodel/couchdb/CouchDbDataContextTest.java b/couchdb/src/test/java/org/apache/metamodel/couchdb/CouchDbDataContextTest.java
new file mode 100644
index 0000000..403a64c
--- /dev/null
+++ b/couchdb/src/test/java/org/apache/metamodel/couchdb/CouchDbDataContextTest.java
@@ -0,0 +1,354 @@
+/**
+ * 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.couchdb;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.ektorp.CouchDbConnector;
+import org.ektorp.DbAccessException;
+import org.ektorp.http.HttpClient;
+import org.ektorp.http.StdHttpClient;
+import org.ektorp.impl.StdCouchDbInstance;
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.drop.DropTable;
+import org.eobjects.metamodel.insert.InsertInto;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.SimpleTableDef;
+
+public class CouchDbDataContextTest extends TestCase {
+
+ private static final String TEST_DATABASE_NAME = "eobjects_metamodel_test";
+
+ private boolean serverAvailable;
+
+ private HttpClient httpClient;
+ private StdCouchDbInstance couchDbInstance;
+ private CouchDbConnector connector;
+ private SimpleTableDef predefinedTableDef;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ httpClient = new StdHttpClient.Builder().host("localhost").build();
+
+ // set up a simple database
+ couchDbInstance = new StdCouchDbInstance(httpClient);
+
+ try {
+ if (couchDbInstance.getAllDatabases().contains(TEST_DATABASE_NAME)) {
+ throw new IllegalStateException("Couch DB instance already has a database called " + TEST_DATABASE_NAME);
+ }
+ connector = couchDbInstance.createConnector(TEST_DATABASE_NAME, true);
+ System.out.println("Running CouchDB integration tests");
+ serverAvailable = true;
+ } catch (DbAccessException e) {
+ System.out.println("!!! WARNING: Skipping CouchDB tests because local server is not available");
+ e.printStackTrace();
+ serverAvailable = false;
+ }
+
+ final String[] columnNames = new String[] { "name", "gender", "age" };
+ final ColumnType[] columnTypes = new ColumnType[] { ColumnType.VARCHAR, ColumnType.CHAR, ColumnType.INTEGER };
+ predefinedTableDef = new SimpleTableDef(TEST_DATABASE_NAME, columnNames, columnTypes);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ connector = null;
+
+ if (serverAvailable) {
+ couchDbInstance.deleteDatabase(TEST_DATABASE_NAME);
+ }
+
+ httpClient.shutdown();
+ }
+
+ public void testWorkingWithMapsAndLists() throws Exception {
+ if (!serverAvailable) {
+ return;
+ }
+
+ connector = couchDbInstance.createConnector("test_table_map_and_list", true);
+
+ final CouchDbDataContext dc = new CouchDbDataContext(couchDbInstance, new SimpleTableDef("test_table_map_and_list",
+ new String[] { "id", "foo", "bar" }, new ColumnType[] { ColumnType.INTEGER, ColumnType.MAP, ColumnType.LIST }));
+ Table table = null;
+ try {
+ table = dc.getTableByQualifiedLabel("test_table_map_and_list");
+ Map<String, Object> exampleMap = new LinkedHashMap<String, Object>();
+ exampleMap.put("hello", Arrays.asList("world", "welt", "verden"));
+ exampleMap.put("foo", "bar");
+
+ List<Map<String, Object>> exampleList = new ArrayList<Map<String, Object>>();
+ exampleList.add(new LinkedHashMap<String, Object>());
+ Map<String, Object> exampleMap2 = new LinkedHashMap<String, Object>();
+ exampleMap2.put("meta", "model");
+ exampleMap2.put("couch", "db");
+ exampleList.add(exampleMap2);
+
+ dc.executeUpdate(new InsertInto(table).value("id", 1).value("foo", exampleMap).value("bar", exampleList));
+
+ DataSet ds = dc.query().from(table).select("id","foo","bar").execute();
+ assertTrue(ds.next());
+ Row row = ds.getRow();
+ assertFalse(ds.next());
+ ds.close();
+
+ assertEquals(
+ "Row[values=[1, {hello=[world, welt, verden], foo=bar}, [{}, {meta=model, couch=db}]]]",
+ row.toString());
+ assertTrue(row.getValue(0) instanceof Integer);
+ assertTrue(row.getValue(1) instanceof Map);
+ assertTrue(row.getValue(2) instanceof List);
+
+ } finally {
+ dc.executeUpdate(new DropTable(table));
+ }
+
+ }
+
+ public void testCreateUpdateDeleteScenario() throws Exception {
+ if (!serverAvailable) {
+ return;
+ }
+
+ final CouchDbDataContext dc = new CouchDbDataContext(couchDbInstance);
+
+ // first delete the manually created database!
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.dropTable(TEST_DATABASE_NAME).execute();
+ }
+ });
+
+ assertNull(dc.getDefaultSchema().getTableByName(TEST_DATABASE_NAME));
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ Table table = callback.createTable(dc.getDefaultSchema(), TEST_DATABASE_NAME).withColumn("foo")
+ .ofType(ColumnType.VARCHAR).withColumn("greeting").ofType(ColumnType.VARCHAR).execute();
+ assertEquals("[_id, _rev, foo, greeting]", Arrays.toString(table.getColumnNames()));
+ }
+ });
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.insertInto(TEST_DATABASE_NAME).value("foo", "bar").value("greeting", "hello").execute();
+ callback.insertInto(TEST_DATABASE_NAME).value("foo", "baz").value("greeting", "hi").execute();
+ }
+ });
+
+ DataSet ds = dc.query().from(TEST_DATABASE_NAME).select("_id", "foo", "greeting").execute();
+ assertTrue(ds.next());
+ assertNotNull(ds.getRow().getValue(0));
+ assertEquals("bar", ds.getRow().getValue(1));
+ assertEquals("hello", ds.getRow().getValue(2));
+ assertTrue(ds.next());
+ assertNotNull(ds.getRow().getValue(0));
+ assertEquals("baz", ds.getRow().getValue(1));
+ assertEquals("hi", ds.getRow().getValue(2));
+ assertFalse(ds.next());
+ ds.close();
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.update(TEST_DATABASE_NAME).value("greeting", "howdy").where("foo").isEquals("baz").execute();
+
+ callback.update(TEST_DATABASE_NAME).value("foo", "foo").where("foo").isEquals("bar").execute();
+ }
+ });
+
+ ds = dc.query().from(TEST_DATABASE_NAME).select("_id", "foo", "greeting").execute();
+ assertTrue(ds.next());
+ assertNotNull(ds.getRow().getValue(0));
+ assertEquals("foo", ds.getRow().getValue(1));
+ assertEquals("hello", ds.getRow().getValue(2));
+ assertTrue(ds.next());
+ assertNotNull(ds.getRow().getValue(0));
+ assertEquals("baz", ds.getRow().getValue(1));
+ assertEquals("howdy", ds.getRow().getValue(2));
+ assertFalse(ds.next());
+ ds.close();
+ }
+
+ public void testBasicQuery() throws Exception {
+ if (!serverAvailable) {
+ return;
+ }
+
+ // insert a few records
+ {
+ HashMap<String, Object> map;
+
+ map = new HashMap<String, Object>();
+ map.put("name", "John Doe");
+ map.put("age", 30);
+ connector.create(map);
+
+ map = new HashMap<String, Object>();
+ map.put("name", "Jane Doe");
+ map.put("gender", 'F');
+ connector.create(map);
+ }
+
+ // create datacontext using detected schema
+ SimpleTableDef tableDef = CouchDbDataContext.detectTable(connector);
+ CouchDbDataContext dc = new CouchDbDataContext(couchDbInstance, tableDef);
+
+ // verify schema and execute query
+ Schema schema = dc.getMainSchema();
+ assertEquals("[eobjects_metamodel_test]", Arrays.toString(schema.getTableNames()));
+
+ assertEquals("[_id, _rev, age, gender, name]",
+ Arrays.toString(schema.getTableByName(TEST_DATABASE_NAME).getColumnNames()));
+ Column idColumn = schema.getTableByName(TEST_DATABASE_NAME).getColumnByName("_id");
+ assertEquals("Column[name=_id,columnNumber=0,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]",
+ idColumn.toString());
+ assertTrue(idColumn.isPrimaryKey());
+
+ assertEquals("Column[name=_rev,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]", schema
+ .getTableByName(TEST_DATABASE_NAME).getColumnByName("_rev").toString());
+
+ DataSet ds;
+
+ ds = dc.query().from(TEST_DATABASE_NAME).select("name").and("age").execute();
+ assertTrue(ds.next());
+ assertEquals("Row[values=[John Doe, 30]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[Jane Doe, null]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ ds.close();
+
+ ds = dc.query().from(TEST_DATABASE_NAME).select("name").and("gender").where("age").isNull().execute();
+ assertTrue(ds.next());
+ assertEquals("Row[values=[Jane Doe, F]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ ds.close();
+ }
+
+ public void testFirstRowAndLastRow() throws Exception {
+ if (!serverAvailable) {
+ return;
+ }
+
+ // insert a few records
+ {
+ HashMap<String, Object> map;
+
+ map = new HashMap<String, Object>();
+ map.put("name", "John Doe");
+ map.put("age", 30);
+ connector.create(map);
+
+ map = new HashMap<String, Object>();
+ map.put("name", "Jane Doe");
+ map.put("gender", 'F');
+ connector.create(map);
+ }
+
+ // create datacontext using detected schema
+ SimpleTableDef tableDef = CouchDbDataContext.detectTable(connector);
+ CouchDbDataContext dc = new CouchDbDataContext(couchDbInstance, tableDef);
+
+ DataSet ds1 = dc.query().from(TEST_DATABASE_NAME).select("name").and("age").firstRow(2).execute();
+ DataSet ds2 = dc.query().from(TEST_DATABASE_NAME).select("name").and("age").maxRows(1).execute();
+
+ assertTrue("Class: " + ds1.getClass().getName(), ds1 instanceof CouchDbDataSet);
+ assertTrue("Class: " + ds2.getClass().getName(), ds2 instanceof CouchDbDataSet);
+
+ assertTrue(ds1.next());
+ assertTrue(ds2.next());
+
+ final Row row1 = ds1.getRow();
+ final Row row2 = ds2.getRow();
+
+ assertFalse(ds1.next());
+ assertFalse(ds2.next());
+
+ assertEquals("Row[values=[Jane Doe, null]]", row1.toString());
+ assertEquals("Row[values=[John Doe, 30]]", row2.toString());
+
+ ds1.close();
+ ds2.close();
+ }
+
+ public void testInsert() throws Exception {
+ if (!serverAvailable) {
+ return;
+ }
+
+ // create datacontext using predefined table def
+ CouchDbDataContext dc = new CouchDbDataContext(httpClient, predefinedTableDef);
+ Table table = dc.getTableByQualifiedLabel(TEST_DATABASE_NAME);
+ assertNotNull(table);
+
+ assertEquals("[_id, _rev, name, gender, age]", Arrays.toString(table.getColumnNames()));
+
+ DataSet ds;
+
+ // assert not rows in DB
+ ds = dc.query().from(TEST_DATABASE_NAME).selectCount().execute();
+ assertTrue(ds.next());
+ assertEquals(0, ((Number) ds.getRow().getValue(0)).intValue());
+ assertFalse(ds.next());
+ ds.close();
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.insertInto(TEST_DATABASE_NAME).value("name", "foo").value("gender", 'M').execute();
+ callback.insertInto(TEST_DATABASE_NAME).value("name", "bar").value("age", 32).execute();
+ }
+ });
+
+ // now count should be 2
+ ds = dc.query().from(TEST_DATABASE_NAME).selectCount().execute();
+ assertTrue(ds.next());
+ assertEquals(2, ((Number) ds.getRow().getValue(0)).intValue());
+ assertFalse(ds.next());
+ ds.close();
+
+ ds = dc.query().from(TEST_DATABASE_NAME).select("name", "gender", "age").execute();
+ assertTrue(ds.next());
+ assertEquals("Row[values=[foo, M, null]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[bar, null, 32]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ ds.close();
+ }
+}
[36/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/data/DataSetHeader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/DataSetHeader.java b/core/src/main/java/org/eobjects/metamodel/data/DataSetHeader.java
deleted file mode 100644
index 186c7b9..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/DataSetHeader.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * 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/eobjects/metamodel/data/DataSetIterator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/DataSetIterator.java b/core/src/main/java/org/eobjects/metamodel/data/DataSetIterator.java
deleted file mode 100644
index 82481c5..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/DataSetIterator.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * 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/eobjects/metamodel/data/DataSetTableModel.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/DataSetTableModel.java b/core/src/main/java/org/eobjects/metamodel/data/DataSetTableModel.java
deleted file mode 100644
index 53fb2be..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/DataSetTableModel.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- * 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/eobjects/metamodel/data/DefaultRow.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/DefaultRow.java b/core/src/main/java/org/eobjects/metamodel/data/DefaultRow.java
deleted file mode 100644
index 3fee3b8..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/DefaultRow.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/**
- * 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/eobjects/metamodel/data/EmptyDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/EmptyDataSet.java b/core/src/main/java/org/eobjects/metamodel/data/EmptyDataSet.java
deleted file mode 100644
index 12d3caf..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/EmptyDataSet.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * 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/eobjects/metamodel/data/FilteredDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/FilteredDataSet.java b/core/src/main/java/org/eobjects/metamodel/data/FilteredDataSet.java
deleted file mode 100644
index ca406ed..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/FilteredDataSet.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * 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/eobjects/metamodel/data/FirstRowDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/FirstRowDataSet.java b/core/src/main/java/org/eobjects/metamodel/data/FirstRowDataSet.java
deleted file mode 100644
index 6662eb5..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/FirstRowDataSet.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * 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/eobjects/metamodel/data/IRowFilter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/IRowFilter.java b/core/src/main/java/org/eobjects/metamodel/data/IRowFilter.java
deleted file mode 100644
index ac46eea..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/IRowFilter.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * 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/eobjects/metamodel/data/InMemoryDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/InMemoryDataSet.java b/core/src/main/java/org/eobjects/metamodel/data/InMemoryDataSet.java
deleted file mode 100644
index 7e21412..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/InMemoryDataSet.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/**
- * 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/eobjects/metamodel/data/MaxRowsDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/MaxRowsDataSet.java b/core/src/main/java/org/eobjects/metamodel/data/MaxRowsDataSet.java
deleted file mode 100644
index adecaed..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/MaxRowsDataSet.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * 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/eobjects/metamodel/data/Row.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/Row.java b/core/src/main/java/org/eobjects/metamodel/data/Row.java
deleted file mode 100644
index 47e95c0..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/Row.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/**
- * 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
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/data/RowBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/RowBuilder.java b/core/src/main/java/org/eobjects/metamodel/data/RowBuilder.java
deleted file mode 100644
index b7bce06..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/RowBuilder.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/**
- * 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 org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
-
-/**
- * Abstract interface for objects that build rows, either for eg. insert or
- * update purposes.
- *
- * @see RowInsertionBuilder
- * @see RowUpdationBuilder
- *
- * @param <RB>
- * the RowBuilder subtype, used for cascading return values
- */
-public interface RowBuilder<RB extends RowBuilder<?>> {
-
- /**
- * Gets the table that this row builder pertains to.
- *
- * @return the table that this row builder pertains to.
- */
- public Table getTable();
-
- /**
- * Sets the value of a column, by column index
- *
- * @param columnIndex
- * @param value
- * @return
- */
- public RB value(int columnIndex, Object value);
-
- /**
- * Sets the value of a column, by column index
- *
- * @param columnIndex
- * @param value
- * @param style
- * @return
- */
- public RB value(int columnIndex, Object value, Style style);
-
- /**
- * Sets the value of a column
- *
- * @param column
- * @param value
- * @return
- */
- public RB value(Column column, Object value);
-
- /**
- * Sets the value of a column
- *
- * @param column
- * @param value
- * @param style
- * @return
- */
- public RB value(Column column, Object value, Style style);
-
- /**
- * Sets the value of a column, by column name
- *
- * @param columnName
- * @param value
- * @return
- */
- public RB value(String columnName, Object value);
-
- /**
- * Sets the value and the style of this value of a column, by column name
- *
- * @param columnName
- * @param value
- * @param style
- * @return
- */
- public RB value(String columnName, Object value, Style style);
-
- /**
- * Gets the built record represented as a {@link Row} object.
- *
- * @return a {@link Row} object as it will appear if committed and queried.
- */
- public Row toRow();
-
- /**
- * Determines if a column's value has been explicitly specified or not. This
- * can be used to tell explicit NULL values apart from just unspecified
- * values in a statement.
- *
- * @param column
- * the column to check
- * @return true if the column's value has been set, or false if not
- */
- public boolean isSet(Column column);
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/data/RowPublisher.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/RowPublisher.java b/core/src/main/java/org/eobjects/metamodel/data/RowPublisher.java
deleted file mode 100644
index fe7678b..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/RowPublisher.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * 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;
-
-/**
- * An object on which a push-style data reader can publish records to a
- * {@link RowPublisherDataSet}. The {@link RowPublisher} acts as a buffer
- * between the publishing and consuming part of a dataset scenario. It will
- * manage a queue of rows and will block calls if the queue is not being
- * read/emptied as fast as it is being filled.
- *
- * @author Kasper Sørensen
- */
-public interface RowPublisher {
-
- /**
- * Publishes a row
- *
- * @param row
- * the {@link Row} to publish.
- * @return a boolean indicating whether or not the consumer is still
- * interested in more rows.
- */
- public boolean publish(Row row);
-
- /**
- * Publishes a row, represented by an array of values.
- *
- * @param values
- * the objects to convert to a row.
- * @return a boolean indicating whether or not the consumer is still
- * interested in more rows.
- */
- public boolean publish(Object[] values);
-
- /**
- * Publishes a row, represented by an array of values and an array of
- * styles.
- *
- * @param values
- * the objects to convert to a row.
- * @param styles
- * the styles that correspond to the values.
- * @return a boolean indicating whether or not the consumer is still
- * interested in more rows.
- */
- public boolean publish(Object[] values, Style[] styles);
-
- /**
- * Invoked to indicate to the consumer that no more rows will be published.
- */
- public void finished();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/data/RowPublisherDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/RowPublisherDataSet.java b/core/src/main/java/org/eobjects/metamodel/data/RowPublisherDataSet.java
deleted file mode 100644
index addbeae..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/RowPublisherDataSet.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- * 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 org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.util.Action;
-import org.eobjects.metamodel.util.SharedExecutorService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Abstract {@link DataSet} implementation for use in scenarios where a
- * pull-oriented style of reading data is not supported. This implementation
- * instead allows a publshing action to publish rows to the dataset in a
- * blocking manner, and thereby to adapt without having to load all rows into
- * memory.
- *
- * @author Kasper Sørensen
- */
-public final class RowPublisherDataSet extends AbstractDataSet {
-
- private static final Logger logger = LoggerFactory
- .getLogger(RowPublisherDataSet.class);
-
- private final int _maxRows;
- private final Action<RowPublisher> _publishAction;
- private RowPublisherImpl _rowPublisher;
- private boolean _closed;
-
- public RowPublisherDataSet(SelectItem[] selectItems, int maxRows,
- Action<RowPublisher> publishAction) {
- super(selectItems);
- _maxRows = maxRows;
- _publishAction = publishAction;
- _closed = false;
- }
-
- public int getMaxRows() {
- return _maxRows;
- }
-
- @Override
- public void close() {
- super.close();
- _closed = true;
- _rowPublisher.finished();
- }
-
- @Override
- protected void finalize() throws Throwable {
- super.finalize();
- if (!_closed) {
- logger.warn(
- "finalize() invoked, but DataSet is not closed. Invoking close() on {}",
- this);
- close();
- }
- }
-
- @Override
- public boolean next() {
- if (_rowPublisher == null) {
- // first time, create the publisher
- _rowPublisher = new RowPublisherImpl(this);
- logger.info("Starting separate thread for publishing action: {}",
- _publishAction);
- Runnable runnable = new Runnable() {
- public void run() {
- boolean successful = false;
- try {
- _publishAction.run(_rowPublisher);
- logger.debug("Publshing action finished!");
- successful = true;
- } catch (Exception e) {
- _rowPublisher.failed(e);
- }
- if (successful) {
- _rowPublisher.finished();
- }
- };
- };
- SharedExecutorService.get().submit(runnable);
- }
- return _rowPublisher.next();
- }
-
- @Override
- public Row getRow() {
- if (_rowPublisher == null) {
- return null;
- }
- return _rowPublisher.getRow();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/data/RowPublisherImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/RowPublisherImpl.java b/core/src/main/java/org/eobjects/metamodel/data/RowPublisherImpl.java
deleted file mode 100644
index 6fe2a0d..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/RowPublisherImpl.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/**
- * 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.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.eobjects.metamodel.MetaModelException;
-
-/**
- * Row publisher implementation used by {@link RowPublisherDataSet}.
- *
- * @author Kasper Sørensen
- */
-class RowPublisherImpl implements RowPublisher {
-
- public static final int BUFFER_SIZE = 20;
-
- private final RowPublisherDataSet _dataSet;
- private final BlockingQueue<Row> _queue;
- private final AtomicBoolean _finished;
- private final AtomicInteger _rowCount;
- private volatile Row _currentRow;
- private volatile Exception _error;
-
- public RowPublisherImpl(RowPublisherDataSet dataSet) {
- _dataSet = dataSet;
- _queue = new ArrayBlockingQueue<Row>(BUFFER_SIZE);
- _finished = new AtomicBoolean(false);
- _rowCount = new AtomicInteger();
- }
-
- @Override
- public boolean publish(Row row) {
- if (_finished.get()) {
- return false;
- }
- while (!offer(row)) {
- if (_finished.get()) {
- return false;
- }
- // wait one more cycle
- }
- int rowCount = _rowCount.incrementAndGet();
- if (_dataSet.getMaxRows() > 0 && rowCount >= _dataSet.getMaxRows()) {
- finished();
- return false;
- }
- return true;
- }
-
- private boolean offer(Row row) {
- try {
- return _queue.offer(row, 1000, TimeUnit.MICROSECONDS);
- } catch (InterruptedException e) {
- // do nothing
- return false;
- }
- }
-
- @Override
- public boolean publish(Object[] values) {
- Row row = new DefaultRow(_dataSet.getHeader(), values);
- return publish(row);
- }
-
- @Override
- public boolean publish(Object[] values, Style[] styles) {
- Row row = new DefaultRow(_dataSet.getHeader(), values, styles);
- return publish(row);
- }
-
- @Override
- public void finished() {
- _finished.set(true);
- }
-
- public boolean next() {
- if (_queue.isEmpty() && _finished.get()) {
- return false;
- }
- try {
- _currentRow = _queue.poll(1000, TimeUnit.MILLISECONDS);
- } catch (InterruptedException e) {
- // do nothing
- }
- if (_currentRow != null) {
- return true;
- }
- if (_error != null) {
- if (_error instanceof RuntimeException) {
- throw (RuntimeException) _error;
- }
- throw new MetaModelException(_error);
- }
- // "busy" (1 second) wait
- return next();
- }
-
- public Row getRow() {
- return _currentRow;
- }
-
- public void failed(Exception error) {
- _error = error;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/data/SimpleDataSetHeader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/SimpleDataSetHeader.java b/core/src/main/java/org/eobjects/metamodel/data/SimpleDataSetHeader.java
deleted file mode 100644
index 1e7e461..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/SimpleDataSetHeader.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/**
- * 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.MetaModelHelper;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-
-/**
- * Simple implementation of {@link DataSetHeader} which does no magic to improve
- * performance.
- *
- * Note that except for datasets with very few records, the
- * {@link CachingDataSetHeader} is preferred.
- */
-public class SimpleDataSetHeader implements DataSetHeader {
-
- private static final long serialVersionUID = 1L;
-
- private final List<SelectItem> _items;
-
- public SimpleDataSetHeader(List<SelectItem> items) {
- _items = items;
- }
-
- public SimpleDataSetHeader(SelectItem[] selectItems) {
- this(Arrays.asList(selectItems));
- }
-
- public SimpleDataSetHeader(Column[] columns) {
- this(MetaModelHelper.createSelectItems(columns));
- }
-
- @Override
- public final SelectItem[] getSelectItems() {
- return _items.toArray(new SelectItem[_items.size()]);
- }
-
- @Override
- public final int size() {
- return _items.size();
- }
-
- @Override
- public SelectItem getSelectItem(int index) {
- return _items.get(index);
- }
-
- @Override
- public int indexOf(Column column) {
- if (column == null) {
- return -1;
- }
- return indexOf(new SelectItem(column));
- }
-
- @Override
- public int indexOf(SelectItem item) {
- if (item == null) {
- return -1;
- }
- int i = 0;
- for (SelectItem selectItem : _items) {
- if (item == selectItem) {
- return i;
- }
- i++;
- }
-
- i = 0;
- for (SelectItem selectItem : _items) {
- if (item.equalsIgnoreAlias(selectItem, true)) {
- return i;
- }
- i++;
- }
-
- i = 0;
- for (SelectItem selectItem : _items) {
- if (item.equalsIgnoreAlias(selectItem)) {
- return i;
- }
- i++;
- }
-
- return -1;
- }
-
- @Override
- public final int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((_items == null) ? 0 : _items.hashCode());
- 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;
- SimpleDataSetHeader other = (SimpleDataSetHeader) obj;
- if (_items == null) {
- if (other._items != null)
- return false;
- } else if (!_items.equals(other._items))
- return false;
- return true;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/data/Style.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/Style.java b/core/src/main/java/org/eobjects/metamodel/data/Style.java
deleted file mode 100644
index d1c04a5..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/Style.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/**
- * 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;
-
-/**
- * A {@link Style} represents the visual presentation ('styling') attributes of
- * a value in a {@link Row}. Styling can be used to highlight special values and
- * format the cells of eg. a spreadsheet.
- *
- * Most datastores don't support styling, but some do. Those who do not support
- * it will just omit it.
- *
- * Creation of {@link Style} objects is handled by the {@link StyleBuilder}
- * class.
- *
- * @author Kasper Sørensen
- */
-public interface Style extends Serializable {
-
- /**
- * A style object used for values without styling, "unstyled" values or
- * "neutrally styled" values.
- */
- public static final Style NO_STYLE = new StyleImpl();
-
- /**
- * Represents the text alignment of a value.
- *
- * @author Kasper Sørensen
- */
- public static enum TextAlignment {
- LEFT, RIGHT, CENTER, JUSTIFY
- }
-
- /**
- * Represents a color used for value highlighting.
- *
- * Creation of {@link Color} objects is handled by the static
- * {@link StyleBuilder}.createColor(...) methods.
- *
- * @author Kasper Sørensen
- */
- public static interface Color extends Serializable {
-
- public short getRed();
-
- public short getGreen();
-
- public short getBlue();
- }
-
- /**
- * Represents a unit of sizing elements (eg. fonts) in a {@link Style}.
- *
- * @author Kasper Sørensen
- */
- public static enum SizeUnit {
- /**
- * Point unit
- */
- PT,
-
- /**
- * Pixel unit
- */
- PX,
-
- /**
- * Percent unit
- */
- PERCENT
- }
-
- /**
- * Determines whether or not the value is written in bold text.
- *
- * @return true if text is bold
- */
- public boolean isBold();
-
- /**
- * Determines whether or not the value is written in italic text.
- *
- * @return true if text is italic
- */
- public boolean isItalic();
-
- /**
- * Determines whether or not the value is written with an underline
- *
- * @return true if text is underlined
- */
- public boolean isUnderline();
-
- /**
- * Gets the font size, or null if font size is unspecified.
- *
- * @see SizeUnit
- *
- * @return an Integer, or null
- */
- public Integer getFontSize();
-
- /**
- * Gets the unit of the font size.
- *
- * @return an enum representing the font size unit used.
- */
- public SizeUnit getFontSizeUnit();
-
- /**
- * Gets the text alignment, or null if text alignment is unspecified.
- *
- * @return a TextAlignment value, or null
- */
- public TextAlignment getAlignment();
-
- /**
- * Gets the foreground (text) color, or null if the color is unspecified.
- *
- * @return a Color object representing the foreground color
- */
- public Color getForegroundColor();
-
- /**
- * Gets the background color, or null if the color is unspecified.
- *
- * @return a Color object representing the background color
- */
- public Color getBackgroundColor();
-
- /**
- * Creates a Cascading Style Sheets (CSS) representation of this style.
- *
- * @return a CSS string
- */
- public String toCSS();
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/data/StyleBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/StyleBuilder.java b/core/src/main/java/org/eobjects/metamodel/data/StyleBuilder.java
deleted file mode 100644
index 65400f7..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/StyleBuilder.java
+++ /dev/null
@@ -1,355 +0,0 @@
-/**
- * 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.Map;
-import java.util.WeakHashMap;
-
-import org.eobjects.metamodel.data.Style.Color;
-import org.eobjects.metamodel.data.Style.SizeUnit;
-import org.eobjects.metamodel.data.Style.TextAlignment;
-import org.eobjects.metamodel.util.EqualsBuilder;
-
-/**
- * Builder class for {@link Style} and related objects, like {@link Color}.
- *
- * @author Kasper Sørensen
- */
-public final class StyleBuilder {
-
- private static final Map<String, Color> _colorCache = new WeakHashMap<String, Color>();
-
- private boolean _bold;
- private boolean _italic;
- private boolean _underline;
- private Integer _fontSize;
- private TextAlignment _alignment;
- private Color _backgroundColor;
- private Color _foregroundColor;
- private SizeUnit _fontSizeUnit;
-
- private final Color _defaultForegroundColor;
- private final Color _defaultBackgroundColor;
-
- /**
- * Constructs a new {@link StyleBuilder} with the default foreground and
- * background colors.
- */
- public StyleBuilder() {
- this(createColor((short) 0, (short) 0, (short) 0), createColor(
- (short) 255, (short) 255, (short) 255));
- }
-
- /**
- * Constructs a new {@link StyleBuilder} with a specified default foreground
- * and background colors. These colors will be disregarded, if posted to the
- * foreground and background methods.
- *
- * @param defaultForegroundColor
- * @param defaultBackgroundColor
- */
- public StyleBuilder(Color defaultForegroundColor,
- Color defaultBackgroundColor) {
- _defaultForegroundColor = defaultForegroundColor;
- _defaultBackgroundColor = defaultBackgroundColor;
- }
-
- /**
- * Resets the state of the built style, which will conceptually match it
- * with {@link Style#NO_STYLE}.
- */
- public void reset() {
- _bold = false;
- _italic = false;
- _underline = false;
- _fontSize = null;
- _alignment = null;
- _backgroundColor = null;
- _foregroundColor = null;
- _fontSizeUnit = null;
- }
-
- /**
- * Creates a {@link Style} object based on the build characteristics.
- *
- * @return a {@link Style} object based on the build characteristics.
- */
- public Style create() {
- StyleImpl style = new StyleImpl(_bold, _italic, _underline, _fontSize,
- _fontSizeUnit, _alignment, _backgroundColor, _foregroundColor);
- if (Style.NO_STYLE.equals(style)) {
- return Style.NO_STYLE;
- }
- return style;
- }
-
- /**
- * Sets the font weight to bold
- *
- * @return the {@link StyleBuilder} self (for cascading method calls)
- */
- public StyleBuilder bold() {
- _bold = true;
- return this;
- }
-
- /**
- * Sets the font style to italic
- *
- * @return the {@link StyleBuilder} self (for cascading method calls)
- */
- public StyleBuilder italic() {
- _italic = true;
- return this;
- }
-
- /**
- * Sets the text decoration to underlined
- *
- * @return the {@link StyleBuilder} self (for cascading method calls)
- */
- public StyleBuilder underline() {
- _underline = true;
- return this;
- }
-
- /**
- * Creates a Color based on a 6-letter RGB hex color code string, eg.
- * "000000" for black and "FFFFFF" for white.
- *
- * @param rgbColorCode
- * a 6-letter RGB hex color code string
- * @return a color representing this color code
- */
- public static Color createColor(String rgbColorCode) {
- assert rgbColorCode.length() == 6;
- String redParth = rgbColorCode.substring(0, 2);
- String greenParth = rgbColorCode.substring(2, 4);
- String blueParth = rgbColorCode.substring(4, 6);
- return createColor(Integer.parseInt(redParth, 16),
- Integer.parseInt(greenParth, 16),
- Integer.parseInt(blueParth, 16));
- }
-
- /**
- * Creates a color based on 3 RGB components, represented as ints
- *
- * @param r
- * @param g
- * @param b
- * @return a color representing the RGB code
- */
- public static Color createColor(int r, int g, int b) {
- return createColor(toRgbComponent(r), toRgbComponent(g),
- toRgbComponent(b));
- }
-
- /**
- * Creates a color based on 3 RGB components, represented as shorts
- *
- * @param r
- * @param g
- * @param b
- * @return a color representing the RGB code
- */
- public static Color createColor(short r, short g, short b) {
- String cacheId = r + "," + g + "," + b;
- Color color = _colorCache.get(cacheId);
- if (color == null) {
- color = new ColorImpl(r, g, b);
- _colorCache.put(cacheId, color);
- }
- return color;
- }
-
- private static short toRgbComponent(int r) {
- if (r < 0) {
- // if eg. a byte was passed as a RGB component
- r = (256 + r);
- }
- if (r > 255) {
- throw new IllegalArgumentException(
- "RGB component cannot be higher than 255");
- }
- return (short) r;
- }
-
- /**
- * Sets the foreground (text) color of the style
- *
- * @param rgbColorCode
- * a 6-letter hex RGB color code, such as FF0000 (red).
- * @return the {@link StyleBuilder} self (for cascading method calls)
- */
- public StyleBuilder foreground(String rgbColorCode) {
- return foreground(createColor(rgbColorCode));
- }
-
- /**
- * Sets the foreground (text) color of the style
- *
- * @param rgb
- * a triplet array of shorts
- * @return the {@link StyleBuilder} self (for cascading method calls)
- */
- public StyleBuilder foreground(short[] rgb) {
- assert rgb.length == 3;
- return foreground(createColor(rgb[0], rgb[1], rgb[2]));
- }
-
- /**
- * Sets the foreground (text) color of the style
- *
- * @param r
- * red amount (0-255)
- * @param g
- * green amount (0-255)
- * @param b
- * blue amount (0-255)
- * @return the {@link StyleBuilder} self (for cascading method calls)
- */
- public StyleBuilder foreground(int r, int g, int b) {
- return foreground(createColor(r, g, b));
- }
-
- /**
- * Sets the foreground (text) color of the style
- *
- * @param color
- * the color to use
- * @return the {@link StyleBuilder} self (for cascading method calls)
- */
- public StyleBuilder foreground(Color color) {
- if (EqualsBuilder.equals(_defaultForegroundColor, color)) {
- _foregroundColor = null;
- } else {
- _foregroundColor = color;
- }
- return this;
- }
-
- /**
- * Sets the background (fill) color of the style
- *
- * @param rgbColorCode
- * a 6-letter hex RGB color code, such as FF0000 (red).
- * @return the {@link StyleBuilder} self (for cascading method calls)
- */
- public StyleBuilder background(String rgbColorCode) {
- return background(createColor(rgbColorCode));
- }
-
- /**
- * Sets the background (fill) color of the style
- *
- * @param rgb
- * a triplet array of shorts
- * @return the {@link StyleBuilder} self (for cascading method calls)
- */
- public StyleBuilder background(short[] rgb) {
- assert rgb.length == 3;
- return background(createColor(rgb[0], rgb[1], rgb[2]));
- }
-
- /**
- * Sets the background (fill) color of the style
- *
- * @param r
- * red amount (0-255)
- * @param g
- * green amount (0-255)
- * @param b
- * blue amount (0-255)
- * @return the {@link StyleBuilder} self (for cascading method calls)
- */
- public StyleBuilder background(int r, int g, int b) {
- return background(createColor(r, g, b));
- }
-
- /**
- * Sets the background (fill) color of the style
- *
- * @param color
- * the color to use
- * @return the {@link StyleBuilder} self (for cascading method calls)
- */
- public StyleBuilder background(Color color) {
- if (EqualsBuilder.equals(_defaultBackgroundColor, color)) {
- _backgroundColor = null;
- } else {
- _backgroundColor = color;
- }
- return this;
- }
-
- /**
- * Sets the font size of the style
- *
- * @param fontSize
- * the font size
- * @param sizeUnit
- * the font size unit
- * @return the {@link StyleBuilder} self (for cascading method calls)
- */
- public StyleBuilder fontSize(int fontSize, SizeUnit sizeUnit) {
- _fontSize = fontSize;
- _fontSizeUnit = sizeUnit;
- return this;
- }
-
- /**
- * Sets the text alignment to center
- *
- * @return the {@link StyleBuilder} self (for cascading method calls)
- */
- public StyleBuilder centerAligned() {
- _alignment = TextAlignment.CENTER;
- return this;
- }
-
- /**
- * Sets the text alignment to left
- *
- * @return the {@link StyleBuilder} self (for cascading method calls)
- */
- public StyleBuilder leftAligned() {
- _alignment = TextAlignment.LEFT;
- return this;
- }
-
- /**
- * Sets the text alignment to right
- *
- * @return the {@link StyleBuilder} self (for cascading method calls)
- */
- public StyleBuilder rightAligned() {
- _alignment = TextAlignment.RIGHT;
- return this;
- }
-
- /**
- * Sets the text alignment to justify
- *
- * @return the {@link StyleBuilder} self (for cascading method calls)
- */
- public StyleBuilder justifyAligned() {
- _alignment = TextAlignment.JUSTIFY;
- return this;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/data/StyleImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/StyleImpl.java b/core/src/main/java/org/eobjects/metamodel/data/StyleImpl.java
deleted file mode 100644
index 9c48cf7..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/StyleImpl.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/**
- * 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.util.BaseObject;
-
-/**
- * Default immutable implementation of {@link Style}.
- *
- * @author Kasper Sørensen
- */
-final class StyleImpl extends BaseObject implements Style {
-
- private static final long serialVersionUID = 1L;
-
- private final boolean _underline;
- private final boolean _italic;
- private final boolean _bold;
- private final Integer _fontSize;
- private final TextAlignment _alignment;
- private final Color _backgroundColor;
- private final Color _foregroundColor;
- private final SizeUnit _fontSizeUnit;
-
- public StyleImpl() {
- this(false, false, false, null, null, null, null, null);
- }
-
- public StyleImpl(boolean bold, boolean italic, boolean underline,
- Integer fontSize, SizeUnit fontSizeUnit, TextAlignment alignment,
- Color backgroundColor, Color foregroundColor) {
- _bold = bold;
- _italic = italic;
- _underline = underline;
- _fontSize = fontSize;
- _fontSizeUnit = fontSizeUnit;
- _alignment = alignment;
- _backgroundColor = backgroundColor;
- _foregroundColor = foregroundColor;
- }
-
- @Override
- public boolean isBold() {
- return _bold;
- }
-
- @Override
- public boolean isItalic() {
- return _italic;
- }
-
- @Override
- public boolean isUnderline() {
- return _underline;
- }
-
- @Override
- public Integer getFontSize() {
- return _fontSize;
- }
-
- @Override
- public SizeUnit getFontSizeUnit() {
- return _fontSizeUnit;
- }
-
- @Override
- public TextAlignment getAlignment() {
- return _alignment;
- }
-
- @Override
- public Color getForegroundColor() {
- return _foregroundColor;
- }
-
- @Override
- public Color getBackgroundColor() {
- return _backgroundColor;
- }
-
- @Override
- public String toCSS() {
- StringBuilder sb = new StringBuilder();
- if (_bold) {
- sb.append("font-weight: bold;");
- }
- if (_italic) {
- sb.append("font-style: italic;");
- }
- if (_underline) {
- sb.append("text-decoration: underline;");
- }
- if (_alignment != null) {
- sb.append("text-align: " + toCSS(_alignment) + ";");
- }
- if (_fontSize != null) {
- sb.append("font-size: " + _fontSize);
- switch (_fontSizeUnit) {
- case PT:
- sb.append("pt");
- break;
- case PX:
- sb.append("px");
- break;
- case PERCENT:
- sb.append("%");
- break;
- default:
- // don't write a size unit
- }
- sb.append(';');
- }
- if (_foregroundColor != null) {
- sb.append("color: " + toCSS(_foregroundColor) + ";");
- }
- if (_backgroundColor != null) {
- sb.append("background-color: " + toCSS(_backgroundColor) + ";");
- }
- return sb.toString();
- }
-
- private String toCSS(Color c) {
- return "rgb(" + c.getRed() + "," + c.getGreen() + "," + c.getBlue()
- + ")";
- }
-
- @Override
- public String toString() {
- return toCSS();
- }
-
- private String toCSS(TextAlignment alignment) {
- switch (alignment) {
- case LEFT:
- return "left";
- case RIGHT:
- return "right";
- case CENTER:
- return "center";
- case JUSTIFY:
- return "justify";
- default:
- throw new IllegalStateException("Unknown alignment: " + alignment);
- }
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- identifiers.add(_underline);
- identifiers.add(_italic);
- identifiers.add(_bold);
- identifiers.add(_fontSize);
- identifiers.add(_fontSizeUnit);
- identifiers.add(_alignment);
- identifiers.add(_backgroundColor);
- identifiers.add(_foregroundColor);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/data/SubSelectionDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/SubSelectionDataSet.java b/core/src/main/java/org/eobjects/metamodel/data/SubSelectionDataSet.java
deleted file mode 100644
index aee4ca6..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/SubSelectionDataSet.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * 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 org.eobjects.metamodel.query.SelectItem;
-
-/**
- * {@link DataSet} wrapper for doing subselection.
- *
- * @author Kasper Sørensen
- */
-public final class SubSelectionDataSet extends AbstractDataSet {
-
- private final DataSet _dataSet;
-
- public SubSelectionDataSet(SelectItem[] selectItemsArray, DataSet dataSet) {
- super(selectItemsArray);
- _dataSet = dataSet;
- }
-
- public DataSet getWrappedDataSet() {
- return _dataSet;
- }
-
- @Override
- public boolean next() {
- return _dataSet.next();
- }
-
- @Override
- public Row getRow() {
- final DataSetHeader header = getHeader();
- return _dataSet.getRow().getSubSelection(header);
- }
-
- @Override
- public void close() {
- super.close();
- _dataSet.close();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/data/WhereClauseBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/WhereClauseBuilder.java b/core/src/main/java/org/eobjects/metamodel/data/WhereClauseBuilder.java
deleted file mode 100644
index 431d640..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/WhereClauseBuilder.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * 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 org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.builder.FilterBuilder;
-import org.eobjects.metamodel.schema.Column;
-
-/**
- * An interface for builder components that formulate a WHERE clause, either for
- * querying, updating, deleting or other purposes.
- *
- * @param <T>
- * the return type of the {@link WhereClauseBuilder}s builder methods
- */
-public interface WhereClauseBuilder<T> {
-
- /**
- * Defines a where item to set as a criteria
- *
- * @param column
- * a column to apply a criteria for
- * @return a builder object for further building the where item
- */
- public FilterBuilder<T> where(Column column);
-
- /**
- * Defines a where item to set as a criteria
- *
- * @param columnName
- * the name of the colum to which the criteria will be applied
- * @return a builder object for further building the where item
- */
- public FilterBuilder<T> where(String columnName);
-
- /**
- * Applies where items to set criteria
- *
- * @param filterItems
- * the where items to set
- * @return the builder object itself, for further building of the update
- */
- public T where(FilterItem... filterItems);
-
- /**
- * Applies where items to set criteria
- *
- * @param filterItems
- * the where items to set
- * @return the builder object, for further building of the update
- */
- public T where(Iterable<FilterItem> filterItems);
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/data/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/data/package-info.java b/core/src/main/java/org/eobjects/metamodel/data/package-info.java
deleted file mode 100644
index 9791fe8..0000000
--- a/core/src/main/java/org/eobjects/metamodel/data/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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 data sets
- */
-package org.eobjects.metamodel.data;
-
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/delete/AbstractRowDeletionBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/delete/AbstractRowDeletionBuilder.java b/core/src/main/java/org/eobjects/metamodel/delete/AbstractRowDeletionBuilder.java
deleted file mode 100644
index 6efc703..0000000
--- a/core/src/main/java/org/eobjects/metamodel/delete/AbstractRowDeletionBuilder.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/**
- * 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.delete;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.FilterClause;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.query.builder.AbstractFilterBuilder;
-import org.eobjects.metamodel.query.builder.FilterBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * Abstract {@link RowDeletionBuilder} implementation
- */
-public abstract class AbstractRowDeletionBuilder implements RowDeletionBuilder {
-
- private final Table _table;
- private final List<FilterItem> _whereItems;
-
- public AbstractRowDeletionBuilder(Table table) {
- if (table == null) {
- throw new IllegalArgumentException("Table cannot be null");
- }
- _table = table;
- _whereItems = new ArrayList<FilterItem>();
- }
-
- protected List<FilterItem> getWhereItems() {
- return _whereItems;
- }
-
- @Override
- public FilterBuilder<RowDeletionBuilder> where(Column column) {
- SelectItem selectItem = new SelectItem(column);
- return new AbstractFilterBuilder<RowDeletionBuilder>(selectItem) {
- @Override
- protected RowDeletionBuilder applyFilter(FilterItem filter) {
- return where(filter);
- }
- };
- }
-
- @Override
- public FilterBuilder<RowDeletionBuilder> where(String columnName) {
- Column column = _table.getColumnByName(columnName);
- if (column == null) {
- throw new IllegalArgumentException("No such column: " + columnName);
- }
- return where(column);
- }
-
- @Override
- public RowDeletionBuilder where(FilterItem... filterItems) {
- for (FilterItem filterItem : filterItems) {
- _whereItems.add(filterItem);
- }
- return this;
- }
-
- @Override
- public RowDeletionBuilder where(Iterable<FilterItem> filterItems) {
- for (FilterItem filterItem : filterItems) {
- _whereItems.add(filterItem);
- }
- return this;
- }
-
- @Override
- public Table getTable() {
- return _table;
- }
-
- /**
- * Determines if a row should be deleted or not (can be used by subclasses
- * as a convenient determinator).
- *
- * @param row
- * @return true if the row should be deleted.
- */
- protected boolean deleteRow(Row row) {
- final List<FilterItem> whereItems = getWhereItems();
- for (FilterItem filterItem : whereItems) {
- if (!filterItem.evaluate(row)) {
- // since filter items are ANDed, if any item does not evaluate
- // to true, the row is not deleted
- return false;
- }
- }
- return true;
- }
-
- /**
- * Convenience method to tell subclasses if the delete operation represents
- * a full table truncate operation. Usually such operations can be optimized
- * by simply removing the table (and maybe restoring similar headers in a
- * new table).
- *
- * @return
- */
- protected boolean isTruncateTableOperation() {
- final List<FilterItem> whereItems = getWhereItems();
- return whereItems.isEmpty();
- }
-
- @Override
- public String toString() {
- return toSql();
- }
-
- @Override
- public String toSql() {
- return "DELETE FROM " + _table.getQualifiedLabel() + new FilterClause(null, " WHERE ").addItems(_whereItems);
- }
-}
[52/61] Renamed all import and package statements from 'org.eobjects'
to 'org.apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDeleteBuilder.java
----------------------------------------------------------------------
diff --git a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDeleteBuilder.java b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDeleteBuilder.java
index 2bf0291..a2041da 100644
--- a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDeleteBuilder.java
+++ b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDeleteBuilder.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.salesforce;
+package org.apache.metamodel.salesforce;
import java.util.ArrayList;
import java.util.List;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.delete.AbstractRowDeletionBuilder;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.delete.AbstractRowDeletionBuilder;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.schema.Table;
/**
* Row deletion builder for Salesforce.com
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceInsertBuilder.java
----------------------------------------------------------------------
diff --git a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceInsertBuilder.java b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceInsertBuilder.java
index a874912..d42e380 100644
--- a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceInsertBuilder.java
+++ b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceInsertBuilder.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.salesforce;
+package org.apache.metamodel.salesforce;
import java.util.ArrayList;
import java.util.List;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.insert.AbstractRowInsertionBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.insert.AbstractRowInsertionBuilder;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
import com.sforce.soap.partner.sobject.SObject;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceSchema.java
----------------------------------------------------------------------
diff --git a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceSchema.java b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceSchema.java
index d075513..90e5a66 100644
--- a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceSchema.java
+++ b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceSchema.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.salesforce;
+package org.apache.metamodel.salesforce;
import java.util.ArrayList;
import java.util.List;
-import org.eobjects.metamodel.schema.AbstractSchema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.LazyRef;
-import org.eobjects.metamodel.util.Ref;
+import org.apache.metamodel.schema.AbstractSchema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.LazyRef;
+import org.apache.metamodel.util.Ref;
import com.sforce.soap.partner.DescribeGlobalResult;
import com.sforce.soap.partner.DescribeGlobalSObjectResult;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceTable.java
----------------------------------------------------------------------
diff --git a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceTable.java b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceTable.java
index 93817ed..5983e7f 100644
--- a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceTable.java
+++ b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceTable.java
@@ -16,20 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.salesforce;
+package org.apache.metamodel.salesforce;
import java.util.ArrayList;
import java.util.List;
-import org.eobjects.metamodel.schema.AbstractTable;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.TableType;
-import org.eobjects.metamodel.util.LazyRef;
-import org.eobjects.metamodel.util.Ref;
+import org.apache.metamodel.schema.AbstractTable;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.Relationship;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.TableType;
+import org.apache.metamodel.util.LazyRef;
+import org.apache.metamodel.util.Ref;
import com.sforce.soap.partner.DescribeSObjectResult;
import com.sforce.soap.partner.Field;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceUpdateBuilder.java
----------------------------------------------------------------------
diff --git a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceUpdateBuilder.java b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceUpdateBuilder.java
index 0a60d6b..777c3fa 100644
--- a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceUpdateBuilder.java
+++ b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceUpdateBuilder.java
@@ -16,16 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.salesforce;
+package org.apache.metamodel.salesforce;
import java.util.ArrayList;
import java.util.List;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.AbstractRowUpdationBuilder;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.update.AbstractRowUpdationBuilder;
import com.sforce.soap.partner.sobject.SObject;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceUpdateCallback.java
----------------------------------------------------------------------
diff --git a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceUpdateCallback.java b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceUpdateCallback.java
index 86c54a0..281276a 100644
--- a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceUpdateCallback.java
+++ b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceUpdateCallback.java
@@ -16,26 +16,26 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.salesforce;
+package org.apache.metamodel.salesforce;
import java.io.Closeable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import org.eobjects.metamodel.AbstractUpdateCallback;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.LogicalOperator;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
+import org.apache.metamodel.AbstractUpdateCallback;
+import org.apache.metamodel.create.TableCreationBuilder;
+import org.apache.metamodel.delete.RowDeletionBuilder;
+import org.apache.metamodel.drop.TableDropBuilder;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.LogicalOperator;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.update.RowUpdationBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceUtils.java
----------------------------------------------------------------------
diff --git a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceUtils.java b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceUtils.java
index dc71a68..a8cec1f 100644
--- a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceUtils.java
+++ b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceUtils.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.salesforce;
+package org.apache.metamodel.salesforce;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/salesforce/src/test/java/org/apache/metamodel/salesforce/SalesforceDataContextTest.java
----------------------------------------------------------------------
diff --git a/salesforce/src/test/java/org/apache/metamodel/salesforce/SalesforceDataContextTest.java b/salesforce/src/test/java/org/apache/metamodel/salesforce/SalesforceDataContextTest.java
index e704a93..edc911f 100644
--- a/salesforce/src/test/java/org/apache/metamodel/salesforce/SalesforceDataContextTest.java
+++ b/salesforce/src/test/java/org/apache/metamodel/salesforce/SalesforceDataContextTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.salesforce;
+package org.apache.metamodel.salesforce;
import java.util.ArrayList;
import java.util.Arrays;
@@ -25,21 +25,21 @@ import java.util.Date;
import java.util.List;
import java.util.TimeZone;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.DateUtils;
-import org.eobjects.metamodel.util.Month;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.DateUtils;
+import org.apache.metamodel.util.Month;
public class SalesforceDataContextTest extends SalesforceTestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/salesforce/src/test/java/org/apache/metamodel/salesforce/SalesforceTestCase.java
----------------------------------------------------------------------
diff --git a/salesforce/src/test/java/org/apache/metamodel/salesforce/SalesforceTestCase.java b/salesforce/src/test/java/org/apache/metamodel/salesforce/SalesforceTestCase.java
index e59ac7a..5e2034f 100644
--- a/salesforce/src/test/java/org/apache/metamodel/salesforce/SalesforceTestCase.java
+++ b/salesforce/src/test/java/org/apache/metamodel/salesforce/SalesforceTestCase.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.salesforce;
+package org.apache.metamodel.salesforce;
import java.io.File;
import java.io.FileReader;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/LoggingMessageHandler.java
----------------------------------------------------------------------
diff --git a/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/LoggingMessageHandler.java b/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/LoggingMessageHandler.java
index 7793062..d80e2fb 100644
--- a/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/LoggingMessageHandler.java
+++ b/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/LoggingMessageHandler.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.sugarcrm;
+package org.apache.metamodel.sugarcrm;
import java.io.ByteArrayOutputStream;
import java.util.Collections;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmDataContext.java
----------------------------------------------------------------------
diff --git a/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmDataContext.java b/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmDataContext.java
index 8f79b20..22446fc 100644
--- a/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmDataContext.java
+++ b/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmDataContext.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.sugarcrm;
+package org.apache.metamodel.sugarcrm;
import java.io.Closeable;
import java.net.URL;
@@ -26,15 +26,15 @@ import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import org.apache.commons.codec.digest.DigestUtils;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.MaxRowsDataSet;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.LazyRef;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.QueryPostprocessDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.MaxRowsDataSet;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.LazyRef;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmDataSet.java
----------------------------------------------------------------------
diff --git a/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmDataSet.java b/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmDataSet.java
index d860bb8..a754ce6 100644
--- a/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmDataSet.java
+++ b/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmDataSet.java
@@ -16,23 +16,23 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.sugarcrm;
+package org.apache.metamodel.sugarcrm;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
-import org.eobjects.metamodel.data.AbstractDataSet;
-import org.eobjects.metamodel.data.DataSetHeader;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.util.BooleanComparator;
-import org.eobjects.metamodel.util.NumberComparator;
-import org.eobjects.metamodel.util.TimeComparator;
+import org.apache.metamodel.data.AbstractDataSet;
+import org.apache.metamodel.data.DataSetHeader;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.util.BooleanComparator;
+import org.apache.metamodel.util.NumberComparator;
+import org.apache.metamodel.util.TimeComparator;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmSchema.java
----------------------------------------------------------------------
diff --git a/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmSchema.java b/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmSchema.java
index f255e29..35f98ab 100644
--- a/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmSchema.java
+++ b/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmSchema.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.sugarcrm;
+package org.apache.metamodel.sugarcrm;
import java.util.ArrayList;
import java.util.List;
-import org.eobjects.metamodel.schema.AbstractSchema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.Ref;
+import org.apache.metamodel.schema.AbstractSchema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.Ref;
import com.sugarcrm.ws.soap.SugarsoapPortType;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmTable.java
----------------------------------------------------------------------
diff --git a/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmTable.java b/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmTable.java
index 5093fa0..1cb965e 100644
--- a/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmTable.java
+++ b/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmTable.java
@@ -16,22 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.sugarcrm;
+package org.apache.metamodel.sugarcrm;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.eobjects.metamodel.schema.AbstractTable;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.TableType;
-import org.eobjects.metamodel.util.LazyRef;
-import org.eobjects.metamodel.util.Ref;
+import org.apache.metamodel.schema.AbstractTable;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.Relationship;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.TableType;
+import org.apache.metamodel.util.LazyRef;
+import org.apache.metamodel.util.Ref;
import org.w3c.dom.Node;
import com.sugarcrm.ws.soap.FieldList;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmXmlHelper.java
----------------------------------------------------------------------
diff --git a/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmXmlHelper.java b/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmXmlHelper.java
index 4ab169f..a49b934 100644
--- a/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmXmlHelper.java
+++ b/sugarcrm/src/main/java/org/apache/metamodel/sugarcrm/SugarCrmXmlHelper.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.sugarcrm;
+package org.apache.metamodel.sugarcrm;
import java.util.ArrayList;
import java.util.List;
@@ -24,7 +24,7 @@ import java.util.List;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.schema.Column;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/sugarcrm/src/test/java/org/apache/metamodel/sugarcrm/SugarCrmDataContextTest.java
----------------------------------------------------------------------
diff --git a/sugarcrm/src/test/java/org/apache/metamodel/sugarcrm/SugarCrmDataContextTest.java b/sugarcrm/src/test/java/org/apache/metamodel/sugarcrm/SugarCrmDataContextTest.java
index 2ab838c..d9cf1e8 100644
--- a/sugarcrm/src/test/java/org/apache/metamodel/sugarcrm/SugarCrmDataContextTest.java
+++ b/sugarcrm/src/test/java/org/apache/metamodel/sugarcrm/SugarCrmDataContextTest.java
@@ -16,20 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.sugarcrm;
+package org.apache.metamodel.sugarcrm;
import java.util.Arrays;
import java.util.Date;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.data.MaxRowsDataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.InMemoryDataSet;
+import org.apache.metamodel.data.MaxRowsDataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
import com.sugarcrm.ws.soap.GetEntryListResultVersion2;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/sugarcrm/src/test/java/org/apache/metamodel/sugarcrm/SugarCrmTestCase.java
----------------------------------------------------------------------
diff --git a/sugarcrm/src/test/java/org/apache/metamodel/sugarcrm/SugarCrmTestCase.java b/sugarcrm/src/test/java/org/apache/metamodel/sugarcrm/SugarCrmTestCase.java
index 1494d3a..7b0ee0e 100644
--- a/sugarcrm/src/test/java/org/apache/metamodel/sugarcrm/SugarCrmTestCase.java
+++ b/sugarcrm/src/test/java/org/apache/metamodel/sugarcrm/SugarCrmTestCase.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.sugarcrm;
+package org.apache.metamodel.sugarcrm;
import java.io.File;
import java.io.FileReader;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/xml/src/main/java/org/apache/metamodel/xml/XmlDataContext.java
----------------------------------------------------------------------
diff --git a/xml/src/main/java/org/apache/metamodel/xml/XmlDataContext.java b/xml/src/main/java/org/apache/metamodel/xml/XmlDataContext.java
index b0c0f70..7738a4e 100644
--- a/xml/src/main/java/org/apache/metamodel/xml/XmlDataContext.java
+++ b/xml/src/main/java/org/apache/metamodel/xml/XmlDataContext.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.xml;
+package org.apache.metamodel.xml;
import java.io.File;
import java.net.URL;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/xml/src/main/java/org/apache/metamodel/xml/XmlDomDataContext.java
----------------------------------------------------------------------
diff --git a/xml/src/main/java/org/apache/metamodel/xml/XmlDomDataContext.java b/xml/src/main/java/org/apache/metamodel/xml/XmlDomDataContext.java
index 250d6f9..5011d04 100644
--- a/xml/src/main/java/org/apache/metamodel/xml/XmlDomDataContext.java
+++ b/xml/src/main/java/org/apache/metamodel/xml/XmlDomDataContext.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.xml;
+package org.apache.metamodel.xml;
import java.io.File;
import java.io.InputStream;
@@ -31,35 +31,35 @@ import java.util.Map.Entry;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.data.CachingDataSetHeader;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetHeader;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.JoinType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableRelationship;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.schema.TableType;
-import org.eobjects.metamodel.util.FileResource;
-import org.eobjects.metamodel.util.ImmutableRef;
-import org.eobjects.metamodel.util.NumberComparator;
-import org.eobjects.metamodel.util.Ref;
-import org.eobjects.metamodel.util.Resource;
-import org.eobjects.metamodel.util.UrlResource;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.MetaModelHelper;
+import org.apache.metamodel.QueryPostprocessDataContext;
+import org.apache.metamodel.data.CachingDataSetHeader;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSetHeader;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.InMemoryDataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.JoinType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableRelationship;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Relationship;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.schema.TableType;
+import org.apache.metamodel.util.FileResource;
+import org.apache.metamodel.util.ImmutableRef;
+import org.apache.metamodel.util.NumberComparator;
+import org.apache.metamodel.util.Ref;
+import org.apache.metamodel.util.Resource;
+import org.apache.metamodel.util.UrlResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Attr;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/xml/src/main/java/org/apache/metamodel/xml/XmlSaxContentHandler.java
----------------------------------------------------------------------
diff --git a/xml/src/main/java/org/apache/metamodel/xml/XmlSaxContentHandler.java b/xml/src/main/java/org/apache/metamodel/xml/XmlSaxContentHandler.java
index fc2a1c1..943757a 100644
--- a/xml/src/main/java/org/apache/metamodel/xml/XmlSaxContentHandler.java
+++ b/xml/src/main/java/org/apache/metamodel/xml/XmlSaxContentHandler.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.xml;
+package org.apache.metamodel.xml;
import java.util.HashMap;
import java.util.Map;
@@ -24,7 +24,7 @@ import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
-import org.eobjects.metamodel.data.RowPublisher;
+import org.apache.metamodel.data.RowPublisher;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/xml/src/main/java/org/apache/metamodel/xml/XmlSaxDataContext.java
----------------------------------------------------------------------
diff --git a/xml/src/main/java/org/apache/metamodel/xml/XmlSaxDataContext.java b/xml/src/main/java/org/apache/metamodel/xml/XmlSaxDataContext.java
index e5ca80c..fc22f16 100644
--- a/xml/src/main/java/org/apache/metamodel/xml/XmlSaxDataContext.java
+++ b/xml/src/main/java/org/apache/metamodel/xml/XmlSaxDataContext.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.xml;
+package org.apache.metamodel.xml;
import java.io.File;
import java.io.InputStream;
@@ -27,24 +27,24 @@ import java.util.Map;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.RowPublisher;
-import org.eobjects.metamodel.data.RowPublisherDataSet;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.ImmutableSchema;
-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.Table;
-import org.eobjects.metamodel.util.Action;
-import org.eobjects.metamodel.util.FileResource;
-import org.eobjects.metamodel.util.Ref;
-import org.eobjects.metamodel.util.Resource;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.QueryPostprocessDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.RowPublisher;
+import org.apache.metamodel.data.RowPublisherDataSet;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.ImmutableSchema;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.Action;
+import org.apache.metamodel.util.FileResource;
+import org.apache.metamodel.util.Ref;
+import org.apache.metamodel.util.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.Attributes;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/xml/src/main/java/org/apache/metamodel/xml/XmlSaxTableDef.java
----------------------------------------------------------------------
diff --git a/xml/src/main/java/org/apache/metamodel/xml/XmlSaxTableDef.java b/xml/src/main/java/org/apache/metamodel/xml/XmlSaxTableDef.java
index 8437aaf..368b578 100644
--- a/xml/src/main/java/org/apache/metamodel/xml/XmlSaxTableDef.java
+++ b/xml/src/main/java/org/apache/metamodel/xml/XmlSaxTableDef.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.xml;
+package org.apache.metamodel.xml;
import java.io.Serializable;
import java.util.Arrays;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.schema.Table;
/**
* Defines a table layout for {@link XmlSaxDataContext}. This class is used as
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/xml/src/main/java/org/apache/metamodel/xml/XmlStopParsingException.java
----------------------------------------------------------------------
diff --git a/xml/src/main/java/org/apache/metamodel/xml/XmlStopParsingException.java b/xml/src/main/java/org/apache/metamodel/xml/XmlStopParsingException.java
index f1f66eb..6a138da 100644
--- a/xml/src/main/java/org/apache/metamodel/xml/XmlStopParsingException.java
+++ b/xml/src/main/java/org/apache/metamodel/xml/XmlStopParsingException.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.xml;
+package org.apache.metamodel.xml;
import org.xml.sax.SAXException;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/xml/src/main/java/org/apache/metamodel/xml/package-info.java
----------------------------------------------------------------------
diff --git a/xml/src/main/java/org/apache/metamodel/xml/package-info.java b/xml/src/main/java/org/apache/metamodel/xml/package-info.java
index eaedd4e..b2c7361 100644
--- a/xml/src/main/java/org/apache/metamodel/xml/package-info.java
+++ b/xml/src/main/java/org/apache/metamodel/xml/package-info.java
@@ -19,5 +19,5 @@
/**
* Module package for XML files
*/
-package org.eobjects.metamodel.xml;
+package org.apache.metamodel.xml;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/xml/src/test/java/org/apache/metamodel/xml/XmlDomDataContextTest.java
----------------------------------------------------------------------
diff --git a/xml/src/test/java/org/apache/metamodel/xml/XmlDomDataContextTest.java b/xml/src/test/java/org/apache/metamodel/xml/XmlDomDataContextTest.java
index 94cd3d2..720bb70 100644
--- a/xml/src/test/java/org/apache/metamodel/xml/XmlDomDataContextTest.java
+++ b/xml/src/test/java/org/apache/metamodel/xml/XmlDomDataContextTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.xml;
+package org.apache.metamodel.xml;
import java.io.File;
import java.net.URL;
@@ -30,15 +30,15 @@ import javax.xml.parsers.DocumentBuilderFactory;
import junit.framework.TestCase;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetTableModel;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.JoinType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSetTableModel;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.JoinType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Relationship;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/xml/src/test/java/org/apache/metamodel/xml/XmlSaxContentHandlerTest.java
----------------------------------------------------------------------
diff --git a/xml/src/test/java/org/apache/metamodel/xml/XmlSaxContentHandlerTest.java b/xml/src/test/java/org/apache/metamodel/xml/XmlSaxContentHandlerTest.java
index f53c71a..4764179 100644
--- a/xml/src/test/java/org/apache/metamodel/xml/XmlSaxContentHandlerTest.java
+++ b/xml/src/test/java/org/apache/metamodel/xml/XmlSaxContentHandlerTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.xml;
+package org.apache.metamodel.xml;
import java.io.FileReader;
import java.util.ArrayList;
@@ -28,9 +28,9 @@ import javax.xml.parsers.SAXParserFactory;
import junit.framework.TestCase;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.RowPublisher;
-import org.eobjects.metamodel.data.Style;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.data.RowPublisher;
+import org.apache.metamodel.data.Style;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/xml/src/test/java/org/apache/metamodel/xml/XmlSaxDataContextTest.java
----------------------------------------------------------------------
diff --git a/xml/src/test/java/org/apache/metamodel/xml/XmlSaxDataContextTest.java b/xml/src/test/java/org/apache/metamodel/xml/XmlSaxDataContextTest.java
index c5d7cab..d150aac 100644
--- a/xml/src/test/java/org/apache/metamodel/xml/XmlSaxDataContextTest.java
+++ b/xml/src/test/java/org/apache/metamodel/xml/XmlSaxDataContextTest.java
@@ -16,19 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.xml;
+package org.apache.metamodel.xml;
import java.io.File;
import java.util.Arrays;
import junit.framework.TestCase;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
public class XmlSaxDataContextTest extends TestCase {
[30/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/ColumnType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/ColumnType.java b/core/src/main/java/org/eobjects/metamodel/schema/ColumnType.java
deleted file mode 100644
index ea938e6..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/ColumnType.java
+++ /dev/null
@@ -1,292 +0,0 @@
-/**
- * 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.schema;
-
-import static org.eobjects.metamodel.schema.SuperColumnType.BINARY_TYPE;
-import static org.eobjects.metamodel.schema.SuperColumnType.BOOLEAN_TYPE;
-import static org.eobjects.metamodel.schema.SuperColumnType.LITERAL_TYPE;
-import static org.eobjects.metamodel.schema.SuperColumnType.NUMBER_TYPE;
-import static org.eobjects.metamodel.schema.SuperColumnType.OTHER_TYPE;
-import static org.eobjects.metamodel.schema.SuperColumnType.TIME_TYPE;
-
-import java.lang.reflect.Field;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.sql.Blob;
-import java.sql.Clob;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.sql.Types;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-import org.eobjects.metamodel.util.NumberComparator;
-import org.eobjects.metamodel.util.ObjectComparator;
-import org.eobjects.metamodel.util.TimeComparator;
-import org.eobjects.metamodel.util.ToStringComparator;
-
-/**
- * Represents the data-type of columns. Most of the elements in this enum are
- * based on the JDBC {@link Types} class, but with a few additions.
- */
-public enum ColumnType {
-
- /**
- * Literal
- */
- CHAR(LITERAL_TYPE), VARCHAR(LITERAL_TYPE), LONGVARCHAR(LITERAL_TYPE), CLOB(LITERAL_TYPE), NCHAR(LITERAL_TYPE), NVARCHAR(
- LITERAL_TYPE), LONGNVARCHAR(LITERAL_TYPE), NCLOB(LITERAL_TYPE),
-
- /**
- * Numbers
- */
- TINYINT(NUMBER_TYPE), SMALLINT(NUMBER_TYPE), INTEGER(NUMBER_TYPE), BIGINT(NUMBER_TYPE), FLOAT(NUMBER_TYPE), REAL(
- NUMBER_TYPE), DOUBLE(NUMBER_TYPE), NUMERIC(NUMBER_TYPE), DECIMAL(NUMBER_TYPE),
-
- /**
- * Time based
- */
- DATE(TIME_TYPE), TIME(TIME_TYPE), TIMESTAMP(TIME_TYPE),
-
- /**
- * Booleans
- */
- BIT(BOOLEAN_TYPE), BOOLEAN(BOOLEAN_TYPE),
-
- /**
- * Binary types
- */
- BINARY(BINARY_TYPE), VARBINARY(BINARY_TYPE), LONGVARBINARY(BINARY_TYPE), BLOB(BINARY_TYPE),
-
- /**
- * Other types (as defined in {@link Types}).
- */
- NULL(OTHER_TYPE), OTHER(OTHER_TYPE), JAVA_OBJECT(OTHER_TYPE), DISTINCT(OTHER_TYPE), STRUCT(OTHER_TYPE), ARRAY(
- OTHER_TYPE), REF(OTHER_TYPE), DATALINK(OTHER_TYPE), ROWID(OTHER_TYPE), SQLXML(OTHER_TYPE),
-
- /**
- * Additional types (added by MetaModel for non-JDBC datastores)
- */
- LIST(OTHER_TYPE), MAP(OTHER_TYPE);
-
- private SuperColumnType _superType;
-
- private ColumnType(SuperColumnType superType) {
- if (superType == null) {
- throw new IllegalArgumentException("SuperColumnType cannot be null");
- }
- _superType = superType;
- }
-
- public Comparator<Object> getComparator() {
- if (isTimeBased()) {
- return TimeComparator.getComparator();
- }
- if (isNumber()) {
- return NumberComparator.getComparator();
- }
- if (isLiteral()) {
- return ToStringComparator.getComparator();
- }
- return ObjectComparator.getComparator();
- }
-
- public boolean isBoolean() {
- return _superType == BOOLEAN_TYPE;
- }
-
- public boolean isBinary() {
- return _superType == BINARY_TYPE;
- }
-
- public boolean isNumber() {
- return _superType == NUMBER_TYPE;
- }
-
- public boolean isTimeBased() {
- return _superType == TIME_TYPE;
- }
-
- public boolean isLiteral() {
- return _superType == LITERAL_TYPE;
- }
-
- public boolean isLargeObject() {
- switch (this) {
- case BLOB:
- case CLOB:
- case NCLOB:
- return true;
- default:
- return false;
- }
- }
-
- /**
- * @return a java class that is appropriate for handling column values of
- * this column type
- */
- public Class<?> getJavaEquivalentClass() {
- switch (this) {
- case TINYINT:
- case SMALLINT:
- return Short.class;
- case INTEGER:
- return Integer.class;
- case BIGINT:
- return BigInteger.class;
- case DECIMAL:
- case NUMERIC:
- case FLOAT:
- case REAL:
- case DOUBLE:
- return Double.class;
- case DATE:
- case TIME:
- case TIMESTAMP:
- return Date.class;
- case BLOB:
- return Blob.class;
- case CLOB:
- case NCLOB:
- return Clob.class;
- case MAP:
- return Map.class;
- case LIST:
- return List.class;
- default:
- // All other types have fitting java equivalent classes in the super
- // type
- return _superType.getJavaEquivalentClass();
- }
- }
-
- public SuperColumnType getSuperType() {
- return _superType;
- }
-
- /**
- * Finds the ColumnType enum corresponding to the incoming JDBC
- * type-constant
- */
- public static ColumnType convertColumnType(int jdbcType) {
- try {
- Field[] fields = JdbcTypes.class.getFields();
- // We assume that the JdbcTypes class only consists of constant
- // integer types, so we make no assertions here
- for (int i = 0; i < fields.length; i++) {
- Field field = fields[i];
- int value = (Integer) field.getInt(null);
- if (value == jdbcType) {
- String fieldName = field.getName();
- ColumnType[] enumConstants = ColumnType.class.getEnumConstants();
- for (int j = 0; j < enumConstants.length; j++) {
- ColumnType columnType = enumConstants[j];
- if (fieldName.equals(columnType.toString())) {
- return columnType;
- }
- }
- }
- }
- } catch (Exception e) {
- throw new IllegalStateException("Could not access fields in JdbcTypes", e);
- }
- return OTHER;
- }
-
- /**
- * Gets the JDBC type as per the {@link Types} class.
- *
- * @return an int representing one of the constants in the {@link Types}
- * class.
- * @throws IllegalStateException
- * in case getting the JDBC type was unsuccesful.
- */
- public int getJdbcType() throws IllegalStateException {
- final String name = this.toString();
- try {
- // We assume that the JdbcTypes class only consists of constant
- // integer types, so we make no assertions here
- final Field[] fields = JdbcTypes.class.getFields();
- for (int i = 0; i < fields.length; i++) {
- Field field = fields[i];
- String fieldName = field.getName();
- if (fieldName.equals(name)) {
- int value = (Integer) field.getInt(null);
- return value;
- }
- }
- throw new IllegalStateException("No JdbcType found with field name: " + name);
- } catch (Exception e) {
- throw new IllegalStateException("Could not access fields in JdbcTypes", e);
- }
- }
-
- /**
- * Finds the ColumnType enum corresponding to the incoming Java class.
- *
- * @param cls
- * @return
- */
- public static ColumnType convertColumnType(Class<?> cls) {
- if (cls == null) {
- throw new IllegalArgumentException("Class cannot be null");
- }
-
- final ColumnType type;
- if (cls == String.class) {
- type = ColumnType.VARCHAR;
- } else if (cls == Boolean.class || cls == boolean.class) {
- type = ColumnType.BOOLEAN;
- } else if (cls == Character.class || cls == char.class || cls == Character[].class || cls == char[].class) {
- type = ColumnType.CHAR;
- } else if (cls == Byte.class || cls == byte.class) {
- type = ColumnType.TINYINT;
- } else if (cls == Short.class || cls == short.class) {
- type = ColumnType.SMALLINT;
- } else if (cls == Integer.class || cls == int.class) {
- type = ColumnType.INTEGER;
- } else if (cls == Long.class || cls == long.class || cls == BigInteger.class) {
- type = ColumnType.BIGINT;
- } else if (cls == Float.class || cls == float.class) {
- type = ColumnType.FLOAT;
- } else if (cls == Double.class || cls == double.class) {
- type = ColumnType.DOUBLE;
- } else if (cls == BigDecimal.class) {
- type = ColumnType.DECIMAL;
- } else if (Map.class.isAssignableFrom(cls)) {
- type = ColumnType.MAP;
- } else if (List.class.isAssignableFrom(cls)) {
- type = ColumnType.LIST;
- } else if (cls == java.sql.Date.class) {
- type = ColumnType.DATE;
- } else if (cls == Timestamp.class) {
- type = ColumnType.TIMESTAMP;
- } else if (cls == Time.class) {
- type = ColumnType.TIME;
- } else if (Date.class.isAssignableFrom(cls)) {
- type = ColumnType.TIMESTAMP;
- } else {
- type = ColumnType.OTHER;
- }
- return type;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/CompositeSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/CompositeSchema.java b/core/src/main/java/org/eobjects/metamodel/schema/CompositeSchema.java
deleted file mode 100644
index f4f75e1..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/CompositeSchema.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- * 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.schema;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.util.CollectionUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A composite schema, comprising tables from several {@link DataContext}s.
- *
- * @author Kasper Sørensen
- */
-public class CompositeSchema extends AbstractSchema {
-
- private static final long serialVersionUID = 1L;
-
- private static final Logger logger = LoggerFactory.getLogger(CompositeSchema.class);
-
- private final String name;
- private final Collection<? extends Schema> delegates;
-
- public CompositeSchema(String name, Collection<? extends Schema> delegates) {
- super();
- this.name = name;
- this.delegates = delegates;
- if (logger.isWarnEnabled()) {
- Set<String> names = new HashSet<String>();
- for (Table table : getTables()) {
- if (names.contains(table.getName())) {
- logger.warn("Name-clash detected for Table {}.", table.getName());
- logger.warn("getTableByName(\"{}\") will return just the first table.", table.getName());
- } else {
- names.add(table.getName());
- }
- }
- if (!names.isEmpty()) {
- logger.warn("The following table names clashes in composite schema: " + names);
- }
- }
- }
-
- @Override
- public Relationship[] getRelationships() {
- Relationship[] result = new Relationship[0];
- for (Schema delegate : delegates) {
- result = CollectionUtils.array(result, delegate.getRelationships());
- }
- return result;
- }
-
- @Override
- public Table[] getTables() {
- Table[] result = new Table[0];
- for (Schema delegate : delegates) {
- result = CollectionUtils.array(result, delegate.getTables());
- }
- return result;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getQuote() {
- return null;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/ImmutableColumn.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/ImmutableColumn.java b/core/src/main/java/org/eobjects/metamodel/schema/ImmutableColumn.java
deleted file mode 100644
index 3236c00..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/ImmutableColumn.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/**
- * 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.schema;
-
-import java.io.Serializable;
-
-/**
- * Immutable implementation of the Column interface.
- *
- * It is not intended to be instantiated on it's own. Rather, use the
- * constructor in ImmutableSchema.
- *
- * @see ImmutableSchema
- *
- * @author Kasper Sørensen
- */
-public final class ImmutableColumn extends AbstractColumn implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private final int columnNumber;
- private final ColumnType type;
- private final Table table;
- private final Boolean nullable;
- private final String remarks;
- private final Integer columnSize;
- private final String nativeType;
- private final boolean indexed;
- private final boolean primaryKey;
- private final String name;
- private final String quote;
-
- /**
- * Constructs a new {@link ImmutableColumn}.
- *
- * @param name
- * the name of the column
- * @param type
- * the type of the column
- * @param table
- * the table which the constructed column will pertain to
- * @param columnNumber
- * the column number of the column
- * @param columnSize
- * the size of the column
- * @param nativeType
- * the native type of the column
- * @param nullable
- * whether the column's values are nullable
- * @param remarks
- * the remarks of the column
- * @param indexed
- * whether the column is indexed or not
- * @param quote
- * the quote character(s) of the column
- * @param primaryKey
- * whether the column is a primary key or not
- */
- public ImmutableColumn(String name, ColumnType type, Table table, int columnNumber, Integer columnSize,
- String nativeType, Boolean nullable, String remarks, boolean indexed, String quote, boolean primaryKey) {
- this.name = name;
- this.type = type;
- this.table = table;
- this.columnNumber = columnNumber;
- this.columnSize = columnSize;
- this.nativeType = nativeType;
- this.nullable = nullable;
- this.remarks = remarks;
- this.indexed = indexed;
- this.quote = quote;
- this.primaryKey = primaryKey;
- }
-
- /**
- * Constructs an {@link ImmutableColumn} based on an existing column and a
- * table.
- *
- * @param column
- * the column to immitate
- * @param table
- * the table that the constructed column will pertain to
- */
- public ImmutableColumn(Column column, Table table) {
- this.name = column.getName();
- this.type = column.getType();
- this.table = table;
- this.columnNumber = column.getColumnNumber();
- this.columnSize = column.getColumnSize();
- this.nativeType = column.getNativeType();
- this.nullable = column.isNullable();
- this.remarks = column.getRemarks();
- this.indexed = column.isIndexed();
- this.quote = column.getQuote();
- this.primaryKey = column.isPrimaryKey();
- }
-
- protected ImmutableColumn(Column column, ImmutableTable table) {
- this(column.getName(), column.getType(), table, column.getColumnNumber(), column.getColumnSize(), column
- .getNativeType(), column.isNullable(), column.getRemarks(), column.isIndexed(), column.getQuote(),
- column.isPrimaryKey());
- }
-
- @Override
- public int getColumnNumber() {
- return columnNumber;
- }
-
- @Override
- public ColumnType getType() {
- return type;
- }
-
- @Override
- public Table getTable() {
- return table;
- }
-
- @Override
- public Boolean isNullable() {
- return nullable;
- }
-
- @Override
- public String getRemarks() {
- return remarks;
- }
-
- @Override
- public Integer getColumnSize() {
- return columnSize;
- }
-
- @Override
- public String getNativeType() {
- return nativeType;
- }
-
- @Override
- public boolean isIndexed() {
- return indexed;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public boolean isPrimaryKey() {
- return primaryKey;
- }
-
- @Override
- public String getQuote() {
- return quote;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/ImmutableRelationship.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/ImmutableRelationship.java b/core/src/main/java/org/eobjects/metamodel/schema/ImmutableRelationship.java
deleted file mode 100644
index 43f2cf0..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/ImmutableRelationship.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- * 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.schema;
-
-import java.io.Serializable;
-
-public final class ImmutableRelationship extends AbstractRelationship implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private final Column[] primaryColumns;
- private final Column[] foreignColumns;
-
- public static void create(Relationship origRelationship,
- ImmutableSchema schema) {
- ImmutableTable primaryTable = getSimilarTable(
- origRelationship.getPrimaryTable(), schema);
- assert primaryTable != null;
- Column[] primaryColumns = getSimilarColumns(
- origRelationship.getPrimaryColumns(), primaryTable);
- checkSameTable(primaryColumns);
-
- ImmutableTable foreignTable = getSimilarTable(
- origRelationship.getForeignTable(), schema);
- assert foreignTable != null;
- Column[] foreignColumns = getSimilarColumns(
- origRelationship.getForeignColumns(), foreignTable);
- checkSameTable(foreignColumns);
-
- ImmutableRelationship relationship = new ImmutableRelationship(
- primaryColumns, foreignColumns);
- primaryTable.addRelationship(relationship);
- foreignTable.addRelationship(relationship);
- }
-
- private static Column[] getSimilarColumns(Column[] columns, Table table) {
- Column[] result = new Column[columns.length];
- for (int i = 0; i < columns.length; i++) {
- String name = columns[i].getName();
- result[i] = table.getColumnByName(name);
- }
- return result;
- }
-
- private static ImmutableTable getSimilarTable(Table table,
- ImmutableSchema schema) {
- String name = table.getName();
- return (ImmutableTable) schema.getTableByName(name);
- }
-
- private ImmutableRelationship(Column[] primaryColumns,
- Column[] foreignColumns) {
- this.primaryColumns = primaryColumns;
- this.foreignColumns = foreignColumns;
- }
-
- @Override
- public Column[] getPrimaryColumns() {
- return primaryColumns;
- }
-
- @Override
- public Column[] getForeignColumns() {
- return foreignColumns;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/ImmutableSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/ImmutableSchema.java b/core/src/main/java/org/eobjects/metamodel/schema/ImmutableSchema.java
deleted file mode 100644
index 8ac8a79..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/ImmutableSchema.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * 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.schema;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * An immutable implementation of the {@link Schema} interface.
- *
- * @author Kasper Sørensen
- */
-public final class ImmutableSchema extends AbstractSchema implements
- Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private final List<ImmutableTable> tables = new ArrayList<ImmutableTable>();
- private String name;
- private String quote;
-
- private ImmutableSchema(String name, String quote) {
- super();
- this.name = name;
- this.quote = quote;
- }
-
- public ImmutableSchema(Schema schema) {
- this(schema.getName(), schema.getQuote());
- Table[] origTables = schema.getTables();
- for (Table table : origTables) {
- tables.add(new ImmutableTable(table, this));
- }
-
- Relationship[] origRelationships = schema.getRelationships();
- for (Relationship relationship : origRelationships) {
- ImmutableRelationship.create(relationship, this);
- }
- }
-
- @Override
- public Table[] getTables() {
- return tables.toArray(new Table[tables.size()]);
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getQuote() {
- return quote;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/ImmutableTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/ImmutableTable.java b/core/src/main/java/org/eobjects/metamodel/schema/ImmutableTable.java
deleted file mode 100644
index a4d6d81..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/ImmutableTable.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/**
- * 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.schema;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * An immutable implementation of the Table interface.
- *
- * It is not intended to be instantiated on it's own. Rather, use the
- * constructor in ImmutableSchema.
- *
- * @see ImmutableSchema
- *
- * @author Kasper Sørensen
- */
-final class ImmutableTable extends AbstractTable implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private final List<ImmutableColumn> columns = new ArrayList<ImmutableColumn>();
- private final List<ImmutableRelationship> relationships = new ArrayList<ImmutableRelationship>();
- private final ImmutableSchema schema;
- private final TableType type;
- private final String remarks;
- private final String name;
- private final String quote;
-
- protected ImmutableTable(String name, TableType type, ImmutableSchema schema,
- String remarks, String quote) {
- this.name = name;
- this.type = type;
- this.schema = schema;
- this.remarks = remarks;
- this.quote = quote;
- }
-
- protected ImmutableTable(Table table, ImmutableSchema schema) {
- this(table.getName(), table.getType(), schema, table.getRemarks(),
- table.getQuote());
- Column[] origColumns = table.getColumns();
- for (Column column : origColumns) {
- columns.add(new ImmutableColumn(column, this));
- }
- }
-
- protected void addRelationship(ImmutableRelationship relationship) {
- if (!relationships.contains(relationship)) {
- relationships.add(relationship);
- }
- }
-
- @Override
- public Column[] getColumns() {
- return columns.toArray(new Column[columns.size()]);
- }
-
- @Override
- public Schema getSchema() {
- return schema;
- }
-
- @Override
- public TableType getType() {
- return type;
- }
-
- @Override
- public Relationship[] getRelationships() {
- return relationships.toArray(new Relationship[relationships.size()]);
- }
-
- @Override
- public String getRemarks() {
- return remarks;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getQuote() {
- return quote;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/JdbcTypes.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/JdbcTypes.java b/core/src/main/java/org/eobjects/metamodel/schema/JdbcTypes.java
deleted file mode 100644
index 4531921..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/JdbcTypes.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * 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.schema;
-
-/**
- * This is a copy of the content (comments removed) of Java 6.0's
- * java.sql.Types. It is backwards compatible with older versions, but have
- * additional types (confirmed by JavaTypesTest). It is being used to convert
- * JDBC types to ColumnType enumerations.
- */
-final class JdbcTypes {
-
- // Prevent instantiation
- private JdbcTypes() {
- }
-
- public final static int BIT = -7;
- public final static int TINYINT = -6;
- public final static int SMALLINT = 5;
- public final static int INTEGER = 4;
- public final static int BIGINT = -5;
- public final static int FLOAT = 6;
- public final static int REAL = 7;
- public final static int DOUBLE = 8;
- public final static int NUMERIC = 2;
- public final static int DECIMAL = 3;
- public final static int CHAR = 1;
- public final static int VARCHAR = 12;
- public final static int LONGVARCHAR = -1;
- public final static int DATE = 91;
- public final static int TIME = 92;
- public final static int TIMESTAMP = 93;
- public final static int BINARY = -2;
- public final static int VARBINARY = -3;
- public final static int LONGVARBINARY = -4;
- public final static int NULL = 0;
- public final static int OTHER = 1111;
- public final static int JAVA_OBJECT = 2000;
- public final static int DISTINCT = 2001;
- public final static int STRUCT = 2002;
- public final static int ARRAY = 2003;
- public final static int BLOB = 2004;
- public final static int CLOB = 2005;
- public final static int REF = 2006;
- public final static int DATALINK = 70;
- public final static int BOOLEAN = 16;
- public final static int ROWID = -8;
- public static final int NCHAR = -15;
- public static final int NVARCHAR = -9;
- public static final int LONGNVARCHAR = -16;
- public static final int NCLOB = 2011;
- public static final int SQLXML = 2009;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/MutableColumn.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/MutableColumn.java b/core/src/main/java/org/eobjects/metamodel/schema/MutableColumn.java
deleted file mode 100644
index d4c464d..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/MutableColumn.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/**
- * 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.schema;
-
-import java.io.Serializable;
-
-/**
- * Represents a column and it's metadata description. Columns reside within a
- * Table and can be used as keys for relationships between tables.
- *
- * @see MutableTable
- * @see Relationship
- */
-public class MutableColumn extends AbstractColumn implements Serializable {
-
- private static final long serialVersionUID = -353183696233890927L;
- private int _columnNumber;
- private String _name;
- private ColumnType _type;
- private Table _table;
- private Boolean _nullable = null;
- private String _remarks;
- private boolean _indexed = false;
- private boolean _primaryKey = false;
- private Integer _columnSize = null;
- private String _nativeType = null;
- private String _quoteString = null;
-
- public MutableColumn() {
- super();
- }
-
- public MutableColumn(String name) {
- this();
- setName(name);
- }
-
- public MutableColumn(String name, ColumnType type) {
- this(name);
- setType(type);
- }
-
- public MutableColumn(String name, ColumnType type, Table table, int columnNumber, Boolean nullable) {
- this(name, type);
- setColumnNumber(columnNumber);
- setTable(table);
- setNullable(nullable);
- }
-
- public MutableColumn(String name, ColumnType type, Table table, int columnNumber, Integer columnSize,
- String nativeType, Boolean nullable, String remarks, boolean indexed, String quote) {
- this(name, type, table, columnNumber, nullable);
- setColumnSize(columnSize);
- setNativeType(nativeType);
- setRemarks(remarks);
- setIndexed(indexed);
- setQuote(quote);
- }
-
- @Override
- public int getColumnNumber() {
- return _columnNumber;
- }
-
- public MutableColumn setColumnNumber(int columnNumber) {
- _columnNumber = columnNumber;
- return this;
- }
-
- @Override
- public String getName() {
- return _name;
- }
-
- public MutableColumn setName(String name) {
- _name = name;
- return this;
- }
-
- @Override
- public ColumnType getType() {
- return _type;
- }
-
- public MutableColumn setType(ColumnType type) {
- _type = type;
- return this;
- }
-
- @Override
- public Table getTable() {
- return _table;
- }
-
- public MutableColumn setTable(Table table) {
- _table = table;
- return this;
- }
-
- @Override
- public Boolean isNullable() {
- return _nullable;
- }
-
- public MutableColumn setNullable(Boolean nullable) {
- _nullable = nullable;
- return this;
- }
-
- @Override
- public String getRemarks() {
- return _remarks;
- }
-
- public MutableColumn setRemarks(String remarks) {
- _remarks = remarks;
- return this;
- }
-
- @Override
- public Integer getColumnSize() {
- return _columnSize;
- }
-
- public MutableColumn setColumnSize(Integer columnSize) {
- _columnSize = columnSize;
- return this;
- }
-
- @Override
- public String getNativeType() {
- return _nativeType;
- }
-
- public MutableColumn setNativeType(String nativeType) {
- _nativeType = nativeType;
- return this;
- }
-
- @Override
- public boolean isIndexed() {
- return _indexed;
- }
-
- public MutableColumn setIndexed(boolean indexed) {
- _indexed = indexed;
- return this;
- }
-
- @Override
- public String getQuote() {
- return _quoteString;
- }
-
- public MutableColumn setQuote(String quoteString) {
- _quoteString = quoteString;
- return this;
- }
-
- @Override
- public boolean isPrimaryKey() {
- return _primaryKey;
- }
-
- public MutableColumn setPrimaryKey(boolean primaryKey) {
- _primaryKey = primaryKey;
- return this;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/MutableRelationship.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/MutableRelationship.java b/core/src/main/java/org/eobjects/metamodel/schema/MutableRelationship.java
deleted file mode 100644
index 8762222..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/MutableRelationship.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/**
- * 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.schema;
-
-import java.io.Serializable;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Immutable implementation of the Relationship interface.
- *
- * The immutability help ensure integrity of object-relationships. To create
- * relationsips use the <code>createRelationship</code> method.
- *
- * @author Kasper Sørensen
- */
-public class MutableRelationship extends AbstractRelationship implements
- Serializable, Relationship {
-
- private static final long serialVersionUID = 238786848828528822L;
- private static final Logger logger = LoggerFactory
- .getLogger(MutableRelationship.class);
-
- private final Column[] _primaryColumns;
- private final Column[] _foreignColumns;
-
- /**
- * Factory method to create relations between two tables by specifying which
- * columns from the tables that enforce the relationship.
- *
- * @param primaryColumns
- * the columns from the primary key table
- * @param foreignColumns
- * the columns from the foreign key table
- * @return the relation created
- */
- public static Relationship createRelationship(Column[] primaryColumns,
- Column[] foreignColumns) {
- Table primaryTable = checkSameTable(primaryColumns);
- Table foreignTable = checkSameTable(foreignColumns);
- MutableRelationship relation = new MutableRelationship(primaryColumns,
- foreignColumns);
-
- if (primaryTable instanceof MutableTable) {
- try {
- ((MutableTable) primaryTable).addRelationship(relation);
- } catch (UnsupportedOperationException e) {
- // this is an allowed behaviour - not all tables need to support
- // this method.
- logger.debug(
- "primary table ({}) threw exception when adding relationship",
- primaryTable);
- }
-
- // Ticket #144: Some tables have relations with them selves and then
- // the
- // relationship should only be added once.
- if (foreignTable != primaryTable
- && foreignTable instanceof MutableTable) {
- try {
- ((MutableTable) foreignTable).addRelationship(relation);
- } catch (UnsupportedOperationException e) {
- // this is an allowed behaviour - not all tables need to
- // support this method.
- logger.debug(
- "foreign table ({}) threw exception when adding relationship",
- foreignTable);
- }
- }
- }
- return relation;
- }
-
- public void remove() {
- Table primaryTable = getPrimaryTable();
- if (primaryTable instanceof MutableTable) {
- ((MutableTable) primaryTable).removeRelationship(this);
- }
- Table foreignTable = getForeignTable();
- if (foreignTable instanceof MutableTable) {
- ((MutableTable) foreignTable).removeRelationship(this);
- }
- }
-
- @Override
- protected void finalize() throws Throwable {
- super.finalize();
- remove();
- }
-
- public static Relationship createRelationship(Column primaryColumn,
- Column foreignColumn) {
- return createRelationship(new Column[] { primaryColumn },
- new Column[] { foreignColumn });
- }
-
- /**
- * Prevent external instantiation
- */
- private MutableRelationship(Column[] primaryColumns, Column[] foreignColumns) {
- _primaryColumns = primaryColumns;
- _foreignColumns = foreignColumns;
- }
-
- @Override
- public Column[] getPrimaryColumns() {
- return _primaryColumns;
- }
-
- @Override
- public Column[] getForeignColumns() {
- return _foreignColumns;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/MutableSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/MutableSchema.java b/core/src/main/java/org/eobjects/metamodel/schema/MutableSchema.java
deleted file mode 100644
index 71d05d2..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/MutableSchema.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/**
- * 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.schema;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * Represents a schema and it's metadata. Schemas represent a collection of
- * tables.
- *
- * @see Table
- */
-public class MutableSchema extends AbstractSchema implements Serializable,
- Schema {
-
- private static final long serialVersionUID = 4465197783868238863L;
-
- private String _name;
- private final List<MutableTable> _tables;
-
- public MutableSchema() {
- super();
- _tables = new ArrayList<MutableTable>();
- }
-
- public MutableSchema(String name) {
- this();
- _name = name;
- }
-
- public MutableSchema(String name, MutableTable... tables) {
- this(name);
- setTables(tables);
- }
-
- @Override
- public String getName() {
- return _name;
- }
-
- public MutableSchema setName(String name) {
- _name = name;
- return this;
- }
-
- @Override
- public MutableTable[] getTables() {
- MutableTable[] array = new MutableTable[_tables.size()];
- return _tables.toArray(array);
- }
-
- public MutableSchema setTables(Collection<? extends MutableTable> tables) {
- clearTables();
- for (MutableTable table : tables) {
- _tables.add(table);
- }
- return this;
- }
-
- public MutableSchema setTables(MutableTable... tables) {
- clearTables();
- for (MutableTable table : tables) {
- _tables.add(table);
- }
- return this;
- }
-
- public MutableSchema clearTables() {
- _tables.clear();
- return this;
- }
-
- public MutableSchema addTable(MutableTable table) {
- _tables.add(table);
- return this;
- }
-
- public MutableSchema removeTable(Table table) {
- _tables.remove(table);
- return this;
- }
-
- @Override
- public String getQuote() {
- return null;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/MutableTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/MutableTable.java b/core/src/main/java/org/eobjects/metamodel/schema/MutableTable.java
deleted file mode 100644
index fb54377..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/MutableTable.java
+++ /dev/null
@@ -1,202 +0,0 @@
-/**
- * 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.schema;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * Represents the metadata about a table. Tables reside within a schema and
- * contains columns and relationships to other tables.
- *
- * @see Schema
- * @see Column
- * @see Relationship
- */
-public class MutableTable extends AbstractTable implements Serializable {
-
- private static final long serialVersionUID = -5094888465714027354L;
- protected String _name;
- protected TableType _type;
- protected String _remarks;
- protected Schema _schema;
- protected final List<Column> _columns;
- protected final List<Relationship> _relationships;
- protected String _quoteString = null;
-
- public MutableTable() {
- super();
- _columns = new ArrayList<Column>();
- _relationships = new ArrayList<Relationship>();
- }
-
- public MutableTable(String name) {
- this();
- setName(name);
- }
-
- public MutableTable(String name, TableType type) {
- this(name);
- _type = type;
- }
-
- public MutableTable(String name, TableType type, Schema schema) {
- this(name, type);
- _schema = schema;
- }
-
- public MutableTable(String name, TableType type, Schema schema, Column... columns) {
- this(name, type, schema);
- setColumns(columns);
- }
-
- @Override
- public String getName() {
- return _name;
- }
-
- public MutableTable setName(String name) {
- _name = name;
- return this;
- }
-
- /**
- * Internal getter for the columns of the table. Overwrite this method to
- * implement column lookup, column lazy-loading or similar.
- */
- protected List<Column> getColumnsInternal() {
- return _columns;
- }
-
- /**
- * Internal getter for the relationships of the table. Overwrite this method
- * to implement relationship lookup, relationship lazy-loading or similar.
- */
- protected List<Relationship> getRelationshipsInternal() {
- return _relationships;
- }
-
- @Override
- public Column[] getColumns() {
- List<Column> columns = getColumnsInternal();
- return columns.toArray(new Column[columns.size()]);
- }
-
- public MutableTable setColumns(Column... columns) {
- _columns.clear();
- for (Column column : columns) {
- _columns.add(column);
- }
- return this;
- }
-
- public MutableTable setColumns(Collection<Column> columns) {
- _columns.clear();
- for (Column column : columns) {
- _columns.add(column);
- }
- return this;
- }
-
- public MutableTable addColumn(Column column) {
- _columns.add(column);
- return this;
- }
-
- public MutableTable addColumn(int index, Column column) {
- _columns.add(index, column);
- return this;
- }
-
- public MutableTable removeColumn(Column column) {
- _columns.remove(column);
- return this;
- }
-
- @Override
- public Schema getSchema() {
- return _schema;
- }
-
- public MutableTable setSchema(Schema schema) {
- _schema = schema;
- return this;
- }
-
- @Override
- public TableType getType() {
- return _type;
- }
-
- public MutableTable setType(TableType type) {
- _type = type;
- return this;
- }
-
- @Override
- public Relationship[] getRelationships() {
- List<Relationship> relationships = getRelationshipsInternal();
- return relationships.toArray(new Relationship[relationships.size()]);
- }
-
- /**
- * Protected method for adding a relationship to this table. Should not be
- * used. Use Relationship.createRelationship(Column[], Column[]) instead.
- */
- protected void addRelationship(Relationship relation) {
- for (Relationship existingRelationship : _relationships) {
- if (existingRelationship.equals(relation)) {
- // avoid duplicate relationships
- return;
- }
- }
- _relationships.add(relation);
- }
-
- /**
- * Protected method for removing a relationship from this table. Should not
- * be used. Use Relationship.remove() instead.
- */
- protected MutableTable removeRelationship(Relationship relation) {
- _relationships.remove(relation);
- return this;
- }
-
- @Override
- public String getRemarks() {
- return _remarks;
- }
-
- public MutableTable setRemarks(String remarks) {
- _remarks = remarks;
- return this;
- }
-
- @Override
- public String getQuote() {
- return _quoteString;
- }
-
- public MutableTable setQuote(String quoteString) {
- _quoteString = quoteString;
- return this;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/NamedStructure.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/NamedStructure.java b/core/src/main/java/org/eobjects/metamodel/schema/NamedStructure.java
deleted file mode 100644
index a5027d6..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/NamedStructure.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * 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.schema;
-
-import org.eobjects.metamodel.util.HasName;
-
-/**
- * Super-interface for named structural types in a DataContext.
- *
- * @author Kasper Sørensen
- */
-public interface NamedStructure extends HasName {
-
- /**
- * Gets the name of this structure.
- *
- * @return The name of the structure
- */
- public String getName();
-
- /**
- * Gets an optional quote string that is used to enclose the name of this
- * structure.
- *
- * @return A quote string used to enclose the name or null if none exists.
- */
- public String getQuote();
-
- /**
- * Gets the name, including optional quotes, of this structure.
- *
- * @return The name of the structure with added quote strings.
- */
- public String getQuotedName();
-
- /**
- * Gets a qualified label for later lookup. Typically this qualified label
- * is formatted with a simple dot separator. For example, for a column a
- * typical qualified label would be: "MY_SCHEMA.MY_TABLE.MY_COLUMN".
- *
- * The qualified label can be used as a unique identifier for the structure
- * but is not necessarily directly transferable to SQL syntax.
- *
- * @return a qualified label
- */
- public String getQualifiedLabel();
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/Relationship.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/Relationship.java b/core/src/main/java/org/eobjects/metamodel/schema/Relationship.java
deleted file mode 100644
index 00a63d9..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/Relationship.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * 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.schema;
-
-import java.io.Serializable;
-
-/**
- * Represents a relationship between two tables where one set of columns is the
- * primary key, and another set is the foreign key.
- *
- * @see Table
- * @see Column
- *
- * @author Kasper Sørensen
- */
-public interface Relationship extends Serializable, Comparable<Relationship> {
-
- /**
- * Gets the table of the primary key column(s).
- *
- * @return the table of the primary key column(s).
- */
- public Table getPrimaryTable();
-
- /**
- * Gets the primary key columns of this relationship.
- *
- * @return an array of primary key columns.
- */
- public Column[] getPrimaryColumns();
-
- /**
- * Gets the table of the foreign key column(s).
- *
- * @return the table of the foreign key column(s).
- */
- public Table getForeignTable();
-
- /**
- * Gets the foreign key columns of this relationship.
- *
- * @return an array of foreign key columns.
- */
- public Column[] getForeignColumns();
-
- /**
- * Determines whether this relationship contains a specific pair of columns
- *
- * @param pkColumn
- * primary key column
- * @param fkColumn
- * foreign key column
- * @return true if this relation contains the specified primary and foreign
- * columns as a part of the relation
- */
- public boolean containsColumnPair(Column pkColumn, Column fkColumn);
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/Schema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/Schema.java b/core/src/main/java/org/eobjects/metamodel/schema/Schema.java
deleted file mode 100644
index 6aa7183..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/Schema.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/**
- * 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.schema;
-
-import java.io.Serializable;
-
-import org.eobjects.metamodel.DataContext;
-
-/**
- * Represents a schema and it's metadata description. Schemas represent a
- * collection of tables.
- *
- * @see DataContext
- * @see Table
- *
- * @author Kasper Sørensen
- */
-public interface Schema extends Comparable<Schema>, Serializable, NamedStructure {
-
- /**
- * Gets the name of this Schema
- *
- * @return the name of this Schema
- */
- @Override
- public String getName();
-
- /**
- * Gets the number of tables that reside in this schema.
- *
- * @return the number of tables that reside in this schema.
- */
- public int getTableCount();
-
- /**
- * Gets the number of tables in this Schema that comply to a given
- * TableType.
- *
- * @param type
- * the TableType to use for searching and matching.
- * @return the count of tables that match the provided TableType.
- */
- public int getTableCount(TableType type);
-
- /**
- * Gets the names of the tables that reside in this Schema.
- *
- * @return an array of table names.
- */
- public String[] getTableNames();
-
- /**
- * Gets all tables in this Schema.
- *
- * @return the tables that reside in the schema
- */
- public Table[] getTables();
-
- /**
- * Gets all tables in this Schema of a particular type.
- *
- * @param type
- * the TableType to use for searching and matching.
- * @return an array of tables in this schema that matches the specified
- * type.
- */
- public Table[] getTables(TableType type);
-
- /**
- * Gets a table by index. Use {@link #getTableCount()} to get the (0-based)
- * index range
- *
- * @param index
- * the index of the table
- * @return the column with the specified index
- *
- * @throws IndexOutOfBoundsException
- * if the index is out of bounds (index >= table count)
- */
- public Table getTable(int index) throws IndexOutOfBoundsException;
-
- /**
- * Convenience method for retrieving a table by it's name.
- *
- * @param tableName
- * the name of the table to retrieve
- * @return the table with the given name. Returns null if no such table is
- * found.
- */
- public Table getTableByName(String tableName);
-
- /**
- * Gets all relationships to and from this Schema.
- *
- * @return an array of relationships.
- */
- public Relationship[] getRelationships();
-
- /**
- * Gets the number of relationships to and from this Schema.
- *
- * @return the number of relationships to and from this Schema
- */
- public int getRelationshipCount();
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/SuperColumnType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/SuperColumnType.java b/core/src/main/java/org/eobjects/metamodel/schema/SuperColumnType.java
deleted file mode 100644
index d6545bc..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/SuperColumnType.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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.schema;
-
-import java.util.Date;
-
-/**
- * Represents an abstract, generalized type of column
- */
-public enum SuperColumnType {
-
- BOOLEAN_TYPE(Boolean.class),
-
- LITERAL_TYPE(String.class),
-
- NUMBER_TYPE(Number.class),
-
- TIME_TYPE(Date.class),
-
- BINARY_TYPE(byte[].class),
-
- OTHER_TYPE(Object.class);
-
- private Class<?> _javaEquivalentClass;
-
- private SuperColumnType(Class<?> javaEquivalentClass) {
- _javaEquivalentClass = javaEquivalentClass;
- }
-
- /**
- * @return a java class that is appropriate for handling column values of
- * this column super type
- */
- public Class<?> getJavaEquivalentClass() {
- return _javaEquivalentClass;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/Table.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/Table.java b/core/src/main/java/org/eobjects/metamodel/schema/Table.java
deleted file mode 100644
index bc9043c..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/Table.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/**
- * 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.schema;
-
-import java.io.Serializable;
-
-/**
- * Represents a table and it's metadata description. Tables reside within a
- * schema and contains columns and relationships to other tables.
- *
- * @see Schema
- * @see Column
- *
- * @author Kasper Sørensen
- */
-public interface Table extends Comparable<Table>, Serializable, NamedStructure {
-
- /**
- * Gets the name of this Table
- *
- * @return the name of this Table
- */
- @Override
- public String getName();
-
- /**
- * Gets the number of columns in this table.
- *
- * @return the number of columns in this table.
- */
- public int getColumnCount();
-
- /**
- * Gets the columns of this table.
- *
- * @return the columns of this table.
- */
- public Column[] getColumns();
-
- /**
- * Convenience method for retrieving a column by it's name.
- *
- * @param columnName
- * the name of the column to retrieve
- * @return the column with the given name. Returns null if no such column is
- * found.
- */
- public Column getColumnByName(String columnName);
-
- /**
- * Gets a column by index. Use {@link #getColumnCount()} to get the
- * (0-based) index range.
- *
- * @param index
- * the index of the column
- * @return the column with the specified index
- * @throws IndexOutOfBoundsException
- * if the index is out of bounds (index >= column count)
- */
- public Column getColumn(int index) throws IndexOutOfBoundsException;
-
- /**
- * Gets the schema that this table resides in.
- *
- * @return the schema that the table resides in.
- */
- public Schema getSchema();
-
- /**
- * Gets the table type of this table.
- *
- * @return the type of table
- */
- public TableType getType();
-
- /**
- * Gets all relationships for this table.
- *
- * @return all relationsips for this table. To add relations use
- * TableRelation.createRelation();
- */
- public Relationship[] getRelationships();
-
- /**
- * Gets relationships between this table and another table.
- *
- * @param otherTable
- * another table for which to find relationships to and from.
- * @return an array of relationsips between this and the other table.
- */
- public Relationship[] getRelationships(Table otherTable);
-
- /**
- * Gets a count of relationships to and from this table.
- *
- * @return a count of relationships to and from this table.
- */
- public int getRelationshipCount();
-
- /**
- * Gets remarks/comments to this table.
- *
- * @return remarks/comments to this table or null if none exist.
- */
- public String getRemarks();
-
- /**
- * Gets all of this table's columns that are of number type.
- *
- * @return an array of columns.
- * @see ColumnType
- */
- public Column[] getNumberColumns();
-
- /**
- * Gets all of this table's columns that are of literal (String/text) type.
- *
- * @return an array of columns.
- * @see ColumnType
- */
- public Column[] getLiteralColumns();
-
- /**
- * Gets all of this table's columns that are time and/or date based.
- *
- * @return an array of columns.
- * @see ColumnType
- */
- public Column[] getTimeBasedColumns();
-
- /**
- * Gets all of this table's columns that are of boolean type.
- *
- * @return an array of columns.
- * @see ColumnType
- */
- public Column[] getBooleanColumns();
-
- /**
- * Gets all of this table's columns that are indexed.
- *
- * @return an array of columns.
- */
- public Column[] getIndexedColumns();
-
- /**
- * @return the relationships where this table is the foreign table
- */
- public Relationship[] getForeignKeyRelationships();
-
- /**
- * @return the relationships where this table is the primary table
- */
- public Relationship[] getPrimaryKeyRelationships();
-
- /**
- * Gets the columns of this table that are known to be foreign keys (ie.
- * references primary keys in other tables).
- *
- * @return an array of columns that are known to be foreign keys.
- */
- public Column[] getForeignKeys();
-
- /**
- * Gets the columns of this table that are known to be primary keys. See
- * {@link Column#isPrimaryKey()}.
- *
- * @return an array of columns that are known to be primary keys.
- */
- public Column[] getPrimaryKeys();
-
- /**
- * Gets the names of this table's columns.
- *
- * @return an array of column names.
- */
- public String[] getColumnNames();
-
- /**
- * Gets the columns of this table that conforms to a specified
- * {@link ColumnType}.
- *
- * @param columnType
- * the column type to search for.
- * @return an array of columns that match the specified ColumnType.
- */
- public Column[] getColumnsOfType(ColumnType columnType);
-
- /**
- * Gets the columns of this table that conforms to a specified
- * {@link SuperColumnType}.
- *
- * @param superColumnType
- * the super type of the column
- * @return an array of columns that match the specified SuperColumnType.
- */
- public Column[] getColumnsOfSuperType(SuperColumnType superColumnType);
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/TableType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/TableType.java b/core/src/main/java/org/eobjects/metamodel/schema/TableType.java
deleted file mode 100644
index 51b7361..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/TableType.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * 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.schema;
-
-/**
- * Represents the various types of tables
- */
-public enum TableType {
-
- TABLE, VIEW, SYSTEM_TABLE, GLOBAL_TEMPORARY, LOCAL_TEMPORARY, ALIAS, SYNONYM, OTHER;
-
- public static final TableType[] DEFAULT_TABLE_TYPES = new TableType[] {
- TableType.TABLE, TableType.VIEW };
-
- public boolean isMaterialized() {
- switch (this) {
- case TABLE:
- case SYSTEM_TABLE:
- return true;
- default:
- return false;
- }
- }
-
- /**
- * Tries to resolve a TableType based on an incoming string/literal. If no
- * fitting TableType is found, OTHER will be returned.
- */
- public static TableType getTableType(String literalType) {
- literalType = literalType.toUpperCase();
- if ("TABLE".equals(literalType)) {
- return TABLE;
- }
- if ("VIEW".equals(literalType)) {
- return VIEW;
- }
- if ("SYSTEM_TABLE".equals(literalType)) {
- return SYSTEM_TABLE;
- }
- if ("GLOBAL_TEMPORARY".equals(literalType)) {
- return GLOBAL_TEMPORARY;
- }
- if ("LOCAL_TEMPORARY".equals(literalType)) {
- return LOCAL_TEMPORARY;
- }
- if ("ALIAS".equals(literalType)) {
- return ALIAS;
- }
- if ("SYNONYM".equals(literalType)) {
- return SYNONYM;
- }
- return OTHER;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/schema/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/schema/package-info.java b/core/src/main/java/org/eobjects/metamodel/schema/package-info.java
deleted file mode 100644
index 05a5e88..0000000
--- a/core/src/main/java/org/eobjects/metamodel/schema/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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 schema structure
- */
-package org.eobjects.metamodel.schema;
-
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/update/AbstractRowUpdationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/update/AbstractRowUpdationBuilder.java b/core/src/main/java/org/eobjects/metamodel/update/AbstractRowUpdationBuilder.java
deleted file mode 100644
index 59fdd10..0000000
--- a/core/src/main/java/org/eobjects/metamodel/update/AbstractRowUpdationBuilder.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * 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.update;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eobjects.metamodel.data.AbstractRowBuilder;
-import org.eobjects.metamodel.query.FilterClause;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.query.builder.AbstractFilterBuilder;
-import org.eobjects.metamodel.query.builder.FilterBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * Abstract {@link RowUpdationBuilder} implementation.
- */
-public abstract class AbstractRowUpdationBuilder extends AbstractRowBuilder<RowUpdationBuilder> implements
- RowUpdationBuilder {
-
- private final Table _table;
- private final List<FilterItem> _whereItems;
-
- public AbstractRowUpdationBuilder(Table table) {
- super(table);
- _table = table;
- _whereItems = new ArrayList<FilterItem>();
- }
-
- protected List<FilterItem> getWhereItems() {
- return _whereItems;
- }
-
- @Override
- public FilterBuilder<RowUpdationBuilder> where(Column column) {
- SelectItem selectItem = new SelectItem(column);
- return new AbstractFilterBuilder<RowUpdationBuilder>(selectItem) {
- @Override
- protected RowUpdationBuilder applyFilter(FilterItem filter) {
- return where(filter);
- }
- };
- }
-
- @Override
- public FilterBuilder<RowUpdationBuilder> where(String columnName) {
- Column column = _table.getColumnByName(columnName);
- if (column == null) {
- throw new IllegalArgumentException("No such column: " + columnName);
- }
- return where(column);
- }
-
- @Override
- public RowUpdationBuilder where(FilterItem... filterItems) {
- for (FilterItem filterItem : filterItems) {
- _whereItems.add(filterItem);
- }
- return this;
- }
-
- @Override
- public RowUpdationBuilder where(Iterable<FilterItem> filterItems) {
- for (FilterItem filterItem : filterItems) {
- _whereItems.add(filterItem);
- }
- return this;
- }
-
- @Override
- public Table getTable() {
- return _table;
- }
-
- @Override
- public String toSql() {
- StringBuilder sb = new StringBuilder();
- sb.append("UPDATE ");
- sb.append(_table.getQualifiedLabel());
- sb.append(" SET ");
- Column[] columns = getColumns();
- Object[] values = getValues();
-
- for (int i = 0; i < columns.length; i++) {
- if (i != 0) {
- sb.append(',');
- }
- sb.append(columns[i].getName());
- sb.append('=');
- sb.append(values[i] == null ? "NULL" : values[i].toString());
- }
-
- List<FilterItem> whereItems = getWhereItems();
- String whereClause = new FilterClause(null, " WHERE ").addItems(whereItems).toSql();
- sb.append(whereClause);
- return sb.toString();
- }
-
- @Override
- public String toString() {
- return toSql();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/update/RowUpdateable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/update/RowUpdateable.java b/core/src/main/java/org/eobjects/metamodel/update/RowUpdateable.java
deleted file mode 100644
index 3afa7e2..0000000
--- a/core/src/main/java/org/eobjects/metamodel/update/RowUpdateable.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * 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.update;
-
-import org.eobjects.metamodel.schema.Table;
-
-public interface RowUpdateable {
-
- /**
- * Determines whether row update is supported
- *
- * @return true if row update is supported
- */
- public boolean isUpdateSupported();
-
- /**
- * Initiates a row updation builder.
- *
- * @param table
- * @return
- * @throws IllegalArgumentException
- * @throws IllegalStateException
- * @throws UnsupportedOperationException
- */
- public RowUpdationBuilder update(Table table) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException;
-
- /**
- * Initiates a row updation builder.
- *
- * @param tableName
- * @return
- * @throws IllegalArgumentException
- * @throws IllegalStateException
- * @throws UnsupportedOperationException
- */
- public RowUpdationBuilder update(String tableName) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException;
-
- /**
- * Initiates a row updation builder.
- *
- * @param schemaName
- * @param tableName
- * @return
- * @throws IllegalArgumentException
- * @throws IllegalStateException
- * @throws UnsupportedOperationException
- */
- public RowUpdationBuilder update(String schemaName, String tableName) throws IllegalArgumentException,
- IllegalStateException, UnsupportedOperationException;
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/update/RowUpdationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/update/RowUpdationBuilder.java b/core/src/main/java/org/eobjects/metamodel/update/RowUpdationBuilder.java
deleted file mode 100644
index 71df267..0000000
--- a/core/src/main/java/org/eobjects/metamodel/update/RowUpdationBuilder.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * 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.update;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.RowBuilder;
-import org.eobjects.metamodel.data.WhereClauseBuilder;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * Builder object for row update on a {@link Table}.
- *
- * @author Kasper Sørensen
- */
-public interface RowUpdationBuilder extends RowBuilder<RowUpdationBuilder>, WhereClauseBuilder<RowUpdationBuilder> {
-
- /**
- * Gets the table that this update pertains to.
- *
- * @return the table that this update pertains to.
- */
- @Override
- public Table getTable();
-
- /**
- * Gets a SQL representation of this update 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 update operation.
- */
- public String toSql();
-
- /**
- * Commits the row updation operation. This operation will overwrite rows in
- * the {@link DataContext}.
- *
- * @throws MetaModelException
- * if the operation was rejected
- */
- public void execute() throws MetaModelException;
-}
[11/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/test/java/org/apache/metamodel/excel/ExcelDataContextTest.java
----------------------------------------------------------------------
diff --git a/excel/src/test/java/org/apache/metamodel/excel/ExcelDataContextTest.java b/excel/src/test/java/org/apache/metamodel/excel/ExcelDataContextTest.java
new file mode 100644
index 0000000..8710d52
--- /dev/null
+++ b/excel/src/test/java/org/apache/metamodel/excel/ExcelDataContextTest.java
@@ -0,0 +1,741 @@
+/**
+ * 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.excel;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.MetaModelHelper;
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.data.Style;
+import org.eobjects.metamodel.data.StyleBuilder;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.DateUtils;
+import org.eobjects.metamodel.util.FileHelper;
+import org.eobjects.metamodel.util.Month;
+
+public class ExcelDataContextTest extends TestCase {
+
+ public void testErrornousConstructors() throws Exception {
+ try {
+ new ExcelDataContext(null);
+ fail("Exception expected");
+ } catch (IllegalArgumentException e) {
+ assertEquals("File cannot be null", e.getMessage());
+ }
+
+ File file = new File("src/test/resources/empty_file.xls");
+ try {
+ new ExcelDataContext(file, null);
+ fail("Exception expected");
+ } catch (IllegalArgumentException e) {
+ assertEquals("ExcelConfiguration cannot be null", e.getMessage());
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ public void testEmptyFile() throws Exception {
+ File file = new File("src/test/resources/empty_file.xls");
+ ExcelDataContext dc = new ExcelDataContext(file);
+
+ assertNull(dc.getSpreadsheetReaderDelegateClass());
+ assertEquals(1, dc.getDefaultSchema().getTableCount());
+
+ Table table = dc.getDefaultSchema().getTables()[0];
+ assertEquals("sheet", table.getName());
+ assertEquals(0, table.getColumnCount());
+
+ assertSame(file, dc.getFile());
+ }
+
+ public void testEmptyFileNoHeaderLine() throws Exception {
+ DataContext dc = new ExcelDataContext(new File("src/test/resources/empty_file.xls"), new ExcelConfiguration(
+ ExcelConfiguration.NO_COLUMN_NAME_LINE, false, false));
+ assertEquals(1, dc.getDefaultSchema().getTableCount());
+
+ Table table = dc.getDefaultSchema().getTables()[0];
+ assertEquals("sheet", table.getName());
+ assertEquals(0, table.getColumnCount());
+ }
+
+ public void testUnexistingHeaderLine() throws Exception {
+ DataContext dc = new ExcelDataContext(new File("src/test/resources/xls_people.xls"), new ExcelConfiguration(20, true,
+ false));
+ assertEquals(1, dc.getDefaultSchema().getTableCount());
+
+ Table table = dc.getDefaultSchema().getTables()[0];
+ assertEquals("xls_people", table.getName());
+ assertEquals(0, table.getColumnCount());
+ }
+
+ public void testSkipEmptyColumns() throws Exception {
+ ExcelConfiguration conf = new ExcelConfiguration(ExcelConfiguration.DEFAULT_COLUMN_NAME_LINE, true, true);
+ ExcelDataContext dc = new ExcelDataContext(new File("src/test/resources/skipped_lines.xlsx"), conf);
+ Table table = dc.getDefaultSchema().getTables()[0];
+ assertEquals("[hello, world]", Arrays.toString(table.getColumnNames()));
+
+ DataSet ds = dc.executeQuery(dc.query().from(table).select("hello").toQuery());
+ assertTrue(ds.next());
+ assertEquals("1", ds.getRow().getValue(0));
+ }
+
+ public void testDontSkipEmptyLinesNoHeader() throws Exception {
+ ExcelConfiguration conf = new ExcelConfiguration(ExcelConfiguration.NO_COLUMN_NAME_LINE, false, true);
+ ExcelDataContext dc = new ExcelDataContext(new File("src/test/resources/skipped_lines.xlsx"), conf);
+ Table table = dc.getDefaultSchema().getTables()[0];
+ assertEquals("[G, H]", Arrays.toString(table.getColumnNames()));
+
+ assertEquals(6, table.getColumnByName("G").getColumnNumber());
+ assertEquals(7, table.getColumnByName("H").getColumnNumber());
+
+ DataSet ds = dc.executeQuery(dc.query().from(table).select("G").toQuery());
+
+ // 5 empty lines
+ for (int i = 0; i < 5; i++) {
+ assertTrue(ds.next());
+ Object value = ds.getRow().getValue(0);
+ assertNull("Values was: " + value + " at row " + i, value);
+ }
+
+ assertTrue(ds.next());
+ assertEquals("hello", ds.getRow().getValue(0));
+ assertTrue(ds.next());
+ assertEquals("1", ds.getRow().getValue(0));
+ }
+
+ public void testDontSkipEmptyLinesAbsoluteHeader() throws Exception {
+ ExcelConfiguration conf = new ExcelConfiguration(6, false, true);
+ ExcelDataContext dc = new ExcelDataContext(new File("src/test/resources/skipped_lines.xlsx"), conf);
+ Table table = dc.getDefaultSchema().getTables()[0];
+ assertEquals("[hello, world]", Arrays.toString(table.getColumnNames()));
+ assertEquals(6, table.getColumnByName("hello").getColumnNumber());
+ assertEquals(7, table.getColumnByName("world").getColumnNumber());
+
+ DataSet ds = dc.executeQuery(dc.query().from(table).select("hello").toQuery());
+ assertTrue(ds.next());
+ assertEquals("1", ds.getRow().getValue(0));
+ }
+
+ public void testInvalidFormula() throws Exception {
+ ExcelDataContext dc = new ExcelDataContext(new File("src/test/resources/invalid_formula.xls"));
+ Table table = dc.getDefaultSchema().getTables()[0];
+
+ assertEquals("[name]", Arrays.toString(table.getColumnNames()));
+
+ Query q = dc.query().from(table).select("name").toQuery();
+
+ DataSet ds = dc.executeQuery(dc.query().from(table).selectCount().toQuery());
+ assertTrue(ds.next());
+ assertEquals(3, Integer.parseInt(ds.getRow().getValue(0).toString()));
+ assertFalse(ds.next());
+ assertFalse(ds.next());
+ ds.close();
+
+ ds = dc.executeQuery(q);
+
+ Row row;
+
+ assertTrue(ds.next());
+ row = ds.getRow();
+ assertEquals("TismmerswerskisMFSTLandsmeers ", row.getValue(0)
+ .toString());
+
+ assertTrue(ds.next());
+ row = ds.getRow();
+ assertEquals("-\"t\" \"houetismfsthueiss\"", row.getValue(0).toString());
+
+ assertTrue(ds.next());
+ row = ds.getRow();
+ assertEquals("TismmerswerskisMFSTLandsmeers ", row.getValue(0)
+ .toString());
+
+ assertFalse(ds.next());
+ ds.close();
+ }
+
+ public void testEvaluateFormula() throws Exception {
+ ExcelDataContext dc = new ExcelDataContext(new File("src/test/resources/xls_formulas.xls"));
+
+ Table table = dc.getDefaultSchema().getTables()[0];
+ Column[] columns = table.getColumns();
+
+ assertEquals("[some number, some mixed formula, some int only formula]", Arrays.toString(table.getColumnNames()));
+
+ Query q = dc.query().from(table).select(columns).toQuery();
+ DataSet ds = dc.executeQuery(q);
+ Object value;
+
+ assertTrue(ds.next());
+ assertEquals("1", ds.getRow().getValue(columns[0]));
+ value = ds.getRow().getValue(columns[1]);
+ assertEquals(String.class, value.getClass());
+ assertEquals("1", value);
+
+ value = ds.getRow().getValue(columns[2]);
+ assertEquals(String.class, value.getClass());
+ assertEquals("1", value);
+
+ assertTrue(ds.next());
+ assertEquals("2", ds.getRow().getValue(columns[0]));
+ value = ds.getRow().getValue(columns[1]);
+ assertEquals(String.class, value.getClass());
+ assertEquals("3", value);
+
+ value = ds.getRow().getValue(columns[2]);
+ assertEquals(String.class, value.getClass());
+ assertEquals("3", value);
+
+ assertTrue(ds.next());
+ assertEquals("3", ds.getRow().getValue(columns[0]));
+ value = ds.getRow().getValue(columns[1]);
+ assertEquals(String.class, value.getClass());
+ assertEquals("8", value);
+
+ value = ds.getRow().getValue(columns[2]);
+ assertEquals(String.class, value.getClass());
+ assertEquals("8", value);
+
+ assertTrue(ds.next());
+ assertEquals("4", ds.getRow().getValue(columns[0]));
+ value = ds.getRow().getValue(columns[1]);
+ assertEquals(String.class, value.getClass());
+ assertEquals("12", value);
+
+ value = ds.getRow().getValue(columns[2]);
+ assertEquals(String.class, value.getClass());
+ assertEquals("12", value);
+
+ assertTrue(ds.next());
+ assertEquals("5", ds.getRow().getValue(columns[0]));
+ value = ds.getRow().getValue(columns[1]);
+ assertEquals(String.class, value.getClass());
+ assertEquals("yes", value);
+
+ value = ds.getRow().getValue(columns[2]);
+ assertEquals(String.class, value.getClass());
+ assertEquals("5", value);
+
+ assertTrue(ds.next());
+ assertEquals("6", ds.getRow().getValue(columns[0]));
+ value = ds.getRow().getValue(columns[1]);
+ assertEquals(String.class, value.getClass());
+ assertEquals("no", value);
+
+ value = ds.getRow().getValue(columns[2]);
+ assertEquals(String.class, value.getClass());
+ assertEquals("6", value);
+
+ assertFalse(ds.next());
+ }
+
+ public void testSingleCellSheet() throws Exception {
+ ExcelDataContext dc = new ExcelDataContext(new File("src/test/resources/xls_single_cell_sheet.xls"));
+
+ Table table = dc.getDefaultSchema().getTableByName("Sheet1");
+
+ assertNotNull(table);
+
+ assertEquals("[[Column 1], hello]", Arrays.toString(table.getColumnNames()));
+
+ Query q = dc.query().from(table).select(table.getColumns()).toQuery();
+ DataSet ds = dc.executeQuery(q);
+ assertFalse(ds.next());
+ }
+
+ public void testOpenXlsxFormat() throws Exception {
+ ExcelDataContext dc = new ExcelDataContext(new File("src/test/resources/Spreadsheet2007.xlsx"));
+ Schema schema = dc.getDefaultSchema();
+ assertEquals("Schema[name=Spreadsheet2007.xlsx]", schema.toString());
+
+ assertEquals("[Sheet1, Sheet2, Sheet3]", Arrays.toString(schema.getTableNames()));
+
+ assertEquals(0, schema.getTableByName("Sheet2").getColumnCount());
+ assertEquals(0, schema.getTableByName("Sheet3").getColumnCount());
+
+ Table table = schema.getTableByName("Sheet1");
+
+ assertEquals("[string, number, date]", Arrays.toString(table.getColumnNames()));
+
+ Query q = dc.query().from(table).select(table.getColumns()).orderBy(table.getColumnByName("number")).toQuery();
+ DataSet ds = dc.executeQuery(q);
+ List<Object[]> objectArrays = ds.toObjectArrays();
+ assertEquals(4, objectArrays.size());
+ assertEquals("[hello, 1, 2010-01-01 00:00:00]", Arrays.toString(objectArrays.get(0)));
+ assertEquals("[world, 2, 2010-01-02 00:00:00]", Arrays.toString(objectArrays.get(1)));
+ assertEquals("[foo, 3, 2010-01-03 00:00:00]", Arrays.toString(objectArrays.get(2)));
+ assertEquals("[bar, 4, 2010-01-04 00:00:00]", Arrays.toString(objectArrays.get(3)));
+ }
+
+ public void testConfigurationWithoutHeader() throws Exception {
+ File file = new File("src/test/resources/xls_people.xls");
+ DataContext dc = new ExcelDataContext(file, new ExcelConfiguration(ExcelConfiguration.NO_COLUMN_NAME_LINE, true, true));
+ Table table = dc.getDefaultSchema().getTables()[0];
+
+ String[] columnNames = table.getColumnNames();
+ assertEquals("[A, B, C, D]", Arrays.toString(columnNames));
+
+ Query q = dc.query().from(table).select(table.getColumnByName("A")).toQuery();
+ assertEquals("SELECT xls_people.A FROM xls_people.xls.xls_people", q.toSql());
+
+ DataSet dataSet = dc.executeQuery(q);
+ assertTrue(dataSet.next());
+ assertEquals("id", dataSet.getRow().getValue(0));
+ for (int i = 1; i <= 9; i++) {
+ assertTrue(dataSet.next());
+ assertEquals(i + "", dataSet.getRow().getValue(0));
+ }
+
+ assertFalse(dataSet.next());
+ }
+
+ public void testConfigurationNonDefaultColumnNameLineNumber() throws Exception {
+ File file = new File("src/test/resources/xls_people.xls");
+ DataContext dc = new ExcelDataContext(file, new ExcelConfiguration(2, true, true));
+ Table table = dc.getDefaultSchema().getTables()[0];
+
+ String[] columnNames = table.getColumnNames();
+ assertEquals("[1, mike, male, 18]", Arrays.toString(columnNames));
+
+ Query q = dc.query().from(table).select(table.getColumnByName("1")).toQuery();
+ assertEquals("SELECT xls_people.1 FROM xls_people.xls.xls_people", q.toSql());
+
+ DataSet dataSet = dc.executeQuery(q);
+ assertTrue(dataSet.next());
+ assertEquals("2", dataSet.getRow().getValue(0));
+ for (int i = 3; i <= 9; i++) {
+ assertTrue(dataSet.next());
+ assertEquals(i + "", dataSet.getRow().getValue(0));
+ }
+ assertFalse(dataSet.next());
+ }
+
+ public void testGetSchemas() throws Exception {
+ File file = new File("src/test/resources/xls_people.xls");
+ DataContext dc = new ExcelDataContext(file);
+ Schema[] schemas = dc.getSchemas();
+ assertEquals(2, schemas.length);
+ Schema schema = schemas[1];
+ assertEquals("xls_people.xls", schema.getName());
+ assertEquals(1, schema.getTableCount());
+ Table table = schema.getTables()[0];
+ assertEquals("xls_people", table.getName());
+
+ assertEquals(4, table.getColumnCount());
+ assertEquals(0, table.getRelationshipCount());
+
+ Column[] columns = table.getColumns();
+ assertEquals("id", columns[0].getName());
+ assertEquals("name", columns[1].getName());
+ assertEquals("gender", columns[2].getName());
+ assertEquals("age", columns[3].getName());
+ }
+
+ public void testMaterializeTable() throws Exception {
+ File file = new File("src/test/resources/xls_people.xls");
+ ExcelDataContext dc = new ExcelDataContext(file);
+ Table table = dc.getDefaultSchema().getTables()[0];
+ DataSet dataSet = dc.materializeMainSchemaTable(table, table.getColumns(), -1);
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[1, mike, male, 18]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[2, michael, male, 19]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[3, peter, male, 18]]", dataSet.getRow().toString());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertTrue(dataSet.next());
+ assertEquals("Row[values=[9, carrie, female, 17]]", dataSet.getRow().toString());
+ assertFalse(dataSet.next());
+ assertNull(dataSet.getRow());
+ }
+
+ public void testMissingValues() throws Exception {
+ File file = new File("src/test/resources/xls_missing_values.xls");
+ DataContext dc = new ExcelDataContext(file);
+ Schema schema = dc.getDefaultSchema();
+ assertEquals(1, schema.getTableCount());
+
+ Table table = schema.getTables()[0];
+ assertEquals("[Column[name=a,columnNumber=0,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
+ + "Column[name=b,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
+ + "Column[name=c,columnNumber=2,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
+ + "Column[name=d,columnNumber=3,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]",
+ Arrays.toString(table.getColumns()));
+
+ Query q = new Query().select(table.getColumns()).from(table);
+ DataSet ds = dc.executeQuery(q);
+ assertTrue(ds.next());
+ assertEquals("[1, 2, 3, null]", Arrays.toString(ds.getRow().getValues()));
+ assertTrue(ds.next());
+ assertEquals("[5, null, 7, 8]", Arrays.toString(ds.getRow().getValues()));
+ assertTrue(ds.next());
+ assertEquals("[9, 10, 11, 12]", Arrays.toString(ds.getRow().getValues()));
+ assertFalse(ds.next());
+ }
+
+ public void testMissingColumnHeader() throws Exception {
+ File file = new File("src/test/resources/xls_missing_column_header.xls");
+ DataContext dc = new ExcelDataContext(file);
+ Schema schema = dc.getDefaultSchema();
+ assertEquals(1, schema.getTableCount());
+
+ Table table = schema.getTables()[0];
+ assertEquals("[Column[name=a,columnNumber=0,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
+ + "Column[name=b,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
+ + "Column[name=[Column 3],columnNumber=2,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
+ + "Column[name=d,columnNumber=3,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]",
+ Arrays.toString(table.getColumns()));
+
+ Query q = new Query().select(table.getColumns()).from(table);
+ DataSet ds = dc.executeQuery(q);
+ assertTrue(ds.next());
+ assertEquals("[1, 2, 3, 4]", Arrays.toString(ds.getRow().getValues()));
+ assertTrue(ds.next());
+ assertEquals("[5, 6, 7, 8]", Arrays.toString(ds.getRow().getValues()));
+ assertTrue(ds.next());
+ assertEquals("[9, 10, 11, 12]", Arrays.toString(ds.getRow().getValues()));
+ assertFalse(ds.next());
+ }
+
+ public void testXlsxFormulas() throws Exception {
+ File file = new File("src/test/resources/formulas.xlsx");
+ ExcelDataContext dc = new ExcelDataContext(file);
+
+ assertEquals("[sh1]", Arrays.toString(dc.getDefaultSchema().getTableNames()));
+ assertEquals(XlsxSpreadsheetReaderDelegate.class, dc.getSpreadsheetReaderDelegateClass());
+
+ Table table = dc.getDefaultSchema().getTableByName("sh1");
+ assertEquals("[Foo, Bar]", Arrays.toString(table.getColumnNames()));
+
+ Query q = dc.query().from(table).select("Foo").toQuery();
+ DataSet ds = dc.executeQuery(q);
+
+ assertTrue(ds.next());
+ assertEquals("1", ds.getRow().getValue(0).toString());
+ assertEquals("", ds.getRow().getStyle(0).toString());
+ assertTrue(ds.next());
+ assertEquals("2", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("3", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("4", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("5", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("6", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("7", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("8", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("9", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("10", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("11", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("12", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("13", ds.getRow().getValue(0).toString());
+ assertFalse(ds.next());
+
+ q = dc.query().from(table).select("Bar").toQuery();
+ ds = dc.executeQuery(q);
+
+ assertTrue(ds.next());
+ assertEquals("lorem", ds.getRow().getValue(0).toString());
+ assertEquals("", ds.getRow().getStyle(0).toString());
+ assertTrue(ds.next());
+ assertEquals("ipsum", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("21", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("foo", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("bar", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("baz", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals(null, ds.getRow().getValue(0));
+ assertNotNull(null, ds.getRow().getStyle(0));
+ assertTrue(ds.next());
+ assertEquals("!\"#¤%&/()<>=?", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("here are", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("some invalid", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("formulas:", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("#DIV/0!", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("0", ds.getRow().getValue(0).toString());
+ assertFalse(ds.next());
+ }
+
+ public void testTicket99defect() throws Exception {
+ File file = new File("src/test/resources/ticket_199_inventory.xls");
+ DataContext dc = new ExcelDataContext(file);
+ Schema schema = dc.getDefaultSchema();
+ assertEquals(
+ "[Table[name=Sheet1,type=null,remarks=null], Table[name=Sheet2,type=null,remarks=null], Table[name=Sheet3,type=null,remarks=null]]",
+ Arrays.toString(schema.getTables()));
+
+ assertEquals(0, schema.getTableByName("Sheet2").getColumnCount());
+ assertEquals(0, schema.getTableByName("Sheet3").getColumnCount());
+
+ Table table = schema.getTableByName("Sheet1");
+ assertEquals(
+
+ "[Column[name=Pkg No.,columnNumber=0,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
+ + "Column[name=Description,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
+ + "Column[name=Room,columnNumber=2,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
+ + "Column[name=Level,columnNumber=3,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]",
+ Arrays.toString(table.getColumns()));
+ }
+
+ public void testInsertInto() throws Exception {
+ File file = new File("target/xls_people_modified.xls");
+
+ if (file.exists()) {
+ assertTrue(file.delete());
+ }
+
+ FileHelper.copy(new File("src/test/resources/xls_people.xls"), file);
+
+ assertTrue(file.exists());
+
+ ExcelDataContext dc = new ExcelDataContext(file);
+ final Table table = dc.getDefaultSchema().getTables()[0];
+ final Column nameColumn = table.getColumnByName("name");
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ Style clownStyle = new StyleBuilder().bold().foreground(255, 0, 0).background(0, 0, 255).create();
+
+ Style thirtyStyle = new StyleBuilder().italic().underline().centerAligned().foreground(10, 10, 200).create();
+
+ cb.insertInto(table).value("id", 1000).value(nameColumn, "pennywise the [clown]", clownStyle)
+ .value("gender", "male").value("age", 30, thirtyStyle).execute();
+ }
+ });
+
+ DataSet ds = dc.query().from(table).select(nameColumn).orderBy(nameColumn).execute();
+ assertTrue(ds.next());
+ assertEquals("barbara", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("bob", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("carrie", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("charlotte", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("hillary", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("michael", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("mike", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("pennywise the [clown]", ds.getRow().getValue(0).toString());
+ assertEquals("font-weight: bold;color: rgb(255,0,0);background-color: rgb(0,0,255);", ds.getRow().getStyle(0).toString());
+ assertTrue(ds.next());
+ assertEquals("peter", ds.getRow().getValue(0).toString());
+ assertTrue(ds.next());
+ assertEquals("vera", ds.getRow().getValue(0).toString());
+ assertFalse(ds.next());
+ ds.close();
+
+ ds = dc.query().from(table).select("age").where("age").eq(30).execute();
+ assertTrue(ds.next());
+ assertEquals("30", ds.getRow().getValue(0));
+ assertEquals("font-style: italic;text-decoration: underline;text-align: center;color: rgb(0,0,255);", ds.getRow()
+ .getStyle(0).toCSS());
+ assertFalse(ds.next());
+ }
+
+ public void testCreateTable() throws Exception {
+ // run the same test with both XLS and XLSX (because of different
+ // workbook implementations)
+ runCreateTableTest(new File("target/xls_people_created.xls"));
+ runCreateTableTest(new File("target/xls_people_created.xlsx"));
+ }
+
+ private void runCreateTableTest(File file) {
+ if (file.exists()) {
+ assertTrue(file.delete());
+ }
+ final ExcelDataContext dc = new ExcelDataContext(file);
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ Schema schema = dc.getDefaultSchema();
+ Table table1 = cb.createTable(schema, "my_table_1").withColumn("foo").withColumn("bar").withColumn("baz")
+ .execute();
+
+ assertEquals(1, schema.getTableCount());
+ assertSame(table1.getSchema(), schema);
+ assertSame(table1, schema.getTables()[0]);
+
+ Table table2 = cb.createTable(schema, "my_table_2").withColumn("foo").withColumn("bar").withColumn("baz")
+ .execute();
+
+ assertSame(table2.getSchema(), schema);
+ assertSame(table2, schema.getTables()[1]);
+ assertEquals(2, schema.getTableCount());
+
+ cb.insertInto(table1).value("foo", 123.0).value("bar", "str 1").value("baz", true).execute();
+ }
+ });
+
+ dc.refreshSchemas();
+
+ Schema schema = dc.getDefaultSchema();
+ assertEquals(2, schema.getTableCount());
+ assertEquals("[my_table_1, my_table_2]", Arrays.toString(schema.getTableNames()));
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ cb.insertInto(dc.getTableByQualifiedLabel("my_table_1")).value("foo", 456.2)
+ .value("bar", "парфюмерия +и косметика").value("baz", false).execute();
+ }
+ });
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ cb.insertInto("my_table_1").value("foo", 789).value("bar", DateUtils.get(2011, Month.JULY, 8))
+ .value("baz", false).execute();
+ }
+ });
+
+ DataSet ds = dc.query().from("my_table_1").select("foo").and("bar").and("baz").execute();
+ assertTrue(ds.next());
+ assertEquals("Row[values=[123, str 1, true]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[456.2, парфюмерия +и косметика, false]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[789, 2011-07-08 00:00:00, false]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ ds.close();
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.deleteFrom("my_table_1").where("foo").greaterThan("124").execute();
+ }
+ });
+
+ assertEquals("1", MetaModelHelper.executeSingleRowQuery(dc, dc.query().from("my_table_1").selectCount().toQuery())
+ .getValue(0).toString());
+
+ ds = dc.query().from("my_table_1").select("foo").and("bar").and("baz").execute();
+ assertTrue(ds.next());
+ assertEquals("Row[values=[123, str 1, true]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ ds.close();
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.dropTable("my_table_1").execute();
+ }
+ });
+
+ assertEquals("[my_table_2]", Arrays.toString(schema.getTableNames()));
+
+ dc.refreshSchemas();
+
+ assertEquals("[my_table_2]", Arrays.toString(schema.getTableNames()));
+
+ assertEquals(1, dc.getDefaultSchema().getTableCount());
+ }
+
+ public void testGetStyles() throws Exception {
+ DataContext dc = new ExcelDataContext(new File("src/test/resources/styles.xlsx"));
+ Table table = dc.getDefaultSchema().getTables()[0];
+ assertEquals("[style name, example]", Arrays.toString(table.getColumnNames()));
+
+ DataSet ds = dc.query().from(table).select(table.getColumns()).execute();
+ assertTrue(ds.next());
+ assertEquals("Row[values=[bold, foo]]", ds.getRow().toString());
+ assertEquals("", ds.getRow().getStyle(0).toCSS());
+ assertEquals("font-weight: bold;", ds.getRow().getStyle(1).toCSS());
+
+ assertTrue(ds.next());
+ assertEquals("Row[values=[italic, foo]]", ds.getRow().toString());
+ assertEquals("", ds.getRow().getStyle(0).toCSS());
+ assertEquals("font-style: italic;", ds.getRow().getStyle(1).toCSS());
+
+ assertTrue(ds.next());
+ assertEquals("Row[values=[underline, foo]]", ds.getRow().toString());
+ assertEquals("", ds.getRow().getStyle(0).toCSS());
+ assertEquals("text-decoration: underline;", ds.getRow().getStyle(1).toCSS());
+
+ assertTrue(ds.next());
+ assertEquals("Row[values=[custom text col, foo]]", ds.getRow().toString());
+ assertEquals("", ds.getRow().getStyle(0).toCSS());
+ assertEquals("color: rgb(138,67,143);", ds.getRow().getStyle(1).toCSS());
+
+ assertTrue(ds.next());
+ assertEquals("Row[values=[yellow text col, foo]]", ds.getRow().toString());
+ assertEquals("", ds.getRow().getStyle(0).toCSS());
+ assertEquals("color: rgb(255,255,0);", ds.getRow().getStyle(1).toCSS());
+
+ assertTrue(ds.next());
+ assertEquals("Row[values=[custom bg, foo]]", ds.getRow().toString());
+ assertEquals("", ds.getRow().getStyle(0).toCSS());
+ assertEquals("background-color: rgb(136,228,171);", ds.getRow().getStyle(1).toCSS());
+
+ assertTrue(ds.next());
+ assertEquals("Row[values=[yellow bg, foo]]", ds.getRow().toString());
+ assertEquals("", ds.getRow().getStyle(0).toCSS());
+ assertEquals("background-color: rgb(255,255,0);", ds.getRow().getStyle(1).toCSS());
+
+ assertTrue(ds.next());
+ assertEquals("Row[values=[center align, foo]]", ds.getRow().toString());
+ assertEquals("", ds.getRow().getStyle(0).toCSS());
+ assertEquals("text-align: center;", ds.getRow().getStyle(1).toCSS());
+
+ assertTrue(ds.next());
+ assertEquals("Row[values=[font size 8, foo]]", ds.getRow().toString());
+ assertEquals("", ds.getRow().getStyle(0).toCSS());
+ assertEquals("font-size: 8pt;", ds.getRow().getStyle(1).toCSS());
+
+ assertTrue(ds.next());
+ assertEquals("Row[values=[font size 16, foo]]", ds.getRow().toString());
+ assertEquals("", ds.getRow().getStyle(0).toCSS());
+ assertEquals("font-size: 16pt;", ds.getRow().getStyle(1).toCSS());
+
+ assertFalse(ds.next());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/test/java/org/apache/metamodel/excel/ExcelUpdateCallbackTest.java
----------------------------------------------------------------------
diff --git a/excel/src/test/java/org/apache/metamodel/excel/ExcelUpdateCallbackTest.java b/excel/src/test/java/org/apache/metamodel/excel/ExcelUpdateCallbackTest.java
new file mode 100644
index 0000000..d1b4e16
--- /dev/null
+++ b/excel/src/test/java/org/apache/metamodel/excel/ExcelUpdateCallbackTest.java
@@ -0,0 +1,103 @@
+/**
+ * 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.excel;
+
+import java.io.File;
+import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.xssf.streaming.SXSSFRow;
+import org.apache.poi.xssf.streaming.SXSSFSheet;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.schema.Table;
+
+public class ExcelUpdateCallbackTest extends TestCase {
+
+ public void testStreamingAPI() throws Exception {
+ File file = new File("target/streaming-api-test.xlsx");
+ if (file.exists()) {
+ file.delete();
+ }
+
+ assertFalse(file.exists());
+
+ // write using streaming writer
+ {
+ ExcelDataContext dc = new ExcelDataContext(file);
+ ExcelUpdateCallback callback = new ExcelUpdateCallback(dc);
+
+ SXSSFSheet sheet = (SXSSFSheet) callback.createSheet("foobar");
+
+ Field windowSizeField = SXSSFSheet.class
+ .getDeclaredField("_randomAccessWindowSize");
+ windowSizeField.setAccessible(true);
+ int windowSize = windowSizeField.getInt(sheet);
+ assertEquals(1000, windowSize);
+
+ Field rowsField = SXSSFSheet.class.getDeclaredField("_rows");
+ rowsField.setAccessible(true);
+ @SuppressWarnings("unchecked")
+ Map<Integer, SXSSFRow> rows = (Map<Integer, SXSSFRow>) rowsField
+ .get(sheet);
+ assertEquals(0, rows.size());
+
+ // create 5x the amound of rows as the streaming sheet will hold in
+ // memory
+ for (int i = 0; i < windowSize * 5; i++) {
+ Row row = sheet.createRow(i);
+ Cell cell = row.createCell(0);
+ cell.setCellValue("value" + i);
+
+ assertTrue(rows.size() <= 1000);
+ }
+
+ assertEquals(1000, rows.size());
+
+ ExcelUtils.writeWorkbook(dc, sheet.getWorkbook());
+ }
+
+ assertTrue("Usually the file size will be circa 42000, but it was: "
+ + file.length(), file.length() > 40000 && file.length() < 45000);
+
+ // read to check results
+ {
+ ExcelDataContext dc = new ExcelDataContext(file);
+ assertEquals("[foobar]",
+ Arrays.toString(dc.getDefaultSchema().getTableNames()));
+
+ Table table = dc.getDefaultSchema().getTableByName("foobar");
+
+ assertEquals("[value0]", Arrays.toString(table.getColumnNames()));
+
+ DataSet ds = dc.query().from(table).select("value0").execute();
+ int recordNo = 1;
+ while (ds.next()) {
+ assertEquals("value" + recordNo, ds.getRow().getValue(0));
+ recordNo++;
+ }
+
+ assertEquals(5000, recordNo);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/test/java/org/apache/metamodel/excel/ZeroBasedRowIteratorTest.java
----------------------------------------------------------------------
diff --git a/excel/src/test/java/org/apache/metamodel/excel/ZeroBasedRowIteratorTest.java b/excel/src/test/java/org/apache/metamodel/excel/ZeroBasedRowIteratorTest.java
new file mode 100644
index 0000000..3e2852a
--- /dev/null
+++ b/excel/src/test/java/org/apache/metamodel/excel/ZeroBasedRowIteratorTest.java
@@ -0,0 +1,75 @@
+/**
+ * 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.excel;
+
+import java.io.FileInputStream;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
+import org.easymock.EasyMock;
+import org.eobjects.metamodel.excel.ZeroBasedRowIterator;
+
+public class ZeroBasedRowIteratorTest extends TestCase {
+
+ public void testHasNext() throws Exception {
+ Workbook workbook = WorkbookFactory.create(new FileInputStream(
+ "src/test/resources/xls_single_cell_sheet.xls"));
+ Sheet sheet = workbook.getSheetAt(0);
+
+ // POI's row numbers are 0-based also - the last cell in the sheet is
+ // actually A6.
+ assertEquals(5, sheet.getLastRowNum());
+
+ ZeroBasedRowIterator it = new ZeroBasedRowIterator(sheet);
+
+ assertTrue(it.hasNext());
+ assertNull(it.next());
+
+ assertTrue(it.hasNext());
+ assertNull(it.next());
+
+ assertTrue(it.hasNext());
+ assertNull(it.next());
+
+ assertTrue(it.hasNext());
+ assertNull(it.next());
+
+ assertTrue(it.hasNext());
+ assertNull(it.next());
+
+ assertTrue(it.hasNext());
+ assertNotNull(it.next());
+
+ assertFalse(it.hasNext());
+ }
+
+ public void testUnsupportedRemove() throws Exception {
+ ZeroBasedRowIterator it = new ZeroBasedRowIterator(EasyMock.createMock(Sheet.class));
+
+ try {
+ it.remove();
+ fail("Exception expected");
+ } catch (UnsupportedOperationException e) {
+ assertEquals("remove() is not supported", e.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/test/java/org/eobjects/metamodel/excel/DefaultSpreadsheetReaderDelegateTest.java
----------------------------------------------------------------------
diff --git a/excel/src/test/java/org/eobjects/metamodel/excel/DefaultSpreadsheetReaderDelegateTest.java b/excel/src/test/java/org/eobjects/metamodel/excel/DefaultSpreadsheetReaderDelegateTest.java
deleted file mode 100644
index dc2e87c..0000000
--- a/excel/src/test/java/org/eobjects/metamodel/excel/DefaultSpreadsheetReaderDelegateTest.java
+++ /dev/null
@@ -1,244 +0,0 @@
-/**
- * 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.excel;
-
-import java.io.File;
-import java.lang.reflect.Field;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-public class DefaultSpreadsheetReaderDelegateTest extends TestCase {
-
- public void testReadAllTestResourceFiles() {
- File[] listFiles = new File("src/test/resources").listFiles();
- for (File file : listFiles) {
- if (file.isFile() && file.getName().indexOf(".xls") != -1) {
- try {
- runTest(file);
- } catch (Throwable e) {
- throw new IllegalStateException("Exception in file: "
- + file, e);
- }
- }
- }
- }
-
- private void runTest(File file) throws Exception {
- ExcelDataContext mainDataContext = new ExcelDataContext(file);
- applyReaderDelegate(mainDataContext);
-
- ExcelDataContext comparedDataContext = null;
- if (file.getName().endsWith(".xlsx")) {
- comparedDataContext = new ExcelDataContext(file);
- }
-
- Schema schema = mainDataContext.getDefaultSchema();
- assertNotNull(schema);
- assertEquals(file.getName(), schema.getName());
-
- if (comparedDataContext != null) {
- assertEquals(comparedDataContext.getDefaultSchema().getName(),
- schema.getName());
- }
-
- assertEquals(DefaultSpreadsheetReaderDelegate.class,
- mainDataContext.getSpreadsheetReaderDelegateClass());
-
- Table[] tables = schema.getTables();
- assertTrue(tables.length > 0);
-
- Table[] comparedTables = null;
- if (comparedDataContext != null) {
- assertEquals(XlsxSpreadsheetReaderDelegate.class,
- comparedDataContext.getSpreadsheetReaderDelegateClass());
- comparedTables = comparedDataContext.getDefaultSchema().getTables();
- assertEquals(comparedTables.length, tables.length);
- }
-
- for (int i = 0; i < tables.length; i++) {
- Table table = tables[i];
- Column[] columns = table.getColumns();
- Query query = mainDataContext.query().from(table).select(columns)
- .toQuery();
- DataSet dataSet = mainDataContext.executeQuery(query);
-
- DataSet comparedDataSet = null;
- if (comparedDataContext != null) {
- Table comparedTable = comparedTables[i];
- assertEquals(comparedTable.getName(), table.getName());
- assertEquals(comparedTable.getColumnCount(),
- table.getColumnCount());
-
- Column[] comparedColumns = comparedTable.getColumns();
- for (int j = 0; j < comparedColumns.length; j++) {
- assertEquals(columns[j].getColumnNumber(),
- comparedColumns[j].getColumnNumber());
- }
-
- Query comparedQuery = comparedDataContext.query()
- .from(comparedTable).select(comparedColumns).toQuery();
- comparedDataSet = comparedDataContext
- .executeQuery(comparedQuery);
- }
-
- while (dataSet.next()) {
- Row row = dataSet.getRow();
- assertNotNull(row);
- Object[] values = row.getValues();
-
- assertEquals(values.length, table.getColumnCount());
-
- if (comparedDataSet != null) {
- boolean next = comparedDataSet.next();
- assertTrue("No comparable row exists for: " + row, next);
- Row comparedRow = comparedDataSet.getRow();
- assertNotNull(comparedRow);
- Object[] comparedValues = comparedRow.getValues();
- assertEquals(comparedValues.length, table.getColumnCount());
-
- for (int j = 0; j < comparedValues.length; j++) {
- assertEquals(comparedValues[j], values[j]);
- }
-
- // compare styles
- for (int j = 0; j < comparedValues.length; j++) {
- Style style1 = comparedRow.getStyle(j);
- Style style2 = row.getStyle(j);
- assertEquals("Diff in style on row: " + row
- + " (value index = " + j + ")\nStyle 1: "
- + style1 + "\nStyle 2: " + style2 + ". ",
- style1, style2);
- }
- }
- }
- dataSet.close();
-
- if (comparedDataSet != null) {
- assertFalse(comparedDataSet.next());
- comparedDataSet.close();
- }
- }
- }
-
- /**
- * Applies the {@link DefaultSpreadsheetReaderDelegate} through reflection.
- *
- * @param dataContext
- * @throws NoSuchFieldException
- * @throws IllegalAccessException
- */
- private void applyReaderDelegate(ExcelDataContext dataContext)
- throws NoSuchFieldException, IllegalAccessException {
- Field field = ExcelDataContext.class
- .getDeclaredField("_spreadsheetReaderDelegate");
- assertNotNull(field);
- field.setAccessible(true);
- field.set(
- dataContext,
- new DefaultSpreadsheetReaderDelegate(dataContext
- .getConfiguration()));
- }
-
- public void testStylingOfDateCell() throws Exception {
- ExcelDataContext dc = new ExcelDataContext(new File(
- "src/test/resources/Spreadsheet2007.xlsx"));
- applyReaderDelegate(dc);
-
- Table table = dc.getDefaultSchema().getTables()[0];
-
- final String expectedStyling = "";
-
- DataSet dataSet = dc.query().from(table).select("date").execute();
- assertTrue(dataSet.next());
- assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
- assertTrue(dataSet.next());
- assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
- assertTrue(dataSet.next());
- assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
- assertTrue(dataSet.next());
- assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
- assertFalse(dataSet.next());
- dataSet.close();
- }
-
- public void testStylingOfNullCell() throws Exception {
- ExcelDataContext dc = new ExcelDataContext(new File(
- "src/test/resources/formulas.xlsx"));
- applyReaderDelegate(dc);
-
- Table table = dc.getDefaultSchema().getTables()[0];
-
- DataSet dataSet = dc.query().from(table).select("Foo").and("Bar")
- .where("Foo").isEquals("7").execute();
- assertTrue(dataSet.next());
- Row row = dataSet.getRow();
- assertNotNull(row.getStyle(0));
-
- final String expectedStyling = "";
-
- assertEquals(expectedStyling, row.getStyle(0).toCSS());
- assertNotNull(row.getStyle(1));
- assertEquals(expectedStyling, row.getStyle(1).toCSS());
- assertFalse(dataSet.next());
- dataSet.close();
-
- dataSet = dc.query().from(table).select("Foo").and("Bar").execute();
- assertTrue(dataSet.next());
- row = dataSet.getRow();
- assertNotNull(row.getStyle(0));
- assertEquals(expectedStyling, row.getStyle(0).toCSS());
- assertNotNull(row.getStyle(1));
- assertEquals(expectedStyling, row.getStyle(1).toCSS());
-
- assertTrue(dataSet.next());
- assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
- assertTrue(dataSet.next());
- assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
- assertTrue(dataSet.next());
- assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
- assertTrue(dataSet.next());
- assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
- assertTrue(dataSet.next());
- assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
- assertTrue(dataSet.next());
- assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
- assertTrue(dataSet.next());
- assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
- assertTrue(dataSet.next());
- assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
- assertTrue(dataSet.next());
- assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
- assertTrue(dataSet.next());
- assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
- assertTrue(dataSet.next());
- assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
- assertTrue(dataSet.next());
- assertEquals(expectedStyling, dataSet.getRow().getStyle(0).toCSS());
- assertFalse(dataSet.next());
- dataSet.close();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/test/java/org/eobjects/metamodel/excel/ExcelConfigurationTest.java
----------------------------------------------------------------------
diff --git a/excel/src/test/java/org/eobjects/metamodel/excel/ExcelConfigurationTest.java b/excel/src/test/java/org/eobjects/metamodel/excel/ExcelConfigurationTest.java
deleted file mode 100644
index 5bc9b00..0000000
--- a/excel/src/test/java/org/eobjects/metamodel/excel/ExcelConfigurationTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * 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.excel;
-
-import org.eobjects.metamodel.excel.ExcelConfiguration;
-
-import junit.framework.TestCase;
-
-public class ExcelConfigurationTest extends TestCase {
-
- public void testToString() throws Exception {
- ExcelConfiguration conf = new ExcelConfiguration(1, true, false);
- assertEquals(
- "ExcelConfiguration[columnNameLineNumber=1, skipEmptyLines=true, skipEmptyColumns=false]",
- conf.toString());
- }
-
- public void testEquals() throws Exception {
- ExcelConfiguration conf1 = new ExcelConfiguration(1, true, false);
- ExcelConfiguration conf2 = new ExcelConfiguration(1, true, false);
- ExcelConfiguration conf3 = new ExcelConfiguration(2, true, false);
-
- assertEquals(conf1, conf2);
- assertFalse(conf1.equals(conf3));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/excel/src/test/java/org/eobjects/metamodel/excel/ExcelDataContextTest.java
----------------------------------------------------------------------
diff --git a/excel/src/test/java/org/eobjects/metamodel/excel/ExcelDataContextTest.java b/excel/src/test/java/org/eobjects/metamodel/excel/ExcelDataContextTest.java
deleted file mode 100644
index 8710d52..0000000
--- a/excel/src/test/java/org/eobjects/metamodel/excel/ExcelDataContextTest.java
+++ /dev/null
@@ -1,741 +0,0 @@
-/**
- * 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.excel;
-
-import java.io.File;
-import java.util.Arrays;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.data.StyleBuilder;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.DateUtils;
-import org.eobjects.metamodel.util.FileHelper;
-import org.eobjects.metamodel.util.Month;
-
-public class ExcelDataContextTest extends TestCase {
-
- public void testErrornousConstructors() throws Exception {
- try {
- new ExcelDataContext(null);
- fail("Exception expected");
- } catch (IllegalArgumentException e) {
- assertEquals("File cannot be null", e.getMessage());
- }
-
- File file = new File("src/test/resources/empty_file.xls");
- try {
- new ExcelDataContext(file, null);
- fail("Exception expected");
- } catch (IllegalArgumentException e) {
- assertEquals("ExcelConfiguration cannot be null", e.getMessage());
- }
- }
-
- @SuppressWarnings("deprecation")
- public void testEmptyFile() throws Exception {
- File file = new File("src/test/resources/empty_file.xls");
- ExcelDataContext dc = new ExcelDataContext(file);
-
- assertNull(dc.getSpreadsheetReaderDelegateClass());
- assertEquals(1, dc.getDefaultSchema().getTableCount());
-
- Table table = dc.getDefaultSchema().getTables()[0];
- assertEquals("sheet", table.getName());
- assertEquals(0, table.getColumnCount());
-
- assertSame(file, dc.getFile());
- }
-
- public void testEmptyFileNoHeaderLine() throws Exception {
- DataContext dc = new ExcelDataContext(new File("src/test/resources/empty_file.xls"), new ExcelConfiguration(
- ExcelConfiguration.NO_COLUMN_NAME_LINE, false, false));
- assertEquals(1, dc.getDefaultSchema().getTableCount());
-
- Table table = dc.getDefaultSchema().getTables()[0];
- assertEquals("sheet", table.getName());
- assertEquals(0, table.getColumnCount());
- }
-
- public void testUnexistingHeaderLine() throws Exception {
- DataContext dc = new ExcelDataContext(new File("src/test/resources/xls_people.xls"), new ExcelConfiguration(20, true,
- false));
- assertEquals(1, dc.getDefaultSchema().getTableCount());
-
- Table table = dc.getDefaultSchema().getTables()[0];
- assertEquals("xls_people", table.getName());
- assertEquals(0, table.getColumnCount());
- }
-
- public void testSkipEmptyColumns() throws Exception {
- ExcelConfiguration conf = new ExcelConfiguration(ExcelConfiguration.DEFAULT_COLUMN_NAME_LINE, true, true);
- ExcelDataContext dc = new ExcelDataContext(new File("src/test/resources/skipped_lines.xlsx"), conf);
- Table table = dc.getDefaultSchema().getTables()[0];
- assertEquals("[hello, world]", Arrays.toString(table.getColumnNames()));
-
- DataSet ds = dc.executeQuery(dc.query().from(table).select("hello").toQuery());
- assertTrue(ds.next());
- assertEquals("1", ds.getRow().getValue(0));
- }
-
- public void testDontSkipEmptyLinesNoHeader() throws Exception {
- ExcelConfiguration conf = new ExcelConfiguration(ExcelConfiguration.NO_COLUMN_NAME_LINE, false, true);
- ExcelDataContext dc = new ExcelDataContext(new File("src/test/resources/skipped_lines.xlsx"), conf);
- Table table = dc.getDefaultSchema().getTables()[0];
- assertEquals("[G, H]", Arrays.toString(table.getColumnNames()));
-
- assertEquals(6, table.getColumnByName("G").getColumnNumber());
- assertEquals(7, table.getColumnByName("H").getColumnNumber());
-
- DataSet ds = dc.executeQuery(dc.query().from(table).select("G").toQuery());
-
- // 5 empty lines
- for (int i = 0; i < 5; i++) {
- assertTrue(ds.next());
- Object value = ds.getRow().getValue(0);
- assertNull("Values was: " + value + " at row " + i, value);
- }
-
- assertTrue(ds.next());
- assertEquals("hello", ds.getRow().getValue(0));
- assertTrue(ds.next());
- assertEquals("1", ds.getRow().getValue(0));
- }
-
- public void testDontSkipEmptyLinesAbsoluteHeader() throws Exception {
- ExcelConfiguration conf = new ExcelConfiguration(6, false, true);
- ExcelDataContext dc = new ExcelDataContext(new File("src/test/resources/skipped_lines.xlsx"), conf);
- Table table = dc.getDefaultSchema().getTables()[0];
- assertEquals("[hello, world]", Arrays.toString(table.getColumnNames()));
- assertEquals(6, table.getColumnByName("hello").getColumnNumber());
- assertEquals(7, table.getColumnByName("world").getColumnNumber());
-
- DataSet ds = dc.executeQuery(dc.query().from(table).select("hello").toQuery());
- assertTrue(ds.next());
- assertEquals("1", ds.getRow().getValue(0));
- }
-
- public void testInvalidFormula() throws Exception {
- ExcelDataContext dc = new ExcelDataContext(new File("src/test/resources/invalid_formula.xls"));
- Table table = dc.getDefaultSchema().getTables()[0];
-
- assertEquals("[name]", Arrays.toString(table.getColumnNames()));
-
- Query q = dc.query().from(table).select("name").toQuery();
-
- DataSet ds = dc.executeQuery(dc.query().from(table).selectCount().toQuery());
- assertTrue(ds.next());
- assertEquals(3, Integer.parseInt(ds.getRow().getValue(0).toString()));
- assertFalse(ds.next());
- assertFalse(ds.next());
- ds.close();
-
- ds = dc.executeQuery(q);
-
- Row row;
-
- assertTrue(ds.next());
- row = ds.getRow();
- assertEquals("TismmerswerskisMFSTLandsmeers ", row.getValue(0)
- .toString());
-
- assertTrue(ds.next());
- row = ds.getRow();
- assertEquals("-\"t\" \"houetismfsthueiss\"", row.getValue(0).toString());
-
- assertTrue(ds.next());
- row = ds.getRow();
- assertEquals("TismmerswerskisMFSTLandsmeers ", row.getValue(0)
- .toString());
-
- assertFalse(ds.next());
- ds.close();
- }
-
- public void testEvaluateFormula() throws Exception {
- ExcelDataContext dc = new ExcelDataContext(new File("src/test/resources/xls_formulas.xls"));
-
- Table table = dc.getDefaultSchema().getTables()[0];
- Column[] columns = table.getColumns();
-
- assertEquals("[some number, some mixed formula, some int only formula]", Arrays.toString(table.getColumnNames()));
-
- Query q = dc.query().from(table).select(columns).toQuery();
- DataSet ds = dc.executeQuery(q);
- Object value;
-
- assertTrue(ds.next());
- assertEquals("1", ds.getRow().getValue(columns[0]));
- value = ds.getRow().getValue(columns[1]);
- assertEquals(String.class, value.getClass());
- assertEquals("1", value);
-
- value = ds.getRow().getValue(columns[2]);
- assertEquals(String.class, value.getClass());
- assertEquals("1", value);
-
- assertTrue(ds.next());
- assertEquals("2", ds.getRow().getValue(columns[0]));
- value = ds.getRow().getValue(columns[1]);
- assertEquals(String.class, value.getClass());
- assertEquals("3", value);
-
- value = ds.getRow().getValue(columns[2]);
- assertEquals(String.class, value.getClass());
- assertEquals("3", value);
-
- assertTrue(ds.next());
- assertEquals("3", ds.getRow().getValue(columns[0]));
- value = ds.getRow().getValue(columns[1]);
- assertEquals(String.class, value.getClass());
- assertEquals("8", value);
-
- value = ds.getRow().getValue(columns[2]);
- assertEquals(String.class, value.getClass());
- assertEquals("8", value);
-
- assertTrue(ds.next());
- assertEquals("4", ds.getRow().getValue(columns[0]));
- value = ds.getRow().getValue(columns[1]);
- assertEquals(String.class, value.getClass());
- assertEquals("12", value);
-
- value = ds.getRow().getValue(columns[2]);
- assertEquals(String.class, value.getClass());
- assertEquals("12", value);
-
- assertTrue(ds.next());
- assertEquals("5", ds.getRow().getValue(columns[0]));
- value = ds.getRow().getValue(columns[1]);
- assertEquals(String.class, value.getClass());
- assertEquals("yes", value);
-
- value = ds.getRow().getValue(columns[2]);
- assertEquals(String.class, value.getClass());
- assertEquals("5", value);
-
- assertTrue(ds.next());
- assertEquals("6", ds.getRow().getValue(columns[0]));
- value = ds.getRow().getValue(columns[1]);
- assertEquals(String.class, value.getClass());
- assertEquals("no", value);
-
- value = ds.getRow().getValue(columns[2]);
- assertEquals(String.class, value.getClass());
- assertEquals("6", value);
-
- assertFalse(ds.next());
- }
-
- public void testSingleCellSheet() throws Exception {
- ExcelDataContext dc = new ExcelDataContext(new File("src/test/resources/xls_single_cell_sheet.xls"));
-
- Table table = dc.getDefaultSchema().getTableByName("Sheet1");
-
- assertNotNull(table);
-
- assertEquals("[[Column 1], hello]", Arrays.toString(table.getColumnNames()));
-
- Query q = dc.query().from(table).select(table.getColumns()).toQuery();
- DataSet ds = dc.executeQuery(q);
- assertFalse(ds.next());
- }
-
- public void testOpenXlsxFormat() throws Exception {
- ExcelDataContext dc = new ExcelDataContext(new File("src/test/resources/Spreadsheet2007.xlsx"));
- Schema schema = dc.getDefaultSchema();
- assertEquals("Schema[name=Spreadsheet2007.xlsx]", schema.toString());
-
- assertEquals("[Sheet1, Sheet2, Sheet3]", Arrays.toString(schema.getTableNames()));
-
- assertEquals(0, schema.getTableByName("Sheet2").getColumnCount());
- assertEquals(0, schema.getTableByName("Sheet3").getColumnCount());
-
- Table table = schema.getTableByName("Sheet1");
-
- assertEquals("[string, number, date]", Arrays.toString(table.getColumnNames()));
-
- Query q = dc.query().from(table).select(table.getColumns()).orderBy(table.getColumnByName("number")).toQuery();
- DataSet ds = dc.executeQuery(q);
- List<Object[]> objectArrays = ds.toObjectArrays();
- assertEquals(4, objectArrays.size());
- assertEquals("[hello, 1, 2010-01-01 00:00:00]", Arrays.toString(objectArrays.get(0)));
- assertEquals("[world, 2, 2010-01-02 00:00:00]", Arrays.toString(objectArrays.get(1)));
- assertEquals("[foo, 3, 2010-01-03 00:00:00]", Arrays.toString(objectArrays.get(2)));
- assertEquals("[bar, 4, 2010-01-04 00:00:00]", Arrays.toString(objectArrays.get(3)));
- }
-
- public void testConfigurationWithoutHeader() throws Exception {
- File file = new File("src/test/resources/xls_people.xls");
- DataContext dc = new ExcelDataContext(file, new ExcelConfiguration(ExcelConfiguration.NO_COLUMN_NAME_LINE, true, true));
- Table table = dc.getDefaultSchema().getTables()[0];
-
- String[] columnNames = table.getColumnNames();
- assertEquals("[A, B, C, D]", Arrays.toString(columnNames));
-
- Query q = dc.query().from(table).select(table.getColumnByName("A")).toQuery();
- assertEquals("SELECT xls_people.A FROM xls_people.xls.xls_people", q.toSql());
-
- DataSet dataSet = dc.executeQuery(q);
- assertTrue(dataSet.next());
- assertEquals("id", dataSet.getRow().getValue(0));
- for (int i = 1; i <= 9; i++) {
- assertTrue(dataSet.next());
- assertEquals(i + "", dataSet.getRow().getValue(0));
- }
-
- assertFalse(dataSet.next());
- }
-
- public void testConfigurationNonDefaultColumnNameLineNumber() throws Exception {
- File file = new File("src/test/resources/xls_people.xls");
- DataContext dc = new ExcelDataContext(file, new ExcelConfiguration(2, true, true));
- Table table = dc.getDefaultSchema().getTables()[0];
-
- String[] columnNames = table.getColumnNames();
- assertEquals("[1, mike, male, 18]", Arrays.toString(columnNames));
-
- Query q = dc.query().from(table).select(table.getColumnByName("1")).toQuery();
- assertEquals("SELECT xls_people.1 FROM xls_people.xls.xls_people", q.toSql());
-
- DataSet dataSet = dc.executeQuery(q);
- assertTrue(dataSet.next());
- assertEquals("2", dataSet.getRow().getValue(0));
- for (int i = 3; i <= 9; i++) {
- assertTrue(dataSet.next());
- assertEquals(i + "", dataSet.getRow().getValue(0));
- }
- assertFalse(dataSet.next());
- }
-
- public void testGetSchemas() throws Exception {
- File file = new File("src/test/resources/xls_people.xls");
- DataContext dc = new ExcelDataContext(file);
- Schema[] schemas = dc.getSchemas();
- assertEquals(2, schemas.length);
- Schema schema = schemas[1];
- assertEquals("xls_people.xls", schema.getName());
- assertEquals(1, schema.getTableCount());
- Table table = schema.getTables()[0];
- assertEquals("xls_people", table.getName());
-
- assertEquals(4, table.getColumnCount());
- assertEquals(0, table.getRelationshipCount());
-
- Column[] columns = table.getColumns();
- assertEquals("id", columns[0].getName());
- assertEquals("name", columns[1].getName());
- assertEquals("gender", columns[2].getName());
- assertEquals("age", columns[3].getName());
- }
-
- public void testMaterializeTable() throws Exception {
- File file = new File("src/test/resources/xls_people.xls");
- ExcelDataContext dc = new ExcelDataContext(file);
- Table table = dc.getDefaultSchema().getTables()[0];
- DataSet dataSet = dc.materializeMainSchemaTable(table, table.getColumns(), -1);
- assertTrue(dataSet.next());
- assertEquals("Row[values=[1, mike, male, 18]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[2, michael, male, 19]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[3, peter, male, 18]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[9, carrie, female, 17]]", dataSet.getRow().toString());
- assertFalse(dataSet.next());
- assertNull(dataSet.getRow());
- }
-
- public void testMissingValues() throws Exception {
- File file = new File("src/test/resources/xls_missing_values.xls");
- DataContext dc = new ExcelDataContext(file);
- Schema schema = dc.getDefaultSchema();
- assertEquals(1, schema.getTableCount());
-
- Table table = schema.getTables()[0];
- assertEquals("[Column[name=a,columnNumber=0,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
- + "Column[name=b,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
- + "Column[name=c,columnNumber=2,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
- + "Column[name=d,columnNumber=3,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]",
- Arrays.toString(table.getColumns()));
-
- Query q = new Query().select(table.getColumns()).from(table);
- DataSet ds = dc.executeQuery(q);
- assertTrue(ds.next());
- assertEquals("[1, 2, 3, null]", Arrays.toString(ds.getRow().getValues()));
- assertTrue(ds.next());
- assertEquals("[5, null, 7, 8]", Arrays.toString(ds.getRow().getValues()));
- assertTrue(ds.next());
- assertEquals("[9, 10, 11, 12]", Arrays.toString(ds.getRow().getValues()));
- assertFalse(ds.next());
- }
-
- public void testMissingColumnHeader() throws Exception {
- File file = new File("src/test/resources/xls_missing_column_header.xls");
- DataContext dc = new ExcelDataContext(file);
- Schema schema = dc.getDefaultSchema();
- assertEquals(1, schema.getTableCount());
-
- Table table = schema.getTables()[0];
- assertEquals("[Column[name=a,columnNumber=0,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
- + "Column[name=b,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
- + "Column[name=[Column 3],columnNumber=2,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
- + "Column[name=d,columnNumber=3,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]",
- Arrays.toString(table.getColumns()));
-
- Query q = new Query().select(table.getColumns()).from(table);
- DataSet ds = dc.executeQuery(q);
- assertTrue(ds.next());
- assertEquals("[1, 2, 3, 4]", Arrays.toString(ds.getRow().getValues()));
- assertTrue(ds.next());
- assertEquals("[5, 6, 7, 8]", Arrays.toString(ds.getRow().getValues()));
- assertTrue(ds.next());
- assertEquals("[9, 10, 11, 12]", Arrays.toString(ds.getRow().getValues()));
- assertFalse(ds.next());
- }
-
- public void testXlsxFormulas() throws Exception {
- File file = new File("src/test/resources/formulas.xlsx");
- ExcelDataContext dc = new ExcelDataContext(file);
-
- assertEquals("[sh1]", Arrays.toString(dc.getDefaultSchema().getTableNames()));
- assertEquals(XlsxSpreadsheetReaderDelegate.class, dc.getSpreadsheetReaderDelegateClass());
-
- Table table = dc.getDefaultSchema().getTableByName("sh1");
- assertEquals("[Foo, Bar]", Arrays.toString(table.getColumnNames()));
-
- Query q = dc.query().from(table).select("Foo").toQuery();
- DataSet ds = dc.executeQuery(q);
-
- assertTrue(ds.next());
- assertEquals("1", ds.getRow().getValue(0).toString());
- assertEquals("", ds.getRow().getStyle(0).toString());
- assertTrue(ds.next());
- assertEquals("2", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("3", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("4", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("5", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("6", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("7", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("8", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("9", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("10", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("11", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("12", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("13", ds.getRow().getValue(0).toString());
- assertFalse(ds.next());
-
- q = dc.query().from(table).select("Bar").toQuery();
- ds = dc.executeQuery(q);
-
- assertTrue(ds.next());
- assertEquals("lorem", ds.getRow().getValue(0).toString());
- assertEquals("", ds.getRow().getStyle(0).toString());
- assertTrue(ds.next());
- assertEquals("ipsum", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("21", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("foo", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("bar", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("baz", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals(null, ds.getRow().getValue(0));
- assertNotNull(null, ds.getRow().getStyle(0));
- assertTrue(ds.next());
- assertEquals("!\"#¤%&/()<>=?", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("here are", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("some invalid", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("formulas:", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("#DIV/0!", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("0", ds.getRow().getValue(0).toString());
- assertFalse(ds.next());
- }
-
- public void testTicket99defect() throws Exception {
- File file = new File("src/test/resources/ticket_199_inventory.xls");
- DataContext dc = new ExcelDataContext(file);
- Schema schema = dc.getDefaultSchema();
- assertEquals(
- "[Table[name=Sheet1,type=null,remarks=null], Table[name=Sheet2,type=null,remarks=null], Table[name=Sheet3,type=null,remarks=null]]",
- Arrays.toString(schema.getTables()));
-
- assertEquals(0, schema.getTableByName("Sheet2").getColumnCount());
- assertEquals(0, schema.getTableByName("Sheet3").getColumnCount());
-
- Table table = schema.getTableByName("Sheet1");
- assertEquals(
-
- "[Column[name=Pkg No.,columnNumber=0,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
- + "Column[name=Description,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
- + "Column[name=Room,columnNumber=2,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
- + "Column[name=Level,columnNumber=3,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]",
- Arrays.toString(table.getColumns()));
- }
-
- public void testInsertInto() throws Exception {
- File file = new File("target/xls_people_modified.xls");
-
- if (file.exists()) {
- assertTrue(file.delete());
- }
-
- FileHelper.copy(new File("src/test/resources/xls_people.xls"), file);
-
- assertTrue(file.exists());
-
- ExcelDataContext dc = new ExcelDataContext(file);
- final Table table = dc.getDefaultSchema().getTables()[0];
- final Column nameColumn = table.getColumnByName("name");
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- Style clownStyle = new StyleBuilder().bold().foreground(255, 0, 0).background(0, 0, 255).create();
-
- Style thirtyStyle = new StyleBuilder().italic().underline().centerAligned().foreground(10, 10, 200).create();
-
- cb.insertInto(table).value("id", 1000).value(nameColumn, "pennywise the [clown]", clownStyle)
- .value("gender", "male").value("age", 30, thirtyStyle).execute();
- }
- });
-
- DataSet ds = dc.query().from(table).select(nameColumn).orderBy(nameColumn).execute();
- assertTrue(ds.next());
- assertEquals("barbara", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("bob", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("carrie", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("charlotte", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("hillary", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("michael", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("mike", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("pennywise the [clown]", ds.getRow().getValue(0).toString());
- assertEquals("font-weight: bold;color: rgb(255,0,0);background-color: rgb(0,0,255);", ds.getRow().getStyle(0).toString());
- assertTrue(ds.next());
- assertEquals("peter", ds.getRow().getValue(0).toString());
- assertTrue(ds.next());
- assertEquals("vera", ds.getRow().getValue(0).toString());
- assertFalse(ds.next());
- ds.close();
-
- ds = dc.query().from(table).select("age").where("age").eq(30).execute();
- assertTrue(ds.next());
- assertEquals("30", ds.getRow().getValue(0));
- assertEquals("font-style: italic;text-decoration: underline;text-align: center;color: rgb(0,0,255);", ds.getRow()
- .getStyle(0).toCSS());
- assertFalse(ds.next());
- }
-
- public void testCreateTable() throws Exception {
- // run the same test with both XLS and XLSX (because of different
- // workbook implementations)
- runCreateTableTest(new File("target/xls_people_created.xls"));
- runCreateTableTest(new File("target/xls_people_created.xlsx"));
- }
-
- private void runCreateTableTest(File file) {
- if (file.exists()) {
- assertTrue(file.delete());
- }
- final ExcelDataContext dc = new ExcelDataContext(file);
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- Schema schema = dc.getDefaultSchema();
- Table table1 = cb.createTable(schema, "my_table_1").withColumn("foo").withColumn("bar").withColumn("baz")
- .execute();
-
- assertEquals(1, schema.getTableCount());
- assertSame(table1.getSchema(), schema);
- assertSame(table1, schema.getTables()[0]);
-
- Table table2 = cb.createTable(schema, "my_table_2").withColumn("foo").withColumn("bar").withColumn("baz")
- .execute();
-
- assertSame(table2.getSchema(), schema);
- assertSame(table2, schema.getTables()[1]);
- assertEquals(2, schema.getTableCount());
-
- cb.insertInto(table1).value("foo", 123.0).value("bar", "str 1").value("baz", true).execute();
- }
- });
-
- dc.refreshSchemas();
-
- Schema schema = dc.getDefaultSchema();
- assertEquals(2, schema.getTableCount());
- assertEquals("[my_table_1, my_table_2]", Arrays.toString(schema.getTableNames()));
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- cb.insertInto(dc.getTableByQualifiedLabel("my_table_1")).value("foo", 456.2)
- .value("bar", "парфюмерия +и косметика").value("baz", false).execute();
- }
- });
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- cb.insertInto("my_table_1").value("foo", 789).value("bar", DateUtils.get(2011, Month.JULY, 8))
- .value("baz", false).execute();
- }
- });
-
- DataSet ds = dc.query().from("my_table_1").select("foo").and("bar").and("baz").execute();
- assertTrue(ds.next());
- assertEquals("Row[values=[123, str 1, true]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[456.2, парфюмерия +и косметика, false]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[789, 2011-07-08 00:00:00, false]]", ds.getRow().toString());
- assertFalse(ds.next());
- ds.close();
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.deleteFrom("my_table_1").where("foo").greaterThan("124").execute();
- }
- });
-
- assertEquals("1", MetaModelHelper.executeSingleRowQuery(dc, dc.query().from("my_table_1").selectCount().toQuery())
- .getValue(0).toString());
-
- ds = dc.query().from("my_table_1").select("foo").and("bar").and("baz").execute();
- assertTrue(ds.next());
- assertEquals("Row[values=[123, str 1, true]]", ds.getRow().toString());
- assertFalse(ds.next());
- ds.close();
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.dropTable("my_table_1").execute();
- }
- });
-
- assertEquals("[my_table_2]", Arrays.toString(schema.getTableNames()));
-
- dc.refreshSchemas();
-
- assertEquals("[my_table_2]", Arrays.toString(schema.getTableNames()));
-
- assertEquals(1, dc.getDefaultSchema().getTableCount());
- }
-
- public void testGetStyles() throws Exception {
- DataContext dc = new ExcelDataContext(new File("src/test/resources/styles.xlsx"));
- Table table = dc.getDefaultSchema().getTables()[0];
- assertEquals("[style name, example]", Arrays.toString(table.getColumnNames()));
-
- DataSet ds = dc.query().from(table).select(table.getColumns()).execute();
- assertTrue(ds.next());
- assertEquals("Row[values=[bold, foo]]", ds.getRow().toString());
- assertEquals("", ds.getRow().getStyle(0).toCSS());
- assertEquals("font-weight: bold;", ds.getRow().getStyle(1).toCSS());
-
- assertTrue(ds.next());
- assertEquals("Row[values=[italic, foo]]", ds.getRow().toString());
- assertEquals("", ds.getRow().getStyle(0).toCSS());
- assertEquals("font-style: italic;", ds.getRow().getStyle(1).toCSS());
-
- assertTrue(ds.next());
- assertEquals("Row[values=[underline, foo]]", ds.getRow().toString());
- assertEquals("", ds.getRow().getStyle(0).toCSS());
- assertEquals("text-decoration: underline;", ds.getRow().getStyle(1).toCSS());
-
- assertTrue(ds.next());
- assertEquals("Row[values=[custom text col, foo]]", ds.getRow().toString());
- assertEquals("", ds.getRow().getStyle(0).toCSS());
- assertEquals("color: rgb(138,67,143);", ds.getRow().getStyle(1).toCSS());
-
- assertTrue(ds.next());
- assertEquals("Row[values=[yellow text col, foo]]", ds.getRow().toString());
- assertEquals("", ds.getRow().getStyle(0).toCSS());
- assertEquals("color: rgb(255,255,0);", ds.getRow().getStyle(1).toCSS());
-
- assertTrue(ds.next());
- assertEquals("Row[values=[custom bg, foo]]", ds.getRow().toString());
- assertEquals("", ds.getRow().getStyle(0).toCSS());
- assertEquals("background-color: rgb(136,228,171);", ds.getRow().getStyle(1).toCSS());
-
- assertTrue(ds.next());
- assertEquals("Row[values=[yellow bg, foo]]", ds.getRow().toString());
- assertEquals("", ds.getRow().getStyle(0).toCSS());
- assertEquals("background-color: rgb(255,255,0);", ds.getRow().getStyle(1).toCSS());
-
- assertTrue(ds.next());
- assertEquals("Row[values=[center align, foo]]", ds.getRow().toString());
- assertEquals("", ds.getRow().getStyle(0).toCSS());
- assertEquals("text-align: center;", ds.getRow().getStyle(1).toCSS());
-
- assertTrue(ds.next());
- assertEquals("Row[values=[font size 8, foo]]", ds.getRow().toString());
- assertEquals("", ds.getRow().getStyle(0).toCSS());
- assertEquals("font-size: 8pt;", ds.getRow().getStyle(1).toCSS());
-
- assertTrue(ds.next());
- assertEquals("Row[values=[font size 16, foo]]", ds.getRow().toString());
- assertEquals("", ds.getRow().getStyle(0).toCSS());
- assertEquals("font-size: 16pt;", ds.getRow().getStyle(1).toCSS());
-
- assertFalse(ds.next());
- }
-}
\ No newline at end of file
[09/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/full/src/main/java/org/apache/metamodel/DataContextFactory.java
----------------------------------------------------------------------
diff --git a/full/src/main/java/org/apache/metamodel/DataContextFactory.java b/full/src/main/java/org/apache/metamodel/DataContextFactory.java
new file mode 100644
index 0000000..5b5598b
--- /dev/null
+++ b/full/src/main/java/org/apache/metamodel/DataContextFactory.java
@@ -0,0 +1,591 @@
+/**
+ * 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;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+import java.sql.Connection;
+import java.util.Collection;
+
+import javax.sql.DataSource;
+
+import org.ektorp.http.StdHttpClient.Builder;
+import org.eobjects.metamodel.access.AccessDataContext;
+import org.eobjects.metamodel.couchdb.CouchDbDataContext;
+import org.eobjects.metamodel.csv.CsvConfiguration;
+import org.eobjects.metamodel.csv.CsvDataContext;
+import org.eobjects.metamodel.excel.ExcelConfiguration;
+import org.eobjects.metamodel.excel.ExcelDataContext;
+import org.eobjects.metamodel.fixedwidth.FixedWidthConfiguration;
+import org.eobjects.metamodel.fixedwidth.FixedWidthDataContext;
+import org.eobjects.metamodel.jdbc.JdbcDataContext;
+import org.eobjects.metamodel.mongodb.MongoDbDataContext;
+import org.eobjects.metamodel.openoffice.OpenOfficeDataContext;
+import org.eobjects.metamodel.salesforce.SalesforceDataContext;
+import org.eobjects.metamodel.schema.TableType;
+import org.eobjects.metamodel.sugarcrm.SugarCrmDataContext;
+import org.eobjects.metamodel.util.FileHelper;
+import org.eobjects.metamodel.xml.XmlDomDataContext;
+import org.xml.sax.InputSource;
+
+import com.mongodb.DB;
+import com.mongodb.Mongo;
+
+/**
+ * A factory for DataContext objects. This class substantially easens the task
+ * of creating and initializing DataContext objects and/or their strategies for
+ * reading datastores.
+ *
+ * @see DataContext
+ */
+public class DataContextFactory {
+
+ public static final char DEFAULT_CSV_SEPARATOR_CHAR = CsvConfiguration.DEFAULT_SEPARATOR_CHAR;
+ public static final char DEFAULT_CSV_QUOTE_CHAR = CsvConfiguration.DEFAULT_QUOTE_CHAR;
+
+ private DataContextFactory() {
+ // Prevent instantiation
+ }
+
+ /**
+ * Creates a composite DataContext based on a set of delegate DataContexts.
+ *
+ * Composite DataContexts enables cross-DataContext querying and unified
+ * schema exploration
+ *
+ * @param delegates
+ * an array/var-args of delegate DataContexts
+ * @return a DataContext that matches the request
+ */
+ public static DataContext createCompositeDataContext(DataContext... delegates) {
+ return new CompositeDataContext(delegates);
+ }
+
+ /**
+ * Creates a composite DataContext based on a set of delegate DataContexts.
+ *
+ * Composite DataContexts enables cross-DataContext querying and unified
+ * schema exploration
+ *
+ * @param delegates
+ * a collection of delegate DataContexts
+ * @return a DataContext that matches the request
+ */
+ public static DataContext createCompositeDataContext(Collection<DataContext> delegates) {
+ return new CompositeDataContext(delegates);
+ }
+
+ /**
+ * Creates a DataContext based on a MS Access (.mdb) file
+ *
+ * @param filename
+ * the path to a MS Access (.mdb) file
+ * @return a DataContext object that matches the request
+ */
+ public static DataContext createAccessDataContext(String filename) {
+ return new AccessDataContext(filename);
+ }
+
+ /**
+ * Creates a DataContext based on a MS Access (.mdb) file
+ *
+ * @param file
+ * a MS Access (.mdb) file
+ * @return a DataContext object that matches the request
+ */
+ public static DataContext createAccessDataContext(File file) {
+ return new AccessDataContext(file);
+ }
+
+ /**
+ * Creates a DataContext that connects to a Salesforce.com instance.
+ *
+ * @param username
+ * the Salesforce username
+ * @param password
+ * the Salesforce password
+ * @param securityToken
+ * the Salesforce security token
+ * @return a DataContext object that matches the request
+ */
+ public static DataContext createSalesforceDataContext(String username, String password, String securityToken) {
+ return new SalesforceDataContext(username, password, securityToken);
+ }
+
+ /**
+ * Create a DataContext that connects to a SugarCRM system.
+ *
+ * @param baseUrl
+ * the base URL of the system, e.g. http://localhost/sugarcrm
+ * @param username
+ * the SugarCRM username
+ * @param password
+ * the SugarCRM password
+ * @param applicationName
+ * the name of the application you are connecting with
+ * @return a DataContext object that matches the request
+ */
+ public static DataContext createSugarCrmDataContext(String baseUrl, String username, String password, String applicationName) {
+ return new SugarCrmDataContext(baseUrl, username, password, applicationName);
+ }
+
+ /**
+ * Creates a DataContext based on a CSV file
+ *
+ * @param file
+ * a CSV file
+ * @return a DataContext object that matches the request
+ */
+ public static UpdateableDataContext createCsvDataContext(File file) {
+ return createCsvDataContext(file, DEFAULT_CSV_SEPARATOR_CHAR, DEFAULT_CSV_QUOTE_CHAR);
+ }
+
+ /**
+ * Creates a DataContext based on a CSV file
+ *
+ * @param file
+ * a CSV file
+ * @param separatorChar
+ * the char to use for separating values
+ * @param quoteChar
+ * the char used for quoting values (typically if they include
+ * the separator char)
+ * @return a DataContext object that matches the request
+ */
+ public static UpdateableDataContext createCsvDataContext(File file, char separatorChar, char quoteChar) {
+ return createCsvDataContext(file, separatorChar, quoteChar, FileHelper.DEFAULT_ENCODING);
+ }
+
+ /**
+ * Creates a DataContext based on a CSV file
+ *
+ * @param file
+ * a CSV file
+ * @param separatorChar
+ * the char to use for separating values
+ * @param quoteChar
+ * the char used for quoting values (typically if they include
+ * the separator char)
+ * @param encoding
+ * the character encoding of the file
+ * @return a DataContext object that matches the request
+ */
+ public static UpdateableDataContext createCsvDataContext(File file, char separatorChar, char quoteChar, String encoding) {
+ CsvConfiguration configuration = new CsvConfiguration(CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, encoding, separatorChar,
+ quoteChar, CsvConfiguration.DEFAULT_ESCAPE_CHAR);
+ CsvDataContext dc = new CsvDataContext(file, configuration);
+ return dc;
+ }
+
+ /**
+ * Creates a DataContext based on a CSV file
+ *
+ * @param file
+ * a CSV file
+ * @param configuration
+ * the CSV configuration to use
+ * @return a DataContext object that matches the request
+ */
+ public static UpdateableDataContext createCsvDataContext(File file, CsvConfiguration configuration) {
+ CsvDataContext dc = new CsvDataContext(file, configuration);
+ return dc;
+ }
+
+ /**
+ * Creates a DataContext based on CSV-content through an input stream
+ *
+ * @param inputStream
+ * the input stream to read from
+ * @param separatorChar
+ * the char to use for separating values
+ * @param quoteChar
+ * the char used for quoting values (typically if they include
+ * the separator char)
+ * @return a DataContext object that matches the request
+ */
+ public static DataContext createCsvDataContext(InputStream inputStream, char separatorChar, char quoteChar) {
+ return createCsvDataContext(inputStream, separatorChar, quoteChar, FileHelper.DEFAULT_ENCODING);
+ }
+
+ /**
+ * Creates a DataContext based on CSV-content through an input stream
+ *
+ * @param inputStream
+ * the input stream to read from
+ * @param separatorChar
+ * the char to use for separating values
+ * @param quoteChar
+ * the char used for quoting values (typically if they include
+ * the separator char)
+ * @return a DataContext object that matches the request
+ */
+ public static DataContext createCsvDataContext(InputStream inputStream, char separatorChar, char quoteChar, String encoding) {
+ CsvConfiguration configuration = new CsvConfiguration(CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, encoding, separatorChar,
+ quoteChar, CsvConfiguration.DEFAULT_ESCAPE_CHAR);
+ CsvDataContext dc = new CsvDataContext(inputStream, configuration);
+ return dc;
+ }
+
+ /**
+ * Creates a DataContext based on CSV-content through an input stream
+ *
+ * @param inputStream
+ * the input stream to read from
+ * @param configuration
+ * the CSV configuration to use
+ * @return a DataContext object that matches the request
+ */
+ public static DataContext createCsvDataContext(InputStream inputStream, CsvConfiguration configuration) {
+ CsvDataContext dc = new CsvDataContext(inputStream, configuration);
+ return dc;
+ }
+
+ /**
+ * Creates a DataContext based on a fixed width file.
+ *
+ * @param file
+ * the file to read from.
+ * @param fileEncoding
+ * the character encoding of the file.
+ * @param fixedValueWidth
+ * the (fixed) width of values in the file.
+ * @return a DataContext object that matches the request
+ */
+ public static DataContext createFixedWidthDataContext(File file, String fileEncoding, int fixedValueWidth) {
+ return createFixedWidthDataContext(file, new FixedWidthConfiguration(FixedWidthConfiguration.DEFAULT_COLUMN_NAME_LINE,
+ fileEncoding, fixedValueWidth));
+ }
+
+ /**
+ * Creates a DataContext based on a fixed width file.
+ *
+ * @param file
+ * the file to read from.
+ * @param configuration
+ * the fixed width configuration to use
+ * @return a DataContext object that matches the request
+ */
+ public static DataContext createFixedWidthDataContext(File file, FixedWidthConfiguration configuration) {
+ FixedWidthDataContext dc = new FixedWidthDataContext(file, configuration);
+ return dc;
+ }
+
+ /**
+ * Creates a DataContext based on a fixed width file.
+ *
+ * @param file
+ * the file to read from.
+ * @param fileEncoding
+ * the character encoding of the file.
+ * @param fixedValueWidth
+ * the (fixed) width of values in the file.
+ * @param headerLineNumber
+ * the line number of the column headers.
+ * @return a DataContext object that matches the request
+ */
+ public static DataContext createFixedWidthDataContext(File file, String fileEncoding, int fixedValueWidth,
+ int headerLineNumber) {
+ return createFixedWidthDataContext(file, new FixedWidthConfiguration(FixedWidthConfiguration.DEFAULT_COLUMN_NAME_LINE,
+ fileEncoding, fixedValueWidth));
+ }
+
+ /**
+ * Creates a DataContet based on an Excel spreadsheet file
+ *
+ * @param file
+ * an excel spreadsheet file
+ * @param configuration
+ * the configuration with metadata for reading the spreadsheet
+ * @return a DataContext object that matches the request
+ */
+ public static UpdateableDataContext createExcelDataContext(File file, ExcelConfiguration configuration) {
+ return new ExcelDataContext(file, configuration);
+ }
+
+ /**
+ * Creates a DataContext based on an Excel spreadsheet file
+ *
+ * @param file
+ * an Excel spreadsheet file
+ * @return a DataContext object that matches the request
+ */
+ public static UpdateableDataContext createExcelDataContext(File file) {
+ return createExcelDataContext(file, new ExcelConfiguration());
+ }
+
+ /**
+ * Creates a DataContext based on XML-content from an input source.
+ *
+ * Tables are created by examining the data in the XML file, NOT by reading
+ * XML Schemas (xsd/dtd's). This enables compliancy with ALL xml formats but
+ * also raises a risk that two XML files with the same format wont
+ * nescesarily yield the same table model if some optional attributes or
+ * tags are omitted in one of the files.
+ *
+ * @param inputSource
+ * an input source feeding XML content
+ * @param schemaName
+ * the name to be used for the main schema
+ * @param autoFlattenTables
+ * a boolean indicating if MetaModel should flatten very simple
+ * table structures (where tables only contain a single
+ * data-carrying column) for greater usability of the generated
+ * table-based model
+ * @return a DataContext object that matches the request
+ */
+ public static DataContext createXmlDataContext(InputSource inputSource, String schemaName, boolean autoFlattenTables) {
+ XmlDomDataContext dc = new XmlDomDataContext(inputSource, schemaName, autoFlattenTables);
+ return dc;
+ }
+
+ /**
+ * Creates a DataContext based on XML-content from a File.
+ *
+ * Tables are created by examining the data in the XML file, NOT by reading
+ * XML Schemas (xsd/dtd's). This enables compliancy with ALL xml formats but
+ * also raises a risk that two XML files with the same format wont
+ * nescesarily yield the same table model if some optional attributes or
+ * tags are omitted in one of the files.
+ *
+ * @param file
+ * the File to use for feeding XML content
+ * @param autoFlattenTables
+ * a boolean indicating if MetaModel should flatten very simple
+ * table structures (where tables only contain a single
+ * data-carrying column) for greater usability of the generated
+ * table-based model
+ * @return a DataContext object that matches the request
+ */
+ public static DataContext createXmlDataContext(File file, boolean autoFlattenTables) {
+ XmlDomDataContext dc = new XmlDomDataContext(file, autoFlattenTables);
+ return dc;
+ }
+
+ /**
+ * Creates a DataContext based on XML-content from a URL.
+ *
+ * Tables are created by examining the data in the XML file, NOT by reading
+ * XML Schemas (xsd/dtd's). This enables compliancy with ALL xml formats but
+ * also raises a risk that two XML files with the same format wont
+ * nescesarily yield the same table model if some optional attributes or
+ * tags are omitted in one of the files.
+ *
+ * @param url
+ * the URL to use for feeding XML content
+ * @param autoFlattenTables
+ * a boolean indicating if MetaModel should flatten very simple
+ * table structures (where tables only contain a single
+ * data-carrying column) for greater usability of the generated
+ * table-based model
+ * @return a DataContext object that matches the request
+ */
+ public static DataContext createXmlDataContext(URL url, boolean autoFlattenTables) {
+ XmlDomDataContext dc = new XmlDomDataContext(url, autoFlattenTables);
+ return dc;
+ }
+
+ /**
+ * Creates a DataContext based on an OpenOffice.org database file.
+ *
+ * @param file
+ * an OpenOffice.org database file
+ * @return a DataContext object that matches the request
+ */
+ public static DataContext createOpenOfficeDataContext(File file) {
+ return new OpenOfficeDataContext(file);
+ }
+
+ /**
+ * Creates a DataContext based on a JDBC connection
+ *
+ * @param connection
+ * a JDBC connection
+ * @return a DataContext object that matches the request
+ */
+ public static UpdateableDataContext createJdbcDataContext(Connection connection) {
+ return new JdbcDataContext(connection);
+ }
+
+ /**
+ * Creates a DataContext based on a JDBC datasource
+ *
+ * @param ds
+ * a JDBC datasource
+ * @return a DataContext object that matches the request
+ */
+ public static UpdateableDataContext createJdbcDataContext(DataSource ds) {
+ return new JdbcDataContext(ds);
+ }
+
+ /**
+ * Creates a DataContext based on a JDBC connection
+ *
+ * @param connection
+ * a JDBC connection
+ * @param catalogName
+ * a catalog name to use
+ * @return a DataContext object that matches the request
+ */
+ public static UpdateableDataContext createJdbcDataContext(Connection connection, String catalogName) {
+ return new JdbcDataContext(connection, TableType.DEFAULT_TABLE_TYPES, catalogName);
+ }
+
+ /**
+ * Creates a DataContext based on a JDBC connection
+ *
+ * @param connection
+ * a JDBC connection
+ * @param tableTypes
+ * the types of tables to include in the generated schemas
+ * @return a DataContext object that matches the request
+ */
+ public static UpdateableDataContext createJdbcDataContext(Connection connection, TableType... tableTypes) {
+ return new JdbcDataContext(connection, tableTypes, null);
+ }
+
+ /**
+ * Creates a DataContext based on a JDBC connection
+ *
+ * @param connection
+ * a JDBC connection
+ * @param catalogName
+ * a catalog name to use
+ * @param tableTypes
+ * the types of tables to include in the generated schemas
+ * @return a DataContext object that matches the request
+ */
+ public static UpdateableDataContext createJdbcDataContext(Connection connection, String catalogName, TableType[] tableTypes) {
+ return new JdbcDataContext(connection, tableTypes, catalogName);
+ }
+
+ /**
+ * Creates a DataContext based on a JDBC datasource
+ *
+ * @param ds
+ * a JDBC datasource
+ * @param tableTypes
+ * the types of tables to include in the generated schemas
+ * @return a DataContext object that matches the request
+ */
+ public static UpdateableDataContext createJdbcDataContext(DataSource ds, TableType... tableTypes) {
+ return new JdbcDataContext(ds, tableTypes, null);
+ }
+
+ /**
+ * Creates a DataContext based on a JDBC datasource
+ *
+ * @param ds
+ * a JDBC datasource
+ * @param catalogName
+ * a catalog name to use
+ * @param tableTypes
+ * the types of tables to include in the generated schemas
+ * @return a DataContext object that matches the request
+ */
+ public static UpdateableDataContext createJdbcDataContext(DataSource ds, String catalogName, TableType[] tableTypes) {
+ return new JdbcDataContext(ds, tableTypes, catalogName);
+ }
+
+ /**
+ * Creates a DataContext based on a JDBC datasource
+ *
+ * @param ds
+ * a JDBC datasource
+ * @param catalogName
+ * a catalog name to use
+ * @return a DataContext object that matches the request
+ */
+ public static UpdateableDataContext createJdbcDataContext(DataSource ds, String catalogName) {
+ return new JdbcDataContext(ds, TableType.DEFAULT_TABLE_TYPES, catalogName);
+ }
+
+ /**
+ * Creates a new MongoDB datacontext.
+ *
+ * @param hostname
+ * The hostname of the MongoDB instance
+ * @param port
+ * the port of the MongoDB instance, or null if the default port
+ * should be used.
+ * @param databaseName
+ * the name of the database
+ * @param username
+ * the username, or null if unauthenticated access should be used
+ * @param password
+ * the password, or null if unathenticated access should be used
+ * @return a DataContext object that matches the request
+ */
+ public static UpdateableDataContext createMongoDbDataContext(String hostname, Integer port, String databaseName,
+ String username, char[] password) {
+ try {
+ DB mongoDb;
+ if (port == null) {
+ mongoDb = new Mongo(hostname).getDB(databaseName);
+ } else {
+ mongoDb = new Mongo(hostname, port).getDB(databaseName);
+ }
+ if (username != null) {
+ mongoDb.authenticate(username, password);
+ }
+ return new MongoDbDataContext(mongoDb);
+ } catch (Exception e) {
+ if (e instanceof RuntimeException) {
+ throw (RuntimeException) e;
+ }
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Creates a new CouchDB datacontext.
+ *
+ * @param hostname
+ * The hostname of the CouchDB instance
+ * @param port
+ * the port of the CouchDB instance, or null if the default port
+ * should be used.
+ * @param username
+ * the username, or null if unauthenticated access should be used
+ * @param password
+ * the password, or null if unathenticated access should be used
+ * @return a DataContext object that matches the request
+ */
+ public static UpdateableDataContext createCouchDbDataContext(String hostname, Integer port, String username, String password) {
+
+ Builder httpClientBuilder = new Builder();
+ httpClientBuilder.host(hostname);
+ if (port != null) {
+ httpClientBuilder.port(port);
+ }
+ if (username != null) {
+ httpClientBuilder.username(username);
+ }
+ if (password != null) {
+ httpClientBuilder.password(password);
+ }
+
+ // increased timeouts (20 sec) - metamodel typically does quite some
+ // batching so it might take a bit of time to provide a connection.
+ httpClientBuilder.connectionTimeout(20000);
+ httpClientBuilder.socketTimeout(20000);
+
+ return new CouchDbDataContext(httpClientBuilder);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/full/src/main/java/org/eobjects/metamodel/DataContextFactory.java
----------------------------------------------------------------------
diff --git a/full/src/main/java/org/eobjects/metamodel/DataContextFactory.java b/full/src/main/java/org/eobjects/metamodel/DataContextFactory.java
deleted file mode 100644
index 5b5598b..0000000
--- a/full/src/main/java/org/eobjects/metamodel/DataContextFactory.java
+++ /dev/null
@@ -1,591 +0,0 @@
-/**
- * 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;
-
-import java.io.File;
-import java.io.InputStream;
-import java.net.URL;
-import java.sql.Connection;
-import java.util.Collection;
-
-import javax.sql.DataSource;
-
-import org.ektorp.http.StdHttpClient.Builder;
-import org.eobjects.metamodel.access.AccessDataContext;
-import org.eobjects.metamodel.couchdb.CouchDbDataContext;
-import org.eobjects.metamodel.csv.CsvConfiguration;
-import org.eobjects.metamodel.csv.CsvDataContext;
-import org.eobjects.metamodel.excel.ExcelConfiguration;
-import org.eobjects.metamodel.excel.ExcelDataContext;
-import org.eobjects.metamodel.fixedwidth.FixedWidthConfiguration;
-import org.eobjects.metamodel.fixedwidth.FixedWidthDataContext;
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.mongodb.MongoDbDataContext;
-import org.eobjects.metamodel.openoffice.OpenOfficeDataContext;
-import org.eobjects.metamodel.salesforce.SalesforceDataContext;
-import org.eobjects.metamodel.schema.TableType;
-import org.eobjects.metamodel.sugarcrm.SugarCrmDataContext;
-import org.eobjects.metamodel.util.FileHelper;
-import org.eobjects.metamodel.xml.XmlDomDataContext;
-import org.xml.sax.InputSource;
-
-import com.mongodb.DB;
-import com.mongodb.Mongo;
-
-/**
- * A factory for DataContext objects. This class substantially easens the task
- * of creating and initializing DataContext objects and/or their strategies for
- * reading datastores.
- *
- * @see DataContext
- */
-public class DataContextFactory {
-
- public static final char DEFAULT_CSV_SEPARATOR_CHAR = CsvConfiguration.DEFAULT_SEPARATOR_CHAR;
- public static final char DEFAULT_CSV_QUOTE_CHAR = CsvConfiguration.DEFAULT_QUOTE_CHAR;
-
- private DataContextFactory() {
- // Prevent instantiation
- }
-
- /**
- * Creates a composite DataContext based on a set of delegate DataContexts.
- *
- * Composite DataContexts enables cross-DataContext querying and unified
- * schema exploration
- *
- * @param delegates
- * an array/var-args of delegate DataContexts
- * @return a DataContext that matches the request
- */
- public static DataContext createCompositeDataContext(DataContext... delegates) {
- return new CompositeDataContext(delegates);
- }
-
- /**
- * Creates a composite DataContext based on a set of delegate DataContexts.
- *
- * Composite DataContexts enables cross-DataContext querying and unified
- * schema exploration
- *
- * @param delegates
- * a collection of delegate DataContexts
- * @return a DataContext that matches the request
- */
- public static DataContext createCompositeDataContext(Collection<DataContext> delegates) {
- return new CompositeDataContext(delegates);
- }
-
- /**
- * Creates a DataContext based on a MS Access (.mdb) file
- *
- * @param filename
- * the path to a MS Access (.mdb) file
- * @return a DataContext object that matches the request
- */
- public static DataContext createAccessDataContext(String filename) {
- return new AccessDataContext(filename);
- }
-
- /**
- * Creates a DataContext based on a MS Access (.mdb) file
- *
- * @param file
- * a MS Access (.mdb) file
- * @return a DataContext object that matches the request
- */
- public static DataContext createAccessDataContext(File file) {
- return new AccessDataContext(file);
- }
-
- /**
- * Creates a DataContext that connects to a Salesforce.com instance.
- *
- * @param username
- * the Salesforce username
- * @param password
- * the Salesforce password
- * @param securityToken
- * the Salesforce security token
- * @return a DataContext object that matches the request
- */
- public static DataContext createSalesforceDataContext(String username, String password, String securityToken) {
- return new SalesforceDataContext(username, password, securityToken);
- }
-
- /**
- * Create a DataContext that connects to a SugarCRM system.
- *
- * @param baseUrl
- * the base URL of the system, e.g. http://localhost/sugarcrm
- * @param username
- * the SugarCRM username
- * @param password
- * the SugarCRM password
- * @param applicationName
- * the name of the application you are connecting with
- * @return a DataContext object that matches the request
- */
- public static DataContext createSugarCrmDataContext(String baseUrl, String username, String password, String applicationName) {
- return new SugarCrmDataContext(baseUrl, username, password, applicationName);
- }
-
- /**
- * Creates a DataContext based on a CSV file
- *
- * @param file
- * a CSV file
- * @return a DataContext object that matches the request
- */
- public static UpdateableDataContext createCsvDataContext(File file) {
- return createCsvDataContext(file, DEFAULT_CSV_SEPARATOR_CHAR, DEFAULT_CSV_QUOTE_CHAR);
- }
-
- /**
- * Creates a DataContext based on a CSV file
- *
- * @param file
- * a CSV file
- * @param separatorChar
- * the char to use for separating values
- * @param quoteChar
- * the char used for quoting values (typically if they include
- * the separator char)
- * @return a DataContext object that matches the request
- */
- public static UpdateableDataContext createCsvDataContext(File file, char separatorChar, char quoteChar) {
- return createCsvDataContext(file, separatorChar, quoteChar, FileHelper.DEFAULT_ENCODING);
- }
-
- /**
- * Creates a DataContext based on a CSV file
- *
- * @param file
- * a CSV file
- * @param separatorChar
- * the char to use for separating values
- * @param quoteChar
- * the char used for quoting values (typically if they include
- * the separator char)
- * @param encoding
- * the character encoding of the file
- * @return a DataContext object that matches the request
- */
- public static UpdateableDataContext createCsvDataContext(File file, char separatorChar, char quoteChar, String encoding) {
- CsvConfiguration configuration = new CsvConfiguration(CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, encoding, separatorChar,
- quoteChar, CsvConfiguration.DEFAULT_ESCAPE_CHAR);
- CsvDataContext dc = new CsvDataContext(file, configuration);
- return dc;
- }
-
- /**
- * Creates a DataContext based on a CSV file
- *
- * @param file
- * a CSV file
- * @param configuration
- * the CSV configuration to use
- * @return a DataContext object that matches the request
- */
- public static UpdateableDataContext createCsvDataContext(File file, CsvConfiguration configuration) {
- CsvDataContext dc = new CsvDataContext(file, configuration);
- return dc;
- }
-
- /**
- * Creates a DataContext based on CSV-content through an input stream
- *
- * @param inputStream
- * the input stream to read from
- * @param separatorChar
- * the char to use for separating values
- * @param quoteChar
- * the char used for quoting values (typically if they include
- * the separator char)
- * @return a DataContext object that matches the request
- */
- public static DataContext createCsvDataContext(InputStream inputStream, char separatorChar, char quoteChar) {
- return createCsvDataContext(inputStream, separatorChar, quoteChar, FileHelper.DEFAULT_ENCODING);
- }
-
- /**
- * Creates a DataContext based on CSV-content through an input stream
- *
- * @param inputStream
- * the input stream to read from
- * @param separatorChar
- * the char to use for separating values
- * @param quoteChar
- * the char used for quoting values (typically if they include
- * the separator char)
- * @return a DataContext object that matches the request
- */
- public static DataContext createCsvDataContext(InputStream inputStream, char separatorChar, char quoteChar, String encoding) {
- CsvConfiguration configuration = new CsvConfiguration(CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, encoding, separatorChar,
- quoteChar, CsvConfiguration.DEFAULT_ESCAPE_CHAR);
- CsvDataContext dc = new CsvDataContext(inputStream, configuration);
- return dc;
- }
-
- /**
- * Creates a DataContext based on CSV-content through an input stream
- *
- * @param inputStream
- * the input stream to read from
- * @param configuration
- * the CSV configuration to use
- * @return a DataContext object that matches the request
- */
- public static DataContext createCsvDataContext(InputStream inputStream, CsvConfiguration configuration) {
- CsvDataContext dc = new CsvDataContext(inputStream, configuration);
- return dc;
- }
-
- /**
- * Creates a DataContext based on a fixed width file.
- *
- * @param file
- * the file to read from.
- * @param fileEncoding
- * the character encoding of the file.
- * @param fixedValueWidth
- * the (fixed) width of values in the file.
- * @return a DataContext object that matches the request
- */
- public static DataContext createFixedWidthDataContext(File file, String fileEncoding, int fixedValueWidth) {
- return createFixedWidthDataContext(file, new FixedWidthConfiguration(FixedWidthConfiguration.DEFAULT_COLUMN_NAME_LINE,
- fileEncoding, fixedValueWidth));
- }
-
- /**
- * Creates a DataContext based on a fixed width file.
- *
- * @param file
- * the file to read from.
- * @param configuration
- * the fixed width configuration to use
- * @return a DataContext object that matches the request
- */
- public static DataContext createFixedWidthDataContext(File file, FixedWidthConfiguration configuration) {
- FixedWidthDataContext dc = new FixedWidthDataContext(file, configuration);
- return dc;
- }
-
- /**
- * Creates a DataContext based on a fixed width file.
- *
- * @param file
- * the file to read from.
- * @param fileEncoding
- * the character encoding of the file.
- * @param fixedValueWidth
- * the (fixed) width of values in the file.
- * @param headerLineNumber
- * the line number of the column headers.
- * @return a DataContext object that matches the request
- */
- public static DataContext createFixedWidthDataContext(File file, String fileEncoding, int fixedValueWidth,
- int headerLineNumber) {
- return createFixedWidthDataContext(file, new FixedWidthConfiguration(FixedWidthConfiguration.DEFAULT_COLUMN_NAME_LINE,
- fileEncoding, fixedValueWidth));
- }
-
- /**
- * Creates a DataContet based on an Excel spreadsheet file
- *
- * @param file
- * an excel spreadsheet file
- * @param configuration
- * the configuration with metadata for reading the spreadsheet
- * @return a DataContext object that matches the request
- */
- public static UpdateableDataContext createExcelDataContext(File file, ExcelConfiguration configuration) {
- return new ExcelDataContext(file, configuration);
- }
-
- /**
- * Creates a DataContext based on an Excel spreadsheet file
- *
- * @param file
- * an Excel spreadsheet file
- * @return a DataContext object that matches the request
- */
- public static UpdateableDataContext createExcelDataContext(File file) {
- return createExcelDataContext(file, new ExcelConfiguration());
- }
-
- /**
- * Creates a DataContext based on XML-content from an input source.
- *
- * Tables are created by examining the data in the XML file, NOT by reading
- * XML Schemas (xsd/dtd's). This enables compliancy with ALL xml formats but
- * also raises a risk that two XML files with the same format wont
- * nescesarily yield the same table model if some optional attributes or
- * tags are omitted in one of the files.
- *
- * @param inputSource
- * an input source feeding XML content
- * @param schemaName
- * the name to be used for the main schema
- * @param autoFlattenTables
- * a boolean indicating if MetaModel should flatten very simple
- * table structures (where tables only contain a single
- * data-carrying column) for greater usability of the generated
- * table-based model
- * @return a DataContext object that matches the request
- */
- public static DataContext createXmlDataContext(InputSource inputSource, String schemaName, boolean autoFlattenTables) {
- XmlDomDataContext dc = new XmlDomDataContext(inputSource, schemaName, autoFlattenTables);
- return dc;
- }
-
- /**
- * Creates a DataContext based on XML-content from a File.
- *
- * Tables are created by examining the data in the XML file, NOT by reading
- * XML Schemas (xsd/dtd's). This enables compliancy with ALL xml formats but
- * also raises a risk that two XML files with the same format wont
- * nescesarily yield the same table model if some optional attributes or
- * tags are omitted in one of the files.
- *
- * @param file
- * the File to use for feeding XML content
- * @param autoFlattenTables
- * a boolean indicating if MetaModel should flatten very simple
- * table structures (where tables only contain a single
- * data-carrying column) for greater usability of the generated
- * table-based model
- * @return a DataContext object that matches the request
- */
- public static DataContext createXmlDataContext(File file, boolean autoFlattenTables) {
- XmlDomDataContext dc = new XmlDomDataContext(file, autoFlattenTables);
- return dc;
- }
-
- /**
- * Creates a DataContext based on XML-content from a URL.
- *
- * Tables are created by examining the data in the XML file, NOT by reading
- * XML Schemas (xsd/dtd's). This enables compliancy with ALL xml formats but
- * also raises a risk that two XML files with the same format wont
- * nescesarily yield the same table model if some optional attributes or
- * tags are omitted in one of the files.
- *
- * @param url
- * the URL to use for feeding XML content
- * @param autoFlattenTables
- * a boolean indicating if MetaModel should flatten very simple
- * table structures (where tables only contain a single
- * data-carrying column) for greater usability of the generated
- * table-based model
- * @return a DataContext object that matches the request
- */
- public static DataContext createXmlDataContext(URL url, boolean autoFlattenTables) {
- XmlDomDataContext dc = new XmlDomDataContext(url, autoFlattenTables);
- return dc;
- }
-
- /**
- * Creates a DataContext based on an OpenOffice.org database file.
- *
- * @param file
- * an OpenOffice.org database file
- * @return a DataContext object that matches the request
- */
- public static DataContext createOpenOfficeDataContext(File file) {
- return new OpenOfficeDataContext(file);
- }
-
- /**
- * Creates a DataContext based on a JDBC connection
- *
- * @param connection
- * a JDBC connection
- * @return a DataContext object that matches the request
- */
- public static UpdateableDataContext createJdbcDataContext(Connection connection) {
- return new JdbcDataContext(connection);
- }
-
- /**
- * Creates a DataContext based on a JDBC datasource
- *
- * @param ds
- * a JDBC datasource
- * @return a DataContext object that matches the request
- */
- public static UpdateableDataContext createJdbcDataContext(DataSource ds) {
- return new JdbcDataContext(ds);
- }
-
- /**
- * Creates a DataContext based on a JDBC connection
- *
- * @param connection
- * a JDBC connection
- * @param catalogName
- * a catalog name to use
- * @return a DataContext object that matches the request
- */
- public static UpdateableDataContext createJdbcDataContext(Connection connection, String catalogName) {
- return new JdbcDataContext(connection, TableType.DEFAULT_TABLE_TYPES, catalogName);
- }
-
- /**
- * Creates a DataContext based on a JDBC connection
- *
- * @param connection
- * a JDBC connection
- * @param tableTypes
- * the types of tables to include in the generated schemas
- * @return a DataContext object that matches the request
- */
- public static UpdateableDataContext createJdbcDataContext(Connection connection, TableType... tableTypes) {
- return new JdbcDataContext(connection, tableTypes, null);
- }
-
- /**
- * Creates a DataContext based on a JDBC connection
- *
- * @param connection
- * a JDBC connection
- * @param catalogName
- * a catalog name to use
- * @param tableTypes
- * the types of tables to include in the generated schemas
- * @return a DataContext object that matches the request
- */
- public static UpdateableDataContext createJdbcDataContext(Connection connection, String catalogName, TableType[] tableTypes) {
- return new JdbcDataContext(connection, tableTypes, catalogName);
- }
-
- /**
- * Creates a DataContext based on a JDBC datasource
- *
- * @param ds
- * a JDBC datasource
- * @param tableTypes
- * the types of tables to include in the generated schemas
- * @return a DataContext object that matches the request
- */
- public static UpdateableDataContext createJdbcDataContext(DataSource ds, TableType... tableTypes) {
- return new JdbcDataContext(ds, tableTypes, null);
- }
-
- /**
- * Creates a DataContext based on a JDBC datasource
- *
- * @param ds
- * a JDBC datasource
- * @param catalogName
- * a catalog name to use
- * @param tableTypes
- * the types of tables to include in the generated schemas
- * @return a DataContext object that matches the request
- */
- public static UpdateableDataContext createJdbcDataContext(DataSource ds, String catalogName, TableType[] tableTypes) {
- return new JdbcDataContext(ds, tableTypes, catalogName);
- }
-
- /**
- * Creates a DataContext based on a JDBC datasource
- *
- * @param ds
- * a JDBC datasource
- * @param catalogName
- * a catalog name to use
- * @return a DataContext object that matches the request
- */
- public static UpdateableDataContext createJdbcDataContext(DataSource ds, String catalogName) {
- return new JdbcDataContext(ds, TableType.DEFAULT_TABLE_TYPES, catalogName);
- }
-
- /**
- * Creates a new MongoDB datacontext.
- *
- * @param hostname
- * The hostname of the MongoDB instance
- * @param port
- * the port of the MongoDB instance, or null if the default port
- * should be used.
- * @param databaseName
- * the name of the database
- * @param username
- * the username, or null if unauthenticated access should be used
- * @param password
- * the password, or null if unathenticated access should be used
- * @return a DataContext object that matches the request
- */
- public static UpdateableDataContext createMongoDbDataContext(String hostname, Integer port, String databaseName,
- String username, char[] password) {
- try {
- DB mongoDb;
- if (port == null) {
- mongoDb = new Mongo(hostname).getDB(databaseName);
- } else {
- mongoDb = new Mongo(hostname, port).getDB(databaseName);
- }
- if (username != null) {
- mongoDb.authenticate(username, password);
- }
- return new MongoDbDataContext(mongoDb);
- } catch (Exception e) {
- if (e instanceof RuntimeException) {
- throw (RuntimeException) e;
- }
- throw new IllegalStateException(e);
- }
- }
-
- /**
- * Creates a new CouchDB datacontext.
- *
- * @param hostname
- * The hostname of the CouchDB instance
- * @param port
- * the port of the CouchDB instance, or null if the default port
- * should be used.
- * @param username
- * the username, or null if unauthenticated access should be used
- * @param password
- * the password, or null if unathenticated access should be used
- * @return a DataContext object that matches the request
- */
- public static UpdateableDataContext createCouchDbDataContext(String hostname, Integer port, String username, String password) {
-
- Builder httpClientBuilder = new Builder();
- httpClientBuilder.host(hostname);
- if (port != null) {
- httpClientBuilder.port(port);
- }
- if (username != null) {
- httpClientBuilder.username(username);
- }
- if (password != null) {
- httpClientBuilder.password(password);
- }
-
- // increased timeouts (20 sec) - metamodel typically does quite some
- // batching so it might take a bit of time to provide a connection.
- httpClientBuilder.connectionTimeout(20000);
- httpClientBuilder.socketTimeout(20000);
-
- return new CouchDbDataContext(httpClientBuilder);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/full/src/test/java/org/apache/metamodel/DataContextFactoryTest.java
----------------------------------------------------------------------
diff --git a/full/src/test/java/org/apache/metamodel/DataContextFactoryTest.java b/full/src/test/java/org/apache/metamodel/DataContextFactoryTest.java
new file mode 100644
index 0000000..5bf24e1
--- /dev/null
+++ b/full/src/test/java/org/apache/metamodel/DataContextFactoryTest.java
@@ -0,0 +1,46 @@
+/**
+ * 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;
+
+import java.io.File;
+
+import org.eobjects.metamodel.excel.ExcelConfiguration;
+import org.eobjects.metamodel.excel.ExcelDataContext;
+
+import junit.framework.TestCase;
+
+public class DataContextFactoryTest extends TestCase {
+
+ public void testCreateExcelDataContext() throws Exception {
+ File file = new File("../excel/src/test/resources/xls_people.xls");
+ assertTrue(file.exists());
+
+ UpdateableDataContext dc;
+
+ dc = DataContextFactory.createExcelDataContext(file);
+ assertNotNull(dc);
+ assertTrue(dc instanceof ExcelDataContext);
+
+ dc = DataContextFactory.createExcelDataContext(file,
+ new ExcelConfiguration());
+ assertNotNull(dc);
+ assertTrue(dc instanceof ExcelDataContext);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/full/src/test/java/org/eobjects/metamodel/DataContextFactoryTest.java
----------------------------------------------------------------------
diff --git a/full/src/test/java/org/eobjects/metamodel/DataContextFactoryTest.java b/full/src/test/java/org/eobjects/metamodel/DataContextFactoryTest.java
deleted file mode 100644
index 374c1b7..0000000
--- a/full/src/test/java/org/eobjects/metamodel/DataContextFactoryTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * 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;
-
-import java.io.File;
-
-import org.eobjects.metamodel.excel.ExcelConfiguration;
-import org.eobjects.metamodel.excel.ExcelDataContext;
-
-import junit.framework.TestCase;
-
-public class DataContextFactoryTest extends TestCase {
-
- public void testCreateExcelDataContext() throws Exception {
- File file = new File("../excel/src/test/resources/xls_people.xls");
- assertTrue(file.exists());
-
- UpdateableDataContext dc;
-
- dc = DataContextFactory.createExcelDataContext(file);
- assertNotNull(dc);
- assertTrue(dc instanceof ExcelDataContext);
-
- dc = DataContextFactory.createExcelDataContext(file,
- new ExcelConfiguration());
- assertNotNull(dc);
- assertTrue(dc instanceof ExcelDataContext);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/FetchSizeCalculator.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/FetchSizeCalculator.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/FetchSizeCalculator.java
new file mode 100644
index 0000000..155adf9
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/FetchSizeCalculator.java
@@ -0,0 +1,264 @@
+/**
+ * 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.jdbc;
+
+import java.util.List;
+
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class used to calculate an appropriate fetch size of a JDBC query.
+ *
+ * The approach used in this class is largely based on the documentation of
+ * Oracle's caching size, see <a href=
+ * "http://www.oracle.com/technetwork/database/enterprise-edition/memory.pdf"
+ * >JDBC Memory Management</a>, section "Where does it all go?".
+ *
+ * @author Kasper Sørensen
+ */
+final class FetchSizeCalculator {
+
+ /**
+ * 22 bytes is a reasonable approximation for remaining row types, we add a
+ * few bytes to be on the safe side.
+ */
+ private static final int DEFAULT_COLUMN_SIZE = 30;
+
+ /**
+ * A kilobyte (kb)
+ */
+ private static final int KB = 1024;
+
+ private static final Logger logger = LoggerFactory
+ .getLogger(FetchSizeCalculator.class);
+
+ private static final int MIN_FETCH_SIZE = 1;
+ private static final int MAX_FETCH_SIZE = 25000;
+ private final int _bytesInMemory;
+
+ public FetchSizeCalculator(int bytesInMemory) {
+ _bytesInMemory = bytesInMemory;
+ }
+
+ /**
+ * Gets the fetch size of a query
+ *
+ * @param query
+ * the query to execute
+ * @return an integer representing how many rows to eagerly fetch for the
+ * query
+ */
+ public int getFetchSize(Query query) {
+ if (isSingleRowQuery(query)) {
+ return 1;
+ }
+ int bytesPerRow = getRowSize(query);
+ int result = getFetchSize(bytesPerRow);
+ final Integer maxRows = query.getMaxRows();
+ if (maxRows != null && result > maxRows) {
+ logger.debug("Result ({}) was below max rows ({}), adjusting.",
+ result, maxRows);
+ result = maxRows;
+ }
+ return result;
+ }
+
+ /**
+ * Gets whether a query is guaranteed to only yield a single row. Such
+ * queries are queries that only consist of aggregation functions and no
+ * group by clause.
+ *
+ * @param query
+ * @return
+ */
+ private boolean isSingleRowQuery(Query query) {
+ if (!query.getGroupByClause().isEmpty()) {
+ return false;
+ }
+
+ List<SelectItem> items = query.getSelectClause().getItems();
+ for (SelectItem item : items) {
+ if (item.getFunction() == null) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Gets the fetch size of a query based on the columns to query.
+ *
+ * @param columns
+ * the columns to query
+ * @return an integer representing how many rows to eagerly fetch for the
+ * query
+ */
+ public int getFetchSize(Column... columns) {
+ int bytesPerRow = getRowSize(columns);
+ return getFetchSize(bytesPerRow);
+ }
+
+ /**
+ * Gets the size of a row (in bytes).
+ *
+ * @param query
+ * the query that will yield the rows
+ * @return an integer representing the size of a row from the given query
+ * (in bytes).
+ */
+ protected int getRowSize(Query query) {
+ List<SelectItem> items = query.getSelectClause().getItems();
+ int bytesPerRow = 0;
+ for (SelectItem selectItem : items) {
+ bytesPerRow += getValueSize(selectItem);
+ }
+ return bytesPerRow;
+ }
+
+ /**
+ * Gets the size of a row (in bytes).
+ *
+ * @param columns
+ * the columns in the row
+ * @return an integer representing the size of a row with the given columns
+ * (in bytes).
+ */
+ protected int getRowSize(Column... columns) {
+ int bytesPerRow = 0;
+ for (Column column : columns) {
+ bytesPerRow += getValueSize(column);
+ }
+ return bytesPerRow;
+ }
+
+ /**
+ * Gets the principal fetch size for a query where a row has the given size.
+ *
+ * @param bytesPerRow
+ * the size (in bytes) of a single row in the result set.
+ * @return an appropriate fetch size.
+ */
+ protected int getFetchSize(int bytesPerRow) {
+ if (bytesPerRow == 0) {
+ // prevent divide by zero
+ return MAX_FETCH_SIZE;
+ }
+ int result = _bytesInMemory / bytesPerRow;
+ if (result < MIN_FETCH_SIZE) {
+ logger.debug(
+ "Result ({}) was below minimum fetch size ({}), adjusting.",
+ result, MIN_FETCH_SIZE);
+ result = MIN_FETCH_SIZE;
+ } else if (result > MAX_FETCH_SIZE) {
+ logger.debug(
+ "Result ({}) was above maximum fetch size ({}), adjusting.",
+ result, MAX_FETCH_SIZE);
+ result = MAX_FETCH_SIZE;
+ }
+ return result;
+ }
+
+ /**
+ * Gets the size (in bytes) of a single {@link SelectItem}
+ */
+ protected int getValueSize(SelectItem selectItem) {
+ Column column = selectItem.getColumn();
+ if (column == null) {
+ return DEFAULT_COLUMN_SIZE;
+ } else {
+ return getValueSize(column);
+ }
+ }
+
+ /**
+ * Gets the size (in bytes) of a single {@link Column}
+ */
+ protected int getValueSize(Column column) {
+ ColumnType type = column.getType();
+ if (type == null) {
+ return DEFAULT_COLUMN_SIZE;
+ } else {
+ Integer columnSize = column.getColumnSize();
+ if (columnSize == null) {
+ // if column size is missing, then use
+ // size-indifferent approach
+ return getSize(type);
+ } else if (columnSize > 10000 && !type.isLargeObject()) {
+ // if column size is unrealistically high, then use
+ // size-indifferent approach
+ return getSize(type);
+ } else {
+ return getSize(type, columnSize);
+ }
+ }
+ }
+
+ /**
+ * Gets the size (in bytes) of a column with a specific {@link ColumnType}
+ * and size
+ */
+ private int getSize(ColumnType type, int columnSize) {
+ final int baseSize;
+ if (type.isBinary()) {
+ baseSize = 1;
+ } else if (type.isBoolean()) {
+ baseSize = 1;
+ } else if (type.isLiteral()) {
+ baseSize = 2;
+ } else if (type.isNumber()) {
+ baseSize = 16;
+ } else {
+ baseSize = DEFAULT_COLUMN_SIZE;
+ }
+
+ int result = baseSize * columnSize;
+
+ if (type.isLargeObject()) {
+ // assign at least 4KB for LOBs.
+ result = Math.max(result, 4 * KB);
+ }
+
+ return result;
+ }
+
+ /**
+ * Gets the (approximate) size (in bytes) of a column with a specific
+ * {@link ColumnType}.
+ */
+ private int getSize(ColumnType type) {
+ if (type.isBinary()) {
+ return 4 * KB;
+ } else if (type.isBoolean()) {
+ return 2;
+ } else if (type.isLargeObject()) {
+ return 4 * KB;
+ } else if (type.isLiteral()) {
+ return KB;
+ } else if (type.isNumber()) {
+ return 16;
+ } else {
+ return DEFAULT_COLUMN_SIZE;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcBatchUpdateCallback.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcBatchUpdateCallback.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcBatchUpdateCallback.java
new file mode 100644
index 0000000..50e38a4
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcBatchUpdateCallback.java
@@ -0,0 +1,76 @@
+/**
+ * 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.jdbc;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.eobjects.metamodel.UpdateCallback;
+import org.eobjects.metamodel.util.FileHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Jdbc {@link UpdateCallback} for databases that support the JDBC Batch
+ * features.
+ *
+ * @author Kasper Sørensen
+ */
+final class JdbcBatchUpdateCallback extends JdbcUpdateCallback {
+
+ private static final Logger logger = LoggerFactory.getLogger(JdbcBatchUpdateCallback.class);
+
+ public JdbcBatchUpdateCallback(JdbcDataContext dataContext) {
+ super(dataContext);
+ }
+
+ @Override
+ protected void closePreparedStatement(PreparedStatement preparedStatement) {
+ try {
+ int[] results = preparedStatement.executeBatch();
+ if (logger.isDebugEnabled()) {
+ for (int i = 0; i < results.length; i++) {
+ int result = results[i];
+ final String resultString;
+ switch (result) {
+ case Statement.SUCCESS_NO_INFO:
+ resultString = "SUCCESS_NO_INFO";
+ break;
+ case Statement.EXECUTE_FAILED:
+ resultString = "EXECUTE_FAILED";
+ break;
+ default:
+ resultString = result + " rows updated";
+ }
+ logger.debug("batch execute result[" + i + "]:" + resultString);
+ }
+ }
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "execute batch: " + preparedStatement);
+ } finally {
+ FileHelper.safeClose(preparedStatement);
+ }
+ }
+
+ @Override
+ protected void executePreparedStatement(PreparedStatement st) throws SQLException {
+ st.addBatch();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcColumn.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcColumn.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcColumn.java
new file mode 100644
index 0000000..de09ce7
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcColumn.java
@@ -0,0 +1,55 @@
+/**
+ * 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.jdbc;
+
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * Column implementation for JDBC data contexts.
+ *
+ * @author Kasper Sørensen
+ */
+final class JdbcColumn extends MutableColumn {
+
+ private static final long serialVersionUID = 389872697452157919L;
+
+ public JdbcColumn(String columnName, ColumnType columnType, JdbcTable table, int columnNumber, Boolean nullable) {
+ super(columnName, columnType, table, columnNumber, nullable);
+ }
+
+ @Override
+ public boolean isIndexed() {
+ Table table = getTable();
+ if (table instanceof JdbcTable) {
+ ((JdbcTable) table).loadIndexes();
+ }
+ return super.isIndexed();
+ }
+
+ @Override
+ public boolean isPrimaryKey() {
+ Table table = getTable();
+ if (table instanceof JdbcTable) {
+ ((JdbcTable) table).loadPrimaryKeys();
+ }
+ return super.isPrimaryKey();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQuery.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQuery.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQuery.java
new file mode 100644
index 0000000..ddadf1f
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQuery.java
@@ -0,0 +1,140 @@
+/**
+ * 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.jdbc;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.List;
+
+import org.apache.commons.pool.impl.GenericObjectPool;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.query.CompiledQuery;
+import org.eobjects.metamodel.query.DefaultCompiledQuery;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Implementation of {@link CompiledQuery} for JDBC which uses a
+ * {@link PreparedStatement} behind the scenes.
+ */
+final class JdbcCompiledQuery extends DefaultCompiledQuery implements CompiledQuery {
+
+ private static final Logger logger = LoggerFactory.getLogger(JdbcCompiledQuery.class);
+
+ private final JdbcDataContext _dataContext;
+ private final Connection _connection;
+ private final String _sql;
+ private final Query _query;
+ private final GenericObjectPool<JdbcCompiledQueryLease> _pool;
+ private boolean _closed;
+
+ public JdbcCompiledQuery(JdbcDataContext dc, Query query) {
+ super(query);
+ _dataContext = dc;
+ _connection = dc.getConnection();
+ _query = query;
+ _sql = dc.getQueryRewriter().rewriteQuery(query);
+ _pool = new GenericObjectPool<JdbcCompiledQueryLease>(new JdbcCompiledQueryLeaseFactory(dc, _connection, _sql));
+ _closed = false;
+
+ logger.debug("Created compiled JDBC query: {}", _sql);
+ }
+
+ public JdbcCompiledQueryLease borrowLease() {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Borrowing lease. Leases (before): Active={}, Idle={}", getActiveLeases(), getIdleLeases());
+ }
+ try {
+ return _pool.borrowObject();
+ } catch (Exception e) {
+ throw handleError(e, "borrow lease");
+ }
+ }
+
+ public void returnLease(JdbcCompiledQueryLease lease) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Returning lease. Leases (before): Active={}, Idle={}", getActiveLeases(), getIdleLeases());
+ }
+ try {
+ _pool.returnObject(lease);
+ } catch (Exception e) {
+ throw handleError(e, "return lease");
+ }
+ }
+
+ private RuntimeException handleError(Exception e, String message) {
+ if (logger.isWarnEnabled()) {
+ logger.warn("Unexpected error occurred in compiled JDBC query: " + message, e);
+ }
+
+ if (e instanceof SQLException) {
+ return JdbcUtils.wrapException((SQLException) e, message);
+ } else if (e instanceof RuntimeException) {
+ return (RuntimeException) e;
+ } else {
+ return new MetaModelException(message, e);
+ }
+ }
+
+ protected int getActiveLeases() {
+ return _pool.getNumActive();
+ }
+
+ protected int getIdleLeases() {
+ return _pool.getNumIdle();
+ }
+
+ protected Query getQuery() {
+ return _query;
+ }
+
+ @Override
+ public String toSql() {
+ return _sql;
+ }
+
+ @Override
+ public void close() {
+ logger.debug("Closing compiled JDBC query: {}", _sql);
+ try {
+ _pool.close();
+ } catch (Exception e) {
+ throw handleError(e, "close pool of leases");
+ } finally {
+ _dataContext.close(_connection, null, null);
+ _closed = true;
+ }
+ }
+
+ protected List<SelectItem> getSelectItems() {
+ return _query.getSelectClause().getItems();
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ if (!_closed) {
+ logger.warn("finalize() invoked, but DataSet is not closed. Invoking close() on {}", this);
+ close();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQueryLease.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQueryLease.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQueryLease.java
new file mode 100644
index 0000000..65bf7b5
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQueryLease.java
@@ -0,0 +1,48 @@
+/**
+ * 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.jdbc;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+
+/**
+ * Represents a "lease" of a JdbcCompiledQuery. A lease holds the
+ * {@link Connection} and {@link PreparedStatement} object associated with
+ * executing a compiled query. Since these are not thread-safe, but expensive to
+ * create, they are pooled to allow proper isolation when executing compiled
+ * queries.
+ */
+final class JdbcCompiledQueryLease {
+
+ private final Connection _connection;
+ private final PreparedStatement _statement;
+
+ public JdbcCompiledQueryLease(Connection connection, PreparedStatement statement) {
+ _connection = connection;
+ _statement = statement;
+ }
+
+ public Connection getConnection() {
+ return _connection;
+ }
+
+ public PreparedStatement getStatement() {
+ return _statement;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQueryLeaseFactory.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQueryLeaseFactory.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQueryLeaseFactory.java
new file mode 100644
index 0000000..e3712ed
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCompiledQueryLeaseFactory.java
@@ -0,0 +1,71 @@
+/**
+ * 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.jdbc;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import org.apache.commons.pool.PoolableObjectFactory;
+
+/**
+ * Factory for the object pool of {@link JdbcCompiledQueryLease}s.
+ */
+final class JdbcCompiledQueryLeaseFactory implements PoolableObjectFactory<JdbcCompiledQueryLease> {
+
+ private final JdbcDataContext _dataContext;
+ private final Connection _connection;
+ private final String _sql;
+
+ public JdbcCompiledQueryLeaseFactory(JdbcDataContext dataContext, Connection connection, String sql) {
+ _dataContext = dataContext;
+ _connection = connection;
+ _sql = sql;
+ }
+
+
+ @Override
+ public JdbcCompiledQueryLease makeObject() throws Exception {
+ try {
+ final PreparedStatement statement = _connection.prepareStatement(_sql);
+ final JdbcCompiledQueryLease lease = new JdbcCompiledQueryLease(_connection, statement);
+ return lease;
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "preparing statement");
+ }
+ }
+
+ @Override
+ public void destroyObject(JdbcCompiledQueryLease lease) throws Exception {
+ _dataContext.close(null, null, lease.getStatement());
+ }
+
+ @Override
+ public boolean validateObject(JdbcCompiledQueryLease lease) {
+ return true;
+ }
+
+ @Override
+ public void activateObject(JdbcCompiledQueryLease obj) throws Exception {
+ }
+
+ @Override
+ public void passivateObject(JdbcCompiledQueryLease obj) throws Exception {
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCreateTableBuilder.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCreateTableBuilder.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCreateTableBuilder.java
new file mode 100644
index 0000000..a1afc6c
--- /dev/null
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCreateTableBuilder.java
@@ -0,0 +1,127 @@
+/**
+ * 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.jdbc;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.eobjects.metamodel.create.AbstractTableCreationBuilder;
+import org.eobjects.metamodel.jdbc.dialects.IQueryRewriter;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.FileHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * {@link CreateTableBuilder} implementation that issues a SQL CREATE TABLE
+ * statement.
+ *
+ * @author Kasper Sørensen
+ */
+final class JdbcCreateTableBuilder extends AbstractTableCreationBuilder<JdbcUpdateCallback> {
+
+ private static final Logger logger = LoggerFactory.getLogger(JdbcCreateTableBuilder.class);
+
+ public JdbcCreateTableBuilder(JdbcUpdateCallback updateCallback, Schema schema, String name) {
+ super(updateCallback, schema, name);
+ if (!(schema instanceof JdbcSchema)) {
+ throw new IllegalArgumentException("Not a valid JDBC schema: " + schema);
+ }
+ }
+
+ @Override
+ public Table execute() {
+ final String sql = createSqlStatement();
+ logger.info("Create table statement created: {}", sql);
+
+ Connection connection = getUpdateCallback().getConnection();
+ Statement st = null;
+ try {
+ st = connection.createStatement();
+ int rowsAffected = st.executeUpdate(sql);
+ logger.debug("Create table statement executed, {} rows affected", rowsAffected);
+ } catch (SQLException e) {
+ throw JdbcUtils.wrapException(e, "execute create table statement: " + sql);
+ } finally {
+ FileHelper.safeClose(st);
+ }
+
+ JdbcSchema schema = (JdbcSchema) getSchema();
+ schema.refreshTables();
+ return schema.getTableByName(getTable().getName());
+ }
+
+ protected String createSqlStatement() {
+ return createSqlStatement(getTable());
+ }
+
+ private String createSqlStatement(Table table) {
+ final IQueryRewriter queryRewriter = getUpdateCallback().getDataContext().getQueryRewriter();
+ final StringBuilder sb = new StringBuilder();
+ sb.append("CREATE TABLE ");
+ final Schema schema = getSchema();
+ if (schema != null && schema.getName() != null) {
+ sb.append(schema.getQualifiedLabel());
+ sb.append(".");
+ }
+ sb.append(getUpdateCallback().quoteIfNescesary(table.getName()));
+ sb.append(" (");
+ final Column[] columns = table.getColumns();
+ for (int i = 0; i < columns.length; i++) {
+ final Column column = columns[i];
+ if (i != 0) {
+ sb.append(", ");
+ }
+ sb.append(getUpdateCallback().quoteIfNescesary(column.getName()));
+ sb.append(' ');
+ final String nativeType = column.getNativeType();
+ if (nativeType == null) {
+ ColumnType columnType = column.getType();
+ if (columnType == null) {
+ columnType = ColumnType.VARCHAR;
+ }
+
+ final String columnTypeString = queryRewriter.rewriteColumnType(columnType);
+
+ sb.append(columnTypeString);
+ } else {
+ sb.append(nativeType);
+ }
+ final Integer columnSize = column.getColumnSize();
+ if (columnSize != null) {
+ sb.append('(');
+ sb.append(columnSize.intValue());
+ 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();
+ }
+
+}
[60/61] git commit: Added a utility ObjectInputStream for
deserializing legacy org.eobjects.metamodel objects.
Posted by ka...@apache.org.
Added a utility ObjectInputStream for deserializing legacy
org.eobjects.metamodel objects.
Project: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/commit/69ad6cdd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/tree/69ad6cdd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/diff/69ad6cdd
Branch: refs/heads/namespace-rename
Commit: 69ad6cdd497f900af50d7cb018ace53139771c8a
Parents: 587d518
Author: kaspers <ka...@kaspers-think.humaninference.com>
Authored: Fri Jul 19 11:04:34 2013 +0200
Committer: kaspers <ka...@kaspers-think.humaninference.com>
Committed: Fri Jul 19 11:04:34 2013 +0200
----------------------------------------------------------------------
.../org/apache/metamodel/data/DefaultRow.java | 2 +-
.../org/apache/metamodel/data/StyleImpl.java | 292 +++++++++----------
.../apache/metamodel/schema/ImmutableTable.java | 2 -
.../LegacyDeserializationObjectInputStream.java | 47 +++
.../apache/metamodel/data/DefaultRowTest.java | 7 +-
5 files changed, 197 insertions(+), 153 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/69ad6cdd/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
index c528bc3..64703d4 100644
--- a/core/src/main/java/org/apache/metamodel/data/DefaultRow.java
+++ b/core/src/main/java/org/apache/metamodel/data/DefaultRow.java
@@ -35,7 +35,7 @@ public final class DefaultRow extends AbstractRow implements Row {
private final DataSetHeader _header;
private final Object[] _values;
private final Style[] _styles;
-
+
/**
* This field was replaced by the DataSetHeader field above.
*
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/69ad6cdd/core/src/main/java/org/apache/metamodel/data/StyleImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/data/StyleImpl.java b/core/src/main/java/org/apache/metamodel/data/StyleImpl.java
index ef6ba31..6e2f078 100644
--- a/core/src/main/java/org/apache/metamodel/data/StyleImpl.java
+++ b/core/src/main/java/org/apache/metamodel/data/StyleImpl.java
@@ -27,151 +27,149 @@ import org.apache.metamodel.util.BaseObject;
*
* @author Kasper Sørensen
*/
-final class StyleImpl extends BaseObject implements Style {
-
- private static final long serialVersionUID = 1L;
-
- private final boolean _underline;
- private final boolean _italic;
- private final boolean _bold;
- private final Integer _fontSize;
- private final TextAlignment _alignment;
- private final Color _backgroundColor;
- private final Color _foregroundColor;
- private final SizeUnit _fontSizeUnit;
-
- public StyleImpl() {
- this(false, false, false, null, null, null, null, null);
- }
-
- public StyleImpl(boolean bold, boolean italic, boolean underline,
- Integer fontSize, SizeUnit fontSizeUnit, TextAlignment alignment,
- Color backgroundColor, Color foregroundColor) {
- _bold = bold;
- _italic = italic;
- _underline = underline;
- _fontSize = fontSize;
- _fontSizeUnit = fontSizeUnit;
- _alignment = alignment;
- _backgroundColor = backgroundColor;
- _foregroundColor = foregroundColor;
- }
-
- @Override
- public boolean isBold() {
- return _bold;
- }
-
- @Override
- public boolean isItalic() {
- return _italic;
- }
-
- @Override
- public boolean isUnderline() {
- return _underline;
- }
-
- @Override
- public Integer getFontSize() {
- return _fontSize;
- }
-
- @Override
- public SizeUnit getFontSizeUnit() {
- return _fontSizeUnit;
- }
-
- @Override
- public TextAlignment getAlignment() {
- return _alignment;
- }
-
- @Override
- public Color getForegroundColor() {
- return _foregroundColor;
- }
-
- @Override
- public Color getBackgroundColor() {
- return _backgroundColor;
- }
-
- @Override
- public String toCSS() {
- StringBuilder sb = new StringBuilder();
- if (_bold) {
- sb.append("font-weight: bold;");
- }
- if (_italic) {
- sb.append("font-style: italic;");
- }
- if (_underline) {
- sb.append("text-decoration: underline;");
- }
- if (_alignment != null) {
- sb.append("text-align: " + toCSS(_alignment) + ";");
- }
- if (_fontSize != null) {
- sb.append("font-size: " + _fontSize);
- switch (_fontSizeUnit) {
- case PT:
- sb.append("pt");
- break;
- case PX:
- sb.append("px");
- break;
- case PERCENT:
- sb.append("%");
- break;
- default:
- // don't write a size unit
- }
- sb.append(';');
- }
- if (_foregroundColor != null) {
- sb.append("color: " + toCSS(_foregroundColor) + ";");
- }
- if (_backgroundColor != null) {
- sb.append("background-color: " + toCSS(_backgroundColor) + ";");
- }
- return sb.toString();
- }
-
- private String toCSS(Color c) {
- return "rgb(" + c.getRed() + "," + c.getGreen() + "," + c.getBlue()
- + ")";
- }
-
- @Override
- public String toString() {
- return toCSS();
- }
-
- private String toCSS(TextAlignment alignment) {
- switch (alignment) {
- case LEFT:
- return "left";
- case RIGHT:
- return "right";
- case CENTER:
- return "center";
- case JUSTIFY:
- return "justify";
- default:
- throw new IllegalStateException("Unknown alignment: " + alignment);
- }
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- identifiers.add(_underline);
- identifiers.add(_italic);
- identifiers.add(_bold);
- identifiers.add(_fontSize);
- identifiers.add(_fontSizeUnit);
- identifiers.add(_alignment);
- identifiers.add(_backgroundColor);
- identifiers.add(_foregroundColor);
- }
+public final class StyleImpl extends BaseObject implements Style {
+
+ private static final long serialVersionUID = 1L;
+
+ private final boolean _underline;
+ private final boolean _italic;
+ private final boolean _bold;
+ private final Integer _fontSize;
+ private final TextAlignment _alignment;
+ private final Color _backgroundColor;
+ private final Color _foregroundColor;
+ private final SizeUnit _fontSizeUnit;
+
+ public StyleImpl() {
+ this(false, false, false, null, null, null, null, null);
+ }
+
+ public StyleImpl(boolean bold, boolean italic, boolean underline, Integer fontSize, SizeUnit fontSizeUnit,
+ TextAlignment alignment, Color backgroundColor, Color foregroundColor) {
+ _bold = bold;
+ _italic = italic;
+ _underline = underline;
+ _fontSize = fontSize;
+ _fontSizeUnit = fontSizeUnit;
+ _alignment = alignment;
+ _backgroundColor = backgroundColor;
+ _foregroundColor = foregroundColor;
+ }
+
+ @Override
+ public boolean isBold() {
+ return _bold;
+ }
+
+ @Override
+ public boolean isItalic() {
+ return _italic;
+ }
+
+ @Override
+ public boolean isUnderline() {
+ return _underline;
+ }
+
+ @Override
+ public Integer getFontSize() {
+ return _fontSize;
+ }
+
+ @Override
+ public SizeUnit getFontSizeUnit() {
+ return _fontSizeUnit;
+ }
+
+ @Override
+ public TextAlignment getAlignment() {
+ return _alignment;
+ }
+
+ @Override
+ public Color getForegroundColor() {
+ return _foregroundColor;
+ }
+
+ @Override
+ public Color getBackgroundColor() {
+ return _backgroundColor;
+ }
+
+ @Override
+ public String toCSS() {
+ StringBuilder sb = new StringBuilder();
+ if (_bold) {
+ sb.append("font-weight: bold;");
+ }
+ if (_italic) {
+ sb.append("font-style: italic;");
+ }
+ if (_underline) {
+ sb.append("text-decoration: underline;");
+ }
+ if (_alignment != null) {
+ sb.append("text-align: " + toCSS(_alignment) + ";");
+ }
+ if (_fontSize != null) {
+ sb.append("font-size: " + _fontSize);
+ switch (_fontSizeUnit) {
+ case PT:
+ sb.append("pt");
+ break;
+ case PX:
+ sb.append("px");
+ break;
+ case PERCENT:
+ sb.append("%");
+ break;
+ default:
+ // don't write a size unit
+ }
+ sb.append(';');
+ }
+ if (_foregroundColor != null) {
+ sb.append("color: " + toCSS(_foregroundColor) + ";");
+ }
+ if (_backgroundColor != null) {
+ sb.append("background-color: " + toCSS(_backgroundColor) + ";");
+ }
+ return sb.toString();
+ }
+
+ private String toCSS(Color c) {
+ return "rgb(" + c.getRed() + "," + c.getGreen() + "," + c.getBlue() + ")";
+ }
+
+ @Override
+ public String toString() {
+ return toCSS();
+ }
+
+ private String toCSS(TextAlignment alignment) {
+ switch (alignment) {
+ case LEFT:
+ return "left";
+ case RIGHT:
+ return "right";
+ case CENTER:
+ return "center";
+ case JUSTIFY:
+ return "justify";
+ default:
+ throw new IllegalStateException("Unknown alignment: " + alignment);
+ }
+ }
+
+ @Override
+ protected void decorateIdentity(List<Object> identifiers) {
+ identifiers.add(_underline);
+ identifiers.add(_italic);
+ identifiers.add(_bold);
+ identifiers.add(_fontSize);
+ identifiers.add(_fontSizeUnit);
+ identifiers.add(_alignment);
+ identifiers.add(_backgroundColor);
+ identifiers.add(_foregroundColor);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/69ad6cdd/core/src/main/java/org/apache/metamodel/schema/ImmutableTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/ImmutableTable.java b/core/src/main/java/org/apache/metamodel/schema/ImmutableTable.java
index 4fc470b..d807290 100644
--- a/core/src/main/java/org/apache/metamodel/schema/ImmutableTable.java
+++ b/core/src/main/java/org/apache/metamodel/schema/ImmutableTable.java
@@ -29,8 +29,6 @@ import java.util.List;
* constructor in ImmutableSchema.
*
* @see ImmutableSchema
- *
- * @author Kasper Sørensen
*/
final class ImmutableTable extends AbstractTable implements Serializable {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/69ad6cdd/core/src/main/java/org/apache/metamodel/util/LegacyDeserializationObjectInputStream.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/LegacyDeserializationObjectInputStream.java b/core/src/main/java/org/apache/metamodel/util/LegacyDeserializationObjectInputStream.java
new file mode 100644
index 0000000..c5ab2e5
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/LegacyDeserializationObjectInputStream.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.metamodel.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+
+/**
+ * A specialized {@link ObjectInputStream} for MetaModel which can be used or
+ * extended if it is needed to deserialize legacy MetaModel objects. This is
+ * needed since the namespace of MetaModel was changed from
+ * org.eobjects.metamodel to org.apache.metamodel.
+ */
+public class LegacyDeserializationObjectInputStream extends ObjectInputStream {
+
+ public LegacyDeserializationObjectInputStream(InputStream in) throws IOException, SecurityException {
+ super(in);
+ }
+
+ @Override
+ protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
+ String className = desc.getName();
+ if (className.startsWith("org.eobjects.metamodel") || className.startsWith("[Lorg.eobjects.metamodel")) {
+ String newClassName = className.replace("org.eobjects", "org.apache");
+ return Class.forName(newClassName);
+ }
+ return super.resolveClass(desc);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/69ad6cdd/core/src/test/java/org/apache/metamodel/data/DefaultRowTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/data/DefaultRowTest.java b/core/src/test/java/org/apache/metamodel/data/DefaultRowTest.java
index e19cc29..45ff980 100644
--- a/core/src/test/java/org/apache/metamodel/data/DefaultRowTest.java
+++ b/core/src/test/java/org/apache/metamodel/data/DefaultRowTest.java
@@ -25,20 +25,21 @@ import java.lang.reflect.Field;
import org.apache.metamodel.query.SelectItem;
import org.apache.metamodel.schema.MutableColumn;
import org.apache.metamodel.util.FileHelper;
+import org.apache.metamodel.util.LegacyDeserializationObjectInputStream;
import junit.framework.TestCase;
public class DefaultRowTest extends TestCase {
- SelectItem[] items = new SelectItem[] { new SelectItem(new MutableColumn("foo")),
+ private SelectItem[] items = new SelectItem[] { new SelectItem(new MutableColumn("foo")),
new SelectItem(new MutableColumn("bar")) };
- Object[] values = new Object[] { "foo", "bar" };
+ private Object[] values = new Object[] { "foo", "bar" };
public void testDeserializeBackwardsCompatible() throws Exception {
Object obj;
FileInputStream fileIn = new FileInputStream("src/test/resources/metamodel-3.0-default-row.ser");
try {
- ObjectInputStream ois = new ObjectInputStream(fileIn);
+ ObjectInputStream ois = new LegacyDeserializationObjectInputStream(fileIn);
obj = ois.readObject();
ois.close();
} finally {
[57/61] Renamed all import and package statements from 'org.eobjects'
to 'org.apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/SelectClause.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/SelectClause.java b/core/src/main/java/org/apache/metamodel/query/SelectClause.java
index 82688a5..60c0b24 100644
--- a/core/src/main/java/org/apache/metamodel/query/SelectClause.java
+++ b/core/src/main/java/org/apache/metamodel/query/SelectClause.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
import java.util.List;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.schema.Column;
/**
* Represents the SELECT clause of a query containing SelectItems.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/SelectItem.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/SelectItem.java b/core/src/main/java/org/apache/metamodel/query/SelectItem.java
index a9b1707..6342676 100644
--- a/core/src/main/java/org/apache/metamodel/query/SelectItem.java
+++ b/core/src/main/java/org/apache/metamodel/query/SelectItem.java
@@ -16,16 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
import java.util.List;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.BaseObject;
-import org.eobjects.metamodel.util.EqualsBuilder;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.BaseObject;
+import org.apache.metamodel.util.EqualsBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/SumAggregateBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/SumAggregateBuilder.java b/core/src/main/java/org/apache/metamodel/query/SumAggregateBuilder.java
index 2cf8811..93b2676 100644
--- a/core/src/main/java/org/apache/metamodel/query/SumAggregateBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/SumAggregateBuilder.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
-import org.eobjects.metamodel.util.AggregateBuilder;
-import org.eobjects.metamodel.util.NumberComparator;
+import org.apache.metamodel.util.AggregateBuilder;
+import org.apache.metamodel.util.NumberComparator;
final class SumAggregateBuilder implements AggregateBuilder<Double> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/AbstractFilterBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/AbstractFilterBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/AbstractFilterBuilder.java
index 2d3bd25..482a6eb 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/AbstractFilterBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/AbstractFilterBuilder.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
import java.util.Collection;
import java.util.Date;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
/**
* Abstract implementation of {@link FilterBuilder} interface. All built filters
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/AbstractQueryFilterBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/AbstractQueryFilterBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/AbstractQueryFilterBuilder.java
index a015292..444ab2e 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/AbstractQueryFilterBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/AbstractQueryFilterBuilder.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
import java.util.Collection;
import java.util.Date;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
abstract class AbstractQueryFilterBuilder<B> extends GroupedQueryBuilderCallback implements FilterBuilder<B> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/ColumnSelectBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/ColumnSelectBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/ColumnSelectBuilder.java
index 00208cf..fa8c0f7 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/ColumnSelectBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/ColumnSelectBuilder.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
public interface ColumnSelectBuilder<B extends SatisfiedQueryBuilder<?>>
extends SatisfiedSelectBuilder<B> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/ColumnSelectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/ColumnSelectBuilderImpl.java b/core/src/main/java/org/apache/metamodel/query/builder/ColumnSelectBuilderImpl.java
index 161a36f..84d5449 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/ColumnSelectBuilderImpl.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/ColumnSelectBuilderImpl.java
@@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
import java.util.List;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
final class ColumnSelectBuilderImpl extends SatisfiedSelectBuilderImpl
implements ColumnSelectBuilder<GroupedQueryBuilder> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/CountSelectBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/CountSelectBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/CountSelectBuilder.java
index 61dd73d..037cf83 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/CountSelectBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/CountSelectBuilder.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
public interface CountSelectBuilder<B extends SatisfiedQueryBuilder<?>> extends
SatisfiedSelectBuilder<B> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/CountSelectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/CountSelectBuilderImpl.java b/core/src/main/java/org/apache/metamodel/query/builder/CountSelectBuilderImpl.java
index e2114b2..cf47d5f 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/CountSelectBuilderImpl.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/CountSelectBuilderImpl.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
import java.util.List;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
final class CountSelectBuilderImpl extends SatisfiedSelectBuilderImpl implements
CountSelectBuilder<GroupedQueryBuilder> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/FilterBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/FilterBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/FilterBuilder.java
index 01a09cc..01f2822 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/FilterBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/FilterBuilder.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
import java.util.Collection;
import java.util.Date;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.schema.Column;
/**
* Interface for builder callbacks that "respond" to filter condition building.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/FunctionSelectBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/FunctionSelectBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/FunctionSelectBuilder.java
index 516ce5e..2c84814 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/FunctionSelectBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/FunctionSelectBuilder.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
public interface FunctionSelectBuilder<B extends SatisfiedQueryBuilder<?>>
extends SatisfiedSelectBuilder<B> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/FunctionSelectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/FunctionSelectBuilderImpl.java b/core/src/main/java/org/apache/metamodel/query/builder/FunctionSelectBuilderImpl.java
index 68e9b39..6e1ced1 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/FunctionSelectBuilderImpl.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/FunctionSelectBuilderImpl.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
import java.util.List;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
final class FunctionSelectBuilderImpl extends SatisfiedSelectBuilderImpl
implements FunctionSelectBuilder<GroupedQueryBuilder> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilder.java
index d798d9b..c180f14 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilder.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.schema.Column;
/**
* Represents a built query that has a GROUP BY clause.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilderCallback.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilderCallback.java b/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilderCallback.java
index 6db7feb..5026696 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilderCallback.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/GroupedQueryBuilderCallback.java
@@ -16,17 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
import java.util.List;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.util.BaseObject;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.CompiledQuery;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.util.BaseObject;
abstract class GroupedQueryBuilderCallback extends BaseObject implements GroupedQueryBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 bd5248c..3c02090 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
@@ -16,22 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
import java.util.Arrays;
import java.util.List;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.BaseObject;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.CompiledQuery;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.BaseObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/HavingBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/HavingBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/HavingBuilder.java
index 1596ada..869ea1d 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/HavingBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/HavingBuilder.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
/**
* Builder interface for having items.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/HavingBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/HavingBuilderImpl.java b/core/src/main/java/org/apache/metamodel/query/builder/HavingBuilderImpl.java
index 13b197d..4406e65 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/HavingBuilderImpl.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/HavingBuilderImpl.java
@@ -16,16 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
import java.util.ArrayList;
import java.util.List;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
final class HavingBuilderImpl extends
AbstractQueryFilterBuilder<SatisfiedHavingBuilder> implements
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/InitFromBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/InitFromBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/InitFromBuilder.java
index fcbdbcf..796dcf6 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/InitFromBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/InitFromBuilder.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
/**
* The initial interface used when building a query. A query starts by stating
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 3d523a8..2585bea 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
@@ -16,16 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
import java.util.Arrays;
import java.util.List;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.BaseObject;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.BaseObject;
public final class InitFromBuilderImpl extends BaseObject implements InitFromBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/JoinFromBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/JoinFromBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/JoinFromBuilder.java
index 1cad5fc..4410cc8 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/JoinFromBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/JoinFromBuilder.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.schema.Column;
public interface JoinFromBuilder extends SatisfiedFromBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/JoinFromBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/JoinFromBuilderImpl.java b/core/src/main/java/org/apache/metamodel/query/builder/JoinFromBuilderImpl.java
index 6e9520c..a3211b0 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/JoinFromBuilderImpl.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/JoinFromBuilderImpl.java
@@ -16,17 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
import java.util.List;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.JoinType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.JoinType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
final class JoinFromBuilderImpl extends SatisfiedFromBuilderCallback implements
JoinFromBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 6cc2611..f51bd2a 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
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
/**
* Represents a builder where the FROM part is satisfied, ie. a SELECT clause is
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 d6798c2..3e58119 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
@@ -16,17 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
import java.util.List;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.BaseObject;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.BaseObject;
abstract class SatisfiedFromBuilderCallback extends BaseObject implements SatisfiedFromBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedHavingBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedHavingBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedHavingBuilder.java
index b5c6efe..ce509ec 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedHavingBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedHavingBuilder.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.schema.Column;
public interface SatisfiedHavingBuilder extends GroupedQueryBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedOrderByBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedOrderByBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedOrderByBuilder.java
index a7023cf..5f80245 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedOrderByBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedOrderByBuilder.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.schema.Column;
public interface SatisfiedOrderByBuilder<B extends SatisfiedQueryBuilder<?>>
extends SatisfiedQueryBuilder<B> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedOrderByBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedOrderByBuilderImpl.java b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedOrderByBuilderImpl.java
index 5ebe755..e50e4c2 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedOrderByBuilderImpl.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedOrderByBuilderImpl.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.OrderByItem;
-import org.eobjects.metamodel.query.OrderByItem.Direction;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.query.OrderByItem;
+import org.apache.metamodel.query.OrderByItem.Direction;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
final class SatisfiedOrderByBuilderImpl extends GroupedQueryBuilderCallback
implements SatisfiedOrderByBuilder<GroupedQueryBuilder> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedQueryBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedQueryBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedQueryBuilder.java
index dd98935..4579f48 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedQueryBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedQueryBuilder.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
+package org.apache.metamodel.query.builder;
+
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.CompiledQuery;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Column;
/**
* Represents a built query that is satisfied and ready for querying or further
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedSelectBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedSelectBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedSelectBuilder.java
index 886b763..a3c16e9 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedSelectBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedSelectBuilder.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.schema.Column;
public interface SatisfiedSelectBuilder<B extends SatisfiedQueryBuilder<?>>
extends SatisfiedQueryBuilder<B> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedSelectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedSelectBuilderImpl.java b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedSelectBuilderImpl.java
index 2fe66ce..47b4fc8 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedSelectBuilderImpl.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedSelectBuilderImpl.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.schema.Column;
class SatisfiedSelectBuilderImpl extends GroupedQueryBuilderCallback implements
SatisfiedSelectBuilder<GroupedQueryBuilder> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedWhereBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedWhereBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedWhereBuilder.java
index d236ed2..83ec7a5 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedWhereBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/SatisfiedWhereBuilder.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.schema.Column;
public interface SatisfiedWhereBuilder<B extends SatisfiedQueryBuilder<?>>
extends SatisfiedQueryBuilder<B> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/TableFromBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/TableFromBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/TableFromBuilder.java
index d030653..a200989 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/TableFromBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/TableFromBuilder.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.schema.Table;
public interface TableFromBuilder extends
SatisfiedFromBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/TableFromBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/TableFromBuilderImpl.java b/core/src/main/java/org/apache/metamodel/query/builder/TableFromBuilderImpl.java
index 4460d8e..399fe38 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/TableFromBuilderImpl.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/TableFromBuilderImpl.java
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
import java.util.List;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.JoinType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.JoinType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.schema.Table;
final class TableFromBuilderImpl extends SatisfiedFromBuilderCallback implements
TableFromBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/WhereBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/WhereBuilder.java b/core/src/main/java/org/apache/metamodel/query/builder/WhereBuilder.java
index 3055214..2695142 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/WhereBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/WhereBuilder.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.QueryParameter;
+import org.apache.metamodel.query.CompiledQuery;
+import org.apache.metamodel.query.QueryParameter;
/**
* Builder interface for WHERE items.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/WhereBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/WhereBuilderImpl.java b/core/src/main/java/org/apache/metamodel/query/builder/WhereBuilderImpl.java
index 7e1db14..65f7a7e 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/WhereBuilderImpl.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/WhereBuilderImpl.java
@@ -16,17 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
import java.util.ArrayList;
import java.util.List;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.QueryParameter;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.QueryParameter;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
final class WhereBuilderImpl extends AbstractQueryFilterBuilder<SatisfiedWhereBuilder<GroupedQueryBuilder>> implements
WhereBuilder<GroupedQueryBuilder>, SatisfiedWhereBuilder<GroupedQueryBuilder> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/builder/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/builder/package-info.java b/core/src/main/java/org/apache/metamodel/query/builder/package-info.java
index 87e58db..091b703 100644
--- a/core/src/main/java/org/apache/metamodel/query/builder/package-info.java
+++ b/core/src/main/java/org/apache/metamodel/query/builder/package-info.java
@@ -19,5 +19,5 @@
/**
* API for query building
*/
-package org.eobjects.metamodel.query.builder;
+package org.apache.metamodel.query.builder;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/package-info.java b/core/src/main/java/org/apache/metamodel/query/package-info.java
index f71ce82..d840931 100644
--- a/core/src/main/java/org/apache/metamodel/query/package-info.java
+++ b/core/src/main/java/org/apache/metamodel/query/package-info.java
@@ -19,5 +19,5 @@
/**
* API for querying
*/
-package org.eobjects.metamodel.query;
+package org.apache.metamodel.query;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/parser/FromItemParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/FromItemParser.java b/core/src/main/java/org/apache/metamodel/query/parser/FromItemParser.java
index 78fff2e..76ff4f2 100644
--- a/core/src/main/java/org/apache/metamodel/query/parser/FromItemParser.java
+++ b/core/src/main/java/org/apache/metamodel/query/parser/FromItemParser.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.parser;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.JoinType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Table;
+package org.apache.metamodel.query.parser;
+
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.JoinType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Table;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/parser/GroupByItemParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/GroupByItemParser.java b/core/src/main/java/org/apache/metamodel/query/parser/GroupByItemParser.java
index fc7e776..c57b955 100644
--- a/core/src/main/java/org/apache/metamodel/query/parser/GroupByItemParser.java
+++ b/core/src/main/java/org/apache/metamodel/query/parser/GroupByItemParser.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.parser;
+package org.apache.metamodel.query.parser;
-import org.eobjects.metamodel.query.Query;
+import org.apache.metamodel.query.Query;
final class GroupByItemParser implements QueryPartProcessor {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/parser/HavingItemParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/HavingItemParser.java b/core/src/main/java/org/apache/metamodel/query/parser/HavingItemParser.java
index 5f4a559..314f97f 100644
--- a/core/src/main/java/org/apache/metamodel/query/parser/HavingItemParser.java
+++ b/core/src/main/java/org/apache/metamodel/query/parser/HavingItemParser.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.parser;
+package org.apache.metamodel.query.parser;
-import org.eobjects.metamodel.query.Query;
+import org.apache.metamodel.query.Query;
final class HavingItemParser implements QueryPartProcessor {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/parser/OrderByItemParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/OrderByItemParser.java b/core/src/main/java/org/apache/metamodel/query/parser/OrderByItemParser.java
index 8c3ebf0..e5dec1f 100644
--- a/core/src/main/java/org/apache/metamodel/query/parser/OrderByItemParser.java
+++ b/core/src/main/java/org/apache/metamodel/query/parser/OrderByItemParser.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.parser;
+package org.apache.metamodel.query.parser;
-import org.eobjects.metamodel.query.Query;
+import org.apache.metamodel.query.Query;
final class OrderByItemParser implements QueryPartProcessor {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/parser/QueryParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/QueryParser.java b/core/src/main/java/org/apache/metamodel/query/parser/QueryParser.java
index a5f0e03..19af3f8 100644
--- a/core/src/main/java/org/apache/metamodel/query/parser/QueryParser.java
+++ b/core/src/main/java/org/apache/metamodel/query/parser/QueryParser.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.parser;
+package org.apache.metamodel.query.parser;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.query.Query;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.query.Query;
/**
* A parser class of for full SQL-like queries.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/parser/QueryParserException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/QueryParserException.java b/core/src/main/java/org/apache/metamodel/query/parser/QueryParserException.java
index ad3f42c..4cfb459 100644
--- a/core/src/main/java/org/apache/metamodel/query/parser/QueryParserException.java
+++ b/core/src/main/java/org/apache/metamodel/query/parser/QueryParserException.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.parser;
+package org.apache.metamodel.query.parser;
-import org.eobjects.metamodel.MetaModelException;
+import org.apache.metamodel.MetaModelException;
/**
* Subtype of {@link MetaModelException} which indicate a problem in parsing a
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/parser/QueryPartCollectionProcessor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/QueryPartCollectionProcessor.java b/core/src/main/java/org/apache/metamodel/query/parser/QueryPartCollectionProcessor.java
index ac45a49..3c3f17d 100644
--- a/core/src/main/java/org/apache/metamodel/query/parser/QueryPartCollectionProcessor.java
+++ b/core/src/main/java/org/apache/metamodel/query/parser/QueryPartCollectionProcessor.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.parser;
+package org.apache.metamodel.query.parser;
import java.util.ArrayList;
import java.util.List;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/parser/QueryPartParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/QueryPartParser.java b/core/src/main/java/org/apache/metamodel/query/parser/QueryPartParser.java
index 15050ea..1751bbf 100644
--- a/core/src/main/java/org/apache/metamodel/query/parser/QueryPartParser.java
+++ b/core/src/main/java/org/apache/metamodel/query/parser/QueryPartParser.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.parser;
+package org.apache.metamodel.query.parser;
/**
* Parser of query parts. This parser is aware of parenthesis symbols '(' and
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/parser/QueryPartProcessor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/QueryPartProcessor.java b/core/src/main/java/org/apache/metamodel/query/parser/QueryPartProcessor.java
index 27a5d88..1057bde 100644
--- a/core/src/main/java/org/apache/metamodel/query/parser/QueryPartProcessor.java
+++ b/core/src/main/java/org/apache/metamodel/query/parser/QueryPartProcessor.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.parser;
+package org.apache.metamodel.query.parser;
/**
* Callback of the {@link QueryPartParser}, which recieves notifications
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/parser/SelectItemParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/SelectItemParser.java b/core/src/main/java/org/apache/metamodel/query/parser/SelectItemParser.java
index 2810a4a..16bb329 100644
--- a/core/src/main/java/org/apache/metamodel/query/parser/SelectItemParser.java
+++ b/core/src/main/java/org/apache/metamodel/query/parser/SelectItemParser.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.parser;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
+package org.apache.metamodel.query.parser;
+
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
public final class SelectItemParser implements QueryPartProcessor {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/query/parser/WhereItemParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/query/parser/WhereItemParser.java b/core/src/main/java/org/apache/metamodel/query/parser/WhereItemParser.java
index 764fbdc..112a2f7 100644
--- a/core/src/main/java/org/apache/metamodel/query/parser/WhereItemParser.java
+++ b/core/src/main/java/org/apache/metamodel/query/parser/WhereItemParser.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.parser;
+package org.apache.metamodel.query.parser;
-import org.eobjects.metamodel.query.Query;
+import org.apache.metamodel.query.Query;
final class WhereItemParser implements QueryPartProcessor {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/schema/AbstractColumn.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/AbstractColumn.java b/core/src/main/java/org/apache/metamodel/schema/AbstractColumn.java
index 85cc2e4..1805381 100644
--- a/core/src/main/java/org/apache/metamodel/schema/AbstractColumn.java
+++ b/core/src/main/java/org/apache/metamodel/schema/AbstractColumn.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
/**
* Abstract {@link Column} implementation. Implements most common and trivial
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 c1d5646..88dd54e 100644
--- a/core/src/main/java/org/apache/metamodel/schema/AbstractRelationship.java
+++ b/core/src/main/java/org/apache/metamodel/schema/AbstractRelationship.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.util.List;
-import org.eobjects.metamodel.util.BaseObject;
+import org.apache.metamodel.util.BaseObject;
public abstract class AbstractRelationship extends BaseObject implements
Relationship {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 79ccb09..9a5f93e 100644
--- a/core/src/main/java/org/apache/metamodel/schema/AbstractSchema.java
+++ b/core/src/main/java/org/apache/metamodel/schema/AbstractSchema.java
@@ -16,18 +16,18 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
-import org.eobjects.metamodel.util.Action;
-import org.eobjects.metamodel.util.CollectionUtils;
-import org.eobjects.metamodel.util.EqualsBuilder;
-import org.eobjects.metamodel.util.HasNameMapper;
-import org.eobjects.metamodel.util.Predicate;
+import org.apache.metamodel.util.Action;
+import org.apache.metamodel.util.CollectionUtils;
+import org.apache.metamodel.util.EqualsBuilder;
+import org.apache.metamodel.util.HasNameMapper;
+import org.apache.metamodel.util.Predicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 3728751..f355c2f 100644
--- a/core/src/main/java/org/apache/metamodel/schema/AbstractTable.java
+++ b/core/src/main/java/org/apache/metamodel/schema/AbstractTable.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.util.ArrayList;
import java.util.Arrays;
@@ -24,11 +24,11 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.util.Action;
-import org.eobjects.metamodel.util.CollectionUtils;
-import org.eobjects.metamodel.util.HasNameMapper;
-import org.eobjects.metamodel.util.Predicate;
+import org.apache.metamodel.MetaModelHelper;
+import org.apache.metamodel.util.Action;
+import org.apache.metamodel.util.CollectionUtils;
+import org.apache.metamodel.util.HasNameMapper;
+import org.apache.metamodel.util.Predicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/schema/Column.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/Column.java b/core/src/main/java/org/apache/metamodel/schema/Column.java
index 1208368..551a818 100644
--- a/core/src/main/java/org/apache/metamodel/schema/Column.java
+++ b/core/src/main/java/org/apache/metamodel/schema/Column.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.io.Serializable;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/schema/ColumnType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/ColumnType.java b/core/src/main/java/org/apache/metamodel/schema/ColumnType.java
index ea938e6..e367fb3 100644
--- a/core/src/main/java/org/apache/metamodel/schema/ColumnType.java
+++ b/core/src/main/java/org/apache/metamodel/schema/ColumnType.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
-import static org.eobjects.metamodel.schema.SuperColumnType.BINARY_TYPE;
-import static org.eobjects.metamodel.schema.SuperColumnType.BOOLEAN_TYPE;
-import static org.eobjects.metamodel.schema.SuperColumnType.LITERAL_TYPE;
-import static org.eobjects.metamodel.schema.SuperColumnType.NUMBER_TYPE;
-import static org.eobjects.metamodel.schema.SuperColumnType.OTHER_TYPE;
-import static org.eobjects.metamodel.schema.SuperColumnType.TIME_TYPE;
+import static org.apache.metamodel.schema.SuperColumnType.BINARY_TYPE;
+import static org.apache.metamodel.schema.SuperColumnType.BOOLEAN_TYPE;
+import static org.apache.metamodel.schema.SuperColumnType.LITERAL_TYPE;
+import static org.apache.metamodel.schema.SuperColumnType.NUMBER_TYPE;
+import static org.apache.metamodel.schema.SuperColumnType.OTHER_TYPE;
+import static org.apache.metamodel.schema.SuperColumnType.TIME_TYPE;
import java.lang.reflect.Field;
import java.math.BigDecimal;
@@ -38,10 +38,10 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
-import org.eobjects.metamodel.util.NumberComparator;
-import org.eobjects.metamodel.util.ObjectComparator;
-import org.eobjects.metamodel.util.TimeComparator;
-import org.eobjects.metamodel.util.ToStringComparator;
+import org.apache.metamodel.util.NumberComparator;
+import org.apache.metamodel.util.ObjectComparator;
+import org.apache.metamodel.util.TimeComparator;
+import org.apache.metamodel.util.ToStringComparator;
/**
* Represents the data-type of columns. Most of the elements in this enum are
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/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 f4f75e1..74f371c 100644
--- a/core/src/main/java/org/apache/metamodel/schema/CompositeSchema.java
+++ b/core/src/main/java/org/apache/metamodel/schema/CompositeSchema.java
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.util.CollectionUtils;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.util.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/schema/ImmutableColumn.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/ImmutableColumn.java b/core/src/main/java/org/apache/metamodel/schema/ImmutableColumn.java
index 3236c00..ad9c01c 100644
--- a/core/src/main/java/org/apache/metamodel/schema/ImmutableColumn.java
+++ b/core/src/main/java/org/apache/metamodel/schema/ImmutableColumn.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.io.Serializable;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/schema/ImmutableRelationship.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/ImmutableRelationship.java b/core/src/main/java/org/apache/metamodel/schema/ImmutableRelationship.java
index 43f2cf0..2bcf95b 100644
--- a/core/src/main/java/org/apache/metamodel/schema/ImmutableRelationship.java
+++ b/core/src/main/java/org/apache/metamodel/schema/ImmutableRelationship.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.io.Serializable;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/schema/ImmutableSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/ImmutableSchema.java b/core/src/main/java/org/apache/metamodel/schema/ImmutableSchema.java
index 8ac8a79..6958a0c 100644
--- a/core/src/main/java/org/apache/metamodel/schema/ImmutableSchema.java
+++ b/core/src/main/java/org/apache/metamodel/schema/ImmutableSchema.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.io.Serializable;
import java.util.ArrayList;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/schema/ImmutableTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/ImmutableTable.java b/core/src/main/java/org/apache/metamodel/schema/ImmutableTable.java
index a4d6d81..4fc470b 100644
--- a/core/src/main/java/org/apache/metamodel/schema/ImmutableTable.java
+++ b/core/src/main/java/org/apache/metamodel/schema/ImmutableTable.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.io.Serializable;
import java.util.ArrayList;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/schema/JdbcTypes.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/JdbcTypes.java b/core/src/main/java/org/apache/metamodel/schema/JdbcTypes.java
index 4531921..2ab39ab 100644
--- a/core/src/main/java/org/apache/metamodel/schema/JdbcTypes.java
+++ b/core/src/main/java/org/apache/metamodel/schema/JdbcTypes.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
/**
* This is a copy of the content (comments removed) of Java 6.0's
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/schema/MutableColumn.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/MutableColumn.java b/core/src/main/java/org/apache/metamodel/schema/MutableColumn.java
index d4c464d..6308d50 100644
--- a/core/src/main/java/org/apache/metamodel/schema/MutableColumn.java
+++ b/core/src/main/java/org/apache/metamodel/schema/MutableColumn.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.io.Serializable;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/schema/MutableRelationship.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/MutableRelationship.java b/core/src/main/java/org/apache/metamodel/schema/MutableRelationship.java
index 8762222..8464d42 100644
--- a/core/src/main/java/org/apache/metamodel/schema/MutableRelationship.java
+++ b/core/src/main/java/org/apache/metamodel/schema/MutableRelationship.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.io.Serializable;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/schema/MutableSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/MutableSchema.java b/core/src/main/java/org/apache/metamodel/schema/MutableSchema.java
index 71d05d2..c4cfe2e 100644
--- a/core/src/main/java/org/apache/metamodel/schema/MutableSchema.java
+++ b/core/src/main/java/org/apache/metamodel/schema/MutableSchema.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.io.Serializable;
import java.util.ArrayList;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/schema/MutableTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/MutableTable.java b/core/src/main/java/org/apache/metamodel/schema/MutableTable.java
index fb54377..39ad0b2 100644
--- a/core/src/main/java/org/apache/metamodel/schema/MutableTable.java
+++ b/core/src/main/java/org/apache/metamodel/schema/MutableTable.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.io.Serializable;
import java.util.ArrayList;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/schema/NamedStructure.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/NamedStructure.java b/core/src/main/java/org/apache/metamodel/schema/NamedStructure.java
index a5027d6..6f0602e 100644
--- a/core/src/main/java/org/apache/metamodel/schema/NamedStructure.java
+++ b/core/src/main/java/org/apache/metamodel/schema/NamedStructure.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
-import org.eobjects.metamodel.util.HasName;
+import org.apache.metamodel.util.HasName;
/**
* Super-interface for named structural types in a DataContext.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/schema/Relationship.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/Relationship.java b/core/src/main/java/org/apache/metamodel/schema/Relationship.java
index 00a63d9..71a1962 100644
--- a/core/src/main/java/org/apache/metamodel/schema/Relationship.java
+++ b/core/src/main/java/org/apache/metamodel/schema/Relationship.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.io.Serializable;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/schema/Schema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/Schema.java b/core/src/main/java/org/apache/metamodel/schema/Schema.java
index 6aa7183..dadb231 100644
--- a/core/src/main/java/org/apache/metamodel/schema/Schema.java
+++ b/core/src/main/java/org/apache/metamodel/schema/Schema.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.io.Serializable;
-import org.eobjects.metamodel.DataContext;
+import org.apache.metamodel.DataContext;
/**
* Represents a schema and it's metadata description. Schemas represent a
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/schema/SuperColumnType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/SuperColumnType.java b/core/src/main/java/org/apache/metamodel/schema/SuperColumnType.java
index d6545bc..bf21788 100644
--- a/core/src/main/java/org/apache/metamodel/schema/SuperColumnType.java
+++ b/core/src/main/java/org/apache/metamodel/schema/SuperColumnType.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.util.Date;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/schema/Table.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/Table.java b/core/src/main/java/org/apache/metamodel/schema/Table.java
index bc9043c..d69c6bc 100644
--- a/core/src/main/java/org/apache/metamodel/schema/Table.java
+++ b/core/src/main/java/org/apache/metamodel/schema/Table.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.io.Serializable;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/schema/TableType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/TableType.java b/core/src/main/java/org/apache/metamodel/schema/TableType.java
index 51b7361..d4f15dd 100644
--- a/core/src/main/java/org/apache/metamodel/schema/TableType.java
+++ b/core/src/main/java/org/apache/metamodel/schema/TableType.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
/**
* Represents the various types of tables
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/schema/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/package-info.java b/core/src/main/java/org/apache/metamodel/schema/package-info.java
index 87d991f..43338ec 100644
--- a/core/src/main/java/org/apache/metamodel/schema/package-info.java
+++ b/core/src/main/java/org/apache/metamodel/schema/package-info.java
@@ -19,5 +19,5 @@
/**
* API for schema structure
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/update/AbstractRowUpdationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/update/AbstractRowUpdationBuilder.java b/core/src/main/java/org/apache/metamodel/update/AbstractRowUpdationBuilder.java
index fd4341c..1a97e3f 100644
--- a/core/src/main/java/org/apache/metamodel/update/AbstractRowUpdationBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/update/AbstractRowUpdationBuilder.java
@@ -16,19 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.update;
+package org.apache.metamodel.update;
import java.util.ArrayList;
import java.util.List;
-import org.eobjects.metamodel.data.AbstractRowBuilder;
-import org.eobjects.metamodel.query.FilterClause;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.query.builder.AbstractFilterBuilder;
-import org.eobjects.metamodel.query.builder.FilterBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.data.AbstractRowBuilder;
+import org.apache.metamodel.query.FilterClause;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.query.builder.AbstractFilterBuilder;
+import org.apache.metamodel.query.builder.FilterBuilder;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
/**
* Abstract {@link RowUpdationBuilder} implementation.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/update/RowUpdateable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/update/RowUpdateable.java b/core/src/main/java/org/apache/metamodel/update/RowUpdateable.java
index 8e42517..2c204fb 100644
--- a/core/src/main/java/org/apache/metamodel/update/RowUpdateable.java
+++ b/core/src/main/java/org/apache/metamodel/update/RowUpdateable.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.update;
+package org.apache.metamodel.update;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.schema.Table;
public interface RowUpdateable {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/update/RowUpdationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/update/RowUpdationBuilder.java b/core/src/main/java/org/apache/metamodel/update/RowUpdationBuilder.java
index 500d066..989537e 100644
--- a/core/src/main/java/org/apache/metamodel/update/RowUpdationBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/update/RowUpdationBuilder.java
@@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.update;
+package org.apache.metamodel.update;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.RowBuilder;
-import org.eobjects.metamodel.data.WhereClauseBuilder;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.data.RowBuilder;
+import org.apache.metamodel.data.WhereClauseBuilder;
+import org.apache.metamodel.schema.Table;
/**
* Builder object for row update on a {@link Table}.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/update/Update.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/update/Update.java b/core/src/main/java/org/apache/metamodel/update/Update.java
index 540dc3c..dc3c813 100644
--- a/core/src/main/java/org/apache/metamodel/update/Update.java
+++ b/core/src/main/java/org/apache/metamodel/update/Update.java
@@ -16,24 +16,24 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.update;
+package org.apache.metamodel.update;
import java.util.ArrayList;
import java.util.List;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.AbstractRowBuilder;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.data.WhereClauseBuilder;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.query.builder.AbstractFilterBuilder;
-import org.eobjects.metamodel.query.builder.FilterBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.UpdateableDataContext;
+import org.apache.metamodel.data.AbstractRowBuilder;
+import org.apache.metamodel.data.Style;
+import org.apache.metamodel.data.WhereClauseBuilder;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.query.builder.AbstractFilterBuilder;
+import org.apache.metamodel.query.builder.FilterBuilder;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
/**
* Represents a single UPDATE operation to be applied to a
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/update/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/update/package-info.java b/core/src/main/java/org/apache/metamodel/update/package-info.java
index 4b03ca5..afaffed 100644
--- a/core/src/main/java/org/apache/metamodel/update/package-info.java
+++ b/core/src/main/java/org/apache/metamodel/update/package-info.java
@@ -19,5 +19,5 @@
/**
* API for updating rows
*/
-package org.eobjects.metamodel.update;
+package org.apache.metamodel.update;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/Action.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/Action.java b/core/src/main/java/org/apache/metamodel/util/Action.java
index 2d79054..bc53c6b 100644
--- a/core/src/main/java/org/apache/metamodel/util/Action.java
+++ b/core/src/main/java/org/apache/metamodel/util/Action.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
/**
* Represents an abstract action, which is an executable piece of functionality
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/AggregateBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/AggregateBuilder.java b/core/src/main/java/org/apache/metamodel/util/AggregateBuilder.java
index 3663959..477c2d4 100644
--- a/core/src/main/java/org/apache/metamodel/util/AggregateBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/util/AggregateBuilder.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
/**
* Interface for aggregate builders which allows for an iterative approach to
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/AlphabeticSequence.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/AlphabeticSequence.java b/core/src/main/java/org/apache/metamodel/util/AlphabeticSequence.java
index 5f578f6..17b25ba 100644
--- a/core/src/main/java/org/apache/metamodel/util/AlphabeticSequence.java
+++ b/core/src/main/java/org/apache/metamodel/util/AlphabeticSequence.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
/**
* A sequence based on alphabetic representations. Typically a sequence begin
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/BaseObject.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/BaseObject.java b/core/src/main/java/org/apache/metamodel/util/BaseObject.java
index dde30da..0d08b88 100644
--- a/core/src/main/java/org/apache/metamodel/util/BaseObject.java
+++ b/core/src/main/java/org/apache/metamodel/util/BaseObject.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.lang.reflect.Array;
import java.util.ArrayList;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/BooleanComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/BooleanComparator.java b/core/src/main/java/org/apache/metamodel/util/BooleanComparator.java
index 22bc9f1..ac542f7 100644
--- a/core/src/main/java/org/apache/metamodel/util/BooleanComparator.java
+++ b/core/src/main/java/org/apache/metamodel/util/BooleanComparator.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.util.Comparator;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/ClasspathResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/ClasspathResource.java b/core/src/main/java/org/apache/metamodel/util/ClasspathResource.java
index e38b372..a205886 100644
--- a/core/src/main/java/org/apache/metamodel/util/ClasspathResource.java
+++ b/core/src/main/java/org/apache/metamodel/util/ClasspathResource.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.io.InputStream;
import java.io.OutputStream;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/CollectionUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/CollectionUtils.java b/core/src/main/java/org/apache/metamodel/util/CollectionUtils.java
index 52cff9a..8e22f17 100644
--- a/core/src/main/java/org/apache/metamodel/util/CollectionUtils.java
+++ b/core/src/main/java/org/apache/metamodel/util/CollectionUtils.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.lang.reflect.Array;
import java.util.ArrayList;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/ConstantFunc.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/ConstantFunc.java b/core/src/main/java/org/apache/metamodel/util/ConstantFunc.java
index 0f071e5..9a48516 100644
--- a/core/src/main/java/org/apache/metamodel/util/ConstantFunc.java
+++ b/core/src/main/java/org/apache/metamodel/util/ConstantFunc.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
/**
* A function that always returns the same constant response.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/DateUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/DateUtils.java b/core/src/main/java/org/apache/metamodel/util/DateUtils.java
index b146523..31af2f9 100644
--- a/core/src/main/java/org/apache/metamodel/util/DateUtils.java
+++ b/core/src/main/java/org/apache/metamodel/util/DateUtils.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/EqualsBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/EqualsBuilder.java b/core/src/main/java/org/apache/metamodel/util/EqualsBuilder.java
index b02b6df..3f6401c 100644
--- a/core/src/main/java/org/apache/metamodel/util/EqualsBuilder.java
+++ b/core/src/main/java/org/apache/metamodel/util/EqualsBuilder.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.lang.reflect.Array;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/main/java/org/apache/metamodel/util/ExclusionPredicate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/ExclusionPredicate.java b/core/src/main/java/org/apache/metamodel/util/ExclusionPredicate.java
index 78744bc..aec67c6 100644
--- a/core/src/main/java/org/apache/metamodel/util/ExclusionPredicate.java
+++ b/core/src/main/java/org/apache/metamodel/util/ExclusionPredicate.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.util.Collection;
import java.util.Collections;
[04/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/MysqlQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/MysqlQueryRewriter.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/MysqlQueryRewriter.java
deleted file mode 100644
index 88757be..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/MysqlQueryRewriter.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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.jdbc.dialects;
-
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-
-/**
- * Query rewriter for MySQL
- */
-public class MysqlQueryRewriter extends LimitOffsetQueryRewriter implements IQueryRewriter {
-
- public MysqlQueryRewriter(JdbcDataContext dataContext) {
- super(dataContext);
- }
-
- @Override
- public String escapeQuotes(String filterItemOperand) {
- return filterItemOperand.replaceAll("\\'", "\\\\'");
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/PostgresqlQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/PostgresqlQueryRewriter.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/PostgresqlQueryRewriter.java
deleted file mode 100644
index d303c50..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/PostgresqlQueryRewriter.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * 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.jdbc.dialects;
-
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * Query rewriter for PostgreSQL
- */
-public class PostgresqlQueryRewriter extends LimitOffsetQueryRewriter implements IQueryRewriter {
-
- public PostgresqlQueryRewriter(JdbcDataContext dataContext) {
- super(dataContext);
- }
-
- @Override
- public ColumnType getColumnType(int jdbcType, String nativeType, Integer columnSize) {
- if ("bool".equals(nativeType)) {
- // override the normal behaviour of postgresql which maps "bool" to
- // a BIT.
- return ColumnType.BOOLEAN;
- }
- return super.getColumnType(jdbcType, nativeType, columnSize);
- }
-
- @Override
- public String rewriteColumnType(ColumnType columnType) {
- if (columnType == ColumnType.BLOB) {
- return "bytea";
- }
- return super.rewriteColumnType(columnType);
- }
-
- @Override
- protected String rewriteFromItem(Query query, FromItem item) {
- String result = super.rewriteFromItem(query, item);
- Table table = item.getTable();
- if (table != null) {
- Schema schema = table.getSchema();
- if (schema != null) {
- String schemaName = schema.getName();
- if (schemaName != null) {
- result = result.replaceFirst(schemaName, '\"' + schema.getName() + '\"');
- }
- }
- }
- return result;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/SQLServerQueryRewriter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/SQLServerQueryRewriter.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/SQLServerQueryRewriter.java
deleted file mode 100644
index 732ec34..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/dialects/SQLServerQueryRewriter.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * 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.jdbc.dialects;
-
-import org.eobjects.metamodel.jdbc.JdbcDataContext;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectClause;
-
-public class SQLServerQueryRewriter extends DefaultQueryRewriter {
-
- public SQLServerQueryRewriter(JdbcDataContext dataContext) {
- super(dataContext);
- }
-
- @Override
- public boolean isMaxRowsSupported() {
- return true;
- }
-
- /**
- * SQL server expects the fully qualified column name, including schema, in
- * select items.
- */
- @Override
- public boolean isSchemaIncludedInColumnPaths() {
- return true;
- }
-
- @Override
- protected String rewriteSelectClause(Query query, SelectClause selectClause) {
- String result = super.rewriteSelectClause(query, selectClause);
-
- Integer maxRows = query.getMaxRows();
- if (maxRows != null) {
- result = "SELECT TOP " + maxRows + " " + result.substring(7);
- }
-
- return result;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/package-info.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/package-info.java b/jdbc/src/main/java/org/eobjects/metamodel/jdbc/package-info.java
deleted file mode 100644
index b7a311b..0000000
--- a/jdbc/src/main/java/org/eobjects/metamodel/jdbc/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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.
- */
-/**
- * Module package for JDBC compliant databases
- */
-package org.eobjects.metamodel.jdbc;
-
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/test/integrationtests/org/apache/metamodel/DB2Test.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/apache/metamodel/DB2Test.java b/jdbc/src/test/integrationtests/org/apache/metamodel/DB2Test.java
new file mode 100644
index 0000000..13cc501
--- /dev/null
+++ b/jdbc/src/test/integrationtests/org/apache/metamodel/DB2Test.java
@@ -0,0 +1,107 @@
+package org.eobjects.metamodel;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.jdbc.JdbcDataContext;
+import org.eobjects.metamodel.jdbc.JdbcTestTemplates;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * DB2 integration test. This is a read-only integration test, meant to be
+ * modified for whatever server is available (even within Human Inference).
+ */
+public class DB2Test extends TestCase {
+
+ private static final String URL = "jdbc:db2://TODO:50000/TODO";
+
+ private static final String USERNAME = "TODO";
+ private static final String PASSWORD = "TODO";
+ private Connection _connection;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ Class.forName("com.ibm.db2.jcc.DB2Driver");
+ _connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ _connection.close();
+ }
+
+
+ public void testInterpretationOfNull() throws Exception {
+ JdbcTestTemplates.interpretationOfNulls(_connection);
+ }
+
+ public void testDefaultSchema() throws Exception {
+ JdbcDataContext dc = new JdbcDataContext(_connection);
+ Schema schema = dc.getDefaultSchema();
+ assertEquals(USERNAME.toUpperCase(), schema.getName());
+
+ Table countryTable = schema.getTableByName("COUNTRY");
+ assertNotNull(countryTable);
+
+ DataSet ds = dc.query().from(countryTable).selectCount().execute();
+ assertTrue(ds.next());
+ assertEquals("Row[values=[1008]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ ds.close();
+ }
+
+ public void testMaxRowsOnly() throws Exception {
+ JdbcDataContext dc = new JdbcDataContext(_connection);
+ Schema schema = dc.getDefaultSchema();
+ String[] tableNames = schema.getTableNames();
+ System.out.println("Tables: " + Arrays.toString(tableNames));
+
+ Table countryTable = schema.getTableByName("COUNTRY");
+ assertNotNull(countryTable);
+
+ Query query = dc.query().from(countryTable).select("COUNTRYCODE").limit(200).toQuery();
+ assertEquals("SELECT DB2INST1.\"COUNTRY\".\"COUNTRYCODE\" FROM DB2INST1.\"COUNTRY\" "
+ + "FETCH FIRST 200 ROWS ONLY", dc.getQueryRewriter().rewriteQuery(query));
+
+ DataSet ds = dc.executeQuery(query);
+ for (int i = 0; i < 200; i++) {
+ assertTrue(ds.next());
+ assertEquals(1, ds.getRow().getValues().length);
+ }
+ assertFalse(ds.next());
+ ds.close();
+ }
+
+ public void testMaxRowsAndOffset() throws Exception {
+ JdbcDataContext dc = new JdbcDataContext(_connection);
+ Schema schema = dc.getDefaultSchema();
+ String[] tableNames = schema.getTableNames();
+ System.out.println("Tables: " + Arrays.toString(tableNames));
+
+ Table countryTable = schema.getTableByName("COUNTRY");
+ assertNotNull(countryTable);
+
+ Query query = dc.query().from(countryTable).select("COUNTRYCODE").limit(200).offset(200).toQuery();
+ assertEquals(
+ "SELECT metamodel_subquery.\"COUNTRYCODE\" FROM ("
+ + "SELECT DB2INST1.\"COUNTRY\".\"COUNTRYCODE\", ROW_NUMBER() OVER() AS metamodel_row_number FROM DB2INST1.\"COUNTRY\""
+ + ") metamodel_subquery WHERE metamodel_row_number BETWEEN 201 AND 400", dc.getQueryRewriter()
+ .rewriteQuery(query));
+
+ DataSet ds = dc.executeQuery(query);
+ for (int i = 0; i < 200; i++) {
+ assertTrue(ds.next());
+ assertEquals(1, ds.getRow().getValues().length);
+ }
+ assertFalse(ds.next());
+ ds.close();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/test/integrationtests/org/apache/metamodel/FirebirdTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/apache/metamodel/FirebirdTest.java b/jdbc/src/test/integrationtests/org/apache/metamodel/FirebirdTest.java
new file mode 100644
index 0000000..ec1ba32
--- /dev/null
+++ b/jdbc/src/test/integrationtests/org/apache/metamodel/FirebirdTest.java
@@ -0,0 +1,115 @@
+package org.eobjects.metamodel;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Date;
+
+import javax.swing.table.TableModel;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.DataSetTableModel;
+import org.eobjects.metamodel.jdbc.JdbcDataContext;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.JoinType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+
+/**
+ * Integrationtests for Firebird SQL.
+ *
+ * This test uses the "employee" sampledata shipped with Firebird. The JDBC
+ * driver ("jaybird") is not available in the Maven repository so you will have
+ * to download and attach it to the eclipse project yourself.
+ *
+ * @see http://www.firebirdsql.org/manual/qsg10-connecting.html
+ * @see http://www.firebirdsql.org/index.php?op=files&id=jaybird
+ */
+public class FirebirdTest extends TestCase {
+
+ private static final String CONNECTION_STRING = "jdbc:firebirdsql:127.0.0.1:employee.fdb";
+ private static final String USERNAME = "SYSDBA";
+ private static final String PASSWORD = "eobjects";
+ private Connection _connection;
+ private DataContext _dataContext;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ Class.forName("org.firebirdsql.jdbc.FBDriver");
+ _connection = DriverManager.getConnection(CONNECTION_STRING, USERNAME, PASSWORD);
+ _connection.setReadOnly(true);
+ _dataContext = new JdbcDataContext(_connection);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ _connection.close();
+ }
+
+ public void testGetSchemas() throws Exception {
+ Schema[] schemas = _dataContext.getSchemas();
+ assertEquals(1, schemas.length);
+ Schema schema = _dataContext.getDefaultSchema();
+ assertEquals("{JdbcTable[name=COUNTRY,type=TABLE,remarks=<null>],"
+ + "JdbcTable[name=CUSTOMER,type=TABLE,remarks=<null>],"
+ + "JdbcTable[name=DEPARTMENT,type=TABLE,remarks=<null>],"
+ + "JdbcTable[name=EMPLOYEE,type=TABLE,remarks=<null>],"
+ + "JdbcTable[name=EMPLOYEE_PROJECT,type=TABLE,remarks=<null>],"
+ + "JdbcTable[name=JOB,type=TABLE,remarks=<null>],"
+ + "JdbcTable[name=PHONE_LIST,type=VIEW,remarks=<null>],"
+ + "JdbcTable[name=PROJECT,type=TABLE,remarks=<null>],"
+ + "JdbcTable[name=PROJ_DEPT_BUDGET,type=TABLE,remarks=<null>],"
+ + "JdbcTable[name=SALARY_HISTORY,type=TABLE,remarks=<null>],"
+ + "JdbcTable[name=SALES,type=TABLE,remarks=<null>]}", Arrays.toString(schema.getTables()));
+
+ assertEquals(
+ "{Relationship[primaryTable=COUNTRY,primaryColumns={COUNTRY},foreignTable=CUSTOMER,foreignColumns={COUNTRY}],"
+ + "Relationship[primaryTable=COUNTRY,primaryColumns={COUNTRY},foreignTable=JOB,foreignColumns={JOB_COUNTRY}],"
+ + "Relationship[primaryTable=CUSTOMER,primaryColumns={CUST_NO},foreignTable=SALES,foreignColumns={CUST_NO}],"
+ + "Relationship[primaryTable=DEPARTMENT,primaryColumns={DEPT_NO},foreignTable=DEPARTMENT,foreignColumns={HEAD_DEPT}],"
+ + "Relationship[primaryTable=DEPARTMENT,primaryColumns={DEPT_NO},foreignTable=EMPLOYEE,foreignColumns={DEPT_NO}],"
+ + "Relationship[primaryTable=DEPARTMENT,primaryColumns={DEPT_NO},foreignTable=PROJ_DEPT_BUDGET,foreignColumns={DEPT_NO}],"
+ + "Relationship[primaryTable=EMPLOYEE,primaryColumns={EMP_NO},foreignTable=DEPARTMENT,foreignColumns={MNGR_NO}],"
+ + "Relationship[primaryTable=EMPLOYEE,primaryColumns={EMP_NO},foreignTable=EMPLOYEE_PROJECT,foreignColumns={EMP_NO}],"
+ + "Relationship[primaryTable=EMPLOYEE,primaryColumns={EMP_NO},foreignTable=PROJECT,foreignColumns={TEAM_LEADER}],"
+ + "Relationship[primaryTable=EMPLOYEE,primaryColumns={EMP_NO},foreignTable=SALARY_HISTORY,foreignColumns={EMP_NO}],"
+ + "Relationship[primaryTable=EMPLOYEE,primaryColumns={EMP_NO},foreignTable=SALES,foreignColumns={SALES_REP}],"
+ + "Relationship[primaryTable=JOB,primaryColumns={JOB_CODE},foreignTable=EMPLOYEE,foreignColumns={JOB_CODE}],"
+ + "Relationship[primaryTable=JOB,primaryColumns={JOB_GRADE},foreignTable=EMPLOYEE,foreignColumns={JOB_GRADE}],"
+ + "Relationship[primaryTable=JOB,primaryColumns={JOB_COUNTRY},foreignTable=EMPLOYEE,foreignColumns={JOB_COUNTRY}],"
+ + "Relationship[primaryTable=PROJECT,primaryColumns={PROJ_ID},foreignTable=EMPLOYEE_PROJECT,foreignColumns={PROJ_ID}],"
+ + "Relationship[primaryTable=PROJECT,primaryColumns={PROJ_ID},foreignTable=PROJ_DEPT_BUDGET,foreignColumns={PROJ_ID}]}",
+ Arrays.toString(schema.getRelationships()));
+ }
+
+ public void testExecuteQuery() throws Exception {
+ Schema schema = _dataContext.getDefaultSchema();
+ Table departmentTable = schema.getTableByName("DEPARTMENT");
+ Table employeeTable = schema.getTableByName("EMPLOYEE");
+ Query q = new Query().from(new FromItem(JoinType.INNER, departmentTable.getRelationships(employeeTable)[0]));
+ q.select(departmentTable.getColumns()[1]);
+ q.select(new SelectItem(employeeTable.getColumns()[4]).setAlias("hire-date"));
+ assertEquals(
+ "SELECT \"DEPARTMENT\".\"DEPARTMENT\", \"EMPLOYEE\".\"HIRE_DATE\" AS hire-date FROM \"EMPLOYEE\" INNER JOIN \"DEPARTMENT\" ON \"EMPLOYEE\".\"EMP_NO\" = \"DEPARTMENT\".\"MNGR_NO\"",
+ q.toString());
+
+ DataSet data = _dataContext.executeQuery(q);
+ assertNotNull(data);
+
+ TableModel tableModel = new DataSetTableModel(data);
+ assertEquals(2, tableModel.getColumnCount());
+ assertEquals(17, tableModel.getRowCount());
+ assertEquals("Quality Assurance", tableModel.getValueAt(4, 0).toString());
+
+ Date date = (Date) tableModel.getValueAt(4, 1);
+ assertEquals("1989-04-17 00:00:00.000000", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS").format(date));
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/test/integrationtests/org/apache/metamodel/MysqlTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/apache/metamodel/MysqlTest.java b/jdbc/src/test/integrationtests/org/apache/metamodel/MysqlTest.java
new file mode 100644
index 0000000..4bd814d
--- /dev/null
+++ b/jdbc/src/test/integrationtests/org/apache/metamodel/MysqlTest.java
@@ -0,0 +1,334 @@
+package org.eobjects.metamodel;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.swing.table.TableModel;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.DataSetTableModel;
+import org.eobjects.metamodel.jdbc.JdbcDataContext;
+import org.eobjects.metamodel.jdbc.JdbcTestTemplates;
+import org.eobjects.metamodel.jdbc.QuerySplitter;
+import org.eobjects.metamodel.jdbc.dialects.MysqlQueryRewriter;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.OperatorType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.schema.TableType;
+
+/**
+ * Test case that tests mysql interaction. The test requires the "sakila" sample
+ * database that can be found at dev.mysql.com.
+ *
+ * @see http://dev.mysql.com/doc/sakila/en/sakila.html#sakila-installation
+ */
+public class MysqlTest extends TestCase {
+
+ private static final String CONNECTION_STRING = "jdbc:mysql://localhost/sakila?defaultFetchSize=" + Integer.MIN_VALUE;
+ private static final String USERNAME = "eobjects";
+ private static final String PASSWORD = "eobjects";
+ private Connection _connection;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ Class.forName("com.mysql.jdbc.Driver");
+ _connection = DriverManager.getConnection(CONNECTION_STRING, USERNAME, PASSWORD);
+ }
+
+ public void testInterpretationOfNull() throws Exception {
+ JdbcTestTemplates.interpretationOfNulls(_connection);
+ }
+
+ public void testDatabaseProductName() throws Exception {
+ String databaseProductName = _connection.getMetaData().getDatabaseProductName();
+ assertEquals(JdbcDataContext.DATABASE_PRODUCT_MYSQL, databaseProductName);
+ }
+
+ public void testAutomaticConversionWhenInsertingString() throws Exception {
+ assertNotNull(_connection);
+
+ Statement st = _connection.createStatement();
+ try {
+ // clean up, if nescesary
+ st.execute("DROP TABLE test_table");
+ st.close();
+ } catch (SQLException e) {
+ // do nothing
+ }
+
+ assertFalse(_connection.isReadOnly());
+
+ JdbcDataContext dc = new JdbcDataContext(_connection);
+ final Schema schema = dc.getDefaultSchema();
+ assertEquals("sakila", schema.getName());
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback cb) {
+ Table table = cb.createTable(schema, "test_table").withColumn("id").ofType(ColumnType.INTEGER)
+ .asPrimaryKey().withColumn("birthdate").ofType(ColumnType.DATE).execute();
+
+ cb.insertInto(table).value("id", "1").execute();
+ cb.insertInto(table).value("id", 2).value("birthdate", "2011-12-21").execute();
+ }
+ });
+
+ assertTrue(dc.getColumnByQualifiedLabel("test_table.id").isPrimaryKey());
+ assertFalse(dc.getColumnByQualifiedLabel("test_table.birthdate").isPrimaryKey());
+
+ DataSet ds = dc.query().from("test_table").select("id").and("birthdate").execute();
+ assertTrue(ds.next());
+ assertEquals("Row[values=[1, null]]", ds.getRow().toString());
+ assertEquals("java.lang.Integer", ds.getRow().getValue(0).getClass().getName());
+ assertTrue(ds.next());
+ assertEquals("Row[values=[2, 2011-12-21]]", ds.getRow().toString());
+ assertEquals("java.sql.Date", ds.getRow().getValue(1).getClass().getName());
+ assertFalse(ds.next());
+ ds.close();
+
+ dc.executeUpdate(new UpdateScript() {
+ @Override
+ public void run(UpdateCallback callback) {
+ callback.dropTable("test_table").execute();
+ }
+ });
+ }
+
+ public void testCharOfSizeOne() throws Exception {
+ JdbcTestTemplates.meaningOfOneSizeChar(_connection);
+ }
+
+ public void testAlternativeConnectionString() throws Exception {
+ _connection = DriverManager.getConnection("jdbc:mysql://localhost", USERNAME, PASSWORD);
+ DataContext dc = new JdbcDataContext(_connection, TableType.DEFAULT_TABLE_TYPES, "sakila");
+ Schema[] schemas = dc.getSchemas();
+ assertEquals("[Schema[name=mysql], Schema[name=performance_schema], Schema[name=portal], "
+ + "Schema[name=sakila], Schema[name=world]]", Arrays.toString(schemas));
+
+ Table table = dc.getSchemaByName("sakila").getTableByName("film");
+ Query q = new Query().from(table).select(table.getColumns());
+ DataSet data = dc.executeQuery(q);
+ TableModel tableModel = new DataSetTableModel(data);
+ assertEquals(13, tableModel.getColumnCount());
+ assertEquals(1000, tableModel.getRowCount());
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ _connection.close();
+ }
+
+ public void testGetCatalogNames() throws Exception {
+ JdbcDataContext strategy = new JdbcDataContext(_connection);
+ assertTrue(strategy.getQueryRewriter() instanceof MysqlQueryRewriter);
+ String[] catalogNames = strategy.getCatalogNames();
+ assertEquals("[information_schema, mysql, performance_schema, portal, sakila, world]",
+ Arrays.toString(catalogNames));
+ }
+
+ public void testGetDefaultSchema() throws Exception {
+ DataContext dc = new JdbcDataContext(_connection);
+ Schema schema = dc.getDefaultSchema();
+ assertEquals("sakila", schema.getName());
+ }
+
+ public void testExecuteQuery() throws Exception {
+ DataContext dc = new JdbcDataContext(_connection);
+ Schema schema = dc.getDefaultSchema();
+ Table actorTable = schema.getTableByName("actor");
+ assertEquals(
+ "[Column[name=actor_id,columnNumber=0,type=SMALLINT,nullable=false,nativeType=SMALLINT UNSIGNED,columnSize=5], Column[name=first_name,columnNumber=1,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=45], Column[name=last_name,columnNumber=2,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=45], Column[name=last_update,columnNumber=3,type=TIMESTAMP,nullable=false,nativeType=TIMESTAMP,columnSize=19]]",
+ Arrays.toString(actorTable.getColumns()));
+ Table filmTable = schema.getTableByName("film");
+ assertEquals(
+ "[Column[name=film_id,columnNumber=0,type=SMALLINT,nullable=false,nativeType=SMALLINT UNSIGNED,columnSize=5], Column[name=title,columnNumber=1,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=255], Column[name=description,columnNumber=2,type=LONGVARCHAR,nullable=true,nativeType=TEXT,columnSize=65535], Column[name=release_year,columnNumber=3,type=DATE,nullable=true,nativeType=YEAR,columnSize=0], Column[name=language_id,columnNumber=4,type=TINYINT,nullable=false,nativeType=TINYINT UNSIGNED,columnSize=3], Column[name=original_language_id,columnNumber=5,type=TINYINT,nullable=true,nativeType=TINYINT UNSIGNED,columnSize=3], Column[name=rental_duration,columnNumber=6,type=TINYINT,nullable=false,nativeType=TINYINT UNSIGNED,columnSize=3], Column[name=rental_rate,columnNumber=7,type=DECIMAL,nullable=false,nativeType=DECIMAL,columnSize=4], Column[name=length,columnNumber=8,type=SMALLINT,nullable=true,nativeType=SMALLINT UNSIGNED,columnSize=5], Column[name=replacement_cost,columnNu
mber=9,type=DECIMAL,nullable=false,nativeType=DECIMAL,columnSize=5], Column[name=rating,columnNumber=10,type=CHAR,nullable=true,nativeType=ENUM,columnSize=5], Column[name=special_features,columnNumber=11,type=CHAR,nullable=true,nativeType=SET,columnSize=54], Column[name=last_update,columnNumber=12,type=TIMESTAMP,nullable=false,nativeType=TIMESTAMP,columnSize=19]]",
+ Arrays.toString(filmTable.getColumns()));
+ Table filmActorJoinTable = schema.getTableByName("film_actor");
+ assertEquals(
+ "[Column[name=actor_id,columnNumber=0,type=SMALLINT,nullable=false,nativeType=SMALLINT UNSIGNED,columnSize=5], "
+ + "Column[name=film_id,columnNumber=1,type=SMALLINT,nullable=false,nativeType=SMALLINT UNSIGNED,columnSize=5], "
+ + "Column[name=last_update,columnNumber=2,type=TIMESTAMP,nullable=false,nativeType=TIMESTAMP,columnSize=19]]",
+ Arrays.toString(filmActorJoinTable.getColumns()));
+
+ Query q = new Query();
+ q.from(new FromItem(actorTable).setAlias("a"));
+ q.select(actorTable.getColumns());
+ q.getSelectClause().getItem(0).setAlias("foo-bar");
+ assertEquals(
+ "SELECT a.`actor_id` AS foo-bar, a.`first_name`, a.`last_name`, a.`last_update` FROM sakila.`actor` a",
+ q.toString());
+ FilterItem f1 = new FilterItem(q.getSelectClause().getItem(0), OperatorType.EQUALS_TO, 5);
+ FilterItem f2 = new FilterItem(q.getSelectClause().getItem(0), OperatorType.EQUALS_TO, 8);
+ q.where(new FilterItem(f1, f2));
+
+ DataSet dataSet = dc.executeQuery(q);
+ TableModel tableModel = new DataSetTableModel(dataSet);
+ assertEquals(4, tableModel.getColumnCount());
+ assertEquals(2, tableModel.getRowCount());
+ assertEquals("LOLLOBRIGIDA", tableModel.getValueAt(0, 2));
+
+ q.setMaxRows(1);
+ dataSet = dc.executeQuery(q);
+ tableModel = new DataSetTableModel(dataSet);
+ assertEquals(4, tableModel.getColumnCount());
+ assertEquals(1, tableModel.getRowCount());
+ assertEquals("LOLLOBRIGIDA", tableModel.getValueAt(0, 2));
+
+ q.setMaxRows(1);
+ q.setFirstRow(2);
+ dataSet = dc.executeQuery(q);
+ tableModel = new DataSetTableModel(dataSet);
+ assertEquals(4, tableModel.getColumnCount());
+ assertEquals(1, tableModel.getRowCount());
+ assertEquals("JOHANSSON", tableModel.getValueAt(0, 2));
+
+ q.getWhereClause().removeItems();
+ q.setMaxRows(25);
+ q.setFirstRow(1);
+ dataSet = dc.executeQuery(q);
+ tableModel = new DataSetTableModel(dataSet);
+ assertEquals(4, tableModel.getColumnCount());
+ assertEquals(25, tableModel.getRowCount());
+ assertEquals("GUINESS", tableModel.getValueAt(0, 2).toString());
+ }
+
+ // Test to query the film table (caused troubles in DataCleaner)
+ public void testFilmQuery() throws Exception {
+ DataContext dc = new JdbcDataContext(_connection);
+ Table table = dc.getDefaultSchema().getTableByName("film");
+ Query q = new Query().select(table.getColumns()).from(table).setMaxRows(400);
+ dc.executeQuery(q);
+ }
+
+ public void testGetSchema() throws Exception {
+ DataContext dc = new JdbcDataContext(_connection);
+ Schema[] schemas = dc.getSchemas();
+ assertEquals(5, schemas.length);
+ Schema schema = dc.getDefaultSchema();
+
+ assertEquals("[Table[name=actor,type=TABLE,remarks=], " + "Table[name=address,type=TABLE,remarks=], "
+ + "Table[name=category,type=TABLE,remarks=], " + "Table[name=city,type=TABLE,remarks=], "
+ + "Table[name=country,type=TABLE,remarks=], " + "Table[name=customer,type=TABLE,remarks=], "
+ + "Table[name=film,type=TABLE,remarks=], " + "Table[name=film_actor,type=TABLE,remarks=], "
+ + "Table[name=film_category,type=TABLE,remarks=], " + "Table[name=film_text,type=TABLE,remarks=], "
+ + "Table[name=inventory,type=TABLE,remarks=], " + "Table[name=language,type=TABLE,remarks=], "
+ + "Table[name=payment,type=TABLE,remarks=], " + "Table[name=rental,type=TABLE,remarks=], "
+ + "Table[name=staff,type=TABLE,remarks=], " + "Table[name=store,type=TABLE,remarks=], "
+ + "Table[name=actor_info,type=VIEW,remarks=], " + "Table[name=customer_list,type=VIEW,remarks=], "
+ + "Table[name=film_list,type=VIEW,remarks=], "
+ + "Table[name=nicer_but_slower_film_list,type=VIEW,remarks=], "
+ + "Table[name=sales_by_film_category,type=VIEW,remarks=], "
+ + "Table[name=sales_by_store,type=VIEW,remarks=], " + "Table[name=staff_list,type=VIEW,remarks=]]",
+ Arrays.toString(schema.getTables()));
+
+ Table filmTable = schema.getTableByName("film");
+ assertEquals(
+ "[Column[name=film_id,columnNumber=0,type=SMALLINT,nullable=false,nativeType=SMALLINT UNSIGNED,columnSize=5], "
+ + "Column[name=title,columnNumber=1,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=255], "
+ + "Column[name=description,columnNumber=2,type=LONGVARCHAR,nullable=true,nativeType=TEXT,columnSize=65535], "
+ + "Column[name=release_year,columnNumber=3,type=DATE,nullable=true,nativeType=YEAR,columnSize=0], "
+ + "Column[name=language_id,columnNumber=4,type=TINYINT,nullable=false,nativeType=TINYINT UNSIGNED,columnSize=3], "
+ + "Column[name=original_language_id,columnNumber=5,type=TINYINT,nullable=true,nativeType=TINYINT UNSIGNED,columnSize=3], "
+ + "Column[name=rental_duration,columnNumber=6,type=TINYINT,nullable=false,nativeType=TINYINT UNSIGNED,columnSize=3], "
+ + "Column[name=rental_rate,columnNumber=7,type=DECIMAL,nullable=false,nativeType=DECIMAL,columnSize=4], "
+ + "Column[name=length,columnNumber=8,type=SMALLINT,nullable=true,nativeType=SMALLINT UNSIGNED,columnSize=5], "
+ + "Column[name=replacement_cost,columnNumber=9,type=DECIMAL,nullable=false,nativeType=DECIMAL,columnSize=5], "
+ + "Column[name=rating,columnNumber=10,type=CHAR,nullable=true,nativeType=ENUM,columnSize=5], "
+ + "Column[name=special_features,columnNumber=11,type=CHAR,nullable=true,nativeType=SET,columnSize=54], "
+ + "Column[name=last_update,columnNumber=12,type=TIMESTAMP,nullable=false,nativeType=TIMESTAMP,columnSize=19]]",
+ Arrays.toString(filmTable.getColumns()));
+ assertEquals(
+ "[Relationship[primaryTable=language,primaryColumns=[language_id],foreignTable=film,foreignColumns=[language_id]], Relationship[primaryTable=language,primaryColumns=[language_id],foreignTable=film,foreignColumns=[original_language_id]], Relationship[primaryTable=film,primaryColumns=[film_id],foreignTable=film_actor,foreignColumns=[film_id]], Relationship[primaryTable=film,primaryColumns=[film_id],foreignTable=film_category,foreignColumns=[film_id]], Relationship[primaryTable=film,primaryColumns=[film_id],foreignTable=inventory,foreignColumns=[film_id]]]",
+ Arrays.toString(filmTable.getRelationships()));
+
+ dc = new JdbcDataContext(_connection, TableType.DEFAULT_TABLE_TYPES, "sakila");
+ schemas = dc.getSchemas();
+ assertEquals(6, schemas.length);
+ assertEquals("[Table[name=actor,type=TABLE,remarks=], " + "Table[name=address,type=TABLE,remarks=], "
+ + "Table[name=category,type=TABLE,remarks=], " + "Table[name=city,type=TABLE,remarks=], "
+ + "Table[name=country,type=TABLE,remarks=], " + "Table[name=customer,type=TABLE,remarks=], "
+ + "Table[name=film,type=TABLE,remarks=], " + "Table[name=film_actor,type=TABLE,remarks=], "
+ + "Table[name=film_category,type=TABLE,remarks=], " + "Table[name=film_text,type=TABLE,remarks=], "
+ + "Table[name=inventory,type=TABLE,remarks=], " + "Table[name=language,type=TABLE,remarks=], "
+ + "Table[name=payment,type=TABLE,remarks=], " + "Table[name=rental,type=TABLE,remarks=], "
+ + "Table[name=staff,type=TABLE,remarks=], " + "Table[name=store,type=TABLE,remarks=], "
+ + "Table[name=actor_info,type=VIEW,remarks=], " + "Table[name=customer_list,type=VIEW,remarks=], "
+ + "Table[name=film_list,type=VIEW,remarks=], "
+ + "Table[name=nicer_but_slower_film_list,type=VIEW,remarks=], "
+ + "Table[name=sales_by_film_category,type=VIEW,remarks=], "
+ + "Table[name=sales_by_store,type=VIEW,remarks=], " + "Table[name=staff_list,type=VIEW,remarks=]]",
+ Arrays.toString(schema.getTables()));
+
+ Table staffView = schema.getTableByName("staff_list");
+ assertEquals(
+ "[Column[name=ID,columnNumber=0,type=TINYINT,nullable=false,nativeType=TINYINT UNSIGNED,columnSize=3], "
+ + "Column[name=name,columnNumber=1,type=VARCHAR,nullable=true,nativeType=VARCHAR,columnSize=91], "
+ + "Column[name=address,columnNumber=2,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=50], "
+ + "Column[name=zip code,columnNumber=3,type=VARCHAR,nullable=true,nativeType=VARCHAR,columnSize=10], "
+ + "Column[name=phone,columnNumber=4,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=20], "
+ + "Column[name=city,columnNumber=5,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=50], "
+ + "Column[name=country,columnNumber=6,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=50], "
+ + "Column[name=SID,columnNumber=7,type=TINYINT,nullable=false,nativeType=TINYINT UNSIGNED,columnSize=3]]",
+ Arrays.toString(staffView.getColumns()));
+ }
+
+ public void testSplitQuery() throws Exception {
+ DataContext dc = new JdbcDataContext(_connection, TableType.DEFAULT_TABLE_TYPES, "sakila");
+ Schema schema = dc.getSchemaByName("sakila");
+ Table staffListTable = schema.getTableByName("staff_list");
+ assertNotNull(staffListTable);
+ Table paymentTable = schema.getTableByName("payment");
+ assertNotNull(paymentTable);
+ Column countryColumn = staffListTable.getColumnByName("country");
+ assertNotNull(countryColumn);
+ Column paymentColumn = paymentTable.getColumns()[0];
+ assertNotNull(paymentColumn);
+ Query q = new Query().from(staffListTable, "sl").from(paymentTable, "e").select(countryColumn, paymentColumn);
+ assertEquals("SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e",
+ q.toString());
+
+ QuerySplitter qs = new QuerySplitter(dc, q);
+ assertEquals(32098, qs.getRowCount());
+ List<Query> splitQueries = qs.setMaxRows(8000).splitQuery();
+ assertEquals(7, splitQueries.size());
+ assertEquals(
+ "[SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` < 4013 OR e.`rental_id` IS NULL) AND (e.`customer_id` < 300 OR e.`customer_id` IS NULL), SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` < 4013 OR e.`rental_id` IS NULL) AND (e.`customer_id` > 300 OR e.`customer_id` = 300), SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` > 4013 OR e.`rental_id` = 4013) AND (e.`rental_id` < 8025 OR e.`rental_id` = 4013) AND (e.`payment_id` < 8025 OR e.`payment_id` IS NULL), SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` > 4013 OR e.`rental_id` = 4013) AND (e.`rental_id` < 8025 OR e.`rental_id` = 4013) AND (e.`payment_id` > 8025 OR e.`payment_id` = 8025), SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` > 8025 OR e.`re
ntal_id` = 8025) AND (e.`rental_id` < 12037 OR e.`rental_id` = 8025) AND (e.`amount` < 6 OR e.`amount` IS NULL), SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` > 8025 OR e.`rental_id` = 8025) AND (e.`rental_id` < 12037 OR e.`rental_id` = 8025) AND (e.`amount` > 6 OR e.`amount` = 6), SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` > 12037 OR e.`rental_id` = 12037)]",
+ Arrays.toString(splitQueries.toArray()));
+
+ DataSet data = qs.executeQueries();
+ int count = 0;
+ while (data.next()) {
+ count++;
+ }
+ data.close();
+ assertEquals(32098, count);
+ }
+
+ public void testQueryWithSingleQuote() throws Exception {
+ DataContext dc = new JdbcDataContext(_connection, TableType.DEFAULT_TABLE_TYPES, "sakila");
+ Query q = dc.query().from("category").selectCount().where("name").eq("kasper's horror movies").toQuery();
+ DataSet ds = dc.executeQuery(q);
+ assertTrue(ds.next());
+ assertEquals(0, ((Number) ds.getRow().getValue(0)).intValue());
+ assertFalse(ds.next());
+ }
+
+ public void testWhiteSpaceColumns() throws Exception {
+ DatabaseMetaData metaData = _connection.getMetaData();
+ assertEquals("`", metaData.getIdentifierQuoteString());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/jdbc/src/test/integrationtests/org/apache/metamodel/OracleTest.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/integrationtests/org/apache/metamodel/OracleTest.java b/jdbc/src/test/integrationtests/org/apache/metamodel/OracleTest.java
new file mode 100644
index 0000000..4717873
--- /dev/null
+++ b/jdbc/src/test/integrationtests/org/apache/metamodel/OracleTest.java
@@ -0,0 +1,222 @@
+package org.eobjects.metamodel;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.util.Arrays;
+
+import javax.swing.table.TableModel;
+
+import junit.framework.TestCase;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.DataSetTableModel;
+import org.eobjects.metamodel.jdbc.JdbcDataContext;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.JoinType;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.Relationship;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.schema.TableType;
+
+/**
+ * Test case that tests oracle interaction. An express edition of the oracle
+ * database can be used to run these tests.
+ *
+ * The test requires the "human resources" schema that is provided ass a sample
+ * schema for Oracle default installations.
+ *
+ * The script for installing it can be found in:
+ *
+ * <pre>
+ * $ORACLE_HOME / demo / schema / human_resources / hr_main.sql
+ * </pre>
+ *
+ * Install with something like:
+ *
+ * <pre>
+ * $ORACLE_HOME/bin/sqlplus -S "/ as sysdba" @hr_main.sql
+ * </pre>
+ *
+ * The JDBC driver is not available in the Maven repository so you will have to
+ * download and attach it to the eclipse project yourself.
+ *
+ * @see http://www.oracle.com/technology/products/bi/samples
+ * @see http
+ * ://www.oracle.com/technology/software/products/database/xe/index.html
+ */
+public class OracleTest extends TestCase {
+
+ private static final String CONNECTION_STRING = "jdbc:oracle:thin:@localhost:1521:XE";
+ private static final String USERNAME = "HR";
+ private static final String PASSWORD = "eobjects";
+ private Connection _connection;
+ private DataContext _dataContext;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ Class.forName("oracle.jdbc.OracleDriver");
+ _connection = DriverManager.getConnection(CONNECTION_STRING, USERNAME,
+ PASSWORD);
+ _connection.setReadOnly(true);
+ _dataContext = new JdbcDataContext(_connection);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ _connection.close();
+ }
+
+ /**
+ * Ticket #170: getIndexInfo causes SQLException. We test that resultsets
+ * are closed properly.
+ */
+ public void testIndexInfo() throws Exception {
+ Schema schema = new JdbcDataContext(_connection,
+ new TableType[] { TableType.TABLE }, null)
+ .getSchemaByName("SYS");
+ assertEquals(12, schema.getTableCount());
+ }
+
+ public void testGetSchemaNames() throws Exception {
+ DataContext dc = new JdbcDataContext(_connection);
+ String[] schemaNames = dc.getSchemaNames();
+
+ String concatSchemas = Arrays.toString(schemaNames);
+
+ // In order to allow the database to be used for other purposes than
+ // this integration test, we will not make an exact assertion as to
+ // which schema names exist, but just assert that HR and the default
+ // oracle schemas exist.
+ assertTrue(concatSchemas.indexOf("foobar_schema_that_does_not_exist") == -1);
+ assertTrue(concatSchemas.indexOf("HR") != -1);
+ assertTrue(concatSchemas.indexOf("SYSTEM") != -1);
+ assertTrue(concatSchemas.indexOf("XDB") != -1);
+ assertTrue(schemaNames.length > 8);
+
+ Schema schema = dc.getDefaultSchema();
+ assertEquals("HR", schema.getName());
+ }
+
+ /**
+ * Really only tests the JDBC implementation, used to help localize the
+ * cause for Ticket #144
+ */
+ public void testGetImportedKeys() throws Exception {
+ ResultSet rs = _connection.getMetaData().getImportedKeys(null, "HR",
+ "EMPLOYEES");
+ int count = 0;
+ while (rs.next()) {
+ count++;
+ assertEquals("HR", rs.getString(2));
+ String pkTableName = rs.getString(3);
+ String pkColumnName = rs.getString(4);
+ String fkTableName = rs.getString(7);
+ assertEquals("EMPLOYEES", fkTableName);
+ String fkColumnName = rs.getString(8);
+ System.out.println("Found primary key relation: pkTableName="
+ + pkTableName + ",pkColumnName=" + pkColumnName
+ + ",fkTableName=" + fkTableName + ",fkColumnName="
+ + fkColumnName);
+ }
+ rs.close();
+ assertEquals(3, count);
+
+ rs = _connection.getMetaData().getImportedKeys(null, "HR",
+ "DEPARTMENTS");
+ count = 0;
+ while (rs.next()) {
+ count++;
+ assertEquals("HR", rs.getString(2));
+ String pkTableName = rs.getString(3);
+ String pkColumnName = rs.getString(4);
+ String fkTableName = rs.getString(7);
+ assertEquals("DEPARTMENTS", fkTableName);
+ String fkColumnName = rs.getString(8);
+ System.out.println("Found primary key relation: pkTableName="
+ + pkTableName + ",pkColumnName=" + pkColumnName
+ + ",fkTableName=" + fkTableName + ",fkColumnName="
+ + fkColumnName);
+ }
+ rs.close();
+ assertEquals(2, count);
+ }
+
+ public void testGetSchema() throws Exception {
+ Schema schema = _dataContext.getSchemaByName("HR");
+ assertNotNull(schema);
+ assertEquals(
+ "{JdbcTable[name=COUNTRIES,type=TABLE,remarks=<null>],"
+ + "JdbcTable[name=DEPARTMENTS,type=TABLE,remarks=<null>]"
+ + ",JdbcTable[name=EMPLOYEES,type=TABLE,remarks=<null>]"
+ + ",JdbcTable[name=JOBS,type=TABLE,remarks=<null>]"
+ + ",JdbcTable[name=JOB_HISTORY,type=TABLE,remarks=<null>]"
+ + ",JdbcTable[name=LOCATIONS,type=TABLE,remarks=<null>]"
+ + ",JdbcTable[name=REGIONS,type=TABLE,remarks=<null>]"
+ + ",JdbcTable[name=EMP_DETAILS_VIEW,type=VIEW,remarks=<null>]}",
+ Arrays.toString(schema.getTables()));
+
+ Relationship[] employeeRelationships = schema.getTableByName(
+ "EMPLOYEES").getRelationships();
+ assertEquals(
+ "{Relationship[primaryTable=EMPLOYEES,primaryColumns={EMPLOYEE_ID},foreignTable=DEPARTMENTS,foreignColumns={MANAGER_ID}],"
+ + "Relationship[primaryTable=DEPARTMENTS,primaryColumns={DEPARTMENT_ID},foreignTable=EMPLOYEES,foreignColumns={DEPARTMENT_ID}],"
+ + "Relationship[primaryTable=EMPLOYEES,primaryColumns={EMPLOYEE_ID},foreignTable=EMPLOYEES,foreignColumns={MANAGER_ID}],"
+ + "Relationship[primaryTable=JOBS,primaryColumns={JOB_ID},foreignTable=EMPLOYEES,foreignColumns={JOB_ID}],"
+ + "Relationship[primaryTable=EMPLOYEES,primaryColumns={EMPLOYEE_ID},foreignTable=JOB_HISTORY,foreignColumns={EMPLOYEE_ID}]}",
+ Arrays.toString(employeeRelationships));
+
+ assertEquals(
+ "{JdbcColumn[name=EMPLOYEE_ID,columnNumber=0,type=DECIMAL,nullable=false,nativeType=NUMBER,columnSize=6],"
+ + "JdbcColumn[name=FIRST_NAME,columnNumber=1,type=VARCHAR,nullable=true,nativeType=VARCHAR2,columnSize=20],"
+ + "JdbcColumn[name=LAST_NAME,columnNumber=2,type=VARCHAR,nullable=false,nativeType=VARCHAR2,columnSize=25],"
+ + "JdbcColumn[name=EMAIL,columnNumber=3,type=VARCHAR,nullable=false,nativeType=VARCHAR2,columnSize=25],"
+ + "JdbcColumn[name=PHONE_NUMBER,columnNumber=4,type=VARCHAR,nullable=true,nativeType=VARCHAR2,columnSize=20],"
+ + "JdbcColumn[name=HIRE_DATE,columnNumber=5,type=DATE,nullable=false,nativeType=DATE,columnSize=7],"
+ + "JdbcColumn[name=JOB_ID,columnNumber=6,type=VARCHAR,nullable=false,nativeType=VARCHAR2,columnSize=10],"
+ + "JdbcColumn[name=SALARY,columnNumber=7,type=DECIMAL,nullable=true,nativeType=NUMBER,columnSize=8],"
+ + "JdbcColumn[name=COMMISSION_PCT,columnNumber=8,type=DECIMAL,nullable=true,nativeType=NUMBER,columnSize=2],"
+ + "JdbcColumn[name=MANAGER_ID,columnNumber=9,type=DECIMAL,nullable=true,nativeType=NUMBER,columnSize=6],"
+ + "JdbcColumn[name=DEPARTMENT_ID,columnNumber=10,type=DECIMAL,nullable=true,nativeType=NUMBER,columnSize=4]}",
+ Arrays.toString(schema.getTableByName("EMPLOYEES").getColumns()));
+
+ assertEquals(
+ "{JdbcColumn[name=DEPARTMENT_ID,columnNumber=0,type=DECIMAL,nullable=false,nativeType=NUMBER,columnSize=4],"
+ + "JdbcColumn[name=DEPARTMENT_NAME,columnNumber=1,type=VARCHAR,nullable=false,nativeType=VARCHAR2,columnSize=30],"
+ + "JdbcColumn[name=MANAGER_ID,columnNumber=2,type=DECIMAL,nullable=true,nativeType=NUMBER,columnSize=6],"
+ + "JdbcColumn[name=LOCATION_ID,columnNumber=3,type=DECIMAL,nullable=true,nativeType=NUMBER,columnSize=4]}",
+ Arrays.toString(schema.getTableByName("DEPARTMENTS")
+ .getColumns()));
+ }
+
+ public void testExecuteQuery() throws Exception {
+ Schema schema = _dataContext.getSchemaByName("HR");
+ Table employeeTable = schema.getTableByName("EMPLOYEES");
+ Table departmentsTable = schema.getTableByName("DEPARTMENTS");
+ Relationship relationship = employeeTable
+ .getRelationships(departmentsTable)[0];
+ assertEquals(
+ "Relationship[primaryTable=EMPLOYEES,primaryColumns={EMPLOYEE_ID},foreignTable=DEPARTMENTS,foreignColumns={MANAGER_ID}]",
+ relationship.toString());
+
+ Query q = new Query().from(new FromItem(JoinType.INNER, relationship))
+ .select(employeeTable.getColumnByName("EMAIL"),
+ departmentsTable.getColumnByName("DEPARTMENT_NAME"));
+ q.getSelectClause().getItem(0).setAlias("e-mail");
+
+ assertEquals(
+ "SELECT \"EMPLOYEES\".\"EMAIL\" AS e-mail, \"DEPARTMENTS\".\"DEPARTMENT_NAME\" FROM HR.\"EMPLOYEES\" INNER JOIN HR.\"DEPARTMENTS\" ON \"EMPLOYEES\".\"EMPLOYEE_ID\" = \"DEPARTMENTS\".\"MANAGER_ID\"",
+ q.toString());
+
+ DataSet data = _dataContext.executeQuery(q);
+ assertNotNull(data);
+ TableModel tableModel = new DataSetTableModel(data);
+ assertEquals(2, tableModel.getColumnCount());
+ assertEquals(11, tableModel.getRowCount());
+ assertEquals("JWHALEN", tableModel.getValueAt(0, 0).toString());
+ assertEquals("Administration", tableModel.getValueAt(0, 1).toString());
+ }
+}
\ No newline at end of file
[29/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/update/Update.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/update/Update.java b/core/src/main/java/org/eobjects/metamodel/update/Update.java
deleted file mode 100644
index 837a05e..0000000
--- a/core/src/main/java/org/eobjects/metamodel/update/Update.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * 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.update;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.AbstractRowBuilder;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.data.WhereClauseBuilder;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.query.builder.AbstractFilterBuilder;
-import org.eobjects.metamodel.query.builder.FilterBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * Represents a single UPDATE 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 update
- * implementation. Some {@link DataContext}s may even optimize specifically
- * based on the knowledge that there will only be a single update statement
- * executed.
- */
-public final class Update extends AbstractRowBuilder<Update> implements UpdateScript, WhereClauseBuilder<Update> {
-
- private final Table _table;
- private final List<FilterItem> _whereItems;
-
- public Update(Table table) {
- super(table);
- _table = table;
- _whereItems = new ArrayList<FilterItem>();
- }
-
- @Override
- public Table getTable() {
- return _table;
- }
-
- @Override
- public void run(UpdateCallback callback) {
- RowUpdationBuilder updateBuilder = callback.update(_table).where(_whereItems);
-
- final Column[] columns = getColumns();
- final Object[] values = getValues();
- final Style[] styles = getStyles();
- final boolean[] explicitNulls = getExplicitNulls();
-
- for (int i = 0; i < columns.length; i++) {
- Object value = values[i];
- Column column = columns[i];
- Style style = styles[i];
- if (value == null) {
- if (explicitNulls[i]) {
- updateBuilder = updateBuilder.value(column, value, style);
- }
- } else {
- updateBuilder = updateBuilder.value(column, value, style);
- }
- }
-
- updateBuilder.execute();
- }
-
- @Override
- public FilterBuilder<Update> where(Column column) {
- SelectItem selectItem = new SelectItem(column);
- return new AbstractFilterBuilder<Update>(selectItem) {
- @Override
- protected Update applyFilter(FilterItem filter) {
- return where(filter);
- }
- };
- }
-
- @Override
- public FilterBuilder<Update> where(String columnName) {
- Column column = _table.getColumnByName(columnName);
- if (column == null) {
- throw new IllegalArgumentException("No such column: " + columnName);
- }
- return where(column);
- }
-
- @Override
- public Update where(FilterItem... filterItems) {
- for (FilterItem filterItem : filterItems) {
- _whereItems.add(filterItem);
- }
- return this;
- }
-
- @Override
- public Update where(Iterable<FilterItem> filterItems) {
- for (FilterItem filterItem : filterItems) {
- _whereItems.add(filterItem);
- }
- return this;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/update/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/update/package-info.java b/core/src/main/java/org/eobjects/metamodel/update/package-info.java
deleted file mode 100644
index d29b7d0..0000000
--- a/core/src/main/java/org/eobjects/metamodel/update/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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 updating rows
- */
-package org.eobjects.metamodel.update;
-
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/Action.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/Action.java b/core/src/main/java/org/eobjects/metamodel/util/Action.java
deleted file mode 100644
index bf0bbc4..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/Action.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * 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.util;
-
-/**
- * Represents an abstract action, which is an executable piece of functionality
- * that takes an argument. An {@link Action} has no return type, unlike a
- * {@link Func}.
- *
- * @author Kasper Sørensen
- *
- * @param <E>
- * the argument type of the action
- */
-public interface Action<E> {
-
- public void run(E arg) throws Exception;
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/AggregateBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/AggregateBuilder.java b/core/src/main/java/org/eobjects/metamodel/util/AggregateBuilder.java
deleted file mode 100644
index 3663959..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/AggregateBuilder.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * 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.util;
-
-/**
- * Interface for aggregate builders which allows for an iterative approach to
- * evaluating aggregates.
- *
- * @author Kasper Sørensen
- *
- * @param <E>
- * the aggregate result type
- */
-public interface AggregateBuilder<E> {
-
- public void add(Object o);
-
- public E getAggregate();
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/AlphabeticSequence.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/AlphabeticSequence.java b/core/src/main/java/org/eobjects/metamodel/util/AlphabeticSequence.java
deleted file mode 100644
index d47b0af..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/AlphabeticSequence.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- * 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.util;
-
-/**
- * A sequence based on alphabetic representations. Typically a sequence begin
- * with "A", "B", "C" etc. and go from "Z" to "AA", from "AZ" to "BA" etc.
- *
- * This sequence is practical for generating column names that correspond to
- * column identifiers in spreadsheets and the like.
- *
- * @author Kasper Sørensen
- */
-public class AlphabeticSequence {
-
- private StringBuilder _stringBuilder;
-
- /**
- * Creates an alphabetic sequence that will have "A" as it's first value, if
- * iterated using next().
- */
- public AlphabeticSequence() {
- this(Character.toString((char) ('A' - 1)));
- }
-
- /**
- * Creates an alphabetic sequence based on a value
- *
- * @param value
- */
- public AlphabeticSequence(String value) {
- _stringBuilder = new StringBuilder(value.toUpperCase());
- }
-
- /**
- * Gets the current value (ie. doesn't iterate).
- *
- * @return a string identifier, eg. "A", "B", "AA" etc.
- */
- public String current() {
- return _stringBuilder.toString();
- }
-
- /**
- * Iterates to the next value and returns it.
- *
- * @return a string identifier, eg. "A", "B", "AA" etc.
- */
- public String next() {
- boolean updated = false;
- int length = _stringBuilder.length();
- for (int i = length - 1; i >= 0; i--) {
- char c = _stringBuilder.charAt(i);
- if (c != 'Z') {
- c = (char) (c + 1);
- _stringBuilder.setCharAt(i, c);
- updated = true;
- break;
- } else {
- _stringBuilder.setCharAt(i, 'A');
- }
- }
-
- if (!updated) {
- // need to add another char
- _stringBuilder.append('A');
- }
- return current();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/BaseObject.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/BaseObject.java b/core/src/main/java/org/eobjects/metamodel/util/BaseObject.java
deleted file mode 100644
index dde30da..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/BaseObject.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/**
- * 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.util;
-
-import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A base object type with conveniently implemented base methods like hashCode()
- * and equals(). Subclasses should implement the {@link #decorateIdentity(List)}
- * method to have {@link #equals(Object)} and {@link #hashCode()} automatically
- * implemented.
- *
- * @author Kasper Sørensen
- */
-public abstract class BaseObject {
-
- private static final Logger logger = LoggerFactory
- .getLogger(BaseObject.class);
-
- @Override
- public String toString() {
- // overridden version of toString() method that uses identity hash code
- // (to prevent hashCode() recursion due to logging!)
- return getClass().getName() + "@"
- + Integer.toHexString(System.identityHashCode(this));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final int hashCode() {
- logger.debug("{}.hashCode()", this);
- int hashCode = -1;
- List<Object> list = new ArrayList<Object>();
- decorateIdentity(list);
- if (list.isEmpty()) {
- list.add(toString());
- }
- hashCode -= list.size();
- for (Object obj : list) {
- hashCode += hashCode(obj);
- }
- return hashCode;
- }
-
- private static final int hashCode(Object obj) {
- if (obj == null) {
- logger.debug("obj is null, returning constant");
- return -17;
- }
- if (obj.getClass().isArray()) {
- logger.debug("obj is an array, returning a sum");
- int length = Array.getLength(obj);
- int hashCode = 4324;
- for (int i = 0; i < length; i++) {
- Object o = Array.get(obj, i);
- hashCode += hashCode(o);
- }
- return hashCode;
- }
- logger.debug("obj is a regular object, returning hashCode");
- return obj.hashCode();
- }
-
- /**
- * Override this method if the equals method should support different
- * subtypes. For example, if different subtypes of Number should be
- * supported, implement this method with:
- *
- * <code>
- * obj instanceof Number
- * </code>
- *
- * and make sure that the decorateIdentity(...) method will always return a
- * comparable list of identity-objects.
- *
- * @param obj
- * @return true if the provided object's class is accepted for equals
- * comparison
- */
- protected boolean classEquals(BaseObject obj) {
- return getClass() == obj.getClass();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (obj == this) {
- return true;
- }
- if (obj instanceof BaseObject) {
- BaseObject that = (BaseObject) obj;
- if (classEquals(that)) {
- List<Object> list1 = new ArrayList<Object>();
- List<Object> list2 = new ArrayList<Object>();
-
- decorateIdentity(list1);
- that.decorateIdentity(list2);
-
- if (list1.size() != list2.size()) {
- throw new IllegalStateException(
- "Two instances of the same class ("
- + getClass().getName()
- + ") returned different size decorated identity lists");
- }
-
- if (list1.isEmpty()) {
- assert list2.isEmpty();
- list1.add(toString());
- list2.add(that.toString());
- }
-
- EqualsBuilder eb = new EqualsBuilder();
-
- Iterator<Object> it1 = list1.iterator();
- Iterator<Object> it2 = list2.iterator();
- while (it1.hasNext()) {
- assert it2.hasNext();
- Object next1 = it1.next();
- Object next2 = it2.next();
- eb.append(next1, next2);
- }
- assert !it2.hasNext();
-
- return eb.isEquals();
- }
- }
- return false;
- }
-
- /**
- * Subclasses should implement this method and add all fields to the list
- * that are to be included in equals(...) and hashCode() evaluation
- *
- * @param identifiers
- */
- protected abstract void decorateIdentity(List<Object> identifiers);
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/BooleanComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/BooleanComparator.java b/core/src/main/java/org/eobjects/metamodel/util/BooleanComparator.java
deleted file mode 100644
index 22bc9f1..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/BooleanComparator.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/**
- * 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.util;
-
-import java.util.Comparator;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Comparator of booleans
- *
- * @author Kasper Sørensen
- */
-public final class BooleanComparator implements Comparator<Object> {
-
- private static final Logger logger = LoggerFactory
- .getLogger(BooleanComparator.class);
-
- private static BooleanComparator _instance = new BooleanComparator();
-
- private BooleanComparator() {
- }
-
- public static Comparator<Object> getComparator() {
- return _instance;
- }
-
- public static Comparable<Object> getComparable(Object object) {
- final Boolean b = toBoolean(object);
- return new Comparable<Object>() {
-
- @Override
- public boolean equals(Object obj) {
- return _instance.equals(obj);
- }
-
- public int compareTo(Object o) {
- return _instance.compare(b, o);
- }
-
- @Override
- public String toString() {
- return "BooleanComparable[boolean=" + b + "]";
- }
- };
- }
-
- public int compare(Object o1, Object o2) {
- if (o1 == null && o2 == null) {
- return 0;
- }
- if (o1 == null) {
- return -1;
- }
- if (o2 == null) {
- return 1;
- }
- Boolean b1 = toBoolean(o1);
- Boolean b2 = toBoolean(o2);
- return b1.compareTo(b2);
- }
-
- public static Boolean toBoolean(Object o) {
- if (o == null) {
- return null;
- }
-
- if (o instanceof Boolean) {
- return (Boolean) o;
- }
- if (o instanceof String) {
- try {
- return parseBoolean((String) o);
- } catch (IllegalArgumentException e) {
- logger.warn(
- "Could not convert String '{}' to boolean, returning false", o);
- return false;
- }
- }
- if (o instanceof Number) {
- int i = ((Number) o).intValue();
- return i >= 1;
- }
-
- logger.warn(
- "Could not convert '{}' to boolean, returning false",
- o);
- return false;
- }
-
- /**
- * Parses a string and returns a boolean representation of it. To parse the
- * string the following values will be accepted, irrespective of case.
- * <ul>
- * <li>true</li>
- * <li>false</li>
- * <li>1</li>
- * <li>0</li>
- * <li>yes</li>
- * <li>no</li>
- * <li>y</li>
- * <li>n</li>
- * </ul>
- *
- * @param string
- * the string to parse
- * @return a boolean
- * @throws IllegalArgumentException
- * if the string provided is null or cannot be parsed as a
- * boolean
- */
- public static boolean parseBoolean(String string)
- throws IllegalArgumentException {
- if (string == null) {
- throw new IllegalArgumentException("string cannot be null");
- }
- string = string.trim();
- if ("true".equalsIgnoreCase(string) || "1".equals(string)
- || "y".equalsIgnoreCase(string)
- || "yes".equalsIgnoreCase(string)) {
- return true;
- } else if ("false".equalsIgnoreCase(string) || "0".equals(string)
- || "n".equalsIgnoreCase(string)
- || "no".equalsIgnoreCase(string)) {
- return false;
- } else {
- throw new IllegalArgumentException(
- "Could not get boolean value of string: " + string);
- }
- }
-
- public static boolean isBoolean(Object o) {
- if (o instanceof Boolean) {
- return true;
- }
- if (o instanceof String) {
- if ("true".equalsIgnoreCase((String) o)
- || "false".equalsIgnoreCase((String) o)) {
- return true;
- }
- }
- return false;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/ClasspathResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/ClasspathResource.java b/core/src/main/java/org/eobjects/metamodel/util/ClasspathResource.java
deleted file mode 100644
index 05275a8..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/ClasspathResource.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/**
- * 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.util;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Serializable;
-import java.net.URL;
-
-/**
- * A {@link Resource} based on a classpath entry
- */
-public class ClasspathResource implements Resource, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private final String _resourcePath;
-
- public ClasspathResource(String resourcePath) {
- if (resourcePath == null) {
- throw new IllegalArgumentException("Classpath resource path cannot be null");
- }
- _resourcePath = resourcePath;
- }
-
- @Override
- public String toString() {
- return "ClasspathResource[" + _resourcePath + "]";
- }
-
- /**
- * Gets the name of the classpath entry
- * @return
- */
- public String getResourcePath() {
- return _resourcePath;
- }
-
- @Override
- public String getName() {
- String name = _resourcePath;
- final int lastSlash = name.lastIndexOf('/');
- final int lastBackSlash = name.lastIndexOf('\\');
- final int lastIndex = Math.max(lastSlash, lastBackSlash);
- if (lastIndex != -1) {
- final String lastPart = name.substring(lastIndex + 1);
- if (!"".equals(lastPart)) {
- return lastPart;
- }
- }
- return name;
- }
-
- protected ClassLoader getClassLoader() {
- return ClassLoader.getSystemClassLoader();
- }
-
- private UrlResource getUrlResourceDelegate() {
- ClassLoader classLoader = getClassLoader();
-
- URL url = classLoader.getResource(_resourcePath);
- if (url == null && _resourcePath.startsWith("/")) {
- url = classLoader.getResource(_resourcePath.substring(1));
- }
-
- if (url == null) {
- return null;
- }
- return new UrlResource(url);
- }
-
- @Override
- public boolean isReadOnly() {
- return true;
- }
-
- @Override
- public boolean isExists() {
- UrlResource delegate = getUrlResourceDelegate();
- if (delegate == null) {
- return false;
- }
- return delegate.isExists();
- }
-
- @Override
- public long getSize() {
- UrlResource delegate = getUrlResourceDelegate();
- if (delegate == null) {
- return -1;
- }
- return delegate.getSize();
- }
-
- @Override
- public long getLastModified() {
- UrlResource delegate = getUrlResourceDelegate();
- if (delegate == null) {
- return -1;
- }
- return delegate.getLastModified();
- }
-
- @Override
- public void write(Action<OutputStream> writeCallback) throws ResourceException {
- getUrlResourceDelegate().write(writeCallback);
- }
-
- @Override
- public void append(Action<OutputStream> appendCallback) throws ResourceException {
- getUrlResourceDelegate().append(appendCallback);
- }
-
- @Override
- public InputStream read() throws ResourceException {
- return getUrlResourceDelegate().read();
- }
-
- @Override
- public void read(Action<InputStream> readCallback) throws ResourceException {
- getUrlResourceDelegate().read(readCallback);
- }
-
- @Override
- public <E> E read(Func<InputStream, E> readCallback) throws ResourceException {
- return getUrlResourceDelegate().read(readCallback);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/CollectionUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/CollectionUtils.java b/core/src/main/java/org/eobjects/metamodel/util/CollectionUtils.java
deleted file mode 100644
index 52cff9a..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/CollectionUtils.java
+++ /dev/null
@@ -1,240 +0,0 @@
-/**
- * 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.util;
-
-import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Various utility methods for handling of collections and arrays.
- *
- * @author Kasper Sørensen
- */
-public final class CollectionUtils {
-
- private CollectionUtils() {
- // prevent instantiation
- }
-
- /**
- * Concatenates two arrays
- *
- * @param existingArray an existing array
- * @param elements the elements to add to the end of it
- * @return
- */
- @SuppressWarnings("unchecked")
- public static <E> E[] array(final E[] existingArray, final E... elements) {
- if (existingArray == null) {
- return elements;
- }
- Object result = Array.newInstance(existingArray.getClass()
- .getComponentType(), existingArray.length + elements.length);
- System.arraycopy(existingArray, 0, result, 0, existingArray.length);
- System.arraycopy(elements, 0, result, existingArray.length,
- elements.length);
- return (E[]) result;
- }
-
- public static <E> List<E> concat(boolean removeDuplicates,
- Collection<? extends E> firstCollection,
- Collection<?>... collections) {
- final List<E> result;
- if (removeDuplicates) {
- result = new ArrayList<E>();
- addElements(removeDuplicates, result, firstCollection);
- } else {
- result = new ArrayList<E>(firstCollection);
- }
- for (Collection<?> collection : collections) {
- @SuppressWarnings("unchecked")
- Collection<? extends E> elems = (Collection<? extends E>) collection;
- addElements(removeDuplicates, result, elems);
- }
- return result;
- }
-
- private static <E> void addElements(boolean removeDuplicates,
- final List<E> result, Collection<? extends E> elements) {
- for (E item : elements) {
- if (removeDuplicates) {
- if (!result.contains(item)) {
- result.add(item);
- }
- } else {
- result.add(item);
- }
- }
- }
-
- public static <E> E[] arrayRemove(E[] array, E elementToRemove) {
- @SuppressWarnings("unchecked")
- E[] result = (E[]) arrayRemoveInternal(array, elementToRemove);
- return result;
- }
-
- public static Object arrayRemove(Object array, Object elementToRemove) {
- return arrayRemoveInternal(array, elementToRemove);
- }
-
- private static Object arrayRemoveInternal(Object array,
- Object elementToRemove) {
- boolean found = false;
- final int oldLength = Array.getLength(array);
- if (oldLength == 0) {
- return array;
- }
- final int newLength = oldLength - 1;
- final Object result = Array.newInstance(array.getClass()
- .getComponentType(), newLength);
- int nextIndex = 0;
- for (int i = 0; i < oldLength; i++) {
- final Object e = Array.get(array, i);
- if (e.equals(elementToRemove)) {
- found = true;
- } else {
- if (nextIndex == newLength) {
- break;
- }
- Array.set(result, nextIndex, e);
- nextIndex++;
- }
- }
- if (!found) {
- return array;
- }
- return result;
- }
-
- @SuppressWarnings("unchecked")
- public static <E> E[] arrayOf(Class<E> elementClass, Object arrayOrElement) {
- if (arrayOrElement == null) {
- return null;
- }
- if (arrayOrElement.getClass().isArray()) {
- return (E[]) arrayOrElement;
- }
- Object result = Array.newInstance(elementClass, 1);
- Array.set(result, 0, arrayOrElement);
- return (E[]) result;
- }
-
- public static <E> List<E> filter(E[] items, Predicate<? super E> predicate) {
- return filter(Arrays.asList(items), predicate);
- }
-
- public static <E> List<E> filter(Iterable<E> items,
- Predicate<? super E> predicate) {
- List<E> result = new ArrayList<E>();
- for (E e : items) {
- if (predicate.eval(e).booleanValue()) {
- result.add(e);
- }
- }
- return result;
- }
-
- public static <I, O> List<O> map(I[] items, Func<? super I, O> func) {
- return map(Arrays.asList(items), func);
- }
-
- public static <I, O> List<O> map(Iterable<I> items, Func<? super I, O> func) {
- List<O> result = new ArrayList<O>();
- for (I item : items) {
- O output = func.eval(item);
- result.add(output);
- }
- return result;
- }
-
- public static <E> void forEach(E[] items, Action<? super E> action) {
- forEach(Arrays.asList(items), action);
- }
-
- public static <E> void forEach(Iterable<E> items, Action<? super E> action) {
- for (E item : items) {
- try {
- action.run(item);
- } catch (Exception e) {
- if (e instanceof RuntimeException) {
- throw (RuntimeException) e;
- }
- throw new IllegalStateException("Action threw exception", e);
- }
- }
- }
-
- public static <E> boolean isNullOrEmpty(E[] arr) {
- return arr == null || arr.length == 0;
- }
-
- public static boolean isNullOrEmpty(Collection<?> col) {
- return col == null || col.isEmpty();
- }
-
- /**
- * General purpose list converter method. Will convert arrays, collections,
- * iterables etc. into lists.
- *
- * If the argument is a single object (such as a String or a POJO) it will
- * be wrapped in a single-element list.
- *
- * Null will be converted to the empty list.
- *
- * @param obj
- * any object
- * @return a list representation of the object
- */
- public static List<?> toList(Object obj) {
- final List<Object> result;
- if (obj == null) {
- result = Collections.emptyList();
- } else if (obj instanceof List) {
- @SuppressWarnings("unchecked")
- List<Object> list = (List<Object>) obj;
- result = list;
- } else if (obj.getClass().isArray()) {
- int length = Array.getLength(obj);
- result = new ArrayList<Object>(length);
- for (int i = 0; i < length; i++) {
- result.add(Array.get(obj, i));
- }
- } else if (obj instanceof Iterable) {
- result = new ArrayList<Object>();
- for (Object item : (Iterable<?>) obj) {
- result.add(item);
- }
- } else if (obj instanceof Iterator) {
- result = new ArrayList<Object>();
- Iterator<?> it = (Iterator<?>) obj;
- while (it.hasNext()) {
- result.add(it.next());
- }
- } else {
- result = new ArrayList<Object>(1);
- result.add(obj);
- }
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/ConstantFunc.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/ConstantFunc.java b/core/src/main/java/org/eobjects/metamodel/util/ConstantFunc.java
deleted file mode 100644
index d2813ed..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/ConstantFunc.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * 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.util;
-
-/**
- * A function that always returns the same constant response.
- *
- * @param <I>
- * @param <O>
- */
-public final class ConstantFunc<I, O> implements Func<I, O> {
-
- private final O _response;
-
- public ConstantFunc(O response) {
- _response = response;
- }
-
- @Override
- public O eval(I arg) {
- return _response;
- }
-
- @Override
- public int hashCode() {
- if (_response == null) {
- return -1;
- }
- return _response.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (obj instanceof ConstantFunc) {
- Object otherResponse = ((ConstantFunc<?, ?>) obj)._response;
- if (otherResponse == null && _response == null) {
- return true;
- } else if (_response == null) {
- return false;
- } else {
- return _response.equals(otherResponse);
- }
- }
- return false;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/DateUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/DateUtils.java b/core/src/main/java/org/eobjects/metamodel/util/DateUtils.java
deleted file mode 100644
index b146523..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/DateUtils.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- * 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.util;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-
-/**
- * Various utility methods pertaining to date handling
- *
- * @author Kasper Sørensen
- */
-public final class DateUtils {
-
- public static final long MILLISECONDS_PER_SECOND = 1000;
- public static final long MILLISECONDS_PER_MINUTE = MILLISECONDS_PER_SECOND * 60;
- public static final long MILLISECONDS_PER_HOUR = MILLISECONDS_PER_MINUTE * 60;
- public static final long MILLISECONDS_PER_DAY = MILLISECONDS_PER_HOUR * 24;
-
- private DateUtils() {
- // prevent instantiation
- }
-
- public static Date get(int year, Month month, int dayOfMonth) {
- Calendar c = createCalendar();
- c.set(Calendar.YEAR, year);
- c.set(Calendar.MONTH, month.getCalendarConstant());
- c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
- c.set(Calendar.HOUR, 0);
- c.set(Calendar.MINUTE, 0);
- c.set(Calendar.SECOND, 0);
- c.set(Calendar.MILLISECOND, 0);
- return c.getTime();
- }
-
- public static Date get(Date date) {
- Calendar c = Calendar.getInstance();
- c.setTime(date);
- c.set(Calendar.HOUR, 0);
- c.set(Calendar.MINUTE, 0);
- c.set(Calendar.SECOND, 0);
- c.set(Calendar.MILLISECOND, 0);
-
- return c.getTime();
- }
-
- public static Date get(Date originalDate, int daysDiff) {
- long millis = originalDate.getTime();
- long diff = daysDiff * MILLISECONDS_PER_DAY;
- millis = millis + diff;
- return new Date(millis);
- }
-
- public static int getYear(Date date) {
- Calendar cal = createCalendar();
- cal.setTime(date);
- return cal.get(Calendar.YEAR);
- }
-
- public static Month getMonth(Date date) {
- Calendar cal = createCalendar();
- cal.setTime(date);
- int monthConstant = cal.get(Calendar.MONTH);
- return Month.getByCalendarConstant(monthConstant);
- }
-
- public static Weekday getWeekday(Date date) {
- Calendar cal = createCalendar();
- cal.setTime(date);
- int weekdayConstant = cal.get(Calendar.DAY_OF_WEEK);
- return Weekday.getByCalendarConstant(weekdayConstant);
- }
-
- public static int getDayOfMonth(Date date) {
- Calendar cal = createCalendar();
- cal.setTime(date);
- return cal.get(Calendar.DAY_OF_MONTH);
- }
-
- public static Calendar createCalendar() {
- Calendar c = Calendar.getInstance();
- c.setTimeInMillis(0l);
- return c;
- }
-
- public static DateFormat createDateFormat() {
- return createDateFormat("yyyy-MM-dd HH:mm:ss");
- }
-
- public static DateFormat createDateFormat(String datePattern) {
- SimpleDateFormat dateFormat = new SimpleDateFormat(datePattern);
- return dateFormat;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/EqualsBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/EqualsBuilder.java b/core/src/main/java/org/eobjects/metamodel/util/EqualsBuilder.java
deleted file mode 100644
index b02b6df..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/EqualsBuilder.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * 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.util;
-
-import java.lang.reflect.Array;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A helper class for implementing equals(...) methods.
- *
- * @author Kasper Sørensen
- */
-public final class EqualsBuilder {
-
- private static final Logger logger = LoggerFactory
- .getLogger(EqualsBuilder.class);
- private boolean equals = true;
-
- public EqualsBuilder append(boolean b) {
- logger.debug("append({})", b);
- if (equals) {
- equals = b;
- }
- return this;
- }
-
- public EqualsBuilder append(Object o1, Object o2) {
- if (equals) {
- equals = equals(o1, o2);
- }
- return this;
- }
-
- public static boolean equals(final Object obj1, final Object obj2) {
- if (obj1 == obj2) {
- return true;
- }
-
- if (obj1 == null || obj2 == null) {
- return false;
- }
-
- Class<? extends Object> class1 = obj1.getClass();
- Class<? extends Object> class2 = obj2.getClass();
- if (class1.isArray()) {
- if (!class2.isArray()) {
- return false;
- } else {
- Class<?> componentType1 = class1.getComponentType();
- Class<?> componentType2 = class2.getComponentType();
- if (!componentType1.equals(componentType2)) {
- return false;
- }
-
- int length1 = Array.getLength(obj1);
- int length2 = Array.getLength(obj2);
- if (length1 != length2) {
- return false;
- }
- for (int i = 0; i < length1; i++) {
- Object elem1 = Array.get(obj1, i);
- Object elem2 = Array.get(obj2, i);
- if (!equals(elem1, elem2)) {
- return false;
- }
- }
- return true;
- }
- } else {
- if (class2.isArray()) {
- return false;
- }
- }
-
- return obj1.equals(obj2);
- }
-
- public boolean isEquals() {
- return equals;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/ExclusionPredicate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/ExclusionPredicate.java b/core/src/main/java/org/eobjects/metamodel/util/ExclusionPredicate.java
deleted file mode 100644
index 78744bc..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/ExclusionPredicate.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * 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.util;
-
-import java.util.Collection;
-import java.util.Collections;
-
-/**
- * A predicate that uses an exclusion list ("black list") of elements to
- * determine whether to evaluate true or false.
- *
- * @param <E>
- */
-public class ExclusionPredicate<E> implements Predicate<E> {
-
- private final Collection<E> _exclusionList;
-
- public ExclusionPredicate(Collection<E> exclusionList) {
- _exclusionList = exclusionList;
- }
-
- @Override
- public Boolean eval(E arg) {
- if (_exclusionList.contains(arg)) {
- return false;
- }
- return true;
- }
-
- public Collection<E> getExclusionList() {
- return Collections.unmodifiableCollection(_exclusionList);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/FalsePredicate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/FalsePredicate.java b/core/src/main/java/org/eobjects/metamodel/util/FalsePredicate.java
deleted file mode 100644
index 7ba8b2a..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/FalsePredicate.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * 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.util;
-
-import java.io.Serializable;
-
-/**
- * A predicate that is always false
- *
- * @param <E>
- */
-public final class FalsePredicate<E> implements Predicate<E>, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public Boolean eval(E arg) {
- return false;
- }
-
- @Override
- public int hashCode() {
- return Boolean.FALSE.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- return obj != null && obj.getClass() == FalsePredicate.class;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/FileHelper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/FileHelper.java b/core/src/main/java/org/eobjects/metamodel/util/FileHelper.java
deleted file mode 100644
index 229baeb..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/FileHelper.java
+++ /dev/null
@@ -1,460 +0,0 @@
-/**
- * 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.util;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.ByteArrayOutputStream;
-import java.io.Closeable;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.Flushable;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PushbackInputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.Statement;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Various helper methods for handling files
- */
-public final class FileHelper {
-
- private final static Logger logger = LoggerFactory.getLogger(FileHelper.class);
-
- public static final String UTF_8_ENCODING = "UTF-8";
- public static final String UTF_16_ENCODING = "UTF-16";
- public static final String US_ASCII_ENCODING = "US-ASCII";
- public static final String ISO_8859_1_ENCODING = "ISO_8859_1";
- public static final String DEFAULT_ENCODING = UTF_8_ENCODING;
-
- private FileHelper() {
- // prevent instantiation
- }
-
- public static File createTempFile(String prefix, String suffix) {
- try {
- return File.createTempFile(prefix, suffix);
- } catch (IOException e) {
- logger.error("Could not create tempFile", e);
- File tempDir = getTempDir();
- return new File(tempDir, prefix + '.' + suffix);
- }
- }
-
- public static File getTempDir() {
- File result = null;
- String tmpDirPath = System.getProperty("java.io.tmpdir");
- if (tmpDirPath != null && !"".equals(tmpDirPath)) {
- result = new File(tmpDirPath);
- } else {
- logger.debug("Could not determine tmpdir by using environment variable.");
- try {
- File file = File.createTempFile("foo", "bar");
- result = file.getParentFile();
- if (!file.delete()) {
- logger.warn("Could not delete temp file '{}'", file.getAbsolutePath());
- }
- } catch (IOException e) {
- logger.error("Could not create tempFile in order to find temporary dir", e);
- result = new File("metamodel.tmp.dir");
- if (!result.mkdir()) {
- throw new IllegalStateException("Could not create directory for temporary files: " + result.getName());
- }
- result.deleteOnExit();
- }
- }
- if (logger.isInfoEnabled()) {
- logger.info("Using '{}' as tmpdir.", result.getAbsolutePath());
- }
- return result;
- }
-
- public static Writer getWriter(File file, String encoding, boolean append) throws IllegalStateException {
- boolean insertBom = !append;
- return getWriter(file, encoding, append, insertBom);
- }
-
- public static Writer getWriter(OutputStream outputStream, String encoding) throws IllegalStateException {
- return getWriter(outputStream, encoding, false);
- }
-
- public static Writer getWriter(OutputStream outputStream, String encoding, boolean insertBom) throws IllegalStateException {
- if (!(outputStream instanceof BufferedOutputStream)) {
- outputStream = new BufferedOutputStream(outputStream);
- }
-
- try {
- if (insertBom) {
- Writer writer = new UnicodeWriter(outputStream, encoding);
- return writer;
- } else {
- Writer writer = new OutputStreamWriter(outputStream, encoding);
- return writer;
- }
- } catch (Exception e) {
- throw new IllegalStateException(e);
- }
- }
-
- public static Writer getWriter(File file, String encoding, boolean append, boolean insertBom) throws IllegalStateException {
- if (append && insertBom) {
- throw new IllegalArgumentException("Can not insert BOM into appending writer");
- }
- final OutputStream outputStream = getOutputStream(file, append);
- return getWriter(outputStream, encoding, insertBom);
-
- }
-
- public static Writer getWriter(File file, String encoding) throws IllegalStateException {
- return getWriter(file, encoding, false);
- }
-
- public static Reader getReader(InputStream inputStream, String encoding) throws IllegalStateException {
- try {
- if (encoding == null || encoding.toLowerCase().indexOf("utf") != -1) {
- byte bom[] = new byte[4];
- int unread;
-
- // auto-detect byte-order-mark
- PushbackInputStream pushbackInputStream = new PushbackInputStream(inputStream, bom.length);
- int n = pushbackInputStream.read(bom, 0, bom.length);
-
- // Read ahead four bytes and check for BOM marks.
- if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF)) {
- encoding = "UTF-8";
- unread = n - 3;
- } else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) {
- encoding = "UTF-16BE";
- unread = n - 2;
- } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) {
- encoding = "UTF-16LE";
- unread = n - 2;
- } else if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00) && (bom[2] == (byte) 0xFE)
- && (bom[3] == (byte) 0xFF)) {
- encoding = "UTF-32BE";
- unread = n - 4;
- } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) && (bom[2] == (byte) 0x00)
- && (bom[3] == (byte) 0x00)) {
- encoding = "UTF-32LE";
- unread = n - 4;
- } else {
- unread = n;
- }
-
- if (unread > 0) {
- pushbackInputStream.unread(bom, (n - unread), unread);
- } else if (unread < -1) {
- pushbackInputStream.unread(bom, 0, 0);
- }
-
- inputStream = pushbackInputStream;
- }
-
- final InputStreamReader inputStreamReader;
- if (encoding == null) {
- inputStreamReader = new InputStreamReader(inputStream);
- } else {
- inputStreamReader = new InputStreamReader(inputStream, encoding);
- }
- return inputStreamReader;
- } catch (IOException e) {
- throw new IllegalStateException(e);
- }
- }
-
- public static Reader getReader(File file, String encoding) throws IllegalStateException {
- final InputStream inputStream;
- try {
- inputStream = new BufferedInputStream(new FileInputStream(file));
- } catch (IOException e) {
- throw new IllegalStateException(e);
- }
- return getReader(inputStream, encoding);
- }
-
- public static String readInputStreamAsString(InputStream inputStream, String encoding) throws IllegalStateException {
- Reader reader = getReader(inputStream, encoding);
- return readAsString(reader);
- }
-
- public static String readFileAsString(File file, String encoding) throws IllegalStateException {
- Reader br = getReader(file, encoding);
- return readAsString(br);
- }
-
- public static String readAsString(Reader reader) throws IllegalStateException {
- final BufferedReader br = getBufferedReader(reader);
- try {
- StringBuilder sb = new StringBuilder();
- boolean firstLine = true;
- for (String line = br.readLine(); line != null; line = br.readLine()) {
- if (firstLine) {
- firstLine = false;
- } else {
- sb.append('\n');
- }
- sb.append(line);
- }
- return sb.toString();
- } catch (Exception e) {
- throw new IllegalStateException(e);
- } finally {
- safeClose(br, reader);
- }
- }
-
- public static void safeClose(Object... objects) {
- boolean debugEnabled = logger.isDebugEnabled();
-
- if (objects == null || objects.length == 0) {
- logger.info("safeClose(...) was invoked with null or empty array: {}", objects);
- return;
- }
-
- for (Object obj : objects) {
- if (obj != null) {
- if (debugEnabled) {
- logger.debug("Trying to safely close {}", obj);
- }
-
- if (obj instanceof Flushable) {
- try {
- ((Flushable) obj).flush();
- } catch (Exception e) {
- if (debugEnabled) {
- logger.debug("Flushing Flushable failed", e);
- }
- }
- }
-
- if (obj instanceof Closeable) {
- try {
- ((Closeable) obj).close();
- } catch (IOException e) {
- if (debugEnabled) {
- logger.debug("Closing Closeable failed", e);
- }
- }
- } else if (obj instanceof Connection) {
- try {
- ((Connection) obj).close();
- } catch (Exception e) {
- if (debugEnabled) {
- logger.debug("Closing Connection failed", e);
- }
- }
- } else if (obj instanceof Statement) {
- try {
- ((Statement) obj).close();
- } catch (Exception e) {
- if (debugEnabled) {
- logger.debug("Closing Statement failed", e);
- }
- }
- } else if (obj instanceof ResultSet) {
- try {
- ((ResultSet) obj).close();
- } catch (Exception e) {
- if (debugEnabled) {
- logger.debug("Closing ResultSet failed", e);
- }
- }
- } else {
- logger.info("obj was neither Closeable, Connection, Statement or ResultSet.");
-
- try {
- Method method = obj.getClass().getMethod("close", new Class[0]);
- if (method == null) {
- logger.info("obj did not have a close() method, ignoring");
- } else {
- method.setAccessible(true);
- method.invoke(obj);
- }
- } catch (InvocationTargetException e) {
- logger.warn("Invoking close() by reflection threw exception", e);
- } catch (Exception e) {
- logger.warn("Could not invoke close() by reflection", e);
- }
- }
- }
-
- }
- }
-
- public static BufferedWriter getBufferedWriter(File file, String encoding) throws IllegalStateException {
- Writer writer = getWriter(file, encoding);
- return new BufferedWriter(writer);
- }
-
- public static BufferedReader getBufferedReader(File file, String encoding) throws IllegalStateException {
- Reader reader = getReader(file, encoding);
- return new BufferedReader(reader);
- }
-
- public static BufferedReader getBufferedReader(InputStream inputStream, String encoding) throws IllegalStateException {
- Reader reader = getReader(inputStream, encoding);
- return new BufferedReader(reader);
- }
-
- public static Reader getReader(File file) throws IllegalStateException {
- return getReader(file, DEFAULT_ENCODING);
- }
-
- public static String readFileAsString(File file) throws IllegalStateException {
- return readFileAsString(file, DEFAULT_ENCODING);
- }
-
- public static BufferedWriter getBufferedWriter(File file) throws IllegalStateException {
- return getBufferedWriter(file, DEFAULT_ENCODING);
- }
-
- public static Writer getWriter(File file) throws IllegalStateException {
- return getWriter(file, DEFAULT_ENCODING);
- }
-
- public static void writeString(OutputStream outputStream, String string) throws IllegalStateException {
- writeString(outputStream, string, DEFAULT_ENCODING);
- }
-
- public static void writeString(OutputStream outputStream, String string, String encoding) throws IllegalStateException {
- final Writer writer = getWriter(outputStream, encoding);
- writeString(writer, string, encoding);
- }
-
- public static void writeString(Writer writer, String string) throws IllegalStateException {
- writeString(writer, string, DEFAULT_ENCODING);
- }
-
- public static void writeString(Writer writer, String string, String encoding) throws IllegalStateException {
- try {
- writer.write(string);
- } catch (Exception e) {
- throw new IllegalStateException(e);
- } finally {
- safeClose(writer);
- }
- }
-
- public static void writeStringAsFile(File file, String string) throws IllegalStateException {
- writeStringAsFile(file, string, DEFAULT_ENCODING);
- }
-
- public static void writeStringAsFile(File file, String string, String encoding) throws IllegalStateException {
- final BufferedWriter bw = getBufferedWriter(file, encoding);
- writeString(bw, string, encoding);
- }
-
- public static BufferedReader getBufferedReader(File file) throws IllegalStateException {
- return getBufferedReader(file, DEFAULT_ENCODING);
- }
-
- public static void copy(Reader reader, Writer writer) throws IllegalStateException {
- final BufferedReader bufferedReader = getBufferedReader(reader);
- try {
- boolean firstLine = true;
- for (String line = bufferedReader.readLine(); line != null; line = bufferedReader.readLine()) {
- if (firstLine) {
- firstLine = false;
- } else {
- writer.write('\n');
- }
- writer.write(line);
- }
- } catch (IOException e) {
- throw new IllegalStateException(e);
- }
- }
-
- public static BufferedReader getBufferedReader(Reader reader) {
- if (reader instanceof BufferedReader) {
- return (BufferedReader) reader;
- }
- return new BufferedReader(reader);
- }
-
- public static void copy(InputStream fromStream, OutputStream toStream) throws IllegalStateException {
- try {
- byte[] buffer = new byte[1024 * 32];
- for (int read = fromStream.read(buffer); read != -1; read = fromStream.read(buffer)) {
- toStream.write(buffer, 0, read);
- }
- } catch (IOException e) {
- throw new IllegalStateException(e);
- }
- }
-
- public static void copy(File from, File to) throws IllegalStateException {
- assert from.exists();
-
- final InputStream fromStream = getInputStream(from);
- final OutputStream toStream = getOutputStream(to);
-
- try {
- copy(fromStream, toStream);
- } finally {
- safeClose(fromStream, toStream);
- }
- }
-
- public static OutputStream getOutputStream(File file) throws IllegalStateException {
- return getOutputStream(file, false);
- }
-
- public static OutputStream getOutputStream(File file, boolean append) {
- try {
- return new BufferedOutputStream(new FileOutputStream(file, append));
- } catch (FileNotFoundException e) {
- throw new IllegalStateException(e);
- }
- }
-
- public static InputStream getInputStream(File file) throws IllegalStateException {
- try {
- return new BufferedInputStream(new FileInputStream(file));
- } catch (FileNotFoundException e) {
- throw new IllegalStateException(e);
- }
- }
-
- public static byte[] readAsBytes(InputStream inputStream) {
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try {
- copy(inputStream, baos);
- } finally {
- safeClose(inputStream);
- }
- return baos.toByteArray();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/FileResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/FileResource.java b/core/src/main/java/org/eobjects/metamodel/util/FileResource.java
deleted file mode 100644
index f713e0c..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/FileResource.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/**
- * 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.util;
-
-import java.io.File;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Serializable;
-
-/**
- * {@link File} based {@link Resource} implementation.
- */
-public class FileResource implements Resource, Serializable {
-
- private static final long serialVersionUID = 1L;
- private final File _file;
-
- public FileResource(String filename) {
- _file = new File(filename);
- }
-
- public FileResource(File file) {
- _file = file;
- }
-
- @Override
- public String toString() {
- return "FileResource[" + _file.getPath() + "]";
- }
-
- @Override
- public String getName() {
- return _file.getName();
- }
-
- @Override
- public boolean isReadOnly() {
- if (!isExists()) {
- return false;
- }
- boolean canWrite = _file.canWrite();
- return !canWrite;
- }
-
- @Override
- public void write(Action<OutputStream> writeCallback) throws ResourceException {
- final OutputStream out = FileHelper.getOutputStream(_file);
- try {
- writeCallback.run(out);
- } catch (Exception e) {
- throw new ResourceException(this, "Error occurred in write callback", e);
- } finally {
- FileHelper.safeClose(out);
- }
- }
-
- @Override
- public void append(Action<OutputStream> appendCallback) {
- final OutputStream out = FileHelper.getOutputStream(_file, true);
- try {
- appendCallback.run(out);
- } catch (Exception e) {
- throw new ResourceException(this, "Error occurred in append callback", e);
- } finally {
- FileHelper.safeClose(out);
- }
- }
-
- @Override
- public void read(Action<InputStream> readCallback) {
- final InputStream in = read();
- try {
- readCallback.run(in);
- } catch (Exception e) {
- throw new ResourceException(this, "Error occurred in read callback", e);
- } finally {
- FileHelper.safeClose(in);
- }
- }
-
- @Override
- public <E> E read(Func<InputStream, E> readCallback) {
- final InputStream in = read();
- try {
- final E result = readCallback.eval(in);
- return result;
- } catch (Exception e) {
- throw new ResourceException(this, "Error occurred in read callback", e);
- } finally {
- FileHelper.safeClose(in);
- }
- }
-
- public File getFile() {
- return _file;
- }
-
- @Override
- public boolean isExists() {
- return _file.exists();
- }
-
- @Override
- public long getSize() {
- return _file.length();
- }
-
- @Override
- public long getLastModified() {
- final long lastModified = _file.lastModified();
- if (lastModified == 0) {
- return -1;
- }
- return lastModified;
- }
-
- @Override
- public InputStream read() throws ResourceException {
- final InputStream in = FileHelper.getInputStream(_file);
- return in;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/FormatHelper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/FormatHelper.java b/core/src/main/java/org/eobjects/metamodel/util/FormatHelper.java
deleted file mode 100644
index 3b954dc..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/FormatHelper.java
+++ /dev/null
@@ -1,273 +0,0 @@
-/**
- * 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.util;
-
-import java.text.DateFormat;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
-import java.text.NumberFormat;
-import java.text.ParseException;
-import java.util.Date;
-
-import org.eobjects.metamodel.query.QueryParameter;
-import org.eobjects.metamodel.schema.ColumnType;
-
-/**
- * Helper class for formatting
- */
-public final class FormatHelper {
-
- /**
- * Creates a uniform number format which is similar to that of eg. Java
- * doubles. The format will not include thousand separators and it will use
- * a dot as a decimal separator.
- *
- * @return
- */
- public static NumberFormat getUiNumberFormat() {
- DecimalFormatSymbols symbols = new DecimalFormatSymbols();
- symbols.setDecimalSeparator('.');
- DecimalFormat format = new DecimalFormat("###.##", symbols);
- format.setGroupingUsed(false);
- return format;
- }
-
- public static NumberFormat getSqlNumberFormat() {
- DecimalFormatSymbols symbols = new DecimalFormatSymbols();
- symbols.setDecimalSeparator('.');
- DecimalFormat format = new DecimalFormat("###.##", symbols);
- format.setGroupingUsed(false);
- format.setMaximumFractionDigits(100);
- return format;
- }
-
- public static String formatSqlBoolean(ColumnType columnType, boolean b) {
- if (columnType == ColumnType.BIT) {
- if (b) {
- return "1";
- } else {
- return "0";
- }
- } else {
- if (b) {
- return "TRUE";
- } else {
- return "FALSE";
- }
- }
- }
-
- /**
- * Formats a date according to a specific column type (DATE, TIME or
- * TIMESTAMP)
- *
- * @param columnType
- * the column type
- * @param date
- * the date value
- * @return
- */
- public static String formatSqlTime(ColumnType columnType, Date date) {
- return formatSqlTime(columnType, date, true);
- }
-
- /**
- * Formats a date according to a specific column type (DATE, TIME or
- * TIMESTAMP)
- *
- * @param columnType
- * the column type
- * @param date
- * the date value
- * @param typeCastDeclaration
- * whether or not to include a type cast declaration
- * @param beforeDateLiteral
- * before date literal
- * @param afterDateLiteral
- * after date literal
- * @return
- */
- public static String formatSqlTime(ColumnType columnType, Date date,
- boolean typeCastDeclaration, String beforeDateLiteral,
- String afterDateLiteral) {
- if (columnType == null) {
- throw new IllegalArgumentException("Column type cannot be null");
- }
- final DateFormat format;
- final String typePrefix;
- switch (columnType) {
- case DATE:
- format = DateUtils.createDateFormat("yyyy-MM-dd");
- typePrefix = "DATE";
- break;
- case TIME:
- format = DateUtils.createDateFormat("HH:mm:ss");
- typePrefix = "TIME";
- break;
- case TIMESTAMP:
- format = DateUtils.createDateFormat("yyyy-MM-dd HH:mm:ss");
- typePrefix = "TIMESTAMP";
- break;
- default:
- throw new IllegalArgumentException(
- "Cannot format time value of type: " + columnType);
- }
-
- if (typeCastDeclaration) {
- return typePrefix + " " + beforeDateLiteral + format.format(date) + afterDateLiteral;
- } else {
- return format.format(date);
- }
- }
-
- /**
- * Formats a date according to a specific column type (DATE, TIME or TIMESTAMP). For backward compatibility.
- * @param columnType
- * @param date
- * @param typeCastDeclaration
- * @return
- */
- public static String formatSqlTime(ColumnType columnType, Date date, boolean typeCastDeclaration) {
- return formatSqlTime(columnType, date, typeCastDeclaration, "\'", "\'");
- }
-
- /**
- * Parses a SQL string representation of a time based value
- *
- * @param type
- * @param value
- * @return
- */
- public static Date parseSqlTime(ColumnType columnType, String value) {
- final String[] formats;
- switch (columnType) {
- case DATE:
- formats = new String[] { "yyyy-MM-dd", };
- break;
- case TIME:
- formats = new String[] { "HH:mm:ss", "HH:mm" };
- break;
- case TIMESTAMP:
- formats = new String[] { "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm",
- "yyyy-MM-dd" };
- break;
- default:
- throw new IllegalArgumentException(
- "Cannot parse time value of type: " + columnType);
- }
-
- for (String format : formats) {
- try {
- DateFormat dateFormat = DateUtils.createDateFormat(format);
- return dateFormat.parse(value);
- } catch (ParseException e) {
- // proceed to next format
- }
- }
-
- throw new IllegalArgumentException("String value '" + value
- + "' not parseable as a " + columnType);
- }
-
- public static String formatSqlValue(ColumnType columnType, Object value) {
- if (value == null) {
- return "NULL";
- }
- if (value instanceof QueryParameter) {
- return value.toString();
- }
- if (value.getClass().isArray()) {
- value = CollectionUtils.toList(value);
- }
- if (value instanceof Iterable) {
- StringBuilder sb = new StringBuilder();
- sb.append('(');
- for (Object item : (Iterable<?>) value) {
- if (sb.length() > 1) {
- sb.append(" , ");
- }
- sb.append(formatSqlValue(columnType, item));
- }
- sb.append(')');
- return sb.toString();
- } else if (isNumber(columnType, value)) {
- NumberFormat numberFormat = getSqlNumberFormat();
- Number n = NumberComparator.toNumber(value);
- if (n == null) {
- throw new IllegalStateException("Could not convert " + value
- + " to number");
- }
- String numberString = numberFormat.format(n);
- return numberString;
- } else if (isBoolean(columnType, value)) {
- Boolean b = BooleanComparator.toBoolean(value);
- if (b == null) {
- throw new IllegalStateException("Could not convert " + value
- + " to boolean");
- }
- String booleanString = formatSqlBoolean(columnType, b);
- return booleanString;
- } else if (isTimeBased(columnType, value)) {
- Date date = TimeComparator.toDate(value);
- if (date == null) {
- throw new IllegalStateException("Could not convert " + value
- + " to date");
- }
- String timeString = formatSqlTime(columnType, date);
- return timeString;
- } else if (isLiteral(columnType, value)) {
- return '\'' + value.toString() + '\'';
- } else {
- if (columnType == null) {
- throw new IllegalStateException("Value type not supported: "
- + value);
- }
- throw new IllegalStateException("Column type not supported: "
- + columnType);
- }
- }
-
- private static boolean isTimeBased(ColumnType columnType, Object operand) {
- if (columnType == null) {
- return TimeComparator.isTimeBased(operand);
- }
- return columnType.isTimeBased();
- }
-
- private static boolean isBoolean(ColumnType columnType, Object operand) {
- if (columnType == null) {
- return operand instanceof Boolean;
- }
- return columnType.isBoolean();
- }
-
- private static boolean isNumber(ColumnType columnType, Object operand) {
- if (columnType == null) {
- return operand instanceof Number;
- }
- return columnType.isNumber();
- }
-
- private static boolean isLiteral(ColumnType columnType, Object operand) {
- if (columnType == null) {
- return operand instanceof String;
- }
- return columnType.isLiteral();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/Func.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/Func.java b/core/src/main/java/org/eobjects/metamodel/util/Func.java
deleted file mode 100644
index e17f3cf..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/Func.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * 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.util;
-
-/**
- * Represents an abstract function, which is an executable piece of
- * functionality that has an input and an output. A {@link Func} has a return
- * type, unlike an {@link Action}.
- *
- * @author Kasper Sørensen
- *
- * @param <I>
- * the input type
- * @param <O>
- * the output type
- */
-public interface Func<I, O> {
-
- /**
- * Evaluates an element and transforms it using this function.
- *
- * @param arg
- * the input given to the function
- * @return the output result of the function
- */
- public O eval(I arg);
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/HasName.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/HasName.java b/core/src/main/java/org/eobjects/metamodel/util/HasName.java
deleted file mode 100644
index 647848f..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/HasName.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * 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.util;
-
-/**
- * Represents anything with a (String based) name.
- *
- * @author Kasper Sørensen
- */
-public interface HasName {
-
- public String getName();
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/HasNameMapper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/HasNameMapper.java b/core/src/main/java/org/eobjects/metamodel/util/HasNameMapper.java
deleted file mode 100644
index 3b22a32..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/HasNameMapper.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.util;
-
-import java.io.Serializable;
-
-/**
- * {@link Func} useful for mapping {@link HasName} instances to names, using
- * {@link CollectionUtils#map(Object[], Func)} and
- * {@link CollectionUtils#map(Iterable, Func)}.
- *
- * @author Kasper Sørensen
- */
-public final class HasNameMapper implements Func<HasName, String>, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public String eval(HasName arg) {
- return arg.getName();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/ImmutableDate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/ImmutableDate.java b/core/src/main/java/org/eobjects/metamodel/util/ImmutableDate.java
deleted file mode 100644
index 4ed34a6..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/ImmutableDate.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * 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.util;
-
-import java.text.DateFormat;
-import java.util.Date;
-
-/**
- * A Date implementation that is immutable and has a predictable
- * (locale-indifferent) toString() method.
- *
- * @author Kasper Sørensen
- *
- * @deprecated MetaModel is not a Date API, use Joda time or live with
- * java.util.Date.
- */
-@Deprecated
-public final class ImmutableDate extends Date {
-
- private static final long serialVersionUID = 1L;
-
- public ImmutableDate(long time) {
- super(time);
- }
-
- public ImmutableDate(Date date) {
- super(date.getTime());
- }
-
- /**
- * This mutator will throw an {@link UnsupportedOperationException}, since
- * the date is ummutable.
- *
- * @param time
- * new time to set
- */
- @Override
- public void setTime(long time) {
- throw new UnsupportedOperationException("setTime(...) is not allowed");
- }
-
- @Override
- public String toString() {
- DateFormat format = DateUtils.createDateFormat();
- return format.format(this);
- }
-}
[22/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/MetaModelTestCase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/MetaModelTestCase.java b/core/src/test/java/org/eobjects/metamodel/MetaModelTestCase.java
deleted file mode 100644
index 6f3e5b1..0000000
--- a/core/src/test/java/org/eobjects/metamodel/MetaModelTestCase.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/**
- * 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;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.easymock.EasyMock;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.EmptyDataSet;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.SimpleDataSetHeader;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableRelationship;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.TableType;
-
-/**
- * Convenient super-class to use for unittesting
- */
-public abstract class MetaModelTestCase extends TestCase {
-
- public static final String COLUMN_CONTRIBUTOR_COUNTRY = "country";
- public static final String COLUMN_CONTRIBUTOR_NAME = "name";
- public static final String COLUMN_CONTRIBUTOR_CONTRIBUTOR_ID = "contributor_id";
-
- public static final String COLUMN_PROJECT_PROJECT_ID = "project_id";
- public static final String COLUMN_PROJECT_NAME = "name";
- public static final String COLUMN_PROJECT_LINES_OF_CODE = "lines_of_code";
- public static final String COLUMN_PROJECT_PARENT_PROJECT_ID = "parent_project_id";
-
- public static final String COLUMN_ROLE_PROJECT_ID = "project_id";
- public static final String COLUMN_ROLE_CONTRIBUTOR_ID = "contributor_id";
- public static final String COLUMN_ROLE_ROLE_NAME = "name";
-
- public static final String COLUMN_PROJECT_CONTRIBUTOR_CONTRIBUTOR = "contributor";
- public static final String COLUMN_PROJECT_CONTRIBUTOR_ROLE = "role";
- public static final String COLUMN_PROJECT_CONTRIBUTOR_PROJECT = "project";
-
- public static final String TABLE_PROJECT_CONTRIBUTOR = "project_contributor";
- public static final String TABLE_ROLE = "role";
- public static final String TABLE_PROJECT = "project";
- public static final String TABLE_CONTRIBUTOR = "contributor";
-
- /**
- * Creates an example schema with three tables and a view:
- * <ul>
- * <li>contributor[contributor_id,name,country] (TABLE)</li>
- * <li>project[project_id,name,lines_of_code,parent_project_id] (TABLE)</li>
- * <li>role[contributor_id,project_id,role_name] (TABLE)</li>
- * <li>project_contributor[contributor,project,role] (VIEW)</li>
- * </ul>
- * The example schema is good for testing purposes and possess various
- * features of the schema model:
- * <ul>
- * <li>Relations between tables: one-Contributor-to-many-Role's and
- * many-Role's-to-one-Project</li>
- * <li>Recursive relations: A project can have a parent project</li>
- * <li>Views: The ProjectContributor view</li>
- * </ul>
- */
- protected Schema getExampleSchema() {
- MutableSchema schema = new MutableSchema("MetaModelSchema");
-
- MutableTable table1 = new MutableTable(TABLE_CONTRIBUTOR, TableType.TABLE, schema);
- Column column1 = new MutableColumn(COLUMN_CONTRIBUTOR_CONTRIBUTOR_ID, ColumnType.INTEGER, table1, 0, false)
- .setIndexed(true).setPrimaryKey(true);
- Column column2 = new MutableColumn(COLUMN_CONTRIBUTOR_NAME, ColumnType.VARCHAR, table1, 1, false);
- Column column3 = new MutableColumn(COLUMN_CONTRIBUTOR_COUNTRY, ColumnType.VARCHAR, table1, 2, true);
- table1.setColumns(column1, column2, column3);
-
- MutableTable table2 = new MutableTable(TABLE_PROJECT, TableType.TABLE, schema);
- Column column4 = new MutableColumn(COLUMN_PROJECT_PROJECT_ID, ColumnType.INTEGER, table2, 0, false)
- .setPrimaryKey(true);
- Column column5 = new MutableColumn(COLUMN_PROJECT_NAME, ColumnType.VARCHAR, table2, 1, false);
- Column column6 = new MutableColumn(COLUMN_PROJECT_LINES_OF_CODE, ColumnType.BIGINT, table2, 2, true);
- Column column7 = new MutableColumn(COLUMN_PROJECT_PARENT_PROJECT_ID, ColumnType.INTEGER, table2, 3, true);
- table2.setColumns(column4, column5, column6, column7);
-
- MutableTable table3 = new MutableTable(TABLE_ROLE, TableType.TABLE, schema);
- Column column8 = new MutableColumn(COLUMN_ROLE_CONTRIBUTOR_ID, ColumnType.INTEGER, table3, 0, false)
- .setPrimaryKey(true);
- Column column9 = new MutableColumn(COLUMN_ROLE_PROJECT_ID, ColumnType.INTEGER, table3, 1, false)
- .setPrimaryKey(true);
- Column column10 = new MutableColumn(COLUMN_ROLE_ROLE_NAME, ColumnType.VARCHAR, table3, 2, false);
- table3.setColumns(column8, column9, column10);
-
- MutableTable table4 = new MutableTable(TABLE_PROJECT_CONTRIBUTOR, TableType.VIEW, schema);
- Column column11 = new MutableColumn(COLUMN_PROJECT_CONTRIBUTOR_CONTRIBUTOR, ColumnType.VARCHAR, table4, 0,
- false);
- Column column12 = new MutableColumn(COLUMN_PROJECT_CONTRIBUTOR_PROJECT, ColumnType.VARCHAR, table4, 1, false);
- Column column13 = new MutableColumn(COLUMN_PROJECT_CONTRIBUTOR_ROLE, ColumnType.VARCHAR, table4, 2, false);
- ArrayList<Column> columnList = new ArrayList<Column>();
- columnList.add(column11);
- columnList.add(column12);
- columnList.add(column13);
- table4.setColumns(columnList);
-
- // one-Contributor-to-many-Role's
- MutableRelationship.createRelationship(new Column[] { column1 }, new Column[] { column8 });
-
- // one-Project-to-many-Role's
- MutableRelationship.createRelationship(new Column[] { column4 }, new Column[] { column9 });
-
- // view relation [contributor -> contributor_name]
- MutableRelationship.createRelationship(new Column[] { column2 }, new Column[] { column11 });
-
- // view relation [project -> project_name]
- MutableRelationship.createRelationship(new Column[] { column5 }, new Column[] { column12 });
-
- // view relation [role -> role_name]
- MutableRelationship.createRelationship(new Column[] { column10 }, new Column[] { column13 });
-
- schema.setTables(table1, table2, table3, table4);
- return schema;
- }
-
- protected static DataSet createDataSet(SelectItem[] selectItems, List<Object[]> data) {
- if (data.isEmpty()) {
- return new EmptyDataSet(selectItems);
- }
-
- SimpleDataSetHeader header = new SimpleDataSetHeader(selectItems);
-
- List<Row> rows = new ArrayList<Row>();
- for (Object[] objects : data) {
- rows.add(new DefaultRow(header, objects));
- }
- return new InMemoryDataSet(header, rows);
- }
-
- private List<Object> _mocks = new ArrayList<Object>();
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- _mocks.clear();
- }
-
- public <T extends Object> T createMock(Class<T> clazz) {
- T mock = EasyMock.createMock(clazz);
- _mocks.add(mock);
- return mock;
- }
-
- public void verifyMocks() {
- EasyMock.verify(_mocks.toArray());
- }
-
- public void replayMocks() {
- EasyMock.replay(_mocks.toArray());
- }
-
- public void assertEquals(DataSet ds1, DataSet ds2) {
- assertEquals(Arrays.toString(ds1.getSelectItems()), Arrays.toString(ds2.getSelectItems()));
- boolean ds1next = true;
- while (ds1next) {
- ds1next = ds1.next();
- boolean ds2next = ds2.next();
- assertEquals("DataSet 1 next=" + ds1next, ds1next, ds2next);
- if (ds1next) {
- Row row1 = ds1.getRow();
- Row row2 = ds2.getRow();
- assertEquals(row1, row2);
- }
- }
- }
-
- protected File getTestResourceAsFile(String filename) {
- return new File("src/test/resources/" + filename);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/MockDataContext.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/MockDataContext.java b/core/src/test/java/org/eobjects/metamodel/MockDataContext.java
deleted file mode 100644
index 5d95034..0000000
--- a/core/src/test/java/org/eobjects/metamodel/MockDataContext.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * 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;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eobjects.metamodel.data.CachingDataSetHeader;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetHeader;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.EmptyDataSet;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-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.Table;
-
-public class MockDataContext extends QueryPostprocessDataContext {
-
- private final String _schemaName;
- private final String _tableName;
- private final String _value;
-
- public MockDataContext(String schemaName, String tableName, String value) {
- _schemaName = schemaName;
- _tableName = tableName;
- _value = value;
- }
-
- @Override
- protected Schema getMainSchema() throws MetaModelException {
-
- final MutableSchema schema = new MutableSchema(_schemaName);
- final MutableTable primaryTable = new MutableTable(_tableName).setSchema(schema);
- primaryTable.addColumn(new MutableColumn("foo").setColumnNumber(0).setType(ColumnType.VARCHAR).setTable(primaryTable));
- primaryTable.addColumn(new MutableColumn("bar").setColumnNumber(1).setType(ColumnType.VARCHAR).setTable(primaryTable));
- primaryTable.addColumn(new MutableColumn("baz").setColumnNumber(2).setType(ColumnType.VARCHAR).setTable(primaryTable));
-
- final MutableTable emptyTable = new MutableTable("an_empty_table").setSchema(schema);
- emptyTable.addColumn(new MutableColumn("foo").setColumnNumber(0).setType(ColumnType.VARCHAR).setTable(emptyTable));
- emptyTable.addColumn(new MutableColumn("bar").setColumnNumber(1).setType(ColumnType.VARCHAR).setTable(emptyTable));
-
- schema.addTable(primaryTable);
- schema.addTable(emptyTable);
-
- return schema;
- }
-
- @Override
- protected String getMainSchemaName() throws MetaModelException {
- return _schemaName;
- }
-
- @Override
- protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
- if (_tableName.equals(table.getName())) {
- final SelectItem[] allSelectItems = MetaModelHelper.createSelectItems(table.getColumns());
- final DataSetHeader header = new CachingDataSetHeader(allSelectItems);
- final List<Row> data = new ArrayList<Row>();
- data.add(new DefaultRow(header, new Object[] { "1", "hello", "world" }, null));
- data.add(new DefaultRow(header, new Object[] { "2", _value, "world" }, null));
- data.add(new DefaultRow(header, new Object[] { "3", "hi", _value }, null));
- data.add(new DefaultRow(header, new Object[] { "4", "yo", "world" }, null));
-
- DataSet ds = new InMemoryDataSet(header, data);
-
- SelectItem[] columnSelectItems = MetaModelHelper.createSelectItems(columns);
- ds = MetaModelHelper.getSelection(columnSelectItems, ds);
-
- return ds;
- } else if ("an_empty_table".equals(table.getName())) {
- return new EmptyDataSet(columns);
- }
- throw new UnsupportedOperationException();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/MockUpdateableDataContext.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/MockUpdateableDataContext.java b/core/src/test/java/org/eobjects/metamodel/MockUpdateableDataContext.java
deleted file mode 100644
index 60f3d95..0000000
--- a/core/src/test/java/org/eobjects/metamodel/MockUpdateableDataContext.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/**
- * 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;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.data.CachingDataSetHeader;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.EmptyDataSet;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.delete.AbstractRowDeletionBuilder;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.AbstractRowInsertionBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-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.Table;
-
-public class MockUpdateableDataContext extends QueryPostprocessDataContext implements UpdateableDataContext {
-
- private final List<Object[]> _values = new ArrayList<Object[]>();
-
- private final MutableTable _table;
- private final MutableSchema _schema;
-
- public MockUpdateableDataContext() {
- _values.add(new Object[] { "1", "hello" });
- _values.add(new Object[] { "2", "there" });
- _values.add(new Object[] { "3", "world" });
-
- _table = new MutableTable("table");
- _table.addColumn(new MutableColumn("foo", ColumnType.VARCHAR).setTable(_table).setColumnNumber(0));
- _table.addColumn(new MutableColumn("bar", ColumnType.VARCHAR).setTable(_table).setColumnNumber(1));
- _schema = new MutableSchema("schema", _table);
- _table.setSchema(_schema);
- }
-
- public MutableTable getTable() {
- return _table;
- }
-
- @Override
- protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
-
- List<Row> rows = new ArrayList<Row>();
- SelectItem[] items = MetaModelHelper.createSelectItems(columns);
- CachingDataSetHeader header = new CachingDataSetHeader(items);
-
- for (final Object[] values : _values) {
- Object[] rowValues = new Object[columns.length];
- for (int i = 0; i < columns.length; i++) {
- int columnNumber = columns[i].getColumnNumber();
- rowValues[i] = values[columnNumber];
- }
- rows.add(new DefaultRow(header, rowValues));
- }
-
- if (rows.isEmpty()) {
- return new EmptyDataSet(items);
- }
- return new InMemoryDataSet(header, rows);
- }
-
- @Override
- protected String getMainSchemaName() throws MetaModelException {
- return _schema.getName();
- }
-
- @Override
- protected Schema getMainSchema() throws MetaModelException {
- return _schema;
- }
-
- @Override
- public void executeUpdate(UpdateScript update) {
- update.run(new AbstractUpdateCallback(this) {
-
- @Override
- public boolean isDeleteSupported() {
- return true;
- }
-
- @Override
- public RowDeletionBuilder deleteFrom(Table table) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException {
- return new AbstractRowDeletionBuilder(table) {
- @Override
- public void execute() throws MetaModelException {
- delete(getWhereItems());
- }
- };
- }
-
- @Override
- public RowInsertionBuilder insertInto(Table table) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException {
- return new AbstractRowInsertionBuilder<UpdateCallback>(this, table) {
-
- @Override
- public void execute() throws MetaModelException {
- Object[] values = toRow().getValues();
- _values.add(values);
- }
- };
- }
-
- @Override
- public boolean isDropTableSupported() {
- return false;
- }
-
- @Override
- public boolean isCreateTableSupported() {
- return false;
- }
-
- @Override
- public TableDropBuilder dropTable(Table table) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public TableCreationBuilder createTable(Schema schema, String name) throws IllegalArgumentException,
- IllegalStateException {
- throw new UnsupportedOperationException();
- }
- });
- }
-
- private void delete(List<FilterItem> whereItems) {
- final SelectItem[] selectItems = MetaModelHelper.createSelectItems(_table.getColumns());
- final CachingDataSetHeader header = new CachingDataSetHeader(selectItems);
- for (Iterator<Object[]> it = _values.iterator(); it.hasNext();) {
- Object[] values = (Object[]) it.next();
- DefaultRow row = new DefaultRow(header, values);
- boolean delete = true;
- for (FilterItem filterItem : whereItems) {
- if (!filterItem.evaluate(row)) {
- delete = false;
- break;
- }
- }
- if (delete) {
- it.remove();
- }
- }
- }
-
- public List<Object[]> getValues() {
- return _values;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/QueryPostprocessDataContextTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/QueryPostprocessDataContextTest.java b/core/src/test/java/org/eobjects/metamodel/QueryPostprocessDataContextTest.java
deleted file mode 100644
index 0562bc5..0000000
--- a/core/src/test/java/org/eobjects/metamodel/QueryPostprocessDataContextTest.java
+++ /dev/null
@@ -1,861 +0,0 @@
-/**
- * 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;
-
-import java.nio.channels.UnsupportedAddressTypeException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import javax.swing.table.TableModel;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetTableModel;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.GroupByItem;
-import org.eobjects.metamodel.query.JoinType;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.OrderByItem;
-import org.eobjects.metamodel.query.QueryParameter;
-import org.eobjects.metamodel.query.OrderByItem.Direction;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-public class QueryPostprocessDataContextTest extends MetaModelTestCase {
-
- private final Schema schema = getExampleSchema();
- private final Table table1 = schema.getTableByName(TABLE_CONTRIBUTOR);
- private final Table table2 = schema.getTableByName(TABLE_ROLE);
-
- public void testAggregateQueryNoWhereClause() throws Exception {
- MockDataContext dc = new MockDataContext("sch", "tab", "1");
- Table table = dc.getDefaultSchema().getTables()[0];
- assertSingleRowResult("Row[values=[4]]", dc.query().from(table).selectCount().execute());
- }
-
- public void testAggregateQueryRegularWhereClause() throws Exception {
- MockDataContext dc = new MockDataContext("sch", "tab", "1");
- Table table = dc.getDefaultSchema().getTables()[0];
- assertSingleRowResult("Row[values=[3]]", dc.query().from(table).selectCount().where("baz").eq("world")
- .execute());
- }
-
- public void testAggregateQueryWhereClauseExcludingAll() throws Exception {
- MockDataContext dc = new MockDataContext("sch", "tab", "1");
- assertSingleRowResult("Row[values=[0]]",
- dc.query().from("tab").selectCount().where("baz").eq("non_existing_value").execute());
- }
-
- public void testMixedAggregateAndRawQueryOnEmptyTable() throws Exception {
- MockDataContext dc = new MockDataContext("sch", "tab", "1");
- Table emptyTable = dc.getTableByQualifiedLabel("an_empty_table");
-
- assertSingleRowResult("Row[values=[0, null]]", dc.query().from(emptyTable).selectCount().and("foo").execute());
- }
-
- private void assertSingleRowResult(String rowStr, DataSet ds) {
- assertTrue("DataSet had no rows", ds.next());
- Row row = ds.getRow();
- assertEquals(rowStr, row.toString());
- assertFalse("DataSet had more than a single row!", ds.next());
- ds.close();
- }
-
- public void testMixedAggregateAndRawQuery() throws Exception {
- MockDataContext dc = new MockDataContext("sch", "tab", "1");
- Table table = dc.getDefaultSchema().getTables()[0];
- Column[] columns = table.getColumns();
-
- Query query = dc.query().from(table).select(FunctionType.MAX, columns[0]).and(columns[1]).toQuery();
- assertEquals("SELECT MAX(tab.foo), tab.bar FROM sch.tab", query.toSql());
-
- DataSet ds = dc.executeQuery(query);
- assertTrue(ds.next());
- assertEquals("Row[values=[4, hello]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[4, 1]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[4, hi]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[4, yo]]", ds.getRow().toString());
- assertFalse(ds.next());
- }
-
- public void testSelectItemReferencesToFromItems() throws Exception {
- MockDataContext dc = new MockDataContext("sch", "tab", "1");
-
- Table table = dc.getDefaultSchema().getTables()[0];
-
- Query q = new Query();
- FromItem fromItem1 = q.from(table, "t1").getFromClause().getItem(0);
- FromItem fromItem2 = q.from(table, "t2").getFromClause().getItem(1);
- q.select(table.getColumnByName("foo"), fromItem1);
- q.select(table.getColumnByName("foo"), fromItem2);
- q.where(q.getSelectClause().getItem(0), OperatorType.EQUALS_TO, "2");
- assertEquals("SELECT t1.foo, t2.foo FROM sch.tab t1, sch.tab t2 WHERE t1.foo = '2'", q.toSql());
-
- DataSet ds = dc.executeQuery(q);
- SelectItem[] selectItems = ds.getSelectItems();
- assertEquals(2, selectItems.length);
- assertEquals("t1.foo", selectItems[0].toSql());
- assertEquals("t2.foo", selectItems[1].toSql());
- assertTrue(ds.next());
- assertEquals("Row[values=[2, 1]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[2, 2]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[2, 3]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[2, 4]]", ds.getRow().toString());
- assertFalse(ds.next());
- ds.close();
- }
-
- private DataContext getDataContext() {
- QueryPostprocessDataContext dataContext = new QueryPostprocessDataContext() {
-
- @Override
- public DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
- if (table == table1) {
- Column[] columns1 = table1.getColumns();
- SelectItem[] selectItems = new SelectItem[columns1.length];
- for (int i = 0; i < selectItems.length; i++) {
- SelectItem selectItem = new SelectItem(columns1[i]);
- selectItems[i] = selectItem;
- }
- List<Object[]> data = new ArrayList<Object[]>();
- data.add(new Object[] { 1, "kasper", "denmark" });
- data.add(new Object[] { 2, "asbjorn", "denmark" });
- data.add(new Object[] { 3, "johny", "israel" });
- data.add(new Object[] { 4, "daniel", "canada" });
- data.add(new Object[] { 5, "sasidhar", "unknown" });
- data.add(new Object[] { 6, "jesper", "denmark" });
- if (maxRows != -1) {
- for (int i = data.size() - 1; i >= maxRows; i--) {
- data.remove(i);
- }
- }
- return createDataSet(selectItems, data);
- } else if (table == table2) {
- Column[] columns2 = table2.getColumns();
- SelectItem[] selectItems = new SelectItem[columns2.length];
- for (int i = 0; i < selectItems.length; i++) {
- SelectItem selectItem = new SelectItem(columns2[i]);
- selectItems[i] = selectItem;
- }
- List<Object[]> data = new ArrayList<Object[]>();
- data.add(new Object[] { 1, 1, "founder" });
- data.add(new Object[] { 1, 1, "developer" });
- data.add(new Object[] { 1, 2, "developer" });
- data.add(new Object[] { 2, 1, "developer" });
- data.add(new Object[] { 2, 3, "developer" });
- data.add(new Object[] { 4, 1, "advisor" });
- data.add(new Object[] { 5, 2, "developer" });
- data.add(new Object[] { 6, 1, "founder" });
- if (maxRows != -1) {
- for (int i = data.size() - 1; i >= maxRows; i--) {
- data.remove(i);
- }
- }
- return createDataSet(selectItems, data);
- }
- throw new IllegalArgumentException("This test only accepts table1 and table2");
- }
-
- @Override
- protected String getMainSchemaName() throws MetaModelException {
- return schema.getName();
- }
-
- @Override
- protected Schema getMainSchema() throws MetaModelException {
- return schema;
- }
- };
- return dataContext;
- }
-
- public void testDistinct() throws Exception {
-
- Column roleColumn = table2.getColumnByName(COLUMN_ROLE_ROLE_NAME);
-
- Query q = new Query().select(roleColumn).from(table2).orderBy(roleColumn);
- q.getSelectClause().setDistinct(true);
-
- DataContext dc = getDataContext();
- DataSet data = dc.executeQuery(q);
- assertTrue(data.next());
- assertEquals("advisor", data.getRow().getValue(roleColumn));
- assertTrue(data.next());
- assertEquals("developer", data.getRow().getValue(roleColumn));
- assertTrue(data.next());
- assertEquals("founder", data.getRow().getValue(roleColumn));
- assertFalse(data.next());
- }
-
- public void testInformationSchema() throws Exception {
- DataContext dc = getDataContext();
- assertEquals("[information_schema, MetaModelSchema]", Arrays.toString(dc.getSchemaNames()));
- Schema informationSchema = dc.getSchemaByName("information_schema");
- assertEquals(
- "[Table[name=tables,type=TABLE,remarks=null], Table[name=columns,type=TABLE,remarks=null], Table[name=relationships,type=TABLE,remarks=null]]",
- Arrays.toString(informationSchema.getTables()));
- assertEquals(
- "[Relationship[primaryTable=tables,primaryColumns=[name],foreignTable=columns,foreignColumns=[table]], "
- + "Relationship[primaryTable=tables,primaryColumns=[name],foreignTable=relationships,foreignColumns=[primary_table]], "
- + "Relationship[primaryTable=tables,primaryColumns=[name],foreignTable=relationships,foreignColumns=[foreign_table]], "
- + "Relationship[primaryTable=columns,primaryColumns=[name],foreignTable=relationships,foreignColumns=[primary_column]], "
- + "Relationship[primaryTable=columns,primaryColumns=[name],foreignTable=relationships,foreignColumns=[foreign_column]]]",
- Arrays.toString(informationSchema.getRelationships()));
- Table tablesTable = informationSchema.getTableByName("tables");
- assertEquals(
- "[Column[name=name,columnNumber=0,type=VARCHAR,nullable=false,nativeType=null,columnSize=null], "
- + "Column[name=type,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
- + "Column[name=num_columns,columnNumber=2,type=INTEGER,nullable=true,nativeType=null,columnSize=null], "
- + "Column[name=remarks,columnNumber=3,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]",
- Arrays.toString(tablesTable.getColumns()));
- Table columnsTable = informationSchema.getTableByName("columns");
- assertEquals(
- "[Column[name=name,columnNumber=0,type=VARCHAR,nullable=false,nativeType=null,columnSize=null], "
- + "Column[name=type,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
- + "Column[name=native_type,columnNumber=2,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
- + "Column[name=size,columnNumber=3,type=INTEGER,nullable=true,nativeType=null,columnSize=null], "
- + "Column[name=nullable,columnNumber=4,type=BOOLEAN,nullable=true,nativeType=null,columnSize=null], "
- + "Column[name=indexed,columnNumber=5,type=BOOLEAN,nullable=true,nativeType=null,columnSize=null], "
- + "Column[name=table,columnNumber=6,type=VARCHAR,nullable=false,nativeType=null,columnSize=null], "
- + "Column[name=remarks,columnNumber=7,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]",
- Arrays.toString(columnsTable.getColumns()));
- Table relationshipsTable = informationSchema.getTableByName("relationships");
- assertEquals(
- "[Column[name=primary_table,columnNumber=0,type=VARCHAR,nullable=false,nativeType=null,columnSize=null], "
- + "Column[name=primary_column,columnNumber=1,type=VARCHAR,nullable=false,nativeType=null,columnSize=null], "
- + "Column[name=foreign_table,columnNumber=2,type=VARCHAR,nullable=false,nativeType=null,columnSize=null], "
- + "Column[name=foreign_column,columnNumber=3,type=VARCHAR,nullable=false,nativeType=null,columnSize=null]]",
- Arrays.toString(relationshipsTable.getColumns()));
-
- DataSet dataSet = dc.query().from(tablesTable).select(tablesTable.getColumns()).execute();
- assertTrue(dataSet.next());
- assertEquals("Row[values=[contributor, TABLE, 3, null]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[project, TABLE, 4, null]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[role, TABLE, 3, null]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[project_contributor, VIEW, 3, null]]", dataSet.getRow().toString());
- assertFalse(dataSet.next());
- dataSet.close();
-
- Relationship relationship = tablesTable.getRelationships(columnsTable)[0];
- FromItem joinFromItem = new FromItem(JoinType.INNER, relationship);
- Query q = new Query().select(tablesTable.getColumnByName("name")).select(columnsTable.getColumnByName("name"))
- .select(columnsTable.getBooleanColumns()).from(joinFromItem);
-
- assertEquals("SELECT tables.name, columns.name, columns.nullable, columns.indexed "
- + "FROM information_schema.tables INNER JOIN information_schema.columns "
- + "ON tables.name = columns.table", q.toString());
-
- dataSet = dc.executeQuery(q);
- assertTrue(dataSet.next());
- assertEquals("Row[values=[contributor, contributor_id, false, true]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[contributor, name, false, false]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[contributor, country, true, false]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[project, project_id, false, false]]", dataSet.getRow().toString());
- assertTrue(dataSet.next());
- assertEquals("Row[values=[project, name, false, false]]", dataSet.getRow().toString());
- dataSet.close();
- }
-
- public void testOrderByWithoutSelecting() throws Exception {
- Query q = new Query();
- q.from(new FromItem(table2).setAlias("r"));
- Column roleColumn = table2.getColumnByName(COLUMN_ROLE_ROLE_NAME);
- Column projectIdColumn = table2.getColumnByName(COLUMN_ROLE_PROJECT_ID);
- q.select(new SelectItem(projectIdColumn));
- q.orderBy(roleColumn);
- assertEquals("SELECT r.project_id FROM MetaModelSchema.role r ORDER BY r.name ASC", q.toString());
-
- DataContext dc = getDataContext();
- DataSet data = dc.executeQuery(q);
- assertEquals(1, data.getSelectItems().length);
-
- @SuppressWarnings("deprecation")
- TableModel tableModel = data.toTableModel();
-
- // should correspond to these lines:
-
- // data.add(new Object[] { 4, 1, "advisor" });
- // data.add(new Object[] { 1, 1, "developer" });
- // data.add(new Object[] { 1, 2, "developer" });
- // data.add(new Object[] { 2, 1, "developer" });
- // data.add(new Object[] { 2, 3, "developer" });
- // data.add(new Object[] { 5, 2, "developer" });
- // data.add(new Object[] { 1, 1, "founder" });
- // data.add(new Object[] { 6, 1, "founder" });
-
- assertEquals(8, tableModel.getRowCount());
- assertEquals(1, tableModel.getColumnCount());
- assertEquals(1, tableModel.getValueAt(0, 0));
- assertEquals(1, tableModel.getValueAt(1, 0));
- assertEquals(2, tableModel.getValueAt(2, 0));
- assertEquals(1, tableModel.getValueAt(3, 0));
- assertEquals(3, tableModel.getValueAt(4, 0));
- assertEquals(2, tableModel.getValueAt(5, 0));
- assertEquals(1, tableModel.getValueAt(6, 0));
- assertEquals(1, tableModel.getValueAt(7, 0));
- }
-
- public void testGroupByWithoutSelecting() throws Exception {
- Query q = new Query();
- q.from(new FromItem(table2).setAlias("r"));
- Column roleColumn = table2.getColumnByName(COLUMN_ROLE_ROLE_NAME);
- Column projectIdColumn = table2.getColumnByName(COLUMN_ROLE_PROJECT_ID);
- q.select(new SelectItem(FunctionType.SUM, projectIdColumn));
- q.groupBy(new GroupByItem(new SelectItem(roleColumn)));
- q.orderBy(roleColumn);
- assertEquals("SELECT SUM(r.project_id) FROM MetaModelSchema.role r GROUP BY r.name ORDER BY r.name ASC",
- q.toString());
-
- DataContext dc = getDataContext();
- DataSet data = dc.executeQuery(q);
- assertEquals(1, data.getSelectItems().length);
- assertEquals("SUM(r.project_id)", data.getSelectItems()[0].toString());
-
- @SuppressWarnings("deprecation")
- TableModel tableModel = data.toTableModel();
- assertEquals(3, tableModel.getRowCount());
- assertEquals(1, tableModel.getColumnCount());
- assertEquals(1.0, tableModel.getValueAt(0, 0));
- assertEquals(9.0, tableModel.getValueAt(1, 0));
- assertEquals(2.0, tableModel.getValueAt(2, 0));
-
- q = dc.query().from(table2).select("name").orderBy("name").toQuery();
- q.getSelectClause().setDistinct(true);
-
- tableModel = new DataSetTableModel(dc.executeQuery(q));
- assertEquals(3, tableModel.getRowCount());
- assertEquals(1, tableModel.getColumnCount());
- assertEquals("advisor", tableModel.getValueAt(0, 0));
- assertEquals("developer", tableModel.getValueAt(1, 0));
- assertEquals("founder", tableModel.getValueAt(2, 0));
- }
-
- public void testSimpleGroupBy() throws Exception {
- Query q = new Query();
- q.from(new FromItem(table2).setAlias("r"));
- Column roleColumn = table2.getColumnByName(COLUMN_ROLE_ROLE_NAME);
- q.select(new SelectItem(roleColumn));
- q.groupBy(new GroupByItem(new SelectItem(roleColumn)));
- assertEquals("SELECT r.name FROM MetaModelSchema.role r GROUP BY r.name", q.toString());
-
- DataContext dc = getDataContext();
- DataSet data = dc.executeQuery(q);
- assertEquals(1, data.getSelectItems().length);
- assertEquals("r.name", data.getSelectItems()[0].toString());
- TableModel tableModel = new DataSetTableModel(data);
- assertEquals(3, tableModel.getRowCount());
-
- q.select(new SelectItem(FunctionType.COUNT, "*", "c"));
- q.where(new FilterItem(new SelectItem(roleColumn), OperatorType.EQUALS_TO, "founder"));
- data = dc.executeQuery(q);
- assertEquals(2, data.getSelectItems().length);
- assertEquals("r.name", data.getSelectItems()[0].toString());
- assertEquals("COUNT(*) AS c", data.getSelectItems()[1].toString());
- tableModel = new DataSetTableModel(data);
- assertEquals(1, tableModel.getRowCount());
- assertEquals("founder", tableModel.getValueAt(0, 0));
- assertEquals(2l, tableModel.getValueAt(0, 1));
-
- q.select(new SelectItem(FunctionType.SUM, table2.getColumns()[0]));
- assertEquals(
- "SELECT r.name, COUNT(*) AS c, SUM(r.contributor_id) FROM MetaModelSchema.role r WHERE r.name = 'founder' GROUP BY r.name",
- q.toString());
- data = dc.executeQuery(q);
- assertEquals(3, data.getSelectItems().length);
- assertEquals("r.name", data.getSelectItems()[0].toString());
- assertEquals("COUNT(*) AS c", data.getSelectItems()[1].toString());
- assertEquals("SUM(r.contributor_id)", data.getSelectItems()[2].toString());
- tableModel = new DataSetTableModel(data);
- assertEquals(1, tableModel.getRowCount());
- assertEquals("founder", tableModel.getValueAt(0, 0));
- assertEquals(2l, tableModel.getValueAt(0, 1));
- assertEquals(7.0, tableModel.getValueAt(0, 2));
- }
-
- public void testSimpleHaving() throws Exception {
- Query q = new Query();
- q.from(table2, "c");
- Column roleColumn = table2.getColumnByName(COLUMN_ROLE_ROLE_NAME);
- Column contributorIdColumn = table2.getColumnByName(COLUMN_ROLE_CONTRIBUTOR_ID);
-
- q.groupBy(roleColumn);
- SelectItem countSelectItem = new SelectItem(FunctionType.COUNT, contributorIdColumn).setAlias("my_count");
- q.select(new SelectItem(roleColumn), countSelectItem);
- q.having(new FilterItem(countSelectItem, OperatorType.GREATER_THAN, 1));
- q.orderBy(new OrderByItem(countSelectItem));
- assertEquals(
- "SELECT c.name, COUNT(c.contributor_id) AS my_count FROM MetaModelSchema.role c GROUP BY c.name HAVING COUNT(c.contributor_id) > 1 ORDER BY COUNT(c.contributor_id) ASC",
- q.toString());
-
- DataSet data = getDataContext().executeQuery(q);
- assertTrue(data.next());
- assertEquals("Row[values=[founder, 2]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[developer, 5]]", data.getRow().toString());
- assertFalse(data.next());
- }
-
- public void testHavingFunctionNotSelected() throws Exception {
- Query q = new Query();
- q.from(table2, "c");
- Column roleColumn = table2.getColumnByName(COLUMN_ROLE_ROLE_NAME);
- Column contributorIdColumn = table2.getColumnByName(COLUMN_ROLE_CONTRIBUTOR_ID);
-
- q.groupBy(roleColumn);
- SelectItem countSelectItem = new SelectItem(FunctionType.COUNT, contributorIdColumn).setAlias("my_count");
- q.select(new SelectItem(roleColumn));
- q.having(new FilterItem(countSelectItem, OperatorType.GREATER_THAN, 3));
- assertEquals("SELECT c.name FROM MetaModelSchema.role c GROUP BY c.name HAVING COUNT(c.contributor_id) > 3",
- q.toString());
-
- DataSet data = getDataContext().executeQuery(q);
- assertTrue(data.next());
- assertEquals("Row[values=[developer]]", data.getRow().toString());
- assertFalse(data.next());
- data.close();
-
- q.getHavingClause().removeItems();
- q.having(new FilterItem(SelectItem.getCountAllItem(), OperatorType.GREATER_THAN, 3));
- assertEquals("SELECT c.name FROM MetaModelSchema.role c GROUP BY c.name HAVING COUNT(*) > 3", q.toString());
- data = getDataContext().executeQuery(q);
- assertTrue(data.next());
- assertEquals("Row[values=[developer]]", data.getRow().toString());
- assertFalse(data.next());
- data.close();
- }
-
- public void testCompiledQueryParameterInWhereClause() throws Exception {
- DataContext dc = getDataContext();
- QueryParameter param1 = new QueryParameter();
- CompiledQuery compiledQuery = dc.query().from(table1).select("name").where(COLUMN_CONTRIBUTOR_COUNTRY)
- .eq(param1).compile();
- try {
- assertEquals(1, compiledQuery.getParameters().size());
- assertSame(param1, compiledQuery.getParameters().get(0));
-
- DataSet ds = dc.executeQuery(compiledQuery, "denmark");
- try {
- assertTrue(ds.next());
- assertEquals("Row[values=[kasper]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[asbjorn]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[jesper]]", ds.getRow().toString());
- assertFalse(ds.next());
- } finally {
- ds.close();
- }
-
- try {
- ds = dc.executeQuery(compiledQuery, "canada");
- assertTrue(ds.next());
- assertEquals("Row[values=[daniel]]", ds.getRow().toString());
- assertFalse(ds.next());
- } finally {
- ds.close();
- }
- } finally {
- compiledQuery.close();
- }
- }
-
- public void testCompiledQueryParameterInSubQuery() throws Exception {
- final DataContext dc = getDataContext();
-
- final QueryParameter param1 = new QueryParameter();
- final Query subQuery = dc.query().from(table1).select("name").where(COLUMN_CONTRIBUTOR_COUNTRY).eq(param1)
- .toQuery();
-
- final FromItem subQueryFromItem = new FromItem(subQuery);
- final Query query = new Query().select(new SelectItem(subQuery.getSelectClause().getItem(0), subQueryFromItem))
- .from(subQueryFromItem);
-
- final CompiledQuery compiledQuery = dc.compileQuery(query);
-
- try {
- assertEquals(1, compiledQuery.getParameters().size());
- assertSame(param1, compiledQuery.getParameters().get(0));
-
- DataSet ds = dc.executeQuery(compiledQuery, "denmark");
- List<Object[]> objectArrays = ds.toObjectArrays();
- assertEquals(3, objectArrays.size());
-
- } finally {
- compiledQuery.close();
- }
- }
-
- public void testSelectCount() throws Exception {
- DataContext dc = getDataContext();
- Query q = new Query();
- q.from(table1);
- q.selectCount();
-
- Row row = MetaModelHelper.executeSingleRowQuery(dc, q);
- assertEquals("6", row.getValue(0).toString());
- }
-
- public void testSimpleSelect() throws Exception {
- DataContext dc = getDataContext();
- Query q = new Query();
- q.from(table1);
- q.select(table1.getColumns());
- DataSet dataSet = dc.executeQuery(q);
- assertTrue(dataSet.next());
- Row row = dataSet.getRow();
- assertEquals("Row[values=[1, kasper, denmark]]", row.toString());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertTrue(dataSet.next());
- assertFalse(dataSet.next());
- }
-
- public void testCarthesianProduct() throws Exception {
- DataContext dc = getDataContext();
- Query q = new Query();
- q.from(table1);
- q.from(table2);
- q.select(table1.getColumns());
- q.select(table2.getColumns());
- DataSet data = dc.executeQuery(q);
- assertEquals(table1.getColumnCount() + table2.getColumnCount(), data.getSelectItems().length);
- for (int i = 0; i < 6 * 8; i++) {
- assertTrue(data.next());
- if (i == 0) {
- assertEquals("Row[values=[1, kasper, denmark, 1, 1, founder]]", data.getRow().toString());
- } else if (i == 1) {
- assertEquals("Row[values=[1, kasper, denmark, 1, 1, developer]]", data.getRow().toString());
- }
- }
- assertFalse(data.next());
- }
-
- public void testJoinAndFirstRow() throws Exception {
- DataSet data;
-
- DataContext dc = getDataContext();
- Query q = new Query();
- q.from(table1);
- q.from(table2);
- q.select(table1.getColumns());
- q.select(table2.getColumns());
- data = dc.executeQuery(q);
- assertEquals(48, data.toObjectArrays().size());
-
- q.setFirstRow(3);
- data = dc.executeQuery(q);
- assertEquals(46, data.toObjectArrays().size());
- }
-
- public void testSimpleWhere() throws Exception {
- DataContext dc = getDataContext();
- Query q = new Query();
- q.from(table1);
- q.select(table1.getColumns());
- SelectItem countrySelectItem = q.getSelectClause().getSelectItem(
- table1.getColumnByName(COLUMN_CONTRIBUTOR_COUNTRY));
- q.where(new FilterItem(countrySelectItem, OperatorType.EQUALS_TO, "denmark"));
-
- DataSet data = dc.executeQuery(q);
- for (int i = 0; i < 3; i++) {
- assertTrue("Assertion failed at i=" + i, data.next());
- }
- assertFalse(data.next());
- }
-
- public void testMaxRows() throws Exception {
- DataContext dc = getDataContext();
- Query q = new Query();
- q.from(table1);
- q.select(table1.getColumns());
- q.setMaxRows(3);
- DataSet data1 = dc.executeQuery(q);
-
- assertTrue(data1.next());
- assertEquals("Row[values=[1, kasper, denmark]]", data1.getRow().toString());
- assertTrue(data1.next());
- assertEquals("Row[values=[2, asbjorn, denmark]]", data1.getRow().toString());
- assertTrue(data1.next());
- assertEquals("Row[values=[3, johny, israel]]", data1.getRow().toString());
-
- assertFalse(data1.next());
- data1.close();
-
- q = new Query();
- q.from(table1);
- q.select(table1.getColumns());
- q.setFirstRow(2);
- q.setMaxRows(2);
- DataSet data2 = dc.executeQuery(q);
- assertTrue(data2.next());
- assertEquals("Row[values=[2, asbjorn, denmark]]", data2.getRow().toString());
- assertTrue(data2.next());
- assertEquals("Row[values=[3, johny, israel]]", data2.getRow().toString());
-
- assertFalse(data2.next());
- data2.close();
- }
-
- public void testCarthesianProductWithWhere() throws Exception {
- DataContext dc = getDataContext();
-
- SelectItem s1 = new SelectItem(table1.getColumnByName(COLUMN_CONTRIBUTOR_NAME));
- SelectItem s2 = new SelectItem(table2.getColumnByName(COLUMN_ROLE_ROLE_NAME));
- FromItem f1 = new FromItem(table1);
- FromItem f2 = new FromItem(table2);
-
- Query q = new Query();
- q.select(s1);
- q.select(s2);
- q.from(f1);
- q.from(f2);
- SelectItem s3 = new SelectItem(table1.getColumnByName(COLUMN_CONTRIBUTOR_CONTRIBUTOR_ID));
- SelectItem s4 = new SelectItem(table2.getColumnByName(COLUMN_ROLE_CONTRIBUTOR_ID));
- q.where(new FilterItem(s3, OperatorType.EQUALS_TO, s4));
- assertEquals(
- "SELECT contributor.name, role.name FROM MetaModelSchema.contributor, MetaModelSchema.role WHERE contributor.contributor_id = role.contributor_id",
- q.toString());
-
- DataSet data = dc.executeQuery(q);
- assertEquals(2, data.getSelectItems().length);
- assertTrue(data.next());
- assertEquals("Row[values=[kasper, founder]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[kasper, developer]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[kasper, developer]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[asbjorn, developer]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[asbjorn, developer]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[daniel, advisor]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[sasidhar, developer]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[jesper, founder]]", data.getRow().toString());
- assertFalse(data.next());
- }
-
- public void testSelectDistinct() throws Exception {
- // there will be three distinct values in bar column: hello (x2), hi,
- // howdy
- MockDataContext dc = new MockDataContext("sch", "tab", "hello");
-
- Table table = dc.getTableByQualifiedLabel("sch.tab");
- Query q = dc.query().from(table).select("bar").toQuery();
- q.getSelectClause().setDistinct(true);
- q.orderBy(table.getColumnByName("bar"));
-
- DataSet ds = dc.executeQuery(q);
- assertTrue(ds.next());
- assertEquals("Row[values=[hello]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[hi]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[yo]]", ds.getRow().toString());
- assertFalse(ds.next());
- }
-
- public void testSubSelectionAndInnerJoin() throws Exception {
- DataContext dc = getDataContext();
-
- SelectItem s1 = new SelectItem(table1.getColumnByName(COLUMN_CONTRIBUTOR_NAME));
- SelectItem s2 = new SelectItem(table2.getColumnByName(COLUMN_ROLE_ROLE_NAME));
- FromItem fromItem = new FromItem(JoinType.INNER, table1.getRelationships(table2)[0]);
-
- Query q = new Query();
- q.select(s1);
- q.select(s2);
- q.from(fromItem);
- assertEquals(
- "SELECT contributor.name, role.name FROM MetaModelSchema.contributor INNER JOIN MetaModelSchema.role ON contributor.contributor_id = role.contributor_id",
- q.toString());
-
- DataSet data = dc.executeQuery(q);
- assertEquals(2, data.getSelectItems().length);
- assertTrue(data.next());
- assertEquals("Row[values=[kasper, founder]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[kasper, developer]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[kasper, developer]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[asbjorn, developer]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[asbjorn, developer]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[daniel, advisor]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[sasidhar, developer]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[jesper, founder]]", data.getRow().toString());
- assertFalse(data.next());
- }
-
- public void testSubquery() throws Exception {
- Query q1 = new Query();
- q1.from(table1);
- q1.select(table1.getColumns());
-
- Query q2 = new Query();
- FromItem fromItem = new FromItem(q1);
- q2.from(fromItem);
- SelectItem selectItem = new SelectItem(q1.getSelectClause().getItems().get(1), fromItem);
- selectItem.setAlias("e");
- q2.select(selectItem);
- assertEquals(
- "SELECT name AS e FROM (SELECT contributor.contributor_id, contributor.name, contributor.country FROM MetaModelSchema.contributor)",
- q2.toString());
-
- fromItem.setAlias("c");
- assertEquals(
- "SELECT c.name AS e FROM (SELECT contributor.contributor_id, contributor.name, contributor.country FROM MetaModelSchema.contributor) c",
- q2.toString());
-
- DataContext dc = getDataContext();
- DataSet data = dc.executeQuery(q2);
- assertEquals(1, data.getSelectItems().length);
- assertTrue(data.next());
- assertEquals("Row[values=[kasper]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[asbjorn]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[johny]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[daniel]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[sasidhar]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[jesper]]", data.getRow().toString());
- assertFalse(data.next());
-
- // Create a sub-query for a sub-query
- Query q3 = new Query();
- fromItem = new FromItem(q2);
- q3.from(fromItem);
- selectItem = new SelectItem(q2.getSelectClause().getItems().get(0), fromItem);
- selectItem.setAlias("f");
- q3.select(selectItem);
- fromItem.setAlias("d");
- assertEquals(
- "SELECT d.e AS f FROM (SELECT c.name AS e FROM (SELECT contributor.contributor_id, contributor.name, contributor.country FROM MetaModelSchema.contributor) c) d",
- q3.toString());
- data = dc.executeQuery(q3);
- assertEquals(1, data.getSelectItems().length);
- assertTrue(data.next());
- assertEquals("Row[values=[kasper]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[asbjorn]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[johny]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[daniel]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[sasidhar]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[jesper]]", data.getRow().toString());
- assertFalse(data.next());
- }
-
- public void testOrderBy() throws Exception {
- Query q = new Query();
- q.from(new FromItem(table1).setAlias("c"));
- q.select(table1.getColumns());
- OrderByItem countryOrderBy = new OrderByItem(q.getSelectClause().getItem(2), Direction.DESC);
- OrderByItem nameOrderBy = new OrderByItem(q.getSelectClause().getItem(1));
- q.orderBy(countryOrderBy, nameOrderBy);
-
- assertEquals(
- "SELECT c.contributor_id, c.name, c.country FROM MetaModelSchema.contributor c ORDER BY c.country DESC, c.name ASC",
- q.toString());
-
- DataSet data = getDataContext().executeQuery(q);
- assertTrue(data.next());
- assertEquals("Row[values=[5, sasidhar, unknown]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[3, johny, israel]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[2, asbjorn, denmark]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[6, jesper, denmark]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[1, kasper, denmark]]", data.getRow().toString());
- assertTrue(data.next());
- assertEquals("Row[values=[4, daniel, canada]]", data.getRow().toString());
- assertFalse(data.next());
- }
-
- public void testExecuteCount() throws Exception {
- QueryPostprocessDataContext dc = new QueryPostprocessDataContext() {
- @Override
- protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
- throw new UnsupportedAddressTypeException();
- }
-
- @Override
- protected Number executeCountQuery(Table table, List<FilterItem> whereItems,
- boolean functionApproximationAllowed) {
- return 1337;
- }
-
- @Override
- protected String getMainSchemaName() throws MetaModelException {
- return "sch";
- }
-
- @Override
- protected Schema getMainSchema() throws MetaModelException {
- MutableSchema schema = new MutableSchema(getMainSchemaName());
- MutableTable table = new MutableTable("tabl").setSchema(schema);
- return schema.addTable(table.addColumn(new MutableColumn("col").setTable(table)));
- }
- };
-
- DataSet ds = dc.query().from("sch.tabl").selectCount().execute();
- assertTrue(ds.next());
- assertEquals("Row[values=[1337]]", ds.getRow().toString());
- assertFalse(ds.next());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/SchemaNameComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/SchemaNameComparatorTest.java b/core/src/test/java/org/eobjects/metamodel/SchemaNameComparatorTest.java
deleted file mode 100644
index 201c911..0000000
--- a/core/src/test/java/org/eobjects/metamodel/SchemaNameComparatorTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * 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;
-
-import java.util.Comparator;
-
-import junit.framework.TestCase;
-
-public class SchemaNameComparatorTest extends TestCase {
-
- final Comparator<? super String> comp = SchemaNameComparator.getInstance();
-
- public void testNormalComparison() throws Exception {
- assertTrue(comp.compare("foo", "bar") > 0);
- assertTrue(comp.compare("bar", "foo") < 0);
- assertTrue(comp.compare("bar", "bar") == 0);
- }
-
- public void testNull() throws Exception {
- assertTrue(comp.compare(null, null) == 0);
- assertTrue(comp.compare("foo", null) > 0);
- assertTrue(comp.compare(null, "foo") < 0);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/convert/ColumnTypeDetectorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/convert/ColumnTypeDetectorTest.java b/core/src/test/java/org/eobjects/metamodel/convert/ColumnTypeDetectorTest.java
deleted file mode 100644
index 0e9cef7..0000000
--- a/core/src/test/java/org/eobjects/metamodel/convert/ColumnTypeDetectorTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * 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.convert;
-
-import junit.framework.TestCase;
-
-public class ColumnTypeDetectorTest extends TestCase {
-
- public void testBooleanConverter() throws Exception {
- ColumnTypeDetector d = new ColumnTypeDetector();
-
- d.registerValue("1");
- d.registerValue("true");
- d.registerValue("0");
-
- assertEquals(StringToBooleanConverter.class, d.createConverter()
- .getClass());
-
- d.registerValue("2");
-
- assertNull(d.createConverter());
- }
-
- public void testIntegerAndDoubleConverter() throws Exception {
- ColumnTypeDetector d = new ColumnTypeDetector();
-
- d.registerValue("123");
- d.registerValue("0");
-
- assertEquals(StringToIntegerConverter.class, d.createConverter()
- .getClass());
-
- d.registerValue("1123.23");
- d.registerValue("0.0");
-
- assertEquals(StringToDoubleConverter.class, d.createConverter()
- .getClass());
-
- d.registerValue("abc");
-
- assertNull(d.createConverter());
- }
-
- public void testDateConverter() throws Exception {
- ColumnTypeDetector d = new ColumnTypeDetector();
-
- d.registerValue("2010-12-30");
-
- assertEquals(StringToDateConverter.class, d.createConverter()
- .getClass());
-
- d.registerValue("2 abc");
-
- assertNull(d.createConverter());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/convert/ConvertedDataSetInterceptorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/convert/ConvertedDataSetInterceptorTest.java b/core/src/test/java/org/eobjects/metamodel/convert/ConvertedDataSetInterceptorTest.java
deleted file mode 100644
index e096283..0000000
--- a/core/src/test/java/org/eobjects/metamodel/convert/ConvertedDataSetInterceptorTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * 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.convert;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MockUpdateableDataContext;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-
-public class ConvertedDataSetInterceptorTest extends TestCase {
-
- public void testConvertedQuery() throws Exception {
- UpdateableDataContext dc = new MockUpdateableDataContext();
- Column fooColumn = dc.getColumnByQualifiedLabel("schema.table.foo");
- assertNotNull(fooColumn);
-
- dc = Converters.addTypeConverter(dc, fooColumn,
- new StringToIntegerConverter());
-
- Table table = dc.getDefaultSchema().getTableByName("table");
- Query query = dc.query().from(table).select(table.getColumns())
- .toQuery();
- assertEquals("SELECT table.foo, table.bar FROM schema.table",
- query.toSql());
-
- DataSet ds = dc.executeQuery(query);
- assertEquals(ConvertedDataSet.class, ds.getClass());
-
- assertTrue(ds.next());
- assertEquals("Row[values=[1, hello]]", ds.getRow().toString());
- assertEquals(Integer.class, ds.getRow().getValue(0).getClass());
- assertEquals(String.class, ds.getRow().getValue(1).getClass());
-
- assertTrue(ds.next());
- assertEquals("Row[values=[2, there]]", ds.getRow().toString());
- assertEquals(Integer.class, ds.getRow().getValue(0).getClass());
- assertEquals(String.class, ds.getRow().getValue(1).getClass());
-
- assertTrue(ds.next());
- assertEquals("Row[values=[3, world]]", ds.getRow().toString());
- assertEquals(Integer.class, ds.getRow().getValue(0).getClass());
- assertEquals(String.class, ds.getRow().getValue(1).getClass());
-
- assertFalse(ds.next());
- ds.close();
- }
-
- public void testNonConvertedQuery() throws Exception {
- MockUpdateableDataContext source = new MockUpdateableDataContext();
- Column fooColumn = source.getColumnByQualifiedLabel("schema.table.foo");
- assertNotNull(fooColumn);
-
- Map<Column, TypeConverter<?, ?>> converters = new HashMap<Column, TypeConverter<?, ?>>();
- converters.put(fooColumn, new StringToIntegerConverter());
- DataContext converted = Converters.addTypeConverter(source, fooColumn,
- new StringToIntegerConverter());
-
- // only select "bar" which is not converted
- Table table = converted.getDefaultSchema().getTableByName("table");
- Query query = converted.query().from(table).select("bar").toQuery();
- assertEquals("SELECT table.bar FROM schema.table", query.toSql());
-
- DataSet ds = converted.executeQuery(query);
- assertEquals(InMemoryDataSet.class, ds.getClass());
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/convert/ConvertedRowInsertionInterceptorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/convert/ConvertedRowInsertionInterceptorTest.java b/core/src/test/java/org/eobjects/metamodel/convert/ConvertedRowInsertionInterceptorTest.java
deleted file mode 100644
index aad70c2..0000000
--- a/core/src/test/java/org/eobjects/metamodel/convert/ConvertedRowInsertionInterceptorTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * 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.convert;
-
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.MockUpdateableDataContext;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.schema.Column;
-
-public class ConvertedRowInsertionInterceptorTest extends TestCase {
-
- public void testConvertedInsert() throws Exception {
- MockUpdateableDataContext source = new MockUpdateableDataContext();
- Column fooColumn = source.getColumnByQualifiedLabel("schema.table.foo");
- assertNotNull(fooColumn);
-
- UpdateableDataContext intercepted = Converters.addTypeConverter(source,
- fooColumn, new StringToIntegerConverter());
-
- final List<Object[]> values = source.getValues();
-
- assertEquals(3, values.size());
-
- intercepted.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.insertInto("schema.table").value(0, 1).value(1, "2")
- .execute();
- callback.insertInto("schema.table").value(0, 3).value(1, "4")
- .execute();
- }
- });
-
- assertEquals(5, values.size());
- assertEquals("1", values.get(3)[0]);
- assertEquals("2", values.get(3)[1]);
- assertEquals("3", values.get(4)[0]);
- assertEquals("4", values.get(4)[1]);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/convert/ConvertersTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/convert/ConvertersTest.java b/core/src/test/java/org/eobjects/metamodel/convert/ConvertersTest.java
deleted file mode 100644
index 7ff2f7c..0000000
--- a/core/src/test/java/org/eobjects/metamodel/convert/ConvertersTest.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/**
- * 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.convert;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.MockUpdateableDataContext;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-
-public class ConvertersTest extends TestCase {
-
- public void testAutoDetectConverters() throws Exception {
- final MockUpdateableDataContext decoratedDataContext = new MockUpdateableDataContext();
- final Table table = decoratedDataContext.getDefaultSchema().getTables()[0];
- Map<Column, TypeConverter<?, ?>> converters = Converters.autoDetectConverters(decoratedDataContext, table, 2);
- assertEquals(1, converters.size());
- assertEquals(
- "[Column[name=foo,columnNumber=0,type=VARCHAR,nullable=null,nativeType=null,columnSize=null]]",
- converters.keySet().toString());
- assertEquals(StringToIntegerConverter.class, converters.values().iterator().next().getClass());
-
- final UpdateableDataContext dc = Converters.addTypeConverters(decoratedDataContext, converters);
-
- DataSet ds = dc.query().from(table).select(table.getColumns()).execute();
- assertEquals(ConvertedDataSet.class, ds.getClass());
- assertTrue(ds.next());
- assertEquals("Row[values=[1, hello]]", ds.getRow().toString());
- assertEquals(Integer.class, ds.getRow().getValue(0).getClass());
- assertEquals(1, ds.getRow().getValue(0));
- assertTrue(ds.next());
- assertEquals(Integer.class, ds.getRow().getValue(0).getClass());
- assertEquals(2, ds.getRow().getValue(0));
- assertTrue(ds.next());
- assertEquals(Integer.class, ds.getRow().getValue(0).getClass());
- assertEquals(3, ds.getRow().getValue(0));
- assertFalse(ds.next());
- ds.close();
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.insertInto(table).value("foo", 4).value("bar", "mrrrrh").execute();
- }
- });
-
- // query the decorator
- ds = dc.query().from(table).select(table.getColumns()).where("foo").eq(4).execute();
- assertTrue(ds.next());
- assertEquals("Row[values=[4, mrrrrh]]", ds.getRow().toString());
- assertEquals(Integer.class, ds.getRow().getValue(0).getClass());
- assertEquals(4, ds.getRow().getValue(0));
- assertFalse(ds.next());
- ds.close();
-
- // query the decorated
- Object[] physicalRow = decoratedDataContext.getValues().get(3);
- assertEquals("[4, mrrrrh]", Arrays.toString(physicalRow));
- assertEquals(String.class, physicalRow[0].getClass());
- }
-
- public void testScenario() throws Exception {
- UpdateableDataContext dc = new MockUpdateableDataContext();
- List<Object[]> physicalValuesList = ((MockUpdateableDataContext) dc).getValues();
- assertEquals(3, physicalValuesList.size());
- for (Object[] physicalValues : physicalValuesList) {
- assertEquals("foo is expected to be string", String.class, physicalValues[0].getClass());
- }
-
- final Table table = dc.getDefaultSchema().getTables()[0];
- Map<Column, TypeConverter<?, ?>> converters = Converters.autoDetectConverters(dc, table, 1000);
- assertEquals(1, converters.size());
- dc = Converters.addTypeConverters(dc, converters);
-
- final Query q = dc.query().from(table).select("foo").toQuery();
- assertEquals("SELECT table.foo FROM schema.table", q.toSql());
- DataSet ds = dc.executeQuery(q);
- assertTrue(ds.next());
- assertEquals(1, ds.getRow().getValue(0));
- assertTrue(ds.next());
- assertEquals(2, ds.getRow().getValue(0));
- assertTrue(ds.next());
- assertEquals(3, ds.getRow().getValue(0));
- assertFalse(ds.next());
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.insertInto(table).value("foo", 4).value("bar", "heidiho!").execute();
- }
- });
-
- ds = dc.executeQuery(q);
- assertTrue(ds.next());
- assertEquals(1, ds.getRow().getValue(0));
- assertTrue(ds.next());
- assertEquals(2, ds.getRow().getValue(0));
- assertTrue(ds.next());
- assertEquals(3, ds.getRow().getValue(0));
- assertTrue(ds.next());
- assertEquals(4, ds.getRow().getValue(0));
- assertFalse(ds.next());
-
- assertEquals(4, physicalValuesList.size());
- for (Object[] physicalValues : physicalValuesList) {
- assertEquals("foo is expected to be string", String.class, physicalValues[0].getClass());
- }
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.insertInto(table).value("foo", 5).value("bar", "hejsa...").execute();
- callback.update(table).where("foo").lessThan(3).value("foo", 100).execute();
- }
- });
-
- ds = dc.executeQuery(q);
- assertTrue(ds.next());
- assertEquals(3, ds.getRow().getValue(0));
- assertTrue(ds.next());
- assertEquals(4, ds.getRow().getValue(0));
- assertTrue(ds.next());
- assertEquals(5, ds.getRow().getValue(0));
- assertTrue(ds.next());
- assertEquals(100, ds.getRow().getValue(0));
- assertTrue(ds.next());
- assertEquals(100, ds.getRow().getValue(0));
- assertFalse(ds.next());
-
- assertEquals(5, physicalValuesList.size());
- for (Object[] physicalValues : physicalValuesList) {
- assertEquals("foo is expected to be string", String.class, physicalValues[0].getClass());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/convert/StringToBooleanConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/convert/StringToBooleanConverterTest.java b/core/src/test/java/org/eobjects/metamodel/convert/StringToBooleanConverterTest.java
deleted file mode 100644
index d173e1e..0000000
--- a/core/src/test/java/org/eobjects/metamodel/convert/StringToBooleanConverterTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * 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.convert;
-
-import junit.framework.TestCase;
-
-public class StringToBooleanConverterTest extends TestCase {
-
- private StringToBooleanConverter conv = new StringToBooleanConverter();
-
- public void testToVirtual() throws Exception {
- assertNull(conv.toVirtualValue(null));
- assertNull(conv.toVirtualValue(""));
- assertEquals(true, conv.toVirtualValue("true").booleanValue());
- }
-
- public void testToPhysical() throws Exception {
- assertNull(conv.toPhysicalValue(null));
- assertEquals("true", conv.toPhysicalValue(true));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/convert/StringToDateConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/convert/StringToDateConverterTest.java b/core/src/test/java/org/eobjects/metamodel/convert/StringToDateConverterTest.java
deleted file mode 100644
index 5288f9d..0000000
--- a/core/src/test/java/org/eobjects/metamodel/convert/StringToDateConverterTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * 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.convert;
-
-import java.text.DateFormat;
-import java.util.Date;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.util.DateUtils;
-import org.eobjects.metamodel.util.Month;
-
-public class StringToDateConverterTest extends TestCase {
-
- public void testToVirtualSimpleDateFormat() throws Exception {
- StringToDateConverter conv = new StringToDateConverter("yyyy-MM-dd");
- assertNull(conv.toVirtualValue(null));
- assertNull(conv.toVirtualValue(""));
-
- assertEquals(DateUtils.get(2010, Month.DECEMBER, 31),
- conv.toVirtualValue("2010-12-31"));
- }
-
- public void testToVirtualNoArgs() throws Exception {
- StringToDateConverter conv = new StringToDateConverter();
- assertNull(conv.toVirtualValue(null));
- assertNull(conv.toVirtualValue(""));
-
- assertEquals(DateUtils.get(2010, Month.DECEMBER, 31),
- conv.toVirtualValue("2010-12-31"));
- }
-
- public void testToPhysicalSimpleDateFormat() throws Exception {
- StringToDateConverter conv = new StringToDateConverter("yyyy-MM-dd");
- assertNull(conv.toPhysicalValue(null));
- Date input = DateUtils.get(2010, Month.DECEMBER, 31);
- String physicalValue = conv.toPhysicalValue(input);
- assertEquals("2010-12-31", physicalValue);
- }
-
- public void testToPhysicalNoArgs() throws Exception {
- StringToDateConverter conv = new StringToDateConverter();
- assertNull(conv.toPhysicalValue(null));
- Date input = DateUtils.get(2010, Month.DECEMBER, 31);
- String physicalValue = conv.toPhysicalValue(input);
- Date virtualValue = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
- DateFormat.MEDIUM).parse(physicalValue);
- assertEquals(virtualValue, input);
- }
-}
[55/61] Renamed all import and package statements from 'org.eobjects'
to 'org.apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/query/parser/QueryParserTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/parser/QueryParserTest.java b/core/src/test/java/org/apache/metamodel/query/parser/QueryParserTest.java
index 786b79e..53126c5 100644
--- a/core/src/test/java/org/apache/metamodel/query/parser/QueryParserTest.java
+++ b/core/src/test/java/org/apache/metamodel/query/parser/QueryParserTest.java
@@ -16,26 +16,26 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.parser;
+package org.apache.metamodel.query.parser;
import java.util.Arrays;
import java.util.List;
import junit.framework.TestCase;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.MockDataContext;
-import org.eobjects.metamodel.query.FilterClause;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.OrderByItem;
-import org.eobjects.metamodel.query.OrderByItem.Direction;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.MetaModelHelper;
+import org.apache.metamodel.MockDataContext;
+import org.apache.metamodel.query.FilterClause;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.OrderByItem;
+import org.apache.metamodel.query.OrderByItem.Direction;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
public class QueryParserTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/query/parser/QueryPartParserTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/query/parser/QueryPartParserTest.java b/core/src/test/java/org/apache/metamodel/query/parser/QueryPartParserTest.java
index 0066f9c..792842b 100644
--- a/core/src/test/java/org/apache/metamodel/query/parser/QueryPartParserTest.java
+++ b/core/src/test/java/org/apache/metamodel/query/parser/QueryPartParserTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.query.parser;
+package org.apache.metamodel.query.parser;
import java.util.List;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/schema/ColumnTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/ColumnTypeTest.java b/core/src/test/java/org/apache/metamodel/schema/ColumnTypeTest.java
index 54b0689..674d362 100644
--- a/core/src/test/java/org/apache/metamodel/schema/ColumnTypeTest.java
+++ b/core/src/test/java/org/apache/metamodel/schema/ColumnTypeTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.sql.Time;
import java.sql.Timestamp;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/schema/DataTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/DataTypeTest.java b/core/src/test/java/org/apache/metamodel/schema/DataTypeTest.java
index 087062d..c61083d 100644
--- a/core/src/test/java/org/apache/metamodel/schema/DataTypeTest.java
+++ b/core/src/test/java/org/apache/metamodel/schema/DataTypeTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/schema/ImmutableSchemaTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/ImmutableSchemaTest.java b/core/src/test/java/org/apache/metamodel/schema/ImmutableSchemaTest.java
index 476af09..16c74f9 100644
--- a/core/src/test/java/org/apache/metamodel/schema/ImmutableSchemaTest.java
+++ b/core/src/test/java/org/apache/metamodel/schema/ImmutableSchemaTest.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
-import org.eobjects.metamodel.MetaModelTestCase;
+import org.apache.metamodel.MetaModelTestCase;
public class ImmutableSchemaTest extends MetaModelTestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/schema/Java5Types.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/Java5Types.java b/core/src/test/java/org/apache/metamodel/schema/Java5Types.java
index 8f44fa9..bbbfd32 100644
--- a/core/src/test/java/org/apache/metamodel/schema/Java5Types.java
+++ b/core/src/test/java/org/apache/metamodel/schema/Java5Types.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
/**
* This is a copy of the content of Java 5.0's java.sql.Types
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/schema/Java6Types.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/Java6Types.java b/core/src/test/java/org/apache/metamodel/schema/Java6Types.java
index d48600a..a5e1a40 100644
--- a/core/src/test/java/org/apache/metamodel/schema/Java6Types.java
+++ b/core/src/test/java/org/apache/metamodel/schema/Java6Types.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
/**
* This is a copy of the content of Java 6.0's java.sql.Types
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/schema/JavaTypesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/JavaTypesTest.java b/core/src/test/java/org/apache/metamodel/schema/JavaTypesTest.java
index 2d5eb9c..e9b02ad 100644
--- a/core/src/test/java/org/apache/metamodel/schema/JavaTypesTest.java
+++ b/core/src/test/java/org/apache/metamodel/schema/JavaTypesTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/schema/MutableColumnTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/MutableColumnTest.java b/core/src/test/java/org/apache/metamodel/schema/MutableColumnTest.java
index a2b3ca6..01224f1 100644
--- a/core/src/test/java/org/apache/metamodel/schema/MutableColumnTest.java
+++ b/core/src/test/java/org/apache/metamodel/schema/MutableColumnTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/schema/MutableSchemaTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/MutableSchemaTest.java b/core/src/test/java/org/apache/metamodel/schema/MutableSchemaTest.java
index 8eca7b2..cc313ee 100644
--- a/core/src/test/java/org/apache/metamodel/schema/MutableSchemaTest.java
+++ b/core/src/test/java/org/apache/metamodel/schema/MutableSchemaTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/schema/MutableTableTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/MutableTableTest.java b/core/src/test/java/org/apache/metamodel/schema/MutableTableTest.java
index 4efb0d6..c738a2b 100644
--- a/core/src/test/java/org/apache/metamodel/schema/MutableTableTest.java
+++ b/core/src/test/java/org/apache/metamodel/schema/MutableTableTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.util.Arrays;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/schema/SchemaModelTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/SchemaModelTest.java b/core/src/test/java/org/apache/metamodel/schema/SchemaModelTest.java
index 380d9d1..956f7e8 100644
--- a/core/src/test/java/org/apache/metamodel/schema/SchemaModelTest.java
+++ b/core/src/test/java/org/apache/metamodel/schema/SchemaModelTest.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import java.util.Arrays;
-import org.eobjects.metamodel.MetaModelTestCase;
+import org.apache.metamodel.MetaModelTestCase;
public class SchemaModelTest extends MetaModelTestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/schema/TableTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/TableTypeTest.java b/core/src/test/java/org/apache/metamodel/schema/TableTypeTest.java
index 127c54b..549e0ed 100644
--- a/core/src/test/java/org/apache/metamodel/schema/TableTypeTest.java
+++ b/core/src/test/java/org/apache/metamodel/schema/TableTypeTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.schema;
+package org.apache.metamodel.schema;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/AlphabeticSequenceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/AlphabeticSequenceTest.java b/core/src/test/java/org/apache/metamodel/util/AlphabeticSequenceTest.java
index 075098e..f4b6670 100644
--- a/core/src/test/java/org/apache/metamodel/util/AlphabeticSequenceTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/AlphabeticSequenceTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/BaseObjectTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/BaseObjectTest.java b/core/src/test/java/org/apache/metamodel/util/BaseObjectTest.java
index e147bc1..ff48527 100644
--- a/core/src/test/java/org/apache/metamodel/util/BaseObjectTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/BaseObjectTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.util.List;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/BooleanComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/BooleanComparatorTest.java b/core/src/test/java/org/apache/metamodel/util/BooleanComparatorTest.java
index 1c099fd..b218d66 100644
--- a/core/src/test/java/org/apache/metamodel/util/BooleanComparatorTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/BooleanComparatorTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.util.Comparator;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/ClasspathResourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/ClasspathResourceTest.java b/core/src/test/java/org/apache/metamodel/util/ClasspathResourceTest.java
index 3936092..72e49b8 100644
--- a/core/src/test/java/org/apache/metamodel/util/ClasspathResourceTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/ClasspathResourceTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.io.InputStream;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/CollectionUtilsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/CollectionUtilsTest.java b/core/src/test/java/org/apache/metamodel/util/CollectionUtilsTest.java
index d3c5ebf..240e0ca 100644
--- a/core/src/test/java/org/apache/metamodel/util/CollectionUtilsTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/CollectionUtilsTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.util.ArrayList;
import java.util.Arrays;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/DateUtilsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/DateUtilsTest.java b/core/src/test/java/org/apache/metamodel/util/DateUtilsTest.java
index b1bd885..9100428 100644
--- a/core/src/test/java/org/apache/metamodel/util/DateUtilsTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/DateUtilsTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.text.SimpleDateFormat;
import java.util.Date;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/EqualsBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/EqualsBuilderTest.java b/core/src/test/java/org/apache/metamodel/util/EqualsBuilderTest.java
index 78649a8..c82af71 100644
--- a/core/src/test/java/org/apache/metamodel/util/EqualsBuilderTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/EqualsBuilderTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/ExclusionPredicateTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/ExclusionPredicateTest.java b/core/src/test/java/org/apache/metamodel/util/ExclusionPredicateTest.java
index f2d9237..405f9b3 100644
--- a/core/src/test/java/org/apache/metamodel/util/ExclusionPredicateTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/ExclusionPredicateTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.util.Arrays;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/FileHelperTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/FileHelperTest.java b/core/src/test/java/org/apache/metamodel/util/FileHelperTest.java
index f51553f..30f2e60 100644
--- a/core/src/test/java/org/apache/metamodel/util/FileHelperTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/FileHelperTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.io.File;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/FormatHelperTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/FormatHelperTest.java b/core/src/test/java/org/apache/metamodel/util/FormatHelperTest.java
index eebe345..f2ef4d6 100644
--- a/core/src/test/java/org/apache/metamodel/util/FormatHelperTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/FormatHelperTest.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.text.NumberFormat;
import java.util.Arrays;
-import org.eobjects.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.ColumnType;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/InMemoryResourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/InMemoryResourceTest.java b/core/src/test/java/org/apache/metamodel/util/InMemoryResourceTest.java
index d6cc1e6..080bd9c 100644
--- a/core/src/test/java/org/apache/metamodel/util/InMemoryResourceTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/InMemoryResourceTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.io.InputStream;
import java.io.OutputStream;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/InclusionPredicateTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/InclusionPredicateTest.java b/core/src/test/java/org/apache/metamodel/util/InclusionPredicateTest.java
index 0225aff..c3866e3 100644
--- a/core/src/test/java/org/apache/metamodel/util/InclusionPredicateTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/InclusionPredicateTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.util.Arrays;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/LazyRefTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/LazyRefTest.java b/core/src/test/java/org/apache/metamodel/util/LazyRefTest.java
index f68fb96..b5e4b27 100644
--- a/core/src/test/java/org/apache/metamodel/util/LazyRefTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/LazyRefTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.util.concurrent.atomic.AtomicInteger;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/MonthTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/MonthTest.java b/core/src/test/java/org/apache/metamodel/util/MonthTest.java
index b70de17..aa29fca 100644
--- a/core/src/test/java/org/apache/metamodel/util/MonthTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/MonthTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/NumberComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/NumberComparatorTest.java b/core/src/test/java/org/apache/metamodel/util/NumberComparatorTest.java
index 211c967..f0f0bcd 100644
--- a/core/src/test/java/org/apache/metamodel/util/NumberComparatorTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/NumberComparatorTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.util.Comparator;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/ObjectComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/ObjectComparatorTest.java b/core/src/test/java/org/apache/metamodel/util/ObjectComparatorTest.java
index 925318c..7f68c55 100644
--- a/core/src/test/java/org/apache/metamodel/util/ObjectComparatorTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/ObjectComparatorTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.util.Comparator;
import java.util.Iterator;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/SerializableRefTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/SerializableRefTest.java b/core/src/test/java/org/apache/metamodel/util/SerializableRefTest.java
index 2d32e54..67331fa 100644
--- a/core/src/test/java/org/apache/metamodel/util/SerializableRefTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/SerializableRefTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/SimpleRefTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/SimpleRefTest.java b/core/src/test/java/org/apache/metamodel/util/SimpleRefTest.java
index fcc89c3..8b4ec47 100644
--- a/core/src/test/java/org/apache/metamodel/util/SimpleRefTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/SimpleRefTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/TimeComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/TimeComparatorTest.java b/core/src/test/java/org/apache/metamodel/util/TimeComparatorTest.java
index 4b43dcb..7d2e70c 100644
--- a/core/src/test/java/org/apache/metamodel/util/TimeComparatorTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/TimeComparatorTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.text.DateFormat;
import java.util.Comparator;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/ToStringComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/ToStringComparatorTest.java b/core/src/test/java/org/apache/metamodel/util/ToStringComparatorTest.java
index 684c714..66e26e4 100644
--- a/core/src/test/java/org/apache/metamodel/util/ToStringComparatorTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/ToStringComparatorTest.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import java.util.Comparator;
import junit.framework.TestCase;
-import org.eobjects.metamodel.util.ToStringComparator;
+import org.apache.metamodel.util.ToStringComparator;
public class ToStringComparatorTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/UrlResourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/UrlResourceTest.java b/core/src/test/java/org/apache/metamodel/util/UrlResourceTest.java
index 43e6523..8478253 100644
--- a/core/src/test/java/org/apache/metamodel/util/UrlResourceTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/UrlResourceTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/WeekdayTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/WeekdayTest.java b/core/src/test/java/org/apache/metamodel/util/WeekdayTest.java
index 1f92320..457cdfc 100644
--- a/core/src/test/java/org/apache/metamodel/util/WeekdayTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/WeekdayTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/core/src/test/java/org/apache/metamodel/util/WildcardPatternTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/util/WildcardPatternTest.java b/core/src/test/java/org/apache/metamodel/util/WildcardPatternTest.java
index 13da97b..1e075dd 100644
--- a/core/src/test/java/org/apache/metamodel/util/WildcardPatternTest.java
+++ b/core/src/test/java/org/apache/metamodel/util/WildcardPatternTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.util;
+package org.apache.metamodel.util;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataContext.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataContext.java b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataContext.java
index ac626e6..557b7e9 100644
--- a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataContext.java
+++ b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataContext.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.couchdb;
+package org.apache.metamodel.couchdb;
import java.util.ArrayList;
import java.util.EnumSet;
@@ -36,21 +36,21 @@ import org.ektorp.ViewResult.Row;
import org.ektorp.http.HttpClient;
import org.ektorp.http.StdHttpClient;
import org.ektorp.impl.StdCouchDbInstance;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.SimpleTableDef;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.MetaModelHelper;
+import org.apache.metamodel.QueryPostprocessDataContext;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.UpdateableDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.SimpleTableDef;
/**
* DataContext implementation for CouchDB
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataSet.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataSet.java b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataSet.java
index 6f3db01..a390975 100644
--- a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataSet.java
+++ b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataSet.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.couchdb;
+package org.apache.metamodel.couchdb;
import java.util.Iterator;
import java.util.List;
@@ -25,10 +25,10 @@ import java.util.Map;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
import org.ektorp.StreamingViewResult;
-import org.eobjects.metamodel.data.AbstractDataSet;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.SelectItem;
+import org.apache.metamodel.data.AbstractDataSet;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.SelectItem;
/**
* DataSet implementation for couch db.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbInsertionBuilder.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbInsertionBuilder.java b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbInsertionBuilder.java
index 7fe2ae6..423b429 100644
--- a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbInsertionBuilder.java
+++ b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbInsertionBuilder.java
@@ -16,16 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.couchdb;
+package org.apache.metamodel.couchdb;
import java.util.HashMap;
import java.util.Map;
import org.ektorp.CouchDbConnector;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.insert.AbstractRowInsertionBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.insert.AbstractRowInsertionBuilder;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
final class CouchDbInsertionBuilder extends AbstractRowInsertionBuilder<CouchDbUpdateCallback> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbRowDeletionBuilder.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbRowDeletionBuilder.java b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbRowDeletionBuilder.java
index fe0fc66..836370f 100644
--- a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbRowDeletionBuilder.java
+++ b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbRowDeletionBuilder.java
@@ -16,17 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.couchdb;
+package org.apache.metamodel.couchdb;
import java.util.List;
import org.ektorp.CouchDbConnector;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.delete.AbstractRowDeletionBuilder;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.delete.AbstractRowDeletionBuilder;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.schema.Table;
final class CouchDbRowDeletionBuilder extends AbstractRowDeletionBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbRowUpdationBuilder.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbRowUpdationBuilder.java b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbRowUpdationBuilder.java
index 15a4298..8697b78 100644
--- a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbRowUpdationBuilder.java
+++ b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbRowUpdationBuilder.java
@@ -16,18 +16,18 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.couchdb;
+package org.apache.metamodel.couchdb;
import java.util.HashMap;
import java.util.Map;
import org.ektorp.CouchDbConnector;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.AbstractRowUpdationBuilder;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.update.AbstractRowUpdationBuilder;
final class CouchDbRowUpdationBuilder extends AbstractRowUpdationBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbTableCreationBuilder.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbTableCreationBuilder.java b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbTableCreationBuilder.java
index df00880..b87d095 100644
--- a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbTableCreationBuilder.java
+++ b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbTableCreationBuilder.java
@@ -16,17 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.couchdb;
+package org.apache.metamodel.couchdb;
import org.ektorp.CouchDbInstance;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.create.AbstractTableCreationBuilder;
-import org.eobjects.metamodel.schema.ColumnType;
-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.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.create.AbstractTableCreationBuilder;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
final class CouchDbTableCreationBuilder extends AbstractTableCreationBuilder<CouchDbUpdateCallback> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbTableDropBuilder.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbTableDropBuilder.java b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbTableDropBuilder.java
index 91297aa..237bcb5 100644
--- a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbTableDropBuilder.java
+++ b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbTableDropBuilder.java
@@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.couchdb;
+package org.apache.metamodel.couchdb;
import org.ektorp.CouchDbInstance;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.drop.AbstractTableDropBuilder;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.drop.AbstractTableDropBuilder;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.Table;
final class CouchDbTableDropBuilder extends AbstractTableDropBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbUpdateCallback.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbUpdateCallback.java b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbUpdateCallback.java
index 8207c0d..465f959 100644
--- a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbUpdateCallback.java
+++ b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbUpdateCallback.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.couchdb;
+package org.apache.metamodel.couchdb;
import java.io.Closeable;
import java.util.ArrayList;
@@ -28,15 +28,15 @@ import java.util.Map;
import org.ektorp.CouchDbConnector;
import org.ektorp.CouchDbInstance;
import org.ektorp.DocumentOperationResult;
-import org.eobjects.metamodel.AbstractUpdateCallback;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
+import org.apache.metamodel.AbstractUpdateCallback;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.create.TableCreationBuilder;
+import org.apache.metamodel.delete.RowDeletionBuilder;
+import org.apache.metamodel.drop.TableDropBuilder;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.update.RowUpdationBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/couchdb/src/main/java/org/apache/metamodel/couchdb/package-info.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/apache/metamodel/couchdb/package-info.java b/couchdb/src/main/java/org/apache/metamodel/couchdb/package-info.java
index 340fd98..daa8ba9 100644
--- a/couchdb/src/main/java/org/apache/metamodel/couchdb/package-info.java
+++ b/couchdb/src/main/java/org/apache/metamodel/couchdb/package-info.java
@@ -19,5 +19,5 @@
/**
* Module package for CouchDB support
*/
-package org.eobjects.metamodel.couchdb;
+package org.apache.metamodel.couchdb;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/couchdb/src/test/java/org/apache/metamodel/couchdb/CouchDbDataContextTest.java
----------------------------------------------------------------------
diff --git a/couchdb/src/test/java/org/apache/metamodel/couchdb/CouchDbDataContextTest.java b/couchdb/src/test/java/org/apache/metamodel/couchdb/CouchDbDataContextTest.java
index 403a64c..afb6c5b 100644
--- a/couchdb/src/test/java/org/apache/metamodel/couchdb/CouchDbDataContextTest.java
+++ b/couchdb/src/test/java/org/apache/metamodel/couchdb/CouchDbDataContextTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.couchdb;
+package org.apache.metamodel.couchdb;
import java.util.ArrayList;
import java.util.Arrays;
@@ -32,17 +32,17 @@ import org.ektorp.DbAccessException;
import org.ektorp.http.HttpClient;
import org.ektorp.http.StdHttpClient;
import org.ektorp.impl.StdCouchDbInstance;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.drop.DropTable;
-import org.eobjects.metamodel.insert.InsertInto;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.SimpleTableDef;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.drop.DropTable;
+import org.apache.metamodel.insert.InsertInto;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.SimpleTableDef;
public class CouchDbDataContextTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/main/java/org/apache/metamodel/csv/CsvConfiguration.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvConfiguration.java b/csv/src/main/java/org/apache/metamodel/csv/CsvConfiguration.java
index 8e34913..e2cd846 100644
--- a/csv/src/main/java/org/apache/metamodel/csv/CsvConfiguration.java
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvConfiguration.java
@@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
import java.io.Serializable;
import java.util.List;
-import org.eobjects.metamodel.util.BaseObject;
-import org.eobjects.metamodel.util.FileHelper;
+import org.apache.metamodel.util.BaseObject;
+import org.apache.metamodel.util.FileHelper;
/**
* Represents the configuration for reading/parsing CSV files.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/main/java/org/apache/metamodel/csv/CsvCreateTableBuilder.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvCreateTableBuilder.java b/csv/src/main/java/org/apache/metamodel/csv/CsvCreateTableBuilder.java
index 906d2e1..513b8e8 100644
--- a/csv/src/main/java/org/apache/metamodel/csv/CsvCreateTableBuilder.java
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvCreateTableBuilder.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
-import org.eobjects.metamodel.create.AbstractTableCreationBuilder;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.create.AbstractTableCreationBuilder;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
final class CsvCreateTableBuilder extends
AbstractTableCreationBuilder<CsvUpdateCallback> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/main/java/org/apache/metamodel/csv/CsvDataContext.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvDataContext.java b/csv/src/main/java/org/apache/metamodel/csv/CsvDataContext.java
index 6409596..2b275a9 100644
--- a/csv/src/main/java/org/apache/metamodel/csv/CsvDataContext.java
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvDataContext.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@@ -30,19 +30,19 @@ import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.List;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.FileHelper;
-import org.eobjects.metamodel.util.FileResource;
-import org.eobjects.metamodel.util.Func;
-import org.eobjects.metamodel.util.Resource;
-import org.eobjects.metamodel.util.UrlResource;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.QueryPostprocessDataContext;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.UpdateableDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.FileHelper;
+import org.apache.metamodel.util.FileResource;
+import org.apache.metamodel.util.Func;
+import org.apache.metamodel.util.Resource;
+import org.apache.metamodel.util.UrlResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/main/java/org/apache/metamodel/csv/CsvDataSet.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvDataSet.java b/csv/src/main/java/org/apache/metamodel/csv/CsvDataSet.java
index ae31865..b69ab13 100644
--- a/csv/src/main/java/org/apache/metamodel/csv/CsvDataSet.java
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvDataSet.java
@@ -16,16 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
import java.io.IOException;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.data.AbstractDataSet;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.util.FileHelper;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.data.AbstractDataSet;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.util.FileHelper;
import au.com.bytecode.opencsv.CSVReader;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/main/java/org/apache/metamodel/csv/CsvDeleteBuilder.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvDeleteBuilder.java b/csv/src/main/java/org/apache/metamodel/csv/CsvDeleteBuilder.java
index 52c18e0..1f3bee9 100644
--- a/csv/src/main/java/org/apache/metamodel/csv/CsvDeleteBuilder.java
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvDeleteBuilder.java
@@ -16,21 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.delete.AbstractRowDeletionBuilder;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.Action;
-import org.eobjects.metamodel.util.FileHelper;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.delete.AbstractRowDeletionBuilder;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.Action;
+import org.apache.metamodel.util.FileHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/main/java/org/apache/metamodel/csv/CsvInsertBuilder.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvInsertBuilder.java b/csv/src/main/java/org/apache/metamodel/csv/CsvInsertBuilder.java
index 718de8e..72a7c7e 100644
--- a/csv/src/main/java/org/apache/metamodel/csv/CsvInsertBuilder.java
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvInsertBuilder.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
-import org.eobjects.metamodel.insert.AbstractRowInsertionBuilder;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.insert.AbstractRowInsertionBuilder;
+import org.apache.metamodel.schema.Table;
final class CsvInsertBuilder extends AbstractRowInsertionBuilder<CsvUpdateCallback> {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/main/java/org/apache/metamodel/csv/CsvSchema.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvSchema.java b/csv/src/main/java/org/apache/metamodel/csv/CsvSchema.java
index c6d2ba9..6de36a6 100644
--- a/csv/src/main/java/org/apache/metamodel/csv/CsvSchema.java
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvSchema.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
-import org.eobjects.metamodel.schema.AbstractSchema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.schema.AbstractSchema;
+import org.apache.metamodel.schema.Table;
final class CsvSchema extends AbstractSchema {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/main/java/org/apache/metamodel/csv/CsvTable.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvTable.java b/csv/src/main/java/org/apache/metamodel/csv/CsvTable.java
index eb9bdc0..1603bc8 100644
--- a/csv/src/main/java/org/apache/metamodel/csv/CsvTable.java
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvTable.java
@@ -16,19 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
import java.io.IOException;
-import org.eobjects.metamodel.schema.AbstractTable;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.TableType;
-import org.eobjects.metamodel.util.AlphabeticSequence;
-import org.eobjects.metamodel.util.FileHelper;
+import org.apache.metamodel.schema.AbstractTable;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.Relationship;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.TableType;
+import org.apache.metamodel.util.AlphabeticSequence;
+import org.apache.metamodel.util.FileHelper;
import au.com.bytecode.opencsv.CSVReader;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/main/java/org/apache/metamodel/csv/CsvTableDropBuilder.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvTableDropBuilder.java b/csv/src/main/java/org/apache/metamodel/csv/CsvTableDropBuilder.java
index 0685fb4..b8b2359 100644
--- a/csv/src/main/java/org/apache/metamodel/csv/CsvTableDropBuilder.java
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvTableDropBuilder.java
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
-import org.eobjects.metamodel.drop.AbstractTableDropBuilder;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.drop.AbstractTableDropBuilder;
+import org.apache.metamodel.schema.Table;
final class CsvTableDropBuilder extends AbstractTableDropBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/main/java/org/apache/metamodel/csv/CsvUpdateCallback.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvUpdateCallback.java b/csv/src/main/java/org/apache/metamodel/csv/CsvUpdateCallback.java
index 72e276c..db60c05 100644
--- a/csv/src/main/java/org/apache/metamodel/csv/CsvUpdateCallback.java
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvUpdateCallback.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
import java.io.File;
import java.io.IOException;
@@ -28,21 +28,21 @@ import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
-import org.eobjects.metamodel.AbstractUpdateCallback;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
-import org.eobjects.metamodel.util.Action;
-import org.eobjects.metamodel.util.EqualsBuilder;
-import org.eobjects.metamodel.util.FileHelper;
-import org.eobjects.metamodel.util.FileResource;
-import org.eobjects.metamodel.util.Resource;
+import org.apache.metamodel.AbstractUpdateCallback;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.create.TableCreationBuilder;
+import org.apache.metamodel.delete.RowDeletionBuilder;
+import org.apache.metamodel.drop.TableDropBuilder;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.update.RowUpdationBuilder;
+import org.apache.metamodel.util.Action;
+import org.apache.metamodel.util.EqualsBuilder;
+import org.apache.metamodel.util.FileHelper;
+import org.apache.metamodel.util.FileResource;
+import org.apache.metamodel.util.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/main/java/org/apache/metamodel/csv/CsvWriter.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvWriter.java b/csv/src/main/java/org/apache/metamodel/csv/CsvWriter.java
index 7b35847..1d0b424 100644
--- a/csv/src/main/java/org/apache/metamodel/csv/CsvWriter.java
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvWriter.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
-import org.eobjects.metamodel.util.Resource;
+import org.apache.metamodel.util.Resource;
/**
* This class is an adaptation of the CSVWriter class of OpenCSV. We've made the
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/main/java/org/apache/metamodel/csv/InconsistentRowLengthException.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/InconsistentRowLengthException.java b/csv/src/main/java/org/apache/metamodel/csv/InconsistentRowLengthException.java
index 60c093f..70d1042 100644
--- a/csv/src/main/java/org/apache/metamodel/csv/InconsistentRowLengthException.java
+++ b/csv/src/main/java/org/apache/metamodel/csv/InconsistentRowLengthException.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
-import org.eobjects.metamodel.InconsistentRowFormatException;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
+import org.apache.metamodel.InconsistentRowFormatException;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.Row;
/**
* Exception thrown when a line in a CSV file has an inconsistent amount of
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/main/java/org/apache/metamodel/csv/package-info.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/package-info.java b/csv/src/main/java/org/apache/metamodel/csv/package-info.java
index 241c74e..120784a 100644
--- a/csv/src/main/java/org/apache/metamodel/csv/package-info.java
+++ b/csv/src/main/java/org/apache/metamodel/csv/package-info.java
@@ -19,5 +19,5 @@
/**
* Module package for Comma Separated Values (CSV) files
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/test/java/org/apache/metamodel/csv/CsvBigFileMemoryTest.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/apache/metamodel/csv/CsvBigFileMemoryTest.java b/csv/src/test/java/org/apache/metamodel/csv/CsvBigFileMemoryTest.java
index ffc11ca..54c6987 100644
--- a/csv/src/test/java/org/apache/metamodel/csv/CsvBigFileMemoryTest.java
+++ b/csv/src/test/java/org/apache/metamodel/csv/CsvBigFileMemoryTest.java
@@ -16,17 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
import java.io.File;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.csv.CsvConfiguration;
-import org.eobjects.metamodel.csv.CsvDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.csv.CsvConfiguration;
+import org.apache.metamodel.csv.CsvDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Table;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/test/java/org/apache/metamodel/csv/CsvConfigurationTest.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/apache/metamodel/csv/CsvConfigurationTest.java b/csv/src/test/java/org/apache/metamodel/csv/CsvConfigurationTest.java
index 2948762..c32a568 100644
--- a/csv/src/test/java/org/apache/metamodel/csv/CsvConfigurationTest.java
+++ b/csv/src/test/java/org/apache/metamodel/csv/CsvConfigurationTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
import junit.framework.TestCase;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/test/java/org/apache/metamodel/csv/CsvDataContextTest.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/apache/metamodel/csv/CsvDataContextTest.java b/csv/src/test/java/org/apache/metamodel/csv/CsvDataContextTest.java
index a8b4d8e..2e6add0 100644
--- a/csv/src/test/java/org/apache/metamodel/csv/CsvDataContextTest.java
+++ b/csv/src/test/java/org/apache/metamodel/csv/CsvDataContextTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
import java.io.File;
import java.io.FileInputStream;
@@ -28,28 +28,28 @@ import javax.swing.table.TableModel;
import junit.framework.TestCase;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.convert.Converters;
-import org.eobjects.metamodel.convert.StringToBooleanConverter;
-import org.eobjects.metamodel.convert.StringToIntegerConverter;
-import org.eobjects.metamodel.convert.TypeConverter;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetTableModel;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.OperatorType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.FileHelper;
-import org.eobjects.metamodel.util.MutableRef;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.QueryPostprocessDataContext;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.convert.Converters;
+import org.apache.metamodel.convert.StringToBooleanConverter;
+import org.apache.metamodel.convert.StringToIntegerConverter;
+import org.apache.metamodel.convert.TypeConverter;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSetTableModel;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.query.OperatorType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.FileHelper;
+import org.apache.metamodel.util.MutableRef;
public class CsvDataContextTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/test/java/org/apache/metamodel/csv/DefaultExampleValueGenerator.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/apache/metamodel/csv/DefaultExampleValueGenerator.java b/csv/src/test/java/org/apache/metamodel/csv/DefaultExampleValueGenerator.java
index b84e93a..2c29fe7 100644
--- a/csv/src/test/java/org/apache/metamodel/csv/DefaultExampleValueGenerator.java
+++ b/csv/src/test/java/org/apache/metamodel/csv/DefaultExampleValueGenerator.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
import org.junit.Ignore;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/test/java/org/apache/metamodel/csv/ExampleDataGenerator.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/apache/metamodel/csv/ExampleDataGenerator.java b/csv/src/test/java/org/apache/metamodel/csv/ExampleDataGenerator.java
index e2da7bf..c7ec3bc 100644
--- a/csv/src/test/java/org/apache/metamodel/csv/ExampleDataGenerator.java
+++ b/csv/src/test/java/org/apache/metamodel/csv/ExampleDataGenerator.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
import java.io.BufferedWriter;
import java.io.File;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/test/java/org/apache/metamodel/csv/ExampleValueGenerator.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/apache/metamodel/csv/ExampleValueGenerator.java b/csv/src/test/java/org/apache/metamodel/csv/ExampleValueGenerator.java
index d7420f0..d89c809 100644
--- a/csv/src/test/java/org/apache/metamodel/csv/ExampleValueGenerator.java
+++ b/csv/src/test/java/org/apache/metamodel/csv/ExampleValueGenerator.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
import org.junit.Ignore;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/test/java/org/apache/metamodel/csv/RandomizedExampleValueGenerator.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/apache/metamodel/csv/RandomizedExampleValueGenerator.java b/csv/src/test/java/org/apache/metamodel/csv/RandomizedExampleValueGenerator.java
index b616f67..ff8aeb9 100644
--- a/csv/src/test/java/org/apache/metamodel/csv/RandomizedExampleValueGenerator.java
+++ b/csv/src/test/java/org/apache/metamodel/csv/RandomizedExampleValueGenerator.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
import java.util.Random;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/test/java/org/apache/metamodel/csv/UnicodeWriterTest.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/apache/metamodel/csv/UnicodeWriterTest.java b/csv/src/test/java/org/apache/metamodel/csv/UnicodeWriterTest.java
index a82b732..3bc6e10 100644
--- a/csv/src/test/java/org/apache/metamodel/csv/UnicodeWriterTest.java
+++ b/csv/src/test/java/org/apache/metamodel/csv/UnicodeWriterTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.csv;
+package org.apache.metamodel.csv;
import static org.junit.Assert.assertEquals;
@@ -25,7 +25,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.Writer;
-import org.eobjects.metamodel.util.UnicodeWriter;
+import org.apache.metamodel.util.UnicodeWriter;
import org.junit.Test;
public class UnicodeWriterTest {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/csv/src/test/java/org/apache/metamodel/intercept/InterceptionCsvIntegrationTest.java
----------------------------------------------------------------------
diff --git a/csv/src/test/java/org/apache/metamodel/intercept/InterceptionCsvIntegrationTest.java b/csv/src/test/java/org/apache/metamodel/intercept/InterceptionCsvIntegrationTest.java
index 3939cfe..5f516f3 100644
--- a/csv/src/test/java/org/apache/metamodel/intercept/InterceptionCsvIntegrationTest.java
+++ b/csv/src/test/java/org/apache/metamodel/intercept/InterceptionCsvIntegrationTest.java
@@ -16,21 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.intercept;
+package org.apache.metamodel.intercept;
import java.io.File;
import java.util.Arrays;
import junit.framework.TestCase;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.csv.CsvDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.UpdateableDataContext;
+import org.apache.metamodel.create.TableCreationBuilder;
+import org.apache.metamodel.csv.CsvDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.schema.Table;
public class InterceptionCsvIntegrationTest extends TestCase {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/main/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegate.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegate.java b/excel/src/main/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegate.java
index f4c6dd7..48a96f3 100644
--- a/excel/src/main/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegate.java
+++ b/excel/src/main/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegate.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import java.io.InputStream;
import java.util.Iterator;
@@ -25,18 +25,18 @@ import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.EmptyDataSet;
-import org.eobjects.metamodel.data.MaxRowsDataSet;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-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.Table;
-import org.eobjects.metamodel.util.AlphabeticSequence;
-import org.eobjects.metamodel.util.Ref;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.EmptyDataSet;
+import org.apache.metamodel.data.MaxRowsDataSet;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.MutableColumn;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.AlphabeticSequence;
+import org.apache.metamodel.util.Ref;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/main/java/org/apache/metamodel/excel/ExcelConfiguration.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/ExcelConfiguration.java b/excel/src/main/java/org/apache/metamodel/excel/ExcelConfiguration.java
index b63140c..66e226c 100644
--- a/excel/src/main/java/org/apache/metamodel/excel/ExcelConfiguration.java
+++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelConfiguration.java
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import java.io.Serializable;
import java.util.List;
-import org.eobjects.metamodel.util.BaseObject;
+import org.apache.metamodel.util.BaseObject;
/**
* Represents the configuration for reading/parsing Excel spreadsheets.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/main/java/org/apache/metamodel/excel/ExcelDataContext.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/ExcelDataContext.java b/excel/src/main/java/org/apache/metamodel/excel/ExcelDataContext.java
index 6726d8b..f29f86b 100644
--- a/excel/src/main/java/org/apache/metamodel/excel/ExcelDataContext.java
+++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelDataContext.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import java.io.File;
import java.io.IOException;
@@ -24,21 +24,21 @@ import java.io.InputStream;
import java.io.PushbackInputStream;
import org.apache.poi.POIXMLDocument;
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.FileHelper;
-import org.eobjects.metamodel.util.FileResource;
-import org.eobjects.metamodel.util.LazyRef;
-import org.eobjects.metamodel.util.Ref;
-import org.eobjects.metamodel.util.Resource;
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.QueryPostprocessDataContext;
+import org.apache.metamodel.UpdateScript;
+import org.apache.metamodel.UpdateableDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.FileHelper;
+import org.apache.metamodel.util.FileResource;
+import org.apache.metamodel.util.LazyRef;
+import org.apache.metamodel.util.Ref;
+import org.apache.metamodel.util.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/main/java/org/apache/metamodel/excel/ExcelDeleteBuilder.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/ExcelDeleteBuilder.java b/excel/src/main/java/org/apache/metamodel/excel/ExcelDeleteBuilder.java
index 4b9308c..7d835c7 100644
--- a/excel/src/main/java/org/apache/metamodel/excel/ExcelDeleteBuilder.java
+++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelDeleteBuilder.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import java.util.ArrayList;
import java.util.Collections;
@@ -26,14 +26,14 @@ import java.util.List;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.data.DataSetHeader;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.SimpleDataSetHeader;
-import org.eobjects.metamodel.delete.AbstractRowDeletionBuilder;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.MetaModelHelper;
+import org.apache.metamodel.data.DataSetHeader;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.SimpleDataSetHeader;
+import org.apache.metamodel.delete.AbstractRowDeletionBuilder;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.Table;
final class ExcelDeleteBuilder extends AbstractRowDeletionBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/main/java/org/apache/metamodel/excel/ExcelDropTableBuilder.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/ExcelDropTableBuilder.java b/excel/src/main/java/org/apache/metamodel/excel/ExcelDropTableBuilder.java
index b303622..2805299 100644
--- a/excel/src/main/java/org/apache/metamodel/excel/ExcelDropTableBuilder.java
+++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelDropTableBuilder.java
@@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.drop.AbstractTableDropBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.drop.AbstractTableDropBuilder;
+import org.apache.metamodel.drop.TableDropBuilder;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.Table;
final class ExcelDropTableBuilder extends AbstractTableDropBuilder implements TableDropBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/main/java/org/apache/metamodel/excel/ExcelInsertBuilder.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/ExcelInsertBuilder.java b/excel/src/main/java/org/apache/metamodel/excel/ExcelInsertBuilder.java
index 3a61a2f..e5750d1 100644
--- a/excel/src/main/java/org/apache/metamodel/excel/ExcelInsertBuilder.java
+++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelInsertBuilder.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import java.util.Date;
@@ -24,15 +24,15 @@ import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.data.Style.Color;
-import org.eobjects.metamodel.data.Style.SizeUnit;
-import org.eobjects.metamodel.data.Style.TextAlignment;
-import org.eobjects.metamodel.insert.AbstractRowInsertionBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.LazyRef;
+import org.apache.metamodel.data.Style;
+import org.apache.metamodel.data.Style.Color;
+import org.apache.metamodel.data.Style.SizeUnit;
+import org.apache.metamodel.data.Style.TextAlignment;
+import org.apache.metamodel.insert.AbstractRowInsertionBuilder;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.util.LazyRef;
/**
* {@link RowInsertionBuilder} for excel spreadsheets.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/main/java/org/apache/metamodel/excel/ExcelTableCreationBuilder.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/ExcelTableCreationBuilder.java b/excel/src/main/java/org/apache/metamodel/excel/ExcelTableCreationBuilder.java
index 7a579e5..f6f90c6 100644
--- a/excel/src/main/java/org/apache/metamodel/excel/ExcelTableCreationBuilder.java
+++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelTableCreationBuilder.java
@@ -16,17 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
-import org.eobjects.metamodel.create.AbstractTableCreationBuilder;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.create.AbstractTableCreationBuilder;
+import org.apache.metamodel.create.TableCreationBuilder;
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
/**
* {@link TableCreationBuilder} implementation for Excel spreadsheets.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/587d518a/excel/src/main/java/org/apache/metamodel/excel/ExcelUpdateCallback.java
----------------------------------------------------------------------
diff --git a/excel/src/main/java/org/apache/metamodel/excel/ExcelUpdateCallback.java b/excel/src/main/java/org/apache/metamodel/excel/ExcelUpdateCallback.java
index 533a878..125c063 100644
--- a/excel/src/main/java/org/apache/metamodel/excel/ExcelUpdateCallback.java
+++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelUpdateCallback.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.eobjects.metamodel.excel;
+package org.apache.metamodel.excel;
import org.apache.poi.hssf.usermodel.HSSFPalette;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -29,16 +29,16 @@ import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.eobjects.metamodel.AbstractUpdateCallback;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Style.Color;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
+import org.apache.metamodel.AbstractUpdateCallback;
+import org.apache.metamodel.UpdateCallback;
+import org.apache.metamodel.create.TableCreationBuilder;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.Style.Color;
+import org.apache.metamodel.delete.RowDeletionBuilder;
+import org.apache.metamodel.drop.TableDropBuilder;
+import org.apache.metamodel.insert.RowInsertionBuilder;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
final class ExcelUpdateCallback extends AbstractUpdateCallback implements UpdateCallback {
[32/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/ColumnSelectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/ColumnSelectBuilderImpl.java b/core/src/main/java/org/eobjects/metamodel/query/builder/ColumnSelectBuilderImpl.java
deleted file mode 100644
index 161a36f..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/ColumnSelectBuilderImpl.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * 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.query.builder;
-
-import java.util.List;
-
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-
-final class ColumnSelectBuilderImpl extends SatisfiedSelectBuilderImpl
- implements ColumnSelectBuilder<GroupedQueryBuilder> {
-
- private SelectItem selectItem;
-
- public ColumnSelectBuilderImpl(Column column, Query query,
- GroupedQueryBuilder queryBuilder) {
- super(queryBuilder);
- this.selectItem = new SelectItem(column);
-
- query.select(selectItem);
- }
-
- @Override
- public GroupedQueryBuilder as(String alias) {
- if (alias == null) {
- throw new IllegalArgumentException("alias cannot be null");
- }
- selectItem.setAlias(alias);
- return getQueryBuilder();
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- super.decorateIdentity(identifiers);
- identifiers.add(selectItem);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/CountSelectBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/CountSelectBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/builder/CountSelectBuilder.java
deleted file mode 100644
index 61dd73d..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/CountSelectBuilder.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * 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.query.builder;
-
-public interface CountSelectBuilder<B extends SatisfiedQueryBuilder<?>> extends
- SatisfiedSelectBuilder<B> {
-
- public B as(String alias);
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/CountSelectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/CountSelectBuilderImpl.java b/core/src/main/java/org/eobjects/metamodel/query/builder/CountSelectBuilderImpl.java
deleted file mode 100644
index e2114b2..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/CountSelectBuilderImpl.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * 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.query.builder;
-
-import java.util.List;
-
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-
-final class CountSelectBuilderImpl extends SatisfiedSelectBuilderImpl implements
- CountSelectBuilder<GroupedQueryBuilder> {
-
- private SelectItem selectItem;
-
- public CountSelectBuilderImpl(Query query, GroupedQueryBuilder queryBuilder) {
- super(queryBuilder);
- this.selectItem = SelectItem.getCountAllItem();
- query.select(selectItem);
- }
-
- @Override
- public GroupedQueryBuilder as(String alias) {
- if (alias == null) {
- throw new IllegalArgumentException("alias cannot be null");
- }
- selectItem.setAlias(alias);
- return getQueryBuilder();
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- super.decorateIdentity(identifiers);
- identifiers.add(selectItem);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/FilterBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/FilterBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/builder/FilterBuilder.java
deleted file mode 100644
index 0890c50..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/FilterBuilder.java
+++ /dev/null
@@ -1,355 +0,0 @@
-/**
- * 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.query.builder;
-
-import java.util.Collection;
-import java.util.Date;
-
-import org.eobjects.metamodel.schema.Column;
-
-/**
- * Interface for builder callbacks that "respond" to filter condition building.
- *
- * @param <B>
- * the builder type to return once filter has been created.
- */
-public interface FilterBuilder<B> {
-
- /**
- * Not null
- */
- public B isNull();
-
- /**
- * Is not null
- */
- public B isNotNull();
-
- /**
- * In ...
- */
- public B in(Collection<?> values);
-
- /**
- * In ...
- */
- public B in(Number... numbers);
-
- /**
- * In ...
- */
- public B in(String... strings);
-
- /**
- * Like ...
- *
- * (use '%' as wildcard).
- */
- public B like(String string);
-
- /**
- * Equal to ...
- */
- public B eq(Column column);
-
- /**
- * Equal to ...
- */
- public B eq(Date date);
-
- /**
- * Equal to ...
- */
- public B eq(Number number);
-
- /**
- * Equal to ...
- */
- public B eq(String string);
-
- /**
- * Equal to ...
- */
- public B eq(Boolean bool);
-
- /**
- * Equal to ...
- */
- public B eq(Object obj);
-
- /**
- * Equal to ...
- */
- public B isEquals(Column column);
-
- /**
- * Equal to ...
- */
- public B isEquals(Date date);
-
- /**
- * Equal to ...
- */
- public B isEquals(Number number);
-
- /**
- * Equal to ...
- */
- public B isEquals(String string);
-
- /**
- * Equal to ...
- */
- public B isEquals(Boolean bool);
-
- /**
- * Equal to ...
- */
- public B isEquals(Object obj);
-
- /**
- * Equal to ...
- *
- * @deprecated use 'eq' or 'isEquals' instead.
- */
- @Deprecated
- public B equals(Column column);
-
- /**
- * Equal to ...
- *
- * @deprecated use 'eq' or 'isEquals' instead.
- */
- @Deprecated
- public B equals(Date date);
-
- /**
- * Equal to ...
- *
- * @deprecated use 'eq' or 'isEquals' instead.
- */
- @Deprecated
- public B equals(Number number);
-
- /**
- * Equal to ...
- *
- * @deprecated use 'eq' or 'isEquals' instead.
- */
- @Deprecated
- public B equals(String string);
-
- /**
- * Equal to ...
- *
- * @deprecated use 'eq' or 'isEquals' instead.
- */
- @Deprecated
- public B equals(Boolean bool);
-
- /**
- * Not equal to ...
- */
- public B differentFrom(Column column);
-
- /**
- * Not equal to ...
- */
- public B differentFrom(Date date);
-
- /**
- * Not equal to ...
- */
- public B differentFrom(Number number);
-
- /**
- * Not equal to ...
- */
- public B differentFrom(String string);
-
- /**
- * Not equal to ...
- */
- public B differentFrom(Boolean bool);
-
- /**
- * Not equal to ...
- */
- public B differentFrom(Object obj);
-
- /**
- * Not equal to ...
- */
- public B ne(Column column);
-
- /**
- * Not equal to ...
- */
- public B ne(Date date);
-
- /**
- * Not equal to ...
- */
- public B ne(Number number);
-
- /**
- * Not equal to ...
- */
- public B ne(String string);
-
- /**
- * Not equal to ...
- */
- public B ne(Boolean bool);
-
- /**
- * Not equal to ...
- */
- public B ne(Object obj);
-
- /**
- * Greater than ...
- *
- * @deprecated use {@link #greaterThan(Column)} instead
- */
- @Deprecated
- public B higherThan(Column column);
-
- /**
- * Greater than ...
- */
- public B greaterThan(Column column);
-
- /**
- * Greater than ...
- */
- public B gt(Column column);
-
- /**
- * Greater than ...
- */
- public B greaterThan(Object obj);
-
- /**
- * Greater than ...
- */
- public B gt(Object obj);
-
- /**
- * Greater than ...
- *
- * @deprecated use {@link #greaterThan(Date)} instead
- */
- @Deprecated
- public B higherThan(Date date);
-
- /**
- * Greater than ...
- */
- public B greaterThan(Date date);
-
- /**
- * Greater than ...
- */
- public B gt(Date date);
-
- /**
- * @deprecated use {@link #greaterThan(Number)} instead
- */
- @Deprecated
- public B higherThan(Number number);
-
- /**
- * Greater than ...
- */
- public B greaterThan(Number number);
-
- /**
- * Greater than ...
- */
- public B gt(Number number);
-
- /**
- * Greater than ...
- *
- * @deprecated use {@link #greaterThan(String)} instead
- */
- @Deprecated
- public B higherThan(String string);
-
- /**
- * Greater than ...
- */
- public B greaterThan(String string);
-
- /**
- * Greater than ...
- */
- public B gt(String string);
-
- /**
- * Less than ...
- */
- public B lessThan(Column column);
-
- /**
- * Less than ...
- */
- public B lt(Column column);
-
- /**
- * Less than ...
- */
- public B lessThan(Date date);
-
- /**
- * Less than ...
- */
- public B lessThan(Number number);
-
- /**
- * Less than ...
- */
- public B lessThan(String string);
-
- /**
- * Less than ...
- */
- public B lessThan(Object obj);
-
- /**
- * Less than ...
- */
- public B lt(Object obj);
-
- /**
- * Less than ...
- */
- public B lt(Date date);
-
- /**
- * Less than ...
- */
- public B lt(Number number);
-
- /**
- * Less than ...
- */
- public B lt(String string);
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/FunctionSelectBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/FunctionSelectBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/builder/FunctionSelectBuilder.java
deleted file mode 100644
index 516ce5e..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/FunctionSelectBuilder.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * 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.query.builder;
-
-public interface FunctionSelectBuilder<B extends SatisfiedQueryBuilder<?>>
- extends SatisfiedSelectBuilder<B> {
-
- public B as(String alias);
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/FunctionSelectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/FunctionSelectBuilderImpl.java b/core/src/main/java/org/eobjects/metamodel/query/builder/FunctionSelectBuilderImpl.java
deleted file mode 100644
index 68e9b39..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/FunctionSelectBuilderImpl.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * 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.query.builder;
-
-import java.util.List;
-
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-
-final class FunctionSelectBuilderImpl extends SatisfiedSelectBuilderImpl
- implements FunctionSelectBuilder<GroupedQueryBuilder> {
-
- private SelectItem selectItem;
-
- public FunctionSelectBuilderImpl(FunctionType functionType, Column column,
- Query query, GroupedQueryBuilder queryBuilder) {
- super(queryBuilder);
-
- this.selectItem = new SelectItem(functionType, column);
-
- query.select(selectItem);
- }
-
- @Override
- public GroupedQueryBuilder as(String alias) {
- if (alias == null) {
- throw new IllegalArgumentException("alias cannot be null");
- }
- selectItem.setAlias(alias);
- return getQueryBuilder();
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- super.decorateIdentity(identifiers);
- identifiers.add(selectItem);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/GroupedQueryBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/GroupedQueryBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/builder/GroupedQueryBuilder.java
deleted file mode 100644
index d798d9b..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/GroupedQueryBuilder.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * 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.query.builder;
-
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.schema.Column;
-
-/**
- * Represents a built query that has a GROUP BY clause.
- *
- * @author Kasper Sørensen
- *
- */
-public interface GroupedQueryBuilder extends
- SatisfiedQueryBuilder<GroupedQueryBuilder> {
-
- public HavingBuilder having(FunctionType functionType, Column column);
-
- public SatisfiedOrderByBuilder<GroupedQueryBuilder> orderBy(
- FunctionType function, Column column);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/GroupedQueryBuilderCallback.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/GroupedQueryBuilderCallback.java b/core/src/main/java/org/eobjects/metamodel/query/builder/GroupedQueryBuilderCallback.java
deleted file mode 100644
index 6db7feb..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/GroupedQueryBuilderCallback.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/**
- * 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.query.builder;
-
-import java.util.List;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.util.BaseObject;
-
-abstract class GroupedQueryBuilderCallback extends BaseObject implements GroupedQueryBuilder {
-
- private GroupedQueryBuilder queryBuilder;
-
- public GroupedQueryBuilderCallback(GroupedQueryBuilder queryBuilder) {
- this.queryBuilder = queryBuilder;
- }
-
- protected GroupedQueryBuilder getQueryBuilder() {
- return queryBuilder;
- }
-
- @Override
- public SatisfiedQueryBuilder<GroupedQueryBuilder> firstRow(int firstRow) {
- return getQueryBuilder().firstRow(firstRow);
- }
-
- @Override
- public SatisfiedQueryBuilder<GroupedQueryBuilder> limit(int maxRows) {
- return getQueryBuilder().limit(maxRows);
- }
-
- @Override
- public SatisfiedQueryBuilder<GroupedQueryBuilder> offset(int offset) {
- return getQueryBuilder().offset(offset);
- }
-
- @Override
- public SatisfiedQueryBuilder<GroupedQueryBuilder> maxRows(int maxRows) {
- return getQueryBuilder().maxRows(maxRows);
- }
-
- @Override
- public SatisfiedSelectBuilder<GroupedQueryBuilder> select(Column... columns) {
- return getQueryBuilder().select(columns);
- }
-
- @Override
- public final Column findColumn(String columnName) throws IllegalArgumentException {
- return getQueryBuilder().findColumn(columnName);
- }
-
- @Override
- public ColumnSelectBuilder<GroupedQueryBuilder> select(Column column) {
- return getQueryBuilder().select(column);
- }
-
- @Override
- public FunctionSelectBuilder<GroupedQueryBuilder> select(FunctionType functionType, Column column) {
- return getQueryBuilder().select(functionType, column);
- }
-
- @Override
- public ColumnSelectBuilder<GroupedQueryBuilder> select(String columnName) {
- return getQueryBuilder().select(columnName);
- }
-
- @Override
- public CountSelectBuilder<GroupedQueryBuilder> selectCount() {
- return getQueryBuilder().selectCount();
- }
-
- @Override
- public WhereBuilder<GroupedQueryBuilder> where(Column column) {
- return getQueryBuilder().where(column);
- }
-
- @Override
- public SatisfiedOrderByBuilder<GroupedQueryBuilder> orderBy(Column column) {
- return getQueryBuilder().orderBy(column);
- }
-
- @Override
- public GroupedQueryBuilder groupBy(String columnName) {
- return getQueryBuilder().groupBy(columnName);
- }
-
- @Override
- public GroupedQueryBuilder groupBy(Column column) {
- return getQueryBuilder().groupBy(column);
- }
-
- @Override
- public Query toQuery() {
- return getQueryBuilder().toQuery();
- }
-
- @Override
- public CompiledQuery compile() {
- return getQueryBuilder().compile();
- }
-
- @Override
- public HavingBuilder having(FunctionType functionType, Column column) {
- return getQueryBuilder().having(functionType, column);
- }
-
- @Override
- public GroupedQueryBuilder groupBy(Column... columns) {
- getQueryBuilder().groupBy(columns);
- return this;
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- identifiers.add(queryBuilder);
- }
-
- @Override
- public DataSet execute() {
- return queryBuilder.execute();
- }
-
- @Override
- public WhereBuilder<GroupedQueryBuilder> where(String columnName) {
- return getQueryBuilder().where(columnName);
- }
-
- @Override
- public SatisfiedQueryBuilder<GroupedQueryBuilder> where(FilterItem... filters) {
- return getQueryBuilder().where(filters);
- }
-
- @Override
- public SatisfiedQueryBuilder<GroupedQueryBuilder> where(Iterable<FilterItem> filters) {
- return getQueryBuilder().where(filters);
- }
-
- @Override
- public SatisfiedOrderByBuilder<GroupedQueryBuilder> orderBy(String columnName) {
- return getQueryBuilder().orderBy(columnName);
- }
-
- @Override
- public SatisfiedOrderByBuilder<GroupedQueryBuilder> orderBy(FunctionType function, Column column) {
- return getQueryBuilder().orderBy(function, column);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/GroupedQueryBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/GroupedQueryBuilderImpl.java b/core/src/main/java/org/eobjects/metamodel/query/builder/GroupedQueryBuilderImpl.java
deleted file mode 100644
index bd5248c..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/GroupedQueryBuilderImpl.java
+++ /dev/null
@@ -1,332 +0,0 @@
-/**
- * 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.query.builder;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.BaseObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Main implementation of the {@link GroupedQueryBuilder} interface.
- */
-final class GroupedQueryBuilderImpl extends BaseObject implements GroupedQueryBuilder {
-
- private static final Logger logger = LoggerFactory.getLogger(GroupedQueryBuilderImpl.class);
-
- private final Query _query;
- private final DataContext _dataContext;
-
- public GroupedQueryBuilderImpl(DataContext dataContext, Query query) {
- if (query == null) {
- throw new IllegalArgumentException("query cannot be null");
- }
- _dataContext = dataContext;
- _query = query;
- }
-
- @Override
- public ColumnSelectBuilder<GroupedQueryBuilder> select(Column column) {
- if (column == null) {
- throw new IllegalArgumentException("column cannot be null");
- }
- return new ColumnSelectBuilderImpl(column, _query, this);
- }
-
- @Override
- public FunctionSelectBuilder<GroupedQueryBuilder> select(FunctionType function, Column column) {
- if (function == null) {
- throw new IllegalArgumentException("function cannot be null");
- }
- if (column == null) {
- throw new IllegalArgumentException("column cannot be null");
- }
- return new FunctionSelectBuilderImpl(function, column, _query, this);
- }
-
- @Override
- public SatisfiedQueryBuilder<GroupedQueryBuilder> where(FilterItem... filters) {
- _query.where(filters);
- return this;
- }
-
- @Override
- public SatisfiedQueryBuilder<GroupedQueryBuilder> where(Iterable<FilterItem> filters) {
- _query.where(filters);
- return this;
- }
-
- @Override
- public ColumnSelectBuilder<GroupedQueryBuilder> select(String columnName) {
- Column column = findColumn(columnName);
- return select(column);
- }
-
- @Override
- public CountSelectBuilder<GroupedQueryBuilder> selectCount() {
- return new CountSelectBuilderImpl(_query, this);
- }
-
- @Override
- public SatisfiedSelectBuilder<GroupedQueryBuilder> select(Column... columns) {
- if (columns == null) {
- throw new IllegalArgumentException("column cannot be null");
- }
- _query.select(columns);
- return new SatisfiedSelectBuilderImpl(this);
- }
-
- @Override
- public WhereBuilder<GroupedQueryBuilder> where(Column column) {
- if (column == null) {
- throw new IllegalArgumentException("column cannot be null");
- }
- return new WhereBuilderImpl(column, _query, this);
- }
-
- @Override
- public WhereBuilder<GroupedQueryBuilder> where(String columnName) {
- Column column = findColumn(columnName);
- return where(column);
- }
-
- @Override
- public Column findColumn(final String columnName) throws IllegalArgumentException {
- if (columnName == null) {
- throw new IllegalArgumentException("columnName cannot be null");
- }
-
- final List<FromItem> fromItems = _query.getFromClause().getItems();
- final List<SelectItem> selectItems = _query.getSelectClause().getItems();
-
- int dotIndex = columnName.indexOf('.');
- if (dotIndex != -1) {
- // check aliases of from items
- final String aliasPart = columnName.substring(0, dotIndex);
- final String columnPart = columnName.substring(dotIndex + 1);
-
- for (FromItem fromItem : fromItems) {
- Column column = null;
- column = findColumnInAliasedTable(column, fromItem, aliasPart, columnPart);
- if (column != null) {
- return column;
- }
- }
- }
-
- // check columns already in select clause
- for (SelectItem item : selectItems) {
- Column column = item.getColumn();
- if (column != null) {
- if (columnName.equals(column.getName())) {
- return column;
- }
- }
- }
-
- for (FromItem fromItem : fromItems) {
- Table table = fromItem.getTable();
- if (table != null) {
- Column column = table.getColumnByName(columnName);
- if (column != null) {
- return column;
- }
- }
- }
-
- Column column = _dataContext.getColumnByQualifiedLabel(columnName);
- if (column != null) {
- return column;
- }
-
- final IllegalArgumentException exception = new IllegalArgumentException("Could not find column: " + columnName);
-
- if (logger.isDebugEnabled()) {
- logger.debug("findColumn('" + columnName + "') could not resolve a column", exception);
- for (FromItem fromItem : fromItems) {
- final Table table = fromItem.getTable();
- if (table != null) {
- logger.debug("Table available in FROM item: {}. Column names: {}", table,
- Arrays.toString(table.getColumnNames()));
- }
- }
- }
-
- throw exception;
- }
-
- private Column findColumnInAliasedTable(Column column, FromItem fromItem, String aliasPart, String columnPart) {
- if (column != null) {
- // ensure that if the column has already been found, return it
- return column;
- }
-
- Table table = fromItem.getTable();
- if (table != null) {
- String alias = fromItem.getAlias();
- if (alias != null && alias.equals(aliasPart)) {
- column = table.getColumnByName(columnPart);
- }
- } else {
- FromItem leftSide = fromItem.getLeftSide();
- column = findColumnInAliasedTable(column, leftSide, aliasPart, columnPart);
- FromItem rightSide = fromItem.getRightSide();
- column = findColumnInAliasedTable(column, rightSide, aliasPart, columnPart);
- if (column != null) {
- Query subQuery = fromItem.getSubQuery();
- if (subQuery != null) {
- List<FromItem> items = subQuery.getFromClause().getItems();
- for (FromItem subQueryFromItem : items) {
- column = findColumnInAliasedTable(column, subQueryFromItem, aliasPart, columnPart);
- }
- }
- }
- }
-
- return column;
- }
-
- @Override
- public SatisfiedOrderByBuilder<GroupedQueryBuilder> orderBy(String columnName) {
- return orderBy(findColumn(columnName));
- }
-
- @Override
- public SatisfiedOrderByBuilder<GroupedQueryBuilder> orderBy(Column column) {
- if (column == null) {
- throw new IllegalArgumentException("column cannot be null");
- }
- return new SatisfiedOrderByBuilderImpl(column, _query, this);
- }
-
- @Override
- public SatisfiedOrderByBuilder<GroupedQueryBuilder> orderBy(FunctionType function, Column column) {
- if (function == null) {
- throw new IllegalArgumentException("function cannot be null");
- }
- if (column == null) {
- throw new IllegalArgumentException("column cannot be null");
- }
- return new SatisfiedOrderByBuilderImpl(function, column, _query, this);
- }
-
- @Override
- public GroupedQueryBuilder groupBy(Column column) {
- if (column == null) {
- throw new IllegalArgumentException("column cannot be null");
- }
- _query.groupBy(column);
- return this;
- }
-
- @Override
- public GroupedQueryBuilder groupBy(String columnName) {
- Column column = findColumn(columnName);
- return groupBy(column);
- }
-
- @Override
- public GroupedQueryBuilder groupBy(Column... columns) {
- if (columns == null) {
- throw new IllegalArgumentException("columns cannot be null");
- }
- _query.groupBy(columns);
- return this;
- }
-
- @Override
- public HavingBuilder having(FunctionType function, Column column) {
- if (function == null) {
- throw new IllegalArgumentException("function cannot be null");
- }
- if (column == null) {
- throw new IllegalArgumentException("column cannot be null");
- }
- return new HavingBuilderImpl(function, column, _query, this);
- }
-
- @Override
- public SatisfiedQueryBuilder<GroupedQueryBuilder> limit(int maxRows) {
- _query.setMaxRows(maxRows);
- return this;
- }
-
- @Override
- public SatisfiedQueryBuilder<GroupedQueryBuilder> maxRows(int maxRows) {
- _query.setMaxRows(maxRows);
- return this;
- }
-
- @Override
- public SatisfiedQueryBuilder<GroupedQueryBuilder> firstRow(int firstRow) {
- if (firstRow >= 0) {
- _query.setFirstRow(firstRow);
- } else {
- _query.setFirstRow(null);
- }
- return this;
- }
-
- @Override
- public SatisfiedQueryBuilder<GroupedQueryBuilder> offset(int offset) {
- if (offset >= 0) {
- _query.setFirstRow(offset + 1);
- } else {
- _query.setFirstRow(null);
- }
- return this;
- }
-
- @Override
- public String toString() {
- return _query.toSql();
- }
-
- @Override
- public Query toQuery() {
- return _query.clone();
- }
-
- @Override
- public CompiledQuery compile() {
- return _dataContext.compileQuery(_query);
- }
-
- @Override
- public DataSet execute() {
- return _dataContext.executeQuery(_query);
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- identifiers.add(_query);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/HavingBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/HavingBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/builder/HavingBuilder.java
deleted file mode 100644
index 1596ada..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/HavingBuilder.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * 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.query.builder;
-
-/**
- * Builder interface for having items.
- */
-public interface HavingBuilder extends FilterBuilder<SatisfiedHavingBuilder> {
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/HavingBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/HavingBuilderImpl.java b/core/src/main/java/org/eobjects/metamodel/query/builder/HavingBuilderImpl.java
deleted file mode 100644
index 13b197d..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/HavingBuilderImpl.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * 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.query.builder;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-
-final class HavingBuilderImpl extends
- AbstractQueryFilterBuilder<SatisfiedHavingBuilder> implements
- HavingBuilder, SatisfiedHavingBuilder {
-
- private final Query _query;
- private final List<FilterItem> _orFilters;
- private FilterItem _parentOrFilter;
-
- public HavingBuilderImpl(FunctionType function, Column column, Query query,
- GroupedQueryBuilder queryBuilder) {
- super(new SelectItem(function, column), queryBuilder);
- _query = query;
- _orFilters = new ArrayList<FilterItem>();
- }
-
- public HavingBuilderImpl(FunctionType function, Column column, Query query,
- FilterItem parentOrFilter, List<FilterItem> orFilters,
- GroupedQueryBuilder queryBuilder) {
- super(new SelectItem(function, column), queryBuilder);
- _query = query;
- _orFilters = orFilters;
- _parentOrFilter = parentOrFilter;
- }
-
- @Override
- protected SatisfiedHavingBuilder applyFilter(FilterItem filter) {
- if (_parentOrFilter == null) {
- _query.having(filter);
- } else {
- if (_parentOrFilter.getChildItemCount() == 1) {
- _query.getHavingClause().removeItem(_orFilters.get(0));
- _query.getHavingClause().addItem(_parentOrFilter);
- }
- }
- _orFilters.add(filter);
- return this;
- }
-
- @Override
- public HavingBuilder or(FunctionType function, Column column) {
- if (function == null) {
- throw new IllegalArgumentException("function cannot be null");
- }
- if (column == null) {
- throw new IllegalArgumentException("column cannot be null");
- }
- if (_parentOrFilter == null) {
- _parentOrFilter = new FilterItem(_orFilters);
- }
- return new HavingBuilderImpl(function, column, _query, _parentOrFilter,
- _orFilters, getQueryBuilder());
- }
-
- @Override
- public HavingBuilder and(FunctionType function, Column column) {
- return getQueryBuilder().having(function, column);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/InitFromBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/InitFromBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/builder/InitFromBuilder.java
deleted file mode 100644
index fcbdbcf..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/InitFromBuilder.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.query.builder;
-
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * The initial interface used when building a query. A query starts by stating
- * the FROM clause.
- *
- * @author Kasper Sørensen
- */
-public interface InitFromBuilder {
-
- public TableFromBuilder from(Table table);
-
- public TableFromBuilder from(Schema schema, String tableName);
-
- public TableFromBuilder from(String schemaName, String tableName);
-
- public TableFromBuilder from(String tableName);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/InitFromBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/InitFromBuilderImpl.java b/core/src/main/java/org/eobjects/metamodel/query/builder/InitFromBuilderImpl.java
deleted file mode 100644
index 3d523a8..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/InitFromBuilderImpl.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- * 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.query.builder;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.BaseObject;
-
-public final class InitFromBuilderImpl extends BaseObject implements InitFromBuilder {
-
- private DataContext dataContext;
- private Query query;
-
- public InitFromBuilderImpl(DataContext dataContext) {
- this.dataContext = dataContext;
- this.query = new Query();
- }
-
- @Override
- public TableFromBuilder from(Table table) {
- if (table == null) {
- throw new IllegalArgumentException("table cannot be null");
- }
- return new TableFromBuilderImpl(table, query, dataContext);
- }
-
- @Override
- public TableFromBuilder from(String schemaName, String tableName) {
- if (schemaName == null) {
- throw new IllegalArgumentException("schemaName cannot be null");
- }
- if (tableName == null) {
- throw new IllegalArgumentException("tableName cannot be null");
- }
- Schema schema = dataContext.getSchemaByName(schemaName);
- if (schema == null) {
- schema = dataContext.getDefaultSchema();
- }
- return from(schema, tableName);
- }
-
- @Override
- public TableFromBuilder from(Schema schema, String tableName) {
- 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()));
- }
- return from(table);
- }
-
- @Override
- public TableFromBuilder from(String tableName) {
- if (tableName == null) {
- throw new IllegalArgumentException("tableName cannot be null");
- }
- Table table = dataContext.getTableByQualifiedLabel(tableName);
- if (table == null) {
- throw new IllegalArgumentException("No such table: " + tableName);
- }
- return from(table);
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- identifiers.add(query);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/JoinFromBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/JoinFromBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/builder/JoinFromBuilder.java
deleted file mode 100644
index 1cad5fc..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/JoinFromBuilder.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * 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.query.builder;
-
-import org.eobjects.metamodel.schema.Column;
-
-public interface JoinFromBuilder extends SatisfiedFromBuilder {
-
- public SatisfiedFromBuilder on(Column left, Column right);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/JoinFromBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/JoinFromBuilderImpl.java b/core/src/main/java/org/eobjects/metamodel/query/builder/JoinFromBuilderImpl.java
deleted file mode 100644
index 6e9520c..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/JoinFromBuilderImpl.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * 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.query.builder;
-
-import java.util.List;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.JoinType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-
-final class JoinFromBuilderImpl extends SatisfiedFromBuilderCallback implements
- JoinFromBuilder {
-
- private JoinType joinType;
- private FromItem leftItem;
- private FromItem rightItem;
-
- public JoinFromBuilderImpl(Query query, FromItem leftItem,
- Table rightTable, JoinType joinType, DataContext dataContext) {
- super(query, dataContext);
- this.joinType = joinType;
- this.leftItem = leftItem;
- this.rightItem = new FromItem(rightTable);
- }
-
- @Override
- public SatisfiedFromBuilder on(Column left, Column right) {
- if (left == null) {
- throw new IllegalArgumentException("left cannot be null");
- }
- if (right == null) {
- throw new IllegalArgumentException("right cannot be null");
- }
- getQuery().getFromClause().removeItem(leftItem);
-
- SelectItem[] leftOn = new SelectItem[] { new SelectItem(left) };
- SelectItem[] rightOn = new SelectItem[] { new SelectItem(right) };
- FromItem fromItem = new FromItem(joinType, leftItem, rightItem, leftOn,
- rightOn);
-
- getQuery().from(fromItem);
-
- return this;
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- super.decorateIdentity(identifiers);
- identifiers.add(joinType);
- identifiers.add(leftItem);
- identifiers.add(rightItem);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedFromBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedFromBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedFromBuilder.java
deleted file mode 100644
index 6cc2611..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedFromBuilder.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * 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.query.builder;
-
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * Represents a builder where the FROM part is satisfied, ie. a SELECT clause is
- * now buildable.
- *
- * @author Kasper Sørensen
- */
-public interface SatisfiedFromBuilder {
-
- public TableFromBuilder and(Table table);
-
- public TableFromBuilder and(String schemaName, String tableName);
-
- public TableFromBuilder and(String tableName);
-
- public ColumnSelectBuilder<?> select(Column column);
-
- public FunctionSelectBuilder<?> select(FunctionType functionType, Column column);
-
- public CountSelectBuilder<?> selectCount();
-
- public SatisfiedSelectBuilder<?> select(Column... columns);
-
- public SatisfiedSelectBuilder<?> selectAll();
-
- public ColumnSelectBuilder<?> select(String columnName);
-
- public SatisfiedSelectBuilder<?> select(String... columnNames);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedFromBuilderCallback.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedFromBuilderCallback.java b/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedFromBuilderCallback.java
deleted file mode 100644
index d6798c2..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedFromBuilderCallback.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/**
- * 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.query.builder;
-
-import java.util.List;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.BaseObject;
-
-abstract class SatisfiedFromBuilderCallback extends BaseObject implements SatisfiedFromBuilder {
-
- private Query query;
- private DataContext dataContext;
-
- public SatisfiedFromBuilderCallback(Query query, DataContext dataContext) {
- this.query = query;
- this.dataContext = dataContext;
- }
-
- protected Query getQuery() {
- return query;
- }
-
- protected DataContext getDataContext() {
- return dataContext;
- }
-
- @Override
- public TableFromBuilder and(Table table) {
- if (table == null) {
- throw new IllegalArgumentException("table cannot be null");
- }
-
- return new TableFromBuilderImpl(table, query, dataContext);
- }
-
- @Override
- public ColumnSelectBuilder<?> select(Column column) {
- if (column == null) {
- throw new IllegalArgumentException("column cannot be null");
- }
-
- GroupedQueryBuilder queryBuilder = new GroupedQueryBuilderImpl(dataContext, query);
- return new ColumnSelectBuilderImpl(column, query, queryBuilder);
- }
-
- @Override
- public SatisfiedSelectBuilder<?> selectAll() {
- getQuery().selectAll();
- GroupedQueryBuilder queryBuilder = new GroupedQueryBuilderImpl(dataContext, query);
- return new SatisfiedSelectBuilderImpl(queryBuilder);
- }
-
- @Override
- public FunctionSelectBuilder<?> select(FunctionType functionType, Column column) {
- if (functionType == null) {
- throw new IllegalArgumentException("functionType cannot be null");
- }
- if (column == null) {
- throw new IllegalArgumentException("column cannot be null");
- }
-
- GroupedQueryBuilder queryBuilder = new GroupedQueryBuilderImpl(dataContext, query);
- return new FunctionSelectBuilderImpl(functionType, column, query, queryBuilder);
- }
-
- @Override
- public CountSelectBuilder<?> selectCount() {
- GroupedQueryBuilder queryBuilder = new GroupedQueryBuilderImpl(dataContext, query);
- return new CountSelectBuilderImpl(query, queryBuilder);
- }
-
- @Override
- public TableFromBuilder and(String schemaName, String tableName) {
- if (schemaName == null) {
- throw new IllegalArgumentException("schemaName cannot be null");
- }
- if (tableName == null) {
- throw new IllegalArgumentException("tableName cannot be null");
- }
-
- Schema schema = dataContext.getSchemaByName(schemaName);
- if (schema == null) {
- schema = dataContext.getDefaultSchema();
- }
- return and(schema, tableName);
- }
-
- private TableFromBuilder and(Schema schema, String tableName) {
- Table table = schema.getTableByName(tableName);
- return and(table);
- }
-
- @Override
- public TableFromBuilder and(String tableName) {
- if (tableName == null) {
- throw new IllegalArgumentException("tableName cannot be null");
- }
- return and(dataContext.getDefaultSchema(), tableName);
- }
-
- @Override
- public SatisfiedSelectBuilder<?> select(Column... columns) {
- if (columns == null) {
- throw new IllegalArgumentException("columns cannot be null");
- }
- query.select(columns);
- GroupedQueryBuilder queryBuilder = new GroupedQueryBuilderImpl(dataContext, query);
- return new SatisfiedSelectBuilderImpl(queryBuilder);
- }
-
- @Override
- public SatisfiedSelectBuilder<?> select(String... columnNames) {
- if (columnNames == null) {
- throw new IllegalArgumentException("columnNames cannot be null");
- }
- for (String columnName : columnNames) {
- select(columnName);
- }
- GroupedQueryBuilder queryBuilder = new GroupedQueryBuilderImpl(dataContext, query);
- return new SatisfiedSelectBuilderImpl(queryBuilder);
- }
-
- @Override
- public ColumnSelectBuilder<?> select(String columnName) {
- if (columnName == null) {
- throw new IllegalArgumentException("columnName cannot be null");
- }
-
- GroupedQueryBuilderImpl queryBuilder = new GroupedQueryBuilderImpl(dataContext, query);
- Column column = queryBuilder.findColumn(columnName);
- return select(column);
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- identifiers.add(query);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedHavingBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedHavingBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedHavingBuilder.java
deleted file mode 100644
index b5c6efe..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedHavingBuilder.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * 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.query.builder;
-
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.schema.Column;
-
-public interface SatisfiedHavingBuilder extends GroupedQueryBuilder {
-
- public HavingBuilder or(FunctionType functionType, Column column);
-
- public HavingBuilder and(FunctionType functionType, Column column);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedOrderByBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedOrderByBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedOrderByBuilder.java
deleted file mode 100644
index a7023cf..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedOrderByBuilder.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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.query.builder;
-
-import org.eobjects.metamodel.schema.Column;
-
-public interface SatisfiedOrderByBuilder<B extends SatisfiedQueryBuilder<?>>
- extends SatisfiedQueryBuilder<B> {
-
- public B asc();
-
- public B desc();
-
- public SatisfiedOrderByBuilder<B> and(Column column);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedOrderByBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedOrderByBuilderImpl.java b/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedOrderByBuilderImpl.java
deleted file mode 100644
index 5ebe755..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedOrderByBuilderImpl.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * 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.query.builder;
-
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.OrderByItem;
-import org.eobjects.metamodel.query.OrderByItem.Direction;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-
-final class SatisfiedOrderByBuilderImpl extends GroupedQueryBuilderCallback
- implements SatisfiedOrderByBuilder<GroupedQueryBuilder> {
-
- private OrderByItem orderByitem;
-
- public SatisfiedOrderByBuilderImpl(Column column, Query query,
- GroupedQueryBuilder queryBuilder) {
- super(queryBuilder);
- orderByitem = new OrderByItem(new SelectItem(column));
- query.orderBy(orderByitem);
- }
-
- public SatisfiedOrderByBuilderImpl(FunctionType function, Column column,
- Query query, GroupedQueryBuilder queryBuilder) {
- super(queryBuilder);
- orderByitem = new OrderByItem(new SelectItem(function, column));
- query.orderBy(orderByitem);
- }
-
- @Override
- public GroupedQueryBuilder asc() {
- orderByitem.setDirection(Direction.ASC);
- return getQueryBuilder();
- }
-
- @Override
- public GroupedQueryBuilder desc() {
- orderByitem.setDirection(Direction.DESC);
- return getQueryBuilder();
- }
-
- @Override
- public SatisfiedOrderByBuilder<GroupedQueryBuilder> and(Column column) {
- return getQueryBuilder().orderBy(column);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedQueryBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedQueryBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedQueryBuilder.java
deleted file mode 100644
index dd98935..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedQueryBuilder.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/**
- * 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.query.builder;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-
-/**
- * Represents a built query that is satisfied and ready for querying or further
- * building.
- *
- * @author Kasper Sørensen
- *
- * @param <B>
- */
-public interface SatisfiedQueryBuilder<B extends SatisfiedQueryBuilder<?>> {
-
- public ColumnSelectBuilder<B> select(Column column);
-
- public SatisfiedSelectBuilder<B> select(Column... columns);
-
- /**
- * Sets the offset (number of rows to skip) of the query that is being
- * built.
- *
- * Note that this number is a 0-based variant of invoking
- * {@link #firstRow(int)}.
- *
- * @param offset
- * the number of rows to skip
- * @return
- */
- public SatisfiedQueryBuilder<B> offset(int offset);
-
- /**
- * Sets the first row of the query that is being built.
- *
- * Note that this is a 1-based variant of invoking {@link #limit(int)}.
- *
- * @param firstRow
- * @return
- */
- public SatisfiedQueryBuilder<B> firstRow(int firstRow);
-
- /**
- * Sets the limit (aka. max rows) of the query that is being built.
- *
- * @param maxRows
- * @return
- */
- public SatisfiedQueryBuilder<B> limit(int limit);
-
- /**
- * Sets the max rows (aka. limit) of the query that is being built.
- *
- * @param maxRows
- * @return
- */
- public SatisfiedQueryBuilder<B> maxRows(int maxRows);
-
- public FunctionSelectBuilder<B> select(FunctionType functionType, Column column);
-
- public CountSelectBuilder<B> selectCount();
-
- public ColumnSelectBuilder<B> select(String columnName);
-
- public WhereBuilder<B> where(Column column);
-
- public WhereBuilder<B> where(String columnName);
-
- public SatisfiedQueryBuilder<B> where(FilterItem... filters);
-
- public SatisfiedQueryBuilder<B> where(Iterable<FilterItem> filters);
-
- public SatisfiedOrderByBuilder<B> orderBy(String columnName);
-
- public SatisfiedOrderByBuilder<B> orderBy(Column column);
-
- public GroupedQueryBuilder groupBy(String columnName);
-
- public GroupedQueryBuilder groupBy(Column column);
-
- public B groupBy(Column... columns);
-
- /**
- * Gets the built query as a {@link Query} object. Typically the returned
- * query will be a clone of the built query to prevent conflicting
- * mutations.
- *
- * @return a {@link Query} object representing the built query.
- */
- public Query toQuery();
-
- public CompiledQuery compile();
-
- /**
- * Executes the built query. This call is similar to calling
- * {@link #toQuery()} and then {@link DataContext#executeQuery(Query)}.
- *
- * @return the {@link DataSet} that is returned by executing the query.
- */
- public DataSet execute();
-
- /**
- * Finds a column by name within the already defined FROM items
- *
- * @param columnName
- * @return
- * @throws IllegalArgumentException
- */
- public Column findColumn(String columnName) throws IllegalArgumentException;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedSelectBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedSelectBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedSelectBuilder.java
deleted file mode 100644
index 886b763..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedSelectBuilder.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * 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.query.builder;
-
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.schema.Column;
-
-public interface SatisfiedSelectBuilder<B extends SatisfiedQueryBuilder<?>>
- extends SatisfiedQueryBuilder<B> {
-
- public ColumnSelectBuilder<B> and(Column column);
-
- public SatisfiedSelectBuilder<B> and(Column ... columns);
-
- public FunctionSelectBuilder<B> and(FunctionType function,
- Column column);
-
- public SatisfiedSelectBuilder<B> and(String columnName);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedSelectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedSelectBuilderImpl.java b/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedSelectBuilderImpl.java
deleted file mode 100644
index 2fe66ce..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedSelectBuilderImpl.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * 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.query.builder;
-
-import org.eobjects.metamodel.query.FunctionType;
-import org.eobjects.metamodel.schema.Column;
-
-class SatisfiedSelectBuilderImpl extends GroupedQueryBuilderCallback implements
- SatisfiedSelectBuilder<GroupedQueryBuilder> {
-
- public SatisfiedSelectBuilderImpl(GroupedQueryBuilder queryBuilder) {
- super(queryBuilder);
- }
-
- @Override
- public ColumnSelectBuilder<GroupedQueryBuilder> and(Column column) {
- if (column == null) {
- throw new IllegalArgumentException("column cannot be null");
- }
- return getQueryBuilder().select(column);
- }
-
- @Override
- public SatisfiedSelectBuilder<GroupedQueryBuilder> and(Column... columns) {
- if (columns == null) {
- throw new IllegalArgumentException("columns cannot be null");
- }
- return getQueryBuilder().select(columns);
- }
-
- @Override
- public FunctionSelectBuilder<GroupedQueryBuilder> and(
- FunctionType functionType, Column column) {
- if (functionType == null) {
- throw new IllegalArgumentException("functionType cannot be null");
- }
- if (column == null) {
- throw new IllegalArgumentException("column cannot be null");
- }
- return getQueryBuilder().select(functionType, column);
- }
-
- @Override
- public SatisfiedSelectBuilder<GroupedQueryBuilder> and(String columnName) {
- if (columnName == null) {
- throw new IllegalArgumentException("columnName cannot be null");
- }
- return getQueryBuilder().select(columnName);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedWhereBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedWhereBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedWhereBuilder.java
deleted file mode 100644
index d236ed2..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/SatisfiedWhereBuilder.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * 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.query.builder;
-
-import org.eobjects.metamodel.schema.Column;
-
-public interface SatisfiedWhereBuilder<B extends SatisfiedQueryBuilder<?>>
- extends SatisfiedQueryBuilder<B> {
-
- public WhereBuilder<B> or(String columnName);
-
- public WhereBuilder<B> or(Column column);
-
- public WhereBuilder<B> and(String columnName);
-
- public WhereBuilder<B> and(Column column);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/TableFromBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/TableFromBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/builder/TableFromBuilder.java
deleted file mode 100644
index d030653..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/TableFromBuilder.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * 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.query.builder;
-
-import org.eobjects.metamodel.schema.Table;
-
-public interface TableFromBuilder extends
- SatisfiedFromBuilder {
-
- public JoinFromBuilder innerJoin(Table table);
-
- public JoinFromBuilder leftJoin(Table table);
-
- public JoinFromBuilder rightJoin(Table table);
-
- public TableFromBuilder as(String alias);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/TableFromBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/TableFromBuilderImpl.java b/core/src/main/java/org/eobjects/metamodel/query/builder/TableFromBuilderImpl.java
deleted file mode 100644
index 4460d8e..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/TableFromBuilderImpl.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/**
- * 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.query.builder;
-
-import java.util.List;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.JoinType;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Table;
-
-final class TableFromBuilderImpl extends SatisfiedFromBuilderCallback implements
- TableFromBuilder {
-
- private FromItem fromItem;
-
- public TableFromBuilderImpl(Table table, Query query,
- DataContext dataContext) {
- super(query, dataContext);
-
- fromItem = new FromItem(table);
- query.from(fromItem);
- }
-
- @Override
- public JoinFromBuilder innerJoin(Table table) {
- if (table == null) {
- throw new IllegalArgumentException("table cannot be null");
- }
- return new JoinFromBuilderImpl(getQuery(), fromItem, table,
- JoinType.INNER, getDataContext());
- }
-
- @Override
- public JoinFromBuilder leftJoin(Table table) {
- if (table == null) {
- throw new IllegalArgumentException("table cannot be null");
- }
- return new JoinFromBuilderImpl(getQuery(), fromItem, table,
- JoinType.LEFT, getDataContext());
- }
-
- @Override
- public JoinFromBuilder rightJoin(Table table) {
- if (table == null) {
- throw new IllegalArgumentException("table cannot be null");
- }
- return new JoinFromBuilderImpl(getQuery(), fromItem, table,
- JoinType.RIGHT, getDataContext());
- }
-
- @Override
- public TableFromBuilder as(String alias) {
- if (alias == null) {
- throw new IllegalArgumentException("alias cannot be null");
- }
- fromItem.setAlias(alias);
- return this;
- }
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- super.decorateIdentity(identifiers);
- identifiers.add(fromItem);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/query/builder/WhereBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/query/builder/WhereBuilder.java b/core/src/main/java/org/eobjects/metamodel/query/builder/WhereBuilder.java
deleted file mode 100644
index 3055214..0000000
--- a/core/src/main/java/org/eobjects/metamodel/query/builder/WhereBuilder.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- * 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.query.builder;
-
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.QueryParameter;
-
-/**
- * Builder interface for WHERE items.
- *
- * In addition to the {@link FilterBuilder}, the WHERE builder allows using
- * {@link QueryParameter}s as operands in the generated filters.
- *
- * @param <B>
- */
-public interface WhereBuilder<B extends SatisfiedQueryBuilder<?>> extends FilterBuilder<SatisfiedWhereBuilder<B>> {
-
- /**
- * Equals to a query parameter. Can be used with {@link CompiledQuery}
- * objects.
- */
- public SatisfiedWhereBuilder<B> eq(QueryParameter queryParameter);
-
- /**
- * Equals to a query parameter. Can be used with {@link CompiledQuery}
- * objects.
- */
- public SatisfiedWhereBuilder<B> isEquals(QueryParameter queryParameter);
-
- /**
- * Not equals to a query parameter. Can be used with {@link CompiledQuery}
- * objects.
- */
- public SatisfiedWhereBuilder<B> differentFrom(QueryParameter queryParameter);
-
- /**
- * Not equals to a query parameter. Can be used with {@link CompiledQuery}
- * objects.
- */
- public SatisfiedWhereBuilder<B> ne(QueryParameter queryParameter);
-
- /**
- * Greater than a query parameter. Can be used with {@link CompiledQuery}
- * objects.
- */
- public SatisfiedWhereBuilder<B> greaterThan(QueryParameter queryParameter);
-
- /**
- * Greater than a query parameter. Can be used with {@link CompiledQuery}
- * objects.
- */
- public SatisfiedWhereBuilder<B> gt(QueryParameter queryParameter);
-
- /**
- * Less than a query parameter. Can be used with {@link CompiledQuery}
- * objects.
- */
- public SatisfiedWhereBuilder<B> lessThan(QueryParameter queryParameter);
-
- /**
- * Less than a query parameter. Can be used with {@link CompiledQuery}
- * objects.
- */
- public SatisfiedWhereBuilder<B> lt(QueryParameter queryParameter);
-
- /**
- * Like a query parameter. Can be used with {@link CompiledQuery} objects.
- */
- public SatisfiedWhereBuilder<B> like(QueryParameter queryParameter);
-}
\ No newline at end of file
[49/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
Posted by ka...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/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
new file mode 100644
index 0000000..d84da6a
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/QueryPostprocessDataContext.java
@@ -0,0 +1,589 @@
+/**
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eobjects.metamodel.convert.ConvertedDataSetInterceptor;
+import org.eobjects.metamodel.convert.Converters;
+import org.eobjects.metamodel.convert.HasReadTypeConverters;
+import org.eobjects.metamodel.convert.TypeConverter;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.DataSetHeader;
+import org.eobjects.metamodel.data.DefaultRow;
+import org.eobjects.metamodel.data.EmptyDataSet;
+import org.eobjects.metamodel.data.FirstRowDataSet;
+import org.eobjects.metamodel.data.InMemoryDataSet;
+import org.eobjects.metamodel.data.MaxRowsDataSet;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.data.SimpleDataSetHeader;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.FromItem;
+import org.eobjects.metamodel.query.GroupByItem;
+import org.eobjects.metamodel.query.JoinType;
+import org.eobjects.metamodel.query.OperatorType;
+import org.eobjects.metamodel.query.OrderByItem;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.MutableColumn;
+import org.eobjects.metamodel.schema.MutableRelationship;
+import org.eobjects.metamodel.schema.MutableSchema;
+import org.eobjects.metamodel.schema.MutableTable;
+import org.eobjects.metamodel.schema.Relationship;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.schema.TableType;
+import org.eobjects.metamodel.util.CollectionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract DataContext for data sources that do not support SQL queries
+ * natively.
+ *
+ * Instead this superclass only requires that a subclass can materialize a
+ * single table at a time. Then the query will be executed by post processing
+ * the datasets client-side.
+ */
+public abstract class QueryPostprocessDataContext extends AbstractDataContext implements HasReadTypeConverters {
+
+ private static final Logger logger = LoggerFactory.getLogger(QueryPostprocessDataContext.class);
+
+ public static final String INFORMATION_SCHEMA_NAME = "information_schema";
+
+ private final Map<Column, TypeConverter<?, ?>> _converters;
+
+ private Schema _mainSchema;
+
+ public QueryPostprocessDataContext() {
+ super();
+ _converters = new HashMap<Column, TypeConverter<?, ?>>();
+ }
+
+ @Override
+ public DataSet executeQuery(final Query query) {
+ final List<SelectItem> selectItems = query.getSelectClause().getItems();
+ final List<FromItem> fromItems = query.getFromClause().getItems();
+ final List<FilterItem> whereItems = query.getWhereClause().getItems();
+ final List<SelectItem> whereSelectItems = query.getWhereClause().getEvaluatedSelectItems();
+ final List<GroupByItem> groupByItems = query.getGroupByClause().getItems();
+ final List<SelectItem> groupBySelectItems = query.getGroupByClause().getEvaluatedSelectItems();
+ final List<SelectItem> havingSelectItems = query.getHavingClause().getEvaluatedSelectItems();
+ final List<SelectItem> orderBySelectItems = query.getOrderByClause().getEvaluatedSelectItems();
+
+ final List<FilterItem> havingItems = query.getHavingClause().getItems();
+ final List<OrderByItem> orderByItems = query.getOrderByClause().getItems();
+
+ // check for approximate SELECT COUNT(*) queries
+ if (fromItems.size() == 1 && selectItems.size() == 1 && groupByItems.isEmpty() && havingItems.isEmpty()) {
+ final SelectItem selectItem = query.getSelectClause().getItem(0);
+ if (SelectItem.isCountAllItem(selectItem)) {
+ final boolean functionApproximationAllowed = selectItem.isFunctionApproximationAllowed();
+ final FromItem fromItem = query.getFromClause().getItem(0);
+ final Table table = fromItem.getTable();
+ if (table != null) {
+ if (isMainSchemaTable(table)) {
+ logger.debug("Query is a COUNT query with {} where items. Trying executeCountQuery(...)",
+ whereItems.size());
+ final Number count = executeCountQuery(table, whereItems, functionApproximationAllowed);
+ if (count == null) {
+ logger.debug("DataContext did not return any count query results. Proceeding with manual counting.");
+ } else {
+ List<Row> data = new ArrayList<Row>(1);
+ final DataSetHeader header = new SimpleDataSetHeader(new SelectItem[] { selectItem });
+ data.add(new DefaultRow(header, new Object[] { count }));
+ return new InMemoryDataSet(header, data);
+ }
+ }
+ }
+ }
+ }
+
+ final int firstRow = (query.getFirstRow() == null ? 1 : query.getFirstRow());
+ final int maxRows = (query.getMaxRows() == null ? -1 : query.getMaxRows());
+
+ // Check for very simple queries with max rows property set (typically
+ // preview), see Ticket #187
+ previewTable: if (whereItems.isEmpty() && groupByItems.isEmpty() && havingItems.isEmpty()
+ && orderByItems.isEmpty() && fromItems.size() == 1) {
+
+ final Table table = fromItems.get(0).getTable();
+ if (table != null) {
+ for (SelectItem item : selectItems) {
+ if (item.getFunction() != null || item.getExpression() != null) {
+ break previewTable;
+ }
+ }
+
+ DataSet dataSet = materializeTable(table, selectItems, firstRow, maxRows);
+ dataSet = MetaModelHelper.getSelection(selectItems, dataSet);
+ return dataSet;
+ }
+ }
+
+ // Creates a list for all select items that are needed to execute query
+ // (some may only be used as part of a filter, but not shown in result)
+ List<SelectItem> workSelectItems = CollectionUtils.concat(true, selectItems, whereSelectItems,
+ groupBySelectItems, havingSelectItems, orderBySelectItems);
+
+ // Materialize the tables in the from clause
+ final DataSet[] fromDataSets = new DataSet[fromItems.size()];
+ for (int i = 0; i < fromDataSets.length; i++) {
+ FromItem fromItem = fromItems.get(i);
+ fromDataSets[i] = materializeFromItem(fromItem, workSelectItems);
+ }
+
+ // Execute the query using the raw data
+ DataSet dataSet = MetaModelHelper.getCarthesianProduct(fromDataSets, whereItems);
+
+ // we can now exclude the select items imposed by the WHERE clause (and
+ // should, to make the aggregation process faster)
+ workSelectItems = CollectionUtils.concat(true, selectItems, groupBySelectItems, havingSelectItems,
+ orderBySelectItems);
+
+ if (groupByItems.size() > 0) {
+ dataSet = MetaModelHelper.getGrouped(workSelectItems, dataSet, groupByItems);
+ } else {
+ dataSet = MetaModelHelper.getAggregated(workSelectItems, dataSet);
+ }
+ dataSet = MetaModelHelper.getFiltered(dataSet, havingItems);
+
+ if (query.getSelectClause().isDistinct()) {
+ dataSet = MetaModelHelper.getSelection(selectItems, dataSet);
+ dataSet = MetaModelHelper.getDistinct(dataSet);
+ dataSet = MetaModelHelper.getOrdered(dataSet, orderByItems);
+ } else {
+ dataSet = MetaModelHelper.getOrdered(dataSet, orderByItems);
+ dataSet = MetaModelHelper.getSelection(selectItems, dataSet);
+ }
+
+ if (firstRow > 1) {
+ dataSet = new FirstRowDataSet(dataSet, firstRow);
+ }
+ if (maxRows != -1) {
+ dataSet = new MaxRowsDataSet(dataSet, maxRows);
+ }
+ return dataSet;
+ }
+
+ /**
+ * Executes a simple count query, if possible. This method is provided to
+ * allow subclasses to optimize count queries since they are quite common
+ * and often a datastore can retrieve the count using some specialized means
+ * which is much more performant than counting all records manually.
+ *
+ * @param table
+ * the table on which the count is requested.
+ * @param whereItems
+ * a (sometimes empty) list of WHERE items.
+ * @param functionApproximationAllowed
+ * whether approximation is allowed or not.
+ * @return the count of the particular table, or null if not available.
+ */
+ protected Number executeCountQuery(Table table, List<FilterItem> whereItems, boolean functionApproximationAllowed) {
+ return null;
+ }
+
+ protected DataSet materializeFromItem(final FromItem fromItem, final List<SelectItem> selectItems) {
+ DataSet dataSet;
+ JoinType joinType = fromItem.getJoin();
+ if (fromItem.getTable() != null) {
+ // We need to materialize a single table
+ final Table table = fromItem.getTable();
+ final List<SelectItem> selectItemsToMaterialize = new ArrayList<SelectItem>();
+
+ for (final SelectItem selectItem : selectItems) {
+ final FromItem selectedFromItem = selectItem.getFromItem();
+ if (selectedFromItem != null) {
+ if (selectedFromItem.equals(fromItem)) {
+ selectItemsToMaterialize.add(selectItem.replaceFunction(null));
+ }
+ } else {
+ // the select item does not specify a specific
+ // from-item
+ final Column selectedColumn = selectItem.getColumn();
+ if (selectedColumn != null) {
+ // we assume that if the table matches, we will use the
+ // column
+ if (selectedColumn.getTable() != null && selectedColumn.getTable().equals(table)) {
+ selectItemsToMaterialize.add(selectItem.replaceFunction(null));
+ }
+ }
+ }
+ }
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("calling materializeTable(" + table.getName() + "," + selectItemsToMaterialize + ",1,-1");
+ }
+
+ // Dispatching to the concrete subclass of
+ // QueryPostprocessDataContextStrategy
+ dataSet = materializeTable(table, selectItemsToMaterialize, 1, -1);
+
+ } else if (joinType != null) {
+ // We need to (recursively) materialize a joined FromItem
+ if (fromItem.getLeftSide() == null || fromItem.getRightSide() == null) {
+ throw new IllegalArgumentException("Joined FromItem requires both left and right side: " + fromItem);
+ }
+ DataSet[] fromItemDataSets = new DataSet[2];
+
+ // materialize left side
+ List<SelectItem> leftOn = Arrays.asList(fromItem.getLeftOn());
+ fromItemDataSets[0] = materializeFromItem(fromItem.getLeftSide(),
+ CollectionUtils.concat(true, selectItems, leftOn));
+
+ // materialize right side
+ List<SelectItem> rightOn = Arrays.asList(fromItem.getRightOn());
+ fromItemDataSets[1] = materializeFromItem(fromItem.getRightSide(),
+ CollectionUtils.concat(true, selectItems, rightOn));
+
+ FilterItem[] onConditions = new FilterItem[leftOn.size()];
+ for (int i = 0; i < onConditions.length; i++) {
+ FilterItem whereItem = new FilterItem(leftOn.get(i), OperatorType.EQUALS_TO, rightOn.get(i));
+ onConditions[i] = whereItem;
+ }
+ if (joinType == JoinType.INNER) {
+ dataSet = MetaModelHelper.getCarthesianProduct(fromItemDataSets, onConditions);
+ } else if (joinType == JoinType.LEFT) {
+ dataSet = MetaModelHelper.getLeftJoin(fromItemDataSets[0], fromItemDataSets[1], onConditions);
+ } else if (joinType == JoinType.RIGHT) {
+ dataSet = MetaModelHelper.getRightJoin(fromItemDataSets[0], fromItemDataSets[1], onConditions);
+ } else {
+ throw new IllegalArgumentException("FromItem type not supported: " + fromItem);
+ }
+ } else if (fromItem.getSubQuery() != null) {
+ // We need to (recursively) materialize a subquery
+ dataSet = executeQuery(fromItem.getSubQuery());
+ } else {
+ throw new IllegalArgumentException("FromItem type not supported: " + fromItem);
+ }
+ if (dataSet == null) {
+ throw new IllegalStateException("FromItem was not succesfully materialized: " + fromItem);
+ }
+ return dataSet;
+ }
+
+ protected DataSet materializeTable(final Table table, final List<SelectItem> selectItems, final int firstRow,
+ final int maxRows) {
+ if (table == null) {
+ throw new IllegalArgumentException("Table cannot be null");
+ }
+
+ if (selectItems == null || selectItems.isEmpty()) {
+ // add any column (typically this occurs because of COUNT(*)
+ // queries)
+ Column[] columns = table.getColumns();
+ if (columns.length == 0) {
+ logger.warn("Queried table has no columns: {}", table);
+ } else {
+ selectItems.add(new SelectItem(columns[0]));
+ }
+ }
+
+ if (maxRows == 0) {
+ return new EmptyDataSet(selectItems);
+ }
+
+ final Schema schema = table.getSchema();
+ final String schemaName;
+ if (schema == null) {
+ schemaName = null;
+ } else {
+ schemaName = schema.getName();
+ }
+
+ final DataSet dataSet;
+ if (INFORMATION_SCHEMA_NAME.equals(schemaName)) {
+ final DataSet informationDataSet = materializeInformationSchemaTable(table, selectItems, maxRows);
+ if (firstRow > 1) {
+ dataSet = new FirstRowDataSet(informationDataSet, firstRow);
+ } else {
+ dataSet = informationDataSet;
+ }
+ } else {
+ final DataSet tableDataSet = materializeMainSchemaTable(table, selectItems, firstRow, maxRows);
+
+ // conversion is done at materialization time, since it enables
+ // the refined types to be used also in eg. where clauses.
+ dataSet = new ConvertedDataSetInterceptor(_converters).intercept(tableDataSet);
+ }
+
+ return dataSet;
+ }
+
+ protected boolean isMainSchemaTable(Table table) {
+ Schema schema = table.getSchema();
+ if (INFORMATION_SCHEMA_NAME.equals(schema.getName())) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ @Override
+ protected final String[] getSchemaNamesInternal() throws MetaModelException {
+ final String[] schemaNames = new String[2];
+ schemaNames[0] = INFORMATION_SCHEMA_NAME;
+ schemaNames[1] = getMainSchemaName();
+ return schemaNames;
+ }
+
+ @Override
+ protected String getDefaultSchemaName() throws MetaModelException {
+ return getMainSchemaName();
+ }
+
+ @Override
+ protected final Schema getSchemaByNameInternal(final String name) throws MetaModelException {
+ final String mainSchemaName = getMainSchemaName();
+ if (name == null) {
+ if (mainSchemaName == null) {
+ return getMainSchema();
+ }
+ return null;
+ }
+
+ if (name.equalsIgnoreCase(mainSchemaName)) {
+ return getMainSchemaInternal();
+ } else if (name.equals(INFORMATION_SCHEMA_NAME)) {
+ return getInformationSchema();
+ }
+
+ logger.warn("Could not find matching schema of name '{}'. Main schema name is: '{}'. Returning null.", name,
+ mainSchemaName);
+ return null;
+ }
+
+ private Schema getInformationSchema() {
+ // Create schema
+ MutableSchema informationSchema = new MutableSchema(INFORMATION_SCHEMA_NAME);
+ MutableTable tablesTable = new MutableTable("tables", TableType.TABLE, informationSchema);
+ MutableTable columnsTable = new MutableTable("columns", TableType.TABLE, informationSchema);
+ MutableTable relationshipsTable = new MutableTable("relationships", TableType.TABLE, informationSchema);
+ informationSchema.addTable(tablesTable).addTable(columnsTable).addTable(relationshipsTable);
+
+ // Create "tables" table: name, type, num_columns, remarks
+ tablesTable.addColumn(new MutableColumn("name", ColumnType.VARCHAR, tablesTable, 0, false));
+ tablesTable.addColumn(new MutableColumn("type", ColumnType.VARCHAR, tablesTable, 1, true));
+ tablesTable.addColumn(new MutableColumn("num_columns", ColumnType.INTEGER, tablesTable, 2, true));
+ tablesTable.addColumn(new MutableColumn("remarks", ColumnType.VARCHAR, tablesTable, 3, true));
+
+ // Create "columns" table: name, type, native_type, size, nullable,
+ // indexed, table, remarks
+ columnsTable.addColumn(new MutableColumn("name", ColumnType.VARCHAR, columnsTable, 0, false));
+ columnsTable.addColumn(new MutableColumn("type", ColumnType.VARCHAR, columnsTable, 1, true));
+ columnsTable.addColumn(new MutableColumn("native_type", ColumnType.VARCHAR, columnsTable, 2, true));
+ columnsTable.addColumn(new MutableColumn("size", ColumnType.INTEGER, columnsTable, 3, true));
+ columnsTable.addColumn(new MutableColumn("nullable", ColumnType.BOOLEAN, columnsTable, 4, true));
+ columnsTable.addColumn(new MutableColumn("indexed", ColumnType.BOOLEAN, columnsTable, 5, true));
+ columnsTable.addColumn(new MutableColumn("table", ColumnType.VARCHAR, columnsTable, 6, false));
+ columnsTable.addColumn(new MutableColumn("remarks", ColumnType.VARCHAR, columnsTable, 7, true));
+
+ // Create "relationships" table: primary_table, primary_column,
+ // foreign_table, foreign_column
+ relationshipsTable.addColumn(new MutableColumn("primary_table", ColumnType.VARCHAR, relationshipsTable, 0,
+ false));
+ relationshipsTable.addColumn(new MutableColumn("primary_column", ColumnType.VARCHAR, relationshipsTable, 1,
+ false));
+ relationshipsTable.addColumn(new MutableColumn("foreign_table", ColumnType.VARCHAR, relationshipsTable, 2,
+ false));
+ relationshipsTable.addColumn(new MutableColumn("foreign_column", ColumnType.VARCHAR, relationshipsTable, 3,
+ false));
+
+ MutableRelationship.createRelationship(tablesTable.getColumnByName("name"),
+ columnsTable.getColumnByName("table"));
+ MutableRelationship.createRelationship(tablesTable.getColumnByName("name"),
+ relationshipsTable.getColumnByName("primary_table"));
+ MutableRelationship.createRelationship(tablesTable.getColumnByName("name"),
+ relationshipsTable.getColumnByName("foreign_table"));
+ MutableRelationship.createRelationship(columnsTable.getColumnByName("name"),
+ relationshipsTable.getColumnByName("primary_column"));
+ MutableRelationship.createRelationship(columnsTable.getColumnByName("name"),
+ relationshipsTable.getColumnByName("foreign_column"));
+
+ return informationSchema;
+ }
+
+ private DataSet materializeInformationSchemaTable(final Table table, final List<SelectItem> selectItems,
+ final int maxRows) {
+ final String tableName = table.getName();
+ final SelectItem[] columnSelectItems = MetaModelHelper.createSelectItems(table.getColumns());
+ final SimpleDataSetHeader header = new SimpleDataSetHeader(columnSelectItems);
+ final Table[] tables = getMainSchemaInternal().getTables();
+ final List<Row> data = new ArrayList<Row>();
+ if ("tables".equals(tableName)) {
+ // "tables" columns: name, type, num_columns, remarks
+ for (Table t : tables) {
+ String typeString = null;
+ if (t.getType() != null) {
+ typeString = t.getType().toString();
+ }
+ data.add(new DefaultRow(header, new Object[] { t.getName(), typeString, t.getColumnCount(),
+ t.getRemarks() }));
+ }
+ } else if ("columns".equals(tableName)) {
+ // "columns" columns: name, type, native_type, size, nullable,
+ // indexed, table, remarks
+ for (Table t : tables) {
+ for (Column c : t.getColumns()) {
+ String typeString = null;
+ if (t.getType() != null) {
+ typeString = c.getType().toString();
+ }
+ data.add(new DefaultRow(header, new Object[] { c.getName(), typeString, c.getNativeType(),
+ c.getColumnSize(), c.isNullable(), c.isIndexed(), t.getName(), c.getRemarks() }));
+ }
+ }
+ } else if ("relationships".equals(tableName)) {
+ // "relationships" columns: primary_table, primary_column,
+ // foreign_table, foreign_column
+ for (Relationship r : getMainSchemaInternal().getRelationships()) {
+ Column[] primaryColumns = r.getPrimaryColumns();
+ 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];
+ data.add(new DefaultRow(header, new Object[] { pTable.getName(), pColumn.getName(),
+ fTable.getName(), fColumn.getName() }));
+ }
+ }
+ } else {
+ throw new IllegalArgumentException("Cannot materialize non information_schema table: " + table);
+ }
+
+ DataSet dataSet;
+ if (data.isEmpty()) {
+ dataSet = new EmptyDataSet(selectItems);
+ } else {
+ dataSet = new InMemoryDataSet(header, data);
+ }
+
+ // Handle column subset
+ dataSet = MetaModelHelper.getSelection(selectItems, dataSet);
+
+ // Handle maxRows
+ if (maxRows != -1) {
+ dataSet = new MaxRowsDataSet(dataSet, maxRows);
+ }
+ return dataSet;
+ }
+
+ protected Schema getMainSchemaInternal() {
+ Schema schema = _mainSchema;
+ if (schema == null) {
+ schema = getMainSchema();
+ _mainSchema = schema;
+ }
+ return schema;
+ }
+
+ /**
+ * Adds a {@link TypeConverter} to this DataContext's query engine (Query
+ * Postprocessor) for read operations. Note that this method should NOT be
+ * invoked directly by consuming code. Rather use
+ * {@link Converters#addTypeConverter(DataContext, Column, TypeConverter)}
+ * to ensure conversion on both reads and writes.
+ */
+ @Override
+ public void addConverter(Column column, TypeConverter<?, ?> converter) {
+ _converters.put(column, converter);
+ }
+
+ /**
+ * @return the main schema that subclasses of this class produce
+ */
+ protected abstract Schema getMainSchema() throws MetaModelException;
+
+ /**
+ * @return the name of the main schema that subclasses of this class produce
+ */
+ protected abstract String getMainSchemaName() throws MetaModelException;
+
+ /**
+ * 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)}.
+ *
+ * @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();
+ }
+ DataSet dataSet = materializeMainSchemaTable(table, columns, firstRow, maxRows);
+
+ dataSet = MetaModelHelper.getSelection(selectItems, dataSet);
+
+ return dataSet;
+ }
+
+ /**
+ * 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
+ * {@link FirstRowDataSet} if necessary.
+ *
+ * @param table
+ * @param columns
+ * @param firstRow
+ * @param maxRows
+ * @return
+ */
+ protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int firstRow, int maxRows) {
+ final int rowsToMaterialize;
+ if (firstRow == 1) {
+ rowsToMaterialize = maxRows;
+ } else {
+ rowsToMaterialize = maxRows + (firstRow - 1);
+ }
+ DataSet dataSet = materializeMainSchemaTable(table, columns, rowsToMaterialize);
+ if (firstRow > 1) {
+ dataSet = new FirstRowDataSet(dataSet, firstRow);
+ }
+ return dataSet;
+ }
+
+ /**
+ * Executes a simple one-table query against a table in the main schema of
+ * the subclasses of this class.
+ *
+ * @param table
+ * the table to query
+ * @param columns
+ * the columns of the table to query
+ * @param maxRows
+ * the maximum amount of rows needed or -1 if all rows are
+ * wanted.
+ * @return a dataset with the raw table/column content.
+ */
+ protected abstract DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows);
+}
\ 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/QueryPostprocessDelegate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/QueryPostprocessDelegate.java b/core/src/main/java/org/apache/metamodel/QueryPostprocessDelegate.java
new file mode 100644
index 0000000..7d8dde3
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/QueryPostprocessDelegate.java
@@ -0,0 +1,45 @@
+/**
+ * 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;
+
+import org.eobjects.metamodel.schema.Schema;
+
+/**
+ * A simple subclass of {@link QueryPostprocessDataContext} which provides less
+ * implementation fuzz when custom querying features (like composite
+ * datacontexts or type conversion) is needed.
+ *
+ * @author Kasper Sørensen
+ * @author Ankit Kumar
+ */
+public abstract class QueryPostprocessDelegate extends
+ QueryPostprocessDataContext {
+
+ @Override
+ protected String getMainSchemaName() throws MetaModelException {
+ throw new UnsupportedOperationException(
+ "QueryPostprocessDelegate cannot perform schema exploration");
+ }
+
+ @Override
+ protected Schema getMainSchema() throws MetaModelException {
+ throw new UnsupportedOperationException(
+ "QueryPostprocessDelegate cannot perform schema exploration");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/SchemaNameComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/SchemaNameComparator.java b/core/src/main/java/org/apache/metamodel/SchemaNameComparator.java
new file mode 100644
index 0000000..14a2f82
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/SchemaNameComparator.java
@@ -0,0 +1,58 @@
+/**
+ * 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;
+
+import java.util.Comparator;
+
+/**
+ * Comparator for comparing schema names.
+ *
+ * @author Kasper Sørensen
+ */
+class SchemaNameComparator implements Comparator<String> {
+
+ private static Comparator<? super String> _instance = new SchemaNameComparator();
+
+ public static Comparator<? super String> getInstance() {
+ return _instance;
+ }
+
+ private SchemaNameComparator() {
+ }
+
+ public int compare(String o1, String o2) {
+ if (o1 == null && o2 == null) {
+ return 0;
+ }
+ if (o1 == null) {
+ return -1;
+ }
+ if (o2 == null) {
+ return 1;
+ }
+ if (MetaModelHelper.isInformationSchema(o1)) {
+ return -1;
+ }
+ if (MetaModelHelper.isInformationSchema(o2)) {
+ return 1;
+ }
+ return o1.compareTo(o2);
+ }
+
+}
\ 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/UpdateCallback.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/UpdateCallback.java b/core/src/main/java/org/apache/metamodel/UpdateCallback.java
new file mode 100644
index 0000000..c19f03f
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/UpdateCallback.java
@@ -0,0 +1,45 @@
+/**
+ * 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;
+
+import org.eobjects.metamodel.create.TableCreatable;
+import org.eobjects.metamodel.delete.RowDeletable;
+import org.eobjects.metamodel.drop.TableDroppable;
+import org.eobjects.metamodel.insert.RowInsertable;
+import org.eobjects.metamodel.update.RowUpdateable;
+
+/**
+ * An {@link UpdateCallback} is used by an {@link UpdateScript} to perform
+ * updates on a {@link DataContext}. Multiple updates (eg. insertion of several
+ * rows or creation of multiple tables) can (and should) be performed with a
+ * single {@link UpdateCallback}. This pattern guarantees that connections
+ * and/or file handles are handled correctly, surrounding the
+ * {@link UpdateScript} that is being executed.
+ *
+ * @author Kasper Sørensen
+ */
+public interface UpdateCallback extends TableCreatable, TableDroppable, RowInsertable, RowUpdateable, RowDeletable {
+
+ /**
+ * Gets the DataContext on which the update script is being executed.
+ *
+ * @return the DataContext on which the update script is being executed.
+ */
+ public DataContext getDataContext();
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/UpdateScript.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/UpdateScript.java b/core/src/main/java/org/apache/metamodel/UpdateScript.java
new file mode 100644
index 0000000..b10318e
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/UpdateScript.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;
+
+import org.eobjects.metamodel.util.Action;
+
+/**
+ * Represents any updating operation or update script that can be executed on a
+ * {@link UpdateableDataContext}. Users of MetaModel should implement their own
+ * {@link UpdateScript} and submit them to the
+ * {@link UpdateableDataContext#executeUpdate(UpdateScript)} method for
+ * execution.
+ *
+ * @author Kasper Sørensen
+ */
+public interface UpdateScript extends Action<UpdateCallback> {
+
+ /**
+ * Invoked by MetaModel when the update script should be run. User should
+ * implement this method and invoke update operations on the
+ * {@link UpdateCallback}.
+ */
+ @Override
+ public void run(UpdateCallback callback);
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/UpdateableDataContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/UpdateableDataContext.java b/core/src/main/java/org/apache/metamodel/UpdateableDataContext.java
new file mode 100644
index 0000000..3153f75
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/UpdateableDataContext.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;
+
+/**
+ * Represents a {@link DataContext} that supports updating write-operations.
+ *
+ * @author Kasper Sørensen
+ */
+public interface UpdateableDataContext extends DataContext {
+
+ /**
+ * Submits an {@link UpdateScript} for execution on the {@link DataContext}.
+ *
+ * Since implementations of the {@link DataContext} vary quite a lot, there
+ * is no golden rule as to how an update script will be executed. But the
+ * implementors should strive towards handling an {@link UpdateScript} as a
+ * single transactional change to the data store.
+ *
+ * @param update
+ * the update script to execute
+ */
+ public void executeUpdate(UpdateScript update);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/convert/ColumnTypeDetector.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/ColumnTypeDetector.java b/core/src/main/java/org/apache/metamodel/convert/ColumnTypeDetector.java
new file mode 100644
index 0000000..1355c95
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/convert/ColumnTypeDetector.java
@@ -0,0 +1,82 @@
+/**
+ * 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.convert;
+
+import org.eobjects.metamodel.util.BooleanComparator;
+import org.eobjects.metamodel.util.TimeComparator;
+
+/**
+ * A class capable of detecting/narrowing a string column type to something more
+ * specific. Either: Boolean, Integer, Double or Date.
+ */
+final class ColumnTypeDetector {
+
+ private boolean _booleanPossible = true;
+ private boolean _integerPossible = true;
+ private boolean _doublePossible = true;
+ private boolean _datePossible = true;
+
+ public void registerValue(String stringValue) {
+ if (stringValue == null || stringValue.length() == 0) {
+ return;
+ }
+ if (_booleanPossible) {
+ try {
+ BooleanComparator.parseBoolean(stringValue);
+ } catch (IllegalArgumentException e) {
+ _booleanPossible = false;
+ }
+ }
+ if (_doublePossible) {
+ try {
+ Double.parseDouble(stringValue);
+ } catch (NumberFormatException e) {
+ _doublePossible = false;
+ _integerPossible = false;
+ }
+ // If integer is possible, double will always also be possible,
+ // but not nescesarily the other way around
+ if (_integerPossible) {
+ try {
+ Integer.parseInt(stringValue);
+ } catch (NumberFormatException e) {
+ _integerPossible = false;
+ }
+ }
+ }
+ if (_datePossible) {
+ if (TimeComparator.toDate(stringValue) == null) {
+ _datePossible = false;
+ }
+ }
+ }
+
+ public TypeConverter<?, ?> createConverter() {
+ if (_booleanPossible) {
+ return new StringToBooleanConverter();
+ } else if (_integerPossible) {
+ return new StringToIntegerConverter();
+ } else if (_doublePossible) {
+ return new StringToDoubleConverter();
+ } else if (_datePossible) {
+ return new StringToDateConverter();
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/convert/ConvertedDataSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/ConvertedDataSet.java b/core/src/main/java/org/apache/metamodel/convert/ConvertedDataSet.java
new file mode 100644
index 0000000..ff0cf79
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/convert/ConvertedDataSet.java
@@ -0,0 +1,74 @@
+/**
+ * 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.convert;
+
+import org.eobjects.metamodel.data.AbstractDataSet;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.DefaultRow;
+import org.eobjects.metamodel.data.Row;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A {@link DataSet} wrapper/decorator which converts values using
+ * {@link TypeConverter}s before returning them to the user.
+ */
+final class ConvertedDataSet extends AbstractDataSet {
+
+ private static final Logger logger = LoggerFactory.getLogger(ConvertedDataSet.class);
+
+ private final DataSet _dataSet;
+ private final TypeConverter<?, ?>[] _converters;
+
+ public ConvertedDataSet(DataSet dataSet, TypeConverter<?, ?>[] converters) {
+ super(dataSet.getSelectItems());
+ _dataSet = dataSet;
+ _converters = converters;
+ }
+
+ @Override
+ public boolean next() {
+ return _dataSet.next();
+ }
+
+ @Override
+ public Row getRow() {
+ Row sourceRow = _dataSet.getRow();
+ Object[] values = new Object[_converters.length];
+ for (int i = 0; i < values.length; i++) {
+ Object value = sourceRow.getValue(i);
+
+ @SuppressWarnings("unchecked")
+ TypeConverter<Object, ?> converter = (TypeConverter<Object, ?>) _converters[i];
+
+ if (converter != null) {
+ Object virtualValue = converter.toVirtualValue(value);
+ logger.debug("Converted physical value {} to {}", value, virtualValue);
+ value = virtualValue;
+ }
+ values[i] = value;
+ }
+ return new DefaultRow(getHeader(), values);
+ }
+
+ @Override
+ public void close() {
+ _dataSet.close();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/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
new file mode 100644
index 0000000..159c469
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/convert/ConvertedDataSetInterceptor.java
@@ -0,0 +1,91 @@
+/**
+ * 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.convert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.intercept.DataSetInterceptor;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+
+/**
+ * A {@link DataSetInterceptor} used for intercepting values in {@link DataSet}s
+ * that need to be converted, according to a set of {@link TypeConverter}s.
+ *
+ * @see TypeConverter
+ * @see Converters
+ */
+public class ConvertedDataSetInterceptor implements DataSetInterceptor, HasReadTypeConverters {
+
+ private Map<Column, TypeConverter<?, ?>> _converters;
+
+ public ConvertedDataSetInterceptor() {
+ this(new HashMap<Column, TypeConverter<?, ?>>());
+ }
+
+ public ConvertedDataSetInterceptor(
+ Map<Column, TypeConverter<?, ?>> converters) {
+ _converters = converters;
+ }
+
+ @Override
+ public void addConverter(Column column, TypeConverter<?, ?> converter) {
+ if (converter == null) {
+ _converters.remove(column);
+ } else {
+ _converters.put(column, converter);
+ }
+ }
+
+ protected Map<Column, TypeConverter<?, ?>> getConverters(DataSet dataSet) {
+ return _converters;
+ }
+
+ @Override
+ public final DataSet intercept(DataSet dataSet) {
+ Map<Column, TypeConverter<?, ?>> converters = getConverters(dataSet);
+ if (converters.isEmpty()) {
+ return dataSet;
+ }
+
+ 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];
+ Column column = selectItem.getColumn();
+ if (column != null && selectItem.getFunction() == null) {
+ TypeConverter<?, ?> converter = converters.get(column);
+ if (converter != null) {
+ hasConverter = true;
+ converterArray[i] = converter;
+ }
+ }
+ }
+
+ if (!hasConverter) {
+ return dataSet;
+ }
+
+ return new ConvertedDataSet(dataSet, converterArray);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/convert/ConvertedRowInsertionInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/ConvertedRowInsertionInterceptor.java b/core/src/main/java/org/apache/metamodel/convert/ConvertedRowInsertionInterceptor.java
new file mode 100644
index 0000000..b7ea3ad
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/convert/ConvertedRowInsertionInterceptor.java
@@ -0,0 +1,75 @@
+/**
+ * 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.convert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eobjects.metamodel.insert.RowInsertionBuilder;
+import org.eobjects.metamodel.intercept.RowInsertionInterceptor;
+import org.eobjects.metamodel.schema.Column;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A {@link RowInsertionInterceptor} used for intercepting values in
+ * {@link RowInsertionBuilder}s that need to be converted, according to a set of
+ * {@link TypeConverter}s.
+ *
+ * @see TypeConverter
+ * @see Converters
+ */
+public class ConvertedRowInsertionInterceptor implements RowInsertionInterceptor {
+
+ private static final Logger logger = LoggerFactory.getLogger(ConvertedRowInsertionInterceptor.class);
+
+ private final Map<Column, TypeConverter<?, ?>> _converters;
+
+ public ConvertedRowInsertionInterceptor() {
+ this(new HashMap<Column, TypeConverter<?, ?>>());
+ }
+
+ public ConvertedRowInsertionInterceptor(Map<Column, TypeConverter<?, ?>> converters) {
+ _converters = converters;
+ }
+
+ public void addConverter(Column column, TypeConverter<?, ?> converter) {
+ if (converter == null) {
+ _converters.remove(column);
+ } else {
+ _converters.put(column, converter);
+ }
+ }
+
+ @Override
+ public RowInsertionBuilder intercept(RowInsertionBuilder insert) {
+ if (_converters.isEmpty()) {
+ return insert;
+ }
+
+ logger.debug("Insert statement before conversion: {}", insert);
+
+ insert = Converters.convertRow(insert, _converters);
+
+ logger.debug("Insert statement after conversion: {}", insert);
+
+ return insert;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/convert/ConvertedRowUpdationInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/ConvertedRowUpdationInterceptor.java b/core/src/main/java/org/apache/metamodel/convert/ConvertedRowUpdationInterceptor.java
new file mode 100644
index 0000000..6a42107
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/convert/ConvertedRowUpdationInterceptor.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.convert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eobjects.metamodel.intercept.RowUpdationInterceptor;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.update.RowUpdationBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ConvertedRowUpdationInterceptor implements RowUpdationInterceptor {
+
+ private static final Logger logger = LoggerFactory.getLogger(ConvertedRowUpdationInterceptor.class);
+
+ private final Map<Column, TypeConverter<?, ?>> _converters;
+
+ public ConvertedRowUpdationInterceptor() {
+ this(new HashMap<Column, TypeConverter<?, ?>>());
+ }
+
+ public ConvertedRowUpdationInterceptor(Map<Column, TypeConverter<?, ?>> converters) {
+ _converters = converters;
+ }
+
+ public void addConverter(Column column, TypeConverter<?, ?> converter) {
+ if (converter == null) {
+ _converters.remove(column);
+ } else {
+ _converters.put(column, converter);
+ }
+ }
+
+ @Override
+ public RowUpdationBuilder intercept(RowUpdationBuilder update) {
+ if (_converters.isEmpty()) {
+ return update;
+ }
+
+ logger.debug("Update statement after conversion: {}", update);
+
+ update = Converters.convertRow(update, _converters);
+
+ logger.debug("Update statement after conversion: {}", update);
+
+ return update;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/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
new file mode 100644
index 0000000..7b7b43c
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/convert/Converters.java
@@ -0,0 +1,329 @@
+/**
+ * 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.convert;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eobjects.metamodel.DataContext;
+import org.eobjects.metamodel.MetaModelHelper;
+import org.eobjects.metamodel.UpdateableDataContext;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.data.Row;
+import org.eobjects.metamodel.data.RowBuilder;
+import org.eobjects.metamodel.data.Style;
+import org.eobjects.metamodel.intercept.InterceptableDataContext;
+import org.eobjects.metamodel.intercept.Interceptors;
+import org.eobjects.metamodel.query.Query;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.SuperColumnType;
+import org.eobjects.metamodel.schema.Table;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class consists of static methods for decorating {@link DataContext}s
+ * with {@link TypeConverter}s, which allows for automatic conversion of values
+ * on data read and write operations.
+ */
+public final class Converters {
+
+ private static final Logger logger = LoggerFactory.getLogger(Converters.class);
+
+ private Converters() {
+ // prevent instantiation
+ }
+
+ /**
+ * Adds a type converter to a specific column in the {@link DataContext}.
+ *
+ * @param dataContext
+ * the DataContext to decorate
+ * @param column
+ * the column which holds values to convert
+ * @param converter
+ * the converter to use on the specified column
+ * @return a decorated DataContext, which should be used for successive
+ * operations on the data.
+ */
+ public static UpdateableDataContext addTypeConverter(UpdateableDataContext dataContext, Column column,
+ TypeConverter<?, ?> converter) {
+ return addTypeConverterInternally(dataContext, column, converter);
+ }
+
+ /**
+ * Adds a type converter to a specific column in the {@link DataContext}.
+ *
+ * @param dataContext
+ * the DataContext to decorate
+ * @param column
+ * the column which holds values to convert
+ * @param converter
+ * the converter to use on the specified column
+ * @return a decorated DataContext, which should be used for successive
+ * operations on the data.
+ */
+ public static DataContext addTypeConverter(DataContext dataContext, Column column, TypeConverter<?, ?> converter) {
+ return addTypeConverterInternally(dataContext, column, converter);
+ }
+
+ /**
+ * Adds a collection of type converters to specific columns in the
+ * {@link DataContext}
+ *
+ * @param dataContext
+ * the DataContext to decorate
+ * @param converters
+ * a map containing columns and mapped type converters.
+ * @return a decorated DataContext, which should be used for successive
+ * operations on the data.
+ */
+ public static UpdateableDataContext addTypeConverters(UpdateableDataContext dataContext,
+ Map<Column, TypeConverter<?, ?>> converters) {
+ return addTypeConvertersInternally(dataContext, converters);
+ }
+
+ /**
+ * Adds a collection of type converters to specific columns in the
+ * {@link DataContext}
+ *
+ * @param dataContext
+ * the DataContext to decorate
+ * @param converters
+ * a map containing columns and mapped type converters.
+ * @return a decorated DataContext, which should be used for successive
+ * operations on the data.
+ */
+ public static DataContext addTypeConverters(DataContext dataContext, Map<Column, TypeConverter<?, ?>> converters) {
+ return addTypeConvertersInternally(dataContext, converters);
+ }
+
+ /**
+ * Auto-detects / guesses the type converters to be applied on set of
+ * columns. This method will query the String columns in order to assert
+ * which columns are likely candidates for conversion.
+ *
+ * As such this method is not guaranteed to pick the correct converters,
+ * since data can change over time or other conversions can be requested.
+ *
+ * @param dataContext
+ * the DataContext that holds the data.
+ * @param columns
+ * the columns to inspect to find type conversion candidates.
+ * @param sampleSize
+ * the max amount of rows to query for doing auto-detection. Use
+ * {@link Integer#MAX_VALUE} if no constraint should be put on
+ * the number of records to sample.
+ * @return a map of {@link Column}s and {@link TypeConverter}s which can be
+ * 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,
+ 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);
+ }
+ return result;
+ }
+
+ /**
+ * Auto-detects / guesses the type converters to be applied on a table. This
+ * method will query the String columns of a table in order to assert which
+ * columns are likely candidates for conversion.
+ *
+ * As such this method is not guaranteed to pick the correct converters,
+ * since data can change over time or other conversions can be requested.
+ *
+ * @param dataContext
+ * the DataContext that holds the data.
+ * @param table
+ * the table to inspect to find type conversion candidates. This
+ * table will hold all columns of the result.
+ * @param sampleSize
+ * the max amount of rows to query for doing auto-detection. Use
+ * {@link Integer#MAX_VALUE} if no constraint should be put on
+ * the number of records to sample.
+ * @return a map of {@link Column}s and {@link TypeConverter}s which can be
+ * used (eg. with the {@link #addTypeConverters(DataContext, Map)}
+ * method) to decorate the DataContext with type 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);
+ autoDetectConvertersInternally(dataContext, table, columns, sampleSize, result);
+ return result;
+ }
+
+ private static void autoDetectConvertersInternally(DataContext dataContext, Table table, Column[] columns,
+ int sampleSize, Map<Column, TypeConverter<?, ?>> result) {
+ if (columns == null || columns.length == 0) {
+ return;
+ }
+
+ Map<Column, ColumnTypeDetector> detectors = new HashMap<Column, ColumnTypeDetector>();
+ for (Column column : columns) {
+ detectors.put(column, new ColumnTypeDetector());
+ }
+
+ Query query = dataContext.query().from(table).select(columns).toQuery();
+ if (sampleSize > 0 && sampleSize != Integer.MAX_VALUE) {
+ query.setMaxRows(sampleSize);
+ }
+ DataSet dataSet = dataContext.executeQuery(query);
+ try {
+ while (dataSet.next()) {
+ Row row = dataSet.getRow();
+ for (Column column : columns) {
+ String stringValue = (String) row.getValue(column);
+ ColumnTypeDetector detector = detectors.get(column);
+ detector.registerValue(stringValue);
+ }
+ }
+ } finally {
+ dataSet.close();
+ }
+ for (Column column : columns) {
+ ColumnTypeDetector detector = detectors.get(column);
+ TypeConverter<?, ?> converter = detector.createConverter();
+ if (converter != null) {
+ result.put(column, converter);
+ }
+ }
+ }
+
+ private static InterceptableDataContext addTypeConvertersInternally(final DataContext dc,
+ Map<Column, TypeConverter<?, ?>> converters) {
+ if (converters == null) {
+ throw new IllegalArgumentException("Converters cannot be null");
+ }
+
+ InterceptableDataContext interceptable = Interceptors.intercept(dc);
+
+ Set<Entry<Column, TypeConverter<?, ?>>> entries = converters.entrySet();
+ for (Entry<Column, TypeConverter<?, ?>> entry : entries) {
+ Column column = entry.getKey();
+ TypeConverter<?, ?> converter = entry.getValue();
+ interceptable = addTypeConverterInternally(interceptable, column, converter);
+ }
+
+ return interceptable;
+ }
+
+ private static InterceptableDataContext addTypeConverterInternally(final DataContext dc, Column column,
+ TypeConverter<?, ?> converter) {
+ if (column == null) {
+ throw new IllegalArgumentException("Column cannot be null");
+ }
+
+ InterceptableDataContext interceptable = Interceptors.intercept(dc);
+ DataContext delegate = interceptable.getDelegate();
+
+ boolean interceptDataSets = true;
+
+ if (delegate instanceof HasReadTypeConverters) {
+ // some DataContexts implement the HasTypeConverters interface,
+ // which is preferred when available
+ HasReadTypeConverters hasTypeConverter = (HasReadTypeConverters) delegate;
+ hasTypeConverter.addConverter(column, converter);
+
+ interceptDataSets = false;
+ }
+
+ addTypeConverterInterceptors(interceptable, column, converter, interceptDataSets);
+ return interceptable;
+ }
+
+ private static void addTypeConverterInterceptors(InterceptableDataContext interceptable, Column column,
+ TypeConverter<?, ?> converter, boolean interceptDataSets) {
+ // intercept datasets (reads)
+ if (interceptDataSets) {
+ ConvertedDataSetInterceptor interceptor = interceptable.getDataSetInterceptors().getInterceptorOfType(
+ ConvertedDataSetInterceptor.class);
+ if (interceptor == null) {
+ interceptor = new ConvertedDataSetInterceptor();
+ interceptable.addDataSetInterceptor(interceptor);
+ }
+ interceptor.addConverter(column, converter);
+ }
+
+ // intercept inserts (writes)
+ {
+ ConvertedRowInsertionInterceptor interceptor = interceptable.getRowInsertionInterceptors()
+ .getInterceptorOfType(ConvertedRowInsertionInterceptor.class);
+ if (interceptor == null) {
+ interceptor = new ConvertedRowInsertionInterceptor();
+ interceptable.addRowInsertionInterceptor(interceptor);
+ }
+ interceptor.addConverter(column, converter);
+ }
+
+ // convert updates
+ {
+ ConvertedRowUpdationInterceptor interceptor = interceptable.getRowUpdationInterceptors()
+ .getInterceptorOfType(ConvertedRowUpdationInterceptor.class);
+ if (interceptor == null) {
+ interceptor = new ConvertedRowUpdationInterceptor();
+ interceptable.addRowUpdationInterceptor(interceptor);
+ }
+ interceptor.addConverter(column, converter);
+ }
+
+ // converting deletes (as well as where-items in updates) should not be
+ // applied, because the DataSet interceptor is anyways only working on
+ // the output. In that sense it adds symetry to NOT support conversion
+ // in the where clause of UPDATEs and DELETEs.
+ }
+
+ /**
+ * Converts values in a {@link RowBuilder}.
+ *
+ * @param rowBuilder
+ * @param converters
+ * @return
+ */
+ protected static <RB extends RowBuilder<?>> RB convertRow(RB rowBuilder, Map<Column, TypeConverter<?, ?>> converters) {
+ Table table = rowBuilder.getTable();
+ Column[] columns = table.getColumns();
+ Row row = rowBuilder.toRow();
+ for (Column column : columns) {
+ @SuppressWarnings("unchecked")
+ TypeConverter<?, Object> converter = (TypeConverter<?, Object>) converters.get(column);
+ if (converter != null) {
+ final int indexInRow = row.indexOf(column);
+ final Object value = row.getValue(indexInRow);
+ final Object physicalValue = converter.toPhysicalValue(value);
+ logger.debug("Converted virtual value {} to {}", value, physicalValue);
+ if (value == null && physicalValue == null && !rowBuilder.isSet(column)) {
+ logger.debug("Omitting implicit null value for column: {}", column);
+ } else {
+ final Style style = row.getStyle(indexInRow);
+ rowBuilder.value(column, physicalValue, style);
+ }
+ }
+ }
+ return rowBuilder;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/convert/HasReadTypeConverters.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/HasReadTypeConverters.java b/core/src/main/java/org/apache/metamodel/convert/HasReadTypeConverters.java
new file mode 100644
index 0000000..5f63c1e
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/convert/HasReadTypeConverters.java
@@ -0,0 +1,33 @@
+/**
+ * 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.convert;
+
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.schema.Column;
+
+/**
+ * Defines an interface for objects that are aware of {@link TypeConverter}s,
+ * and know how to apply them to read operations (Queries or {@link DataSet}s).
+ *
+ * @author Kasper Sørensen
+ */
+public interface HasReadTypeConverters {
+
+ public void addConverter(Column column, TypeConverter<?, ?> converter);
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/convert/StringToBooleanConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/StringToBooleanConverter.java b/core/src/main/java/org/apache/metamodel/convert/StringToBooleanConverter.java
new file mode 100644
index 0000000..fb546a4
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/convert/StringToBooleanConverter.java
@@ -0,0 +1,54 @@
+/**
+ * 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.convert;
+
+import org.eobjects.metamodel.util.BooleanComparator;
+
+/**
+ * A {@link TypeConverter} that converts String values (on the physical layer)
+ * to interpreted Booleans.
+ *
+ * @author Kasper Sørensen
+ * @author Ankit Kumar
+ */
+public class StringToBooleanConverter implements TypeConverter<String, Boolean> {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toPhysicalValue(Boolean virtualValue) {
+ if (virtualValue == null) {
+ return null;
+ }
+ return virtualValue.toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Boolean toVirtualValue(String physicalValue) {
+ if (physicalValue == null || physicalValue.length() == 0) {
+ return null;
+ }
+ return BooleanComparator.parseBoolean(physicalValue);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/convert/StringToDateConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/StringToDateConverter.java b/core/src/main/java/org/apache/metamodel/convert/StringToDateConverter.java
new file mode 100644
index 0000000..1684a31
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/convert/StringToDateConverter.java
@@ -0,0 +1,127 @@
+/**
+ * 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.convert;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.eobjects.metamodel.util.Func;
+import org.eobjects.metamodel.util.TimeComparator;
+
+/**
+ * A {@link TypeConverter} that converts String values (on the physical layer)
+ * to interpreted {@link Date}s.
+ *
+ * @author Kasper Sørensen
+ * @author Ankit Kumar
+ */
+public class StringToDateConverter implements TypeConverter<String, Date> {
+
+ private final Func<Date, String> _serializeFunc;
+ private final Func<String, Date> _deserializeFunc;
+
+ /**
+ * Constructs a new {@link StringToDateConverter} which will use the
+ * {@link TimeComparator#toDate(Object)} method for parsing dates and the
+ * {@link DateFormat#MEDIUM} date time format for physical representation.
+ */
+ public StringToDateConverter() {
+ _deserializeFunc = new Func<String, Date>() {
+ @Override
+ public Date eval(String stringValue) {
+ return TimeComparator.toDate(stringValue);
+ }
+ };
+ _serializeFunc = new Func<Date, String>() {
+ @Override
+ public String eval(Date date) {
+ return DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
+ DateFormat.MEDIUM).format(date);
+ }
+ };
+ }
+
+ /**
+ * Constructs a new {@link StringToDateConverter} using a given date
+ * pattern.
+ *
+ * @param datePattern
+ * a String date pattern, corresponding to the syntax of a
+ * {@link SimpleDateFormat}.
+ */
+ public StringToDateConverter(String datePattern) {
+ this(new SimpleDateFormat(datePattern));
+ }
+
+ /**
+ * Constructs a new {@link StringToDateConverter} using a given
+ * {@link DateFormat}.
+ *
+ * @param dateFormat
+ * the {@link DateFormat} to use for parsing and formatting
+ * dates.
+ */
+ public StringToDateConverter(final DateFormat dateFormat) {
+ if (dateFormat == null) {
+ throw new IllegalArgumentException("DateFormat cannot be null");
+ }
+ _deserializeFunc = new Func<String, Date>() {
+ @Override
+ public Date eval(String string) {
+ try {
+ return dateFormat.parse(string);
+ } catch (ParseException e) {
+ throw new IllegalArgumentException(
+ "Could not parse date string: " + string);
+ }
+ }
+ };
+ _serializeFunc = new Func<Date, String>() {
+ @Override
+ public String eval(Date date) {
+ return dateFormat.format(date);
+ }
+ };
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toPhysicalValue(Date virtualValue) {
+ if (virtualValue == null) {
+ return null;
+ }
+ return _serializeFunc.eval(virtualValue);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Date toVirtualValue(String physicalValue) {
+ if (physicalValue == null || physicalValue.length() == 0) {
+ return null;
+ }
+ return _deserializeFunc.eval(physicalValue);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/convert/StringToDoubleConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/StringToDoubleConverter.java b/core/src/main/java/org/apache/metamodel/convert/StringToDoubleConverter.java
new file mode 100644
index 0000000..6ce6406
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/convert/StringToDoubleConverter.java
@@ -0,0 +1,52 @@
+/**
+ * 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.convert;
+
+/**
+ * A {@link TypeConverter} that converts String values (on the physical layer)
+ * to interpreted Doubles.
+ *
+ * @author Kasper Sørensen
+ * @author Ankit Kumar
+ */
+public class StringToDoubleConverter implements TypeConverter<String, Double> {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toPhysicalValue(Double virtualValue) {
+ if (virtualValue == null) {
+ return null;
+ }
+ return virtualValue.toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Double toVirtualValue(String physicalValue) {
+ if (physicalValue == null || physicalValue.length() == 0) {
+ return null;
+ }
+ return Double.parseDouble(physicalValue);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/convert/StringToIntegerConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/StringToIntegerConverter.java b/core/src/main/java/org/apache/metamodel/convert/StringToIntegerConverter.java
new file mode 100644
index 0000000..4aafe7d
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/convert/StringToIntegerConverter.java
@@ -0,0 +1,52 @@
+/**
+ * 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.convert;
+
+/**
+ * A {@link TypeConverter} that converts String values (on the physical layer)
+ * to interpreted Integers.
+ *
+ * @author Kasper Sørensen
+ * @author Ankit Kumar
+ */
+public class StringToIntegerConverter implements TypeConverter<String, Integer> {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toPhysicalValue(Integer virtualValue) {
+ if (virtualValue == null) {
+ return null;
+ }
+ return virtualValue.toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Integer toVirtualValue(String physicalValue) {
+ if (physicalValue == null || physicalValue.length() == 0) {
+ return null;
+ }
+ return Integer.parseInt(physicalValue);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/convert/TypeConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/TypeConverter.java b/core/src/main/java/org/apache/metamodel/convert/TypeConverter.java
new file mode 100644
index 0000000..542449e
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/convert/TypeConverter.java
@@ -0,0 +1,54 @@
+/**
+ * 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.convert;
+
+/**
+ * Defines an interface for converting values from and to their physical
+ * materializations and their virtual representations.
+ *
+ * @see ConvertedDataContext
+ *
+ * @author Kasper Sørensen
+ * @author Ankit Kumar
+ *
+ * @param <P>
+ * the physical type of value
+ * @param <V>
+ * the virtual type of value
+ */
+public interface TypeConverter<P, V> {
+
+ /**
+ * Converts a virtual representation of a value into it's physical value.
+ *
+ * @param virtualValue
+ * the virtual representation
+ * @return the physical value
+ */
+ public P toPhysicalValue(V virtualValue);
+
+ /**
+ * Converts a physical value into it's virtual representation.
+ *
+ * @param physicalValue
+ * the physical value
+ * @return the virtual representation
+ */
+ public V toVirtualValue(P physicalValue);
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/convert/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/convert/package-info.java b/core/src/main/java/org/apache/metamodel/convert/package-info.java
new file mode 100644
index 0000000..0adf2aa
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/convert/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.
+ */
+/**
+ * DataContext decorator for implicit conversion of value types after querying and before insertion.
+ */
+package org.eobjects.metamodel.convert;
+
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/create/AbstractColumnBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/create/AbstractColumnBuilder.java b/core/src/main/java/org/apache/metamodel/create/AbstractColumnBuilder.java
new file mode 100644
index 0000000..26fee26
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/create/AbstractColumnBuilder.java
@@ -0,0 +1,87 @@
+/**
+ * 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;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.MutableColumn;
+
+/**
+ * Convenience implementation of all {@link ColumnBuilder} methods
+ *
+ * @param <T>
+ * the return type of the builder methods.
+ */
+abstract class AbstractColumnBuilder<T extends ColumnBuilder<?>> implements ColumnBuilder<T> {
+
+ private final MutableColumn _column;
+
+ public AbstractColumnBuilder(MutableColumn column) {
+ _column = column;
+ }
+
+ protected MutableColumn getColumn() {
+ return _column;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected T getReturnObject() {
+ return (T) this;
+ }
+
+ @Override
+ public final T like(Column column) {
+ _column.setColumnSize(column.getColumnSize());
+ _column.setNativeType(column.getNativeType());
+ _column.setType(column.getType());
+ _column.setNullable(column.isNullable());
+ return getReturnObject();
+ }
+
+ @Override
+ public final T ofType(ColumnType type) {
+ _column.setType(type);
+ return getReturnObject();
+ }
+
+ @Override
+ public final T ofNativeType(String nativeType) {
+ _column.setNativeType(nativeType);
+ return getReturnObject();
+ }
+
+ @Override
+ public final T ofSize(int size) {
+ _column.setColumnSize(size);
+ return getReturnObject();
+ }
+
+ @Override
+ public final T nullable(boolean nullable) {
+ _column.setNullable(nullable);
+ return getReturnObject();
+ }
+
+ @Override
+ public final T asPrimaryKey() {
+ _column.setPrimaryKey(true);
+ return getReturnObject();
+ }
+
+}