Package ch.agent.crnickl.api

Examples of ch.agent.crnickl.api.Surrogate


    operation = operation(Operator.SET,
        MongoDatabase.FLD_SER_FIRST, range.getFirstIndex(),
        MongoDatabase.FLD_SER_LAST, range.getLastIndex(),
        MongoDatabase.FLD_SER_VALUES, data);
   
    Surrogate s = series.getSurrogate();
    getMongoDB(s).getSeries().update(asQuery(s.getId()), operation);
  }
View Full Code Here


      Object values = obj.get(MongoDatabase.FLD_VT_VALUES);
      boolean restricted = values != null;
      Map<String, String> valueMap = null;
      if (restricted)
        valueMap = (Map<String, String>)((BasicDBObject) values).toMap();
      Surrogate s = makeSurrogate(db, DBObjectType.VALUE_TYPE, new MongoDBObjectId(id));
      return new ValueTypeImpl<T>(name, restricted, type, valueMap, s);
    } catch (ClassCastException e) {
      throw T2DBMMsg.exception(e, J.J81010, obj.toString());
    }
  }
View Full Code Here

   * @return true if any value found
   * @throws T2DBException
   */
  public boolean getAttributeValue(List<Chronicle> chronicles, Attribute<?> attribute) throws T2DBException {
    boolean found = false;
    Surrogate s = attribute.getProperty().getSurrogate();
    Database db = s.getDatabase();
    try {
      ObjectId[] chrOids = new ObjectId[chronicles.size()];
      int offset = 0;
      for(Chronicle chronicle : chronicles) {
        chrOids[offset++] = getId(chronicle);
      }
      DBCursor cursor = getMongoDB(db).getAttributes().find(
          mongoObject(MongoDatabase.FLD_ATTR_PROP,
              getId(s), MongoDatabase.FLD_ATTR_CHRON,
              mongoObject(Operator.IN.op(), chrOids)));
     
      offset = Integer.MAX_VALUE;
      BasicDBObject objAtOffset = null;
     
      while (cursor.hasNext()) {
        BasicDBObject obj = (BasicDBObject) cursor.next();
        ObjectId chrOid = obj.getObjectId(MongoDatabase.FLD_ATTR_CHRON);
        int offset1 = findOffset(chrOid, chronicles);
        if (offset1 < offset) {
          offset = offset1;
          objAtOffset = obj;
        }
        if (offset == 0)
          break;
      }

            if (objAtOffset != null) {
              ObjectId chrOid = objAtOffset.getObjectId(MongoDatabase.FLD_ATTR_CHRON);
              Surrogate chronicle = makeSurrogate(db, DBObjectType.CHRONICLE, chrOid);
              check(Permission.READ, chronicle);
              attribute.scan(objAtOffset.getString(MongoDatabase.FLD_ATTR_VALUE));
        String description = objAtOffset.getString(MongoDatabase.FLD_ATTR_DESC);
        if (description.length() > 0)
          attribute.setDescription(description);
View Full Code Here

   * @return a list of chronicles, possibly empty, never null
   * @throws T2DBException
   */
  public <T>List<Chronicle> getChroniclesByAttributeValue(Property<T> property, T value, int maxSize) throws T2DBException {
    List<Chronicle> result = new ArrayList<Chronicle>();
    Surrogate s = property.getSurrogate();
    Database db = s.getDatabase();
    try {
      DBCursor cursor = getMongoDB(db).getAttributes().find(
          mongoObject(MongoDatabase.FLD_ATTR_PROP,
              getId(s), MongoDatabase.FLD_ATTR_VALUE,
              property.getValueType().toString(value)));
      while (cursor.hasNext()) {
        BasicDBObject obj = (BasicDBObject) cursor.next();
        ObjectId chrOid = obj.getObjectId(MongoDatabase.FLD_ATTR_CHRON);
        Surrogate chronicle = makeSurrogate(db, DBObjectType.CHRONICLE, chrOid);
        try {
          check(Permission.READ, chronicle);
          result.add(new ChronicleImpl(chronicle));
        } catch (T2DBException e) {
          // ignore "unreadable" chronicles
View Full Code Here

        if (numbers[i] > 0) {
          if (map.put(numbers[i], i) != null)
            throw new IllegalArgumentException("duplicate number: " + numbers[i]);
        }
      }
      Surrogate s = chronicle.getSurrogate();
      Database db = s.getDatabase();
      try {
        check(Permission.READ, chronicle);
      } catch (Exception e) {
        throw T2DBMsg.exception(e, E.E40104, s.toString());
      }
      try {
        DBCursor cursor = getMongoDB(db).getSeries().find(
            mongoObject(MongoDatabase.FLD_SER_CHRON,
                getId(chronicle), MongoDatabase.FLD_SER_NUM,
View Full Code Here

  }

  private Chronicle unpack(Database db, BasicDBObject obj) throws T2DBException {
    try {
      ObjectId id = obj.getObjectId(MongoDatabase.FLD_ID);
      Surrogate s = makeSurrogate(db, DBObjectType.CHRONICLE, id);
      ChronicleImpl.RawData data = new ChronicleImpl.RawData();
      data.setSurrogate(s);
      data.setName(obj.getString(MongoDatabase.FLD_CHRON_NAME));
      data.setDescription(obj.getString(MongoDatabase.FLD_CHRON_DESC));
      ObjectId parentId = obj.getObjectId(MongoDatabase.FLD_CHRON_PARENT);
View Full Code Here

  }
 
  public void test_030_rename_type() {
    try {
      ValueType<String> vt = db.getValueType("foo-type");
      Surrogate s = vt.getSurrogate();
      UpdatableValueType<String> uvt = vt.edit();
      uvt.setName("moo-type");
      uvt.applyUpdates();
      assertEquals("moo-type", db.getValueType(s).getName());
    } catch (Exception e) {
View Full Code Here

  }
 
  public void test_rename_type() {
    try {
      ValueType<String> vt = db.getValueType("foo-type");
      Surrogate s = vt.getSurrogate();
      UpdatableValueType<String> uvt = vt.edit();
      uvt.setName("moo-type");
      uvt.applyUpdates();
      assertEquals("moo-type", db.getValueType(s).getName());
    } catch (Exception e) {
View Full Code Here

  /**
   * Bug 4424 2013-03-16
   */
  public void test14() {
    try {
      Surrogate k = new SurrogateImpl((DatabaseBackend)db, DBObjectType.CHRONICLE, id(42));
      db.getSeries(k);
      expectException();
    } catch (Exception e) {
      assertException(e, D.D02102);
    }
View Full Code Here

  /**
   * Bug 4424 2013-03-16
   */
  public void test15() {
    try {
      Surrogate k = new SurrogateImpl((DatabaseBackend)db, DBObjectType.CHRONICLE, id(42));
      db.getSchema(k);
      expectException();
    } catch (Exception e) {
      assertException(e, D.D02102);
    }
View Full Code Here

TOP

Related Classes of ch.agent.crnickl.api.Surrogate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.