Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
    *
    *  *  Copyright 2014 Orient Technologies LTD (info(at)orientechnologies.com)
    *  *
    *  *  Licensed under the Apache License, Version 2.0 (the "License");
    *  *  you may not use this file except in compliance with the License.
    *  *  You may obtain a copy of the License at
    *  *
    *  *       http://www.apache.org/licenses/LICENSE-2.0
   *  *
   *  *  Unless required by applicable law or agreed to in writing, software
   *  *  distributed under the License is distributed on an "AS IS" BASIS,
   *  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  *  See the License for the specific language governing permissions and
   *  *  limitations under the License.
   *  *
   *  * For more information: http://www.orientechnologies.com
   *
   */
 
 package com.orientechnologies.orient.graph.migration;
 
 import java.util.List;
 import java.util.Map;
 
In OrientDb 1.7-rc1 was introduced RidBag a new data structure for link management. Since OrientDB 1.7 RidBag is default data structure for management relationships in graph. Use this class to upgrade graphs created under older versions of OrientDB. Structure of manual indexes was changed too. This class is used to upgrade structure of manual indexes.

Author(s):
Artem Orobets (enisher-at-gmail.com)
 
 public class OGraphMigration {
   private final ODatabaseDocument      database;
 
   public OGraphMigration(ODatabaseDocument databaseOCommandOutputListener commandOutputListener) {
     this. = database;
     this. = commandOutputListener;
   }
 
   public void execute() {
     List<ODocumentvertexes = .query(new OSQLSynchQuery<ODocument>("select from V"));
 
     if ( != null)
       .onMessage(vertexes.size() + " vertexes were fetched to process.");
     for (int i = 0; i < vertexes.size(); i++) {
       final ODocument vertex = vertexes.get(i);
 
       for (String fieldName : vertex.fieldNames()) {
         if (fieldName.startsWith(.) || fieldName.startsWith(.)) {
           Object oldValue = vertex.field(fieldName);
           if (oldValue instanceof OMVRBTreeRIDSet) {
             OMVRBTreeRIDSet oldTree = (OMVRBTreeRIDSetoldValue;
             ORidBag bag = new ORidBag();
             bag.addAll(oldTree);
 
             vertex.field(fieldNamebag);
           }
         }
       }
       vertex.save();
 
       if ( != null && i % 10000 == 0)
         .onMessage(i + " vertexes were processed.");
     }
 
     if ( != null)
       .onMessage("All vertexes were processed, looking for manual indexes to update.");
 
     final OIndexManager indexManager = .getMetadata().getIndexManager();
 
     boolean indexWasMigrated = false;
     for (OIndex index : indexManager.getIndexes()) {
       final ODocument config = index.getConfiguration();
 
       ODocument metadata = index.getMetadata();
 
       if (config.field(.) != null && metadata == null) {
         if ( != null)
           .onMessage("Index " + index.getName() + " uses out of dated index format and will be updated.");
 
         final OIndex<OIdentifiablerecordKeyValueIndex = (OIndex<OIdentifiable>) 
             .getMetadata()
             .getIndexManager()
            .createIndex("__@recordmap@___" + index.getName(), ...toString(),
                new OSimpleKeyIndexDefinition(..), nullnullnull);
        OIndexCursor cursor = index.cursor();
        Map.Entry<ObjectOIdentifiableentry = cursor.nextEntry();
        while (entry != null) {
          final String keyTemp = entry.getKey().toString();
          final OIdentifiable identifiable = entry.getValue();
          recordKeyValueIndex.put(new OCompositeKey(identifiable.getIdentity(), keyTemp), identifiable.getIdentity());
          entry = cursor.nextEntry();
        }
        metadata = new ODocument();
        metadata.field(.recordKeyValueIndex.getName());
        config.field("metadata"metadata);
        indexWasMigrated = true;
        if ( != null)
          .onMessage("Index " + index.getName() + " structure was updated.");
      }
    }
    if (indexWasMigrated)
      indexManager.save();
    if ( != null)
      .onMessage("Graph database update is completed");
  }
New to GrepCode? Check out our FAQ X