Skip to content

Commit d48e7c3

Browse files
committed
- Do not modify input projection.
- Bump to 1.8.4.
1 parent d36b038 commit d48e7c3

File tree

4 files changed

+58
-36
lines changed

4 files changed

+58
-36
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ https://github.com/BoD/android-contentprovider-generator/releases/latest
122122

123123
### Run the tool
124124

125-
`java -jar android-contentprovider-generator-1.8.3-bundle.jar -i <input folder> -o <output folder>`
125+
`java -jar android-contentprovider-generator-1.8.4-bundle.jar -i <input folder> -o <output folder>`
126126
- Input folder: where to find `_config.json` and your entity json files
127127
- Output folder: where the resulting files will be generated
128128

@@ -211,7 +211,7 @@ You need maven to build this tool.
211211

212212
`mvn package`
213213

214-
This will produce `android-contentprovider-generator-1.8.3-bundle.jar` in the `target` folder.
214+
This will produce `android-contentprovider-generator-1.8.4-bundle.jar` in the `target` folder.
215215

216216

217217
Similar tools

etc/sample/app/src/org/jraf/androidcontentprovidergenerator/sample/provider/SampleProvider.java

+45-26
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
* \___/_/|_/_/ |_/_/ (_)___/_/ \_, /
77
* /___/
88
* repository.
9-
*
9+
*
1010
* Copyright (C) 2012-2014 Benoit 'BoD' Lubek ([email protected])
11-
*
11+
*
1212
* This program is free software: you can redistribute it and/or modify
1313
* it under the terms of the GNU General Public License as published by
1414
* the Free Software Foundation, either version 3 of the License, or
1515
* (at your option) any later version.
16-
*
16+
*
1717
* This program is distributed in the hope that it will be useful,
1818
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1919
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2020
* GNU General Public License for more details.
21-
*
21+
*
2222
* You should have received a copy of the GNU General Public License
2323
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2424
*/
@@ -42,11 +42,11 @@
4242
import android.util.Log;
4343

4444
import org.jraf.androidcontentprovidergenerator.sample.BuildConfig;
45-
import org.jraf.androidcontentprovidergenerator.sample.provider.serialnumber.SerialNumberColumns;
46-
import org.jraf.androidcontentprovidergenerator.sample.provider.personteam.PersonTeamColumns;
47-
import org.jraf.androidcontentprovidergenerator.sample.provider.team.TeamColumns;
4845
import org.jraf.androidcontentprovidergenerator.sample.provider.company.CompanyColumns;
4946
import org.jraf.androidcontentprovidergenerator.sample.provider.person.PersonColumns;
47+
import org.jraf.androidcontentprovidergenerator.sample.provider.personteam.PersonTeamColumns;
48+
import org.jraf.androidcontentprovidergenerator.sample.provider.serialnumber.SerialNumberColumns;
49+
import org.jraf.androidcontentprovidergenerator.sample.provider.team.TeamColumns;
5050

