Skip to content

Commit 12a61f3

Browse files
committed
1. Modified Db helper class.
2. Removed unwanted casts.
1 parent 4d53606 commit 12a61f3

File tree

8 files changed

+32
-22
lines changed

8 files changed

+32
-22
lines changed

.idea/caches/build_file_checksums.ser

0 Bytes
Binary file not shown.

.idea/caches/gradle_models.ser

96.8 KB
Binary file not shown.

.idea/gradle.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ dependencies {
4848
implementation "com.android.support:appcompat-v7:$supportLibraryVersion"
4949

5050
// RxJava dependencies
51-
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
51+
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
5252
}

app/src/main/java/com/amit/db/DBHelper.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ public DBHelper(Context context)
134134
* @return true or false
135135
**/
136136
// endregion
137-
public boolean executeDatabaseOperations(String tableName,
138-
String operations,
137+
public boolean executeDatabaseOperations(String tableName, String operations,
139138
LinkedHashMap<String, String> values,
140139
boolean hasConditions,
141140
LinkedHashMap<String, String> conditionalValues)
@@ -403,8 +402,7 @@ public Cursor executeSelectQuery(String query)
403402
* no matter condition is there or not
404403
**/
405404
// endregion COMMENTS FOR executeSelectQuery method
406-
public Cursor executeSelectQuery(String tableName,
407-
String values,
405+
public Cursor executeSelectQuery(String tableName, String values,
408406
boolean hasConditions,
409407
StringBuilder conditionalValues)
410408
{
@@ -505,11 +503,9 @@ public Cursor executeSelectQuery(String tableName,
505503
*
506504
**/
507505
//#endregion COMMENTS FOR executeSelectQuery method
508-
public <T> ArrayList<T> executeSelectQuery(String tableName,
509-
String values,
506+
public <T> ArrayList<T> executeSelectQuery(String tableName, String values,
510507
boolean hasConditions,
511-
String conditionalValues,
512-
Class<T> tClass)
508+
String conditionalValues, Class<T> tClass)
513509
{
514510
try
515511
{
@@ -562,7 +558,7 @@ public <T> ArrayList<T> executeSelectQuery(String tableName,
562558
{
563559
// setting new instance of the class passed
564560
// for invoking the values returned from database
565-
Object instance = tClass.newInstance();
561+
T instance = tClass.newInstance();
566562

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

637-
tArrayList.add((T) instance);
633+
tArrayList.add(instance);
638634
cursor.moveToNext();
639635
}
640636
//#endregion LOOP FOR EXTRACTING DATA FROM DATABASE
@@ -692,10 +688,8 @@ else if (double.class == method.getParameterTypes()[0])
692688
*** @return this method will return the count of the record in the table
693689
**/
694690
// endregion COMMENTS FOR getRecordCount method
695-
public int getRecordCount(String tableName,
696-
String values,
697-
boolean hasConditions,
698-
StringBuilder conditionalValues)
691+
public int getRecordCount(String tableName, String values,
692+
boolean hasConditions, StringBuilder conditionalValues)
699693
{
700694
try
701695
{
@@ -961,7 +955,7 @@ public DBHelper createTable(String tableName)
961955
}
962956

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

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

1431-
tArrayList.add((T) instance);
1425+
tArrayList.add(instance);
14321426
cursor.moveToNext();
14331427
}
14341428
//#endregion LOOP FOR EXTRACTING DATA FROM DATABASE
@@ -1529,7 +1523,7 @@ public <T> ArrayList<T> getAllRecords(String tableName, boolean isAscending,
15291523
{
15301524
// setting new instance of the class passed
15311525
// for invoking the values returned from database
1532-
Object instance = tClass.newInstance();
1526+
T instance = tClass.newInstance();
15331527

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

1603-
tArrayList.add((T) instance);
1597+
tArrayList.add(instance);
16041598
cursor.moveToNext();
16051599
}
16061600
//#endregion LOOP FOR EXTRACTING DATA FROM DATABASE

app/src/main/java/com/amit/db/Database.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ static Database getDBInstance(Context context, String databaseName)
3131
{
3232
if (mDatabase == null)
3333
{
34+
if (!databaseName.endsWith(".db"))
35+
{
36+
databaseName += ".db";
37+
}
38+
3439
mDatabase = new Database(context, databaseName);
3540
}
3641
}
@@ -45,6 +50,7 @@ public void onCreate(SQLiteDatabase db)
4550

4651
}
4752

53+
//#region COMMENTS FOR getRecordCount method
4854
/**
4955
* 2018 April 17 - Tuesday - 12:11 PM
5056
* Get Record Count
@@ -57,6 +63,7 @@ public void onCreate(SQLiteDatabase db)
5763
* OR
5864
* SELECT * FROM TABLE_NAME WHERE ID = 1
5965
**/
66+
//#endregion COMMENTS FOR getRecordCount method
6067
int getRecordCount(String query)
6168
{
6269
try
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sat Oct 20 10:27:15 IST 2018
1+
#Tue Jan 15 10:18:27 IST 2019
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

0 commit comments

Comments
 (0)