1 25 package org.ofbiz.shark.instance; 26 27 import org.ofbiz.entity.GenericDelegator; 28 import org.ofbiz.entity.GenericValue; 29 import org.ofbiz.entity.GenericEntityException; 30 import org.ofbiz.base.util.UtilMisc; 31 import org.ofbiz.base.util.Debug; 32 import org.ofbiz.shark.container.SharkContainer; 33 34 import org.enhydra.shark.api.internal.instancepersistence.*; 35 36 43 public class Resource extends InstanceEntityObject implements ResourcePersistenceInterface { 44 45 public static final String module = Resource.class.getName(); 46 47 protected GenericValue resource = null; 48 protected boolean newValue = false; 49 50 protected Resource(EntityPersistentMgr mgr, GenericDelegator delegator, String name) throws PersistenceException { 51 super(mgr, delegator); 52 if (this.delegator != null) { 53 try { 54 this.resource = delegator.findByPrimaryKey("WfResource", UtilMisc.toMap("userName", name)); 55 } catch (GenericEntityException e) { 56 throw new PersistenceException(e); 57 } 58 } else { 59 Debug.logError("Invalid delegator object passed", module); 60 } 61 } 62 63 protected Resource(EntityPersistentMgr mgr, GenericValue resource) { 64 super(mgr, resource.getDelegator()); 65 this.resource = resource; 66 } 67 68 public Resource(EntityPersistentMgr mgr, GenericDelegator delegator) { 69 super(mgr, delegator); 70 this.newValue = true; 71 this.resource = delegator.makeValue("WfResource", null); 72 } 73 74 public static Resource getInstance(EntityPersistentMgr mgr, GenericValue resource) { 75 Resource res = new Resource(mgr, resource); 76 if (res.isLoaded()) { 77 return res; 78 } 79 return null; 80 } 81 82 public static Resource getInstance(EntityPersistentMgr mgr, String name) throws PersistenceException { 83 Resource res = new Resource(mgr, SharkContainer.getDelegator(), name); 84 if (res.isLoaded()) { 85 return res; 86 } 87 return null; 88 } 89 90 public boolean isLoaded() { 91 if (resource == null) { 92 return false; 93 } 94 return true; 95 } 96 97 public void setUsername(String s) { 98 resource.set("userName", s); 99 } 100 101 public String getUsername() { 102 return resource.getString("userName"); 103 } 104 105 public void setName(String s) { 106 resource.set("resourceName", s); 107 } 108 109 public String getName() { 110 return resource.getString("resourceName"); 111 } 112 113 public void store() throws GenericEntityException { 114 if (newValue) { 115 delegator.createOrStore(resource); 116 newValue = false; 117 } else { 118 delegator.store(resource); 119 } 120 } 121 122 public void reload() throws GenericEntityException { 123 if (!newValue) { 124 resource.refresh(); 125 } 126 } 127 128 public void remove() throws GenericEntityException { 129 if (!newValue) { 130 delegator.removeValue(resource); 131 Debug.log("**** REMOVED : " + this, module); 132 } 133 } 134 } 135 | Popular Tags |