svn-gvsig-desktop / trunk / libraries / libGDBMS / src / com / hardcode / gdbms / engine / FirstStrategy.java @ 466
History | View | Annotate | Download (2.49 KB)
1 |
package com.hardcode.gdbms.engine; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import com.hardcode.gdbms.engine.data.DataSource; |
6 |
import com.hardcode.gdbms.engine.data.DriverException; |
7 |
import com.hardcode.gdbms.engine.instruction.Expression; |
8 |
import com.hardcode.gdbms.engine.instruction.SelectAdapter; |
9 |
import com.hardcode.gdbms.engine.instruction.SemanticException; |
10 |
import com.hardcode.gdbms.engine.instruction.UnionAdapter; |
11 |
import com.hardcode.gdbms.engine.instruction.Utilities; |
12 |
|
13 |
|
14 |
/**
|
15 |
* Strategy de pruebas, en la que los metodos tienen la caracter?stica de que
|
16 |
* son los m?s f?ciles de implementar en el momento en que fueron necesarios
|
17 |
*
|
18 |
* @author Fernando Gonz?lez Cort?s
|
19 |
*/
|
20 |
public class FirstStrategy implements Strategy { |
21 |
|
22 |
/**
|
23 |
* @see com.hardcode.gdbms.engine.Strategy#select(com.hardcode.gdbms.parser.ASTSQLSelectCols,
|
24 |
* com.hardcode.gdbms.parser.ASTSQLTableList,
|
25 |
* com.hardcode.gdbms.parser.ASTSQLWhere)
|
26 |
*/
|
27 |
public DataSource select(SelectAdapter instr) |
28 |
throws DriverException, SemanticException, IOException { |
29 |
DataSource ret = null; |
30 |
|
31 |
DataSource[] fromTables = instr.getTables(); |
32 |
DataSource prod = new PDataSource(fromTables); |
33 |
|
34 |
ret = prod; |
35 |
|
36 |
/*
|
37 |
* Se establece como origen de datos el DataSource producto de las tablas
|
38 |
* de la cl?usula from para que el acceso desde el objeto field a los
|
39 |
* valores del dataSource sea correcto
|
40 |
*/
|
41 |
Utilities.setTablesAndSource((SelectAdapter) instr, fromTables, prod);
|
42 |
|
43 |
Expression[] fields = instr.getFieldsExpression(); |
44 |
|
45 |
if (fields != null) { |
46 |
ret.start(); |
47 |
|
48 |
DataSource res = new ProjectionDataSource(prod, fields, |
49 |
instr.getFieldsAlias()); |
50 |
ret.stop(); |
51 |
|
52 |
ret = res; |
53 |
} else {
|
54 |
ret = prod; |
55 |
} |
56 |
|
57 |
Expression whereExpression = instr.getWhereExpression();
|
58 |
|
59 |
if (whereExpression != null) { |
60 |
ret.start(); |
61 |
|
62 |
FilteredDataSource dataSource = new FilteredDataSource(ret,
|
63 |
whereExpression); |
64 |
dataSource.filtrar(); |
65 |
ret.stop(); |
66 |
|
67 |
ret = dataSource; |
68 |
} |
69 |
|
70 |
return ret;
|
71 |
} |
72 |
|
73 |
/**
|
74 |
* @see com.hardcode.gdbms.engine.Strategy#union(com.hardcode.gdbms.engine.instruction.UnionInstruction)
|
75 |
*/
|
76 |
public DataSource union(UnionAdapter instr) |
77 |
throws DriverException, IOException, SemanticException { |
78 |
return new UnionDataSource(instr.getFirstTable(), instr.getSecondTable()); |
79 |
} |
80 |
} |