예제 #1
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();
  }
예제 #2
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();
  }
예제 #3
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();
  }
예제 #4
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();
  }
  /**
   * unlocks this instance for the given instance and state
   *
   * @param state state that have to be locked
   * @param user the locking user
   */
  public void unlock(ProcessInstance instance, State state, User user) throws WorkflowException {
    Database db = null;

    try {
      // Get database connection
      db = WorkflowJDOManager.getDatabase();

      // begin transaction
      db.begin();

      // Re-load process instance
      UpdatableProcessInstance copyInstance =
          (UpdatableProcessInstance) db.load(ProcessInstanceImpl.class, instance.getInstanceId());

      // Do workflow stuff
      try {
        // unlock instance for user
        copyInstance.unLock(state, user);
      } catch (WorkflowException we) {
        db.rollback();
        throw new WorkflowException(
            "ProcessInstanceManagerImpl.unlock", "workflowEngine.EX_ERR_UNLOCK", we);
      }

      // commit
      db.commit();
    } catch (PersistenceException pe) {
      throw new WorkflowException(
          "ProcessInstanceManagerImpl.unlock", "workflowEngine.EX_ERR_CASTOR_UNLOCK", pe);
    } finally {
      WorkflowJDOManager.closeDatabase(db);
    }
  }
  /**
   * Removes a new process instance
   *
   * @param instanceId instance id
   */
  public void removeProcessInstance(String instanceId) throws WorkflowException {
    SilverTrace.info(
        "worflowEngine",
        "ProcessInstanceManagerImpl.removeProcessInstance()",
        "root.MSG_GEN_ENTER_METHOD",
        "InstanceId=" + instanceId);
    ProcessInstanceImpl instance;
    Database db = null;
    try {
      // Delete forms data associated with this instance
      removeProcessInstanceData(instanceId);

      // Constructs the query
      db = WorkflowJDOManager.getDatabase();
      db.begin();
      instance = (ProcessInstanceImpl) db.load(ProcessInstanceImpl.class, instanceId);
      db.remove(instance);
      db.commit();
    } catch (PersistenceException pe) {
      throw new WorkflowException(
          "ProcessInstanceManagerImpl.removeProcessInstance", "EX_ERR_CASTOR_REMOVE_INSTANCE", pe);
    } finally {
      WorkflowJDOManager.closeDatabase(db);
    }

    WorkflowHub.getErrorManager().removeErrorsOfInstance(instanceId);
    SilverTrace.info(
        "worflowEngine",
        "ProcessInstanceManagerImpl.removeProcessInstance()",
        "root.MSG_GEN_EXIT_METHOD");
  }
예제 #7
0
 /** Get a JDO database */
 public void setUp() throws Exception {
   _db = getJDOManager(DBNAME, MAPPING).getDatabase();
   _db.begin();
   LOG.info("Delete everything");
   Statement stmt = _db.getJdbcConnection().createStatement();
   stmt.executeUpdate("delete from test77_depend2");
   stmt.executeUpdate("delete from test77_master");
   stmt.executeUpdate("delete from test77_depend1");
   _db.commit();
 }
예제 #8
0
  /**
   * Test method.
   *
   * @throws Exception For any exception thrown.
   */
  public void testLoadChild() throws Exception {
    Database db = _category.getDatabase();
    db.begin();

    Child child = (Child) db.load(Child.class, new Integer(1));

    assertNotNull(child);
    assertEquals(new Integer(1), child.getId());

    db.commit();
    db.close();
  }
예제 #9
0
  public void testLoadTruck() throws Exception {
    Database database = _category.getDatabase();

    database.begin();
    Truck truck = (Truck) database.load(Truck.class, new Integer(5));
    database.commit();

    assertNotNull(truck);
    assertEquals(5, truck.getId());

    database.close();
  }
예제 #10
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();
  }
예제 #11
0
  /**
   * Test method.
   *
   * @throws Exception For any exception thrown.
   */
  public void testQueryEntityOne() throws Exception {
    Database db = _category.getDatabase();
    db.begin();

    Parent entity = (Parent) db.load(Parent.class, new Integer(1));

    assertNotNull(entity);
    assertEquals(new Integer(1), entity.getId());

    db.commit();
    db.close();
  }
예제 #12
0
  public void testLoadComputer() throws Exception {
    Database database = _category.getDatabase();

    database.begin();
    Computer computer = (Computer) database.load(Computer.class, new Integer(2));
    database.commit();

    assertNotNull(computer);
    assertEquals("ctf.jdo.tc9x.Laptop", computer.getClass().getName());
    assertEquals(2, computer.getId());
    assertEquals("laptop 2", computer.getName());

    database.close();
  }
