Revision 19965
trunk/libraries/libDataSourceDBBaseDrivers/src-test/org/gvsig/data/datastores/vectorial/db/jdbc/postgresql/postgresqlTest.java | ||
---|---|---|
23 | 23 |
private static String DS_NAME = PostgresqlStore.DATASTORE_NAME; |
24 | 24 |
|
25 | 25 |
|
26 |
public void postgresTest1(){
|
|
26 |
public void testSimpleIteration(){
|
|
27 | 27 |
Register.selfRegister(); |
28 | 28 |
DataManager manager = DataManager.getManager(); |
29 | 29 |
|
... | ... | |
46 | 46 |
|
47 | 47 |
} |
48 | 48 |
|
49 |
public void postgresTest2(){
|
|
49 |
public void testSimpleIteration38K_regs(){
|
|
50 | 50 |
Register.selfRegister(); |
51 | 51 |
DataManager manager = DataManager.getManager(); |
52 | 52 |
|
... | ... | |
60 | 60 |
dparam.setPassw(SERVER_PASWD); |
61 | 61 |
dparam.setSchema(null); |
62 | 62 |
dparam.setDb(SERVER_DBNAME); |
63 |
// dparam.setTableName("portu");
|
|
64 |
dparam.setTableName("ejes"); |
|
63 |
dparam.setTableName("hidropol");
|
|
64 |
// dparam.setTableName("ejes");
|
|
65 | 65 |
dparam.setFieldId(new String[] {"gid"}); |
66 | 66 |
dparam.setFields(new String[] {"*"}); |
67 | 67 |
dparam.setDefaultGeometryField("the_geom"); |
trunk/libraries/libDataSourceDBBaseDrivers/src-test/org/gvsig/data/datastores/vectorial/db/jdbc/postgresqlbin/postgresqlBinTest.java | ||
---|---|---|
60 | 60 |
dparam.setPassw(SERVER_PASWD); |
61 | 61 |
dparam.setSchema(null); |
62 | 62 |
dparam.setDb(SERVER_DBNAME); |
63 |
// dparam.setTableName("portu");
|
|
64 |
dparam.setTableName("ejes"); |
|
63 |
dparam.setTableName("hidropol");
|
|
64 |
// dparam.setTableName("ejes");
|
|
65 | 65 |
dparam.setFieldId(new String[] {"gid"}); |
66 | 66 |
dparam.setFields(new String[] {"*"}); |
67 | 67 |
dparam.setDefaultGeometryField("the_geom"); |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/AbstractDataSourceDBDriverJDBC.java | ||
---|---|---|
1 |
package org.gvsig.data.datastores.vectorial.db.jdbc; |
|
2 |
|
|
3 |
import org.gvsig.data.vectorial.AbstractDataExplorerDB; |
|
4 |
|
|
5 |
public abstract class AbstractDataSourceDBDriverJDBC extends AbstractDataExplorerDB { |
|
6 |
static String DATASOURCE_NAME = "AbstractDataSourceDBDriverJDBC"; |
|
7 |
|
|
8 |
} |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresqlbin/PostgresqlBinStore.java | ||
---|---|---|
98 | 98 |
try{ |
99 | 99 |
this.open(); |
100 | 100 |
Statement st=this.getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); |
101 |
String sql = this.getSqlSelectPart() + " WHERE "+ PostgresqlStoreUtils.getFliterForID(this.featureType, featureKey); |
|
101 |
String sql = this.getSqlSelectPart() + " WHERE "+ PostgresqlBinStoreUtils.getFliterForID(this.featureType, featureKey);
|
|
102 | 102 |
rs=st.executeQuery(sql); |
103 | 103 |
if (rs.isLast()) { |
104 | 104 |
|
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresqlbin/PostgresqlBinStoreUtils.java | ||
---|---|---|
42 | 42 |
private static String baseCursorName=null; |
43 | 43 |
|
44 | 44 |
|
45 |
public static IFeature createFeatureFromBinaryCursor(JDBCStore store, ResultSet rs, DBFeatureType featureType) throws ReadException {
|
|
45 |
static IFeature createFeatureFromBinaryCursor(JDBCStore store, ResultSet rs, DBFeatureType featureType) throws ReadException { |
|
46 | 46 |
|
47 |
PostgresqlFeature feature=null; |
|
47 |
PostgresqlBinFeature feature=null;
|
|
48 | 48 |
|
49 | 49 |
|
50 | 50 |
Object[] pk; |
51 | 51 |
try { |
52 | 52 |
pk = getPkFromResulsetBinary(rs, featureType); |
53 | 53 |
|
54 |
feature=new PostgresqlFeature(featureType,store,pk); |
|
54 |
feature=new PostgresqlBinFeature(featureType,store,pk);
|
|
55 | 55 |
|
56 | 56 |
Iterator iter = featureType.iterator(); |
57 | 57 |
IGeometry geom = null; |
... | ... | |
66 | 66 |
} |
67 | 67 |
} |
68 | 68 |
|
69 |
public static Connection getConnection(String dbUrl, String dbUser, String dbPass) throws InitializeException {
|
|
69 |
static Connection getConnection(String dbUrl, String dbUser, String dbPass) throws InitializeException { |
|
70 | 70 |
//TODO: Aqu? habria que implementar la llamada |
71 | 71 |
// al Resource Manager para comprobar si ya hay |
72 | 72 |
// una connexion a la BD |
... | ... | |
241 | 241 |
return aSql+ " limit " + fetchSize + " offset " + (fetchSize*page); |
242 | 242 |
} |
243 | 243 |
|
244 |
public static String createCursorName() {
|
|
244 |
static String createCursorName() { |
|
245 | 245 |
if (baseCursorName == null){ |
246 | 246 |
baseCursorName = "gv_"+ System.currentTimeMillis(); |
247 | 247 |
} |
... | ... | |
251 | 251 |
|
252 | 252 |
|
253 | 253 |
|
254 |
public static DBFeatureType getFeatureType(Connection connection, PostgresqlStoreParameters params) throws ReadException{
|
|
254 |
static DBFeatureType getFeatureType(Connection connection, PostgresqlStoreParameters params) throws ReadException{ |
|
255 | 255 |
DBFeatureType featureType = new DBFeatureType(); |
256 | 256 |
|
257 | 257 |
|
... | ... | |
370 | 370 |
} |
371 | 371 |
|
372 | 372 |
|
373 |
public static String getFliterForID(DBFeatureType featureType, Object[] featureKey) {
|
|
373 |
static String getFliterForID(DBFeatureType featureType, Object[] featureKey) { |
|
374 | 374 |
// TODO Auto-generated method stub |
375 | 375 |
return null; |
376 | 376 |
} |
... | ... | |
404 | 404 |
|
405 | 405 |
} |
406 | 406 |
|
407 |
public static String getJDBCUrl(String host, String db, String port) {
|
|
407 |
static String getJDBCUrl(String host, String db, String port) { |
|
408 | 408 |
String url; |
409 | 409 |
url = "jdbc:postgresql://"+host+":" + port +"/"+db; |
410 | 410 |
|
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresqlbin/PostgresqlBinFeature.java | ||
---|---|---|
12 | 12 |
|
13 | 13 |
|
14 | 14 |
|
15 |
public class PostgresqlBinFeature extends PostgresqlFeature{
|
|
15 |
public class PostgresqlBinFeature extends JDBCFeature{
|
|
16 | 16 |
|
17 | 17 |
|
18 | 18 |
|
19 |
public PostgresqlBinFeature(IFeatureType featureType, JDBCStore store, Object[] featureKey) {
|
|
19 |
PostgresqlBinFeature(IFeatureType featureType, JDBCStore store, Object[] featureKey) { |
|
20 | 20 |
super(featureType, store, featureKey); |
21 | 21 |
} |
22 | 22 |
|
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/AbstractJDBCDataFeatureCollectionWithFeatureID.java | ||
---|---|---|
1 |
package org.gvsig.data.datastores.vectorial.db.jdbc; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Collection; |
|
5 |
import java.util.Comparator; |
|
6 |
import java.util.ConcurrentModificationException; |
|
7 |
import java.util.Iterator; |
|
8 |
import java.util.TreeSet; |
|
9 |
|
|
10 |
import org.gvsig.data.exception.ReadException; |
|
11 |
import org.gvsig.data.vectorial.IFeature; |
|
12 |
import org.gvsig.data.vectorial.IFeatureCollection; |
|
13 |
import org.gvsig.data.vectorial.IFeatureID; |
|
14 |
import org.gvsig.data.vectorial.IFeatureType; |
|
15 |
import org.gvsig.data.vectorial.expansionadapter.FeatureManager; |
|
16 |
import org.gvsig.data.vectorial.filter.FeatureFilterParser; |
|
17 |
import org.gvsig.data.vectorial.order.FeatureComparator; |
|
18 |
|
|
19 |
public abstract class AbstractJDBCDataFeatureCollectionWithFeatureID extends |
|
20 |
AbstractJDBCDataFeatureCollection { |
|
21 |
|
|
22 |
protected Collection featureIDs; |
|
23 |
protected IFeatureType featureType; |
|
24 |
|
|
25 |
protected abstract IFeatureCollection newBaseDataFeatureCollection(JDBCStore store,IFeatureType featureType,String filter,String order); |
|
26 |
|
|
27 |
protected void intilizeFeatureIDs(FeatureManager fm, JDBCStore store, String filter, String order) throws ReadException { |
|
28 |
FeatureFilterParser parser = null; |
|
29 |
IFeature feature; |
|
30 |
Collection tmpFeatures; |
|
31 |
if (order == null){ |
|
32 |
if (filter == null){ |
|
33 |
tmpFeatures = new ArrayList(); // Si queremos optimizar deberiamos inicializar |
|
34 |
// el tama?o |
|
35 |
} else { |
|
36 |
tmpFeatures = new ArrayList(); |
|
37 |
} |
|
38 |
} else { |
|
39 |
Comparator comparator = new FeatureComparator(this.featureType,order); |
|
40 |
tmpFeatures = new TreeSet(comparator); |
|
41 |
} |
|
42 |
|
|
43 |
if (filter != null && filter != ""){ |
|
44 |
parser = new FeatureFilterParser(filter,featureType); |
|
45 |
} |
|
46 |
for (int i=0;i<fm.getNum();i++){ |
|
47 |
feature = fm.getFeature(i); |
|
48 |
if (fm.isDeleted(feature)){ |
|
49 |
continue; |
|
50 |
} |
|
51 |
if (parser == null || parser.match(feature)){ |
|
52 |
if (order != null){ |
|
53 |
tmpFeatures.add(feature); |
|
54 |
} else { |
|
55 |
tmpFeatures.add(feature.getID()); |
|
56 |
} |
|
57 |
} |
|
58 |
|
|
59 |
|
|
60 |
} |
|
61 |
|
|
62 |
IFeatureCollection coll = this.newBaseDataFeatureCollection(store, featureType, filter, order); |
|
63 |
Iterator iter = coll.iterator(); |
|
64 |
while (iter.hasNext()){ |
|
65 |
feature =(IFeature)iter.next(); |
|
66 |
if (!fm.isDeleted(feature)){ |
|
67 |
if (order != null){ |
|
68 |
tmpFeatures.add(feature); |
|
69 |
} else { |
|
70 |
tmpFeatures.add(feature.getID()); |
|
71 |
} |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
if (order != null){ |
|
76 |
featureIDs = new ArrayList(); |
|
77 |
iter = tmpFeatures.iterator(); |
|
78 |
while (iter.hasNext()){ |
|
79 |
featureIDs.add(((IFeature)iter.next()).getID()); |
|
80 |
} |
|
81 |
} else { |
|
82 |
featureIDs = tmpFeatures; |
|
83 |
} |
|
84 |
|
|
85 |
|
|
86 |
} |
|
87 |
|
|
88 |
public int size() { |
|
89 |
return featureIDs.size(); |
|
90 |
} |
|
91 |
|
|
92 |
public Iterator iterator() { |
|
93 |
FIDIterator dbfIter=new FIDIterator(featureIDs.iterator()); |
|
94 |
return dbfIter; |
|
95 |
} |
|
96 |
|
|
97 |
public class FIDIterator implements Iterator{ |
|
98 |
private Iterator iter; |
|
99 |
|
|
100 |
public FIDIterator(Iterator iter){ |
|
101 |
this.iter=iter; |
|
102 |
} |
|
103 |
public boolean hasNext() { |
|
104 |
checkModified(); |
|
105 |
return iter.hasNext(); |
|
106 |
} |
|
107 |
|
|
108 |
protected void checkModified(){ |
|
109 |
if (modified) |
|
110 |
throw new ConcurrentModificationException("FeatureCollection modified"); |
|
111 |
} |
|
112 |
|
|
113 |
public Object next() { |
|
114 |
checkModified(); |
|
115 |
|
|
116 |
IFeatureID fid= (IFeatureID)iter.next(); |
|
117 |
IFeature feature; |
|
118 |
try { |
|
119 |
feature = fid.getFeature(featureType); |
|
120 |
} catch (ReadException e) { |
|
121 |
throw new RuntimeException(e); |
|
122 |
} |
|
123 |
return feature; |
|
124 |
} |
|
125 |
|
|
126 |
public void remove() { |
|
127 |
throw new UnsupportedOperationException(); |
|
128 |
} |
|
129 |
|
|
130 |
} |
|
131 |
} |
|
0 | 132 |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/JDBCFeaturesWriter.java | ||
---|---|---|
8 | 8 |
import org.gvsig.data.datastores.vectorial.db.jdbc.h2.H2StoreParameters; |
9 | 9 |
import org.gvsig.data.vectorial.IFeatureStore; |
10 | 10 |
|
11 |
public class JDBCFeaturesWriter { |
|
11 |
public abstract class JDBCFeaturesWriter {
|
|
12 | 12 |
|
13 | 13 |
protected Connection conex; |
14 | 14 |
|
15 |
public JDBCFeaturesWriter() { |
|
16 |
super(); |
|
17 |
} |
|
18 |
|
|
19 | 15 |
} |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresql/PostgresqlFeature.java | ||
---|---|---|
1 | 1 |
package org.gvsig.data.datastores.vectorial.db.jdbc.postgresql; |
2 | 2 |
|
3 |
import java.util.List; |
|
4 |
|
|
5 | 3 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCFeature; |
6 | 4 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCStore; |
7 |
import org.gvsig.data.spatialprovisional.IExtent; |
|
8 |
import org.gvsig.data.vectorial.Feature; |
|
9 | 5 |
import org.gvsig.data.vectorial.IFeatureID; |
10 | 6 |
import org.gvsig.data.vectorial.IFeatureType; |
11 | 7 |
|
... | ... | |
19 | 15 |
private static final long serialVersionUID = -8217916635473746942L; |
20 | 16 |
|
21 | 17 |
|
22 |
public PostgresqlFeature(IFeatureType featureType, JDBCStore store, Object[] featureKey) {
|
|
18 |
PostgresqlFeature(IFeatureType featureType, JDBCStore store, Object[] featureKey) { |
|
23 | 19 |
super(featureType, store, featureKey); |
24 | 20 |
} |
25 | 21 |
|
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresql/PostgresqlFeatureCollectionWithFeatureID.java | ||
---|---|---|
1 |
package org.gvsig.data.datastores.vectorial.db.jdbc.postgresql; |
|
2 |
|
|
3 |
import java.util.Collection; |
|
4 |
|
|
5 |
import org.gvsig.data.datastores.vectorial.db.jdbc.AbstractJDBCDataFeatureCollectionWithFeatureID; |
|
6 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCStore; |
|
7 |
import org.gvsig.data.exception.ReadException; |
|
8 |
import org.gvsig.data.vectorial.IFeatureCollection; |
|
9 |
import org.gvsig.data.vectorial.IFeatureType; |
|
10 |
import org.gvsig.data.vectorial.expansionadapter.FeatureManager; |
|
11 |
|
|
12 |
|
|
13 |
public class PostgresqlFeatureCollectionWithFeatureID extends AbstractJDBCDataFeatureCollectionWithFeatureID { |
|
14 |
protected Collection featureIDs;//<IFeatureID> |
|
15 |
protected IFeatureType featureType; |
|
16 |
|
|
17 |
|
|
18 |
PostgresqlFeatureCollectionWithFeatureID(FeatureManager fm,PostgresqlStore store,IFeatureType type, String filter,String order) throws ReadException { |
|
19 |
this.featureType=type; |
|
20 |
intilizeFeatureIDs(fm, store, filter, order); |
|
21 |
} |
|
22 |
|
|
23 |
public IFeatureCollection newBaseDataFeatureCollection(JDBCStore store, IFeatureType featureType, String filter, String order) { |
|
24 |
return new PostgresqlFeatureCollection((PostgresqlStore)store,this.featureType,filter,order); |
|
25 |
} |
|
26 |
|
|
27 |
} |
|
0 | 28 |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresql/PostgresqlStore.java | ||
---|---|---|
116 | 116 |
if (featureManager == null){ |
117 | 117 |
coll=new PostgresqlFeatureCollection(this,type,filter,order); |
118 | 118 |
}else{ |
119 |
// if ((order != null && order != "")){
|
|
120 |
// coll=new H2FeatureCollectionWithFeatureID(featureManager,this,type,filter,order);
|
|
121 |
// } else{
|
|
119 |
if ((order != null && order != "")){ |
|
120 |
coll=new PostgresqlFeatureCollectionWithFeatureID(featureManager,this,type,filter,order);
|
|
121 |
} else{ |
|
122 | 122 |
// if (filter == null || filter == ""){ |
123 | 123 |
// coll=new H2FeatureCollectionEditing(featureManager,this,type); |
124 | 124 |
// } else { |
125 | 125 |
// coll=new H2FeatureCollectionEditingFiltered(featureManager,this,type,filter); |
126 | 126 |
// } |
127 |
// } |
|
128 |
// |
|
127 |
} |
|
129 | 128 |
|
129 |
|
|
130 | 130 |
} |
131 | 131 |
this.addObserver(new WeakReference(coll)); |
132 | 132 |
|
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresql/PostgresqlStoreUtils.java | ||
---|---|---|
36 | 36 |
private static WKBWriter wkbWriter = new WKBWriter(); |
37 | 37 |
|
38 | 38 |
|
39 |
public static String getJDBCUrl(String host, String db, String port) {
|
|
39 |
static String getJDBCUrl(String host, String db, String port) { |
|
40 | 40 |
String url; |
41 | 41 |
url = "jdbc:postgresql://"+host+":" + port +"/"+db; |
42 | 42 |
|
43 | 43 |
return url; |
44 | 44 |
} |
45 | 45 |
|
46 |
public static DBFeatureType getFeatureType(Connection connection, PostgresqlStoreParameters params) throws ReadException{
|
|
46 |
static DBFeatureType getFeatureType(Connection connection, PostgresqlStoreParameters params) throws ReadException{ |
|
47 | 47 |
DBFeatureType featureType = new DBFeatureType(); |
48 | 48 |
|
49 | 49 |
|
... | ... | |
162 | 162 |
} |
163 | 163 |
|
164 | 164 |
|
165 |
public static String getFliterForID(DBFeatureType featureType, Object[] featureKey) {
|
|
165 |
static String getFliterForID(DBFeatureType featureType, Object[] featureKey) { |
|
166 | 166 |
// TODO Auto-generated method stub |
167 | 167 |
return null; |
168 | 168 |
} |
169 | 169 |
|
170 |
public static Connection getConnection(String dbUrl, String dbUser, String dbPass) throws InitializeException {
|
|
170 |
static Connection getConnection(String dbUrl, String dbUser, String dbPass) throws InitializeException { |
|
171 | 171 |
//TODO: Aqu? habria que implementar la llamada |
172 | 172 |
// al Resource Manager para comprobar si ya hay |
173 | 173 |
// una connexion a la BD |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresql/PostgresqlFeatureCollection.java | ||
---|---|---|
23 | 23 |
protected DBFeatureType featureType; |
24 | 24 |
protected String filter; |
25 | 25 |
protected String totalFilter; |
26 |
protected PostgresqlStore store;
|
|
26 |
protected JDBCStore store;
|
|
27 | 27 |
protected ResultSet rs; |
28 | 28 |
private String order; |
29 | 29 |
private int numReg=-1; |
... | ... | |
32 | 32 |
private String totalOrder; |
33 | 33 |
private int fetchSize=5000; |
34 | 34 |
|
35 |
public PostgresqlFeatureCollection(PostgresqlStore store,IFeatureType type, String filter, String order) {
|
|
35 |
PostgresqlFeatureCollection(PostgresqlStore store,IFeatureType type, String filter, String order) { |
|
36 | 36 |
this.store=store; |
37 | 37 |
this.featureType=(DBFeatureType)type; |
38 | 38 |
this.filter=filter; |
... | ... | |
60 | 60 |
private ResultSet getNewResulset(String aSql) throws ReadException{ |
61 | 61 |
this.store.open(); |
62 | 62 |
|
63 |
Connection conn = this.store.getCurrentConnection();
|
|
63 |
Connection conn = ((PostgresqlStore)this.store).getCurrentConnection();
|
|
64 | 64 |
try { |
65 | 65 |
Statement st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY); |
66 | 66 |
return rs = st.executeQuery(aSql); |
... | ... | |
126 | 126 |
|
127 | 127 |
public Iterator iterator() { |
128 | 128 |
|
129 |
H2Iterator dbfIter;
|
|
129 |
PostgresqlIterator dbfIter;
|
|
130 | 130 |
try { |
131 |
dbfIter=new H2Iterator(this.store,this.featureType,this.sql,this.fetchSize);
|
|
131 |
dbfIter=new PostgresqlIterator((PostgresqlStore)this.store,this.featureType,this.sql,this.fetchSize);
|
|
132 | 132 |
} catch (ReadException e) { |
133 | 133 |
throw new RuntimeException(e); |
134 | 134 |
} |
... | ... | |
136 | 136 |
return dbfIter; |
137 | 137 |
} |
138 | 138 |
|
139 |
protected class H2Iterator implements Iterator{
|
|
139 |
protected class PostgresqlIterator implements Iterator{
|
|
140 | 140 |
private ResultSet rs; |
141 | 141 |
private PostgresqlStore store; |
142 | 142 |
private DBFeatureType featureType; |
... | ... | |
145 | 145 |
private int page; |
146 | 146 |
private int index; |
147 | 147 |
|
148 |
public H2Iterator(PostgresqlStore store,DBFeatureType featureType ,String sql,int fetchSize) throws ReadException{
|
|
148 |
public PostgresqlIterator(PostgresqlStore store,DBFeatureType featureType ,String sql,int fetchSize) throws ReadException{
|
|
149 | 149 |
this.sql = sql; |
150 | 150 |
this.store = store; |
151 | 151 |
this.featureType = featureType; |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresql/PostgresqlFeatureID.java | ||
---|---|---|
5 | 5 |
|
6 | 6 |
public class PostgresqlFeatureID extends DBFeatureID{ |
7 | 7 |
|
8 |
public PostgresqlFeatureID(JDBCStore store, Object[] featureKey) {
|
|
8 |
PostgresqlFeatureID(JDBCStore store, Object[] featureKey) { |
|
9 | 9 |
super(store, featureKey); |
10 | 10 |
} |
11 | 11 |
|
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2FeatureCollection.java | ||
---|---|---|
21 | 21 |
import com.iver.cit.gvsig.fmap.drivers.WKBParser2; |
22 | 22 |
|
23 | 23 |
public class H2FeatureCollection extends AbstractJDBCDataFeatureCollection { |
24 |
protected DBFeatureType featureType;
|
|
24 |
protected IFeatureType featureType;
|
|
25 | 25 |
protected String filter; |
26 | 26 |
protected String totalFilter; |
27 | 27 |
protected H2Store store; |
... | ... | |
32 | 32 |
private String sqlCount; |
33 | 33 |
private String totalOrder; |
34 | 34 |
|
35 |
public H2FeatureCollection(H2Store store,IFeatureType type, String filter, String order) {
|
|
35 |
H2FeatureCollection(H2Store store,IFeatureType type, String filter, String order) { |
|
36 | 36 |
this.store=store; |
37 |
this.featureType=(DBFeatureType)type;
|
|
37 |
this.featureType=type; |
|
38 | 38 |
this.filter=filter; |
39 | 39 |
this.order=order; |
40 | 40 |
this.calculateWhere(); |
... | ... | |
139 | 139 |
protected class H2Iterator implements Iterator{ |
140 | 140 |
private ResultSet rs; |
141 | 141 |
private JDBCStore store; |
142 |
private DBFeatureType featureType;
|
|
142 |
private IFeatureType featureType;
|
|
143 | 143 |
|
144 |
public H2Iterator(JDBCStore store,DBFeatureType featureType ,ResultSet rs){
|
|
144 |
public H2Iterator(JDBCStore store,IFeatureType featureType ,ResultSet rs){
|
|
145 | 145 |
this.rs = rs; |
146 | 146 |
this.store = store; |
147 | 147 |
this.featureType = featureType; |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2FeatureID.java | ||
---|---|---|
5 | 5 |
|
6 | 6 |
public class H2FeatureID extends DBFeatureID{ |
7 | 7 |
|
8 |
public H2FeatureID(JDBCStore store, Object[] featureKey) {
|
|
8 |
H2FeatureID(JDBCStore store, Object[] featureKey) { |
|
9 | 9 |
super(store, featureKey); |
10 | 10 |
} |
11 | 11 |
|
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2FeatureCollectionEditingFiltered.java | ||
---|---|---|
34 | 34 |
private FeatureFilterParser parser; |
35 | 35 |
|
36 | 36 |
|
37 |
public H2FeatureCollectionEditingFiltered(FeatureManager fm,H2Store store,IFeatureType type,String filter) {
|
|
37 |
H2FeatureCollectionEditingFiltered(FeatureManager fm,H2Store store,IFeatureType type,String filter) { |
|
38 | 38 |
this.featureManager=fm; |
39 | 39 |
this.store=store; |
40 | 40 |
this.featureType=(DBFeatureType)type; |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2Feature.java | ||
---|---|---|
13 | 13 |
|
14 | 14 |
public class H2Feature extends JDBCFeature{ |
15 | 15 |
|
16 |
public H2Feature(IFeatureType featureType, JDBCStore store, Object[] featureKey) {
|
|
16 |
H2Feature(IFeatureType featureType, JDBCStore store, Object[] featureKey) { |
|
17 | 17 |
super(featureType, store, featureKey); |
18 | 18 |
} |
19 | 19 |
|
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2FeatureCollectionEditing.java | ||
---|---|---|
31 | 31 |
// private FeatureFilterParser parser; |
32 | 32 |
|
33 | 33 |
|
34 |
public H2FeatureCollectionEditing(FeatureManager fm,H2Store store,IFeatureType type) {
|
|
34 |
H2FeatureCollectionEditing(FeatureManager fm,H2Store store,IFeatureType type) { |
|
35 | 35 |
this.featureManager=fm; |
36 | 36 |
this.store=store; |
37 | 37 |
this.featureType=(DBFeatureType)type; |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2FeaturesWriter.java | ||
---|---|---|
39 | 39 |
import com.iver.cit.gvsig.fmap.core.IGeometry3D; |
40 | 40 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
41 | 41 |
|
42 |
public class H2FeaturesWriter extends JDBCFeaturesWriter implements ISelectiveWriter {
|
|
42 |
class H2FeaturesWriter extends JDBCFeaturesWriter implements ISelectiveWriter { |
|
43 | 43 |
DBFeatureType featureType; |
44 | 44 |
boolean bCreateTable=false; |
45 | 45 |
private String toEncode; |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2FeatureCollectionWithFeatureID.java | ||
---|---|---|
1 | 1 |
package org.gvsig.data.datastores.vectorial.db.jdbc.h2; |
2 | 2 |
|
3 |
import java.sql.Connection; |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.Collection; |
|
6 |
import java.util.Comparator; |
|
7 |
import java.util.ConcurrentModificationException; |
|
8 |
import java.util.Iterator; |
|
9 |
import java.util.TreeSet; |
|
10 |
|
|
11 |
import org.gvsig.data.datastores.vectorial.db.jdbc.AbstractJDBCDataFeatureCollection; |
|
3 |
import org.gvsig.data.datastores.vectorial.db.jdbc.AbstractJDBCDataFeatureCollectionWithFeatureID; |
|
12 | 4 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCStore; |
13 | 5 |
import org.gvsig.data.exception.ReadException; |
14 |
import org.gvsig.data.vectorial.AbstractFeatureCollection; |
|
15 |
import org.gvsig.data.vectorial.IFeature; |
|
16 | 6 |
import org.gvsig.data.vectorial.IFeatureCollection; |
17 |
import org.gvsig.data.vectorial.IFeatureID; |
|
18 | 7 |
import org.gvsig.data.vectorial.IFeatureType; |
19 | 8 |
import org.gvsig.data.vectorial.expansionadapter.FeatureManager; |
20 |
import org.gvsig.data.vectorial.filter.FeatureFilterParser; |
|
21 |
import org.gvsig.data.vectorial.order.FeatureComparator; |
|
22 | 9 |
|
23 | 10 |
|
24 |
public class H2FeatureCollectionWithFeatureID extends AbstractJDBCDataFeatureCollection { |
|
25 |
protected Collection featureIDs;//<IFeatureID> |
|
26 |
protected IFeatureType featureType; |
|
27 |
|
|
28 |
|
|
29 |
public H2FeatureCollectionWithFeatureID(FeatureManager fm,H2Store store,IFeatureType type, String filter,String order) throws ReadException { |
|
11 |
public class H2FeatureCollectionWithFeatureID extends AbstractJDBCDataFeatureCollectionWithFeatureID { |
|
12 |
H2FeatureCollectionWithFeatureID(FeatureManager fm,H2Store store,IFeatureType type, String filter,String order) throws ReadException { |
|
30 | 13 |
this.featureType=type; |
31 | 14 |
intilizeFeatureIDs(fm, store, filter, order); |
32 | 15 |
} |
33 | 16 |
|
34 |
protected void intilizeFeatureIDs(FeatureManager fm,H2Store store, String filter,String order) throws ReadException { |
|
35 |
FeatureFilterParser parser = null; |
|
36 |
IFeature feature; |
|
37 |
Collection tmpFeatures; |
|
38 |
if (order == null){ |
|
39 |
if (filter == null){ |
|
40 |
tmpFeatures = new ArrayList(); // Si queremos optimizar deberiamos inicializar |
|
41 |
// el tama?o |
|
42 |
} else { |
|
43 |
tmpFeatures = new ArrayList(); |
|
44 |
} |
|
45 |
} else { |
|
46 |
Comparator comparator = new FeatureComparator(this.featureType,order); |
|
47 |
tmpFeatures = new TreeSet(comparator); |
|
48 |
} |
|
49 |
|
|
50 |
if (filter != null && filter != ""){ |
|
51 |
parser = new FeatureFilterParser(filter,featureType); |
|
52 |
} |
|
53 |
for (int i=0;i<fm.getNum();i++){ |
|
54 |
feature = fm.getFeature(i); |
|
55 |
if (fm.isDeleted(feature)){ |
|
56 |
continue; |
|
57 |
} |
|
58 |
if (parser == null || parser.match(feature)){ |
|
59 |
if (order != null){ |
|
60 |
tmpFeatures.add(feature); |
|
61 |
} else { |
|
62 |
tmpFeatures.add(feature.getID()); |
|
63 |
} |
|
64 |
} |
|
65 |
|
|
66 |
|
|
67 |
} |
|
68 |
|
|
69 |
IFeatureCollection coll = new H2FeatureCollection(store,this.featureType,filter,order); |
|
70 |
Iterator iter = coll.iterator(); |
|
71 |
while (iter.hasNext()){ |
|
72 |
feature =(IFeature)iter.next(); |
|
73 |
if (!fm.isDeleted(feature)){ |
|
74 |
if (order != null){ |
|
75 |
tmpFeatures.add(feature); |
|
76 |
} else { |
|
77 |
tmpFeatures.add(feature.getID()); |
|
78 |
} |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
if (order != null){ |
|
83 |
featureIDs = new ArrayList(); |
|
84 |
iter = tmpFeatures.iterator(); |
|
85 |
while (iter.hasNext()){ |
|
86 |
featureIDs.add(((IFeature)iter.next()).getID()); |
|
87 |
} |
|
88 |
} else { |
|
89 |
featureIDs = tmpFeatures; |
|
90 |
} |
|
91 |
|
|
92 |
|
|
17 |
public IFeatureCollection newBaseDataFeatureCollection(JDBCStore store, IFeatureType featureType, String filter, String order) { |
|
18 |
return new H2FeatureCollection((H2Store)store,this.featureType,filter,order); |
|
93 | 19 |
} |
94 | 20 |
|
95 |
public int size() { |
|
96 |
return featureIDs.size(); |
|
97 |
} |
|
98 |
|
|
99 |
public Iterator iterator() { |
|
100 |
H2FIDIterator dbfIter=new H2FIDIterator(featureIDs.iterator()); |
|
101 |
return dbfIter; |
|
102 |
} |
|
103 |
|
|
104 |
private class H2FIDIterator implements Iterator{ |
|
105 |
private Iterator iter; |
|
106 |
|
|
107 |
public H2FIDIterator(Iterator iter){ |
|
108 |
this.iter=iter; |
|
109 |
} |
|
110 |
public boolean hasNext() { |
|
111 |
checkModified(); |
|
112 |
return iter.hasNext(); |
|
113 |
} |
|
114 |
|
|
115 |
protected void checkModified(){ |
|
116 |
if (modified) |
|
117 |
throw new ConcurrentModificationException("FeatureCollection modified"); |
|
118 |
} |
|
119 |
|
|
120 |
public Object next() { |
|
121 |
checkModified(); |
|
122 |
|
|
123 |
IFeatureID fid= (IFeatureID)iter.next(); |
|
124 |
IFeature feature; |
|
125 |
try { |
|
126 |
feature = fid.getFeature(featureType); |
|
127 |
} catch (ReadException e) { |
|
128 |
throw new RuntimeException(e); |
|
129 |
} |
|
130 |
return feature; |
|
131 |
} |
|
132 |
|
|
133 |
public void remove() { |
|
134 |
throw new UnsupportedOperationException(); |
|
135 |
} |
|
136 |
|
|
137 |
} |
|
138 |
|
|
139 | 21 |
} |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2Store.java | ||
---|---|---|
5 | 5 |
import java.sql.ResultSet; |
6 | 6 |
import java.sql.Statement; |
7 | 7 |
import java.util.ArrayList; |
8 |
import java.util.Iterator; |
|
9 | 8 |
import java.util.List; |
10 | 9 |
import java.util.Locale; |
11 | 10 |
|
12 | 11 |
import org.gvsig.data.IDataCollection; |
13 | 12 |
import org.gvsig.data.IDataExplorer; |
14 | 13 |
import org.gvsig.data.IDataStoreParameters; |
15 |
import org.gvsig.data.commands.implementation.AbstractAttributeCommand; |
|
16 |
import org.gvsig.data.commands.implementation.AbstractFeatureCommand; |
|
17 |
import org.gvsig.data.commands.implementation.UpdateAttributeCommand; |
|
18 |
import org.gvsig.data.commands.implementation.UpdateFeatureCommand; |
|
19 |
import org.gvsig.data.datastores.vectorial.IFeaturesWriter; |
|
20 |
import org.gvsig.data.datastores.vectorial.ISelectiveWriter; |
|
21 | 14 |
import org.gvsig.data.datastores.vectorial.db.DBFeatureType; |
22 | 15 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCFeaturesWriter; |
23 | 16 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCStore; |
24 |
import org.gvsig.data.datastores.vectorial.db.jdbc.exception.SQLException; |
|
25 | 17 |
import org.gvsig.data.exception.CloseException; |
26 | 18 |
import org.gvsig.data.exception.InitializeException; |
27 | 19 |
import org.gvsig.data.exception.OpenException; |
28 | 20 |
import org.gvsig.data.exception.ReadException; |
29 |
import org.gvsig.data.exception.WriteException; |
|
30 | 21 |
import org.gvsig.data.spatialprovisional.IExtent; |
31 |
import org.gvsig.data.vectorial.CreatedFeature; |
|
32 | 22 |
import org.gvsig.data.vectorial.IFeature; |
33 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
|
34 | 23 |
import org.gvsig.data.vectorial.IFeatureCollection; |
35 | 24 |
import org.gvsig.data.vectorial.IFeatureID; |
36 | 25 |
import org.gvsig.data.vectorial.IFeatureType; |
... | ... | |
44 | 33 |
protected static Locale ukLocale = new Locale("en", "UK"); // English, UK version |
45 | 34 |
public DBFeatureType featureType; |
46 | 35 |
protected IMetadata metadata; |
36 |
|
|
37 |
|
|
38 |
|
|
47 | 39 |
public H2StoreParameters getParametersH2(){ |
48 | 40 |
return (H2StoreParameters)this.parameters; |
49 | 41 |
} |
... | ... | |
120 | 112 |
new UnsupportedOperationException("Unsuported filter/order in sqlSource mode")); |
121 | 113 |
} |
122 | 114 |
} |
123 |
if (type==null){ |
|
124 |
type=getDefaultFeatureType(); |
|
115 |
if (type!=null && type != this.getDefaultFeatureType()){ |
|
116 |
throw new UnsupportedOperationException("Type != null"); |
|
117 |
}else{ |
|
118 |
type = this.getDefaultFeatureType(); |
|
125 | 119 |
} |
120 |
|
|
126 | 121 |
IFeatureCollection coll; |
127 | 122 |
if (featureManager == null){ |
128 | 123 |
coll=new H2FeatureCollection(this,type,filter,order); |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2Utils.java | ||
---|---|---|
8 | 8 |
import java.sql.Statement; |
9 | 9 |
import java.util.Iterator; |
10 | 10 |
|
11 |
import org.gvsig.data.datastores.vectorial.db.DBAttributeDescriptor; |
|
12 | 11 |
import org.gvsig.data.datastores.vectorial.db.DBFeatureType; |
13 | 12 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCAttributeDescriptor; |
14 | 13 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCFeature; |
... | ... | |
20 | 19 |
import org.gvsig.data.vectorial.DefaultAttributeDescriptor; |
21 | 20 |
import org.gvsig.data.vectorial.IFeature; |
22 | 21 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
22 |
import org.gvsig.data.vectorial.IFeatureType; |
|
23 | 23 |
|
24 | 24 |
import com.iver.cit.gvsig.fmap.core.FShape; |
25 | 25 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
... | ... | |
417 | 417 |
|
418 | 418 |
} |
419 | 419 |
|
420 |
static IFeature createFeature(JDBCStore store,ResultSet rs,DBFeatureType featureType) throws ReadException{
|
|
420 |
static IFeature createFeature(JDBCStore store,ResultSet rs,IFeatureType featureType) throws ReadException{
|
|
421 | 421 |
|
422 | 422 |
JDBCFeature feature=null; |
423 | 423 |
|
424 |
if (featureType == null){ |
|
425 |
featureType = store.getDefaultFeatureType(); |
|
426 |
} |
|
424 | 427 |
|
428 |
|
|
425 | 429 |
Object[] pk; |
426 | 430 |
try { |
427 |
pk = getPkFromResulset(rs, featureType);
|
|
431 |
pk = getPkFromResulset(rs, (DBFeatureType) store.getDefaultFeatureType());
|
|
428 | 432 |
|
429 | 433 |
feature=new H2Feature(featureType,store,pk); |
430 | 434 |
|
Also available in: Unified diff