Package ch.agent.crnickl.api

Examples of ch.agent.crnickl.api.Surrogate


   *
   * @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);
      create_valuetype = open(CREATE_VALUETYPE, vt, create_valuetype);
      create_valuetype.setString(1, vt.getName());
View Full Code Here


  public <T>void updateValueType(ValueType<T> vt, SchemaUpdatePolicy policy) throws T2DBException {
    boolean done = false;
    Throwable cause = null;
    try {
      check(Permission.MODIFY, vt);
      Surrogate s = vt.getSurrogate();
      ValueType<T> original =
          ((JDBCDatabase) s.getDatabase()).getReadMethodsForValueType().getValueType(s);
      if (!original.getName().equals(vt.getName())) {
        update_valuetype = open(UPDATE_VALUETYPE, vt, update_valuetype);
        update_valuetype.setString(1, vt.getName());
        update_valuetype.setInt(2, getId(vt));
        update_valuetype.execute();
View Full Code Here

   *
   * @param schema a schema
   * @throws T2DBException
   */
  public void createSchema(UpdatableSchema schema) throws T2DBException {
    Surrogate surrogate = null;
    Throwable cause = null;
    try {
      check(Permission.CREATE, schema);
      Schema base = schema.getBase();
      if (base != null)
View Full Code Here

   * @throws T2DBException
   */
  public void deleteSchema(UpdatableSchema schema, SchemaUpdatePolicy policy) throws T2DBException {
    boolean done = false;
    Throwable cause = null;
    Surrogate s = schema.getSurrogate();
    MongoDatabase database = (MongoDatabase) s.getDatabase();
    try {
      check(Permission.MODIFY, schema);
      policy.willDelete(schema);
      UpdatableSchema original = database.getReadMethodsForSchema().getSchema(s);
      DBCollection coll = getMongoDB(s).getSchemas();
      coll.remove(asQuery(s.getId()), WriteConcern.SAFE);
      database.sleep();
      try {
        policy.willDelete(schema);
      } catch (T2DBException e) {
        // Oops! referential integrity broken!
View Full Code Here

   * @throws T2DBException
   */
  public boolean updateSchema(UpdatableSchema schema, SchemaUpdatePolicy policy) throws T2DBException {
    boolean done = false;
    Throwable cause = null;
    Surrogate s = schema.getSurrogate();
    MongoDatabase database = (MongoDatabase) s.getDatabase();
    try {
      check(Permission.MODIFY, schema);
      UpdatableSchema original = database.getReadMethodsForSchema().getSchema(s);
      Schema base = schema.getBase();
      if (base != null && !base.equals(original.getBase()))
        check(Permission.READ, base);
      DBCollection coll = getMongoDB(s).getSchemas();
      // full replace (no need to set _id in full update)
      com.mongodb.DBObject operation = mongoObject(
          MongoDatabase.FLD_SCHEMA_NAME, schema.getName(),
          MongoDatabase.FLD_SCHEMA_BASE, getIdOrZero(schema.getBase()),
          MongoDatabase.FLD_SCHEMA_ATTRIBS,
          attributeDefinitions(schema.getAttributeDefinitions()),
          MongoDatabase.FLD_SCHEMA_SERIES,
          seriesDefinitions(schema.getSeriesDefinitions()));
      coll.update(asQuery(s.getId()), operation, false, false, WriteConcern.SAFE);
      database.sleep();
      try {
        policy.willUpdate(schema);
      } catch (T2DBException e) {
        // Oops! referential integrity broken!
        operation = mongoObject(
            MongoDatabase.FLD_SCHEMA_NAME, original.getName(),
            MongoDatabase.FLD_SCHEMA_BASE, getId(original.getBase()),
            MongoDatabase.FLD_SCHEMA_ATTRIBS, original.getAttributeDefinitions(),
            MongoDatabase.FLD_SCHEMA_SERIES, original.getSeriesDefinitions());
        coll.update(asQuery(s.getId()), operation);
        throw e;
      }
      done = true;
    } catch (Exception e) {
      cause = e;
View Full Code Here

   * @param schema a schema
   * @return a surrogate or null
   * @throws T2DBException
   */
  public Surrogate findChronicle(Schema schema) throws T2DBException {
    Surrogate result = null;
    try {
      Database db = schema.getDatabase();
      DBObject query = new BasicDBObject();
      query.put(MongoDatabase.FLD_CHRON_SCHEMA, getId(schema));
      DBObject obj = getMongoDB(db).getChronicles().findOne(query);
View Full Code Here

   * @param schema a schema
   * @return a surrogate or null
   * @throws T2DBException
   */
  public Surrogate findChronicle(Property<?> property, Schema schema) throws T2DBException {
    Surrogate result = null;
    DBCursor cursor = null
    try {
      Database db = schema.getDatabase();
      cursor = getMongoDB(db).getAttributes().find(mongoObject(
          MongoDatabase.FLD_ATTR_PROP, getId(property)));
      while (cursor.hasNext()) {
        ObjectId chrOid = ((BasicDBObject) cursor.next()).getObjectId(MongoDatabase.FLD_ATTR_CHRON);
        Surrogate entityKey = makeSurrogate(db, DBObjectType.CHRONICLE, chrOid);
        Schema s = db.getChronicle(entityKey).getSchema(true);
        if (s.dependsOnSchema(schema)) {
          result = entityKey;
          break;
        }
View Full Code Here

   * @param schema a schema
   * @return a surrogate or null
   * @throws T2DBException
   */
  public Surrogate findChronicle(SeriesDefinition ss, Schema schema) throws T2DBException {
    Surrogate result = null;
    DBCursor cursor1 = null
    DBCursor cursor2 = null
    try {
      Database db = schema.getDatabase();
      cursor1 = getMongoDB(db).getChronicles().find(mongoObject(
          MongoDatabase.FLD_CHRON_SCHEMA, getId(schema)));
      OUTER: while (cursor1.hasNext()) {
        ObjectId chronicleOid = getObjectId((BasicDBObject) cursor1.next());
        cursor2 = getMongoDB(db).getSeries().find(mongoObject(
            MongoDatabase.FLD_SER_CHRON, chronicleOid,
            MongoDatabase.FLD_SER_NUM, ss.getNumber()));
        while (cursor2.hasNext()) {
          Surrogate entityKey = makeSurrogate(db, DBObjectType.CHRONICLE, chronicleOid);
          Schema s = db.getChronicle(entityKey).getSchema(true);
          if (s.dependsOnSchema(schema)) {
            result = entityKey;
            break OUTER;
          }
View Full Code Here

    return result;
 
 
  private <T>DBObjectId insert(UpdatableSchema schema) throws T2DBException {
    com.mongodb.BasicDBObject bo = new BasicDBObject();
    Surrogate s = schema.getSurrogate();
    if (!s.inConstruction())
      bo.put(MongoDatabase.FLD_ID, getId(schema));
    bo.put(MongoDatabase.FLD_SCHEMA_NAME, schema.getName());
    bo.put(MongoDatabase.FLD_SCHEMA_BASE, getIdOrZero(schema.getBase()));
    bo.put(MongoDatabase.FLD_SCHEMA_ATTRIBS, attributeDefinitions(schema.getAttributeDefinitions()));
    bo.put(MongoDatabase.FLD_SCHEMA_SERIES, seriesDefinitions(schema.getSeriesDefinitions()));
View Full Code Here

   */
  public void createChronicle(Chronicle chronicle) throws T2DBException {
    createChronicle(chronicle, false);
  }
  private void createChronicle(Chronicle chronicle, boolean undoDelete) throws T2DBException {
    Surrogate surrogate = null;
    Throwable cause = null;
    try {
      String name = chronicle.getName(false);
      chronicle.getSurrogate().getDatabase().getNamingPolicy().checkSimpleName(name, false); // defensive
      String description = chronicle.getDescription(false);
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.