Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

SampleDB.java 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. package com.itmill.toolkit.demo.reservation;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8. import java.util.Date;
  9. import java.util.Iterator;
  10. import java.util.List;
  11. import com.itmill.toolkit.data.Container;
  12. import com.itmill.toolkit.data.Item;
  13. import com.itmill.toolkit.data.util.QueryContainer;
  14. public class SampleDB {
  15. public class User {
  16. public static final String TABLE = "USER";
  17. public static final String PROPERTY_ID_ID = TABLE + "_ID";
  18. public static final String PROPERTY_ID_FULLNAME = TABLE + "_FULLNAME";
  19. public static final String PROPERTY_ID_EMAIL = TABLE + "_EMAIL";
  20. public static final String PROPERTY_ID_PASSWORD = TABLE + "_PASSWORD";
  21. public static final String PROPERTY_ID_DELETED = TABLE + "_DELETED";
  22. }
  23. public class Resource {
  24. public static final String TABLE = "RESOURCE";
  25. public static final String PROPERTY_ID_ID = TABLE + "_ID";
  26. public static final String PROPERTY_ID_NAME = TABLE + "_NAME";
  27. public static final String PROPERTY_ID_DESCRIPTION = TABLE
  28. + "_DESCRIPTION";
  29. public static final String PROPERTY_ID_LOCATIONX = TABLE
  30. + "_LOCATION_X";
  31. public static final String PROPERTY_ID_LOCATIONY = TABLE
  32. + "_LOCATION_Y";
  33. public static final String PROPERTY_ID_CATEGORY = TABLE + "_CATEGORY";
  34. public static final String PROPERTY_ID_DELETED = TABLE + "_DELETED";
  35. }
  36. public class Reservation {
  37. public static final String TABLE = "RESERVATION";
  38. public static final String PROPERTY_ID_ID = TABLE + "_ID";
  39. public static final String PROPERTY_ID_DESCRIPTION = TABLE
  40. + "_DESCRIPTION";
  41. public static final String PROPERTY_ID_RESOURCE_ID = TABLE
  42. + "_RESOURCE_ID";
  43. public static final String PROPERTY_ID_RESERVED_BY_ID = TABLE
  44. + "_RESERVED_BY_USER_ID";
  45. public static final String PROPERTY_ID_RESERVED_FROM = TABLE
  46. + "_RESERVED_FROM";
  47. public static final String PROPERTY_ID_RESERVED_TO = TABLE
  48. + "_RESERVED_TO";
  49. }
  50. // TODO -> param
  51. private static final String DB_URL = "jdbc:hsqldb:file:reservation.db";
  52. private static final String CREATE_TABLE_USER = "CREATE TABLE "
  53. + User.TABLE + " (" + " " + User.PROPERTY_ID_ID
  54. + " INTEGER IDENTITY" + ", " + User.PROPERTY_ID_FULLNAME
  55. + " VARCHAR(100) NOT NULL" + ", " + User.PROPERTY_ID_EMAIL
  56. + " VARCHAR(50) NOT NULL" + ", " + User.PROPERTY_ID_PASSWORD
  57. + " VARCHAR(20) NOT NULL" + ", " + User.PROPERTY_ID_DELETED
  58. + " BOOLEAN DEFAULT false NOT NULL" + ", UNIQUE("
  59. + User.PROPERTY_ID_FULLNAME + "), UNIQUE(" + User.PROPERTY_ID_EMAIL
  60. + ") )";
  61. private static final String CREATE_TABLE_RESOURCE = "CREATE TABLE "
  62. + Resource.TABLE + " (" + " " + Resource.PROPERTY_ID_ID
  63. + " INTEGER IDENTITY" + ", " + Resource.PROPERTY_ID_NAME
  64. + " VARCHAR(30) NOT NULL" + ", " + Resource.PROPERTY_ID_DESCRIPTION
  65. + " VARCHAR(100)" + ", " + Resource.PROPERTY_ID_LOCATIONX
  66. + " DOUBLE" + ", " + Resource.PROPERTY_ID_LOCATIONY + " DOUBLE"
  67. + ", " + Resource.PROPERTY_ID_CATEGORY + " VARCHAR(30)" + ", "
  68. + Resource.PROPERTY_ID_DELETED + " BOOLEAN DEFAULT false NOT NULL"
  69. + ", UNIQUE(" + Resource.PROPERTY_ID_NAME + "))";
  70. private static final String CREATE_TABLE_RESERVATION = "CREATE TABLE "
  71. + Reservation.TABLE + " (" + " " + Reservation.PROPERTY_ID_ID
  72. + " INTEGER IDENTITY" + ", " + Reservation.PROPERTY_ID_RESOURCE_ID
  73. + " INTEGER" + ", " + Reservation.PROPERTY_ID_RESERVED_BY_ID
  74. + " INTEGER" + ", " + Reservation.PROPERTY_ID_RESERVED_FROM
  75. + " TIMESTAMP NOT NULL" + ", "
  76. + Reservation.PROPERTY_ID_RESERVED_TO + " TIMESTAMP NOT NULL"
  77. + ", " + Reservation.PROPERTY_ID_DESCRIPTION + " VARCHAR(100)"
  78. + ", FOREIGN KEY (" + Reservation.PROPERTY_ID_RESOURCE_ID
  79. + ") REFERENCES " + Resource.TABLE + "(" + Resource.PROPERTY_ID_ID
  80. + "), FOREIGN KEY (" + Reservation.PROPERTY_ID_RESERVED_BY_ID
  81. + ") REFERENCES " + User.TABLE + "(" + User.PROPERTY_ID_ID + "))";
  82. private Connection connection = null;
  83. /**
  84. * Create database.
  85. */
  86. public SampleDB() {
  87. this(false);
  88. }
  89. public SampleDB(boolean recreate) {
  90. // connect to SQL database
  91. connect();
  92. if (recreate) {
  93. dropTables();
  94. }
  95. // initialize SQL database
  96. createTables();
  97. // test by executing sample JDBC query
  98. testDatabase();
  99. }
  100. private void dropTables() {
  101. try {
  102. update("DROP TABLE " + Reservation.TABLE);
  103. } catch (SQLException IGNORED) {
  104. // IGNORED, assuming it was not there
  105. }
  106. try {
  107. update("DROP TABLE " + Resource.TABLE);
  108. } catch (SQLException IGNORED) {
  109. // IGNORED, assuming it was not there
  110. }
  111. try {
  112. update("DROP TABLE " + User.TABLE);
  113. } catch (SQLException IGNORED) {
  114. // IGNORED, assuming it was not there
  115. }
  116. }
  117. /**
  118. * Connect to SQL database. In this sample we use HSQLDB and an toolkit
  119. * named database in implicitly created into system memory.
  120. *
  121. */
  122. private void connect() {
  123. try {
  124. Class.forName("org.hsqldb.jdbcDriver").newInstance();
  125. connection = DriverManager.getConnection(DB_URL);
  126. } catch (Exception e) {
  127. throw new RuntimeException(e);
  128. }
  129. }
  130. /**
  131. * use for SQL commands CREATE, DROP, INSERT and UPDATE
  132. *
  133. * @param expression
  134. * @throws SQLException
  135. */
  136. private void update(String expression) throws SQLException {
  137. Statement st = null;
  138. st = connection.createStatement();
  139. int i = st.executeUpdate(expression);
  140. if (i == -1) {
  141. System.out.println("SampleDatabase error : " + expression);
  142. }
  143. st.close();
  144. }
  145. /**
  146. * Create test table and few rows. Issue note: using capitalized column
  147. * names as HSQLDB returns column names in capitalized form with this demo.
  148. *
  149. */
  150. private void createTables() {
  151. try {
  152. String stmt = null;
  153. stmt = CREATE_TABLE_RESOURCE;
  154. update(stmt);
  155. } catch (SQLException e) {
  156. if (e.toString().indexOf("Table already exists") == -1)
  157. throw new RuntimeException(e);
  158. }
  159. try {
  160. String stmt = null;
  161. stmt = CREATE_TABLE_USER;
  162. update(stmt);
  163. } catch (SQLException e) {
  164. if (e.toString().indexOf("Table already exists") == -1)
  165. throw new RuntimeException(e);
  166. }
  167. try {
  168. String stmt = null;
  169. stmt = CREATE_TABLE_RESERVATION;
  170. update(stmt);
  171. } catch (SQLException e) {
  172. if (e.toString().indexOf("Table already exists") == -1)
  173. throw new RuntimeException(e);
  174. }
  175. }
  176. /**
  177. * Test database connection with simple SELECT command.
  178. *
  179. */
  180. private String testDatabase() {
  181. String result = null;
  182. try {
  183. Statement stmt = connection.createStatement(
  184. ResultSet.TYPE_SCROLL_INSENSITIVE,
  185. ResultSet.CONCUR_UPDATABLE);
  186. ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM "
  187. + Resource.TABLE);
  188. rs.next();
  189. result = "rowcount for table test is " + rs.getObject(1).toString();
  190. stmt.close();
  191. } catch (SQLException e) {
  192. throw new RuntimeException(e);
  193. }
  194. return result;
  195. }
  196. public Connection getConnection() {
  197. return connection;
  198. }
  199. public Container getCategories() {
  200. // TODO where deleted=?
  201. String q = "SELECT DISTINCT(" + Resource.PROPERTY_ID_CATEGORY
  202. + ") FROM " + Resource.TABLE + " ORDER BY "
  203. + Resource.PROPERTY_ID_CATEGORY;
  204. try {
  205. return new QueryContainer(q, connection,
  206. ResultSet.TYPE_SCROLL_INSENSITIVE,
  207. ResultSet.CONCUR_READ_ONLY);
  208. } catch (SQLException e) {
  209. throw new RuntimeException(e);
  210. }
  211. }
  212. public Container getResources(String category) {
  213. // TODO where deleted=?
  214. String q = "SELECT * FROM " + Resource.TABLE;
  215. if (category != null) {
  216. q += " WHERE " + Resource.PROPERTY_ID_CATEGORY + "='" + category
  217. + "'"; // FIXME ->
  218. // PreparedStatement!
  219. }
  220. try {
  221. return new QueryContainer(q, connection,
  222. ResultSet.TYPE_SCROLL_INSENSITIVE,
  223. ResultSet.CONCUR_READ_ONLY);
  224. } catch (SQLException e) {
  225. throw new RuntimeException(e);
  226. }
  227. }
  228. public Container getReservations(List resources) {
  229. // TODO where reserved_by=?
  230. // TODO where from=?
  231. // TODO where to=?
  232. // TODO where deleted=?
  233. String q = "SELECT * FROM " + Reservation.TABLE + "," + Resource.TABLE;
  234. q += " WHERE " + Reservation.PROPERTY_ID_RESOURCE_ID + "="
  235. + Resource.PROPERTY_ID_ID;
  236. if (resources != null && resources.size() > 0) {
  237. StringBuilder s = new StringBuilder();
  238. for (Iterator it = resources.iterator(); it.hasNext();) {
  239. if (s.length() > 0) {
  240. s.append(",");
  241. }
  242. s.append(((Item) it.next())
  243. .getItemProperty(Resource.PROPERTY_ID_ID));
  244. }
  245. q += " HAVING " + Reservation.PROPERTY_ID_RESOURCE_ID + " IN (" + s
  246. + ")";
  247. }
  248. q += " ORDER BY " + Reservation.PROPERTY_ID_RESERVED_FROM;
  249. try {
  250. QueryContainer qc = new QueryContainer(q, connection,
  251. ResultSet.TYPE_SCROLL_INSENSITIVE,
  252. ResultSet.CONCUR_READ_ONLY);
  253. if (qc.size() < 1) {
  254. return null;
  255. } else {
  256. return qc;
  257. }
  258. } catch (SQLException e) {
  259. throw new RuntimeException(e);
  260. }
  261. }
  262. public void addReservation(Item resource, int reservedById,
  263. Date reservedFrom, Date reservedTo, String description) {
  264. if (reservedFrom.after(reservedTo)) {
  265. Date tmp = reservedTo;
  266. reservedTo = reservedFrom;
  267. reservedFrom = tmp;
  268. }
  269. int resourceId = ((Integer) resource.getItemProperty(
  270. Resource.PROPERTY_ID_ID).getValue()).intValue();
  271. String q = "INSERT INTO " + Reservation.TABLE + " ("
  272. + Reservation.PROPERTY_ID_RESOURCE_ID + ","
  273. + Reservation.PROPERTY_ID_RESERVED_BY_ID + ","
  274. + Reservation.PROPERTY_ID_RESERVED_FROM + ","
  275. + Reservation.PROPERTY_ID_RESERVED_TO + ","
  276. + Reservation.PROPERTY_ID_DESCRIPTION + ")"
  277. + "VALUES (?,?,?,?,?)";
  278. synchronized (DB_URL) {
  279. try {
  280. if (!isAvailableResource(resourceId, reservedFrom, reservedTo)) {
  281. throw new ResourceNotAvailableException(
  282. "The resource is not available at that time.");
  283. }
  284. PreparedStatement p = connection.prepareStatement(q);
  285. p.setInt(1, resourceId);
  286. p.setInt(2, reservedById);
  287. p.setTimestamp(3,
  288. new java.sql.Timestamp(reservedFrom.getTime()));
  289. p.setTimestamp(4, new java.sql.Timestamp(reservedTo.getTime()));
  290. p.setString(5, description);
  291. p.execute();
  292. } catch (Exception e) {
  293. throw new RuntimeException(e);
  294. }
  295. }
  296. }
  297. public boolean isAvailableResource(int resourceId, Date reservedFrom,
  298. Date reservedTo) {
  299. // TODO where deleted=?
  300. if (reservedFrom.after(reservedTo)) {
  301. Date tmp = reservedTo;
  302. reservedTo = reservedFrom;
  303. reservedFrom = tmp;
  304. }
  305. String checkQ = "SELECT count(*) FROM " + Reservation.TABLE + " WHERE "
  306. + Reservation.PROPERTY_ID_RESOURCE_ID + "=? AND (("
  307. + Reservation.PROPERTY_ID_RESERVED_FROM + ">=? AND "
  308. + Reservation.PROPERTY_ID_RESERVED_FROM + "<=?) OR ("
  309. + Reservation.PROPERTY_ID_RESERVED_TO + ">=? AND "
  310. + Reservation.PROPERTY_ID_RESERVED_TO + "<=?) OR ("
  311. + Reservation.PROPERTY_ID_RESERVED_FROM + "<=? AND "
  312. + Reservation.PROPERTY_ID_RESERVED_TO + ">=?)" + ")";
  313. try {
  314. PreparedStatement p = connection.prepareStatement(checkQ);
  315. p.setInt(1, resourceId);
  316. p.setTimestamp(2, new java.sql.Timestamp(reservedFrom.getTime()));
  317. p.setTimestamp(3, new java.sql.Timestamp(reservedTo.getTime()));
  318. p.setTimestamp(4, new java.sql.Timestamp(reservedFrom.getTime()));
  319. p.setTimestamp(5, new java.sql.Timestamp(reservedTo.getTime()));
  320. p.setTimestamp(6, new java.sql.Timestamp(reservedFrom.getTime()));
  321. p.setTimestamp(7, new java.sql.Timestamp(reservedTo.getTime()));
  322. p.execute();
  323. ResultSet rs = p.getResultSet();
  324. if (rs.next() && rs.getInt(1) > 0) {
  325. return false;
  326. }
  327. } catch (Exception e) {
  328. throw new RuntimeException(e);
  329. }
  330. return true;
  331. }
  332. public Container getUsers() {
  333. // TODO where deleted=?
  334. String q = "SELECT * FROM " + User.TABLE + " ORDER BY "
  335. + User.PROPERTY_ID_FULLNAME;
  336. try {
  337. QueryContainer qc = new QueryContainer(q, connection,
  338. ResultSet.TYPE_SCROLL_INSENSITIVE,
  339. ResultSet.CONCUR_READ_ONLY);
  340. return qc;
  341. } catch (SQLException e) {
  342. throw new RuntimeException(e);
  343. }
  344. }
  345. public void generateResources() {
  346. /*
  347. * map.addMarker("Old Mill", new Point.Double(60.452224f,22.299929f));
  348. * map.addMarker("ICT", new Point.Double(60.449007f,22.295508f));
  349. * map.addMarker("DataCity", new Point.Double(60.448329f,22.295165f));
  350. * map.addMarker("BioCity", new Point.Double(60.449451f,22.293105f));
  351. * map.addMarker("PharmaCity", new Point.Double(60.44888f,22.292032f));
  352. * map.addMarker("Intelligate", new Point.Double(60.450403f,22.29495f));
  353. * map.addMarker("Paviljonki", new Point.Double(60.445408f,22.290831f));
  354. * map.addMarker("Trivium", new Point.Double(60.44641962165445f,
  355. * 22.301753170493f)); map.addMarker("Linja-auto asema", new
  356. * Point.Double(60.457049f,22.267957f));
  357. */
  358. /*
  359. * Object[][] resources = { { "IT Mill Toolkit Manual", "the manual",
  360. * "Books", new Double(60.452224),new Double(22.299929)}, { "IT Mill
  361. * Toolkit for Dummies", "the hardcover version", "Books", new
  362. * Double(60.452224),new Double(22.299929) }, { "Sony", "Old Sony video
  363. * projector", "AV equipment", new Double(60.449007),new
  364. * Double(22.295508) }, { "Sanyo", "Brand new hd-ready video projector",
  365. * "AV equipment", new Double(60.452224),new Double(22.299929) }, {
  366. * "Room 7", "Conference room in the lobby", "Conference rooms", new
  367. * Double(60.449451),new Double(22.292032) }, { "Nintendo Wii", "Teh
  368. * uber fun", "Entertainment", new Double(60.445408),new
  369. * Double(22.290831) }, { "Playstation", "We don't actually have one",
  370. * "Entertainment", new Double(60.44641962165445),new
  371. * Double(22.301753170493) }, { "Luokkahuone", "Classroom right next to
  372. * IT Mill", "Conference rooms", new Double(60.44888),new
  373. * Double(22.292032) } };
  374. */
  375. Object[][] resources = {
  376. // Turku
  377. { "01 Ford Mondeo", "w/ company logo", "Turku",
  378. new Double(60.510857), new Double(22.275424) },
  379. { "02 Citroen Jumper", "w/ company logo. 12m3 storage space.",
  380. "Turku", new Double(60.452171), new Double(22.2995) },
  381. { "03 Saab 93", "Cabriolet<br/>Keys from the rental desk.",
  382. "Turku", new Double(60.4507), new Double(22.295551) },
  383. { "04 Volvo S60", "Key from the rental desk.", "Turku",
  384. new Double(60.434722), new Double(22.224398) },
  385. { "05 Smart fourtwo", "Cabrio. Keys from infodesk.", "Turku",
  386. new Double(60.508970), new Double(22.264790) },
  387. // Helsinki
  388. { "06 Smart fourtwo", "Cabrio. Keys from infodesk.",
  389. "Helsinki", new Double(60.17175), new Double(24.939029) },
  390. { "07 Smart fourtwo", "Cabrio. Keys from infodesk.",
  391. "Helsinki", new Double(60.17175), new Double(24.939029) },
  392. { "08 Smart fourtwo", "Cabrio. Keys from infodesk.",
  393. "Helsinki", new Double(60.166579),
  394. new Double(24.953899) },
  395. { "09 Volvo S60", "Keys from infodesk.", "Helsinki",
  396. new Double(60.317832), new Double(24.967289) },
  397. { "10 Saab 93", "Keys from infodesk.", "Helsinki",
  398. new Double(60.249193), new Double(25.045921) },
  399. // Silicon Valley
  400. { "11 Ford Mustang", "Keys from Acme clerk.", "Silicon Valley",
  401. new Double(37.615853), new Double(-122.386384) },
  402. { "12 Ford Mondeo", "Keys from infodesk.", "Silicon Valley",
  403. new Double(37.365028), new Double(-121.922654) },
  404. { "13 Ford Mustang", "GT Cal Special. Keys from guard.",
  405. "Silicon Valley", new Double(37.403812),
  406. new Double(-121.977425) },
  407. { "14 Ford Mustang", "GT Cal Special. Keys from guard.",
  408. "Silicon Valley", new Double(37.403812),
  409. new Double(-121.977425) },
  410. { "15 Land Rover", "Keys from infodesk.", "Silicon Valley",
  411. new Double(37.365028), new Double(-121.922654) },
  412. // Paris
  413. { "17 Peugeot 308", "Keys from infodesk.", "Paris",
  414. new Double(48.844756), new Double(2.372784) },
  415. { "18 Citroën C6", "Keys from rental desk.", "Paris",
  416. new Double(49.007253), new Double(2.545025) },
  417. { "19 Citroën C6", "Keys from infodesk.", "Paris",
  418. new Double(48.729061), new Double(2.368087) },
  419. { "20 Peugeot 308", "Keys from ticket sales.", "Paris",
  420. new Double(48.880931), new Double(2.356988) },
  421. { "21 Peugeot 308", "Keys from ticket sales.", "Paris",
  422. new Double(48.876479), new Double(2.358161) },
  423. // STHLM
  424. { "22 Volvo S60", "Keys from infodesk.", "Stockholm",
  425. new Double(59.350414), new Double(18.106574) },
  426. { "23 Saab 93", "Keys from infodesk.", "Stockholm",
  427. new Double(59.355905), new Double(17.946784) },
  428. { "24 Smart fourtwo", "Keys from infodesk.", "Stockholm",
  429. new Double(59.315939), new Double(18.095904) },
  430. { "25 Smart fourtwo", "Keys from infodesk.", "Stockholm",
  431. new Double(59.330716), new Double(18.058702) },
  432. // Boston
  433. { "26 Ford Mustang", "Keys from infodesk.", "Boston",
  434. new Double(42.366588), new Double(-71.020955) },
  435. { "27 Smart fourtwo", "Keys from infodesk.", "Boston",
  436. new Double(42.365419), new Double(-71.061748) },
  437. { "28 Volvo S60", "Keys from Seaport Hotel reception.",
  438. "Boston", new Double(42.34811), new Double(-71.041127) },
  439. { "29 Smart fourtwo", "Keys from Seaport Hotel reception.",
  440. "Boston", new Double(42.348072), new Double(-71.041315) },
  441. };
  442. String q = "INSERT INTO " + Resource.TABLE + "("
  443. + Resource.PROPERTY_ID_NAME + ","
  444. + Resource.PROPERTY_ID_DESCRIPTION + ","
  445. + Resource.PROPERTY_ID_CATEGORY + ","
  446. + Resource.PROPERTY_ID_LOCATIONX + ","
  447. + Resource.PROPERTY_ID_LOCATIONY + ")" + " VALUES (?,?,?,?,?)";
  448. try {
  449. PreparedStatement stmt = connection.prepareStatement(q);
  450. for (int i = 0; i < resources.length; i++) {
  451. int j = 0;
  452. stmt.setString(j + 1, (String) resources[i][j++]);
  453. stmt.setString(j + 1, (String) resources[i][j++]);
  454. stmt.setString(j + 1, (String) resources[i][j++]);
  455. stmt.setDouble(j + 1, ((Double) resources[i][j++])
  456. .doubleValue());
  457. stmt.setDouble(j + 1, ((Double) resources[i][j++])
  458. .doubleValue());
  459. stmt.execute();
  460. }
  461. } catch (SQLException e) {
  462. throw new RuntimeException(e);
  463. }
  464. }
  465. public void generateDemoUser() {
  466. String q = "INSERT INTO USER (" + User.PROPERTY_ID_FULLNAME + ","
  467. + User.PROPERTY_ID_EMAIL + "," + User.PROPERTY_ID_PASSWORD
  468. + ") VALUES (?,?,?)";
  469. try {
  470. PreparedStatement stmt = connection.prepareStatement(q);
  471. stmt.setString(1, "Demo User");
  472. stmt.setString(2, "demo.user@itmill.com");
  473. stmt.setString(3, "demo");
  474. stmt.execute();
  475. } catch (SQLException e) {
  476. throw new RuntimeException(e);
  477. }
  478. }
  479. }