示例#1
0
 private void setFieldValueInIndex(int rowIndex, int fieldId, Value oldValue, Value value)
     throws DriverException {
   if (indexEditionManager != null) {
     try {
       for (DataSourceIndex index : indexEditionManager.getDataSourceIndexes()) {
         String[] idxFields = index.getFieldNames();
         if (idxFields.length == 1) {
           if (idxFields[0].equals(getMetadata().getFieldName(fieldId))) {
             index.setFieldValue(oldValue, value, rowIndex);
           }
         } else {
           Value[] oldSet = new Value[idxFields.length];
           Value[] newSet = new Value[idxFields.length];
           String fieldName = getFieldName(fieldId);
           for (int i = 0; i < idxFields.length; i++) {
             if (idxFields[i].equals(fieldName)) {
               oldSet[i] = oldValue;
               newSet[i] = value;
             } else {
               oldSet[i] = getFieldValue(rowIndex, getFieldIndexByName(idxFields[i]));
               newSet[i] = oldSet[i];
             }
           }
           index.setFieldValue(
               ValueFactory.createValue(oldSet), ValueFactory.createValue(newSet), rowIndex);
         }
       }
     } catch (IndexException e) {
       throw new DriverException(e);
     }
   }
 }
示例#2
0
 private void insertInIndex(Value[] values, int rowIndex) throws DriverException {
   if (indexEditionManager != null) {
     try {
       for (DataSourceIndex index : indexEditionManager.getDataSourceIndexes()) {
         Metadata metadata = getMetadata();
         String[] idxFields = index.getFieldNames();
         if (idxFields.length == 1) {
           for (int i = 0; i < metadata.getFieldCount(); i++) {
             if (metadata.getFieldName(i).equals(idxFields[0])) {
               index.insertRow(values[i], rowIndex);
             }
           }
         } else {
           Value[] toInsert = new Value[idxFields.length];
           for (int i = 0; i < metadata.getFieldCount(); i++) {
             for (int j = 0; j < idxFields.length; j++) {
               if (metadata.getFieldName(i).equals(idxFields[j])) {
                 toInsert[j] = values[i];
               }
             }
             index.insertRow(ValueFactory.createValue(values), rowIndex);
           }
         }
       }
     } catch (IndexException e) {
       throw new DriverException("Cannot update index", e);
     }
   }
 }
示例#3
0
 private void deleteInIndex(int rowIndex) throws DriverException {
   if (indexEditionManager != null) {
     try {
       for (DataSourceIndex index : indexEditionManager.getDataSourceIndexes()) {
         Metadata metadata = getMetadata();
         String[] idxFields = index.getFieldNames();
         if (idxFields.length == 1) {
           for (int i = 0; i < metadata.getFieldCount(); i++) {
             if (metadata.getFieldName(i).equals(idxFields[0])) {
               Value v = getFieldValue(rowIndex, i);
               index.deleteRow(v, rowIndex);
             }
           }
         } else {
           Value[] toInsert = new Value[idxFields.length];
           for (int i = 0; i < metadata.getFieldCount(); i++) {
             for (int j = 0; j < idxFields.length; j++) {
               if (metadata.getFieldName(i).equals(idxFields[j])) {
                 toInsert[j] = getFieldValue(rowIndex, i);
               }
             }
             index.deleteRow(ValueFactory.createValue(toInsert), rowIndex);
           }
         }
       }
     } catch (IndexException e) {
       throw new DriverException(e);
     }
   }
 }
示例#4
0
 @Override
 public void syncWithSource() throws DriverException {
   getDataSource().syncWithSource();
   indexEditionManager.cancel();
   freeResources();
   initialize();
   editionListenerSupport.callSync();
 }
示例#5
0
  @Override
  public void close() throws DriverException {
    freeResources();
    getDataSource().close();
    indexEditionManager.cancel();

    SourceManager sm = getDataSourceFactory().getSourceManager();
    sm.removeCommitListener(this);
  }
示例#6
0
 @Override
 public Iterator<Integer> queryIndex(IndexQuery indexQuery) throws DriverException {
   if (!isModified()) {
     return getDataSource().queryIndex(indexQuery);
   } else {
     try {
       int[] result = indexEditionManager.query(indexQuery);
       if (result == null) {
         return new FullIterator(this);
       } else {
         return new ResultIterator(result);
       }
     } catch (IndexException e) {
       throw new DriverException("Cannot access modified index", e);
     } catch (IndexQueryException e) {
       throw new DriverException("Cannot query the index", e);
     }
   }
 }
示例#7
0
  @Override
  public void commit() throws DriverException, NonEditableDataSourceException {
    if (!getDriver().isCommitable()) {
      throw new NonEditableDataSourceException("The driver has no write capabilities");
    }

    if (commiter != null) {
      SourceManager dsm = getDataSourceFactory().getSourceManager();
      dsm.fireIsCommiting(getName(), this);
      boolean rebuildIndexes =
          commiter.commit(
              rowsAddresses, getFieldNames(), getSchemaActions(), editionActions, deletedPKs, this);
      dsm.fireCommitDone(getName());

      try {
        indexEditionManager.commit(rebuildIndexes);
      } catch (DriverException e) {
        throw new DriverException("Cannot update indexes", e);
      }
    } else {
      throw new UnsupportedOperationException("DataSource not editable");
    }
  }