play.db.jpa.JPAApi

Here are the examples of the java api play.db.jpa.JPAApi taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

6 Examples 7

19 Source : PostRepositoryImpl.java
with Apache License 2.0
from vladmihalcea

public clreplaced PostRepositoryImpl implements PostRepository {

    private final JPAApi jpaApi;

    private final DatabaseExecutionContext executionContext;

    private final HypersistenceOptimizer hypersistenceOptimizer;

    @Inject
    public PostRepositoryImpl(JPAApi jpaApi, DatabaseExecutionContext executionContext) {
        this.jpaApi = jpaApi;
        this.executionContext = executionContext;
        Map<String, EnreplacedyManagerFactory> emfs = ReflectionUtils.getFieldValue(jpaApi, "emfs");
        this.hypersistenceOptimizer = new HypersistenceOptimizer(new JpaConfig(emfs.get("default")));
    }

    @Override
    public CompletionStage<Post> save(Post post) {
        return supplyAsync(() -> wrap(em -> persist(em, post)), executionContext);
    }

    @Override
    public CompletionStage<Stream<Post>> findAll() {
        return supplyAsync(() -> wrap(this::stream), executionContext);
    }

    private <T> T wrap(Function<EnreplacedyManager, T> function) {
        return jpaApi.withTransaction(function);
    }

    private Post persist(EnreplacedyManager em, Post post) {
        em.persist(post);
        return post;
    }

    private Stream<Post> stream(EnreplacedyManager em) {
        return em.createQuery("select p from Post p", Post.clreplaced).getResultList().stream();
    }
}

19 Source : JPAPostRepository.java
with Creative Commons Zero v1.0 Universal
from playframework

/**
 * A repository that provides a non-blocking API with a custom execution context
 * and circuit breaker.
 */
@Singleton
public clreplaced JPAPostRepository implements PostRepository {

    private final JPAApi jpaApi;

    private final PostExecutionContext ec;

    private final CircuitBreaker circuitBreaker = new CircuitBreaker().withFailureThreshold(1).withSuccessThreshold(3);

    @Inject
    public JPAPostRepository(JPAApi api, PostExecutionContext ec) {
        this.jpaApi = api;
        this.ec = ec;
    }

    @Override
    public CompletionStage<Stream<PostData>> list() {
        return supplyAsync(() -> wrap(em -> select(em)), ec);
    }

    @Override
    public CompletionStage<PostData> create(PostData postData) {
        return supplyAsync(() -> wrap(em -> insert(em, postData)), ec);
    }

    @Override
    public CompletionStage<Optional<PostData>> get(Long id) {
        return supplyAsync(() -> wrap(em -> Failsafe.with(circuitBreaker).get(() -> lookup(em, id))), ec);
    }

    @Override
    public CompletionStage<Optional<PostData>> update(Long id, PostData postData) {
        return supplyAsync(() -> wrap(em -> Failsafe.with(circuitBreaker).get(() -> modify(em, id, postData))), ec);
    }

    private <T> T wrap(Function<EnreplacedyManager, T> function) {
        return jpaApi.withTransaction(function);
    }

    private Optional<PostData> lookup(EnreplacedyManager em, Long id) throws SQLException {
        throw new SQLException("Call this to cause the circuit breaker to trip");
    // return Optional.ofNullable(em.find(PostData.clreplaced, id));
    }

    private Stream<PostData> select(EnreplacedyManager em) {
        TypedQuery<PostData> query = em.createQuery("SELECT p FROM PostData p", PostData.clreplaced);
        return query.getResultList().stream();
    }

    private Optional<PostData> modify(EnreplacedyManager em, Long id, PostData postData) throws InterruptedException {
        final PostData data = em.find(PostData.clreplaced, id);
        if (data != null) {
            data.replacedle = postData.replacedle;
            data.body = postData.body;
        }
        Thread.sleep(10000L);
        return Optional.ofNullable(data);
    }

    private PostData insert(EnreplacedyManager em, PostData postData) {
        return em.merge(postData);
    }
}

19 Source : JPAPersonRepository.java
with Creative Commons Zero v1.0 Universal
from playframework

/**
 * Provide JPA operations running inside of a thread pool sized to the connection pool
 */
public clreplaced JPAPersonRepository implements PersonRepository {

    private final JPAApi jpaApi;

    private final DatabaseExecutionContext executionContext;

    @Inject
    public JPAPersonRepository(JPAApi jpaApi, DatabaseExecutionContext executionContext) {
        this.jpaApi = jpaApi;
        this.executionContext = executionContext;
    }

    @Override
    public CompletionStage<Person> add(Person person) {
        return supplyAsync(() -> wrap(em -> insert(em, person)), executionContext);
    }

    @Override
    public CompletionStage<Stream<Person>> list() {
        return supplyAsync(() -> wrap(em -> list(em)), executionContext);
    }

    private <T> T wrap(Function<EnreplacedyManager, T> function) {
        return jpaApi.withTransaction(function);
    }

    private Person insert(EnreplacedyManager em, Person person) {
        em.persist(person);
        return person;
    }

    private Stream<Person> list(EnreplacedyManager em) {
        List<Person> persons = em.createQuery("select p from Person p", Person.clreplaced).getResultList();
        return persons.stream();
    }
}

19 Source : PlaySessionFactory.java
with GNU General Public License v2.0
from ia-toki

