use of org.litepal.tablemanager.model.TableModel in project LitePal by LitePalFramework.
the class LitePalBase method getTableModel.
/**
* This method is used to get the table model by the class name passed
* in. The principle to generate table model is that each field in the class
* with non-static modifier and has a type among int/Integer, long/Long,
* short/Short, float/Float, double/Double, char/Character, boolean/Boolean
* or String, would generate a column with same name as corresponding field.
* If users don't want some of the fields map a column, declare an ignore
* annotation with {@link Column#ignore()}.
*
* @param className
* The full name of the class to map in database.
* @return A table model with table name, class name and the map of column
* name and column type.
*/
protected TableModel getTableModel(String className) {
String tableName = DBUtility.getTableNameByClassName(className);
TableModel tableModel = new TableModel();
tableModel.setTableName(tableName);
tableModel.setClassName(className);
List<Field> supportedFields = getSupportedFields(className);
for (Field field : supportedFields) {
ColumnModel columnModel = convertFieldToColumnModel(field);
tableModel.addColumnModel(columnModel);
}
return tableModel;
}
use of org.litepal.tablemanager.model.TableModel in project LitePal by LitePalFramework.
the class AssociationUpdater method getRemoveColumnSQLs.
/**
* This method create a SQL array for the whole remove dump columns job.
*
* @param removeColumnNames
* The column names need to remove.
* @param tableName
* The table name to remove from.
* @return A SQL list contains create temporary table, create new table,
* migrate data and drop temporary table.
*/
private List<String> getRemoveColumnSQLs(Collection<String> removeColumnNames, String tableName) {
TableModel tableModelFromDB = getTableModelFromDB(tableName);
String alterToTempTableSQL = generateAlterToTempTableSQL(tableName);
LogUtil.d(TAG, "generateRemoveColumnSQL >> " + alterToTempTableSQL);
String createNewTableSQL = generateCreateNewTableSQL(removeColumnNames, tableModelFromDB);
LogUtil.d(TAG, "generateRemoveColumnSQL >> " + createNewTableSQL);
String dataMigrationSQL = generateDataMigrationSQL(tableModelFromDB);
LogUtil.d(TAG, "generateRemoveColumnSQL >> " + dataMigrationSQL);
String dropTempTableSQL = generateDropTempTableSQL(tableName);
LogUtil.d(TAG, "generateRemoveColumnSQL >> " + dropTempTableSQL);
List<String> sqls = new ArrayList<String>();
sqls.add(alterToTempTableSQL);
sqls.add(createNewTableSQL);
sqls.add(dataMigrationSQL);
sqls.add(dropTempTableSQL);
return sqls;
}
use of org.litepal.tablemanager.model.TableModel in project LitePal by LitePalFramework.
the class TableStructureActivity method analyzeTableStructure.
private void analyzeTableStructure() {
TableModel tableMode = DBUtility.findPragmaTableInfo(mTableName, Connector.getDatabase());
List<ColumnModel> columnModelList = tableMode.getColumnModels();
mList.addAll(columnModelList);
}
use of org.litepal.tablemanager.model.TableModel in project LitePal by LitePalFramework.
the class AssociationUpdater method removeForeignKeyColumns.
/**
* Analyzing the table models, then remove all the foreign key columns if
* their association in model classes are no longer exist any more.
*/
private void removeForeignKeyColumns() {
for (String className : LitePalAttr.getInstance().getClassNames()) {
TableModel tableModel = getTableModel(className);
removeColumns(findForeignKeyToRemove(tableModel), tableModel.getTableName());
}
}
use of org.litepal.tablemanager.model.TableModel in project LitePal by LitePalFramework.
the class Upgrader method createOrUpgradeTable.
/**
* Analyzing the table model, them remove the dump columns and add new
* columns of a table.
*/
@Override
protected void createOrUpgradeTable(SQLiteDatabase db, boolean force) {
mDb = db;
for (TableModel tableModel : getAllTableModels()) {
mTableModel = tableModel;
mTableModelDB = getTableModelFromDB(tableModel.getTableName());
LogUtil.d(TAG, "createOrUpgradeTable: model is " + mTableModel.getTableName());
upgradeTable();
}
}
Aggregations