本文整理汇总了Java中org.litepal.tablemanager.Connector类的典型用法代码示例。如果您正苦于以下问题:Java Connector类的具体用法?Java Connector怎么用?Java Connector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Connector类属于org.litepal.tablemanager包,在下文中一共展示了Connector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findBySQL
import org.litepal.tablemanager.Connector; //导入依赖的package包/类
/**
* Runs the provided SQL and returns a Cursor over the result set. You may
* include ? in where clause in the query, which will be replaced by the
* second to the last parameters, such as:
*
* <pre>
* Cursor cursor = DataSupport.findBySQL("select * from person where name=? and age=?", "Tom", "14");
* </pre>
*
* @param sql
* First parameter is the SQL clause to apply. Second to the last
* parameters will replace the place holders.
* @return A Cursor object, which is positioned before the first entry. Note
* that Cursors are not synchronized, see the documentation for more
* details.
*/
public static synchronized Cursor findBySQL(String... sql) {
BaseUtility.checkConditionsCorrect(sql);
if (sql == null) {
return null;
}
if (sql.length <= 0) {
return null;
}
String[] selectionArgs;
if (sql.length == 1) {
selectionArgs = null;
} else {
selectionArgs = new String[sql.length - 1];
System.arraycopy(sql, 1, selectionArgs, 0, sql.length - 1);
}
return Connector.getDatabase().rawQuery(sql[0], selectionArgs);
}
示例2: saveFast
import org.litepal.tablemanager.Connector; //导入依赖的package包/类
/**
* This method is deprecated and will be removed in the future releases.
* Use {@link #save()} instead.
*/
@Deprecated
public synchronized boolean saveFast() {
SQLiteDatabase db = Connector.getDatabase();
db.beginTransaction();
try {
SaveHandler saveHandler = new SaveHandler(db);
saveHandler.onSaveFast(this);
db.setTransactionSuccessful();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
db.endTransaction();
}
}
示例3: isDataExists
import org.litepal.tablemanager.Connector; //导入依赖的package包/类
/**
* Check if the associations between self model and associated model is
* already saved into intermediate join table.<br>
* Make sure baseObj and associatedModel are saved already, or the result
* might be wrong.
*
* @param baseObj
* The baseObj currently want to persist or update.
* @param associatedModel
* The associated model of baseObj.
* @return If the associations between them is saved into intermediate join
* table, return true. Otherwise return false.
*/
@SuppressWarnings("unused")
@Deprecated
private boolean isDataExists(DataSupport baseObj, DataSupport associatedModel) {
boolean exists = false;
SQLiteDatabase db = Connector.getDatabase();
Cursor cursor = null;
try {
cursor = db.query(getJoinTableName(baseObj, associatedModel), null,
getSelection(baseObj, associatedModel),
getSelectionArgs(baseObj, associatedModel), null, null, null);
exists = cursor.getCount() > 0;
} catch (Exception e) {
e.printStackTrace();
return true;
} finally {
cursor.close();
}
return exists;
}
示例4: populateTables
import org.litepal.tablemanager.Connector; //导入依赖的package包/类
private void populateTables() {
mProgressBar.setVisibility(View.VISIBLE);
new Thread(new Runnable() {
@Override
public void run() {
List<String> tables = DBUtility.findAllTableNames(Connector.getDatabase());
for (String table : tables) {
if (table.equalsIgnoreCase("android_metadata")
|| table.equalsIgnoreCase("sqlite_sequence")
|| table.equalsIgnoreCase("table_schema")) {
continue;
}
mList.add(table);
}
runOnUiThread(new Runnable() {
@Override
public void run() {
mProgressBar.setVisibility(View.GONE);
mAdapter.notifyDataSetChanged();
}
});
}
}).start();
}
示例5: isFKInsertCorrect
import org.litepal.tablemanager.Connector; //导入依赖的package包/类
/**
*
* @param table1
* Table without foreign key.
* @param table2
* Table with foreign key.
* @param table1Id
* id of table1.
* @param table2Id
* id of table2.
* @return success or failed.
*/
protected boolean isFKInsertCorrect(String table1, String table2, long table1Id, long table2Id) {
SQLiteDatabase db = Connector.getDatabase();
Cursor cursor = null;
try {
cursor = db.query(table2, null, "id = ?", new String[] { String.valueOf(table2Id) },
null, null, null);
cursor.moveToFirst();
long fkId = cursor.getLong(cursor.getColumnIndexOrThrow(BaseUtility.changeCase(table1
+ "_id")));
return fkId == table1Id;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
cursor.close();
}
}
示例6: isIntermediateDataCorrect
import org.litepal.tablemanager.Connector; //导入依赖的package包/类
protected boolean isIntermediateDataCorrect(String table1, String table2, long table1Id,
long table2Id) {
SQLiteDatabase db = Connector.getDatabase();
Cursor cursor = null;
try {
String where = table1 + "_id = ? and " + table2 + "_id = ?";
cursor = db.query(DBUtility.getIntermediateTableName(table1, table2), null, where,
new String[] { String.valueOf(table1Id), String.valueOf(table2Id) }, null,
null, null);
return cursor.getCount() == 1;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
cursor.close();
}
}
示例7: isDataExists
import org.litepal.tablemanager.Connector; //导入依赖的package包/类
protected boolean isDataExists(String table, long id) {
SQLiteDatabase db = Connector.getDatabase();
Cursor cursor = null;
try {
cursor = db.query(table, null, "id = ?", new String[] { String.valueOf(id) }, null,
null, null);
return cursor.getCount() == 1 ? true : false;
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cursor != null) {
cursor.close();
}
}
return false;
}
示例8: getCellPhone
import org.litepal.tablemanager.Connector; //导入依赖的package包/类
protected Cellphone getCellPhone(long id) {
Cellphone cellPhone = null;
Cursor cursor = Connector.getDatabase().query(getTableName(Cellphone.class), null, "id = ?",
new String[] { String.valueOf(id) }, null, null, null);
if (cursor.moveToFirst()) {
cellPhone = new Cellphone();
double newPrice = cursor.getDouble(cursor.getColumnIndexOrThrow("price"));
char inStock = cursor.getString(cursor.getColumnIndexOrThrow("instock")).charAt(0);
String brand = cursor.getString(cursor.getColumnIndexOrThrow("brand"));
cellPhone.setBrand(brand);
cellPhone.setInStock(inStock);
cellPhone.setPrice(newPrice);
}
cursor.close();
return cellPhone;
}
示例9: getTeacher
import org.litepal.tablemanager.Connector; //导入依赖的package包/类
protected Teacher getTeacher(long id) {
Teacher teacher = null;
Cursor cursor = Connector.getDatabase().query(getTableName(Teacher.class), null, "id = ?",
new String[] { String.valueOf(id) }, null, null, null);
if (cursor.moveToFirst()) {
teacher = new Teacher();
String teacherName = cursor.getString(cursor.getColumnIndexOrThrow("teachername"));
int teachYears = cursor.getInt(cursor.getColumnIndexOrThrow("teachyears"));
int age = cursor.getInt(cursor.getColumnIndexOrThrow("age"));
int sex = cursor.getInt(cursor.getColumnIndexOrThrow("sex"));
teacher.setTeacherName(teacherName);
teacher.setTeachYears(teachYears);
teacher.setAge(age);
if (sex == 0) {
teacher.setSex(false);
} else if (sex == 1) {
teacher.setSex(true);
}
}
cursor.close();
return teacher;
}
示例10: getTeachers
import org.litepal.tablemanager.Connector; //导入依赖的package包/类
protected List<Teacher> getTeachers(int[] ids) {
List<Teacher> teachers = new ArrayList<Teacher>();
Cursor cursor = Connector.getDatabase().query(getTableName(Teacher.class), null, getWhere(ids), null, null,
null, null);
if (cursor.moveToFirst()) {
Teacher t = new Teacher();
String teacherName = cursor.getString(cursor.getColumnIndexOrThrow("teachername"));
int teachYears = cursor.getInt(cursor.getColumnIndexOrThrow("teachyears"));
int age = cursor.getInt(cursor.getColumnIndexOrThrow("age"));
int sex = cursor.getInt(cursor.getColumnIndexOrThrow("sex"));
t.setTeacherName(teacherName);
t.setTeachYears(teachYears);
t.setAge(age);
if (sex == 0) {
t.setSex(false);
} else if (sex == 1) {
t.setSex(true);
}
teachers.add(t);
}
cursor.close();
return teachers;
}
示例11: onCreate
import org.litepal.tablemanager.Connector; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// litepal
Connector.getDatabase();
// 获得包名和资源,方便后面的程序使用
PACKAGE_NAME = getApplicationContext().getPackageName();
resources = getResources();
showBtn = (Button) findViewById(R.id.show_money_button);
addBtn = (CircleButton) findViewById(R.id.add_button);
ioItemRecyclerView = (RecyclerView) findViewById(R.id.in_and_out_items);
headerImg = (ImageView) findViewById(R.id.header_img);
monthlyCost = (TextView) findViewById(R.id.monthly_cost_money);
monthlyEarn = (TextView) findViewById(R.id.monthly_earn_money);
// 设置按钮监听
showBtn.setOnClickListener(new ButtonListener());
addBtn.setOnClickListener(new ButtonListener());
// 设置首页header图片长按以更换图片
headerImg.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
selectPictureFromGallery();
return false;
}
});
setImageForHeader();
}
示例12: findBySQL
import org.litepal.tablemanager.Connector; //导入依赖的package包/类
/**
* Runs the provided SQL and returns a Cursor over the result set. You may
* include ?s in where clause in the query, which will be replaced by the
* second to the last parameters, such as:
*
* <pre>
* Cursor cursor = DataSupport.findBySQL("select * from person where name=? and age=?", "Tom", "14");
* </pre>
*
* @param sql
* First parameter is the SQL clause to apply. Second to the last
* parameters will replace the place holders.
* @return A Cursor object, which is positioned before the first entry. Note
* that Cursors are not synchronized, see the documentation for more
* details.
*/
public static synchronized Cursor findBySQL(String... sql) {
BaseUtility.checkConditionsCorrect(sql);
if (sql == null) {
return null;
}
if (sql.length <= 0) {
return null;
}
String[] selectionArgs;
if (sql.length == 1) {
selectionArgs = null;
} else {
selectionArgs = new String[sql.length - 1];
System.arraycopy(sql, 1, selectionArgs, 0, sql.length - 1);
}
return Connector.getDatabase().rawQuery(sql[0], selectionArgs);
}
示例13: use
import org.litepal.tablemanager.Connector; //导入依赖的package包/类
/**
* Switch the using database to the one specified by parameter.
* @param litePalDB
* The database to switch to.
*/
public static void use(LitePalDB litePalDB) {
LitePalAttr litePalAttr = LitePalAttr.getInstance();
litePalAttr.setDbName(litePalDB.getDbName());
litePalAttr.setVersion(litePalDB.getVersion());
litePalAttr.setStorage(litePalDB.getStorage());
litePalAttr.setClassNames(litePalDB.getClassNames());
// set the extra key name only when use database other than default or litepal.xml not exists
if (!isDefaultDatabase(litePalDB.getDbName())) {
litePalAttr.setExtraKeyName(litePalDB.getDbName());
litePalAttr.setCases("lower");
}
Connector.clearLitePalOpenHelperInstance();
}
示例14: find
import org.litepal.tablemanager.Connector; //导入依赖的package包/类
/**
* It is mostly same as {@link org.litepal.crud.ClusterQuery#find(Class)} but an isEager
* parameter. If set true the associated models will be loaded as well.
* <br>
* Note that isEager will only work for one deep level relation, considering the query efficiency.
* You have to implement on your own if you need to load multiple deepness of relation at once.
*
* @param modelClass
* Which table to query and the object type to return as a list.
* @param isEager
* True to load the associated models, false not.
* @return An object list with founded data from database, or an empty list.
*/
public synchronized <T> List<T> find(Class<T> modelClass, boolean isEager) {
QueryHandler queryHandler = new QueryHandler(Connector.getDatabase());
String limit;
if (mOffset == null) {
limit = mLimit;
} else {
if (mLimit == null) {
mLimit = "0";
}
limit = mOffset + "," + mLimit;
}
return queryHandler.onFind(modelClass, mColumns, mConditions, mOrderBy, limit, isEager);
}
示例15: getForeignKeyValue
import org.litepal.tablemanager.Connector; //导入依赖的package包/类
protected long getForeignKeyValue(String tableWithFK, String tableWithoutFK, long id) {
Cursor cursor = Connector.getDatabase().query(tableWithFK, null, "id = ?",
new String[]{String.valueOf(id)}, null, null, null);
long foreignKeyId = 0;
if (cursor.moveToFirst()) {
foreignKeyId = cursor.getLong(cursor.getColumnIndexOrThrow(BaseUtility
.changeCase(tableWithoutFK + "_id")));
}
cursor.close();
return foreignKeyId;
}