}
public void setRuleForPrincipal(Principal principal, ProfilingRule rule, String locatorName)
{
Transaction tx = persistentStore.getTransaction();
tx.begin();
Filter filter = persistentStore.newFilter();
filter.addEqualTo("principalName", principal);
filter.addEqualTo("locatorName", locatorName);
Object query = persistentStore.newQuery(principalRuleClass, filter);
PrincipalRule pr = (PrincipalRule) persistentStore.getObjectByQuery(query);
if (pr == null)
{
pr = new PrincipalRuleImpl(); // TODO: factory
pr.setPrincipalName(principal.getName());
pr.setLocatorName(locatorName);
pr.setProfilingRule(rule);
}
try
{
pr.setProfilingRule(rule);
persistentStore.lockForWrite(pr);
}
catch (LockFailedException e)
{
tx.rollback();
e.printStackTrace();
// TODO: throw appropriate exception
}
persistentStore.getTransaction().commit();
principalRules.put(makePrincipalRuleKey(principal.getName(), locatorName), pr);