Prefixed id with _ so Raw Packet Table will work with cursor adapters.
Prefixed id with _ so Raw Packet Table will work with cursor adapters.

package com.dryerzinia.aprs_x.db.table; package com.dryerzinia.aprs_x.db.table;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import com.dryerzinia.aprs_x.data_model.packet.RawPacket; import com.dryerzinia.aprs_x.data_model.packet.RawPacket;
import android.content.ContentValues; import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
public class RawPacketTable { public class RawPacketTable {
public static final String TABLE_RAW_PACKET = "packet_master"; public static final String TABLE_RAW_PACKET = "packet_master";
public static final String COLUMN_ID = "id"; public static final String COLUMN_ID = "_id";
public static final String COLUMN_TIME_STAMP = "time_stamp"; public static final String COLUMN_TIME_STAMP = "time_stamp";
public static final String COLUMN_SOURCE_ADDRESS = "source_address"; public static final String COLUMN_SOURCE_ADDRESS = "source_address";
public static final String COLUMN_DESTINATION_ADDRESS = "desination_address"; public static final String COLUMN_DESTINATION_ADDRESS = "desination_address";
public static final String COLUMN_REPEATER_1_ADDRESS = "repeater_1_address"; public static final String COLUMN_REPEATER_1_ADDRESS = "repeater_1_address";
public static final String COLUMN_REPEATER_2_ADDRESS = "repeater_2_address"; public static final String COLUMN_REPEATER_2_ADDRESS = "repeater_2_address";
public static final String COLUMN_REPEATER_3_ADDRESS = "repeater_3_address"; public static final String COLUMN_REPEATER_3_ADDRESS = "repeater_3_address";
public static final String COLUMN_REPEATER_4_ADDRESS = "repeater_4_address"; public static final String COLUMN_REPEATER_4_ADDRESS = "repeater_4_address";
public static final String COLUMN_REPEATER_5_ADDRESS = "repeater_5_address"; public static final String COLUMN_REPEATER_5_ADDRESS = "repeater_5_address";
public static final String COLUMN_REPEATER_6_ADDRESS = "repeater_6_address"; public static final String COLUMN_REPEATER_6_ADDRESS = "repeater_6_address";
public static final String COLUMN_REPEATER_7_ADDRESS = "repeater_7_address"; public static final String COLUMN_REPEATER_7_ADDRESS = "repeater_7_address";
public static final String COLUMN_REPEATER_8_ADDRESS = "repeater_8_address"; public static final String COLUMN_REPEATER_8_ADDRESS = "repeater_8_address";
public static final String COLUMN_PACKET_TYPE = "packet_type"; public static final String COLUMN_PACKET_TYPE = "packet_type";
public static final String COLUMN_PACKET_TYPE_DATA_ID = "packet_type_data_id"; public static final String COLUMN_PACKET_TYPE_DATA_ID = "packet_type_data_id";
public static final String COLUMN_RAW_DATA = "raw_rata"; public static final String COLUMN_RAW_DATA = "raw_rata";
public static final String TABLE_CREATE = public static final String TABLE_CREATE =
"create table " + TABLE_RAW_PACKET "create table " + TABLE_RAW_PACKET
+ "(" + "("
+ COLUMN_ID + " INTEGER primary key autoincrement, " + COLUMN_ID + " INTEGER primary key autoincrement, "
+ COLUMN_TIME_STAMP + " INTEGER not null, " + COLUMN_TIME_STAMP + " INTEGER not null, "
+ COLUMN_SOURCE_ADDRESS + " TEXT not null, " + COLUMN_SOURCE_ADDRESS + " TEXT not null, "
+ COLUMN_DESTINATION_ADDRESS + " TEXT not null, " + COLUMN_DESTINATION_ADDRESS + " TEXT not null, "
+ COLUMN_REPEATER_1_ADDRESS + " TEXT, " + COLUMN_REPEATER_1_ADDRESS + " TEXT, "
+ COLUMN_REPEATER_2_ADDRESS + " TEXT, " + COLUMN_REPEATER_2_ADDRESS + " TEXT, "
+ COLUMN_REPEATER_3_ADDRESS + " TEXT, " + COLUMN_REPEATER_3_ADDRESS + " TEXT, "
+ COLUMN_REPEATER_4_ADDRESS + " TEXT, " + COLUMN_REPEATER_4_ADDRESS + " TEXT, "
+ COLUMN_REPEATER_5_ADDRESS + " TEXT, " + COLUMN_REPEATER_5_ADDRESS + " TEXT, "
+ COLUMN_REPEATER_6_ADDRESS + " TEXT, " + COLUMN_REPEATER_6_ADDRESS + " TEXT, "
+ COLUMN_REPEATER_7_ADDRESS + " TEXT, " + COLUMN_REPEATER_7_ADDRESS + " TEXT, "
+ COLUMN_REPEATER_8_ADDRESS + " TEXT, " + COLUMN_REPEATER_8_ADDRESS + " TEXT, "
+ COLUMN_PACKET_TYPE + " INTEGER, " + COLUMN_PACKET_TYPE + " INTEGER, "
+ COLUMN_PACKET_TYPE_DATA_ID + " INTEGER, " + COLUMN_PACKET_TYPE_DATA_ID + " INTEGER, "
+ COLUMN_RAW_DATA + " BLOB" + COLUMN_RAW_DATA + " BLOB"
+ ");"; + ");";
private static final HashSet<String> availableColumns = private static final HashSet<String> availableColumns =
new HashSet<String>( new HashSet<String>(
Arrays.asList(new String[]{ Arrays.asList(new String[]{
COLUMN_ID, COLUMN_ID,
COLUMN_TIME_STAMP, COLUMN_TIME_STAMP,
COLUMN_SOURCE_ADDRESS, COLUMN_SOURCE_ADDRESS,
COLUMN_DESTINATION_ADDRESS, COLUMN_DESTINATION_ADDRESS,
COLUMN_REPEATER_1_ADDRESS, COLUMN_REPEATER_1_ADDRESS,
COLUMN_REPEATER_2_ADDRESS, COLUMN_REPEATER_2_ADDRESS,
COLUMN_REPEATER_3_ADDRESS, COLUMN_REPEATER_3_ADDRESS,
COLUMN_REPEATER_4_ADDRESS, COLUMN_REPEATER_4_ADDRESS,
COLUMN_REPEATER_5_ADDRESS, COLUMN_REPEATER_5_ADDRESS,
COLUMN_REPEATER_6_ADDRESS, COLUMN_REPEATER_6_ADDRESS,
COLUMN_REPEATER_7_ADDRESS, COLUMN_REPEATER_7_ADDRESS,
COLUMN_REPEATER_8_ADDRESS, COLUMN_REPEATER_8_ADDRESS,
COLUMN_PACKET_TYPE, COLUMN_PACKET_TYPE,
COLUMN_PACKET_TYPE_DATA_ID, COLUMN_PACKET_TYPE_DATA_ID,
COLUMN_RAW_DATA COLUMN_RAW_DATA
}) })
); );
public RawPacketTable(){ public RawPacketTable(){
// //
} }
public static void onCreate(SQLiteDatabase db){ public static void onCreate(SQLiteDatabase db){
db.execSQL(TABLE_CREATE); db.execSQL(TABLE_CREATE);
} }
public static void onUpgrade(SQLiteDatabase db){ public static void onUpgrade(SQLiteDatabase db){
db.execSQL("DROP TABLE IF EXISTS " + TABLE_RAW_PACKET); db.execSQL("DROP TABLE IF EXISTS " + TABLE_RAW_PACKET);
onCreate(db); onCreate(db);
} }
public static ContentValues getContentValues(RawPacket pkt){ public static ContentValues getContentValues(RawPacket pkt){
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(RawPacketTable.COLUMN_TIME_STAMP, pkt.getTimeStamp()); values.put(RawPacketTable.COLUMN_TIME_STAMP, pkt.getTimeStamp());
values.put(RawPacketTable.COLUMN_SOURCE_ADDRESS, pkt.getSourceAddress()); values.put(RawPacketTable.COLUMN_SOURCE_ADDRESS, pkt.getSourceAddress());
values.put(RawPacketTable.COLUMN_DESTINATION_ADDRESS, pkt.getDestinationAddress()); values.put(RawPacketTable.COLUMN_DESTINATION_ADDRESS, pkt.getDestinationAddress());
List<String> repeaterAddresses = pkt.getRepeaterAddress(); List<String> repeaterAddresses = pkt.getRepeaterAddress();
if(repeaterAddresses.size() >= 1) if(repeaterAddresses.size() >= 1)
values.put(RawPacketTable.COLUMN_REPEATER_1_ADDRESS, repeaterAddresses.get(0)); values.put(RawPacketTable.COLUMN_REPEATER_1_ADDRESS, repeaterAddresses.get(0));
if(repeaterAddresses.size() >= 2) if(repeaterAddresses.size() >= 2)
values.put(RawPacketTable.COLUMN_REPEATER_2_ADDRESS, repeaterAddresses.get(1)); values.put(RawPacketTable.COLUMN_REPEATER_2_ADDRESS, repeaterAddresses.get(1));
if(repeaterAddresses.size() >= 3) if(repeaterAddresses.size() >= 3)
values.put(RawPacketTable.COLUMN_REPEATER_3_ADDRESS, repeaterAddresses.get(2)); values.put(RawPacketTable.COLUMN_REPEATER_3_ADDRESS, repeaterAddresses.get(2));
if(repeaterAddresses.size() >= 4) if(repeaterAddresses.size() >= 4)
values.put(RawPacketTable.COLUMN_REPEATER_4_ADDRESS, repeaterAddresses.get(3)); values.put(RawPacketTable.COLUMN_REPEATER_4_ADDRESS, repeaterAddresses.get(3));
if(repeaterAddresses.size() >= 5) if(repeaterAddresses.size() >= 5)
values.put(RawPacketTable.COLUMN_REPEATER_5_ADDRESS, repeaterAddresses.get(4)); values.put(RawPacketTable.COLUMN_REPEATER_5_ADDRESS, repeaterAddresses.get(4));
if(repeaterAddresses.size() >= 6) if(repeaterAddresses.size() >= 6)
values.put(RawPacketTable.COLUMN_REPEATER_6_ADDRESS, repeaterAddresses.get(5)); values.put(RawPacketTable.COLUMN_REPEATER_6_ADDRESS, repeaterAddresses.get(5));
if(repeaterAddresses.size() >= 7) if(repeaterAddresses.size() >= 7)
values.put(RawPacketTable.COLUMN_REPEATER_7_ADDRESS, repeaterAddresses.get(6)); values.put(RawPacketTable.COLUMN_REPEATER_7_ADDRESS, repeaterAddresses.get(6));
if(repeaterAddresses.size() >= 8) if(repeaterAddresses.size() >= 8)
values.put(RawPacketTable.COLUMN_REPEATER_8_ADDRESS, repeaterAddresses.get(7)); values.put(RawPacketTable.COLUMN_REPEATER_8_ADDRESS, repeaterAddresses.get(7));
values.put(RawPacketTable.COLUMN_RAW_DATA, pkt.getRawData()); values.put(RawPacketTable.COLUMN_RAW_DATA, pkt.getRawData());
return values; return values;
} }
public static void checkColumns(String[] projection){ public static void checkColumns(String[] projection){
if(projection != null) { if(projection != null) {
HashSet<String> requestedColumns = new HashSet<String>(Arrays.asList(projection)); HashSet<String> requestedColumns = new HashSet<String>(Arrays.asList(projection));
if(!availableColumns.containsAll(requestedColumns)){ if(!availableColumns.containsAll(requestedColumns)){
throw new IllegalArgumentException("Unknown columns in projection"); throw new IllegalArgumentException("Unknown columns in projection");
} }
} }
} }
} }