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;
}
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);
}
}
Aggregations