public <T> Key<T> createKey(Class<T> clazz, Serializable id) { return new Key<T>(clazz, id); }
@Override protected Key<T> convertItem(DBObject dbObj) { Key<T> key = new Key<T>(kind, dbObj.get(Mapper.ID_KEY)); key.setKindClass(this.clazz); return key; }
public <T> Key<T> refToKey(DBRef ref) { if (ref == null) return null; return new Key<T>(ref.getRef(), ref.getId()); }
public <T> Key<T> getKey(T entity) { if (entity == null) throw new MappingException("getKey has been passed a null entity"); if (entity instanceof ProxiedEntityReference) { return getKey((ProxiedEntityReference) entity); } entity = ProxyHelper.unwrap(entity); if (entity instanceof Key) return (Key<T>) entity; Object id = getId(entity); if (id == null) throw new MappingException("Could not get id for " + entity.getClass().getName()); return new Key<T>((Class<T>) entity.getClass(), id); }
private Key<?> getKey(final Object entity, Mapper mapr) { try { if (entity instanceof ProxiedEntityReference) { ProxiedEntityReference proxy = (ProxiedEntityReference) entity; return proxy.__getKey(); } MappedClass mappedClass = mapr.getMappedClass(entity); Object id = mappedClass.getIdField().get(entity); if (id == null) throw new MappingException("@Id field cannot be null!"); Key key = new Key(mappedClass.getCollectionName(), id); return key; } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } }
public <T> Key<T> createKey(Class<T> clazz, Object id) { if (id instanceof Serializable) return createKey(clazz, (Serializable) id); //TODO: cache the encoders, maybe use the pool version of the buffer that the driver does. BSONEncoder enc = new BasicBSONEncoder(); return new Key<T>(clazz, enc.encode(toDBObject(id))); }
/** * call postSaveOperations and returns Key for entity. */ protected <T> Key<T> postSaveGetKey(T entity, DBObject dbObj, DBCollection dbColl, Map<Object, DBObject> involvedObjects) { if (dbObj.get(Mapper.ID_KEY) == null) throw new MappingException("Missing _id after save!"); postSaveOperations(entity, dbObj, involvedObjects); Key<T> key = new Key<T>(dbColl.getName(), mapr.getId(entity)); key.setKindClass((Class<? extends T>) entity.getClass()); return key; }