/** * Récupération d'une liste de publications en ordre * * @param p_Section * @param p_StartIndex * @param p_StopIndex * @param p_IsDescending * @return * @throws MappingException */ public static Collection sortPublications( Section p_Section, int p_StartIndex, int p_StopIndex, boolean p_IsDescending) throws MappingException { String ORDER_DESC_REQ = "SELECT sp.publication FROM org.nextime.ion.framework.business.impl.SectionPublicationImpl sp WHERE sp.section = $1 order by sp.index desc LIMIT $2 OFFSET $3 "; String ORDER_ASC_REQ = "SELECT sp.publication FROM org.nextime.ion.framework.business.impl.SectionPublicationImpl sp WHERE sp.section = $1 order by sp.index asc LIMIT $2 OFFSET $3 "; Date begindate = new Date(); List ret = new FastArrayList(); try { OQLQuery oql = Mapping.getInstance() .getDb() .getOQLQuery(p_IsDescending ? ORDER_DESC_REQ : ORDER_ASC_REQ); oql.bind(p_Section); oql.bind(p_StopIndex - p_StartIndex); oql.bind(p_StartIndex); QueryResults results = oql.execute(org.exolab.castor.jdo.Database.ReadOnly); while (results.hasMore()) { Publication p = (Publication) results.next(); ret.add(p); } } catch (Exception e) { Logger.getInstance().error("erreur lors du list sortPublications", Section.class, e); throw new MappingException(e.getMessage()); } Logger.getInstance() .log( " Temps consomé = " + (new Date().getTime() - begindate.getTime()) + " ms ", PublicationSorter.class); return ret; }
/** * Récupération d'une list des publications par date * * @param p_Section * @param p_Limit * @param p_Offset * @param is_Descending * @return * @throws MappingException */ public static Collection sortDatePublications( Section p_Section, int p_Limit, int p_Offset, boolean is_Descending) throws MappingException { String DATE_DESC_REQ = "SELECT sp.publication FROM org.nextime.ion.framework.business.impl.SectionPublicationImpl sp WHERE sp.section = $1 order by sp.publication.datePubli desc LIMIT $2 OFFSET $3 "; String DATE_ASC_REQ = "SELECT sp.publication FROM org.nextime.ion.framework.business.impl.SectionPublicationImpl sp WHERE sp.section = $1 order by sp.publication.datePubli asc LIMIT $2 OFFSET $3 "; ArrayList<Publication> ret = new ArrayList<Publication>(); try { OQLQuery oql = Mapping.getInstance().getDb().getOQLQuery((is_Descending) ? DATE_DESC_REQ : DATE_ASC_REQ); oql.bind(p_Section); oql.bind(p_Limit); oql.bind(p_Offset); QueryResults results = oql.execute(org.exolab.castor.jdo.Database.ReadOnly); while (results.hasMore()) { Publication p = (Publication) results.next(); ret.add(p); } } catch (Exception e) { Logger.getInstance().error("erreur lors du list des sortDatePublications", Section.class, e); throw new MappingException(e.getMessage()); } return ret; }
/** * This method is called by the tests and preform the actual concurrent modification test. * * @param accessMode the access mode that is used in the concurrent modification tests */ private void testDirtyIgnored(final AccessMode accessMode) throws PersistenceException, SQLException { OQLQuery oql; Sample object; QueryResults enumeration; // Open transaction in order to perform JDO operations _db.begin(); // Determine if test object exists, if not create it. // If it exists, set the name to some predefined value // that this test will later override. oql = _db.getOQLQuery("SELECT object FROM " + Sample.class.getName() + " object WHERE id = $1"); oql.bind(Sample.DEFAULT_ID); enumeration = oql.execute(); if (enumeration.hasMore()) { object = (Sample) enumeration.next(); LOG.debug("Retrieved object: " + object); object.setValue1(Sample.DEFAULT_VALUE_1); object.setValue2(Sample.DEFAULT_VALUE_2); } else { object = new Sample(); LOG.debug("Creating new object: " + object); _db.create(object); } _db.commit(); // Open a new transaction in order to conduct test _db.begin(); oql.bind(new Integer(Sample.DEFAULT_ID)); object = (Sample) oql.execute(accessMode).nextElement(); object.setValue2(JDO_VALUE); // Perform direct JDBC access and override the value of that table if (accessMode != Database.DbLocked) { _conn .createStatement() .execute( "UPDATE tc0x_sample SET value2='" + JDBC_VALUE + "' WHERE id=" + Sample.DEFAULT_ID); LOG.debug("Updated test object from JDBC"); } // Commit JDO transaction, this should report object modified exception LOG.debug("Commit update: no dirty checking field not modified"); try { _db.commit(); LOG.debug("OK: ObjectModifiedException not thrown"); } catch (ObjectModifiedException ex) { if (_db.isActive()) { _db.rollback(); } LOG.error("Error: ObjectModifiedException thrown", ex); fail("ObjectModifiedException thrown"); } }
/** * Récupère les paramètres passés au controleur. * * @throws ServletException - * @see owep.controle.CControleurBase#initialiserParametres() */ public void initialiserParametres() throws ServletException { OQLQuery lRequete; // Requête à réaliser sur la base QueryResults lResultat; // Résultat de la requête sur la base try { lListeTaches = new ArrayList(); lListeTachesImprevues = new ArrayList(); if (mSession.getIteration() != null) { // pour chaque tache for (int i = 0; i < mCollaborateur.getNbTaches(); i++) { // on regarde si toutes les conditions pour que la tache soit prete sont vérifiées MTache lTache = mCollaborateur.getTache(i); int lIdTache = lTache.getId(); // Récupère la liste des tâches du collaborateur. lRequete = getBaseDonnees() .getOQLQuery( "select TACHE from owep.modele.execution.MTache TACHE where mId = $1"); lRequete.bind(lIdTache); lResultat = lRequete.execute(); lTache = (MTache) lResultat.next(); // on vérifie la tâche verifierTache(lTache); } // pour chaque tâche imprévue for (int i = 0; i < mCollaborateur.getNbTachesImprevues(); i++) { // on regarde si toutes les conditions pour que la tache imprévue soit prete sont // vérifiées MTacheImprevue lTacheImprevue = mCollaborateur.getTacheImprevue(i); int lIdTacheImprevue = lTacheImprevue.getId(); // Récupère la liste des tâches du collaborateur. lRequete = getBaseDonnees() .getOQLQuery( "select TACHEIMPREVUE from owep.modele.execution.MTacheImprevue TACHEIMPREVUE where mId = $1"); lRequete.bind(lIdTacheImprevue); lResultat = lRequete.execute(); lTacheImprevue = (MTacheImprevue) lResultat.next(); // Si la tache correspond à l'itération sélectionnée if (lTacheImprevue.getIteration().getId() == mSession.getIteration().getId()) { lListeTachesImprevues.add(lTacheImprevue); } } mCollaborateur.setListe(new Integer(0), lListeTaches); mCollaborateur.setListe(new Integer(1), lListeTachesImprevues); } } catch (Exception eException) { eException.printStackTrace(); throw new ServletException(CConstante.EXC_TRAITEMENT); } }
/** * Reinitaliser les position de publication dans la section * * @param p * @param s * @throws MappingException */ public static void removePublication(Publication p, Section s) throws MappingException { SectionPublication impl = ((PublicationImpl) p).findSectionPublication(s); try { if (impl != null) { // mettre à jour les autres en diminuant int currentIndex = impl.getIndex(); OQLQuery oql = Mapping.getInstance() .getDb() .getOQLQuery( "SELECT sp FROM org.nextime.ion.framework.business.impl.SectionPublicationImpl sp " + " WHERE sp.section = $1 AND sp.index > $2 "); oql.bind(s.getId()); oql.bind(currentIndex); QueryResults results = oql.execute(); while (results.hasMore()) { SectionPublication sp = (SectionPublication) results.next(); sp.setIndex(sp.getIndex() - 1); } } } catch (PersistenceException e) { Logger.getInstance() .error( "Error de mettre à jour les sections_publications la publicaiton ", PublicationSorter.class, e); throw new MappingException( "Error de mettre à jour les sections_publications la publicaiton "); } return; /* try { Vector publications = s.listPublications(); int index = Integer.parseInt(p.getMetaData("index_" + s.getId()) + ""); for (int i = 0; i < publications.size(); i++) { Publication tp = (Publication) publications.get(i); int tindex = Integer.parseInt(tp.getMetaData("index_" + s.getId()) + ""); if (tindex > index) { tp.setMetaData("index_" + s.getId(), (tindex - 1) + ""); } } } catch (Exception e) { //e.printStackTrace(); org.nextime.ion.framework.logger.Logger.getInstance().error( e.getMessage(), PublicationSorter.class); }*/ }
public static Collection sortDatePublications( List p_SectionIds, int p_Limit, int p_Offset, boolean is_Descending) throws MappingException { String ids = buildListId(p_SectionIds); String DATE_DESC_REQ = "SELECT sp.publication FROM org.nextime.ion.framework.business.impl.SectionPublicationImpl sp " + " WHERE sp.section.id IN LIST " + ids + " order by sp.publication.datePubli desc LIMIT $1 OFFSET $2"; String DATE_ASC_REQ = "SELECT sp.publication FROM org.nextime.ion.framework.business.impl.SectionPublicationImpl sp " + " WHERE sp.section.id IN LIST " + ids + " order by sp.publication.datePubli LIMIT $1 OFFSET $2"; int offset = p_Offset; int limit = offset + GAP; ArrayList<Publication> ret = new ArrayList<Publication>(); boolean hasResultat = true; try { while (ret.size() < p_Limit && hasResultat) { OQLQuery oql = Mapping.getInstance() .getDb() .getOQLQuery((is_Descending) ? DATE_DESC_REQ : DATE_ASC_REQ); oql.bind(limit); oql.bind(offset); QueryResults results = oql.execute(org.exolab.castor.jdo.Database.ReadOnly); hasResultat = results.hasMore(); while (results.hasMore() && ret.size() < p_Limit) { Publication p = (Publication) results.next(); if (!ret.contains(p)) { ret.add(p); } } offset = limit + 1; limit = offset + GAP; } } catch (Exception e) { Logger.getInstance() .error("erreur lors du list des sortDatePublications", PublicationSorter.class, e); throw new MappingException(e.getMessage()); } return ret; }
/** Get the SystemUser with the userName */ public SystemUserVO getReadOnlySystemUserVOWithName(String userName, Database db) throws SystemException, Bug { SystemUserVO systemUserVO = null; try { OQLQuery oql = db.getOQLQuery( "SELECT u FROM org.infoglue.cms.entities.management.impl.simple.SmallSystemUserImpl u WHERE u.userName = $1"); oql.bind(userName); QueryResults results = oql.execute(Database.ReadOnly); if (results.hasMore()) { SystemUser systemUser = (SystemUser) results.next(); systemUserVO = systemUser.getValueObject(); } results.close(); oql.close(); } catch (Exception e) { throw new SystemException( "An error occurred when we tried to fetch " + userName + " Reason:" + e.getMessage(), e); } return systemUserVO; }
/** * Returns the Language with the given languageCode fetched within a given transaction. * * @param code * @param db * @return * @throws SystemException * @throws Bug */ public Language getLanguageWithCode(String code, Database db) throws SystemException, Bug { Language language = null; try { OQLQuery oql = db.getOQLQuery( "SELECT f FROM org.infoglue.cms.entities.management.impl.simple.LanguageImpl f WHERE f.languageCode = $1"); oql.bind(code); QueryResults results = oql.execute(); this.logger.info("Fetching entity in read/write mode" + code); if (results.hasMore()) { language = (Language) results.next(); } results.close(); oql.close(); } catch (Exception e) { throw new SystemException( "An error occurred when we tried to fetch a named language. Reason:" + e.getMessage(), e); } return language; }
/** * This method returns all languages for a certain repository. * * @param repositoryId * @return * @throws SystemException * @throws Exception */ public List getLanguageVOList(Integer repositoryId, Database db) throws SystemException, Exception { String key = "" + repositoryId + "_allLanguages"; logger.info("key:" + key); List list = (List) CacheController.getCachedObject("languageCache", key); if (list != null) { logger.info("There was an cached list:" + list); } else { list = new ArrayList(); OQLQuery oql = db.getOQLQuery( "SELECT l FROM org.infoglue.cms.entities.management.impl.simple.LanguageImpl l WHERE l.repositoryLanguages.repository = $1 ORDER BY l.repositoryLanguages.sortOrder, l.languageId"); oql.bind(repositoryId); QueryResults results = oql.execute(Database.ReadOnly); while (results.hasMore()) { Language language = (Language) results.next(); list.add(language.getValueObject()); } results.close(); oql.close(); if (list.size() > 0) CacheController.cacheObject("languageCache", key, list); } return list; }
/** Get the SystemUser with the userName */ public SystemUser getSystemUserWithName(String userName, Database db) throws SystemException, Bug { SystemUser systemUser = null; OQLQuery oql; try { oql = db.getOQLQuery( "SELECT u FROM org.infoglue.cms.entities.management.impl.simple.SystemUserImpl u WHERE u.userName = $1"); oql.bind(userName); QueryResults results = oql.execute(); this.logger.info("Fetching entity in read/write mode" + userName); if (results.hasMore()) { systemUser = (SystemUser) results.next(); logger.info("found one:" + systemUser.getFirstName()); } results.close(); oql.close(); } catch (Exception e) { throw new SystemException( "An error occurred when we tried to fetch " + userName + " Reason:" + e.getMessage(), e); } return systemUser; }
public void testOQLQueryWithParameter() throws Exception { Database database = _category.getDatabase(); database.begin(); OQLQuery query = database.getOQLQuery( "SELECT count(laptop.id) FROM " + Laptop.class.getName() + " laptop WHERE laptop.resolution = $1"); query.bind("1024"); QueryResults results = query.execute(); if (results.hasMore()) { Object obj = results.next(); Long count = null; if (obj instanceof Long) { count = (Long) obj; } else if (obj instanceof Integer) { count = new Long(((Integer) obj).intValue()); } else if (obj instanceof BigDecimal) { count = new Long(((BigDecimal) obj).longValue()); } assertNotNull(count); assertEquals(1, count.intValue()); } database.commit(); database.close(); }
/** * Récupération d'une liste des publications par ordre naturelle * * @param s * @return * @throws MappingException */ public static Collection sortPublications(Section s) throws MappingException { Date begindate = new Date(); List ret = new FastArrayList(); try { OQLQuery oql = Mapping.getInstance() .getDb() .getOQLQuery( "SELECT sp.publication FROM org.nextime.ion.framework.business.impl.SectionPublicationImpl sp WHERE sp.section = $1 order by sp.index desc "); oql.bind(s); QueryResults results = oql.execute(org.exolab.castor.jdo.Database.ReadOnly); while (results.hasMore()) { Publication p = (Publication) results.next(); ret.add(p); } } catch (Exception e) { Logger.getInstance().error("erreur lors du list des sections root", Section.class, e); throw new MappingException(e.getMessage()); } Logger.getInstance() .log( " Temps consomé = " + (new Date().getTime() - begindate.getTime()) + " ms ", PublicationSorter.class); return ret; }
public void runTest() throws PersistenceException, SQLException { OQLQuery oql; TestObject object; QueryResults enumeration; _db.begin(); // Determine if test object exists, if not create it. // If it exists, set the name to some predefined value // that this test will later override. oql = _db.getOQLQuery("SELECT object FROM jdo.TestObject object WHERE id = $1"); oql.bind(50); enumeration = oql.execute(); if (enumeration.hasMore()) { object = (TestObject) enumeration.next(); stream.println("Retrieved object: " + object); object.setValue1(TestObject.DefaultValue1); object.setValue2(TestObject.DefaultValue2); } else { object = new TestObject(); object.setId(50); stream.println("Creating new object: " + object); _db.create(object); } oql.close(); _db.commit(); try { stream.println("CALL SQL query"); _db.begin(); oql = _db.getOQLQuery( "CALL SQL SELECT ID,VALUE1,VALUE2 FROM TEST_TABLE WHERE (ID = $1) AS jdo.TestObject"); oql.bind(50); enumeration = oql.execute(); if (enumeration.hasMore()) { object = (TestObject) enumeration.next(); stream.println("Retrieved object: " + object); } else { fail("test object not found"); } oql.close(); _db.commit(); } catch (Exception e) { fail("Exception thrown " + e); } }
private void iterateEquipments(final State state, final AccessMode mode) throws Exception { _queryEquipment.bind(state.getId()); QueryResults results = _queryEquipment.execute(mode); while (results.hasMore()) { iterateServices((Equipment) results.next(), mode); } }
private void iterateStates(final Locked locked, final AccessMode mode) throws Exception { _queryState.bind(locked.getId()); QueryResults results = _queryState.execute(mode); while (results.hasMore()) { iterateEquipments((State) results.next(), mode); } }
private void iterateServices(final Equipment equipment, final AccessMode mode) throws Exception { _queryService.bind(equipment.getId()); QueryResults results = _queryService.execute(mode); while (results.hasMore()) { results.next(); } }
private void iterateStatesOID(final Locked locked, final AccessMode mode) throws Exception { _queryStateOID.bind(locked.getId()); QueryResults results = _queryStateOID.execute(mode); while (results.hasMore()) { OID oid = (OID) results.next(); iterateEquipmentsOID((State) _db.load(State.class, oid.getId(), mode), mode); } }
private void iterateEquipmentsOID(final State state, final AccessMode mode) throws Exception { _queryEquipmentOID.bind(state.getId()); QueryResults results = _queryEquipmentOID.execute(Database.ReadOnly); while (results.hasMore()) { OID oid = (OID) results.next(); iterateServicesOID((Equipment) _db.load(Equipment.class, oid.getId(), mode), mode); } }
private void iterateServicesOID(final Equipment equipment, final AccessMode mode) throws Exception { _queryServiceOID.bind(equipment.getId()); QueryResults results = _queryServiceOID.execute(Database.ReadOnly); while (results.hasMore()) { OID oid = (OID) results.next(); _db.load(Service.class, oid.getId(), mode); } }
public void test(final Database db) throws Exception { db.begin(); String s = "SELECT e FROM " + Employee.class.getName() + " e " + "WHERE e.holiday > $1"; OQLQuery qry = db.getOQLQuery(s); qry.bind(50.0); QueryResults rst = qry.execute(); while (rst.hasMore()) { Employee emp = (Employee) rst.next(); emp.setHoliday(50.0f); } rst.close(); qry.close(); db.commit(); }
/** * Récupère les données nécessaire au controleur dans la base de données. * * @throws ServletException Si une erreur survient durant la connexion * @see owep.controle.CControleurBase#initialiserBaseDonnees() */ public void initialiserBaseDonnees() throws ServletException { OQLQuery lRequete; // Requête à réaliser sur la base QueryResults lResultat; // Résultat de la requête sur la base try { // Récupère le collaborateur connecté HttpSession session = getRequete().getSession(true); mSession = (Session) session.getAttribute("SESSION"); mCollaborateur = mSession.getCollaborateur(); getBaseDonnees().begin(); int idCollab = mCollaborateur.getId(); // Récupère la liste des tâches du collaborateur. lRequete = getBaseDonnees() .getOQLQuery( "select COLLABORATEUR from owep.modele.execution.MCollaborateur COLLABORATEUR where mId = $1"); lRequete.bind(idCollab); lResultat = lRequete.execute(); mCollaborateur = (MCollaborateur) lResultat.next(); lProjet = mSession.getProjet(); int idProjet = lProjet.getId(); // Récupère le projet dans la BD lRequete = getBaseDonnees() .getOQLQuery( "select PROJET from owep.modele.execution.MProjet PROJET where mId = $1"); lRequete.bind(idProjet); lResultat = lRequete.execute(); lProjet = (MProjet) lResultat.next(); } catch (Exception eException) { eException.printStackTrace(); throw new ServletException(CConstante.EXC_TRAITEMENT); } }
public void testQueryEntity() throws Exception { Database db = _jdo.getDatabase(); db.begin(); OQLQuery query = db.getOQLQuery("SELECT entity FROM " + Entity.class.getName() + " entity WHERE id = $1"); query.bind(new Integer(1)); QueryResults results = query.execute(); Entity entity = (Entity) results.next(); assertNotNull(entity); assertEquals(new Integer(1), entity.getId()); db.commit(); db.close(); }
/** This method returns the master language within an transaction. */ public Language getMasterLanguage(Database db, Integer repositoryId) throws SystemException, Exception { Language language = null; OQLQuery oql = db.getOQLQuery( "SELECT l FROM org.infoglue.cms.entities.management.impl.simple.LanguageImpl l WHERE l.repositoryLanguages.repository.repositoryId = $1 ORDER BY l.repositoryLanguages.sortOrder, l.languageId"); oql.bind(repositoryId); QueryResults results = oql.execute(Database.ReadOnly); if (results.hasMore()) { language = (Language) results.next(); } results.close(); oql.close(); return language; }
public List<SystemUserVO> getSystemUserVOListWithPassword(String password, Database db) throws SystemException, Bug, Exception { List<SystemUserVO> filteredVOList = new ArrayList<SystemUserVO>(); OQLQuery oql = db.getOQLQuery( "SELECT u FROM org.infoglue.cms.entities.management.impl.simple.SystemUserImpl u WHERE u.password = $1 ORDER BY u.userName"); oql.bind(password); QueryResults results = oql.execute(Database.ReadOnly); while (results.hasMore()) { SystemUser extranetUser = (SystemUser) results.next(); filteredVOList.add(extranetUser.getValueObject()); } results.close(); oql.close(); return filteredVOList; }
public void setUp() throws PersistenceException { _jdo = _category.getJDO(); _jdo.setCallbackInterceptor(_i); _jdo.setInstanceFactory(_i); _db = _category.getDatabase(); OQLQuery oql; QueryResults qres; LOG.debug("Delete everything"); _db.begin(); oql = _db.getOQLQuery("SELECT p FROM " + TimeStampableObject.class.getName() + " p WHERE id=$1"); oql.bind(TimeStampableObject.DEFAULT_ID); qres = oql.execute(); while (qres.hasMore()) { _db.remove(qres.next()); } oql.close(); _db.commit(); }
public SystemUserVO getSystemUserVO(Database db, String userName, String password) throws SystemException, Exception { SystemUserVO systemUserVO = null; OQLQuery oql = db.getOQLQuery( "SELECT u FROM org.infoglue.cms.entities.management.impl.simple.SmallSystemUserImpl u WHERE u.userName = $1 AND u.password = $2"); oql.bind(userName); oql.bind(password); QueryResults results = oql.execute(Database.ReadOnly); if (results.hasMore()) { SystemUser systemUser = (SystemUser) results.next(); systemUserVO = systemUser.getValueObject(); } results.close(); oql.close(); return systemUserVO; }
public SystemUser getSystemUser(Database db, String userName, String password) throws SystemException, Exception { SystemUser systemUser = null; OQLQuery oql = db.getOQLQuery( "SELECT u FROM org.infoglue.cms.entities.management.impl.simple.SystemUserImpl u WHERE u.userName = $1 AND u.password = $2"); oql.bind(userName); oql.bind(password); QueryResults results = oql.execute(); this.logger.info("Fetching entity in read/write mode" + userName); if (results.hasMore()) { systemUser = (SystemUser) results.next(); logger.info("found one:" + systemUser.getFirstName()); } results.close(); oql.close(); return systemUser; }
public void tearDown() throws PersistenceException { if (_db.isActive()) { _db.rollback(); } OQLQuery oql; QueryResults qres; LOG.debug("Delete everything"); _db.begin(); oql = _db.getOQLQuery("SELECT p FROM " + TimeStampableObject.class.getName() + " p WHERE id=$1"); oql.bind(TimeStampableObject.DEFAULT_ID); qres = oql.execute(); while (qres.hasMore()) { _db.remove(qres.next()); } oql.close(); _db.commit(); _db.close(); _jdo.setCallbackInterceptor(null); }
/** Get if the SystemUser with the userName exists */ public boolean systemUserExists(String userName, Database db) throws SystemException, Bug { boolean systemUserExists = false; try { OQLQuery oql = db.getOQLQuery( "SELECT u FROM org.infoglue.cms.entities.management.impl.simple.SmallSystemUserImpl u WHERE u.userName = $1"); oql.bind(userName); QueryResults results = oql.execute(Database.ReadOnly); if (results.hasMore()) { systemUserExists = true; } results.close(); oql.close(); } catch (Exception e) { throw new SystemException( "An error occurred when we tried to fetch " + userName + " Reason:" + e.getMessage(), e); } return systemUserExists; }
/** * This method is called by the tests and preform the actual concurrent modification test. * * @param accessMode the access mode that is used in the concurrent modification tests */ private void testDirtyChecked(final AccessMode accessMode) throws PersistenceException, SQLException { OQLQuery oql; Sample object; QueryResults enumeration; // Open transaction in order to perform JDO operations _db.begin(); // Determine if test object exists, if not create it. // If it exists, set the name to some predefined value // that this test will later override. oql = _db.getOQLQuery("SELECT object FROM " + Sample.class.getName() + " object WHERE id = $1"); oql.bind(Sample.DEFAULT_ID); enumeration = oql.execute(); if (enumeration.hasMore()) { object = (Sample) enumeration.next(); LOG.debug("Retrieved object: " + object); object.setValue1(Sample.DEFAULT_VALUE_1); object.setValue2(Sample.DEFAULT_VALUE_2); } else { object = new Sample(); LOG.debug("Creating new object: " + object); _db.create(object); } _db.commit(); // Open a new transaction in order to conduct test _db.begin(); oql.bind(new Integer(Sample.DEFAULT_ID)); object = (Sample) oql.execute(accessMode).nextElement(); object.setValue1(JDO_VALUE); // Perform direct JDBC access and override the value of that table if (accessMode != Database.DbLocked) { _conn .createStatement() .execute( "UPDATE tc0x_sample SET value1='" + JDBC_VALUE + "' WHERE id=" + Sample.DEFAULT_ID); LOG.debug("OK: Updated object from JDBC"); } else { Thread th = new Thread() { public void run() { Connection conn = null; try { conn = _category.getJDBCConnection(); conn.createStatement() .execute( "UPDATE tc0x_sample SET value1='" + JDBC_VALUE + "' WHERE id=" + Sample.DEFAULT_ID); conn.close(); } catch (Exception ex) { } finally { try { if (conn != null) { conn.close(); } } catch (Exception ex) { } } } }; th.start(); synchronized (this) { try { wait(5000); if (th.isAlive()) { th.interrupt(); LOG.debug("OK: Cannot update object from JDBC"); } else { LOG.error("Error: Updated object from JDBC"); fail("Updated test object from JDBC"); } } catch (InterruptedException ex) { } } } // Commit JDO transaction, this should report object modified exception LOG.debug("Committing JDO update: dirty checking field modified"); if (accessMode != Database.DbLocked) { try { _db.commit(); LOG.error("Error: ObjectModifiedException not thrown"); fail("ObjectModifiedException not thrown"); } catch (ObjectModifiedException ex) { LOG.debug("OK: ObjectModifiedException thrown"); } } else { try { _db.commit(); LOG.debug("OK: ObjectModifiedException not thrown"); // After _db.commit the concurrent update will be performed. // and we need to undo it. _conn .createStatement() .execute( "UPDATE tc0x_sample SET value1='" + JDO_VALUE + "' WHERE id=" + Sample.DEFAULT_ID); } catch (ObjectModifiedException ex) { _db.rollback(); LOG.error("Error: ObjectModifiedException thrown"); fail("ObjectModifiedException not thrown"); } } }