use of org.xutils.ex.DbException in project xUtils3 by wyouflf.
the class DbBase method dropDb.
@Override
public void dropDb() throws DbException {
Cursor cursor = execQuery("SELECT name FROM sqlite_master WHERE type='table' AND name<>'sqlite_sequence'");
if (cursor != null) {
try {
while (cursor.moveToNext()) {
try {
String tableName = cursor.getString(0);
execNonQuery("DROP TABLE " + tableName);
} catch (Throwable e) {
LogUtil.e(e.getMessage(), e);
}
}
synchronized (tableMap) {
for (TableEntity<?> table : tableMap.values()) {
table.setCheckedDatabase(false);
}
tableMap.clear();
}
} catch (Throwable e) {
throw new DbException(e);
} finally {
IOUtil.closeQuietly(cursor);
}
}
}
use of org.xutils.ex.DbException in project xUtils3 by wyouflf.
the class SqlInfoBuilder method buildDeleteSqlInfo.
//*********************************************** delete sql ***********************************************
public static SqlInfo buildDeleteSqlInfo(TableEntity<?> table, Object entity) throws DbException {
SqlInfo result = new SqlInfo();
ColumnEntity id = table.getId();
Object idValue = id.getColumnValue(entity);
if (idValue == null) {
throw new DbException("this entity[" + table.getEntityType() + "]'s id value is null");
}
StringBuilder builder = new StringBuilder("DELETE FROM ");
builder.append("\"").append(table.getName()).append("\"");
builder.append(" WHERE ").append(WhereBuilder.b(id.getName(), "=", idValue));
result.setSql(builder.toString());
return result;
}
use of org.xutils.ex.DbException in project xUtils3 by wyouflf.
the class SqlInfoBuilder method buildDeleteSqlInfoById.
public static SqlInfo buildDeleteSqlInfoById(TableEntity<?> table, Object idValue) throws DbException {
SqlInfo result = new SqlInfo();
ColumnEntity id = table.getId();
if (idValue == null) {
throw new DbException("this entity[" + table.getEntityType() + "]'s id value is null");
}
StringBuilder builder = new StringBuilder("DELETE FROM ");
builder.append("\"").append(table.getName()).append("\"");
builder.append(" WHERE ").append(WhereBuilder.b(id.getName(), "=", idValue));
result.setSql(builder.toString());
return result;
}
use of org.xutils.ex.DbException in project xUtils3 by wyouflf.
the class LruDiskCache method getDiskCacheFile.
public DiskCacheFile getDiskCacheFile(String key) throws InterruptedException {
if (!available || TextUtils.isEmpty(key)) {
return null;
}
DiskCacheFile result = null;
DiskCacheEntity entity = get(key);
if (entity != null && new File(entity.getPath()).exists()) {
ProcessLock processLock = ProcessLock.tryLock(entity.getPath(), false, LOCK_WAIT);
if (processLock != null && processLock.isValid()) {
result = new DiskCacheFile(entity, entity.getPath(), processLock);
if (!result.exists()) {
try {
cacheDb.delete(entity);
} catch (DbException ex) {
LogUtil.e(ex.getMessage(), ex);
}
result = null;
}
}
}
return result;
}
use of org.xutils.ex.DbException in project xUtils3 by wyouflf.
the class LruDiskCache method commitDiskCacheFile.
/**
* 添加缓存文件
*
* @param cacheFile
*/
/*package*/
DiskCacheFile commitDiskCacheFile(DiskCacheFile cacheFile) throws IOException {
if (cacheFile != null && cacheFile.length() < 1L) {
IOUtil.closeQuietly(cacheFile);
return null;
}
if (!available || cacheFile == null) {
return null;
}
DiskCacheFile result = null;
DiskCacheEntity cacheEntity = cacheFile.cacheEntity;
if (cacheFile.getName().endsWith(TEMP_FILE_SUFFIX)) {
// is temp file
ProcessLock processLock = null;
DiskCacheFile destFile = null;
try {
String destPath = cacheEntity.getPath();
processLock = ProcessLock.tryLock(destPath, true, LOCK_WAIT);
if (processLock != null && processLock.isValid()) {
// lock
destFile = new DiskCacheFile(cacheEntity, destPath, processLock);
if (cacheFile.renameTo(destFile)) {
try {
result = destFile;
cacheDb.replace(cacheEntity);
} catch (DbException ex) {
LogUtil.e(ex.getMessage(), ex);
}
trimSize();
} else {
throw new IOException("rename:" + cacheFile.getAbsolutePath());
}
} else {
throw new FileLockedException(destPath);
}
} catch (InterruptedException ex) {
result = cacheFile;
LogUtil.e(ex.getMessage(), ex);
} finally {
if (result == null) {
result = cacheFile;
IOUtil.closeQuietly(destFile);
IOUtil.closeQuietly(processLock);
IOUtil.deleteFileOrDir(destFile);
} else {
IOUtil.closeQuietly(cacheFile);
IOUtil.deleteFileOrDir(cacheFile);
}
}
} else {
result = cacheFile;
}
return result;
}
Aggregations