Revision 9492
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/filter/TestFilterExpressionFromWhereIsEmpty_Method.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.gui.filter; |
|
2 |
|
|
3 |
import junit.framework.TestCase; |
|
4 |
|
|
5 |
|
|
6 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
7 |
* |
|
8 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
9 |
* |
|
10 |
* This program is free software; you can redistribute it and/or |
|
11 |
* modify it under the terms of the GNU General Public License |
|
12 |
* as published by the Free Software Foundation; either version 2 |
|
13 |
* of the License, or (at your option) any later version. |
|
14 |
* |
|
15 |
* This program is distributed in the hope that it will be useful, |
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
* GNU General Public License for more details. |
|
19 |
* |
|
20 |
* You should have received a copy of the GNU General Public License |
|
21 |
* along with this program; if not, write to the Free Software |
|
22 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
23 |
* |
|
24 |
* For more information, contact: |
|
25 |
* |
|
26 |
* Generalitat Valenciana |
|
27 |
* Conselleria d'Infraestructures i Transport |
|
28 |
* Av. Blasco Ib??ez, 50 |
|
29 |
* 46010 VALENCIA |
|
30 |
* SPAIN |
|
31 |
* |
|
32 |
* +34 963862235 |
|
33 |
* gvsig@gva.es |
|
34 |
* www.gvsig.gva.es |
|
35 |
* |
|
36 |
* or |
|
37 |
* |
|
38 |
* IVER T.I. S.A |
|
39 |
* Salamanca 50 |
|
40 |
* 46005 Valencia |
|
41 |
* Spain |
|
42 |
* |
|
43 |
* +34 963163400 |
|
44 |
* dac@iver.es |
|
45 |
*/ |
|
46 |
|
|
47 |
/** |
|
48 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com) |
|
49 |
*/ |
|
50 |
public class TestFilterExpressionFromWhereIsEmpty_Method extends TestCase { |
|
51 |
/* |
|
52 |
* (non-Javadoc) |
|
53 |
* @see junit.framework.TestCase#setUp() |
|
54 |
*/ |
|
55 |
protected void setUp() throws Exception { |
|
56 |
super.setUp(); |
|
57 |
} |
|
58 |
|
|
59 |
/* |
|
60 |
* (non-Javadoc) |
|
61 |
* @see junit.framework.TestCase#tearDown() |
|
62 |
*/ |
|
63 |
protected void tearDown() throws Exception { |
|
64 |
super.tearDown(); |
|
65 |
} |
|
66 |
|
|
67 |
/** |
|
68 |
* Test 1 (valid) |
|
69 |
*/ |
|
70 |
public void test1() { |
|
71 |
String expression = new String("select * from 'gdbms144426c_10fc90fa1aa__7c18' where ;"); |
|
72 |
|
|
73 |
System.out.println("? Es vac?o el filtro en: " + expression + " ? "); |
|
74 |
|
|
75 |
if (this.filterExpressionFromWhereIsEmpty(expression)) |
|
76 |
System.out.println("Si."); |
|
77 |
else |
|
78 |
System.out.println("No."); |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Test 2 (invalid) |
|
83 |
*/ |
|
84 |
public void test2() { |
|
85 |
String expression = new String("select * from 'gdbms158fd70_10fc92ee61e__7c18' where layer < '61';"); |
|
86 |
|
|
87 |
System.out.println("? Es vac?o el filtro en: " + expression + " ? "); |
|
88 |
|
|
89 |
if (this.filterExpressionFromWhereIsEmpty(expression)) |
|
90 |
System.out.println("Si."); |
|
91 |
else |
|
92 |
System.out.println("No."); |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* Returns true if the WHERE subconsultation of the filterExpression is empty ("") |
|
97 |
* |
|
98 |
* @param expression An string |
|
99 |
* @return A boolean value |
|
100 |
*/ |
|
101 |
private boolean filterExpressionFromWhereIsEmpty(String expression) { |
|
102 |
String subExpression = expression.trim(); |
|
103 |
int pos; |
|
104 |
|
|
105 |
// Remove last ';' if exists |
|
106 |
if (subExpression.charAt(subExpression.length() -1) == ';') |
|
107 |
subExpression = subExpression.substring(0, subExpression.length() -1).trim(); |
|
108 |
|
|
109 |
// If there is no 'where' clause |
|
110 |
if ((pos = subExpression.indexOf("where")) == -1) |
|
111 |
return false; |
|
112 |
|
|
113 |
// If there is no subexpression in the WHERE clause -> true |
|
114 |
subExpression = subExpression.substring(pos + 5, subExpression.length()).trim(); // + 5 is the length of 'where' |
|
115 |
if ( subExpression.length() == 0 ) |
|
116 |
return true; |
|
117 |
else |
|
118 |
return false; |
|
119 |
} |
|
120 |
} |
|
0 | 121 |
Also available in: Unified diff