protected IndexImpl mutateAddIndex(TableUpdater mutator) throws IOException {
  IndexBuilder index=mutator.getIndex();
  JetFormat format=mutator.getFormat();
  mutator.addTdefLen(format.SIZE_INDEX_INFO_BLOCK);
  int nameByteLen=DBMutator.calculateNameLength(index.getName());
  mutator.addTdefLen(nameByteLen);
  ByteBuffer tableBuffer=loadCompleteTableDefinitionBufferForUpdate(mutator);
  IndexImpl newIdx=null;
  boolean success=false;
  try {
    ByteUtil.forward(tableBuffer,35);
    tableBuffer.putInt(_logicalIndexCount + 1);
    tableBuffer.position(format.SIZE_TDEF_HEADER + (_indexCount * format.SIZE_INDEX_DEFINITION));
    ByteUtil.forward(tableBuffer,(_columns.size() * format.SIZE_COLUMN_DEF_BLOCK));
    skipNames(tableBuffer,_columns.size());
    ByteUtil.forward(tableBuffer,(_indexCount * format.SIZE_INDEX_COLUMN_BLOCK));
    ByteUtil.forward(tableBuffer,(_logicalIndexCount * format.SIZE_INDEX_INFO_BLOCK));
    int idxDefPos=tableBuffer.position();
    ByteUtil.insertEmptyData(tableBuffer,format.SIZE_INDEX_INFO_BLOCK);
    IndexImpl.writeDefinition(mutator,index,tableBuffer);
    skipNames(tableBuffer,_logicalIndexCount);
    ByteUtil.insertEmptyData(tableBuffer,nameByteLen);
    writeName(tableBuffer,index.getName(),mutator.getCharset());
    validateTableDefUpdate(mutator,tableBuffer);
    tableBuffer.position(idxDefPos);
    newIdx=new IndexImpl(tableBuffer,_indexDatas,format);
    newIdx.setName(index.getName());
    writeTableDefinitionBuffer(tableBuffer,_tableDefPageNumber,mutator,mutator.getNextPages());
    success=true;
  }
  finally {
    if (!success) {
      _tableDefBufferH.invalidate();
    }
  }
  ++_logicalIndexCount;
  _indexes.add(newIdx);
  completeTableMutation(tableBuffer);
  return newIdx;
}

protected IndexImpl mutateAddIndex ( TableUpdater mutator ) throws IOException { IndexBuilder index = mutator . getIndex ( ) ; JetFormat format = mutator . getFormat ( ) ; mutator . addTdefLen ( format . SIZE_INDEX_INFO_BLOCK ) ; int nameByteLen = DBMutator . calculateNameLength ( index . getName ( ) ) ; mutator . addTdefLen ( nameByteLen ) ; ByteBuffer tableBuffer = loadCompleteTableDefinitionBufferForUpdate ( mutator ) ; IndexImpl newIdx = null ; boolean success = false ; try { ByteUtil . forward ( tableBuffer , 35 ) ; tableBuffer . putInt ( _logicalIndexCount + 1 ) ; tableBuffer . position ( format . SIZE_TDEF_HEADER + ( _indexCount * format . SIZE_INDEX_DEFINITION ) ) ; ByteUtil . forward ( tableBuffer , ( _columns . size ( ) * format . SIZE_COLUMN_DEF_BLOCK ) ) ; skipNames ( tableBuffer , _columns . size ( ) ) ; ByteUtil . forward ( tableBuffer , ( _indexCount * format . SIZE_INDEX_COLUMN_BLOCK ) ) ; ByteUtil . forward ( tableBuffer , ( _logicalIndexCount * format . SIZE_INDEX_INFO_BLOCK ) ) ; int idxDefPos = tableBuffer . position ( ) ; ByteUtil . insertEmptyData ( tableBuffer , format . SIZE_INDEX_INFO_BLOCK ) ; IndexImpl . writeDefinition ( mutator , index , tableBuffer ) ; skipNames ( tableBuffer , _logicalIndexCount ) ; ByteUtil . insertEmptyData ( tableBuffer , nameByteLen ) ; writeName ( tableBuffer , index . getName ( ) , mutator . getCharset ( ) ) ; validateTableDefUpdate ( mutator , tableBuffer ) ; tableBuffer . position ( idxDefPos ) ; newIdx = new IndexImpl ( tableBuffer , _indexDatas , format ) ; newIdx . setName ( index . getName ( ) ) ; writeTableDefinitionBuffer ( tableBuffer , _tableDefPageNumber , mutator , mutator . getNextPages ( ) ) ; success = true ; } finally { if ( ! success ) { _tableDefBufferH . invalidate ( ) ; } } ++ _logicalIndexCount ; _indexes . add ( newIdx ) ; completeTableMutation ( tableBuffer ) ; return newIdx ; }
writes a index defined by the given tableupdater to this table .
