Revision 20376
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/JDBCStore.java | ||
---|---|---|
17 | 17 |
import org.gvsig.data.datastores.vectorial.db.jdbc.exception.SQLException; |
18 | 18 |
import org.gvsig.data.datastores.vectorial.db.jdbc.h2.H2Utils; |
19 | 19 |
import org.gvsig.data.exception.DataException; |
20 |
import org.gvsig.data.exception.InitializeWriterException; |
|
20 | 21 |
import org.gvsig.data.exception.ReadException; |
21 | 22 |
import org.gvsig.data.exception.WriteException; |
22 | 23 |
import org.gvsig.data.vectorial.AbstractFeatureStore; |
... | ... | |
72 | 73 |
return this.sqlSource; |
73 | 74 |
} |
74 | 75 |
|
75 |
protected abstract JDBCFeaturesWriter getFeaturesWriter(); |
|
76 |
protected abstract JDBCFeaturesWriter getFeaturesWriter() throws InitializeWriterException;
|
|
76 | 77 |
|
77 | 78 |
protected void doFinishEdition() throws WriteException, ReadException { |
78 | 79 |
Iterator commandsfeatures = null; |
79 |
JDBCFeaturesWriter writer = getFeaturesWriter();
|
|
80 |
JDBCFeaturesWriter selectiveWriter = getFeaturesWriter();
|
|
80 | 81 |
IFeatureType type = getDefaultFeatureType(); |
81 | 82 |
|
82 |
if (writer instanceof ISelectiveWriter){ |
|
83 |
ISelectiveWriter selectiveWriter=(ISelectiveWriter)writer; |
|
84 |
selectiveWriter.updateFeatureType(type); |
|
85 |
selectiveWriter.preProcess(); |
|
86 | 83 |
|
87 |
commandsfeatures = commands.getCommandsAttributeDeleted().iterator(); |
|
88 |
while( commandsfeatures.hasNext() ) { |
|
89 |
Object obj=commandsfeatures.next(); |
|
90 |
if (obj instanceof AbstractAttributeCommand){ |
|
91 |
IFeatureAttributeDescriptor attribute = ((AbstractAttributeCommand)obj).getAttributeDescriptor(); |
|
92 |
selectiveWriter.deleteAttribute(attribute); |
|
93 |
} |
|
94 |
} |
|
95 |
commandsfeatures = commands.getCommandsAttributeUpdated().iterator(); |
|
96 |
while( commandsfeatures.hasNext() ) { |
|
97 |
Object obj=commandsfeatures.next(); |
|
98 |
if (obj instanceof AbstractAttributeCommand){ |
|
99 |
IFeatureAttributeDescriptor oldAttribute = ((UpdateAttributeCommand)obj).getOldAttributeDescriptor(); |
|
100 |
IFeatureAttributeDescriptor attribute = ((UpdateAttributeCommand)obj).getAttributeDescriptor(); |
|
101 |
selectiveWriter.updateAttribute(oldAttribute,attribute); |
|
102 |
} |
|
103 |
} |
|
104 |
commandsfeatures = commands.getCommandsAttributeInserted().iterator(); |
|
105 |
while( commandsfeatures.hasNext() ) { |
|
106 |
Object obj=commandsfeatures.next(); |
|
107 |
if (obj instanceof AbstractAttributeCommand){ |
|
108 |
IFeatureAttributeDescriptor attribute = ((AbstractAttributeCommand)obj).getAttributeDescriptor(); |
|
109 |
selectiveWriter.insertAttribute(attribute); |
|
110 |
} |
|
111 |
} |
|
84 |
selectiveWriter.updateFeatureType(type); |
|
85 |
selectiveWriter.preProcess(); |
|
112 | 86 |
|
87 |
try{ |
|
88 |
commandsfeatures = commands.getCommandsAttributeDeleted().iterator(); |
|
89 |
while( commandsfeatures.hasNext() ) { |
|
90 |
Object obj=commandsfeatures.next(); |
|
91 |
if (obj instanceof AbstractAttributeCommand){ |
|
92 |
IFeatureAttributeDescriptor attribute = ((AbstractAttributeCommand)obj).getAttributeDescriptor(); |
|
93 |
selectiveWriter.deleteAttribute(attribute); |
|
94 |
} |
|
95 |
} |
|
96 |
commandsfeatures = commands.getCommandsAttributeUpdated().iterator(); |
|
97 |
while( commandsfeatures.hasNext() ) { |
|
98 |
Object obj=commandsfeatures.next(); |
|
99 |
if (obj instanceof AbstractAttributeCommand){ |
|
100 |
IFeatureAttributeDescriptor oldAttribute = ((UpdateAttributeCommand)obj).getOldAttributeDescriptor(); |
|
101 |
IFeatureAttributeDescriptor attribute = ((UpdateAttributeCommand)obj).getAttributeDescriptor(); |
|
102 |
selectiveWriter.updateAttribute(oldAttribute,attribute); |
|
103 |
} |
|
104 |
} |
|
105 |
commandsfeatures = commands.getCommandsAttributeInserted().iterator(); |
|
106 |
while( commandsfeatures.hasNext() ) { |
|
107 |
Object obj=commandsfeatures.next(); |
|
108 |
if (obj instanceof AbstractAttributeCommand){ |
|
109 |
IFeatureAttributeDescriptor attribute = ((AbstractAttributeCommand)obj).getAttributeDescriptor(); |
|
110 |
selectiveWriter.insertAttribute(attribute); |
|
111 |
} |
|
112 |
} |
|
113 | 113 |
|
114 |
commandsfeatures = commands.getCommandsFeatureDeleted().iterator(); |
|
115 |
while( commandsfeatures.hasNext() ) { |
|
116 |
Object obj=commandsfeatures.next(); |
|
117 |
if (obj instanceof AbstractFeatureCommand){ |
|
118 |
IFeature feature = ((AbstractFeatureCommand)obj).getFeature(); |
|
119 |
if (feature instanceof CreatedFeature) |
|
120 |
continue; |
|
121 | 114 |
|
122 |
selectiveWriter.deleteFeature(feature); |
|
123 |
} |
|
124 |
} |
|
125 |
commandsfeatures = commands.getCommandsFeatureUpdated().iterator(); |
|
126 |
while( commandsfeatures.hasNext() ) { |
|
127 |
Object obj=commandsfeatures.next(); |
|
128 |
if (obj instanceof AbstractFeatureCommand){ |
|
129 |
IFeature oldFeature = ((UpdateFeatureCommand)obj).getOldFeature(); |
|
130 |
IFeature feature = ((UpdateFeatureCommand)obj).getFeature(); |
|
131 |
if (featureManager.isDeleted(feature)){ |
|
132 |
continue; |
|
133 |
} |
|
134 |
selectiveWriter.updateFeature(oldFeature,feature); |
|
135 |
} |
|
136 |
} |
|
137 |
commandsfeatures = commands.getCommandsFeatureInserted().iterator(); |
|
138 |
while( commandsfeatures.hasNext() ) { |
|
139 |
Object obj=commandsfeatures.next(); |
|
140 |
if (obj instanceof AbstractFeatureCommand){ |
|
141 |
IFeature feature = ((AbstractFeatureCommand)obj).getFeature(); |
|
142 |
if (featureManager.isDeleted(feature)){ |
|
143 |
continue; |
|
144 |
} |
|
145 |
selectiveWriter.insertFeature(feature); |
|
146 |
} |
|
147 |
} |
|
148 |
selectiveWriter.postProcess(); |
|
149 |
} |
|
115 |
commandsfeatures = commands.getCommandsFeatureDeleted().iterator(); |
|
116 |
while( commandsfeatures.hasNext() ) { |
|
117 |
Object obj=commandsfeatures.next(); |
|
118 |
if (obj instanceof AbstractFeatureCommand){ |
|
119 |
IFeature feature = ((AbstractFeatureCommand)obj).getFeature(); |
|
120 |
if (feature instanceof CreatedFeature) |
|
121 |
continue; |
|
150 | 122 |
|
123 |
selectiveWriter.deleteFeature(feature); |
|
124 |
} |
|
125 |
} |
|
126 |
commandsfeatures = commands.getCommandsFeatureUpdated().iterator(); |
|
127 |
while( commandsfeatures.hasNext() ) { |
|
128 |
Object obj=commandsfeatures.next(); |
|
129 |
if (obj instanceof AbstractFeatureCommand){ |
|
130 |
IFeature oldFeature = ((UpdateFeatureCommand)obj).getOldFeature(); |
|
131 |
IFeature feature = ((UpdateFeatureCommand)obj).getFeature(); |
|
132 |
if (featureManager.isDeleted(feature)){ |
|
133 |
continue; |
|
134 |
} |
|
135 |
selectiveWriter.updateFeature(oldFeature,feature); |
|
136 |
} |
|
137 |
} |
|
138 |
commandsfeatures = commands.getCommandsFeatureInserted().iterator(); |
|
139 |
while( commandsfeatures.hasNext() ) { |
|
140 |
Object obj=commandsfeatures.next(); |
|
141 |
if (obj instanceof AbstractFeatureCommand){ |
|
142 |
IFeature feature = ((AbstractFeatureCommand)obj).getFeature(); |
|
143 |
if (featureManager.isDeleted(feature)){ |
|
144 |
continue; |
|
145 |
} |
|
146 |
selectiveWriter.insertFeature(feature); |
|
147 |
} |
|
148 |
} |
|
149 |
selectiveWriter.postProcess(); |
|
150 |
|
|
151 |
}catch (ReadException e) { |
|
152 |
selectiveWriter.cancelProcess(); |
|
153 |
throw e; |
|
154 |
} catch (WriteException e){ |
|
155 |
selectiveWriter.cancelProcess(); |
|
156 |
throw e; |
|
157 |
} catch (Exception e){ |
|
158 |
selectiveWriter.cancelProcess(); |
|
159 |
throw new WriteException(this.getName(),e); |
|
160 |
} |
|
151 | 161 |
} |
152 | 162 |
|
153 | 163 |
public String getFilterForID(DBFeatureType fType, Object[] featureKey) { |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresql/PostgresqlFeaturesWriter.java | ||
---|---|---|
19 | 19 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCAttributeDescriptor; |
20 | 20 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCFeature; |
21 | 21 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCFeaturesWriter; |
22 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCStore; |
|
23 | 22 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCTypes; |
24 | 23 |
import org.gvsig.data.exception.InitializeException; |
25 | 24 |
import org.gvsig.data.exception.InitializeWriterException; |
26 |
import org.gvsig.data.exception.OpenException; |
|
27 | 25 |
import org.gvsig.data.exception.ReadException; |
28 | 26 |
import org.gvsig.data.exception.WriteException; |
29 | 27 |
import org.gvsig.data.vectorial.IFeature; |
... | ... | |
36 | 34 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
37 | 35 |
import com.vividsolutions.jts.io.WKBWriter; |
38 | 36 |
|
39 |
class PostgresqlFeaturesWriter extends JDBCFeaturesWriter implements ISelectiveWriter {
|
|
37 |
public class PostgresqlFeaturesWriter extends JDBCFeaturesWriter {
|
|
40 | 38 |
DBFeatureType featureType; |
41 | 39 |
boolean bCreateTable=false; |
42 | 40 |
private String toEncode; |
43 |
JDBCStore store; |
|
44 | 41 |
PostgresqlStoreParameters parameters; |
45 | 42 |
|
46 | 43 |
private PreparedStatement insertSt; |
... | ... | |
52 | 49 |
} |
53 | 50 |
|
54 | 51 |
public void init(IFeatureStore store) { |
52 |
super.init(store); |
|
55 | 53 |
PostgresqlStore pgStore = (PostgresqlStore)store; |
56 |
this.store = pgStore; |
|
57 | 54 |
this.parameters=pgStore.getParametersPostgresql(); |
58 | 55 |
|
59 | 56 |
this.featureType = (DBFeatureType)this.store.getDefaultFeatureType(); |
60 |
conex = pgStore.getConnection(); |
|
61 | 57 |
|
62 | 58 |
} |
63 | 59 |
|
64 |
public void postProcess() throws OpenException, WriteException { |
|
65 |
try { |
|
66 |
conex.commit(); |
|
67 |
} catch (SQLException e) { |
|
68 |
throw new WriteException(this.store.getName(),e); |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
public void cancelActions() throws WriteException{ |
|
73 |
try { |
|
74 |
conex.rollback(); |
|
75 |
} catch (SQLException e) { |
|
76 |
throw new WriteException(this.store.getName(),e); |
|
77 |
} |
|
78 |
} |
|
79 |
|
|
80 |
|
|
81 | 60 |
public void preProcess() throws WriteException, ReadException { |
61 |
super.preProcess(); |
|
82 | 62 |
//?????????????????????????? |
83 | 63 |
// ATENTION: We will transform (in PostGIS class; doubleQuote()) |
84 | 64 |
// to UTF-8 strings. Then, we tell the PostgreSQL server |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresql/PostgresqlStore.java | ||
---|---|---|
16 | 16 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCStore; |
17 | 17 |
import org.gvsig.data.exception.CloseException; |
18 | 18 |
import org.gvsig.data.exception.InitializeException; |
19 |
import org.gvsig.data.exception.InitializeWriterException; |
|
19 | 20 |
import org.gvsig.data.exception.OpenException; |
20 | 21 |
import org.gvsig.data.exception.ReadException; |
21 | 22 |
import org.gvsig.data.spatialprovisional.IExtent; |
... | ... | |
203 | 204 |
} |
204 | 205 |
|
205 | 206 |
|
206 |
protected JDBCFeaturesWriter getFeaturesWriter() { |
|
207 |
PostgresqlFeaturesWriter writer = new PostgresqlFeaturesWriter();
|
|
207 |
protected JDBCFeaturesWriter getFeaturesWriter() throws InitializeWriterException {
|
|
208 |
JDBCFeaturesWriter writer = new PostgresqlFeaturesWriter();
|
|
208 | 209 |
writer.init(this); |
209 | 210 |
return writer; |
210 | 211 |
} |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2FeaturesWriter.java | ||
---|---|---|
15 | 15 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCAttributeDescriptor; |
16 | 16 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCFeature; |
17 | 17 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCFeaturesWriter; |
18 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCStore; |
|
19 | 18 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCTypes; |
20 | 19 |
import org.gvsig.data.exception.InitializeException; |
21 | 20 |
import org.gvsig.data.exception.InitializeWriterException; |
22 |
import org.gvsig.data.exception.OpenException; |
|
23 | 21 |
import org.gvsig.data.exception.ReadException; |
24 | 22 |
import org.gvsig.data.exception.WriteException; |
25 | 23 |
import org.gvsig.data.vectorial.IFeature; |
... | ... | |
36 | 34 |
DBFeatureType featureType; |
37 | 35 |
boolean bCreateTable=false; |
38 | 36 |
private String toEncode; |
39 |
JDBCStore store; |
|
40 | 37 |
H2StoreParameters parameters; |
41 | 38 |
|
42 | 39 |
private PreparedStatement insertSt; |
... | ... | |
49 | 46 |
} |
50 | 47 |
|
51 | 48 |
public void init(IFeatureStore store) { |
49 |
super.init(store); |
|
52 | 50 |
H2Store h2Store = (H2Store)store; |
53 |
this.store = h2Store; |
|
54 |
|
|
55 |
this.parameters=(H2StoreParameters)store.getParameters(); |
|
56 |
|
|
51 |
this.parameters=h2Store.getParametersH2(); |
|
57 | 52 |
this.featureType = (DBFeatureType)this.store.getDefaultFeatureType(); |
58 |
conex = h2Store.getConnection(); |
|
59 |
} |
|
60 | 53 |
|
61 |
public void postProcess() throws OpenException, WriteException { |
|
62 |
try { |
|
63 |
conex.commit(); |
|
64 |
} catch (SQLException e) { |
|
65 |
throw new WriteException(this.store.getName(),e); |
|
66 |
} |
|
67 | 54 |
} |
68 | 55 |
|
69 |
public void cancelActions() throws WriteException{ |
|
70 |
try { |
|
71 |
conex.rollback(); |
|
72 |
} catch (SQLException e) { |
|
73 |
throw new WriteException(this.store.getName(),e); |
|
74 |
} |
|
75 |
} |
|
76 |
|
|
77 | 56 |
public void preProcess() throws WriteException, ReadException { |
78 |
//FIXME: Transacciones!!!!!!!!! |
|
79 |
try { |
|
80 |
conex.setAutoCommit(false); |
|
81 |
} catch (SQLException e) { |
|
82 |
throw new WriteException(this.store.getName(),e); |
|
83 |
} |
|
57 |
super.preProcess(); |
|
84 | 58 |
|
85 | 59 |
if (bCreateTable) { |
86 | 60 |
H2Explorer explorer = (H2Explorer)this.store.getExplorer(); |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2Store.java | ||
---|---|---|
16 | 16 |
import org.gvsig.data.datastores.vectorial.db.jdbc.WKBParser2; |
17 | 17 |
import org.gvsig.data.exception.CloseException; |
18 | 18 |
import org.gvsig.data.exception.InitializeException; |
19 |
import org.gvsig.data.exception.InitializeWriterException; |
|
19 | 20 |
import org.gvsig.data.exception.OpenException; |
20 | 21 |
import org.gvsig.data.exception.ReadException; |
21 | 22 |
import org.gvsig.data.spatialprovisional.IExtent; |
... | ... | |
204 | 205 |
return DATASTORE_NAME; |
205 | 206 |
} |
206 | 207 |
|
207 |
protected JDBCFeaturesWriter getFeaturesWriter() { |
|
208 |
protected JDBCFeaturesWriter getFeaturesWriter() throws InitializeWriterException {
|
|
208 | 209 |
H2FeaturesWriter writer = new H2FeaturesWriter(); |
209 | 210 |
writer.init(this); |
210 | 211 |
return writer; |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/JDBCFeaturesWriter.java | ||
---|---|---|
4 | 4 |
import java.sql.SQLException; |
5 | 5 |
import java.sql.Statement; |
6 | 6 |
|
7 |
import org.gvsig.data.datastores.vectorial.ISelectiveWriter; |
|
7 | 8 |
import org.gvsig.data.datastores.vectorial.db.DBFeatureType; |
8 | 9 |
import org.gvsig.data.datastores.vectorial.db.jdbc.h2.H2StoreParameters; |
10 |
import org.gvsig.data.datastores.vectorial.db.jdbc.postgresql.PostgresqlStore; |
|
11 |
import org.gvsig.data.exception.OpenException; |
|
12 |
import org.gvsig.data.exception.ReadException; |
|
13 |
import org.gvsig.data.exception.WriteException; |
|
9 | 14 |
import org.gvsig.data.vectorial.IFeatureStore; |
10 | 15 |
|
11 |
public abstract class JDBCFeaturesWriter { |
|
16 |
public abstract class JDBCFeaturesWriter implements ISelectiveWriter{
|
|
12 | 17 |
|
13 | 18 |
protected Connection conex; |
19 |
protected JDBCStore store; |
|
20 |
protected boolean previousAutocommit; |
|
14 | 21 |
|
22 |
|
|
23 |
public void init(IFeatureStore store) { |
|
24 |
this.store = (JDBCStore)store; |
|
25 |
this.conex = this.store.getConnection(); |
|
26 |
} |
|
27 |
|
|
28 |
|
|
29 |
public void preProcess() throws WriteException, ReadException { |
|
30 |
try { |
|
31 |
previousAutocommit = conex.getAutoCommit(); |
|
32 |
conex.setAutoCommit(false); |
|
33 |
} catch (SQLException e) { |
|
34 |
throw new WriteException(this.store.getName(),e); |
|
35 |
} |
|
36 |
|
|
37 |
} |
|
38 |
|
|
39 |
public void postProcess() throws OpenException, WriteException { |
|
40 |
try { |
|
41 |
conex.commit(); |
|
42 |
if (previousAutocommit){ |
|
43 |
conex.setAutoCommit(true); |
|
44 |
} |
|
45 |
} catch (SQLException e) { |
|
46 |
throw new WriteException(this.store.getName(),e); |
|
47 |
} |
|
48 |
} |
|
49 |
|
|
50 |
public void cancelProcess() throws WriteException { |
|
51 |
try { |
|
52 |
conex.rollback(); |
|
53 |
if (previousAutocommit){ |
|
54 |
conex.setAutoCommit(true); |
|
55 |
} |
|
56 |
} catch (SQLException e) { |
|
57 |
throw new WriteException(this.store.getName(),e); |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
15 | 61 |
} |
Also available in: Unified diff