All Downloads are FREE. Search and download functionalities are using the official Maven repository.

brainslug.jpa.Database Maven / Gradle / Ivy

The newest version!
package brainslug.jpa;

import com.mysema.query.jpa.JPQLTemplates;
import com.mysema.query.jpa.impl.JPADeleteClause;
import com.mysema.query.jpa.impl.JPAQuery;
import com.mysema.query.jpa.impl.JPAUpdateClause;
import com.mysema.query.types.EntityPath;

import javax.persistence.EntityManager;

public class Database {

  private final EntityManager entityManager;
  private final JPQLTemplates jpqlDialect;

  public Database(EntityManager entityManager, JPQLTemplates jpqlTemplates) {
    this.entityManager = entityManager;
    this.jpqlDialect = jpqlTemplates;
  }

  public JPAQuery query() {
    return new JPAQuery(entityManager, jpqlDialect);
  }

  public JPAUpdateClause update(EntityPath entity) {
    return new JPAUpdateClause(entityManager, entity);
  }

  public  T insertOrUpdate(T entity) {
    entityManager.persist(entity);
    flush();
    return entity;
  }

  public void flush() {
    entityManager.flush();
  }

  public  T unwrap(Class clazz) {
    return entityManager.unwrap(clazz);
  }

  public JPADeleteClause delete(EntityPath path) {
    return new JPADeleteClause(entityManager, path, jpqlDialect);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy