Skip to content

Commit 38c36de

Browse files
committed
Move the creation/update logs from the provider to the content class
This change makes the code more readable in the onCreate and onUpgrade method in the Provider class. Fixes foxykeep#14
1 parent 09330c6 commit 38c36de

3 files changed

Lines changed: 16 additions & 23 deletions

File tree

generator/res/content_subclass.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,21 @@
4848
}
4949

5050
public static void createTable(SQLiteDatabase db) {
51+
if (%2$sProvider.ACTIVATE_ALL_LOGS) {
52+
Log.d(LOG_TAG, "%1$s | createTable start");
53+
}
5154
db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + %8$s%9$s + ");");
5255

53-
%10$s }
56+
%10$s if (%2$sProvider.ACTIVATE_ALL_LOGS) {
57+
Log.d(LOG_TAG, "%1$s | createTable end");
58+
}
59+
}
5460

5561
// Version %15$d : Creation of the table
5662
%16$s public static void upgradeTable(SQLiteDatabase db, int oldVersion, int newVersion) {
63+
if (%2$sProvider.ACTIVATE_ALL_LOGS) {
64+
Log.d(LOG_TAG, "%1$s | upgradeTable start");
65+
}
5766

5867
if (oldVersion < %15$d) {
5968
Log.i(LOG_TAG, "Upgrading from version " + oldVersion + " to " + newVersion
@@ -69,6 +78,10 @@
6978
throw new IllegalStateException("Error upgrading the database to version "
7079
+ newVersion);
7180
}
81+
82+
if (%2$sProvider.ACTIVATE_ALL_LOGS) {
83+
Log.d(LOG_TAG, "%1$s | upgradeTable end");
84+
}
7285
}
7386

7487
static String getBulkInsertString() {

generator/res/provider.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public %14$sclass %3$sProvider extends ContentProvider {
2828

2929
private static final String LOG_TAG = %3$sProvider.class.getSimpleName();
3030

31-
private static final boolean ACTIVATE_ALL_LOGS = false;
31+
/* package */ static final boolean ACTIVATE_ALL_LOGS = false;
3232

3333
protected static final String DATABASE_NAME = "%3$sProvider.db";
3434

generator/src/com/foxykeep/cpcodegenerator/generator/DatabaseGenerator.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -441,31 +441,11 @@ private static void generateProviderClass(final String fileName, final String cl
441441
tableData.dbClassName, " + \"/#\"", "TYPE_DIR_TYPE",
442442
i != tableDataListSize - 1 ? "," : ";"));
443443

444-
sbCreateTables
445-
.append(" if (ACTIVATE_ALL_LOGS) {\n")
446-
.append(" Log.d(LOG_TAG, \"")
447-
.append(tableData.dbClassName)
448-
.append(" | createTable start\");\n }\n");
449444
sbCreateTables.append(" ").append(tableData.dbClassName)
450445
.append(".createTable(db);\n");
451-
sbCreateTables
452-
.append(" if (ACTIVATE_ALL_LOGS) {\n")
453-
.append(" Log.d(LOG_TAG, \"")
454-
.append(tableData.dbClassName)
455-
.append(" | createTable end\");\n }\n");
456-
457-
sbUpgradeTables
458-
.append(" if (ACTIVATE_ALL_LOGS) {\n")
459-
.append(" Log.d(LOG_TAG, \"")
460-
.append(tableData.dbClassName)
461-
.append(" | upgradeTable start\");\n }\n");
446+
462447
sbUpgradeTables.append(" ").append(tableData.dbClassName)
463448
.append(".upgradeTable(db, oldVersion, newVersion);\n");
464-
sbUpgradeTables
465-
.append(" if (ACTIVATE_ALL_LOGS) {\n")
466-
.append(" Log.d(LOG_TAG, \"")
467-
.append(tableData.dbClassName)
468-
.append(" | upgradeTable end\");\n }\n");
469449

470450
sbCaseWithId.append(" case ").append(tableData.dbConstantName)
471451
.append("_ID:\n");

0 commit comments

Comments
 (0)