Search in sources :

Example 1 with Transactional

use of com.querydsl.example.sql.guice.Transactional in project querydsl by querydsl.

the class TweetRepository method save.

@Transactional
public Long save(Tweet tweet, Long... mentions) {
    Long tweetId = save(tweet);
    SQLInsertClause insert = insert(tweetUser);
    for (Long mentionsId : mentions) {
        TweetUser tu = new TweetUser();
        tu.setTweetId(tweetId);
        tu.setMentionsId(mentionsId);
        insert.populate(tu).addBatch();
    }
    insert.execute();
    return tweetId;
}
Also used : TweetUser(com.querydsl.example.sql.model.TweetUser) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) Transactional(com.querydsl.example.sql.guice.Transactional)

Example 2 with Transactional

use of com.querydsl.example.sql.guice.Transactional in project querydsl by querydsl.

the class AbstractPersistenceTest method before.

@Before
@Transactional
public void before() {
    try (Connection connection = dataSource.getConnection()) {
        List<String> tables = new ArrayList<String>();
        DatabaseMetaData md = connection.getMetaData();
        ResultSet rs = md.getTables(null, null, null, new String[] { "TABLE" });
        try {
            while (rs.next()) {
                tables.add(rs.getString("TABLE_NAME"));
            }
        } finally {
            rs.close();
        }
        java.sql.Statement stmt = connection.createStatement();
        try {
            stmt.execute("SET REFERENTIAL_INTEGRITY FALSE");
            for (String table : tables) {
                stmt.execute("TRUNCATE TABLE " + table);
            }
            stmt.execute("SET REFERENTIAL_INTEGRITY TRUE");
        } finally {
            stmt.close();
        }
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData) Before(org.junit.Before) Transactional(com.querydsl.example.sql.guice.Transactional)

Aggregations

Transactional (com.querydsl.example.sql.guice.Transactional)2 TweetUser (com.querydsl.example.sql.model.TweetUser)1 SQLInsertClause (com.querydsl.sql.dml.SQLInsertClause)1 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1