5151
public class SampleProvider extends ContentProvider {
5252
private static final String TAG = SampleProvider.class.getSimpleName();
@@ -223,21 +223,24 @@ public Cursor query(Uri uri, String[] projection, String selection, String[] sel
223223
Log.d(TAG, "query uri=" + uri + " selection=" + selection + " selectionArgs=" + Arrays.toString(selectionArgs) + " sortOrder=" + sortOrder
224224
+ " groupBy=" + groupBy);
225225
QueryParams queryParams = getQueryParams(uri, selection, projection);
226-
ensureIdIsFullyQualified(projection, queryParams.table);
227-
Cursor res = mSampleSQLiteOpenHelper.getReadableDatabase().query(queryParams.tablesWithJoins, projection, queryParams.selection, selectionArgs, groupBy,
228-
null, sortOrder == null ? queryParams.orderBy : sortOrder);
226+
projection = ensureIdIsFullyQualified(projection, queryParams.table);
227+
Cursor res = mSampleSQLiteOpenHelper.getReadableDatabase().query(queryParams.tablesWithJoins, projection, queryParams.selection, selectionArgs,
228+
groupBy, null, sortOrder == null ? queryParams.orderBy : sortOrder);
229229
res.setNotificationUri(getContext().getContentResolver(), uri);
230230
return res;
231231
}
232232

233-
private void ensureIdIsFullyQualified(String[] projection, String tableName) {
234-
if (projection != null) {
235-
for (int i = 0; i < projection.length; ++i) {
236-
if (projection[i].equals(BaseColumns._ID)) {
237-
projection[i] = tableName + "." + BaseColumns._ID + " AS " + BaseColumns._ID;
238-
}
233+
private String[] ensureIdIsFullyQualified(String[] projection, String tableName) {
234+
if (projection == null) return null;
235+
String[] res = new String[projection.length];
236+
for (int i = 0; i < projection.length; i++) {
237+
if (projection[i].equals(BaseColumns._ID)) {
238+
res[i] = tableName + "." + BaseColumns._ID + " AS " + BaseColumns._ID;
239+
} else {
240+
res[i] = projection[i];
239241
}
240242
}
243+
return res;
241244
}
242245

243246
@Override
@@ -293,19 +296,28 @@ private QueryParams getQueryParams(Uri uri, String selection, String[] projectio
293296
res.table = PersonTeamColumns.TABLE_NAME;
294297
res.tablesWithJoins = PersonTeamColumns.TABLE_NAME;
295298
if (PersonColumns.hasColumns(projection)) {
296-
res.tablesWithJoins += " LEFT OUTER JOIN " + PersonColumns.TABLE_NAME + " AS " + PersonTeamColumns.PREFIX_PERSON + " ON " + PersonTeamColumns.TABLE_NAME + "." + PersonTeamColumns.PERSON_ID + "=" + PersonTeamColumns.PREFIX_PERSON + "." + PersonColumns._ID;
299+
res.tablesWithJoins += " LEFT OUTER JOIN " + PersonColumns.TABLE_NAME + " AS " + PersonTeamColumns.PREFIX_PERSON + " ON "
300+
+ PersonTeamColumns.TABLE_NAME + "." + PersonTeamColumns.PERSON_ID + "=" + PersonTeamColumns.PREFIX_PERSON + "."
301+
+ PersonColumns._ID;
297302
}
298-
if (TeamColumns.hasColumns(projection) || CompanyColumns.hasColumns(projection) || SerialNumberColumns.hasColumns(projection) || SerialNumberColumns.hasColumns(projection)) {
299-
res.tablesWithJoins += " LEFT OUTER JOIN " + TeamColumns.TABLE_NAME + " AS " + PersonTeamColumns.PREFIX_TEAM + " ON " + PersonTeamColumns.TABLE_NAME + "." + PersonTeamColumns.TEAM_ID + "=" + PersonTeamColumns.PREFIX_TEAM + "." + TeamColumns._ID;
303+
if (TeamColumns.hasColumns(projection) || CompanyColumns.hasColumns(projection) || SerialNumberColumns.hasColumns(projection)
304+
|| SerialNumberColumns.hasColumns(projection)) {
305+
res.tablesWithJoins += " LEFT OUTER JOIN " + TeamColumns.TABLE_NAME + " AS " + PersonTeamColumns.PREFIX_TEAM + " ON "
306+
+ PersonTeamColumns.TABLE_NAME + "." + PersonTeamColumns.TEAM_ID + "=" + PersonTeamColumns.PREFIX_TEAM + "." + TeamColumns._ID;
300307
}
301308
if (CompanyColumns.hasColumns(projection) || SerialNumberColumns.hasColumns(projection)) {
302-
res.tablesWithJoins += " LEFT OUTER JOIN " + CompanyColumns.TABLE_NAME + " AS " + TeamColumns.PREFIX_COMPANY + " ON " + PersonTeamColumns.PREFIX_TEAM + "." + TeamColumns.COMPANY_ID + "=" + TeamColumns.PREFIX_COMPANY + "." + CompanyColumns._ID;
309+
res.tablesWithJoins += " LEFT OUTER JOIN " + CompanyColumns.TABLE_NAME + " AS " + TeamColumns.PREFIX_COMPANY + " ON "
310+
+ PersonTeamColumns.PREFIX_TEAM + "." + TeamColumns.COMPANY_ID + "=" + TeamColumns.PREFIX_COMPANY + "." + CompanyColumns._ID;
303311
}
304312
if (SerialNumberColumns.hasColumns(projection)) {
305-
res.tablesWithJoins += " LEFT OUTER JOIN " + SerialNumberColumns.TABLE_NAME + " AS " + CompanyColumns.PREFIX_SERIAL_NUMBER + " ON " + TeamColumns.PREFIX_COMPANY + "." + CompanyColumns.SERIAL_NUMBER_ID + "=" + CompanyColumns.PREFIX_SERIAL_NUMBER + "." + SerialNumberColumns._ID;
313+
res.tablesWithJoins += " LEFT OUTER JOIN " + SerialNumberColumns.TABLE_NAME + " AS " + CompanyColumns.PREFIX_SERIAL_NUMBER + " ON "
314+
+ TeamColumns.PREFIX_COMPANY + "." + CompanyColumns.SERIAL_NUMBER_ID + "=" + CompanyColumns.PREFIX_SERIAL_NUMBER + "."
315+
+ SerialNumberColumns._ID;
306316
}
307317
if (SerialNumberColumns.hasColumns(projection)) {
308-
res.tablesWithJoins += " LEFT OUTER JOIN " + SerialNumberColumns.TABLE_NAME + " AS " + TeamColumns.PREFIX_SERIAL_NUMBER + " ON " + PersonTeamColumns.PREFIX_TEAM + "." + TeamColumns.SERIAL_NUMBER_ID + "=" + TeamColumns.PREFIX_SERIAL_NUMBER + "." + SerialNumberColumns._ID;
318+
res.tablesWithJoins += " LEFT OUTER JOIN " + SerialNumberColumns.TABLE_NAME + " AS " + TeamColumns.PREFIX_SERIAL_NUMBER + " ON "
319+
+ PersonTeamColumns.PREFIX_TEAM + "." + TeamColumns.SERIAL_NUMBER_ID + "=" + TeamColumns.PREFIX_SERIAL_NUMBER + "."
320+
+ SerialNumberColumns._ID;
309321
}
310322
res.orderBy = PersonTeamColumns.DEFAULT_ORDER;
311323
break;
@@ -315,13 +327,18 @@ private QueryParams getQueryParams(Uri uri, String selection, String[] projectio
315327
res.table = TeamColumns.TABLE_NAME;
316328
res.tablesWithJoins = TeamColumns.TABLE_NAME;
317329
if (CompanyColumns.hasColumns(projection) || SerialNumberColumns.hasColumns(projection)) {
318-
res.tablesWithJoins += " LEFT OUTER JOIN " + CompanyColumns.TABLE_NAME + " AS " + TeamColumns.PREFIX_COMPANY + " ON " + TeamColumns.TABLE_NAME + "." + TeamColumns.COMPANY_ID + "=" + TeamColumns.PREFIX_COMPANY + "." + CompanyColumns._ID;
330+
res.tablesWithJoins += " LEFT OUTER JOIN " + CompanyColumns.TABLE_NAME + " AS " + TeamColumns.PREFIX_COMPANY + " ON "
331+
+ TeamColumns.TABLE_NAME + "." + TeamColumns.COMPANY_ID + "=" + TeamColumns.PREFIX_COMPANY + "." + CompanyColumns._ID;
319332
}
320333
if (SerialNumberColumns.hasColumns(projection)) {
321-
res.tablesWithJoins += " LEFT OUTER JOIN " + SerialNumberColumns.TABLE_NAME + " AS " + CompanyColumns.PREFIX_SERIAL_NUMBER + " ON " + TeamColumns.PREFIX_COMPANY + "." + CompanyColumns.SERIAL_NUMBER_ID + "=" + CompanyColumns.PREFIX_SERIAL_NUMBER + "." + SerialNumberColumns._ID;
334+
res.tablesWithJoins += " LEFT OUTER JOIN " + SerialNumberColumns.TABLE_NAME + " AS " + CompanyColumns.PREFIX_SERIAL_NUMBER + " ON "
335+
+ TeamColumns.PREFIX_COMPANY + "." + CompanyColumns.SERIAL_NUMBER_ID + "=" + CompanyColumns.PREFIX_SERIAL_NUMBER + "."
336+
+ SerialNumberColumns._ID;
322337
}
323338
if (SerialNumberColumns.hasColumns(projection)) {
324-
res.tablesWithJoins += " LEFT OUTER JOIN " + SerialNumberColumns.TABLE_NAME + " AS " + TeamColumns.PREFIX_SERIAL_NUMBER + " ON " + TeamColumns.TABLE_NAME + "." + TeamColumns.SERIAL_NUMBER_ID + "=" + TeamColumns.PREFIX_SERIAL_NUMBER + "." + SerialNumberColumns._ID;
339+
res.tablesWithJoins += " LEFT OUTER JOIN " + SerialNumberColumns.TABLE_NAME + " AS " + TeamColumns.PREFIX_SERIAL_NUMBER + " ON "
340+
+ TeamColumns.TABLE_NAME + "." + TeamColumns.SERIAL_NUMBER_ID + "=" + TeamColumns.PREFIX_SERIAL_NUMBER + "."
341+
+ SerialNumberColumns._ID;
325342
}
326343
res.orderBy = TeamColumns.DEFAULT_ORDER;
327344
break;
@@ -331,7 +348,9 @@ private QueryParams getQueryParams(Uri uri, String selection, String[] projectio
331348
res.table = CompanyColumns.TABLE_NAME;
332349
res.tablesWithJoins = CompanyColumns.TABLE_NAME;
333350
if (SerialNumberColumns.hasColumns(projection)) {
334-
res.tablesWithJoins += " LEFT OUTER JOIN " + SerialNumberColumns.TABLE_NAME + " AS " + CompanyColumns.PREFIX_SERIAL_NUMBER + " ON " + CompanyColumns.TABLE_NAME + "." + CompanyColumns.SERIAL_NUMBER_ID + "=" + CompanyColumns.PREFIX_SERIAL_NUMBER + "." + SerialNumberColumns._ID;
351+
res.tablesWithJoins += " LEFT OUTER JOIN " + SerialNumberColumns.TABLE_NAME + " AS " + CompanyColumns.PREFIX_SERIAL_NUMBER + " ON "
352+
+ CompanyColumns.TABLE_NAME + "." + CompanyColumns.SERIAL_NUMBER_ID + "=" + CompanyColumns.PREFIX_SERIAL_NUMBER + "."
353+
+ SerialNumberColumns._ID;
335354
}
336355
res.orderBy = CompanyColumns.DEFAULT_ORDER;
337356
break;

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>org.jraf</groupId>
55
<artifactId>android_contentprovider_generator</artifactId>
6-
<version>1.8.3</version> <!-- Do not forget to update README.md when updating this value -->
6+
<version>1.8.4</version> <!-- Do not forget to update README.md when updating this value -->
77
<packaging>jar</packaging>
88

99
<name>GenerateAndroidProvider</name>

src/main/resources/org/jraf/androidcontentprovidergenerator/contentprovider.ftl

+10-7
Original file line numberDiff line numberDiff line change
@@ -169,21 +169,24 @@ public class ${config.providerClassName} extends ContentProvider {
169169
Log.d(TAG, "query uri=" + uri + " selection=" + selection + " selectionArgs=" + Arrays.toString(selectionArgs) + " sortOrder=" + sortOrder
170170
+ " groupBy=" + groupBy);
171171
QueryParams queryParams = getQueryParams(uri, selection, projection);
172-
ensureIdIsFullyQualified(projection, queryParams.table);
172+
projection = ensureIdIsFullyQualified(projection, queryParams.table);
173173
Cursor res = m${config.sqliteOpenHelperClassName}.getReadableDatabase().query(queryParams.tablesWithJoins, projection, queryParams.selection, selectionArgs, groupBy,
174174
null, sortOrder == null ? queryParams.orderBy : sortOrder);
175175
res.setNotificationUri(getContext().getContentResolver(), uri);
176176
return res;
177177
}
178178

179-
private void ensureIdIsFullyQualified(String[] projection, String tableName) {
180-
if (projection != null) {
181-
for (int i = 0; i < projection.length; ++i) {
182-
if (projection[i].equals(BaseColumns._ID)) {
183-
projection[i] = tableName + "." + BaseColumns._ID + " AS " + BaseColumns._ID;
184-
}
179+
private String[] ensureIdIsFullyQualified(String[] projection, String tableName) {
180+
if (projection == null) return null;
181+
String[] res = new String[projection.length];
182+
for (int i = 0; i < projection.length; i++) {
183+
if (projection[i].equals(BaseColumns._ID)) {
184+
res[i] = tableName + "." + BaseColumns._ID + " AS " + BaseColumns._ID;
185+
} else {
186+
res[i] = projection[i];
185187
}
186188
}
189+
return res;
187190
}
188191

189192
@Override

0 commit comments

Comments
 (0)