}
SbiDataSetHistory hibDataSetHistory =null;
if(dataSet!=null){
// get active dataset
GuiDataSetDetail dataSetActiveDetail = dataSet.getActiveDetail();
if(dataSetActiveDetail instanceof FileDataSetDetail){
hibDataSetHistory=new SbiFileDataSet();
if(((FileDataSetDetail)dataSetActiveDetail).getFileName()!=null){
((SbiFileDataSet)hibDataSetHistory).setFileName(((FileDataSetDetail)dataSetActiveDetail).getFileName());
}
}
else if(dataSetActiveDetail instanceof QueryDataSetDetail){
hibDataSetHistory=new SbiQueryDataSet();
if(((QueryDataSetDetail)dataSetActiveDetail).getQuery()!=null){
((SbiQueryDataSet)hibDataSetHistory).setQuery(((QueryDataSetDetail)dataSetActiveDetail).getQuery().toString());
}
if(((QueryDataSetDetail)dataSetActiveDetail).getDataSourceLabel()!=null){
SbiDataSource hibDataSource = null;
String dataSourceLabel = ((QueryDataSetDetail)dataSetActiveDetail).getDataSourceLabel();
if(dataSourceLabel!=null && !dataSourceLabel.equals("")){
IDataSourceDAO dataSourceDao = DAOFactory.getDataSourceDAO();
IDataSource ds = dataSourceDao.loadDataSourceByLabel(dataSourceLabel);
insertDataSource(ds, session);
Criterion labelCriterrion = Expression.eq("label", dataSourceLabel);
Criteria criteria = session.createCriteria(SbiDataSource.class);
criteria.add(labelCriterrion);
hibDataSource = (SbiDataSource) criteria.uniqueResult();
((SbiQueryDataSet)hibDataSetHistory).setDataSource(hibDataSource);
}
}
}else if(dataSetActiveDetail instanceof QbeDataSetDetail){
hibDataSetHistory = new SbiQbeDataSet();
SbiQbeDataSet hibQbeDataSet = (SbiQbeDataSet) hibDataSetHistory;
QbeDataSetDetail qbeDataSet = (QbeDataSetDetail) dataSetActiveDetail;
hibQbeDataSet.setSqlQuery(qbeDataSet.getSqlQuery());
hibQbeDataSet.setJsonQuery(qbeDataSet.getJsonQuery());
hibQbeDataSet.setDatamarts(qbeDataSet.getDatamarts());
String dataSourceLabel = qbeDataSet.getDataSourceLabel();
Criterion labelCriterrion = Expression.eq("label", dataSourceLabel);
Criteria criteria = session.createCriteria(SbiDataSource.class);
criteria.add(labelCriterrion);
SbiDataSource hibDataSource = (SbiDataSource) criteria.uniqueResult();
hibQbeDataSet.setDataSource(hibDataSource);
}
else if(dataSetActiveDetail instanceof WSDataSetDetail){
hibDataSetHistory=new SbiWSDataSet();
if(((WSDataSetDetail)dataSetActiveDetail).getAddress()!=null){
((SbiWSDataSet)hibDataSetHistory).setAdress(((WSDataSetDetail)dataSetActiveDetail).getAddress());
}
if(((WSDataSetDetail)dataSetActiveDetail).getOperation()!=null){
((SbiWSDataSet)hibDataSetHistory).setOperation(((WSDataSetDetail)dataSetActiveDetail).getOperation());
}
}
else if(dataSetActiveDetail instanceof JClassDataSetDetail){
hibDataSetHistory=new SbiJClassDataSet();
if(((JClassDataSetDetail)dataSetActiveDetail).getJavaClassName()!=null){
((SbiJClassDataSet)hibDataSetHistory).setJavaClassName(((JClassDataSetDetail)dataSetActiveDetail).getJavaClassName());
}
}
else if(dataSetActiveDetail instanceof ScriptDataSetDetail){
hibDataSetHistory=new SbiScriptDataSet();
if(((ScriptDataSetDetail)dataSetActiveDetail).getScript()!=null){
((SbiScriptDataSet)hibDataSetHistory).setScript(((ScriptDataSetDetail)dataSetActiveDetail).getScript());
}
if(((ScriptDataSetDetail)dataSetActiveDetail).getLanguageScript()!=null){
((SbiScriptDataSet)hibDataSetHistory).setLanguageScript(((ScriptDataSetDetail)dataSetActiveDetail).getLanguageScript());
}
}
SbiDomains transformer = null;
if (dataSetActiveDetail.getTransformerId() != null){
Criterion aCriterion = Expression.eq("valueId", dataSetActiveDetail.getTransformerId());
Criteria criteria = session.createCriteria(SbiDomains.class);
criteria.add(aCriterion);
transformer = (SbiDomains) criteria.uniqueResult();
if (transformer == null){
logger.error("The Domain with value_id= "+dataSetActiveDetail.getTransformerId()+" does not exist.");
throw new EMFUserError(EMFErrorSeverity.ERROR, 1035);
}
}
SbiDomains category = null;
if (dataSetActiveDetail.getCategoryId()!= null){
Criterion aCriterion = Expression.eq("valueId", dataSetActiveDetail.getCategoryId());
Criteria criteria = session.createCriteria(SbiDomains.class);
criteria.add(aCriterion);
category = (SbiDomains) criteria.uniqueResult();
if (category == null){
logger.error("The Domain with value_id= "+dataSetActiveDetail.getCategoryId()+" does not exist.");
throw new EMFUserError(EMFErrorSeverity.ERROR, 1035);
}
}
Date currentTStamp = new Date();
// Fill dataset config values
SbiDataSetConfig hibDataSetConfig = new SbiDataSetConfig();
hibDataSetConfig.setDsId(dataSet.getDsId());
hibDataSetConfig.setLabel(dataSet.getLabel());
hibDataSetConfig.setDescription(dataSet.getDescription());
hibDataSetConfig.setName(dataSet.getName());
tx = session.beginTransaction();
session.save(hibDataSetConfig);
tx.commit();
// Fill Data set history values
hibDataSetHistory.setSbiDsConfig(hibDataSetConfig);
if(dataSetActiveDetail.getDsHId()!=0){
hibDataSetHistory.setDsHId(dataSetActiveDetail.getDsHId());
}
hibDataSetHistory.setVersionNum(1);
hibDataSetHistory.setActive(true);
hibDataSetHistory.setTransformer(transformer);
hibDataSetHistory.setPivotColumnName(dataSetActiveDetail.getPivotColumnName());
hibDataSetHistory.setPivotRowName(dataSetActiveDetail.getPivotRowName());
hibDataSetHistory.setPivotColumnValue(dataSetActiveDetail.getPivotColumnValue());
hibDataSetHistory.setNumRows(dataSetActiveDetail.isNumRows());
hibDataSetHistory.setCategory(category);
hibDataSetHistory.setParameters(dataSetActiveDetail.getParameters());
hibDataSetHistory.setDsMetadata(dataSetActiveDetail.getDsMetadata());
tx2 = session.beginTransaction();
session.save(hibDataSetHistory);
tx2.commit();
}