public clreplaced PlaySessionFactory implements SessionFactory {

    @Inject
    private JPAApi jpaApi;

    @Override
    public SessionFactoryOptions getSessionFactoryOptions() {
        return null;
    }

    @Override
    public SessionBuilder withOptions() {
        return null;
    }

    @Override
    public Session openSession() throws HibernateException {
        return null;
    }

    @Override
    public Session getCurrentSession() throws HibernateException {
        return jpaApi.em().unwrap(Session.clreplaced);
    }

    @Override
    public StatelessSessionBuilder withStatelessOptions() {
        return null;
    }

    @Override
    public StatelessSession openStatelessSession() {
        return null;
    }

    @Override
    public StatelessSession openStatelessSession(Connection connection) {
        return null;
    }

    @Override
    public Statistics getStatistics() {
        return null;
    }

    @Override
    public void close() throws HibernateException {
    }

    @Override
    public boolean isClosed() {
        return false;
    }

    @Override
    public Cache getCache() {
        return null;
    }

    @Override
    public Set getDefinedFilterNames() {
        return null;
    }

    @Override
    public FilterDefinition getFilterDefinition(String filterName) throws HibernateException {
        return null;
    }

    @Override
    public boolean containsFetchProfileDefinition(String name) {
        return false;
    }

    @Override
    public TypeHelper getTypeHelper() {
        return null;
    }

    @Override
    public ClreplacedMetadata getClreplacedMetadata(Clreplaced enreplacedyClreplaced) {
        return null;
    }

    @Override
    public ClreplacedMetadata getClreplacedMetadata(String enreplacedyName) {
        return null;
    }

    @Override
    public CollectionMetadata getCollectionMetadata(String roleName) {
        return null;
    }

    @Override
    public Map<String, ClreplacedMetadata> getAllClreplacedMetadata() {
        return null;
    }

    @Override
    public Map getAllCollectionMetadata() {
        return null;
    }

    @Override
    public Reference getReference() throws NamingException {
        return null;
    }

    @Override
    public <T> List<EnreplacedyGraph<? super T>> findEnreplacedyGraphsByType(Clreplaced<T> enreplacedyClreplaced) {
        return null;
    }

    @Override
    public Metamodel getMetamodel() {
        return null;
    }

    @Override
    public EnreplacedyManager createEnreplacedyManager() {
        return null;
    }

    @Override
    public EnreplacedyManager createEnreplacedyManager(Map map) {
        return null;
    }

    @Override
    public EnreplacedyManager createEnreplacedyManager(SynchronizationType synchronizationType) {
        return null;
    }

    @Override
    public EnreplacedyManager createEnreplacedyManager(SynchronizationType synchronizationType, Map map) {
        return null;
    }

    @Override
    public CriteriaBuilder getCriteriaBuilder() {
        return null;
    }

    @Override
    public boolean isOpen() {
        return false;
    }

    @Override
    public Map<String, Object> getProperties() {
        return null;
    }

    @Override
    public PersistenceUnitUtil getPersistenceUnitUtil() {
        return null;
    }

    @Override
    public void addNamedQuery(String name, Query query) {
    }

    @Override
    public <T> T unwrap(Clreplaced<T> cls) {
        return null;
    }

    @Override
    public <T> void addNamedEnreplacedyGraph(String graphName, EnreplacedyGraph<T> enreplacedyGraph) {
    }
}

18 Source : SandalphonModule.java
with GNU General Public License v2.0
from ia-toki

@Provides
@Singleton
GradingResponseProcessor gradingResponseProcessor(JPAApi jpaApi, ObjectMapper mapper, @Named("sealtiel") BasicAuthHeader sealtielClientAuthHeader, MessageService messageService, SubmissionStore submissionStore) {
    return new GradingResponseProcessor(jpaApi, mapper, submissionStore, sealtielClientAuthHeader, messageService);
}

16 Source : GradingResponseProcessor.java
with GNU General Public License v2.0
from ia-toki

public final clreplaced GradingResponseProcessor {

    private static final Logger LOGGER = LoggerFactory.getLogger(GradingResponseProcessor.clreplaced);

    private static final int MAX_RETRIES = 3;

    private static final Duration DELAY_BETWEEN_RETRIES = Duration.ofSeconds(5);

    private final JPAApi jpaApi;

    private final ObjectMapper mapper;

    private final SubmissionStore submissionStore;

    private final BasicAuthHeader sealtielClientAuthHeader;

    private final MessageService messageService;

    public GradingResponseProcessor(JPAApi jpaApi, ObjectMapper mapper, SubmissionStore submissionStore, BasicAuthHeader sealtielClientAuthHeader, MessageService messageService) {
        this.jpaApi = jpaApi;
        this.mapper = mapper;
        this.submissionStore = submissionStore;
        this.sealtielClientAuthHeader = sealtielClientAuthHeader;
        this.messageService = messageService;
    }

    public void process(Message message) {
        jpaApi.withTransaction(() -> {
            try {
                GradingResponse response = mapper.readValue(message.getContent(), GradingResponse.clreplaced);
                boolean gradingExists = false;
                // it is possible that the grading model is not immediately found, because it is not flushed yet.
                for (int i = 0; i < MAX_RETRIES; i++) {
                    Optional<Submission> submission = submissionStore.updateGrading(response.getGradingJid(), response.getResult());
                    if (submission.isPresent()) {
                        gradingExists = true;
                        messageService.confirmMessage(sealtielClientAuthHeader, message.getId());
                        break;
                    }
                    try {
                        Thread.sleep(DELAY_BETWEEN_RETRIES.toMillis());
                    } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                    }
                }
                if (!gradingExists) {
                    LOGGER.error("Failed to find grading jid {}", response.getGradingJid());
                }
            } catch (Throwable e) {
                LOGGER.error("Failed to process grading response", e);
            }
        });
    }
}