public void actionSaveChanges(CommandRequest request) throws Exception {
//save datasourceEntry changes
setSelectedTables(request.getRequestObject().getParameter("selectedTables"));
actionCreateDatasource(request);
//complete selected tables columns, delete previous introspect and save new introspect
HibernateTxFragment txFragment = new HibernateTxFragment() {
protected void txFragment(Session session) throws Exception {
String[] selectedTableNames = getSelectedTables().split(",");
String deleteHql = "delete from "+DataSourceTableEntry.class.getName() + " where datasource = '"+getName()+"'";
Query deleteQuery = session.createQuery(deleteHql);
deleteQuery.executeUpdate();
for (String tableName : selectedTableNames) {
DataSourceTableEntry tableEntry = new DataSourceTableEntry();
tableEntry.setDatasource(getName());
tableEntry.setName(tableName);
tableEntry.setSelected("true");
session.saveOrUpdate(tableEntry);
}
deleteHql = "delete from " + DataSourceColumnEntry.class.getName() + " where datasource = '"+getName()+"'";
deleteQuery = session.createQuery(deleteHql);
deleteQuery.executeUpdate();
for (String tableName : selectedTableNames) {
List<DataSourceColumnEntry> tableColumns = getTableColumns(tableName);
for (DataSourceColumnEntry columnEntry : tableColumns) {
session.saveOrUpdate(columnEntry);
}
}
}
};
txFragment.execute();
clearParametersHandler();
setCreating(false);
}