// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class ContactsContract {
//     public static final String TABLE_NAME = "contacts";
// 
//     public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build();
//     public static final int ALL_URI_CODE = 2;
//     public static final int URI_CODE = 3;
// 
//     public static class ContactEntry {
//         public static final String ID = BaseColumns._ID;
//         public static final String UUID = "uuid";
//         public static final String NAME = "name";
//     }
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class ContactEntry {
//     public static final String ID = BaseColumns._ID;
//     public static final String UUID = "uuid";
//     public static final String NAME = "name";
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class MessagesContract {
//     public static final String TABLE_NAME = "messages";
// 
//     public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build();
//     public static final int ALL_URI_CODE = 0;
//     public static final int URI_CODE = 1;
// 
//     public static class MessageEntry {
//         public static final String ID = BaseColumns._ID;
//         public static final String SENDER_UUID = "sender_uuid";
//         public static final String SENDER_NAME = "sender_name";
//         public static final String MESSAGE = "message";
//         public static final String RECEIVED_TIME = "received_time";
//     }
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class MessageEntry {
//     public static final String ID = BaseColumns._ID;
//     public static final String SENDER_UUID = "sender_uuid";
//     public static final String SENDER_NAME = "sender_name";
//     public static final String MESSAGE = "message";
//     public static final String RECEIVED_TIME = "received_time";
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java
// public interface QueryContactsUuidsCallback {
// 
//     void onComplete(@NonNull final Set<String> uuids);
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Contact.java
// public final class Contact {
// 
//     @NonNull
//     private final String name;
// 
//     @NonNull
//     private final String uuid;
// 
//     public Contact(@NonNull final String name, @NonNull final String uuid) {
//         this.name = name;
//         this.uuid = uuid;
//     }
// 
//     @NonNull
//     public String getName() {
//         return name;
//     }
// 
//     @NonNull
//     public String getUuid() {
//         return uuid;
//     }
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Message.java
// public final class Message {
// 
//     @NonNull
//     private final String senderUuid;
// 
//     @NonNull
//     private final String messageText;
// 
//     private final long receivedTime;
// 
//     public Message(@NonNull final String senderUuid,
//                    @NonNull final String messageText,
//                    final long receivedTime) {
//         this.senderUuid = senderUuid;
//         this.messageText = messageText;
//         this.receivedTime = receivedTime;
//     }
// 
//     @NonNull
//     public String getSenderUuid() {
//         return senderUuid;
//     }
// 
//     @NonNull
//     public String getMessageText() {
//         return messageText;
//     }
// 
//     public long getReceivedTime() {
//         return receivedTime;
//     }
// }


import org.onepf.pushchat.model.db.Message;
import java.util.HashSet;
import java.util.Set;
import android.content.AsyncQueryHandler;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.NonNull;
import org.onepf.pushchat.db.ContentDescriptor.ContactsContract;
import org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry;
import org.onepf.pushchat.db.ContentDescriptor.MessagesContract;
import org.onepf.pushchat.db.ContentDescriptor.MessagesContract.MessageEntry;
import org.onepf.pushchat.db.DatabaseHelper.ContactsUuidsAsyncQueryHandler.QueryContactsUuidsCallback;
import org.onepf.pushchat.model.db.Contact;
/*
 * Copyright 2012-2015 One Platform Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.onepf.pushchat.db;



/**
 * @author Roman Savin
 * @since 06.05.2015
 */
@SuppressWarnings("PMD.NonThreadSafeSingleton")
public final class DatabaseHelper extends SQLiteOpenHelper {

    private static final String DATABASE_NAME = "org.onepf.pushchat.db";
    private static final int DATABASE_VERSION = 1;

    private static final String COMMA_SEP = ",";

    private static final String SQL_CREATE_CONTACTS_TABLE =
            "CREATE TABLE " + ContactsContract.TABLE_NAME + " ( "
                    + ContactEntry.ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL" + COMMA_SEP
                    + ContactEntry.NAME + " TEXT" + COMMA_SEP
                    + ContactEntry.UUID + " TEXT UNIQUE NOT NULL"
                    + " )";

    private static final String SQL_CREATE_MESSAGES_TABLE =
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class ContactsContract {
//     public static final String TABLE_NAME = "contacts";
// 
//     public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build();
//     public static final int ALL_URI_CODE = 2;
//     public static final int URI_CODE = 3;
// 
//     public static class ContactEntry {
//         public static final String ID = BaseColumns._ID;
//         public static final String UUID = "uuid";
//         public static final String NAME = "name";
//     }
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class ContactEntry {
//     public static final String ID = BaseColumns._ID;
//     public static final String UUID = "uuid";
//     public static final String NAME = "name";
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class MessagesContract {
//     public static final String TABLE_NAME = "messages";
// 
//     public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build();
//     public static final int ALL_URI_CODE = 0;
//     public static final int URI_CODE = 1;
// 
//     public static class MessageEntry {
//         public static final String ID = BaseColumns._ID;
//         public static final String SENDER_UUID = "sender_uuid";
//         public static final String SENDER_NAME = "sender_name";
//         public static final String MESSAGE = "message";
//         public static final String RECEIVED_TIME = "received_time";
//     }
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class MessageEntry {
//     public static final String ID = BaseColumns._ID;
//     public static final String SENDER_UUID = "sender_uuid";
//     public static final String SENDER_NAME = "sender_name";
//     public static final String MESSAGE = "message";
//     public static final String RECEIVED_TIME = "received_time";
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java
// public interface QueryContactsUuidsCallback {
// 
//     void onComplete(@NonNull final Set<String> uuids);
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Contact.java
// public final class Contact {
// 
//     @NonNull
//     private final String name;
// 
//     @NonNull
//     private final String uuid;
// 
//     public Contact(@NonNull final String name, @NonNull final String uuid) {
//         this.name = name;
//         this.uuid = uuid;
//     }
// 
//     @NonNull
//     public String getName() {
//         return name;
//     }
// 
//     @NonNull
//     public String getUuid() {
//         return uuid;
//     }
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Message.java
// public final class Message {
// 
//     @NonNull
//     private final String senderUuid;
// 
//     @NonNull
//     private final String messageText;
// 
//     private final long receivedTime;
// 
//     public Message(@NonNull final String senderUuid,
//                    @NonNull final String messageText,
//                    final long receivedTime) {
//         this.senderUuid = senderUuid;
//         this.messageText = messageText;
//         this.receivedTime = receivedTime;
//     }
// 
//     @NonNull
//     public String getSenderUuid() {
//         return senderUuid;
//     }
// 
//     @NonNull
//     public String getMessageText() {
//         return messageText;
//     }
// 
//     public long getReceivedTime() {
//         return receivedTime;
//     }
// }


// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java
import org.onepf.pushchat.model.db.Message;
import java.util.HashSet;
import java.util.Set;
import android.content.AsyncQueryHandler;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.NonNull;
import org.onepf.pushchat.db.ContentDescriptor.ContactsContract;
import org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry;
import org.onepf.pushchat.db.ContentDescriptor.MessagesContract;
import org.onepf.pushchat.db.ContentDescriptor.MessagesContract.MessageEntry;
import org.onepf.pushchat.db.DatabaseHelper.ContactsUuidsAsyncQueryHandler.QueryContactsUuidsCallback;
import org.onepf.pushchat.model.db.Contact;

/*
 * Copyright 2012-2015 One Platform Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.onepf.pushchat.db;



/**
 * @author Roman Savin
 * @since 06.05.2015
 */
@SuppressWarnings("PMD.NonThreadSafeSingleton")
public final class DatabaseHelper extends SQLiteOpenHelper {

    private static final String DATABASE_NAME = "org.onepf.pushchat.db";
    private static final int DATABASE_VERSION = 1;

    private static final String COMMA_SEP = ",";

    private static final String SQL_CREATE_CONTACTS_TABLE =
            "CREATE TABLE " + ContactsContract.TABLE_NAME + " ( "
                    + ContactEntry.ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL" + COMMA_SEP
                    + ContactEntry.NAME + " TEXT" + COMMA_SEP
                    + ContactEntry.UUID + " TEXT UNIQUE NOT NULL"
                    + " )";

    private static final String SQL_CREATE_MESSAGES_TABLE =
            "CREATE TABLE " + MessagesContract.TABLE_NAME + " ( "