Revision 45919 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/operations/FetchFeatureTypeOperation.java

View differences:

FetchFeatureTypeOperation.java
30 30
import java.sql.SQLException;
31 31
import java.sql.Statement;
32 32
import java.util.ArrayList;
33
import java.util.HashMap;
33 34
import java.util.List;
35
import java.util.Map;
34 36
import org.apache.commons.collections.CollectionUtils;
35 37
import org.apache.commons.lang3.StringUtils;
36 38
import org.cresques.cts.IProjection;
......
39 41
import org.gvsig.fmap.dal.exception.DataException;
40 42
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
41 43
import org.gvsig.fmap.dal.feature.EditableFeatureType;
42
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
43 44
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
44 45
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
45 46
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
......
52 53

  
53 54
@SuppressWarnings("UseSpecificCatch")
54 55
public class FetchFeatureTypeOperation extends AbstractConnectionOperation {
56

  
57
    protected static class IndexInformation {
58
        String column_name;
59
        boolean ascending;
60
        boolean unique;
61
    }
62

  
55 63
    protected final EditableFeatureType featureType;
56 64
    protected final TableReference table;
57 65
    protected final List<String> primaryKeys;
......
60 68
    protected final int geometryType;
61 69
    protected final int geometrySubtype;
62 70

  
71
    protected Map<String,IndexInformation> indexesInformation;
72

  
63 73
    public FetchFeatureTypeOperation(
64 74
            JDBCHelper helper
65 75
        ) {
......
150 160
    
151 161
    
152 162
    public void fetchFeatureTypeFromMetadata(Connection conn, ResultSetMetaData rsMetadata) throws SQLException {
153
        this.fetchFeatureTypeFromMetadata(conn, rsMetadata, new ArrayList<String>());
163
        this.fetchFeatureTypeFromMetadata(conn, rsMetadata, new ArrayList<>());
154 164
    }
155 165

  
156 166
    protected void fetchFeatureTypeFromMetadata(Connection conn, ResultSetMetaData rsMetadata, List<String> pks) throws SQLException {
......
407 417
                this.fetchGeometryTypeAndSRS(attr, rsMetadata, colIndex);
408 418
                break;
409 419
        }
420
        IndexInformation indexInformation = this.getIndexesInformation(conn).get(attr.getName());
421
        if( indexInformation!=null ) {
422
            attr.setIsIndexed(true);
423
            attr.setIsIndexAscending(indexInformation.ascending);
424
//            attr.setIsIndexUnique(indexInformation.unique);
425
        }
410 426
        return attr;
411 427
    }
428
       
429
    protected Map<String,IndexInformation> getIndexesInformation(
430
            Connection conn
431
        ) throws SQLException {
432
        if( this.indexesInformation==null ) {
433
            this.indexesInformation = new HashMap<>();
434
            DatabaseMetaData metaData = conn.getMetaData();
435
            if( metaData!=null ) {
436
                ResultSet rsIndexes = metaData.getIndexInfo(null, this.table.getSchema(), this.table.getTable(), false, false);
437
                if( rsIndexes!=null ) {
438
                    while( rsIndexes.next() ) {
439
                        IndexInformation x = new IndexInformation();
440
                        x.column_name = rsIndexes.getString("COLUMN_NAME");
441
                        String asc_or_desc = rsIndexes.getString("ASC_OR_DESC");
442
                        // ASC_OR_DESC String => column sort sequence, 
443
                        // "A" => ascending, 
444
                        // "D" => descending, 
445
                        // may be null if sort sequence is not supported; 
446
                        // null when TYPE is tableIndexStatistic
447
                        if( StringUtils.isNotBlank(asc_or_desc) ) {
448
                            if( asc_or_desc.equalsIgnoreCase("A") ) {
449
                                x.ascending = true;
450
                            } else {
451
                                x.ascending = false;
452
                            }
453
                        }
454
                        x.unique = !rsIndexes.getBoolean("NON_UNIQUE");
455
                        // NON_UNIQUE boolean => Can index values be non-unique. 
456
                        // false when TYPE is tableIndexStatistic 
457
                    }
458
                }
459
            }
460
        }
461
        return this.indexesInformation;
462
    }    
412 463

  
413 464
    protected int getDataTypeFromMetadata(
414 465
            ResultSetMetaData rsMetadata,

Also available in: Unified diff