Pattern for database-wrapper in java
Posted
by Space_C0wb0y
on Stack Overflow
See other posts from Stack Overflow
or by Space_C0wb0y
Published on 2010-05-03T13:22:53Z
Indexed on
2010/05/03
13:28 UTC
Read the original article
Hit count: 212
I am currently writing a java-class that wraps an SQLite database. This class has two ways to be instantiated:
- Open an existing database.
- Create a new database.
This is what I cam up with:
public class SQLiteDatabaseWrapper {
public static SQLiteDatabaseWrapper openExisting(File PathToDB) {
return new SQLiteDatabaseWrapper(PathToDB);
}
public static SQLiteDatabaseWrapper createNew(File PathToDB) {
CreateAndInitializeNewDatabase(PathToDB);
return new SQLiteDatabaseWrapper(PathToDB);
}
private SQLiteDatabaseWrapper(File PathToDB) {
// Open connection and setup wrapper
}
}
Is this the way to go in Java, or is there any other best practice for this situation?
© Stack Overflow or respective owner