Skip to content

Commit

Permalink
1. Modified Db helper class.
Browse files Browse the repository at this point in the history
2. Removed unwanted casts.
  • Loading branch information
amitjangid80 committed Feb 6, 2019
1 parent 4d53606 commit 12a61f3
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 22 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
Binary file added .idea/caches/gradle_models.ser
Binary file not shown.
3 changes: 3 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ dependencies {
implementation "com.android.support:appcompat-v7:$supportLibraryVersion"

// RxJava dependencies
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
}
32 changes: 13 additions & 19 deletions app/src/main/java/com/amit/db/DBHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ public DBHelper(Context context)
* @return true or false
**/
// endregion
public boolean executeDatabaseOperations(String tableName,
String operations,
public boolean executeDatabaseOperations(String tableName, String operations,
LinkedHashMap<String, String> values,
boolean hasConditions,
LinkedHashMap<String, String> conditionalValues)
Expand Down Expand Up @@ -403,8 +402,7 @@ public Cursor executeSelectQuery(String query)
* no matter condition is there or not
**/
// endregion COMMENTS FOR executeSelectQuery method
public Cursor executeSelectQuery(String tableName,
String values,
public Cursor executeSelectQuery(String tableName, String values,
boolean hasConditions,
StringBuilder conditionalValues)
{
Expand Down Expand Up @@ -505,11 +503,9 @@ public Cursor executeSelectQuery(String tableName,
*
**/
//#endregion COMMENTS FOR executeSelectQuery method
public <T> ArrayList<T> executeSelectQuery(String tableName,
String values,
public <T> ArrayList<T> executeSelectQuery(String tableName, String values,
boolean hasConditions,
String conditionalValues,
Class<T> tClass)
String conditionalValues, Class<T> tClass)
{
try
{
Expand Down Expand Up @@ -562,7 +558,7 @@ public <T> ArrayList<T> executeSelectQuery(String tableName,
{
// setting new instance of the class passed
// for invoking the values returned from database
Object instance = tClass.newInstance();
T instance = tClass.newInstance();

//#region LOOP FOR COUNT OF COLUMNS
for (int j = 0; j < cursor.getColumnCount(); j++)
Expand Down Expand Up @@ -634,7 +630,7 @@ else if (double.class == method.getParameterTypes()[0])
}
//#endregion LOOP FOR COUNT OF COLUMNS

tArrayList.add((T) instance);
tArrayList.add(instance);
cursor.moveToNext();
}
//#endregion LOOP FOR EXTRACTING DATA FROM DATABASE
Expand Down Expand Up @@ -692,10 +688,8 @@ else if (double.class == method.getParameterTypes()[0])
*** @return this method will return the count of the record in the table
**/
// endregion COMMENTS FOR getRecordCount method
public int getRecordCount(String tableName,
String values,
boolean hasConditions,
StringBuilder conditionalValues)
public int getRecordCount(String tableName, String values,
boolean hasConditions, StringBuilder conditionalValues)
{
try
{
Expand Down Expand Up @@ -961,7 +955,7 @@ public DBHelper createTable(String tableName)
}

// checking if columns were provided or not for creating table
if (dbColumnArrayList == null || dbColumnArrayList.size() > 0)
if (dbColumnArrayList == null || dbColumnArrayList.size() == 0)
{
Log.e(TAG, "createTable: No columns provided for creating table.");
return this;
Expand Down Expand Up @@ -1357,7 +1351,7 @@ public <T> ArrayList<T> getAllRecords(String tableName, boolean isAscending,
{
// setting new instance of the class passed
// for invoking the values returned from database
Object instance = tClass.newInstance();
T instance = tClass.newInstance();

//#region LOOP FOR COUNT OF COLUMNS
for (int j = 0; j < cursor.getColumnCount(); j++)
Expand Down Expand Up @@ -1428,7 +1422,7 @@ else if (double.class == method.getParameterTypes()[0])
}
//#endregion LOOP FOR COUNT OF COLUMNS

tArrayList.add((T) instance);
tArrayList.add(instance);
cursor.moveToNext();
}
//#endregion LOOP FOR EXTRACTING DATA FROM DATABASE
Expand Down Expand Up @@ -1529,7 +1523,7 @@ public <T> ArrayList<T> getAllRecords(String tableName, boolean isAscending,
{
// setting new instance of the class passed
// for invoking the values returned from database
Object instance = tClass.newInstance();
T instance = tClass.newInstance();

//#region LOOP FOR COUNT OF COLUMNS
for (int j = 0; j < cursor.getColumnCount(); j++)
Expand Down Expand Up @@ -1600,7 +1594,7 @@ else if (double.class == method.getParameterTypes()[0])
}
//#endregion LOOP FOR COUNT OF COLUMNS

tArrayList.add((T) instance);
tArrayList.add(instance);
cursor.moveToNext();
}
//#endregion LOOP FOR EXTRACTING DATA FROM DATABASE
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/amit/db/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ static Database getDBInstance(Context context, String databaseName)
{
if (mDatabase == null)
{
if (!databaseName.endsWith(".db"))
{
databaseName += ".db";
}

mDatabase = new Database(context, databaseName);
}
}
Expand All @@ -45,6 +50,7 @@ public void onCreate(SQLiteDatabase db)

}

//#region COMMENTS FOR getRecordCount method
/**
* 2018 April 17 - Tuesday - 12:11 PM
* Get Record Count
Expand All @@ -57,6 +63,7 @@ public void onCreate(SQLiteDatabase db)
* OR
* SELECT * FROM TABLE_NAME WHERE ID = 1
**/
//#endregion COMMENTS FOR getRecordCount method
int getRecordCount(String query)
{
try
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Oct 20 10:27:15 IST 2018
#Tue Jan 15 10:18:27 IST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

0 comments on commit 12a61f3

Please sign in to comment.