Revision 20976 branches/v10/extensions/extArcims/src/es/prodevelop/cit/gvsig/arcims/fmap/drivers/FMapFeatureArcImsDriver.java

View differences:

FMapFeatureArcImsDriver.java
273 273
        osi.name = attsDataSourceAdapter.getTableName();
274 274
        osi.driverName = "ArcImsAttributesDataSourceAdapter";
275 275

  
276
        //		String tablename = attsDataSourceAdapter.getTableName();
277
        //		String sqlstr = "select * from " + tablename + " where " + ArcImsSqlUtils.rowIndexFieldName + " = 8;";
278
        //		DataSource result = null;
279
        //		int n = -1;
280 276
        try {
281
            //			attsDataSourceAdapter.start();
282
            //			result = dataSourceFactory.executeSQL(sqlstr, DataSourceFactory.AUTOMATIC_OPENING);
283
            //			attsDataSourceAdapter.stop();
284
            //			
285
            //			n = (int) result.getRowCount();
286 277
            dataSource = new SelectableDataSource(attsDataSourceAdapter);
287 278
        }
288 279
        catch (DriverException e) {
......
363 354
            logger.error("While loading selectable data source");
364 355
        }
365 356

  
366
        //		try {
367
        //			dataSource = new SelectableDataSource(attsDataSourceAdapter);
368
        //			View v = PluginServices.getMDIManager().getActiveView();
369
        //			
370
        //			if (v == null) {
371
        //				ProjectView newprojview = ProjectView.createView("Nueva");
372
        //				com.iver.cit.gvsig.gui.View newview = new com.iver.cit.gvsig.gui.View();
373
        //				newview.setModel(newprojview);
374
        //				Project newproj = new Project();
375
        //				newproj.setName("nuevo");
376
        //				newproj.addView(newprojview);
377
        //				v = newview;
378
        //			}
379
        //			ProjectView pv = ((com.iver.cit.gvsig.gui.View) v).getModel();
380
        //			ProjectTable pt = ProjectTable.createTable(attsDataSourceAdapter.getName(), dataSource);
381
        //			pv.getProject().addTable(pt);
382
        //		} catch (Exception e) {
383
        //			logger.error("While creating DataSource ", e);
384
        //			e.printStackTrace();
385
        //		}
386 357
    }
387 358

  
388 359
    private Value[] getAsValueArray(ArrayList ids) {
......
462 433
                added_row_ind = attsDataSourceAdapter.getRowIndex(id.getValue());
463 434

  
464 435
                addPseudoGeometry(ifeat.getGeometry(), added_row_ind);
465

  
466
                //				Value[] newrow = new Value[n_of_fields];
467
                //				for (int j = 0; j < n_of_fields; j++)
468
                //					newrow[j] = ifeat.getAttribute(j); 
469
                //				// System.err.println("Updating row with id = " + ((IntValue) newrow[1]).getValue());
470
                //				attsDataSourceAdapter..getRowIndex()
471
                //				added_row_ind = attsDataSourceAdapter.updateRow(newrow, f_query);
472

  
473
                // logger.debug("Added pair:  Visible: " + i + ", Overall: " + added_row_ind);
474 436
                overallIndexToVisibleIndex.put(new Integer(added_row_ind),
475 437
                    new Integer(i));
476 438
                visibleIndexToOverallIndex.put(new Integer(i),
......
490 452
        return "";
491 453
    }
492 454

  
493
    //	public ArrayList getGeometries() {
494
    //		if (geometries == null) {
495
    //			// geometris = client.get.....
496
    //			setTestGeometries();
497
    //		}
498
    //		return geometries;
499
    //	}
500
    //	
501 455
    public boolean connect(ICancellable cancel) {
502 456
        return client.connect(false, cancel);
503

  
504
        //		File csvFile = null;
505
        //		// This method is in libArcIMS
506
        //		// csvFile = client....connect(); (por ejemplo)
507
        //		
508
        //		JFileChooser jfc = new JFileChooser();
509
        //		jfc.setDialogTitle("Indice archivo CSV con los atributos de las geometrias");
510
        //	    int returnVal = jfc.showOpenDialog(null);
511
        //	    if (returnVal != JFileChooser.APPROVE_OPTION) {
512
        //	    	return false;
513
        //	    }
514
        //	    csvFile = jfc.getSelectedFile();
515
        //		if (! jfc.accept(csvFile)) return false;
516
        //		
517
        //		// csv = 
518
        //		// .....
519
        //		dataSource = getRecordSet(csvFile);
520
        //		// return client.connect();
521
        //		return true;
522 457
    }
523 458

  
524 459
    /**
......
528 463
     */
529 464
    public TreeMap getLayers() {
530 465
        return null;
531

  
532 466
        // This method is in libArcIMS
533 467
        // return client.getLayers();
534 468
    }
......
708 642
            return;
709 643
        }
