本文整理了Java中com.j256.ormlite.dao.Dao.executeRaw()
方法的一些代码示例,展示了Dao.executeRaw()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dao.executeRaw()
方法的具体详情如下:
包路径:com.j256.ormlite.dao.Dao
类名称:Dao
方法名:executeRaw
[英]Run a raw execute SQL statement to the database. The arguments are optional but can be set with strings to expand ? type of SQL. If you have no arguments, you may want to call #executeRawNoArgs(String).
[中]对数据库运行原始的execute SQL语句。参数是可选的,但可以使用字符串进行设置以展开?SQL的类型。如果没有参数,则可能需要调用#executeRawNoArgs(String)。
代码示例来源:origin: magefree/mage
private boolean migrateFrom1To2() {
try {
Logger.getLogger(AuthorizedUserRepository.class).info("Starting " + VERSION_ENTITY_NAME + " DB migration from version 1 to version 2");
dao.executeRaw("ALTER TABLE authorized_user ADD COLUMN active BOOLEAN DEFAULT true;");
dao.executeRaw("ALTER TABLE authorized_user ADD COLUMN lockedUntil DATETIME;");
dao.executeRaw("ALTER TABLE authorized_user ADD COLUMN chatLockedUntil DATETIME;");
dao.executeRaw("ALTER TABLE authorized_user ADD COLUMN lastConnection DATETIME;");
RepositoryUtil.updateVersion(dao.getConnectionSource(), VERSION_ENTITY_NAME, DB_VERSION);
Logger.getLogger(AuthorizedUserRepository.class).info("Migration finished.");
return true;
} catch (SQLException ex) {
Logger.getLogger(AuthorizedUserRepository.class).error("Error while migrating from version 1 to version 2 - ", ex);
return false;
}
}
}
代码示例来源:origin: stackoverflow.com
@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) {
if(oldVersion == 1) {
try {
Dao dao = getCardDao();
dao.executeRaw("ALTER TABLE `Card` ADD COLUMN ccv STRING;");
dao.executeRaw("ALTER TABLE `Card` ADD COLUMN validFrom STRING;");
} catch (SQLException e) {
Log.e(DatabaseHelper.class.getName(), "Error ", e);
}
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
private void executeSqlQuery(String sqlQuery) {
try {
long startTime = System.currentTimeMillis();
int deleteCount = DaoUtils.getMetricsDoubleTypeDeviceDao().getDao().executeRaw(sqlQuery);
_logger.debug("Sql Query[{}], Deletion count:{}, Time taken:{} ms", sqlQuery, deleteCount,
System.currentTimeMillis() - startTime);
} catch (SQLException ex) {
_logger.error("Exception when executing query[{}] ", sqlQuery, ex);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public void dropSequence(String sequenceName) throws SQLException {
int dropCount = DaoUtils.getUserDao().getDao()
.executeRaw("DROP SEQUENCE IF EXISTS " + getSequenceName(sequenceName) + " CASCADE");
_logger.info("Dropped sequence:{}, drop count:{}", sequenceName, dropCount);
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public void dropSequence(String sequenceName) throws SQLException {
int dropCount = DaoUtils.getUserDao().getDao()
.executeRaw("DROP SEQUENCE IF EXISTS " + getSequenceName(sequenceName));
_logger.info("Dropped sequence:{}, drop count:{}", sequenceName, dropCount);
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public void dropSequence(String sequenceName) throws SQLException {
int dropCount = DaoUtils.getUserDao().getDao()
.executeRaw("DROP SEQUENCE IF EXISTS " + getSequenceName(sequenceName));
_logger.info("Dropped sequence:{}, drop count:{}", sequenceName, dropCount);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
public void alterColumn(String tableName, String columnName, String columnDefinition) throws SQLException {
int alterCount = DaoUtils.getUserDao().getDao().executeRaw("ALTER TABLE "
+ tableName + " ALTER COLUMN " + getColumnName(columnName) + " TYPE " + columnDefinition);
_logger.debug("Altered column:{}, columnDefinition:{}, table:{}, add count:{}",
columnName, columnDefinition, tableName, alterCount);
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
public void dropTable(String tableName) throws SQLException {
if (hasTable(tableName)) {
int dropCount = DaoUtils.getUserDao().getDao().executeRaw("DROP TABLE " + getTableName(tableName));
_logger.debug("Dropped table:{}, drop count:{}", tableName, dropCount);
} else {
_logger.warn("Selected table[{}] not found!", tableName);
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
public void renameTable(String tableName, String newTableName) throws SQLException {
if (hasTable(tableName)) {
int changeCount = DaoUtils.getUserDao().getDao().executeRaw(
"ALTER TABLE " + getTableName(tableName) + " RENAME TO " + getTableName(newTableName));
_logger.debug("Renamed table:{}, NewTable:{}, Change count:{}", tableName, newTableName, changeCount);
} else {
_logger.warn("Selected table[{}] not found!", tableName);
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
public void alterColumn(String tableName, String columnName, String columnDefinition) throws SQLException {
int alterCount = DaoUtils.getUserDao().getDao().executeRaw("ALTER TABLE "
+ getTableName(tableName) + " MODIFY COLUMN " + getColumnName(columnName) + " " + columnDefinition);
_logger.debug("Altered column:{}, columnDefinition:{}, table:{}, add count:{}",
columnName, columnDefinition, tableName, alterCount);
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
public void renameTable(String tableName, String newTableName) throws SQLException {
if (hasTable(tableName)) {
int changeCount = DaoUtils.getUserDao().getDao().executeRaw(
"RENAME TABLE " + getTableName(tableName) + " TO " + getColumnName(newTableName));
_logger.debug("Renamed table:{}, NewTable:{}, Change count:{}", tableName, newTableName, changeCount);
} else {
_logger.warn("Selected table[{}] not found!", tableName);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
public void renameTable(String tableName, String newTableName) throws SQLException {
if (hasTable(tableName)) {
int changeCount = DaoUtils.getUserDao().getDao().executeRaw(
"RENAME TABLE " + getTableName(tableName) + " TO " + getColumnName(newTableName));
_logger.debug("Renamed table:{}, NewTable:{}, Change count:{}", tableName, newTableName, changeCount);
} else {
_logger.warn("Selected table[{}] not found!", tableName);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
public void renameColumn(String tableName, String oldColumnName, String newColumnName) throws SQLException {
if (hasColumn(tableName, oldColumnName)) {
int dropCount = DaoUtils.getUserDao().getDao().executeRaw(
"ALTER TABLE " + getTableName(tableName) + " RENAME COLUMN "
+ getColumnName(oldColumnName) + " TO " + getColumnName(newColumnName));
_logger.debug("Renamed OldColumn:{}, NewColumn:{}, Table:{}, Drop count:{}", oldColumnName, newColumnName,
tableName, dropCount);
} else {
_logger.warn("Selected column[{}] not found! Table:{}", oldColumnName, tableName);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
public void addColumn(String tableName, String columnName, String columnDefinition) throws SQLException {
if (!hasColumn(tableName, columnName)) {
int addCount = DaoUtils
.getUserDao().getDao().executeRaw(
"ALTER TABLE " + getTableName(tableName) + " ADD COLUMN " + getColumnName(columnName)
+ " " + columnDefinition);
_logger.debug("Added column:{}, columnDefinition:{}, table:{}, add count:{}",
columnName, columnDefinition, tableName, addCount);
}
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testExecuteRaw() throws Exception {
@SuppressWarnings("unchecked")
Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
expect(dao.executeRaw(null)).andReturn(0);
replay(dao);
rtDao.executeRaw(null);
verify(dao);
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = RuntimeException.class)
public void testExecuteRawThrow() throws Exception {
@SuppressWarnings("unchecked")
Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
expect(dao.executeRaw(null)).andThrow(new SQLException("Testing catch"));
replay(dao);
rtDao.executeRaw(null);
verify(dao);
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public void createIndex(String indexSuffix, String tableName, String columnName) throws SQLException {
if (hasColumn(tableName, columnName)) {
DaoUtils.getUserDao().getDao().executeRaw(
"CREATE INDEX " + getIndexName(indexSuffix, tableName, columnName) + " ON "
+ getTableName(tableName) + "(" + getColumnName(columnName) + ")");
}
}
代码示例来源:origin: mycontroller-org/mycontroller
public void createIndex(String indexSuffix, String tableName, String columnName) throws SQLException {
if (hasColumn(tableName, columnName)) {
DaoUtils.getUserDao().getDao().executeRaw(
"CREATE INDEX " + getIndexName(indexSuffix, tableName, columnName) + " ON "
+ getTableName(tableName) + "(" + getColumnName(columnName) + ")");
}
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testExecuteRaw() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo1 = new Foo();
assertEquals(1, dao.create(foo1));
Foo foo2 = new Foo();
assertEquals(1, dao.create(foo2));
assertEquals(2, dao.queryForAll().size());
dao.executeRaw("TRUNCATE TABLE FOO");
assertEquals(0, dao.queryForAll().size());
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = SQLException.class)
public void testExecuteRawThrow() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo = new Foo();
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadWriteConnection(FOO_TABLE_NAME);
try {
conn.close();
dao.executeRaw("TRUNCATE TABLE FOO");
} finally {
connectionSource.releaseConnection(conn);
}
}
内容来源于网络,如有侵权,请联系作者删除!