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); } } }
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); } } }
private void initializeEdition() throws DriverException { if (!initialized) { long rowCount = getDataSource().getRowCount(); // build alpha indexes on unique fields Metadata m = getMetadata(); for (int i = 0; i < m.getFieldCount(); i++) { Type type = m.getFieldType(i); if (type.getBooleanConstraint(Constraint.UNIQUE) || type.getBooleanConstraint(Constraint.PK)) { IndexManager indexManager = getDataSourceFactory().getIndexManager(); try { if (!indexManager.isIndexed(getName(), m.getFieldName(i))) { indexManager.buildIndex(getName(), m.getFieldName(i), new NullProgressMonitor()); } } catch (NoSuchTableException e) { throw new DriverException("table not found: " + getName(), e); } catch (IndexException e) { throw new DriverException("Cannot create index on unique fields", e); } } } // initialize directions rowsAddresses = new ArrayList<PhysicalRowAddress>(); for (int i = 0; i < rowCount; i++) { PhysicalRowAddress dir = new OriginalRowAddress(getDataSource(), i); rowsAddresses.add(dir); editionActions.add(new NoEditionInfo(getPK(i), i)); } Number[] xScope = getDataSource().getScope(DataSet.X); Number[] yScope = getDataSource().getScope(DataSet.Y); if ((xScope != null) && (yScope != null)) { cachedScope = new Envelope( new Coordinate(xScope[0].doubleValue(), yScope[0].doubleValue()), new Coordinate(xScope[1].doubleValue(), yScope[1].doubleValue())); } else { cachedScope = null; } initialized = true; } }
private synchronized List<Field> getFields() throws DriverException { if (null == fields) { ArrayList<Field> fieldArray = new ArrayList<Field>(); Metadata metadata = getDataSource().getMetadata(); if (metadata == null) { throw new DriverException( "Error initializing metadata; cannot get the metadata of" + " the inner source."); } final int fc = metadata.getFieldCount(); for (int i = 0; i < fc; i++) { fieldArray.add(new Field(i, metadata.getFieldName(i), getDataSource().getFieldType(i))); } fields = fieldArray; } return fields; }