Search in sources :

Example 1 with ConflictAction

use of com.activeandroid.annotation.Column.ConflictAction in project ActiveAndroid by pardom.

the class SQLiteUtils method createUniqueColumnDefinition.

public static void createUniqueColumnDefinition(TableInfo tableInfo, Field field) {
    final String name = tableInfo.getColumnName(field);
    final Column column = field.getAnnotation(Column.class);
    if (field.getName().equals("mId")) {
        return;
    }
    String[] groups = column.uniqueGroups();
    ConflictAction[] conflictActions = column.onUniqueConflicts();
    if (groups.length != conflictActions.length)
        return;
    for (int i = 0; i < groups.length; i++) {
        String group = groups[i];
        ConflictAction conflictAction = conflictActions[i];
        if (TextUtils.isEmpty(group))
            continue;
        List<String> list = sUniqueGroupMap.get(group);
        if (list == null) {
            list = new ArrayList<String>();
        }
        list.add(name);
        sUniqueGroupMap.put(group, list);
        sOnUniqueConflictsMap.put(group, conflictAction);
    }
}
Also used : ConflictAction(com.activeandroid.annotation.Column.ConflictAction) Column(com.activeandroid.annotation.Column) String(java.lang.String)

Example 2 with ConflictAction

use of com.activeandroid.annotation.Column.ConflictAction in project ActiveAndroid by pardom.

the class SQLiteUtils method createUniqueDefinition.

// Database creation
public static ArrayList<String> createUniqueDefinition(TableInfo tableInfo) {
    final ArrayList<String> definitions = new ArrayList<String>();
    sUniqueGroupMap = new HashMap<String, List<String>>();
    sOnUniqueConflictsMap = new HashMap<String, ConflictAction>();
    for (Field field : tableInfo.getFields()) {
        createUniqueColumnDefinition(tableInfo, field);
    }
    if (sUniqueGroupMap.isEmpty()) {
        return definitions;
    }
    Set<String> keySet = sUniqueGroupMap.keySet();
    for (String key : keySet) {
        List<String> group = sUniqueGroupMap.get(key);
        ConflictAction conflictAction = sOnUniqueConflictsMap.get(key);
        definitions.add(String.format("UNIQUE (%s) ON CONFLICT %s", TextUtils.join(", ", group), conflictAction.toString()));
    }
    return definitions;
}
Also used : ConflictAction(com.activeandroid.annotation.Column.ConflictAction) Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) String(java.lang.String)

Aggregations

ConflictAction (com.activeandroid.annotation.Column.ConflictAction)2 String (java.lang.String)2 Column (com.activeandroid.annotation.Column)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1