@Override
 protected synchronized Record getNext() throws NoSuchElementException {
   final FileGdbRecordStore recordStore = this.recordStore;
   final FileGdbEnumRowsIterator rows = this.rows;
   if (rows == null || this.closed) {
     throw new NoSuchElementException();
   } else {
     Row row = null;
     while (this.offset > 0 && this.count < this.offset) {
       row = rows.next();
       this.count++;
       if (this.closed) {
         throw new NoSuchElementException();
       }
     }
     if (this.count - this.offset >= this.limit) {
       throw new NoSuchElementException();
     }
     row = rows.next();
     this.count++;
     try {
       final Record record = this.recordFactory.newRecord(this.recordDefinition);
       if (this.labelCountMap == null) {
         recordStore.addStatistic("query", record);
       } else {
         this.labelCountMap.addCount(record);
       }
       record.setState(RecordState.INITIALIZING);
       for (final FieldDefinition field : this.recordDefinition.getFields()) {
         final String name = field.getName();
         final AbstractFileGdbFieldDefinition esriFieldDefinition =
             (AbstractFileGdbFieldDefinition) field;
         final Object value = esriFieldDefinition.getValue(row);
         record.setValue(name, value);
         if (this.closed) {
           throw new NoSuchElementException();
         }
       }
       record.setState(RecordState.PERSISTED);
       if (this.closed) {
         throw new NoSuchElementException();
       }
       return record;
     } finally {
       row.delete();
     }
   }
 }
Ejemplo n.º 2
0
  private void insert(final Record record) throws SQLException {
    final PathName typePath = record.getPathName();
    final RecordDefinition recordDefinition = getRecordDefinition(typePath);
    flushIfRequired(recordDefinition);
    final String idFieldName = recordDefinition.getIdFieldName();
    final boolean hasId = idFieldName != null;

    final GlobalIdProperty globalIdProperty = GlobalIdProperty.getProperty(record);
    if (globalIdProperty != null) {
      if (record.getValue(globalIdProperty.getFieldName()) == null) {
        record.setValue(globalIdProperty.getFieldName(), UUID.randomUUID().toString());
      }
    }

    final boolean hasIdValue = hasId && record.getValue(idFieldName) != null;

    if (!hasId || hasIdValue) {
      insert(record, typePath, recordDefinition);
    } else {
      insertSequence(record, typePath, recordDefinition);
    }
    record.setState(RecordState.PERSISTED);
    this.recordStore.addStatistic("Insert", record);
  }