コード例 #1
0
ファイル: OSchemaShared.java プロジェクト: jango2015/orientdb
  private void dropClassIndexes(final OClass cls) {
    final ODatabaseDocument database = getDatabase();
    final OIndexManager indexManager = database.getMetadata().getIndexManager();

    for (final OIndex<?> index : indexManager.getClassIndexes(cls.getName()))
      indexManager.dropIndex(index.getName());
  }
コード例 #2
0
ファイル: OSchemaShared.java プロジェクト: jango2015/orientdb
  private void deleteDefaultCluster(final OClass clazz) {
    final ODatabaseDocumentInternal database = getDatabase();
    final int clusterId = clazz.getDefaultClusterId();
    final OCluster cluster = database.getStorage().getClusterById(clusterId);

    if (cluster.getName().equalsIgnoreCase(clazz.getName()))
      database.getStorage().dropCluster(clusterId, true);

    // FREE THE RECORD CACHE
    getDatabase().getLocalCache().freeCluster(clusterId);
  }
コード例 #3
0
  @Override
  public void merge(ImmutableOntologyVocabulary v) {
    if (v instanceof OntologyVocabularyImpl) {
      OntologyVocabularyImpl vi = (OntologyVocabularyImpl) v;

      concepts.putAll(vi.concepts);
      objectProperties.putAll(vi.objectProperties);
      dataProperties.putAll(vi.dataProperties);
      annotationProperties.putAll(vi.annotationProperties);
    } else {
      for (OClass oc : v.getClasses())
        if (!oc.isTop() && !oc.isBottom()) concepts.put(oc.getName(), oc);
      for (ObjectPropertyExpression ope : v.getObjectProperties())
        if (!ope.isTop() && !ope.isBottom()) objectProperties.put(ope.getName(), ope);
      for (DataPropertyExpression dpe : v.getDataProperties())
        if (!dpe.isTop() && !dpe.isBottom()) dataProperties.put(dpe.getName(), dpe);
      for (AnnotationProperty ap : v.getAnnotationProperties())
        annotationProperties.put(ap.getName(), ap);
    }
  }
コード例 #4
0
ファイル: OProperty.java プロジェクト: astubbs/orient
  @OBeforeSerialization
  public ODocument toStream() {
    document.field("name", name);
    document.field("type", type.id);
    document.field("offset", offset);
    document.field("mandatory", mandatory);
    document.field("notNull", notNull);
    document.field("min", min);
    document.field("max", max);

    document.field("linkedClass", linkedClass != null ? linkedClass.getName() : null);
    document.field("linkedType", linkedType != null ? linkedType.id : null);

    // SAVE THE INDEX
    if (index != null) {
      index.lazySave();
      document.field("index", index.getRID());
      document.field("index-type", index.getType());
    } else {
      document.field("index", ORecordId.EMPTY_RECORD_ID);
    }
    return document;
  }
コード例 #5
0
ファイル: OSchemaShared.java プロジェクト: jango2015/orientdb
  private OClass doCreateClass(
      final String className, final int[] clusterIds, int retry, OClass... superClasses)
      throws ClusterIdsAreEmptyException {
    OClass result;

    final ODatabaseDocumentInternal db = getDatabase();
    final OStorage storage = db.getStorage();
    StringBuilder cmd = null;

    getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_CREATE);
    acquireSchemaWriteLock();
    try {

      final String key = className.toLowerCase();
      if (classes.containsKey(key) && retry == 0)
        throw new OSchemaException("Class " + className + " already exists in current database");

      if (!isDistributedCommand()) checkClustersAreAbsent(clusterIds);

      cmd = new StringBuilder("create class ");
      // if (getDatabase().getStorage().getConfiguration().isStrictSql())
      // cmd.append('`');
      cmd.append(className);
      // if (getDatabase().getStorage().getConfiguration().isStrictSql())
      // cmd.append('`');

      List<OClass> superClassesList = new ArrayList<OClass>();
      if (superClasses != null && superClasses.length > 0) {
        boolean first = true;
        for (OClass superClass : superClasses) {
          // Filtering for null
          if (superClass != null) {
            if (first) cmd.append(" extends ");
            else cmd.append(", ");
            cmd.append(superClass.getName());
            first = false;
            superClassesList.add(superClass);
          }
        }
      }

      if (clusterIds != null) {
        if (clusterIds.length == 1 && clusterIds[0] == -1) cmd.append(" abstract");
        else {
          cmd.append(" cluster ");
          for (int i = 0; i < clusterIds.length; ++i) {
            if (i > 0) cmd.append(',');
            else cmd.append(' ');

            cmd.append(clusterIds[i]);
          }
        }
      }

      if (isDistributedCommand()) {
        createClassInternal(className, clusterIds, superClassesList);

        final OAutoshardedStorage autoshardedStorage = (OAutoshardedStorage) storage;
        OCommandSQL commandSQL = new OCommandSQL(cmd.toString());
        commandSQL.addExcludedNode(autoshardedStorage.getNodeId());

        final Object res = db.command(commandSQL).execute();

      } else if (storage instanceof OStorageProxy) {
        db.command(new OCommandSQL(cmd.toString())).execute();
        reload();
      } else createClassInternal(className, clusterIds, superClassesList);

      result = classes.get(className.toLowerCase());

      // WAKE UP DB LIFECYCLE LISTENER
      for (Iterator<ODatabaseLifecycleListener> it = Orient.instance().getDbLifecycleListeners();
          it.hasNext(); ) it.next().onCreateClass(getDatabase(), result);

    } finally {
      releaseSchemaWriteLock();
    }

    return result;
  }