예제 #13
0
  public void testLoadLaptop() throws Exception {
    Database database = _category.getDatabase();

    database.begin();
    Laptop laptop = (Laptop) database.load(Laptop.class, new Integer(1));
    database.commit();

    assertNotNull(laptop);
    assertEquals("ctf.jdo.tc9x.Laptop", laptop.getClass().getName());
    assertEquals(1, laptop.getId());
    assertEquals("laptop 1", laptop.getName());

    database.close();
  }
예제 #14
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();
 }
예제 #15
0
  public void testLoadServer() throws Exception {
    Database database = _category.getDatabase();

    database.begin();
    Server server = (Server) database.load(Server.class, new Integer(3));
    database.commit();

    assertNotNull(server);
    assertEquals("ctf.jdo.tc9x.Server", server.getClass().getName());
    assertEquals(3, server.getId());
    assertEquals("server 3", server.getName());

    database.close();
  }
예제 #16
0
  /**
   * Test method.
   *
   * @throws Exception For any exception thrown.
   */
  public void testLoadEntityWithCompoundId() throws Exception {
    Database db = _category.getDatabase();
    db.begin();

    ParentWithCompoundId child =
        (ParentWithCompoundId)
            db.load(ParentWithCompoundId.class, new Complex(new Integer(1), new Integer(1)));

    assertNotNull(child);
    assertEquals(new Integer(1), child.getId1());
    assertEquals(new Integer(1), child.getId2());

    db.commit();
    db.close();
  }
예제 #17
0
  public void testLoadCar() throws Exception {
    Database database = _category.getDatabase();

    database.begin();
    Object object = database.load(Car.class, new Integer(5));
    assertNotNull(object);
    assertEquals("ctf.jdo.tc9x.Truck", object.getClass().getName());
    Truck truck = (Truck) object;
    database.commit();

    assertNotNull(truck);
    assertEquals(5, truck.getId());

    database.close();
  }
예제 #18
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");
    }
  }
예제 #19
0
    public boolean run( CWVerboseStream stream ) {
        try {
            _db = _category.getDatabase( stream.verbose() );
            _conn = _category.getJDBCConnection();

            boolean result = true;
            for ( int i=0; i < 4; i++ ) {
                _cacheType = i;
                if ( !runOnce( stream ) )
                    result = false;
            }
            _db.close();
            _conn.close();
            if ( _errLeak )
                System.out.println("Element leak happened!");
            if ( _errCount )
                System.out.println("Sum do not match!");

            return result && !_errLeak && !_errCount;
        } catch ( Exception e ) {
            stream.write( "Error: "+ e );
            return false;
        }

    }
예제 #20
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;
  }
예제 #21
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;
  }
예제 #22
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;
  }
예제 #23
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;
  }
예제 #24
0
  public void testLoadComputerMulti() throws Exception {
    Database database = _category.getDatabase();

    database.begin();
    ComputerMulti computer =
        (LaptopMulti)
            database.load(ComputerMulti.class, new Identity(new Integer(1), new Integer(1)));
    database.commit();

    assertNotNull(computer);
    assertEquals(1, computer.getId1());
    assertEquals(1, computer.getId2());
    assertEquals("laptop 1", computer.getName());

    database.close();
  }
예제 #25
0
 public LanguageVO create(Database db, LanguageVO languageVO)
     throws ConstraintException, SystemException, Exception {
   Language ent = new LanguageImpl();
   ent.setValueObject(languageVO);
   db.create(ent);
   return ent.getValueObject();
 }
예제 #26
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;
  }
예제 #27
0
  public void testReadOnlyOidCached() 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();

    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(
            "ReadOnlyOidCached",
            DF.format(begin - start),
            DF.format(result - begin),
            DF.format(iterate - result),
            DF.format(commit - iterate),
            DF.format(close - commit)));
  }
예제 #28
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");
 }
예제 #29
0
  public void testLoadM() throws Exception {
    Database database = _category.getDatabase();

    database.begin();
    M m = (M) database.load(M.class, new Integer(1));
    database.commit();

    assertNotNull(m);
    assertEquals(1, m.getId());
    assertEquals("m1", m.getName());

    Collection ns = m.getNs();
    assertNotNull(ns);
    assertEquals(2, ns.size());

    database.close();
  }
예제 #30
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();
  }