Revision 570
trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/PostgreSQLBuilderTest.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import junit.framework.TestCase; |
4 | 4 |
import org.apache.commons.lang3.ArrayUtils; |
5 |
import org.apache.commons.lang3.StringUtils; |
|
6 | 5 |
import org.cresques.cts.IProjection; |
7 | 6 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
7 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
|
8 | 8 |
import org.gvsig.fmap.crs.CRSFactory; |
9 | 9 |
import org.gvsig.fmap.dal.SQLBuilder; |
10 | 10 |
import org.gvsig.fmap.dal.SQLBuilder.Privilege; |
11 | 11 |
import org.gvsig.fmap.dal.feature.spi.SQLBuilderBase; |
12 | 12 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
13 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_TABLE; |
|
14 | 13 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.OperationsFactoryBase; |
15 | 14 |
import org.gvsig.fmap.geom.DataTypes; |
16 | 15 |
import org.gvsig.fmap.geom.Geometry; |
... | ... | |
46 | 45 |
String columnName = "the_geom"; |
47 | 46 |
|
48 | 47 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
49 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
48 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression();
|
|
50 | 49 |
|
51 | 50 |
sqlbuilder.select().column().value( |
52 | 51 |
expbuilder.as_geometry( |
... | ... | |
96 | 95 |
limit.addVertex(0, 0); |
97 | 96 |
|
98 | 97 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
99 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
98 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression();
|
|
100 | 99 |
|
101 | 100 |
sqlbuilder.select().column().value( |
102 | 101 |
expbuilder.as_geometry( |
... | ... | |
365 | 364 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
366 | 365 |
|
367 | 366 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
368 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
367 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression();
|
|
369 | 368 |
|
370 | 369 |
sqlbuilder.insert().table().database("master").schema("dbo").name("test1"); |
371 | 370 |
sqlbuilder.insert().column().name("id").with_value(expbuilder.parameter("id")); |
... | ... | |
394 | 393 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
395 | 394 |
|
396 | 395 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
397 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
396 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression();
|
|
398 | 397 |
|
399 | 398 |
sqlbuilder.insert().table().database("master").schema("dbo").name("test1"); |
400 | 399 |
sqlbuilder.insert().column().name("id").with_value(expbuilder.parameter("id")); |
... | ... | |
423 | 422 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
424 | 423 |
|
425 | 424 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
426 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
425 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression();
|
|
427 | 426 |
|
428 | 427 |
sqlbuilder.update().table().database("master").schema("dbo").name("test1"); |
429 | 428 |
sqlbuilder.update().where().and( |
... | ... | |
459 | 458 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
460 | 459 |
|
461 | 460 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
462 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
461 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression();
|
|
463 | 462 |
|
464 | 463 |
sqlbuilder.update().table().database("master").schema("dbo").name("test1"); |
465 | 464 |
sqlbuilder.update().where().and( |
trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLHelper.java | ||
---|---|---|
6 | 6 |
import org.apache.commons.dbcp.BasicDataSource; |
7 | 7 |
import org.apache.commons.lang3.BooleanUtils; |
8 | 8 |
import org.apache.commons.lang3.StringUtils; |
9 |
import org.gvsig.expressionevaluator.ExpressionBuilder.GeometrySupportType; |
|
10 |
import org.gvsig.fmap.dal.SQLBuilder; |
|
9 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometrySupportType; |
|
11 | 10 |
import org.gvsig.fmap.dal.resource.exception.AccessResourceException; |
12 | 11 |
import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters; |
13 | 12 |
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters; |
... | ... | |
24 | 23 |
|
25 | 24 |
public class PostgreSQLHelper extends JDBCHelperBase { |
26 | 25 |
|
27 |
static final Logger logger = LoggerFactory.getLogger(PostgreSQLHelper.class);
|
|
26 |
/* friend */ static final Logger LOGGER = LoggerFactory.getLogger(PostgreSQLHelper.class);
|
|
28 | 27 |
|
29 | 28 |
public static final String POSTGRESQL_JDBC_DRIVER = "org.postgresql.Driver"; |
30 | 29 |
|
... | ... | |
45 | 44 |
connectionURL = connectionURL + ":" + port; |
46 | 45 |
} |
47 | 46 |
connectionURL = connectionURL + "/" + db; |
48 |
logger.debug("connectionURL: {}", connectionURL);
|
|
47 |
LOGGER.debug("connectionURL: {}", connectionURL);
|
|
49 | 48 |
return connectionURL; |
50 | 49 |
} |
51 | 50 |
|
... | ... | |
65 | 64 |
if (this.dataSource == null) { |
66 | 65 |
this.dataSource = this.createDataSource(); |
67 | 66 |
} |
68 |
if( logger.isDebugEnabled() ) {
|
|
69 |
logger.debug("getConnection:\n" + getStatusInformation());
|
|
67 |
if( LOGGER.isDebugEnabled() ) {
|
|
68 |
LOGGER.debug("getConnection:\n" + getStatusInformation());
|
|
70 | 69 |
} |
71 | 70 |
Connection conn; |
72 | 71 |
try { |
73 | 72 |
conn = this.dataSource.getConnection(); |
74 | 73 |
} catch(Throwable ex) { |
75 |
logger.debug("Error getting connection from pool.",ex);
|
|
74 |
LOGGER.debug("Error getting connection from pool.",ex);
|
|
76 | 75 |
throw ex; |
77 | 76 |
} |
78 |
if( logger.isDebugEnabled() ) {
|
|
79 |
logger.debug("Created connection: {}\n NumActive: {}\n NumIdle: {}",
|
|
77 |
if( LOGGER.isDebugEnabled() ) {
|
|
78 |
LOGGER.debug("Created connection: {}\n NumActive: {}\n NumIdle: {}",
|
|
80 | 79 |
new Object[] { |
81 | 80 |
conn.hashCode(), |
82 | 81 |
this.dataSource.getNumActive(), |
... | ... | |
93 | 92 |
try { |
94 | 93 |
connection.close(); |
95 | 94 |
} catch(Throwable ex) { |
96 |
logger.warn("Can't close connection.", ex);
|
|
95 |
LOGGER.warn("Can't close connection.", ex);
|
|
97 | 96 |
} |
98 |
if( logger.isDebugEnabled() ) {
|
|
97 |
if( LOGGER.isDebugEnabled() ) {
|
|
99 | 98 |
Boolean isClosed; |
100 | 99 |
try { |
101 | 100 |
isClosed = connection.isClosed(); |
102 | 101 |
} catch(Throwable th) { |
103 | 102 |
isClosed = null; |
104 | 103 |
} |
105 |
logger.debug("Closed connection: {}\n isClosed: {}\n NumActive: {}\n NumIdle: {}",
|
|
104 |
LOGGER.debug("Closed connection: {}\n isClosed: {}\n NumActive: {}\n NumIdle: {}",
|
|
106 | 105 |
new Object[] { |
107 | 106 |
connectionId, |
108 | 107 |
isClosed, |
... | ... | |
111 | 110 |
} |
112 | 111 |
); |
113 | 112 |
} |
114 |
} else if( logger.isDebugEnabled() ) {
|
|
115 |
logger.debug("Close connection: null");
|
|
113 |
} else if( LOGGER.isDebugEnabled() ) {
|
|
114 |
LOGGER.debug("Close connection: null");
|
|
116 | 115 |
} |
117 | 116 |
} |
118 | 117 |
|
trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLLibrary.java | ||
---|---|---|
36 | 36 |
try { |
37 | 37 |
Class.forName(PostgreSQLHelper.POSTGRESQL_JDBC_DRIVER); |
38 | 38 |
} catch(Throwable th) { |
39 |
PostgreSQLHelper.logger.warn("Can't load PostgreSQL JDBC Driver.",th);
|
|
39 |
PostgreSQLHelper.LOGGER.warn("Can't load PostgreSQL JDBC Driver.",th);
|
|
40 | 40 |
} |
41 | 41 |
|
42 | 42 |
DBHelper.registerParametersDefinition( |
trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/ST_ExtentAggregate.java | ||
---|---|---|
4 | 4 |
import java.util.List; |
5 | 5 |
import org.apache.commons.lang3.StringUtils; |
6 | 6 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
7 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_ST_EXTENTAGGREGATE; |
|
7 |
import static org.gvsig.expressionevaluator.GeometryExpressionBuilder.FUNCTION_ST_EXTENTAGGREGATE;
|
|
8 | 8 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
9 | 9 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
10 | 10 |
import org.gvsig.expressionevaluator.Formatter; |
trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/ST_GeomFromWKB.java | ||
---|---|---|
7 | 7 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
8 | 8 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
9 | 9 |
import org.gvsig.expressionevaluator.Formatter; |
10 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
|
10 | 11 |
import org.gvsig.fmap.dal.SQLBuilder; |
11 | 12 |
import org.gvsig.fmap.dal.feature.FeatureType; |
12 | 13 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_FEATURE_TYPE; |
... | ... | |
27 | 28 |
@Override |
28 | 29 |
public boolean canApply(ExpressionBuilder.Value value) { |
29 | 30 |
if (value instanceof ExpressionBuilder.Function) { |
30 |
return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_GEOMFROMWKB, ((Function) value).name()); |
|
31 |
return StringUtils.equalsIgnoreCase(GeometryExpressionBuilder.FUNCTION_ST_GEOMFROMWKB, ((Function) value).name());
|
|
31 | 32 |
} |
32 | 33 |
return false; |
33 | 34 |
} |
trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/ST_GeomFromText.java | ||
---|---|---|
7 | 7 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
8 | 8 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
9 | 9 |
import org.gvsig.expressionevaluator.Formatter; |
10 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
|
10 | 11 |
import org.gvsig.fmap.dal.SQLBuilder; |
11 | 12 |
import org.gvsig.fmap.dal.feature.FeatureType; |
12 | 13 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_FEATURE_TYPE; |
... | ... | |
27 | 28 |
@Override |
28 | 29 |
public boolean canApply(ExpressionBuilder.Value value) { |
29 | 30 |
if (value instanceof ExpressionBuilder.Function) { |
30 |
return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_GEOMFROMTEXT, ((Function) value).name()); |
|
31 |
return StringUtils.equalsIgnoreCase(GeometryExpressionBuilder.FUNCTION_ST_GEOMFROMTEXT, ((Function) value).name());
|
|
31 | 32 |
} |
32 | 33 |
return false; |
33 | 34 |
} |
trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/PostgreSQLFormatter.java | ||
---|---|---|
21 | 21 |
new Decode(this.builder, this), |
22 | 22 |
new Constant(this.builder, this), |
23 | 23 |
new ILike(this.builder, this), |
24 |
new IfNull(this.builder, this), |
|
24 | 25 |
new IsNull(this.builder, this), |
25 | 26 |
// new ST_AsEWKB(this.builder, this), |
26 | 27 |
new ST_ExtentAggregate(this.builder, this), |
trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/Constant.java | ||
---|---|---|
4 | 4 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
5 | 5 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
6 | 6 |
import org.gvsig.expressionevaluator.Formatter; |
7 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
|
7 | 8 |
import org.gvsig.fmap.dal.SQLBuilder; |
8 | 9 |
import org.gvsig.fmap.geom.Geometry; |
9 | 10 |
import org.gvsig.fmap.geom.GeometryUtils; |
... | ... | |
43 | 44 |
@Override |
44 | 45 |
public String format(Value constant) { |
45 | 46 |
Object x = ((ExpressionBuilder.Constant)constant).value(); |
46 |
ExpressionBuilder builder = this.sqlbuilder.expression(); |
|
47 |
GeometryExpressionBuilder builder = this.sqlbuilder.expression();
|
|
47 | 48 |
if( x instanceof byte[] ) { |
48 | 49 |
return builder.string("\\x"+builder.bytearray_hex((byte[]) x))+"::bytea"; |
49 | 50 |
} |
trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/IfNull.java | ||
---|---|---|
1 |
package org.gvsig.postgresql.dal.expressionbuilderformatter; |
|
2 |
|
|
3 |
import java.text.MessageFormat; |
|
4 |
import java.util.List; |
|
5 |
import org.apache.commons.lang3.StringUtils; |
|
6 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
7 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_IFNULL; |
|
8 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
|
9 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
|
10 |
import org.gvsig.expressionevaluator.Formatter; |
|
11 |
import org.gvsig.fmap.dal.SQLBuilder; |
|
12 |
|
|
13 |
/** |
|
14 |
* |
|
15 |
* @author jjdelcerro |
|
16 |
*/ |
|
17 |
class IfNull implements Formatter<Value> { |
|
18 |
|
|
19 |
private final Formatter<Value> formatter; |
|
20 |
private final SQLBuilder builder; |
|
21 |
|
|
22 |
public IfNull(SQLBuilder builder, Formatter<Value> formatter) { |
|
23 |
this.builder = builder; |
|
24 |
this.formatter = formatter; |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
28 |
public boolean canApply(Value value) { |
|
29 |
if (value instanceof Function) { |
|
30 |
if (value instanceof ExpressionBuilder.Function) { |
|
31 |
return StringUtils.equalsIgnoreCase(FUNCTION_IFNULL, ((Function) value).name()); |
|
32 |
} |
|
33 |
} |
|
34 |
return false; |
|
35 |
} |
|
36 |
|
|
37 |
@Override |
|
38 |
public String format(Value function) { |
|
39 |
List<Value> parameters = ((Function) function).parameters(); |
|
40 |
String p1 = parameters.get(0).toString(formatter); |
|
41 |
String p2 = parameters.get(1).toString(formatter); |
|
42 |
String p3 = parameters.get(2).toString(formatter); |
|
43 |
String r = MessageFormat.format( |
|
44 |
"CASE WHEN ({0}) IS NULL THEN ({1}) ELSE ({2}) END", |
|
45 |
p1, |
|
46 |
p3, |
|
47 |
p2 |
|
48 |
); |
|
49 |
return r; |
|
50 |
|
|
51 |
} |
|
52 |
|
|
53 |
} |
trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/ILike.java | ||
---|---|---|
36 | 36 |
List<Value> parameters = ((Function) function).parameters(); |
37 | 37 |
String p1 = parameters.get(0).toString(formatter); |
38 | 38 |
String p2 = parameters.get(1).toString(formatter); |
39 |
String r = MessageFormat.format("(({0}).LOWER() LIKE ({1}).LOWER())", p1, p2);
|
|
39 |
String r = MessageFormat.format("({0}) ~~* ({1})", p1, p2);
|
|
40 | 40 |
return r; |
41 | 41 |
} |
42 | 42 |
|
trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/pom.xml | ||
---|---|---|
12 | 12 |
<artifactId>org.gvsig.postgresql</artifactId> |
13 | 13 |
<version>2.0.115-SNAPSHOT</version> |
14 | 14 |
</parent> |
15 |
<build> |
|
16 |
<plugins> |
|
17 |
<plugin> |
|
18 |
<groupId>org.apache.maven.plugins</groupId> |
|
19 |
<artifactId>maven-surefire-plugin</artifactId> |
|
20 |
<version>2.15</version> |
|
21 |
</plugin> |
|
22 |
</plugins> |
|
23 |
</build> |
|
24 | 15 |
<dependencies> |
25 | 16 |
<dependency> |
26 | 17 |
<groupId>com.googlecode.log4jdbc</groupId> |
... | ... | |
129 | 120 |
</dependency> |
130 | 121 |
<dependency> |
131 | 122 |
<groupId>org.gvsig</groupId> |
132 |
<artifactId>org.gvsig.expressionevaluator.lib.impl</artifactId> |
|
123 |
<artifactId>org.gvsig.expressionevaluator.geometry.lib.impl</artifactId>
|
|
133 | 124 |
<scope>test</scope> |
134 | 125 |
</dependency> |
135 | 126 |
<dependency> |
... | ... | |
150 | 141 |
<dependency> |
151 | 142 |
<artifactId>junit</artifactId> |
152 | 143 |
<groupId>junit</groupId> |
153 |
<version>4.11</version>
|
|
144 |
<scope>test</scope>
|
|
154 | 145 |
</dependency> |
155 | 146 |
</dependencies> |
156 | 147 |
|
148 |
<build> |
|
149 |
<plugins> |
|
150 |
|
|
151 |
<!-- Skip test execution ? --> |
|
152 |
<plugin> |
|
153 |
<groupId>org.apache.maven.plugins</groupId> |
|
154 |
<artifactId>maven-surefire-plugin</artifactId> |
|
155 |
<configuration> |
|
156 |
<skipTests>false</skipTests> |
|
157 |
</configuration> |
|
158 |
</plugin> |
|
159 |
|
|
160 |
<!-- Skip test compilation ? --> |
|
161 |
<plugin> |
|
162 |
<groupId>org.apache.maven.plugins</groupId> |
|
163 |
<artifactId>maven-compiler-plugin</artifactId> |
|
164 |
<executions> |
|
165 |
<execution> |
|
166 |
<id>default-testCompile</id> |
|
167 |
<phase>process-test-sources</phase> |
|
168 |
<goals> |
|
169 |
<goal>testCompile</goal> |
|
170 |
</goals> |
|
171 |
<configuration> |
|
172 |
<skip>false</skip> |
|
173 |
</configuration> |
|
174 |
</execution> |
|
175 |
</executions> |
|
176 |
</plugin> |
|
177 |
|
|
178 |
<!-- Ignore test execution failure ? --> |
|
179 |
<plugin> |
|
180 |
<groupId>org.apache.maven.plugins</groupId> |
|
181 |
<artifactId>maven-surefire-plugin</artifactId> |
|
182 |
<configuration> |
|
183 |
<testFailureIgnore>false</testFailureIgnore> |
|
184 |
</configuration> |
|
185 |
</plugin> |
|
186 |
|
|
187 |
</plugins> |
|
188 |
</build> |
|
189 |
|
|
157 | 190 |
</project> |
trunk/org.gvsig.postgresql/pom.xml | ||
---|---|---|
11 | 11 |
<parent> |
12 | 12 |
<groupId>org.gvsig</groupId> |
13 | 13 |
<artifactId>org.gvsig.desktop</artifactId> |
14 |
<version>2.0.259</version>
|
|
14 |
<version>2.0.261-SNAPSHOT</version>
|
|
15 | 15 |
</parent> |
16 | 16 |
|
17 | 17 |
<url>https://devel.gvsig.org/redmine/projects/gvsig-postgresql</url> |
Also available in: Unified diff