Integer idToReturn = null;
try {
aSession = getSession();
tx = aSession.beginTransaction();
SbiObjects hibBIObject = new SbiObjects();
// add the common info
SbiEngines hibEngine = (SbiEngines) aSession.load(SbiEngines.class, obj.getEngine().getId());
hibBIObject.setSbiEngines(hibEngine);
hibBIObject.setDescr(obj.getDescription());
hibBIObject.setLabel(obj.getLabel());
hibBIObject.setName(obj.getName());
if(obj.getEncrypt()!=null){
hibBIObject.setEncrypt(new Short(obj.getEncrypt().shortValue()));
}
if(obj.getVisible()!=null){
hibBIObject.setVisible(new Short(obj.getVisible().shortValue()));
}
hibBIObject.setProfiledVisibility(obj.getProfiledVisibility());
hibBIObject.setRelName(obj.getRelName());
SbiDomains hibState = (SbiDomains) aSession.load(SbiDomains.class, obj.getStateID());
hibBIObject.setState(hibState);
hibBIObject.setStateCode(obj.getStateCode());
SbiDomains hibObjectType = (SbiDomains) aSession.load(SbiDomains.class, obj.getBiObjectTypeID());
hibBIObject.setObjectType(hibObjectType);
hibBIObject.setObjectTypeCode(obj.getBiObjectTypeCode());
SbiDataSource dSource = null;
if (obj.getDataSourceId() != null) {
dSource = (SbiDataSource) aSession.load(SbiDataSource.class, obj.getDataSourceId());
}
hibBIObject.setDataSource(dSource);
SbiDataSetConfig dSet= null;
if (obj.getDataSetId() != null) {
dSet = (SbiDataSetConfig) aSession.load(SbiDataSetConfig.class, obj.getDataSetId());
}
hibBIObject.setDataSet(dSet);
Integer refreshSeconds=obj.getRefreshSeconds();
if(refreshSeconds==null)refreshSeconds=new Integer(0);
hibBIObject.setRefreshSeconds(refreshSeconds);
// uuid generation
UUIDGenerator uuidGenerator = UUIDGenerator.getInstance();
UUID uuidObj = uuidGenerator.generateTimeBasedUUID();
String uuid = uuidObj.toString();
hibBIObject.setUuid(uuid);
hibBIObject.setCreationDate(new Date());
hibBIObject.setCreationUser(obj.getCreationUser());
updateSbiCommonInfo4Insert(hibBIObject);
// save biobject
Integer id = (Integer) aSession.save(hibBIObject);
idToReturn = id;
// recover the saved hibernate object
hibBIObject = (SbiObjects) aSession.load(SbiObjects.class, id);
// functionalities storing
Set hibObjFunc = new HashSet();
List functionalities = obj.getFunctionalities();
for (Iterator it = functionalities.iterator(); it.hasNext(); ) {
Integer functId = (Integer) it.next();
SbiFunctions aSbiFunctions = (SbiFunctions) aSession.load(SbiFunctions.class, functId);
SbiObjFuncId aSbiObjFuncId = new SbiObjFuncId();
aSbiObjFuncId.setSbiFunctions(aSbiFunctions);
aSbiObjFuncId.setSbiObjects(hibBIObject);
SbiObjFunc aSbiObjFunc = new SbiObjFunc(aSbiObjFuncId);
updateSbiCommonInfo4Insert(aSbiObjFunc);
aSession.save(aSbiObjFunc);
hibObjFunc.add(aSbiObjFunc);
}
hibBIObject.setSbiObjFuncs(hibObjFunc);
// we must close transaction before saving ObjTemplate, since ObjTemplateDAO opens a new transaction and it would fail in Ingres
tx.commit();
obj.setId(id);