igel wrote:
I tryed release you technology but had some errors (or mistakes).
Could you write more examples: BusinessAction class and mapping for class that uses BusinessAction?
BusinessAction.java:
Code:
public class BusinessAction implements Serializable
{
private UniqueKey id = null;
private String name;
private transient String cachedToString = null;
public UniqueKey getId()
{
return id;
}
public String getName()
{
return name;
}
public boolean equals(Object o)
{
if (this == o) return true;
if (!(o instanceof BusinessAction)) return false;
final BusinessAction businessAction = (BusinessAction) o;
if (name != null ? !name.equals(businessAction.name) : businessAction.name != null) return false;
return true;
}
public int hashCode()
{
return (name != null ? name.hashCode() : 0);
}
public String toString()
{
if (null == this.cachedToString)
{
StringBuffer result = new StringBuffer("BusinessAction@{")
.append("id: ").append(id)
.append(", name: ").append(name)
.append("}");
this.cachedToString = result.toString();
}
return this.cachedToString;
}
}
BusinessPermission.java (class has BusinessAction association):
Code:
public class BusinessPermission implements Serializable, IModelObject
{
public static final BusinessPermission EMPTY = new BusinessPermission();
private UniqueKey id = null;
private BusinessAction businessAction;
private BusinessClass businessClass;
/**
* Lazily initialized, cached hashCode.
* see item 8 of "Effective Jave".
*/
private volatile int hashCode = 0;
public BusinessPermission()
{
}
public BusinessPermission(BusinessAction businessAction, BusinessClass businessClass)
{
if (null == businessAction)
throw new NullPointerException("Argument businessAction is null!");
if (null == businessAction.getId())
throw new IllegalArgumentException("Argument businessAction.getId() is null!");
if (null == businessClass)
throw new NullPointerException("Argument businessClass is null!");
if (null == businessClass.getId())
throw new IllegalArgumentException("Argument businessClass.getId() is null!");
this.businessAction = businessAction;
this.businessClass = businessClass;
}
public UniqueKey getId()
{
return id;
}
public BusinessAction getBusinessAction()
{
return businessAction;
}
public BusinessClass getBusinessClass()
{
return businessClass;
}
public boolean equals(Object o)
{
if (this == o) return true;
if (!(o instanceof BusinessPermission)) return false;
final BusinessPermission businessPermission = (BusinessPermission) o;
if (businessAction != null ? !businessAction.equals(businessPermission.businessAction) : businessPermission.businessAction != null) return false;
if (businessClass != null ? !businessClass.equals(businessPermission.businessClass) : businessPermission.businessClass != null) return false;
return true;
}
public int hashCode()
{
if (0 == hashCode)
{
int result = 17;
result = 37 * result + (businessAction != null ? businessAction.hashCode() : 0);
result = 37 * result + (businessClass != null ? businessClass.hashCode() : 0);
hashCode = result;
}
return hashCode;
}
public String toString()
{
StringBuffer result = new StringBuffer("BusinessPermission@{")
.append("id: ").append(id)
.append(", businessAction: ").append(businessAction)
.append(", businessClass: ").append(businessClass)
.append("}");
return result.toString();
}
}
BusinessPermission mapping:
Code:
<hibernate-mapping>
<class name="ru.xxx.common.security.BusinessPermission" table="`BusinessPermission`"
batch-size="100" mutable="false">
<cache usage="nonstrict-read-write"/>
<id name="id" column="`BusinessPermissionId`" type="ru.xxx.hibernate.UniqueKeyType" access="field">
<generator class="ru.xxx.hibernate.UniqueKeyGenerator"/>
</id>
<many-to-one name="businessAction" column="`BusinessActionId`" access="field" cascade="none"
class="ru.xxx.common.security.BusinessAction" outer-join="false"/>
<many-to-one name="businessClass" column="`BusinessClassId`" access="field" cascade="none"
class="ru.xxx.common.security.BusinessClass" outer-join="false"/>
</class>
</hibernate-mapping>
cache configuration (ehcache.xml):
Code:
<ehcache>
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="false"
/>
<cache name="ru.xxx.common.security.BusinessClass"
maxElementsInMemory="10"
eternal="true"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="false"
/>
<cache name="ru.xxx.common.security.BusinessAction"
maxElementsInMemory="10"
eternal="true"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="false"
/>
<cache name="ru.xxx.common.security.BusinessPermission"
maxElementsInMemory="100"
eternal="true"
timeToIdleSeconds="600"
timeToLiveSeconds="2400"
overflowToDisk="false"
/>
</ehcache>