This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[x | x <- (zip [1..] ['A'..'Z']), even (fst x)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void configure() { | |
RefreshEntityInterceptor refreshEntityInterceptor = new RefreshEntityInterceptor(); | |
requestInjection(refreshEntityInterceptor); | |
bindInterceptor(Matchers.any(), Matchers.annotatedWith(RefreshEntity.class), refreshEntityInterceptor); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RefreshEntityInterceptor implements MethodInterceptor { | |
@Inject | |
private Provider<EntityManager> entityManagerProvider; | |
@Inject | |
protected Logger logger; | |
@SuppressWarnings("unchecked") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Retention(RetentionPolicy.RUNTIME) | |
@Target(ElementType.METHOD) | |
public @interface RefreshEntity { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RefreshEntity | |
public List<SchoolBus> findAll() { | |
CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder(); | |
CriteriaQuery<SchoolBus> criteriaQuery = criteriaBuilder.createQuery(SchoolBus.class); | |
Root<SchoolBus> table = criteriaQuery.from(SchoolBus.class); | |
TypedQuery<SchoolBus> query = getEntityManager().createQuery(criteriaQuery.select(table).orderBy(criteriaBuilder.asc(table.get("busNumber")))); | |
return query.getResultList(); | |
} | |
@RefreshEntity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<SchoolBus> findAll() { | |
CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder(); | |
CriteriaQuery<SchoolBus> criteriaQuery = criteriaBuilder.createQuery(SchoolBus.class); | |
Root<SchoolBus> table = criteriaQuery.from(SchoolBus.class); | |
TypedQuery<SchoolBus> query = getEntityManager().createQuery(criteriaQuery.select(table).orderBy(criteriaBuilder.asc(table.get("busNumber")))); | |
refreshSchoolBuses(query.getResultList()); | |
return query.getResultList(); | |
} | |
public SchoolBus findById(Long id) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<SchoolBus> findAll() { | |
CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder(); | |
CriteriaQuery<SchoolBus> criteriaQuery = criteriaBuilder.createQuery(SchoolBus.class); | |
Root<SchoolBus> table = criteriaQuery.from(SchoolBus.class); | |
TypedQuery<SchoolBus> query = getEntityManager().createQuery(criteriaQuery.select(table).orderBy(criteriaBuilder.asc(table.get("busNumber")))); | |
/* | |
/ Refresh all the school buses | |
*/ | |
for (SchoolBus schoolBus : query.getResultList()) { | |
schoolBus.getStudents().clear(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Transactional | |
public void save(Object entity) { | |
getEntityManager().persist(entity); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void save(Object entity) { | |
final EntityTransaction transaction = getEntityManager().getTransaction(); | |
transaction.begin(); | |
try { | |
getEntityManager().persist(entity); | |
transaction.commit(); | |
} catch (Throwable e) { | |
transaction.rollback(); | |
throw new RuntimeException(e); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def config-file (ref nil)) | |
(def data (ref [])) | |
(defn -main [& args] | |
(let [{:keys [config] inputs}] (cli args ["--config" "Config file"]) | |
(dosync (ref-set config-file config)) | |
(println @config-file) | |
(dosync (ref-set data [1 2 3])) | |
(println @data))) |