public int[] keys() { return map.keys(); }
public long remove(int key1, int key2, int key3) { int key = key(key1, key2, key3); return map.remove(key); }
public TIntLongIterator iterator() { return map.iterator(); }
public TIntSet keySet() { return map.keySet(); }
public boolean increment(int key1, int key2, int key3) { int key = key(key1, key2, key3); return map.increment(key); }
public boolean isEmpty() { return map.isEmpty(); }
public void clear() { map.clear(); }
public boolean containsValue(long val) { return map.containsValue(val); }
public long get(int key1, int key2, int key3) { int key = key(key1, key2, key3); return map.get(key); }
public boolean containsKey(int key1, int key2, int key3) { int key = key(key1, key2, key3); return map.containsKey(key); }
public long put(int key1, int key2, int key3, long value) { int key = key(key1, key2, key3); return map.put(key, value); }
public long[] values() { return map.values(); }
public TLongCollection valueCollection() { return map.valueCollection(); }
public int size() { return map.size(); }
public void importBukmak( List<Bookmark2> xbukmak, boolean tumpuk, TObjectIntHashMap<Bookmark2> bukmakToRelIdMap, TIntLongHashMap labelRelIdToAbsIdMap, TIntObjectHashMap<TIntList> bukmak2RelIdToLabelRelIdsMap) { SQLiteDatabase db = helper.getWritableDatabase(); db.beginTransaction(); try { TIntLongHashMap bukmakRelIdToAbsIdMap = new TIntLongHashMap(); { // tulis bukmak2 baru String[] params1 = new String[1]; String[] params2 = new String[2]; for (Bookmark2 bukmak : xbukmak) { int bukmak2_relId = bukmakToRelIdMap.get(bukmak); params2[0] = String.valueOf(bukmak.ari); params2[1] = String.valueOf(bukmak.jenis); long _id = -1; boolean ada = false; Cursor cursor = db.query( Db.TABEL_Bukmak2, null, Db.Bukmak2.ari + "=? and " + Db.Bukmak2.jenis + "=?", params2, null, null, null); //$NON-NLS-1$ //$NON-NLS-2$ if (cursor.moveToNext()) { ada = true; _id = cursor.getLong(cursor.getColumnIndexOrThrow(BaseColumns._ID)); /* [1] */ } cursor.close(); // --------------------------------- dapet _id dari // ada tumpuk: delete insert [2] // ada !tumpuk: (nop) [1] // !ada tumpuk: insert [2] // !ada !tumpuk: insert [2] if (ada && tumpuk) { params1[0] = String.valueOf(_id); db.delete(Db.TABEL_Bukmak2, "_id=?", params1); // $NON-NLS-1$ db.delete( Db.TABEL_Bukmak2_Label, Db.Bukmak2_Label.bukmak2_id + "=?", params1); // $NON-NLS-1$ } if ((ada && tumpuk) || (!ada)) { _id = db.insert(Db.TABEL_Bukmak2, null, bukmak.toContentValues()); /* [2] */ } // map it bukmakRelIdToAbsIdMap.put(bukmak2_relId, _id); } } { // sekarang pemasangan label String where = Db.Bukmak2_Label.bukmak2_id + "=?"; // $NON-NLS-1$ String[] params = {null}; ContentValues cv = new ContentValues(); // nlabel>0 tumpuk: delete insert // nlabel>0 !tumpuk: (nop) // nlabel=0 tumpuk: insert // nlabel=0 !tumpuk: insert for (int bukmak2_relId : bukmak2RelIdToLabelRelIdsMap.keys()) { TIntList label_relIds = bukmak2RelIdToLabelRelIdsMap.get(bukmak2_relId); long bukmak2_id = bukmakRelIdToAbsIdMap.get(bukmak2_relId); if (bukmak2_id > 0) { params[0] = String.valueOf(bukmak2_id); // cek ada berapa label untuk bukmak2_id ini int nlabel = 0; Cursor c = db.rawQuery( "select count(*) from " + Db.TABEL_Bukmak2_Label + " where " + where, params); //$NON-NLS-1$ //$NON-NLS-2$ try { c.moveToNext(); nlabel = c.getInt(0); } finally { c.close(); } if (nlabel > 0 && tumpuk) { db.delete(Db.TABEL_Bukmak2_Label, where, params); } if ((nlabel > 0 && tumpuk) || (!(nlabel > 0))) { for (int label_relId : label_relIds.toArray()) { long label_id = labelRelIdToAbsIdMap.get(label_relId); if (label_id > 0) { cv.put(Db.Bukmak2_Label.bukmak2_id, bukmak2_id); cv.put(Db.Bukmak2_Label.label_id, label_id); db.insert(Db.TABEL_Bukmak2_Label, null, cv); } else { Log.w(TAG, "label_id ngaco!: " + label_id); // $NON-NLS-1$ } } } } else { Log.w(TAG, "bukmak2_id ngaco!: " + bukmak2_id); // $NON-NLS-1$ } } } db.setTransactionSuccessful(); } finally { db.endTransaction(); } }