src/com/wherehoo/WHInsertOperation.java
/**
     * Inserts an entry into the database, and sends an uid to the client as a confirmation
     * @param client_socket a socket of the connecting client.  After executing an insert operation, this method sends
     * uid to the client via client_socket.
     */
Inserts an entry into the database, and sends an uid to the client as a confirmation
@param client_socket a socket of the connecting client.  After executing an insert operation, this method sends
uid to the client via client_socket.
Inserts an entry into the database and sends an uid to the client as a confirmation @param client_socket a socket of the connecting client . After executing an insert operation this method sends uid to the client via client_socket .
public synchronized void executeAndOutputToClient(Socket client_socket) throws IOException{
	String queryString;
	Connection C;
	PreparedStatement pps;
	String client_address = client_socket.getInetAddress().getHostAddress();
	int st;
	PrintWriter out;
	if (this.getVeryVerbose()) System.out.println("Opening PrintWriter");
	out = new PrintWriter(client_socket.getOutputStream(),true);
	try {
	    uniqueidSHA=getUniqueID(client_address);
	    if (this.getVeryVerbose()) System.out.println("Calculated uniqueID :"+uniqueidSHA);
	    C = DriverManager.getConnection("jdbc:"+WHServer.DB,"postgres","");
	    if (this.getVeryVerbose()) System.out.println("Connected to database");
	    C.setAutoCommit(false);
	    if ( ! poly.zeroCrossing()){	
		if (this.getVeryVerbose()) System.out.println("No zero crossing");
		queryString=this.getQueryString(0);
		pps = C.prepareStatement(queryString);
		if (this.getVeryVerbose()) System.out.println("Prepared statement");
		pps.setTimestamp(1,time.getBegin());
		pps.setTimestamp(2,time.getEnd());
		if (this.getVeryVerbose()) System.out.println("Set the timestamps in SQL query string");
		pps.setBytes(3, data);
		if (this.getVeryVerbose()) System.out.println("Set data bytes in SQL query string");
		if (meta_is_set){
		    pps.setString(4,meta);
		    if (this.getVeryVerbose()) System.out.println("Set meta in SQL query string");
		}
		st = pps.executeUpdate();
		if (this.getVeryVerbose()) System.out.println("Executed query, result : "+st);
		C.commit();
		if (this.getVeryVerbose()) System.out.println("Commited changes");
		if (st == 1){
		    out.println(uniqueidSHA);
		    if (this.getVeryVerbose())System.out.println("Sent UID to client");
		}
	    } else {
		if (this.getVeryVerbose()) System.out.println("Zero crossing");
		queryString=this.getQueryString(-1);
		if (this.getVeryVerbose()) System.out.println("Prepared statement centered around zero meridian");
		pps = C.prepareStatement(queryString);
		pps.setTimestamp(1,time.getBegin());
		pps.setTimestamp(2,time.getEnd());
		pps.setBytes(3, data);
		if (meta_is_set)
		    pps.setString(4,meta);
		st = pps.executeUpdate();
		if (this.getVeryVerbose()) System.out.println("Executed statement");
		queryString=this.getQueryString(1);
		pps = C.prepareStatement(queryString);
		if (this.getVeryVerbose()) System.out.println("Prepared statement centered around 360 meridian");
		pps.setTimestamp(1,time.getBegin());
		pps.setTimestamp(2,time.getEnd());
		pps.setBytes(3, data);
		if (meta_is_set)
		    pps.setString(4,meta);
		st = st + pps.executeUpdate();
		if (this.getVeryVerbose()) System.out.println("Executed statement");
		C.commit();
		if (st == 2)
		    out.println(uniqueidSHA);
		if (this.getVeryVerbose()) System.out.println("Insert fully sucessfull, sent uniqueidSHA to client");
	    }
	    C.close();
	}
	catch (SQLException sqle) {
	    System.out.println("SQLException: " + sqle.getMessage());
	    System.out.println("SQLState:     " + sqle.getSQLState());
	    System.out.println("VendorError:  " + sqle.getErrorCode());
	}
	catch (NoSuchAlgorithmException nsae){
	    System.out.println("NoSuchAlgorithmException: "+nsae.getMessage());
	}
	catch (UnknownHostException uhe){
	    System.out.println("UnknownHostException: "+uhe.getMessage());
	}
    }
