/** * renames of this collection to newName * * @param newName new collection name (not a full namespace) * @param dropTarget if a collection with the new name exists, whether or not to drop it * @return the new collection * @throws MongoException If an error occurred */ public JacksonDBCollection<T, K> rename(String newName, boolean dropTarget) throws MongoException { return new JacksonDBCollection<T, K>(dbCollection.rename(newName, dropTarget), type, keyType, objectMapper, features); }
/** * renames of this collection to newName * * @param newName new collection name (not a full namespace) * @param dropTarget if a collection with the new name exists, whether or not to drop it * @return the new collection * @throws MongoException If an error occurred */ public JacksonDBCollection<T, K> rename(String newName, boolean dropTarget) throws MongoException { return new JacksonDBCollection<T, K>(dbCollection.rename(newName, dropTarget), type, keyType, objectMapper, features); }
/** * Wraps a DB collection in a JacksonDBCollection * * @param dbCollection The DB collection to wrap * @param type The type of objects to deserialise to * @param keyType The type of the objects key * @return The wrapped collection */ public static <T, K> JacksonDBCollection<T, K> wrap(DBCollection dbCollection, Class<T> type, Class<K> keyType) { return new JacksonDBCollection<T, K>(dbCollection, DEFAULT_OBJECT_MAPPER.constructType(type), DEFAULT_OBJECT_MAPPER.constructType(keyType), DEFAULT_OBJECT_MAPPER, null); }
/** * Wraps a DB collection in a JacksonDBCollection * * @param dbCollection The DB collection to wrap * @param type The type of objects to deserialise to * @return The wrapped collection */ public static <T> JacksonDBCollection<T, Object> wrap(DBCollection dbCollection, Class<T> type) { return new JacksonDBCollection<T, Object>(dbCollection, DEFAULT_OBJECT_MAPPER.constructType(type), DEFAULT_OBJECT_MAPPER.constructType(Object.class), DEFAULT_OBJECT_MAPPER, null); }
/** * Wraps a DB collection in a JacksonDBCollection * * @param dbCollection The DB collection to wrap * @param type The type of objects to deserialise to * @param keyType The type of the objects key * @return The wrapped collection */ public static <T, K> JacksonDBCollection<T, K> wrap(DBCollection dbCollection, Class<T> type, Class<K> keyType) { return new JacksonDBCollection<T, K>(dbCollection, DEFAULT_OBJECT_MAPPER.constructType(type), DEFAULT_OBJECT_MAPPER.constructType(keyType), DEFAULT_OBJECT_MAPPER, null); }
/** * Wraps a DB collection in a JacksonDBCollection * * @param dbCollection The DB collection to wrap * @param type The type of objects to deserialise to * @return The wrapped collection */ public static <T> JacksonDBCollection<T, Object> wrap(DBCollection dbCollection, Class<T> type) { return new JacksonDBCollection<T, Object>(dbCollection, DEFAULT_OBJECT_MAPPER.constructType(type), DEFAULT_OBJECT_MAPPER.constructType(Object.class), DEFAULT_OBJECT_MAPPER, null); }
/** * Wraps a DB collection in a JacksonDBCollection, using the given object mapper. * * JacksonDBCollection requires a specially configured object mapper to work. It does not automatically configure * the object mapper passed into this method, because the same object mapper might be passed into multiple calls to * this method. Consequently, it is up to the caller to ensure that the object mapper has been configured for use * by JacksonDBCollection. This can be done by passing the object mapper to * {@link MongoJacksonMapperModule#configure(org.codehaus.jackson.map.ObjectMapper)}. * * @param dbCollection The DB collection to wrap * @param type The type of objects to deserialise to * @param objectMapper The ObjectMapper to configure. * @return The wrapped collection */ public static <T, K> JacksonDBCollection<T, K> wrap(DBCollection dbCollection, Class<T> type, Class<K> keyType, ObjectMapper objectMapper) { return new JacksonDBCollection<T, K>(dbCollection, objectMapper.constructType(type), objectMapper.constructType(keyType), objectMapper, null); }
/** * Wraps a DB collection in a JacksonDBCollection, using the given object mapper. * * JacksonDBCollection requires a specially configured object mapper to work. It does not automatically configure * the object mapper passed into this method, because the same object mapper might be passed into multiple calls to * this method. Consequently, it is up to the caller to ensure that the object mapper has been configured for use * by JacksonDBCollection. This can be done by passing the object mapper to * {@link MongoJacksonMapperModule#configure(org.codehaus.jackson.map.ObjectMapper)}. * * @param dbCollection The DB collection to wrap * @param type The type of objects to deserialise to * @param objectMapper The ObjectMapper to configure. * @return The wrapped collection */ public static <T, K> JacksonDBCollection<T, K> wrap(DBCollection dbCollection, Class<T> type, Class<K> keyType, ObjectMapper objectMapper) { return new JacksonDBCollection<T, K>(dbCollection, objectMapper.constructType(type), objectMapper.constructType(keyType), objectMapper, null); }
/** * Get a collection for loading a reference of the given type * * @param collectionKey The key for the collection * @return The collection */ public <T, K> JacksonDBCollection<T, K> getReferenceCollection(JacksonCollectionKey collectionKey) { JacksonDBCollection<T, K> collection = referencedCollectionCache.get(collectionKey); if (collection == null) { collection = new JacksonDBCollection<T, K>(getDB().getCollection(collectionKey.getName()), collectionKey.getType(), collectionKey.getKeyType(), objectMapper, features); referencedCollectionCache.put(collectionKey, collection); } return collection; }
/** * Get a collection for loading a reference of the given type * * @param collectionKey The key for the collection * @return The collection */ public <T, K> JacksonDBCollection<T, K> getReferenceCollection(JacksonCollectionKey collectionKey) { JacksonDBCollection<T, K> collection = referencedCollectionCache.get(collectionKey); if (collection == null) { collection = new JacksonDBCollection<T, K>(getDB().getCollection(collectionKey.getName()), collectionKey.getType(), collectionKey.getKeyType(), objectMapper, features); referencedCollectionCache.put(collectionKey, collection); } return collection; }
/** * Wraps a DB collection in a JacksonDBCollection * * @param dbCollection The DB collection to wrap * @param type The type of objects to deserialise to * @param keyType The type of the objects key * @param view The JSON view to use for serialisation * @return The wrapped collection */ public static <T, K> JacksonDBCollection<T, K> wrap(DBCollection dbCollection, Class<T> type, Class<K> keyType, Class<?> view) { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setSerializationConfig(objectMapper.getSerializationConfig().withView(view)); MongoJacksonMapperModule.configure(objectMapper); return new JacksonDBCollection<T, K>(dbCollection, DEFAULT_OBJECT_MAPPER.constructType(type), DEFAULT_OBJECT_MAPPER.constructType(keyType), objectMapper, null); }
/** * Wraps a DB collection in a JacksonDBCollection * * @param dbCollection The DB collection to wrap * @param type The type of objects to deserialise to * @param keyType The type of the objects key * @param view The JSON view to use for serialisation * @return The wrapped collection */ public static <T, K> JacksonDBCollection<T, K> wrap(DBCollection dbCollection, Class<T> type, Class<K> keyType, Class<?> view) { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setSerializationConfig(objectMapper.getSerializationConfig().withView(view)); MongoJacksonMapperModule.configure(objectMapper); return new JacksonDBCollection<T, K>(dbCollection, DEFAULT_OBJECT_MAPPER.constructType(type), DEFAULT_OBJECT_MAPPER.constructType(keyType), objectMapper, null); }