So is it ok to got with Morphia 1.0.1 + Mongo java driver 2.14.2, I haven't tested the application yet, just the build.
Thanks,
Daniel
--
You received this message because you are subscribed to the Google Groups "Morphia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to morphia+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jeff, thanks for your interest.
We're are planning for a limited production release in a few months and the current MongoDB server used on beta-testing (real users/real data but limited numbers) turns out to be recently EOL'd as it happens (v2.4) so the idea is to go with something that does not break the code, is not too old and preferably go with MongoDB 3.2 server).
This is an edited version of a write up I made for the decision makers. Although long-ish it might help other users:
Lowest risk but these will just buys us some time. See support policy.
Builds OK and from what I've gathered it's doable as it supposed to be forward-compatible but just lacking the new v3.2 bells & whistles:
MJD 3.2 breaks the build and requires non-trivial refactoring for which we don't have time/resources at the moment. Some issues are:
public class EntityId<T> extends ObjectId
ObjectId
has been made final
so our EntityId
class breaks and it's used all over the place. THIS IS THE BIGGEST PROBLEMObjectId.massageToObjectId(String)
has been removedMorphia 1.1.0 breaks the build
org.mongodb.morphia.Morphia
public <T> T fromDBObject(final Class<T> entityClass, final DBObject dbObject)
is changed to –>public <T> T fromDBObject(final Datastore datastore, final Class<T> entityClass, final DBObject dbObject)
and then the javadoc for the new version goes on saying This method is primarily an internal method. Reliance on this method may break your application in future releases.Hello Jeff,
Thanks for you reply. We have made our own type-safe ID class first and foremost to prevent usage errors and secondly to improve readability.
We send a lot of IDs between different services in the system so our code prevents from sending let's say, a User ID into a method that expects a Project ID.
So a method called:
void doStuff(EntityId<User> userId, EntityId<Project> projectId, EntityId<Task> taskId)
is IMHO far less error prone and more readable than its non type-safe equivalent:
void doStuff(ObjectId userId, ObjectId projectId, ObjectId taskId)
Especially since the latter would still work even if we, for example, switch userId
with projectId
; it would just unknowingly return the wrongful data.
The fact that not everyone seems to make their IDs type-safe is kind of mystifying as in our case the alternative would be to unit-test everything just to check that IDs haven’t been accidentally swapped… a huge pain in the neck.
import org.mongodb.morphia.query.Criteria;
import org.mongodb.morphia.query.Query;
public class TaskDAO extends AbstractDAO<CWTask> {
public static final String PROJECT_ID_KEY = "projectId";
public static final String ASSIGNEES_FIELD = "assignees";
public static final String ASSIGNEES_ROLE_ID_KEY = "assignees.roleId";
...
public void removeAssignedRoleForTasks(EntityId<CWProject> projectId, EntityId<CWRole> roleId) {
Query<CWTask> q = q();
applyProjectCriteria(q, projectId);
applyAssignedToRoleCriteria(q, roleId);
set(q, ASSIGNEES_FIELD, new ArrayList<>());
}
...
protected CriteriaContainer applyProjectCriteria(Query<CWTask> q, EntityId<CWProject> projectId) {
if (projectId == null) {
return q.or(
q.criteria(PROJECT_ID_KEY).doesNotExist(),
q.criteria(PROJECT_ID_KEY).equal(null)
);
} else {
return q.criteria(PROJECT_ID_KEY).equal(projectId);
}
}
...
protected CriteriaContainer applyAssignedToRoleCriteria(Query<CWTask> q, EntityId<CWRole> roleId) {
return q.criteria(ASSIGNEES_ROLE_ID_KEY).hasThisOne(roleId);
}
I know both of options involve a bit of refactoring but it's what comes to mind.
--