Revision 992
tags/org.gvsig.postgresql-2.0.192/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
|
|
3 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
4 |
|
|
5 |
<modelVersion>4.0.0</modelVersion> |
|
6 |
<artifactId>org.gvsig.postgresql</artifactId> |
|
7 |
<version>2.0.192</version> |
|
8 |
<packaging>pom</packaging> |
|
9 |
<name>${project.artifactId}</name> |
|
10 |
<description>PostgreSQL support fort DAL and gvSIG</description> |
|
11 |
<parent> |
|
12 |
<groupId>org.gvsig</groupId> |
|
13 |
<artifactId>org.gvsig.desktop</artifactId> |
|
14 |
<version>2.0.355</version> |
|
15 |
</parent> |
|
16 |
|
|
17 |
<url>https://devel.gvsig.org/redmine/projects/gvsig-postgresql</url> |
|
18 |
<scm> |
|
19 |
<connection>scm:svn:https://devel.gvsig.org/svn/gvsig-postgresql/tags/org.gvsig.postgresql-2.0.192</connection> |
|
20 |
<developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-postgresql/tags/org.gvsig.postgresql-2.0.192</developerConnection> |
|
21 |
<url>https://devel.gvsig.org/redmine/projects/gvsig-postgresql/repository/show/tags/org.gvsig.postgresql-2.0.192</url> |
|
22 |
</scm> |
|
23 |
|
|
24 |
<repositories> |
|
25 |
<repository> |
|
26 |
<id>gvsig-public-http-repository</id> |
|
27 |
<name>gvSIG maven public HTTP repository</name> |
|
28 |
<url>http://devel.gvsig.org/m2repo/j2se</url> |
|
29 |
<releases> |
|
30 |
<enabled>true</enabled> |
|
31 |
<updatePolicy>daily</updatePolicy> |
|
32 |
<checksumPolicy>warn</checksumPolicy> |
|
33 |
</releases> |
|
34 |
<snapshots> |
|
35 |
<enabled>true</enabled> |
|
36 |
<updatePolicy>daily</updatePolicy> |
|
37 |
<checksumPolicy>warn</checksumPolicy> |
|
38 |
</snapshots> |
|
39 |
</repository> |
|
40 |
</repositories> |
|
41 |
|
|
42 |
|
|
43 |
<build> |
|
44 |
<plugins> |
|
45 |
<plugin> |
|
46 |
<groupId>org.apache.maven.plugins</groupId> |
|
47 |
<artifactId>maven-release-plugin</artifactId> |
|
48 |
<configuration> |
|
49 |
<tagBase>https://devel.gvsig.org/svn/gvsig-postgresql/tags/</tagBase> |
|
50 |
<goals>deploy</goals> |
|
51 |
</configuration> |
|
52 |
</plugin> |
|
53 |
</plugins> |
|
54 |
</build> |
|
55 |
|
|
56 |
|
|
57 |
<dependencyManagement> |
|
58 |
<dependencies> |
|
59 |
<dependency> |
|
60 |
<groupId>org.gvsig</groupId> |
|
61 |
<artifactId>org.gvsig.postgresql.provider</artifactId> |
|
62 |
<version>2.0.192</version> |
|
63 |
</dependency> |
|
64 |
<dependency> |
|
65 |
<groupId>org.gvsig</groupId> |
|
66 |
<artifactId>org.gvsig.postgresql.app.mainplugin</artifactId> |
|
67 |
<version>2.0.192</version> |
|
68 |
</dependency> |
|
69 |
<dependency> |
|
70 |
<groupId>org.postgresql</groupId> |
|
71 |
<artifactId>postgresql</artifactId> |
|
72 |
<version>42.3.1</version> |
|
73 |
</dependency> |
|
74 |
<dependency> |
|
75 |
<groupId>org.apache.commons</groupId> |
|
76 |
<artifactId>commons-dbcp2</artifactId> |
|
77 |
<version>2.7.0</version> |
|
78 |
</dependency> |
|
79 |
<dependency> |
|
80 |
<groupId>org.apache.commons</groupId> |
|
81 |
<artifactId>commons-pool2</artifactId> |
|
82 |
<version>2.7.0</version> |
|
83 |
</dependency> |
|
84 |
</dependencies> |
|
85 |
</dependencyManagement> |
|
86 |
|
|
87 |
<modules> |
|
88 |
<module>org.gvsig.postgresql.app</module> |
|
89 |
<module>org.gvsig.postgresql.provider</module> |
|
90 |
</modules> |
|
91 |
|
|
92 |
</project> |
tags/org.gvsig.postgresql-2.0.192/org.gvsig.postgresql.provider/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
|
|
3 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
4 |
|
|
5 |
<modelVersion>4.0.0</modelVersion> |
|
6 |
<artifactId>org.gvsig.postgresql.provider</artifactId> |
|
7 |
<packaging>jar</packaging> |
|
8 |
<name>${project.artifactId}</name> |
|
9 |
<description>DAL provider for PostgeSQL files</description> |
|
10 |
<parent> |
|
11 |
<groupId>org.gvsig</groupId> |
|
12 |
<artifactId>org.gvsig.postgresql</artifactId> |
|
13 |
<version>2.0.192</version> |
|
14 |
</parent> |
|
15 |
<dependencies> |
|
16 |
<dependency> |
|
17 |
<groupId>com.googlecode.log4jdbc</groupId> |
|
18 |
<artifactId>log4jdbc</artifactId> |
|
19 |
<scope>compile</scope> |
|
20 |
</dependency> |
|
21 |
<dependency> |
|
22 |
<groupId>org.gvsig</groupId> |
|
23 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
24 |
<scope>compile</scope> |
|
25 |
</dependency> |
|
26 |
<dependency> |
|
27 |
<groupId>org.gvsig</groupId> |
|
28 |
<artifactId>org.gvsig.projection.api</artifactId> |
|
29 |
<scope>compile</scope> |
|
30 |
</dependency> |
|
31 |
<dependency> |
|
32 |
<groupId>org.gvsig</groupId> |
|
33 |
<artifactId>org.gvsig.fmap.dal.api</artifactId> |
|
34 |
<scope>compile</scope> |
|
35 |
</dependency> |
|
36 |
|
|
37 |
<dependency> |
|
38 |
<groupId>org.gvsig</groupId> |
|
39 |
<artifactId>org.gvsig.fmap.dal.db.jdbc</artifactId> |
|
40 |
<scope>compile</scope> |
|
41 |
</dependency> |
|
42 |
|
|
43 |
<dependency> |
|
44 |
<groupId>org.gvsig</groupId> |
|
45 |
<artifactId>org.gvsig.fmap.dal.db.jdbc</artifactId> |
|
46 |
<scope>test</scope> |
|
47 |
<type>test-jar</type> |
|
48 |
</dependency> |
|
49 |
|
|
50 |
<dependency> |
|
51 |
<groupId>org.gvsig</groupId> |
|
52 |
<artifactId>org.gvsig.fmap.dal.db.lib</artifactId> |
|
53 |
<scope>compile</scope> |
|
54 |
</dependency> |
|
55 |
|
|
56 |
<dependency> |
|
57 |
<groupId>org.gvsig</groupId> |
|
58 |
<artifactId>org.gvsig.fmap.dal.spi</artifactId> |
|
59 |
<scope>compile</scope> |
|
60 |
</dependency> |
|
61 |
<dependency> |
|
62 |
<groupId>org.gvsig</groupId> |
|
63 |
<artifactId>org.gvsig.metadata.lib.basic.api</artifactId> |
|
64 |
<scope>compile</scope> |
|
65 |
</dependency> |
|
66 |
<dependency> |
|
67 |
<groupId>org.gvsig</groupId> |
|
68 |
<artifactId>org.gvsig.fmap.geometry.api</artifactId> |
|
69 |
<scope>compile</scope> |
|
70 |
</dependency> |
|
71 |
<!-- |
|
72 |
<dependency> |
|
73 |
<groupId>org.gvsig</groupId> |
|
74 |
<artifactId>org.gvsig.fmap.geometry.operation</artifactId> |
|
75 |
<scope>compile</scope> |
|
76 |
</dependency> |
|
77 |
--> |
|
78 |
<dependency> |
|
79 |
<groupId>org.gvsig</groupId> |
|
80 |
<artifactId>org.gvsig.timesupport.lib.api</artifactId> |
|
81 |
<scope>compile</scope> |
|
82 |
</dependency> |
|
83 |
<dependency> |
|
84 |
<groupId>org.gvsig</groupId> |
|
85 |
<artifactId>org.gvsig.utils</artifactId> |
|
86 |
<scope>compile</scope> |
|
87 |
</dependency> |
|
88 |
<dependency> |
|
89 |
<groupId>org.postgresql</groupId> |
|
90 |
<artifactId>postgresql</artifactId> |
|
91 |
<scope>compile</scope> |
|
92 |
</dependency> |
|
93 |
<dependency> |
|
94 |
<groupId>org.apache.commons</groupId> |
|
95 |
<artifactId>commons-dbcp2</artifactId> |
|
96 |
</dependency> |
|
97 |
<dependency> |
|
98 |
<groupId>org.apache.commons</groupId> |
|
99 |
<artifactId>commons-pool2</artifactId> |
|
100 |
</dependency> |
|
101 |
<dependency> |
|
102 |
<groupId>commons-collections</groupId> |
|
103 |
<artifactId>commons-collections</artifactId> |
|
104 |
<scope>compile</scope> |
|
105 |
</dependency> |
|
106 |
|
|
107 |
|
|
108 |
<!-- TESTS --> |
|
109 |
<dependency> |
|
110 |
<groupId>org.gvsig</groupId> |
|
111 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
112 |
<type>test-jar</type> |
|
113 |
<scope>test</scope> |
|
114 |
</dependency> |
|
115 |
<dependency> |
|
116 |
<groupId>org.gvsig</groupId> |
|
117 |
<artifactId>org.gvsig.compat.se</artifactId> |
|
118 |
<scope>test</scope> |
|
119 |
</dependency> |
|
120 |
<dependency> |
|
121 |
<groupId>org.gvsig</groupId> |
|
122 |
<artifactId>org.gvsig.fmap.dal.impl</artifactId> |
|
123 |
<scope>test</scope> |
|
124 |
</dependency> |
|
125 |
<dependency> |
|
126 |
<groupId>org.gvsig</groupId> |
|
127 |
<artifactId>org.gvsig.fmap.dal.file.csv</artifactId> |
|
128 |
<scope>test</scope> |
|
129 |
</dependency> |
|
130 |
<dependency> |
|
131 |
<groupId>org.gvsig</groupId> |
|
132 |
<artifactId>org.gvsig.tools.util.impl</artifactId> |
|
133 |
<scope>test</scope> |
|
134 |
</dependency> |
|
135 |
<dependency> |
|
136 |
<groupId>org.gvsig</groupId> |
|
137 |
<artifactId>org.gvsig.tools.swing.impl</artifactId> |
|
138 |
<scope>test</scope> |
|
139 |
</dependency> |
|
140 |
<dependency> |
|
141 |
<groupId>org.gvsig</groupId> |
|
142 |
<artifactId>${org.gvsig.fmap.geometry.impl}</artifactId> |
|
143 |
<scope>test</scope> |
|
144 |
</dependency> |
|
145 |
<dependency> |
|
146 |
<groupId>org.gvsig</groupId> |
|
147 |
<artifactId>org.gvsig.expressionevaluator.geometry.lib.impl</artifactId> |
|
148 |
<scope>test</scope> |
|
149 |
</dependency> |
|
150 |
<dependency> |
|
151 |
<groupId>org.gvsig</groupId> |
|
152 |
<artifactId>${org.gvsig.proj.lib.impl}</artifactId> |
|
153 |
<scope>test</scope> |
|
154 |
</dependency> |
|
155 |
<dependency> |
|
156 |
<groupId>org.gvsig</groupId> |
|
157 |
<artifactId>org.gvsig.projection.cresques.impl</artifactId> |
|
158 |
<scope>test</scope> |
|
159 |
</dependency> |
|
160 |
<dependency> |
|
161 |
<groupId>org.gvsig</groupId> |
|
162 |
<artifactId>org.gvsig.timesupport.lib.impl</artifactId> |
|
163 |
<scope>test</scope> |
|
164 |
</dependency> |
|
165 |
<dependency> |
|
166 |
<groupId>org.gvsig</groupId> |
|
167 |
<artifactId>org.gvsig.metadata.lib.basic.impl</artifactId> |
|
168 |
<scope>test</scope> |
|
169 |
</dependency> |
|
170 |
|
|
171 |
|
|
172 |
<dependency> |
|
173 |
<artifactId>junit</artifactId> |
|
174 |
<groupId>junit</groupId> |
|
175 |
<scope>test</scope> |
|
176 |
</dependency> |
|
177 |
</dependencies> |
|
178 |
|
|
179 |
<build> |
|
180 |
<plugins> |
|
181 |
|
|
182 |
<!-- Skip test execution ? --> |
|
183 |
<plugin> |
|
184 |
<groupId>org.apache.maven.plugins</groupId> |
|
185 |
<artifactId>maven-surefire-plugin</artifactId> |
|
186 |
<configuration> |
|
187 |
<skipTests>false</skipTests> |
|
188 |
</configuration> |
|
189 |
</plugin> |
|
190 |
|
|
191 |
<!-- Skip test compilation ? --> |
|
192 |
<plugin> |
|
193 |
<groupId>org.apache.maven.plugins</groupId> |
|
194 |
<artifactId>maven-compiler-plugin</artifactId> |
|
195 |
<executions> |
|
196 |
<execution> |
|
197 |
<id>default-testCompile</id> |
|
198 |
<phase>process-test-sources</phase> |
|
199 |
<goals> |
|
200 |
<goal>testCompile</goal> |
|
201 |
</goals> |
|
202 |
<configuration> |
|
203 |
<skip>false</skip> |
|
204 |
</configuration> |
|
205 |
</execution> |
|
206 |
</executions> |
|
207 |
</plugin> |
|
208 |
|
|
209 |
<!-- Ignore test execution failure ? --> |
|
210 |
<plugin> |
|
211 |
<groupId>org.apache.maven.plugins</groupId> |
|
212 |
<artifactId>maven-surefire-plugin</artifactId> |
|
213 |
<configuration> |
|
214 |
<testFailureIgnore>false</testFailureIgnore> |
|
215 |
</configuration> |
|
216 |
</plugin> |
|
217 |
|
|
218 |
</plugins> |
|
219 |
</build> |
|
220 |
|
|
221 |
</project> |
tags/org.gvsig.postgresql-2.0.192/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/TestComputedAttributes.java | ||
---|---|---|
1 |
package org.gvsig.postgresql.dal; |
|
2 |
|
|
3 |
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestComputedAttributes; |
|
4 |
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestUtils; |
|
5 |
|
|
6 |
public class TestComputedAttributes extends AbstractTestComputedAttributes { |
|
7 |
|
|
8 |
public TestComputedAttributes(String testName) { |
|
9 |
super(testName); |
|
10 |
} |
|
11 |
|
|
12 |
@Override |
|
13 |
protected AbstractTestUtils createUtils() { |
|
14 |
return new TestUtilsPostgreSQL(); |
|
15 |
} |
|
16 |
|
|
17 |
@Override |
|
18 |
public void testComputed1() throws Exception { |
|
19 |
super.testComputed1(); |
|
20 |
} |
|
21 |
|
|
22 |
@Override |
|
23 |
public void testComputed2() throws Exception { |
|
24 |
super.testComputed2(); |
|
25 |
} |
|
26 |
|
|
27 |
} |
tags/org.gvsig.postgresql-2.0.192/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/PostgreSQLBuilderTest.java | ||
---|---|---|
1 |
package org.gvsig.postgresql.dal; |
|
2 |
|
|
3 |
import junit.framework.TestCase; |
|
4 |
import org.apache.commons.lang3.ArrayUtils; |
|
5 |
import org.cresques.cts.IProjection; |
|
6 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
7 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
|
8 |
import org.gvsig.fmap.crs.CRSFactory; |
|
9 |
import org.gvsig.fmap.dal.SQLBuilder; |
|
10 |
import org.gvsig.fmap.dal.SQLBuilder.Privilege; |
|
11 |
import org.gvsig.fmap.dal.feature.spi.SQLBuilderBase; |
|
12 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
|
13 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.OperationsFactoryBase; |
|
14 |
import org.gvsig.fmap.geom.DataTypes; |
|
15 |
import org.gvsig.fmap.geom.Geometry; |
|
16 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
17 |
import org.gvsig.fmap.geom.GeometryManager; |
|
18 |
import org.gvsig.fmap.geom.primitive.Polygon; |
|
19 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
20 |
|
|
21 |
public class PostgreSQLBuilderTest extends TestCase { |
|
22 |
|
|
23 |
public PostgreSQLBuilderTest(String testName) { |
|
24 |
super(testName); |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
28 |
protected void setUp() throws Exception { |
|
29 |
super.setUp(); |
|
30 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
31 |
} |
|
32 |
|
|
33 |
@Override |
|
34 |
protected void tearDown() throws Exception { |
|
35 |
super.tearDown(); |
|
36 |
} |
|
37 |
|
|
38 |
private SQLBuilder createSQLBuilder() { |
|
39 |
return new PostgreSQLBuilder(new PostgreSQLHelper(new FakePostgreSQLConnectionParameters())); |
|
40 |
} |
|
41 |
|
|
42 |
public void testCalulateEnvelopeOfColumn() throws Exception { |
|
43 |
|
|
44 |
TableReference table = new OperationsFactoryBase.DefaultTableReference("master","dbo","test1", null); |
|
45 |
String columnName = "the_geom"; |
|
46 |
|
|
47 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
48 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
49 |
|
|
50 |
sqlbuilder.select().column().value( |
|
51 |
expbuilder.as_geometry( |
|
52 |
expbuilder.ST_ExtentAggregate( |
|
53 |
expbuilder.column(columnName) |
|
54 |
) |
|
55 |
) |
|
56 |
); |
|
57 |
//sqlbuilder.select().group_by(expbuilder.column(columnName)); |
|
58 |
sqlbuilder.select().from().table() |
|
59 |
.database(table.getDatabase()) |
|
60 |
.schema(table.getSchema()) |
|
61 |
.name(table.getTable()); |
|
62 |
sqlbuilder.select().from().subquery(table.getSubquery()); |
|
63 |
|
|
64 |
sqlbuilder.select().where().and( |
|
65 |
expbuilder.not_is_null(expbuilder.column(columnName)) |
|
66 |
); |
|
67 |
|
|
68 |
System.out.println("# Test:: testCalulateEnvelopeOfColumn"); |
|
69 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
70 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
71 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
72 |
assertEquals( |
|
73 |
"SELECT ST_AsBinary(ST_Extent(\"the_geom\")) FROM \"master\".\"dbo\".\"test1\" WHERE ( (\"the_geom\") IS NOT NULL )", |
|
74 |
sqlbuilder.toString() |
|
75 |
); |
|
76 |
assertEquals( |
|
77 |
"[the_geom]", |
|
78 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
79 |
); |
|
80 |
assertEquals( |
|
81 |
"[]", |
|
82 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
83 |
); |
|
84 |
} |
|
85 |
|
|
86 |
public void testCalulateEnvelope() throws Exception { |
|
87 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
88 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
|
89 |
|
|
90 |
Polygon limit = geometryManager.createPolygon(Geometry.SUBTYPES.GEOM2D); |
|
91 |
limit.addVertex(0, 0); |
|
92 |
limit.addVertex(0, 100); |
|
93 |
limit.addVertex(100, 100); |
|
94 |
limit.addVertex(100, 0); |
|
95 |
limit.addVertex(0, 0); |
|
96 |
|
|
97 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
98 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
99 |
|
|
100 |
sqlbuilder.select().column().value( |
|
101 |
expbuilder.as_geometry( |
|
102 |
expbuilder.ST_ExtentAggregate( |
|
103 |
expbuilder.column("the_geom") |
|
104 |
) |
|
105 |
) |
|
106 |
).as("envelope"); |
|
107 |
sqlbuilder.select().from().table().database("master").schema("dbo").name("test1"); |
|
108 |
sqlbuilder.select().where().set( |
|
109 |
expbuilder.ST_Intersects( |
|
110 |
expbuilder.ST_Envelope( |
|
111 |
expbuilder.column("the_geom") |
|
112 |
), |
|
113 |
expbuilder.geometry(limit, proj) |
|
114 |
) |
|
115 |
); |
|
116 |
sqlbuilder.select().where().and( |
|
117 |
expbuilder.custom("x = 27") |
|
118 |
); |
|
119 |
|
|
120 |
System.out.println("# Test:: testCalulateEnvelope"); |
|
121 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
122 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
123 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
124 |
assertEquals( |
|
125 |
"SELECT ST_AsBinary(ST_Extent(\"the_geom\")) AS \"envelope\" FROM \"master\".\"dbo\".\"test1\" WHERE (ST_Intersects((ST_Envelope(\"the_geom\")), (ST_GeomFromWKB(('\\x000000000300000001000000050000000000000000000000000000000000000000000000004059000000000000405900000000000040590000000000004059000000000000000000000000000000000000000000000000000000000000'::bytea), (4326)))) AND x = 27)", |
|
126 |
sqlbuilder.toString() |
|
127 |
); |
|
128 |
assertEquals( |
|
129 |
"[the_geom]", |
|
130 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
131 |
); |
|
132 |
assertEquals( |
|
133 |
"[]", |
|
134 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
135 |
); |
|
136 |
} |
|
137 |
|
|
138 |
public void testCount() throws Exception { |
|
139 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
140 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
141 |
|
|
142 |
sqlbuilder.select().column().value(sqlbuilder.count().all()); |
|
143 |
sqlbuilder.select().from().table().database("master").schema("dbo").name("test1"); |
|
144 |
sqlbuilder.select().from().subquery(null); |
|
145 |
sqlbuilder.select().where().set( expbuilder.custom("pp = 200")); |
|
146 |
|
|
147 |
System.out.println("# Test:: testCount"); |
|
148 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
149 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
150 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
151 |
|
|
152 |
//# Test:: testCount |
|
153 |
//# SQL:: SELECT COUNT(*) FROM "test1" WHERE pp = 200 |
|
154 |
//# Variables:: [] |
|
155 |
//# Parametros:: [] |
|
156 |
|
|
157 |
assertEquals( |
|
158 |
"SELECT COUNT(*) FROM \"master\".\"dbo\".\"test1\" WHERE pp = 200", |
|
159 |
sqlbuilder.toString() |
|
160 |
); |
|
161 |
assertEquals( |
|
162 |
"[]", |
|
163 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
164 |
); |
|
165 |
assertEquals( |
|
166 |
"[]", |
|
167 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
168 |
); |
|
169 |
} |
|
170 |
|
|
171 |
public void testCreateTable() throws Exception { |
|
172 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
173 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
174 |
|
|
175 |
sqlbuilder.create_table().table().database("master").schema("dbo").name("test1"); |
|
176 |
sqlbuilder.create_table().add_column( |
|
177 |
"name", |
|
178 |
DataTypes.STRING, |
|
179 |
45, |
|
180 |
0, |
|
181 |
0, |
|
182 |
false, |
|
183 |
false, |
|
184 |
true, |
|
185 |
false, |
|
186 |
null |
|
187 |
); |
|
188 |
sqlbuilder.create_table().add_column( |
|
189 |
"id", |
|
190 |
DataTypes.INT, |
|
191 |
0, |
|
192 |
0, |
|
193 |
0, |
|
194 |
true, |
|
195 |
false, |
|
196 |
false, |
|
197 |
true, |
|
198 |
0 |
|
199 |
); |
|
200 |
sqlbuilder.create_table().add_column( |
|
201 |
"geom", |
|
202 |
DataTypes.GEOMETRY, |
|
203 |
0, |
|
204 |
0, |
|
205 |
0, |
|
206 |
false, |
|
207 |
false, |
|
208 |
true, |
|
209 |
false, |
|
210 |
null |
|
211 |
); |
|
212 |
|
|
213 |
|
|
214 |
// CREATE TABLE "test1" ("name" VARCHAR(45) DEFAULT NULL, "id" INTEGER PRIMARY KEY AUTO_INCREMENT DEFAULT '0' NOT NULL, "geom" GEOMETRY ); ALTER TABLE "test1" ADD CONSTRAINT IF NOT EXISTS "constraint_test1_geom_dim" CHECK ST_CoordDim("geom") = 2 |
|
215 |
System.out.println("# Test:: testCreateTable"); |
|
216 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
217 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
218 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
219 |
assertEquals( |
|
220 |
"CREATE TABLE \"master\".\"dbo\".\"test1\" (\"name\" VARCHAR(45) DEFAULT NULL NULL, \"id\" SERIAL PRIMARY KEY ); SELECT AddGeometryColumn('dbo' , 'test1' , 'geom', null , 'GEOMETRY' , 2, TRUE)", |
|
221 |
sqlbuilder.toString() |
|
222 |
); |
|
223 |
assertEquals( |
|
224 |
"[]", |
|
225 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
226 |
); |
|
227 |
assertEquals( |
|
228 |
"[]", |
|
229 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
230 |
); |
|
231 |
} |
|
232 |
|
|
233 |
public void testDropTable() throws Exception { |
|
234 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
235 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
236 |
|
|
237 |
sqlbuilder.drop_table().table().database("master").schema("dbo").name("test1"); |
|
238 |
|
|
239 |
// DROP TABLE "test1" |
|
240 |
|
|
241 |
System.out.println("# Test:: testDropTable"); |
|
242 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
243 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
244 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
245 |
assertEquals( |
|
246 |
"DROP TABLE \"master\".\"dbo\".\"test1\"", |
|
247 |
sqlbuilder.toString() |
|
248 |
); |
|
249 |
assertEquals( |
|
250 |
"[]", |
|
251 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
252 |
); |
|
253 |
assertEquals( |
|
254 |
"[]", |
|
255 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
256 |
); |
|
257 |
} |
|
258 |
|
|
259 |
public void testFetchFeatureProviderByReference() throws Exception { |
|
260 |
SQLBuilder sqlbuilder = new SQLBuilderBase(); |
|
261 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
262 |
|
|
263 |
String value = "yoyo"; |
|
264 |
sqlbuilder.select().column().name("name"); |
|
265 |
sqlbuilder.select().column().name("id"); |
|
266 |
sqlbuilder.select().column().name("geom").as_geometry(); |
|
267 |
sqlbuilder.select().from().table().database("master").schema("dbo").name("test1"); |
|
268 |
sqlbuilder.select().where().set( |
|
269 |
expbuilder.eq( |
|
270 |
expbuilder.column("name"), |
|
271 |
expbuilder.parameter(value).as_constant() |
|
272 |
) |
|
273 |
); |
|
274 |
sqlbuilder.select().limit(1); |
|
275 |
|
|
276 |
// SELECT "name", "id", ST_AsBinary("geom") FROM "master"."dbo"."test1" WHERE ( ("name") = (?) ) LIMIT 1 |
|
277 |
|
|
278 |
System.out.println("# Test:: testFetchFeatureProviderByReference"); |
|
279 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
280 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
281 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
282 |
assertEquals( |
|
283 |
"SELECT \"name\", \"id\", ST_AsBinary(\"geom\") FROM \"master\".\"dbo\".\"test1\" WHERE ( (\"name\") = (?) ) LIMIT 1", |
|
284 |
sqlbuilder.toString() |
|
285 |
); |
|
286 |
assertEquals( |
|
287 |
"[geom, id, name]", |
|
288 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
289 |
); |
|
290 |
assertEquals( |
|
291 |
"['yoyo']", |
|
292 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
293 |
); |
|
294 |
} |
|
295 |
|
|
296 |
public void testFetchFeatureType() throws Exception { |
|
297 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
298 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
299 |
|
|
300 |
sqlbuilder.select().column().all(); |
|
301 |
sqlbuilder.select().from().table().database("master").schema("dbo").name("test1"); |
|
302 |
sqlbuilder.select().limit(1); |
|
303 |
|
|
304 |
System.out.println("# Test:: testFetchFeatureType"); |
|
305 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
306 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
307 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
308 |
|
|
309 |
//# Test:: testFetchFeatureType |
|
310 |
//# SQL:: SELECT * FROM "test1" LIMIT 1 |
|
311 |
//# Variables:: [] |
|
312 |
//# Parametros:: [] |
|
313 |
|
|
314 |
assertEquals( |
|
315 |
"SELECT * FROM \"master\".\"dbo\".\"test1\" LIMIT 1", |
|
316 |
sqlbuilder.toString() |
|
317 |
); |
|
318 |
assertEquals( |
|
319 |
"[]", |
|
320 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
321 |
); |
|
322 |
assertEquals( |
|
323 |
"[]", |
|
324 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
325 |
); |
|
326 |
} |
|
327 |
|
|
328 |
public void testPerformDeletes() throws Exception { |
|
329 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
330 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
331 |
|
|
332 |
sqlbuilder.delete().table().database("master").schema("dbo").name("test1"); |
|
333 |
sqlbuilder.delete().where().and( |
|
334 |
expbuilder.eq( |
|
335 |
expbuilder.column("id1"), |
|
336 |
expbuilder.parameter("id1").as_variable() |
|
337 |
) |
|
338 |
); |
|
339 |
sqlbuilder.delete().where().and( |
|
340 |
expbuilder.eq( |
|
341 |
expbuilder.column("id2"), |
|
342 |
expbuilder.parameter("id2").as_variable() |
|
343 |
) |
|
344 |
); |
|
345 |
|
|
346 |
// DELETE FROM "test1" WHERE ( ("id1") = (?) ) AND ( ("id2") = (?) ) |
|
347 |
|
|
348 |
System.out.println("# Test:: testPerformDeletes"); |
|
349 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
350 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
351 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
352 |
assertEquals( |
|
353 |
"DELETE FROM \"master\".\"dbo\".\"test1\" WHERE (( (\"id1\") = (?) ) AND ( (\"id2\") = (?) ))", |
|
354 |
sqlbuilder.toString() |
|
355 |
); |
|
356 |
assertEquals( |
|
357 |
"[id1, id2]", |
|
358 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
359 |
); |
|
360 |
assertEquals( |
|
361 |
"[\"id1\", \"id2\"]", |
|
362 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
363 |
); |
|
364 |
} |
|
365 |
|
|
366 |
public void testPerformInserts1() throws Exception { |
|
367 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
|
368 |
|
|
369 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
370 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
371 |
|
|
372 |
sqlbuilder.insert().table().database("master").schema("dbo").name("test1"); |
|
373 |
sqlbuilder.insert().column().name("id").with_value(expbuilder.parameter("id")); |
|
374 |
sqlbuilder.insert().column().name("name").with_value(expbuilder.parameter("name")); |
|
375 |
sqlbuilder.insert().column().name("geom").with_value(expbuilder.parameter("geom").as_geometry_variable().srs(proj)); |
|
376 |
|
|
377 |
System.out.println("# Test:: testPerformInserts1"); |
|
378 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
379 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
380 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
381 |
assertEquals( |
|
382 |
"INSERT INTO \"master\".\"dbo\".\"test1\" ( \"id\", \"name\", \"geom\" ) VALUES ( ?, ?, ST_GeomFromWKB((?), (4326)) )", |
|
383 |
sqlbuilder.toString() |
|
384 |
); |
|
385 |
assertEquals( |
|
386 |
"[geom, id, name]", |
|
387 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
388 |
); |
|
389 |
assertEquals( |
|
390 |
"[\"id\", \"name\", \"geom\"]", |
|
391 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
392 |
); |
|
393 |
} |
|
394 |
|
|
395 |
public void testPerformInserts2() throws Exception { |
|
396 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
|
397 |
|
|
398 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
399 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
400 |
|
|
401 |
sqlbuilder.insert().table().database("master").schema("dbo").name("test1"); |
|
402 |
sqlbuilder.insert().column().name("id").with_value(expbuilder.parameter("id")); |
|
403 |
sqlbuilder.insert().column().name("name").with_value(expbuilder.parameter("name")); |
|
404 |
sqlbuilder.insert().column().name("geom").with_value(expbuilder.parameter("geom").as_geometry_variable().srs(proj)); |
|
405 |
|
|
406 |
System.out.println("# Test:: testPerformInserts2"); |
|
407 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
408 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
409 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
410 |
assertEquals( |
|
411 |
"INSERT INTO \"master\".\"dbo\".\"test1\" ( \"id\", \"name\", \"geom\" ) VALUES ( ?, ?, ST_GeomFromWKB((?), (4326)) )", |
|
412 |
sqlbuilder.toString() |
|
413 |
); |
|
414 |
assertEquals( |
|
415 |
"[geom, id, name]", |
|
416 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
417 |
); |
|
418 |
assertEquals( |
|
419 |
"[\"id\", \"name\", \"geom\"]", |
|
420 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
421 |
); |
|
422 |
} |
|
423 |
|
|
424 |
public void testPerformUpdates1() throws Exception { |
|
425 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
|
426 |
|
|
427 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
428 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
429 |
|
|
430 |
sqlbuilder.update().table().database("master").schema("dbo").name("test1"); |
|
431 |
sqlbuilder.update().where().and( |
|
432 |
expbuilder.eq( |
|
433 |
expbuilder.column("id"), |
|
434 |
expbuilder.parameter("id").as_variable() |
|
435 |
) |
|
436 |
); |
|
437 |
sqlbuilder.update().column().name("name").with_value(expbuilder.parameter("name")); |
|
438 |
sqlbuilder.update().column().name("geom").with_value( |
|
439 |
expbuilder.parameter("geom").as_geometry_variable().srs(proj) |
|
440 |
); |
|
441 |
|
|
442 |
System.out.println("# Test:: testPerformUpdates"); |
|
443 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
444 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
445 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
446 |
assertEquals( |
|
447 |
"UPDATE \"master\".\"dbo\".\"test1\" SET \"name\" = ?, \"geom\" = ST_GeomFromWKB((?), (4326)) WHERE ( (\"id\") = (?) )", |
|
448 |
sqlbuilder.toString() |
|
449 |
); |
|
450 |
assertEquals( |
|
451 |
"[geom, id, name]", |
|
452 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
453 |
); |
|
454 |
assertEquals( |
|
455 |
"[\"name\", \"geom\", \"id\"]", |
|
456 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
457 |
); |
|
458 |
} |
|
459 |
|
|
460 |
public void testPerformUpdates2() throws Exception { |
|
461 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
|
462 |
|
|
463 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
464 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
465 |
|
|
466 |
sqlbuilder.update().table().database("master").schema("dbo").name("test1"); |
|
467 |
sqlbuilder.update().where().and( |
|
468 |
expbuilder.eq( |
|
469 |
expbuilder.column("id"), |
|
470 |
expbuilder.parameter("id").as_variable() |
|
471 |
) |
|
472 |
); |
|
473 |
sqlbuilder.update().column().name("name").with_value(expbuilder.parameter("name")); |
|
474 |
sqlbuilder.update().column().name("geom").with_value( |
|
475 |
expbuilder.parameter("geom").as_geometry_variable() |
|
476 |
.srs(expbuilder.parameter().value(proj)) |
|
477 |
); |
|
478 |
|
|
479 |
System.out.println("# Test:: testPerformUpdates"); |
|
480 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
481 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
482 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
483 |
assertEquals( |
|
484 |
"UPDATE \"master\".\"dbo\".\"test1\" SET \"name\" = ?, \"geom\" = ST_GeomFromWKB((?), (?)) WHERE ( (\"id\") = (?) )", |
|
485 |
sqlbuilder.toString() |
|
486 |
); |
|
487 |
assertEquals( |
|
488 |
"[geom, id, name]", |
|
489 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
490 |
); |
|
491 |
assertEquals( |
|
492 |
"[\"name\", \"geom\", 4326, \"id\"]", |
|
493 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
494 |
); |
|
495 |
} |
|
496 |
|
|
497 |
public void testGrant1() throws Exception { |
|
498 |
|
|
499 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
500 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
501 |
|
|
502 |
sqlbuilder.grant().table().database("master").schema("dbo").name("test1"); |
|
503 |
sqlbuilder.grant().role("prueba").select().insert().update(); |
|
504 |
sqlbuilder.grant().role("gis").all(); |
|
505 |
|
|
506 |
|
|
507 |
System.out.println("# Test:: testGrant1"); |
|
508 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
509 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
510 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
511 |
assertEquals( |
|
512 |
"", |
|
513 |
sqlbuilder.toString() |
|
514 |
); |
|
515 |
assertEquals( |
|
516 |
"[]", |
|
517 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
518 |
); |
|
519 |
assertEquals( |
|
520 |
"[]", |
|
521 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
522 |
); |
|
523 |
} |
|
524 |
|
|
525 |
public void testGrant2() throws Exception { |
|
526 |
|
|
527 |
SQLBuilder sqlbuilder = new SQLBuilderBase(); |
|
528 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
529 |
|
|
530 |
sqlbuilder.grant().table().database("master").schema("dbo").name("test1"); |
|
531 |
sqlbuilder.grant().role("prueba").privilege(Privilege.SELECT) |
|
532 |
.privilege(Privilege.INSERT) |
|
533 |
.privilege(Privilege.UPDATE); |
|
534 |
sqlbuilder.grant().role("gis").privilege(Privilege.ALL); |
|
535 |
|
|
536 |
|
|
537 |
System.out.println("# Test:: testGrant2"); |
|
538 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
539 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
540 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
541 |
assertEquals( |
|
542 |
"", |
|
543 |
sqlbuilder.toString() |
|
544 |
); |
|
545 |
assertEquals( |
|
546 |
"[]", |
|
547 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
548 |
); |
|
549 |
assertEquals( |
|
550 |
"[]", |
|
551 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
552 |
); |
|
553 |
} |
|
554 |
|
|
555 |
|
|
556 |
} |
tags/org.gvsig.postgresql-2.0.192/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/TestWhereWithComputedField.java | ||
---|---|---|
1 |
package org.gvsig.postgresql.dal; |
|
2 |
|
|
3 |
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestUtils; |
|
4 |
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestWhereWithComputedField; |
|
5 |
|
|
6 |
public class TestWhereWithComputedField extends AbstractTestWhereWithComputedField { |
|
7 |
|
|
8 |
public TestWhereWithComputedField(String testName) { |
|
9 |
super(testName); |
|
10 |
} |
|
11 |
|
|
12 |
@Override |
|
13 |
protected AbstractTestUtils createUtils() { |
|
14 |
return new TestUtilsPostgreSQL(); |
|
15 |
} |
|
16 |
|
|
17 |
@Override |
|
18 |
public void testWhereWithComputedField() throws Exception { |
|
19 |
super.testWhereWithComputedField(); |
|
20 |
} |
|
21 |
|
|
22 |
} |
tags/org.gvsig.postgresql-2.0.192/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/TestUtils.java | ||
---|---|---|
1 |
package org.gvsig.postgresql.dal; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.net.URL; |
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.List; |
|
7 |
import org.apache.commons.io.FileUtils; |
|
8 |
import org.apache.commons.lang3.StringUtils; |
|
9 |
import org.gvsig.fmap.dal.DALLocator; |
|
10 |
import org.gvsig.fmap.dal.DataManager; |
|
11 |
import org.gvsig.fmap.dal.DataStore; |
|
12 |
import org.gvsig.fmap.dal.feature.Feature; |
|
13 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
14 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeature; |
|
15 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
|
16 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
|
17 |
import org.gvsig.fmap.dal.store.jdbc2.spi.FakeConnectionParameters; |
|
18 |
import org.gvsig.fmap.dal.store.jdbc2.spi.FakeConnectionProvider; |
|
19 |
import org.slf4j.Logger; |
|
20 |
import org.slf4j.LoggerFactory; |
|
21 |
|
|
22 |
public class TestUtils { |
|
23 |
|
|
24 |
public static final Logger LOGGER = LoggerFactory.getLogger(TestUtils.class); |
|
25 |
|
|
26 |
public static final String PROVIDER_NAME = PostgreSQLLibrary.NAME; |
|
27 |
|
|
28 |
public static File getTargetFolder() throws Exception { |
|
29 |
URL url = TestUtils.class.getResource("/"); |
|
30 |
File x = new File(url.toURI()); |
|
31 |
File target = x.getParentFile(); |
|
32 |
return target; |
|
33 |
} |
|
34 |
|
|
35 |
public static File getResource(String name) throws Exception { |
|
36 |
File x = new File(getTargetFolder(), name); |
|
37 |
return x; |
|
38 |
} |
|
39 |
|
|
40 |
public static File getResourceAsFile(String pathname) throws Exception { |
|
41 |
URL url = TestUtils.class.getResource(pathname); |
|
42 |
File x = new File(url.toURI()); |
|
43 |
return x; |
|
44 |
} |
|
45 |
|
|
46 |
public static FeatureStore openSourceStore1() throws Exception { |
|
47 |
DataManager dataManager = DALLocator.getDataManager(); |
|
48 |
File f = getResourceAsFile("/org/gvsig/postgresql/dal/testCreateSource1.csv"); |
|
49 |
FeatureStore store = (FeatureStore) dataManager.openStore( |
|
50 |
DataStore.CSV_PROVIDER_NAME, |
|
51 |
"file=",f, |
|
52 |
"automaticTypesDetection=", false, |
|
53 |
"locale=","en" |
|
54 |
); |
|
55 |
return store; |
|
56 |
} |
|
57 |
|
|
58 |
|
|
59 |
public static List<String> getSQLs(String name) throws Exception { |
|
60 |
File f = getResourceAsFile("/org/gvsig/postgresql/dal/"+name); |
|
61 |
List<String> SQLs = new ArrayList<>(); |
|
62 |
List<String> lines = FileUtils.readLines(f); |
|
63 |
StringBuilder sb = new StringBuilder(); |
|
64 |
for (String line : lines) { |
|
65 |
line = StringUtils.stripStart(line, null); |
|
66 |
if( line.startsWith("--") ) { |
|
67 |
continue; |
|
68 |
} |
|
69 |
if( line.endsWith(";") ) { |
|
70 |
sb.append(line.substring(0, line.length()-1)); |
|
71 |
SQLs.add(sb.toString()); |
|
72 |
sb.setLength(0); |
|
73 |
} else { |
|
74 |
sb.append(line); |
|
75 |
} |
|
76 |
} |
|
77 |
return SQLs; |
|
78 |
} |
|
79 |
|
|
80 |
public static JDBCHelper getJDBCHelper() { |
|
81 |
JDBCHelper helper = new PostgreSQLHelper(new FakePostgreSQLConnectionParameters(), new FakeConnectionProvider()); |
|
82 |
return helper; |
|
83 |
} |
|
84 |
|
|
85 |
public static FeatureProvider getFeatureProvider(Feature feature) { |
|
86 |
return ((DefaultFeature)feature).getData(); |
|
87 |
} |
|
88 |
} |
tags/org.gvsig.postgresql-2.0.192/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/usecases/arena2/TestMultipleExpansionOfCalculatedField.java | ||
---|---|---|
1 |
package org.gvsig.postgresql.dal.operations.usecases.arena2; |
|
2 |
|
|
3 |
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestUtils; |
|
4 |
import org.gvsig.fmap.dal.store.jdbc2.operations.usecases.arena2.AbstractTestMultipleExpansionOfCalculatedField; |
|
5 |
import org.gvsig.postgresql.dal.TestUtilsPostgreSQL; |
|
6 |
|
|
7 |
@SuppressWarnings("UseSpecificCatch") |
|
8 |
public class TestMultipleExpansionOfCalculatedField extends AbstractTestMultipleExpansionOfCalculatedField { |
|
9 |
|
|
10 |
public TestMultipleExpansionOfCalculatedField(String testName) { |
|
11 |
super(testName); |
|
12 |
} |
|
13 |
|
|
14 |
@Override |
|
15 |
protected AbstractTestUtils createUtils() { |
|
16 |
return new TestUtilsPostgreSQL(); |
|
17 |
} |
|
18 |
|
|
19 |
@Override |
|
20 |
public void testMultipleExpansionOfCalculatedField() throws Exception { |
|
21 |
super.testMultipleExpansionOfCalculatedField(); |
|
22 |
} |
|
23 |
|
|
24 |
} |
tags/org.gvsig.postgresql-2.0.192/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestDropTable.java | ||
---|---|---|
1 |
package org.gvsig.postgresql.dal.operations.sql; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import junit.framework.TestCase; |
|
5 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
6 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
|
7 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
|
8 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
|
9 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
|
10 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.DropTableOperation; |
|
11 |
import org.gvsig.postgresql.dal.TestUtils; |
|
12 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
13 |
import org.slf4j.Logger; |
|
14 |
import org.slf4j.LoggerFactory; |
|
15 |
|
|
16 |
public class TestDropTable extends TestCase { |
|
17 |
|
|
18 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestDropTable.class); |
|
19 |
|
|
20 |
public TestDropTable(String testName) { |
|
21 |
super(testName); |
|
22 |
} |
|
23 |
|
|
24 |
@Override |
|
25 |
protected void setUp() throws Exception { |
|
26 |
super.setUp(); |
|
27 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
28 |
} |
|
29 |
|
|
30 |
@Override |
|
31 |
protected void tearDown() throws Exception { |
|
32 |
super.tearDown(); |
|
33 |
} |
|
34 |
|
|
35 |
// TODO add test methods here. The name must begin with 'test'. For example: |
|
36 |
// public void testHello() {} |
|
37 |
|
|
38 |
public void testDropTable() throws Exception { |
|
39 |
JDBCHelper helper = TestUtils.getJDBCHelper(); |
|
40 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
41 |
OperationsFactory operations = helper.getOperations(); |
|
42 |
|
|
43 |
List<String> expectedSQLs = TestUtils.getSQLs("dropTable.sql"); |
|
44 |
|
|
45 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
46 |
|
|
47 |
TableReference table = operations.createTableReference( |
|
48 |
"dbtest", |
|
49 |
sqlbuilder.default_schema(), |
|
50 |
"test", |
|
51 |
null |
|
52 |
); |
|
53 |
DropTableOperation dropTable = operations.createDropTable( |
|
54 |
table |
|
55 |
); |
|
56 |
List<String> SQLs = dropTable.getSQLs(); |
|
57 |
assertEquals("DropTable num. SQLs", expectedSQLs.size(), SQLs.size()); |
|
58 |
for (int i = 0; i < expectedSQLs.size(); i++) { |
|
59 |
assertEquals("DropTable SQL "+i, expectedSQLs.get(i), SQLs.get(i)); |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
} |
tags/org.gvsig.postgresql-2.0.192/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestTableIsEmpty.java | ||
---|---|---|
1 |
package org.gvsig.postgresql.dal.operations.sql; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import junit.framework.TestCase; |
|
5 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
6 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
7 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
|
8 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
|
9 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
|
10 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
|
11 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.TableIsEmptyOperation; |
|
12 |
import org.gvsig.postgresql.dal.TestUtils; |
|
13 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
14 |
import org.slf4j.Logger; |
|
15 |
import org.slf4j.LoggerFactory; |
|
16 |
|
|
17 |
public class TestTableIsEmpty extends TestCase { |
|
18 |
|
|
19 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestTableIsEmpty.class); |
|
20 |
|
|
21 |
public TestTableIsEmpty(String testName) { |
|
22 |
super(testName); |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
protected void setUp() throws Exception { |
|
27 |
super.setUp(); |
|
28 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
protected void tearDown() throws Exception { |
|
33 |
super.tearDown(); |
|
34 |
} |
|
35 |
|
|
36 |
// TODO add test methods here. The name must begin with 'test'. For example: |
|
37 |
// public void testHello() {} |
|
38 |
|
|
39 |
public void testTableIsEmpty() throws Exception { |
|
40 |
JDBCHelper helper = TestUtils.getJDBCHelper(); |
|
41 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
42 |
OperationsFactory operations = helper.getOperations(); |
|
43 |
|
|
44 |
List<String> expectedSQLs = TestUtils.getSQLs("tableIsEmpty.sql"); |
|
45 |
|
|
46 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
47 |
|
|
48 |
TableReference table = operations.createTableReference( |
|
49 |
"dbtest", |
|
50 |
sqlbuilder.default_schema(), |
|
51 |
"test", |
|
52 |
null |
|
53 |
); |
|
54 |
FeatureType featureType = sourceStore.getDefaultFeatureType(); |
|
55 |
TableIsEmptyOperation tableIsEmpty = operations.createTableIsEmpty( |
|
56 |
featureType, |
|
57 |
table, |
|
58 |
null, |
|
59 |
null |
|
60 |
); |
|
61 |
|
|
62 |
String sql = tableIsEmpty.getSQL(); |
|
63 |
assertEquals("TableIsEmpty SQL", expectedSQLs.get(0), sql); |
|
64 |
} |
|
65 |
|
|
66 |
} |
tags/org.gvsig.postgresql-2.0.192/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestPerformChanges.java | ||
---|---|---|
1 |
package org.gvsig.postgresql.dal.operations.sql; |
|
2 |
|
|
3 |
import java.util.Collections; |
|
4 |
import java.util.List; |
|
5 |
import junit.framework.TestCase; |
|
6 |
import org.gvsig.fmap.dal.DALLocator; |
|
7 |
import org.gvsig.fmap.dal.DataTypes; |
|
8 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
|
9 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
10 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
11 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
12 |
import org.gvsig.fmap.dal.feature.FeatureType.FeatureTypeChanged; |
|
13 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
|
14 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
|
15 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
|
16 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
|
17 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.PerformChangesOperation; |
|
18 |
import org.gvsig.postgresql.dal.TestUtils; |
|
19 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
20 |
import org.slf4j.Logger; |
|
21 |
import org.slf4j.LoggerFactory; |
|
22 |
|
|
23 |
public class TestPerformChanges extends TestCase { |
|
24 |
|
|
25 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestPerformChanges.class); |
|
26 |
|
|
27 |
public TestPerformChanges(String testName) { |
|
28 |
super(testName); |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
protected void setUp() throws Exception { |
|
33 |
super.setUp(); |
|
34 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
35 |
} |
|
36 |
|
|
37 |
@Override |
|
38 |
protected void tearDown() throws Exception { |
|
39 |
super.tearDown(); |
|
40 |
} |
|
41 |
|
|
42 |
// TODO add test methods here. The name must begin with 'test'. For example: |
|
43 |
// public void testHello() {} |
|
44 |
|
|
45 |
public void testPerformChanges() throws Exception { |
|
46 |
JDBCHelper helper = TestUtils.getJDBCHelper(); |
|
47 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
48 |
OperationsFactory operations = helper.getOperations(); |
|
49 |
|
|
50 |
List<String> expectedSQLs = TestUtils.getSQLs("performChanges.sql"); |
|
51 |
|
|
52 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
53 |
|
|
54 |
TableReference table = operations.createTableReference( |
|
55 |
"dbtest", |
|
56 |
sqlbuilder.default_schema(), |
|
57 |
"test", |
|
58 |
null |
|
59 |
); |
|
60 |
FeatureType featureType = sourceStore.getDefaultFeatureType(); |
|
61 |
|
|
62 |
|
|
63 |
FeatureTypeChanged featureTypeChanged = new FeatureTypeChanged() { |
|
64 |
@Override |
|
65 |
public FeatureType getSource() { |
|
66 |
EditableFeatureType ft = DALLocator.getDataManager().createFeatureType(); |
|
67 |
EditableFeatureAttributeDescriptor id = ft.add("ID", DataTypes.INT); |
|
68 |
id.copyFrom(featureType.getAttributeDescriptor("ID")); |
|
69 |
return ft; |
|
70 |
} |
|
71 |
|
|
72 |
@Override |
|
73 |
public FeatureType getTarget() { |
|
74 |
return featureType; |
|
75 |
} |
|
76 |
}; |
|
77 |
List<FeatureTypeChanged> featureTypesChangeds = Collections.singletonList(featureTypeChanged); |
|
78 |
|
|
79 |
PerformChangesOperation performChanges = operations.createPerformChanges( |
|
80 |
table, |
|
81 |
sourceStore.getDefaultFeatureType(), |
|
82 |
null, |
|
83 |
null, |
|
84 |
null, |
|
85 |
featureTypesChangeds.iterator() |
|
86 |
); |
|
87 |
String insertSQL = performChanges.getInsertSQL(); |
|
88 |
String deleteSQL = performChanges.getDeleteSQL(); |
|
89 |
String updateSQL = performChanges.getUpdateSQL(); |
|
90 |
List<String> updateTableSQLs = performChanges.getUpdateTableSQLs(); |
|
91 |
|
|
92 |
assertEquals("Insert SQL", expectedSQLs.get(0), insertSQL); |
|
93 |
assertEquals("Delete SQL", expectedSQLs.get(1), deleteSQL); |
|
94 |
assertEquals("Update SQL", expectedSQLs.get(2), updateSQL); |
|
95 |
assertEquals("UpdateTable num. SQLs", expectedSQLs.size()-3, updateTableSQLs.size()); |
|
96 |
for (int i = 0; i < updateTableSQLs.size(); i++) { |
|
97 |
assertEquals("UpdateTable SQL "+i, expectedSQLs.get(i+3), updateTableSQLs.get(i)); |
|
98 |
} |
|
99 |
|
|
100 |
// FIXME: El ALTER TABLE de una columna geometria no funciona |
|
101 |
} |
|
102 |
|
|
103 |
} |
tags/org.gvsig.postgresql-2.0.192/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestUpdateTableStatistics.java | ||
---|---|---|
1 |
package org.gvsig.postgresql.dal.operations.sql; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import junit.framework.TestCase; |
|
5 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
6 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
7 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
|
8 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
|
9 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
|
10 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
|
11 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.UpdateTableStatisticsOperation; |
|
12 |
import org.gvsig.postgresql.dal.TestUtils; |
|
13 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
14 |
import org.slf4j.Logger; |
|
15 |
import org.slf4j.LoggerFactory; |
|
16 |
|
|
17 |
public class TestUpdateTableStatistics extends TestCase { |
|
18 |
|
|
19 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestUpdateTableStatistics.class); |
|
20 |
|
|
21 |
public TestUpdateTableStatistics(String testName) { |
|
22 |
super(testName); |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
protected void setUp() throws Exception { |
|
27 |
super.setUp(); |
|
28 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
protected void tearDown() throws Exception { |
|
33 |
super.tearDown(); |
|
34 |
} |
|
35 |
|
|
36 |
// TODO add test methods here. The name must begin with 'test'. For example: |
|
37 |
// public void testHello() {} |
|
38 |
|
|
39 |
public void testUpdateTableStatistics() throws Exception { |
|
40 |
JDBCHelper helper = TestUtils.getJDBCHelper(); |
|
41 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
42 |
OperationsFactory operations = helper.getOperations(); |
|
43 |
|
|
44 |
List<String> expectedSQLs = TestUtils.getSQLs("updateTableStatistics.sql"); |
|
45 |
|
|
46 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
47 |
|
|
48 |
TableReference table = operations.createTableReference( |
|
49 |
"dbtest", |
|
50 |
sqlbuilder.default_schema(), |
|
51 |
"test", |
|
52 |
null |
|
53 |
); |
|
54 |
FeatureType featureType = sourceStore.getDefaultFeatureType(); |
|
55 |
UpdateTableStatisticsOperation updateTableStatistics = operations.createUpdateTableStatistics( |
|
56 |
table |
|
57 |
); |
|
58 |
|
|
59 |
List<String> SQLs = updateTableStatistics.getSQLs(); |
|
60 |
assertEquals("UpdateTableStatistics num. SQLs", expectedSQLs.size(), SQLs.size()); |
|
61 |
for (int i = 0; i < expectedSQLs.size(); i++) { |
|
62 |
assertEquals("UpdateTableStatistics SQL "+i, expectedSQLs.get(i), SQLs.get(i)); |
|
63 |
} |
|
64 |
} |
|
65 |
|
|
66 |
} |
tags/org.gvsig.postgresql-2.0.192/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestJsonValue.java | ||
---|---|---|
1 |
package org.gvsig.postgresql.dal.operations.sql; |
|
2 |
|
|
3 |
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestJsonValue; |
|
4 |
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestUtils; |
|
5 |
import org.gvsig.postgresql.dal.TestUtilsPostgreSQL; |
|
6 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
7 |
import org.slf4j.Logger; |
|
8 |
import org.slf4j.LoggerFactory; |
|
9 |
|
|
10 |
public class TestJsonValue extends AbstractTestJsonValue { |
|
11 |
|
|
12 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestJsonValue.class); |
|
13 |
|
|
14 |
public TestJsonValue(String testName) { |
|
15 |
super(testName); |
|
16 |
} |
|
17 |
|
|
18 |
@Override |
|
19 |
protected void setUp() throws Exception { |
|
20 |
super.setUp(); |
|
21 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
22 |
} |
|
23 |
|
|
24 |
@Override |
|
25 |
protected void tearDown() throws Exception { |
|
26 |
super.tearDown(); |
|
27 |
} |
|
28 |
|
|
29 |
@Override |
|
30 |
protected AbstractTestUtils createUtils() { |
|
31 |
return new TestUtilsPostgreSQL(); |
|
32 |
} |
|
33 |
|
|
34 |
public void testJsonValue() throws Exception { |
|
35 |
super.testJsonValue(); |
|
36 |
} |
|
37 |
|
|
38 |
|
|
39 |
} |
tags/org.gvsig.postgresql-2.0.192/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestAppend.java | ||
---|---|---|
1 |
package org.gvsig.postgresql.dal.operations.sql; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
import junit.framework.TestCase; |
|
6 |
import org.gvsig.fmap.dal.DataTypes; |
|
7 |
import org.gvsig.fmap.dal.feature.Feature; |
|
8 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
9 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
10 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
11 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
|
12 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
|
13 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
|
14 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
|
15 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.AppendOperation; |
|
16 |
import org.gvsig.postgresql.dal.TestUtils; |
|
17 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
18 |
import org.slf4j.Logger; |
|
19 |
import org.slf4j.LoggerFactory; |
|
20 |
|
|
21 |
public class TestAppend extends TestCase { |
|
22 |
|
|
23 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestAppend.class); |
|
24 |
|
|
25 |
public TestAppend(String testName) { |
|
26 |
super(testName); |
|
27 |
} |
|
28 |
|
|
29 |
@Override |
|
30 |
protected void setUp() throws Exception { |
|
31 |
super.setUp(); |
|
32 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
33 |
} |
|
34 |
|
|
35 |
@Override |
|
36 |
protected void tearDown() throws Exception { |
|
37 |
super.tearDown(); |
|
38 |
} |
|
39 |
|
|
40 |
// TODO add test methods here. The name must begin with 'test'. For example: |
|
41 |
// public void testHello() {} |
|
42 |
|
|
43 |
public void testAppend() throws Exception { |
|
44 |
JDBCHelper helper = TestUtils.getJDBCHelper(); |
|
45 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
46 |
OperationsFactory operations = helper.getOperations(); |
|
47 |
|
|
48 |
List<String> expectedSQLs = TestUtils.getSQLs("append.sql"); |
|
49 |
|
|
50 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
51 |
|
|
52 |
TableReference table = operations.createTableReference( |
|
53 |
"dbtest", |
|
54 |
sqlbuilder.default_schema(), |
|
55 |
"test", |
|
56 |
null |
|
57 |
); |
|
58 |
FeatureType featureType = sourceStore.getDefaultFeatureType(); |
|
59 |
AppendOperation append = operations.createAppend( |
|
60 |
table, |
|
61 |
featureType |
|
62 |
); |
|
63 |
append.begin(); |
|
64 |
List<String> SQLs = new ArrayList<>(); |
|
65 |
SQLs.addAll(append.getPreviousSQLs()); |
|
66 |
SQLs.add( append.getSQL()); |
|
67 |
SQLs.addAll(append.getPostSQLs()); |
|
68 |
assertEquals("Append num SQLs", expectedSQLs.size(), SQLs.size()); |
Also available in: Unified diff