http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/query/strategy/ByteRange.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/ByteRange.java b/common/rya.api/src/main/java/mvm/rya/api/query/strategy/ByteRange.java deleted file mode 100644 index 6ebc722..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/ByteRange.java +++ /dev/null @@ -1,45 +0,0 @@ -package mvm.rya.api.query.strategy; - -/* - * 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. - */ - - - -/** - * Date: 1/10/13 - * Time: 12:47 PM - */ -public class ByteRange { - - private byte[] start; - private byte[] end; - - public ByteRange(byte[] start, byte[] end) { - this.start = start; - this.end = end; - } - - public byte[] getStart() { - return start; - } - - public byte[] getEnd() { - return end; - } -}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/query/strategy/TriplePatternStrategy.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/TriplePatternStrategy.java b/common/rya.api/src/main/java/mvm/rya/api/query/strategy/TriplePatternStrategy.java deleted file mode 100644 index 7b7eb39..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/TriplePatternStrategy.java +++ /dev/null @@ -1,49 +0,0 @@ -package mvm.rya.api.query.strategy; - -/* - * 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. - */ - - - -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaURI; -import mvm.rya.api.resolver.triple.TripleRowRegex; - -import java.io.IOException; -import java.util.Map; - -import static mvm.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; - -/** - * Date: 7/14/12 - * Time: 7:21 AM - */ -public interface TriplePatternStrategy { - - public Map.Entry<TABLE_LAYOUT, ByteRange> defineRange(RyaURI subject, RyaURI predicate, RyaType object, RyaURI context, - RdfCloudTripleStoreConfiguration conf) throws IOException; - - public TABLE_LAYOUT getLayout(); - - public boolean handles(RyaURI subject, RyaURI predicate, RyaType object, RyaURI context); - - public TripleRowRegex buildRegex(String subject, String predicate, String object, String context, byte[] objectTypeInfo); - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/AbstractHashedTriplePatternStrategy.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/AbstractHashedTriplePatternStrategy.java b/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/AbstractHashedTriplePatternStrategy.java deleted file mode 100644 index 9a1aef3..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/AbstractHashedTriplePatternStrategy.java +++ /dev/null @@ -1,90 +0,0 @@ -package mvm.rya.api.query.strategy.wholerow; -/* - * 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. - */ - -import com.google.common.base.Preconditions; -import mvm.rya.api.RdfCloudTripleStoreConstants; -import mvm.rya.api.query.strategy.AbstractTriplePatternStrategy; -import mvm.rya.api.query.strategy.TriplePatternStrategy; -import mvm.rya.api.resolver.triple.TripleRowRegex; - -import static mvm.rya.api.RdfCloudTripleStoreConstants.DELIM; -import static mvm.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM; - -public abstract class AbstractHashedTriplePatternStrategy extends AbstractTriplePatternStrategy implements TriplePatternStrategy { - public static final String HASHED_ALL_REGEX = "([0-9a-f]{32})\u0000"; - - public abstract RdfCloudTripleStoreConstants.TABLE_LAYOUT getLayout(); - - @Override - public TripleRowRegex buildRegex(String subject, String predicate, String object, String context, byte[] objectTypeInfo) { - RdfCloudTripleStoreConstants.TABLE_LAYOUT table_layout = getLayout(); - Preconditions.checkNotNull(table_layout); - - //O is not hashed so kick out to super - if(table_layout == RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP) { - return super.buildRegex(subject, predicate, object, context, objectTypeInfo); - } - - if (subject == null && predicate == null && object == null && context == null && objectTypeInfo == null) { - return null; //no regex - } - StringBuilder sb = new StringBuilder(); - String first = subject; - String second = predicate; - String third = object; - if (table_layout == RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO) { - first = predicate; - second = object; - third = subject; - } - - sb.append(HASHED_ALL_REGEX); - if (first != null) { - sb.append(first); - } else { - sb.append(ALL_REGEX); - } - sb.append(DELIM); - - if (second != null) { - sb.append(second); - } else { - sb.append(ALL_REGEX); - } - sb.append(DELIM); - - if (third != null) { - sb.append(third); - if (objectTypeInfo == null) { - sb.append(TYPE_DELIM); - sb.append(ALL_REGEX); - }else { - sb.append(new String(objectTypeInfo)); - } - }else { - sb.append(ALL_REGEX); - if (objectTypeInfo != null) { - sb.append(new String(objectTypeInfo)); - } - } - - return new TripleRowRegex(sb.toString(), (context != null) ? (context + ALL_REGEX) : null, null); - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/HashedPoWholeRowTriplePatternStrategy.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/HashedPoWholeRowTriplePatternStrategy.java b/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/HashedPoWholeRowTriplePatternStrategy.java deleted file mode 100644 index 1c2bc3c..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/HashedPoWholeRowTriplePatternStrategy.java +++ /dev/null @@ -1,136 +0,0 @@ -package mvm.rya.api.query.strategy.wholerow; - -/* - * 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. - */ - - - -import static mvm.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; -import static mvm.rya.api.RdfCloudTripleStoreConstants.LAST_BYTES; -import static mvm.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTES; - -import java.io.IOException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Map; - -import org.apache.commons.codec.binary.Hex; - -import com.google.common.primitives.Bytes; - -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.RdfCloudTripleStoreConstants; -import mvm.rya.api.RdfCloudTripleStoreUtils; -import mvm.rya.api.domain.RyaRange; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaURI; -import mvm.rya.api.query.strategy.ByteRange; -import mvm.rya.api.resolver.RyaContext; -import mvm.rya.api.resolver.RyaTypeResolverException; - -/** - * Date: 7/14/12 - * Time: 7:35 AM - */ -public class HashedPoWholeRowTriplePatternStrategy extends AbstractHashedTriplePatternStrategy { - - @Override - public RdfCloudTripleStoreConstants.TABLE_LAYOUT getLayout() { - return RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO; - } - - @Override - public Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, - ByteRange> defineRange(RyaURI subject, RyaURI predicate, RyaType object, - RyaURI context, RdfCloudTripleStoreConfiguration conf) throws IOException { - try { - //po(ng) - //po_r(s)(ng) - //p(ng) - //p_r(o)(ng) - //r(p)(ng) - if (!handles(subject, predicate, object, context)) return null; - - RyaContext ryaContext = RyaContext.getInstance(); - MessageDigest md = MessageDigest.getInstance("MD5"); - - - RdfCloudTripleStoreConstants.TABLE_LAYOUT table_layout = RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO; - byte[] start, stop; - if (object != null) { - if (object instanceof RyaRange) { - //p_r(o) - RyaRange rv = (RyaRange) object; - rv = ryaContext.transformRange(rv); - byte[] objStartBytes = ryaContext.serializeType(rv.getStart())[0]; - byte[] objEndBytes = ryaContext.serializeType(rv.getStop())[0]; - byte[] predBytes = predicate.getData().getBytes(); - byte[] predHash = Hex.encodeHexString(md.digest(predBytes)).getBytes(); - start = Bytes.concat(predHash, DELIM_BYTES, predBytes, DELIM_BYTES, objStartBytes); - stop = Bytes.concat(predHash, DELIM_BYTES, predBytes,DELIM_BYTES, objEndBytes, DELIM_BYTES, LAST_BYTES); - } else { - if (subject != null && subject instanceof RyaRange) { - //po_r(s) - RyaRange ru = (RyaRange) subject; - ru = ryaContext.transformRange(ru); - byte[] subjStartBytes = ru.getStart().getData().getBytes(); - byte[] subjStopBytes = ru.getStop().getData().getBytes(); - byte[] predBytes = predicate.getData().getBytes(); - byte[] predHash = Hex.encodeHexString(md.digest(predBytes)).getBytes(); - byte[] objBytes = ryaContext.serializeType(object)[0]; - start = Bytes.concat(predHash, DELIM_BYTES, predBytes, DELIM_BYTES, objBytes, DELIM_BYTES, subjStartBytes); - stop = Bytes.concat(predHash, DELIM_BYTES, predBytes, DELIM_BYTES, objBytes, DELIM_BYTES, subjStopBytes, TYPE_DELIM_BYTES, LAST_BYTES); - } else { - //po - //TODO: There must be a better way than creating multiple byte[] - byte[] predBytes = predicate.getData().getBytes(); - byte[] predHash = Hex.encodeHexString(md.digest(predBytes)).getBytes(); - byte[] objBytes = ryaContext.serializeType(object)[0]; - start = Bytes.concat(predHash, DELIM_BYTES, predBytes, DELIM_BYTES, objBytes, DELIM_BYTES); - stop = Bytes.concat(start, LAST_BYTES); - } - } - } else { - //p - byte[] predBytes = predicate.getData().getBytes(); - byte[] predHash = Hex.encodeHexString(md.digest(predBytes)).getBytes(); - start = Bytes.concat(predHash, DELIM_BYTES, predBytes, DELIM_BYTES); - stop = Bytes.concat(start, LAST_BYTES); - } - return new RdfCloudTripleStoreUtils.CustomEntry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, - ByteRange>(table_layout, new ByteRange(start, stop)); - } catch (RyaTypeResolverException e) { - throw new IOException(e); - } catch (NoSuchAlgorithmException e) { - throw new IOException(e); - } - } - - @Override - public boolean handles(RyaURI subject, RyaURI predicate, RyaType object, RyaURI context) { - //po(ng) - //p_r(o)(ng) - //po_r(s)(ng) - //p(ng) - //r(p)(ng) - if ((predicate == null) || (predicate instanceof RyaRange)) return false; - if (subject != null && !(subject instanceof RyaRange)) return false; - return subject == null || object != null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/HashedSpoWholeRowTriplePatternStrategy.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/HashedSpoWholeRowTriplePatternStrategy.java b/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/HashedSpoWholeRowTriplePatternStrategy.java deleted file mode 100644 index f801525..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/HashedSpoWholeRowTriplePatternStrategy.java +++ /dev/null @@ -1,142 +0,0 @@ -package mvm.rya.api.query.strategy.wholerow; - -import static mvm.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; -import static mvm.rya.api.RdfCloudTripleStoreConstants.LAST_BYTES; -import static mvm.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTES; - -import java.io.IOException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Map; - -import org.apache.commons.codec.binary.Hex; - -/* - * 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. - */ - - - -import com.google.common.primitives.Bytes; - -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; -import mvm.rya.api.RdfCloudTripleStoreUtils; -import mvm.rya.api.domain.RyaRange; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaURI; -import mvm.rya.api.domain.RyaURIRange; -import mvm.rya.api.query.strategy.ByteRange; -import mvm.rya.api.resolver.RyaContext; -import mvm.rya.api.resolver.RyaTypeResolverException; - -/** - * Date: 7/14/12 - * Time: 7:35 AM - */ -public class HashedSpoWholeRowTriplePatternStrategy extends AbstractHashedTriplePatternStrategy { - - - @Override - public TABLE_LAYOUT getLayout() { - return TABLE_LAYOUT.SPO; - } - - @Override - public Map.Entry<TABLE_LAYOUT, ByteRange> defineRange(RyaURI subject, RyaURI predicate, RyaType object, - RyaURI context, RdfCloudTripleStoreConfiguration conf) throws IOException { - try { - //spo(ng) - //sp(ng) - //s(ng) - //sp_r(o)(ng) - //s_r(p)(ng) - if (!handles(subject, predicate, object, context)) return null; - MessageDigest md = MessageDigest.getInstance("MD5"); - - RyaContext ryaContext = RyaContext.getInstance(); - - TABLE_LAYOUT table_layout = TABLE_LAYOUT.SPO; - byte[] start; - byte[] stop; - if (predicate != null) { - if (object != null) { - if (object instanceof RyaRange) { - //sp_r(o) - //range = sp_r(o.s)->sp_r(o.e) (remove last byte to remove type info) - RyaRange rv = (RyaRange) object; - rv = ryaContext.transformRange(rv); - byte[] objStartBytes = ryaContext.serializeType(rv.getStart())[0]; - byte[] objEndBytes = ryaContext.serializeType(rv.getStop())[0]; - byte[] subjBytes = subject.getData().getBytes(); - byte[] hashSubj = Hex.encodeHexString(md.digest(subjBytes)).getBytes(); - byte[] predBytes = predicate.getData().getBytes(); - start = Bytes.concat(hashSubj, DELIM_BYTES, subjBytes, DELIM_BYTES, predBytes, DELIM_BYTES, objStartBytes); - stop = Bytes.concat(hashSubj, DELIM_BYTES,subjBytes, DELIM_BYTES, predBytes, DELIM_BYTES, objEndBytes, DELIM_BYTES, LAST_BYTES); - } else { - //spo - //range = spo->spo (remove last byte to remove type info) - //TODO: There must be a better way than creating multiple byte[] - byte[] subjBytes = subject.getData().getBytes(); - byte[] hashSubj = Hex.encodeHexString(md.digest(subjBytes)).getBytes(); - byte[] objBytes = ryaContext.serializeType(object)[0]; - start = Bytes.concat(hashSubj, DELIM_BYTES, subjBytes, DELIM_BYTES, predicate.getData().getBytes(), DELIM_BYTES, objBytes, TYPE_DELIM_BYTES); - stop = Bytes.concat(start, LAST_BYTES); - } - } else if (predicate instanceof RyaRange) { - //s_r(p) - //range = s_r(p.s)->s_r(p.e) - RyaRange rv = (RyaRange) predicate; - rv = ryaContext.transformRange(rv); - byte[] subjBytes = subject.getData().getBytes(); - byte[] hashSubj = Hex.encodeHexString(md.digest(subjBytes)).getBytes(); - byte[] predStartBytes = rv.getStart().getData().getBytes(); - byte[] predStopBytes = rv.getStop().getData().getBytes(); - start = Bytes.concat(hashSubj, DELIM_BYTES, subjBytes, DELIM_BYTES, predStartBytes); - stop = Bytes.concat(hashSubj, DELIM_BYTES, subjBytes, DELIM_BYTES, predStopBytes, DELIM_BYTES, LAST_BYTES); - } else { - //sp - //range = sp - byte[] subjBytes = subject.getData().getBytes(); - byte[] hashSubj = Hex.encodeHexString(md.digest(subjBytes)).getBytes(); - start = Bytes.concat(hashSubj, DELIM_BYTES, subjBytes, DELIM_BYTES, predicate.getData().getBytes(), DELIM_BYTES); - stop = Bytes.concat(start, LAST_BYTES); - } - } else { - //s - //range = s - byte[] subjBytes = subject.getData().getBytes(); - byte[] hashSubj = Hex.encodeHexString(md.digest(subjBytes)).getBytes(); - start = Bytes.concat(hashSubj, DELIM_BYTES, subjBytes, DELIM_BYTES); - stop = Bytes.concat(start, LAST_BYTES); - } - return new RdfCloudTripleStoreUtils.CustomEntry<TABLE_LAYOUT, ByteRange>(table_layout, - new ByteRange(start, stop)); - } catch (RyaTypeResolverException e) { - throw new IOException(e); - } catch (NoSuchAlgorithmException e) { - throw new IOException(e); - } - } - - @Override - public boolean handles(RyaURI subject, RyaURI predicate, RyaType object, RyaURI context) { - //if subject is not null and not a range (if predicate is null then object must be null) - return (subject != null && !(subject instanceof RyaURIRange)) && !((predicate == null || predicate instanceof RyaURIRange) && (object != null)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/OspWholeRowTriplePatternStrategy.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/OspWholeRowTriplePatternStrategy.java b/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/OspWholeRowTriplePatternStrategy.java deleted file mode 100644 index 24f5852..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/OspWholeRowTriplePatternStrategy.java +++ /dev/null @@ -1,113 +0,0 @@ -package mvm.rya.api.query.strategy.wholerow; - -/* - * 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. - */ - - - -import static mvm.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; -import static mvm.rya.api.RdfCloudTripleStoreConstants.LAST_BYTES; - -import java.io.IOException; -import java.util.Map; - -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; -import mvm.rya.api.RdfCloudTripleStoreUtils; -import mvm.rya.api.domain.RyaRange; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaURI; -import mvm.rya.api.query.strategy.AbstractTriplePatternStrategy; -import mvm.rya.api.query.strategy.ByteRange; -import mvm.rya.api.resolver.RyaContext; -import mvm.rya.api.resolver.RyaTypeResolverException; - -import com.google.common.primitives.Bytes; - -/** - * Date: 7/14/12 - * Time: 7:35 AM - */ -public class OspWholeRowTriplePatternStrategy extends AbstractTriplePatternStrategy { - - @Override - public TABLE_LAYOUT getLayout() { - return TABLE_LAYOUT.OSP; - } - - @Override - public Map.Entry<TABLE_LAYOUT, - ByteRange> defineRange(RyaURI subject, RyaURI predicate, RyaType object, - RyaURI context, RdfCloudTripleStoreConfiguration conf) throws IOException { - try { - //os(ng) - //o_r(s)(ng) - //o(ng) - //r(o) - if (!handles(subject, predicate, object, context)) return null; - - RyaContext ryaContext = RyaContext.getInstance(); - - TABLE_LAYOUT table_layout = TABLE_LAYOUT.OSP; - byte[] start, stop; - if (subject != null) { - if (subject instanceof RyaRange) { - //o_r(s) - RyaRange ru = (RyaRange) subject; - ru = ryaContext.transformRange(ru); - byte[] subjStartBytes = ru.getStart().getData().getBytes(); - byte[] subjEndBytes = ru.getStop().getData().getBytes(); - byte[] objBytes = ryaContext.serializeType(object)[0]; - start = Bytes.concat(objBytes, DELIM_BYTES, subjStartBytes); - stop = Bytes.concat(objBytes, DELIM_BYTES, subjEndBytes, DELIM_BYTES, LAST_BYTES); - } else { - //os - byte[] objBytes = ryaContext.serializeType(object)[0]; - start = Bytes.concat(objBytes, DELIM_BYTES, subject.getData().getBytes(), DELIM_BYTES); - stop = Bytes.concat(start, LAST_BYTES); - } - } else { - if (object instanceof RyaRange) { - //r(o) - RyaRange rv = (RyaRange) object; - rv = ryaContext.transformRange(rv); - start = ryaContext.serializeType(rv.getStart())[0]; - stop = Bytes.concat(ryaContext.serializeType(rv.getStop())[0], DELIM_BYTES, LAST_BYTES); - } else { - //o - start = Bytes.concat(ryaContext.serializeType(object)[0], DELIM_BYTES); - stop = Bytes.concat(start, LAST_BYTES); - } - } - return new RdfCloudTripleStoreUtils.CustomEntry<TABLE_LAYOUT, - ByteRange>(table_layout, new ByteRange(start, stop)); - } catch (RyaTypeResolverException e) { - throw new IOException(e); - } - } - - @Override - public boolean handles(RyaURI subject, RyaURI predicate, RyaType object, RyaURI context) { - //os(ng) - //o_r(s)(ng) - //o(ng) - //r(o) - return object != null && (!(object instanceof RyaRange) || predicate == null && subject == null); - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/PoWholeRowTriplePatternStrategy.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/PoWholeRowTriplePatternStrategy.java b/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/PoWholeRowTriplePatternStrategy.java deleted file mode 100644 index 3f050e0..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/PoWholeRowTriplePatternStrategy.java +++ /dev/null @@ -1,128 +0,0 @@ -package mvm.rya.api.query.strategy.wholerow; - -/* - * 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. - */ - - - -import com.google.common.primitives.Bytes; -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.RdfCloudTripleStoreConstants; -import mvm.rya.api.RdfCloudTripleStoreUtils; -import mvm.rya.api.domain.RyaRange; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaURI; -import mvm.rya.api.query.strategy.AbstractTriplePatternStrategy; -import mvm.rya.api.query.strategy.ByteRange; -import mvm.rya.api.resolver.RyaContext; -import mvm.rya.api.resolver.RyaTypeResolverException; - -import java.io.IOException; -import java.util.Map; - -import static mvm.rya.api.RdfCloudTripleStoreConstants.*; - -/** - * Date: 7/14/12 - * Time: 7:35 AM - */ -public class PoWholeRowTriplePatternStrategy extends AbstractTriplePatternStrategy { - - @Override - public RdfCloudTripleStoreConstants.TABLE_LAYOUT getLayout() { - return RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO; - } - - @Override - public Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, - ByteRange> defineRange(RyaURI subject, RyaURI predicate, RyaType object, - RyaURI context, RdfCloudTripleStoreConfiguration conf) throws IOException { - try { - //po(ng) - //po_r(s)(ng) - //p(ng) - //p_r(o)(ng) - //r(p)(ng) - if (!handles(subject, predicate, object, context)) return null; - - RyaContext ryaContext = RyaContext.getInstance(); - - RdfCloudTripleStoreConstants.TABLE_LAYOUT table_layout = RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO; - byte[] start, stop; - if (object != null) { - if (object instanceof RyaRange) { - //p_r(o) - RyaRange rv = (RyaRange) object; - rv = ryaContext.transformRange(rv); - byte[] objStartBytes = ryaContext.serializeType(rv.getStart())[0]; - byte[] objEndBytes = ryaContext.serializeType(rv.getStop())[0]; - byte[] predBytes = predicate.getData().getBytes(); - start = Bytes.concat(predBytes, DELIM_BYTES, objStartBytes); - stop = Bytes.concat(predBytes, DELIM_BYTES, objEndBytes, DELIM_BYTES, LAST_BYTES); - } else { - if (subject != null && subject instanceof RyaRange) { - //po_r(s) - RyaRange ru = (RyaRange) subject; - ru = ryaContext.transformRange(ru); - byte[] subjStartBytes = ru.getStart().getData().getBytes(); - byte[] subjStopBytes = ru.getStop().getData().getBytes(); - byte[] predBytes = predicate.getData().getBytes(); - byte[] objBytes = ryaContext.serializeType(object)[0]; - start = Bytes.concat(predBytes, DELIM_BYTES, objBytes, DELIM_BYTES, subjStartBytes); - stop = Bytes.concat(predBytes, DELIM_BYTES, objBytes, DELIM_BYTES, subjStopBytes, TYPE_DELIM_BYTES, LAST_BYTES); - } else { - //po - //TODO: There must be a better way than creating multiple byte[] - byte[] objBytes = ryaContext.serializeType(object)[0]; - start = Bytes.concat(predicate.getData().getBytes(), DELIM_BYTES, objBytes, DELIM_BYTES); - stop = Bytes.concat(start, LAST_BYTES); - } - } - } else if (predicate instanceof RyaRange) { - //r(p) - RyaRange rv = (RyaRange) predicate; - rv = ryaContext.transformRange(rv); - start = rv.getStart().getData().getBytes(); - stop = Bytes.concat(rv.getStop().getData().getBytes(), DELIM_BYTES, LAST_BYTES); - } else { - //p - start = Bytes.concat(predicate.getData().getBytes(), DELIM_BYTES); - stop = Bytes.concat(start, LAST_BYTES); - } - return new RdfCloudTripleStoreUtils.CustomEntry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, - ByteRange>(table_layout, new ByteRange(start, stop)); - } catch (RyaTypeResolverException e) { - throw new IOException(e); - } - } - - @Override - public boolean handles(RyaURI subject, RyaURI predicate, RyaType object, RyaURI context) { - //po(ng) - //p_r(o)(ng) - //po_r(s)(ng) - //p(ng) - //r(p)(ng) - if (predicate == null) return false; - if (subject != null && !(subject instanceof RyaRange)) return false; - if (predicate instanceof RyaRange) - return object == null && subject == null; - return subject == null || object != null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/SpoWholeRowTriplePatternStrategy.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/SpoWholeRowTriplePatternStrategy.java b/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/SpoWholeRowTriplePatternStrategy.java deleted file mode 100644 index 2b91a4b..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/SpoWholeRowTriplePatternStrategy.java +++ /dev/null @@ -1,130 +0,0 @@ -package mvm.rya.api.query.strategy.wholerow; - -/* - * 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. - */ - - - -import com.google.common.primitives.Bytes; -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.RdfCloudTripleStoreUtils; -import mvm.rya.api.domain.RyaRange; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaURI; -import mvm.rya.api.domain.RyaURIRange; -import mvm.rya.api.query.strategy.AbstractTriplePatternStrategy; -import mvm.rya.api.query.strategy.ByteRange; -import mvm.rya.api.resolver.RyaContext; -import mvm.rya.api.resolver.RyaTypeResolverException; - -import java.io.IOException; -import java.util.Map; - -import static mvm.rya.api.RdfCloudTripleStoreConstants.*; - -/** - * Date: 7/14/12 - * Time: 7:35 AM - */ -public class SpoWholeRowTriplePatternStrategy extends AbstractTriplePatternStrategy { - - @Override - public TABLE_LAYOUT getLayout() { - return TABLE_LAYOUT.SPO; - } - - @Override - public Map.Entry<TABLE_LAYOUT, ByteRange> defineRange(RyaURI subject, RyaURI predicate, RyaType object, - RyaURI context, RdfCloudTripleStoreConfiguration conf) throws IOException { - try { - //spo(ng) - //sp(ng) - //s(ng) - //sp_r(o)(ng) - //s_r(p)(ng) - if (!handles(subject, predicate, object, context)) return null; - - RyaContext ryaContext = RyaContext.getInstance(); - - TABLE_LAYOUT table_layout = TABLE_LAYOUT.SPO; - byte[] start; - byte[] stop; - if (predicate != null) { - if (object != null) { - if (object instanceof RyaRange) { - //sp_r(o) - //range = sp_r(o.s)->sp_r(o.e) (remove last byte to remove type info) - RyaRange rv = (RyaRange) object; - rv = ryaContext.transformRange(rv); - byte[] objStartBytes = ryaContext.serializeType(rv.getStart())[0]; - byte[] objEndBytes = ryaContext.serializeType(rv.getStop())[0]; - byte[] subjBytes = subject.getData().getBytes(); - byte[] predBytes = predicate.getData().getBytes(); - start = Bytes.concat(subjBytes, DELIM_BYTES, predBytes, DELIM_BYTES, objStartBytes); - stop = Bytes.concat(subjBytes, DELIM_BYTES, predBytes, DELIM_BYTES, objEndBytes, DELIM_BYTES, LAST_BYTES); - } else { - //spo - //range = spo->spo (remove last byte to remove type info) - //TODO: There must be a better way than creating multiple byte[] - byte[] objBytes = ryaContext.serializeType(object)[0]; - start = Bytes.concat(subject.getData().getBytes(), DELIM_BYTES, predicate.getData().getBytes(), DELIM_BYTES, objBytes, TYPE_DELIM_BYTES); - stop = Bytes.concat(start, LAST_BYTES); - } - } else if (predicate instanceof RyaRange) { - //s_r(p) - //range = s_r(p.s)->s_r(p.e) - RyaRange rv = (RyaRange) predicate; - rv = ryaContext.transformRange(rv); - byte[] subjBytes = subject.getData().getBytes(); - byte[] predStartBytes = rv.getStart().getData().getBytes(); - byte[] predStopBytes = rv.getStop().getData().getBytes(); - start = Bytes.concat(subjBytes, DELIM_BYTES, predStartBytes); - stop = Bytes.concat(subjBytes, DELIM_BYTES, predStopBytes, DELIM_BYTES, LAST_BYTES); - } else { - //sp - //range = sp - start = Bytes.concat(subject.getData().getBytes(), DELIM_BYTES, predicate.getData().getBytes(), DELIM_BYTES); - stop = Bytes.concat(start, LAST_BYTES); - } - } else if (subject instanceof RyaRange) { - //r(s) - //range = r(s.s) -> r(s.e) - RyaRange ru = (RyaRange) subject; - ru = ryaContext.transformRange(ru); - start = ru.getStart().getData().getBytes(); - stop = Bytes.concat(ru.getStop().getData().getBytes(), DELIM_BYTES, LAST_BYTES); - } else { - //s - //range = s - start = Bytes.concat(subject.getData().getBytes(), DELIM_BYTES); - stop = Bytes.concat(start, LAST_BYTES); - } - return new RdfCloudTripleStoreUtils.CustomEntry<TABLE_LAYOUT, ByteRange>(table_layout, - new ByteRange(start, stop)); - } catch (RyaTypeResolverException e) { - throw new IOException(e); - } - } - - @Override - public boolean handles(RyaURI subject, RyaURI predicate, RyaType object, RyaURI context) { - //if subject is not null and (if predicate is null then object must be null) - return (subject != null && !(subject instanceof RyaURIRange && predicate != null)) && !((predicate == null || predicate instanceof RyaURIRange) && (object != null)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/resolver/CustomRyaTypeResolverMapping.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/resolver/CustomRyaTypeResolverMapping.java b/common/rya.api/src/main/java/mvm/rya/api/resolver/CustomRyaTypeResolverMapping.java deleted file mode 100644 index 3a6d125..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/resolver/CustomRyaTypeResolverMapping.java +++ /dev/null @@ -1,57 +0,0 @@ -package mvm.rya.api.resolver; - -/* - * 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. - */ - - - -import org.openrdf.model.URI; - -/** - * Date: 7/16/12 - * Time: 12:25 PM - */ -public class CustomRyaTypeResolverMapping extends RyaTypeResolverMapping { - - protected URI ryaDataType; - protected byte markerByte; - - public CustomRyaTypeResolverMapping() { - } - - public CustomRyaTypeResolverMapping(URI ryaDataType, byte markerByte) { - this(null, ryaDataType, markerByte); - } - - public CustomRyaTypeResolverMapping(RyaTypeResolver ryaTypeResolver, URI ryaDataType, byte markerByte) { - super(ryaTypeResolver); - this.ryaDataType = ryaDataType; - this.markerByte = markerByte; - } - - @Override - public URI getRyaDataType() { - return ryaDataType; - } - - @Override - byte getMarkerByte() { - return markerByte; - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/resolver/RdfToRyaConversions.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/resolver/RdfToRyaConversions.java b/common/rya.api/src/main/java/mvm/rya/api/resolver/RdfToRyaConversions.java deleted file mode 100644 index 485bf0d..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/resolver/RdfToRyaConversions.java +++ /dev/null @@ -1,93 +0,0 @@ -package mvm.rya.api.resolver; - -/* - * 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. - */ - - - -import mvm.rya.api.domain.*; -import org.openrdf.model.*; - -/** - * Date: 7/17/12 - * Time: 8:34 AM - */ -public class RdfToRyaConversions { - - public static RyaURI convertURI(URI uri) { - if (uri == null) return null; - if (uri instanceof RangeURI) { - RangeURI ruri = (RangeURI) uri; - return new RyaURIRange(convertURI(ruri.getStart()), convertURI(ruri.getEnd())); - } - return new RyaURI(uri.stringValue()); - } - - public static RyaType convertLiteral(Literal literal) { - if (literal == null) return null; - if (literal.getDatatype() != null) { - return new RyaType(literal.getDatatype(), literal.stringValue()); - } - //no language literal conversion yet - return new RyaType(literal.stringValue()); - } - - public static RyaType convertValue(Value value) { - if (value == null) return null; - //assuming either uri or Literal here - if(value instanceof Resource) { - return convertResource((Resource) value); - } - if (value instanceof Literal) { - return convertLiteral((Literal) value); - } - if (value instanceof RangeValue) { - RangeValue rv = (RangeValue) value; - if (rv.getStart() instanceof URI) { - return new RyaURIRange(convertURI((URI) rv.getStart()), convertURI((URI) rv.getEnd())); - } else { - //literal - return new RyaTypeRange(convertLiteral((Literal) rv.getStart()), convertLiteral((Literal) rv.getEnd())); - } - } - return null; - } - - public static RyaURI convertResource(Resource subject) { - if(subject == null) return null; - if (subject instanceof BNode) { - return new RyaURI(RyaSchema.BNODE_NAMESPACE + ((BNode) subject).getID()); - } - return convertURI((URI) subject); - } - - public static RyaStatement convertStatement(Statement statement) { - if (statement == null) return null; - Resource subject = statement.getSubject(); - URI predicate = statement.getPredicate(); - Value object = statement.getObject(); - Resource context = statement.getContext(); - return new RyaStatement( - convertResource(subject), - convertURI(predicate), - convertValue(object), - convertResource(context)); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaContext.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaContext.java b/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaContext.java deleted file mode 100644 index 2b97e1c..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaContext.java +++ /dev/null @@ -1,192 +0,0 @@ -package mvm.rya.api.resolver; - -/* - * 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. - */ - - - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import mvm.rya.api.domain.RyaRange; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.resolver.impl.BooleanRyaTypeResolver; -import mvm.rya.api.resolver.impl.ByteRyaTypeResolver; -import mvm.rya.api.resolver.impl.CustomDatatypeResolver; -import mvm.rya.api.resolver.impl.DateTimeRyaTypeResolver; -import mvm.rya.api.resolver.impl.DoubleRyaTypeResolver; -import mvm.rya.api.resolver.impl.FloatRyaTypeResolver; -import mvm.rya.api.resolver.impl.IntegerRyaTypeResolver; -import mvm.rya.api.resolver.impl.LongRyaTypeResolver; -import mvm.rya.api.resolver.impl.RyaTypeResolverImpl; -import mvm.rya.api.resolver.impl.RyaURIResolver; -import mvm.rya.api.resolver.impl.ServiceBackedRyaTypeResolverMappings; -import mvm.rya.api.resolver.impl.ShortRyaTypeResolver; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.openrdf.model.URI; -import org.openrdf.model.vocabulary.XMLSchema; - -/** - * Date: 7/16/12 - * Time: 12:04 PM - */ -public class RyaContext { - - public Log logger = LogFactory.getLog(RyaContext.class); - - private Map<URI, RyaTypeResolver> uriToResolver = new HashMap<URI, RyaTypeResolver>(); - private Map<Byte, RyaTypeResolver> byteToResolver = new HashMap<Byte, RyaTypeResolver>(); - private RyaTypeResolver defaultResolver = new CustomDatatypeResolver(); - - private RyaContext() { - //add default - addDefaultMappings(); - } - - protected void addDefaultMappings() { - if (logger.isDebugEnabled()) { - logger.debug("Adding default mappings"); - } - addRyaTypeResolverMapping(new RyaTypeResolverMapping(new RyaTypeResolverImpl())); // plain string - addRyaTypeResolverMapping(new RyaTypeResolverMapping(new RyaURIResolver())); // uri - addRyaTypeResolverMapping(new RyaTypeResolverMapping(new DateTimeRyaTypeResolver())); // dateTime - addRyaTypeResolverMapping(new RyaTypeResolverMapping(new DoubleRyaTypeResolver())); // double - addRyaTypeResolverMapping(new RyaTypeResolverMapping(new FloatRyaTypeResolver())); // float - addRyaTypeResolverMapping(new RyaTypeResolverMapping(new IntegerRyaTypeResolver())); // integer - addRyaTypeResolverMapping(new RyaTypeResolverMapping(new ShortRyaTypeResolver())); // short - addRyaTypeResolverMapping(new RyaTypeResolverMapping(new LongRyaTypeResolver())); // long - addRyaTypeResolverMapping(new RyaTypeResolverMapping(new BooleanRyaTypeResolver())); // boolean - addRyaTypeResolverMapping(new RyaTypeResolverMapping(new ByteRyaTypeResolver())); // byte - - //int is integer - uriToResolver.put(XMLSchema.INT, new IntegerRyaTypeResolver()); - - //add service loaded mappings - addRyaTypeResolverMappings(new ServiceBackedRyaTypeResolverMappings().getResolvers()); - } - - private static class RyaContextHolder { - public static final RyaContext INSTANCE = new RyaContext(); - } - - public synchronized static RyaContext getInstance() { - return RyaContextHolder.INSTANCE; - } - - - //need to go from datatype->resolver - public RyaTypeResolver retrieveResolver(URI datatype) { - RyaTypeResolver ryaTypeResolver = uriToResolver.get(datatype); - if (ryaTypeResolver == null) return defaultResolver; - return ryaTypeResolver; - } - - //need to go from byte->resolver - public RyaTypeResolver retrieveResolver(byte markerByte) { - RyaTypeResolver ryaTypeResolver = byteToResolver.get(markerByte); - if (ryaTypeResolver == null) return defaultResolver; - return ryaTypeResolver; - } - - public byte[] serialize(RyaType ryaType) throws RyaTypeResolverException { - RyaTypeResolver ryaTypeResolver = retrieveResolver(ryaType.getDataType()); - if (ryaTypeResolver != null) { - return ryaTypeResolver.serialize(ryaType); - } - return null; - } - - public byte[][] serializeType(RyaType ryaType) throws RyaTypeResolverException { - RyaTypeResolver ryaTypeResolver = retrieveResolver(ryaType.getDataType()); - if (ryaTypeResolver != null) { - return ryaTypeResolver.serializeType(ryaType); - } - return null; - } - - public RyaType deserialize(byte[] bytes) throws RyaTypeResolverException { - RyaTypeResolver ryaTypeResolver = retrieveResolver(bytes[bytes.length - 1]); - if (ryaTypeResolver != null) { - return ryaTypeResolver.deserialize(bytes); - } - return null; - } - - public void addRyaTypeResolverMapping(RyaTypeResolverMapping mapping) { - if (!uriToResolver.containsKey(mapping.getRyaDataType())) { - if (logger.isDebugEnabled()) { - logger.debug("addRyaTypeResolverMapping uri:[" + mapping.getRyaDataType() + "] byte:[" + mapping.getMarkerByte() + "] for mapping[" + mapping + "]"); - } - uriToResolver.put(mapping.getRyaDataType(), mapping.getRyaTypeResolver()); - byteToResolver.put(mapping.getMarkerByte(), mapping.getRyaTypeResolver()); - } else { - logger.warn("Could not add ryaType mapping because one already exists. uri:[" + mapping.getRyaDataType() + "] byte:[" + mapping.getMarkerByte() + "] for mapping[" + mapping + "]"); - } - } - - public void addRyaTypeResolverMappings(List<RyaTypeResolverMapping> mappings) { - for (RyaTypeResolverMapping mapping : mappings) { - addRyaTypeResolverMapping(mapping); - } - } - - public RyaTypeResolver removeRyaTypeResolver(URI dataType) { - RyaTypeResolver ryaTypeResolver = uriToResolver.remove(dataType); - if (ryaTypeResolver != null) { - if (logger.isDebugEnabled()) { - logger.debug("Removing ryaType Resolver uri[" + dataType + "] + [" + ryaTypeResolver + "]"); - } - byteToResolver.remove(ryaTypeResolver.getMarkerByte()); - return ryaTypeResolver; - } - return null; - } - - public RyaTypeResolver removeRyaTypeResolver(byte markerByte) { - RyaTypeResolver ryaTypeResolver = byteToResolver.remove(markerByte); - if (ryaTypeResolver != null) { - if (logger.isDebugEnabled()) { - logger.debug("Removing ryaType Resolver byte[" + markerByte + "] + [" + ryaTypeResolver + "]"); - } - uriToResolver.remove(ryaTypeResolver.getRyaDataType()); - return ryaTypeResolver; - } - return null; - } - - //transform range - public RyaRange transformRange(RyaRange range) throws RyaTypeResolverException { - RyaTypeResolver ryaTypeResolver = retrieveResolver(range.getStart().getDataType()); - if (ryaTypeResolver != null) { - return ryaTypeResolver.transformRange(range); - } - return range; - } - - public RyaTypeResolver getDefaultResolver() { - return defaultResolver; - } - - public void setDefaultResolver(RyaTypeResolver defaultResolver) { - this.defaultResolver = defaultResolver; - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaToRdfConversions.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaToRdfConversions.java b/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaToRdfConversions.java deleted file mode 100644 index a30d250..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaToRdfConversions.java +++ /dev/null @@ -1,75 +0,0 @@ -package mvm.rya.api.resolver; - -/* - * 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. - */ - - - -import mvm.rya.api.domain.RyaStatement; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaURI; -import org.openrdf.model.Literal; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.Value; -import org.openrdf.model.impl.ContextStatementImpl; -import org.openrdf.model.impl.LiteralImpl; -import org.openrdf.model.impl.StatementImpl; -import org.openrdf.model.impl.URIImpl; -import org.openrdf.model.vocabulary.XMLSchema; - -/** - * Date: 7/17/12 - * Time: 8:34 AM - */ -public class RyaToRdfConversions { - - public static URI convertURI(RyaURI uri) { - return new URIImpl(uri.getData()); - } - - public static Literal convertLiteral(RyaType literal) { - if (XMLSchema.STRING.equals(literal.getDataType())) { - return new LiteralImpl(literal.getData()); - } else { - return new LiteralImpl(literal.getData(), literal.getDataType()); - } - //TODO: No Language support yet - } - - public static Value convertValue(RyaType value) { - //assuming either uri or Literal here - return (value instanceof RyaURI) ? convertURI((RyaURI) value) : convertLiteral(value); - } - - public static Statement convertStatement(RyaStatement statement) { - assert statement != null; - if (statement.getContext() != null) { - return new ContextStatementImpl(convertURI(statement.getSubject()), - convertURI(statement.getPredicate()), - convertValue(statement.getObject()), - convertURI(statement.getContext())); - } else { - return new StatementImpl(convertURI(statement.getSubject()), - convertURI(statement.getPredicate()), - convertValue(statement.getObject())); - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaTripleContext.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaTripleContext.java b/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaTripleContext.java deleted file mode 100644 index 848a0d3..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaTripleContext.java +++ /dev/null @@ -1,133 +0,0 @@ -package mvm.rya.api.resolver; - -/* - * 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. - */ - - - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.RdfCloudTripleStoreConstants; -import mvm.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; -import mvm.rya.api.domain.RyaStatement; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaURI; -import mvm.rya.api.query.strategy.TriplePatternStrategy; -import mvm.rya.api.query.strategy.wholerow.HashedPoWholeRowTriplePatternStrategy; -import mvm.rya.api.query.strategy.wholerow.HashedSpoWholeRowTriplePatternStrategy; -import mvm.rya.api.query.strategy.wholerow.OspWholeRowTriplePatternStrategy; -import mvm.rya.api.query.strategy.wholerow.PoWholeRowTriplePatternStrategy; -import mvm.rya.api.query.strategy.wholerow.SpoWholeRowTriplePatternStrategy; -import mvm.rya.api.resolver.triple.TripleRow; -import mvm.rya.api.resolver.triple.TripleRowResolver; -import mvm.rya.api.resolver.triple.TripleRowResolverException; -import mvm.rya.api.resolver.triple.impl.WholeRowHashedTripleResolver; -import mvm.rya.api.resolver.triple.impl.WholeRowTripleResolver; - -/** - * Date: 7/16/12 - * Time: 12:04 PM - */ -public class RyaTripleContext { - - public Log logger = LogFactory.getLog(RyaTripleContext.class); - private TripleRowResolver tripleResolver; - private List<TriplePatternStrategy> triplePatternStrategyList = new ArrayList<TriplePatternStrategy>(); - - private RyaTripleContext(boolean addPrefixHash) { - addDefaultTriplePatternStrategies(addPrefixHash); - if (addPrefixHash){ - tripleResolver = new WholeRowHashedTripleResolver(); - } - else { - tripleResolver = new WholeRowTripleResolver(); - } - } - - - private static class RyaTripleContextHolder { - // TODO want to be able to support more variability in configuration here - public static final RyaTripleContext INSTANCE = new RyaTripleContext(false); - public static final RyaTripleContext HASHED_INSTANCE = new RyaTripleContext(true); - } - - public synchronized static RyaTripleContext getInstance(RdfCloudTripleStoreConfiguration conf) { - if (conf.isPrefixRowsWithHash()){ - return RyaTripleContextHolder.HASHED_INSTANCE; - } - return RyaTripleContextHolder.INSTANCE; - } - - - public Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serializeTriple(RyaStatement statement) throws TripleRowResolverException { - return getTripleResolver().serialize(statement); - } - - public RyaStatement deserializeTriple(RdfCloudTripleStoreConstants.TABLE_LAYOUT table_layout, TripleRow tripleRow) throws TripleRowResolverException { - return getTripleResolver().deserialize(table_layout, tripleRow); - } - - protected void addDefaultTriplePatternStrategies(boolean addPrefixHash) { - if (addPrefixHash){ - triplePatternStrategyList.add(new HashedSpoWholeRowTriplePatternStrategy()); - triplePatternStrategyList.add(new HashedPoWholeRowTriplePatternStrategy()); - } - else { - triplePatternStrategyList.add(new SpoWholeRowTriplePatternStrategy()); - triplePatternStrategyList.add(new PoWholeRowTriplePatternStrategy()); - } - triplePatternStrategyList.add(new OspWholeRowTriplePatternStrategy()); - } - - //retrieve triple pattern strategy - public TriplePatternStrategy retrieveStrategy(RyaURI subject, RyaURI predicate, RyaType object, RyaURI context) { - for (TriplePatternStrategy strategy : triplePatternStrategyList) { - if (strategy.handles(subject, predicate, object, context)) - return strategy; - } - return null; - } - - public TriplePatternStrategy retrieveStrategy(RyaStatement stmt) { - return retrieveStrategy(stmt.getSubject(), stmt.getPredicate(), stmt.getObject(), stmt.getContext()); - } - - public TriplePatternStrategy retrieveStrategy(TABLE_LAYOUT layout) { - for(TriplePatternStrategy strategy : triplePatternStrategyList) { - if (strategy.getLayout().equals(layout)) { - return strategy; - } - } - return null; - } - - public TripleRowResolver getTripleResolver() { - return tripleResolver; - } - - public void setTripleResolver(TripleRowResolver tripleResolver) { - this.tripleResolver = tripleResolver; - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaTypeResolver.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaTypeResolver.java b/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaTypeResolver.java deleted file mode 100644 index 5b1cd20..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaTypeResolver.java +++ /dev/null @@ -1,60 +0,0 @@ -package mvm.rya.api.resolver; - -/* - * 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. - */ - - - -import mvm.rya.api.domain.RyaRange; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaTypeRange; -import org.openrdf.model.URI; - -/** - * Date: 7/16/12 - * Time: 12:08 PM - */ -public interface RyaTypeResolver { - public byte[] serialize(RyaType ryaType) throws RyaTypeResolverException; - public byte[][] serializeType(RyaType ryaType) throws RyaTypeResolverException; - - public RyaType deserialize(byte[] bytes) throws RyaTypeResolverException; - - public RyaType newInstance(); - - /** - * @param bytes - * @return true if this byte[] is deserializable by this resolver - */ - public boolean deserializable(byte[] bytes); - - public URI getRyaDataType(); - - byte getMarkerByte(); - - /** - * This will allow a resolver to modify a range. For example, a date time resolver, with a reverse index, - * might want to reverse the start and stop - * - * @return - * @throws RyaTypeResolverException - */ - public RyaRange transformRange(RyaRange ryaRange) throws RyaTypeResolverException; - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaTypeResolverException.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaTypeResolverException.java b/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaTypeResolverException.java deleted file mode 100644 index 45f874c..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaTypeResolverException.java +++ /dev/null @@ -1,43 +0,0 @@ -package mvm.rya.api.resolver; - -/* - * 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. - */ - - - -/** - * Date: 7/16/12 - * Time: 12:09 PM - */ -public class RyaTypeResolverException extends Exception { - public RyaTypeResolverException() { - } - - public RyaTypeResolverException(String s) { - super(s); - } - - public RyaTypeResolverException(String s, Throwable throwable) { - super(s, throwable); - } - - public RyaTypeResolverException(Throwable throwable) { - super(throwable); - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaTypeResolverMapping.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaTypeResolverMapping.java b/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaTypeResolverMapping.java deleted file mode 100644 index 0c7a30a..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/resolver/RyaTypeResolverMapping.java +++ /dev/null @@ -1,57 +0,0 @@ -package mvm.rya.api.resolver; - -/* - * 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. - */ - - - -import org.openrdf.model.URI; - -/** - * Date: 7/16/12 - * Time: 12:11 PM - */ -public class RyaTypeResolverMapping { - - protected RyaTypeResolver ryaTypeResolver; - - public RyaTypeResolverMapping() { - } - - public RyaTypeResolverMapping(RyaTypeResolver ryaTypeResolver) { - this.ryaTypeResolver = ryaTypeResolver; - } - - public void setRyaTypeResolver(RyaTypeResolver ryaTypeResolver) { - this.ryaTypeResolver = ryaTypeResolver; - } - - public RyaTypeResolver getRyaTypeResolver() { - return ryaTypeResolver; - } - - public URI getRyaDataType() { - return ryaTypeResolver.getRyaDataType(); - } - - byte getMarkerByte() { - return ryaTypeResolver.getMarkerByte(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/resolver/impl/BooleanRyaTypeResolver.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/resolver/impl/BooleanRyaTypeResolver.java b/common/rya.api/src/main/java/mvm/rya/api/resolver/impl/BooleanRyaTypeResolver.java deleted file mode 100644 index f5de2de..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/resolver/impl/BooleanRyaTypeResolver.java +++ /dev/null @@ -1,61 +0,0 @@ -package mvm.rya.api.resolver.impl; - -/* - * 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. - */ - - - -import mvm.rya.api.resolver.RyaTypeResolverException; -import org.calrissian.mango.types.LexiTypeEncoders; -import org.calrissian.mango.types.TypeEncoder; -import org.calrissian.mango.types.exception.TypeDecodingException; -import org.calrissian.mango.types.exception.TypeEncodingException; -import org.openrdf.model.vocabulary.XMLSchema; - -public class BooleanRyaTypeResolver extends RyaTypeResolverImpl { - public static final int BOOLEAN_LITERAL_MARKER = 10; - public static final TypeEncoder<Boolean, String> BOOLEAN_TYPE_ENCODER = LexiTypeEncoders - .booleanEncoder(); - - public BooleanRyaTypeResolver() { - super((byte) BOOLEAN_LITERAL_MARKER, XMLSchema.BOOLEAN); - } - - @Override - protected String serializeData(String data) throws - RyaTypeResolverException { - try { - boolean value = Boolean.parseBoolean(data); - return BOOLEAN_TYPE_ENCODER.encode(value); - } catch (TypeEncodingException e) { - throw new RyaTypeResolverException( - "Exception occurred serializing data[" + data + "]", e); - } - } - - @Override - protected String deserializeData(String value) throws RyaTypeResolverException { - try { - return BOOLEAN_TYPE_ENCODER.decode(value).toString(); - } catch (TypeDecodingException e) { - throw new RyaTypeResolverException( - "Exception occurred deserializing data[" + value + "]", e); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/resolver/impl/ByteRyaTypeResolver.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/resolver/impl/ByteRyaTypeResolver.java b/common/rya.api/src/main/java/mvm/rya/api/resolver/impl/ByteRyaTypeResolver.java deleted file mode 100644 index 4b80679..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/resolver/impl/ByteRyaTypeResolver.java +++ /dev/null @@ -1,63 +0,0 @@ -package mvm.rya.api.resolver.impl; - -/* - * 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. - */ - - - -import mvm.rya.api.resolver.RyaTypeResolverException; -import org.calrissian.mango.types.LexiTypeEncoders; -import org.calrissian.mango.types.TypeEncoder; -import org.calrissian.mango.types.exception.TypeDecodingException; -import org.calrissian.mango.types.exception.TypeEncodingException; -import org.openrdf.model.vocabulary.XMLSchema; - -public class ByteRyaTypeResolver extends RyaTypeResolverImpl { - public static final int LITERAL_MARKER = 9; - public static final TypeEncoder<Byte, String> BYTE_STRING_TYPE_ENCODER = LexiTypeEncoders - .byteEncoder(); - - public ByteRyaTypeResolver() { - super((byte) LITERAL_MARKER, XMLSchema.BYTE); - } - - @Override - protected String serializeData(String data) throws RyaTypeResolverException { - try { - Byte value = Byte.parseByte(data); - return BYTE_STRING_TYPE_ENCODER.encode(value); - } catch (NumberFormatException e) { - throw new RyaTypeResolverException( - "Exception occurred serializing data[" + data + "]", e); - } catch (TypeEncodingException e) { - throw new RyaTypeResolverException( - "Exception occurred serializing data[" + data + "]", e); - } - } - - @Override - protected String deserializeData(String value) throws RyaTypeResolverException { - try { - return BYTE_STRING_TYPE_ENCODER.decode(value).toString(); - } catch (TypeDecodingException e) { - throw new RyaTypeResolverException( - "Exception occurred deserializing data[" + value + "]", e); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/resolver/impl/CustomDatatypeResolver.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/resolver/impl/CustomDatatypeResolver.java b/common/rya.api/src/main/java/mvm/rya/api/resolver/impl/CustomDatatypeResolver.java deleted file mode 100644 index ae93e0f..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/resolver/impl/CustomDatatypeResolver.java +++ /dev/null @@ -1,70 +0,0 @@ -package mvm.rya.api.resolver.impl; - -/* - * 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. - */ - - - -import com.google.common.primitives.Bytes; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.resolver.RyaTypeResolverException; -import org.openrdf.model.impl.URIImpl; -import static mvm.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTE; -import static mvm.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTES; - -/** - * Date: 7/16/12 - * Time: 1:12 PM - */ -public class CustomDatatypeResolver extends RyaTypeResolverImpl { - public static final int DT_LITERAL_MARKER = 8; - - public CustomDatatypeResolver() { - super((byte) DT_LITERAL_MARKER, null); - } - - @Override - public byte[][] serializeType(RyaType ryaType) throws RyaTypeResolverException { - byte[] bytes = serializeData(ryaType.getData()).getBytes(); - return new byte[][]{bytes, Bytes.concat(TYPE_DELIM_BYTES, ryaType.getDataType().stringValue().getBytes(), TYPE_DELIM_BYTES, markerBytes)}; - } - - @Override - public byte[] serialize(RyaType ryaType) throws RyaTypeResolverException { - byte[][] bytes = serializeType(ryaType); - return Bytes.concat(bytes[0], bytes[1]); - } - - @Override - public RyaType deserialize(byte[] bytes) throws RyaTypeResolverException { - if (!deserializable(bytes)) { - throw new RyaTypeResolverException("Bytes not deserializable"); - } - RyaType rt = newInstance(); - int length = bytes.length; - int indexOfType = Bytes.indexOf(bytes, TYPE_DELIM_BYTE); - if (indexOfType < 1) { - throw new RyaTypeResolverException("Not a datatype literal"); - } - String label = deserializeData(new String(bytes, 0, indexOfType)); - rt.setDataType(new URIImpl(new String(bytes, indexOfType + 1, (length - indexOfType) - 3))); - rt.setData(label); - return rt; - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/resolver/impl/DateTimeRyaTypeResolver.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/resolver/impl/DateTimeRyaTypeResolver.java b/common/rya.api/src/main/java/mvm/rya/api/resolver/impl/DateTimeRyaTypeResolver.java deleted file mode 100644 index cb3e7cf..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/resolver/impl/DateTimeRyaTypeResolver.java +++ /dev/null @@ -1,76 +0,0 @@ -package mvm.rya.api.resolver.impl; - -/* - * 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. - */ - - - -import mvm.rya.api.resolver.RyaTypeResolverException; -import org.calrissian.mango.types.LexiTypeEncoders; -import org.calrissian.mango.types.TypeEncoder; -import org.calrissian.mango.types.exception.TypeDecodingException; -import org.calrissian.mango.types.exception.TypeEncodingException; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.format.DateTimeFormatter; -import org.joda.time.format.ISODateTimeFormat; -import org.openrdf.model.vocabulary.XMLSchema; - -import java.util.Date; - -/** - * Reverse index xml datetime strings - * <p/> - * Date: 7/13/12 - * Time: 7:33 AM - */ -public class DateTimeRyaTypeResolver extends RyaTypeResolverImpl { - public static final int DATETIME_LITERAL_MARKER = 7; - public static final TypeEncoder<Date, String> DATE_STRING_TYPE_ENCODER = LexiTypeEncoders.dateEncoder(); - public static final DateTimeFormatter XMLDATETIME_PARSER = org.joda.time.format.ISODateTimeFormat.dateTimeParser(); - public static final DateTimeFormatter UTC_XMLDATETIME_FORMATTER = ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC); - - - public DateTimeRyaTypeResolver() { - super((byte) DATETIME_LITERAL_MARKER, XMLSchema.DATETIME); - } - - @Override - protected String serializeData(String data) throws RyaTypeResolverException { - try { - DateTime dateTime = DateTime.parse(data, XMLDATETIME_PARSER); - Date value = dateTime.toDate(); - return DATE_STRING_TYPE_ENCODER.encode(value); - } catch (TypeEncodingException e) { - throw new RyaTypeResolverException( - "Exception occurred serializing data[" + data + "]", e); - } - } - - @Override - protected String deserializeData(String value) throws RyaTypeResolverException { - try { - Date date = DATE_STRING_TYPE_ENCODER.decode(value); - return UTC_XMLDATETIME_FORMATTER.print(date.getTime()); - } catch (TypeDecodingException e) { - throw new RyaTypeResolverException( - "Exception occurred deserializing data[" + value + "]", e); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/mvm/rya/api/resolver/impl/DoubleRyaTypeResolver.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/resolver/impl/DoubleRyaTypeResolver.java b/common/rya.api/src/main/java/mvm/rya/api/resolver/impl/DoubleRyaTypeResolver.java deleted file mode 100644 index 88daa0f..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/resolver/impl/DoubleRyaTypeResolver.java +++ /dev/null @@ -1,68 +0,0 @@ -package mvm.rya.api.resolver.impl; - -/* - * 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. - */ - - - -import mvm.rya.api.resolver.RyaTypeResolverException; -import org.calrissian.mango.types.LexiTypeEncoders; -import org.calrissian.mango.types.TypeEncoder; -import org.calrissian.mango.types.exception.TypeDecodingException; -import org.calrissian.mango.types.exception.TypeEncodingException; -import org.openrdf.model.vocabulary.XMLSchema; - -import java.text.DecimalFormat; - -/** - * Date: 7/20/12 - * Time: 9:33 AM - */ -public class DoubleRyaTypeResolver extends RyaTypeResolverImpl { - public static final int DOUBLE_LITERAL_MARKER = 6; - public static final TypeEncoder<Double, String> DOUBLE_TYPE_ENCODER = LexiTypeEncoders.doubleEncoder(); - - public DoubleRyaTypeResolver() { - super((byte) DOUBLE_LITERAL_MARKER, XMLSchema.DOUBLE); - } - - @Override - protected String serializeData(String data) throws RyaTypeResolverException { - try { - double value = Double.parseDouble(data); - return DOUBLE_TYPE_ENCODER.encode(value); - } catch (NumberFormatException e) { - throw new RyaTypeResolverException( - "Exception occurred serializing data[" + data + "]", e); - } catch (TypeEncodingException e) { - throw new RyaTypeResolverException( - "Exception occurred serializing data[" + data + "]", e); - } - } - - @Override - protected String deserializeData(String value) throws RyaTypeResolverException { - try { - return DOUBLE_TYPE_ENCODER.decode(value).toString(); - } catch (TypeDecodingException e) { - throw new RyaTypeResolverException( - "Exception occurred deserializing data[" + value + "]", e); - } - } -}
