Пример #1
0
 @Test
 public void testOrNegative() throws Exception {
   insertMockObject();
   DBCursor<MockObject> cursor =
       coll.find().or(DBQuery.is("integer", 9), DBQuery.lessThan("integer", 9));
   assertThat(cursor.hasNext(), equalTo(false));
 }
Пример #2
0
 @Test
 public void testNorPositive() throws Exception {
   MockObject mockObject = insertMockObject();
   DBCursor<MockObject> cursor =
       coll.find().nor(DBQuery.lessThan("integer", 9), DBQuery.greaterThan("integer", 11));
   assertThat(cursor.hasNext(), equalTo(true));
   assertThat(cursor.next(), equalTo(mockObject));
 }
Пример #3
0
 @Test
 public void testNorNegative() throws Exception {
   insertMockObject();
   DBCursor<MockObject> cursor =
       coll.find()
           .and(
               DBQuery.lessThan("integer", 9),
               DBQuery.is("string", "hello"),
               DBQuery.greaterThan("integer", 11));
   assertThat(cursor.hasNext(), equalTo(false));
 }
Пример #4
0
 @Test
 public void testAnd() {
   MockObject o = new MockObject();
   o.i = 5;
   coll.save(o);
   // Ensure that the serializer actually worked
   assertThat(
       coll.find().and(DBQuery.lessThan("i", 12), DBQuery.greaterThan("i", 4)).toArray(),
       hasSize(1));
   assertThat(
       coll.find().and(DBQuery.lessThan("i", 12), DBQuery.greaterThan("i", 9)).toArray(),
       hasSize(0));
 }
Пример #5
0
 @Test
 public void testSerializationFromInFind() throws Exception {
   MockObject mockObject = insertMockObjectWithEmbedded();
   DBCursor<MockObject> cursor = coll.find(DBQuery.in("object", mockObject.object));
   assertThat(cursor.hasNext(), equalTo(true));
   assertThat(cursor.next(), equalTo(mockObject));
 }
Пример #6
0
 @Test
 public void testElemMatchNegative() throws Exception {
   insertMockObjectWithComplexList();
   DBCursor<MockObject> cursor =
       coll.find().elemMatch("complexList", DBQuery.in("value", "foo", "la").size("list", 2));
   assertThat(cursor.hasNext(), equalTo(false));
 }
  /**
   * Create an squery using some preset values for the query parameters, only passing in the
   * document ids to be searched.
   *
   * @param docidList an array of document identifiers to search for
   */
  public static String createDocidQuery(String[] docidList) throws PropertyNotFoundException {
    String pathQuery = "";
    Hashtable params = getDefaultQueryParams();
    if (docidList != null) {
      params.put("/eml/@packageId", docidList);
    }

    pathQuery = DBQuery.createSQuery(params);
    return pathQuery;
  }
Пример #8
0
 @Test
 public void testSimpleEquals() {
   coll.save(new MockObject());
   String id = coll.findOne().id;
   assertNotNull(coll.findOne(DBQuery.is("_id", id)));
 }
  /**
   * Perform the query on the database, and prepare the array of returned DO objects.
   *
   * @exception DataObjectException If a database access error occurs.
   * @exception NonUniqueQueryException If too many rows were found.
   */
  private void runQuery() throws DataObjectException, NonUniqueQueryException {
    needToRun = false;
    arrayIndex = -1;

    DBQuery dbQuery = null;
    try {
      Vector results;
      /*
         if ( cacheHits.size() > 0 ) {
      // The setQuery methods build up the cacheHits.
      // If the cache had our desired objects,
      // we don't query the database, so we have no ResultSet.
      results = cacheHits;	 // executeQuery saw cache hits
         } else {
      // If the cache doesn't exist, or could not handle the query,
      // then we actually query the database.
      dbQuery = Enhydra.getDatabaseManager().createQuery();
      dbQuery.query( this );    // invokes executeQuery
             results = new Vector();
             while ( resultSet.next() ) {
          results.addElement( new SoftwareCandidateDO ( resultSet ) );
             }
         }
         */
      if (/* partialCache && */ 0 == cacheHits.size()) hitDb = true;
      if (hitDb) {
        dbQuery = Enhydra.getDatabaseManager().createQuery();
        dbQuery.query(this); // invokes executeQuery
        results = new Vector();
        while (resultSet.next()) {
          //		    results.addElement( new SoftwareCandidateDO ( resultSet ) );
          results.addElement(SoftwareCandidateDO.createExisting(resultSet));
        }
      } else {
        results = cacheHits; // executeQuery saw cache hits
      }

      if (results.size() > 1 && uniqueInstance)
        throw new NonUniqueQueryException("Too many rows returned from database");
      DOs = new SoftwareCandidateDO[results.size()];
      for (int i = 0; i < results.size(); i++) {
        DOs[i] = (SoftwareCandidateDO) results.elementAt(i);
      }
      arrayIndex = 0;
    } catch (SQLException se) {
      if (null == se.getSQLState()) {
        throw new DataObjectException("Unknown SQLException", se);
      }
      if (se.getSQLState().startsWith("02") && se.getErrorCode() == 100) {
        throw new DataObjectException("Update or delete DO is out of synch", se);
      } else if (se.getSQLState().equals("S1000") && se.getErrorCode() == -268) {
        throw new DataObjectException("Integrity constraint violation", se);
      } else {
        throw new DataObjectException("Data Object Error", se);
      }
    } catch (ObjectIdException oe) {
      throw new DataObjectException("Object ID Error", oe);
    } catch (DatabaseManagerException de) {
      throw new DataObjectException("Database connection Error", de);
    } finally {
      if (null != dbQuery) dbQuery.release();
    }
  }