Java Code Examples for com.j256.ormlite.jdbc.JdbcConnectionSource#getReadWriteConnection()

The following examples show how to use com.j256.ormlite.jdbc.JdbcConnectionSource#getReadWriteConnection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Database.java    From PacketProxy with Apache License 2.0 6 votes vote down vote up
private void createDB() throws Exception
{
	PacketProxyUtility util = PacketProxyUtility.getInstance();
	if (! Files.exists(databaseDir)) {
		util.packetProxyLog(databaseDir.toAbsolutePath() + " directory is not found...");
		util.packetProxyLog("creating the directory...");
		Files.createDirectories(databaseDir);
		System.out.println("success!");
	} else {
		if (! Files.isDirectory(databaseDir)) {
			util.packetProxyLogErr(databaseDir.toAbsolutePath() + " file is not directory...");
			util.packetProxyLogErr("Must be a directory");
			System.exit(1);
		}
	}

	System.setProperty(LocalLog.LOCAL_LOG_LEVEL_PROPERTY, "error");
	source = new JdbcConnectionSource(getDatabaseURL());
	DatabaseConnection conn = source.getReadWriteConnection();
	conn.executeStatement("pragma auto_vacuum = full", DatabaseConnection.DEFAULT_RESULT_FLAGS);
}
 
Example 2
Source File: Database.java    From PacketProxy with Apache License 2.0 6 votes vote down vote up
public void saveWithoutLog(String path) throws Exception
{
	setChanged();
	notifyObservers(DatabaseMessage.PAUSE);
	clearChanged();

	Path src = databasePath;
	Path dest = FileSystems.getDefault().getPath(path);
	Files.copy(src,  dest, StandardCopyOption.REPLACE_EXISTING);
	JdbcConnectionSource new_db = new JdbcConnectionSource("jdbc:sqlite:"+dest);
	DatabaseConnection conn = new_db.getReadWriteConnection();
	conn.executeStatement("delete from packets", DatabaseConnection.DEFAULT_RESULT_FLAGS);
	conn.close();
	new_db.close();

	setChanged();
	notifyObservers(DatabaseMessage.RESUME);
	clearChanged();
}
 
Example 3
Source File: BaseJdbcDatabaseTypeTest.java    From ormlite-jdbc with ISC License 6 votes vote down vote up
@Test
public void testFileSystem() throws Exception {
	File dbDir = new File(DB_DIRECTORY);
	TestUtils.deleteDirectory(dbDir);
	dbDir.mkdirs();
	assertEquals(0, dbDir.list().length);
	closeConnectionSource();
	String dbUrl = "jdbc:h2:" + dbDir.getPath() + "/" + DATABASE_NAME;
	connectionSource = new JdbcConnectionSource(dbUrl);
	DatabaseConnection conn = connectionSource.getReadWriteConnection(null);
	try {
		databaseType = DatabaseTypeUtils.createDatabaseType(dbUrl);
		assertTrue(dbDir.list().length != 0);
	} finally {
		connectionSource.releaseConnection(conn);
	}
}