Revision 46102
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/test/resources/org/gvsig/fmap/dal/store/h2/count.sql | ||
---|---|---|
1 |
|
|
2 |
-- Count SQL |
|
3 |
SELECT COUNT(*) FROM "PUBLIC"."test"; |
|
4 |
|
|
5 |
-- Count with group SQL |
|
6 |
SELECT COUNT(*) |
|
7 |
FROM ( |
|
8 |
SELECT COUNT(*) |
|
9 |
FROM "PUBLIC"."test" |
|
10 |
GROUP BY "Long" |
|
11 |
ORDER BY "Long" ASC |
|
12 |
) as _subquery_alias_ ; |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/test/resources/org/gvsig/fmap/dal/store/h2/performChanges.sql | ||
---|---|---|
50 | 50 |
ALTER TABLE "PUBLIC"."test" ADD COLUMN "Decimal" DECIMAL(6,3) DEFAULT NULL NULL; |
51 | 51 |
ALTER TABLE "PUBLIC"."test" ADD COLUMN "Geometry" GEOMETRY(1) DEFAULT NULL NULL; |
52 | 52 |
ALTER TABLE "PUBLIC"."test" ADD CONSTRAINT |
53 |
IF NOT EXISTS "constraint_test_Geometry_geom"
|
|
53 |
IF NOT EXISTS "test_GEOM_Geometry"
|
|
54 | 54 |
CHECK NVL2( |
55 | 55 |
"Geometry", |
56 | 56 |
ST_GeometryTypeCode("Geometry") = 1 AND |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/test/resources/org/gvsig/fmap/dal/store/h2/performChangesUpdateStructure.txt | ||
---|---|---|
1 |
|
|
2 |
|
|
3 |
-- begin PerformChangesAddPk |
|
4 |
ALTER TABLE "PUBLIC"."test" ALTER COLUMN "ID" INTEGER NOT NULL |
|
5 |
-- end PerformChangesAddPk |
|
6 |
|
|
7 |
-- begin PerformChangesAddPk |
|
8 |
ALTER TABLE "PUBLIC"."test" ADD CONSTRAINT "test_PK_ID" PRIMARY KEY ( "ID" ) INDEX "test_IDX_ID" |
|
9 |
-- end PerformChangesAddPk |
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
-- begin changePk1 |
|
14 |
ALTER TABLE "PUBLIC"."test" ALTER COLUMN "ID" INTEGER NOT NULL |
|
15 |
-- end changePk1 |
|
16 |
|
|
17 |
-- begin changePk1 |
|
18 |
ALTER TABLE "PUBLIC"."test" ADD CONSTRAINT "test_PK_ID" PRIMARY KEY ( "ID" ) INDEX "test_IDX_ID" |
|
19 |
-- end changePk1 |
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
-- begin changePk2 |
|
24 |
ALTER TABLE "PUBLIC"."test" DROP CONSTRAINT IF EXISTS "test_PK_ID" |
|
25 |
-- end changePk2 |
|
26 |
|
|
27 |
-- begin changePk2 |
|
28 |
DROP INDEX IF EXISTS "test_IDX_ID" |
|
29 |
-- end changePk2 |
|
30 |
|
|
31 |
-- begin changePk2 |
|
32 |
ALTER TABLE "PUBLIC"."test" ALTER COLUMN "ID" INTEGER DEFAULT NULL NULL |
|
33 |
-- end changePk2 |
|
34 |
|
|
35 |
-- begin changePk2 |
|
36 |
ALTER TABLE "PUBLIC"."test" ALTER COLUMN "NAME" VARCHAR(50) NOT NULL |
|
37 |
-- end changePk2 |
|
38 |
|
|
39 |
-- begin changePk2 |
|
40 |
ALTER TABLE "PUBLIC"."test" ADD CONSTRAINT "test_PK_NAME" PRIMARY KEY ( "NAME" ) INDEX "test_IDX_NAME" |
|
41 |
-- end changePk2 |
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
-- begin changePk3 |
|
46 |
ALTER TABLE "PUBLIC"."test" DROP CONSTRAINT IF EXISTS "test_PK_ID" |
|
47 |
-- end changePk3 |
|
48 |
|
|
49 |
-- begin changePk3 |
|
50 |
DROP INDEX IF EXISTS "test_IDX_ID" |
|
51 |
-- end changePk3 |
|
52 |
|
|
53 |
-- begin changePk3 |
|
54 |
ALTER TABLE "PUBLIC"."test" ALTER COLUMN "ID" INTEGER DEFAULT NULL NULL |
|
55 |
-- end changePk3 |
|
56 |
|
|
57 |
-- begin changePk3 |
|
58 |
CREATE INDEX IF NOT EXISTS "test_IDX_ID" ON "PUBLIC"."test" ( "ID" ) |
|
59 |
-- end changePk3 |
|
60 |
|
|
61 |
-- begin changePk3 |
|
62 |
CREATE INDEX IF NOT EXISTS "test_IDX_NAME" ON "PUBLIC"."test" ( "NAME" ) |
|
63 |
-- end changePk3 |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/test/resources/org/gvsig/fmap/dal/store/h2/count.txt | ||
---|---|---|
1 |
|
|
2 |
-- begin count |
|
3 |
SELECT COUNT(*) FROM "PUBLIC"."test" |
|
4 |
-- end count |
|
5 |
|
|
6 |
-- begin SimpleGroup |
|
7 |
-- rem Count with group SQL |
|
8 |
SELECT COUNT(*) |
|
9 |
FROM ( |
|
10 |
SELECT COUNT(*) |
|
11 |
FROM "PUBLIC"."test" |
|
12 |
GROUP BY "Long" |
|
13 |
ORDER BY "Long" ASC |
|
14 |
) as _subquery_alias_ |
|
15 |
-- end SimpleGroup |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/test/java/org/gvsig/fmap/dal/store/h2/operations/sql/PerformChangesUpdateStructure.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.store.h2.operations.sql; |
|
2 |
|
|
3 |
import org.gvsig.fmap.dal.store.h2.TestUtilsH2Spatial; |
|
4 |
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestUtils; |
|
5 |
import org.gvsig.fmap.dal.store.jdbc2.operations.sql.AbstractTestPerformChangesUpdateStructure; |
|
6 |
|
|
7 |
public class PerformChangesUpdateStructure extends AbstractTestPerformChangesUpdateStructure { |
|
8 |
|
|
9 |
public PerformChangesUpdateStructure(String testName) { |
|
10 |
super(testName); |
|
11 |
} |
|
12 |
|
|
13 |
@Override |
|
14 |
protected AbstractTestUtils createUtils() { |
|
15 |
return new TestUtilsH2Spatial(); |
|
16 |
} |
|
17 |
|
|
18 |
@Override |
|
19 |
public void testPerformChangesAddPk() throws Exception { |
|
20 |
super.testPerformChangesAddPk(); |
|
21 |
} |
|
22 |
|
|
23 |
public void testChangePk1() throws Exception { |
|
24 |
super.testChangePk1(); |
|
25 |
} |
|
26 |
|
|
27 |
public void testChangePk2() throws Exception { |
|
28 |
super.testChangePk2(); |
|
29 |
} |
|
30 |
|
|
31 |
public void testChangePk3() throws Exception { |
|
32 |
super.testChangePk3(); |
|
33 |
} |
|
34 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/test/java/org/gvsig/fmap/dal/store/h2/operations/sql/TestCount.java | ||
---|---|---|
1 | 1 |
package org.gvsig.fmap.dal.store.h2.operations.sql; |
2 | 2 |
|
3 |
import java.util.List; |
|
4 |
import junit.framework.TestCase; |
|
5 |
import static junit.framework.TestCase.assertEquals; |
|
6 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
7 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
8 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
9 |
import org.gvsig.fmap.dal.store.h2.TestUtils; |
|
10 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
|
11 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
|
12 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
|
13 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
|
14 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.CountOperation; |
|
15 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.ResultSetForSetProviderOperation; |
|
16 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
17 |
import org.slf4j.Logger; |
|
18 |
import org.slf4j.LoggerFactory; |
|
3 |
import org.gvsig.fmap.dal.store.h2.TestUtilsH2Spatial; |
|
4 |
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestUtils; |
|
5 |
import org.gvsig.fmap.dal.store.jdbc2.operations.sql.AbstractTestCount; |
|
19 | 6 |
|
20 |
public class TestCount extends TestCase {
|
|
7 |
public class TestCount extends AbstractTestCount {
|
|
21 | 8 |
|
22 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestCount.class); |
|
9 |
public TestCount(String testName) { |
|
10 |
super(testName); |
|
11 |
} |
|
23 | 12 |
|
24 |
public TestCount(String testName) { |
|
25 |
super(testName); |
|
26 |
} |
|
13 |
@Override |
|
14 |
protected AbstractTestUtils createUtils() { |
|
15 |
return new TestUtilsH2Spatial(); |
|
16 |
} |
|
27 | 17 |
|
28 |
@Override |
|
29 |
protected void setUp() throws Exception { |
|
30 |
super.setUp(); |
|
31 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
32 |
} |
|
18 |
@Override |
|
19 |
public void testCount() throws Exception { |
|
20 |
super.testCount(); |
|
21 |
} |
|
33 | 22 |
|
34 |
@Override |
|
35 |
protected void tearDown() throws Exception { |
|
36 |
super.tearDown(); |
|
37 |
} |
|
38 |
|
|
39 |
public void testCount() throws Exception { |
|
40 |
JDBCHelper helper = TestUtils.createJDBCHelper(); |
|
41 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
42 |
OperationsFactory operations = helper.getOperations(); |
|
23 |
@Override |
|
24 |
public void testSimpleGroup() throws Exception { |
|
25 |
super.testSimpleGroup(); |
|
26 |
} |
|
43 | 27 |
|
44 |
List<String> expectedSQLs = TestUtils.getSQLs("count.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 |
CountOperation count = operations.createCount( |
|
56 |
featureType, |
|
57 |
table, |
|
58 |
null, |
|
59 |
null |
|
60 |
); |
|
61 |
|
|
62 |
String sql = count.getSQL(); |
|
63 |
assertEquals("Count SQL", expectedSQLs.get(0), sql); |
|
64 |
} |
|
65 |
|
|
66 |
public void testSimpleGroup() throws Exception { |
|
67 |
JDBCHelper helper = TestUtils.createJDBCHelper(); |
|
68 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
69 |
OperationsFactory operations = helper.getOperations(); |
|
70 |
|
|
71 |
List<String> expectedSQLs = TestUtils.getSQLs("count.sql"); |
|
72 |
|
|
73 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
74 |
|
|
75 |
TableReference table = operations.createTableReference( |
|
76 |
"dbtest", |
|
77 |
sqlbuilder.default_schema(), |
|
78 |
"test", |
|
79 |
null |
|
80 |
); |
|
81 |
FeatureType featureType = sourceStore.getDefaultFeatureType(); |
|
82 |
FeatureQuery query = sourceStore.createFeatureQuery(); |
|
83 |
query.getGroupByColumns().add("Long"); |
|
84 |
query.getAggregateFunctions().put("ID", "MIN"); |
|
85 |
query.getAggregateFunctions().put("Byte", "MAX"); |
|
86 |
query.getAggregateFunctions().put("Double", "SUM"); |
|
87 |
query.getOrder().add("Long"); |
|
88 |
CountOperation count = operations.createCount( |
|
89 |
featureType, |
|
90 |
table, |
|
91 |
null, |
|
92 |
query |
|
93 |
); |
|
94 |
String sql = count.getSQL(); |
|
95 |
System.out.println("###### SQL:"+sql); |
|
96 |
System.out.println("###### EXP:"+expectedSQLs.get(1)); |
|
97 |
|
|
98 |
assertEquals("Count with group SQL", expectedSQLs.get(1), sql); |
|
99 |
} |
|
100 |
|
|
101 |
// TODO: a?adir un test con where, group y order. |
|
102 | 28 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/test/java/org/gvsig/fmap/dal/store/h2/operations/sql/TestPerformChanges.java | ||
---|---|---|
89 | 89 |
String updateSQL = performChanges.getUpdateSQL(); |
90 | 90 |
List<String> updateTableSQLs = performChanges.getUpdateTableSQLs(); |
91 | 91 |
|
92 |
System.out.println("###### EXP[insert]:" + expectedSQLs.get(0) + "###"); |
|
93 |
System.out.println("###### SQL[insert]:" + insertSQL + "###"); |
|
94 |
System.out.println("###### EXP[delete]:" + expectedSQLs.get(1) + "###"); |
|
95 |
System.out.println("###### SQL[delete]:" + deleteSQL + "###"); |
|
96 |
System.out.println("###### EXP[update]:" + expectedSQLs.get(2) + "###"); |
|
97 |
System.out.println("###### SQL[update]:" + updateSQL + "###"); |
|
98 |
|
|
99 |
for (int i = 0; i < updateTableSQLs.size(); i++) { |
|
100 |
System.out.println("###### EXP[updatetable "+i+"]:" + expectedSQLs.get(i+3) + "###"); |
|
101 |
System.out.println("###### SQL[updatetable "+i+"]:" + updateTableSQLs.get(i) + "###"); |
|
102 |
} |
|
103 |
|
|
92 | 104 |
assertEquals("Insert SQL", expectedSQLs.get(0), insertSQL); |
93 | 105 |
assertEquals("Delete SQL", expectedSQLs.get(1), deleteSQL); |
94 | 106 |
assertEquals("Update SQL", expectedSQLs.get(2), updateSQL); |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/test/java/org/gvsig/fmap/dal/store/h2/TestComputedAttributes.java | ||
---|---|---|
1 | 1 |
package org.gvsig.fmap.dal.store.h2; |
2 | 2 |
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Date; |
|
5 |
import java.util.List; |
|
6 |
import junit.framework.TestCase; |
|
7 |
import static junit.framework.TestCase.assertEquals; |
|
8 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
9 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
|
10 |
import org.gvsig.fmap.dal.DALLocator; |
|
11 |
import org.gvsig.fmap.dal.DataTypes; |
|
12 |
import org.gvsig.fmap.dal.DataManager; |
|
13 |
import org.gvsig.fmap.dal.DataStore; |
|
14 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
15 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
16 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
|
17 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
18 |
import org.gvsig.fmap.dal.feature.Feature; |
|
19 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
20 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
21 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
22 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
23 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
24 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureAttributeEmulatorExpression; |
|
25 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
|
26 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
|
27 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
28 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
29 |
import org.slf4j.Logger; |
|
30 |
import org.slf4j.LoggerFactory; |
|
3 |
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestComputedAttributes; |
|
4 |
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestUtils; |
|
31 | 5 |
|
32 |
public class TestComputedAttributes extends TestCase { |
|
33 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestComputedAttributes.class); |
|
6 |
public class TestComputedAttributes extends AbstractTestComputedAttributes { |
|
34 | 7 |
|
35 |
public static final String DBNAME = "testCreate"; |
|
36 |
|
|
37 | 8 |
public TestComputedAttributes(String testName) { |
38 | 9 |
super(testName); |
39 | 10 |
} |
40 |
|
|
11 |
|
|
41 | 12 |
@Override |
42 |
protected void setUp() throws Exception { |
|
43 |
super.setUp(); |
|
44 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
13 |
protected AbstractTestUtils createUtils() { |
|
14 |
return new TestUtilsH2Spatial(); |
|
45 | 15 |
} |
46 |
|
|
47 |
@Override |
|
48 |
protected void tearDown() throws Exception { |
|
49 |
super.tearDown(); |
|
50 |
} |
|
51 | 16 |
|
52 |
// TODO add test methods here. The name must begin with 'test'. For example: |
|
53 |
// public void testHello() {} |
|
54 |
|
|
55 |
protected String getProviderName() { |
|
56 |
return DataStore.H2SPATIAL_PROVIDER_NAME; |
|
57 |
} |
|
58 |
|
|
59 |
protected String getTargetName() { |
|
60 |
return "testCreateTarget2"; |
|
61 |
} |
|
62 |
|
|
63 |
protected FeatureStore openTargetStore1(JDBCServerExplorer explorer) throws Exception { |
|
64 |
JDBCStoreParameters params = explorer.get(getTargetName()); |
|
65 |
|
|
66 |
DataManager dataManager = DALLocator.getDataManager(); |
|
67 |
FeatureStore store; |
|
68 |
try { |
|
69 |
store = (FeatureStore) dataManager.openStore( |
|
70 |
getProviderName(), |
|
71 |
params |
|
72 |
); |
|
73 |
} catch(ValidateDataParametersException ex) { |
|
74 |
LOGGER.warn(ex.getLocalizedMessageStack()); |
|
75 |
throw ex; |
|
76 |
} |
|
77 |
return store; |
|
78 |
} |
|
79 |
|
|
80 |
protected void createFrom(JDBCServerExplorer explorer, FeatureStore sourceStore) throws Exception { |
|
81 |
NewFeatureStoreParameters params = (NewFeatureStoreParameters) explorer.getAddParameters( |
|
82 |
getTargetName() |
|
83 |
); |
|
84 |
EditableFeatureType ft = params.getDefaultFeatureType(); |
|
85 |
ft.addAll(sourceStore.getDefaultFeatureType()); |
|
86 |
explorer.add(getProviderName(), params, true); |
|
87 |
} |
|
88 |
|
|
89 |
protected void checkTypes(JDBCServerExplorer explorer, FeatureType sourceFeatureType) throws Exception { |
|
90 |
// DataType STRING_TYPE = ToolsLocator.getDataTypesManager().get(DataTypes.STRING); |
|
91 |
// DataType INT_TYPE = ToolsLocator.getDataTypesManager().get(DataTypes.INT); |
|
92 |
|
|
93 |
FeatureStore targetStore = openTargetStore1(explorer); |
|
94 |
FeatureType targetFeatureType = targetStore.getDefaultFeatureType(); |
|
95 |
|
|
96 |
assertEquals("Feature type size",sourceFeatureType.size(), targetFeatureType.size()); |
|
97 |
for (int i = 0; i < sourceFeatureType.size(); i++) { |
|
98 |
FeatureAttributeDescriptor sourceAttr = sourceFeatureType.get(i); |
|
99 |
FeatureAttributeDescriptor targetAttr = targetFeatureType.get(i); |
|
100 |
switch(sourceAttr.getType()) { |
|
101 |
case DataTypes.BYTE: |
|
102 |
case DataTypes.INT: |
|
103 |
case DataTypes.LONG: |
|
104 |
case DataTypes.BOOLEAN: |
|
105 |
case DataTypes.DATE: |
|
106 |
case DataTypes.STRING: |
|
107 |
case DataTypes.TIME: |
|
108 |
case DataTypes.TIMESTAMP: |
|
109 |
case DataTypes.DOUBLE: |
|
110 |
case DataTypes.FLOAT: |
|
111 |
case DataTypes.DECIMAL: |
|
112 |
assertEquals( |
|
113 |
String.format("Field %s name mismatch", sourceAttr.getName()), |
|
114 |
sourceAttr.getName(), |
|
115 |
targetAttr.getName() |
|
116 |
); |
|
117 |
assertEquals( |
|
118 |
String.format("Field %s type mismatch", sourceAttr.getName()), |
|
119 |
sourceAttr.getDataTypeName(), |
|
120 |
targetAttr.getDataTypeName() |
|
121 |
); |
|
122 |
assertEquals( |
|
123 |
String.format("Field %s size mismatch", sourceAttr.getName()), |
|
124 |
sourceAttr.getSize(), |
|
125 |
targetAttr.getSize() |
|
126 |
); |
|
127 |
assertEquals( |
|
128 |
String.format("Field %s precision mismatch", sourceAttr.getName()), |
|
129 |
sourceAttr.getPrecision(), |
|
130 |
targetAttr.getPrecision() |
|
131 |
); |
|
132 |
assertEquals( |
|
133 |
String.format("Field %s scale mismatch", sourceAttr.getName()), |
|
134 |
sourceAttr.getScale(), |
|
135 |
targetAttr.getScale() |
|
136 |
); |
|
137 |
break; |
|
138 |
case DataTypes.GEOMETRY: |
|
139 |
assertEquals( |
|
140 |
String.format("Field %s name mismatch", sourceAttr.getName()), |
|
141 |
sourceAttr.getName(), |
|
142 |
targetAttr.getName() |
|
143 |
); |
|
144 |
assertEquals( |
|
145 |
String.format("Field %s type mismatch", sourceAttr.getName()), |
|
146 |
sourceAttr.getDataTypeName(), |
|
147 |
targetAttr.getDataTypeName() |
|
148 |
); |
|
149 |
assertEquals( |
|
150 |
String.format("Field %s geometry type mismatch", sourceAttr.getName()), |
|
151 |
sourceAttr.getGeomType().getName(), |
|
152 |
targetAttr.getGeomType().getName() |
|
153 |
); |
|
154 |
assertEquals( |
|
155 |
String.format("Field %s geometry SRS mismatch", sourceAttr.getName()), |
|
156 |
sourceAttr.getSRS().toString(), |
|
157 |
targetAttr.getSRS().toString() |
|
158 |
); |
|
159 |
assertEquals( |
|
160 |
String.format("Field %s size mismatch", sourceAttr.getName()), |
|
161 |
sourceAttr.getSize(), |
|
162 |
targetAttr.getSize() |
|
163 |
); |
|
164 |
assertEquals( |
|
165 |
String.format("Field %s precision mismatch", sourceAttr.getName()), |
|
166 |
sourceAttr.getPrecision(), |
|
167 |
targetAttr.getPrecision() |
|
168 |
); |
|
169 |
break; |
|
170 |
default: |
|
171 |
fail( |
|
172 |
String.format("Field %s type %d (%s) not supported.", |
|
173 |
targetAttr.getName(), |
|
174 |
targetAttr.getType(), |
|
175 |
targetAttr.getDataTypeName() |
|
176 |
) |
|
177 |
); |
|
178 |
} |
|
179 |
} |
|
180 |
} |
|
181 |
|
|
182 |
protected void copyFrom(JDBCServerExplorer explorer, FeatureStore sourceStore, int mode) throws Exception { |
|
183 |
FeatureStore targetStore = openTargetStore1(explorer); |
|
184 |
targetStore.edit(mode); |
|
185 |
try { |
|
186 |
for (Feature sourceFeature : sourceStore.getFeatureSet()) { |
|
187 |
EditableFeature targetFeature = targetStore.createNewFeature(sourceFeature); |
|
188 |
targetStore.insert(targetFeature); |
|
189 |
} |
|
190 |
} finally { |
|
191 |
targetStore.finishEditing(); |
|
192 |
} |
|
193 |
} |
|
194 |
|
|
195 |
protected void checkData(JDBCServerExplorer explorer, FeatureStore sourceStore) throws Exception { |
|
196 |
FeatureStore targetStore = openTargetStore1(explorer); |
|
197 |
|
|
198 |
List<Feature> sourceFeatures = sourceStore.getFeatures(); |
|
199 |
List<Feature> targetFeatures = targetStore.getFeatures(); |
|
200 |
assertEquals("Count features", sourceFeatures.size(), targetFeatures.size()); |
|
201 |
for (int i = 0; i < targetFeatures.size(); i++) { |
|
202 |
Feature sourceFeature = sourceFeatures.get(i); |
|
203 |
Feature targetFeature = targetFeatures.get(i); |
|
204 |
for (FeatureAttributeDescriptor sourceAttr : sourceStore.getDefaultFeatureType()) { |
|
205 |
switch(sourceAttr.getType()) { |
|
206 |
case DataTypes.BYTE: |
|
207 |
assertEquals( |
|
208 |
String.format("Feature %03d attribute %s", i, sourceAttr.getName()), |
|
209 |
sourceFeature.getInt(sourceAttr.getName()), |
|
210 |
targetFeature.getInt(sourceAttr.getName()) |
|
211 |
); |
|
212 |
break; |
|
213 |
case DataTypes.TIMESTAMP: |
|
214 |
Date sourceTimestamp = sourceFeature.getDate(sourceAttr.getName()); |
|
215 |
Date targetTimestamp = targetFeature.getDate(sourceAttr.getName()); |
|
216 |
assertEquals( |
|
217 |
String.format("Feature %03d attribute %s", i, sourceAttr.getName()), |
|
218 |
sourceTimestamp, |
|
219 |
targetTimestamp |
|
220 |
); |
|
221 |
break; |
|
222 |
case DataTypes.TIME: |
|
223 |
assertEquals( |
|
224 |
String.format("Feature %03d attribute %s", i, sourceAttr.getName()), |
|
225 |
sourceFeature.getDate(sourceAttr.getName()), |
|
226 |
targetFeature.getDate(sourceAttr.getName()) |
|
227 |
); |
|
228 |
break; |
|
229 |
case DataTypes.GEOMETRY: |
|
230 |
assertEquals( |
|
231 |
String.format("Feature %03d attribute %s", i, sourceAttr.getName()), |
|
232 |
sourceFeature.get(sourceAttr.getName()), |
|
233 |
targetFeature.get(sourceAttr.getName()) |
|
234 |
); |
|
235 |
break; |
|
236 |
case DataTypes.STRING: |
|
237 |
case DataTypes.INT: |
|
238 |
case DataTypes.LONG: |
|
239 |
case DataTypes.FLOAT: |
|
240 |
case DataTypes.DOUBLE: |
|
241 |
default: |
|
242 |
Object sourceValue = sourceFeature.get(sourceAttr.getName()); |
|
243 |
Object targetValue = targetFeature.get(sourceAttr.getName()); |
|
244 |
if( sourceValue == null ) { |
|
245 |
LOGGER.info(String.format("Feature %03d attribute %s is null", i, sourceAttr.getName())); |
|
246 |
} |
|
247 |
assertEquals( |
|
248 |
String.format("Feature %03d attribute %s", i, sourceAttr.getName()), |
|
249 |
sourceValue, |
|
250 |
targetValue |
|
251 |
); |
|
252 |
} |
|
253 |
} |
|
254 |
} |
|
255 |
} |
|
256 |
|
|
257 |
|
|
17 |
@Override |
|
258 | 18 |
public void testComputed1() throws Exception { |
259 |
FeatureStore sourceStore = TestUtils.openSourceStore2(); |
|
260 |
JDBCServerExplorer explorer = TestUtils.openServerExplorer(DBNAME); |
|
261 |
|
|
262 |
createFrom(explorer, sourceStore); |
|
263 |
copyFrom(explorer, sourceStore, FeatureStore.MODE_APPEND); |
|
264 |
|
|
265 |
FeatureStore h2Store = openTargetStore1(explorer); |
|
266 |
h2Store.edit(); |
|
267 |
FeatureType featureType = h2Store.getDefaultFeatureType(); |
|
268 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
|
269 |
eFeatureType.add("Compu1", |
|
270 |
DataTypes.INTEGER, |
|
271 |
new DefaultFeatureAttributeEmulatorExpression( |
|
272 |
eFeatureType, |
|
273 |
ExpressionUtils.createExpression("ID*2") |
|
274 |
)); |
|
275 |
eFeatureType.add("Compu2", |
|
276 |
DataTypes.INTEGER, |
|
277 |
new DefaultFeatureAttributeEmulatorExpression( |
|
278 |
eFeatureType, |
|
279 |
ExpressionUtils.createExpression("Poblacion+10000+Compu1") |
|
280 |
)); |
|
281 |
h2Store.update(eFeatureType); |
|
282 |
h2Store.finishEditing(); |
|
283 |
List<Feature> features = h2Store.getFeatures(); |
|
284 |
for (int i = 0; i < features.size(); i++) { |
|
285 |
Feature feature = features.get(i); |
|
286 |
assertEquals("Compu1 "+i, feature.getInt("ID") * 2, feature.getInt("Compu1")); |
|
287 |
if(feature.get("Poblacion")==null) { |
|
288 |
assertEquals("Compu2 "+i, null, feature.get("Compu2")); |
|
289 |
} else { |
|
290 |
assertEquals("Compu2 "+i, feature.getInt("Poblacion") + 10000 + feature.getInt("Compu1"), feature.getInt("Compu2")); |
|
291 |
} |
|
292 |
} |
|
293 |
DisposeUtils.dispose(h2Store); |
|
19 |
super.testComputed1(); |
|
294 | 20 |
} |
295 |
|
|
296 |
public void testComputed2() throws Exception { |
|
297 |
FeatureStore sourceStore = TestUtils.openSourceStore2(); |
|
298 |
JDBCServerExplorer explorer = TestUtils.openServerExplorer(DBNAME); |
|
299 |
|
|
300 |
createFrom(explorer, sourceStore); |
|
301 |
copyFrom(explorer, sourceStore, FeatureStore.MODE_APPEND); |
|
302 |
|
|
303 |
FeatureStore h2Store = openTargetStore1(explorer); |
|
304 |
h2Store.edit(); |
|
305 |
FeatureType featureType = h2Store.getDefaultFeatureType(); |
|
306 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
|
307 |
FeatureQuery query = sourceStore.createFeatureQuery(); |
|
308 |
eFeatureType.add("CompuID", |
|
309 |
DataTypes.INTEGER, |
|
310 |
new DefaultFeatureAttributeEmulatorExpression( |
|
311 |
eFeatureType, |
|
312 |
ExpressionUtils.createExpression("MOD(ID,10)") |
|
313 |
)); |
|
314 |
eFeatureType.add("CompuPob", |
|
315 |
DataTypes.INTEGER, |
|
316 |
new DefaultFeatureAttributeEmulatorExpression( |
|
317 |
eFeatureType, |
|
318 |
ExpressionUtils.createExpression("Poblacion+1") |
|
319 |
)); |
|
320 |
eFeatureType.add("CompuProv", |
|
321 |
DataTypes.STRING, |
|
322 |
new DefaultFeatureAttributeEmulatorExpression( |
|
323 |
eFeatureType, |
|
324 |
ExpressionUtils.createExpression("UPPER(Provincia)") |
|
325 |
)); |
|
326 |
EditableFeatureAttributeDescriptor extraColumn1 = |
|
327 |
query.getExtraColumn().add("ExtraID900", DataTypes.INTEGER); |
|
328 |
EditableFeatureAttributeDescriptor extraColumn2 = |
|
329 |
query.getExtraColumn().add("ExtraPobDen", DataTypes.INTEGER); |
|
330 |
EditableFeatureAttributeDescriptor extraColumn3 = |
|
331 |
query.getExtraColumn().add("ExtraAno", DataTypes.INTEGER); |
|
332 | 21 |
|
333 |
extraColumn1.setFeatureAttributeEmulator( |
|
334 |
new DefaultFeatureAttributeEmulatorExpression( |
|
335 |
eFeatureType, |
|
336 |
ExpressionUtils.createExpression("CompuID+900"))); |
|
337 |
extraColumn2.setFeatureAttributeEmulator( |
|
338 |
new DefaultFeatureAttributeEmulatorExpression( |
|
339 |
eFeatureType, |
|
340 |
ExpressionUtils.createExpression("CompuPob+Densidad"))); |
|
341 |
extraColumn3.setFeatureAttributeEmulator( |
|
342 |
new DefaultFeatureAttributeEmulatorExpression( |
|
343 |
eFeatureType, |
|
344 |
ExpressionUtils.createExpression("EXTRACT(YEAR FROM Fecha)"))); |
|
345 |
|
|
346 |
query.getGroupByColumns().add("Comunidad"); |
|
347 |
query.getGroupByColumns().add("CompuProv"); |
|
348 |
query.getGroupByColumns().add("ExtraAno"); |
|
349 |
query.getAggregateFunctions().put("ID", "MIN"); |
|
350 |
query.getAggregateFunctions().put("Poblacion", "MIN"); |
|
351 |
query.getAggregateFunctions().put("CompuID", "MIN"); |
|
352 |
query.getAggregateFunctions().put("CompuPob", "SUM"); |
|
353 |
query.getAggregateFunctions().put("ExtraID900", "SUM"); |
|
354 |
query.getAggregateFunctions().put("ExtraPobDen", "SUM"); |
|
355 |
h2Store.update(eFeatureType); |
|
356 |
h2Store.finishEditing(); |
|
357 |
|
|
358 |
|
|
359 |
List<Feature> features0 = h2Store.getFeatures(query); |
|
360 |
ArrayList<Feature> features = new ArrayList<>(); |
|
361 |
|
|
362 |
System.out.println("ID,Comunidad,Provincia,Ciudad,Poblacion,Densidad,Fecha,CompuID,CompuPob,CompuProv,ExtraID900,ExtraPobDen,ExtraAno"); |
|
363 |
for (int i = 0; i < features0.size(); i++) { |
|
364 |
Feature feature = features0.get(i); |
|
365 |
features.add(feature.getCopy()); |
|
366 |
System.out.print(feature.toString()); |
|
367 |
System.out.print(","+feature.get("ExtraID900")); |
|
368 |
System.out.print(","+feature.get("ExtraPobDen")); |
|
369 |
System.out.println(","+feature.get("ExtraAno")); |
|
370 |
} |
|
371 |
System.out.println("ID,Comunidad,Provincia,Ciudad,Poblacion,Densidad,Fecha,CompuID,CompuPob,CompuProv,ExtraID900,ExtraPobDen,ExtraAno"); |
|
372 |
|
|
373 |
features0 = null; |
|
374 |
String[] header = new String[]{"ID","Comunidad","Provincia","Ciudad","Poblacion","Densidad","Fecha","CompuID","CompuPob","CompuProv","ExtraID900","ExtraPobDen","ExtraAno"}; |
|
375 |
ArrayList<Object[]> values = new ArrayList<Object[]>(); |
|
376 |
values.add(new Object[]{0, null, null, null, null, null, null, 0, null,"",900,null,null}); |
|
377 |
values.add(new Object[]{1, "GVA", null, null, 500, null, null, 1, 1502, "VALENCIA",1803,1505,2019}); |
|
378 |
values.add(new Object[]{3, "GVA", null, null, 50, null, null, 3, 352, "VALENCIA",1807,359,2020}); |
|
379 |
values.add(new Object[]{5, "GVA", null, null, 200, null, null, 5, 201, "ALICANTE",905,206,2019}); |
|
380 |
values.add(new Object[]{6, "GVA", null, null, 20, null, null, 6, 422, "ALICANTE",1813,1135,2020}); |
|
381 |
values.add(new Object[]{8, "GVA", null, null, 100, null, null, 8, 702, "CASTELLON",1817,719,2019}); |
|
382 |
for (int i = 0; i < features.size(); i++) { |
|
383 |
for (int j = 0; j < header.length; j++) { |
|
384 |
assertEquals("feature["+i+"]["+header[j]+"]:", values.get(i)[j],features.get(i).get(header[j])); |
|
385 |
} |
|
386 |
} |
|
387 |
|
|
388 |
DisposeUtils.dispose(h2Store); |
|
22 |
@Override |
|
23 |
public void testComputed2() throws Exception { |
|
24 |
super.testComputed2(); |
|
389 | 25 |
} |
390 | 26 |
|
391 |
|
|
392 |
|
|
393 | 27 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/test/java/org/gvsig/fmap/dal/store/h2/TestUtilsH2Spatial.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.store.h2; |
|
2 |
|
|
3 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
4 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
|
5 |
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestUtils; |
|
6 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
|
7 |
import org.gvsig.fmap.dal.store.jdbc2.spi.FakeConnectionProvider; |
|
8 |
|
|
9 |
/** |
|
10 |
* |
|
11 |
* @author jjdelcerro |
|
12 |
*/ |
|
13 |
public class TestUtilsH2Spatial extends AbstractTestUtils { |
|
14 |
|
|
15 |
@Override |
|
16 |
public String getProviderName() { |
|
17 |
return FeatureStore.H2SPATIAL_PROVIDER_NAME; |
|
18 |
} |
|
19 |
|
|
20 |
@Override |
|
21 |
public String getExpectedsPath() { |
|
22 |
return "/org/gvsig/fmap/dal/store/h2"; |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
public JDBCHelper createJDBCHelper() throws Exception { |
|
27 |
H2SpatialConnectionParameters params = (H2SpatialConnectionParameters) this.getServerExplorerParameters("fake"); |
|
28 |
H2SpatialHelper helper = new H2SpatialHelper(params, new FakeConnectionProvider()); |
|
29 |
return helper; |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
public JDBCServerExplorerParameters getServerExplorerParameters(String dbname) throws Exception { |
|
34 |
return this.getH2SpatialServerExplorerParameters(dbname); |
|
35 |
} |
|
36 |
|
|
37 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/test/java/org/gvsig/fmap/dal/store/h2/TestExport2db.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.store.h2; |
|
2 |
|
|
3 |
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestExport2db; |
|
4 |
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestUtils; |
|
5 |
|
|
6 |
public class TestExport2db extends AbstractTestExport2db { |
|
7 |
|
|
8 |
public TestExport2db(String testName) { |
|
9 |
super(testName); |
|
10 |
} |
|
11 |
|
|
12 |
@Override |
|
13 |
protected AbstractTestUtils createUtils() { |
|
14 |
return new TestUtilsH2Spatial(); |
|
15 |
} |
|
16 |
|
|
17 |
@Override |
|
18 |
public void testExport1() throws Exception { |
|
19 |
super.testExport1(); |
|
20 |
} |
|
21 |
|
|
22 |
} |
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/H2SpatialSQLBuilder.java | ||
---|---|---|
7 | 7 |
import java.text.MessageFormat; |
8 | 8 |
import java.util.ArrayList; |
9 | 9 |
import java.util.Date; |
10 |
import java.util.HashSet; |
|
10 | 11 |
import java.util.List; |
11 | 12 |
import java.util.Objects; |
13 |
import java.util.Set; |
|
14 |
import org.apache.commons.lang3.StringUtils; |
|
12 | 15 |
import org.apache.commons.lang3.tuple.Pair; |
13 | 16 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Parameter; |
14 | 17 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
... | ... | |
132 | 135 |
} |
133 | 136 |
|
134 | 137 |
} |
135 |
|
|
138 |
|
|
136 | 139 |
protected class H2SpatialAlterTableBuilderBase extends AlterTableBuilderBase { |
140 |
|
|
137 | 141 |
@Override |
138 | 142 |
public List<String> toStrings(Formatter formatter) { |
139 | 143 |
List<String> sqls = new ArrayList<>(); |
140 | 144 |
if( this.isEmpty() ) { |
141 | 145 |
return sqls; |
142 | 146 |
} |
147 |
|
|
148 |
String local_drop_primary_key_column = this.drop_primary_key_column; |
|
143 | 149 |
for (String column : drops) { |
144 | 150 |
StringBuilder builder = new StringBuilder(); |
145 | 151 |
builder.append("ALTER TABLE "); |
... | ... | |
147 | 153 |
builder.append(" DROP COLUMN IF EXISTS "); |
148 | 154 |
builder.append(as_identifier(column)); |
149 | 155 |
sqls.add(builder.toString()); |
156 |
if( StringUtils.equals(local_drop_primary_key_column, column) ) { |
|
157 |
// Si hemos eliminado la columna sobre la que estaba la pk, ya no hay que |
|
158 |
// eliminar la pk |
|
159 |
local_drop_primary_key_column = null; |
|
160 |
} |
|
150 | 161 |
} |
151 | 162 |
for (ColumnDescriptor column : adds) { |
152 | 163 |
StringBuilder builder = new StringBuilder(); |
... | ... | |
183 | 194 |
} else { |
184 | 195 |
builder.append(" NOT NULL"); |
185 | 196 |
} |
197 |
sqls.add(builder.toString()); |
|
198 |
|
|
186 | 199 |
if (column.isPrimaryKey()) { |
187 |
builder.append(" PRIMARY KEY"); |
|
200 |
String sql; |
|
201 |
sql = MessageFormat.format( |
|
202 |
"ALTER TABLE \"{0}\".\"{1}\" ADD CONSTRAINT \"{2}\" PRIMARY KEY ( \"{3}\" ) INDEX \"{4}\"", |
|
203 |
this.table().getSchema(), |
|
204 |
this.table().getName(), |
|
205 |
this.getConstrainName("PK", column.getName()), |
|
206 |
column.getName(), |
|
207 |
this.getConstrainName("IDX", column.getName()) |
|
208 |
); |
|
209 |
sqls.add(sql); |
|
210 |
} else if( column.isIndexed() ) { |
|
211 |
String sql; |
|
212 |
sql = MessageFormat.format( |
|
213 |
"CREATE INDEX IF NOT EXISTS \"{0}\" ON \"{1}\".\"{2}\" ( \"{3}\" )", |
|
214 |
this.getConstrainName("IDX", column.getName()), |
|
215 |
this.table().getSchema(), |
|
216 |
this.table().getName(), |
|
217 |
column.getName() |
|
218 |
); |
|
219 |
sqls.add(sql); |
|
188 | 220 |
} |
189 |
sqls.add(builder.toString()); |
|
190 | 221 |
|
191 | 222 |
if( column.isGeometry() ) { |
192 |
String constraint_name = "constraint_" + this.table().getName() + "_" + column.getName() + "_geom";
|
|
223 |
String constraint_name = this.getConstrainName("GEOM", column.getName());
|
|
193 | 224 |
String sql; |
194 | 225 |
if (column.getGeometrySRSId() == null) { |
195 | 226 |
if ((int) sqlgeometrytype(column.getGeometryType(), column.getGeometrySubtype()) == 0) { |
... | ... | |
238 | 269 |
} |
239 | 270 |
sqls.add(sql); |
240 | 271 |
} |
272 |
if( StringUtils.equals(local_drop_primary_key_column, column.getName()) ) { |
|
273 |
// Si la columna de la que tenemos que quitar la pk la acabamos de a?adir |
|
274 |
// ya se habra a?adido como toca, y no tendremos que quitar luego la pk. |
|
275 |
local_drop_primary_key_column = null; |
|
276 |
} |
|
241 | 277 |
} |
278 |
|
|
279 |
if( StringUtils.isNotBlank(local_drop_primary_key_column) ) { |
|
280 |
String sql; |
|
281 |
sql = MessageFormat.format( |
|
282 |
"ALTER TABLE \"{0}\".\"{1}\" DROP CONSTRAINT IF EXISTS \"{2}\"", |
|
283 |
this.table().getSchema(), |
|
284 |
this.table().getName(), |
|
285 |
this.getConstrainName("PK", local_drop_primary_key_column) |
|
286 |
); |
|
287 |
sqls.add(sql); |
|
288 |
sql = MessageFormat.format( |
|
289 |
"DROP INDEX IF EXISTS \"{0}\"", |
|
290 |
this.getConstrainName("IDX", local_drop_primary_key_column) |
|
291 |
); |
|
292 |
sqls.add(sql); |
|
293 |
} |
|
294 |
|
|
242 | 295 |
for (ColumnDescriptor column : alters) { |
243 | 296 |
StringBuilder builder = new StringBuilder(); |
244 | 297 |
builder.append("ALTER TABLE "); |
... | ... | |
268 | 321 |
if( column.isAutomatic() ) { |
269 | 322 |
builder.append(" AUTO_INCREMENT"); |
270 | 323 |
} |
324 |
if (column.allowNulls()) { |
|
325 |
builder.append(" NULL"); |
|
326 |
} else { |
|
327 |
builder.append(" NOT NULL"); |
|
328 |
} |
|
271 | 329 |
sqls.add(builder.toString()); |
330 |
if (column.isPrimaryKey()) { |
|
331 |
String sql; |
|
332 |
sql = MessageFormat.format( |
|
333 |
"ALTER TABLE \"{0}\".\"{1}\" ADD CONSTRAINT \"{2}\" PRIMARY KEY ( \"{3}\" ) INDEX \"{4}\"", |
|
334 |
this.table().getSchema(), |
|
335 |
this.table().getName(), |
|
336 |
this.getConstrainName("PK", column.getName()), |
|
337 |
column.getName(), |
|
338 |
this.getConstrainName("IDX", column.getName()) |
|
339 |
); |
|
340 |
sqls.add(sql); |
|
341 |
} |
|
272 | 342 |
if( column.isGeometry() ) { |
273 | 343 |
String sql; |
274 |
String constraint_name = "constraint_" + this.table().getName() + "_" + column.getName()+"_dim"; |
|
275 | 344 |
sql = MessageFormat.format( |
276 | 345 |
"ALTER TABLE \"{0}\".\"{1}\" ADD CONSTRAINT IF NOT EXISTS \"{2}\" CHECK ST_CoordDim(\"{3}\") = {4}", |
277 | 346 |
this.table().getSchema(), |
278 | 347 |
this.table().getName(), |
279 |
constraint_name,
|
|
348 |
this.getConstrainName("DIM", column.getName()),
|
|
280 | 349 |
column.getName(), |
281 | 350 |
sqlgeometrynumdimension(column.getGeometryType(),column.getGeometrySubtype()) |
282 | 351 |
); |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/pom.xml | ||
---|---|---|
268 | 268 |
</dependency> |
269 | 269 |
<dependency> |
270 | 270 |
<groupId>org.gvsig</groupId> |
271 |
<artifactId>org.gvsig.fmap.dal.db.jdbc</artifactId> |
|
272 |
<scope>test</scope> |
|
273 |
<type>test-jar</type> |
|
274 |
</dependency> |
|
275 |
<dependency> |
|
276 |
<groupId>org.gvsig</groupId> |
|
271 | 277 |
<artifactId>org.gvsig.fmap.dal.file.lib</artifactId> |
272 | 278 |
<scope>compile</scope> |
273 | 279 |
</dependency> |
Also available in: Unified diff