Beispiel #1
0
  /**
   * 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);
    }
  }
Beispiel #3
0
  public void testQueryComputers() throws Exception {
    String[] classNames = {
      "ctf.jdo.tc9x.Laptop", "ctf.jdo.tc9x.Laptop", "ctf.jdo.tc9x.Server", "ctf.jdo.tc9x.Server"
    };

    Database database = _category.getDatabase();

    database.begin();
    OQLQuery query =
        database.getOQLQuery(
            "select computer from "
                + Computer.class.getName()
                + " as computer order by computer.id");
    QueryResults results = query.execute();

    if (results.hasMore()) {
      int counter = 1;
      while (results.hasMore()) {
        Computer computer = (Computer) results.next();
        assertNotNull(computer);
        assertEquals(counter, computer.getId());
        assertEquals(classNames[counter - 1], computer.getClass().getName());

        counter += 1;
      }
    } else {
      fail("Query does not return any Computer instances.");
    }
    database.commit();

    database.close();
  }
  public List getFilteredSystemUserList(String searchString, Database db)
      throws SystemException, Bug, Exception {
    List filteredList = new ArrayList();

    OQLQuery oql =
        db.getOQLQuery(
            "SELECT u FROM org.infoglue.cms.entities.management.impl.simple.SystemUserImpl u ORDER BY u.userName");

    QueryResults results = oql.execute(Database.ReadOnly);

    while (results.hasMore()) {
      SystemUser extranetUser = (SystemUser) results.next();
      boolean include = false;
      if (searchString == null || searchString.equals("")) {
        include = true;
      } else {
        if (extranetUser.getFirstName().toLowerCase().indexOf(searchString.toLowerCase()) > -1)
          include = true;
        else if (extranetUser.getLastName().toLowerCase().indexOf(searchString.toLowerCase()) > -1)
          include = true;
        else if (extranetUser.getUserName().toLowerCase().indexOf(searchString.toLowerCase()) > -1)
          include = true;
        else if (extranetUser.getEmail().toLowerCase().indexOf(searchString.toLowerCase()) > -1)
          include = true;
      }

      if (include) filteredList.add(extranetUser);
    }

    results.close();
    oql.close();

    return filteredList;
  }
  /** 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;
  }
 /**
  * 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 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;
 }
Beispiel #8
0
  public void testQueryLaptops() throws Exception {
    Database database = _category.getDatabase();

    database.begin();
    OQLQuery query =
        database.getOQLQuery("select l from " + Laptop.class.getName() + " as l order by l.id");
    QueryResults results = query.execute();

    if (results.hasMore()) {
      int counter = 1;
      Laptop laptop = null;
      while (results.hasMore()) {
        laptop = (Laptop) results.next();
        assertNotNull(laptop);
        assertEquals(counter, laptop.getId());

        counter += 1;
      }
    } else {
      fail("Query does not return any Laptop instances.");
    }
    database.commit();

    database.close();
  }
Beispiel #9
0
  public void testQueryProducts() throws Exception {
    String[] classNames = {
      "ctf.jdo.tc9x.Laptop",
      "ctf.jdo.tc9x.Laptop",
      "ctf.jdo.tc9x.Server",
      "ctf.jdo.tc9x.Server",
      "ctf.jdo.tc9x.Truck"
    };

    Database database = _category.getDatabase();

    database.begin();
    OQLQuery query =
        database.getOQLQuery(
            "select product from " + Product.class.getName() + " as product order by product.id");
    QueryResults results = query.execute();

    if (results.hasMore()) {
      int counter = 1;
      while (results.hasMore()) {
        Product product = (Product) results.next();
        assertNotNull(product);
        assertEquals(counter, product.getId());
        assertEquals(classNames[counter - 1], product.getClass().getName());

        counter += 1;
      }
    } else {
      fail("Query does not return any Product instances.");
    }
    database.commit();

    database.close();
  }
  /**
   * 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 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;
  }
Beispiel #12
0
  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 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;
  }
  /**
   * 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;
  }
Beispiel #15
0
  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);
    }
  }
Beispiel #16
0
  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);
    }
  }
Beispiel #17
0
  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);
    }
  }
Beispiel #18
0
  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();
    }
  }
Beispiel #19
0
  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);
    }
  }
Beispiel #20
0
  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);
    }
  }
Beispiel #21
0
  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);
    }
  }
Beispiel #22
0
  public void test() throws Exception {
    Database db = getJDOManager(DBNAME, MAPPING).getDatabase();

    db.begin();
    LOG.info("Begin transaction to query log entries");

    OQLQuery oql = db.getOQLQuery("SELECT e FROM " + LogEntry.class.getName() + " e");

    QueryResults results = oql.execute();
    while (results.hasMore()) {
      LogEntry entry = (LogEntry) results.next();
      int id = entry.getId().intValue();
      boolean isRefering = (entry instanceof ReferingLogEntry);
      boolean isException = (entry.getException() != null);

      if (LOG.isDebugEnabled()) {
        LOG.debug(id + "/" + isRefering + "/" + isException);
      }

      switch (id) {
        case 1:
        case 2:
        case 7:
        case 9:
        case 10:
        case 12:
        case 15:
          assertFalse(isRefering);
          assertFalse(isException);
          break;
        case 3:
        case 4:
        case 8:
        case 13:
          assertFalse(isRefering);
          assertTrue(isException);
          break;
        case 5:
        case 6:
        case 11:
        case 14:
          assertTrue(isRefering);
          assertFalse(isException);
          break;
        default:
          fail();
      }
    }

    LOG.info("End transaction to query log entries");
    db.commit();
    db.close();
  }
  /**
   * 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);
    }*/
  }
