Skip to content

Commit

Permalink
- Do not modify input projection.
Browse files Browse the repository at this point in the history
- Bump to 1.8.4.
  • Loading branch information
BoD committed Dec 29, 2014
1 parent d36b038 commit d48e7c3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 36 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ https://github.com/BoD/android-contentprovider-generator/releases/latest

### Run the tool

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

Expand Down Expand Up @@ -211,7 +211,7 @@ You need maven to build this tool.

`mvn package`

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


Similar tools
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
* \___/_/|_/_/ |_/_/ (_)___/_/ \_, /
* /___/
* repository.
*
*
* Copyright (C) 2012-2014 Benoit 'BoD' Lubek ([email protected])
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Expand All @@ -42,11 +42,11 @@
import android.util.Log;

import org.jraf.androidcontentprovidergenerator.sample.BuildConfig;
import org.jraf.androidcontentprovidergenerator.sample.provider.serialnumber.SerialNumberColumns;
import org.jraf.androidcontentprovidergenerator.sample.provider.personteam.PersonTeamColumns;
import org.jraf.androidcontentprovidergenerator.sample.provider.team.TeamColumns;
import org.jraf.androidcontentprovidergenerator.sample.provider.company.CompanyColumns;
import org.jraf.androidcontentprovidergenerator.sample.provider.person.PersonColumns;
import org.jraf.androidcontentprovidergenerator.sample.provider.personteam.PersonTeamColumns;
import org.jraf.androidcontentprovidergenerator.sample.provider.serialnumber.SerialNumberColumns;
import org.jraf.androidcontentprovidergenerator.sample.provider.team.TeamColumns;

