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

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


      }
    };

    // drop all classes
    try (ODatabaseDocumentTx db = databaseInstanceProvider.get().acquire()) {
      OSchema schema = db.getMetadata().getSchema();
      maybeDropClass(schema, "testcomponent");
      maybeDropClass(schema, "component");
      maybeDropClass(schema, "testasset");
      maybeDropClass(schema, "asset");
    }
View Full Code Here


  }

  @Test
  public void schema() throws Exception {
    try (ODatabaseDocumentTx db = createDatabase()) {
      OSchema schema = db.getMetadata().getSchema();
      OClass eventData = schema.createClass("EventData");
      eventData.createProperty("type", OType.STRING);
      eventData.createProperty("timestamp", OType.LONG);
      eventData.createProperty("userId", OType.STRING);
      eventData.createProperty("sessionId", OType.STRING);
      eventData.createProperty("attributes", OType.EMBEDDEDMAP);

      log("Class: {}", eventData);
      log("Properties: {}", eventData.properties());

      // can count since we have defined schema
      log("Count: {}", db.countClass("EventData"));
    }

    try (ODatabaseDocumentTx db = openDatabase()) {
      OSchema schema = db.getMetadata().getSchema();
      OClass eventData = schema.getClass("EventData");

      log("Class: {}", eventData);
      log("Properties: {}", eventData.properties());
    }
  }
