aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/demo/util/SampleCalendarDatabase.java
diff options
context:
space:
mode:
authorJani Laakso <jani.laakso@itmill.com>2007-10-09 06:12:02 +0000
committerJani Laakso <jani.laakso@itmill.com>2007-10-09 06:12:02 +0000
commit5ba28731e951c06ddb3bb9eaa73bfbf207084958 (patch)
tree283027b45f0a1dc287c4e3e836ebb2bba00b227f /src/com/itmill/toolkit/demo/util/SampleCalendarDatabase.java
parentd5e956890c9a08915ecd0e0ebf9f59c42f7edd7c (diff)
downloadvaadin-framework-5ba28731e951c06ddb3bb9eaa73bfbf207084958.tar.gz
vaadin-framework-5ba28731e951c06ddb3bb9eaa73bfbf207084958.zip
Mass format based on eclipse build in formatting style.
svn changeset:2461/svn branch:trunk
Diffstat (limited to 'src/com/itmill/toolkit/demo/util/SampleCalendarDatabase.java')
-rw-r--r--src/com/itmill/toolkit/demo/util/SampleCalendarDatabase.java266
1 files changed, 134 insertions, 132 deletions
diff --git a/src/com/itmill/toolkit/demo/util/SampleCalendarDatabase.java b/src/com/itmill/toolkit/demo/util/SampleCalendarDatabase.java
index d27756b4f5..c452a44d24 100644
--- a/src/com/itmill/toolkit/demo/util/SampleCalendarDatabase.java
+++ b/src/com/itmill/toolkit/demo/util/SampleCalendarDatabase.java
@@ -19,144 +19,146 @@ import java.sql.Timestamp;
*/
public class SampleCalendarDatabase {
- public static final int ENTRYCOUNT = 100;
-
- public static final String DB_TABLE_NAME = "calendar";
- public static final String PROPERTY_ID_START = "EVENTSTART";
- public static final String PROPERTY_ID_END = "EVENTEND";
- public static final String PROPERTY_ID_TITLE = "TITLE";
- public static final String PROPERTY_ID_NOTIME = "NOTIME";
-
- private Connection connection = null;
-
- private static final String[] titles = new String[] { "Meeting", "Dentist",
- "Haircut", "Bank", "Birthday", "Library", "Rent", "Acme test", "Party" };
-
- /**
- * Create temporary database.
- *
- */
- public SampleCalendarDatabase() {
- // connect to SQL database
- connect();
-
- // initialize SQL database
- createTables();
-
- // test by executing sample JDBC query
- testDatabase();
- }
-
- /**
- * Creates sample table named employee and populates it with data.Use the
- * specified database connection.
- *
- * @param connection
- */
- public SampleCalendarDatabase(Connection connection) {
- // initialize SQL database
- createTables();
-
- // test by executing sample JDBC query
- testDatabase();
- }
-
- /**
- * Connect to SQL database. In this sample we use HSQLDB and an toolkit
- * named database in implicitly created into system memory.
- *
- */
- private void connect() {
- // use memory-Only Database
- String url = "jdbc:hsqldb:mem:toolkit";
- try {
- Class.forName("org.hsqldb.jdbcDriver").newInstance();
- connection = DriverManager.getConnection(url, "sa", "");
- } catch (Exception e) {
- throw new RuntimeException(e);
+ public static final int ENTRYCOUNT = 100;
+
+ public static final String DB_TABLE_NAME = "calendar";
+ public static final String PROPERTY_ID_START = "EVENTSTART";
+ public static final String PROPERTY_ID_END = "EVENTEND";
+ public static final String PROPERTY_ID_TITLE = "TITLE";
+ public static final String PROPERTY_ID_NOTIME = "NOTIME";
+
+ private Connection connection = null;
+
+ private static final String[] titles = new String[] { "Meeting", "Dentist",
+ "Haircut", "Bank", "Birthday", "Library", "Rent", "Acme test",
+ "Party" };
+
+ /**
+ * Create temporary database.
+ *
+ */
+ public SampleCalendarDatabase() {
+ // connect to SQL database
+ connect();
+
+ // initialize SQL database
+ createTables();
+
+ // test by executing sample JDBC query
+ testDatabase();
+ }
+
+ /**
+ * Creates sample table named employee and populates it with data.Use the
+ * specified database connection.
+ *
+ * @param connection
+ */
+ public SampleCalendarDatabase(Connection connection) {
+ // initialize SQL database
+ createTables();
+
+ // test by executing sample JDBC query
+ testDatabase();
}
- }
-
- /**
- * use for SQL commands CREATE, DROP, INSERT and UPDATE
- *
- * @param expression
- * @throws SQLException
- */
- public void update(String expression) throws SQLException {
- Statement st = null;
- st = connection.createStatement();
- int i = st.executeUpdate(expression);
- if (i == -1) {
- System.out.println("SampleDatabase error : " + expression);
+
+ /**
+ * Connect to SQL database. In this sample we use HSQLDB and an toolkit
+ * named database in implicitly created into system memory.
+ *
+ */
+ private void connect() {
+ // use memory-Only Database
+ String url = "jdbc:hsqldb:mem:toolkit";
+ try {
+ Class.forName("org.hsqldb.jdbcDriver").newInstance();
+ connection = DriverManager.getConnection(url, "sa", "");
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
}
- st.close();
- }
-
- /**
- * Create test table and few rows. Issue note: using capitalized column
- * names as HSQLDB returns column names in capitalized form with this demo.
- *
- */
- private void createTables() {
- try {
- String stmt = null;
- stmt = "CREATE TABLE "+DB_TABLE_NAME+" ( ID INTEGER IDENTITY, TITLE VARCHAR(100), "
- + "EVENTSTART DATETIME, EVENTEND DATETIME, NOTIME BOOLEAN )";
- update(stmt);
- for (int j = 0; j < ENTRYCOUNT; j++) {
- Timestamp start = new Timestamp(new java.util.Date().getTime());
- start.setDate((int)((Math.random()-0.4) * 200));
- start.setMinutes(0);
- start.setHours(8+(int)Math.random()*12);
- Timestamp end = new Timestamp(start.getTime());
- if (Math.random()<0.7) {
- long t = end.getTime();
- long hour = 60 * 60 * 1000;
- t = t + hour + (long)(Math.round(Math.random() * 3 * hour));
- end.setTime(t);
+
+ /**
+ * use for SQL commands CREATE, DROP, INSERT and UPDATE
+ *
+ * @param expression
+ * @throws SQLException
+ */
+ public void update(String expression) throws SQLException {
+ Statement st = null;
+ st = connection.createStatement();
+ int i = st.executeUpdate(expression);
+ if (i == -1) {
+ System.out.println("SampleDatabase error : " + expression);
}
+ st.close();
+ }
- stmt = "INSERT INTO "+DB_TABLE_NAME+"(TITLE, EVENTSTART, EVENTEND, NOTIME) VALUES ("
- + "'"
- + titles[(int) (Math.round(Math.random() * (titles.length - 1)))]
- + "','"
- + start
- + "','"
- + end
- + "',"
- + (Math.random()>0.7)
- + ")";
- update(stmt);
- }
- } catch (SQLException e) {
- if (e.toString().indexOf("Table already exists") == -1)
- throw new RuntimeException(e);
+ /**
+ * Create test table and few rows. Issue note: using capitalized column
+ * names as HSQLDB returns column names in capitalized form with this demo.
+ *
+ */
+ private void createTables() {
+ try {
+ String stmt = null;
+ stmt = "CREATE TABLE "
+ + DB_TABLE_NAME
+ + " ( ID INTEGER IDENTITY, TITLE VARCHAR(100), "
+ + "EVENTSTART DATETIME, EVENTEND DATETIME, NOTIME BOOLEAN )";
+ update(stmt);
+ for (int j = 0; j < ENTRYCOUNT; j++) {
+ Timestamp start = new Timestamp(new java.util.Date().getTime());
+ start.setDate((int) ((Math.random() - 0.4) * 200));
+ start.setMinutes(0);
+ start.setHours(8 + (int) Math.random() * 12);
+ Timestamp end = new Timestamp(start.getTime());
+ if (Math.random() < 0.7) {
+ long t = end.getTime();
+ long hour = 60 * 60 * 1000;
+ t = t + hour
+ + (long) (Math.round(Math.random() * 3 * hour));
+ end.setTime(t);
+ }
+
+ stmt = "INSERT INTO "
+ + DB_TABLE_NAME
+ + "(TITLE, EVENTSTART, EVENTEND, NOTIME) VALUES ("
+ + "'"
+ + titles[(int) (Math.round(Math.random()
+ * (titles.length - 1)))] + "','" + start
+ + "','" + end + "'," + (Math.random() > 0.7) + ")";
+ update(stmt);
+ }
+ } catch (SQLException e) {
+ if (e.toString().indexOf("Table already exists") == -1)
+ throw new RuntimeException(e);
+ }
}
- }
-
- /**
- * Test database connection with simple SELECT command.
- *
- */
- private String testDatabase() {
- String result = null;
- try {
- Statement stmt = connection.createStatement(
- ResultSet.TYPE_SCROLL_INSENSITIVE,
- ResultSet.CONCUR_UPDATABLE);
- ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM "+DB_TABLE_NAME);
- rs.next();
- result = "rowcount for table test is " + rs.getObject(1).toString();
- stmt.close();
- } catch (SQLException e) {
- throw new RuntimeException(e);
+
+ /**
+ * Test database connection with simple SELECT command.
+ *
+ */
+ private String testDatabase() {
+ String result = null;
+ try {
+ Statement stmt = connection.createStatement(
+ ResultSet.TYPE_SCROLL_INSENSITIVE,
+ ResultSet.CONCUR_UPDATABLE);
+ ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM "
+ + DB_TABLE_NAME);
+ rs.next();
+ result = "rowcount for table test is " + rs.getObject(1).toString();
+ stmt.close();
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ return result;
}
- return result;
- }
- public Connection getConnection() {
- return connection;
- }
+ public Connection getConnection() {
+ return connection;
+ }
}