Lines 295-318
Link Here
|
295 |
} |
295 |
} |
296 |
} |
296 |
} |
297 |
|
297 |
|
298 |
RequestProcessor.Task executeInsertRow(final DataViewPageContext pageContext, |
298 |
int executeInsertRow(final DataViewPageContext pageContext, |
299 |
final DBTable table, |
299 |
final DBTable table, |
300 |
final String insertSQL, |
300 |
final String[] insertSQLs, |
301 |
final Object[] insertedRow) { |
301 |
final Object[][] insertedRows) { |
302 |
dataView.setEditable(false); |
|
|
303 |
|
302 |
|
304 |
String title = NbBundle.getMessage(SQLExecutionHelper.class, "LBL_sql_insert"); |
303 |
assert (! SwingUtilities.isEventDispatchThread()); |
305 |
SQLStatementExecutor executor = new SQLStatementExecutor(dataView, title, "", true) { |
|
|
306 |
|
304 |
|
307 |
@Override |
|
|
308 |
public void execute() throws SQLException, DBException { |
309 |
dataView.setEditable(false); |
305 |
dataView.setEditable(false); |
310 |
List<DBColumn> columns = table.getColumnList(); |
306 |
|
311 |
PreparedStatement pstmt = conn.prepareStatement(insertSQL); |
307 |
int done = 0; |
|
|
308 |
Exception caughtException = null; |
309 |
|
312 |
try { |
310 |
try { |
|
|
311 |
List<DBColumn> columns = table.getColumnList(); |
312 |
|
313 |
for (int j = 0; j < insertSQLs.length; j++) { |
314 |
try (PreparedStatement pstmt = dataView.getDatabaseConnection().getJDBCConnection().prepareStatement(insertSQLs[j])) { |
313 |
int pos = 1; |
315 |
int pos = 1; |
314 |
for (int i = 0; i < insertedRow.length; i++) { |
316 |
for (int i = 0; i < insertedRows[j].length; i++) { |
315 |
Object val = insertedRow[i]; |
317 |
Object val = insertedRows[j][i]; |
316 |
|
318 |
|
317 |
// Check for Constant e.g <NULL>, <DEFAULT>, <CURRENT_TIMESTAMP> etc |
319 |
// Check for Constant e.g <NULL>, <DEFAULT>, <CURRENT_TIMESTAMP> etc |
318 |
if (DataViewUtils.isSQLConstantString(val, columns.get(i))) { |
320 |
if (DataViewUtils.isSQLConstantString(val, columns.get(i))) { |
Lines 324-377
Link Here
|
324 |
DBReadWriteHelper.setAttributeValue(pstmt, pos++, colType, val); |
326 |
DBReadWriteHelper.setAttributeValue(pstmt, pos++, colType, val); |
325 |
} |
327 |
} |
326 |
|
328 |
|
327 |
executePreparedStatement(pstmt); |
329 |
int rows = pstmt.executeUpdate(); |
328 |
int rows = dataView.getUpdateCount(); |
330 |
|
329 |
if (rows != 1) { |
331 |
if (rows != 1) { |
330 |
error = true; |
332 |
throw new SQLException("MSG_failure_insert_rows"); |
331 |
errorMsg = NbBundle.getMessage(SQLExecutionHelper.class, "MSG_failure_insert_rows"); |
|
|
332 |
} |
333 |
} |
333 |
} finally { |
334 |
done++; |
334 |
DataViewUtils.closeResources(pstmt); |
|
|
335 |
} |
335 |
} |
336 |
} |
336 |
} |
337 |
|
337 |
} catch (DBException | SQLException ex) { |
338 |
@Override |
338 |
LOGGER.log(Level.INFO, ex.getLocalizedMessage(), ex); |
339 |
public void finished() { |
339 |
caughtException = ex; |
|
|
340 |
} finally { |
340 |
dataView.resetEditable(); |
341 |
dataView.resetEditable(); |
341 |
commitOrRollback(NbBundle.getMessage(SQLExecutionHelper.class, "LBL_insert_command")); |
|
|
342 |
} |
342 |
} |
343 |
|
343 |
|
344 |
@Override |
344 |
final int finalDone = done; |
345 |
protected void executeOnSucess() { |
345 |
final Exception finalCaught = caughtException; |
|
|
346 |
|
346 |
// refresh when required |
347 |
// refresh when required |
347 |
Boolean needRequery = Mutex.EVENT.readAccess(new Mutex.Action<Boolean>() { |
348 |
Boolean needRequery = Mutex.EVENT.readAccess(new Mutex.Action<Boolean>() { |
348 |
@Override |
349 |
@Override |
349 |
public Boolean run() { |
350 |
public Boolean run() { |
|
|
351 |
if (finalCaught != null) { |
352 |
DialogDisplayer.getDefault().notifyLater( |
353 |
new NotifyDescriptor.Message( |
354 |
finalCaught.getLocalizedMessage())); |
355 |
} |
350 |
if (pageContext.getTotalRows() < 0) { |
356 |
if (pageContext.getTotalRows() < 0) { |
351 |
pageContext.setTotalRows(0); |
357 |
pageContext.setTotalRows(0); |
352 |
pageContext.first(); |
358 |
pageContext.first(); |
353 |
} |
359 |
} |
354 |
pageContext.incrementRowSize(1); |
360 |
pageContext.incrementRowSize(finalDone); |
355 |
return pageContext.refreshRequiredOnInsert(); |
361 |
return pageContext.refreshRequiredOnInsert(); |
356 |
}; |
362 |
} |
|
|
363 |
; |
357 |
}); |
364 |
}); |
358 |
if(needRequery) { |
365 |
if (needRequery) { |
359 |
SQLExecutionHelper.this.executeQuery(); |
366 |
SQLExecutionHelper.this.executeQuery(); |
360 |
} else { |
367 |
} else { |
361 |
Mutex.EVENT.readAccess(new Runnable() { |
368 |
Mutex.EVENT.readAccess(new Runnable() { |
362 |
@Override |
369 |
@Override |
363 |
public void run() { |
370 |
public void run() { |
364 |
reinstateToolbar(); |
371 |
synchronized (dataView) { |
|
|
372 |
dataView.resetToolbar(false); |
365 |
} |
373 |
} |
|
|
374 |
} |
366 |
}); |
375 |
}); |
367 |
} |
376 |
} |
|
|
377 |
|
378 |
return done; |
368 |
} |
379 |
} |
369 |
}; |
|
|
370 |
RequestProcessor.Task task = rp.create(executor); |
371 |
executor.setTask(task); |
372 |
task.schedule(0); |
373 |
return task; |
374 |
} |
375 |
|
380 |
|
376 |
void executeDeleteRow(final DataViewPageContext pageContext, final DBTable table, final DataViewTableUI rsTable) { |
381 |
void executeDeleteRow(final DataViewPageContext pageContext, final DBTable table, final DataViewTableUI rsTable) { |
377 |
dataView.setEditable(false); |
382 |
dataView.setEditable(false); |