Skip to content

Commit a66a4fa

Browse files
committed
- Reverted annotations on overridden methods because it provoked
compilation errors - Re generated the sample with the latest version - Updated CHANGELOG
1 parent 8639453 commit a66a4fa

File tree

14 files changed

+46
-39
lines changed

14 files changed

+46
-39
lines changed

CHANGELOG.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Android ContentProvider Generator Changelog
22
===========================================
33

4-
v1.9.0 (2015-02-??)
4+
v1.9.0 (2015-02-15)
55
------
66
- The config `syntaxVersion` for this release is **3**. This means you **must** update your `_config.json` file.
77
- Generation of new "Model" interfaces (one per entity)
@@ -11,6 +11,6 @@ v1.9.0 (2015-02-??)
1111
- New `contains`, `startsWith`, `endsWitdh` methods on Selection objects (issue #55)
1212
- The `CREATE_TABLE and CREATE_INDEX` constants are now public to make upgrades easier (issue #59)
1313
- The "id" (single column primary key) can now be specified to be an arbitrary column, instead of automatically being generated as "_id" (issue #56)
14-
- Ability to specify a LIMIT clause in queries, via a query parameter (issue #62)
14+
- Ability to specify a LIMIT and HAVING clause in queries, via a query parameter (issues #62 and #70)
1515
- Better handling of default values (issue #67)
16-
- Ability to call `notify`, `groupBy` and `limit` on Selection objects.
16+
- Ability to call `notify`, `groupBy`, `limit` and `having` on Selection objects.

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import android.database.Cursor;
3232
import android.database.sqlite.SQLiteOpenHelper;
3333
import android.net.Uri;
34+
import android.support.annotation.NonNull;
3435
import android.util.Log;
3536

3637
import org.jraf.androidcontentprovidergenerator.sample.BuildConfig;
@@ -166,7 +167,7 @@ public int delete(Uri uri, String selection, String[] selectionArgs) {
166167
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
167168
if (DEBUG)
168169
Log.d(TAG, "query uri=" + uri + " selection=" + selection + " selectionArgs=" + Arrays.toString(selectionArgs) + " sortOrder=" + sortOrder
169-
+ " groupBy=" + uri.getQueryParameter(QUERY_GROUP_BY) + " limit=" + uri.getQueryParameter(QUERY_LIMIT));
170+
+ " groupBy=" + uri.getQueryParameter(QUERY_GROUP_BY) + " having=" + uri.getQueryParameter(QUERY_HAVING) + " limit=" + uri.getQueryParameter(QUERY_LIMIT));
170171
return super.query(uri, projection, selection, selectionArgs, sortOrder);
171172
}
172173

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

+6-9
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import android.database.DatabaseErrorHandler;
3030
import android.database.DefaultDatabaseErrorHandler;
3131
import android.database.sqlite.SQLiteDatabase;
32-
import android.database.sqlite.SQLiteDatabase.CursorFactory;
3332
import android.database.sqlite.SQLiteOpenHelper;
3433
import android.os.Build;
3534
import android.util.Log;
@@ -142,13 +141,12 @@ private static SampleSQLiteOpenHelper newInstance(Context context) {
142141
/*
143142
* Pre Honeycomb.
144143
*/
145-
146144
private static SampleSQLiteOpenHelper newInstancePreHoneycomb(Context context) {
147-
return new SampleSQLiteOpenHelper(context, DATABASE_FILE_NAME, null, DATABASE_VERSION);
145+
return new SampleSQLiteOpenHelper(context);
148146
}
149147

150-
private SampleSQLiteOpenHelper(Context context, String name, CursorFactory factory, int version) {
151-
super(context, name, factory, version);
148+
private SampleSQLiteOpenHelper(Context context) {
149+
super(context, DATABASE_FILE_NAME, null, DATABASE_VERSION);
152150
mContext = context;
153151
mOpenHelperCallbacks = new SampleSQLiteOpenHelperCallbacks();
154152
}
@@ -157,15 +155,14 @@ private SampleSQLiteOpenHelper(Context context, String name, CursorFactory facto
157155
/*
158156
* Post Honeycomb.
159157
*/
160-
161158
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
162159
private static SampleSQLiteOpenHelper newInstancePostHoneycomb(Context context) {
163-
return new SampleSQLiteOpenHelper(context, DATABASE_FILE_NAME, null, DATABASE_VERSION, new DefaultDatabaseErrorHandler());
160+
return new SampleSQLiteOpenHelper(context, new DefaultDatabaseErrorHandler());
164161
}
165162

166163
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
167-
private SampleSQLiteOpenHelper(Context context, String name, CursorFactory factory, int version, DatabaseErrorHandler errorHandler) {
168-
super(context, name, factory, version, errorHandler);
164+
private SampleSQLiteOpenHelper(Context context, DatabaseErrorHandler errorHandler) {
165+
super(context, DATABASE_FILE_NAME, null, DATABASE_VERSION, errorHandler);
169166
mContext = context;
170167
mOpenHelperCallbacks = new SampleSQLiteOpenHelperCallbacks();
171168
}

etc/sample/app/src/org/jraf/androidcontentprovidergenerator/sample/provider/base/AbstractContentValues.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import android.net.Uri;
3030

3131
public abstract class AbstractContentValues {
32-
protected ContentValues mContentValues = new ContentValues();
32+
protected final ContentValues mContentValues = new ContentValues();
3333

3434
/**
3535
* Returns the {@code uri} argument to pass to the {@code ContentResolver} methods.

etc/sample/app/src/org/jraf/androidcontentprovidergenerator/sample/provider/base/AbstractSelection.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ public abstract class AbstractSelection<T extends AbstractSelection<?>> {
5555
private final StringBuilder mSelection = new StringBuilder();
5656
private final List<String> mSelectionArgs = new ArrayList<String>(5);
5757

58-
private Boolean mNotify;
59-
private String mGroupBy;
60-
private Integer mLimit;
58+
Boolean mNotify;
59+
String mGroupBy;
60+
String mHaving;
61+
Integer mLimit;
6162

6263
protected void addEquals(String column, Object[] value) {
6364
mSelection.append(column);
@@ -301,6 +302,7 @@ public Uri uri() {
301302
Uri uri = baseUri();
302303
if (mNotify != null) uri = BaseContentProvider.notify(uri, mNotify);
303304
if (mGroupBy != null) uri = BaseContentProvider.groupBy(uri, mGroupBy);
305+
if (mHaving != null) uri = BaseContentProvider.having(uri, mHaving);
304306
if (mLimit != null) uri = BaseContentProvider.limit(uri, String.valueOf(mLimit));
305307
return uri;
306308
}
@@ -329,6 +331,12 @@ public T groupBy(String groupBy) {
329331
return (T) this;
330332
}
331333

334+
@SuppressWarnings("unchecked")
335+
public T having(String having) {
336+
mHaving = having;
337+
return (T) this;
338+
}
339+
332340
@SuppressWarnings("unchecked")
333341
public T limit(int limit) {
334342
mLimit = limit;

etc/sample/app/src/org/jraf/androidcontentprovidergenerator/sample/provider/base/BaseContentProvider.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@
3838
import android.database.sqlite.SQLiteOpenHelper;
3939
import android.net.Uri;
4040
import android.provider.BaseColumns;
41+
import android.support.annotation.NonNull;
4142
import android.util.Log;
4243

4344
public abstract class BaseContentProvider extends ContentProvider {
4445
public static final String QUERY_NOTIFY = "QUERY_NOTIFY";
4546
public static final String QUERY_GROUP_BY = "QUERY_GROUP_BY";
47+
public static final String QUERY_HAVING = "QUERY_HAVING";
4648
public static final String QUERY_LIMIT = "QUERY_LIMIT";
4749

4850
public static class QueryParams {
@@ -147,11 +149,12 @@ public int delete(Uri uri, String selection, String[] selectionArgs) {
147149
@Override
148150
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
149151
String groupBy = uri.getQueryParameter(QUERY_GROUP_BY);
152+
String having = uri.getQueryParameter(QUERY_HAVING);
150153
String limit = uri.getQueryParameter(QUERY_LIMIT);
151154
QueryParams queryParams = getQueryParams(uri, selection, projection);
152155
projection = ensureIdIsFullyQualified(projection, queryParams.table, queryParams.idColumn);
153156
Cursor res = mSqLiteOpenHelper.getReadableDatabase().query(queryParams.tablesWithJoins, projection, queryParams.selection, selectionArgs, groupBy,
154-
null, sortOrder == null ? queryParams.orderBy : sortOrder, limit);
157+
having, sortOrder == null ? queryParams.orderBy : sortOrder, limit);
155158
res.setNotificationUri(getContext().getContentResolver(), uri);
156159
return res;
157160
}
@@ -207,6 +210,10 @@ public static Uri groupBy(Uri uri, String groupBy) {
207210
return uri.buildUpon().appendQueryParameter(QUERY_GROUP_BY, groupBy).build();
208211
}
209212

213+
public static Uri having(Uri uri, String having) {
214+
return uri.buildUpon().appendQueryParameter(QUERY_HAVING, having).build();
215+
}
216+
210217
public static Uri limit(Uri uri, String limit) {
211218
return uri.buildUpon().appendQueryParameter(QUERY_LIMIT, limit).build();
212219
}

etc/sample/app/src/org/jraf/androidcontentprovidergenerator/sample/provider/company/CompanySelection.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ public CompanyCursor query(ContentResolver contentResolver, String[] projection,
5858
}
5959

6060
/**
61-
* Equivalent of calling {@code query(contentResolver, projection, null}.
61+
* Equivalent of calling {@code query(contentResolver, projection, null)}.
6262
*/
6363
public CompanyCursor query(ContentResolver contentResolver, String[] projection) {
6464
return query(contentResolver, projection, null);
6565
}
6666

6767
/**
68-
* Equivalent of calling {@code query(contentResolver, projection, null, null}.
68+
* Equivalent of calling {@code query(contentResolver, projection, null, null)}.
6969
*/
7070
public CompanyCursor query(ContentResolver contentResolver) {
7171
return query(contentResolver, null, null);
@@ -77,7 +77,6 @@ public CompanySelection id(long... value) {
7777
return this;
7878
}
7979

80-
8180
public CompanySelection name(String... value) {
8281
addEquals(CompanyColumns.NAME, value);
8382
return this;

etc/sample/app/src/org/jraf/androidcontentprovidergenerator/sample/provider/person/PersonSelection.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ public PersonCursor query(ContentResolver contentResolver, String[] projection,
5757
}
5858

5959
/**
60-
* Equivalent of calling {@code query(contentResolver, projection, null}.
60+
* Equivalent of calling {@code query(contentResolver, projection, null)}.
6161
*/
6262
public PersonCursor query(ContentResolver contentResolver, String[] projection) {
6363
return query(contentResolver, projection, null);
6464
}
6565

6666
/**
67-
* Equivalent of calling {@code query(contentResolver, projection, null, null}.
67+
* Equivalent of calling {@code query(contentResolver, projection, null, null)}.
6868
*/
6969
public PersonCursor query(ContentResolver contentResolver) {
7070
return query(contentResolver, null, null);
@@ -76,7 +76,6 @@ public PersonSelection id(long... value) {
7676
return this;
7777
}
7878

79-
8079
public PersonSelection firstName(String... value) {
8180
addEquals(PersonColumns.FIRST_NAME, value);
8281
return this;

etc/sample/app/src/org/jraf/androidcontentprovidergenerator/sample/provider/personteam/PersonTeamSelection.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ public PersonTeamCursor query(ContentResolver contentResolver, String[] projecti
6262
}
6363

6464
/**
65-
* Equivalent of calling {@code query(contentResolver, projection, null}.
65+
* Equivalent of calling {@code query(contentResolver, projection, null)}.
6666
*/
6767
public PersonTeamCursor query(ContentResolver contentResolver, String[] projection) {
6868
return query(contentResolver, projection, null);
6969
}
7070

7171
/**
72-
* Equivalent of calling {@code query(contentResolver, projection, null, null}.
72+
* Equivalent of calling {@code query(contentResolver, projection, null, null)}.
7373
*/
7474
public PersonTeamCursor query(ContentResolver contentResolver) {
7575
return query(contentResolver, null, null);
@@ -81,7 +81,6 @@ public PersonTeamSelection id(long... value) {
8181
return this;
8282
}
8383

84-
8584
public PersonTeamSelection personId(long... value) {
8685
addEquals(PersonTeamColumns.PERSON_ID, toObjectArray(value));
8786
return this;

etc/sample/app/src/org/jraf/androidcontentprovidergenerator/sample/provider/product/ProductSelection.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ public ProductCursor query(ContentResolver contentResolver, String[] projection,
5757
}
5858

5959
/**
60-
* Equivalent of calling {@code query(contentResolver, projection, null}.
60+
* Equivalent of calling {@code query(contentResolver, projection, null)}.
6161
*/
6262
public ProductCursor query(ContentResolver contentResolver, String[] projection) {
6363
return query(contentResolver, projection, null);
6464
}
6565

6666
/**
67-
* Equivalent of calling {@code query(contentResolver, projection, null, null}.
67+
* Equivalent of calling {@code query(contentResolver, projection, null, null)}.
6868
*/
6969
public ProductCursor query(ContentResolver contentResolver) {
7070
return query(contentResolver, null, null);
@@ -76,7 +76,6 @@ public ProductSelection id(long... value) {
7676
return this;
7777
}
7878

79-
8079
public ProductSelection productId(long... value) {
8180
addEquals(ProductColumns.PRODUCT_ID, toObjectArray(value));
8281
return this;

etc/sample/app/src/org/jraf/androidcontentprovidergenerator/sample/provider/serialnumber/SerialNumberSelection.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ public SerialNumberCursor query(ContentResolver contentResolver, String[] projec
5757
}
5858

5959
/**
60-
* Equivalent of calling {@code query(contentResolver, projection, null}.
60+
* Equivalent of calling {@code query(contentResolver, projection, null)}.
6161
*/
6262
public SerialNumberCursor query(ContentResolver contentResolver, String[] projection) {
6363
return query(contentResolver, projection, null);
6464
}
6565

6666
/**
67-
* Equivalent of calling {@code query(contentResolver, projection, null, null}.
67+
* Equivalent of calling {@code query(contentResolver, projection, null, null)}.
6868
*/
6969
public SerialNumberCursor query(ContentResolver contentResolver) {
7070
return query(contentResolver, null, null);
@@ -76,7 +76,6 @@ public SerialNumberSelection id(long... value) {
7676
return this;
7777
}
7878

79-
8079
public SerialNumberSelection part0(String... value) {
8180
addEquals(SerialNumberColumns.PART0, value);
8281
return this;

etc/sample/app/src/org/jraf/androidcontentprovidergenerator/sample/provider/team/TeamSelection.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ public TeamCursor query(ContentResolver contentResolver, String[] projection, St
6060
}
6161

6262
/**
63-
* Equivalent of calling {@code query(contentResolver, projection, null}.
63+
* Equivalent of calling {@code query(contentResolver, projection, null)}.
6464
*/
6565
public TeamCursor query(ContentResolver contentResolver, String[] projection) {
6666
return query(contentResolver, projection, null);
6767
}
6868

6969
/**
70-
* Equivalent of calling {@code query(contentResolver, projection, null, null}.
70+
* Equivalent of calling {@code query(contentResolver, projection, null, null)}.
7171
*/
7272
public TeamCursor query(ContentResolver contentResolver) {
7373
return query(contentResolver, null, null);
@@ -79,7 +79,6 @@ public TeamSelection id(long... value) {
7979
return this;
8080
}
8181

82-
8382
public TeamSelection companyId(long... value) {
8483
addEquals(TeamColumns.COMPANY_ID, toObjectArray(value));
8584
return this;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public abstract class BaseContentProvider extends ContentProvider {
8080
}
8181

8282
@Override
83-
public int bulkInsert(Uri uri, <#if config.useAnnotations>@NonNull </#if>ContentValues[] values) {
83+
public int bulkInsert(Uri uri, ContentValues[] values) {
8484
String table = uri.getLastPathSegment();
8585
SQLiteDatabase db = mSqLiteOpenHelper.getWritableDatabase();
8686
int res = 0;
@@ -154,7 +154,7 @@ public abstract class BaseContentProvider extends ContentProvider {
154154
}
155155

156156
@Override
157-
public ContentProviderResult[] applyBatch(<#if config.useAnnotations>@NonNull </#if>ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
157+
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
158158
HashSet<Uri> urisToNotify = new HashSet<Uri>(operations.size());
159159
for (ContentProviderOperation operation : operations) {
160160
urisToNotify.add(operation.getUri());

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public class ${config.providerClassName} extends BaseContentProvider {
8383
}
8484

8585
@Override
86-
public int bulkInsert(Uri uri, <#if config.useAnnotations>@NonNull </#if>ContentValues[] values) {
86+
public int bulkInsert(Uri uri, ContentValues[] values) {
8787
if (DEBUG) Log.d(TAG, "bulkInsert uri=" + uri + " values.length=" + values.length);
8888
return super.bulkInsert(uri, values);
8989
}

0 commit comments

Comments
 (0)