svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dataDB / src / org / gvsig / data / datastores / vectorial / db / jdbc / JDBCFeaturesWriter.java @ 20973
History | View | Annotate | Download (2.11 KB)
1 |
package org.gvsig.data.datastores.vectorial.db.jdbc; |
---|---|
2 |
|
3 |
import java.sql.Connection; |
4 |
import java.sql.SQLException; |
5 |
import java.sql.Statement; |
6 |
|
7 |
import org.gvsig.data.CloseException; |
8 |
import org.gvsig.data.DataException; |
9 |
import org.gvsig.data.OpenException; |
10 |
import org.gvsig.data.ReadException; |
11 |
import org.gvsig.data.WriteException; |
12 |
import org.gvsig.data.datastores.vectorial.ISelectiveWriter; |
13 |
import org.gvsig.data.datastores.vectorial.InitializeWriterException; |
14 |
import org.gvsig.data.datastores.vectorial.db.DBFeatureType; |
15 |
import org.gvsig.data.datastores.vectorial.db.jdbc.h2.H2StoreParameters; |
16 |
import org.gvsig.data.datastores.vectorial.db.jdbc.postgresql.PostgresqlStore; |
17 |
import org.gvsig.data.vectorial.IFeatureStore; |
18 |
|
19 |
public abstract class JDBCFeaturesWriter implements ISelectiveWriter{ |
20 |
|
21 |
protected Connection conex; |
22 |
protected JDBCStore store;
|
23 |
protected boolean previousAutocommit; |
24 |
|
25 |
|
26 |
public void init(IFeatureStore store) throws InitializeWriterException{ |
27 |
this.store = (JDBCStore)store;
|
28 |
try {
|
29 |
this.conex = this.store.getWriterConnection(); |
30 |
} catch (ReadException e) {
|
31 |
throw new InitializeWriterException(this.store.getName(),e); |
32 |
} |
33 |
} |
34 |
|
35 |
/* (non-Javadoc)
|
36 |
* @see org.gvsig.data.datastores.vectorial.IFeaturesWriter#dispose()
|
37 |
*/
|
38 |
public void dispose() throws DataException { |
39 |
try {
|
40 |
this.conex.close();
|
41 |
} catch (SQLException e) { |
42 |
throw new CloseException(this.store.getName(),e); |
43 |
} |
44 |
this.conex = null; |
45 |
|
46 |
} |
47 |
|
48 |
|
49 |
public void preProcess() throws WriteException, ReadException { |
50 |
try {
|
51 |
previousAutocommit = conex.getAutoCommit(); |
52 |
conex.setAutoCommit(false);
|
53 |
} catch (SQLException e) { |
54 |
throw new WriteException(this.store.getName(),e); |
55 |
} |
56 |
|
57 |
} |
58 |
|
59 |
public void postProcess() throws OpenException, WriteException { |
60 |
try {
|
61 |
conex.commit(); |
62 |
if (previousAutocommit){
|
63 |
conex.setAutoCommit(true);
|
64 |
} |
65 |
} catch (SQLException e) { |
66 |
throw new WriteException(this.store.getName(),e); |
67 |
} |
68 |
} |
69 |
|
70 |
public void cancelProcess() throws WriteException { |
71 |
try {
|
72 |
conex.rollback(); |
73 |
if (previousAutocommit){
|
74 |
conex.setAutoCommit(true);
|
75 |
} |
76 |
} catch (SQLException e) { |
77 |
throw new WriteException(this.store.getName(),e); |
78 |
} |
79 |
} |
80 |
|
81 |
} |