/** * Updates the collection value on a Key with the mapped value on the Key's type Class * * @param key the Key to update * @return the collection name on the Key */ public String updateCollection(final Key key) { if (key.getCollection() == null && key.getType() == null) { throw new IllegalStateException("Key is invalid! " + toString()); } else if (key.getCollection() == null) { key.setCollection(getMappedClass(key.getType()).getCollectionName()); } return key.getCollection(); }
/** * Converts a Key to a DBRef * * @param key the Key to convert * @return the DBRef */ public DBRef keyToDBRef(final Key key) { if (key == null) { return null; } if (key.getType() == null && key.getCollection() == null) { throw new IllegalStateException("How can it be missing both?"); } if (key.getCollection() == null) { key.setCollection(getCollectionName(key.getType())); } Object id = key.getId(); if (isMapped(id.getClass())) { id = toMongoObject(id, true); } return new DBRef(key.getCollection(), id); }