Lines 180-191
Link Here
|
180 |
DataViewDBTable dvTable = new DataViewDBTable(tables); |
180 |
DataViewDBTable dvTable = new DataViewDBTable(tables); |
181 |
dataView.getDataViewPageContext().getModel().setColumns( |
181 |
dataView.getDataViewPageContext().getModel().setColumns( |
182 |
dvTable.getColumns().toArray(new DBColumn[0])); |
182 |
dvTable.getColumns().toArray(new DBColumn[0])); |
183 |
dataView.setDataViewDBTable(dvTable); |
183 |
dataView.getDataViewPageContext().setTableMetaData(dvTable); |
184 |
if (resultSetNeedsReloading(dvTable)) { |
184 |
if (resultSetNeedsReloading(dvTable)) { |
185 |
executeSQLStatement(stmt, sql); |
185 |
executeSQLStatement(stmt, sql); |
186 |
rs = stmt.getResultSet(); |
186 |
rs = stmt.getResultSet(); |
187 |
} |
187 |
} |
188 |
loadDataFrom(rs); |
188 |
loadDataFrom(dvTable, rs); |
189 |
|
189 |
|
190 |
if (Thread.interrupted()) { |
190 |
if (Thread.interrupted()) { |
191 |
return; |
191 |
return; |
Lines 258-270
Link Here
|
258 |
} |
258 |
} |
259 |
} |
259 |
} |
260 |
|
260 |
|
261 |
RequestProcessor.Task executeInsertRow(final String insertSQL, final Object[] insertedRow) { |
261 |
RequestProcessor.Task executeInsertRow(final DBTable table, final String insertSQL, final Object[] insertedRow) { |
262 |
String title = NbBundle.getMessage(SQLExecutionHelper.class, "LBL_sql_insert"); |
262 |
String title = NbBundle.getMessage(SQLExecutionHelper.class, "LBL_sql_insert"); |
263 |
SQLStatementExecutor executor = new SQLStatementExecutor(dataView, title, "") { |
263 |
SQLStatementExecutor executor = new SQLStatementExecutor(dataView, title, "") { |
264 |
|
264 |
|
265 |
@Override |
265 |
@Override |
266 |
public void execute() throws SQLException, DBException { |
266 |
public void execute() throws SQLException, DBException { |
267 |
dataView.setEditable(false); |
267 |
dataView.setEditable(false); |
|
|
268 |
List<DBColumn> columns = table.getColumnList(); |
268 |
PreparedStatement pstmt = conn.prepareStatement(insertSQL); |
269 |
PreparedStatement pstmt = conn.prepareStatement(insertSQL); |
269 |
try { |
270 |
try { |
270 |
int pos = 1; |
271 |
int pos = 1; |
Lines 272-284
Link Here
|
272 |
Object val = insertedRow[i]; |
273 |
Object val = insertedRow[i]; |
273 |
|
274 |
|
274 |
// Check for Constant e.g <NULL>, <DEFAULT>, <CURRENT_TIMESTAMP> etc |
275 |
// Check for Constant e.g <NULL>, <DEFAULT>, <CURRENT_TIMESTAMP> etc |
275 |
if (DataViewUtils.isSQLConstantString(val, |
276 |
if (DataViewUtils.isSQLConstantString(val, columns.get(i))) { |
276 |
dataView.getDataViewDBTable().getColumn(i))) { |
|
|
277 |
continue; |
277 |
continue; |
278 |
} |
278 |
} |
279 |
|
279 |
|
280 |
// literals |
280 |
// literals |
281 |
int colType = dataView.getDataViewDBTable().getColumnType(i); |
281 |
int colType = columns.get(i).getJdbcType(); |
282 |
DBReadWriteHelper.setAttributeValue(pstmt, pos++, colType, val); |
282 |
DBReadWriteHelper.setAttributeValue(pstmt, pos++, colType, val); |
283 |
} |
283 |
} |
284 |
|
284 |
|
Lines 321-337
Link Here
|
321 |
return task; |
321 |
return task; |
322 |
} |
322 |
} |
323 |
|
323 |
|
324 |
void executeDeleteRow(final DataViewTableUI rsTable) { |
324 |
void executeDeleteRow(final DBTable table, final DataViewTableUI rsTable) { |
325 |
// @todo enhance to be able to work with more than one table |
|
|
326 |
assert dataView.getDataViewDBTable().getTableCount() == 1 : "Deletes only supported for single table in resultset"; |
327 |
|
328 |
String title = NbBundle.getMessage(SQLExecutionHelper.class, "LBL_sql_delete"); |
325 |
String title = NbBundle.getMessage(SQLExecutionHelper.class, "LBL_sql_delete"); |
329 |
final int[] rows = rsTable.getSelectedRows(); |
326 |
final int[] rows = rsTable.getSelectedRows(); |
330 |
for(int i = 0; i < rows.length; i++) { |
327 |
for(int i = 0; i < rows.length; i++) { |
331 |
rows[i] = rsTable.convertRowIndexToModel(rows[i]); |
328 |
rows[i] = rsTable.convertRowIndexToModel(rows[i]); |
332 |
} |
329 |
} |
333 |
Arrays.sort(rows); |
330 |
Arrays.sort(rows); |
334 |
final DBTable table = dataView.getDataViewDBTable().getTable(0); |
331 |
|
335 |
SQLStatementExecutor executor = new SQLStatementExecutor(dataView, title, "") { |
332 |
SQLStatementExecutor executor = new SQLStatementExecutor(dataView, title, "") { |
336 |
|
333 |
|
337 |
@Override |
334 |
@Override |
Lines 391-401
Link Here
|
391 |
task.schedule(0); |
388 |
task.schedule(0); |
392 |
} |
389 |
} |
393 |
|
390 |
|
394 |
void executeUpdateRow(final DataViewTableUI rsTable, final boolean selectedOnly) { |
391 |
void executeUpdateRow(final DBTable table, final DataViewTableUI rsTable, final boolean selectedOnly) { |
395 |
// @todo enhance to be able to work with more than one table |
392 |
|
396 |
assert dataView.getDataViewDBTable().getTableCount() == 1 : "Updates only supported for single table in resultset"; |
|
|
397 |
|
398 |
final DBTable table = dataView.getDataViewDBTable().getTable(0); |
399 |
final DataViewTableUIModel dataViewTableUIModel = rsTable.getModel(); |
393 |
final DataViewTableUIModel dataViewTableUIModel = rsTable.getModel(); |
400 |
String title = NbBundle.getMessage(SQLExecutionHelper.class, "LBL_sql_update"); |
394 |
String title = NbBundle.getMessage(SQLExecutionHelper.class, "LBL_sql_update"); |
401 |
SQLStatementExecutor executor = new SQLStatementExecutor(dataView, title, "") { |
395 |
SQLStatementExecutor executor = new SQLStatementExecutor(dataView, title, "") { |
Lines 485-491
Link Here
|
485 |
} |
479 |
} |
486 |
|
480 |
|
487 |
// Truncate is allowed only when there is single table used in the query. |
481 |
// Truncate is allowed only when there is single table used in the query. |
488 |
void executeTruncate() { |
482 |
void executeTruncate(final DBTable dbTable) { |
489 |
String msg = NbBundle.getMessage(SQLExecutionHelper.class, "MSG_truncate_table_progress"); |
483 |
String msg = NbBundle.getMessage(SQLExecutionHelper.class, "MSG_truncate_table_progress"); |
490 |
String title = NbBundle.getMessage(SQLExecutionHelper.class, "LBL_sql_truncate"); |
484 |
String title = NbBundle.getMessage(SQLExecutionHelper.class, "LBL_sql_truncate"); |
491 |
SQLStatementExecutor executor = new SQLStatementExecutor(dataView, title, msg) { |
485 |
SQLStatementExecutor executor = new SQLStatementExecutor(dataView, title, msg) { |
Lines 494-502
Link Here
|
494 |
|
488 |
|
495 |
@Override |
489 |
@Override |
496 |
public void execute() throws SQLException, DBException { |
490 |
public void execute() throws SQLException, DBException { |
497 |
|
|
|
498 |
|
499 |
DBTable dbTable = dataView.getDataViewDBTable().getTable(0); |
500 |
String truncateSql = "TRUNCATE TABLE " + dbTable.getFullyQualifiedName(true); // NOI18N |
491 |
String truncateSql = "TRUNCATE TABLE " + dbTable.getFullyQualifiedName(true); // NOI18N |
501 |
|
492 |
|
502 |
try { |
493 |
try { |
Lines 563-569
Link Here
|
563 |
executeSQLStatement(stmt, sql); |
554 |
executeSQLStatement(stmt, sql); |
564 |
if (dataView.hasResultSet()) { |
555 |
if (dataView.hasResultSet()) { |
565 |
ResultSet rs = stmt.getResultSet(); |
556 |
ResultSet rs = stmt.getResultSet(); |
566 |
loadDataFrom(rs); |
557 |
loadDataFrom(dataView.getDataViewPageContext().getTableMetaData(), |
|
|
558 |
rs); |
567 |
|
559 |
|
568 |
if (getTotal) { |
560 |
if (getTotal) { |
569 |
Integer result = null; |
561 |
Integer result = null; |
Lines 633-639
Link Here
|
633 |
task.schedule(0); |
625 |
task.schedule(0); |
634 |
} |
626 |
} |
635 |
|
627 |
|
636 |
void loadDataFrom(ResultSet rs) throws SQLException { |
628 |
void loadDataFrom(DataViewDBTable tblMeta, ResultSet rs) throws SQLException { |
637 |
if (rs == null) { |
629 |
if (rs == null) { |
638 |
return; |
630 |
return; |
639 |
} |
631 |
} |
Lines 641-647
Link Here
|
641 |
int pageSize = dataView.getDataViewPageContext().getPageSize(); |
633 |
int pageSize = dataView.getDataViewPageContext().getPageSize(); |
642 |
int startFrom = dataView.getDataViewPageContext().getCurrentPos(); |
634 |
int startFrom = dataView.getDataViewPageContext().getCurrentPos(); |
643 |
|
635 |
|
644 |
DataViewDBTable tblMeta = dataView.getDataViewDBTable(); |
|
|
645 |
List<Object[]> rows = new ArrayList<Object[]>(); |
636 |
List<Object[]> rows = new ArrayList<Object[]>(); |
646 |
int colCnt = tblMeta.getColumnCount(); |
637 |
int colCnt = tblMeta.getColumnCount(); |
647 |
try { |
638 |
try { |