svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / test / java / org / gvsig / app / gui / filter / TestFilterExpressionFromWhereIsEmpty_Method.java @ 40596
History | View | Annotate | Download (2.93 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.gui.filter; |
25 |
|
26 |
import junit.framework.TestCase; |
27 |
|
28 |
|
29 |
/**
|
30 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
|
31 |
*/
|
32 |
public class TestFilterExpressionFromWhereIsEmpty_Method extends TestCase { |
33 |
/*
|
34 |
* (non-Javadoc)
|
35 |
* @see junit.framework.TestCase#setUp()
|
36 |
*/
|
37 |
protected void setUp() throws Exception { |
38 |
super.setUp();
|
39 |
} |
40 |
|
41 |
/*
|
42 |
* (non-Javadoc)
|
43 |
* @see junit.framework.TestCase#tearDown()
|
44 |
*/
|
45 |
protected void tearDown() throws Exception { |
46 |
super.tearDown();
|
47 |
} |
48 |
|
49 |
/**
|
50 |
* Test 1 (valid)
|
51 |
*/
|
52 |
public void test1() { |
53 |
String expression = new String("select * from 'gdbms144426c_10fc90fa1aa__7c18' where ;"); |
54 |
|
55 |
System.out.println("? Es vac?o el filtro en: " + expression + " ? "); |
56 |
|
57 |
if (this.filterExpressionFromWhereIsEmpty(expression)) |
58 |
System.out.println("Si."); |
59 |
else
|
60 |
System.out.println("No."); |
61 |
} |
62 |
|
63 |
/**
|
64 |
* Test 2 (invalid)
|
65 |
*/
|
66 |
public void test2() { |
67 |
String expression = new String("select * from 'gdbms158fd70_10fc92ee61e__7c18' where layer < '61';"); |
68 |
|
69 |
System.out.println("? Es vac?o el filtro en: " + expression + " ? "); |
70 |
|
71 |
if (this.filterExpressionFromWhereIsEmpty(expression)) |
72 |
System.out.println("Si."); |
73 |
else
|
74 |
System.out.println("No."); |
75 |
} |
76 |
|
77 |
/**
|
78 |
* Returns true if the WHERE subconsultation of the filterExpression is empty ("")
|
79 |
*
|
80 |
* @param expression An string
|
81 |
* @return A boolean value
|
82 |
*/
|
83 |
private boolean filterExpressionFromWhereIsEmpty(String expression) { |
84 |
String subExpression = expression.trim();
|
85 |
int pos;
|
86 |
|
87 |
// Remove last ';' if exists
|
88 |
if (subExpression.charAt(subExpression.length() -1) == ';') |
89 |
subExpression = subExpression.substring(0, subExpression.length() -1).trim(); |
90 |
|
91 |
// If there is no 'where' clause
|
92 |
if ((pos = subExpression.indexOf("where")) == -1) |
93 |
return false; |
94 |
|
95 |
// If there is no subexpression in the WHERE clause -> true
|
96 |
subExpression = subExpression.substring(pos + 5, subExpression.length()).trim(); // + 5 is the length of 'where' |
97 |
if ( subExpression.length() == 0 ) |
98 |
return true; |
99 |
else
|
100 |
return false; |
101 |
} |
102 |
} |