View Full Code Here

   * Register schema.
   */
  public OClass register(final ODatabaseDocumentTx db) {
    checkNotNull(db);

    OSchema schema = db.getMetadata().getSchema();
    OClass type = schema.getClass(DB_CLASS);
    if (type == null) {
      type = schema.createClass(DB_CLASS);

      type.createProperty(P_SOURCEID_NAME, OType.STRING).setNotNull(true);
      type.createProperty(P_SOURCEID_ID, OType.STRING).setNotNull(true);
      type.createProperty(P_FACTORYNAME, OType.STRING).setNotNull(true);
      type.createProperty(P_CONFIGURATION, OType.EMBEDDEDMAP);
View Full Code Here

  @Test
  public void maxClusters() throws Exception {
    log(" * Create database");
    try (ODatabaseDocumentTx db = createDatabase()) {
      OSchema schema = db.getMetadata().getSchema();
      OClass type = schema.createClass("Message");
      type.setClusterSelection(ODefaultClusterSelectionStrategy.NAME);
      type.createProperty("text", OType.STRING);
    }

    try (ODatabaseDocumentTx db = openDatabase()) {
      OSchema schema = db.getMetadata().getSchema();
      OClass type = schema.getClass("Message");
      int previousClusterId = type.getDefaultClusterId();

      for (int c = 0; c < 32_767 - 10; c++) {
        log("Previous cluster-id: {}", previousClusterId);

        log(" * Create new cluster #{}", c);

        // create new cluster
        String newClusterName = String.format("Message_%s", System.currentTimeMillis());
        type.addCluster(newClusterName);
        int newClusterId = db.getClusterIdByName(newClusterName);
        type.setDefaultClusterId(newClusterId);
        log("New cluster; id: {}, name: {}", newClusterId, newClusterName);

        log(" * create records");
        for (int i = 0; i < 1; i++) {
          db.newInstance("Message")
              .field("text", String.format("Hi %s", System.currentTimeMillis()))
              .save();
        }

        log(" * truncating cluster: id: {}", previousClusterId);
        type.removeClusterId(previousClusterId);
        db.dropCluster(previousClusterId, false);

        previousClusterId = newClusterId;
      }
    }

    log(" * dump clusters");
    try (ODatabaseDocumentTx db = openDatabase()) {
      OSchema schema = db.getMetadata().getSchema();
      OClass type = schema.getClass("Message");
      for (int clusterId : type.getClusterIds()) {
        String clusterName = db.getClusterNameById(clusterId);
        log("Cluster; id: {}, name: {}", clusterId, clusterName);
        for (ODocument doc : db.browseCluster(clusterName)) {
          log("Document: {}", doc);
View Full Code Here

  @Test
  public void clusterReUse() throws Exception {
    log(" * Create database");
    try (ODatabaseDocumentTx db = createDatabase()) {
      OSchema schema = db.getMetadata().getSchema();
      OClass type = schema.createClass("Message");
      type.setClusterSelection(ODefaultClusterSelectionStrategy.NAME);
      type.createProperty("text", OType.STRING);
    }

    for (int c = 0; c < 4; c++) {
      log(" * Create new cluster");
      try (ODatabaseDocumentTx db = openDatabase()) {
        OSchema schema = db.getMetadata().getSchema();
        OClass type = schema.getClass("Message");

        // create new cluster
        String newClusterName = String.format("Message_%s", System.currentTimeMillis());
        type.addCluster(newClusterName);
        int newClusterId = db.getClusterIdByName(newClusterName);
        type.setDefaultClusterId(newClusterId);
        log("New cluster; id: {}, name: {}", newClusterId, newClusterName);
      }

      log(" * create records");
      for (int i = 0; i < 4; i++) {
        try (ODatabaseDocumentTx db = openDatabase()) {
          db.newInstance("Message")
              .field("text", String.format("Hi %s", System.currentTimeMillis()))
              .save();
        }
      }
    }

    log(" * dump clusters");
    try (ODatabaseDocumentTx db = openDatabase()) {
      OSchema schema = db.getMetadata().getSchema();
      OClass type = schema.getClass("Message");
      for (int clusterId : type.getClusterIds()) {
        String clusterName = db.getClusterNameById(clusterId);
        log("Cluster; id: {}, name: {}", clusterId, clusterName);
        for (ODocument doc : db.browseCluster(clusterName)) {
          log("Document: {}", doc);
View Full Code Here

   * Register schema.
   */
  public OClass register(final ODatabaseDocumentTx db) {
    checkNotNull(db);

    OSchema schema = db.getMetadata().getSchema();
    OClass type = schema.getClass(DB_CLASS);
    if (type == null) {
      type = schema.createClass(DB_CLASS);

      type.createProperty(P_VIEWNAME, OType.STRING).setNotNull(true);
      type.createProperty(P_VIEWID, OType.STRING).setNotNull(true);
      type.createProperty(P_FACTORYNAME, OType.STRING).setNotNull(true);
      type.createProperty(P_CONFIGURATION, OType.EMBEDDEDMAP);
View Full Code Here

   * Register schema.
   */
  public OClass register(final ODatabaseDocumentTx db) {
    checkNotNull(db);

    OSchema schema = db.getMetadata().getSchema();
    OClass type = schema.getClass(DB_CLASS);
    if (type == null) {
      type = schema.createClass(DB_CLASS);

      type.createProperty(P_PATH, OType.STRING).setNotNull(true);
      type.createIndex(P_PATH + "idx", INDEX_TYPE.UNIQUE, P_PATH);
      type.createProperty(P_BLOBID, OType.STRING).setNotNull(true);
      type.createProperty(P_CONTENTTYPE, OType.STRING);
View Full Code Here

   * Register schema.
   */
  public OClass register(final ODatabaseDocumentTx db) {
    checkNotNull(db);

    OSchema schema = db.getMetadata().getSchema();
    OClass type = schema.getClass(DB_CLASS);
    if (type == null) {
      type = schema.createClass(DB_CLASS);
      type.createProperty(P_VERSION, OType.INTEGER);
      type.createProperty(P_TYPE, OType.STRING);
      type.createProperty(P_ENABLED, OType.BOOLEAN);
      type.createProperty(P_NOTES, OType.STRING);
      type.createProperty(P_PROPERTIES, OType.EMBEDDEDMAP);
View Full Code Here

  @Override
  public void doStart() throws Exception {
    try (ODatabaseDocumentTx db = databaseManager.connect(DB_NAME, true)) {

      // entities
      final OSchema schema = db.getMetadata().getSchema();
      if (!schema.existsClass(DB_CLASS)) {
        final OClass type = schema.createClass(DB_CLASS);
        type.createProperty(P_TIMESTAMP, OType.LONG);
        type.createProperty(P_TYPE, OType.STRING);
        type.createProperty(P_SUBTYPE, OType.STRING);
        type.createProperty(P_DATA, OType.EMBEDDEDMAP, OType.STRING);
        type.createIndex(I_TYPE, INDEX_TYPE.NOTUNIQUE_HASH_INDEX, P_TYPE);
View Full Code Here

    final String name = String.format("%s%s", DB_CLUSTER_PREFIX,
        new DateMidnight(timestamp, DateTimeZone.UTC).toString("YYYYMMdd"));
    int cid = db.getClusterIdByName(name); // undocumented: if cluster not exists, returns -1
    if (cid == -1) {
      cid = db.addCluster(name);
      final OSchema schema = db.getMetadata().getSchema();
      final OClass type = schema.getClass(DB_CLASS);
      type.addClusterId(cid);
      log.info("Created new journal cluster; id: {}, name: {}", cid, name);
    }
    else {
      log.debug("Journal cluster exists; id: {}, name: {}", cid, name);
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.