汇联通执法队后台管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestHsqldbClient.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Date: 2011-6-18
  3. * author: Peream (peream@gmail.com)
  4. *
  5. */
  6. package tests;
  7. import java.io.File;
  8. import java.io.IOException;
  9. import java.util.List;
  10. import java.util.Map;
  11. import java.util.Map.Entry;
  12. import java.util.concurrent.TimeUnit;
  13. import org.junit.Test;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.test.context.ContextConfiguration;
  16. import cn.com.taiji.common.pub.FileCopyTools;
  17. import cn.com.yskj.zfdm.dao.HsqlDBInitDao;
  18. /**
  19. *
  20. * @author Peream <br>
  21. * Create Time:2011-6-18 下午07:46:15<br>
  22. * <a href="mailto:peream@gmail.com">peream@gmail.com</a>
  23. * @since 1.0
  24. * @version 1.0
  25. */
  26. @ContextConfiguration(locations = { "classpath:tests/hsqldb.xml" })
  27. public class TestHsqldbClient extends MyBaseTest
  28. {
  29. private static final String SPACE = "\t";
  30. @Autowired
  31. private HsqlDBInitDao dao;
  32. @Test
  33. public void queryForList()
  34. {
  35. String sql = "select * from acl_resource limit 500";
  36. List<Map<String, Object>> list = dao.queryForList(sql);
  37. int i = 1;
  38. System.out.println(getRowTitle(list));
  39. for (Map<String, Object> row : list)
  40. {
  41. System.out.print(i + SPACE);
  42. for (Entry<String, Object> en : row.entrySet())
  43. {
  44. System.out.print(en.getValue() + SPACE);
  45. }
  46. System.out.println();
  47. i++;
  48. }
  49. System.out.println();
  50. }
  51. @Test
  52. public void update() throws Exception
  53. {
  54. String sql = "delete from acl_role where id='zfdm' ";
  55. int count = dao.update(sql);
  56. System.out.println("受影响的记录数:" + count);
  57. // sleep 一段时间等待语句生效
  58. TimeUnit.SECONDS.sleep(1);
  59. }
  60. @Test
  61. public void init() throws Exception
  62. {
  63. File file = new File("resources/sql/hsqldb_init.sql");
  64. initFile(file);
  65. file = new File("resources/sql/init_data.sql");
  66. initFile(file);
  67. // sleep 一段时间等待初始化完成,很重要!!!,记得查看log,看完成没
  68. TimeUnit.SECONDS.sleep(10);
  69. }
  70. private void initFile(File file) throws IOException
  71. {
  72. List<String> list = FileCopyTools.copyToLines(file, "UTF-8", true);
  73. // List<String> list = Lists.newArrayList("delete from comm_ftp_line");
  74. for (String sql : list)
  75. {
  76. if (sql.startsWith("#") || sql.startsWith("--") || sql.startsWith("commit")) continue;
  77. System.out.println(sql);
  78. dao.execute(sql);
  79. }
  80. }
  81. private String getRowTitle(List<Map<String, Object>> rows)
  82. {
  83. if (rows.size() == 0) return "\n未查询到符合条件的记录";
  84. StringBuilder title = new StringBuilder("\n序号" + SPACE);
  85. for (Entry<String, Object> en : rows.get(0).entrySet())
  86. {
  87. title.append(en.getKey()).append(SPACE);
  88. }
  89. return title.toString();
  90. }
  91. }