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:03 UTC
[28/42] metamodel git commit: METAMODEL-244: Moved to pkg
org.apache.metamodel.schema.naming
METAMODEL-244: Moved to pkg org.apache.metamodel.schema.naming
Project: http://git-wip-us.apache.org/repos/asf/metamodel/repo
Commit: http://git-wip-us.apache.org/repos/asf/metamodel/commit/a2314f8d
Tree: http://git-wip-us.apache.org/repos/asf/metamodel/tree/a2314f8d
Diff: http://git-wip-us.apache.org/repos/asf/metamodel/diff/a2314f8d
Branch: refs/heads/5.x
Commit: a2314f8da2379f7c6da264b1f20071fa77ac832e
Parents: 0fcc4de
Author: Kasper S�rensen <i....@gmail.com>
Authored: Sun Apr 24 13:54:40 2016 -0700
Committer: Kasper S�rensen <i....@gmail.com>
Committed: Sun Apr 24 13:54:40 2016 -0700
----------------------------------------------------------------------
.../builder/AlphabeticColumnNamingStrategy.java | 43 -------------
.../schema/builder/ColumnNamingContext.java | 52 ----------------
.../schema/builder/ColumnNamingContextImpl.java | 64 --------------------
.../schema/builder/ColumnNamingSession.java | 47 --------------
.../schema/builder/ColumnNamingStrategy.java | 31 ----------
.../builder/DefaultColumnNamingStrategy.java | 33 ----------
...tingIntrinsicSwitchColumnNamingStrategy.java | 4 ++
.../builder/UniqueColumnNamingStrategy.java | 62 -------------------
.../naming/AlphabeticColumnNamingStrategy.java | 43 +++++++++++++
.../schema/naming/ColumnNamingContext.java | 52 ++++++++++++++++
.../schema/naming/ColumnNamingContextImpl.java | 64 ++++++++++++++++++++
.../schema/naming/ColumnNamingSession.java | 47 ++++++++++++++
.../schema/naming/ColumnNamingStrategy.java | 31 ++++++++++
.../naming/DefaultColumnNamingStrategy.java | 35 +++++++++++
.../naming/UniqueColumnNamingStrategy.java | 62 +++++++++++++++++++
.../DefaultColumnNamingStrategyTest.java | 46 --------------
.../naming/DefaultColumnNamingStrategyTest.java | 49 +++++++++++++++
.../apache/metamodel/csv/CsvConfiguration.java | 4 +-
.../java/org/apache/metamodel/csv/CsvTable.java | 6 +-
.../fixedwidth/FixedWidthConfiguration.java | 4 +-
.../fixedwidth/FixedWidthDataContext.java | 6 +-
21 files changed, 397 insertions(+), 388 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/metamodel/blob/a2314f8d/core/src/main/java/org/apache/metamodel/schema/builder/AlphabeticColumnNamingStrategy.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/builder/AlphabeticColumnNamingStrategy.java b/core/src/main/java/org/apache/metamodel/schema/builder/AlphabeticColumnNamingStrategy.java
deleted file mode 100644
index 91d1b85..0000000
--- a/core/src/main/java/org/apache/metamodel/schema/builder/AlphabeticColumnNamingStrategy.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.metamodel.schema.builder;
-
-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/a2314f8d/core/src/main/java/org/apache/metamodel/schema/builder/ColumnNamingContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/builder/ColumnNamingContext.java b/core/src/main/java/org/apache/metamodel/schema/builder/ColumnNamingContext.java
deleted file mode 100644
index 5bcfe56..0000000
--- a/core/src/main/java/org/apache/metamodel/schema/builder/ColumnNamingContext.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */package org.apache.metamodel.schema.builder;
-
-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/a2314f8d/core/src/main/java/org/apache/metamodel/schema/builder/ColumnNamingContextImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/builder/ColumnNamingContextImpl.java b/core/src/main/java/org/apache/metamodel/schema/builder/ColumnNamingContextImpl.java
deleted file mode 100644
index cd04f98..0000000
--- a/core/src/main/java/org/apache/metamodel/schema/builder/ColumnNamingContextImpl.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.metamodel.schema.builder;
-
-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/a2314f8d/core/src/main/java/org/apache/metamodel/schema/builder/ColumnNamingSession.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/builder/ColumnNamingSession.java b/core/src/main/java/org/apache/metamodel/schema/builder/ColumnNamingSession.java
deleted file mode 100644
index 2c6f7b2..0000000
--- a/core/src/main/java/org/apache/metamodel/schema/builder/ColumnNamingSession.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.metamodel.schema.builder;
-
-import java.io.Closeable;
-
-import org.apache.metamodel.schema.Column;
-import org.apache.metamodel.schema.Table;
-
-/**
- * Represents a 'session' in which a single {@link Table}'s {@link Column}s are
- * named.
- */
-public interface ColumnNamingSession extends Closeable {
-
- /**
- * Provides the name to apply for a given column.
- *
- * @param ctx
- * the context of the column naming taking place. This contains
- * column index, intrinsic name etc. if available.
- * @return the name to provide to the column.
- */
- public String getNextColumnName(ColumnNamingContext ctx);
-
- /**
- * Ends the column naming session.
- */
- @Override
- public void close();
-}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/a2314f8d/core/src/main/java/org/apache/metamodel/schema/builder/ColumnNamingStrategy.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/builder/ColumnNamingStrategy.java b/core/src/main/java/org/apache/metamodel/schema/builder/ColumnNamingStrategy.java
deleted file mode 100644
index 2219fb7..0000000
--- a/core/src/main/java/org/apache/metamodel/schema/builder/ColumnNamingStrategy.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.metamodel.schema.builder;
-
-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/a2314f8d/core/src/main/java/org/apache/metamodel/schema/builder/DefaultColumnNamingStrategy.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/builder/DefaultColumnNamingStrategy.java b/core/src/main/java/org/apache/metamodel/schema/builder/DefaultColumnNamingStrategy.java
deleted file mode 100644
index 2cc9fb7..0000000
--- a/core/src/main/java/org/apache/metamodel/schema/builder/DefaultColumnNamingStrategy.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.metamodel.schema.builder;
-
-/**
- * The default (in most cases) {@link ColumnNamingStrategy} to use when no other
- * strategy is specified.
- */
-public class DefaultColumnNamingStrategy extends DelegatingIntrinsicSwitchColumnNamingStrategy {
-
- private static final long serialVersionUID = 1L;
-
- public DefaultColumnNamingStrategy() {
- super(new UniqueColumnNamingStrategy(), new AlphabeticColumnNamingStrategy());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/a2314f8d/core/src/main/java/org/apache/metamodel/schema/builder/DelegatingIntrinsicSwitchColumnNamingStrategy.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/builder/DelegatingIntrinsicSwitchColumnNamingStrategy.java b/core/src/main/java/org/apache/metamodel/schema/builder/DelegatingIntrinsicSwitchColumnNamingStrategy.java
index 612f81d..4fa5d30 100644
--- a/core/src/main/java/org/apache/metamodel/schema/builder/DelegatingIntrinsicSwitchColumnNamingStrategy.java
+++ b/core/src/main/java/org/apache/metamodel/schema/builder/DelegatingIntrinsicSwitchColumnNamingStrategy.java
@@ -18,6 +18,10 @@
*/
package org.apache.metamodel.schema.builder;
+import org.apache.metamodel.schema.naming.ColumnNamingContext;
+import org.apache.metamodel.schema.naming.ColumnNamingSession;
+import org.apache.metamodel.schema.naming.ColumnNamingStrategy;
+
/**
* A {@link ColumnNamingStrategy} that switches between two other
* {@link ColumnNamingStrategy} delegates depending on the availability of a
http://git-wip-us.apache.org/repos/asf/metamodel/blob/a2314f8d/core/src/main/java/org/apache/metamodel/schema/builder/UniqueColumnNamingStrategy.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/builder/UniqueColumnNamingStrategy.java b/core/src/main/java/org/apache/metamodel/schema/builder/UniqueColumnNamingStrategy.java
deleted file mode 100644
index 17e7830..0000000
--- a/core/src/main/java/org/apache/metamodel/schema/builder/UniqueColumnNamingStrategy.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.metamodel.schema.builder;
-
-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",
- * "name1", "name2" 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/a2314f8d/core/src/main/java/org/apache/metamodel/schema/naming/AlphabeticColumnNamingStrategy.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/naming/AlphabeticColumnNamingStrategy.java b/core/src/main/java/org/apache/metamodel/schema/naming/AlphabeticColumnNamingStrategy.java
new file mode 100644
index 0000000..f6575c7
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/naming/AlphabeticColumnNamingStrategy.java
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.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/a2314f8d/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingContext.java b/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingContext.java
new file mode 100644
index 0000000..b613913
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingContext.java
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */package org.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/a2314f8d/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingContextImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingContextImpl.java b/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingContextImpl.java
new file mode 100644
index 0000000..cc7a24e
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingContextImpl.java
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.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/a2314f8d/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingSession.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingSession.java b/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingSession.java
new file mode 100644
index 0000000..85e5261
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingSession.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.metamodel.schema.naming;
+
+import java.io.Closeable;
+
+import org.apache.metamodel.schema.Column;
+import org.apache.metamodel.schema.Table;
+
+/**
+ * Represents a 'session' in which a single {@link Table}'s {@link Column}s are
+ * named.
+ */
+public interface ColumnNamingSession extends Closeable {
+
+ /**
+ * Provides the name to apply for a given column.
+ *
+ * @param ctx
+ * the context of the column naming taking place. This contains
+ * column index, intrinsic name etc. if available.
+ * @return the name to provide to the column.
+ */
+ public String getNextColumnName(ColumnNamingContext ctx);
+
+ /**
+ * Ends the column naming session.
+ */
+ @Override
+ public void close();
+}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/a2314f8d/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingStrategy.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingStrategy.java b/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingStrategy.java
new file mode 100644
index 0000000..6ccccbf
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/naming/ColumnNamingStrategy.java
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.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/a2314f8d/core/src/main/java/org/apache/metamodel/schema/naming/DefaultColumnNamingStrategy.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/naming/DefaultColumnNamingStrategy.java b/core/src/main/java/org/apache/metamodel/schema/naming/DefaultColumnNamingStrategy.java
new file mode 100644
index 0000000..f0bcb23
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/naming/DefaultColumnNamingStrategy.java
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.metamodel.schema.naming;
+
+import org.apache.metamodel.schema.builder.DelegatingIntrinsicSwitchColumnNamingStrategy;
+
+/**
+ * The default (in most cases) {@link ColumnNamingStrategy} to use when no other
+ * strategy is specified.
+ */
+public class DefaultColumnNamingStrategy extends DelegatingIntrinsicSwitchColumnNamingStrategy {
+
+ private static final long serialVersionUID = 1L;
+
+ public DefaultColumnNamingStrategy() {
+ super(new UniqueColumnNamingStrategy(), new AlphabeticColumnNamingStrategy());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/a2314f8d/core/src/main/java/org/apache/metamodel/schema/naming/UniqueColumnNamingStrategy.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/schema/naming/UniqueColumnNamingStrategy.java b/core/src/main/java/org/apache/metamodel/schema/naming/UniqueColumnNamingStrategy.java
new file mode 100644
index 0000000..e5288fe
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/schema/naming/UniqueColumnNamingStrategy.java
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.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",
+ * "name1", "name2" 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/a2314f8d/core/src/test/java/org/apache/metamodel/schema/builder/DefaultColumnNamingStrategyTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/builder/DefaultColumnNamingStrategyTest.java b/core/src/test/java/org/apache/metamodel/schema/builder/DefaultColumnNamingStrategyTest.java
deleted file mode 100644
index b903065..0000000
--- a/core/src/test/java/org/apache/metamodel/schema/builder/DefaultColumnNamingStrategyTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.metamodel.schema.builder;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-
-public class DefaultColumnNamingStrategyTest {
-
- private final DefaultColumnNamingStrategy namingStrategy = new DefaultColumnNamingStrategy();
-
- @Test
- public void testDuplicateColumnNames() throws Exception {
- try (final ColumnNamingSession session = namingStrategy.startColumnNamingSession()) {
- assertEquals("foo", session.getNextColumnName(new ColumnNamingContextImpl(null, "foo", 0)));
- assertEquals("bar", session.getNextColumnName(new ColumnNamingContextImpl(null, "bar", 1)));
- assertEquals("foo2", session.getNextColumnName(new ColumnNamingContextImpl(null, "foo", 2)));
- }
- }
-
- @Test
- public void testNoIntrinsicColumnNames() throws Exception {
- try (final ColumnNamingSession session = namingStrategy.startColumnNamingSession()) {
- assertEquals("A", session.getNextColumnName(new ColumnNamingContextImpl(null, "", 0)));
- assertEquals("B", session.getNextColumnName(new ColumnNamingContextImpl(null, null, 1)));
- assertEquals("C", session.getNextColumnName(new ColumnNamingContextImpl(null, "", 2)));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/a2314f8d/core/src/test/java/org/apache/metamodel/schema/naming/DefaultColumnNamingStrategyTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/metamodel/schema/naming/DefaultColumnNamingStrategyTest.java b/core/src/test/java/org/apache/metamodel/schema/naming/DefaultColumnNamingStrategyTest.java
new file mode 100644
index 0000000..c8c408b
--- /dev/null
+++ b/core/src/test/java/org/apache/metamodel/schema/naming/DefaultColumnNamingStrategyTest.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.metamodel.schema.naming;
+
+import static org.junit.Assert.*;
+
+import org.apache.metamodel.schema.naming.ColumnNamingContextImpl;
+import org.apache.metamodel.schema.naming.ColumnNamingSession;
+import org.apache.metamodel.schema.naming.DefaultColumnNamingStrategy;
+import org.junit.Test;
+
+public class DefaultColumnNamingStrategyTest {
+
+ private final DefaultColumnNamingStrategy namingStrategy = new DefaultColumnNamingStrategy();
+
+ @Test
+ public void testDuplicateColumnNames() throws Exception {
+ try (final ColumnNamingSession session = namingStrategy.startColumnNamingSession()) {
+ assertEquals("foo", session.getNextColumnName(new ColumnNamingContextImpl(null, "foo", 0)));
+ assertEquals("bar", session.getNextColumnName(new ColumnNamingContextImpl(null, "bar", 1)));
+ assertEquals("foo2", session.getNextColumnName(new ColumnNamingContextImpl(null, "foo", 2)));
+ }
+ }
+
+ @Test
+ public void testNoIntrinsicColumnNames() throws Exception {
+ try (final ColumnNamingSession session = namingStrategy.startColumnNamingSession()) {
+ assertEquals("A", session.getNextColumnName(new ColumnNamingContextImpl(null, "", 0)));
+ assertEquals("B", session.getNextColumnName(new ColumnNamingContextImpl(null, null, 1)));
+ assertEquals("C", session.getNextColumnName(new ColumnNamingContextImpl(null, "", 2)));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/a2314f8d/csv/src/main/java/org/apache/metamodel/csv/CsvConfiguration.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvConfiguration.java b/csv/src/main/java/org/apache/metamodel/csv/CsvConfiguration.java
index 4d1874c..dd1c8ac 100644
--- a/csv/src/main/java/org/apache/metamodel/csv/CsvConfiguration.java
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvConfiguration.java
@@ -21,8 +21,8 @@ package org.apache.metamodel.csv;
import java.io.Serializable;
import java.util.List;
-import org.apache.metamodel.schema.builder.ColumnNamingStrategy;
-import org.apache.metamodel.schema.builder.DefaultColumnNamingStrategy;
+import org.apache.metamodel.schema.naming.ColumnNamingStrategy;
+import org.apache.metamodel.schema.naming.DefaultColumnNamingStrategy;
import org.apache.metamodel.util.BaseObject;
import org.apache.metamodel.util.FileHelper;
http://git-wip-us.apache.org/repos/asf/metamodel/blob/a2314f8d/csv/src/main/java/org/apache/metamodel/csv/CsvTable.java
----------------------------------------------------------------------
diff --git a/csv/src/main/java/org/apache/metamodel/csv/CsvTable.java b/csv/src/main/java/org/apache/metamodel/csv/CsvTable.java
index e2a665d..334af7e 100644
--- a/csv/src/main/java/org/apache/metamodel/csv/CsvTable.java
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvTable.java
@@ -27,9 +27,9 @@ import org.apache.metamodel.schema.MutableColumn;
import org.apache.metamodel.schema.Relationship;
import org.apache.metamodel.schema.Schema;
import org.apache.metamodel.schema.TableType;
-import org.apache.metamodel.schema.builder.ColumnNamingContextImpl;
-import org.apache.metamodel.schema.builder.ColumnNamingSession;
-import org.apache.metamodel.schema.builder.ColumnNamingStrategy;
+import org.apache.metamodel.schema.naming.ColumnNamingContextImpl;
+import org.apache.metamodel.schema.naming.ColumnNamingSession;
+import org.apache.metamodel.schema.naming.ColumnNamingStrategy;
import org.apache.metamodel.util.FileHelper;
import au.com.bytecode.opencsv.CSVReader;
http://git-wip-us.apache.org/repos/asf/metamodel/blob/a2314f8d/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthConfiguration.java
----------------------------------------------------------------------
diff --git a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthConfiguration.java b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthConfiguration.java
index 9c0dd46..bbdd0ad 100644
--- a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthConfiguration.java
+++ b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthConfiguration.java
@@ -23,8 +23,8 @@ import java.util.Arrays;
import java.util.List;
import org.apache.metamodel.data.DataSet;
-import org.apache.metamodel.schema.builder.ColumnNamingStrategy;
-import org.apache.metamodel.schema.builder.DefaultColumnNamingStrategy;
+import org.apache.metamodel.schema.naming.ColumnNamingStrategy;
+import org.apache.metamodel.schema.naming.DefaultColumnNamingStrategy;
import org.apache.metamodel.util.BaseObject;
import org.apache.metamodel.util.FileHelper;
http://git-wip-us.apache.org/repos/asf/metamodel/blob/a2314f8d/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 25a8457..d28a0b2 100644
--- a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataContext.java
+++ b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataContext.java
@@ -33,9 +33,9 @@ import org.apache.metamodel.schema.MutableTable;
import org.apache.metamodel.schema.Schema;
import org.apache.metamodel.schema.Table;
import org.apache.metamodel.schema.TableType;
-import org.apache.metamodel.schema.builder.ColumnNamingContextImpl;
-import org.apache.metamodel.schema.builder.ColumnNamingSession;
-import org.apache.metamodel.schema.builder.ColumnNamingStrategy;
+import org.apache.metamodel.schema.naming.ColumnNamingContextImpl;
+import org.apache.metamodel.schema.naming.ColumnNamingSession;
+import org.apache.metamodel.schema.naming.ColumnNamingStrategy;
import org.apache.metamodel.util.FileHelper;
import org.apache.metamodel.util.FileResource;
import org.apache.metamodel.util.Resource;