Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package org.sqldroid; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.PrintWriter; | ||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
import java.sql.SQLFeatureNotSupportedException; | ||
import java.util.Properties; | ||
import java.util.logging.Logger; | ||
|
||
import javax.sql.DataSource; | ||
|
||
public class DroidDataSource implements DataSource { | ||
Connection connection = null; | ||
protected String description = "Android Sqlite Data Source"; | ||
protected String packageName; | ||
protected String databaseName; | ||
|
||
public DroidDataSource() { | ||
|
||
} | ||
|
||
public DroidDataSource(String packageName, String databaseName) { | ||
setPackageName(packageName); | ||
setDatabaseName(databaseName); | ||
} | ||
|
||
@Override | ||
public Connection getConnection() throws SQLException { | ||
String url = "jdbc:sqldroid:" + "/data/data/" + packageName + "/" + databaseName + ".db"; | ||
connection = new org.sqldroid.SQLDroidDriver().connect(url , new Properties()); | ||
return connection; | ||
} | ||
|
||
@Override | ||
public Connection getConnection(String username, String password) | ||
throws SQLException { | ||
return getConnection(); | ||
} | ||
|
||
@Override | ||
public PrintWriter getLogWriter() throws SQLException { | ||
PrintWriter logWriter = null; | ||
try { | ||
logWriter = new PrintWriter("droid.log"); | ||
} catch (FileNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
return logWriter; | ||
} | ||
|
||
@Override | ||
public int getLoginTimeout() throws SQLException { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void setLogWriter(PrintWriter out) throws SQLException { | ||
try { | ||
DriverManager.setLogWriter(new PrintWriter("droid.log")); | ||
} catch (FileNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void setLoginTimeout(int seconds) throws SQLException { | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public void setDescription(String desc) { | ||
description = desc; | ||
} | ||
|
||
public String getPackageName() { | ||
return packageName; | ||
} | ||
|
||
public void setPackageName(String packageName) { | ||
this.packageName = packageName; | ||
} | ||
|
||
public String getDatabaseName() { | ||
return databaseName; | ||
} | ||
|
||
public void setDatabaseName(String databaseName) { | ||
this.databaseName = databaseName; | ||
} | ||
|
||
@Override | ||
public boolean isWrapperFor(Class<?> iface) throws SQLException { | ||
throw new UnsupportedOperationException("isWrapperfor"); | ||
} | ||
|
||
@Override | ||
public <T> T unwrap(Class<T> iface) throws SQLException { | ||
throw new UnsupportedOperationException("unwrap"); | ||
} | ||
|
||
public Logger getParentLogger() throws SQLFeatureNotSupportedException { | ||
return null; | ||
} | ||
|
||
} |