Refactoring.
Project: http://git-wip-us.apache.org/repos/asf/metamodel/repo Commit: http://git-wip-us.apache.org/repos/asf/metamodel/commit/b60601e7 Tree: http://git-wip-us.apache.org/repos/asf/metamodel/tree/b60601e7 Diff: http://git-wip-us.apache.org/repos/asf/metamodel/diff/b60601e7 Branch: refs/heads/master Commit: b60601e76e0218ae314f1dbf3e50c6a27a0877cf Parents: fdaaed0 Author: jakub <j.horci...@quadient.com> Authored: Tue May 22 12:22:26 2018 +0200 Committer: jakub <j.horci...@quadient.com> Committed: Tue May 22 12:22:26 2018 +0200 ---------------------------------------------------------------------- .../metamodel/neo4j/Neo4jDataContext.java | 110 +---------------- .../neo4j/utils/AbstractColumnTypeHandler.java | 33 ++++++ .../neo4j/utils/ArrayColumnTypeHandler.java | 39 +++++++ .../neo4j/utils/BooleanColumnTypeHandler.java | 39 +++++++ .../neo4j/utils/ColumnTypeHandler.java | 38 ++++++ .../neo4j/utils/ColumnTypeResolver.java | 117 +++++++++++++++++++ .../neo4j/utils/DoubleColumnTypeHandler.java | 39 +++++++ .../neo4j/utils/IntegerColumnTypeHandler.java | 39 +++++++ .../neo4j/utils/LongColumnTypeHandler.java | 39 +++++++ .../neo4j/utils/MapColumnTypeHandler.java | 39 +++++++ .../neo4j/utils/StringColumnTypeHandler.java | 39 +++++++ 11 files changed, 465 insertions(+), 106 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/metamodel/blob/b60601e7/neo4j/src/main/java/org/apache/metamodel/neo4j/Neo4jDataContext.java ---------------------------------------------------------------------- diff --git a/neo4j/src/main/java/org/apache/metamodel/neo4j/Neo4jDataContext.java b/neo4j/src/main/java/org/apache/metamodel/neo4j/Neo4jDataContext.java index 70686ef..83f01e7 100644 --- a/neo4j/src/main/java/org/apache/metamodel/neo4j/Neo4jDataContext.java +++ b/neo4j/src/main/java/org/apache/metamodel/neo4j/Neo4jDataContext.java @@ -19,8 +19,6 @@ package org.apache.metamodel.neo4j; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -35,10 +33,10 @@ import org.apache.metamodel.MetaModelException; import org.apache.metamodel.QueryPostprocessDataContext; import org.apache.metamodel.data.DataSet; import org.apache.metamodel.data.DocumentSource; +import org.apache.metamodel.neo4j.utils.ColumnTypeResolver; import org.apache.metamodel.query.FilterItem; import org.apache.metamodel.query.SelectItem; import org.apache.metamodel.schema.Column; -import org.apache.metamodel.schema.ColumnType; import org.apache.metamodel.schema.MutableSchema; import org.apache.metamodel.schema.MutableTable; import org.apache.metamodel.schema.Schema; @@ -194,9 +192,9 @@ public class Neo4jDataContext extends QueryPostprocessDataContext implements Dat // Do not add a table if label has no nodes (empty tables are considered non-existent) if (!nodesPerLabel.isEmpty()) { final String[] columnNames = propertiesPerLabel.toArray(new String[propertiesPerLabel.size()]); - final ColumnType[] columnTypes = guessColumnTypesFromValues(nodesPerLabel.get(0), - new ArrayList<>(Arrays.asList(columnNames))); - final SimpleTableDef tableDef = new SimpleTableDef(label, columnNames, columnTypes); + final ColumnTypeResolver columnTypeResolver = new ColumnTypeResolver(); + final SimpleTableDef tableDef = new SimpleTableDef(label, columnNames, + columnTypeResolver.getColumnTypes(nodesPerLabel.get(0), columnNames)); tableDefs.add(tableDef); } } @@ -236,106 +234,6 @@ public class Neo4jDataContext extends QueryPostprocessDataContext implements Dat return propertiesPerLabel; } - private ColumnType[] guessColumnTypesFromValues(final JSONObject jsonObject, final List<String> columnNames) { - final List<ColumnType> columnTypes = new ArrayList<>(); - - try { - fillColumnTypesFromMetadata(jsonObject, columnNames, columnTypes); - fillColumnTypesFromData(jsonObject, columnNames, columnTypes); - } catch (final JSONException e) { - // ignore missing data - } - - fillColumnTypesFromRemainingColumns(columnNames, columnTypes); - return columnTypes.toArray(new ColumnType[columnTypes.size()]); - } - - private void fillColumnTypesFromData(final JSONObject jsonObject, final List<String> columnNames, - final List<ColumnType> columnTypes) throws JSONException { - final String dataKey = "data"; - - if (jsonObject.has(dataKey)) { - final JSONObject data = jsonObject.getJSONObject(dataKey); - final Iterator keysIterator = data.keys(); - - while (keysIterator.hasNext()) { - final String key = (String) keysIterator.next(); - final ColumnType type = getTypeFromValue(data, key); - columnTypes.add(type); - removeIfAvailable(columnNames, key); - } - } - } - - private void fillColumnTypesFromMetadata(final JSONObject jsonObject, final List<String> columnNames, - final List<ColumnType> columnTypes) throws JSONException { - final String metadataKey = "metadata"; - - if (jsonObject.has(metadataKey)) { - final JSONObject metadata = jsonObject.getJSONObject(metadataKey); - - if (metadata.has("id")) { - columnTypes.add(ColumnType.BIGINT); - removeIfAvailable(columnNames, "_id"); - } - } - } - - private void fillColumnTypesFromRemainingColumns(final List<String> columnNames, - final List<ColumnType> columnTypes) { - for (final String remainingColumnName : columnNames) { - if (remainingColumnName.contains("rel_")) { - if (remainingColumnName.contains("#")) { - columnTypes.add(ColumnType.ARRAY); - } else { - columnTypes.add(ColumnType.BIGINT); - } - } else { - columnTypes.add(ColumnType.STRING); - } - } - } - - private void removeIfAvailable(final List<String> list, final String key) { - if (list.contains(key)) { - list.remove(key); - } - } - - private ColumnType getTypeFromValue(final JSONObject data, final String key) { - try { - data.getBoolean(key); - return ColumnType.BOOLEAN; - } catch (final JSONException e1) { - try { - data.getInt(key); - return ColumnType.INTEGER; - } catch (final JSONException e2) { - try { - data.getLong(key); - return ColumnType.BIGINT; - } catch (final JSONException e3) { - try { - data.getDouble(key); - return ColumnType.DOUBLE; - } catch (final JSONException e4) { - try { - data.getJSONArray(key); - return ColumnType.ARRAY; - } catch (final JSONException e5) { - try { - data.getJSONObject(key); - return ColumnType.MAP; - } catch (final JSONException e6) { - return ColumnType.STRING; - } - } - } - } - } - } - } - private List<String> getAllPropertiesPerRelationship(JSONObject relationship) { List<String> propertyNames = new ArrayList<String>(); try { http://git-wip-us.apache.org/repos/asf/metamodel/blob/b60601e7/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/AbstractColumnTypeHandler.java ---------------------------------------------------------------------- diff --git a/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/AbstractColumnTypeHandler.java b/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/AbstractColumnTypeHandler.java new file mode 100644 index 0000000..1198fe0 --- /dev/null +++ b/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/AbstractColumnTypeHandler.java @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.metamodel.neo4j.utils; + +import org.apache.metamodel.schema.ColumnType; +import org.json.JSONObject; + +public abstract class AbstractColumnTypeHandler implements ColumnTypeHandler { + protected ColumnTypeHandler _successor; + + @Override + public void setSuccessor(final ColumnTypeHandler successor) { + _successor = successor; + } + + public abstract ColumnType getTypeFromValue(final JSONObject data, final String key); +} http://git-wip-us.apache.org/repos/asf/metamodel/blob/b60601e7/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/ArrayColumnTypeHandler.java ---------------------------------------------------------------------- diff --git a/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/ArrayColumnTypeHandler.java b/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/ArrayColumnTypeHandler.java new file mode 100644 index 0000000..3d491f4 --- /dev/null +++ b/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/ArrayColumnTypeHandler.java @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.metamodel.neo4j.utils; + +import org.apache.metamodel.schema.ColumnType; +import org.json.JSONException; +import org.json.JSONObject; + +public class ArrayColumnTypeHandler extends AbstractColumnTypeHandler { + @Override + public ColumnType getTypeFromValue(final JSONObject data, final String key) { + try { + data.getJSONArray(key); + return ColumnType.ARRAY; + } catch (final JSONException e) { + if (_successor != null) { + return _successor.getTypeFromValue(data, key); + } else { + return ColumnType.STRING; + } + } + } +} http://git-wip-us.apache.org/repos/asf/metamodel/blob/b60601e7/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/BooleanColumnTypeHandler.java ---------------------------------------------------------------------- diff --git a/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/BooleanColumnTypeHandler.java b/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/BooleanColumnTypeHandler.java new file mode 100644 index 0000000..5aa4194 --- /dev/null +++ b/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/BooleanColumnTypeHandler.java @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.metamodel.neo4j.utils; + +import org.apache.metamodel.schema.ColumnType; +import org.json.JSONException; +import org.json.JSONObject; + +public class BooleanColumnTypeHandler extends AbstractColumnTypeHandler { + @Override + public ColumnType getTypeFromValue(final JSONObject data, final String key) { + try { + data.getBoolean(key); + return ColumnType.BOOLEAN; + } catch (final JSONException e) { + if (_successor != null) { + return _successor.getTypeFromValue(data, key); + } else { + return ColumnType.STRING; + } + } + } +} http://git-wip-us.apache.org/repos/asf/metamodel/blob/b60601e7/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/ColumnTypeHandler.java ---------------------------------------------------------------------- diff --git a/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/ColumnTypeHandler.java b/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/ColumnTypeHandler.java new file mode 100644 index 0000000..f673f4d --- /dev/null +++ b/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/ColumnTypeHandler.java @@ -0,0 +1,38 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.metamodel.neo4j.utils; + +import org.apache.metamodel.schema.ColumnType; +import org.json.JSONObject; + +public interface ColumnTypeHandler { + /** + * Sets the following node in the chain. + * @param successor + */ + void setSuccessor(final ColumnTypeHandler successor); + + /** + * Returns a column type based on the given value. + * @param data + * @param key + * @return ColumnType + */ + ColumnType getTypeFromValue(final JSONObject data, final String key); +} http://git-wip-us.apache.org/repos/asf/metamodel/blob/b60601e7/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/ColumnTypeResolver.java ---------------------------------------------------------------------- diff --git a/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/ColumnTypeResolver.java b/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/ColumnTypeResolver.java new file mode 100644 index 0000000..75677a2 --- /dev/null +++ b/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/ColumnTypeResolver.java @@ -0,0 +1,117 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.metamodel.neo4j.utils; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +import org.apache.metamodel.schema.ColumnType; +import org.json.JSONException; +import org.json.JSONObject; + +public class ColumnTypeResolver { + public ColumnType[] getColumnTypes(final JSONObject jsonObject, final String[] columnNamesArray) { + final List<String> columnNames = new ArrayList<>(Arrays.asList(columnNamesArray)); + final List<ColumnType> columnTypes = new ArrayList<>(); + + try { + fillColumnTypesFromMetadata(jsonObject, columnNames, columnTypes); + fillColumnTypesFromData(jsonObject, columnNames, columnTypes); + } catch (final JSONException e) { + // ignore missing data + } + + fillColumnTypesFromRemainingColumns(columnNames, columnTypes); + return columnTypes.toArray(new ColumnType[columnTypes.size()]); + } + + private void fillColumnTypesFromData(final JSONObject jsonObject, final List<String> columnNames, + final List<ColumnType> columnTypes) throws JSONException { + final String dataKey = "data"; + + if (jsonObject.has(dataKey)) { + final JSONObject data = jsonObject.getJSONObject(dataKey); + final Iterator keysIterator = data.keys(); + + while (keysIterator.hasNext()) { + final String key = (String) keysIterator.next(); + final ColumnType type = getTypeFromValue(data, key); + columnTypes.add(type); + removeIfAvailable(columnNames, key); + } + } + } + + private void fillColumnTypesFromMetadata(final JSONObject jsonObject, final List<String> columnNames, + final List<ColumnType> columnTypes) throws JSONException { + final String metadataKey = "metadata"; + + if (jsonObject.has(metadataKey)) { + final JSONObject metadata = jsonObject.getJSONObject(metadataKey); + + if (metadata.has("id")) { + columnTypes.add(ColumnType.BIGINT); + removeIfAvailable(columnNames, "_id"); + } + } + } + + private void fillColumnTypesFromRemainingColumns(final List<String> columnNames, + final List<ColumnType> columnTypes) { + for (final String remainingColumnName : columnNames) { + if (remainingColumnName.contains("rel_")) { + if (remainingColumnName.contains("#")) { + columnTypes.add(ColumnType.ARRAY); + } else { + columnTypes.add(ColumnType.BIGINT); + } + } else { + columnTypes.add(ColumnType.STRING); + } + } + } + + private void removeIfAvailable(final List<String> list, final String key) { + if (list.contains(key)) { + list.remove(key); + } + } + + private ColumnType getTypeFromValue(final JSONObject data, final String key) { + final BooleanColumnTypeHandler booleanHandler = new BooleanColumnTypeHandler(); + final IntegerColumnTypeHandler integerHandler = new IntegerColumnTypeHandler(); + final LongColumnTypeHandler longHandler = new LongColumnTypeHandler(); + final DoubleColumnTypeHandler doubleHandler = new DoubleColumnTypeHandler(); + final ArrayColumnTypeHandler arrayHandler = new ArrayColumnTypeHandler(); + final MapColumnTypeHandler mapHandler = new MapColumnTypeHandler(); + final StringColumnTypeHandler stringHandler = new StringColumnTypeHandler(); + + // chain of responsibility + booleanHandler.setSuccessor(integerHandler); + integerHandler.setSuccessor(longHandler); + longHandler.setSuccessor(doubleHandler); + doubleHandler.setSuccessor(arrayHandler); + arrayHandler.setSuccessor(mapHandler); + mapHandler.setSuccessor(stringHandler); + + return booleanHandler.getTypeFromValue(data, key); + } +} http://git-wip-us.apache.org/repos/asf/metamodel/blob/b60601e7/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/DoubleColumnTypeHandler.java ---------------------------------------------------------------------- diff --git a/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/DoubleColumnTypeHandler.java b/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/DoubleColumnTypeHandler.java new file mode 100644 index 0000000..35e9ef8 --- /dev/null +++ b/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/DoubleColumnTypeHandler.java @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.metamodel.neo4j.utils; + +import org.apache.metamodel.schema.ColumnType; +import org.json.JSONException; +import org.json.JSONObject; + +public class DoubleColumnTypeHandler extends AbstractColumnTypeHandler { + @Override + public ColumnType getTypeFromValue(final JSONObject data, final String key) { + try { + data.getDouble(key); + return ColumnType.DOUBLE; + } catch (final JSONException e) { + if (_successor != null) { + return _successor.getTypeFromValue(data, key); + } else { + return ColumnType.STRING; + } + } + } +} http://git-wip-us.apache.org/repos/asf/metamodel/blob/b60601e7/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/IntegerColumnTypeHandler.java ---------------------------------------------------------------------- diff --git a/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/IntegerColumnTypeHandler.java b/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/IntegerColumnTypeHandler.java new file mode 100644 index 0000000..9a48742 --- /dev/null +++ b/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/IntegerColumnTypeHandler.java @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.metamodel.neo4j.utils; + +import org.apache.metamodel.schema.ColumnType; +import org.json.JSONException; +import org.json.JSONObject; + +public class IntegerColumnTypeHandler extends AbstractColumnTypeHandler { + @Override + public ColumnType getTypeFromValue(final JSONObject data, final String key) { + try { + data.getInt(key); + return ColumnType.INTEGER; + } catch (final JSONException e) { + if (_successor != null) { + return _successor.getTypeFromValue(data, key); + } else { + return ColumnType.STRING; + } + } + } +} http://git-wip-us.apache.org/repos/asf/metamodel/blob/b60601e7/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/LongColumnTypeHandler.java ---------------------------------------------------------------------- diff --git a/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/LongColumnTypeHandler.java b/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/LongColumnTypeHandler.java new file mode 100644 index 0000000..939e355 --- /dev/null +++ b/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/LongColumnTypeHandler.java @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.metamodel.neo4j.utils; + +import org.apache.metamodel.schema.ColumnType; +import org.json.JSONException; +import org.json.JSONObject; + +public class LongColumnTypeHandler extends AbstractColumnTypeHandler { + @Override + public ColumnType getTypeFromValue(final JSONObject data, final String key) { + try { + data.getLong(key); + return ColumnType.BIGINT; + } catch (final JSONException e) { + if (_successor != null) { + return _successor.getTypeFromValue(data, key); + } else { + return ColumnType.STRING; + } + } + } +} http://git-wip-us.apache.org/repos/asf/metamodel/blob/b60601e7/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/MapColumnTypeHandler.java ---------------------------------------------------------------------- diff --git a/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/MapColumnTypeHandler.java b/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/MapColumnTypeHandler.java new file mode 100644 index 0000000..8151490 --- /dev/null +++ b/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/MapColumnTypeHandler.java @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.metamodel.neo4j.utils; + +import org.apache.metamodel.schema.ColumnType; +import org.json.JSONException; +import org.json.JSONObject; + +public class MapColumnTypeHandler extends AbstractColumnTypeHandler { + @Override + public ColumnType getTypeFromValue(final JSONObject data, final String key) { + try { + data.getJSONObject(key); + return ColumnType.MAP; + } catch (final JSONException e) { + if (_successor != null) { + return _successor.getTypeFromValue(data, key); + } else { + return ColumnType.STRING; + } + } + } +} http://git-wip-us.apache.org/repos/asf/metamodel/blob/b60601e7/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/StringColumnTypeHandler.java ---------------------------------------------------------------------- diff --git a/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/StringColumnTypeHandler.java b/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/StringColumnTypeHandler.java new file mode 100644 index 0000000..06afe36 --- /dev/null +++ b/neo4j/src/main/java/org/apache/metamodel/neo4j/utils/StringColumnTypeHandler.java @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.metamodel.neo4j.utils; + +import org.apache.metamodel.schema.ColumnType; +import org.json.JSONException; +import org.json.JSONObject; + +public class StringColumnTypeHandler extends AbstractColumnTypeHandler { + @Override + public ColumnType getTypeFromValue(final JSONObject data, final String key) { + try { + data.getString(key); + return ColumnType.STRING; + } catch (final JSONException e) { + if (_successor != null) { + return _successor.getTypeFromValue(data, key); + } else { + return ColumnType.STRING; + } + } + } +}