try {
aSession = getSession();
tx = aSession.beginTransaction();
SbiDataSetHistory hibDataSet =null;
if(dataSet!=null && dataSet.getActiveDetail()!=null){
GuiDataSetDetail dataSetActiveDetail = dataSet.getActiveDetail();
if(dataSetActiveDetail instanceof FileDataSetDetail){
hibDataSet=new SbiFileDataSet();
if(((FileDataSetDetail)dataSetActiveDetail).getFileName()!=null){
((SbiFileDataSet)hibDataSet).setFileName(((FileDataSetDetail)dataSetActiveDetail).getFileName());
}
}
else if(dataSetActiveDetail instanceof QueryDataSetDetail){
hibDataSet=new SbiQueryDataSet();
if(((QueryDataSetDetail)dataSetActiveDetail).getQuery()!=null){
((SbiQueryDataSet)hibDataSet).setQuery(((QueryDataSetDetail)dataSetActiveDetail).getQuery().toString());
}
if(((QueryDataSetDetail)dataSetActiveDetail).getDataSourceLabel()!=null){
SbiDataSource hibDataSource = null;
String dataSourceLabel = ((QueryDataSetDetail)dataSetActiveDetail).getDataSourceLabel();
Criterion labelCriterrion = Expression.eq("label", dataSourceLabel);
Criteria criteria = aSession.createCriteria(SbiDataSource.class);
criteria.add(labelCriterrion);
hibDataSource = (SbiDataSource) criteria.uniqueResult();
((SbiQueryDataSet)hibDataSet).setDataSource(hibDataSource);
}
}
else if(dataSetActiveDetail instanceof QbeDataSetDetail){
hibDataSet = new SbiQbeDataSet();
SbiQbeDataSet hibQbeDataSet = (SbiQbeDataSet) hibDataSet;
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 = aSession.createCriteria(SbiDataSource.class);
criteria.add(labelCriterrion);
SbiDataSource hibDataSource = (SbiDataSource) criteria.uniqueResult();
hibQbeDataSet.setDataSource(hibDataSource);
}
else if(dataSetActiveDetail instanceof WSDataSetDetail){
hibDataSet=new SbiWSDataSet();
if(((WSDataSetDetail)dataSetActiveDetail).getAddress()!=null){
((SbiWSDataSet)hibDataSet).setAdress(((WSDataSetDetail)dataSetActiveDetail).getAddress());
}
if(((WSDataSetDetail)dataSetActiveDetail).getOperation()!=null){
((SbiWSDataSet)hibDataSet).setOperation(((WSDataSetDetail)dataSetActiveDetail).getOperation());
}
}
else if(dataSetActiveDetail instanceof JClassDataSetDetail){
hibDataSet=new SbiJClassDataSet();
if(((JClassDataSetDetail)dataSetActiveDetail).getJavaClassName()!=null){
((SbiJClassDataSet)hibDataSet).setJavaClassName(((JClassDataSetDetail)dataSetActiveDetail).getJavaClassName());
}
}
else if(dataSetActiveDetail instanceof ScriptDataSetDetail){
hibDataSet=new SbiScriptDataSet();
if(((ScriptDataSetDetail)dataSetActiveDetail).getScript()!=null){
((SbiScriptDataSet)hibDataSet).setScript(((ScriptDataSetDetail)dataSetActiveDetail).getScript());
}
if(((ScriptDataSetDetail)dataSetActiveDetail).getLanguageScript()!=null){
((SbiScriptDataSet)hibDataSet).setLanguageScript(((ScriptDataSetDetail)dataSetActiveDetail).getLanguageScript());
}
}
SbiDomains transformer = null;
if (dataSetActiveDetail.getTransformerId() != null){
Criterion aCriterion = Expression.eq("valueId", dataSetActiveDetail.getTransformerId());
Criteria criteria = aSession.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 = aSession.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();
SbiDataSetConfig dsConfig = new SbiDataSetConfig();
dsConfig.setLabel(dataSet.getLabel());
dsConfig.setDescription(dataSet.getDescription());
dsConfig.setName(dataSet.getName());
updateSbiCommonInfo4Insert(dsConfig);
String userIn = dsConfig.getCommonInfo().getUserIn();
String sbiVersionIn = dsConfig.getCommonInfo().getSbiVersionIn();
hibDataSet.setUserIn(userIn);
hibDataSet.setSbiVersionIn(sbiVersionIn);
hibDataSet.setVersionNum(1);
hibDataSet.setTimeIn(currentTStamp);
hibDataSet.setActive(true);
hibDataSet.setTransformer(transformer);
hibDataSet.setPivotColumnName(dataSetActiveDetail.getPivotColumnName());
hibDataSet.setPivotRowName(dataSetActiveDetail.getPivotRowName());
hibDataSet.setPivotColumnValue(dataSetActiveDetail.getPivotColumnValue());
hibDataSet.setNumRows(dataSetActiveDetail.isNumRows());
hibDataSet.setCategory(category);
hibDataSet.setParameters(dataSetActiveDetail.getParameters());
hibDataSet.setDsMetadata(dataSetActiveDetail.getDsMetadata());
Integer dsId =(Integer) aSession.save(dsConfig);
dsConfig.setDsId(dsId);
hibDataSet.setSbiDsConfig(dsConfig);