Package com.orientechnologies.orient.core.metadata.schema

Examples of com.orientechnologies.orient.core.metadata.schema.OSchema


          final int month = Integer.parseInt(name.substring(prefixLen + 4, prefixLen + 6));
          final int day = Integer.parseInt(name.substring(prefixLen + 6, prefixLen + 8));
          final DateMidnight clusterDm = new DateMidnight(year, month, day, DateTimeZone.UTC);
          if (Days.daysBetween(clusterDm, nowDm).getDays() >= days) {
            log.info("Cluster {}, is {} days old, purging it", name, Days.daysBetween(clusterDm, nowDm).getDays());
            OSchema schema = db.getMetadata().getSchema();
            OClass type = schema.getClass(DB_CLASS);
            type.removeClusterId(cid);
            db.dropCluster(cid, true);
          }
        }
      }
View Full Code Here


      storage2.close();
    }
  }

  private void compareSchama() {
    OSchema schema1 = databaseDocumentTxOne.getMetadata().getSchema();
    OSchema schema2 = databaseDocumentTxTwo.getMetadata().getSchema();
    boolean ok = true;
    for (OClass clazz : schema1.getClasses()) {
      OClass clazz2 = schema2.getClass(clazz.getName());
      if (clazz2 == null) {
        listener.onMessage("\n- ERR: Class definition " + clazz.getName() + " for DB2 is null.");
        continue;
      }
      if (clazz.getSuperClass() != null) {
View Full Code Here

  @Override
  protected boolean evaluateExpression(final OIdentifiable iRecord, final OSQLFilterCondition iCondition, final Object iLeft,
      final Object iRight, OCommandContext iContext) {

    final OSchema schema = ODatabaseRecordThreadLocal.INSTANCE.get().getMetadata().getSchema();

    final String baseClassName = iRight.toString();
    final OClass baseClass = schema.getClass(baseClassName);
    if (baseClass == null)
      throw new OCommandExecutionException("Class '" + baseClassName + "' is not defined in database schema");

    OClass cls = null;
    if (iLeft instanceof OIdentifiable) {
      // GET THE RECORD'S CLASS
      final ORecord record = ((OIdentifiable) iLeft).getRecord();
      if (record instanceof ODocument) {
        cls = ((ODocument) record).getSchemaClass();
      }
    } else if (iLeft instanceof String)
      // GET THE CLASS BY NAME
      cls = schema.getClass((String) iLeft);

    return cls != null ? cls.isSubClassOf(baseClass) : false;
  }
View Full Code Here

    // In v4 new cluster for manual indexes has been implemented. To keep database consistent we should shift back
    // all clusters and recreate cluster for manual indexes in the end.
    database.dropCluster(OMetadataDefault.CLUSTER_MANUAL_INDEX_NAME, true);

    final OSchema schema = database.getMetadata().getSchema();
    if (schema.existsClass(OUser.CLASS_NAME))
      schema.dropClass(OUser.CLASS_NAME);
    if (schema.existsClass(ORole.CLASS_NAME))
      schema.dropClass(ORole.CLASS_NAME);
    if (schema.existsClass(OSecurityShared.RESTRICTED_CLASSNAME))
      schema.dropClass(OSecurityShared.RESTRICTED_CLASSNAME);
    if (schema.existsClass(OFunction.CLASS_NAME))
      schema.dropClass(OFunction.CLASS_NAME);
    if (schema.existsClass(OMVRBTreeRIDProvider.PERSISTENT_CLASS_NAME))
      schema.dropClass(OMVRBTreeRIDProvider.PERSISTENT_CLASS_NAME);
    if (schema.existsClass(OClassTrigger.CLASSNAME))
      schema.dropClass(OClassTrigger.CLASSNAME);
    schema.save();

    database.dropCluster(OStorage.CLUSTER_DEFAULT_NAME, true);

    database.getStorage().setDefaultClusterId(database.addCluster(OStorage.CLUSTER_DEFAULT_NAME));
View Full Code Here

  @BeforeTest
  public void before() {
    db = new ODatabaseDocumentTx("memory:" + OCompositeIndexSQLInserTest.class.getSimpleName());
    db.create();
    OSchema schema = db.getMetadata().getSchema();
    OClass book = schema.createClass("Book");
    book.createProperty("author", OType.STRING);
    book.createProperty("title", OType.STRING);
    book.createProperty("publicationYears", OType.EMBEDDEDLIST, OType.INTEGER);
    book.createIndex("books", "unique", "author", "title", "publicationYears");
  }
View Full Code Here

    db.drop();
  }

  @Test
  public void testShortName() {
    OSchema schema = db.getMetadata().getSchema();
    OClass oClass = schema.createClass(SHORTNAME_CLASS_NAME);
    Assert.assertNull(oClass.getShortName());
    Assert.assertNull(queryShortName());

    final OStorage storage = db.getStorage();
View Full Code Here

  }

  @Test
  public void testRename() {
    OSchema schema = db.getMetadata().getSchema();
    OClass oClass = schema.createClass("ClassName");

    final OStorage storage = db.getStorage();
    final OAbstractPaginatedStorage paginatedStorage = (OAbstractPaginatedStorage) storage;
    final ODiskCache diskCache = paginatedStorage.getDiskCache();
View Full Code Here

    Assert.assertTrue(diskCache.exists("classname" + OPaginatedCluster.DEF_EXTENSION));
  }

  @Test
  public void testRenameClusterAlreadyExists() {
    OSchema schema = db.getMetadata().getSchema();
    OClass classOne = schema.createClass("ClassOne");
    OClass classTwo = schema.createClass("ClassTwo");

    final int clusterId = db.addCluster("classthree");
    classTwo.addClusterId(clusterId);

    ODocument document = new ODocument("ClassTwo");
View Full Code Here

      return null;

    if (isDetached())
      return className;

    final OSchema schema = graph.getRawGraph().getMetadata().getSchema();

    if (!schema.existsClass(className)) {
      // CREATE A NEW CLASS AT THE FLY
      try {
        graph
            .executeOutsideTx(new OCallable<OClass, OrientBaseGraph>() {

              @Override
              public OClass call(final OrientBaseGraph g) {
                return schema.createClass(className, schema.getClass(getBaseClassName()));

              }
            }, "Committing the active transaction to create the new type '", className, "' as subclass of '", getBaseClassName(),
                "'. The transaction will be reopen right after that. To avoid this behavior create the classes outside the transaction");

      } catch (OSchemaException e) {
        if (!schema.existsClass(className))
          throw e;
      }
    } else {
      // CHECK THE CLASS INHERITANCE
      final OClass cls = schema.getClass(className);
      if (!cls.isSubClassOf(getBaseClassName()))
        throw new IllegalArgumentException("Class '" + className + "' is not an instance of " + getBaseClassName());
    }

    return className;
View Full Code Here

  @SuppressWarnings("unchecked")
  @Test
  public void testTruncateClass() {

    OSchema schema = database.getMetadata().getSchema();
    OClass testClass = getOrCreateClass(schema);

    final OIndex<?> index = getOrCreateIndex(testClass);
    schema.save();

    database.command(new OCommandSQL("truncate class test_class")).execute();

    database.save(new ODocument(testClass).field("name", "x").field("data", Arrays.asList(1, 2)));
    database.save(new ODocument(testClass).field("name", "y").field("data", Arrays.asList(3, 0)));

    database.command(new OCommandSQL("truncate class test_class")).execute();

    database.save(new ODocument(testClass).field("name", "x").field("data", Arrays.asList(5, 6, 7)));
    database.save(new ODocument(testClass).field("name", "y").field("data", Arrays.asList(8, 9, -1)));

    List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>("select from test_class"));
    Assert.assertEquals(result.size(), 2);
    Set<Integer> set = new HashSet<Integer>();
    for (ODocument document : result) {
      set.addAll((Collection<Integer>) document.field("data"));
    }
    Assert.assertTrue(set.containsAll(Arrays.asList(5, 6, 7, 8, 9, -1)));

    Assert.assertEquals(index.getSize(), 6);

    OIndexCursor cursor = index.cursor();
    Map.Entry<Object, OIdentifiable> entry = cursor.nextEntry();
    while (entry != null) {
      Assert.assertTrue(set.contains((Integer) entry.getKey()));
      entry = cursor.nextEntry();
    }

    schema.dropClass("test_class");
  }
View Full Code Here

TOP

Related Classes of com.orientechnologies.orient.core.metadata.schema.OSchema

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.