Modify create_base_tables.sql -> version 5, create spatial database ( Add, "gtype" for geometry data ) create upgrade_base_004_005 -> to migrate of version 4 to version 5 modify statements.properties -> add SELECT and STORE SQL to GEOMETRY COLUM
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/796c598e Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/796c598e Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/796c598e Branch: refs/heads/MARMOTTA-584 Commit: 796c598e05c8480d5a5c73491b9d86ab1e83e262 Parents: 2e14b1a Author: cuent <[email protected]> Authored: Thu Jul 23 10:38:36 2015 -0500 Committer: cuent <[email protected]> Committed: Thu Jul 23 10:38:36 2015 -0500 ---------------------------------------------------------------------- .../org/apache/marmotta/kiwi/io/KiWiIO.java | 110 ++ .../kiwi/model/rdf/KiWiGeometryLiteral.java | 83 + .../kiwi/persistence/KiWiConnection.java | 1568 ++++++++++-------- .../marmotta/kiwi/persistence/KiWiDialect.java | 47 +- .../marmotta/kiwi/sail/KiWiValueFactory.java | 325 ++-- .../persistence/h2/upgrade_base_004_005.sql | 18 + .../persistence/mysql/create_base_tables.sql | 2 +- .../persistence/mysql/upgrade_base_004_005.sql | 18 + .../persistence/pgsql/create_base_tables.sql | 13 +- .../persistence/pgsql/statements.properties | 26 +- .../persistence/pgsql/upgrade_base_004_005.sql | 25 + .../apache/marmotta/kiwi/test/DialectTest.java | 2 +- 12 files changed, 1389 insertions(+), 848 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/marmotta/blob/796c598e/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/io/KiWiIO.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/io/KiWiIO.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/io/KiWiIO.java index 51254f6..b165ccf 100644 --- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/io/KiWiIO.java +++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/io/KiWiIO.java @@ -77,6 +77,7 @@ public class KiWiIO { private static final int TYPE_DOUBLE = 5; private static final int TYPE_INT = 6; private static final int TYPE_STRING = 7; + private static final int TYPE_GEOMETRY = 8; public static final int MODE_DEFAULT = 1; // no compression @@ -112,6 +113,7 @@ public class KiWiIO { classTable.put(KiWiDoubleLiteral.class, TYPE_DOUBLE); classTable.put(KiWiIntLiteral.class, TYPE_INT); classTable.put(KiWiStringLiteral.class, TYPE_STRING); + classTable.put(KiWiGeometryLiteral.class, TYPE_GEOMETRY); } @@ -168,6 +170,9 @@ public class KiWiIO { case TYPE_STRING: writeStringLiteral(output, (KiWiStringLiteral) node); break; + case TYPE_GEOMETRY: + writeGeometryLiteral(output, (KiWiGeometryLiteral) node); + break; default: throw new IllegalArgumentException("unknown KiWiNode type: "+node.getClass()); } @@ -202,6 +207,8 @@ public class KiWiIO { return readIntLiteral(input); case TYPE_STRING: return readStringLiteral(input); + case TYPE_GEOMETRY: + return readGeometryLiteral(input); default: throw new IllegalArgumentException("unknown KiWiNode type: "+type); } @@ -668,7 +675,110 @@ public class KiWiIO { } } +/** + * Efficiently serialize a KiWiGeometryLiteral to a DataOutput destination. + *add on MARMOTA 584 - GeoSPARQL Support + * @param out the destination + * @param literal the KiWiGeometryLiteral to serialize + * @throws IOException + */ + public static void writeGeometryLiteral(DataOutput out, KiWiGeometryLiteral literal) throws IOException { + if(literal == null) { + out.writeLong(-1L); + } else { + out.writeLong(literal.getId()); + writeContent(out, literal.getContent()); + if(langTable.containsKey(literal.getLanguage())) { + out.writeByte(langTable.get(literal.getLanguage())); + } else { + out.writeByte(LANG_UNKNOWN); + DataIO.writeString(out, literal.getLanguage()); + } + writeURI(out, literal.getType()); + out.writeLong(literal.getCreated().getTime()); + } + } + + + + /** + * Read a KiWiGeometyrLiteral serialized with writeGeometryLiteral from a DataInput source + * + * @param input the source + * @return the de-serialized KiWiStringLiteral + * @throws IOException + */ + public static KiWiGeometryLiteral readGeometryLiteral(DataInput input) throws IOException { + long id = input.readLong(); + + if(id == -1) { + return null; + } else { + String content = readContent(input); + byte langB = input.readByte(); + String lang; + + switch (langB) { + case LANG_EN: + lang = "en"; + break; + case LANG_DE: + lang = "de"; + break; + case LANG_FR: + lang = "fr"; + break; + case LANG_ES: + lang = "es"; + break; + case LANG_IT: + lang = "it"; + break; + case LANG_PT: + lang = "pt"; + break; + case LANG_NL: + lang = "nl"; + break; + case LANG_SV: + lang = "sv"; + break; + case LANG_NO: + lang = "no"; + break; + case LANG_FI: + lang = "fi"; + break; + case LANG_RU: + lang = "ru"; + break; + case LANG_DK: + lang = "dk"; + break; + case LANG_PL: + lang = "pl"; + break; + default: + lang = DataIO.readString(input); + } + + + + KiWiUriResource dtype = readURI(input); + + Date created = new Date(input.readLong()); + KiWiGeometryLiteral r = new KiWiGeometryLiteral(content, lang != null ? Locale.forLanguageTag(lang) : null, dtype, created); + r.setId(id); + + return r; + } + } + + + + + /** * Efficiently serialize a KiWiTriple to a DataOutput destination. * http://git-wip-us.apache.org/repos/asf/marmotta/blob/796c598e/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiGeometryLiteral.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiGeometryLiteral.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiGeometryLiteral.java new file mode 100644 index 0000000..63f14d5 --- /dev/null +++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiGeometryLiteral.java @@ -0,0 +1,83 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.marmotta.kiwi.model.rdf; + +import java.util.Date; +import java.util.Locale; + +/** + * A RDF geometry literal (of type geo:wktLiteral), possibly with language information. + * <p/> + * User: Xavier + */ +public class KiWiGeometryLiteral extends KiWiLiteral { + + private static final long serialVersionUID = 8761608427535540348L; + + protected String content; + + + public KiWiGeometryLiteral() { + super(); + } + + public KiWiGeometryLiteral(Date created) { + super(created); + } + + + public KiWiGeometryLiteral(String content) { + super(null, null); + this.content = content; + } + + public KiWiGeometryLiteral(String content, Date created) { + super(null, null, created); + this.content = content; + } + + + public KiWiGeometryLiteral(String content, Locale language, KiWiUriResource type) { + super(language, type); + this.content = content; + } + + public KiWiGeometryLiteral(String content, Locale language, KiWiUriResource type, Date created) { + super(language, type, created); + this.content = content; + } + + + /** + * Return the content of the literal, using the parametrized Java type + * @return + */ + public String getContent() { + return content; + } + + + /** + * Set the content of the literal to the content provided as parameter. + * @param content + */ + public void setContent(String content) { + this.content = content; + } + +}
