public String getPrefix() { String data = getStart().getData(); return data.substring(0, data.length() - 1); } }
@Override public JsonElement serialize(RyaType src, Type typeOfSrc, JsonSerializationContext context) { JsonObject result = new JsonObject(); result.add("type", new JsonPrimitive(src.getClass().getName())); StringBuilder builder = new StringBuilder(); builder.append(src.getData()).append("\u0000").append(src.getDataType().toString()); result.add("properties", new JsonPrimitive(builder.toString())); return result; }
@Override public byte[][] serializeType(final RyaType ryaType) throws RyaTypeResolverException { final byte[] bytes = serializeData(ryaType.getData()).getBytes(StandardCharsets.UTF_8); return new byte[][]{bytes, Bytes.concat(TYPE_DELIM_BYTES, markerBytes)}; }
@Override public JsonElement serialize(RyaType src, Type typeOfSrc, JsonSerializationContext context) { JsonObject result = new JsonObject(); result.add("type", new JsonPrimitive(src.getClass().getName())); StringBuilder builder = new StringBuilder(); builder.append(src.getData()).append("\u0000").append(src.getDataType().toString()); result.add("properties", new JsonPrimitive(builder.toString())); return result; }
@Override public DBObject serialize(final RyaStatement ryaStatement) { final BasicDBObject base = (BasicDBObject) super.serialize(ryaStatement); base.append(text, ryaStatement.getObject().getData()); return base; } }
@Override public Document toDocument(final RyaType ryaType) { requireNonNull(ryaType); return new Document() .append(DATA_TYPE, ryaType.getDataType().toString()) .append(VALUE, ryaType.getData()); }
@Override public DBObject serialize(final RyaStatement ryaStatement) { final BasicDBObject base = (BasicDBObject) super.serialize(ryaStatement); final DBObject time = getTimeValue(ryaStatement.getObject().getData()); base.putAll(time.toMap()); return base; }
@Override public Document toDocument(final RyaType ryaType) { requireNonNull(ryaType); return new Document() .append(DATA_TYPE, ryaType.getDataType().toString()) .append(VALUE, ryaType.getData()); }
private static String prettyFormat(final RyaStatement statement) { final RyaIRI s = statement.getSubject(); final RyaIRI p = statement.getPredicate(); final RyaType o = statement.getObject(); return "<" + s.getData() + "> <"+ p.getData() + "> <" + o.getData() + ">"; }
@Override public void write(DataOutput dataOutput) throws IOException { dataOutput.writeChars(ryatype.getData()); dataOutput.writeChars(ryatype.getDataType().toString()); }
@Override public String getVersion() throws RyaDAOException { String version = null; final CloseableIteration<RyaStatement, RyaDAOException> versIter = queryEngine.query(new RyaStatement(RTS_SUBJECT_RYA, RTS_VERSION_PREDICATE_RYA, null), conf); if (versIter.hasNext()) { version = versIter.next().getObject().getData(); } versIter.close(); return version; }
public static String getTripleString(final RyaStatement rs) { checkNotNull(rs); final String subj = rs.getSubject().getData() + TYPE_DELIM + URI_TYPE; final String pred = rs.getPredicate().getData() + TYPE_DELIM + URI_TYPE; final String objData = rs.getObject().getData(); final String objDataType = rs.getObject().getDataType().stringValue(); return subj + DELIM + pred + DELIM + objData + TYPE_DELIM + objDataType; }
@Override public String getVersion() throws RyaDAOException { String version = null; final CloseableIteration<RyaStatement, RyaDAOException> versIter = queryEngine.query(new RyaStatement(RTS_SUBJECT_RYA, RTS_VERSION_PREDICATE_RYA, null), conf); if (versIter.hasNext()) { version = versIter.next().getObject().getData(); } versIter.close(); return version; }
public static String getTripleString(final RyaStatement rs) { checkNotNull(rs); final String subj = rs.getSubject().getData() + TYPE_DELIM + URI_TYPE; final String pred = rs.getPredicate().getData() + TYPE_DELIM + URI_TYPE; final String objData = rs.getObject().getData(); final String objDataType = rs.getObject().getDataType().stringValue(); return subj + DELIM + pred + DELIM + objData + TYPE_DELIM + objDataType; }
public void testDoubleSerialization() throws Exception { Double d = randomDouble(); RyaType ryaType = new RyaType(XMLSchema.DOUBLE, d.toString()); byte[] serialize = new DoubleRyaTypeResolver().serialize(ryaType); assertEquals(d, Double.parseDouble(new DoubleRyaTypeResolver().deserialize(serialize).getData())); }
@Test public void testDateNoTimeNoZone() throws Exception { String beforeDate = "2000-02-02"; String afterDate="2000-02-0(1|2|3)T\\d\\d:\\d\\d:00\\.000Z"; RyaType deserialize = serializeAndDeserialize(beforeDate, XMLSchema.DATE); final String afterActual = deserialize.getData(); assertTrue("Before='"+beforeDate+"'; Expected should match actual regex after='"+afterDate+"' deserialized:"+afterActual, afterActual.matches(afterDate)); assertEquals(XMLSchema.DATETIME, deserialize.getDataType()); } @Test
@Test public void testSerialization() throws Exception { Long i = randomLong(); byte[] serialize = new LongRyaTypeResolver().serialize(new RyaType(XMLSchema.LONG, i.toString())); assertEquals(i, new Long(new LongRyaTypeResolver().deserialize(serialize).getData())); }
@Test public void testNoZone() throws Exception { String beforeDate = "2000-01-02T00:00:01"; String afterDate="2000-01-0(1|2|3)T\\d\\d:\\d\\d:01\\.000Z"; RyaType deserialize = serializeAndDeserialize(beforeDate, XMLSchema.DATE); final String afterActual = deserialize.getData(); assertTrue("Before='"+beforeDate+"'; Expected should match actual regex after='"+afterDate+"' deserialized:"+afterActual, afterActual.matches(afterDate)); assertEquals(XMLSchema.DATETIME, deserialize.getDataType()); } @Test
@Test public void testMilliSecondsNoZone() throws Exception { String beforeDate="2002-02-02T02:02:02.222"; String afterDate="2002-02-0(1|2|3)T\\d\\d:\\d\\d:02\\.222.*"; RyaType deserialize = serializeAndDeserialize(beforeDate, XMLSchema.DATETIME); final String afterActual = deserialize.getData(); assertTrue("Before='"+beforeDate+"'; Expected should match actual regex after='"+afterDate+"' deserialized:"+afterActual, afterActual.matches(afterDate)); assertEquals(XMLSchema.DATETIME, deserialize.getDataType()); } @Test