public <P extends BaseProxy> SimpleProxyId<P> getBaseProxyId( String historyToken) { assert !IdUtil.isSynthetic(historyToken) : "Synthetic id resolution" + " should be handled by AbstractRequestContext"; if (IdUtil.isPersisted(historyToken)) { return getId(IdUtil.getTypeToken(historyToken), IdUtil.getServerId(historyToken)); } if (IdUtil.isEphemeral(historyToken)) { @SuppressWarnings("unchecked") SimpleProxyId<P> toReturn = (SimpleProxyId<P>) ephemeralIds.get(historyToken); /* * This is tested in FindServiceTest.testFetchUnpersistedFutureId. In * order to get here, the user would have to get an unpersisted history * token and attempt to use it with a different RequestFactory instance. * This could occur if an ephemeral token were bookmarked. In this case, * we'll create a token, however it will never match anything. */ if (toReturn == null) { Class<P> clazz = checkTypeToken(IdUtil.getTypeToken(historyToken)); toReturn = createId(clazz, -1 * ephemeralIds.size()); ephemeralIds.put(historyToken, toReturn); } return toReturn; } throw new IllegalArgumentException(historyToken); }
private <P extends BaseProxy> SimpleProxyId<P> createId(Class<P> clazz, String serverId) { SimpleProxyId<P> toReturn; if (isValueType(clazz)) { toReturn = new SimpleProxyId<P>(clazz, serverId); } else { @SuppressWarnings("unchecked") SimpleProxyId<P> temp = (SimpleProxyId<P>) new SimpleEntityProxyId<EntityProxy>( asEntityProxy(clazz), serverId); toReturn = (SimpleProxyId<P>) temp; } return toReturn; }
/** * Allocates an ephemeral proxy id. This object is only valid for the lifetime * of the RequestFactory. */ public <P extends BaseProxy> SimpleProxyId<P> allocateId(Class<P> clazz) { SimpleProxyId<P> toReturn = createId(clazz, ephemeralIds.size() + 1); ephemeralIds.put(getHistoryToken(toReturn), toReturn); return toReturn; }
/** * Create or retrieve a SimpleProxyId. If both the serverId and clientId are * specified and the id is ephemeral, it will be updated with the server id. */ public <P extends BaseProxy> SimpleProxyId<P> getId(Class<P> clazz, String serverId, int clientId) { return getId(getTypeToken(clazz), serverId, clientId); }
/** * Get or create BaseProxy AutoBeans for a list of id-bearing messages. */ public List<AutoBean<? extends BaseProxy>> getBeansForPayload(List<? extends IdMessage> idMessages) { List<SimpleProxyId<?>> ids = new ArrayList<SimpleProxyId<?>>(idMessages.size()); for (IdMessage idMessage : idMessages) { SimpleProxyId<?> id; if (Strength.SYNTHETIC.equals(idMessage.getStrength())) { Class<? extends BaseProxy> clazz = service.resolveClass(idMessage.getTypeToken()); id = idFactory.allocateSyntheticId(clazz, idMessage.getSyntheticId()); } else { String decodedId = idMessage.getServerId() == null ? null : SimpleRequestProcessor.fromBase64(idMessage .getServerId()); id = idFactory.getId(idMessage.getTypeToken(), decodedId, idMessage.getClientId()); } ids.add(id); } return getBeansForIds(ids); }
Class<P> clazz = getTypeFromToken(typeToken); toReturn = createId(clazz, clientId); ephemeralIds.put(ephemeralKey, toReturn); assert toReturn.getProxyClass().equals(getTypeFromToken(typeToken)); Class<P> clazz = getTypeFromToken(typeToken); assert clazz != null : "No class literal for " + typeToken; return createId(clazz, serverId);
/** * EntityCodex support. */ public boolean isValueType(Class<?> clazz) { return idFactory.isValueType(clazz); }
/** * EntityCodex support. */ public boolean isEntityType(Class<?> clazz) { return idFactory.isEntityType(clazz); }
/** * Allocates a synthetic proxy id. This object is only valid for the lifetime * of a request. */ public <P extends BaseProxy> SimpleProxyId<P> allocateSyntheticId( Class<P> clazz, int syntheticId) { assert syntheticId > 0; SimpleProxyId<P> toReturn = createId(clazz, "%" + syntheticId); toReturn.setSyntheticId(syntheticId); return toReturn; }
public String getHistoryToken(SimpleProxyId<?> proxy) { SimpleProxyId<?> id = (SimpleProxyId<?>) proxy; String token = getTypeToken(proxy.getProxyClass()); if (id.isEphemeral()) { return IdUtil.ephemeralId(id.getClientId(), token); } else if (id.isSynthetic()) { return IdUtil.syntheticId(id.getSyntheticId(), token); } else { return IdUtil.persistedId(id.getServerId(), token); } }
private <P> Class<P> checkTypeToken(String token) { @SuppressWarnings("unchecked") Class<P> clazz = (Class<P>) getTypeFromToken(token); if (clazz == null) { throw new IllegalArgumentException("Unknnown type"); } return clazz; }
/** * Create or retrieve a SimpleProxyId. */ public <P extends BaseProxy> SimpleProxyId<P> getId(String typeToken, String serverId) { return getId(typeToken, serverId, 0); }
id = state.getIdFactory().allocateSyntheticId(proxyType, ++syntheticId); } else { Splittable flatValue = state.flatten(domainId); id = state.getIdFactory().getId(proxyType, flatValue.getPayload(), 0);
Class<P> clazz = getTypeFromToken(typeToken); toReturn = createId(clazz, clientId); ephemeralIds.put(ephemeralKey, toReturn); assert toReturn.getProxyClass().equals(getTypeFromToken(typeToken)); Class<P> clazz = getTypeFromToken(typeToken); assert clazz != null : "No class literal for " + typeToken; return createId(clazz, serverId);
/** * Create or retrieve a SimpleProxyId. If both the serverId and clientId are * specified and the id is ephemeral, it will be updated with the server id. */ public <P extends BaseProxy> SimpleProxyId<P> getId(Class<P> clazz, String serverId, int clientId) { return getId(getTypeToken(clazz), serverId, clientId); }
/** * A utility function to handle generic type conversion. This method will also * assert that {@code clazz} is actually a ValueProxy type. */ @SuppressWarnings("unchecked") public <P extends ValueProxy> Class<P> asValueProxy( Class<? extends BaseProxy> clazz) { assert isValueType(clazz) : clazz.getName() + " is not a ValueProxy type"; return (Class<P>) clazz; }
/** * A utility function to handle generic type conversion. This method will also * assert that {@code clazz} is actually an EntityProxy type. */ @SuppressWarnings("unchecked") public <P extends EntityProxy> Class<P> asEntityProxy( Class<? extends BaseProxy> clazz) { assert isEntityType(clazz) : clazz.getName() + " is not an EntityProxy type"; return (Class<P>) clazz; }
System.err.println(fact.createId());
public String getHistoryToken(SimpleProxyId<?> proxy) { SimpleProxyId<?> id = (SimpleProxyId<?>) proxy; String token = getTypeToken(proxy.getProxyClass()); if (id.isEphemeral()) { return IdUtil.ephemeralId(id.getClientId(), token); } else if (id.isSynthetic()) { return IdUtil.syntheticId(id.getSyntheticId(), token); } else { return IdUtil.persistedId(id.getServerId(), token); } }
private <P> Class<P> checkTypeToken(String token) { @SuppressWarnings("unchecked") Class<P> clazz = (Class<P>) getTypeFromToken(token); if (clazz == null) { throw new IllegalArgumentException("Unknnown type"); } return clazz; }