710 644

  
711
        int[] ids = new int[length];
712 645
        int[] rowinds = new int[length];
713
        int idind = 0;
714 646

  
715 647
        try {
716
            for (int i = fbs.nextSetBit(0); i >= 0;
717
                    i = fbs.nextSetBit(i + 1)) {
718
                ids[idind] = attsDataSourceAdapter.getRowId(i);
719
                rowinds[idind] = i;
720
                idind++;
721
            }
648
        	int[] req_indices = enumarate(indlimits[0], indlimits[1]);
649
        	int sz = req_indices.length;
650
        	int[] req_ids = new int[sz];
651
        	for (int i=0; i<sz; i++)
652
        		req_ids[i] = attsDataSourceAdapter.getRowId(req_indices[i]);
722 653

  
723
            String minval = Integer.toString(attsDataSourceAdapter.getRowId(
724
                        indlimits[0]));
725
            String maxval = Integer.toString(attsDataSourceAdapter.getRowId(
726
                        indlimits[1]));
727

  
728 654
            int idcolindex = attsDataSourceAdapter.getIdIndex();
729 655
            String idFieldName = attsDataSourceAdapter.getOriginalFieldName(idcolindex);
730
            String whereClause = idFieldName + " &gt;= " + minval + " and " +
731
                idFieldName + " &lt;= " + maxval;
656
            String inParenthesis = getInIntParenthesis(req_ids);
657
            String whereClause = idFieldName + " " + inParenthesis;
732 658

  
733
            System.err.println("WHERE = " + whereClause);
734

  
735 659
            String[] subflds = new String[1];
736 660
            subflds[0] = "#ALL#";
737 661

  
738 662
            logger.debug("Justo antes de llamar a client.getAttributes(...)");
739 663

  
740
            // ---------------- with geometries -----------------------
741
            //			ArrayList atts = client.getAttributes(layer.getArcimsStatus(),
742
            //					subflds, whereClause, null);
743 664
            ArrayList atts = client.getAttributesWithEnvelope(layer.getArcimsStatus(),
744 665
                    subflds, whereClause, null);
666
            
667
            rowinds = getRowIndicesFromResponse(atts, idcolindex);
745 668

  
746 669
            // --------------------------------------------------------
747 670
            logger.debug("Justo despues de llamar a client.getAttributes(...)");
......
753 676
            for (int i = (atts.size() - 1); i >= 0; i--) {
754 677
                Value[] newrow = ((DefaultFeature) atts.get(i)).getAttributes();
755 678

  
756
                // Value[] newrow = (Value[]) atts.get(i);
757 679
                attsDataSourceAdapter.updateRow(newrow, subflds, rowinds[i]);
758 680
            }
759 681

  
......
781 703
        }
782 704
    }
783 705

  
784
    public void requestFeatureAttributesWithoutChecking(FBitSet fbs)
706
    private int[] enumarate(int a, int b) {
707

  
708
    	int[] resp = null;
709
    	if (a == b) {
710
    		resp = new int[1];
711
    		resp[0] = a;
712
    	} else {
713
    		
714
    		resp = new int[Math.abs(b-a+1)];
715
    		if (a < b) {
716
        		for (int i=a; i<=b; i++) resp[i-a] = i;
717
    		} else {
718
        		for (int i=b; i<=a; i++) resp[i-b] = i;
719
    		}
720
    	}
721
    	return resp;
722
    	
723
	}
724

  
725
	private int[] getRowIndicesFromResponse(ArrayList resp_list, int id_col_ind) {
726
    	
727
    	int sz = resp_list.size();
728
    	int[] resp = new int[sz];
729
    	int row_ind = 0;
730
    	for (int i=0; i<sz; i++) {
731
    		Value[] item_row = ((DefaultFeature) resp_list.get(i)).getAttributes();
732
    		IntValue idv = (IntValue) item_row[id_col_ind];
733
    		row_ind = idToRow(idv.intValue());
734
    		resp[i] = row_ind;
735
    	}
736
		return resp;
737
	}
738

  
739
	private int idToRow(int i) {
740
		try {
741
			return attsDataSourceAdapter.getRowIndex(i);
742
		} catch (DriverException e) {
743
			logger.error("While getting row index of id: " + i + " : " + e.getMessage());
744
			return 0;
745
		}
746
	}
747

  
748
	public void requestFeatureAttributesWithoutChecking(FBitSet fbs)
785 749
        throws ArcImsException {
786 750
        int length = fbs.cardinality();
787 751

  

Also available in: Unified diff