//package arpClasses.DB;

//import arpClasses.Drawing.PolyLine;
//import arpClasses.Interface.*;
//import arpClasses.Serialize.arpArc;
//import arpClasses.Search.FinalData;
import java.sql.*;
import java.util.*;
import java.io.*;
/**
 *    This class use to execute queries in ARP
 *    @author Alan Sheung Chi Mak
 */
public class dbManager{

    public dbManager()
    {
    }
    
    public void addShapesRoadName(Vector polys){
    	try{
    		if(!arpSQLConn.getInstance().isConnected()){
    	    arpSQLConn.getInstance().connect();
        }
        //Vector newData = new Vector();
        PolyLine record;
        int id, level;
        String road_name, suffix, road_type;
        ResultSet rs = arpSQLConn.getInstance().executeQuery("select id,road_name, road_type, suffix, level from roads_shape");
        while(rs.next()){
        	id = rs.getInt("id");
        	level = rs.getInt("level");
        	road_name = rs.getString("road_name");
        	suffix = rs.getString("suffix");
        	road_type = rs.getString("road_type");
        	record = (PolyLine)polys.elementAt(id);
        	//if(!suffix.equals("")){
        	   road_name = road_name + " "+road_type;
        	//}
        	if(!suffix.equals("")){
        	   road_name = road_name + " "+suffix;
        	}
        	record.setName(road_name);
        	record.setLevel(level);
        }	
        //return null;	
    	}
    	catch(Exception e){
    		System.out.println(e);
            //return polys;
    	}
    }
  public static void main(String[] argv){
      try{
/*
	// connect to database
	//arpSQLConn db = new arpSQLConn();
	    if(!arpSQLConn.getInstance().isConnected()){
    	  arpSQLConn.getInstance().connect();
      }
      //setDefaultSoundex();
      
      int count = 6504;
      ResultSet rs;
      String name="";
      //for (int i=5001; i<31683;i++){
        //int i=15;
        String newName ="";
        String road_name, road_type;
        rs = arpSQLConn.getInstance().executeQuery("select road_name, road_type from segment group by road_name, road_type");
        //if(rs.next()){
        while(rs.next()){
        	name=rs.getString("road_name");
            road_type=rs.getString("road_type");
        	int pos=0;
        	//name = rs.getString(1);
        	if((pos=name.indexOf('\''))!=-1){
        	   name=name.substring(0,pos)+"\\"+name.substring(pos);
        	   //newName=name.charAt(0)+"\\'"+name.substring(2,3).toUpperCase()+name.substring(3).toLowerCase();
        	}
        	//newName = name;
        	//newName=name.charAt(0)+(name.substring(1)).toLowerCase();
        	//if((pos=name.indexOf(' '))!=-1){
        		//newName=newName.substring(0,pos)+(" "+newName.charAt(pos+1)).toUpperCase()+newName.substring(pos+2);
        	//}
        	//System.out.println(name);
        	//arpSQLConn.getInstance().execute("update segment set road_name='"+newName+"' where road_name='"+name+"'");  
            
            
            try{
            arpSQLConn.getInstance().execute("update segment set shape_id="+count+" where road_name='"+name+"' and road_type='"+road_type+"'");
            arpSQLConn.getInstance().execute("update roads_shape set shape_id="+count+" where road_name='"+name+"' and road_type='"+road_type+"'");
            }catch(Exception e1){ System.out.println(e1+" "+name+" "+road_type+" "+count);}
            count++;
        }
        
      //}
      */
      //serializeRoadSoundex2();
      }catch(Exception e){ System.out.println(e);}

    }
    
	public ResultSet getResultSet(arpSQLConn db, String sqlStr) throws Exception{
	  return db.executeQuery(sqlStr);
	}
	
}//end of class dbManager