logger.debug("IN");
Session aSession = null;
Transaction tx = null;
Integer toReturn = null;
boolean save = true;
SbiThresholdValue sbiThresholdValue = null;
try {
aSession = getSession();
tx = aSession.beginTransaction();
Integer position = thresholdValue.getPosition();
String label = thresholdValue.getLabel();
Double minValue = thresholdValue.getMinValue();
Double maxValue = thresholdValue.getMaxValue();
Boolean minClosed = thresholdValue.getMinClosed();
Boolean maxClosed = thresholdValue.getMaxClosed();
Double value = thresholdValue.getValue();
String colour = "";
colour=thresholdValue.getColourString();
Integer thresholdId = thresholdValue.getThresholdId();
Integer severityId = thresholdValue.getSeverityId();
SbiDomains severity = null;
if (severityId != null) {
severity = (SbiDomains) aSession.load(SbiDomains.class,
severityId);
}
SbiThreshold threshold = null;
if (thresholdId != null) {
threshold = (SbiThreshold) aSession.load(SbiThreshold.class,
thresholdId);
}
Integer thrValId = thresholdValue.getId();
if(thrValId!=null && !thrValId.equals(new Integer(0))){
save = false;
try{
sbiThresholdValue = (SbiThresholdValue) aSession.load(SbiThresholdValue.class, thrValId);
Hibernate.initialize(sbiThresholdValue);
toReturn = thrValId;
if(sbiThresholdValue == null || (sbiThresholdValue != null && sbiThresholdValue.getIdThresholdValue() == null)){
sbiThresholdValue = new SbiThresholdValue();
save = true;
}
}catch(Throwable ex){
sbiThresholdValue = new SbiThresholdValue();
save = true;
}
}else{
sbiThresholdValue = new SbiThresholdValue();
}
if(sbiThresholdValue == null || (sbiThresholdValue != null && sbiThresholdValue.getIdThresholdValue() == null)){
//previously deleted
//reinsert
sbiThresholdValue = new SbiThresholdValue();
save = true;
}
sbiThresholdValue.setPosition(position);
sbiThresholdValue.setLabel(label);
sbiThresholdValue.setMinValue(minValue);
sbiThresholdValue.setMaxValue(maxValue);
sbiThresholdValue.setColour(colour);
sbiThresholdValue.setMinClosed(minClosed);
sbiThresholdValue.setMaxClosed(maxClosed);
sbiThresholdValue.setThValue(value);
sbiThresholdValue.setSbiThreshold(threshold);
sbiThresholdValue.setSeverity(severity);
if(save){
//save
toReturn = (Integer)aSession.save(sbiThresholdValue);
sbiThresholdValue.setIdThresholdValue(toReturn);
}else{
//update
aSession.saveOrUpdate(sbiThresholdValue);
}