本文整理汇总了Java中org.litepal.tablemanager.Connector.getDatabase方法的典型用法代码示例。如果您正苦于以下问题:Java Connector.getDatabase方法的具体用法?Java Connector.getDatabase怎么用?Java Connector.getDatabase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.litepal.tablemanager.Connector
的用法示例。
在下文中一共展示了Connector.getDatabase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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();
}
}
示例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: 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();
}
}
示例5: onCreate
import org.litepal.tablemanager.Connector; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//初始化XMenu(自己做的一个自定义控件 https://github.com/monkeywiiu/Xmenu)
initXMenu();
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);
initBinding();
initFragmentList();
loadViewPager();
initBottomBar();
//创建litepal数据库
Connector.getDatabase();
}
示例6: setupViews
import org.litepal.tablemanager.Connector; //导入方法依赖的package包/类
@Override
protected void setupViews() {
SQLiteDatabase db = Connector.getDatabase();
mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
setSupportActionBar(mToolbar);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getSupportFragmentManager().findFragmentById(R.id.fragment_drawer);
// Set up the drawer.
mNavigationDrawerFragment.setup(R.id.fragment_drawer, (DrawerLayout) findViewById(R.id.drawer), mToolbar);
// populate the navigation drawer
}
示例7: 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.
*
* @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);
}
示例8: praseJsonWithGson
import org.litepal.tablemanager.Connector; //导入方法依赖的package包/类
public static void praseJsonWithGson(String jsonData) {
Gson gson = new Gson();
GsonModel gsonModel = gson.fromJson(jsonData, new TypeToken<GsonModel>() {
}.getType());
ArrayList<GsonModel.Model> models = gsonModel.getResult();
SQLiteDatabase db = Connector.getDatabase();
ArrayList<WeatherCity> cities=new ArrayList<WeatherCity>();
for(int i=0;i<models.size();i++)
{
WeatherCity city=new WeatherCity();
GsonModel.Model model=models.get(i);
city.setServer_id(model.getId());
city.setProvince_name(model.getProvince());
city.setCity_name(model.getCity());
city.setDistrict_name(model.getDistrict());
cities.add(city);
}
DataSupport.saveAll(cities);
List<WeatherCity> cityList=DataSupport.select("province_name").where(
"id IN (select MAX(id) from WeatherCity GROUP BY province_name)").find(WeatherCity.class);
ArrayList<WeatherProvince> provinces=new ArrayList<WeatherProvince>();
for (int i=0;i<cityList.size();i++)
{
WeatherCity weatherCity=cityList.get(i);
WeatherProvince weatherProvince=new WeatherProvince();
weatherProvince.setProvince_name(weatherCity.getProvince_name());
provinces.add(weatherProvince);
}
DataSupport.saveAll(provinces);
SharedPreferencesUtil.getInstance().getEditor().putBoolean("isexsit", true).commit();
}
示例9: setUp
import org.litepal.tablemanager.Connector; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
db = Connector.getDatabase();
}
示例10: getInstance
import org.litepal.tablemanager.Connector; //导入方法依赖的package包/类
public static DataManager getInstance() throws IOException {
Connector.getDatabase();
// dataManager.init();
return InnerHelper.dataManager;
}
示例11: setUp
import org.litepal.tablemanager.Connector; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
Connector.getDatabase();
}
示例12: saveOrUpdate
import org.litepal.tablemanager.Connector; //导入方法依赖的package包/类
/**
* Save the model if the conditions data not exist, or update the matching models if the conditions data exist. <br>
*
* <pre>
* Person person = new Person();
* person.setName("Tom");
* person.setAge(22);
* person.saveOrUpdate("name = ?", "Tom");
* </pre>
*
* If person table doesn't have a name with Tom, a new record gets created in the database,
* otherwise all records which names are Tom will be updated.<br>
* If saving process failed by any accident, the whole action will be
* cancelled and your database will be <b>rolled back</b>. <br>
* If the model has a field named id or _id and field type is int or long,
* the id value generated by database will assign to it after the model is
* saved.<br>
* Note that if the associated models of this model is already saved. The
* associations between them will be built automatically in database after
* it saved.
*
* @param conditions
* A string array representing the WHERE part of an SQL
* statement. First parameter is the WHERE clause to apply when
* updating. The way of specifying place holders is to insert one
* or more question marks in the SQL. The first question mark is
* replaced by the second element of the array, the next question
* mark by the third, and so on. Passing empty string will update
* all rows.
* @return If the model saved or updated successfully, return true. Otherwise return false.
*/
@SuppressWarnings("unchecked")
public synchronized boolean saveOrUpdate(String... conditions) {
if (conditions == null) {
return save();
}
List<DataSupport> list = (List<DataSupport>) where(conditions).find(getClass());
if (list.isEmpty()) {
return save();
} else {
SQLiteDatabase db = Connector.getDatabase();
db.beginTransaction();
try {
for (DataSupport dataSupport : list) {
baseObjId = dataSupport.getBaseObjId();
SaveHandler saveHandler = new SaveHandler(db);
saveHandler.onSave(this);
clearAssociatedData();
}
db.setTransactionSuccessful();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
db.endTransaction();
}
}
}
示例13: saveThrows
import org.litepal.tablemanager.Connector; //导入方法依赖的package包/类
/**
* Saves the model. <br>
*
* <pre>
* Person person = new Person();
* person.setName("Tom");
* person.setAge(22);
* person.saveThrows();
* </pre>
*
* If the model is a new record gets created in the database, otherwise the
* existing record gets updated.<br>
* If saving process failed by any accident, the whole action will be
* cancelled and your database will be <b>rolled back</b> and throws
* {@link DataSupportException}<br>
* If the model has a field named id or _id and field type is int or long,
* the id value generated by database will assign to it after the model is
* saved.<br>
* Note that if the associated models of this model is already saved. The
* associations between them will be built automatically in database after
* it saved.
*
* @throws DataSupportException
*/
public synchronized void saveThrows() {
SQLiteDatabase db = Connector.getDatabase();
db.beginTransaction();
try {
SaveHandler saveHandler = new SaveHandler(db);
saveHandler.onSave(this);
clearAssociatedData();
db.setTransactionSuccessful();
} catch (Exception e) {
throw new DataSupportException(e.getMessage(), e);
} finally {
db.endTransaction();
}
}
示例14: delete
import org.litepal.tablemanager.Connector; //导入方法依赖的package包/类
/**
* Deletes the record in the database by id.<br>
* The data in other tables which is referenced with the record will be
* removed too.
*
* <pre>
* DataSupport.delete(Person.class, 1);
* </pre>
*
* This means that the record 1 in person table will be removed.
*
* @param modelClass
* Which table to delete from by class.
* @param id
* Which record to delete.
* @return The number of rows affected. Including cascade delete rows.
*/
public static synchronized int delete(Class<?> modelClass, long id) {
int rowsAffected = 0;
SQLiteDatabase db = Connector.getDatabase();
db.beginTransaction();
try {
DeleteHandler deleteHandler = new DeleteHandler(db);
rowsAffected = deleteHandler.onDelete(modelClass, id);
db.setTransactionSuccessful();
return rowsAffected;
} finally {
db.endTransaction();
}
}
示例15: saveAll
import org.litepal.tablemanager.Connector; //导入方法依赖的package包/类
/**
* Saves the collection into database. <br>
*
* <pre>
* DataSupport.saveAll(people);
* </pre>
*
* If the model in collection is a new record gets created in the database,
* otherwise the existing record gets updated.<br>
* If saving process failed by any accident, the whole action will be
* cancelled and your database will be <b>rolled back</b>. <br>
* This method acts the same result as the below way, but <b>much more
* efficient</b>.
*
* <pre>
* for (Person person : people) {
* person.save();
* }
* </pre>
*
* So when your collection holds huge of models,
* {@link #saveAll(java.util.Collection)} is the better choice.
*
* @param collection
* Holds all models to save.
*/
public static synchronized <T extends DataSupport> void saveAll(Collection<T> collection) {
SQLiteDatabase db = Connector.getDatabase();
db.beginTransaction();
try {
SaveHandler saveHandler = new SaveHandler(db);
saveHandler.onSaveAll(collection);
db.setTransactionSuccessful();
} catch (Exception e) {
throw new DataSupportException(e.getMessage(), e);
} finally {
db.endTransaction();
}
}