svn-gvsig-desktop / trunk / libraries / libDataSourceDBBaseDrivers / src / org / gvsig / data / datastores / vectorial / db / jdbc / JDBCStore.java @ 20032
History | View | Annotate | Download (4.88 KB)
1 |
package org.gvsig.data.datastores.vectorial.db.jdbc; |
---|---|
2 |
|
3 |
import java.sql.Connection; |
4 |
import java.sql.ResultSet; |
5 |
import java.sql.Statement; |
6 |
import java.util.Iterator; |
7 |
|
8 |
import org.gvsig.data.commands.implementation.AbstractAttributeCommand; |
9 |
import org.gvsig.data.commands.implementation.AbstractFeatureCommand; |
10 |
import org.gvsig.data.commands.implementation.UpdateAttributeCommand; |
11 |
import org.gvsig.data.commands.implementation.UpdateFeatureCommand; |
12 |
import org.gvsig.data.datastores.vectorial.ISelectiveWriter; |
13 |
import org.gvsig.data.datastores.vectorial.db.jdbc.exception.SQLException; |
14 |
import org.gvsig.data.datastores.vectorial.db.jdbc.h2.H2Utils; |
15 |
import org.gvsig.data.exception.ReadException; |
16 |
import org.gvsig.data.exception.WriteException; |
17 |
import org.gvsig.data.vectorial.AbstractFeatureStore; |
18 |
import org.gvsig.data.vectorial.CreatedFeature; |
19 |
import org.gvsig.data.vectorial.IFeature; |
20 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
21 |
import org.gvsig.data.vectorial.IFeatureType; |
22 |
|
23 |
public abstract class JDBCStore extends AbstractFeatureStore { |
24 |
|
25 |
protected Connection connection = null; |
26 |
protected String sqlSelectPart; |
27 |
protected String baseWhereClause = null; |
28 |
protected String baseOrder = null; |
29 |
protected String sqlSource = null; |
30 |
protected boolean useSqlSource = false; |
31 |
|
32 |
|
33 |
protected abstract Connection getConnection(); |
34 |
|
35 |
public abstract IFeature getFeatureByID(IFeatureType featureType2, Object[] featureKey) throws ReadException; |
36 |
|
37 |
public boolean isEditable() { |
38 |
return !this.useSqlSource; |
39 |
} |
40 |
|
41 |
|
42 |
public String getSqlSelectPart() { |
43 |
return sqlSelectPart;
|
44 |
} |
45 |
|
46 |
public String getBaseOrder() { |
47 |
return this.baseOrder; |
48 |
} |
49 |
|
50 |
public String getBaseWhereClause() { |
51 |
return baseWhereClause;
|
52 |
} |
53 |
|
54 |
public boolean isUseSqlSource() { |
55 |
return this.useSqlSource; |
56 |
} |
57 |
|
58 |
public String getSqlSource() { |
59 |
return this.sqlSource; |
60 |
} |
61 |
|
62 |
protected abstract JDBCFeaturesWriter getFeaturesWriter(); |
63 |
|
64 |
protected void doFinishEdition() throws WriteException, ReadException { |
65 |
Iterator commandsfeatures = null; |
66 |
JDBCFeaturesWriter writer = getFeaturesWriter(); |
67 |
IFeatureType type = getDefaultFeatureType(); |
68 |
|
69 |
if (writer instanceof ISelectiveWriter){ |
70 |
ISelectiveWriter selectiveWriter=(ISelectiveWriter)writer; |
71 |
selectiveWriter.updateFeatureType(type); |
72 |
selectiveWriter.preProcess(); |
73 |
|
74 |
commandsfeatures = commands.getCommandsAttributeDeleted().iterator(); |
75 |
while( commandsfeatures.hasNext() ) {
|
76 |
Object obj=commandsfeatures.next();
|
77 |
if (obj instanceof AbstractAttributeCommand){ |
78 |
IFeatureAttributeDescriptor attribute = ((AbstractAttributeCommand)obj).getAttributeDescriptor(); |
79 |
selectiveWriter.deleteAttribute(attribute); |
80 |
} |
81 |
} |
82 |
commandsfeatures = commands.getCommandsAttributeUpdated().iterator(); |
83 |
while( commandsfeatures.hasNext() ) {
|
84 |
Object obj=commandsfeatures.next();
|
85 |
if (obj instanceof AbstractAttributeCommand){ |
86 |
IFeatureAttributeDescriptor oldAttribute = ((UpdateAttributeCommand)obj).getOldAttributeDescriptor(); |
87 |
IFeatureAttributeDescriptor attribute = ((UpdateAttributeCommand)obj).getAttributeDescriptor(); |
88 |
selectiveWriter.updateAttribute(oldAttribute,attribute); |
89 |
} |
90 |
} |
91 |
commandsfeatures = commands.getCommandsAttributeInserted().iterator(); |
92 |
while( commandsfeatures.hasNext() ) {
|
93 |
Object obj=commandsfeatures.next();
|
94 |
if (obj instanceof AbstractAttributeCommand){ |
95 |
IFeatureAttributeDescriptor attribute = ((AbstractAttributeCommand)obj).getAttributeDescriptor(); |
96 |
selectiveWriter.insertAttribute(attribute); |
97 |
} |
98 |
} |
99 |
|
100 |
|
101 |
commandsfeatures = commands.getCommandsFeatureDeleted().iterator(); |
102 |
while( commandsfeatures.hasNext() ) {
|
103 |
Object obj=commandsfeatures.next();
|
104 |
if (obj instanceof AbstractFeatureCommand){ |
105 |
IFeature feature = ((AbstractFeatureCommand)obj).getFeature(); |
106 |
if (feature instanceof CreatedFeature) |
107 |
continue;
|
108 |
|
109 |
selectiveWriter.deleteFeature(feature); |
110 |
} |
111 |
} |
112 |
commandsfeatures = commands.getCommandsFeatureUpdated().iterator(); |
113 |
while( commandsfeatures.hasNext() ) {
|
114 |
Object obj=commandsfeatures.next();
|
115 |
if (obj instanceof AbstractFeatureCommand){ |
116 |
IFeature oldFeature = ((UpdateFeatureCommand)obj).getOldFeature(); |
117 |
IFeature feature = ((UpdateFeatureCommand)obj).getFeature(); |
118 |
if (featureManager.isDeleted(feature)){
|
119 |
continue;
|
120 |
} |
121 |
selectiveWriter.updateFeature(oldFeature,feature); |
122 |
} |
123 |
} |
124 |
commandsfeatures = commands.getCommandsFeatureInserted().iterator(); |
125 |
while( commandsfeatures.hasNext() ) {
|
126 |
Object obj=commandsfeatures.next();
|
127 |
if (obj instanceof AbstractFeatureCommand){ |
128 |
IFeature feature = ((AbstractFeatureCommand)obj).getFeature(); |
129 |
if (featureManager.isDeleted(feature)){
|
130 |
continue;
|
131 |
} |
132 |
selectiveWriter.insertFeature(feature); |
133 |
} |
134 |
} |
135 |
selectiveWriter.postProcess(); |
136 |
} |
137 |
|
138 |
} |
139 |
|
140 |
} |