本文整理汇总了Java中org.litepal.tablemanager.model.AssociationsModel.getAssociationType方法的典型用法代码示例。如果您正苦于以下问题:Java AssociationsModel.getAssociationType方法的具体用法?Java AssociationsModel.getAssociationType怎么用?Java AssociationsModel.getAssociationType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.litepal.tablemanager.model.AssociationsModel
的用法示例。
在下文中一共展示了AssociationsModel.getAssociationType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addAssociations
import org.litepal.tablemanager.model.AssociationsModel; //导入方法依赖的package包/类
/**
* Analyzing all the association models in the collection. Judge their
* association types. If it's one2one or many2one associations, add the
* foreign key column to the associated table. If it's many2many
* associations, create an intermediate join table.
*
* @param associatedModels
* A collection contains all the association models.Use the
* association models to get association type and associated
* table names.
* @param db
* Instance of SQLiteDatabase.
* @param force
* Drop the table first if it already exists.
*/
private void addAssociations(Collection<AssociationsModel> associatedModels, SQLiteDatabase db,
boolean force) {
for (AssociationsModel associationModel : associatedModels) {
if (Const.Model.MANY_TO_ONE == associationModel.getAssociationType()
|| Const.Model.ONE_TO_ONE == associationModel.getAssociationType()) {
addForeignKeyColumn(associationModel.getTableName(),
associationModel.getAssociatedTableName(),
associationModel.getTableHoldsForeignKey(), db);
} else if (Const.Model.MANY_TO_MANY == associationModel.getAssociationType()) {
createIntermediateTable(associationModel.getTableName(),
associationModel.getAssociatedTableName(), db, force);
}
}
for (GenericModel genericModel : getGenericModels()) {
createGenericTable(genericModel, db, force);
}
}
示例2: findIntermediateTablesToDrop
import org.litepal.tablemanager.model.AssociationsModel; //导入方法依赖的package包/类
/**
* When many2many associations are no longer exist between two models, the
* intermediate join table should be dropped from database. This method
* helps find out those intermediate join tables which should be dropped
* cause their associations in classes are done.
*
* @return A list with all intermediate join tables to drop.
*/
private List<String> findIntermediateTablesToDrop() {
List<String> intermediateTables = new ArrayList<String>();
for (String tableName : DBUtility.findAllTableNames(mDb)) {
if (DBUtility.isIntermediateTable(tableName, mDb)) {
boolean dropIntermediateTable = true;
for (AssociationsModel associationModel : mAssociationModels) {
if (associationModel.getAssociationType() == Const.Model.MANY_TO_MANY) {
String intermediateTableName = DBUtility.getIntermediateTableName(
associationModel.getTableName(),
associationModel.getAssociatedTableName());
if (tableName.equalsIgnoreCase(intermediateTableName)) {
dropIntermediateTable = false;
}
}
}
if (dropIntermediateTable) {
// drop the intermediate join table
intermediateTables.add(tableName);
}
}
}
LogUtil.d(TAG, "findIntermediateTablesToDrop >> " + intermediateTables);
return intermediateTables;
}
示例3: shouldDropForeignKey
import org.litepal.tablemanager.model.AssociationsModel; //导入方法依赖的package包/类
/**
* Judge if the current iterated foreign key column should be dropped. It is
* only used in {@link #findForeignKeyToRemove(org.litepal.tablemanager.model.TableModel)} when iterating
* the foreign key column list. When this foreign key can not be found in
* the association model collection, this foreign key should be dropped.
*
* @param selfTableName
* The table name of currently table model.
* @param associatedTableName
* The associated table name of current table model.
* @return If the foreign key currently iterated should be dropped, return
* true. Otherwise return false.
*/
private boolean shouldDropForeignKey(String selfTableName, String associatedTableName) {
for (AssociationsModel associationModel : mAssociationModels) {
if (associationModel.getAssociationType() == Const.Model.ONE_TO_ONE) {
if (selfTableName.equalsIgnoreCase(associationModel.getTableHoldsForeignKey())) {
if (associationModel.getTableName().equalsIgnoreCase(selfTableName)) {
if (isRelationCorrect(associationModel, selfTableName, associatedTableName)) {
return false;
}
} else if (associationModel.getAssociatedTableName().equalsIgnoreCase(
selfTableName)) {
if (isRelationCorrect(associationModel, associatedTableName, selfTableName)) {
return false;
}
}
}
} else if (associationModel.getAssociationType() == Const.Model.MANY_TO_ONE) {
if (isRelationCorrect(associationModel, associatedTableName, selfTableName)) {
return false;
}
}
}
return true;
}
示例4: addAssociations
import org.litepal.tablemanager.model.AssociationsModel; //导入方法依赖的package包/类
/**
* Analyzing all the association models in the collection. Judge their
* association types. If it's one2one or many2one associations, add the
* foreign key column to the associated table. If it's many2many
* associations, create an intermediate join table.
*
* @param associatedModels
* A collection contains all the association models.Use the
* association models to get association type and associated
* table names.
* @param db
* Instance of SQLiteDatabase.
* @param force
* Drop the table first if it already exists.
*/
private void addAssociations(Collection<AssociationsModel> associatedModels, SQLiteDatabase db,
boolean force) {
for (AssociationsModel associationModel : associatedModels) {
if (Const.Model.MANY_TO_ONE == associationModel.getAssociationType()
|| Const.Model.ONE_TO_ONE == associationModel.getAssociationType()) {
addForeignKeyColumn(associationModel.getTableName(),
associationModel.getAssociatedTableName(),
associationModel.getTableHoldsForeignKey(), db);
} else if (Const.Model.MANY_TO_MANY == associationModel.getAssociationType()) {
createIntermediateTable(associationModel.getTableName(),
associationModel.getAssociatedTableName(), db, force);
}
}
}