core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLCreateIndex.java
@SuppressWarnings("rawtypes")
  public Object execute(final Map<Object, Object> iArgs) {
    if (indexName == null)
      throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");

    final ODatabaseDocument database = getDatabase();
    final OIndex<?> idx;
    List<OCollate> collatesList = null;

    if (collates != null) {
      collatesList = new ArrayList<OCollate>();

      for (String collate : collates) {
        if (collate != null) {
          final OCollate col = OSQLEngine.getCollate(collate);
          collatesList.add(col);
        } else
          collatesList.add(null);
      }
    }

    if (fields == null || fields.length == 0) {
      OIndexFactory factory = OIndexes.getFactory(indexType.toString(), null);

      if (keyTypes != null)
        idx = database.getMetadata().getIndexManager()
            .createIndex(indexName, indexType.toString(), new OSimpleKeyIndexDefinition(keyTypes, collatesList), null, null,
                metadataDoc, engine);
      else if (serializerKeyId != 0) {
        idx = database.getMetadata().getIndexManager()
            .createIndex(indexName, indexType.toString(), new ORuntimeKeyIndexDefinition(serializerKeyId), null, null, metadataDoc,
                engine);
      } else {
        throw new ODatabaseException("Impossible to create an index without specify the key type or the associated property");
      }
    } else {
      if ((keyTypes == null || keyTypes.length == 0) && collates == null) {
        idx = oClass.createIndex(indexName, indexType.toString(), null, metadataDoc, engine, fields);
      } else {
        final List<OType> fieldTypeList;
        if (keyTypes == null) {
          for (final String fieldName : fields) {
            if (!fieldName.equals("@rid") && !oClass.existsProperty(fieldName))
              throw new OIndexException(
                  "Index with name : '" + indexName + "' cannot be created on class : '" + oClass.getName() + "' because field: '"
                      + fieldName + "' is absent in class definition.");
          }
          fieldTypeList = ((OClassImpl) oClass).extractFieldTypes(fields);
        } else
          fieldTypeList = Arrays.asList(keyTypes);

        final OIndexDefinition idxDef = OIndexDefinitionFactory
            .createIndexDefinition(oClass, Arrays.asList(fields), fieldTypeList, collatesList, indexType.toString(), null);

        idx = database.getMetadata().getIndexManager()
            .createIndex(indexName, indexType.name(), idxDef, oClass.getPolymorphicClusterIds(), null, metadataDoc, engine);
      }
    }

    if (idx != null)
      return idx.getSize();

    return null;
  }
@SuppressWarnings("rawtypes")
  public Object execute(final Map<Object, Object> iArgs) {
    if (indexName == null)
      throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");

    final ODatabaseDocument database = getDatabase();
    final OIndex<?> idx;
    List<OCollate> collatesList = null;

    if (collates != null) {
      collatesList = new ArrayList<OCollate>();

      for (String collate : collates) {
        if (collate != null) {
          final OCollate col = OSQLEngine.getCollate(collate);
          collatesList.add(col);
        } else
          collatesList.add(null);
      }
    }

    if (fields == null || fields.length == 0) {
      OIndexFactory factory = OIndexes.getFactory(indexType.toString(), null);

      if (keyTypes != null)
        idx = database.getMetadata().getIndexManager()
            .createIndex(indexName, indexType.toString(), new OSimpleKeyIndexDefinition(keyTypes, collatesList), null, null,
                metadataDoc, engine);
      else if (serializerKeyId != 0) {
        idx = database.getMetadata().getIndexManager()
            .createIndex(indexName, indexType.toString(), new ORuntimeKeyIndexDefinition(serializerKeyId), null, null, metadataDoc,
                engine);
      } else {
        throw new ODatabaseException("Impossible to create an index without specify the key type or the associated property");
      }
    } else {
      if ((keyTypes == null || keyTypes.length == 0) && collates == null) {
        idx = oClass.createIndex(indexName, indexType.toString(), null, metadataDoc, engine, fields);
      } else {
        final List<OType> fieldTypeList;
        if (keyTypes == null) {
          for (final String fieldName : fields) {
            if (!fieldName.equals("@rid") && !oClass.existsProperty(fieldName))
              throw new OIndexException(
                  "Index with name : '" + indexName + "' cannot be created on class : '" + oClass.getName() + "' because field: '"
                      + fieldName + "' is absent in class definition.");
          }
          fieldTypeList = ((OClassImpl) oClass).extractFieldTypes(fields);
        } else
          fieldTypeList = Arrays.asList(keyTypes);

        final OIndexDefinition idxDef = OIndexDefinitionFactory
            .createIndexDefinition(oClass, Arrays.asList(fields), fieldTypeList, collatesList, indexType.toString(), null);

        idx = database.getMetadata().getIndexManager()
            .createIndex(indexName, indexType.name(), idxDef, oClass.getPolymorphicClusterIds(), null, metadataDoc, engine);
      }
    }

    if (idx != null)
      return idx.getSize();

    return null;
  }
