Revision 46047
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/symboltable/SQLSymbolTable.java | ||
---|---|---|
78 | 78 |
import org.gvsig.expressionevaluator.impl.function.string.LowerFunction; |
79 | 79 |
import org.gvsig.expressionevaluator.impl.function.string.LpadFunction; |
80 | 80 |
import org.gvsig.expressionevaluator.impl.function.string.MidFunction; |
81 |
import org.gvsig.expressionevaluator.impl.function.string.PositionFunction; |
|
82 | 81 |
import org.gvsig.expressionevaluator.impl.function.string.RTrimFunction; |
83 | 82 |
import org.gvsig.expressionevaluator.impl.function.string.RepeatFunction; |
84 | 83 |
import org.gvsig.expressionevaluator.impl.function.string.ReplaceFunction; |
84 |
import org.gvsig.expressionevaluator.impl.function.string.ReverseFunction; |
|
85 |
import org.gvsig.expressionevaluator.impl.function.string.ReverseInStrFunction; |
|
85 | 86 |
import org.gvsig.expressionevaluator.impl.function.string.RightFunction; |
86 | 87 |
import org.gvsig.expressionevaluator.impl.function.string.RpadFunction; |
87 | 88 |
import org.gvsig.expressionevaluator.impl.function.string.SpaceFunction; |
... | ... | |
172 | 173 |
this.addFunction(new LocateFunction()); |
173 | 174 |
this.addFunction(new LowerFunction()); |
174 | 175 |
this.addFunction(new LpadFunction()); |
175 |
this.addFunction(new PositionFunction()); |
|
176 | 176 |
this.addFunction(new RTrimFunction()); |
177 | 177 |
this.addFunction(new RepeatFunction()); |
178 | 178 |
this.addFunction(new ReplaceFunction()); |
... | ... | |
183 | 183 |
this.addFunction(new TrimFunction()); |
184 | 184 |
this.addFunction(new UpperFunction()); |
185 | 185 |
this.addFunction(new MidFunction()); |
186 |
this.addFunction(new ReverseInStrFunction()); |
|
187 |
this.addFunction(new ReverseFunction()); |
|
186 | 188 |
|
187 | 189 |
this.addFunction(new CurrentTimestampFunction()); |
188 | 190 |
this.addFunction(new CurrentTimeFunction()); |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/string/PositionFunction.java | ||
---|---|---|
1 |
package org.gvsig.expressionevaluator.impl.function.string; |
|
2 |
|
|
3 |
import org.apache.commons.lang3.Range; |
|
4 |
import org.apache.commons.lang3.StringUtils; |
|
5 |
import org.gvsig.expressionevaluator.Interpreter; |
|
6 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
|
7 |
|
|
8 |
public class PositionFunction extends AbstractFunction { |
|
9 |
|
|
10 |
public PositionFunction() { |
|
11 |
super("String", "POSITION", Range.is(2)); |
|
12 |
} |
|
13 |
|
|
14 |
@Override |
|
15 |
public boolean allowConstantFolding() { |
|
16 |
return true; |
|
17 |
} |
|
18 |
|
|
19 |
@Override |
|
20 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
21 |
String search = getStr(args,0); |
|
22 |
String str = getStr(args,1); |
|
23 |
int r = StringUtils.indexOf(str, search); |
|
24 |
return r; |
|
25 |
} |
|
26 |
|
|
27 |
|
|
28 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/string/ReverseFunction.java | ||
---|---|---|
1 |
package org.gvsig.expressionevaluator.impl.function.string; |
|
2 |
|
|
3 |
import org.apache.commons.lang3.Range; |
|
4 |
import org.apache.commons.lang3.StringUtils; |
|
5 |
import org.gvsig.expressionevaluator.Interpreter; |
|
6 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
|
7 |
|
|
8 |
public class ReverseFunction extends AbstractFunction { |
|
9 |
|
|
10 |
public ReverseFunction() { |
|
11 |
super( |
|
12 |
"String", "REVERSE", Range.is(1), |
|
13 |
"reverses a string and returns the result.", |
|
14 |
"REVERSE"+"({{string}})", |
|
15 |
new String[]{ |
|
16 |
"string - String to reverse." |
|
17 |
}, |
|
18 |
"String", |
|
19 |
true |
|
20 |
); |
|
21 |
// Nota: |
|
22 |
// Parece ser que no habria falta poner un formatter, H2 es la unica que no |
|
23 |
// tiene esta funcion y sl proveedor de gvSIG para h2 se la a?ade. |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
public boolean allowConstantFolding() { |
|
28 |
return true; |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
33 |
String string = getStr(args, 0); |
|
34 |
return StringUtils.reverse(string); |
|
35 |
} |
|
36 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/string/ReverseInStrFunction.java | ||
---|---|---|
1 |
package org.gvsig.expressionevaluator.impl.function.string; |
|
2 |
|
|
3 |
import org.apache.commons.lang3.Range; |
|
4 |
import org.gvsig.expressionevaluator.Interpreter; |
|
5 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
|
6 |
|
|
7 |
public class ReverseInStrFunction extends AbstractFunction { |
|
8 |
|
|
9 |
public ReverseInStrFunction() { |
|
10 |
super( |
|
11 |
"String", "REVERSEINSTR", Range.is(2), |
|
12 |
"Returns the index (position) of the last occurrence of a specified substring in a string.", |
|
13 |
"REVERSEINSTR"+"({{string}}, substring)", |
|
14 |
new String[]{ |
|
15 |
"string - String in which to perform the search. ", |
|
16 |
"substring - String to search" |
|
17 |
}, |
|
18 |
"Integer", |
|
19 |
true |
|
20 |
); |
|
21 |
// Nota: |
|
22 |
// Habria que poner un formatter. Para REVERSEINSTR(string, substring): |
|
23 |
// En H2: INSTR(string,substring, -1) |
|
24 |
// En PostgreSQL: LENGTH(string)-STRPOS(REVERSE(string), substring) |
|
25 |
// En Oracle: LEN(string)-INSTR(REVERSE(string), substring) |
|
26 |
// En SQL Server: LEN(string)-CHARINDEX(substring, REVERSE(string)) |
|
27 |
} |
|
28 |
|
|
29 |
@Override |
|
30 |
public boolean allowConstantFolding() { |
|
31 |
return true; |
|
32 |
} |
|
33 |
|
|
34 |
@Override |
|
35 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
36 |
String string = getStr(args, 0); |
|
37 |
String substring = getStr(args, 1); |
|
38 |
if( string == null || substring == null ) { |
|
39 |
return null; |
|
40 |
} |
|
41 |
int n = string.lastIndexOf(substring); |
|
42 |
if( n<0 ) { |
|
43 |
return 0; |
|
44 |
} |
|
45 |
return n+1; |
|
46 |
} |
|
47 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/string/InstrFunction.java | ||
---|---|---|
7 | 7 |
public class InstrFunction extends AbstractFunction { |
8 | 8 |
|
9 | 9 |
public InstrFunction() { |
10 |
super("String", "INSTR", Range.between(2, 3)); |
|
10 |
super( |
|
11 |
"String", "INSTR", Range.is(2), |
|
12 |
"The functions search string for substring. The function returns " |
|
13 |
+ "an integer indicating the position of the character " |
|
14 |
+ "in string that is the first character of this occurrence.\n" |
|
15 |
+ "The function returns a numeric value. The first position " |
|
16 |
+ "in the string is 1. If substring is not found in string, " |
|
17 |
+ "then the function will return 0", |
|
18 |
"INSTR"+"({{string}}, substring)", |
|
19 |
new String[]{ |
|
20 |
"string - String in which to perform the search. ", |
|
21 |
"substring - String to search" |
|
22 |
}, |
|
23 |
"Integer", |
|
24 |
true |
|
25 |
); |
|
26 |
// Nota: |
|
27 |
// En SQL Server: CHARINDEX(substring, string) |
|
28 |
// En PostgreSQL: STRPOS(string,substring) o POSITION(substring in string) |
|
29 |
// En Oracle: INSTR(string,substring) |
|
30 |
// En H2: INSTR(string,substring) |
|
11 | 31 |
} |
12 |
|
|
32 |
|
|
13 | 33 |
@Override |
14 | 34 |
public boolean allowConstantFolding() { |
15 | 35 |
return true; |
... | ... | |
19 | 39 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
20 | 40 |
String str = getStr(args, 0); |
21 | 41 |
String search = getStr(args, 1); |
22 |
int start = 0; |
|
23 |
if( args.length == 3 ) { |
|
24 |
start = getInt(args, 2); |
|
42 |
if( str==null || search==null ) { |
|
43 |
return null; |
|
25 | 44 |
} |
26 |
return str.indexOf(search, start); |
|
45 |
int n = str.indexOf(search); |
|
46 |
if( n<0 ) { |
|
47 |
return 0; |
|
48 |
} |
|
49 |
return n+1; |
|
27 | 50 |
} |
28 | 51 |
|
29 | 52 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialHelper.java | ||
---|---|---|
38 | 38 |
import org.gvsig.fmap.dal.resource.exception.AccessResourceException; |
39 | 39 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
40 | 40 |
import static org.gvsig.fmap.dal.store.h2.H2SpatialHelper.LOGGER; |
41 |
import org.gvsig.fmap.dal.store.h2.functions.Json_value; |
|
42 |
import org.gvsig.fmap.dal.store.h2.functions.Reverse; |
|
43 |
import org.gvsig.fmap.dal.store.h2.functions.Reverseinstr; |
|
41 | 44 |
import org.gvsig.fmap.dal.store.h2.operations.H2SpatialOperationsFactory; |
42 | 45 |
import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters; |
43 | 46 |
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters; |
... | ... | |
162 | 165 |
} catch(SQLException ex) { |
163 | 166 |
H2GISFunctions.load(conn); |
164 | 167 |
} |
165 |
try { |
|
166 |
conn.createStatement().execute("CREATE SCHEMA IF NOT EXISTS PUBLIC;SET SCHEMA PUBLIC"); |
|
167 |
} catch(SQLException ex) { |
|
168 |
LOGGER.trace("Can't create schema public.",ex); |
|
169 |
// Ignore this error. |
|
168 |
|
|
169 |
String[] sqls = new String[] { |
|
170 |
"CREATE SCHEMA IF NOT EXISTS PUBLIC;SET SCHEMA PUBLIC", |
|
171 |
Json_value.getSQL(), |
|
172 |
Reverse.getSQL(), |
|
173 |
Reverseinstr.getSQL() |
|
174 |
}; |
|
175 |
for (String sql : sqls) { |
|
176 |
try { |
|
177 |
conn.createStatement().execute(sql); |
|
178 |
} catch(SQLException ex) { |
|
179 |
LOGGER.debug("Can't configure gvsig tables.",ex); |
|
180 |
LOGGER.warn("Can't configure gvsig tables. "+sql); |
|
181 |
// Ignore this error. |
|
182 |
} |
|
170 | 183 |
} |
171 | 184 |
|
172 | 185 |
if( newdb ) { |
173 |
String[] sqls = new String[] { |
|
186 |
String[] sqls2 = new String[] {
|
|
174 | 187 |
"CREATE CACHED TABLE PUBLIC.\""+TABLE_RESOURCES_NAME+"\"(\""+FIELD_RESOURCES_NAME+"\" VARCHAR(150) NOT NULL, \""+FIELD_RESOURCES_RESOURCE+"\" BLOB DEFAULT NULL)", |
175 | 188 |
"ALTER TABLE PUBLIC.\""+TABLE_RESOURCES_NAME+"\" ADD CONSTRAINT PUBLIC.CONSTRAINT_E PRIMARY KEY(\""+FIELD_RESOURCES_NAME+"\")", |
176 | 189 |
"CREATE CACHED TABLE PUBLIC.\""+TABLE_CONFIGURATION_NAME+"\"(\""+FIELD_CONFIGURATION_NAME+"\" VARCHAR(200) NOT NULL, \""+FIELD_CONFIGURATION_VALUE+"\" CLOB DEFAULT NULL)", |
177 |
"ALTER TABLE PUBLIC.\""+TABLE_CONFIGURATION_NAME+"\" ADD CONSTRAINT PUBLIC.CONSTRAINT_2 PRIMARY KEY(\""+FIELD_CONFIGURATION_NAME+"\")" |
|
190 |
"ALTER TABLE PUBLIC.\""+TABLE_CONFIGURATION_NAME+"\" ADD CONSTRAINT PUBLIC.CONSTRAINT_2 PRIMARY KEY(\""+FIELD_CONFIGURATION_NAME+"\")",
|
|
178 | 191 |
}; |
179 |
for (String sql : sqls) { |
|
192 |
for (String sql : sqls2) {
|
|
180 | 193 |
try { |
181 | 194 |
conn.createStatement().execute(sql); |
182 | 195 |
} catch(SQLException ex) { |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/main/java/org/gvsig/fmap/dal/store/h2/functions/Reverse.java | ||
---|---|---|
1 |
/* |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2020 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, see <https://www.gnu.org/licenses/>. |
|
18 |
* |
|
19 |
* For any additional information, do not hesitate to contact us |
|
20 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
21 |
*/ |
|
22 |
|
|
23 |
package org.gvsig.fmap.dal.store.h2.functions; |
|
24 |
|
|
25 |
import org.apache.commons.lang3.StringUtils; |
|
26 |
|
|
27 |
/** |
|
28 |
* |
|
29 |
* @author gvSIG Team |
|
30 |
*/ |
|
31 |
public class Reverse { |
|
32 |
|
|
33 |
public static String getSQL() { |
|
34 |
return "CREATE ALIAS REVERSE FOR \"org.gvsig.fmap.dal.store.h2.functions.Reverse.reverse\""; |
|
35 |
} |
|
36 |
|
|
37 |
public static Object reverse(String s) { |
|
38 |
return StringUtils.reverse(s); |
|
39 |
} |
|
40 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/main/java/org/gvsig/fmap/dal/store/h2/functions/Reverseinstr.java | ||
---|---|---|
1 |
/* |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2020 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, see <https://www.gnu.org/licenses/>. |
|
18 |
* |
|
19 |
* For any additional information, do not hesitate to contact us |
|
20 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
21 |
*/ |
|
22 |
|
|
23 |
package org.gvsig.fmap.dal.store.h2.functions; |
|
24 |
|
|
25 |
import org.apache.commons.lang3.StringUtils; |
|
26 |
|
|
27 |
/** |
|
28 |
* |
|
29 |
* @author gvSIG Team |
|
30 |
*/ |
|
31 |
public class Reverseinstr { |
|
32 |
|
|
33 |
public static String getSQL() { |
|
34 |
return "CREATE ALIAS REVERSE FOR \"org.gvsig.fmap.dal.store.h2.functions.Reverseinstr.reverseinstr\""; |
|
35 |
} |
|
36 |
|
|
37 |
public static Object reverseinstr(String string, String substring) { |
|
38 |
if( string == null || substring == null ) { |
|
39 |
return null; |
|
40 |
} |
|
41 |
int n = string.lastIndexOf(substring); |
|
42 |
if( n<0 ) { |
|
43 |
return 0; |
|
44 |
} |
|
45 |
return n+1; |
|
46 |
} |
|
47 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/main/java/org/gvsig/fmap/dal/store/h2/functions/Json_value.java | ||
---|---|---|
32 | 32 |
public class Json_value { |
33 | 33 |
|
34 | 34 |
public static String getSQL() { |
35 |
return "CREATE ALIAS JSON_VALUE FOR \"org.gvsig.fmap.dal.store.h2.functions.Json_value\""; |
|
35 |
return "CREATE ALIAS JSON_VALUE FOR \"org.gvsig.fmap.dal.store.h2.functions.Json_value.json_value\"";
|
|
36 | 36 |
} |
37 | 37 |
|
38 | 38 |
public static Object json_value(String json, String path) { |
Also available in: Unified diff