Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-102

No mechanism to specify object class for DBObjects returned from DBRef.fetch()

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      This is borderline bug / feature request.

      I have been happily using the DBCollection.setObjectClass(CUSTOM_CLASS) feature in my app, but unfortunately, any time I have a DBRef from one DBObject to another, I cannot direct DBRef.fetch() (actually it is DBRefBase.fetch()) to use a custom DBObject class. It always uses BasicDBObject.

      One solution would be to have an optional property of DBRef to configure an object class. If none is specified the default behavior is to use BasicDBObject.

      Current impl code snippet (from github):

      public DBObject fetch() {
      if (_loadedPointedTo)
      return _pointedTo;

      if (_db == null)
      throw new RuntimeException("no db");

      if (D)

      { System.out.println("following db pointer. ref to ns:" + _ns); Throwable t = new Throwable(); t.fillInStackTrace(); t.printStackTrace(); }

      final DBCollection coll = _db.getCollectionFromString(_ns);

      _pointedTo = coll.findOne(_id);
      _loadedPointedTo = true;
      return _pointedTo;
      }

      Attachments

        Activity

          People

            eliot Eliot Horowitz (Inactive)
            william.shulman@gmail.com William Shulman
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: