@@ -0,0 +1,2891 @@
+package com.twilio.ivrrecording.repositories;%0A%0Aimport javax.persistence.EntityManager;%0Aimport javax.persistence.EntityTransaction;%0Aimport javax.persistence.Persistence;%0Aimport javax.persistence.Query;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0A@SuppressWarnings(%22unused%22)%0Apublic abstract class Repository%3CT%3E %7B%0A%0A    protected final EntityManager em;%0A    protected final Class%3CT%3E entityType;%0A%0A    public Repository(Class%3CT%3E entity) %7B%0A%0A        entityType = entity;%0A%0A        Map%3CString, String%3E properties = getProperties();%0A        em = Persistence%0A                .createEntityManagerFactory(%22airtng%22, properties)%0A                .createEntityManager();%0A    %7D%0A%0A    /**%0A     * Returns all instances of the type.%0A     *%0A     * @return all entities%0A     */%0A    @SuppressWarnings(%22unchecked%22)%0A    public Iterable%3CT%3E findAll() %7B%0A        Query query = em.createQuery(%0A                String.format(%22SELECT e FROM %25s e%22, entityType.getSimpleName()));%0A%0A        return query.getResultList();%0A    %7D%0A%0A    /**%0A     * Retrieves an entity by its id.%0A     *%0A     * @param id The given id.%0A     * @return the entity with the given id%0A     */%0A    public T find(long id) %7B%0A        T entity = em.find(entityType, id);%0A        em.refresh(entity);%0A%0A        return entity;%0A    %7D%0A%0A    /**%0A     * Saves a given entity. Use the returned instance for further operations.%0A     *%0A     * @param entity The entity%0A     * @return the saved entity%0A     */%0A    public T create(T entity) %7B%0A        getTransaction().begin();%0A        em.persist(entity);%0A        getTransaction().commit();%0A%0A        return entity;%0A    %7D%0A%0A    /**%0A     * Updates a given entity. Use the returned instance for further operations.%0A     *%0A     * @param entity The entity%0A     * @return the updated entity%0A     */%0A    public T update(T entity) %7B%0A        getTransaction().begin();%0A        T updatedEntity = em.merge(entity);%0A        getTransaction().commit();%0A%0A        return updatedEntity;%0A    %7D%0A%0A    /**%0A     * Deletes the entity.%0A     *%0A     * @param entity The entity%0A     */%0A    public void delete(T entity) %7B%0A        getTransaction().begin();%0A        em.remove(entity);%0A        getTransaction().commit();%0A    %7D%0A%0A    private EntityTransaction getTransaction() %7B%0A        return em.getTransaction();%0A    %7D%0A%0A    private Map%3CString, String%3E getProperties() %7B%0A        Map%3CString, String%3E env = System.getenv();%0A        Map%3CString, String%3E config = new HashMap%3C%3E();%0A        for (String key : env.keySet()) %7B%0A            if (key.contains(%22JDBC_URL%22)) %7B%0A                config.put(%22javax.persistence.jdbc.url%22, env.get(key));%0A            %7D%0A%0A            if (key.contains(%22DB_USER%22)) %7B%0A                config.put(%22javax.persistence.jdbc.user%22, env.get(key));%0A            %7D%0A%0A            if (key.contains(%22DB_PASSWORD%22)) %7B%0A                config.put(%22javax.persistence.jdbc.password%22, env.get(key));%0A            %7D%0A        %7D%0A%0A        return config;%0A    %7D%0A%7D

Add Base Repository