Exemplo n.º 1
0
  private static DBAttributeDescriptor getAttributeFromJDBC(
      DefaultFeatureType fType, Connection conn, ResultSetMetaData rsMetadata, int colIndex)
      throws SQLException {
    DBAttributeDescriptor column = (DBAttributeDescriptor) fType.createAttributeDescriptor();
    try {
      column.loading();
      column.setName(rsMetadata.getColumnName(colIndex));
      column.setCaseSensitive(rsMetadata.isCaseSensitive(colIndex));
      column.setSqlType(rsMetadata.getColumnType(colIndex));
      column.setAllowNull(rsMetadata.isNullable(colIndex) == ResultSetMetaData.columnNullable);
      column.setAutoIncrement(rsMetadata.isAutoIncrement(colIndex));
      column.setReadOnly(rsMetadata.isReadOnly(colIndex));
      column.setWritable(rsMetadata.isWritable(colIndex));
      column.setClassName(rsMetadata.getColumnClassName(colIndex));
      column.setCatalogName(rsMetadata.getCatalogName(colIndex));
      column.setDefinitelyWritable(rsMetadata.isDefinitelyWritable(colIndex));
      column.setLabel(rsMetadata.getColumnLabel(colIndex));
      column.setSchemaName(rsMetadata.getSchemaName(colIndex));
      column.setTableName(rsMetadata.getTableName(colIndex));
      column.setCatalogName(rsMetadata.getCatalogName(colIndex));
      column.setSqlTypeName(rsMetadata.getColumnTypeName(colIndex));
      column.setSearchable(rsMetadata.isSearchable(colIndex));
      column.setSigned(rsMetadata.isSigned(colIndex));
      column.setCurrency(rsMetadata.isCurrency(colIndex));
      column.setPrecision(rsMetadata.getPrecision(colIndex));
      column.setSize(rsMetadata.getColumnDisplaySize(colIndex));

      switch (rsMetadata.getColumnType(colIndex)) {
        case java.sql.Types.INTEGER:
          column.setType(FeatureAttributeDescriptor.INT);
          break;
        case java.sql.Types.BIGINT:
          column.setType(FeatureAttributeDescriptor.LONG);
          break;
        case java.sql.Types.REAL:
          column.setType(FeatureAttributeDescriptor.DOUBLE);
          break;
        case java.sql.Types.DOUBLE:
          column.setType(FeatureAttributeDescriptor.DOUBLE);
          break;
        case java.sql.Types.CHAR:
          column.setType(FeatureAttributeDescriptor.STRING);
          break;
        case java.sql.Types.VARCHAR:
          column.setType(FeatureAttributeDescriptor.STRING);
          break;
        case java.sql.Types.FLOAT:
          column.setType(FeatureAttributeDescriptor.FLOAT);
          break;
        case java.sql.Types.DECIMAL:
          column.setType(FeatureAttributeDescriptor.FLOAT);
          break;
        case java.sql.Types.DATE:
          column.setType(FeatureAttributeDescriptor.DATE);
          break;
        case java.sql.Types.TIME:
          column.setType(FeatureAttributeDescriptor.TIME);
          break;
        case java.sql.Types.TIMESTAMP:
          column.setType(FeatureAttributeDescriptor.TIMESTAMP);
          break;
        case java.sql.Types.BOOLEAN:
          column.setType(FeatureAttributeDescriptor.BOOLEAN);
          break;
        case java.sql.Types.OTHER:
          if (column.getSqlTypeName().equalsIgnoreCase("geometry")) {
            column.setType(FeatureAttributeDescriptor.GEOMETRY);
            break;
          }
          // No hacemos break para que se quede en default

        default:
          column.setType(FeatureAttributeDescriptor.OBJECT);
          break;
      }
      column.stopLoading();
    } catch (java.sql.SQLException e) {
      throw new SQLException("", "load attribute definition", e);
    } catch (IsNotAttributeSettingException e) {
      e.printStackTrace();
    }

    return column;
  }