Revision 45469
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/pom.xml | ||
---|---|---|
16 | 16 |
<modules> |
17 | 17 |
<module>org.gvsig.fmap.dal.db.lib</module> |
18 | 18 |
<module>org.gvsig.fmap.dal.db.jdbc</module> |
19 |
<module>org.gvsig.fmap.dal.db.h2</module> |
|
20 | 19 |
<module>org.gvsig.fmap.dal.db.mdb</module> |
21 | 20 |
</modules> |
22 | 21 |
</project> |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/LargeFeatureReferenceSelection.java | ||
---|---|---|
33 | 33 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
34 | 34 |
import org.gvsig.fmap.dal.feature.FeatureStoreNotification; |
35 | 35 |
import org.gvsig.fmap.dal.feature.FeatureType; |
36 |
import org.gvsig.fmap.dal.impl.LargeSetImpl; |
|
37 | 36 |
import org.gvsig.tools.ToolsLocator; |
38 | 37 |
import org.gvsig.tools.dispose.DisposeUtils; |
39 | 38 |
import org.gvsig.tools.dispose.impl.AbstractDisposable; |
... | ... | |
44 | 43 |
import org.gvsig.tools.observer.impl.DelegateWeakReferencingObservable; |
45 | 44 |
import org.gvsig.tools.persistence.PersistentState; |
46 | 45 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
46 |
import org.gvsig.tools.util.Size64; |
|
47 | 47 |
import org.gvsig.tools.visitor.Visitor; |
48 | 48 |
|
49 | 49 |
/** |
50 | 50 |
* |
51 | 51 |
* @author gvSIG Team |
52 | 52 |
*/ |
53 |
@SuppressWarnings("UseSpecificCatch") |
|
53 | 54 |
public class LargeFeatureReferenceSelection extends AbstractDisposable |
54 | 55 |
implements FeatureReferenceSelection { |
55 | 56 |
|
56 | 57 |
public static final String DYNCLASS_PERSISTENT_NAME = "LargeFeatureReferenceSelection"; |
57 | 58 |
|
58 | 59 |
private Set<String> selection; |
59 |
private FeatureStore featureStore; |
|
60 |
private DefaultFeatureStore featureStore;
|
|
60 | 61 |
private Boolean available = null; |
61 | 62 |
private DelegateWeakReferencingObservable delegateObservable |
62 | 63 |
= new DelegateWeakReferencingObservable(this); |
... | ... | |
65 | 66 |
super(); |
66 | 67 |
this.featureStore = featureStore; |
67 | 68 |
DisposeUtils.bind(this.featureStore); |
68 |
this.selection = new LargeSetImpl<>();
|
|
69 |
this.selection = featureStore.getManager().createLargeSet();
|
|
69 | 70 |
|
70 | 71 |
} |
71 | 72 |
|
72 | 73 |
LargeFeatureReferenceSelection(FeatureStore featureStore, FeatureSelectionHelper helper) { |
73 | 74 |
super(); |
74 |
this.featureStore = featureStore; |
|
75 |
this.featureStore = (DefaultFeatureStore) featureStore;
|
|
75 | 76 |
DisposeUtils.bind(this.featureStore); |
76 |
this.selection = new LargeSetImpl<>();
|
|
77 |
this.selection = this.featureStore.getManager().createLargeSet();
|
|
77 | 78 |
} |
78 | 79 |
|
79 | 80 |
/** |
... | ... | |
152 | 153 |
|
153 | 154 |
@Override |
154 | 155 |
public long getSelectedCount() { |
155 |
return ((LargeSetImpl)selection).size64(); |
|
156 |
try { |
|
157 |
return ((Size64)selection).size64(); |
|
158 |
} catch(Exception ex) { |
|
159 |
return selection.size(); |
|
160 |
} |
|
156 | 161 |
} |
157 | 162 |
|
158 | 163 |
@Override |
... | ... | |
315 | 320 |
|
316 | 321 |
@Override |
317 | 322 |
public void loadFromState(PersistentState state) throws PersistenceException { |
323 |
featureStore = (DefaultFeatureStore) state.get("store"); |
|
318 | 324 |
if(selection != null) { |
319 | 325 |
this.selection.clear(); |
320 | 326 |
} else { |
321 |
this.selection = new LargeSetImpl<>();
|
|
327 |
this.selection = this.featureStore.getManager().createLargeSet();
|
|
322 | 328 |
} |
323 |
featureStore = (FeatureStore) state.get("store"); |
|
324 | 329 |
Iterator it = state.getIterator("selected"); |
325 | 330 |
while (it!=null && it.hasNext()) { |
326 | 331 |
DefaultFeatureReference ref = (DefaultFeatureReference) it.next(); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/impl/LargeSetImpl.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package org.gvsig.fmap.dal.impl; |
|
7 |
|
|
8 |
import java.io.File; |
|
9 |
import java.util.Collection; |
|
10 |
import java.util.Iterator; |
|
11 |
import java.util.Set; |
|
12 |
import org.gvsig.tools.ToolsLocator; |
|
13 |
import org.gvsig.tools.dispose.Disposable; |
|
14 |
import org.gvsig.tools.dispose.impl.AbstractDisposable; |
|
15 |
import org.gvsig.tools.exception.BaseException; |
|
16 |
import org.gvsig.tools.folders.FoldersManager; |
|
17 |
import org.gvsig.tools.util.Size; |
|
18 |
import org.gvsig.tools.util.Size64; |
|
19 |
import org.h2.mvstore.MVMap; |
|
20 |
import org.h2.mvstore.MVStore; |
|
21 |
import org.slf4j.Logger; |
|
22 |
import org.slf4j.LoggerFactory; |
|
23 |
|
|
24 |
/** |
|
25 |
* |
|
26 |
* @author fdiaz |
|
27 |
* @param <K> |
|
28 |
*/ |
|
29 |
public class LargeSetImpl<K> extends AbstractDisposable implements Set<K>, Size64, Size, Disposable { |
|
30 |
|
|
31 |
protected static final Logger LOGGER = LoggerFactory.getLogger(LargeSetImpl.class); |
|
32 |
|
|
33 |
private MVStore mvstore; |
|
34 |
private MVMap<K, Boolean> mvMap; |
|
35 |
|
|
36 |
public LargeSetImpl() { |
|
37 |
super(); |
|
38 |
FoldersManager folderManager = ToolsLocator.getFoldersManager(); |
|
39 |
File f = folderManager.getUniqueTemporaryFile("MinLargeSet.mv"); |
|
40 |
this.mvstore = MVStore.open(f.getAbsolutePath()); |
|
41 |
this.mvMap = mvstore.openMap("DefaultMap"); |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
protected void doDispose() throws BaseException { |
|
46 |
this.mvstore.close(); |
|
47 |
this.mvMap = null; |
|
48 |
this.mvstore = null; |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public int size() { |
|
53 |
return this.mvMap.size(); |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
public boolean isEmpty() { |
|
58 |
return this.mvMap.isEmpty(); |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public boolean contains(Object o) { |
|
63 |
return this.mvMap.containsKey((K)o); |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public Iterator<K> iterator() { |
|
68 |
return this.mvMap.keySet().iterator(); |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public Object[] toArray() { |
|
73 |
//FIXME: Ojo, si el set es grande, esto puede puede provocar un desbordamiento de memoria. |
|
74 |
//duda ?implementarlo o lanzar UnsupportedOperationException? |
|
75 |
// LOGGER.warn("Access to LargeSet's toArray() method."); |
|
76 |
// return this.mvMap.entrySet().toArray(); |
|
77 |
throw new UnsupportedOperationException("Not supported yet."); |
|
78 |
} |
|
79 |
|
|
80 |
@Override |
|
81 |
public <T> T[] toArray(T[] a) { |
|
82 |
//FIXME: Ojo, si el set es grande, esto puede puede provocar un desbordamiento de memoria. |
|
83 |
//duda ?implementarlo o lanzar UnsupportedOperationException? |
|
84 |
// LOGGER.warn("Access to LargeSet's toArray(T[] a) method."); |
|
85 |
// return this.mvMap.keySet().toArray((T[]) new K[this.size()]); |
|
86 |
throw new UnsupportedOperationException("Not supported yet."); |
|
87 |
} |
|
88 |
|
|
89 |
@Override |
|
90 |
public boolean add(K e) { |
|
91 |
return this.mvMap.put(e, Boolean.TRUE)!=null; |
|
92 |
} |
|
93 |
|
|
94 |
@Override |
|
95 |
public boolean remove(Object o) { |
|
96 |
return this.mvMap.remove((K)o)!=null; |
|
97 |
} |
|
98 |
|
|
99 |
@Override |
|
100 |
public boolean containsAll(Collection<?> c) { |
|
101 |
//FIXME: Comprobar que esto no lo haga en memoria |
|
102 |
return this.mvMap.keySet().containsAll(c); |
|
103 |
//Si lo hace en memoria, usar lo siguiente; |
|
104 |
// if (!c.stream().noneMatch(object -> (!contains((K)object)))) { |
|
105 |
// return false; |
|
106 |
// } |
|
107 |
// return true; |
|
108 |
} |
|
109 |
|
|
110 |
@Override |
|
111 |
public boolean addAll(Collection<? extends K> c) { |
|
112 |
boolean result = false; |
|
113 |
for (K k : c) { |
|
114 |
result |= this.add(k); |
|
115 |
} |
|
116 |
return result; |
|
117 |
} |
|
118 |
|
|
119 |
@Override |
|
120 |
public boolean retainAll(Collection<?> c) { |
|
121 |
boolean result = false; |
|
122 |
for (Object next : this) { |
|
123 |
if(!c.contains(next)){ |
|
124 |
result |= remove((K)next); |
|
125 |
} |
|
126 |
} |
|
127 |
return result; |
|
128 |
} |
|
129 |
|
|
130 |
@Override |
|
131 |
public boolean removeAll(Collection<?> c) { |
|
132 |
boolean result = false; |
|
133 |
for (Object object : c) { |
|
134 |
result |= remove((K)object); |
|
135 |
} |
|
136 |
return result; |
|
137 |
} |
|
138 |
|
|
139 |
@Override |
|
140 |
public void clear() { |
|
141 |
this.mvMap.clear(); |
|
142 |
} |
|
143 |
|
|
144 |
@Override |
|
145 |
public long size64() { |
|
146 |
return this.mvMap.sizeAsLong(); |
|
147 |
} |
|
148 |
|
|
149 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/impl/LargeMapImpl.java | ||
---|---|---|
1 |
/* |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2020 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
18 |
* |
|
19 |
* For any additional information, do not hesitate to contact us |
|
20 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
21 |
*/ |
|
22 |
package org.gvsig.fmap.dal.impl; |
|
23 |
|
|
24 |
import java.io.File; |
|
25 |
import java.util.AbstractList; |
|
26 |
import java.util.Collection; |
|
27 |
import java.util.List; |
|
28 |
import java.util.Map; |
|
29 |
import java.util.Map.Entry; |
|
30 |
import java.util.Set; |
|
31 |
import org.gvsig.tools.ToolsLocator; |
|
32 |
import org.gvsig.tools.dispose.Disposable; |
|
33 |
import org.gvsig.tools.dispose.impl.AbstractDisposable; |
|
34 |
import org.gvsig.tools.exception.BaseException; |
|
35 |
import org.gvsig.tools.folders.FoldersManager; |
|
36 |
import org.gvsig.tools.util.GetItemByKey; |
|
37 |
import org.gvsig.tools.util.GetKeys; |
|
38 |
import org.gvsig.tools.util.Size; |
|
39 |
import org.gvsig.tools.util.Size64; |
|
40 |
import org.h2.mvstore.MVMap; |
|
41 |
import org.h2.mvstore.MVStore; |
|
42 |
import org.slf4j.Logger; |
|
43 |
import org.slf4j.LoggerFactory; |
|
44 |
|
|
45 |
/** |
|
46 |
* |
|
47 |
* @author gvSIG Team |
|
48 |
*/ |
|
49 |
public class LargeMapImpl<K, V> extends AbstractDisposable implements Map<K, V>, GetItemByKey<K, V>, Size64, Size, GetKeys<K>, Disposable { |
|
50 |
|
|
51 |
protected static final Logger LOGGER = LoggerFactory.getLogger(LargeMapImpl.class); |
|
52 |
|
|
53 |
private MVStore mvstore; |
|
54 |
private MVMap<K, V> mvMap; |
|
55 |
|
|
56 |
public LargeMapImpl() { |
|
57 |
super(); |
|
58 |
FoldersManager folderManager = ToolsLocator.getFoldersManager(); |
|
59 |
File f = folderManager.getUniqueTemporaryFile("MinLargeMap.mv"); |
|
60 |
this.mvstore = MVStore.open(f.getAbsolutePath()); |
|
61 |
this.mvMap = mvstore.openMap("DefaultMap"); |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
public long size64() { |
|
66 |
return this.mvMap.sizeAsLong(); |
|
67 |
} |
|
68 |
|
|
69 |
@Override |
|
70 |
protected void doDispose() throws BaseException { |
|
71 |
this.mvstore.close(); |
|
72 |
this.mvMap = null; |
|
73 |
this.mvstore = null; |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public Set<Entry<K, V>> entrySet() { |
|
78 |
return this.mvMap.entrySet(); |
|
79 |
} |
|
80 |
|
|
81 |
@Override |
|
82 |
public List<K> getKeys() { |
|
83 |
List<K> keys = new AbstractList<K>() { |
|
84 |
@Override |
|
85 |
public K get(int index) { |
|
86 |
K key = mvMap.getKey(index); |
|
87 |
return key; |
|
88 |
} |
|
89 |
|
|
90 |
@Override |
|
91 |
public int size() { |
|
92 |
return mvMap.size(); |
|
93 |
} |
|
94 |
}; |
|
95 |
return keys; |
|
96 |
} |
|
97 |
|
|
98 |
@Override |
|
99 |
public int size() { |
|
100 |
return this.mvMap.size(); |
|
101 |
} |
|
102 |
|
|
103 |
@Override |
|
104 |
public boolean isEmpty() { |
|
105 |
return this.mvMap.isEmpty(); |
|
106 |
} |
|
107 |
|
|
108 |
@Override |
|
109 |
public boolean containsKey(Object key) { |
|
110 |
return this.mvMap.containsKey(key); |
|
111 |
} |
|
112 |
|
|
113 |
@Override |
|
114 |
public boolean containsValue(Object value) { |
|
115 |
return this.mvMap.containsValue(value); |
|
116 |
} |
|
117 |
|
|
118 |
@Override |
|
119 |
public V get(Object key) { |
|
120 |
return this.mvMap.get(key); |
|
121 |
} |
|
122 |
|
|
123 |
@Override |
|
124 |
public V put(K key, V value) { |
|
125 |
return this.mvMap.put(key, value); |
|
126 |
} |
|
127 |
|
|
128 |
@Override |
|
129 |
public V remove(Object key) { |
|
130 |
return this.mvMap.remove(key); |
|
131 |
} |
|
132 |
|
|
133 |
@Override |
|
134 |
public void putAll(Map<? extends K, ? extends V> m) { |
|
135 |
this.mvMap.putAll(m); |
|
136 |
} |
|
137 |
|
|
138 |
@Override |
|
139 |
public void clear() { |
|
140 |
this.mvMap.clear(); |
|
141 |
} |
|
142 |
|
|
143 |
@Override |
|
144 |
public Set<K> keySet() { |
|
145 |
return this.mvMap.keySet(); |
|
146 |
} |
|
147 |
|
|
148 |
@Override |
|
149 |
public Collection<V> values() { |
|
150 |
return this.mvMap.values(); |
|
151 |
} |
|
152 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/impl/DefaultDataManager.java | ||
---|---|---|
211 | 211 |
return new HashSet(); |
212 | 212 |
} |
213 | 213 |
}; |
214 |
|
|
215 |
// TODO: Esto habria que llevarlo al plugin de h2 |
|
216 |
// this.registerLargeMap(new Factory() { |
|
217 |
// @Override |
|
218 |
// public String getName() { |
|
219 |
// return "MVStoreMapFactory"; |
|
220 |
// } |
|
221 |
// |
|
222 |
// @Override |
|
223 |
// public Object create(Object... parameters) { |
|
224 |
// return new LargeMapImpl(); |
|
225 |
// } |
|
226 |
// }); |
|
227 |
// this.registerLargeSet(new Factory() { |
|
228 |
// @Override |
|
229 |
// public String getName() { |
|
230 |
// return "MVStoreSetFactory"; |
|
231 |
// } |
|
232 |
// |
|
233 |
// @Override |
|
234 |
// public Object create(Object... parameters) { |
|
235 |
// return new LargeSetImpl(); |
|
236 |
// } |
|
237 |
// }); |
|
238 | 214 |
} |
239 | 215 |
|
240 | 216 |
@Override |
... | ... | |
1452 | 1428 |
return this.maxSizeForSmallFeatureSelection; |
1453 | 1429 |
} |
1454 | 1430 |
|
1431 |
@Override |
|
1455 | 1432 |
public void registerLargeMap(Factory factory) { |
1456 | 1433 |
this.largeMapFactory = factory; |
1457 | 1434 |
} |
1458 | 1435 |
|
1436 |
@Override |
|
1459 | 1437 |
public void registerLargeSet(Factory factory) { |
1460 | 1438 |
this.largeSetFactory = factory; |
1461 | 1439 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/pom.xml | ||
---|---|---|
134 | 134 |
<artifactId>org.gvsig.tools.util.api</artifactId> |
135 | 135 |
<scope>compile</scope> |
136 | 136 |
</dependency> |
137 |
<dependency> |
|
138 |
<groupId>com.h2database</groupId> |
|
139 |
<artifactId>h2</artifactId> |
|
140 |
<scope>compile</scope> |
|
141 |
</dependency> |
|
142 | 137 |
</dependencies> |
143 | 138 |
|
144 | 139 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial.app/org.gvsig.h2spatial.app.mainplugin/src/test/java/org/gvsig/fmap/dal/store/h2/H2SpatialSQLBuilderTest.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.store.h2; |
|
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.FakeConnectionProvider; |
|
14 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.OperationsFactoryBase; |
|
15 |
import org.gvsig.fmap.geom.DataTypes; |
|
16 |
import org.gvsig.fmap.geom.Geometry; |
|
17 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
18 |
import org.gvsig.fmap.geom.GeometryManager; |
|
19 |
import org.gvsig.fmap.geom.primitive.Polygon; |
|
20 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
21 |
|
|
22 |
public class H2SpatialSQLBuilderTest extends TestCase { |
|
23 |
|
|
24 |
public H2SpatialSQLBuilderTest(String testName) { |
|
25 |
super(testName); |
|
26 |
} |
|
27 |
|
|
28 |
@Override |
|
29 |
protected void setUp() throws Exception { |
|
30 |
super.setUp(); |
|
31 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
32 |
} |
|
33 |
|
|
34 |
@Override |
|
35 |
protected void tearDown() throws Exception { |
|
36 |
super.tearDown(); |
|
37 |
} |
|
38 |
|
|
39 |
private SQLBuilder createSQLBuilder() { |
|
40 |
H2SpatialHelper helper = new H2SpatialHelper(null, new FakeConnectionProvider()); |
|
41 |
return new H2SpatialSQLBuilder(helper); |
|
42 |
} |
|
43 |
|
|
44 |
public void testCalulateEnvelopeOfColumn() throws Exception { |
|
45 |
|
|
46 |
TableReference table = new OperationsFactoryBase.DefaultTableReference("master","dbo","test1", null); |
|
47 |
String columnName = "the_geom"; |
|
48 |
|
|
49 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
50 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
51 |
|
|
52 |
sqlbuilder.select().column().value( |
|
53 |
expbuilder.as_geometry( |
|
54 |
expbuilder.ST_ExtentAggregate( |
|
55 |
expbuilder.column(columnName) |
|
56 |
) |
|
57 |
) |
|
58 |
); |
|
59 |
//sqlbuilder.select().group_by(expbuilder.column(columnName)); |
|
60 |
sqlbuilder.select().from().table() |
|
61 |
.database(table.getDatabase()) |
|
62 |
.schema(table.getSchema()) |
|
63 |
.name(table.getTable()); |
|
64 |
sqlbuilder.select().from().subquery(table.getSubquery()); |
|
65 |
|
|
66 |
sqlbuilder.select().where().and( |
|
67 |
expbuilder.not_is_null(expbuilder.column(columnName)) |
|
68 |
); |
|
69 |
|
|
70 |
System.out.println("# Test:: testCalulateEnvelopeOfColumn"); |
|
71 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
72 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
73 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
74 |
assertEquals( |
|
75 |
"SELECT NVL2(ST_Extent(\"the_geom\"),ST_AsBinary(ST_Extent(\"the_geom\")),NULL) FROM \"dbo\".\"test1\" WHERE ( (\"the_geom\") IS NOT NULL )", |
|
76 |
sqlbuilder.toString() |
|
77 |
); |
|
78 |
assertEquals( |
|
79 |
"[the_geom]", |
|
80 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
81 |
); |
|
82 |
assertEquals( |
|
83 |
"[]", |
|
84 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
85 |
); |
|
86 |
} |
|
87 |
|
|
88 |
public void testCalulateEnvelope() throws Exception { |
|
89 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
90 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
|
91 |
|
|
92 |
Polygon limit = geometryManager.createPolygon(Geometry.SUBTYPES.GEOM2D); |
|
93 |
limit.addVertex(0, 0); |
|
94 |
limit.addVertex(0, 100); |
|
95 |
limit.addVertex(100, 100); |
|
96 |
limit.addVertex(100, 0); |
|
97 |
limit.addVertex(0, 0); |
|
98 |
|
|
99 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
100 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
101 |
|
|
102 |
sqlbuilder.select().column().value( |
|
103 |
expbuilder.as_geometry( |
|
104 |
expbuilder.ST_ExtentAggregate( |
|
105 |
expbuilder.column("the_geom") |
|
106 |
) |
|
107 |
) |
|
108 |
).as("envelope"); |
|
109 |
sqlbuilder.select().from().table().database("master").schema("dbo").name("test1"); |
|
110 |
sqlbuilder.select().where().set( |
|
111 |
expbuilder.ST_Intersects( |
|
112 |
expbuilder.ST_Envelope( |
|
113 |
expbuilder.column("the_geom") |
|
114 |
), |
|
115 |
expbuilder.geometry(limit, proj) |
|
116 |
) |
|
117 |
); |
|
118 |
sqlbuilder.select().where().and( |
|
119 |
expbuilder.custom("x = 27") |
|
120 |
); |
|
121 |
|
|
122 |
System.out.println("# Test:: testCalulateEnvelope"); |
|
123 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
124 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
125 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
126 |
assertEquals( |
|
127 |
"SELECT NVL2(ST_Extent(\"the_geom\"),ST_AsBinary(ST_Extent(\"the_geom\")),NULL) AS \"envelope\" FROM \"dbo\".\"test1\" WHERE (( ((ST_Envelope(\"the_geom\")) && (ST_GeomFromWKB((x'000000000300000001000000050000000000000000000000000000000000000000000000004059000000000000405900000000000040590000000000004059000000000000000000000000000000000000000000000000000000000000'), (4326)))) AND ST_Intersects((ST_Envelope(\"the_geom\")),(ST_GeomFromWKB((x'000000000300000001000000050000000000000000000000000000000000000000000000004059000000000000405900000000000040590000000000004059000000000000000000000000000000000000000000000000000000000000'), (4326))) )) AND x = 27)", |
|
128 |
sqlbuilder.toString() |
|
129 |
); |
|
130 |
assertEquals( |
|
131 |
"[the_geom]", |
|
132 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
133 |
); |
|
134 |
assertEquals( |
|
135 |
"[]", |
|
136 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
137 |
); |
|
138 |
} |
|
139 |
|
|
140 |
public void testCount() throws Exception { |
|
141 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
142 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
143 |
|
|
144 |
sqlbuilder.select().column().value(sqlbuilder.count().all()); |
|
145 |
sqlbuilder.select().from().table().database("master").schema("dbo").name("test1"); |
|
146 |
sqlbuilder.select().from().subquery(null); |
|
147 |
sqlbuilder.select().where().set( expbuilder.custom("pp = 200")); |
|
148 |
|
|
149 |
System.out.println("# Test:: testCount"); |
|
150 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
151 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
152 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
153 |
|
|
154 |
//# Test:: testCount |
|
155 |
//# SQL:: SELECT COUNT(*) FROM "test1" WHERE pp = 200 |
|
156 |
//# Variables:: [] |
|
157 |
//# Parametros:: [] |
|
158 |
|
|
159 |
assertEquals( |
|
160 |
"SELECT COUNT(*) FROM \"dbo\".\"test1\" WHERE pp = 200", |
|
161 |
sqlbuilder.toString() |
|
162 |
); |
|
163 |
assertEquals( |
|
164 |
"[]", |
|
165 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
166 |
); |
|
167 |
assertEquals( |
|
168 |
"[]", |
|
169 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
170 |
); |
|
171 |
} |
|
172 |
|
|
173 |
public void testCreateTable() throws Exception { |
|
174 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
175 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
176 |
|
|
177 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
|
178 |
|
|
179 |
sqlbuilder.create_table().table().database("master").schema("dbo").name("test1"); |
|
180 |
sqlbuilder.create_table().add_column( |
|
181 |
"name", |
|
182 |
DataTypes.STRING, |
|
183 |
45, |
|
184 |
0, |
|
185 |
0, |
|
186 |
false, |
|
187 |
false, |
|
188 |
true, |
|
189 |
false, |
|
190 |
null |
|
191 |
); |
|
192 |
sqlbuilder.create_table().add_column( |
|
193 |
"id", |
|
194 |
DataTypes.INT, |
|
195 |
0, |
|
196 |
0, |
|
197 |
0, |
|
198 |
true, |
|
199 |
false, |
|
200 |
false, |
|
201 |
true, |
|
202 |
0 |
|
203 |
); |
|
204 |
|
|
205 |
sqlbuilder.create_table().add_geometry_column("geom", Geometry.TYPES.MULTIPOLYGON, Geometry.SUBTYPES.GEOM2D, proj, true, true); |
|
206 |
|
|
207 |
|
|
208 |
// 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 |
|
209 |
System.out.println("# Test:: testCreateTable"); |
|
210 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
211 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
212 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
213 |
assertEquals( |
|
214 |
"CREATE TABLE \"dbo\".\"test1\" (\"name\" VARCHAR(45) DEFAULT NULL, \"id\" INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL, \"geom\" GEOMETRY(6) CHECK NVL2(\"geom\", ST_GeometryTypeCode(\"geom\") = 6 AND ST_CoordDim(\"geom\") = 2 AND ST_SRID(\"geom\") = 4326, TRUE) )", |
|
215 |
sqlbuilder.toString() |
|
216 |
); |
|
217 |
assertEquals( |
|
218 |
"[]", |
|
219 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
220 |
); |
|
221 |
assertEquals( |
|
222 |
"[]", |
|
223 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
224 |
); |
|
225 |
} |
|
226 |
|
|
227 |
public void testDropTable() throws Exception { |
|
228 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
229 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
230 |
|
|
231 |
sqlbuilder.drop_table().table().database("master").schema("dbo").name("test1"); |
|
232 |
|
|
233 |
// DROP TABLE "test1" |
|
234 |
|
|
235 |
System.out.println("# Test:: testDropTable"); |
|
236 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
237 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
238 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
239 |
assertEquals( |
|
240 |
"DROP TABLE \"dbo\".\"test1\"", |
|
241 |
sqlbuilder.toString() |
|
242 |
); |
|
243 |
assertEquals( |
|
244 |
"[]", |
|
245 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
246 |
); |
|
247 |
assertEquals( |
|
248 |
"[]", |
|
249 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
250 |
); |
|
251 |
} |
|
252 |
|
|
253 |
public void testFetchFeatureProviderByReference() throws Exception { |
|
254 |
SQLBuilder sqlbuilder = new SQLBuilderBase(); |
|
255 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
256 |
|
|
257 |
String value = "yoyo"; |
|
258 |
sqlbuilder.select().column().name("name"); |
|
259 |
sqlbuilder.select().column().name("id"); |
|
260 |
sqlbuilder.select().column().name("geom").as_geometry(); |
|
261 |
sqlbuilder.select().from().table().database("master").schema("dbo").name("test1"); |
|
262 |
sqlbuilder.select().where().set( |
|
263 |
expbuilder.eq( |
|
264 |
expbuilder.column("name"), |
|
265 |
expbuilder.parameter(value).as_constant() |
|
266 |
) |
|
267 |
); |
|
268 |
sqlbuilder.select().limit(1); |
|
269 |
|
|
270 |
// SELECT "name", "id", ST_AsBinary("geom") FROM "master"."dbo"."test1" WHERE ( ("name") = (?) ) LIMIT 1 |
|
271 |
|
|
272 |
System.out.println("# Test:: testFetchFeatureProviderByReference"); |
|
273 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
274 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
275 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
276 |
assertEquals( |
|
277 |
"SELECT \"name\", \"id\", ST_AsBinary(\"geom\") FROM \"master\".\"dbo\".\"test1\" WHERE ( (\"name\") = (?) ) LIMIT 1", |
|
278 |
sqlbuilder.toString() |
|
279 |
); |
|
280 |
assertEquals( |
|
281 |
"[geom, id, name]", |
|
282 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
283 |
); |
|
284 |
assertEquals( |
|
285 |
"['yoyo']", |
|
286 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
287 |
); |
|
288 |
} |
|
289 |
|
|
290 |
public void testFetchFeatureType() throws Exception { |
|
291 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
292 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
293 |
|
|
294 |
sqlbuilder.select().column().all(); |
|
295 |
sqlbuilder.select().from().table().database("master").schema("dbo").name("test1"); |
|
296 |
sqlbuilder.select().limit(1); |
|
297 |
|
|
298 |
System.out.println("# Test:: testFetchFeatureType"); |
|
299 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
300 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
301 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
302 |
|
|
303 |
//# Test:: testFetchFeatureType |
|
304 |
//# SQL:: SELECT * FROM "test1" LIMIT 1 |
|
305 |
//# Variables:: [] |
|
306 |
//# Parametros:: [] |
|
307 |
|
|
308 |
assertEquals( |
|
309 |
"SELECT * FROM \"dbo\".\"test1\" LIMIT 1", |
|
310 |
sqlbuilder.toString() |
|
311 |
); |
|
312 |
assertEquals( |
|
313 |
"[]", |
|
314 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
315 |
); |
|
316 |
assertEquals( |
|
317 |
"[]", |
|
318 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
319 |
); |
|
320 |
} |
|
321 |
|
|
322 |
public void testPerformDeletes() throws Exception { |
|
323 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
324 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
325 |
|
|
326 |
sqlbuilder.delete().table().database("master").schema("dbo").name("test1"); |
|
327 |
sqlbuilder.delete().where().and( |
|
328 |
expbuilder.eq( |
|
329 |
expbuilder.column("id1"), |
|
330 |
expbuilder.parameter("id1").as_variable() |
|
331 |
) |
|
332 |
); |
|
333 |
sqlbuilder.delete().where().and( |
|
334 |
expbuilder.eq( |
|
335 |
expbuilder.column("id2"), |
|
336 |
expbuilder.parameter("id2").as_variable() |
|
337 |
) |
|
338 |
); |
|
339 |
|
|
340 |
// DELETE FROM "test1" WHERE ( ("id1") = (?) ) AND ( ("id2") = (?) ) |
|
341 |
|
|
342 |
System.out.println("# Test:: testPerformDeletes"); |
|
343 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
344 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
345 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
346 |
assertEquals( |
|
347 |
"DELETE FROM \"dbo\".\"test1\" WHERE (( (\"id1\") = (?) ) AND ( (\"id2\") = (?) ))", |
|
348 |
sqlbuilder.toString() |
|
349 |
); |
|
350 |
assertEquals( |
|
351 |
"[id1, id2]", |
|
352 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
353 |
); |
|
354 |
assertEquals( |
|
355 |
"[\"id1\", \"id2\"]", |
|
356 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
357 |
); |
|
358 |
} |
|
359 |
|
|
360 |
public void testPerformInserts1() throws Exception { |
|
361 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
|
362 |
|
|
363 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
364 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
365 |
|
|
366 |
sqlbuilder.insert().table().database("master").schema("dbo").name("test1"); |
|
367 |
sqlbuilder.insert().column().name("id").with_value(expbuilder.parameter("id")); |
|
368 |
sqlbuilder.insert().column().name("name").with_value(expbuilder.parameter("name")); |
|
369 |
sqlbuilder.insert().column().name("geom").with_value(expbuilder.parameter("geom").as_geometry_variable().srs(proj)); |
|
370 |
|
|
371 |
System.out.println("# Test:: testPerformInserts1"); |
|
372 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
373 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
374 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
375 |
assertEquals( |
|
376 |
"INSERT INTO \"dbo\".\"test1\" ( \"id\", \"name\", \"geom\" ) VALUES ( ?, ?, ST_GeomFromWKB((?), (4326)) )", |
|
377 |
sqlbuilder.toString() |
|
378 |
); |
|
379 |
assertEquals( |
|
380 |
"[geom, id, name]", |
|
381 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
382 |
); |
|
383 |
assertEquals( |
|
384 |
"[\"id\", \"name\", \"geom\"]", |
|
385 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
386 |
); |
|
387 |
} |
|
388 |
|
|
389 |
public void testPerformInserts2() throws Exception { |
|
390 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
|
391 |
|
|
392 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
393 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
394 |
|
|
395 |
sqlbuilder.insert().table().database("master").schema("dbo").name("test1"); |
|
396 |
sqlbuilder.insert().column().name("id").with_value(expbuilder.parameter("id")); |
|
397 |
sqlbuilder.insert().column().name("name").with_value(expbuilder.parameter("name")); |
|
398 |
sqlbuilder.insert().column().name("geom").with_value(expbuilder.parameter("geom").as_geometry_variable().srs(proj)); |
|
399 |
|
|
400 |
System.out.println("# Test:: testPerformInserts2"); |
|
401 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
402 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
403 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
404 |
assertEquals( |
|
405 |
"INSERT INTO \"dbo\".\"test1\" ( \"id\", \"name\", \"geom\" ) VALUES ( ?, ?, ST_GeomFromWKB((?), (4326)) )", |
|
406 |
sqlbuilder.toString() |
|
407 |
); |
|
408 |
assertEquals( |
|
409 |
"[geom, id, name]", |
|
410 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
411 |
); |
|
412 |
assertEquals( |
|
413 |
"[\"id\", \"name\", \"geom\"]", |
|
414 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
415 |
); |
|
416 |
} |
|
417 |
|
|
418 |
public void testPerformUpdates1() throws Exception { |
|
419 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
|
420 |
|
|
421 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
422 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
423 |
|
|
424 |
sqlbuilder.update().table().database("master").schema("dbo").name("test1"); |
|
425 |
sqlbuilder.update().where().and( |
|
426 |
expbuilder.eq( |
|
427 |
expbuilder.column("id"), |
|
428 |
expbuilder.parameter("id").as_variable() |
|
429 |
) |
|
430 |
); |
|
431 |
sqlbuilder.update().column().name("name").with_value(expbuilder.parameter("name")); |
|
432 |
sqlbuilder.update().column().name("geom").with_value( |
|
433 |
expbuilder.parameter("geom").as_geometry_variable().srs(proj) |
|
434 |
); |
|
435 |
|
|
436 |
System.out.println("# Test:: testPerformUpdates"); |
|
437 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
438 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
439 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
440 |
assertEquals( |
|
441 |
"UPDATE \"dbo\".\"test1\" SET \"name\" = ?, \"geom\" = ST_GeomFromWKB((?), (4326)) WHERE ( (\"id\") = (?) )", |
|
442 |
sqlbuilder.toString() |
|
443 |
); |
|
444 |
assertEquals( |
|
445 |
"[geom, id, name]", |
|
446 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
447 |
); |
|
448 |
assertEquals( |
|
449 |
"[\"name\", \"geom\", \"id\"]", |
|
450 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
451 |
); |
|
452 |
} |
|
453 |
|
|
454 |
public void testPerformUpdates2() throws Exception { |
|
455 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
|
456 |
|
|
457 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
458 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
459 |
|
|
460 |
sqlbuilder.update().table().database("master").schema("dbo").name("test1"); |
|
461 |
sqlbuilder.update().where().and( |
|
462 |
expbuilder.eq( |
|
463 |
expbuilder.column("id"), |
|
464 |
expbuilder.parameter("id").as_variable() |
|
465 |
) |
|
466 |
); |
|
467 |
sqlbuilder.update().column().name("name").with_value(expbuilder.parameter("name")); |
|
468 |
sqlbuilder.update().column().name("geom").with_value( |
|
469 |
expbuilder.parameter("geom").as_geometry_variable() |
|
470 |
.srs(expbuilder.parameter().value(proj)) |
|
471 |
); |
|
472 |
|
|
473 |
System.out.println("# Test:: testPerformUpdates"); |
|
474 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
475 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
476 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
477 |
assertEquals( |
|
478 |
"UPDATE \"dbo\".\"test1\" SET \"name\" = ?, \"geom\" = ST_GeomFromWKB((?), (?)) WHERE ( (\"id\") = (?) )", |
|
479 |
sqlbuilder.toString() |
|
480 |
); |
|
481 |
assertEquals( |
|
482 |
"[geom, id, name]", |
|
483 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
484 |
); |
|
485 |
assertEquals( |
|
486 |
"[\"name\", \"geom\", 4326, \"id\"]", |
|
487 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
488 |
); |
|
489 |
} |
|
490 |
|
|
491 |
public void testGrant1() throws Exception { |
|
492 |
|
|
493 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
494 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
495 |
|
|
496 |
sqlbuilder.grant().table().database("master").schema("dbo").name("test1"); |
|
497 |
sqlbuilder.grant().role("prueba").select().insert().update(); |
|
498 |
sqlbuilder.grant().role("gis").all(); |
|
499 |
|
|
500 |
|
|
501 |
System.out.println("# Test:: testGrant1"); |
|
502 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
503 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
504 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
505 |
assertEquals( |
|
506 |
"", |
|
507 |
sqlbuilder.toString() |
|
508 |
); |
|
509 |
assertEquals( |
|
510 |
"[]", |
|
511 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
512 |
); |
|
513 |
assertEquals( |
|
514 |
"[]", |
|
515 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
516 |
); |
|
517 |
} |
|
518 |
|
|
519 |
public void testGrant2() throws Exception { |
|
520 |
|
|
521 |
SQLBuilder sqlbuilder = new SQLBuilderBase(); |
|
522 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
523 |
|
|
524 |
sqlbuilder.grant().table().database("master").schema("dbo").name("test1"); |
|
525 |
sqlbuilder.grant().role("prueba").privilege(Privilege.SELECT) |
|
526 |
.privilege(Privilege.INSERT) |
|
527 |
.privilege(Privilege.UPDATE); |
|
528 |
sqlbuilder.grant().role("gis").privilege(Privilege.ALL); |
|
529 |
|
|
530 |
|
|
531 |
System.out.println("# Test:: testGrant2"); |
|
532 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
533 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
534 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
535 |
assertEquals( |
|
536 |
"", |
|
537 |
sqlbuilder.toString() |
|
538 |
); |
|
539 |
assertEquals( |
|
540 |
"[]", |
|
541 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
542 |
); |
|
543 |
assertEquals( |
|
544 |
"[]", |
|
545 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
546 |
); |
|
547 |
} |
|
548 |
|
|
549 |
|
|
550 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial.app/org.gvsig.h2spatial.app.mainplugin/src/test/java/org/gvsig/fmap/dal/store/h2/WorkspaceTest.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.store.h2; |
|
2 |
|
|
3 |
import java.util.HashMap; |
|
4 |
import java.util.List; |
|
5 |
import java.util.Map; |
|
6 |
import junit.framework.TestCase; |
|
7 |
import org.gvsig.fmap.dal.DALLocator; |
|
8 |
import org.gvsig.fmap.dal.DataManager; |
|
9 |
import org.gvsig.fmap.dal.DataStore; |
|
10 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
11 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager; |
|
12 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
13 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
14 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
15 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
16 |
import static org.gvsig.fmap.dal.store.h2.TestCreate.DBNAME; |
|
17 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
|
18 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
|
19 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
20 |
import org.slf4j.Logger; |
|
21 |
import org.slf4j.LoggerFactory; |
|
22 |
|
|
23 |
/** |
|
24 |
* |
|
25 |
* @author jjdelcerro |
|
26 |
*/ |
|
27 |
public class WorkspaceTest extends TestCase { |
|
28 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestCreate.class); |
|
29 |
|
|
30 |
public static final String DBNAME = "test_workspace"; |
|
31 |
|
|
32 |
public WorkspaceTest(String testName) { |
|
33 |
super(testName); |
|
34 |
} |
|
35 |
|
|
36 |
@Override |
|
37 |
protected void setUp() throws Exception { |
|
38 |
super.setUp(); |
|
39 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
40 |
} |
|
41 |
|
|
42 |
@Override |
|
43 |
protected void tearDown() throws Exception { |
|
44 |
super.tearDown(); |
|
45 |
} |
|
46 |
|
|
47 |
protected String getProviderName() { |
|
48 |
return DataStore.H2SPATIAL_PROVIDER_NAME; |
|
49 |
} |
|
50 |
|
|
51 |
protected String getTargetName() { |
|
52 |
return "testCreateTarget1"; |
|
53 |
} |
|
54 |
|
|
55 |
protected FeatureStore openTargetStore1(JDBCServerExplorer explorer) throws Exception { |
|
56 |
JDBCStoreParameters params = explorer.get(getTargetName()); |
|
57 |
|
|
58 |
DataManager dataManager = DALLocator.getDataManager(); |
|
59 |
FeatureStore store; |
|
60 |
try { |
|
61 |
store = (FeatureStore) dataManager.openStore( |
|
62 |
getProviderName(), |
|
63 |
params |
|
64 |
); |
|
65 |
} catch(ValidateDataParametersException ex) { |
|
66 |
LOGGER.warn(ex.getLocalizedMessageStack()); |
|
67 |
throw ex; |
|
68 |
} |
|
69 |
return store; |
|
70 |
} |
|
71 |
|
|
72 |
protected void createFrom(JDBCServerExplorer explorer, FeatureStore sourceStore) throws Exception { |
|
73 |
NewFeatureStoreParameters params = (NewFeatureStoreParameters) explorer.getAddParameters( |
|
74 |
getTargetName() |
|
75 |
); |
|
76 |
EditableFeatureType ft = params.getDefaultFeatureType(); |
|
77 |
ft.addAll(sourceStore.getDefaultFeatureType()); |
|
78 |
explorer.add(getProviderName(), params, true); |
|
79 |
} |
|
80 |
|
|
81 |
public void testWorkspace() throws Exception { |
|
82 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
83 |
JDBCServerExplorer explorer = TestUtils.openServerExplorer(DBNAME); |
|
84 |
|
|
85 |
createFrom(explorer, sourceStore); |
|
86 |
|
|
87 |
DataManager dataManager = DALLocator.getDataManager(); |
|
88 |
|
|
89 |
DatabaseWorkspaceManager workspace = dataManager.createDatabaseWorkspaceManager(explorer.getParameters()); |
|
90 |
|
|
91 |
workspace.create("Testid", "Test label"); |
|
92 |
workspace.disconnect(); |
|
93 |
|
|
94 |
workspace = dataManager.createDatabaseWorkspaceManager(explorer.getParameters()); |
|
95 |
assertEquals("Testid",workspace.getId()); |
|
96 |
assertEquals("Test label",workspace.getLabel()); |
|
97 |
|
|
98 |
List<DataStoreParameters> tables_l = explorer.list(); |
|
99 |
assertEquals(6, tables_l.size()); |
|
100 |
|
|
101 |
Map<String, JDBCStoreParameters> tables = new HashMap<>(); |
|
102 |
for (DataStoreParameters table1 : tables_l) { |
|
103 |
JDBCStoreParameters table = (JDBCStoreParameters) table1; |
|
104 |
tables.put(table.getTable(), table); |
|
105 |
} |
|
106 |
|
|
107 |
JDBCStoreParameters params = tables.get("testCreateTarget1"); |
|
108 |
assertNotNull("Table testCreateTarget1 not found",params); |
|
109 |
|
|
110 |
workspace.writeStoresRepositoryEntry(params.getTable(), params); |
|
111 |
|
|
112 |
DataStoreParameters store = workspace.getStoresRepository().get(params.getTable()); |
|
113 |
assertNotNull("Can't open table testCreateTarget1 ",store); |
|
114 |
} |
|
115 |
|
|
116 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial.app/org.gvsig.h2spatial.app.mainplugin/src/test/java/org/gvsig/fmap/dal/store/h2/STAsBinaryTest.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.store.h2; |
|
2 |
|
|
3 |
import junit.framework.TestCase; |
|
4 |
import org.gvsig.fmap.dal.DALLocator; |
|
5 |
import org.gvsig.fmap.dal.DataManager; |
|
6 |
import org.gvsig.fmap.dal.DataTypes; |
|
7 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
8 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
9 |
import org.gvsig.fmap.dal.feature.Feature; |
|
10 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
11 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
12 |
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters; |
|
13 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
|
14 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
|
15 |
import org.gvsig.fmap.geom.Geometry; |
|
16 |
import org.gvsig.fmap.geom.GeometryUtils; |
|
17 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
18 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
19 |
|
|
20 |
/** |
|
21 |
* |
|
22 |
* @author jjdelcerro |
|
23 |
*/ |
|
24 |
public class STAsBinaryTest extends TestCase { |
|
25 |
|
|
26 |
private static final String TABLE_EMPTY_WITH_GEOM = "TABLE_EMPTY_WITH_GEOM"; |
|
27 |
private static final String TABLE_WITH_NULL_GEOMS = "TABLE_WITH_NULL_GEOMS"; |
|
28 |
|
|
29 |
public static final String DBNAME = "STAsBinaryTest"; |
|
30 |
|
|
31 |
public STAsBinaryTest(String testName) { |
|
32 |
super(testName); |
|
33 |
} |
|
34 |
|
|
35 |
@Override |
|
36 |
protected void setUp() throws Exception { |
|
37 |
super.setUp(); |
|
38 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
protected void tearDown() throws Exception { |
|
43 |
super.tearDown(); |
|
44 |
} |
|
45 |
private void createTableWithNullGeoms(JDBCServerExplorer explorer, String tableName) throws Exception { |
|
46 |
DataManager dataManager = DALLocator.getDataManager(); |
|
47 |
|
|
48 |
JDBCNewStoreParameters create_params = explorer.getAddParameters(); |
|
49 |
create_params.setTable(tableName); |
|
50 |
EditableFeatureType ft = create_params.getDefaultFeatureType(); |
|
51 |
ft.add("ID", DataTypes.INT).setIsPrimaryKey(true); |
|
52 |
ft.add("ISNULL", DataTypes.BOOLEAN); |
|
53 |
ft.add("GEOM", DataTypes.GEOMETRY) |
|
54 |
.setGeometryType(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2D). |
|
55 |
setSRS("EPSG:4326"); |
|
56 |
explorer.add(TestUtils.PROVIDER_NAME, create_params, false); |
|
57 |
|
|
58 |
JDBCStoreParameters open_params = explorer.getOpenParameters(); |
|
59 |
open_params.setTable(tableName); |
|
60 |
FeatureStore store = (FeatureStore) dataManager.openStore(TestUtils.PROVIDER_NAME, open_params); |
|
61 |
store.edit(FeatureStore.MODE_FULLEDIT); |
|
62 |
EditableFeature f; |
|
63 |
int id=1; |
|
64 |
f = store.createNewFeature(); |
|
65 |
f.set("ID", id++); |
|
66 |
f.set("ISNULL", false); |
|
67 |
f.set("GEOM", GeometryUtils.createPoint(10, 10)); |
|
68 |
store.insert(f); |
|
69 |
f = store.createNewFeature(); |
|
70 |
f.set("ID", id++); |
|
71 |
f.set("ISNULL", true); |
|
72 |
f.set("GEOM", null); |
|
73 |
store.insert(f); |
|
74 |
f = store.createNewFeature(); |
|
75 |
f.set("ID", id++); |
|
76 |
f.set("ISNULL", true); |
|
77 |
f.set("GEOM", null); |
|
78 |
store.insert(f); |
|
79 |
f = store.createNewFeature(); |
|
80 |
f.set("ID", id++); |
|
81 |
f.set("ISNULL", false); |
|
82 |
f.set("GEOM", GeometryUtils.createPoint(20, 20)); |
|
83 |
store.insert(f); |
|
84 |
store.finishEditing(); |
|
85 |
} |
|
86 |
|
|
87 |
private void createEmptyTable(JDBCServerExplorer explorer, String tableName) throws Exception { |
|
88 |
JDBCNewStoreParameters params = explorer.getAddParameters(); |
|
89 |
params.setTable(tableName); |
|
90 |
EditableFeatureType ft = params.getDefaultFeatureType(); |
|
91 |
ft.add("ID", DataTypes.INT).setIsPrimaryKey(true); |
|
92 |
ft.add("ISNULL", DataTypes.BOOLEAN); |
|
93 |
ft.add("GEOM", DataTypes.GEOMETRY) |
|
94 |
.setGeometryType(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2D). |
|
95 |
setSRS("EPSG:4326"); |
|
96 |
explorer.add(TestUtils.PROVIDER_NAME, params, false); |
|
97 |
} |
|
98 |
|
|
99 |
public void testGetEnvelopeOfEmptyTable() throws Exception { |
|
100 |
DataManager dataManager = DALLocator.getDataManager(); |
|
101 |
|
|
102 |
JDBCServerExplorer explorer = TestUtils.openServerExplorer(DBNAME); |
|
103 |
createEmptyTable(explorer, TABLE_EMPTY_WITH_GEOM); |
|
104 |
|
|
105 |
JDBCStoreParameters params = explorer.getOpenParameters(); |
|
106 |
params.setTable(TABLE_EMPTY_WITH_GEOM); |
|
107 |
FeatureStore store = (FeatureStore) dataManager.openStore(TestUtils.PROVIDER_NAME, params); |
|
108 |
Envelope env = store.getEnvelope(); |
|
109 |
assertNull(env); |
|
110 |
} |
|
111 |
|
|
112 |
public void testGetEnvelopeOfTableWithNullGeoms() throws Exception { |
|
113 |
DataManager dataManager = DALLocator.getDataManager(); |
|
114 |
|
|
115 |
JDBCServerExplorer explorer = TestUtils.openServerExplorer(DBNAME); |
|
116 |
createTableWithNullGeoms(explorer, TABLE_WITH_NULL_GEOMS); |
|
117 |
|
|
118 |
JDBCStoreParameters params = explorer.getOpenParameters(); |
|
119 |
params.setTable(TABLE_WITH_NULL_GEOMS); |
|
120 |
FeatureStore store = (FeatureStore) dataManager.openStore(TestUtils.PROVIDER_NAME, params); |
|
121 |
Envelope env = store.getEnvelope(); |
|
122 |
assertNotNull(env); |
|
123 |
assertEquals("POLYGON ((10.0 10.0, 10.0 20.0, 20.0 20.0, 20.0 10.0, 10.0 10.0))", env.toString()); |
|
124 |
} |
|
125 |
|
|
126 |
public void testIterateOverTableWithNullGeoms() throws Exception { |
|
127 |
DataManager dataManager = DALLocator.getDataManager(); |
|
128 |
|
|
129 |
JDBCServerExplorer explorer = TestUtils.openServerExplorer(DBNAME); |
|
130 |
createTableWithNullGeoms(explorer, TABLE_WITH_NULL_GEOMS); |
|
131 |
|
|
132 |
JDBCStoreParameters params = explorer.getOpenParameters(); |
|
133 |
params.setTable(TABLE_WITH_NULL_GEOMS); |
|
134 |
FeatureStore store = (FeatureStore) dataManager.openStore(TestUtils.PROVIDER_NAME, params); |
|
135 |
FeatureSet set = store.getFeatureSet(); |
|
136 |
int sz = (int) set.getSize(); |
|
137 |
// System.out.println("#### count: "+sz); |
|
138 |
for (Feature f : set ) { |
|
139 |
// System.out.println("#### feature: "+f.toString()); |
|
140 |
if( !f.getBoolean("ISNULL") ) { |
|
141 |
assertNotNull(f.getGeometry("GEOM")); |
|
142 |
} |
|
143 |
} |
|
144 |
assertEquals(4, sz); |
|
145 |
} |
|
146 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial.app/org.gvsig.h2spatial.app.mainplugin/src/test/java/org/gvsig/fmap/dal/store/h2/TestUtils.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.store.h2; |
|
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.DataServerExplorerParameters; |
|
12 |
import org.gvsig.fmap.dal.DataStore; |
|
13 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager; |
|
14 |
import org.gvsig.fmap.dal.feature.Feature; |
|
15 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
16 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeature; |
|
17 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
|
18 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
|
19 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
|
20 |
import org.gvsig.fmap.dal.store.jdbc2.spi.FakeConnectionProvider; |
|
21 |
import org.slf4j.Logger; |
|
22 |
import org.slf4j.LoggerFactory; |
|
23 |
|
|
24 |
public class TestUtils { |
|
25 |
|
|
26 |
public static final Logger LOGGER = LoggerFactory.getLogger(TestUtils.class); |
|
27 |
|
|
28 |
public static final String PROVIDER_NAME = H2SpatialLibrary.NAME; |
|
29 |
|
|
30 |
private static int dbcounter = 1; |
|
31 |
|
|
32 |
public static H2SpatialConnectionParameters buildDBConnection(String dbname) throws Exception { |
|
33 |
DataManager dataManager = DALLocator.getDataManager(); |
|
34 |
H2SpatialConnectionParameters conn = (H2SpatialConnectionParameters) |
|
35 |
dataManager.createServerExplorerParameters(H2SpatialLibrary.NAME); |
|
36 |
|
|
37 |
File dbfile = TestUtils.getResource(String.format( |
|
38 |
"test-dbs/%s-%d-%03d", |
|
39 |
dbname, |
|
40 |
System.currentTimeMillis(), |
|
41 |
dbcounter++ |
|
42 |
) |
|
43 |
); |
|
44 |
// System.out.println("#### dbfile: " + dbfile.getAbsolutePath()); |
|
45 |
FileUtils.forceMkdir(dbfile.getParentFile()); |
|
46 |
conn.setFile(dbfile); |
|
47 |
return conn; |
|
48 |
} |
|
49 |
|
|
50 |
public static JDBCServerExplorer openServerExplorer(String dbname) throws Exception { |
|
51 |
DataManager dataManager = DALLocator.getDataManager(); |
|
52 |
H2SpatialConnectionParameters conn = buildDBConnection(dbname); |
|
53 |
JDBCServerExplorer explorer = (JDBCServerExplorer) dataManager.openServerExplorer( |
|
54 |
PROVIDER_NAME, conn |
|
55 |
); |
|
56 |
return explorer; |
|
57 |
} |
|
58 |
|
|
59 |
public static File getTargetFolder() throws Exception { |
|
60 |
URL url = TestUtils.class.getResource("/"); |
|
61 |
File x = new File(url.toURI()); |
|
62 |
File target = x.getParentFile(); |
|
63 |
return target; |
|
64 |
} |
|
65 |
|
|
66 |
public static File getResource(String name) throws Exception { |
|
67 |
File x = new File(getTargetFolder(), name); |
|
68 |
return x; |
|
69 |
} |
|
70 |
|
|
71 |
public static File getResourceAsFile(String pathname) throws Exception { |
|
72 |
URL url = TestUtils.class.getResource(pathname); |
|
73 |
File x = new File(url.toURI()); |
|
74 |
return x; |
|
75 |
} |
|
76 |
|
|
77 |
public static void removeDALResource(String dbname, String name) throws Exception { |
|
78 |
H2SpatialConnectionParameters connection = buildDBConnection(dbname); |
|
79 |
DatabaseWorkspaceManager workspace = DALLocator.getDataManager().createDatabaseWorkspaceManager( |
|
80 |
(DataServerExplorerParameters) connection |
|
81 |
); |
|
82 |
// ResourcesStorage resources = workspace.getResourcesStorage(name); |
|
83 |
// resources.remove("dal"); |
|
84 |
} |
|
85 |
|
|
86 |
public static FeatureStore openSourceStore1() throws Exception { |
|
87 |
DataManager dataManager = DALLocator.getDataManager(); |
|
88 |
File f = getResourceAsFile("/org/gvsig/fmap/dal/store/h2/testCreateSource1.csv"); |
|
89 |
FeatureStore store = (FeatureStore) dataManager.openStore( |
|
90 |
DataStore.CSV_PROVIDER_NAME, |
|
91 |
"file=",f, |
|
92 |
"automaticTypesDetection=", false, |
|
93 |
"locale=","en" |
|
94 |
); |
|
95 |
return store; |
|
96 |
} |
|
97 |
|
|
98 |
|
|
99 |
public static List<String> getSQLs(String name) throws Exception { |
|
100 |
File f = getResourceAsFile("/org/gvsig/fmap/dal/store/h2/"+name); |
|
101 |
List<String> SQLs = new ArrayList<>(); |
|
102 |
List<String> lines = FileUtils.readLines(f); |
|
103 |
StringBuilder sb = new StringBuilder(); |
|
104 |
for (String line : lines) { |
|
105 |
line = StringUtils.stripStart(line, null); |
|
106 |
if( line.startsWith("--") ) { |
|
107 |
continue; |
|
108 |
} |
|
109 |
if( line.endsWith(";") ) { |
|
110 |
sb.append(line.substring(0, line.length()-1)); |
|
111 |
SQLs.add(sb.toString()); |
|
112 |
sb.setLength(0); |
|
113 |
} else { |
|
114 |
sb.append(line); |
|
115 |
} |
|
116 |
} |
|
117 |
return SQLs; |
|
118 |
} |
|
119 |
|
|
120 |
public static FeatureProvider getFeatureProvider(Feature feature) { |
|
121 |
return ((DefaultFeature)feature).getData(); |
|
122 |
} |
|
123 |
|
|
124 |
public static JDBCHelper getJDBCHelper() { |
|
125 |
H2SpatialHelper helper = new H2SpatialHelper(null, new FakeConnectionProvider()); |
|
126 |
return helper; |
|
127 |
} |
|
128 |
|
|
129 |
|
|
130 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial.app/org.gvsig.h2spatial.app.mainplugin/src/test/java/org/gvsig/fmap/dal/store/h2/TestCreate.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.store.h2; |
|
2 |
|
|
3 |
import java.util.Date; |
|
4 |
import java.util.List; |
|
5 |
import junit.framework.TestCase; |
|
6 |
import static junit.framework.TestCase.assertEquals; |
|
7 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
8 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
|
9 |
import org.gvsig.fmap.dal.DALLocator; |
|
10 |
import org.gvsig.fmap.dal.DataTypes; |
|
11 |
import org.gvsig.fmap.dal.DataManager; |
|
12 |
import org.gvsig.fmap.dal.DataStore; |
|
13 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
14 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
15 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
16 |
import org.gvsig.fmap.dal.feature.Feature; |
|
17 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
18 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
19 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
20 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
21 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
22 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
|
23 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
|
24 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
25 |
import org.slf4j.Logger; |
|
26 |
import org.slf4j.LoggerFactory; |
|
27 |
|
|
28 |
public class TestCreate extends TestCase { |
|
29 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestCreate.class); |
|
30 |
|
|
31 |
public static final String DBNAME = "testCreate"; |
|
32 |
|
|
33 |
public TestCreate(String testName) { |
|
34 |
super(testName); |
|
35 |
} |
|
36 |
|
|
37 |
@Override |
|
38 |
protected void setUp() throws Exception { |
|
39 |
super.setUp(); |
|
40 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
protected void tearDown() throws Exception { |
|
45 |
super.tearDown(); |
|
46 |
} |
|
47 |
|
|
48 |
// TODO add test methods here. The name must begin with 'test'. For example: |
|
49 |
// public void testHello() {} |
|
50 |
|
|
51 |
protected String getProviderName() { |
|
52 |
return DataStore.H2SPATIAL_PROVIDER_NAME; |
|
53 |
} |
|
54 |
|
|
55 |
protected String getTargetName() { |
|
56 |
return "testCreateTarget1"; |
|
57 |
} |
|
58 |
|
|
59 |
protected FeatureStore openTargetStore1(JDBCServerExplorer explorer) throws Exception { |
|
60 |
JDBCStoreParameters params = explorer.get(getTargetName()); |
|
61 |
|
|
62 |
DataManager dataManager = DALLocator.getDataManager(); |
|
63 |
FeatureStore store; |
|
64 |
try { |
Also available in: Unified diff