@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();
     }
   }
 }
예제 #2
0
  public static void write(
      final File file, final RecordDefinition recordDefinition, final String dataSource)
      throws IOException {
    try (XmlWriter writer = new XmlWriter(new FileWriter(file))) {
      writer.setIndent(true);
      writer.startDocument("UTF-8", "1.0");
      writer.startTag("OGRVRTDataSource");
      writer.startTag("OGRVRTLayer");
      final String typeName = recordDefinition.getName();
      writer.attribute("name", typeName);
      writer.startTag("SrcDataSource");
      writer.attribute("relativeToVRT", "1");
      writer.text(dataSource);
      writer.endTag("SrcDataSource");

      writer.element(new QName("SrcLayer"), typeName);

      for (final FieldDefinition attribute : recordDefinition.getFields()) {
        final String fieldName = attribute.getName();
        final DataType fieldType = attribute.getDataType();
        final Class<?> typeClass = attribute.getTypeClass();
        if (Geometry.class.isAssignableFrom(typeClass)) {
          final GeometryFactory geometryFactory = recordDefinition.getGeometryFactory();
          writer.element("GeometryType", "wkb" + fieldType);
          if (geometryFactory != null) {
            writer.element("LayerSRS", "EPSG:" + geometryFactory.getCoordinateSystemId());
          }
          writer.startTag("GeometryField");
          writer.attribute("encoding", "WKT");
          writer.attribute("field", fieldName);
          writer.attribute("name", fieldName);
          writer.attribute("reportSrcColumn", "FALSE");
          writer.element("GeometryType", "wkb" + fieldType);
          if (geometryFactory != null) {
            writer.element("SRS", "EPSG:" + geometryFactory.getCoordinateSystemId());
          }
          writer.endTag("GeometryField");
        } else {
          writer.startTag("Field");
          writer.attribute("name", fieldName);
          String type = "String";
          if (Arrays.asList(
                  DataTypes.BYTE, DataTypes.SHORT, DataTypes.INT, DataTypes.LONG, DataTypes.INTEGER)
              .contains(fieldType)) {
            type = "Integer";
          } else if (Arrays.asList(DataTypes.FLOAT, DataTypes.DOUBLE, DataTypes.DECIMAL)
              .contains(fieldType)) {
            type = "Real";
          } else if (DataTypes.DATE.equals(type)) {
            type = "Date";
          } else if (DataTypes.DATE_TIME.equals(type)) {
            type = "DateTime";
          } else {
            type = "String";
          }
          writer.attribute("type", type);
          final int length = attribute.getLength();
          if (length > 0) {
            writer.attribute("width", length);
          }
          final int scale = attribute.getScale();
          if (scale > 0) {
            writer.attribute("scale", scale);
          }
          writer.attribute("src", fieldName);
          writer.endTag("Field");
        }
      }
      writer.endTag("OGRVRTLayer");
      writer.endTag("OGRVRTDataSource");
      writer.endDocument();
    }
  }