View Javadoc

1   package uba.db.client.structure;
2   
3   import uba.db.client.model.ResultSet;
4   
5   /***
6    * Utility methods para ser usados por el server.
7    * 
8    * @version $Revision 1.0$
9    */
10  
11  public class ClientDataConverter {
12  	/***
13  	 * Convierte los resultados del socket en una tabla para mostrar.
14  	 * 
15  	 * @param s
16  	 *            El string que llega por el socket.
17  	 * @return Una tabla de resultados que tiene que mostrar la ventana cliente.
18  	 */
19  	public ResultSet convertToResultSet(String s) {
20  		if (s.length() == 0)
21  			return new ResultSet("", "");
22  
23  		int position = 0;
24  		int nextStop;
25  		int cantFilas;
26  		int cantColumnas;
27  		String tuples = "";
28  		nextStop = s.indexOf("\t", position);
29  		cantFilas = new Integer(s.substring(position, nextStop)).intValue();
30  		position = nextStop + 1;
31  		for (int j = 0; j < cantFilas + 1; j++) {
32  			if (j != 0)
33  				tuples += "\n";
34  			nextStop = s.indexOf("\t", position);
35  			cantColumnas = new Integer(s.substring(position, nextStop))
36  					.intValue();
37  			position = nextStop + 1;
38  			for (int i = 0; i < cantColumnas; i++) {
39  				if (i != cantColumnas && i != 0)
40  					tuples += "\t";
41  				nextStop = s.indexOf("\t", position);
42  				tuples += s.substring(position, nextStop);
43  				position = nextStop + 1;
44  			}
45  		}
46  
47  		String queryPlan = "";
48  		while (position != s.length()) {
49  			nextStop = s.indexOf("\t", position);
50  			queryPlan += s.substring(position, nextStop) + "\n";
51  			position = nextStop + 1;
52  		}
53  		return new ResultSet(tuples, queryPlan);
54  	}
55  }