forked from littleinc/android-orm-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request littleinc#2 from MazyNoc/optimized-raw-sql
New optimized raw sql executor
- Loading branch information
Showing
6 changed files
with
542 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
ORM-Benchmark/src/main/java/com/littleinc/orm_benchmark/optimizedsqlite/DataBaseHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.littleinc.orm_benchmark.optimizedsqlite; | ||
|
||
import android.content.Context; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.database.sqlite.SQLiteOpenHelper; | ||
|
||
public class DataBaseHelper extends SQLiteOpenHelper { | ||
|
||
// DB CONFIG | ||
private static int DB_VERSION = 1; | ||
|
||
private static String DB_NAME = "sqliteopt_db"; | ||
|
||
public DataBaseHelper(Context context, boolean isInMemory) { | ||
super(context, (isInMemory ? null : DB_NAME), null, DB_VERSION); | ||
} | ||
|
||
@Override | ||
public void onCreate(SQLiteDatabase db) { | ||
} | ||
|
||
@Override | ||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | ||
} | ||
} |
160 changes: 160 additions & 0 deletions
160
ORM-Benchmark/src/main/java/com/littleinc/orm_benchmark/optimizedsqlite/Message.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package com.littleinc.orm_benchmark.optimizedsqlite; | ||
|
||
import android.database.sqlite.SQLiteDatabase; | ||
import android.database.sqlite.SQLiteStatement; | ||
import android.provider.BaseColumns; | ||
|
||
import java.util.List; | ||
|
||
public class Message { | ||
|
||
public static final String TABLE_NAME = "message"; | ||
|
||
public static final String CONTENT = "content"; | ||
|
||
public static final String READERS = "readers"; | ||
|
||
public static final String SORTED_BY = "sorted_by"; | ||
|
||
public static final String CLIENT_ID = "client_id"; | ||
|
||
public static final String SENDER_ID = "sender_id"; | ||
|
||
public static final String CHANNEL_ID = "channel_id"; | ||
|
||
public static final String COMMAND_ID = "command_id"; | ||
|
||
public static final String CREATED_AT = "created_at"; | ||
|
||
private long mId; | ||
|
||
private long mClientId; | ||
|
||
private long mCommandId; | ||
|
||
private double mSortedBy; | ||
|
||
private int mCreatedAt; | ||
|
||
private String mContent; | ||
|
||
private long mSenderId; | ||
|
||
private long mChannelId; | ||
|
||
private List<User> mReaders; | ||
|
||
public static final String[] PROJECTION = new String[] { CONTENT, | ||
SORTED_BY, CLIENT_ID, SENDER_ID, CHANNEL_ID, COMMAND_ID, CREATED_AT }; | ||
|
||
public static void createTable(DataBaseHelper helper) { | ||
SQLiteDatabase db = helper.getWritableDatabase(); | ||
|
||
db.execSQL(new StringBuilder("CREATE TABLE '").append(TABLE_NAME) | ||
.append("' ('").append(BaseColumns._ID) | ||
.append("' INTEGER PRIMARY KEY AUTOINCREMENT, '") | ||
.append(CLIENT_ID).append("' INTEGER, '").append(SORTED_BY) | ||
.append("' REAL, '").append(CREATED_AT).append("' INTEGER, '") | ||
.append(CONTENT).append("' TEXT, '").append(SENDER_ID) | ||
.append("' INTEGER NOT NULL, '").append(CHANNEL_ID) | ||
.append("' INTEGER NOT NULL, '").append(COMMAND_ID) | ||
.append("' INTEGER);").toString()); | ||
|
||
db.execSQL(new StringBuilder("CREATE INDEX IDX_MESSAGE_COMMAND_ID ON ") | ||
.append(TABLE_NAME).append(" (").append(COMMAND_ID) | ||
.append(");").toString()); | ||
} | ||
|
||
public static void dropTable(DataBaseHelper helper) { | ||
SQLiteDatabase db = helper.getWritableDatabase(); | ||
|
||
db.execSQL(new StringBuilder("DROP TABLE '").append(TABLE_NAME) | ||
.append("';").toString()); | ||
} | ||
|
||
public long getId() { | ||
return mId; | ||
} | ||
|
||
public void setId(long id) { | ||
this.mId = id; | ||
} | ||
|
||
public long getClientId() { | ||
return mClientId; | ||
} | ||
|
||
public void setClientId(long clientId) { | ||
this.mClientId = clientId; | ||
} | ||
|
||
public long getCommandId() { | ||
return mCommandId; | ||
} | ||
|
||
public void setCommandId(long commandId) { | ||
this.mCommandId = commandId; | ||
} | ||
|
||
public double getSortedBy() { | ||
return mSortedBy; | ||
} | ||
|
||
public void setSortedBy(double sortedBy) { | ||
this.mSortedBy = sortedBy; | ||
} | ||
|
||
public int getCreatedAt() { | ||
return mCreatedAt; | ||
} | ||
|
||
public void setCreatedAt(int createdAt) { | ||
this.mCreatedAt = createdAt; | ||
} | ||
|
||
public String getContent() { | ||
return mContent; | ||
} | ||
|
||
public void setContent(String content) { | ||
this.mContent = content; | ||
} | ||
|
||
public long getSenderId() { | ||
return mSenderId; | ||
} | ||
|
||
public void setSenderId(long senderId) { | ||
this.mSenderId = senderId; | ||
} | ||
|
||
public long getChannelId() { | ||
return mChannelId; | ||
} | ||
|
||
public void setChannelId(long channelId) { | ||
this.mChannelId = channelId; | ||
} | ||
|
||
public void setReaders(List<User> readers) { | ||
mReaders = readers; | ||
} | ||
|
||
public List<User> getReaders() { | ||
return mReaders; | ||
} | ||
|
||
public boolean hasReaders() { | ||
return mReaders != null && !mReaders.isEmpty(); | ||
} | ||
|
||
public void prepareForInsert(final SQLiteStatement insertMessage) { | ||
insertMessage.bindString(1, mContent); | ||
insertMessage.bindDouble(2, mSortedBy); | ||
insertMessage.bindLong(3, mClientId); | ||
insertMessage.bindLong(4, mSenderId); | ||
insertMessage.bindLong(5, mChannelId); | ||
insertMessage.bindLong(6, mCommandId); | ||
insertMessage.bindLong(7, mCreatedAt); | ||
} | ||
} |
Oops, something went wrong.