New implementation with PersistableEntity of the Car object | Existing implementation with Entity of the Car object |
package persistenceexample4.datafactory; |
package persistenceexample2.datafactory; import persistenceexample2.Constants; import com.sap.ip.me.api.persist.app.Entity; import com.sap.ip.me.api.persist.core.PersistenceException; import com.sap.ip.me.api.persist.core.PersistedObject; /** * Car entity - represents the car type (manufacturer) * A Car entity can have a relation to one License entity */ public class Car implements Entity { final static String CLASSTYPE = "Car-Query"; final String entityKey; private String make; private String model; private String enginetype; private int cylinders; private int valvespercylinder; License license; /** * Constructor for the Car object *@param entityKey - String that contains the car type */ Car(String entityKey) { this.entityKey = entityKey; } /** * Gets the entityKey attribute of the Car object *@return The entityKey value */ public String getEntityKey() { return this.entityKey; } /** * Gets the classtype attribute of the Car object * @return The classtype value */ public String getClasstype() { return CLASSTYPE; } /** * Sets the instance attribute of the Car object *@param persistedObject The new instance value *@exception EntityPersistenceException Description of the Exception */ public void setInstance(PersistedObject persistedObject) throws PersistenceException { this.make = (String) persistedObject.getAttribute(0); this.model = (String) persistedObject.getAttribute(1); this.enginetype = (String) persistedObject.getAttribute(2); Integer integer_value = (Integer) persistedObject.getAttribute(3); this.cylinders = integer_value.intValue(); integer_value = (Integer) persistedObject.getAttribute(4); this.valvespercylinder = integer_value.intValue(); this.license = (License)persistedObject.getLink(0); } /** * Method setIntValue. * @param string * @return int */ private int setIntValue(String string) { int i = 0; if (string != null) { if (string.length() > 0) { i = Integer.parseInt(string); } } return i; } /** * Gets the instance attribute of the Car object *@param persistedObject Description of the Parameter *@exception EntityPersistenceException Description of the Exception */ public void getInstance(PersistedObject persistedObject) throws PersistenceException { persistedObject.setAttribute(0, this.make); persistedObject.setAttribute(1, this.model); persistedObject.setAttribute(2, this.enginetype); Integer integer_value = new Integer(this.cylinders); persistedObject.setAttribute(3, integer_value); integer_value = new Integer(this.valvespercylinder); persistedObject.setAttribute(4, integer_value); persistedObject.setLink(0, this.license); } public void setValues(String make, String mod, String engtyp, int cylnum, int valves) { this.make = make; this.model = mod; this.enginetype = engtyp; this.cylinders = cylnum; this.valvespercylinder = valves; } /** * Sets the license attribute of the Car object *@param License The new License value */ void setLicense(License license) { this.license = license; } public String toString() { // ** See comment at end of coding for HTML encoding return this.entityKey.toString(); } public String licToString() { String lic = Constants.NOT_REGISTERED;; if (this.license != null) { lic = this.license.toString(); } // ** See comment at end of coding for HTML encoding return lic; } public String modelToString() { String st = Constants.NOT_SPECIFIED; if (this.model != null) { st = this.model.toString(); } // ** See comment at end of coding for HTML encoding return st; } public String makeToString() { String st = Constants.NOT_SPECIFIED; if (this.make != null) { st = this.make.toString(); } // ** See comment at end of coding for HTML encoding return Encoding.encodeForHtml(st); } public String engineToString() { String st = Constants.NOT_SPECIFIED; if (this.enginetype != null) { st = this.enginetype.toString(); } // ** See comment at end of coding for HTML encoding return st; } public String cylToString() { String st = Constants.NOT_SPECIFIED; if (this.cylinders != 0) { st = this.cylinders.toString(); } return st; } public String valveToString() { String st = Constants.NOT_SPECIFIED; if (this.valvespercylinder != 0) { st = this.valvespercylinder.toString(); } return st; } } // ** Comment for JSP // The returned string can be converted into a HTML // compliant/encoded string at this point by using the // encodeForHtml(value) method of the ME HttpServlet // For example: return MyServlet.encodeForHtml(rawText); |