@Test(expected = IllegalArgumentException.class) public void GetId() { session.getId(value); }
@Test public void getId() { MiniRepository repository = new MiniRepository(); Session session = SessionUtil.openSession(repository, EnumType.class, EnumRef.class); assertEquals(new UID(TEST.NS, "PRIMARY"), session.getId(EnumType.PRIMARY)); assertEquals(new UID(TEST.NS, "SECONDARY"), session.getId(EnumType.SECONDARY)); } }
public Expression<?> visit(Constant<?> constant, Filters filters) { Object javaValue = constant.getConstant(); ConverterRegistry converter = configuration.getConverterRegistry(); if (List.class.isAssignableFrom(constant.getType()) && ((List<?>) constant.getConstant()).isEmpty()) { return new ConstantImpl<UID>(RDF.nil); } else if (NODE.class.isAssignableFrom(constant.getType())) { return constant; } else if (javaValue instanceof Class<?>) { UID datatype = converter.getDatatype((Class<?>) javaValue); if (datatype != null) { return new ConstantImpl<UID>(datatype); } else { return new ConstantImpl<UID>(getTypeForDomainClass((Class<?>) javaValue)); } } else if (javaValue instanceof String) { return new ConstantImpl<LIT>(new LIT(javaValue.toString(), XSD.stringType)); } else if (converter.supports(javaValue.getClass())) { String label = converter.toString(javaValue); UID datatype = converter.getDatatype(javaValue.getClass()); return new ConstantImpl<LIT>(new LIT(label, datatype)); } else { ID id = session.getId(javaValue); return new ConstantImpl<ID>(id); } }
@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 SimpleDeleteResource() { DeleteTest dtest = new DeleteTest(); dtest.name = "dtest"; session.save(dtest); newSession(); DeleteTest tmp = dtest; dtest = session.getById(dtest.id, DeleteTest.class); assertNotSame(tmp, dtest); assertEquals("dtest", dtest.name); session.delete(DeleteTest.class, session.getId(dtest)); assertNull(session.getById(dtest.id, DeleteTest.class)); newSession(); assertNull(session.getById(dtest.id, DeleteTest.class)); }