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 2016/05/16 03:54:17 UTC
[42/42] metamodel git commit: Merge branch 'master' into 5.x
Merge branch 'master' into 5.x
Conflicts:
CHANGES.md
cassandra/pom.xml
core/pom.xml
couchdb/pom.xml
csv/pom.xml
elasticsearch/common/pom.xml
elasticsearch/native/pom.xml
elasticsearch/native/src/main/java/org/apache/metamodel/elasticsearch/nativeclient/ElasticSearchDataContext.java
elasticsearch/pom.xml
elasticsearch/rest/pom.xml
elasticsearch/rest/src/main/java/org/apache/metamodel/elasticsearch/rest/ElasticSearchRestDataContext.java
excel/pom.xml
fixedwidth/pom.xml
full/pom.xml
hadoop/pom.xml
hbase/pom.xml
jdbc/pom.xml
json/pom.xml
mongodb/pom.xml
mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDataContext.java
neo4j/pom.xml
openoffice/pom.xml
pojo/pom.xml
pom.xml
salesforce/pom.xml
spring/pom.xml
sugarcrm/pom.xml
xml/pom.xml
Project: http://git-wip-us.apache.org/repos/asf/metamodel/repo
Commit: http://git-wip-us.apache.org/repos/asf/metamodel/commit/6d50f0e3
Tree: http://git-wip-us.apache.org/repos/asf/metamodel/tree/6d50f0e3
Diff: http://git-wip-us.apache.org/repos/asf/metamodel/diff/6d50f0e3
Branch: refs/heads/5.x
Commit: 6d50f0e310f58a7278ef0f4c3b3e090f22707fb6
Parents: 9522663 2e39b50
Author: kaspersorensen <i....@gmail.com>
Authored: Sun May 15 20:40:06 2016 -0700
Committer: kaspersorensen <i....@gmail.com>
Committed: Sun May 15 20:51:27 2016 -0700
----------------------------------------------------------------------
.gitignore | 2 +-
.travis.yml | 2 +-
CHANGES.md | 22 +
.../java/org/apache/metamodel/DataContext.java | 2 +-
.../apache/metamodel/convert/TypeConverter.java | 2 +-
.../org/apache/metamodel/data/DefaultRow.java | 2 +-
.../query/AverageAggregateFunction.java | 2 +
.../metamodel/query/CountAggregateFunction.java | 2 +
.../query/DefaultAggregateFunction.java | 2 +
.../metamodel/query/DefaultScalarFunction.java | 2 +
.../metamodel/query/FirstAggregateFunction.java | 2 +
.../apache/metamodel/query/FunctionType.java | 4 +-
.../metamodel/query/LastAggregateFunction.java | 2 +
.../metamodel/query/MapValueFunction.java | 2 +
.../metamodel/query/MaxAggregateFunction.java | 2 +
.../metamodel/query/MinAggregateFunction.java | 2 +
.../apache/metamodel/query/OperatorType.java | 6 +-
.../metamodel/query/OperatorTypeImpl.java | 6 +-
.../query/RandomAggregateFunction.java | 2 +
.../metamodel/query/SumAggregateFunction.java | 2 +
.../metamodel/query/ToBooleanFunction.java | 2 +
.../apache/metamodel/query/ToDateFunction.java | 2 +
.../metamodel/query/ToNumberFunction.java | 2 +
.../metamodel/query/ToStringFunction.java | 2 +
.../query/builder/SatisfiedQueryBuilder.java | 2 +-
.../apache/metamodel/schema/ColumnTypeImpl.java | 4 +-
.../org/apache/metamodel/schema/Schema.java | 2 +-
.../java/org/apache/metamodel/schema/Table.java | 2 +-
.../naming/AlphabeticColumnNamingStrategy.java | 43 ++
.../schema/naming/ColumnNamingContext.java | 52 ++
.../schema/naming/ColumnNamingContextImpl.java | 64 ++
.../schema/naming/ColumnNamingSession.java | 47 ++
.../schema/naming/ColumnNamingStrategies.java | 45 ++
.../schema/naming/ColumnNamingStrategy.java | 31 +
.../naming/CustomColumnNamingStrategy.java | 62 ++
...tingIntrinsicSwitchColumnNamingStrategy.java | 60 ++
.../naming/UniqueColumnNamingStrategy.java | 62 ++
.../org/apache/metamodel/util/FormatHelper.java | 2 +-
.../LegacyDeserializationObjectInputStream.java | 2 +-
.../metamodel/util/SimpleTableDefParser.java | 4 -
.../metamodel/query/parser/QueryParserTest.java | 7 +
.../metamodel/schema/ColumnTypeImplTest.java | 95 +++
.../apache/metamodel/schema/ColumnTypeTest.java | 92 ---
...IntrinsicSwitchColumnNamingStrategyTest.java | 51 ++
.../couchdb/CouchDbDataContextTest.java | 19 +-
.../apache/metamodel/csv/CsvConfiguration.java | 24 +-
.../java/org/apache/metamodel/csv/CsvTable.java | 26 +-
.../org/apache/metamodel/csv/CsvWriter.java | 37 +-
.../org/apache/metamodel/csv/CsvWriterTest.java | 43 ++
.../common/ElasticSearchUtils.java | 91 ++-
.../ElasticSearchCreateTableBuilder.java | 10 +-
.../nativeclient/ElasticSearchDataContext.java | 6 +-
.../nativeclient/NativeElasticSearchUtils.java | 3 +-
elasticsearch/rest/pom.xml | 2 +-
.../rest/ElasticSearchRestDataContext.java | 12 +-
.../JestElasticSearchCreateTableBuilder.java | 20 +-
.../rest/JestElasticSearchDataSet.java | 2 +-
.../rest/JestElasticSearchDeleteBuilder.java | 2 +-
.../rest/JestElasticSearchDropTableBuilder.java | 5 +-
.../rest/JestElasticSearchInsertBuilder.java | 33 +-
.../rest/JestElasticSearchUpdateCallback.java | 89 ++-
.../rest/JestElasticSearchUtils.java | 24 +-
.../rest/JestElasticSearchUtilsTest.java | 132 +++-
.../excel/DefaultSpreadsheetReaderDelegate.java | 45 +-
.../metamodel/excel/ExcelConfiguration.java | 31 +-
.../metamodel/excel/ExcelDataContext.java | 4 +-
.../excel/XlsxSpreadsheetReaderDelegate.java | 60 +-
.../metamodel/excel/ExcelDataContextTest.java | 4 +-
fixedwidth/pom.xml | 6 +
.../fixedwidth/FixedWidthColumnSpec.java | 45 ++
.../fixedwidth/FixedWidthConfiguration.java | 88 ++-
.../FixedWidthConfigurationReader.java | 180 ++++++
.../fixedwidth/FixedWidthDataContext.java | 26 +-
.../FixedWidthConfigurationReaderTest.java | 89 +++
.../src/test/resources/metadata_spec1/data.txt | 5 +
.../metadata_spec1/sas-formatfile-metadata.txt | 4 +
.../metadata_spec1/sas-input-metadata.txt | 19 +
full/pom.xml | 7 +-
.../apache/metamodel/DataContextFactory.java | 105 ++-
.../metamodel/jdbc/JdbcMetadataLoader.java | 19 +
.../jdbc/dialects/AbstractQueryRewriter.java | 1 -
.../jdbc/dialects/DB2QueryRewriter.java | 4 +-
.../dialects/DB2QueryRewriterTest.java | 6 +
mongodb/common/pom.xml | 67 ++
.../metamodel/mongodb/common/MongoDBUtils.java | 93 +++
.../mongodb/common/MongoDbTableDef.java | 46 ++
mongodb/mongo2/pom.xml | 70 ++
.../mongo2/DefaultWriteConcernAdvisor.java | 32 +
.../mongodb/mongo2/MongoDbDataContext.java | 530 ++++++++++++++++
.../mongodb/mongo2/MongoDbDataSet.java | 84 +++
.../mongodb/mongo2/MongoDbDeleteBuilder.java | 56 ++
.../mongodb/mongo2/MongoDbDropTableBuilder.java | 43 ++
.../mongodb/mongo2/MongoDbInsertionBuilder.java | 64 ++
.../mongo2/MongoDbTableCreationBuilder.java | 57 ++
.../mongodb/mongo2/MongoDbUpdateCallback.java | 115 ++++
.../mongo2/SimpleWriteConcernAdvisor.java | 50 ++
.../mongodb/mongo2/WriteConcernAdvisor.java | 35 +
.../metamodel/mongodb/mongo2/package-info.java | 23 +
.../mongodb/mongo2/MongoDbDataContextTest.java | 635 ++++++++++++++++++
.../mongodb/mongo2/MongoDbDataCopyer.java | 124 ++++
.../mongodb/mongo2/MongoDbTestCase.java | 111 ++++
mongodb/mongo3/pom.xml | 70 ++
.../mongo3/DefaultWriteConcernAdvisor.java | 32 +
.../mongodb/mongo3/MongoDbDataContext.java | 547 ++++++++++++++++
.../mongodb/mongo3/MongoDbDataSet.java | 84 +++
.../mongodb/mongo3/MongoDbDeleteBuilder.java | 53 ++
.../mongodb/mongo3/MongoDbDropTableBuilder.java | 43 ++
.../mongodb/mongo3/MongoDbInsertionBuilder.java | 63 ++
.../mongo3/MongoDbTableCreationBuilder.java | 57 ++
.../mongodb/mongo3/MongoDbUpdateCallback.java | 119 ++++
.../mongo3/SimpleWriteConcernAdvisor.java | 51 ++
.../mongodb/mongo3/WriteConcernAdvisor.java | 36 ++
.../metamodel/mongodb/mongo3/package-info.java | 23 +
.../mongodb/mongo3/MongoDbDataContextTest.java | 613 ++++++++++++++++++
.../mongodb/mongo3/MongoDbDataCopyer.java | 127 ++++
.../mongodb/mongo3/MongoDbTestCase.java | 111 ++++
mongodb/pom.xml | 45 +-
.../mongodb/DefaultWriteConcernAdvisor.java | 32 -
.../apache/metamodel/mongodb/MongoDBUtils.java | 77 ---
.../metamodel/mongodb/MongoDbDataContext.java | 529 ---------------
.../metamodel/mongodb/MongoDbDataSet.java | 83 ---
.../metamodel/mongodb/MongoDbDeleteBuilder.java | 56 --
.../mongodb/MongoDbDropTableBuilder.java | 43 --
.../mongodb/MongoDbInsertionBuilder.java | 64 --
.../mongodb/MongoDbTableCreationBuilder.java | 57 --
.../metamodel/mongodb/MongoDbTableDef.java | 46 --
.../mongodb/MongoDbUpdateCallback.java | 115 ----
.../mongodb/SimpleWriteConcernAdvisor.java | 50 --
.../metamodel/mongodb/WriteConcernAdvisor.java | 35 -
.../apache/metamodel/mongodb/package-info.java | 23 -
.../mongodb/MongoDbDataContextTest.java | 636 -------------------
.../metamodel/mongodb/MongoDbDataCopyer.java | 124 ----
.../metamodel/mongodb/MongoDbTestCase.java | 111 ----
.../metamodel/neo4j/Neo4jDataContext.java | 4 +-
.../metamodel/neo4j/Neo4jDataContextTest.java | 10 +
.../pojo/ObjectTableDataProviderTest.java | 2 +-
pom.xml | 8 +-
.../MongoDbDataContextFactoryBeanDelegate.java | 2 +-
.../apache/metamodel/xml/XmlDomDataContext.java | 4 +-
139 files changed, 6092 insertions(+), 2463 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/metamodel/blob/6d50f0e3/.travis.yml
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/metamodel/blob/6d50f0e3/CHANGES.md
----------------------------------------------------------------------
diff --cc CHANGES.md
index 388bfb1,66d1917..a103d91
--- a/CHANGES.md
+++ b/CHANGES.md
@@@ -1,8 -1,25 +1,30 @@@
+### Apache MetaModel 5.0
+
+ * [METAMODEL-6] - Added update summary containing information about changes on returning UpdateableDataContext.executeUpdate(..)
+ * [METAMODEL-222] - Added support for Java 8 lambdas, removed support for Java 7.
+
+ ### Apache MetaModel 4.5.3 (work in progress)
+
+ * [METAMODEL-235] - Fixed a bug related to handling of null or missing values in ElasticSearch using REST client.
+ * [METAMODEL-225] - Fixed support for nested objects and arrays in ElasticSearch using REST client.
+ * [METAMODEL-244] - Added ColumnNamingStrategies concept which allows custom column naming and column name overriding.
+ * [METAMODEL-242] - Fixed issue when de-serializing old enum-instances of FunctionType.
+ * [METAMODEL-247] - Added FixedWidthConfigurationReader for reading fixed width file metadata from external files.
+ * [METAMODEL-159] - DataContextFactory misses methods to create HBase and POJO data contexts.
+ * [METAMODEL-252] - Fixed a bug that caused JDBC updates to unnecessarily refresh schema objects.
+ * [METAMODEL-1082] - Improved performance of batch ElasticSearch operations by using bulk API.
+
+ ### Apache MetaModel 4.5.2
+
+ * [METAMODEL-236] - Made OperatorType and FunctionType Serializable to ensure that serialization of Query is possible.
+
+ ### Apache MetaModel 4.5.1
+
+ * [METAMODEL-227] - Fix for respecting CSV escape character also when no quote character is set.
+ * [METAMODEL-183] - MongoDB module split into three: common, Mongo2 and Mongo3 to allow use of either old or new MongoDB API.
+ * [METAMODEL-231] - Fixed a bug causing the Neo4j to represent the same table multiple times within a schema.
+ * [METAMODEL-228] - Fixed a bug causing Number.class to not be converted to ColumnType.NUMBER.
+
### Apache MetaModel 4.5.0
* [METAMODEL-212] - New module for ElasticSearch via REST client.
http://git-wip-us.apache.org/repos/asf/metamodel/blob/6d50f0e3/core/src/main/java/org/apache/metamodel/schema/naming/AlphabeticColumnNamingStrategy.java
----------------------------------------------------------------------
diff --cc core/src/main/java/org/apache/metamodel/schema/naming/AlphabeticColumnNamingStrategy.java
index 0000000,f6575c7..34498de
mode 000000,100644..100644
--- a/core/src/main/java/org/apache/metamodel/schema/naming/AlphabeticColumnNamingStrategy.java
+++ b/core/src/main/java/org/apache/metamodel/schema/naming/AlphabeticColumnNamingStrategy.java
@@@ -1,0 -1,43 +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.apache.metamodel.schema.naming;
-
-import org.apache.metamodel.util.AlphabeticSequence;
-
-public class AlphabeticColumnNamingStrategy implements ColumnNamingStrategy {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public ColumnNamingSession startColumnNamingSession() {
- return new ColumnNamingSession() {
- private final AlphabeticSequence seq = new AlphabeticSequence();
-
- @Override
- public String getNextColumnName(ColumnNamingContext ctx) {
- return seq.next();
- }
-
- @Override
- public void close() {
- }
- };
- }
-
-}
++/**
++ * Licensed to the Apache Software Foundation (ASF) under one
++ * or more contributor license agreements. See the NOTICE file
++ * distributed with this work for additional information
++ * regarding copyright ownership. The ASF licenses this file
++ * to you under the Apache License, Version 2.0 (the
++ * "License"); you may not use this file except in compliance
++ * with the License. You may obtain a copy of the License at
++ *
++ * http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing,
++ * software distributed under the License is distributed on an
++ * "AS IS" BASIS, WITHOUT WARRANTIES OR 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.schema.naming;
++
++import org.apache.metamodel.util.AlphabeticSequence;
++
++public class AlphabeticColumnNamingStrategy implements ColumnNamingStrategy {
++
++ private static final long serialVersionUID = 1L;
++
++ @Override
++ public ColumnNamingSession startColumnNamingSession() {
++ return new ColumnNamingSession() {
++ private final AlphabeticSequence seq = new AlphabeticSequence();
++
++ @Override
++ public String getNextColumnName(ColumnNamingContext ctx) {
++ return seq.next();
++ }
++
++ @Override
++ public void close() {
++ }
++ };
++ }
++
++}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/6d50f0e3/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingContext.java
----------------------------------------------------------------------
diff --cc core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingContext.java
index 0000000,b613913..b43ad87
mode 000000,100644..100644
--- a/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingContext.java
+++ b/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingContext.java
@@@ -1,0 -1,52 +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.apache.metamodel.schema.naming;
-
-import org.apache.metamodel.schema.Table;
-
-/**
- * Defines the context for naming a single column in a
- * {@link ColumnNamingStrategy} session.
- */
-public interface ColumnNamingContext {
-
- /**
- * Gets the index of the column being named.
- *
- * @return
- */
- public int getColumnIndex();
-
- /**
- * Gets the {@link Table} that the column is to pertain to. If the table is
- * not yet available then this may return null.
- *
- * @return
- */
- public Table getTable();
-
- /**
- * Gets the intrinsic column name, if this is defined in the datastore
- * itself. This may be in the form of a header or such. Sometimes intrinsic
- * column names exist only for some columns and sometimes there may be
- * duplicate names or other anomalies which are often discouraged.
- *
- * @return
- */
- public String getIntrinsicColumnName();
-}
++/**
++ * Licensed to the Apache Software Foundation (ASF) under one
++ * or more contributor license agreements. See the NOTICE file
++ * distributed with this work for additional information
++ * regarding copyright ownership. The ASF licenses this file
++ * to you under the Apache License, Version 2.0 (the
++ * "License"); you may not use this file except in compliance
++ * with the License. You may obtain a copy of the License at
++ *
++ * http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing,
++ * software distributed under the License is distributed on an
++ * "AS IS" BASIS, WITHOUT WARRANTIES OR 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.schema.naming;
++
++import org.apache.metamodel.schema.Table;
++
++/**
++ * Defines the context for naming a single column in a
++ * {@link ColumnNamingStrategy} session.
++ */
++public interface ColumnNamingContext {
++
++ /**
++ * Gets the index of the column being named.
++ *
++ * @return
++ */
++ public int getColumnIndex();
++
++ /**
++ * Gets the {@link Table} that the column is to pertain to. If the table is
++ * not yet available then this may return null.
++ *
++ * @return
++ */
++ public Table getTable();
++
++ /**
++ * Gets the intrinsic column name, if this is defined in the datastore
++ * itself. This may be in the form of a header or such. Sometimes intrinsic
++ * column names exist only for some columns and sometimes there may be
++ * duplicate names or other anomalies which are often discouraged.
++ *
++ * @return
++ */
++ public String getIntrinsicColumnName();
++}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/6d50f0e3/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingContextImpl.java
----------------------------------------------------------------------
diff --cc core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingContextImpl.java
index 0000000,cc7a24e..ec77440
mode 000000,100644..100644
--- a/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingContextImpl.java
+++ b/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingContextImpl.java
@@@ -1,0 -1,64 +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.apache.metamodel.schema.naming;
-
-import org.apache.metamodel.schema.Table;
-
-public class ColumnNamingContextImpl implements ColumnNamingContext {
-
- private final int columnIndex;
- private final Table table;
- private final String intrinsicColumnName;
-
- /**
- *
- * @param table
- * @param intrinsicColumnName
- * @param columnIndex
- */
- public ColumnNamingContextImpl(Table table, String intrinsicColumnName, int columnIndex) {
- this.table = table;
- this.intrinsicColumnName = intrinsicColumnName;
- this.columnIndex = columnIndex;
- }
-
- /**
- *
- * @param columnIndex
- */
- public ColumnNamingContextImpl(int columnIndex) {
- this(null, null, columnIndex);
- }
-
- @Override
- public int getColumnIndex() {
- return columnIndex;
- }
-
- @Override
- public Table getTable() {
- return table;
- }
-
- @Override
- public String getIntrinsicColumnName() {
- return intrinsicColumnName;
- }
-
-}
++/**
++ * Licensed to the Apache Software Foundation (ASF) under one
++ * or more contributor license agreements. See the NOTICE file
++ * distributed with this work for additional information
++ * regarding copyright ownership. The ASF licenses this file
++ * to you under the Apache License, Version 2.0 (the
++ * "License"); you may not use this file except in compliance
++ * with the License. You may obtain a copy of the License at
++ *
++ * http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing,
++ * software distributed under the License is distributed on an
++ * "AS IS" BASIS, WITHOUT WARRANTIES OR 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.schema.naming;
++
++import org.apache.metamodel.schema.Table;
++
++public class ColumnNamingContextImpl implements ColumnNamingContext {
++
++ private final int columnIndex;
++ private final Table table;
++ private final String intrinsicColumnName;
++
++ /**
++ *
++ * @param table
++ * @param intrinsicColumnName
++ * @param columnIndex
++ */
++ public ColumnNamingContextImpl(Table table, String intrinsicColumnName, int columnIndex) {
++ this.table = table;
++ this.intrinsicColumnName = intrinsicColumnName;
++ this.columnIndex = columnIndex;
++ }
++
++ /**
++ *
++ * @param columnIndex
++ */
++ public ColumnNamingContextImpl(int columnIndex) {
++ this(null, null, columnIndex);
++ }
++
++ @Override
++ public int getColumnIndex() {
++ return columnIndex;
++ }
++
++ @Override
++ public Table getTable() {
++ return table;
++ }
++
++ @Override
++ public String getIntrinsicColumnName() {
++ return intrinsicColumnName;
++ }
++
++}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/6d50f0e3/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingStrategies.java
----------------------------------------------------------------------
diff --cc core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingStrategies.java
index 0000000,0696376..f0da83a
mode 000000,100644..100644
--- a/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingStrategies.java
+++ b/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingStrategies.java
@@@ -1,0 -1,45 +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.apache.metamodel.schema.naming;
-
-import java.util.List;
-
-/**
- * Constructors and common utilities for {@link ColumnNamingStrategy} objects.
- */
-public class ColumnNamingStrategies {
-
- private static final DelegatingIntrinsicSwitchColumnNamingStrategy DEFAULT_STRATEGY = new DelegatingIntrinsicSwitchColumnNamingStrategy(
- new UniqueColumnNamingStrategy(), new AlphabeticColumnNamingStrategy());
-
- private ColumnNamingStrategies() {
- }
-
- public static ColumnNamingStrategy defaultStrategy() {
- return DEFAULT_STRATEGY;
- }
-
- public static ColumnNamingStrategy customNames(List<String> columnNames) {
- return new CustomColumnNamingStrategy(columnNames);
- }
-
- public static ColumnNamingStrategy customNames(String ... columnNames) {
- return new CustomColumnNamingStrategy(columnNames);
- }
-}
++/**
++ * Licensed to the Apache Software Foundation (ASF) under one
++ * or more contributor license agreements. See the NOTICE file
++ * distributed with this work for additional information
++ * regarding copyright ownership. The ASF licenses this file
++ * to you under the Apache License, Version 2.0 (the
++ * "License"); you may not use this file except in compliance
++ * with the License. You may obtain a copy of the License at
++ *
++ * http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing,
++ * software distributed under the License is distributed on an
++ * "AS IS" BASIS, WITHOUT WARRANTIES OR 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.schema.naming;
++
++import java.util.List;
++
++/**
++ * Constructors and common utilities for {@link ColumnNamingStrategy} objects.
++ */
++public class ColumnNamingStrategies {
++
++ private static final DelegatingIntrinsicSwitchColumnNamingStrategy DEFAULT_STRATEGY = new DelegatingIntrinsicSwitchColumnNamingStrategy(
++ new UniqueColumnNamingStrategy(), new AlphabeticColumnNamingStrategy());
++
++ private ColumnNamingStrategies() {
++ }
++
++ public static ColumnNamingStrategy defaultStrategy() {
++ return DEFAULT_STRATEGY;
++ }
++
++ public static ColumnNamingStrategy customNames(List<String> columnNames) {
++ return new CustomColumnNamingStrategy(columnNames);
++ }
++
++ public static ColumnNamingStrategy customNames(String ... columnNames) {
++ return new CustomColumnNamingStrategy(columnNames);
++ }
++}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/6d50f0e3/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingStrategy.java
----------------------------------------------------------------------
diff --cc core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingStrategy.java
index 0000000,6ccccbf..27e85ea
mode 000000,100644..100644
--- a/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingStrategy.java
+++ b/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingStrategy.java
@@@ -1,0 -1,31 +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.apache.metamodel.schema.naming;
-
-import java.io.Serializable;
-
-/**
- * A strategy that defines how columns are logically named. Such strategies are
- * mostly used when a particular datastore is not itself intrinsically
- * specifying the column name.
- */
-public interface ColumnNamingStrategy extends Serializable {
-
- public ColumnNamingSession startColumnNamingSession();
-}
++/**
++ * Licensed to the Apache Software Foundation (ASF) under one
++ * or more contributor license agreements. See the NOTICE file
++ * distributed with this work for additional information
++ * regarding copyright ownership. The ASF licenses this file
++ * to you under the Apache License, Version 2.0 (the
++ * "License"); you may not use this file except in compliance
++ * with the License. You may obtain a copy of the License at
++ *
++ * http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing,
++ * software distributed under the License is distributed on an
++ * "AS IS" BASIS, WITHOUT WARRANTIES OR 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.schema.naming;
++
++import java.io.Serializable;
++
++/**
++ * A strategy that defines how columns are logically named. Such strategies are
++ * mostly used when a particular datastore is not itself intrinsically
++ * specifying the column name.
++ */
++public interface ColumnNamingStrategy extends Serializable {
++
++ public ColumnNamingSession startColumnNamingSession();
++}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/6d50f0e3/core/src/main/java/org/apache/metamodel/schema/naming/CustomColumnNamingStrategy.java
----------------------------------------------------------------------
diff --cc core/src/main/java/org/apache/metamodel/schema/naming/CustomColumnNamingStrategy.java
index 0000000,e6cc706..39397d7
mode 000000,100644..100644
--- a/core/src/main/java/org/apache/metamodel/schema/naming/CustomColumnNamingStrategy.java
+++ b/core/src/main/java/org/apache/metamodel/schema/naming/CustomColumnNamingStrategy.java
@@@ -1,0 -1,62 +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.apache.metamodel.schema.naming;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * A {@link ColumnNamingStrategy} that allows the user to supply his own list of
- * custom column names.
- */
-public class CustomColumnNamingStrategy implements ColumnNamingStrategy {
-
- private static final long serialVersionUID = 1L;
-
- private final List<String> columnNames;
-
- public CustomColumnNamingStrategy(List<String> columnNames) {
- this.columnNames = columnNames;
- }
-
- public CustomColumnNamingStrategy(String... columnNames) {
- this(Arrays.asList(columnNames));
- }
-
- @Override
- public ColumnNamingSession startColumnNamingSession() {
- final Iterator<String> iterator = columnNames.iterator();
- return new ColumnNamingSession() {
-
- @Override
- public String getNextColumnName(ColumnNamingContext ctx) {
- if (iterator.hasNext()) {
- return iterator.next();
- }
- return null;
- }
-
- @Override
- public void close() {
- }
- };
- }
-
-}
++/**
++ * Licensed to the Apache Software Foundation (ASF) under one
++ * or more contributor license agreements. See the NOTICE file
++ * distributed with this work for additional information
++ * regarding copyright ownership. The ASF licenses this file
++ * to you under the Apache License, Version 2.0 (the
++ * "License"); you may not use this file except in compliance
++ * with the License. You may obtain a copy of the License at
++ *
++ * http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing,
++ * software distributed under the License is distributed on an
++ * "AS IS" BASIS, WITHOUT WARRANTIES OR 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.schema.naming;
++
++import java.util.Arrays;
++import java.util.Iterator;
++import java.util.List;
++
++/**
++ * A {@link ColumnNamingStrategy} that allows the user to supply his own list of
++ * custom column names.
++ */
++public class CustomColumnNamingStrategy implements ColumnNamingStrategy {
++
++ private static final long serialVersionUID = 1L;
++
++ private final List<String> columnNames;
++
++ public CustomColumnNamingStrategy(List<String> columnNames) {
++ this.columnNames = columnNames;
++ }
++
++ public CustomColumnNamingStrategy(String... columnNames) {
++ this(Arrays.asList(columnNames));
++ }
++
++ @Override
++ public ColumnNamingSession startColumnNamingSession() {
++ final Iterator<String> iterator = columnNames.iterator();
++ return new ColumnNamingSession() {
++
++ @Override
++ public String getNextColumnName(ColumnNamingContext ctx) {
++ if (iterator.hasNext()) {
++ return iterator.next();
++ }
++ return null;
++ }
++
++ @Override
++ public void close() {
++ }
++ };
++ }
++
++}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/6d50f0e3/core/src/main/java/org/apache/metamodel/schema/naming/DelegatingIntrinsicSwitchColumnNamingStrategy.java
----------------------------------------------------------------------
diff --cc core/src/main/java/org/apache/metamodel/schema/naming/DelegatingIntrinsicSwitchColumnNamingStrategy.java
index 0000000,e18cb3a..35a0f39
mode 000000,100644..100644
--- a/core/src/main/java/org/apache/metamodel/schema/naming/DelegatingIntrinsicSwitchColumnNamingStrategy.java
+++ b/core/src/main/java/org/apache/metamodel/schema/naming/DelegatingIntrinsicSwitchColumnNamingStrategy.java
@@@ -1,0 -1,60 +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.apache.metamodel.schema.naming;
-
-/**
- * A {@link ColumnNamingStrategy} that switches between two other
- * {@link ColumnNamingStrategy} delegates depending on the availability of a
- * intrinsic column name.
- */
-public class DelegatingIntrinsicSwitchColumnNamingStrategy implements ColumnNamingStrategy {
-
- private static final long serialVersionUID = 1L;
- private final ColumnNamingStrategy intrinsicStrategy;
- private final ColumnNamingStrategy nonIntrinsicStrategy;
-
- public DelegatingIntrinsicSwitchColumnNamingStrategy(ColumnNamingStrategy intrinsicStrategy,
- ColumnNamingStrategy nonIntrinsicStrategy) {
- this.intrinsicStrategy = intrinsicStrategy;
- this.nonIntrinsicStrategy = nonIntrinsicStrategy;
- }
-
- @Override
- public ColumnNamingSession startColumnNamingSession() {
- final ColumnNamingSession intrinsicSession = intrinsicStrategy.startColumnNamingSession();
- final ColumnNamingSession nonIntrinsicSession = nonIntrinsicStrategy.startColumnNamingSession();
- return new ColumnNamingSession() {
-
- @Override
- public String getNextColumnName(ColumnNamingContext ctx) {
- final String intrinsicColumnName = ctx.getIntrinsicColumnName();
- if (intrinsicColumnName == null || intrinsicColumnName.isEmpty()) {
- return nonIntrinsicSession.getNextColumnName(ctx);
- }
- return intrinsicSession.getNextColumnName(ctx);
- }
-
- @Override
- public void close() {
- intrinsicSession.close();
- nonIntrinsicSession.close();
- }
- };
- }
-}
++/**
++ * Licensed to the Apache Software Foundation (ASF) under one
++ * or more contributor license agreements. See the NOTICE file
++ * distributed with this work for additional information
++ * regarding copyright ownership. The ASF licenses this file
++ * to you under the Apache License, Version 2.0 (the
++ * "License"); you may not use this file except in compliance
++ * with the License. You may obtain a copy of the License at
++ *
++ * http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing,
++ * software distributed under the License is distributed on an
++ * "AS IS" BASIS, WITHOUT WARRANTIES OR 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.schema.naming;
++
++/**
++ * A {@link ColumnNamingStrategy} that switches between two other
++ * {@link ColumnNamingStrategy} delegates depending on the availability of a
++ * intrinsic column name.
++ */
++public class DelegatingIntrinsicSwitchColumnNamingStrategy implements ColumnNamingStrategy {
++
++ private static final long serialVersionUID = 1L;
++ private final ColumnNamingStrategy intrinsicStrategy;
++ private final ColumnNamingStrategy nonIntrinsicStrategy;
++
++ public DelegatingIntrinsicSwitchColumnNamingStrategy(ColumnNamingStrategy intrinsicStrategy,
++ ColumnNamingStrategy nonIntrinsicStrategy) {
++ this.intrinsicStrategy = intrinsicStrategy;
++ this.nonIntrinsicStrategy = nonIntrinsicStrategy;
++ }
++
++ @Override
++ public ColumnNamingSession startColumnNamingSession() {
++ final ColumnNamingSession intrinsicSession = intrinsicStrategy.startColumnNamingSession();
++ final ColumnNamingSession nonIntrinsicSession = nonIntrinsicStrategy.startColumnNamingSession();
++ return new ColumnNamingSession() {
++
++ @Override
++ public String getNextColumnName(ColumnNamingContext ctx) {
++ final String intrinsicColumnName = ctx.getIntrinsicColumnName();
++ if (intrinsicColumnName == null || intrinsicColumnName.isEmpty()) {
++ return nonIntrinsicSession.getNextColumnName(ctx);
++ }
++ return intrinsicSession.getNextColumnName(ctx);
++ }
++
++ @Override
++ public void close() {
++ intrinsicSession.close();
++ nonIntrinsicSession.close();
++ }
++ };
++ }
++}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/6d50f0e3/core/src/main/java/org/apache/metamodel/schema/naming/UniqueColumnNamingStrategy.java
----------------------------------------------------------------------
diff --cc core/src/main/java/org/apache/metamodel/schema/naming/UniqueColumnNamingStrategy.java
index 0000000,d4d21dd..9321998
mode 000000,100644..100644
--- a/core/src/main/java/org/apache/metamodel/schema/naming/UniqueColumnNamingStrategy.java
+++ b/core/src/main/java/org/apache/metamodel/schema/naming/UniqueColumnNamingStrategy.java
@@@ -1,0 -1,62 +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.apache.metamodel.schema.naming;
-
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * A {@link ColumnNamingStrategy} that uses the intrinsic column names, but
- * ensures that all column names are unique. When duplicate names are
- * encountered a number will be appended yielding column names like "name",
- * "name_2", "name_3" etc.
- */
-public class UniqueColumnNamingStrategy implements ColumnNamingStrategy {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public ColumnNamingSession startColumnNamingSession() {
- return new ColumnNamingSession() {
-
- private final Set<String> names = new HashSet<>();
-
- @Override
- public String getNextColumnName(ColumnNamingContext ctx) {
- final String intrinsicName = ctx.getIntrinsicColumnName();
- boolean unique = names.add(intrinsicName);
- if (unique) {
- return intrinsicName;
- }
-
- String newName = null;
- for (int i = 2; !unique; i++) {
- newName = intrinsicName + '_' + i;
- unique = names.add(newName);
- }
- return newName;
- }
-
- @Override
- public void close() {
- }
- };
- }
-
-}
++/**
++ * Licensed to the Apache Software Foundation (ASF) under one
++ * or more contributor license agreements. See the NOTICE file
++ * distributed with this work for additional information
++ * regarding copyright ownership. The ASF licenses this file
++ * to you under the Apache License, Version 2.0 (the
++ * "License"); you may not use this file except in compliance
++ * with the License. You may obtain a copy of the License at
++ *
++ * http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing,
++ * software distributed under the License is distributed on an
++ * "AS IS" BASIS, WITHOUT WARRANTIES OR 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.schema.naming;
++
++import java.util.HashSet;
++import java.util.Set;
++
++/**
++ * A {@link ColumnNamingStrategy} that uses the intrinsic column names, but
++ * ensures that all column names are unique. When duplicate names are
++ * encountered a number will be appended yielding column names like "name",
++ * "name_2", "name_3" etc.
++ */
++public class UniqueColumnNamingStrategy implements ColumnNamingStrategy {
++
++ private static final long serialVersionUID = 1L;
++
++ @Override
++ public ColumnNamingSession startColumnNamingSession() {
++ return new ColumnNamingSession() {
++
++ private final Set<String> names = new HashSet<>();
++
++ @Override
++ public String getNextColumnName(ColumnNamingContext ctx) {
++ final String intrinsicName = ctx.getIntrinsicColumnName();
++ boolean unique = names.add(intrinsicName);
++ if (unique) {
++ return intrinsicName;
++ }
++
++ String newName = null;
++ for (int i = 2; !unique; i++) {
++ newName = intrinsicName + '_' + i;
++ unique = names.add(newName);
++ }
++ return newName;
++ }
++
++ @Override
++ public void close() {
++ }
++ };
++ }
++
++}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/6d50f0e3/elasticsearch/native/src/main/java/org/apache/metamodel/elasticsearch/nativeclient/ElasticSearchDataContext.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/metamodel/blob/6d50f0e3/elasticsearch/rest/pom.xml
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/metamodel/blob/6d50f0e3/elasticsearch/rest/src/main/java/org/apache/metamodel/elasticsearch/rest/ElasticSearchRestDataContext.java
----------------------------------------------------------------------
diff --cc elasticsearch/rest/src/main/java/org/apache/metamodel/elasticsearch/rest/ElasticSearchRestDataContext.java
index e762050,c452d7b..e26646a
--- a/elasticsearch/rest/src/main/java/org/apache/metamodel/elasticsearch/rest/ElasticSearchRestDataContext.java
+++ b/elasticsearch/rest/src/main/java/org/apache/metamodel/elasticsearch/rest/ElasticSearchRestDataContext.java
@@@ -358,11 -354,11 +359,12 @@@ public class ElasticSearchRestDataConte
}
@Override
- public void executeUpdate(UpdateScript update) {
+ public UpdateSummary executeUpdate(UpdateScript update) {
- final JestElasticSearchUpdateCallback callback = new JestElasticSearchUpdateCallback(this);
+ final boolean isBatch = update instanceof BatchUpdateScript;
+ final JestElasticSearchUpdateCallback callback = new JestElasticSearchUpdateCallback(this, isBatch);
update.run(callback);
callback.onExecuteUpdateFinished();
+ return callback.getUpdateSummary();
}
/**
http://git-wip-us.apache.org/repos/asf/metamodel/blob/6d50f0e3/elasticsearch/rest/src/main/java/org/apache/metamodel/elasticsearch/rest/JestElasticSearchUpdateCallback.java
----------------------------------------------------------------------
diff --cc elasticsearch/rest/src/main/java/org/apache/metamodel/elasticsearch/rest/JestElasticSearchUpdateCallback.java
index ca2ed13,521955d..94e557c
--- a/elasticsearch/rest/src/main/java/org/apache/metamodel/elasticsearch/rest/JestElasticSearchUpdateCallback.java
+++ b/elasticsearch/rest/src/main/java/org/apache/metamodel/elasticsearch/rest/JestElasticSearchUpdateCallback.java
@@@ -1,84 -1,165 +1,165 @@@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR 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.elasticsearch.rest;
-
-import java.util.List;
-
-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.elasticsearch.action.bulk.BulkRequest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import io.searchbox.action.Action;
-import io.searchbox.action.BulkableAction;
-import io.searchbox.client.JestResult;
-import io.searchbox.core.Bulk;
-import io.searchbox.core.Bulk.Builder;
-import io.searchbox.core.BulkResult;
-import io.searchbox.core.BulkResult.BulkResultItem;
-import io.searchbox.indices.Refresh;
-
-/**
- * {@link UpdateCallback} implementation for
- * {@link ElasticSearchRestDataContext}.
- */
-final class JestElasticSearchUpdateCallback extends AbstractUpdateCallback {
-
- private static final Logger logger = LoggerFactory.getLogger(JestElasticSearchUpdateCallback.class);
-
- private static final int BULK_BUFFER_SIZE = 1000;
-
- private Bulk.Builder bulkBuilder;
- private int bulkActionCount = 0;
- private final boolean isBatch;
-
- public JestElasticSearchUpdateCallback(ElasticSearchRestDataContext dataContext, boolean isBatch) {
- super(dataContext);
- this.isBatch = isBatch;
- }
-
- private boolean isBatch() {
- return isBatch;
- }
-
- @Override
- public ElasticSearchRestDataContext getDataContext() {
- return (ElasticSearchRestDataContext) super.getDataContext();
- }
-
- @Override
- public TableCreationBuilder createTable(Schema schema, String name) throws IllegalArgumentException,
- IllegalStateException {
- return new JestElasticSearchCreateTableBuilder(this, schema, name);
- }
-
- @Override
- public boolean isDropTableSupported() {
- return true;
- }
-
- @Override
- public TableDropBuilder dropTable(Table table) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException {
- return new JestElasticSearchDropTableBuilder(this, table);
- }
-
- @Override
- public RowInsertionBuilder insertInto(Table table) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException {
- return new JestElasticSearchInsertBuilder(this, table);
- }
-
- @Override
- public boolean isDeleteSupported() {
- return true;
- }
-
- @Override
- public RowDeletionBuilder deleteFrom(Table table) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException {
- return new JestElasticSearchDeleteBuilder(this, table);
- }
-
- public void onExecuteUpdateFinished() {
- if (isBatch()) {
- flushBulkActions();
- }
-
- final String indexName = getDataContext().getIndexName();
- final Refresh refresh = new Refresh.Builder().addIndex(indexName).build();
-
- JestClientExecutor.execute(getDataContext().getElasticSearchClient(), refresh, false);
- }
-
- private void flushBulkActions() {
- if (bulkBuilder == null || bulkActionCount == 0) {
- // nothing to flush
- return;
- }
- final Bulk bulk = getBulkBuilder().build();
- logger.info("Flushing {} actions to ElasticSearch index {}", bulkActionCount, getDataContext().getIndexName());
- executeBlocking(bulk);
-
- bulkActionCount = 0;
- bulkBuilder = null;
- }
-
- public void execute(Action<?> action) {
- if (isBatch() && action instanceof BulkableAction) {
- final Bulk.Builder bulkBuilder = getBulkBuilder();
- bulkBuilder.addAction((BulkableAction<?>) action);
- bulkActionCount++;
- if (bulkActionCount == BULK_BUFFER_SIZE) {
- flushBulkActions();
- }
- } else {
- executeBlocking(action);
- }
- }
-
- private void executeBlocking(Action<?> action) {
- final JestResult result = JestClientExecutor.execute(getDataContext().getElasticSearchClient(), action);
- if (!result.isSucceeded()) {
- if (result instanceof BulkResult) {
- final List<BulkResultItem> failedItems = ((BulkResult) result).getFailedItems();
- for (int i = 0; i < failedItems.size(); i++) {
- final BulkResultItem failedItem = failedItems.get(i);
- logger.error("Bulk failed with item no. {} of {}: id={} op={} status={} error={}", i+1, failedItems.size(), failedItem.id, failedItem.operation, failedItem.status, failedItem.error);
- }
- }
- throw new MetaModelException(result.getResponseCode() + " - " + result.getErrorMessage());
- }
- }
-
- private Builder getBulkBuilder() {
- if (bulkBuilder == null) {
- bulkBuilder = new Bulk.Builder();
- bulkBuilder.defaultIndex(getDataContext().getIndexName());
- }
- return bulkBuilder;
- }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR 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.elasticsearch.rest;
+
- import io.searchbox.indices.Refresh;
++import java.util.List;
++
+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.elasticsearch.action.bulk.BulkRequest;
++import org.slf4j.Logger;
++import org.slf4j.LoggerFactory;
++
++import io.searchbox.action.Action;
++import io.searchbox.action.BulkableAction;
++import io.searchbox.client.JestResult;
++import io.searchbox.core.Bulk;
++import io.searchbox.core.Bulk.Builder;
++import io.searchbox.core.BulkResult;
++import io.searchbox.core.BulkResult.BulkResultItem;
++import io.searchbox.indices.Refresh;
+
+/**
- * {@link UpdateCallback} implementation for {@link ElasticSearchRestDataContext}.
++ * {@link UpdateCallback} implementation for
++ * {@link ElasticSearchRestDataContext}.
+ */
+final class JestElasticSearchUpdateCallback extends AbstractUpdateCallback {
- public JestElasticSearchUpdateCallback(ElasticSearchRestDataContext dataContext) {
++
++ private static final Logger logger = LoggerFactory.getLogger(JestElasticSearchUpdateCallback.class);
++
++ private static final int BULK_BUFFER_SIZE = 1000;
++
++ private Bulk.Builder bulkBuilder;
++ private int bulkActionCount = 0;
++ private final boolean isBatch;
++
++ public JestElasticSearchUpdateCallback(ElasticSearchRestDataContext dataContext, boolean isBatch) {
+ super(dataContext);
++ this.isBatch = isBatch;
++ }
++
++ private boolean isBatch() {
++ return isBatch;
+ }
+
+ @Override
+ public ElasticSearchRestDataContext getDataContext() {
+ return (ElasticSearchRestDataContext) super.getDataContext();
+ }
+
+ @Override
+ public TableCreationBuilder createTable(Schema schema, String name) throws IllegalArgumentException,
+ IllegalStateException {
+ return new JestElasticSearchCreateTableBuilder(this, schema, name);
+ }
+
+ @Override
+ public boolean isDropTableSupported() {
+ return true;
+ }
+
+ @Override
+ public TableDropBuilder dropTable(Table table) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException {
+ return new JestElasticSearchDropTableBuilder(this, table);
+ }
+
+ @Override
+ public RowInsertionBuilder insertInto(Table table) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException {
+ return new JestElasticSearchInsertBuilder(this, table);
+ }
+
+ @Override
+ public boolean isDeleteSupported() {
+ return true;
+ }
+
+ @Override
+ public RowDeletionBuilder deleteFrom(Table table) throws IllegalArgumentException, IllegalStateException,
+ UnsupportedOperationException {
+ return new JestElasticSearchDeleteBuilder(this, table);
+ }
+
+ public void onExecuteUpdateFinished() {
++ if (isBatch()) {
++ flushBulkActions();
++ }
++
+ final String indexName = getDataContext().getIndexName();
- Refresh refresh = new Refresh.Builder().addIndex(indexName).build();
++ final Refresh refresh = new Refresh.Builder().addIndex(indexName).build();
+
+ JestClientExecutor.execute(getDataContext().getElasticSearchClient(), refresh, false);
+ }
++
++ private void flushBulkActions() {
++ if (bulkBuilder == null || bulkActionCount == 0) {
++ // nothing to flush
++ return;
++ }
++ final Bulk bulk = getBulkBuilder().build();
++ logger.info("Flushing {} actions to ElasticSearch index {}", bulkActionCount, getDataContext().getIndexName());
++ executeBlocking(bulk);
++
++ bulkActionCount = 0;
++ bulkBuilder = null;
++ }
++
++ public void execute(Action<?> action) {
++ if (isBatch() && action instanceof BulkableAction) {
++ final Bulk.Builder bulkBuilder = getBulkBuilder();
++ bulkBuilder.addAction((BulkableAction<?>) action);
++ bulkActionCount++;
++ if (bulkActionCount == BULK_BUFFER_SIZE) {
++ flushBulkActions();
++ }
++ } else {
++ executeBlocking(action);
++ }
++ }
++
++ private void executeBlocking(Action<?> action) {
++ final JestResult result = JestClientExecutor.execute(getDataContext().getElasticSearchClient(), action);
++ if (!result.isSucceeded()) {
++ if (result instanceof BulkResult) {
++ final List<BulkResultItem> failedItems = ((BulkResult) result).getFailedItems();
++ for (int i = 0; i < failedItems.size(); i++) {
++ final BulkResultItem failedItem = failedItems.get(i);
++ logger.error("Bulk failed with item no. {} of {}: id={} op={} status={} error={}", i+1, failedItems.size(), failedItem.id, failedItem.operation, failedItem.status, failedItem.error);
++ }
++ }
++ throw new MetaModelException(result.getResponseCode() + " - " + result.getErrorMessage());
++ }
++ }
++
++ private Builder getBulkBuilder() {
++ if (bulkBuilder == null) {
++ bulkBuilder = new Bulk.Builder();
++ bulkBuilder.defaultIndex(getDataContext().getIndexName());
++ }
++ return bulkBuilder;
++ }
+}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/6d50f0e3/excel/src/main/java/org/apache/metamodel/excel/ExcelDataContext.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/metamodel/blob/6d50f0e3/fixedwidth/pom.xml
----------------------------------------------------------------------
diff --cc fixedwidth/pom.xml
index a304038,43e4021..7cae86b
--- a/fixedwidth/pom.xml
+++ b/fixedwidth/pom.xml
@@@ -1,46 -1,52 +1,52 @@@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<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">
- <parent>
- <artifactId>MetaModel</artifactId>
- <groupId>org.apache.metamodel</groupId>
- <version>4.5.3-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <artifactId>MetaModel-fixedwidth</artifactId>
- <name>MetaModel module for fixed width value files</name>
- <dependencies>
- <dependency>
- <groupId>org.apache.metamodel</groupId>
- <artifactId>MetaModel-core</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.metamodel</groupId>
- <artifactId>MetaModel-csv</artifactId>
- <version>${project.version}</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-nop</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<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">
+ <parent>
+ <artifactId>MetaModel</artifactId>
+ <groupId>org.apache.metamodel</groupId>
+ <version>5.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>MetaModel-fixedwidth</artifactId>
+ <name>MetaModel module for fixed width value files</name>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.metamodel</groupId>
+ <artifactId>MetaModel-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
++ <dependency>
++ <groupId>org.apache.metamodel</groupId>
++ <artifactId>MetaModel-csv</artifactId>
++ <version>${project.version}</version>
++ <optional>true</optional>
++ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-nop</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/metamodel/blob/6d50f0e3/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthColumnSpec.java
----------------------------------------------------------------------
diff --cc fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthColumnSpec.java
index 0000000,65ec219..f9d62df
mode 000000,100644..100644
--- a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthColumnSpec.java
+++ b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthColumnSpec.java
@@@ -1,0 -1,45 +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.apache.metamodel.fixedwidth;
-
-import org.apache.metamodel.util.HasName;
-
-/**
- * Represents the specification of a single column for a
- * {@link FixedWidthDataContext}.
- */
-public final class FixedWidthColumnSpec implements HasName {
-
- private final String name;
- private final int width;
-
- public FixedWidthColumnSpec(String name, int width) {
- this.name = name;
- this.width = width;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- public int getWidth() {
- return width;
- }
-}
++/**
++ * Licensed to the Apache Software Foundation (ASF) under one
++ * or more contributor license agreements. See the NOTICE file
++ * distributed with this work for additional information
++ * regarding copyright ownership. The ASF licenses this file
++ * to you under the Apache License, Version 2.0 (the
++ * "License"); you may not use this file except in compliance
++ * with the License. You may obtain a copy of the License at
++ *
++ * http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing,
++ * software distributed under the License is distributed on an
++ * "AS IS" BASIS, WITHOUT WARRANTIES OR 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.fixedwidth;
++
++import org.apache.metamodel.util.HasName;
++
++/**
++ * Represents the specification of a single column for a
++ * {@link FixedWidthDataContext}.
++ */
++public final class FixedWidthColumnSpec implements HasName {
++
++ private final String name;
++ private final int width;
++
++ public FixedWidthColumnSpec(String name, int width) {
++ this.name = name;
++ this.width = width;
++ }
++
++ @Override
++ public String getName() {
++ return name;
++ }
++
++ public int getWidth() {
++ return width;
++ }
++}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/6d50f0e3/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthConfiguration.java
----------------------------------------------------------------------
diff --cc fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthConfiguration.java
index 86a038a,2b2cae5..fe12177
--- a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthConfiguration.java
+++ b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthConfiguration.java
@@@ -1,149 -1,189 +1,189 @@@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR 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.fixedwidth;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.metamodel.data.DataSet;
-import org.apache.metamodel.schema.naming.ColumnNamingStrategies;
-import org.apache.metamodel.schema.naming.ColumnNamingStrategy;
-import org.apache.metamodel.util.BaseObject;
-import org.apache.metamodel.util.CollectionUtils;
-import org.apache.metamodel.util.FileHelper;
-import org.apache.metamodel.util.HasNameMapper;
-
-/**
- * Configuration of metadata about a fixed width values datacontext.
- */
-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;
- private final ColumnNamingStrategy columnNamingStrategy;
-
- 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.columnNamingStrategy = null;
- this.valueWidths = new int[0];
- }
-
- public FixedWidthConfiguration(int columnNameLineNumber, String encoding,
- int[] valueWidths, boolean failOnInconsistentLineWidth) {
- this(columnNameLineNumber, null, encoding, valueWidths, failOnInconsistentLineWidth);
- }
-
- public FixedWidthConfiguration(int columnNameLineNumber, ColumnNamingStrategy columnNamingStrategy, String encoding,
- int[] valueWidths, boolean failOnInconsistentLineWidth) {
- this.encoding = encoding;
- this.fixedValueWidth = -1;
- this.columnNameLineNumber = columnNameLineNumber;
- this.failOnInconsistentLineWidth = failOnInconsistentLineWidth;
- this.columnNamingStrategy = columnNamingStrategy;
- this.valueWidths = valueWidths;
- }
-
- public FixedWidthConfiguration(String encoding, List<FixedWidthColumnSpec> columnSpecs) {
- this(encoding, columnSpecs, false);
- }
-
- public FixedWidthConfiguration(String encoding, List<FixedWidthColumnSpec> columnSpecs,
- boolean failOnInconsistentLineWidth) {
- this.encoding = encoding;
- this.fixedValueWidth = -1;
- this.columnNameLineNumber = NO_COLUMN_NAME_LINE;
- this.columnNamingStrategy = ColumnNamingStrategies.customNames(CollectionUtils.map(columnSpecs,
- new HasNameMapper()));
- this.valueWidths = new int[columnSpecs.size()];
- for (int i = 0; i < valueWidths.length; i++) {
- valueWidths[i] = columnSpecs.get(i).getWidth();
- }
- this.failOnInconsistentLineWidth = failOnInconsistentLineWidth;
- }
-
- /**
- * 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 a {@link ColumnNamingStrategy} to use if needed.
- * @return
- */
- public ColumnNamingStrategy getColumnNamingStrategy() {
- if (columnNamingStrategy == null) {
- return ColumnNamingStrategies.defaultStrategy();
- }
- return columnNamingStrategy;
- }
-
- /**
- * 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];
- }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR 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.fixedwidth;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.metamodel.data.DataSet;
++import org.apache.metamodel.schema.naming.ColumnNamingStrategies;
++import org.apache.metamodel.schema.naming.ColumnNamingStrategy;
+import org.apache.metamodel.util.BaseObject;
++import org.apache.metamodel.util.CollectionUtils;
+import org.apache.metamodel.util.FileHelper;
++import org.apache.metamodel.util.HasNameMapper;
+
+/**
+ * Configuration of metadata about a fixed width values datacontext.
+ */
+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;
++ private final ColumnNamingStrategy columnNamingStrategy;
+
+ 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;
- }
-
- /**
++ 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.columnNamingStrategy = null;
++ this.valueWidths = new int[0];
++ }
++
++ public FixedWidthConfiguration(int columnNameLineNumber, String encoding,
++ int[] valueWidths, boolean failOnInconsistentLineWidth) {
++ this(columnNameLineNumber, null, encoding, valueWidths, failOnInconsistentLineWidth);
++ }
++
++ public FixedWidthConfiguration(int columnNameLineNumber, ColumnNamingStrategy columnNamingStrategy, String encoding,
++ int[] valueWidths, boolean failOnInconsistentLineWidth) {
++ this.encoding = encoding;
++ this.fixedValueWidth = -1;
++ this.columnNameLineNumber = columnNameLineNumber;
++ this.failOnInconsistentLineWidth = failOnInconsistentLineWidth;
++ this.columnNamingStrategy = columnNamingStrategy;
++ this.valueWidths = valueWidths;
++ }
++
++ public FixedWidthConfiguration(String encoding, List<FixedWidthColumnSpec> columnSpecs) {
++ this(encoding, columnSpecs, false);
++ }
++
++ public FixedWidthConfiguration(String encoding, List<FixedWidthColumnSpec> columnSpecs,
++ boolean failOnInconsistentLineWidth) {
++ this.encoding = encoding;
++ this.fixedValueWidth = -1;
++ this.columnNameLineNumber = NO_COLUMN_NAME_LINE;
++ this.columnNamingStrategy = ColumnNamingStrategies.customNames(CollectionUtils.map(columnSpecs,
++ new HasNameMapper()));
++ this.valueWidths = new int[columnSpecs.size()];
++ for (int i = 0; i < valueWidths.length; i++) {
++ valueWidths[i] = columnSpecs.get(i).getWidth();
++ }
++ this.failOnInconsistentLineWidth = failOnInconsistentLineWidth;
++ }
++
++ /**
+ * 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 a {@link ColumnNamingStrategy} to use if needed.
++ * @return
++ */
++ public ColumnNamingStrategy getColumnNamingStrategy() {
++ if (columnNamingStrategy == null) {
++ return ColumnNamingStrategies.defaultStrategy();
++ }
++ return columnNamingStrategy;
++ }
+
+ /**
+ * 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];
+ }
+}