本文整理汇总了Java中org.springframework.test.jdbc.JdbcTestUtils.deleteFromTables方法的典型用法代码示例。如果您正苦于以下问题:Java JdbcTestUtils.deleteFromTables方法的具体用法?Java JdbcTestUtils.deleteFromTables怎么用?Java JdbcTestUtils.deleteFromTables使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.test.jdbc.JdbcTestUtils
的用法示例。
在下文中一共展示了JdbcTestUtils.deleteFromTables方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ddlOrDelete
import org.springframework.test.jdbc.JdbcTestUtils; //导入方法依赖的package包/类
private void ddlOrDelete() {
try {
final int pathsCount = JdbcTestUtils.countRowsInTable(jdbcTemplate, NAMES_TABLE);
if (pathsCount > 0) {
JdbcTestUtils.deleteFromTables(jdbcTemplate, NAMES_TABLE);
}
} catch (BadSqlGrammarException e) {
switch (e.getSQLException().getErrorCode()) {
case ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1:
jdbcTemplate.execute(new StringBuilder()
.append("CREATE TABLE ").append(NAMES_TABLE).append(" (\n")
.append(" id INT PRIMARY KEY,\n")
.append(" name VARCHAR,\n")
.append(" automat VARCHAR\n")
.append(");").toString());
break;
default:
throw e;
}
}
}
示例2: doTearDown
import org.springframework.test.jdbc.JdbcTestUtils; //导入方法依赖的package包/类
public final void doTearDown() {
try {
solrServer.deleteByQuery("*:*");
JdbcTestUtils.deleteFromTables(jdbc, tableNames());
} catch (SolrServerException | IOException e) {
logger.error("Error tearing down test data");
e.printStackTrace();
}
}
示例3: beforeTestClass
import org.springframework.test.jdbc.JdbcTestUtils; //导入方法依赖的package包/类
@Override
public void beforeTestClass(TestContext testContext) throws Exception {
ApplicationContext applicationContext = testContext.getApplicationContext();
DataSource dataSource = applicationContext.getBean("dataSource", DataSource.class);
JdbcTestUtils.deleteFromTables(new JdbcTemplate(dataSource), "claim");
}
示例4: setUp
import org.springframework.test.jdbc.JdbcTestUtils; //导入方法依赖的package包/类
@Before
public void setUp() {
JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "SERVICETICKET");
JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "TICKETGRANTINGTICKET");
}
示例5: deleteFromTables
import org.springframework.test.jdbc.JdbcTestUtils; //导入方法依赖的package包/类
protected int deleteFromTables(String... names) {
return JdbcTestUtils.deleteFromTables(this.jdbcTemplate, names);
}
示例6: savePathsIntoDb
import org.springframework.test.jdbc.JdbcTestUtils; //导入方法依赖的package包/类
private void savePathsIntoDb(List<Path> paths) throws SQLException {
LOG.info("--- savePathsIntoDb ---");
try {
final int pathsCount = JdbcTestUtils.countRowsInTable(jdbcTemplate, PATHS_TABLE);
if (pathsCount > 0) {
JdbcTestUtils.deleteFromTables(jdbcTemplate, PATHS_TABLE);
}
} catch (BadSqlGrammarException e) {
switch (e.getSQLException().getErrorCode()) {
case ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1:
jdbcTemplate.execute(new StringBuilder()
.append("CREATE TABLE ").append(PATHS_TABLE).append(" (\n")
.append(" id INT PRIMARY KEY AUTO_INCREMENT,\n")
.append(" source_uid INT,\n")
.append(" target_uid INT,\n")
.append(" distance DOUBLE,\n")
.append(" bbox VARCHAR,\n")
.append(" weight DOUBLE,\n")
.append(" time INT,\n")
.append(" points CLOB\n")
.append(");").toString());
jdbcTemplate.execute(String.format("CREATE UNIQUE INDEX IDX_source_target ON %s (source_uid, target_uid);", PATHS_TABLE));
jdbcTemplate.execute(String.format("CREATE INDEX IDX_source_uid ON %s (source_uid);", PATHS_TABLE));
jdbcTemplate.execute(String.format("CREATE INDEX IDX_target_uid ON %s (target_uid);", PATHS_TABLE));
jdbcTemplate.execute(String.format("CREATE INDEX IDX_distance ON %s (distance);", PATHS_TABLE));
jdbcTemplate.execute(String.format("CREATE INDEX IDX_time ON %s (time);", PATHS_TABLE));
break;
default:
throw e;
}
}
final String insertSql = "INSERT INTO " + PATHS_TABLE + " (source_uid, target_uid, distance, bbox, weight, time, points) VALUES (?, ?, ?, ?, ?, ?, ?)";
jdbcTemplate.batchUpdate(insertSql, paths, paths.size(), (ps, argument) -> {
ps.setInt(1, argument.source.uid);
ps.setInt(2, argument.target.uid);
ps.setDouble(3, argument.distance);
ps.setString(4, Joiner.on(',').join(argument.bbox));
ps.setDouble(5, argument.weight);
ps.setInt(6, argument.time);
ps.setString(7, argument.points);
});
// System.out.println(JdbcTestUtils.countRowsInTable(jdbcTemplate, PATHS_TABLE));
// List<Map<String, Object>> list = jdbcTemplate.queryForList("SELECT * FROM " + PATHS_TABLE);
// for (Map<String, Object> map : list) {
// System.out.println(map);
// }
}
示例7: beforeTestMethod
import org.springframework.test.jdbc.JdbcTestUtils; //导入方法依赖的package包/类
@Override
public void beforeTestMethod(final TestContext testContext) throws Exception {
JdbcTestUtils.deleteFromTables(getJdbcTemplate(testContext.getApplicationContext()), "pets", "people");
log.info("Deleted data from tables: 'pets', 'people'...");
}
示例8: afterPropertiesSet
import org.springframework.test.jdbc.JdbcTestUtils; //导入方法依赖的package包/类
/**
* One-time test initialization.
*
* @throws Exception On setup errors.
*/
public void afterPropertiesSet() throws Exception {
JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "locks");
}
示例9: deleteFromTables
import org.springframework.test.jdbc.JdbcTestUtils; //导入方法依赖的package包/类
/**
* Convenience method for deleting all rows from the specified tables.
* <p>Use with caution outside of a transaction!
* @param names the names of the tables from which to delete
* @return the total number of rows deleted from all specified tables
* @see JdbcTestUtils#deleteFromTables
*/
protected int deleteFromTables(String... names) {
return JdbcTestUtils.deleteFromTables(this.jdbcTemplate, names);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:AbstractTransactionalTestNGSpringContextTests.java
示例10: deleteFromTables
import org.springframework.test.jdbc.JdbcTestUtils; //导入方法依赖的package包/类
/**
* Convenience method for deleting all rows from the specified tables. Use
* with caution outside of a transaction!
* @param names the names of the tables from which to delete
* @return the total number of rows deleted from all specified tables
*/
protected int deleteFromTables(String... names) {
return JdbcTestUtils.deleteFromTables(this.jdbcTemplate, names);
}