Beispiel #24
0
 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 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;
  }
Beispiel #27
0
  public void testQuery() throws Exception {
    Database database;

    // create some products
    database = _category.getDatabase();
    database.begin();

    database.create(new Product(1, "LCD", KindEnum.MONITOR));
    database.create(new Product(2, "Laser", KindEnum.PRINTER));
    database.create(new Product(3, "Desktop", KindEnum.COMPUTER));
    database.create(new Product(4, "Notebook", KindEnum.COMPUTER));

    database.commit();
    database.close();

    // query and delete all product
    database = _category.getDatabase();
    database.begin();

    Product pq;
    OQLQuery query =
        database.getOQLQuery(
            "select p from " + jdo.tc167.Product.class.getName() + " p order by p.id");
    QueryResults results = query.execute();

    pq = (Product) results.next();
    assertEquals(pq, new Product(1, "LCD", KindEnum.MONITOR));
    database.remove(pq);

    pq = (Product) results.next();
    assertEquals(pq, new Product(2, "Laser", KindEnum.PRINTER));
    database.remove(pq);

    pq = (Product) results.next();
    assertEquals(pq, new Product(3, "Desktop", KindEnum.COMPUTER));
    database.remove(pq);

    pq = (Product) results.next();
    assertEquals(pq, new Product(4, "Notebook", KindEnum.COMPUTER));
    database.remove(pq);

    assertFalse(results.hasMore());
    results.close();
    query.close();

    database.commit();
    database.close();
  }
Beispiel #28
0
  public void testReadOnlyOidEmpty() throws Exception {
    long start = System.currentTimeMillis();

    _db = _jdo.getDatabase();
    _db.getCacheManager().expireCache();
    _db.begin();

    long begin = System.currentTimeMillis();

    OQLQuery query =
        _db.getOQLQuery(
            "CALL SQL select PTF_LOCKED.ID as ID "
                + "from PTF_LOCKED order by PTF_LOCKED.ID "
                + "AS ptf.jdo.rel1toN.OID");
    QueryResults results = query.execute(Database.ReadOnly);

    long result = System.currentTimeMillis();

    initIterateQueriesOID();

    int count = 0;
    while (results.hasMore()) {
      OID oid = (OID) results.next();
      iterateStatesOID(
          (Locked) _db.load(Locked.class, oid.getId(), Database.ReadOnly), Database.ReadOnly);

      count++;
    }

    long iterate = System.currentTimeMillis();

    _db.commit();

    long commit = System.currentTimeMillis();

    _db.close();

    long close = System.currentTimeMillis();

    LOG.info(
        format(
            "ReadOnlyOidEmpty",
            DF.format(begin - start),
            DF.format(result - begin),
            DF.format(iterate - result),
            DF.format(commit - iterate),
            DF.format(close - commit)));
  }
Beispiel #29
0
  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();
  }
Beispiel #30
0
  public void testReadWriteEmpty() throws Exception {
    long start = System.currentTimeMillis();

    _db = _jdo.getDatabase();
    _db.getCacheManager().expireCache();
    _db.begin();

    long begin = System.currentTimeMillis();

    OQLQuery query =
        _db.getOQLQuery("SELECT o FROM " + Locked.class.getName() + " o order by o.id");
    QueryResults results = query.execute();

    long result = System.currentTimeMillis();

    initIterateQueries();

    int count = 0;
    while (results.hasMore()) {
      iterateStates((Locked) results.next(), Database.Shared);

      count++;
    }

    long iterate = System.currentTimeMillis();

    _db.commit();

    long commit = System.currentTimeMillis();

    _db.close();

    long close = System.currentTimeMillis();

    LOG.info(
        format(
            "ReadWriteEmpty",
            DF.format(begin - start),
            DF.format(result - begin),
            DF.format(iterate - result),
            DF.format(commit - iterate),
            DF.format(close - commit)));
  }