public RoboStorage(RoboPlatform platform) { this.platform = platform; String dbDir = null; try { // we access SqlLite via JDBC... egads try { Class.forName("SQLite.JDBCDriver"); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } dbDir = NSFileManager.getDefaultManager().getURLsForDirectory( NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask).get(0).getPath(); File dbFile = new File(dbDir, platform.config.storageFileName); dbFile.getParentFile().mkdirs(); platform.log().info("Using db in file: " + dbFile.getAbsolutePath()); conn = DriverManager.getConnection("jdbc:sqlite:" + dbFile.getAbsolutePath()); // create our schema if needed try (Statement stmt = conn.createStatement()) { stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + "Data (DataKey ntext PRIMARY KEY, DataValue ntext NOT NULL)"); } } catch (SQLException sqe) { throw new RuntimeException("Failed to initialize storage [dbDir=" + dbDir + "]", sqe); } }
public RoboStorage(RoboPlatform platform) { this.platform = platform; String dbDir = null; try { // we access SqlLite via JDBC... egads try { Class.forName("SQLite.JDBCDriver"); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } dbDir = NSFileManager.getDefaultManager().getURLsForDirectory( NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask).get(0).getPath(); File dbFile = new File(dbDir, platform.config.storageFileName); dbFile.getParentFile().mkdirs(); platform.log().info("Using db in file: " + dbFile.getAbsolutePath()); conn = DriverManager.getConnection("jdbc:sqlite:" + dbFile.getAbsolutePath()); // create our schema if needed try (Statement stmt = conn.createStatement()) { stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + "Data (DataKey ntext PRIMARY KEY, DataValue ntext NOT NULL)"); } } catch (SQLException sqe) { throw new RuntimeException("Failed to initialize storage [dbDir=" + dbDir + "]", sqe); } }