/** * Persists this object to the database by storing its data as XML blobs. * * @throws PropertyException when the operations fails. */ public void persist() throws PropertyException { try { // first check if we have to create/update the property defintion or merely // have to add an PropertyLookup entry for it. if (!existingPropertyDef) { // we are dealing with a property definition that was defined in this // uol. So create/up the definition and optionally add the property lookup try { // try to find find the property definition pdf = new PropertyDefFacade(uolId, propId); // update this definition pdf.setDto(dto); } catch (FinderException ex) { // no PropertyDef was found, so create a new PropertyDef pdf = new PropertyDefFacade(dto); // set the values for this definitions dto = pdf.getDto(); // create an entry for this PropertyDefEntity the PropertyLookUp new PropertyLookUpFacade(uolId, propId, dto.getPropDefPK(), dto.getDataType()); } } else { // The definition was created outside this uol so only the lookup table needs to be altered. PropertyLookUpFacade plf; // check if the lookup already exists try { plf = new PropertyLookUpFacade(uolId, propId); // found, remove the lookup record plf.remove(); } catch (FinderException ex1) { // nothing needs to happen } // not found or removed, create an new entry for this existing PropertyDefEntity new PropertyLookUpFacade(uolId, propId, dto.getPropDefPK(), dto.getDataType()); } } catch (CreateException ex) { throw new PropertyException(ex); } catch (RemoveException ex) { throw new PropertyException(ex); } }
/** * This constructor creates a PropertyDef based on the parameters passed. If no corresponding * PropertyDef was persisted a FinderException was thrown. * * @param uolId int * @param propId String * @throws PropertyException */ PropertyDef(int uolId, String propId) throws PropertyException { try { // the property defintion should be created/updated when persisiting this.existingPropertyDef = false; this.uolId = uolId; this.propId = propId; // try to find find the property definition pdf = new PropertyDefFacade(uolId, propId); // get the dto for future reference dto = pdf.getDto(); // inform about intitialization onInit(); // create the data container for this definition unpack(uolId, dto.getDefaultValue()); } catch (FinderException ex) { throw new PropertyNotFoundException(ex); } }
/** * Returns the XML blob representing the default value in XML format to be used when initialising * properties based on this PropertyDefintion. This method is called when a new Property based on * this PropertyDefinition is created. * * @return String the XML default value to used when creating Property instances. */ protected String getXmlBlobValue() { if (dto == null) { dto = pdf.getDto(); } return dto.getDefaultValue(); }
/** * Returns the primary key of this PropertyDefintion in the database. * * @return int the primary key in the database of this PropertyDefintion. */ public int getPropDefPK() { return pdf.getDto().getPropDefPK(); }