Beispiel #1
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;
        }

    }
Beispiel #2
0
 CreateDeleteThread( CWVerboseStream stream, JDOCategory c, int cachetype, int n ) throws Exception {
     this.db = c.getDatabase( stream.verbose() );
     this.trial = n;
     this.stream = stream;
     this.ran = new Random();
     this.cachetype = cachetype;
 }
Beispiel #3
0
 ReadThread( CWVerboseStream stream, CreateDeleteThread other, JDOCategory c, int n ) throws Exception {
     this.db = c.getDatabase( stream.verbose() );
     this.trial = n;
     this.stream = stream;
     this.ran = new Random();
     this.other = other;
 }
Beispiel #4
0
  public void setUp() throws PersistenceException, SQLException {
    _db = _category.getDatabase(verbose);
    _conn = _category.getJDBCConnection();
    _conn.setAutoCommit(false);

    // delete everything directly
    stream.println("Delete everything");
    Statement stmt = _conn.createStatement();
    stmt.executeUpdate("DELETE FROM test_pks_person");
    stmt.executeUpdate("DELETE FROM test_pks_employee");
    stmt.executeUpdate("DELETE FROM test_pks_payroll");
    stmt.executeUpdate("DELETE FROM test_pks_address");
    stmt.executeUpdate("DELETE FROM test_pks_contract");
    stmt.executeUpdate("DELETE FROM test_pks_category");
    stmt.executeUpdate("DELETE FROM test_pks_project");
    _conn.commit();

    createDataObjects();
  }
Beispiel #5
0
 /** Get a JDO database */
 public void setUp() throws PersistenceException, SQLException {
   _db = _category.getDatabase();
 }
Beispiel #6
0
 public void setUp() throws PersistenceException, SQLException {
   _db = _category.getDatabase(verbose);
   _conn = _category.getJDBCConnection();
   _conn.setAutoCommit(false);
 }
Beispiel #7
0
  public boolean run(CWVerboseStream stream) {
    try {

      _db = _category.getDatabase(stream.verbose());
      _conn = _category.getJDBCConnection();

      stream.writeVerbose("Running...");
      stream.writeVerbose("");

      // delete everything
      _conn.createStatement().executeUpdate("DELETE test_serial");
      _conn.commit();

      // create new object with an serializable dependent object
      _db.begin();
      TestSerial master = new TestSerial();
      master.setId(1);
      master.setSerializableObject(new TestSerializableObject());
      master.getSerializableObject().aCoolString = "Very cool!";
      master.getSerializableObject().ints = new int[] {1, 3, 5, 7, 9};
      _db.create(master);
      _db.commit();

      // test if object created properly
      _db.begin();
      TestSerial testSerial = (TestSerial) _db.load(TestSerial.class, new Integer(1));
      if (testSerial == null) throw new Exception("Object creation failed!");

      if (testSerial.getSerializableObject() == null
          || !testSerial.getSerializableObject().aCoolString.equals("Very cool!")
          || testSerial.getSerializableObject().ints == null
          || testSerial.getSerializableObject().ints.length != 5
          || testSerial.getSerializableObject().ints[0] != 1
          || testSerial.getSerializableObject().ints[1] != 3
          || testSerial.getSerializableObject().ints[2] != 5
          || testSerial.getSerializableObject().ints[3] != 7
          || testSerial.getSerializableObject().ints[4] != 9)
        throw new Exception("dependent objects creation failed!" + testSerial);

      // modify the object
      testSerial.getSerializableObject().ints[1] = 103;
      testSerial.getSerializableObject().ints[3] = 107;
      testSerial.getSerializableObject().aCoolString = "Very very cool!";
      _db.commit();

      _db.begin();
      testSerial = (TestSerial) _db.load(TestSerial.class, new Integer(1));
      if (testSerial == null) throw new Exception("dependent modfiication failed!" + testSerial);

      if (testSerial.getSerializableObject() == null
          || !testSerial.getSerializableObject().aCoolString.equals("Very very cool!")
          || testSerial.getSerializableObject().ints == null
          || testSerial.getSerializableObject().ints.length != 5
          || testSerial.getSerializableObject().ints[0] != 1
          || testSerial.getSerializableObject().ints[1] != 103
          || testSerial.getSerializableObject().ints[2] != 5
          || testSerial.getSerializableObject().ints[3] != 107
          || testSerial.getSerializableObject().ints[4] != 9)
        throw new Exception("dependent modification failed!" + testSerial);

      // set the field to null;
      testSerial.getSerializableObject().ints = null;
      testSerial.getSerializableObject().aCoolString = null;
      _db.commit();

      _db.begin();
      testSerial = (TestSerial) _db.load(TestSerial.class, new Integer(1));
      if (testSerial == null) throw new Exception("dependent modfiication failed!" + testSerial);

      if (testSerial.getSerializableObject() == null
          || testSerial.getSerializableObject().aCoolString != null
          || testSerial.getSerializableObject().ints != null)
        throw new Exception("dependent modification failed!" + testSerial);

      // setSerializableObject( null );
      testSerial.setSerializableObject(null);
      _db.commit();

      _db.begin();
      testSerial = (TestSerial) _db.load(TestSerial.class, new Integer(1));
      if (testSerial == null) throw new Exception("dependent modfiication failed!" + testSerial);

      if (testSerial.getSerializableObject() != null)
        throw new Exception("dependent modification failed!" + testSerial);
      _db.commit();

    } catch (Exception e) {
      e.printStackTrace();

      stream.writeVerbose("Exception: " + e);
      try {
        if (_db.isActive()) _db.close();
        return false;
      } catch (Exception ex) {
        return false;
      }
    }
    return true;
  }