if (ctx.getRealmId() == null)
{
throw new IllegalStateException("Realm Id not present");
}
HibernateRealm realm = null;
// If store is not realm aware return null to create/get objects accessible from other realms
if (!isRealmAware())
{
realm = (HibernateRealm)hibernateSession.
createCriteria(HibernateRealm.class).add(Restrictions.eq("name", DEFAULT_REALM_NAME)).uniqueResult();
if (realm == null)
{
throw new IllegalStateException("Default store realm is not present: " + DEFAULT_REALM_NAME);
}
}
else
{
realm = (HibernateRealm)hibernateSession.
createCriteria(HibernateRealm.class).add(Restrictions.eq("name", ctx.getRealmId())).uniqueResult();
// TODO: other way to not lazy initialize realm? special method called on every new session creation
if (realm == null)
{
HibernateRealm newRealm = new HibernateRealm(ctx.getRealmId());
hibernateSession.persist(newRealm);
return newRealm;
}
}