Package ch.agent.crnickl.api

Examples of ch.agent.crnickl.api.Surrogate


   * @throws T2DBException
   */
  public <T>void deleteProperty(Property<T> prop, SchemaUpdatePolicy policy) throws T2DBException {
    boolean done = false;
    Throwable cause = null;
    Surrogate s = prop.getSurrogate();
    MongoDatabase database = (MongoDatabase) s.getDatabase();
    try {
      check(Permission.MODIFY, prop);
      // dangerous update! see comment in MongoDatabase.sleep
      policy.willDelete(prop);
      Property<T> original = database.getReadMethodsForProperty().getProperty(s);
      DBCollection coll = getMongoDB(s).getProperties();
      coll.remove(asQuery(s.getId()), WriteConcern.SAFE);
      database.sleep();
      try {
        policy.willDelete(original);
      } catch (T2DBException e) {
        createProperty(original);
View Full Code Here


   * @throws T2DBException
   */
  public void updateProperty(Property<?> prop, SchemaUpdatePolicy policy) throws T2DBException {
    boolean done = false;
    Throwable cause = null;
    Surrogate s = prop.getSurrogate();
    try {
      check(Permission.MODIFY, prop);
      DBCollection coll = getMongoDB(s).getProperties();
      coll.update(asQuery(s.getId()), operation(Operator.SET, MongoDatabase.FLD_PROP_NAME, prop.getName()));
      done = true;
    } catch (Exception e) {
      cause = e;
    } finally {
    }
View Full Code Here

   *
   * @param vt a value type
   * @throws T2DBException
   */
  public <T>void createValueType(ValueType<T> vt) throws T2DBException {
    Surrogate surrogate = null;
    Throwable cause = null;
    try {
      check(Permission.CREATE, vt);
      DBObjectId ox = insert(vt);
      surrogate = makeSurrogate(vt, ox);
View Full Code Here

   * @throws T2DBException
   */
  public <T>void deleteValueType(ValueType<T> vt, SchemaUpdatePolicy policy) throws T2DBException {
    boolean done = false;
    Throwable cause = null;
    Surrogate s = vt.getSurrogate();
    MongoDatabase database = (MongoDatabase) s.getDatabase();
    try {
      check(Permission.MODIFY, vt);
      policy.willDelete(vt);
      ValueType<T> original = database.getReadMethodsForValueType().getValueType(s);
      DBCollection coll = getMongoDB(s).getValueTypes();
      coll.remove(asQuery(s.getId()), WriteConcern.SAFE); // ??? REPLICA_SAFE --> MongoException("norepl");
      database.sleep();
      try {
        policy.willDelete(original);
      } catch (T2DBException e) {
        // Oops! referential integrity broken!
View Full Code Here

   * @throws T2DBException
   */
  public <T>void updateValueType(ValueType<T> vt, SchemaUpdatePolicy policy) throws T2DBException {
    boolean done = false;
    Throwable cause = null;
    Surrogate s = vt.getSurrogate();
    MongoDatabase database = (MongoDatabase) s.getDatabase();
    try {
      check(Permission.MODIFY, vt);
      DBCollection coll = getMongoDB(s).getValueTypes();
     
      if (vt.isRestricted() && vt.getValues().size() > 0) {
        ValueType<T> original = database.getReadMethodsForValueType().getValueType(s);
        Set<T> deleted = deletedValues(original, vt);
        com.mongodb.DBObject operation = operation(Operator.SET,
            MongoDatabase.FLD_VT_NAME, vt.getName(),
            MongoDatabase.FLD_VT_VALUES, valueDescriptionsAsMap(vt));
       
        if (deleted.size() > 0) {
          // dangerous update! see comment in MongoDatabase.sleep
          Iterator<T> it = deleted.iterator();
          while (it.hasNext()) {
            policy.willDelete(vt, it.next());
          }
          coll.update(asQuery(s.getId()), operation, false, false, WriteConcern.SAFE);
          database.sleep();
          try {
            it = deleted.iterator();
            while (it.hasNext()) {
              policy.willDelete(vt, it.next());
            }
          } catch (T2DBException e) {
            // restore state and throw exception
            operation = operation(Operator.SET,
                MongoDatabase.FLD_VT_NAME, original.getName(),
                MongoDatabase.FLD_VT_VALUES, valueDescriptionsAsMap(original));
            coll.update(asQuery(s.getId()), operation);
            throw e;
          }
        } else {
          coll.update(asQuery(s.getId()), operation);
        }
      } else
        coll.update(asQuery(s.getId()), operation(Operator.SET, MongoDatabase.FLD_VT_NAME, vt.getName()));
      done = true;
    } catch (Exception e) {
      cause = e;
    } finally {
    }
View Full Code Here

    deleted.removeAll(vt.getValues());
    return deleted;
  }
 
  private <T>DBObjectId insert(ValueType<T> vt) throws T2DBException {
    Surrogate s = vt.getSurrogate();
    com.mongodb.BasicDBObject bo = new BasicDBObject();
    if (!s.inConstruction())
      bo.put(MongoDatabase.FLD_ID, getId(vt));
    bo.put(MongoDatabase.FLD_VT_NAME, vt.getName());
    bo.put(MongoDatabase.FLD_VT_TYPE, vt.getExternalRepresentation());
    if (vt.isRestricted())
      bo.put(MongoDatabase.FLD_VT_VALUES, valueDescriptionsAsMap(vt));
View Full Code Here

    try {
      ObjectId id = obj.getObjectId(MongoDatabase.FLD_ID);
      String name = obj.getString(MongoDatabase.FLD_PROP_NAME);
      ObjectId vtId = obj.getObjectId(MongoDatabase.FLD_PROP_VT);
      Boolean indexed = obj.getBoolean(MongoDatabase.FLD_PROP_INDEXED);
      Surrogate vts = makeSurrogate(db, DBObjectType.VALUE_TYPE, new MongoDBObjectId(vtId));
      ValueType<T> vt = db.getValueType(vts);
      Surrogate s = makeSurrogate(db, DBObjectType.PROPERTY, new MongoDBObjectId(id));
      checkIntegrity(vt, vts, s);
      return new PropertyImpl<T>(name, vt, indexed, s);
    } catch (ClassCastException e) {
      throw T2DBMMsg.exception(e, J.J81010, obj.toString());
    }
View Full Code Here

    return dependencyList;
  }

  @Override
  public boolean dependsOnSchema(Schema schema) {
    Surrogate surrogate = schema.getSurrogate();
    if (dependencyList != null) {
      for (Surrogate k : dependencyList) {
        if (k.equals(surrogate))
          return true;
      }
View Full Code Here

    }
    if (count > 0)
      throw T2DBMsg.exception(D.D30140, schema.getName(), count);
   
    // (2) cannot delete if schema explicitly referenced by an entity
    Surrogate entity = database.findChronicle(schema);
    if (entity != null) {
      throw T2DBMsg.exception(D.D30141, schema.getName(), chronicleName(entity));
    }
  }
View Full Code Here

  /**
   * A series definition can be deleted only if there are no series using it.
   */
  private void willDeleteOrErase(UpdatableSchema schema, SeriesDefinition ss) throws T2DBException {
    Surrogate entity = database.findChronicle(ss, schema);
    if (entity != null)
      throw T2DBMsg.exception(D.D30150, ss.getNumber(), schema.getName(), chronicleName(entity));
  }
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.