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[] arrTableName=getSelectedTables().split(",");
String deleteHql = "delete from "+DataSourceTableEntry.class.getName() + " where datasource = '"+getName()+"'";
Query deleteQuery = session.createQuery(deleteHql);
deleteQuery.executeUpdate();
for(int i=0;i<arrTableName.length;i++){
DataSourceTableEntry tableEntry = new DataSourceTableEntry();
tableEntry.setDatasource(getName());
tableEntry.setName(arrTableName[i]);
tableEntry.setSelected("true");
session.saveOrUpdate(tableEntry);
}
deleteHql = "delete from " + DataSourceColumnEntry.class.getName() + " where datasource = '"+getName()+"'";
deleteQuery = session.createQuery(deleteHql);
deleteQuery.executeUpdate();
for(int i=0;i<arrTableName.length;i++){
List tableColumns = getTableColumns(arrTableName[i]);
Iterator it = tableColumns.iterator();
while(it.hasNext()){
DataSourceColumnEntry columnEntry = (DataSourceColumnEntry) it.next();
session.saveOrUpdate(columnEntry);
}
}
}
};
txFragment.execute();
clearParametersHandler();
setCreating(false);
}