public class SampleProvider extends ContentProvider {
private static final String TAG = SampleProvider.class.getSimpleName();
Expand Down Expand Up @@ -223,21 +223,24 @@ public Cursor query(Uri uri, String[] projection, String selection, String[] sel
Log.d(TAG, "query uri=" + uri + " selection=" + selection + " selectionArgs=" + Arrays.toString(selectionArgs) + " sortOrder=" + sortOrder
+ " groupBy=" + groupBy);
QueryParams queryParams = getQueryParams(uri, selection, projection);
ensureIdIsFullyQualified(projection, queryParams.table);
Cursor res = mSampleSQLiteOpenHelper.getReadableDatabase().query(queryParams.tablesWithJoins, projection, queryParams.selection, selectionArgs, groupBy,
null, sortOrder == null ? queryParams.orderBy : sortOrder);
projection = ensureIdIsFullyQualified(projection, queryParams.table);
Cursor res = mSampleSQLiteOpenHelper.getReadableDatabase().query(queryParams.tablesWithJoins, projection, queryParams.selection, selectionArgs,
groupBy, null, sortOrder == null ? queryParams.orderBy : sortOrder);
res.setNotificationUri(getContext().getContentResolver(), uri);
return res;
}

private void ensureIdIsFullyQualified(String[] projection, String tableName) {
if (projection != null) {
for (int i = 0; i < projection.length; ++i) {
if (projection[i].equals(BaseColumns._ID)) {
projection[i] = tableName + "." + BaseColumns._ID + " AS " + BaseColumns._ID;
}
private String[] ensureIdIsFullyQualified(String[] projection, String tableName) {
if (projection == null) return null;
String[] res = new String[projection.length];
for (int i = 0; i < projection.length; i++) {
if (projection[i].equals(BaseColumns._ID)) {
res[i] = tableName + "." + BaseColumns._ID + " AS " + BaseColumns._ID;
} else {
res[i] = projection[i];
}
}
return res;
}

@Override
Expand Down Expand Up @@ -293,19 +296,28 @@ private QueryParams getQueryParams(Uri uri, String selection, String[] projectio
res.table = PersonTeamColumns.TABLE_NAME;
res.tablesWithJoins = PersonTeamColumns.TABLE_NAME;
if (PersonColumns.hasColumns(projection)) {
res.tablesWithJoins += " LEFT OUTER JOIN " + PersonColumns.TABLE_NAME + " AS " + PersonTeamColumns.PREFIX_PERSON + " ON " + PersonTeamColumns.TABLE_NAME + "." + PersonTeamColumns.PERSON_ID + "=" + PersonTeamColumns.PREFIX_PERSON + "." + PersonColumns._ID;
res.tablesWithJoins += " LEFT OUTER JOIN " + PersonColumns.TABLE_NAME + " AS " + PersonTeamColumns.PREFIX_PERSON + " ON "
+ PersonTeamColumns.TABLE_NAME + "." + PersonTeamColumns.PERSON_ID + "=" + PersonTeamColumns.PREFIX_PERSON + "."
+ PersonColumns._ID;
}
if (TeamColumns.hasColumns(projection) || CompanyColumns.hasColumns(projection) || SerialNumberColumns.hasColumns(projection) || SerialNumberColumns.hasColumns(projection)) {
res.tablesWithJoins += " LEFT OUTER JOIN " + TeamColumns.TABLE_NAME + " AS " + PersonTeamColumns.PREFIX_TEAM + " ON " + PersonTeamColumns.TABLE_NAME + "." + PersonTeamColumns.TEAM_ID + "=" + PersonTeamColumns.PREFIX_TEAM + "." + TeamColumns._ID;
if (TeamColumns.hasColumns(projection) || CompanyColumns.hasColumns(projection) || SerialNumberColumns.hasColumns(projection)
|| SerialNumberColumns.hasColumns(projection)) {
res.tablesWithJoins += " LEFT OUTER JOIN " + TeamColumns.TABLE_NAME + " AS " + PersonTeamColumns.PREFIX_TEAM + " ON "
+ PersonTeamColumns.TABLE_NAME + "." + PersonTeamColumns.TEAM_ID + "=" + PersonTeamColumns.PREFIX_TEAM + "." + TeamColumns._ID;
}
if (CompanyColumns.hasColumns(projection) || SerialNumberColumns.hasColumns(projection)) {
res.tablesWithJoins += " LEFT OUTER JOIN " + CompanyColumns.TABLE_NAME + " AS " + TeamColumns.PREFIX_COMPANY + " ON " + PersonTeamColumns.PREFIX_TEAM + "." + TeamColumns.COMPANY_ID + "=" + TeamColumns.PREFIX_COMPANY + "." + CompanyColumns._ID;
res.tablesWithJoins += " LEFT OUTER JOIN " + CompanyColumns.TABLE_NAME + " AS " + TeamColumns.PREFIX_COMPANY + " ON "
+ PersonTeamColumns.PREFIX_TEAM + "." + TeamColumns.COMPANY_ID + "=" + TeamColumns.PREFIX_COMPANY + "." + CompanyColumns._ID;
}
if (SerialNumberColumns.hasColumns(projection)) {
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;
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;
}
if (SerialNumberColumns.hasColumns(projection)) {
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;
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;
}
res.orderBy = PersonTeamColumns.DEFAULT_ORDER;
break;
Expand All @@ -315,13 +327,18 @@ private QueryParams getQueryParams(Uri uri, String selection, String[] projectio
res.table = TeamColumns.TABLE_NAME;
res.tablesWithJoins = TeamColumns.TABLE_NAME;
if (CompanyColumns.hasColumns(projection) || SerialNumberColumns.hasColumns(projection)) {
res.tablesWithJoins += " LEFT OUTER JOIN " + CompanyColumns.TABLE_NAME + " AS " + TeamColumns.PREFIX_COMPANY + " ON " + TeamColumns.TABLE_NAME + "." + TeamColumns.COMPANY_ID + "=" + TeamColumns.PREFIX_COMPANY + "." + CompanyColumns._ID;
res.tablesWithJoins += " LEFT OUTER JOIN " + CompanyColumns.TABLE_NAME + " AS " + TeamColumns.PREFIX_COMPANY + " ON "
+ TeamColumns.TABLE_NAME + "." + TeamColumns.COMPANY_ID + "=" + TeamColumns.PREFIX_COMPANY + "." + CompanyColumns._ID;
}
if (SerialNumberColumns.hasColumns(projection)) {
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;
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;
}
if (SerialNumberColumns.hasColumns(projection)) {
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;
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;
}
res.orderBy = TeamColumns.DEFAULT_ORDER;
break;
Expand All @@ -331,7 +348,9 @@ private QueryParams getQueryParams(Uri uri, String selection, String[] projectio
res.table = CompanyColumns.TABLE_NAME;
res.tablesWithJoins = CompanyColumns.TABLE_NAME;
if (SerialNumberColumns.hasColumns(projection)) {
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;
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;
}
res.orderBy = CompanyColumns.DEFAULT_ORDER;
break;
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

<name>GenerateAndroidProvider</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,24 @@ public class ${config.providerClassName} extends ContentProvider {
Log.d(TAG, "query uri=" + uri + " selection=" + selection + " selectionArgs=" + Arrays.toString(selectionArgs) + " sortOrder=" + sortOrder
+ " groupBy=" + groupBy);
QueryParams queryParams = getQueryParams(uri, selection, projection);
ensureIdIsFullyQualified(projection, queryParams.table);
projection = ensureIdIsFullyQualified(projection, queryParams.table);
Cursor res = m${config.sqliteOpenHelperClassName}.getReadableDatabase().query(queryParams.tablesWithJoins, projection, queryParams.selection, selectionArgs, groupBy,
null, sortOrder == null ? queryParams.orderBy : sortOrder);
res.setNotificationUri(getContext().getContentResolver(), uri);
return res;
}

private void ensureIdIsFullyQualified(String[] projection, String tableName) {
if (projection != null) {
for (int i = 0; i < projection.length; ++i) {
if (projection[i].equals(BaseColumns._ID)) {
projection[i] = tableName + "." + BaseColumns._ID + " AS " + BaseColumns._ID;
}
private String[] ensureIdIsFullyQualified(String[] projection, String tableName) {
if (projection == null) return null;
String[] res = new String[projection.length];
for (int i = 0; i < projection.length; i++) {
if (projection[i].equals(BaseColumns._ID)) {
res[i] = tableName + "." + BaseColumns._ID + " AS " + BaseColumns._ID;
} else {
res[i] = projection[i];
}
}
return res;
}

@Override
Expand Down

0 comments on commit d48e7c3

Please sign in to comment.