Search in sources :

Example 36 with EntityTransaction

use of javax.persistence.EntityTransaction in project Truck-Factor by aserg-ufmg.

the class NewFileInfoDAO method filterAndUpdateFilesInfo.

//	public void update(FileInfo o){
//		FileInfo persistedProject = this.em.find(FileInfo.class, o.getId());
//		if (persistedProject != null){
//			persistedProject.setFiltered(o.getFiltered());
//			persistedProject.setFilterInfo(o.getFilterInfo());
//			persistedProject.setMode(o.getMode());
//			persistedProject.setPath(o.getPath());
//			persistedProject.setSha(o.getSha());
//			persistedProject.setSize(o.getSize());
//			persistedProject.setType(o.getType());
//			persistedProject.setLanguage(o.getLanguage());
//			super.merge(persistedProject);
//		}
//	}
//	public List<String> getPathsOfNotFilteredProjectFiles(String projectName){
//		String custom = "";
//		     
//		String hql = "SELECT fi.path FROM projectinfo_fileinfo pi_fi "
//				+ "JOIN projectinfo pi ON pi_fi.projectinfo_fullname = pi.fullname "
//				+ "JOIN newfileinfo nfi on pi_fi.files_id = nfi.id "
//				+ "WHERE pi.fullname = \'"+projectName+"\' AND nfi.filtered = 'FALSE' "
//				+ ";";
//				
//		Query q = em.createNativeQuery(hql);
//		return q.getResultList();
//			
//	}
public int filterAndUpdateFilesInfo(String whereClauses, String filterStamp) {
    String custom = "";
    String hql = "UPDATE  newfileinfo AS fi " + "SET filtered = \'TRUE\', filterinfo = \'" + filterStamp + "\'  " + "WHERE " + whereClauses + ";";
    Query q = em.createNativeQuery(hql);
    int rows = 0;
    EntityTransaction tx = this.em.getTransaction();
    try {
        tx.begin();
        rows = q.executeUpdate();
        tx.commit();
    } catch (RuntimeException e) {
        if (tx != null && tx.isActive())
            tx.rollback();
        throw e;
    } finally {
        this.em.clear();
    }
    return rows;
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) Query(javax.persistence.Query)

Example 37 with EntityTransaction

use of javax.persistence.EntityTransaction in project Truck-Factor by aserg-ufmg.

the class NewFileInfoDAO method removeFilterAndUpdateFilesInfo.

public int removeFilterAndUpdateFilesInfo(String whereClauses, String filterStamp) {
    String custom = "";
    String hql = "UPDATE  newfileinfo AS fi " + "SET filtered = \'FALSE\', filterinfo = \'\'  " + "WHERE " + whereClauses + ";";
    Query q = em.createNativeQuery(hql);
    int rows = 0;
    EntityTransaction tx = this.em.getTransaction();
    try {
        tx.begin();
        rows = q.executeUpdate();
        tx.commit();
    } catch (RuntimeException e) {
        if (tx != null && tx.isActive())
            tx.rollback();
        throw e;
    } finally {
        this.em.clear();
    }
    return rows;
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) Query(javax.persistence.Query)

Example 38 with EntityTransaction

use of javax.persistence.EntityTransaction in project Truck-Factor by aserg-ufmg.

the class NewFileInfoDAO method filterAndUpdateFilesInfoByLanguage.

public int filterAndUpdateFilesInfoByLanguage(String whereClauses, String filterStamp) {
    String custom = "";
    String hql = "UPDATE  newfileinfo AS fi " + "SET filtered = \'TRUE\', filterinfo = \'" + filterStamp + "\'  " + "FROM projectinfo AS pi    " + "WHERE pi.fullname = fi.repositoryname AND " + whereClauses + ";";
    Query q = em.createNativeQuery(hql);
    int rows = 0;
    EntityTransaction tx = this.em.getTransaction();
    try {
        tx.begin();
        rows = q.executeUpdate();
        tx.commit();
    } catch (RuntimeException e) {
        if (tx != null && tx.isActive())
            tx.rollback();
        throw e;
    } finally {
        this.em.clear();
    }
    return rows;
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) Query(javax.persistence.Query)

Example 39 with EntityTransaction

use of javax.persistence.EntityTransaction in project Truck-Factor by aserg-ufmg.

the class NewFileInfoDAO method classifierAndUpdateFilesInfo.

public int classifierAndUpdateFilesInfo(String whereClauses, FileType fileType) {
    String custom = "";
    String hql = "UPDATE  newfileinfo AS fi " + "SET kind = \'" + fileType + "\'  " + "WHERE  " + whereClauses + ";";
    Query q = em.createNativeQuery(hql);
    int rows = 0;
    EntityTransaction tx = this.em.getTransaction();
    try {
        tx.begin();
        rows = q.executeUpdate();
        tx.commit();
    } catch (RuntimeException e) {
        if (tx != null && tx.isActive())
            tx.rollback();
        throw e;
    } finally {
        this.em.clear();
    }
    return rows;
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) Query(javax.persistence.Query)

Example 40 with EntityTransaction

use of javax.persistence.EntityTransaction in project hibernate-orm by hibernate.

the class EmbeddableWithNoDeclaredDataTest method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    EntityWithEmbeddableWithNoDeclaredData entity = new EntityWithEmbeddableWithNoDeclaredData();
    entity.setName("Entity 1");
    entity.setValue(new EmbeddableWithNoDeclaredData(84));
    EntityTransaction tx = em.getTransaction();
    tx.begin();
    em.persist(entity);
    tx.commit();
    em.close();
    id = entity.getId();
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Aggregations

EntityTransaction (javax.persistence.EntityTransaction)59 EntityManager (javax.persistence.EntityManager)38 Test (org.junit.Test)12 EntityManagerFactory (javax.persistence.EntityManagerFactory)9 Query (javax.persistence.Query)8 UserTestDbo (org.webpieces.plugins.hibernate.app.dbo.UserTestDbo)6 InumSqlEntry (org.gluu.oxtrust.model.sql.InumSqlEntry)4 Person (org.hibernate.userguide.model.Person)3 TransactionStatus (org.springframework.transaction.TransactionStatus)3 Transactional (com.google.inject.persist.Transactional)2 Priority (org.hibernate.envers.test.Priority)2 DefaultTransactionAttribute (org.springframework.transaction.interceptor.DefaultTransactionAttribute)2 UserDbo (WEBPIECESxPACKAGE.base.libs.UserDbo)1 UserRole (WEBPIECESxPACKAGE.base.libs.UserRole)1 FileType (aserg.gtf.model.FileType)1 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1