本文整理汇总了Java中com.j256.ormlite.jdbc.JdbcConnectionSource类的典型用法代码示例。如果您正苦于以下问题:Java JdbcConnectionSource类的具体用法?Java JdbcConnectionSource怎么用?Java JdbcConnectionSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JdbcConnectionSource类属于com.j256.ormlite.jdbc包,在下文中一共展示了JdbcConnectionSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initDb
import com.j256.ormlite.jdbc.JdbcConnectionSource; //导入依赖的package包/类
private void initDb() throws SQLException {
// create a connection source to our database
connectionSource = new JdbcConnectionSource(DATABASE_URL, "sa", "",
new HsqldbDatabaseType());
// instantiate the DAO
vaultDao = DaoManager.createDao(connectionSource, VaultEntry.class);
if (!vaultDao.isTableExists()) {
TableUtils.createTableIfNotExists(connectionSource, VaultEntry.class);
} else {
LOG.warning("Found existing DB for VaultEntries. Reusing it!!");
}
rawDao = DaoManager.createDao(connectionSource, RawEntry.class);
if (!rawDao.isTableExists()) {
TableUtils.createTableIfNotExists(connectionSource, RawEntry.class);
}
// TableUtils.createTableIfNotExists(connectionSource, SliceEntry.class);
}
示例2: AnkiDatabase
import com.j256.ormlite.jdbc.JdbcConnectionSource; //导入依赖的package包/类
AnkiDatabase(File databaseFile) throws SQLException {
try {
//Loading the sqlite drivers
Class.forName("org.sqlite.JDBC");
} catch (ClassNotFoundException e) {
//Should never happen
throw new SQLException(e);
}
//Creating a connection to the database:
connectionSource = new JdbcConnectionSource("jdbc:sqlite:" + databaseFile.getAbsolutePath());
//Creating DAOs
notesDAO = DaoManager.createDao(connectionSource, DBNote.class);
cardsDAO = DaoManager.createDao(connectionSource, DBCard.class);
configDAO = DaoManager.createDao(connectionSource, DBConfig.class);
}
示例3: initDb
import com.j256.ormlite.jdbc.JdbcConnectionSource; //导入依赖的package包/类
/**
* Initializes the actual database as a {@link JdbcConnectionSource}.
*
* @throws SQLException Thrown if the database can not be successfully initialized.
*/
private void initDb() throws SQLException {
// create a connection source to our database
connectionSource = new JdbcConnectionSource(DATABASE_URL, "sa", "",
new HsqldbDatabaseType());
// instantiate the DAO
vaultDao = DaoManager.createDao(connectionSource, VaultEntry.class);
if (!vaultDao.isTableExists()) {
TableUtils.createTableIfNotExists(connectionSource, VaultEntry.class);
} else {
LOG.warning("Found existing DB for VaultEntries. Reusing it!!");
}
rawDao = DaoManager.createDao(connectionSource, RawEntry.class);
if (!rawDao.isTableExists()) {
TableUtils.createTableIfNotExists(connectionSource, RawEntry.class);
}
// TableUtils.createTableIfNotExists(connectionSource, SliceEntry.class);
}
示例4: setUpTest
import com.j256.ormlite.jdbc.JdbcConnectionSource; //导入依赖的package包/类
@BeforeClass
public static void setUpTest() throws Exception {
ServerEventService eventService = new ServerEventService();
daoProvider = new DataSourceProvider();
eventService.subscribe(DataSourceInitializedEvent.class, daoProvider);
DataSourceEventSubscriber daoInitializer = new DataSourceEventSubscriber();
eventService.subscribe(DeviceDaoCreatedEvent.class, daoInitializer);
eventService.subscribe(AgentDaoCreatedEvent.class, daoInitializer);
DataSourceManager dataSourceManager = new DataSourceManager(new DataSourceCallback());
dataSourceManager.initialize();
assertNotNull("Initialization of the database failed. ", agentDao);
// initialize a test agent entry in the data source to attach the devices to
agentDao.add(TEST_AGENT_ID);
initializeTestDevices();
// initialize an OrmLite device DAO to clear the device table after each test
JdbcConnectionSource connectionSource = new JdbcConnectionSource(Property.DATABASE_URL);
ormliteDeviceDao = DaoManager.createDao(connectionSource, Device.class);
}
示例5: DatabaseManager
import com.j256.ormlite.jdbc.JdbcConnectionSource; //导入依赖的package包/类
protected DatabaseManager() {
String databaseUrl = "jdbc:sqlite:halgnu.db";
try {
m_connectionSource = new JdbcConnectionSource(databaseUrl);
// Create daos
m_memberDao = DaoManager.createDao(m_connectionSource, MemberModel.class);
m_activityDao = DaoManager.createDao(m_connectionSource, ActivityModel.class);
TableUtils.createTableIfNotExists(m_connectionSource, MemberModel.class);
TableUtils.createTableIfNotExists(m_connectionSource, ActivityModel.class);
// Check if tables need to be created
CheckIfAdminExists();
} catch (SQLException e) {
e.printStackTrace();
}
}
示例6: main
import com.j256.ormlite.jdbc.JdbcConnectionSource; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.err.println("CreateTables (database name)");
System.exit(1);
}
String databaseName = args[0];
int exitCode = 0;
String databaseUrl = ManagerFactory.DATABASE_URL.replace("/mitro", "/" + databaseName);
JdbcConnectionSource connection = new JdbcConnectionSource(databaseUrl);
try {
Manager.createTablesIfNotExists(connection);
} catch (SQLException e) {
exitCode = 1;
System.err.println("Failed: Some exception was thrown:");
e.printStackTrace(System.err);
} finally {
connection.close();
}
System.exit(exitCode);
}
示例7: memorySetUp
import com.j256.ormlite.jdbc.JdbcConnectionSource; //导入依赖的package包/类
@Before
public void memorySetUp() throws SQLException, CyclicGroupError, CryptoError, MitroServletException {
// Create a fake SecretsBundle
TwoFactorSigningService.initialize(SecretsBundle.generateForTest());
groupToPrivateKeyMap = Maps.newHashMap();
JdbcConnectionSource connectionSource = new JdbcConnectionSource(DATABASE_URL);
connectionSource.getReadWriteConnection().executeStatement(
"DROP ALL OBJECTS", DatabaseConnection.DEFAULT_RESULT_FLAGS);
managerFactory = new ManagerFactory(DATABASE_URL, new Manager.Pool(),
ManagerFactory.IDLE_TXN_POLL_SECONDS, TimeUnit.SECONDS, ConnectionMode.READ_WRITE);
manager = managerFactory.newManager();
testIdentityKey = keyFactory.generate();
testIdentity = createIdentity("[email protected]", testIdentityKey);
testIdentityLoginToken = GetMyPrivateKey.makeLoginTokenString(testIdentity, null, null);
testIdentityLoginTokenSignature = testIdentityKey.sign(testIdentityLoginToken);
testIdentity2 = createIdentity("[email protected]", null);
testGroup = createGroupContainingIdentity(testIdentity);
manager.commitTransaction();
// remove the audit log that commit writes so that tests start with an empty log
connectionSource.getReadWriteConnection().executeStatement(
"DELETE FROM audit;", DatabaseConnection.DEFAULT_RESULT_FLAGS);
connectionSource.getReadWriteConnection().commit(null);
}
示例8: testTimeZone
import com.j256.ormlite.jdbc.JdbcConnectionSource; //导入依赖的package包/类
@Test
public void testTimeZone() throws SQLException {
// create a temporary H2 connection
JdbcConnectionSource connection = new JdbcConnectionSource("jdbc:h2:mem:");
TableUtils.createTable(connection, DBEmailQueue.class);
Dao<DBEmailQueue, Integer> dao = DaoManager.createDao(connection, DBEmailQueue.class);
DBEmailQueue email = DBEmailQueue.makeInvitation("[email protected]", "[email protected]", "pw");
dao.create(email);
// Force a daylight savings time string in the DB
setRawDate(connection, email.getId(), "2013-05-17T14:47:59.864022");
Date t = dao.queryForId(email.getId()).getAttemptedTime();
assertEquals("2013-05-17T14:47:59.864Z", DBEmailQueue.getUtcIsoFormat().format(t));
assertEquals(1368802079864L, t.getTime());
// Set a date/time in standard time, not daylight time
setRawDate(connection, email.getId(), "2013-11-04T15:38:11.997012");
t = dao.queryForId(email.getId()).getAttemptedTime();
assertEquals("2013-11-04T15:38:11.997Z", DBEmailQueue.getUtcIsoFormat().format(t));
assertEquals(1383579491997L, t.getTime());
}
示例9: LocalSqliteDriverImpl
import com.j256.ormlite.jdbc.JdbcConnectionSource; //导入依赖的package包/类
public LocalSqliteDriverImpl(String sqlite_filename) throws MaeDBException {
SQLITE_FILENAME = sqlite_filename;
logger = LoggerFactory.getLogger(this.getClass().getName() + SQLITE_FILENAME);
try {
cs = new JdbcConnectionSource(JDBC_DRIVER + SQLITE_FILENAME);
idHandler = new IdHandler();
this.setupDatabase(cs);
// put a placeholder for task metadata in DB
workingTask = new Task(SQLITE_FILENAME);
taskDao.create(workingTask);
} catch (SQLException e) {
throw catchSQLException(e);
}
logger.info("New JDBC SQLite Driver is initialized, using a local file: " + SQLITE_FILENAME);
workChanged = false;
}
示例10: getManager
import com.j256.ormlite.jdbc.JdbcConnectionSource; //导入依赖的package包/类
public static DatabaseManager getManager(){
if(manager==null){
Properties properties=new Properties();
try {
properties.load(DatabaseManager.class.getResourceAsStream("database.properties"));
JdbcConnectionSource source=new JdbcConnectionSource(
properties.getProperty(HOST),
properties.getProperty(LOGIN),
properties.getProperty(PASSWD),
DatabaseTypeUtils.createDatabaseType(properties.getProperty(HOST)));
manager=new DatabaseManager(source);
} catch (IOException | SQLException e) {
e.printStackTrace();
}
}
return manager;
}
示例11: testFileSystem
import com.j256.ormlite.jdbc.JdbcConnectionSource; //导入依赖的package包/类
@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);
}
}
示例12: testRemotePort
import com.j256.ormlite.jdbc.JdbcConnectionSource; //导入依赖的package包/类
@Test(expected = SQLException.class)
public void testRemotePort() throws Exception {
File dbDir = new File(DB_DIRECTORY);
TestUtils.deleteDirectory(dbDir);
dbDir.mkdirs();
// bad port
int notTheRightPort = 12345;
closeConnectionSource();
// try to disable the retry feature which delays this test failure
System.setProperty("h2.socketConnectRetry", "0");
String dbUrl = "jdbc:h2:tcp://localhost:" + notTheRightPort + "/" + dbDir.getPath() + "/" + DATABASE_NAME;
connectionSource = new JdbcConnectionSource(dbUrl);
DatabaseConnection conn = connectionSource.getReadOnlyConnection(null);
try {
DatabaseTypeUtils.createDatabaseType(dbUrl);
} finally {
connectionSource.releaseConnection(conn);
}
}
示例13: OrmLiteSqliteStorage
import com.j256.ormlite.jdbc.JdbcConnectionSource; //导入依赖的package包/类
OrmLiteSqliteStorage(String path) {
withCatcher(() -> {
File parent = new File(path).getParentFile();
if (!parent.mkdirs() && !parent.isDirectory()) {
throw new RuntimeException("Unable to create DB parent directory: " + parent);
}
ConnectionSource connPool = new JdbcConnectionSource("jdbc:sqlite:" + path);
invDao = createDaoAndTable(connPool, ThreePidInviteIO.class);
sessionDao = createDaoAndTable(connPool, ThreePidSessionDao.class);
});
}
示例14: getConnectionSource
import com.j256.ormlite.jdbc.JdbcConnectionSource; //导入依赖的package包/类
@Bean
public JdbcConnectionSource getConnectionSource() throws SQLException {
JdbcConnectionSource source = new JdbcConnectionSource(
"jdbc:h2:~/.nutch/config", new H2DatabaseType());
source.initialize();
return source;
}
示例15: inform
import com.j256.ormlite.jdbc.JdbcConnectionSource; //导入依赖的package包/类
/**
* Informs data source provider for {@link DataSourceInitializedEvent event} received when data source is
* initialized.
*
* @param event
* - event, which is received when data source is initialized
*/
public void inform(DataSourceInitializedEvent event) {
// TODO: Data AccessObjects can be passed through events.
// FIXME: Recreating objects is a dirty fix for unit tests. Because of the monostate pattern the fields are
// shared in all test classes. This resulted in an inconsistent event sending and some classed were not
// initialized correctly because the events were not send as expected. See #231
try {
// if (connectionSource == null) {
connectionSource = new JdbcConnectionSource(Property.DATABASE_URL);
keepAliveConnection = connectionSource.getReadOnlyConnection();
// }
// if (wrappedAgentDao == null) {
Dao<Agent, String> agentDao = DaoManager.createDao(connectionSource, Agent.class);
wrappedAgentDao = new AgentDao(agentDao);
publishDataSourceCreatedEvent(new AgentDaoCreatedEvent());
// }
// if (wrappedDeviceDao == null) {
Dao<Device, String> deviceDao = DaoManager.createDao(connectionSource, Device.class);
wrappedDeviceDao = new DeviceDao(deviceDao);
publishDataSourceCreatedEvent(new DeviceDaoCreatedEvent());
// }
// if (devicePoolDao == null) {
devicePoolDao = new DevicePoolDao(wrappedDeviceDao, wrappedAgentDao);
publishDataSourceCreatedEvent(new DevicePoolDaoCreatedEvent());
// }
} catch (SQLException e) {
LOGGER.error("Connection to the data source failed.", e);
}
}