/** * 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, null, features); }
/** * Wraps a DB collection in a JacksonDBCollection * * @param dbCollection * The DB collection to wrap * @param type * The type of objects to deserialize 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, null); }
/** * Wraps a DB collection in a JacksonDBCollection * * @param dbCollection * The DB collection to wrap * @param type * The type of objects to deserialize 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, 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 org.mongojack.internal.MongoJackModule#configure(com.fasterxml.jackson.databind.ObjectMapper)} . * * @param dbCollection * The DB collection to wrap * @param type * The type of objects to deserialize 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, null); }
/** * Wraps a DB collection in a JacksonDBCollection * * @param dbCollection * The DB collection to wrap * @param type * The type of objects to deserialize to * @param keyType * The type of the objects key * @param view * The JSON view to use for serialization * @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(); MongoJackModule.configure(objectMapper); return new JacksonDBCollection<T, K>(dbCollection, DEFAULT_OBJECT_MAPPER.constructType(type), DEFAULT_OBJECT_MAPPER.constructType(keyType), objectMapper, view, null); }
/** * Wraps a DB collection in a JacksonDBCollection * * @param dbCollection The DB collection to wrap * @param type The type of objects to deserialize to * @param keyType The type of the objects key * @param objectMapper The ObjectMapper to configure. * @param view The JSON view to use for serialization * @return The wrapped collection */ public static <T, K> JacksonDBCollection<T, K> wrap( DBCollection dbCollection, Class<T> type, Class<K> keyType, ObjectMapper objectMapper, Class<?> view) { MongoJackModule.configure(objectMapper); return new JacksonDBCollection<T, K>(dbCollection, objectMapper.constructType(type), objectMapper.constructType(keyType), objectMapper, view, 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, null, features); referencedCollectionCache.put(collectionKey, collection); } return collection; }