Package ch.agent.crnickl.api

Examples of ch.agent.crnickl.api.Surrogate


   * @throws T2DBException
   */
  public void deleteChronicle(UpdatableChronicle chronicle, ChronicleUpdatePolicy policy) throws T2DBException {
    boolean done = false;
    Throwable cause = null;
    Surrogate s = chronicle.getSurrogate();
    MongoDatabase db = (MongoDatabase) s.getDatabase();
    try {
      check(Permission.MODIFY, chronicle);
      policy.willDelete(chronicle);
      Chronicle original = getChronicle(s);
      getMongoDB(s).getChronicles().remove(asQuery(s.getId()), WriteConcern.SAFE);
      db.sleep();
      try {
        policy.willDelete(chronicle);
      } catch (T2DBException e) {
        // Oops! referential integrity broken!
View Full Code Here


   *
   * @param chronicle
   * @throws T2DBException
   */
  private void deleteAttributes(Chronicle chronicle) throws T2DBException {
    Surrogate s = chronicle.getSurrogate();
    Database db = s.getDatabase();
    try {
      getMongoDB(db).getAttributes().remove(
          mongoObject(MongoDatabase.FLD_ATTR_CHRON,getId(s)));
    } catch (Exception e) {
      throw T2DBMsg.exception(e, E.E40124, chronicle.getName(true));
View Full Code Here

   */
  public void createSeries(Series<?> series) throws T2DBException {
    createSeries(series, false);
  }
  private void createSeries(Series<?> series, boolean undoDelete) throws T2DBException {
    Surrogate surrogate = null;
    Throwable cause = null;
    try {
      check(Permission.MODIFY, series.getChronicle());
      DBObjectId ox = insert(series);
      surrogate = makeSurrogate(series, ox);
View Full Code Here

   * @throws T2DBException
   */
  public void deleteSeries(UpdatableSeries<?> series, ChronicleUpdatePolicy policy) throws T2DBException {
    boolean done = false;
    Throwable cause = null;
    Surrogate s = series.getSurrogate();
    MongoDatabase db = (MongoDatabase) s.getDatabase();
    try {
      check(Permission.MODIFY, series);
      policy.willDelete(series);
      done = policy.deleteSeries(series);
      Series<?> original = db.getReadMethodsForChronicleAndSeries().getSeries(s);
      getMongoDB(db).getSeries().remove(asQuery(s.getId()), WriteConcern.SAFE);
      db.sleep();
      try {
        policy.willDelete(series);
      } catch (T2DBException e) {
        // Oops! referential integrity broken!
View Full Code Here

      throw T2DBMsg.exception(cause, E.E50112, series.getName(true));
  }
 
  private DBObjectId insert(Chronicle chronicle) throws T2DBException {
    com.mongodb.BasicDBObject bo = new BasicDBObject();
    Surrogate s = chronicle.getSurrogate();
    if (!s.inConstruction())
      bo.put(MongoDatabase.FLD_ID, getId(chronicle)); // use case: re-creating
    bo.put(MongoDatabase.FLD_CHRON_NAME, chronicle.getName(false));
    bo.put(MongoDatabase.FLD_CHRON_DESC, chronicle.getDescription(false));
    bo.put(MongoDatabase.FLD_CHRON_PARENT, getIdOrZero(chronicle.getCollection()));
    bo.put(MongoDatabase.FLD_CHRON_SCHEMA, getIdOrZero(chronicle.getSchema(false)));
View Full Code Here

    return new MongoDBObjectId(ox);
  }

  private <T>DBObjectId insert(Series<T> series) throws T2DBException {
    com.mongodb.BasicDBObject bo = new BasicDBObject();
    Surrogate s = series.getSurrogate();
    if (!s.inConstruction())
      bo.put(MongoDatabase.FLD_ID, getId(series)); // use case: re-creating
    bo.put(MongoDatabase.FLD_SER_CHRON, getIdOrZero(series.getChronicle()));
    bo.put(MongoDatabase.FLD_SER_NUM, series.getNumber());
    bo.put(MongoDatabase.FLD_SER_FIRST, 1);
    bo.put(MongoDatabase.FLD_SER_LAST, 0);
View Full Code Here

      }
      DBCursor cursor = coll.find(query);
      try {
        while (cursor.hasNext()) {
          ObjectId id = (ObjectId) cursor.next().get(MongoDatabase.FLD_ID);
          Surrogate s = makeSurrogate(db, DBObjectType.SCHEMA, new MongoDBObjectId(id));
          result.add(s);
        }
      } finally {
        cursor.close();
      }
View Full Code Here

  private UpdatableSchema unpack(Database db, BasicDBObject obj, Set<ObjectId> cycleDetector) throws T2DBException {
    if (cycleDetector == null)
      cycleDetector = new HashSet<ObjectId>();
    try {
      ObjectId id = obj.getObjectId(MongoDatabase.FLD_ID);
      Surrogate s = makeSurrogate(db, DBObjectType.SCHEMA, new MongoDBObjectId(id));
      boolean cycleDetected = !cycleDetector.add(id);
      String name = obj.getString(MongoDatabase.FLD_SCHEMA_NAME);
      UpdatableSchema base = null;
      ObjectId baseId = obj.getObjectId(MongoDatabase.FLD_SCHEMA_BASE);
      if (baseId != null && !cycleDetected) {
        Surrogate baseSurr = makeSurrogate(db, DBObjectType.SCHEMA, new MongoDBObjectId(baseId));
        base = getSchema(baseSurr, cycleDetector);
      }
      Collection<AttributeDefinition<?>> attribs = attributeDefinitions(s, 0, db, (BasicDBList)obj.get(MongoDatabase.FLD_SCHEMA_ATTRIBS));
      Collection<SeriesDefinition> series = seriesDefinitions(s, db, (BasicDBList)obj.get(MongoDatabase.FLD_SCHEMA_SERIES));
      return new UpdatableSchemaImpl(name,  base,  attribs,  series,  s);
View Full Code Here

      def = new AttributeDefinitionImpl(seriesNr, number, null, null);
      def.edit();
      def.setErasing(true);
    } else {
      ObjectId propId =  bo.getObjectId(MongoDatabase.FLD_ATTRIBDEF_PROP);
      Surrogate propSurr = makeSurrogate(db, DBObjectType.PROPERTY, new MongoDBObjectId(propId));
      Property<?> prop = ((MongoDatabase) db).getReadMethodsForProperty().getProperty(propSurr);
      String val =  bo.getString(MongoDatabase.FLD_ATTRIBDEF_VAL);
      checkIntegrity(prop, propSurr, schemaSurrogate);
      def = new AttributeDefinitionImpl(seriesNr, number, prop, prop.getValueType().scan(val));
    }
View Full Code Here

   *
   * @param prop a property
   * @throws T2DBException
   */
  public <T>void createProperty(Property<T> prop) throws T2DBException {
    Surrogate surrogate = null;
    Throwable cause = null;
    try {
      check(Permission.CREATE, prop);
      BasicDBObject dob = pack(prop);
      getMongoDB(prop).getProperties().insert(dob);
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.