Revision 47779 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/operations/AppendOperation.java
AppendOperation.java | ||
---|---|---|
31 | 31 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
32 | 32 |
import org.gvsig.fmap.dal.exception.DataException; |
33 | 33 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
34 |
import static org.gvsig.fmap.dal.feature.FeatureStore.SUBMODE_MERGE; |
|
35 |
import static org.gvsig.fmap.dal.feature.FeatureStore.SUBMODE_NONE; |
|
34 | 36 |
import org.gvsig.fmap.dal.feature.FeatureType; |
35 | 37 |
import org.gvsig.fmap.dal.feature.exception.AlreadyEditingException; |
36 | 38 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
... | ... | |
46 | 48 |
import org.slf4j.LoggerFactory; |
47 | 49 |
|
48 | 50 |
|
51 |
@SuppressWarnings("UseSpecificCatch") |
|
49 | 52 |
public class AppendOperation { |
50 | 53 |
protected static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(AppendOperation.class); |
51 | 54 |
|
... | ... | |
78 | 81 |
this.disposableParameters = null; |
79 | 82 |
} |
80 | 83 |
} |
81 |
|
|
82 |
public void begin() throws DataException { |
|
84 |
|
|
85 |
public void begin(int submode) throws DataException {
|
|
83 | 86 |
if (this.sqlbuilder != null) { |
84 | 87 |
throw new AlreadyEditingException(this.helper.getSourceId()); |
85 | 88 |
} |
86 | 89 |
|
87 | 90 |
try { |
88 | 91 |
this.connection = this.helper.getConnectionWritable(); |
92 |
switch(submode) { |
|
93 |
case SUBMODE_MERGE: |
|
94 |
this.insertSQL = this.getMergeSQL(); |
|
95 |
break; |
|
96 |
case SUBMODE_NONE: |
|
97 |
default: |
|
98 |
this.insertSQL = this.getInsertSQL(); |
|
99 |
break; |
|
100 |
} |
|
89 | 101 |
|
102 |
if( this.connection != null ) { // Not in test mode ??? |
|
103 |
this.preparedStatement = this.connection.prepareStatement(insertSQL); |
|
104 |
this.connection.begin(); |
|
105 |
for (String sql : this.getPreviousSQLs()) { |
|
106 |
this.connection.execute(sql); |
|
107 |
} |
|
108 |
} |
|
109 |
|
|
110 |
} catch (SQLException ex) { |
|
111 |
throw new JDBCPreparingSQLException(this.sqlbuilder.toString(),ex); |
|
112 |
} |
|
113 |
|
|
114 |
} |
|
115 |
|
|
116 |
protected String getInsertSQL() { |
|
90 | 117 |
this.sqlbuilder = this.helper.createSQLBuilder(); |
91 | 118 |
this.expbuilder = this.sqlbuilder.expression(); |
92 | 119 |
|
... | ... | |
112 | 139 |
} |
113 | 140 |
} |
114 | 141 |
|
115 |
this.insertSQL = this.sqlbuilder.insert().toString(); |
|
116 |
if( this.connection != null ) { // Not in test mode ??? |
|
117 |
this.preparedStatement = this.connection.prepareStatement(insertSQL); |
|
118 |
this.connection.begin(); |
|
119 |
for (String sql : this.getPreviousSQLs()) { |
|
120 |
this.connection.execute(sql); |
|
121 |
} |
|
142 |
return this.sqlbuilder.insert().toString(); |
|
143 |
} |
|
144 |
|
|
145 |
protected String getMergeSQL() { |
|
146 |
this.sqlbuilder = this.helper.createSQLBuilder(); |
|
147 |
this.expbuilder = this.sqlbuilder.expression(); |
|
148 |
|
|
149 |
this.sqlbuilder.merge().table() |
|
150 |
.database(this.table.getDatabase()) |
|
151 |
.schema(this.table.getSchema()) |
|
152 |
.name(this.table.getTable() |
|
153 |
); |
|
154 |
for (FeatureAttributeDescriptor pk : type.getPrimaryKey()) { |
|
155 |
this.sqlbuilder.merge().key(pk.getName()); |
|
122 | 156 |
} |
123 | 157 |
|
124 |
} catch (SQLException ex) { |
|
125 |
throw new JDBCPreparingSQLException(this.sqlbuilder.toString(),ex); |
|
126 |
} |
|
158 |
for (FeatureAttributeDescriptor attr : type) { |
|
159 |
if( attr.isAutomatic() || attr.isComputed() ) { |
|
160 |
continue; |
|
161 |
} |
|
162 |
if (attr.getType() == DataTypes.GEOMETRY) { |
|
163 |
this.sqlbuilder.merge().column().name(attr.getName()).with_value( |
|
164 |
expbuilder.parameter(attr.getName()).as_geometry_variable().srs( |
|
165 |
expbuilder.parameter().value(attr.getSRS()) |
|
166 |
) |
|
167 |
); |
|
168 |
} else { |
|
169 |
this.sqlbuilder.merge().column().name(attr.getName()).with_value( |
|
170 |
expbuilder.parameter(attr.getName()).as_variable() |
|
171 |
); |
|
172 |
} |
|
173 |
} |
|
127 | 174 |
|
175 |
return this.sqlbuilder.merge().toString(); |
|
128 | 176 |
} |
129 |
|
|
177 |
|
|
130 | 178 |
protected void clean() { |
131 | 179 |
if( this.batchCount > 0 ) { |
132 | 180 |
this.clearBatch(); |
Also available in: Unified diff