http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 7504d64..1f424d6 100644 --- a/excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java +++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java @@ -24,6 +24,8 @@ import java.io.OutputStream; import java.text.NumberFormat; import java.util.Date; import java.util.Iterator; +import java.util.List; +import java.util.stream.Collectors; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; @@ -440,7 +442,7 @@ final class ExcelUtils { } public static DataSet getDataSet(Workbook workbook, Sheet sheet, Table table, ExcelConfiguration configuration) { - final SelectItem[] selectItems = MetaModelHelper.createSelectItems(table.getColumns()); + final List<SelectItem> selectItems = table.getColumns().stream().map(SelectItem::new).collect(Collectors.toList()); final Iterator<Row> rowIterator = getRowIterator(sheet, configuration, true); if (!rowIterator.hasNext()) { // no more rows!
http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 1181b07..5fdd7ec 100644 --- a/excel/src/main/java/org/apache/metamodel/excel/SpreadsheetReaderDelegate.java +++ b/excel/src/main/java/org/apache/metamodel/excel/SpreadsheetReaderDelegate.java @@ -23,6 +23,8 @@ import org.apache.metamodel.schema.Column; import org.apache.metamodel.schema.Schema; import org.apache.metamodel.schema.Table; +import java.util.List; + /** * Delegate for spreadsheet-implementation specific operations in an * {@link ExcelDataContext}. @@ -33,6 +35,6 @@ interface SpreadsheetReaderDelegate { public Schema createSchema(String schemaName) throws Exception; - public DataSet executeQuery(Table table, Column[] columns, int maxRows) throws Exception; + public DataSet executeQuery(Table table, List<Column> columns, int maxRows) throws Exception; } http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 4e097e4..e0f4986 100644 --- a/excel/src/main/java/org/apache/metamodel/excel/XlsDataSet.java +++ b/excel/src/main/java/org/apache/metamodel/excel/XlsDataSet.java @@ -19,6 +19,7 @@ package org.apache.metamodel.excel; import java.util.Iterator; +import java.util.List; import org.apache.poi.ss.usermodel.Workbook; import org.apache.metamodel.data.AbstractDataSet; @@ -46,8 +47,8 @@ final class XlsDataSet extends AbstractDataSet { * @param workbook * @param rowIterator */ - public XlsDataSet(SelectItem[] selectItems, Workbook workbook, - Iterator<org.apache.poi.ss.usermodel.Row> rowIterator) { + public XlsDataSet(List<SelectItem> selectItems, Workbook workbook, + Iterator<org.apache.poi.ss.usermodel.Row> rowIterator) { super(selectItems); _workbook = workbook; _rowIterator = rowIterator; http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 a154251..5635de6 100644 --- a/excel/src/main/java/org/apache/metamodel/excel/XlsxRowPublisherAction.java +++ b/excel/src/main/java/org/apache/metamodel/excel/XlsxRowPublisherAction.java @@ -38,12 +38,12 @@ class XlsxRowPublisherAction implements Action<RowPublisher> { .getLogger(XlsxRowPublisherAction.class); private final ExcelConfiguration _configuration; - private final Column[] _columns; + private final List<Column> _columns; private final String _relationshipId; private final XSSFReader _xssfReader; public XlsxRowPublisherAction(ExcelConfiguration configuration, - Column[] columns, String relationshipId, XSSFReader xssfReader) { + List<Column> columns, String relationshipId, XSSFReader xssfReader) { _configuration = configuration; _columns = columns; _relationshipId = relationshipId; @@ -66,10 +66,10 @@ class XlsxRowPublisherAction implements Action<RowPublisher> { } } - Object[] rowData = new Object[_columns.length]; - Style[] styleData = new Style[_columns.length]; - for (int i = 0; i < _columns.length; i++) { - int columnNumber = _columns[i].getColumnNumber(); + Object[] rowData = new Object[_columns.size()]; + Style[] styleData = new Style[_columns.size()]; + for (int i = 0; i < _columns.size(); i++) { + int columnNumber = _columns.get(i).getColumnNumber(); if (columnNumber < values.size()) { rowData[i] = values.get(columnNumber); styleData[i] = styles.get(columnNumber); http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 94a9ff7..0436a2a 100644 --- a/excel/src/main/java/org/apache/metamodel/excel/XlsxSpreadsheetReaderDelegate.java +++ b/excel/src/main/java/org/apache/metamodel/excel/XlsxSpreadsheetReaderDelegate.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; import org.apache.metamodel.data.DataSet; import org.apache.metamodel.data.RowPublisherDataSet; @@ -72,7 +73,7 @@ final class XlsxSpreadsheetReaderDelegate implements SpreadsheetReaderDelegate { } @Override - public DataSet executeQuery(Table table, Column[] columns, int maxRows) throws Exception { + public DataSet executeQuery(Table table, List<Column> columns, int maxRows) throws Exception { final OPCPackage pkg = openOPCPackage(); final XSSFReader xssfReader = new XSSFReader(pkg); final String relationshipId = _tableNamesToInternalIds.get(table.getName()); @@ -136,13 +137,10 @@ final class XlsxSpreadsheetReaderDelegate implements SpreadsheetReaderDelegate { } } - private DataSet buildDataSet(final Column[] columns, int maxRows, final String relationshipId, + private DataSet buildDataSet(final List<Column> columns, int maxRows, final String relationshipId, final XSSFReader xssfReader, final OPCPackage pkg) throws Exception { - List<SelectItem> selectItems = new ArrayList<SelectItem>(columns.length); - for (Column column : columns) { - selectItems.add(new SelectItem(column)); - } + List<SelectItem> selectItems = columns.stream().map(SelectItem::new).collect(Collectors.toList()); final XlsxRowPublisherAction publishAction = new XlsxRowPublisherAction(_configuration, columns, relationshipId, xssfReader); http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 96d7dff..91d336b 100644 --- a/excel/src/test/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegateTest.java +++ b/excel/src/test/java/org/apache/metamodel/excel/DefaultSpreadsheetReaderDelegateTest.java @@ -20,6 +20,7 @@ package org.apache.metamodel.excel; import java.io.File; import java.lang.reflect.Field; +import java.util.List; import org.apache.metamodel.data.DataSet; import org.apache.metamodel.data.Row; @@ -85,31 +86,31 @@ public class DefaultSpreadsheetReaderDelegateTest extends TestCase { assertEquals(DefaultSpreadsheetReaderDelegate.class, mainDataContext.getSpreadsheetReaderDelegateClass()); - Table[] tables = schema.getTables(); - assertTrue(tables.length > 0); + List<Table> tables = schema.getTables(); + assertTrue(tables.size() > 0); - Table[] comparedTables = null; + List<Table> comparedTables = null; if (comparedDataContext != null) { assertEquals(XlsxSpreadsheetReaderDelegate.class, comparedDataContext.getSpreadsheetReaderDelegateClass()); comparedTables = comparedDataContext.getDefaultSchema().getTables(); - assertEquals(comparedTables.length, tables.length); + assertEquals(comparedTables.size(), tables.size()); } - for (int i = 0; i < tables.length; i++) { - Table table = tables[i]; - Column[] columns = table.getColumns(); + for (int i = 0; i < tables.size(); i++) { + Table table = tables.get(i); + List<Column> columns = table.getColumns(); Query query = mainDataContext.query().from(table).select(columns).toQuery(); DataSet dataSet = mainDataContext.executeQuery(query); DataSet comparedDataSet = null; if (comparedDataContext != null) { - Table comparedTable = comparedTables[i]; + Table comparedTable = comparedTables.get(i); assertEquals(comparedTable.getName(), table.getName()); assertEquals(comparedTable.getColumnCount(), table.getColumnCount()); - Column[] comparedColumns = comparedTable.getColumns(); - for (int j = 0; j < comparedColumns.length; j++) { - assertEquals(columns[j].getColumnNumber(), comparedColumns[j].getColumnNumber()); + List<Column> comparedColumns = comparedTable.getColumns(); + for (int j = 0; j < comparedColumns.size(); j++) { + assertEquals(columns.get(j).getColumnNumber(), comparedColumns.get(j).getColumnNumber()); } Query comparedQuery = comparedDataContext.query().from(comparedTable).select(comparedColumns).toQuery(); @@ -173,7 +174,7 @@ public class DefaultSpreadsheetReaderDelegateTest extends TestCase { ExcelDataContext dc = new ExcelDataContext(copyOf("src/test/resources/Spreadsheet2007.xlsx")); applyReaderDelegate(dc); - Table table = dc.getDefaultSchema().getTables()[0]; + Table table = dc.getDefaultSchema().getTables().get(0); final String expectedStyling = ""; @@ -194,7 +195,7 @@ public class DefaultSpreadsheetReaderDelegateTest extends TestCase { ExcelDataContext dc = new ExcelDataContext(copyOf("src/test/resources/formulas.xlsx")); applyReaderDelegate(dc); - Table table = dc.getDefaultSchema().getTables()[0]; + Table table = dc.getDefaultSchema().getTables().get(0); DataSet dataSet = dc.query().from(table).select("Foo").and("Bar").where("Foo").isEquals("7").execute(); assertTrue(dataSet.next()); http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 ecd6691..844522e 100644 --- a/excel/src/test/java/org/apache/metamodel/excel/ExcelDataContextTest.java +++ b/excel/src/test/java/org/apache/metamodel/excel/ExcelDataContextTest.java @@ -82,7 +82,7 @@ public class ExcelDataContextTest extends TestCase { assertNull(dc.getSpreadsheetReaderDelegateClass()); assertEquals(1, dc.getDefaultSchema().getTableCount()); - Table table = dc.getDefaultSchema().getTables()[0]; + Table table = dc.getDefaultSchema().getTables().get(0); assertEquals("sheet", table.getName()); assertEquals(0, table.getColumnCount()); @@ -94,7 +94,7 @@ public class ExcelDataContextTest extends TestCase { ExcelConfiguration.NO_COLUMN_NAME_LINE, false, false)); assertEquals(1, dc.getDefaultSchema().getTableCount()); - Table table = dc.getDefaultSchema().getTables()[0]; + Table table = dc.getDefaultSchema().getTables().get(0); assertEquals("sheet", table.getName()); assertEquals(0, table.getColumnCount()); } @@ -104,7 +104,7 @@ public class ExcelDataContextTest extends TestCase { true, false)); assertEquals(1, dc.getDefaultSchema().getTableCount()); - Table table = dc.getDefaultSchema().getTables()[0]; + Table table = dc.getDefaultSchema().getTables().get(0); assertEquals("xls_people", table.getName()); assertEquals(0, table.getColumnCount()); } @@ -112,8 +112,8 @@ public class ExcelDataContextTest extends TestCase { public void testSkipEmptyColumns() throws Exception { ExcelConfiguration conf = new ExcelConfiguration(ExcelConfiguration.DEFAULT_COLUMN_NAME_LINE, true, true); ExcelDataContext dc = new ExcelDataContext(copyOf("src/test/resources/skipped_lines.xlsx"), conf); - Table table = dc.getDefaultSchema().getTables()[0]; - assertEquals("[hello, world]", Arrays.toString(table.getColumnNames())); + Table table = dc.getDefaultSchema().getTables().get(0); + assertEquals("[hello, world]", Arrays.toString(table.getColumnNames().toArray())); DataSet ds = dc.executeQuery(dc.query().from(table).select("hello").toQuery()); assertTrue(ds.next()); @@ -123,8 +123,8 @@ public class ExcelDataContextTest extends TestCase { public void testDontSkipEmptyLinesNoHeader() throws Exception { ExcelConfiguration conf = new ExcelConfiguration(ExcelConfiguration.NO_COLUMN_NAME_LINE, false, true); ExcelDataContext dc = new ExcelDataContext(copyOf("src/test/resources/skipped_lines.xlsx"), conf); - Table table = dc.getDefaultSchema().getTables()[0]; - assertEquals("[G, H]", Arrays.toString(table.getColumnNames())); + Table table = dc.getDefaultSchema().getTables().get(0); + assertEquals("[G, H]", Arrays.toString(table.getColumnNames().toArray())); assertEquals(6, table.getColumnByName("G").getColumnNumber()); assertEquals(7, table.getColumnByName("H").getColumnNumber()); @@ -147,8 +147,8 @@ public class ExcelDataContextTest extends TestCase { public void testDontSkipEmptyLinesAbsoluteHeader() throws Exception { ExcelConfiguration conf = new ExcelConfiguration(6, false, true); ExcelDataContext dc = new ExcelDataContext(copyOf("src/test/resources/skipped_lines.xlsx"), conf); - Table table = dc.getDefaultSchema().getTables()[0]; - assertEquals("[hello, world]", Arrays.toString(table.getColumnNames())); + Table table = dc.getDefaultSchema().getTables().get(0); + assertEquals("[hello, world]", Arrays.toString(table.getColumnNames().toArray())); assertEquals(6, table.getColumnByName("hello").getColumnNumber()); assertEquals(7, table.getColumnByName("world").getColumnNumber()); @@ -159,9 +159,9 @@ public class ExcelDataContextTest extends TestCase { public void testInvalidFormula() throws Exception { ExcelDataContext dc = new ExcelDataContext(copyOf("src/test/resources/invalid_formula.xls")); - Table table = dc.getDefaultSchema().getTables()[0]; + Table table = dc.getDefaultSchema().getTables().get(0); - assertEquals("[name]", Arrays.toString(table.getColumnNames())); + assertEquals("[name]", Arrays.toString(table.getColumnNames().toArray())); Query q = dc.query().from(table).select("name").toQuery(); @@ -197,11 +197,11 @@ public class ExcelDataContextTest extends TestCase { public void testEvaluateFormula() throws Exception { ExcelDataContext dc = new ExcelDataContext(copyOf("src/test/resources/xls_formulas.xls")); - Table table = dc.getDefaultSchema().getTables()[0]; - Column[] columns = table.getColumns(); + Table table = dc.getDefaultSchema().getTables().get(0); + Column[] columns = table.getColumns().toArray(new Column[0]); assertEquals("[some number, some mixed formula, some int only formula]", - Arrays.toString(table.getColumnNames())); + Arrays.toString(table.getColumnNames().toArray())); Query q = dc.query().from(table).select(columns).toQuery(); DataSet ds = dc.executeQuery(q); @@ -277,7 +277,7 @@ public class ExcelDataContextTest extends TestCase { assertNotNull(table); - assertEquals("[A, hello]", Arrays.toString(table.getColumnNames())); + assertEquals("[A, hello]", Arrays.toString(table.getColumnNames().toArray())); Query q = dc.query().from(table).select(table.getColumns()).toQuery(); DataSet ds = dc.executeQuery(q); @@ -289,14 +289,14 @@ public class ExcelDataContextTest extends TestCase { Schema schema = dc.getDefaultSchema(); assertEquals("Schema[name=testOpenXlsxFormat-Spreadsheet2007.xlsx]", schema.toString()); - assertEquals("[Sheet1, Sheet2, Sheet3]", Arrays.toString(schema.getTableNames())); + assertEquals("[Sheet1, Sheet2, Sheet3]", Arrays.toString(schema.getTableNames().toArray())); assertEquals(0, schema.getTableByName("Sheet2").getColumnCount()); assertEquals(0, schema.getTableByName("Sheet3").getColumnCount()); Table table = schema.getTableByName("Sheet1"); - assertEquals("[string, number, date]", Arrays.toString(table.getColumnNames())); + assertEquals("[string, number, date]", Arrays.toString(table.getColumnNames().toArray())); Query q = dc.query().from(table).select(table.getColumns()).orderBy(table.getColumnByName("number")).toQuery(); DataSet ds = dc.executeQuery(q); @@ -312,9 +312,9 @@ public class ExcelDataContextTest extends TestCase { File file = copyOf("src/test/resources/xls_people.xls"); DataContext dc = new ExcelDataContext(file, new ExcelConfiguration(ExcelConfiguration.NO_COLUMN_NAME_LINE, true, true)); - Table table = dc.getDefaultSchema().getTables()[0]; + Table table = dc.getDefaultSchema().getTables().get(0); - String[] columnNames = table.getColumnNames(); + String[] columnNames = table.getColumnNames().toArray(new String[0]); assertEquals("[A, B, C, D]", Arrays.toString(columnNames)); Query q = dc.query().from(table).select(table.getColumnByName("A")).toQuery(); @@ -334,9 +334,9 @@ public class ExcelDataContextTest extends TestCase { public void testConfigurationNonDefaultColumnNameLineNumber() throws Exception { File file = copyOf("src/test/resources/xls_people.xls"); DataContext dc = new ExcelDataContext(file, new ExcelConfiguration(2, true, true)); - Table table = dc.getDefaultSchema().getTables()[0]; + Table table = dc.getDefaultSchema().getTables().get(0); - String[] columnNames = table.getColumnNames(); + String[] columnNames = table.getColumnNames().toArray(new String[0]); assertEquals("[1, mike, male, 18]", Arrays.toString(columnNames)); Query q = dc.query().from(table).select(table.getColumnByName("1")).toQuery(); @@ -355,18 +355,18 @@ public class ExcelDataContextTest extends TestCase { public void testGetSchemas() throws Exception { File file = copyOf("src/test/resources/xls_people.xls"); DataContext dc = new ExcelDataContext(file); - Schema[] schemas = dc.getSchemas(); + Schema[] schemas = dc.getSchemas().toArray(new Schema[0]); assertEquals(2, schemas.length); Schema schema = schemas[1]; assertEquals("testGetSchemas-xls_people.xls", schema.getName()); assertEquals(1, schema.getTableCount()); - Table table = schema.getTables()[0]; + Table table = schema.getTables().get(0); assertEquals("xls_people", table.getName()); assertEquals(4, table.getColumnCount()); assertEquals(0, table.getRelationshipCount()); - Column[] columns = table.getColumns(); + Column[] columns = table.getColumns().toArray(new Column[0]); assertEquals("id", columns[0].getName()); assertEquals("name", columns[1].getName()); assertEquals("gender", columns[2].getName()); @@ -376,7 +376,7 @@ public class ExcelDataContextTest extends TestCase { public void testMaterializeTable() throws Exception { File file = copyOf("src/test/resources/xls_people.xls"); ExcelDataContext dc = new ExcelDataContext(file); - Table table = dc.getDefaultSchema().getTables()[0]; + Table table = dc.getDefaultSchema().getTables().get(0); DataSet dataSet = dc.materializeMainSchemaTable(table, table.getColumns(), -1); assertTrue(dataSet.next()); assertEquals("Row[values=[1, mike, male, 18]]", dataSet.getRow().toString()); @@ -401,12 +401,12 @@ public class ExcelDataContextTest extends TestCase { Schema schema = dc.getDefaultSchema(); assertEquals(1, schema.getTableCount()); - Table table = schema.getTables()[0]; + Table table = schema.getTables().get(0); assertEquals("[Column[name=a,columnNumber=0,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], " + "Column[name=b,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], " + "Column[name=c,columnNumber=2,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], " + "Column[name=d,columnNumber=3,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]", - Arrays.toString(table.getColumns())); + Arrays.toString(table.getColumns().toArray())); Query q = new Query().select(table.getColumns()).from(table); DataSet ds = dc.executeQuery(q); @@ -425,12 +425,12 @@ public class ExcelDataContextTest extends TestCase { Schema schema = dc.getDefaultSchema(); assertEquals(1, schema.getTableCount()); - Table table = schema.getTables()[0]; + Table table = schema.getTables().get(0); assertEquals("[Column[name=a,columnNumber=0,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], " + "Column[name=b,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], " + "Column[name=A,columnNumber=2,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], " + "Column[name=d,columnNumber=3,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]", - Arrays.toString(table.getColumns())); + Arrays.toString(table.getColumns().toArray())); Query q = new Query().select(table.getColumns()).from(table); DataSet ds = dc.executeQuery(q); @@ -447,11 +447,11 @@ public class ExcelDataContextTest extends TestCase { File file = copyOf("src/test/resources/formulas.xlsx"); ExcelDataContext dc = new ExcelDataContext(file); - assertEquals("[sh1]", Arrays.toString(dc.getDefaultSchema().getTableNames())); + assertEquals("[sh1]", Arrays.toString(dc.getDefaultSchema().getTableNames().toArray())); assertEquals(XlsxSpreadsheetReaderDelegate.class, dc.getSpreadsheetReaderDelegateClass()); Table table = dc.getDefaultSchema().getTableByName("sh1"); - assertEquals("[Foo, Bar]", Arrays.toString(table.getColumnNames())); + assertEquals("[Foo, Bar]", Arrays.toString(table.getColumnNames().toArray())); Query q = dc.query().from(table).select("Foo").toQuery(); DataSet ds = dc.executeQuery(q); @@ -525,7 +525,7 @@ public class ExcelDataContextTest extends TestCase { Schema schema = dc.getDefaultSchema(); assertEquals( "[Table[name=Sheet1,type=null,remarks=null], Table[name=Sheet2,type=null,remarks=null], Table[name=Sheet3,type=null,remarks=null]]", - Arrays.toString(schema.getTables())); + Arrays.toString(schema.getTables().toArray())); assertEquals(0, schema.getTableByName("Sheet2").getColumnCount()); assertEquals(0, schema.getTableByName("Sheet3").getColumnCount()); @@ -537,14 +537,14 @@ public class ExcelDataContextTest extends TestCase { + "Column[name=Description,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], " + "Column[name=Room,columnNumber=2,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], " + "Column[name=Level,columnNumber=3,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]", - Arrays.toString(table.getColumns())); + Arrays.toString(table.getColumns().toArray())); } public void testInsertInto() throws Exception { final File file = copyOf("src/test/resources/xls_people.xls"); final ExcelDataContext dc = new ExcelDataContext(file); - final Table table = dc.getDefaultSchema().getTables()[0]; + final Table table = dc.getDefaultSchema().getTables().get(0); final Column nameColumn = table.getColumnByName("name"); dc.executeUpdate(new UpdateScript() { @@ -620,13 +620,13 @@ public class ExcelDataContextTest extends TestCase { assertEquals(1, schema.getTableCount()); assertSame(table1.getSchema(), schema); - assertSame(table1, schema.getTables()[0]); + assertSame(table1, schema.getTables().get(0)); Table table2 = cb.createTable(schema, "my_table_2").withColumn("foo").withColumn("bar") .withColumn("baz").execute(); assertSame(table2.getSchema(), schema); - assertSame(table2, schema.getTables()[1]); + assertSame(table2, schema.getTables().get(1)); assertEquals(2, schema.getTableCount()); cb.insertInto(table1).value("foo", 123.0).value("bar", "str 1").value("baz", true).execute(); @@ -637,7 +637,7 @@ public class ExcelDataContextTest extends TestCase { Schema schema = dc.getDefaultSchema(); assertEquals(2, schema.getTableCount()); - assertEquals("[my_table_1, my_table_2]", Arrays.toString(schema.getTableNames())); + assertEquals("[my_table_1, my_table_2]", Arrays.toString(schema.getTableNames().toArray())); dc.executeUpdate(new UpdateScript() { @Override @@ -689,18 +689,18 @@ public class ExcelDataContextTest extends TestCase { } }); - assertEquals("[my_table_2]", Arrays.toString(schema.getTableNames())); + assertEquals("[my_table_2]", Arrays.toString(schema.getTableNames().toArray())); dc.refreshSchemas(); - assertEquals("[my_table_2]", Arrays.toString(dc.getDefaultSchema().getTableNames())); + assertEquals("[my_table_2]", Arrays.toString(dc.getDefaultSchema().getTableNames().toArray())); assertEquals(1, dc.getDefaultSchema().getTableCount()); } public void testGetStyles() throws Exception { DataContext dc = new ExcelDataContext(copyOf("src/test/resources/styles.xlsx")); - Table table = dc.getDefaultSchema().getTables()[0]; - assertEquals("[style name, example]", Arrays.toString(table.getColumnNames())); + Table table = dc.getDefaultSchema().getTables().get(0); + assertEquals("[style name, example]", Arrays.toString(table.getColumnNames().toArray())); DataSet ds = dc.query().from(table).select(table.getColumns()).execute(); assertTrue(ds.next()); http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 97101bd..a181248 100644 --- a/excel/src/test/java/org/apache/metamodel/excel/ExcelUpdateCallbackTest.java +++ b/excel/src/test/java/org/apache/metamodel/excel/ExcelUpdateCallbackTest.java @@ -84,11 +84,11 @@ public class ExcelUpdateCallbackTest extends TestCase { { ExcelDataContext dc = new ExcelDataContext(file); assertEquals("[foobar]", - Arrays.toString(dc.getDefaultSchema().getTableNames())); + Arrays.toString(dc.getDefaultSchema().getTableNames().toArray())); Table table = dc.getDefaultSchema().getTableByName("foobar"); - assertEquals("[value0]", Arrays.toString(table.getColumnNames())); + assertEquals("[value0]", Arrays.toString(table.getColumnNames().toArray())); DataSet ds = dc.query().from(table).select("value0").execute(); int recordNo = 1; http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 952c4b5..aac5ada 100644 --- a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataContext.java +++ b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataContext.java @@ -21,6 +21,7 @@ package org.apache.metamodel.fixedwidth; import java.io.BufferedInputStream; import java.io.File; import java.io.InputStream; +import java.util.List; import org.apache.metamodel.MetaModelException; import org.apache.metamodel.QueryPostprocessDataContext; @@ -130,7 +131,7 @@ public class FixedWidthDataContext extends QueryPostprocessDataContext { } @Override - public DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) { + public DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) { final FixedWidthReader reader = createReader(); try { for (int i = 1; i <= _configuration.getColumnNameLineNumber(); i++) { http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 4f78bab..ae469c1 100644 --- a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataSet.java +++ b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataSet.java @@ -21,9 +21,13 @@ package org.apache.metamodel.fixedwidth; import org.apache.metamodel.data.AbstractDataSet; import org.apache.metamodel.data.DefaultRow; import org.apache.metamodel.data.Row; +import org.apache.metamodel.query.SelectItem; import org.apache.metamodel.schema.Column; import org.apache.metamodel.util.FileHelper; +import java.util.List; +import java.util.stream.Collectors; + /** * DataSet implementation for fixed width values. */ @@ -33,9 +37,9 @@ class FixedWidthDataSet extends AbstractDataSet { private volatile Integer _rowsRemaining; private volatile Row _row; - public FixedWidthDataSet(FixedWidthReader reader, Column[] columns, + public FixedWidthDataSet(FixedWidthReader reader, List<Column> columns, Integer maxRows) { - super(columns); + super(columns.stream().map(SelectItem::new).collect(Collectors.toList())); _reader = reader; _rowsRemaining = maxRows; } http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthConfigurationReaderTest.java ---------------------------------------------------------------------- diff --git a/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthConfigurationReaderTest.java b/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthConfigurationReaderTest.java index c34b294..61e10d4 100644 --- a/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthConfigurationReaderTest.java +++ b/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthConfigurationReaderTest.java @@ -69,7 +69,7 @@ public class FixedWidthConfigurationReaderTest { */ private void performAssertionsOnSpec1(FixedWidthDataContext dataContext) { final Table table = dataContext.getDefaultSchema().getTable(0); - final String[] columnNames = table.getColumnNames(); + final String[] columnNames = table.getColumnNames().toArray(new String[0]); assertEquals("[Record type, Description, Initials]", Arrays.toString(columnNames)); try (final DataSet dataSet = dataContext.query().from(table).selectAll().execute()) { http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 7a4b75f..16f2c5b 100644 --- a/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthDataContextTest.java +++ b/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthDataContextTest.java @@ -37,7 +37,7 @@ public class FixedWidthDataContextTest extends TestCase { new FixedWidthConfiguration(10)); assertEquals(1, dc.getDefaultSchema().getTableCount()); - Table table = dc.getDefaultSchema().getTables()[0]; + Table table = dc.getDefaultSchema().getTables().get(0); assertEquals("empty_file.txt", table.getName()); assertEquals(0, table.getColumnCount()); } @@ -47,7 +47,7 @@ public class FixedWidthDataContextTest extends TestCase { new FixedWidthConfiguration(FixedWidthConfiguration.NO_COLUMN_NAME_LINE, "UTF8", 10)); assertEquals(1, dc.getDefaultSchema().getTableCount()); - Table table = dc.getDefaultSchema().getTables()[0]; + Table table = dc.getDefaultSchema().getTables().get(0); assertEquals("empty_file.txt", table.getName()); assertEquals(0, table.getColumnCount()); } @@ -57,7 +57,7 @@ public class FixedWidthDataContextTest extends TestCase { new FixedWidthConfiguration(20, "UTF8", 10)); assertEquals(1, dc.getDefaultSchema().getTableCount()); - Table table = dc.getDefaultSchema().getTables()[0]; + Table table = dc.getDefaultSchema().getTables().get(0); assertEquals("example_simple1.txt", table.getName()); assertEquals(0, table.getColumnCount()); } @@ -66,7 +66,7 @@ public class FixedWidthDataContextTest extends TestCase { FixedWidthConfiguration conf = new FixedWidthConfiguration(10); FixedWidthDataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple1.txt"), conf); - String[] schemaNames = dc.getSchemaNames(); + String[] schemaNames = dc.getSchemaNames().toArray(new String[0]); assertEquals(2, schemaNames.length); assertEquals("[information_schema, resources]", Arrays.toString(schemaNames)); @@ -78,7 +78,7 @@ public class FixedWidthDataContextTest extends TestCase { Table table = schema.getTableByName("example_simple1.txt"); assertEquals("Table[name=example_simple1.txt,type=TABLE,remarks=null]", table.toString()); - assertEquals("[greeting, greeter]", Arrays.toString(table.getColumnNames())); + assertEquals("[greeting, greeter]", Arrays.toString(table.getColumnNames().toArray())); assertEquals(10, table.getColumnByName("greeting").getColumnSize().intValue()); assertEquals(10, table.getColumnByName("greeter").getColumnSize().intValue()); @@ -99,7 +99,7 @@ public class FixedWidthDataContextTest extends TestCase { 10, true); FixedWidthDataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple1.txt"), conf); - String[] schemaNames = dc.getSchemaNames(); + String[] schemaNames = dc.getSchemaNames().toArray(new String[0]); assertEquals(2, schemaNames.length); assertEquals("[information_schema, resources]", Arrays.toString(schemaNames)); @@ -111,7 +111,7 @@ public class FixedWidthDataContextTest extends TestCase { Table table = schema.getTableByName("example_simple1.txt"); assertEquals("Table[name=example_simple1.txt,type=TABLE,remarks=null]", table.toString()); - assertEquals("[A, B]", Arrays.toString(table.getColumnNames())); + assertEquals("[A, B]", Arrays.toString(table.getColumnNames().toArray())); Query q = dc.query().from(table).select(table.getColumns()).toQuery(); DataSet ds = dc.executeQuery(q); @@ -137,8 +137,8 @@ public class FixedWidthDataContextTest extends TestCase { public void testVaryingValueLengthsCorrect() throws Exception { DataContext dc = new FixedWidthDataContext(new File("src/test/resources/example_simple2.txt"), new FixedWidthConfiguration(new int[] { 1, 8, 7 })); - Table table = dc.getDefaultSchema().getTables()[0]; - assertEquals("[i, greeting, greeter]", Arrays.toString(table.getColumnNames())); + Table table = dc.getDefaultSchema().getTables().get(0); + assertEquals("[i, greeting, greeter]", Arrays.toString(table.getColumnNames().toArray())); assertEquals(1, table.getColumnByName("i").getColumnSize().intValue()); assertEquals(8, table.getColumnByName("greeting").getColumnSize().intValue()); @@ -174,8 +174,8 @@ public class FixedWidthDataContextTest extends TestCase { new FixedWidthConfiguration(FixedWidthConfiguration.DEFAULT_COLUMN_NAME_LINE, "UTF8", new int[] { 1, 5, 7 }, false)); - Table table = dc.getDefaultSchema().getTables()[0]; - assertEquals("[i, greet, inggree]", Arrays.toString(table.getColumnNames())); + Table table = dc.getDefaultSchema().getTables().get(0); + assertEquals("[i, greet, inggree]", Arrays.toString(table.getColumnNames().toArray())); Query q = dc.query().from(table).select(table.getColumns()).toQuery(); DataSet ds = dc.executeQuery(q); @@ -208,8 +208,8 @@ public class FixedWidthDataContextTest extends TestCase { new FixedWidthConfiguration(FixedWidthConfiguration.DEFAULT_COLUMN_NAME_LINE, "UTF8", new int[] { 1, 8, 9 }, false)); - Table table = dc.getDefaultSchema().getTables()[0]; - assertEquals("[i, greeting, greeter]", Arrays.toString(table.getColumnNames())); + Table table = dc.getDefaultSchema().getTables().get(0); + assertEquals("[i, greeting, greeter]", Arrays.toString(table.getColumnNames().toArray())); Query q = dc.query().from(table).select(table.getColumns()).toQuery(); DataSet ds = dc.executeQuery(q); http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/hbase/src/main/java/org/apache/metamodel/hbase/HBaseDataContext.java ---------------------------------------------------------------------- diff --git a/hbase/src/main/java/org/apache/metamodel/hbase/HBaseDataContext.java b/hbase/src/main/java/org/apache/metamodel/hbase/HBaseDataContext.java index e49076e..55e4f41 100644 --- a/hbase/src/main/java/org/apache/metamodel/hbase/HBaseDataContext.java +++ b/hbase/src/main/java/org/apache/metamodel/hbase/HBaseDataContext.java @@ -211,7 +211,7 @@ public class HBaseDataContext extends QueryPostprocessDataContext { } @Override - protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) { + protected DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) { final Scan scan = new Scan(); for (Column column : columns) { if (!column.isPrimaryKey()) { http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/hbase/src/main/java/org/apache/metamodel/hbase/HBaseDataSet.java ---------------------------------------------------------------------- diff --git a/hbase/src/main/java/org/apache/metamodel/hbase/HBaseDataSet.java b/hbase/src/main/java/org/apache/metamodel/hbase/HBaseDataSet.java index a4158d5..c68e6da 100644 --- a/hbase/src/main/java/org/apache/metamodel/hbase/HBaseDataSet.java +++ b/hbase/src/main/java/org/apache/metamodel/hbase/HBaseDataSet.java @@ -19,12 +19,15 @@ package org.apache.metamodel.hbase; import java.io.IOException; +import java.util.List; +import java.util.stream.Collectors; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.metamodel.MetaModelException; import org.apache.metamodel.data.AbstractDataSet; import org.apache.metamodel.data.Row; +import org.apache.metamodel.query.SelectItem; import org.apache.metamodel.schema.Column; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,8 +40,8 @@ final class HBaseDataSet extends AbstractDataSet { private final org.apache.hadoop.hbase.client.Table _hTable; private volatile Result _nextResult; - public HBaseDataSet(Column[] columns, ResultScanner scanner, org.apache.hadoop.hbase.client.Table hTable) { - super(columns); + public HBaseDataSet(List<Column> columns, ResultScanner scanner, org.apache.hadoop.hbase.client.Table hTable) { + super(columns.stream().map(SelectItem::new).collect(Collectors.toList())); _scanner = scanner; _hTable = hTable; } http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/hbase/src/test/java/org/apache/metamodel/hbase/HBaseDataContextTest.java ---------------------------------------------------------------------- diff --git a/hbase/src/test/java/org/apache/metamodel/hbase/HBaseDataContextTest.java b/hbase/src/test/java/org/apache/metamodel/hbase/HBaseDataContextTest.java index eb0ba48..6187f2c 100644 --- a/hbase/src/test/java/org/apache/metamodel/hbase/HBaseDataContextTest.java +++ b/hbase/src/test/java/org/apache/metamodel/hbase/HBaseDataContextTest.java @@ -59,7 +59,7 @@ public class HBaseDataContextTest extends HBaseTestCase { final Table table = _dataContext.getDefaultSchema().getTableByName(EXAMPLE_TABLE_NAME); assertNotNull(table); - assertEquals("[_id, bar, foo]", Arrays.toString(table.getColumnNames())); + assertEquals("[_id, bar, foo]", Arrays.toString(table.getColumnNames().toArray())); assertEquals(ColumnType.MAP, table.getColumn(1).getType()); // insert two records http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 d20f369..0612b3e 100644 --- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCreateTableBuilder.java +++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCreateTableBuilder.java @@ -21,6 +21,7 @@ package org.apache.metamodel.jdbc; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; +import java.util.List; import org.apache.metamodel.create.AbstractTableCreationBuilder; import org.apache.metamodel.jdbc.dialects.IQueryRewriter; @@ -84,9 +85,9 @@ final class JdbcCreateTableBuilder extends AbstractTableCreationBuilder<JdbcUpda } sb.append(getUpdateCallback().quoteIfNescesary(table.getName())); sb.append(" ("); - final Column[] columns = table.getColumns(); - for (int i = 0; i < columns.length; i++) { - final Column column = columns[i]; + final List<Column> columns = table.getColumns(); + for (int i = 0; i < columns.size(); i++) { + final Column column = columns.get(i); if (i != 0) { sb.append(", "); } @@ -114,15 +115,15 @@ final class JdbcCreateTableBuilder extends AbstractTableCreationBuilder<JdbcUpda } } boolean primaryKeyExists = false; - for (int i = 0; i < columns.length; i++) { - if (columns[i].isPrimaryKey()) { + for (int i = 0; i < columns.size(); i++) { + if (columns.get(i).isPrimaryKey()) { if (!primaryKeyExists) { sb.append(", PRIMARY KEY("); - sb.append(columns[i].getName()); + sb.append(columns.get(i).getName()); primaryKeyExists = true; } else { sb.append(","); - sb.append(columns[i].getName()); + sb.append(columns.get(i).getName()); } } } http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 5a9b784..3f4a0ad 100644 --- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataContext.java +++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcDataContext.java @@ -643,12 +643,12 @@ public class JdbcDataContext extends AbstractDataContext implements UpdateableDa // databases). boolean found = false; String result = null; - String[] schemaNames = getSchemaNames(); + List<String> schemaNames = getSchemaNames(); // First strategy: If there's only one schema available, that must // be it - if (schemaNames.length == 1) { - result = schemaNames[0]; + if (schemaNames.size() == 1) { + result = schemaNames.get(0); found = true; } @@ -669,7 +669,7 @@ public class JdbcDataContext extends AbstractDataContext implements UpdateableDa } } if (url != null && url.length() > 0) { - if (schemaNames.length > 0) { + if (schemaNames.size() > 0) { StringTokenizer st = new StringTokenizer(url, "/\\:"); int tokenCount = st.countTokens(); if (tokenCount > 0) { @@ -678,8 +678,8 @@ public class JdbcDataContext extends AbstractDataContext implements UpdateableDa } String lastToken = st.nextToken(); - for (int i = 0; i < schemaNames.length && !found; i++) { - String schemaName = schemaNames[i]; + for (int i = 0; i < schemaNames.size() && !found; i++) { + String schemaName = schemaNames.get(i); if (lastToken.indexOf(schemaName) != -1) { result = schemaName; found = true; @@ -701,9 +701,9 @@ public class JdbcDataContext extends AbstractDataContext implements UpdateableDa } } if (username != null) { - for (int i = 0; i < schemaNames.length && !found; i++) { - if (username.equalsIgnoreCase(schemaNames[i])) { - result = schemaNames[i]; + for (int i = 0; i < schemaNames.size() && !found; i++) { + if (username.equalsIgnoreCase(schemaNames.get(i))) { + result = schemaNames.get(i); found = true; } } @@ -741,7 +741,7 @@ public class JdbcDataContext extends AbstractDataContext implements UpdateableDa return result; } - private String findDefaultSchema(final String defaultName, final String[] schemaNames) { + private String findDefaultSchema(final String defaultName, final List<String> schemaNames) { for (String schemaName : schemaNames) { if (defaultName.equals(schemaName)) { return schemaName; @@ -785,14 +785,14 @@ public class JdbcDataContext extends AbstractDataContext implements UpdateableDa } @Override - protected String[] getSchemaNamesInternal() { + protected List<String> getSchemaNamesInternal() { Connection connection = getConnection(); try { DatabaseMetaData metaData = connection.getMetaData(); - Collection<String> result = new ArrayList<>(); + List<String> result = new ArrayList<>(); if (DATABASE_PRODUCT_SQLSERVER.equals(_databaseProductName)) { - result = getSchemaSQLServerNames(metaData); + result = new ArrayList<>(getSchemaSQLServerNames(metaData)); } else if (_usesCatalogsAsSchemas) { String[] catalogNames = getCatalogNames(); for (String name : catalogNames) { @@ -818,7 +818,7 @@ public class JdbcDataContext extends AbstractDataContext implements UpdateableDa logger.info("No schemas or catalogs found. Creating unnamed schema."); result.add(null); } - return result.toArray(new String[result.size()]); + return result; } catch (SQLException e) { throw JdbcUtils.wrapException(e, "get schema names"); } finally { http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 837fb18..49e242b 100644 --- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcMetadataLoader.java +++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcMetadataLoader.java @@ -398,9 +398,8 @@ final class JdbcMetadataLoader implements MetadataLoader { return; } try { - final Table[] tables = schema.getTables(); final DatabaseMetaData metaData = connection.getMetaData(); - for (Table table : tables) { + for (Table table : schema.getTables()) { loadRelations(table, metaData); } _loadedRelations.add(identity); @@ -453,7 +452,7 @@ final class JdbcMetadataLoader implements MetadataLoader { logger.error("pkColumn={}", pkColumn); logger.error("fkColumn={}", fkColumn); } else { - MutableRelationship.createRelationship(new Column[] { pkColumn }, new Column[] { fkColumn }); + MutableRelationship.createRelationship(pkColumn, fkColumn); } } } http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 06aa93c..0dc0381 100644 --- a/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSchema.java +++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcSchema.java @@ -59,8 +59,7 @@ final class JdbcSchema extends MutableSchema { } public Schema toSerializableForm() { - MutableTable[] tables = getTables(); - for (MutableTable table : tables) { + for (MutableTable table : getMutableTables()) { table.getColumns(); table.getIndexedColumns(); table.getPrimaryKeys(); http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 bbb09c9..07a0db2 100644 --- a/jdbc/src/main/java/org/apache/metamodel/jdbc/QuerySplitter.java +++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/QuerySplitter.java @@ -274,9 +274,7 @@ public final class QuerySplitter { } private static void addColumnsToResult(Table table, List<Column> result) { - Column[] numberColumns = table.getNumberColumns(); - for (int i = 0; i < numberColumns.length; i++) { - Column column = numberColumns[i]; + for (Column column: table.getNumberColumns()) { if (column.isIndexed()) { // Indexed columns have first priority, they will be // added to the beginning of the list http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 ff6ef22..eb026d8 100644 --- a/jdbc/src/test/java/org/apache/metamodel/jdbc/DerbyTest.java +++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/DerbyTest.java @@ -139,7 +139,7 @@ public class DerbyTest extends TestCase { q.toSql()); DataSet dataSet = dc.executeQuery(q); - assertEquals("[\"CUSTOMERS\".\"CUSTOMERNUMBER\"]", Arrays.toString(dataSet.getSelectItems())); + assertEquals("[\"CUSTOMERS\".\"CUSTOMERNUMBER\"]", Arrays.toString(dataSet.getSelectItems().toArray())); assertTrue(dataSet.next()); assertEquals("Row[values=[114]]", dataSet.getRow().toString()); assertTrue(dataSet.next()); @@ -152,7 +152,7 @@ public class DerbyTest extends TestCase { public void testGetSchemaNormalTableTypes() throws Exception { DataContext dc = new JdbcDataContext(_connection, new TableType[] { TableType.TABLE, TableType.VIEW }, null); - Schema[] schemas = dc.getSchemas(); + Schema[] schemas = dc.getSchemas().toArray(new Schema[dc.getSchemas().size()]); assertEquals(11, schemas.length); assertEquals("Schema[name=APP]", schemas[0].toString()); @@ -182,7 +182,7 @@ public class DerbyTest extends TestCase { public void testGetSchemaAllTableTypes() throws Exception { DataContext dc = new JdbcDataContext(_connection, new TableType[] { TableType.OTHER, TableType.GLOBAL_TEMPORARY }, null); - Schema[] schemas = dc.getSchemas(); + Schema[] schemas = dc.getSchemas().toArray(new Schema[dc.getSchemas().size()]); assertEquals(11, schemas.length); assertEquals("Schema[name=APP]", schemas[0].toString()); @@ -194,7 +194,7 @@ public class DerbyTest extends TestCase { + "Table[name=ORDERS,type=TABLE,remarks=], " + "Table[name=PAYMENTS,type=TABLE,remarks=], " + "Table[name=PRODUCTS,type=TABLE,remarks=], " + "Table[name=QUADRANT_ACTUALS,type=TABLE,remarks=], " + "Table[name=TIME,type=TABLE,remarks=], " + "Table[name=TRIAL_BALANCE,type=TABLE,remarks=]]", - Arrays.toString(schemas[0].getTables())); + Arrays.toString(schemas[0].getTables().toArray())); assertEquals("Schema[name=NULLID]", schemas[1].toString()); assertEquals(0, schemas[1].getTableCount()); assertEquals("Schema[name=SQLJ]", schemas[2].toString()); @@ -210,7 +210,7 @@ public class DerbyTest extends TestCase { + "Table[name=SYSSCHEMAS,type=OTHER,remarks=], " + "Table[name=SYSSTATEMENTS,type=OTHER,remarks=], " + "Table[name=SYSSTATISTICS,type=OTHER,remarks=], " + "Table[name=SYSTABLEPERMS,type=OTHER,remarks=], " + "Table[name=SYSTABLES,type=OTHER,remarks=], " + "Table[name=SYSTRIGGERS,type=OTHER,remarks=], " - + "Table[name=SYSVIEWS,type=OTHER,remarks=]]", Arrays.toString(schemas[3].getTables())); + + "Table[name=SYSVIEWS,type=OTHER,remarks=]]", Arrays.toString(schemas[3].getTables().toArray())); assertEquals("Schema[name=SYSCAT]", schemas[4].toString()); assertEquals(0, schemas[4].getTableCount()); assertEquals("Schema[name=SYSCS_DIAG]", schemas[5].toString()); @@ -221,7 +221,7 @@ public class DerbyTest extends TestCase { assertEquals(0, schemas[7].getTableCount()); assertEquals("Schema[name=SYSIBM]", schemas[8].toString()); assertEquals(1, schemas[8].getTableCount()); - assertEquals("[Table[name=SYSDUMMY1,type=OTHER,remarks=]]", Arrays.toString(schemas[8].getTables())); + assertEquals("[Table[name=SYSDUMMY1,type=OTHER,remarks=]]", Arrays.toString(schemas[8].getTables().toArray())); assertEquals("Schema[name=SYSPROC]", schemas[9].toString()); assertEquals(0, schemas[9].getTableCount()); assertEquals("Schema[name=SYSSTAT]", schemas[10].toString()); @@ -241,7 +241,7 @@ public class DerbyTest extends TestCase { + "Column[name=COUNTRY,columnNumber=10,type=VARCHAR,nullable=true,nativeType=VARCHAR,columnSize=255], " + "Column[name=SALESREPEMPLOYEENUMBER,columnNumber=11,type=INTEGER,nullable=true,nativeType=INTEGER,columnSize=10], " + "Column[name=CREDITLIMIT,columnNumber=12,type=BIGINT,nullable=true,nativeType=BIGINT,columnSize=19]]", - Arrays.toString(schemas[0].getTableByName("CUSTOMERS").getColumns())); + Arrays.toString(schemas[0].getTableByName("CUSTOMERS").getColumns().toArray())); } public void testQueryRewriterQuoteAliases() throws Exception { @@ -328,7 +328,7 @@ public class DerbyTest extends TestCase { assertSame(conn, dc.getConnection()); final Table readTable = dc.getDefaultSchema().getTableByName("test_table"); - assertEquals("[ID, NAME, AGE]", Arrays.toString(readTable.getColumnNames())); + assertEquals("[ID, NAME, AGE]", Arrays.toString(readTable.getColumnNames().toArray())); assertTrue(readTable.getColumnByName("id").isPrimaryKey()); assertFalse(readTable.getColumnByName("age").isPrimaryKey()); assertFalse(readTable.getColumnByName("name").isPrimaryKey()); http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 6e21ae5..e7b5386 100644 --- a/jdbc/src/test/java/org/apache/metamodel/jdbc/H2databaseTest.java +++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/H2databaseTest.java @@ -143,16 +143,16 @@ public class H2databaseTest extends TestCase { } JdbcDataContext dc = new JdbcDataContext(conn); - assertEquals("[INFORMATION_SCHEMA, PUBLIC]", Arrays.toString(dc.getSchemaNames())); + assertEquals("[INFORMATION_SCHEMA, PUBLIC]", Arrays.toString(dc.getSchemaNames().toArray())); Schema schema = dc.getDefaultSchema(); assertEquals("PUBLIC", schema.getName()); - assertEquals("[TEST_TABLE]", Arrays.toString(schema.getTableNames())); + assertEquals("[TEST_TABLE]", Arrays.toString(schema.getTableNames().toArray())); Table table = schema.getTableByName("test_table"); - assertEquals("[ID, NAME, AGE]", Arrays.toString(table.getColumnNames())); + assertEquals("[ID, NAME, AGE]", Arrays.toString(table.getColumnNames().toArray())); Column idColumn = table.getColumnByName("ID"); assertEquals("Column[name=ID,columnNumber=0,type=INTEGER,nullable=false,nativeType=INTEGER,columnSize=10]", @@ -283,18 +283,18 @@ public class H2databaseTest extends TestCase { String sql = createTableBuilder.createSqlStatement(); assertEquals("CREATE TABLE PUBLIC.test_table (id INTEGER, name VARCHAR(255), age INTEGER, PRIMARY KEY(id))", sql); assertNotNull(writtenTable); - assertEquals("[ID, NAME, AGE]", Arrays.toString(writtenTable.getColumnNames())); + assertEquals("[ID, NAME, AGE]", Arrays.toString(writtenTable.getColumnNames().toArray())); writtenTableRef.set(writtenTable); } }); - assertEquals("[TEST_TABLE]", Arrays.toString(dc.getDefaultSchema().getTableNames())); + assertEquals("[TEST_TABLE]", Arrays.toString(dc.getDefaultSchema().getTableNames().toArray())); readTable = dc.getDefaultSchema().getTableByName("test_table"); - assertEquals("[ID, NAME, AGE]", Arrays.toString(readTable.getColumnNames())); + assertEquals("[ID, NAME, AGE]", Arrays.toString(readTable.getColumnNames().toArray())); assertEquals("[Column[name=ID,columnNumber=0,type=INTEGER,nullable=false,nativeType=INTEGER,columnSize=10]]", - Arrays.toString(readTable.getPrimaryKeys())); + Arrays.toString(readTable.getPrimaryKeys().toArray())); assertEquals(writtenTableRef.get(), readTable); assertFalse(conn.isReadOnly()); @@ -303,7 +303,7 @@ public class H2databaseTest extends TestCase { assertSame(conn, dc.getConnection()); readTable = dc.getDefaultSchema().getTableByName("test_table"); - assertEquals("[ID, NAME, AGE]", Arrays.toString(readTable.getColumnNames())); + assertEquals("[ID, NAME, AGE]", Arrays.toString(readTable.getColumnNames().toArray())); assertTrue(writtenTableRef.get().getQualifiedLabel().equalsIgnoreCase(readTable.getQualifiedLabel())); dc.executeUpdate(new UpdateScript() { @@ -362,7 +362,7 @@ public class H2databaseTest extends TestCase { assertFalse(ds.next()); ds.close(); - assertEquals("[TEST_TABLE]", Arrays.toString(dc.getDefaultSchema().getTableNames())); + assertEquals("[TEST_TABLE]", Arrays.toString(dc.getDefaultSchema().getTableNames().toArray())); dc.executeUpdate(new UpdateScript() { @Override @@ -371,7 +371,7 @@ public class H2databaseTest extends TestCase { } }); - assertEquals("[]", Arrays.toString(dc.getDefaultSchema().getTableNames())); + assertEquals("[]", Arrays.toString(dc.getDefaultSchema().getTableNames().toArray())); } public void testSelectItemsThatReferencesDifferentFromItems() throws Exception { http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 12d5fe2..bf64fdd 100644 --- a/jdbc/src/test/java/org/apache/metamodel/jdbc/HsqldbTest.java +++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/HsqldbTest.java @@ -100,12 +100,12 @@ public class HsqldbTest extends TestCase { public void testGetSchemas() throws Exception { assertNotNull(_connection); JdbcDataContext dc = new JdbcDataContext(_connection); - assertEquals("[Schema[name=INFORMATION_SCHEMA], " + "Schema[name=PUBLIC]]", Arrays.toString(dc.getSchemas())); + assertEquals("[Schema[name=INFORMATION_SCHEMA], " + "Schema[name=PUBLIC]]", Arrays.toString(dc.getSchemas().toArray())); Schema defaultSchema = dc.getDefaultSchema(); Schema publicSchema = dc.getSchemaByName("PUBLIC"); assertSame(defaultSchema, publicSchema); - Table[] tables = publicSchema.getTables(); + Table[] tables = publicSchema.getTables().toArray(new Table[publicSchema.getTables().size()]); assertEquals(13, tables.length); assertEquals("[Table[name=CUSTOMERS,type=TABLE,remarks=null], " + "Table[name=CUSTOMER_W_TER,type=TABLE,remarks=null], " @@ -128,16 +128,16 @@ public class HsqldbTest extends TestCase { + "Column[name=OFFICECODE,columnNumber=5,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=20], " + "Column[name=REPORTSTO,columnNumber=6,type=INTEGER,nullable=true,nativeType=INTEGER,columnSize=0], " + "Column[name=JOBTITLE,columnNumber=7,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=50]]", - Arrays.toString(empTable.getColumns())); + Arrays.toString(empTable.getColumns().toArray())); assertEquals( "[Column[name=EMPLOYEENUMBER,columnNumber=0,type=INTEGER,nullable=false,nativeType=INTEGER,columnSize=0]]", - Arrays.toString(empTable.getPrimaryKeys())); + Arrays.toString(empTable.getPrimaryKeys().toArray())); // Only a single relationship registered in the database assertEquals( "[Relationship[primaryTable=PRODUCTS,primaryColumns=[PRODUCTCODE],foreignTable=ORDERFACT,foreignColumns=[PRODUCTCODE]]]", - Arrays.toString(publicSchema.getRelationships())); + Arrays.toString(publicSchema.getRelationships().toArray())); } public void testExecuteQuery() throws Exception { @@ -146,8 +146,8 @@ public class HsqldbTest extends TestCase { Table productsTable = schema.getTableByName("PRODUCTS"); Table factTable = schema.getTableByName("ORDERFACT"); - Query q = new Query().from(new FromItem(JoinType.INNER, productsTable.getRelationships(factTable)[0])).select( - productsTable.getColumns()[0], factTable.getColumns()[0]); + Query q = new Query().from(new FromItem(JoinType.INNER, productsTable.getRelationships(factTable).iterator().next())).select( + productsTable.getColumns().get(0), factTable.getColumns().get(0)); assertEquals( "SELECT \"PRODUCTS\".\"PRODUCTCODE\", \"ORDERFACT\".\"ORDERNUMBER\" FROM PUBLIC.\"PRODUCTS\" INNER JOIN PUBLIC.\"ORDERFACT\" ON \"PRODUCTS\".\"PRODUCTCODE\" = \"ORDERFACT\".\"PRODUCTCODE\"", q.toString()); http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 17b86fa..c0f1b4e 100644 --- a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcDataContextTest.java +++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcDataContextTest.java @@ -79,7 +79,7 @@ public class JdbcDataContextTest extends JdbcTestCase { public void testQueryMaxRows0() throws Exception { final Connection con = getTestDbConnection(); final DataContext dc = new JdbcDataContext(con); - final Table table = dc.getDefaultSchema().getTables()[0]; + final Table table = dc.getDefaultSchema().getTables().get(0); final DataSet dataSet = dc.query().from(table).selectAll().limit(0).execute(); assertTrue(dataSet instanceof EmptyDataSet); assertFalse(dataSet.next()); @@ -142,7 +142,7 @@ public class JdbcDataContextTest extends JdbcTestCase { Schema schema = strategy.getSchemaByName(strategy.getDefaultSchemaName()); Query q = new Query(); - Table table = schema.getTables()[0]; + Table table = schema.getTables().get(0); q.from(table, "a"); q.select(table.getColumns()); assertEquals( @@ -174,7 +174,7 @@ public class JdbcDataContextTest extends JdbcTestCase { QueryParameter queryParameter = new QueryParameter(); Query q = new Query(); - Table table = schema.getTables()[0]; + Table table = schema.getTables().get(0); q.select(table.getColumns()); q.from(table, "a"); q.where(table.getColumnByName("CUSTOMERNUMBER"), OperatorType.EQUALS_TO, queryParameter); @@ -232,7 +232,7 @@ public class JdbcDataContextTest extends JdbcTestCase { .select(FunctionType.TO_DATE, "creditlimit").select("creditlimit").limit(2).execute(); try { assertEquals("[_CUSTOMERS_._CREDITLIMIT_, TO_DATE(_CUSTOMERS_._CREDITLIMIT_), _CUSTOMERS_._CREDITLIMIT_]", - Arrays.toString(dataSet.getSelectItems()).replaceAll("\"", "_")); + Arrays.toString(dataSet.getSelectItems().toArray()).replaceAll("\"", "_")); assertTrue(dataSet.next()); final Object value0 = dataSet.getRow().getValue(0); @@ -282,7 +282,7 @@ public class JdbcDataContextTest extends JdbcTestCase { QueryParameter queryParameter = new QueryParameter(); Query q = new Query(); - Table table = schema.getTables()[0]; + Table table = schema.getTables().get(0); q.select(new SelectItem("COUNT(*)", null)); q.from(table, "a"); q.where(table.getColumnByName("CREDITLIMIT"), OperatorType.GREATER_THAN_OR_EQUAL, queryParameter); @@ -338,7 +338,7 @@ public class JdbcDataContextTest extends JdbcTestCase { QueryParameter queryParameter = new QueryParameter(); Query q = new Query(); - Table table = schema.getTables()[0]; + Table table = schema.getTables().get(0); q.select(new SelectItem("COUNT(*)", null)); q.from(table, "a"); q.where(table.getColumnByName("CREDITLIMIT"), OperatorType.LESS_THAN_OR_EQUAL, queryParameter); @@ -388,7 +388,7 @@ public class JdbcDataContextTest extends JdbcTestCase { public void testGetSchemaNormalTableTypes() throws Exception { Connection connection = getTestDbConnection(); JdbcDataContext dc = new JdbcDataContext(connection, new TableType[] { TableType.TABLE, TableType.VIEW }, null); - Schema[] schemas = dc.getSchemas(); + Schema[] schemas = dc.getSchemas().toArray(new Schema[dc.getSchemas().size()]); assertEquals(2, schemas.length); assertEquals("Schema[name=INFORMATION_SCHEMA]", schemas[0].toString()); @@ -405,7 +405,6 @@ public class JdbcDataContextTest extends JdbcTestCase { TableType.GLOBAL_TEMPORARY }, null); Schema schema = dc.getDefaultSchema(); Table customersTable = schema.getTableByName("CUSTOMERS"); - Column[] columns = customersTable.getColumns(); assertEquals( "[Column[name=CUSTOMERNUMBER,columnNumber=0,type=INTEGER,nullable=false,nativeType=INTEGER,columnSize=0], " + "Column[name=CUSTOMERNAME,columnNumber=1,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=50], " @@ -423,7 +422,7 @@ public class JdbcDataContextTest extends JdbcTestCase { + "Column[name=SALESREPEMPLOYEENUMBER,columnNumber=11,type=INTEGER,nullable=true,nativeType=INTEGER," + "columnSize=0], " + "Column[name=CREDITLIMIT,columnNumber=12,type=NUMERIC,nullable=true,nativeType=NUMERIC,columnSize=17]]", - Arrays.toString(columns)); + Arrays.toString(customersTable.getColumns().toArray())); connection.close(); } @@ -432,18 +431,16 @@ public class JdbcDataContextTest extends JdbcTestCase { JdbcDataContext dc = new JdbcDataContext(connection, new TableType[] { TableType.TABLE }, null); Schema schema = dc.getDefaultSchema(); Table productsTable = schema.getTableByName("PRODUCTS"); - Relationship[] relations = productsTable.getRelationships(); /** * TODO: A single constraint now exists, create more ... */ assertEquals("[Relationship[primaryTable=PRODUCTS,primaryColumns=[PRODUCTCODE],foreignTable=ORDERFACT," - + "foreignColumns=[PRODUCTCODE]]]", Arrays.toString(relations)); + + "foreignColumns=[PRODUCTCODE]]]", Arrays.toString(productsTable.getRelationships().toArray())); - Column[] indexedColumns = productsTable.getIndexedColumns(); assertEquals( "[Column[name=PRODUCTCODE,columnNumber=0,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=50]]", - Arrays.toString(indexedColumns)); + Arrays.toString(productsTable.getIndexedColumns().toArray())); connection.close(); } @@ -494,7 +491,7 @@ public class JdbcDataContextTest extends JdbcTestCase { Schema schema = dc.getDefaultSchema(); Query q = new Query().setMaxRows(3); - Table table = schema.getTables()[0]; + Table table = schema.getTables().get(0); q.from(table, "a"); q.select(table.getColumns()); assertEquals("SELECT a.\"CUSTOMERNUMBER\", a.\"CUSTOMERNAME\", a.\"CONTACTLASTNAME\", a.\"CONTACTFIRSTNAME\", " @@ -540,7 +537,7 @@ public class JdbcDataContextTest extends JdbcTestCase { final DataContext dataContext1 = new JdbcDataContext(connection); final DataContext dataContext2 = new QueryPostprocessDataContext() { @Override - public DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) { + public DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) { Query q = new Query(); q.from(table, "a"); q.select(columns); @@ -578,7 +575,7 @@ public class JdbcDataContextTest extends JdbcTestCase { + "Column[name=SALESREPEMPLOYEENUMBER,columnNumber=11,type=INTEGER,nullable=true,nativeType=INTEGER," + "columnSize=0], " + "Column[name=CREDITLIMIT,columnNumber=12,type=NUMERIC,nullable=true,nativeType=NUMERIC,columnSize=17]]", - Arrays.toString(customersTable.getColumns())); + Arrays.toString(customersTable.getColumns().toArray())); assertEquals( "[Column[name=EMPLOYEENUMBER,columnNumber=0,type=INTEGER,nullable=false,nativeType=INTEGER,columnSize=0], " + "Column[name=LASTNAME,columnNumber=1,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=50], " @@ -588,7 +585,7 @@ public class JdbcDataContextTest extends JdbcTestCase { + "Column[name=OFFICECODE,columnNumber=5,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=20], " + "Column[name=REPORTSTO,columnNumber=6,type=INTEGER,nullable=true,nativeType=INTEGER,columnSize=0], " + "Column[name=JOBTITLE,columnNumber=7,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=50]]", - Arrays.toString(employeeTable.getColumns())); + Arrays.toString(employeeTable.getColumns().toArray())); Column employeeNumberColumn1 = customersTable.getColumnByName("SALESREPEMPLOYEENUMBER"); Column countryColumn = customersTable.getColumnByName("COUNTRY"); http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 dbade6a..fa1b064 100644 --- a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcDeleteBuilderTest.java +++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcDeleteBuilderTest.java @@ -50,7 +50,7 @@ public class JdbcDeleteBuilderTest extends JdbcTestCase { dataContext), true); assertEquals("[EMPLOYEENUMBER, LASTNAME, FIRSTNAME, EXTENSION, EMAIL, OFFICECODE, REPORTSTO, JOBTITLE]", - Arrays.toString(table.getColumnNames())); + Arrays.toString(table.getColumnNames().toArray())); updateBuilder.where("firstname").isNull().where("lastname").isNotNull(); assertEquals( @@ -64,7 +64,7 @@ public class JdbcDeleteBuilderTest extends JdbcTestCase { JdbcUpdateCallback updateCallback = new JdbcSimpleUpdateCallback(dataContext); assertEquals("[EMPLOYEENUMBER, LASTNAME, FIRSTNAME, EXTENSION, EMAIL, OFFICECODE, REPORTSTO, JOBTITLE]", - Arrays.toString(table.getColumnNames())); + Arrays.toString(table.getColumnNames().toArray())); JdbcDeleteBuilder updateBuilder = new JdbcDeleteBuilder(updateCallback, table, new DefaultQueryRewriter( dataContext), false); http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 8b56e05..2a29943 100644 --- a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcInsertBuilderTest.java +++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcInsertBuilderTest.java @@ -33,7 +33,7 @@ public class JdbcInsertBuilderTest extends JdbcTestCase { new DefaultQueryRewriter(dataContext)); assertEquals("[EMPLOYEENUMBER, LASTNAME, FIRSTNAME, EXTENSION, EMAIL, OFFICECODE, REPORTSTO, JOBTITLE]", - Arrays.toString(table.getColumnNames())); + Arrays.toString(table.getColumnNames().toArray())); insertBuilder.value("LASTNAME", "foo").value("firstname", "BAR"); assertEquals("INSERT INTO PUBLIC._EMPLOYEES_ (LASTNAME,FIRSTNAME) VALUES ('foo','BAR')", insertBuilder.createSqlStatement() @@ -53,7 +53,7 @@ public class JdbcInsertBuilderTest extends JdbcTestCase { new DefaultQueryRewriter(dataContext)); assertEquals("[EMPLOYEENUMBER, LASTNAME, FIRSTNAME, EXTENSION, EMAIL, OFFICECODE, REPORTSTO, JOBTITLE]", - Arrays.toString(table.getColumnNames())); + Arrays.toString(table.getColumnNames().toArray())); insertBuilder.value("LASTNAME", "foo").value("firstname", null); assertEquals("INSERT INTO PUBLIC._EMPLOYEES_ (LASTNAME,FIRSTNAME) VALUES ('foo',NULL)", insertBuilder.createSqlStatement() @@ -68,7 +68,7 @@ public class JdbcInsertBuilderTest extends JdbcTestCase { new DefaultQueryRewriter(dataContext)); assertEquals("[EMPLOYEENUMBER, LASTNAME, FIRSTNAME, EXTENSION, EMAIL, OFFICECODE, REPORTSTO, JOBTITLE]", - Arrays.toString(table.getColumnNames())); + Arrays.toString(table.getColumnNames().toArray())); insertBuilder.value("LASTNAME", "foo").value("firstname", "BAR"); assertEquals("INSERT INTO PUBLIC._EMPLOYEES_ (LASTNAME,FIRSTNAME) VALUES ('foo','BAR')", insertBuilder.createSqlStatement() http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 020b37d..8654679 100644 --- a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcSchemaTest.java +++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcSchemaTest.java @@ -54,7 +54,7 @@ public class JdbcSchemaTest extends JdbcTestCase { assertEquals( "[CUSTOMERS, CUSTOMER_W_TER, DEPARTMENT_MANAGERS, DIM_TIME, EMPLOYEES, OFFICES, ORDERDETAILS, ORDERFACT, ORDERS, PAYMENTS, PRODUCTS, QUADRANT_ACTUALS, TRIAL_BALANCE]", - Arrays.toString(schema.getTableNames())); + Arrays.toString(schema.getTableNames().toArray())); connection.close(); dataContext = null; @@ -72,14 +72,14 @@ public class JdbcSchemaTest extends JdbcTestCase { assertEquals( "[CUSTOMERS, CUSTOMER_W_TER, DEPARTMENT_MANAGERS, DIM_TIME, EMPLOYEES, OFFICES, ORDERDETAILS, ORDERFACT, ORDERS, PAYMENTS, PRODUCTS, QUADRANT_ACTUALS, TRIAL_BALANCE]", - Arrays.toString(schema.getTableNames())); + Arrays.toString(schema.getTableNames().toArray())); Table table = schema.getTableByName("CUSTOMERS"); assertTrue(table instanceof JdbcTable); assertNotNull(table); assertEquals( "[CUSTOMERNUMBER, CUSTOMERNAME, CONTACTLASTNAME, CONTACTFIRSTNAME, PHONE, ADDRESSLINE1, ADDRESSLINE2, CITY, STATE, POSTALCODE, COUNTRY, SALESREPEMPLOYEENUMBER, CREDITLIMIT]", - Arrays.toString(table.getColumnNames())); + Arrays.toString(table.getColumnNames().toArray())); } public void testToSerializableForm() throws Exception { @@ -92,10 +92,10 @@ public class JdbcSchemaTest extends JdbcTestCase { Table table = schema.getTableByName("CUSTOMERS"); assertEquals( "[CUSTOMERNUMBER, CUSTOMERNAME, CONTACTLASTNAME, CONTACTFIRSTNAME, PHONE, ADDRESSLINE1, ADDRESSLINE2, CITY, STATE, POSTALCODE, COUNTRY, SALESREPEMPLOYEENUMBER, CREDITLIMIT]", - Arrays.toString(table.getColumnNames())); + Arrays.toString(table.getColumnNames().toArray())); assertEquals( "[Relationship[primaryTable=PRODUCTS,primaryColumns=[PRODUCTCODE],foreignTable=ORDERFACT,foreignColumns=[PRODUCTCODE]]]", - Arrays.toString(schema.getRelationships())); + Arrays.toString(schema.getRelationships().toArray())); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 0f6d82d..aca3780 100644 --- a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcTestTemplates.java +++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcTestTemplates.java @@ -626,7 +626,7 @@ public class JdbcTestTemplates { final Table table = defaultSchema.getTableByName(testTableName); assertNotNull(table); - Column[] primaryKeys = table.getPrimaryKeys(); + Column[] primaryKeys = table.getPrimaryKeys().toArray(new Column[table.getPrimaryKeys().size()]); assertEquals(2, primaryKeys.length); assertEquals("mykey1", primaryKeys[0].getName().toLowerCase()); assertEquals("mykey2", primaryKeys[1].getName().toLowerCase()); http://git-wip-us.apache.org/repos/asf/metamodel/blob/2d156bcd/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 f44c77b..3c338ff 100644 --- a/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcUpdateBuilderTest.java +++ b/jdbc/src/test/java/org/apache/metamodel/jdbc/JdbcUpdateBuilderTest.java @@ -33,7 +33,7 @@ public class JdbcUpdateBuilderTest extends JdbcTestCase { dataContext), true); assertEquals("[EMPLOYEENUMBER, LASTNAME, FIRSTNAME, EXTENSION, EMAIL, OFFICECODE, REPORTSTO, JOBTITLE]", - Arrays.toString(table.getColumnNames())); + Arrays.toString(table.getColumnNames().toArray())); updateBuilder.value("LASTNAME", "foo").value("firstname", "BAR"); assertEquals("UPDATE PUBLIC._EMPLOYEES_ SET LASTNAME='foo',FIRSTNAME='BAR'", updateBuilder.createSqlStatement() @@ -58,7 +58,7 @@ public class JdbcUpdateBuilderTest extends JdbcTestCase { dataContext), true); assertEquals("[EMPLOYEENUMBER, LASTNAME, FIRSTNAME, EXTENSION, EMAIL, OFFICECODE, REPORTSTO, JOBTITLE]", - Arrays.toString(table.getColumnNames())); + Arrays.toString(table.getColumnNames().toArray())); updateBuilder.value("LASTNAME", "foo").value("firstname", null); assertEquals("UPDATE PUBLIC._EMPLOYEES_ SET LASTNAME='foo',FIRSTNAME=NULL", updateBuilder.createSqlStatement() @@ -71,7 +71,7 @@ public class JdbcUpdateBuilderTest extends JdbcTestCase { JdbcUpdateCallback updateCallback = new JdbcSimpleUpdateCallback(dataContext); assertEquals("[EMPLOYEENUMBER, LASTNAME, FIRSTNAME, EXTENSION, EMAIL, OFFICECODE, REPORTSTO, JOBTITLE]", - Arrays.toString(table.getColumnNames())); + Arrays.toString(table.getColumnNames().toArray())); JdbcUpdateBuilder updateBuilder = new JdbcUpdateBuilder(updateCallback, table, new DefaultQueryRewriter( dataContext), false); @@ -89,7 +89,7 @@ public class JdbcUpdateBuilderTest extends JdbcTestCase { dataContext), true); assertEquals("[EMPLOYEENUMBER, LASTNAME, FIRSTNAME, EXTENSION, EMAIL, OFFICECODE, REPORTSTO, JOBTITLE]", - Arrays.toString(table.getColumnNames())); + Arrays.toString(table.getColumnNames().toArray())); updateBuilder.value("LASTNAME", "foo").value("firstname", "BAR"); assertEquals("UPDATE PUBLIC._EMPLOYEES_ SET LASTNAME='foo',FIRSTNAME='BAR'", updateBuilder.createSqlStatement()