@Override public <T> T getById(String id, Class<T> clazz) { return get(clazz, new LID(id)); }
@Override public String getAsText() { LID uid = (LID) getValue(); if (uid == null) { return ""; } else { return uid.getId(); } }
@Test public void URI2() { LID lid = identityService.getLID(RDF.type); assertEquals(lid, identityService.getLID(RDF.type)); assertEquals(lid, identityService.getLID(RDF.type)); assertFalse(lid.equals(identityService.getLID(RDF.li))); }
@Override public void setAsText(String text) { if (Strings.isNullOrEmpty(text)) { setValue(null); } else { setValue(new LID(text)); } }
@Override public ID getID(LID lid) { STMT stmt = find(null, CORE.localId, new LIT(lid.getId())); return stmt != null ? stmt.getSubject() : null; }
@Override public LID getLID(ID id) { STMT stmt = find(id, CORE.localId, null); String lid; if (stmt != null) { lid = stmt.getObject().getValue(); } else { lid = String.valueOf(connection.getNextLocalId()); add(id, CORE.localId, new LIT(lid)); } return new LID(lid); }
@Test public void Local() { LID lid = session.getLID(new BID("foobar")); LIDResource resource1 = session.get(LIDResource.class, lid); assertNotNull(resource1); LID id = resource1.id; assertNotNull(id); // assertTrue(id instanceof LID); assertTrue(Integer.parseInt(id.getId()) > 0); } }
@Test public void HashCode() { LID lid2 = new LID("1"); assertEquals(lid, lid2); }
@SuppressWarnings("unchecked") private <RT> RT getAsProjectionValue(NODE node, Class<RT> type) { if (node.isResource()) { if (type.equals(String.class)) { // TODO : always return LID ? return (RT) session.getLID(node.asResource()).getId(); } else { return session.get(type, node.asResource()); } } else { return converterRegistry.fromString(node.getValue(), type); } }
lid = (LID) id; } else { lid = new LID(id.toString());
@SuppressWarnings("unchecked") private Operation<?> transformPathEqNeConstant(Operation<?> operation) { Path<?> path = (Path<?>) operation.getArg(0); Constant<?> constant = (Constant<?>) operation.getArg(1); MappedPath mappedPath = getMappedPath(path); // id property if (path.getMetadata().getPathType() == PathType.PROPERTY && constant.getType().equals(String.class) && mappedPath.getPredicatePath().isEmpty()) { operation = PredicateOperation.create((Operator) operation.getOperator(), path, new ConstantImpl<ID>(session.getId(new LID(constant.toString())))); // localized property } else if (mappedPath.getMappedProperty().isLocalized()) { Locale locale; if (path.getMetadata().getPathType() == PathType.PROPERTY) { locale = session.getCurrentLocale(); } else { locale = (Locale) path.getMetadata().getElement(); } operation = PredicateOperation.create((Operator) operation.getOperator(), path, new ConstantImpl<LIT>(new LIT(constant.toString(), locale))); } return operation; }
@Test public void GetAsText() { editor.setValue(new LID("1")); assertEquals("1", editor.getAsText()); }
@Test public void SetAsTextString() { editor.setAsText("1"); assertEquals(new LID("1"), editor.getValue()); }
@Test public void Array() { MiniRepository repository = new MiniRepository(); Session session = SessionUtil.openSession(repository, ArrayTest.class); ArrayTest test = new ArrayTest(); test.array = new String[] { "a", "b", "c" }; test.numbers = new int[] { 1, 2, 3 }; session.save(test); session.clear(); ArrayTest test2 = session.get(ArrayTest.class, new LID(test.id)); assertEquals(test.id, test2.id); assertArrayEquals(test.array, test2.array); assertArrayEquals(test.numbers, test2.numbers); }