use of org.jboss.weld.examples.pastecode.model.CodeFragment in project core by weld.
the class CodeFragmentManagerImpl method getCodeFragment.
public CodeFragment getCodeFragment(String id) {
// If it's not an integer, it's a hash!
if (!isInteger(id)) {
Query query = entityManager.createQuery("SELECT c FROM CodeFragment c WHERE hash = :hash");
query.setParameter("hash", id);
@SuppressWarnings("unchecked") List<CodeFragment> fragments = query.getResultList();
if (fragments.size() == 0) {
throw new RuntimeException("No such fragment!");
} else {
return fragments.get(0);
}
} else {
CodeFragment c = entityManager.find(CodeFragment.class, Integer.parseInt(id));
if (c == null) {
throw new RuntimeException("No such fragment!");
}
// If no hash was set, then this is not a private fragment, return it!
if (c.getHash() == null) {
return c;
} else {
throw new RuntimeException("Access denied!");
}
}
}
Aggregations