Exemplo n.º 1
0
  /**
   * 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;
  }
Exemplo n.º 2
0
  /** 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;
  }
Exemplo n.º 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();
  }
Exemplo n.º 4
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();
  }
Exemplo n.º 5
0
  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;
  }
Exemplo n.º 6
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();
  }
Exemplo n.º 7
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();
  }
Exemplo n.º 8
0
  /** 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;
  }
Exemplo n.º 9
0
  /**
   * 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;
  }
Exemplo n.º 10
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);
    }
  }
Exemplo n.º 11
0
 private void initIterateQueriesOID() throws Exception {
   _queryStateOID =
       _db.getOQLQuery(
           "CALL SQL select PTF_STATE.ID as ID from PTF_STATE "
               + "where PTF_STATE.LOCKED_ID=$1 order by PTF_STATE.ID "
               + "AS ptf.jdo.rel1toN.OID");
   _queryEquipmentOID =
       _db.getOQLQuery(
           "CALL SQL select PTF_EQUIPMENT.ID as ID from PTF_EQUIPMENT "
               + "where PTF_EQUIPMENT.STATE_ID=$1 order by PTF_EQUIPMENT.ID "
               + "AS ptf.jdo.rel1toN.OID");
   _queryServiceOID =
       _db.getOQLQuery(
           "CALL SQL select PTF_SERVICE.ID as ID from PTF_SERVICE "
               + "where PTF_SERVICE.EQUIPMENT_ID=$1 order by PTF_SERVICE.ID "
               + "AS ptf.jdo.rel1toN.OID");
 }
Exemplo n.º 12
0
 private void initIterateQueries() throws Exception {
   _queryState =
       _db.getOQLQuery(
           "select o from " + State.class.getName() + " o " + "where o.locked=$1 order by o.id");
   _queryEquipment =
       _db.getOQLQuery(
           "select o from "
               + Equipment.class.getName()
               + " o "
               + "where o.state=$1 order by o.id");
   _queryService =
       _db.getOQLQuery(
           "select o from "
               + Service.class.getName()
               + " o "
               + "where o.equipment=$1 order by o.id");
 }
Exemplo n.º 13
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");
    }
  }
Exemplo n.º 14
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();
  }
Exemplo n.º 15
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();
 }
Exemplo n.º 16
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();
  }
Exemplo n.º 17
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)));
  }
Exemplo n.º 18
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();
  }
Exemplo n.º 19
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)));
  }
Exemplo n.º 20
0
  public void testReadOnlyOidOnly() throws Exception {
    long start = System.currentTimeMillis();

    _db = _jdo.getDatabase();
    _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();

    int count = 0;
    while (results.hasMore()) {
      results.next();
      count++;
    }

    long iterate = System.currentTimeMillis();

    _db.commit();

    long commit = System.currentTimeMillis();

    _db.close();

    long close = System.currentTimeMillis();

    LOG.info(
        format(
            "ReadOnlyOidOnly",
            DF.format(begin - start),
            DF.format(result - begin),
            DF.format(iterate - result),
            DF.format(commit - iterate),
            DF.format(close - commit)));
  }
Exemplo n.º 21
0
  /** 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;
  }
Exemplo n.º 22
0
  public void testRemoveState() throws Exception {
    long time = System.currentTimeMillis();
    int count = 0;

    Database db = _jdo.getDatabase();
    db.begin();

    OQLQuery query = db.getOQLQuery("SELECT o FROM " + State.class.getName() + " o");
    QueryResults results = query.execute();
    while (results.hasMore()) {
      db.remove(results.next());
      count++;
    }

    db.commit();
    db.close();

    LOG.info(
        "Removed " + count + " state objects in " + (System.currentTimeMillis() - time) + "ms.");
  }
Exemplo n.º 23
0
  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;
  }
Exemplo n.º 24
0
  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();
  }
Exemplo n.º 25
0
  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;
  }
Exemplo n.º 26
0
  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;
  }
Exemplo n.º 27
0
  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);
  }
Exemplo n.º 28
0
  public void testQueryServers() throws Exception {
    Database database = _category.getDatabase();

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

    if (results.hasMore()) {
      int counter = 3;
      while (results.hasMore()) {
        Server server = (Server) results.next();
        assertNotNull(server);
        assertEquals(counter, server.getId());

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

    database.close();
  }
Exemplo n.º 29
0
  public void testQueryOwner() throws Exception {
    Database database = _category.getDatabase();

    database.begin();
    OQLQuery query =
        database.getOQLQuery("select owner from " + Owner.class.getName() + " as owner");
    QueryResults results = query.execute();

    if (results.hasMore()) {
      int counter = 1;
      while (results.hasMore()) {
        Owner owner = (Owner) results.next();
        assertNotNull(owner);
        assertEquals(counter, owner.getId().intValue());

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

    database.close();
  }
Exemplo n.º 30
0
  /** 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;
  }