public synchronized void executeAndOutputToClient ( Socket client_socket ) throws IOException { String queryString ; Connection C ; PreparedStatement pps ; String client_address = client_socket . getInetAddress ( ) . getHostAddress ( ) ; int st ; PrintWriter out ; if ( this . getVeryVerbose ( ) ) System . out . println ( "Opening PrintWriter" ) ; out = new PrintWriter ( client_socket . getOutputStream ( ) , true ) ; try { uniqueidSHA = getUniqueID ( client_address ) ; if ( this . getVeryVerbose ( ) ) System . out . println ( "Calculated uniqueID :" + uniqueidSHA ) ; C = DriverManager . getConnection ( "jdbc:" + WHServer . DB , "postgres" , "" ) ; if ( this . getVeryVerbose ( ) ) System . out . println ( "Connected to database" ) ; C . setAutoCommit ( false ) ; if ( ! poly . zeroCrossing ( ) ) { if ( this . getVeryVerbose ( ) ) System . out . println ( "No zero crossing" ) ; queryString = this . getQueryString ( 0 ) ; pps = C . prepareStatement ( queryString ) ; if ( this . getVeryVerbose ( ) ) System . out . println ( "Prepared statement" ) ; pps . setTimestamp ( 1 , time . getBegin ( ) ) ; pps . setTimestamp ( 2 , time . getEnd ( ) ) ; if ( this . getVeryVerbose ( ) ) System . out . println ( "Set the timestamps in SQL query string" ) ; pps . setBytes ( 3 , data ) ; if ( this . getVeryVerbose ( ) ) System . out . println ( "Set data bytes in SQL query string" ) ; if ( meta_is_set ) { pps . setString ( 4 , meta ) ; if ( this . getVeryVerbose ( ) ) System . out . println ( "Set meta in SQL query string" ) ; } st = pps . executeUpdate ( ) ; if ( this . getVeryVerbose ( ) ) System . out . println ( "Executed query, result : " + st ) ; C . commit ( ) ; if ( this . getVeryVerbose ( ) ) System . out . println ( "Commited changes" ) ; if ( st == 1 ) { out . println ( uniqueidSHA ) ; if ( this . getVeryVerbose ( ) ) System . out . println ( "Sent UID to client" ) ; } } else { if ( this . getVeryVerbose ( ) ) System . out . println ( "Zero crossing" ) ; queryString = this . getQueryString ( - 1 ) ; if ( this . getVeryVerbose ( ) ) System . out . println ( "Prepared statement centered around zero meridian" ) ; pps = C . prepareStatement ( queryString ) ; pps . setTimestamp ( 1 , time . getBegin ( ) ) ; pps . setTimestamp ( 2 , time . getEnd ( ) ) ; pps . setBytes ( 3 , data ) ; if ( meta_is_set ) pps . setString ( 4 , meta ) ; st = pps . executeUpdate ( ) ; if ( this . getVeryVerbose ( ) ) System . out . println ( "Executed statement" ) ; queryString = this . getQueryString ( 1 ) ; pps = C . prepareStatement ( queryString ) ; if ( this . getVeryVerbose ( ) ) System . out . println ( "Prepared statement centered around 360 meridian" ) ; pps . setTimestamp ( 1 , time . getBegin ( ) ) ; pps . setTimestamp ( 2 , time . getEnd ( ) ) ; pps . setBytes ( 3 , data ) ; if ( meta_is_set ) pps . setString ( 4 , meta ) ; st = st + pps . executeUpdate ( ) ; if ( this . getVeryVerbose ( ) ) System . out . println ( "Executed statement" ) ; C . commit ( ) ; if ( st == 2 ) out . println ( uniqueidSHA ) ; if ( this . getVeryVerbose ( ) ) System . out . println ( "Insert fully sucessfull, sent uniqueidSHA to client" ) ; } C . close ( ) ; } catch ( SQLException sqle ) { System . out . println ( "SQLException: " + sqle . getMessage ( ) ) ; System . out . println ( "SQLState:     " + sqle . getSQLState ( ) ) ; System . out . println ( "VendorError:  " + sqle . getErrorCode ( ) ) ; } catch ( NoSuchAlgorithmException nsae ) { System . out . println ( "NoSuchAlgorithmException: " + nsae . getMessage ( ) ) ; } catch ( UnknownHostException uhe ) { System . out . println ( "UnknownHostException: " + uhe . getMessage ( ) ) ; } }
Inserts an entry into the database, and sends an uid to the client as a confirmation
 @param client_socket a socket of the connecting client.
Inserts an entry into the database and sends an uid to the client as a confirmation @param client_socket a socket of the connecting client .
//insert two objects, each with different coordinates
 //object represented by polygon with 180<lon<540;
 //object represented by polygon with -180<lon<180
 //out.close();