@ SuppressWarnings ( "rawtypes" ) public Object execute ( final Map < Object , Object > iArgs ) { if ( indexName == null ) throw new OCommandExecutionException ( "Cannot execute the command because it has not been parsed yet" ) ; final ODatabaseDocument database = getDatabase ( ) ; final OIndex < ? > idx ; List < OCollate > collatesList = null ; if ( collates != null ) { collatesList = new ArrayList < OCollate > ( ) ; for ( String collate : collates ) { if ( collate != null ) { final OCollate col = OSQLEngine . getCollate ( collate ) ; collatesList . add ( col ) ; } else collatesList . add ( null ) ; } } if ( fields == null || fields . length == 0 ) { OIndexFactory factory = OIndexes . getFactory ( indexType . toString ( ) , null ) ; if ( keyTypes != null ) idx = database . getMetadata ( ) . getIndexManager ( ) . createIndex ( indexName , indexType . toString ( ) , new OSimpleKeyIndexDefinition ( keyTypes , collatesList ) , null , null , metadataDoc , engine ) ; else if ( serializerKeyId != 0 ) { idx = database . getMetadata ( ) . getIndexManager ( ) . createIndex ( indexName , indexType . toString ( ) , new ORuntimeKeyIndexDefinition ( serializerKeyId ) , null , null , metadataDoc , engine ) ; } else { throw new ODatabaseException ( "Impossible to create an index without specify the key type or the associated property" ) ; } } else { if ( ( keyTypes == null || keyTypes . length == 0 ) && collates == null ) { idx = oClass . createIndex ( indexName , indexType . toString ( ) , null , metadataDoc , engine , fields ) ; } else { final List < OType > fieldTypeList ; if ( keyTypes == null ) { for ( final String fieldName : fields ) { if ( ! fieldName . equals ( "@rid" ) && ! oClass . existsProperty ( fieldName ) ) throw new OIndexException ( "Index with name : '" + indexName + "' cannot be created on class : '" + oClass . getName ( ) + "' because field: '" + fieldName + "' is absent in class definition." ) ; } fieldTypeList = ( ( OClassImpl ) oClass ) . extractFieldTypes ( fields ) ; } else fieldTypeList = Arrays . asList ( keyTypes ) ; final OIndexDefinition idxDef = OIndexDefinitionFactory . createIndexDefinition ( oClass , Arrays . asList ( fields ) , fieldTypeList , collatesList , indexType . toString ( ) , null ) ; idx = database . getMetadata ( ) . getIndexManager ( ) . createIndex ( indexName , indexType . name ( ) , idxDef , oClass . getPolymorphicClusterIds ( ) , null , metadataDoc , engine ) ; } } if ( idx != null ) return idx . getSize ( ) ; return null ; }
Execute the CREATE INDEX.
Execute the CREATE INDEX .