DAO { public static <T> T save(T obj) { return asWrapper(obj).save(); } private  DAO(); static IODocumentWrapper asWrapper(Object obj); static ODocument asDocument(Object obj); static T loadFromDocument(T obj, ODocument doc); static T save(T obj); static T reload(T obj); static T create(Class<T> interfaceClass, Class<?>... additionalInterfaces); static T create(Class<T> interfaceClass, String className, Class<?>... additionalInterfaces); static T provide(Class<T> interfaceClass, ORID iRID, Class<?>... additionalInterfaces); static T provide(Class<T> interfaceClass, ODocument doc, Class<?>... additionalInterfaces); @SuppressWarnings("unchecked") static T provide(Class<T> interfaceClass, ODocumentWrapper docWrapper, Class<?>... additionalInterfaces); @SuppressWarnings("unchecked") static T dao(Class<T> interfaceClass, Class<?>... additionalInterfaces); static OSchemaHelper describe(OSchemaHelper helper, Class<?>... classes);  }
@Test @Sudo public void testConvertions() { ITestDAO dao = tester.getApplication().getServiceInstance(ITestDAO.class); ODocument doc = dao.findSingleAsDocument("root"); IDAOTestClass root = dao.findSingleAsDAO("root"); assertEquals(doc.field("name"), root.getName()); List<ODocument> listDocs = dao.findAllAsDocument(); List<IDAOTestClass> listObjs = dao.findAllAsDAO(); assertEquals(listDocs.size(), listObjs.size()); assertTrue(listDocs.get(0) instanceof ODocument); assertTrue(listObjs.get(0) instanceof IDAOTestClass); assertConsistent(root.getChild(), root.getChildAsDocuments(), 5); List<ODocument> allExceptOneChild = root.getChildAsDocuments(); allExceptOneChild.remove(0); root.setChildAsDocuments(allExceptOneChild); root.save(); assertConsistent(root.getChild(), root.getChildAsDocuments(), 4); List<IDAOTestClass> allExceptOneMoreChild = new ArrayList<IDAOTestClass>(root.getChild()); allExceptOneMoreChild.remove(0); root.setChild(allExceptOneMoreChild); root.save(); assertConsistent(root.getChild(), root.getChildAsDocuments(), 3); assertConsistent(root.getLinkMap(), root.getLinkMapAsDocuments(), 5); Map<String, ODocument> mapDocs = root.getLinkMapAsDocuments(); Iterator<Map.Entry<String, ODocument>> itDocs = mapDocs.entrySet().iterator(); itDocs.next(); itDocs.remove(); root.setLinkMapAsDocuments(mapDocs); root.save(); assertConsistent(root.getLinkMap(), root.getLinkMapAsDocuments(), 4); Map<String, IDAOTestClass> map = new HashMap<String, IDAOTestClass>(root.getLinkMap()); Iterator<Map.Entry<String, IDAOTestClass>> it = map.entrySet().iterator(); it.next(); it.remove(); root.setLinkMap(map); root.save(); assertConsistent(root.getLinkMap(), root.getLinkMapAsDocuments(), 3); }