Revision 41536 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/jdbc/JDBCStoreProviderWriter.java

View differences:

JDBCStoreProviderWriter.java
60 60
	final static private Logger logger = LoggerFactory
61 61
			.getLogger(JDBCStoreProviderWriter.class);
62 62

  
63
        protected Appender appender;
63 64

  
64
	protected String appendModeSql;
65
	protected List<FeatureAttributeDescriptor> appendModeAttributes;
66

  
67

  
68 65
	public JDBCStoreProviderWriter(JDBCStoreParameters params,
69 66
			DataStoreProviderServices storeServices)
70 67
			throws InitializeException {
71 68
		super(params, storeServices);
69
                this.appender = this.createAppender();
72 70
	}
73 71

  
74 72
	protected JDBCStoreProviderWriter(JDBCStoreParameters params,
75 73
			DataStoreProviderServices storeServices, DynObject metadata)
76 74
			throws InitializeException {
77 75
		super(params, storeServices, metadata);
76
                this.appender = this.createAppender();
78 77
	}
79 78

  
79
        protected Appender createAppender() {
80
            return new JDBCAppender(this);
81
        }
80 82

  
83
        public boolean supportsAppendMode() {
84
            return true;
85
        }
81 86

  
87
        public void endAppend() throws DataException {
88
            this.appender.end();
89
        }
90

  
91
        public void beginAppend() throws DataException {
92
            this.appender.begin();
93
        }
94

  
95
        public void append(final FeatureProvider featureProvider) throws DataException {
96
            this.appender.append(featureProvider);
97
        }
98

  
82 99
	protected void addToListFeatureValues(FeatureProvider featureProvider,
83 100
			FeatureAttributeDescriptor attrOfList,
84 101
			FeatureAttributeDescriptor attr, List<Object> values) throws DataException {
......
244 261

  
245 262
	}
246 263

  
247
	public boolean supportsAppendMode() {
248
		return true;
249
	}
250

  
251
	public void endAppend() throws DataException {
252
		appendModeSql = null;
253
		appendModeAttributes = null;
254
	}
255

  
256 264
	protected List<String> getSqlStatementAlterField(
257 265
			FeatureAttributeDescriptor attrOrg,
258 266
			FeatureAttributeDescriptor attrTrg, List<String> additionalStatement)
......
411 419
	}
412 420

  
413 421

  
414
	private void perfomInsert(Connection conn, PreparedStatement insertSt,
422
	public void perfomInsert(Connection conn, PreparedStatement insertSt,
415 423
			String sql, FeatureProvider feature, List<FeatureAttributeDescriptor> attributes)
416 424
			throws DataException {
417 425

  
......
440 448
		}
441 449
	}
442 450

  
443
	public void append(final FeatureProvider featureProvider) throws DataException {
444
		TransactionalAction action = new TransactionalAction() {
445
			public Object action(Connection conn) throws DataException {
446 451

  
447
				PreparedStatement st;
448
				try {
449
					st = conn.prepareStatement(appendModeSql);
450
				} catch (SQLException e) {
451
					throw new JDBCPreparingSQLException(appendModeSql, e);
452
				}
453
				try {
454
					perfomInsert(conn, st, appendModeSql, featureProvider,
455
							appendModeAttributes);
456
				} finally {
457
					try {
458
						st.close();
459
					} catch (SQLException e) {
460
					}
461
					;
462
				}
463
				return null;
464
			}
465

  
466
			public boolean continueTransactionAllowed() {
467
				return false;
468
			}
469
		};
470
		try {
471
			this.helper.doConnectionAction(action);
472

  
473
			resetCount();
474

  
475
		} catch (Exception e) {
476
			throw new PerformEditingException(this.getSourceId().toString(), e);
477
		}
478
	}
479

  
480 452
	protected void prepareAttributeForUpdate(FeatureAttributeDescriptor attr,
481 453
			List<String> values) {
482 454
		values.add(helper.escapeFieldName(attr.getName()) + " = ?");
......
614 586
	}
615 587

  
616 588

  
617
	public void beginAppend() throws DataException {
618
		StringBuilder sqlb = new StringBuilder();
619
		List<FeatureAttributeDescriptor> attrs = new ArrayList<FeatureAttributeDescriptor>();
620 589

  
621
		prepareSQLAndAttributeListForInsert(sqlb, attrs);
622

  
623
		appendModeSql = sqlb.toString();
624
		appendModeAttributes = attrs;
625
	}
626

  
627

  
628 590
	protected TransactionalAction getPerformChangesAction(
629 591
			final Iterator<FeatureReferenceProviderServices> deleteds, 
630 592
			final Iterator<FeatureProvider> inserteds,

Also available in: Unified diff