public static Key toKey(Repository r, IdRef<?> id) { return convertWithinRightNamespace(r, id.getClazz(), id); }
public static void beforeDestroy(Repository r, IdRef<?> id) { invokeHooks(r, id.getClazz(), id, "beforeDestroy"); }
private void destroySinkMarkers(List<? extends IdRef<?>> markerIds) { for (IdRef<?> id : markerIds) { if (!id.getParentId().getClazz().equals(sourceClazz)) { continue; } r.destroy(id); } }
private static void validateParentId(IdRef<?> id, String path) { Class<?> parentClazz = id.getParentClazz(); if (parentClazz == null) { return; } if (id.getParentId() == null) { throw new RuntimeException("Invalid parent structure for id: " + path); } if (!parentClazz.equals(id.getParentId().getClazz())) { throw new RuntimeException("Invalid parent structure for id: " + path); } }
private boolean beginTransactionForPipesOnDestroy(IdRef<?> id) { Class<?> endpointClazz = id.getClazz(); if (!RepositoryPipes.isPipeSource(this, endpointClazz)) { return false; } return beginTransactionForPipes(); }
private ActionKey singleObjectCustomActionKey(String lastToken) { ActionKey actionKey = new ActionKey(rightCustomActionVerb(), lastToken, false); if (features.hasCustomAction(id.getClazz(), actionKey)) { return actionKey; } return null; }
private Class<?> parseEndpointClazz() { String[] parts = uri.substring(1).split("/"); if (isOverCollection()) { if (isCustomAction()) { return features.getByPath("/" + parts[parts.length - 2]).getClazz(); } return features.getByPath("/" + parts[parts.length - 1]).getClazz(); } return id.getClazz(); }
protected FutureObject<Void> destroyAsync(final IdRef<?> id) { namespace.set(id.getClazz()); try { RepositoryHooks.beforeDestroy(this, id); return destroyInternalAsync(id); } finally { namespace.reset(); } }
@Override public <T> T fetch(IdRef<T> id) { namespace.set(id.getClazz()); try { return driver().query().fetch(id); } finally { namespace.reset(); } }
@Override public <T> FutureObject<T> fetchAsync(IdRef<T> id) { namespace.set(id.getClazz()); try { return driver().query().fetchAsync(id); } finally { namespace.reset(); } }
@Override public void destroy(IdRef<?> id) { namespace.set(id.getClazz()); try { RepositoryHooks.beforeDestroy(this, id); destroyInternal(id); RepositoryHooks.afterDestroy(this, id); } finally { namespace.reset(); } }
@Override public <T> FutureObject<T> fetchAsync(IdRef<T> id) { Key key = IdRefToKey.toKey(r, id); Future<Entity> futureEntity = asyncDatastore().get(key); return new FutureObject<>(r, new FutureEntityToObject(r, id.getClazz(), futureEntity)); }
public IdRef<SinkMarker> createSinkMarkerId() { IdRef<?> sourceId = payload.getSourceId(); IdRef<?> sinkId = payload.getSinkId(); IdRef<SinkMarker> sinkMarkerId; if (sourceId.getId() != null) { sinkMarkerId = IdRef.create(yawp(), SinkMarker.class, sourceId.getId()); sinkMarkerId.setParentId(sinkId.createChildId(sourceId.getClazz(), sourceId.getId())); } else { sinkMarkerId = IdRef.create(yawp(), SinkMarker.class, sourceId.getName()); sinkMarkerId.setParentId(sinkId.createChildId(sourceId.getClazz(), sourceId.getName())); } return sinkMarkerId; }
private static Key convertWithinRightNamespace(Repository r, Class<?> clazz, IdRef<?> id) { r.namespace().set(clazz); try { Key parent = id.getParentId() == null ? null : toKey(r, id.getParentId()); String kind = KindResolver.getKindFromClass(id.getClazz()); return createKey(id, parent, kind); } finally { r.namespace().reset(); } }
private static Key convertWithinRightNamespace(Repository r, Class<?> clazz, IdRef<?> id) { r.namespace().set(clazz); try { Key parent = id.getParentId() == null ? null : toKey(r, id.getParentId()); String kind = KindResolver.getKindFromClass(id.getClazz()); return createKey(id, parent, kind); } finally { r.namespace().reset(); } }
private void assertIdRef(IdRef<?> id, Class<?> clazz, String idAsString) { assertEquals(clazz, id.getClazz()); assertEquals(idAsString, id.asString()); assertNull(id.asLong()); }
private void assertIdRef(IdRef<?> id, Class<?> clazz, Long idAsLong) { assertEquals(clazz, id.getClazz()); assertEquals(idAsLong, id.asLong()); assertNull(id.asString()); }
@Test public void testIdHelper() { Feature feature = new Feature(); feature.setRepository(yawp); IdRef<Job> jobId = feature.id("/jobs/1").of(Job.class); assertEquals((Long) 1l, jobId.getId()); assertEquals(Job.class, jobId.getClazz()); }