MAX
20 | */
21 | public interface Max extends IFunction {
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/bingzer/android/dbv/queries/Min.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Ricky Tobing
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance insert the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.bingzer.android.dbv.queries;
17 |
18 | /**
19 | * Represents MIN
20 | */
21 | public interface Min extends IFunction {
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/bingzer/android/dbv/queries/Sum.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Ricky Tobing
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance insert the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.bingzer.android.dbv.queries;
17 |
18 | /**
19 | * Represents SUM
20 | */
21 | public interface Sum extends IFunction {
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/Library/build.gradle:
--------------------------------------------------------------------------------
1 | project.ext.set("archivesBaseName", "dbquery");
2 |
3 | apply plugin: 'com.android.library'
4 |
5 | android {
6 | compileSdkVersion Integer.parseInt(project.VERSION_SDK)
7 | buildToolsVersion project.VERSION_TOOLS
8 |
9 | defaultConfig {
10 | minSdkVersion Integer.parseInt(project.VERSION_SDK_MIN)
11 | targetSdkVersion Integer.parseInt(project.VERSION_SDK_TARGET)
12 | versionCode Integer.parseInt(project.VERSION_CODE)
13 | versionName project.VERSION_NAME
14 | }
15 | }
16 |
17 | dependencies{
18 | // -- Mockito
19 | androidTestCompile 'org.mockito:mockito-core:1.9.5'
20 | androidTestCompile 'com.google.dexmaker:dexmaker:1.1'
21 | androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.1'
22 | }
23 |
24 | apply from: 'https://raw.github.com/bingzer/gradle-mvn-push/master/gradle-mvn-push.gradle'
25 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/bingzer/android/dbv/queries/Total.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Ricky Tobing
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance insert the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.bingzer.android.dbv.queries;
17 |
18 | /**
19 | * Represents Total
20 | */
21 | public interface Total extends IFunction {
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/bingzer/android/dbv/queries/Average.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Ricky Tobing
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance insert the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.bingzer.android.dbv.queries;
17 |
18 | /**
19 | * Represents AVG functions.
20 | */
21 | public interface Average extends IFunction{
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/bingzer/android/dbv/internal/DeleteImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Ricky Tobing
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.bingzer.android.dbv.internal;
17 |
18 | import com.bingzer.android.dbv.queries.Delete;
19 |
20 | /**
21 | * Created by Ricky on 4/26/2014.
22 | */
23 | class DeleteImpl extends QueryImpl
21 | * Find a complete Wiki and documentation here:
22 | * https://github.com/bingzer/DbQuery/wiki
23 | *
21 | * Find a complete Wiki and documentation here:
22 | * https://github.com/bingzer/DbQuery/wiki
23 | *
Authority
25 | * @param authority authority to set
26 | */
27 | void setDefaultAuthority(String authority);
28 |
29 | /**
30 | * Returns the authority
31 | * @return Authority
32 | */
33 | String getDefaultAuthority();
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/bingzer/android/dbv/queries/IQuery.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Ricky Tobing
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance insert the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.bingzer.android.dbv.queries;
17 |
18 | /**
19 | *
20 | * Find a complete Wiki and documentation here:
21 | * https://github.com/bingzer/DbQuery/wiki
22 | *
21 | * Find a complete Wiki and documentation here:
22 | * https://github.com/bingzer/DbQuery/wiki
23 | *
29 | * Sample Code: To drop a table 30 | *
31 | * db.from("TableName").drop().query();
32 | *
33 | *
34 | *
35 | * @return true if success, false if otherwise.
36 | */
37 | IQuery
30 | * groupBy("SUM(Price) AS TotalPrice", "Name",...)
31 | *
32 | * @param columns column names.
33 | * @return GroupBy object
34 | * @see com.bingzer.android.dbv.queries.GroupBy
35 | */
36 | GroupBy groupBy(String... columns);
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/Sample/src/main/java/com/bingzer/android/dbv/sample/SampleApp.java:
--------------------------------------------------------------------------------
1 | package com.bingzer.android.dbv.sample;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 |
6 | import com.bingzer.android.dbv.DbQuery;
7 | import com.bingzer.android.dbv.IDatabase;
8 | import com.bingzer.android.dbv.SQLiteBuilder;
9 |
10 | import java.io.File;
11 | import java.io.IOException;
12 |
13 | /**
14 | * Created by Ricky on 8/17/13.
15 | */
16 | public class SampleApp extends Application {
17 |
18 | File dbFile = null;
19 |
20 | @Override
21 | public void onCreate() {
22 | super.onCreate();
23 |
24 | extractDbFile();
25 | IDatabase db = DbQuery.getDatabase("Chinook");
26 | db.getConfig().setReadOnly(true);
27 | db.getConfig().setAppendTableNameForId(true);
28 | db.open(1, dbFile.getAbsolutePath(), new SQLiteBuilder.WithoutModeling(this));
29 | }
30 |
31 | private void extractDbFile(){
32 | // transfer the db file to sd card
33 | dbFile = new File(getBaseContext().getFilesDir(), "Chinook.sqlite");
34 | if(!dbFile.exists()){
35 | try{
36 | IOHelper.copyFile(getResources().getAssets().open("Chinook.sqlite"), dbFile);
37 | }
38 | catch (IOException e){
39 | throw new Error(e);
40 | }
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/bingzer/android/dbv/queries/InnerJoin.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Ricky Tobing
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance insert the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.bingzer.android.dbv.queries;
17 |
18 | import com.bingzer.android.dbv.contracts.Distinguishable;
19 | import com.bingzer.android.dbv.contracts.Joinable;
20 | import com.bingzer.android.dbv.contracts.Selectable;
21 |
22 | /**
23 | * Represents an inner join statement
24 | *
25 | * Find a complete Wiki and documentation here:
26 | * https://github.com/bingzer/DbQuery/wiki
27 | *
25 | * Find a complete Wiki and documentation here:
26 | * https://github.com/bingzer/DbQuery/wiki
27 | *
25 | * Find a complete Wiki and documentation here:
26 | * https://github.com/bingzer/DbQuery/wiki
27 | *
27 | * Find a complete Wiki and documentation here:
28 | * https://github.com/bingzer/DbQuery/wiki
29 | *
query() to from the cursor.
30 | * @param sql sql string to raw
31 | * @return {@link IQuery}
32 | */
33 | IQueryquery() to from the cursor.
37 | * @param sql sql string to raw
38 | * @param args arguments
39 | * @return {@link IQuery}
40 | */
41 | IQuerySELECT statement
29 | * @param select {@link com.bingzer.android.dbv.queries.Select} object
30 | * @return {@link com.bingzer.android.dbv.queries.Union} object
31 | */
32 | Union union(Select select);
33 |
34 | /**
35 | * Union All with other SELECT statement
36 | * @param select {@link com.bingzer.android.dbv.queries.Select} object
37 | * @return {@link com.bingzer.android.dbv.queries.Union} object
38 | */
39 | Union unionAll(Select select);
40 | }
41 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/bingzer/android/dbv/queries/Having.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Ricky Tobing
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance insert the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.bingzer.android.dbv.queries;
17 |
18 | import android.database.Cursor;
19 |
20 | import com.bingzer.android.dbv.contracts.ColumnSelectable;
21 | import com.bingzer.android.dbv.contracts.CursorEnumerable;
22 | import com.bingzer.android.dbv.contracts.EntitySelectable;
23 | import com.bingzer.android.dbv.contracts.Pagination;
24 |
25 | /**
26 | * Represents HAVING
27 | *
28 | * Find a complete Wiki and documentation here:
29 | * https://github.com/bingzer/DbQuery/wiki
30 | *
condition
33 | */
34 | long selectId(String condition);
35 |
36 | /**
37 | * Returns id with specified condition
38 | * @param whereClause 'where' clause
39 | * @param args arguments
40 | * @return the id that matches the condition
41 | */
42 | long selectId(String whereClause, Object... args);
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/Sample/src/androidTest/java/com/bingzer/android/dbv/content/Word.java:
--------------------------------------------------------------------------------
1 | package com.bingzer.android.dbv.content;
2 |
3 | import com.bingzer.android.dbv.Delegate;
4 | import com.bingzer.android.dbv.IEntity;
5 |
6 | /**
7 | * Created by Ricky Tobing on 8/23/13.
8 | */
9 | public class Word implements IEntity{
10 | private long id;
11 | private String word;
12 |
13 | Word(){
14 | this(null);
15 | }
16 |
17 | Word(String word){
18 | this(-1, word);
19 | }
20 |
21 | Word(long id, String word){
22 | this.id = id;
23 | this.word = word;
24 | }
25 |
26 | void setId(long id) {
27 | this.id = id;
28 | }
29 |
30 | String getWord() {
31 | return word;
32 | }
33 |
34 | void setWord(String word) {
35 | this.word = word;
36 | }
37 |
38 | @Override
39 | public long getId() {
40 | return id;
41 | }
42 |
43 | @Override
44 | public void map(Mapper mapper) {
45 | mapper.mapId(new Delegate.TypeLong() {
46 | @Override
47 | public void set(Long value) {
48 | setId(value);
49 | }
50 |
51 | @Override
52 | public Long get() {
53 | return getId();
54 | }
55 | });
56 |
57 | mapper.map("word", new Delegate.TypeString(){
58 |
59 | @Override
60 | public void set(String value) {
61 | setWord(value);
62 | }
63 |
64 | @Override
65 | public String get() {
66 | return getWord();
67 | }
68 | });
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/bingzer/android/dbv/queries/IFunction.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Ricky Tobing
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance insert the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.bingzer.android.dbv.queries;
17 |
18 | /**
19 | * Created by Ricky Tobing on 7/20/13.
20 | */
21 | public interface IFunction {
22 |
23 | /**
24 | * Returns value as int
25 | * @return value as int
26 | */
27 | int asInt();
28 |
29 | /**
30 | * Returns value as long
31 | * @return value as long
32 | */
33 | long asLong();
34 |
35 | /**
36 | * Returns value as float
37 | * @return value as float
38 | */
39 | float asFloat();
40 |
41 | /**
42 | * Returns value as double
43 | * @return value as double
44 | */
45 | double asDouble();
46 |
47 | /**
48 | * Returns value as String
49 | * @return value as String
50 | */
51 | String asString();
52 |
53 | /**
54 | * Returns the 'raw' value
55 | * @return raw value
56 | */
57 | Object value();
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/Extensions/ContentQuery/src/main/java/com/bingzer/android/dbv/content/contracts/IBaseResolver.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Ricky Tobing
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.bingzer.android.dbv.content.contracts;
17 |
18 |
19 | import android.net.Uri;
20 |
21 | import com.bingzer.android.dbv.contracts.PrimaryKeyIdentifier;
22 | import com.bingzer.android.dbv.contracts.Countable;
23 | import com.bingzer.android.dbv.contracts.Deletable;
24 | import com.bingzer.android.dbv.contracts.Insertable;
25 | import com.bingzer.android.dbv.contracts.SelectIdentifiable;
26 | import com.bingzer.android.dbv.contracts.Tangible;
27 | import com.bingzer.android.dbv.contracts.Updatable;
28 |
29 | /**
30 | * Created by Ricky Tobing on 8/23/13.
31 | */
32 | public interface IBaseResolver extends
33 | PrimaryKeyIdentifier,
34 | SelectIdentifiable, Insertable, Updatable, Deletable, Tangible, Countable {
35 |
36 | /**
37 | * Returns the URI
38 | * @return the URI
39 | */
40 | Uri getUri();
41 |
42 | /**
43 | * Returns the default config
44 | * @return the config
45 | */
46 | IContentQueryConfig getContentConfig();
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/bingzer/android/dbv/contracts/CursorEnumerable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Ricky Tobing
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance insert the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */package com.bingzer.android.dbv.contracts;
16 |
17 | import android.database.Cursor;
18 |
19 | import com.bingzer.android.dbv.queries.ISequence;
20 |
21 | /**
22 | * Cursor enumerable.
23 | */
24 | public interface CursorEnumerable {
25 |
26 | /**
27 | * A convenient method iterate through cursor.
28 | * The provider will call this method as long as
29 | * cursor.moveNext() is true. Cursor will be open and closed
30 | * automatically after this method returns
31 | * 32 | * Sample code: Print and LOG all customers names in the customers table 33 | *
34 | * db.from("Customers")
35 | * .select().columns("Name")
36 | * .query(new IEnumerable<Cursor>(){
37 | * public void next(Cursor cursor){
38 | * Log.i("TAG", "Name: " + cursor.getString(0));
39 | * }
40 | * });
41 | *
42 | *
43 | * @param cursor the cursor
44 | */
45 | void query(ISequenceINSERT,UPDATE and DELETE
25 | * operations. They are, however, allowed to query or perform
26 | * SELECT
27 | *
28 | */
29 | public abstract class ReadOnlyDataProvider extends DataProvider {
30 |
31 | @Override
32 | public Uri insert(Uri uri, ContentValues contentValues) {
33 | throw new UnsupportedOperationException("Read-only");
34 | }
35 |
36 | @Override
37 | public int delete(Uri uri, String selection, String[] selectionArgs) {
38 | throw new UnsupportedOperationException("Read-only");
39 | }
40 |
41 | @Override
42 | public int update(Uri uri, ContentValues contentValues, String selection, String[] selectionArgs) {
43 | throw new UnsupportedOperationException("Read-only");
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/bingzer/android/dbv/internal/InsertIntoImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Ricky Tobing
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.bingzer.android.dbv.internal;
17 |
18 | import android.content.ContentValues;
19 |
20 | import com.bingzer.android.dbv.queries.IQuery;
21 | import com.bingzer.android.dbv.queries.InsertInto;
22 | import com.bingzer.android.dbv.utils.ContentValuesUtils;
23 |
24 | /**
25 | * Created by Ricky on 4/26/2014.
26 | */
27 | class InsertIntoImpl extends InsertImpl implements InsertInto {
28 |
29 | private ContentSet
31 | *
32 | * ...
33 | * public IDatabase openDatabase(){
34 | * IDatabase db = DbQuery.getDatabase("MyDatabase");
35 | * db.open(1, new SQLiteBuilder(){
36 | * ...
37 | * });
38 | *
39 | * return db;
40 | * }
41 | * ...
42 | *
43 | *
44 | *
45 | * @see {@link IDatabase}
46 | * @return {@link IDatabase}
47 | */
48 | IDatabase openDatabase();
49 |
50 | /**
51 | * Returns the authority string. Android documentation suggested to use
52 | * package style name (i.e: com.company.data.x).
53 | *
54 | * @return Authority string
55 | */
56 | String getAuthority();
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/Library/src/androidTest/java/com/bingzer/android/dbv/OrmPerson.java:
--------------------------------------------------------------------------------
1 | package com.bingzer.android.dbv;
2 |
3 | public class OrmPerson extends BaseEntity {
4 |
5 | private String name;
6 | private int age;
7 |
8 | public OrmPerson(){
9 | this(null, -1);
10 | }
11 |
12 | public OrmPerson(String name, int age){
13 | this.name = name;
14 | this.age = age;
15 | }
16 |
17 | public OrmPerson(IEnvironment environment){
18 | super(environment);
19 | }
20 |
21 | public int getAge() {
22 | return age;
23 | }
24 |
25 | public void setAge(int age) {
26 | this.age = age;
27 | }
28 |
29 | public String getName() {
30 | return name;
31 | }
32 |
33 | public void setName(String name) {
34 | this.name = name;
35 | }
36 |
37 | /**
38 | * The table name that this entity represents
39 | */
40 | @Override
41 | public String getTableName() {
42 | return "Person";
43 | }
44 |
45 | /**
46 | * Determines how to map column and the class variable.
47 | *
48 | * @param mapper the mapper object
49 | */
50 | @Override
51 | public void map(Mapper mapper) {
52 | mapId(mapper);
53 | mapper.map("Name", new Delegate.TypeString(){
54 | @Override
55 | public void set(String value) {
56 | setName(value);
57 | }
58 | @Override
59 | public String get() {
60 | return getName();
61 | }
62 | });
63 |
64 | mapper.map("Age", new Delegate.TypeInteger(){
65 | @Override
66 | public void set(Integer value) {
67 | setAge(value);
68 | }
69 | @Override
70 | public Integer get() {
71 | return getAge();
72 | }
73 | });
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/bingzer/android/dbv/utils/CursorUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Ricky Tobing
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance insert the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.bingzer.android.dbv.utils;
17 |
18 | import android.database.Cursor;
19 |
20 | /**
21 | * Collection of utility methods that's cursor related
22 | */
23 | public final class CursorUtils {
24 |
25 | /**
26 | * Try to return value from cursor
27 | * @param cursor the target cursor
28 | * @param columnName the column index
29 | * @param
28 | * Find a complete Wiki and documentation here:
29 | * https://github.com/bingzer/DbQuery/wiki
30 | *
HAVING statement
40 | * with the specified condition
41 | * @param condition the condition to set
42 | * @return Having object
43 | */
44 | Having having(String condition);
45 |
46 | /**
47 | * Adds a HAVING statement
48 | * with the specified condition
49 | * @param clause clause
50 | * @param args args
51 | * @return Having object
52 | */
53 | Having having(String clause, Object... args);
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/bingzer/android/dbv/internal/TransactionImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Ricky Tobing
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance insert the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.bingzer.android.dbv.internal;
18 |
19 | import com.bingzer.android.dbv.IDatabase;
20 | import com.bingzer.android.dbv.internal.Database;
21 |
22 | /**
23 | * Implements of {@link com.bingzer.android.dbv.IDatabase.Transaction}
24 | *
25 | * Created by Ricky Tobing on 8/12/13.
26 | */
27 | class TransactionImpl implements IDatabase.Transaction {
28 |
29 | final Database database;
30 | final IDatabase.Batch batch;
31 |
32 | public TransactionImpl(Database database, IDatabase.Batch batch){
33 | this.database = database;
34 | this.batch = batch;
35 | }
36 |
37 | @Override
38 | public void commit() {
39 | synchronized (this){
40 | database.begin();
41 | batch.exec(database);
42 | database.commit();
43 | }
44 | }
45 |
46 | @Override
47 | public void rollback() {
48 | database.rollback();
49 | }
50 |
51 | @Override
52 | public void end() {
53 | database.end();
54 | }
55 |
56 | @Override
57 | public boolean execute() {
58 | try{
59 | commit();
60 | return true;
61 | }
62 | catch (Throwable e){
63 | rollback();
64 | return false;
65 | }
66 | finally {
67 | end();
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/bingzer/android/dbv/contracts/EntitySelectable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Ricky Tobing
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance insert the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.bingzer.android.dbv.contracts;
18 |
19 | import com.bingzer.android.dbv.IEntity;
20 | import com.bingzer.android.dbv.IEntityList;
21 |
22 | /**
23 | * Extension for an IEntity
24 | *
25 | * @see IEntity
26 | */
27 | public interface EntitySelectable {
28 |
29 | /**
30 | * Query and store the result to an {@link com.bingzer.android.dbv.IEntity}
31 | * 32 | * Sample Code: Populate customer data whose name is John into a Customer object 33 | *
34 | * Customer customer = new Customer();
35 | * ...
36 | * db.from("TableName").select("Name = ?", "John").query(customer);
37 | *
38 | *
39 | * @see IEntity
40 | * @param entity the IEntity object
41 | */
42 | void query(IEntity entity);
43 |
44 | /**
45 | * Query and store the result to an {@link com.bingzer.android.dbv.IEntityList}
46 | * 47 | * Sample Code: Populate a customer list whose country is US 48 | *
49 | * CustomerList customerList = new CustomerList();
50 | * ...
51 | * db.from("TableName").select("Country = ?", "US").query(customerList);
52 | *
53 | *
54 | * @see IEntityList
55 | * @param entityList the IEntityList object
56 | * @param 24 | * Sample Code: 25 | *
26 | * //---- Person.java
27 | * public Person implements IEntity {
28 | * ...
29 | * }
30 | *
31 | * //---- PersonList.java
32 | * public PersonList extends ArrayList<Person> implements IEntityList<Person> {
33 | * ...
34 | * }
35 | *
36 | * //---- Other.java
37 | * IDatabase db = ...
38 | * PersonList personList = new PersonList();
39 | *
40 | * // Get all customers from US
41 | * db.from("Customers").select("Country = ?", "US").query(personList);
42 | *
43 | *
44 | *
45 | * @version 2.0
46 | * @see com.bingzer.android.dbv.IEntity
47 | * @see com.bingzer.android.dbv.queries.Select#query(IEntity)
48 | * @see com.bingzer.android.dbv.ITable#insert(IEntity)
49 | */
50 | public interface IEntityList
23 | * Find a complete Wiki and documentation here:
24 | * https://github.com/bingzer/DbQuery/wiki
25 | *
29 | * Sample code to from the customer name from a customer table 30 | *
31 | * String customerName = db.from("customers").select().columns("Name", "Age").query(0);
32 | *
33 | *
34 | *
35 | * Sample code to from the customer's age from a customer table
36 | *
37 | * int customerAge = db.from("customers").select().columns("Name", "Age").query(1);
38 | *
39 | *
40 | * @param columnIndex the column index
41 | * @param 52 | * Sample code to from the customer name from a customer table 53 | *
54 | * String customerName = db.from("customers").select().columns("Name", "Age").query("Name");
55 | *
56 | *
57 | * Sample code to from the customer's age from a customer table
58 | *
59 | * int customerAge = db.from("customers").select().columns("Name", "Age").query("Age");
60 | *
61 | *
62 | * @param columnName the column name
63 | * @param selectDistinct(null)
29 | * @return {@link com.bingzer.android.dbv.queries.Select}
30 | */
31 | Select selectDistinct();
32 |
33 | /**
34 | * Select distinct
35 | * @param condition the condition
36 | * @return {@link com.bingzer.android.dbv.queries.Select}
37 | */
38 | Select selectDistinct(String condition);
39 |
40 | /**
41 | * Select distinct add condition
42 | * @param whereClause 'where' clause
43 | * @param args arguments
44 | * @return {@link com.bingzer.android.dbv.queries.Select}
45 | */
46 | Select selectDistinct(String whereClause, Object... args);
47 |
48 | /**
49 | * Select distinct with limit (top)
50 | * @param top the limit to return
51 | * @return {@link com.bingzer.android.dbv.queries.Select}
52 | */
53 | Select selectDistinct(int top);
54 |
55 | /**
56 | * Select distinct with limit (top) with the specified condition
57 | * @param top the limit to return
58 | * @param condition the condition
59 | * @return {@link com.bingzer.android.dbv.queries.Select}
60 | */
61 | Select selectDistinct(int top, String condition);
62 |
63 | /**
64 | * Select distinct with limit (top) with the specified condition
65 | * @param top the limit to return
66 | * @param whereClause the where clause
67 | * @param args arguments
68 | * @return {@link com.bingzer.android.dbv.queries.Select}
69 | */
70 | Select selectDistinct(int top, String whereClause, Object... args);
71 | }
72 |
--------------------------------------------------------------------------------
/Library/src/androidTest/java/com/bingzer/android/dbv/IdNamingConventionTest.java:
--------------------------------------------------------------------------------
1 | package com.bingzer.android.dbv;
2 |
3 | import android.content.Context;
4 | import android.test.AndroidTestCase;
5 |
6 | import com.bingzer.android.dbv.queries.InsertInto;
7 |
8 | /**
9 | * Created by Ricky Tobing on 8/13/13.
10 | */
11 | public class IdNamingConventionTest extends AndroidTestCase {
12 |
13 | IDatabase db;
14 |
15 | @Override
16 | public void setUp(){
17 | db = DbQuery.getDatabase("NamingConventionDb");
18 | db.getConfig().setIdNamingConvention("IDX");
19 | db.getConfig().setAppendTableNameForId(true);
20 | db.open(1, new SQLiteBuilder() {
21 | @Override
22 | public Context getContext() {
23 | return IdNamingConventionTest.this.getContext();
24 | }
25 |
26 | @Override
27 | public void onModelCreate(IDatabase database, IDatabase.Modeling modeling) {
28 | modeling.add("Person")
29 | .addPrimaryKey("PersonIDX")
30 | .add("Name", "String")
31 | .add("Age", "Integer")
32 | .add("Address", "Blob");
33 | }
34 | });
35 |
36 | db.from("Person").delete();
37 |
38 |
39 | InsertInto insert = db.from("Person").insertInto("Name", "Age", "Address");
40 | insert.val("John", 23, "Washington DC".getBytes());
41 | insert.val("Ronaldo", 40, "Madrid".getBytes());
42 | insert.val("Messi", 25, "Barcelona".getBytes());
43 | }
44 |
45 | public void testSelect(){
46 | Person person = new Person();
47 |
48 | db.from("Person").select("Name = ?", "John").query(person);
49 | assertTrue(person.getId() > 0);
50 | assertTrue(person.getName().equals("John"));
51 | db.from("Person").select("Name = ?", "Messi").query(person);
52 | assertTrue(person.getId() > 0);
53 | assertTrue(new String(person.getAddressBytes()).equals("Barcelona"));
54 | }
55 |
56 | public void testUpdate(){
57 | Person person = new Person();
58 | db.from("Person").select("Name = ?", "John").query(person); // john
59 | long id = person.getId();
60 | // modify
61 | person.setName("MOD");
62 | person.setAge(20);
63 | db.from("Person").update(person);
64 | // reget
65 | db.from("Person").select(id).query(person);
66 | assertTrue(person.getName().equals("MOD"));
67 | assertTrue(person.getAge() == 20);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/bingzer/android/dbv/queries/Select.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Ricky Tobing
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance insert the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.bingzer.android.dbv.queries;
17 |
18 | import android.database.Cursor;
19 |
20 | import com.bingzer.android.dbv.contracts.ColumnSelectable;
21 | import com.bingzer.android.dbv.contracts.CursorEnumerable;
22 | import com.bingzer.android.dbv.contracts.EntitySelectable;
23 | import com.bingzer.android.dbv.contracts.Groupable;
24 | import com.bingzer.android.dbv.contracts.Pagination;
25 |
26 | /**
27 | * For select statement
28 | *
29 | * Find a complete Wiki and documentation here:
30 | * https://github.com/bingzer/DbQuery/wiki
31 | *
50 | * db.from("Table").select().orderBy("Id", "Name", "Price DESC");
51 | *
52 | *
53 | * @param columns column names
54 | * @return {@link com.bingzer.android.dbv.queries.Select}
55 | */
56 | OrderBy orderBy(String... columns);
57 |
58 | /////////////////////////////////////////////////////////////////////////////////////////
59 |
60 | /**
61 | * Order By
62 | */
63 | public static interface OrderBy extends IQueryId. Id with the following scheme is not yet supported:
23 | * val(Object... values)
56 | * to specify the values
57 | * @param columns column names
58 | * @return an InsertWith object
59 | */
60 | InsertInto insertInto(String... columns);
61 |
62 | /////////////////////////////////////////////////////////////////////////////////
63 | /////////////////////////////////////////////////////////////////////////////////
64 |
65 | /**
66 | * Insert an entity.
67 | * @param entity entity
68 | * @return an Insert object
69 | */
70 | Insert insert(IEntity entity);
71 |
72 | /**
73 | * Bulk-insert an entity list. The returned value, (via Insert.query())
74 | * is an integer and returns the number of entity successfully inserted.
75 | * Ids are automatically populated inside the IEntity object
76 | * @param entityList the entity list to insert
77 | * @param value.
53 | * The equals() will be performed to check the equality
54 | * @param iterable the target iterable
55 | * @param value the value
56 | * @param value, false otherwise
58 | */
59 | public static value.
67 | * The equals() will be performed to check the equality
68 | * @param iterator the target iterator
69 | * @param value the value
70 | * @param value, false otherwise
72 | */
73 | public static delete(entity.getId())
77 | * @param entity entity to delete
78 | * @return Delete object
79 | */
80 | Delete delete(IEntity entity);
81 |
82 | /**
83 | * Bulk-delete several entities.
84 | * This is equivalent of calling
85 | * delete(list-of-ids)
86 | * @param entityList the entity list
87 | * @param Authority
66 | * @param authority authority to set
67 | */
68 | @Override
69 | public void setDefaultAuthority(String authority){
70 | this.authority = authority;
71 | }
72 |
73 | /**
74 | * Returns the authority
75 | * @return Authority
76 | */
77 | @Override
78 | public String getDefaultAuthority(){
79 | return authority;
80 | }
81 |
82 | @Override
83 | public void setIdNamingConvention(String id) {
84 | String oldId = getIdNamingConvention();
85 | super.setIdNamingConvention(id);
86 |
87 | if(defaultProjections != null && defaultProjections.length > 0){
88 | for(int i = 0; i < defaultProjections.length; i++){
89 | if(defaultProjections[i].equalsIgnoreCase(oldId)){
90 | defaultProjections[i] = id;
91 | }
92 | }
93 | }
94 | else setDefaultProjections();
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/Extensions/ContentQuery/src/main/java/com/bingzer/android/dbv/content/ContentQuery.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Ricky Tobing
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.bingzer.android.dbv.content;
17 |
18 | import android.content.Context;
19 | import android.net.Uri;
20 |
21 | import com.bingzer.android.dbv.content.contracts.IResolver;
22 | import com.bingzer.android.dbv.content.contracts.IStrictResolver;
23 | import com.bingzer.android.dbv.internal.Resolver;
24 | import com.bingzer.android.dbv.internal.StrictResolver;
25 |
26 | /**
27 | * ContentQuery allows DbQuery style while
28 | * querying data from ContentProvider.
29 | *
30 | * For complete documentation please refer to:
31 | * https://github.com/bingzer/DbQuery/wiki/ContentQuery
32 | *
33 | * @see com.bingzer.android.dbv.content.contracts.IResolver
34 | * @see com.bingzer.android.dbv.content.contracts.IStrictResolver
35 | */
36 | public final class ContentQuery {
37 |
38 | /**
39 | * Creates an {@link com.bingzer.android.dbv.content.contracts.IResolver} for the specified URI
40 | * @param uri the uri string
41 | * @param context GOD-object {@link Context}
42 | * @return {@link com.bingzer.android.dbv.content.contracts.IResolver}
43 | */
44 | public static IResolver resolve(String uri, Context context){
45 | return resolve(Uri.parse(uri), context);
46 | }
47 |
48 | /**
49 | * Creates an {@link IResolver} for the specified URI
50 | * @param uri the uri object
51 | * @param context GOD-object {@link Context}
52 | * @return {@link IResolver}
53 | */
54 | public static IResolver resolve(Uri uri, Context context){
55 | return new Resolver(uri, context);
56 | }
57 |
58 | /**
59 | * Creates an {@link com.bingzer.android.dbv.content.contracts.IStrictResolver} for the specified URI
60 | * @param uri the uri string
61 | * @param context GOD-object {@link Context}
62 | * @return {@link com.bingzer.android.dbv.content.contracts.IStrictResolver}
63 | */
64 | public static IStrictResolver strictlyResolve(String uri, Context context){
65 | return strictlyResolve(Uri.parse(uri), context);
66 | }
67 |
68 | /**
69 | * Creates an {@link IStrictResolver} for the specified URI
70 | * @param uri the uri object
71 | * @param context GOD-object {@link Context}
72 | * @return {@link IStrictResolver}
73 | */
74 | public static IStrictResolver strictlyResolve(Uri uri, Context context){
75 | return new StrictResolver(uri, context);
76 | }
77 |
78 | //////////////////////////////////////////////////////////////////////////////////////////////
79 |
80 | private ContentQuery(){
81 | // nothing
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/bingzer/android/dbv/internal/FunctionImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Ricky Tobing
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.bingzer.android.dbv.internal;
17 |
18 | import com.bingzer.android.dbv.queries.IFunction;
19 |
20 | import java.util.Locale;
21 |
22 | /**
23 | * Created by Ricky Tobing on 7/20/13.
24 | */
25 | class FunctionImpl implements IFunction {
26 |
27 | private double value;
28 | private final StringBuilder builder;
29 |
30 | FunctionImpl(String functionName, String tableName, String columnName, String condition){
31 | builder = new StringBuilder("SELECT ")
32 | .append(functionName).append("(").append(columnName).append(") AS FN ")
33 | .append(" FROM ").append(tableName);
34 |
35 | if(condition != null){
36 | // append where if necessary
37 | if(!condition.toLowerCase(Locale.getDefault()).startsWith("where"))
38 | builder.append(" WHERE ");
39 | // safely prepare the where part
40 | builder.append(condition);
41 | }
42 | }
43 |
44 | ////////////////////////////////////////////////////////////////////////////////////////
45 |
46 | public void setValue(double value){
47 | this.value = value;
48 | }
49 |
50 | ////////////////////////////////////////////////////////////////////////////////////////
51 |
52 | @Override
53 | public int asInt() {
54 | try{
55 | return (int) value;
56 | }
57 | catch (NumberFormatException e){
58 | throw new IllegalArgumentException(e);
59 | }
60 | }
61 |
62 | @Override
63 | public long asLong() {
64 | try{
65 | return (long) value;
66 | }
67 | catch (NumberFormatException e){
68 | throw new IllegalArgumentException(e);
69 | }
70 | }
71 |
72 | @Override
73 | public float asFloat() {
74 | try{
75 | return (float) value;
76 | }
77 | catch (NumberFormatException e){
78 | throw new IllegalArgumentException(e);
79 | }
80 | }
81 |
82 | @Override
83 | public double asDouble() {
84 | try{
85 | return value;
86 | }
87 | catch (NumberFormatException e){
88 | throw new IllegalArgumentException(e);
89 | }
90 | }
91 |
92 | @Override
93 | public String asString() {
94 | return value() == null ? null : value().toString();
95 | }
96 |
97 | @Override
98 | public Object value() {
99 | return value;
100 | }
101 |
102 | @Override
103 | public String toString(){
104 | return builder.toString();
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/Extensions/ContentQuery/src/main/java/com/bingzer/android/dbv/content/contracts/StrictSelectable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Ricky Tobing
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.bingzer.android.dbv.content.contracts;
17 |
18 | import android.database.Cursor;
19 |
20 | import com.bingzer.android.dbv.contracts.EntitySelectable;
21 | import com.bingzer.android.dbv.queries.IQuery;
22 |
23 | /**
24 | * Created by Ricky Tobing on 8/23/13.
25 | */
26 | public interface StrictSelectable {
27 |
28 | /**
29 | * Select some condition
30 | * @param condition the condition
31 | * @return {@link com.bingzer.android.dbv.queries.Select}
32 | */
33 | Select select(String condition);
34 |
35 | /**
36 | * Select id. Id column must be defined in the naming convention
37 | * specified in {@link com.bingzer.android.dbv.IConfig}
38 | * @param id id to search
39 | * @see com.bingzer.android.dbv.IConfig#setIdNamingConvention(String)
40 | * @return {@link com.bingzer.android.dbv.queries.Select}
41 | */
42 | Select select(long id);
43 |
44 | /**
45 | * Select multiple ids
46 | * @param ids array id
47 | * @return {@link com.bingzer.android.dbv.queries.Select}
48 | */
49 | Select select(long... ids);
50 |
51 | /**
52 | * Select along with whereClause
53 | * @param whereClause 'where' clause
54 | * @param args arguments
55 | * @return {@link com.bingzer.android.dbv.queries.Select}
56 | */
57 | Select select(String whereClause, Object... args);
58 |
59 | /**
60 | * For select statement
61 | *
62 | * Find a complete Wiki and documentation here:
63 | * https://github.com/bingzer/DbQuery/wiki
64 | *
80 | *
81 | * db.from("Table").select().orderBy("Id", "Name", "Price DESC");
82 | *
83 | *
84 | * @param columns column names
85 | * @return {@link com.bingzer.android.dbv.queries.Select}
86 | */
87 | OrderBy orderBy(String... columns);
88 |
89 | /**
90 | * Order By
91 | */
92 | public static interface OrderBy extends IQuery
27 | * DbQuery provides access to {@link IDatabase}. To use DbQuery,
28 | * you must follow special conventions when it comes to "Id" as primary key
29 | * in every table in your database.
30 | *
33 | * Warning:
34 | * DbQuery will assume
35 | * that every table will follow a naming convention for
36 | * their identifier scheme. By default, "Id" is assigned
37 | * automatically. For more information see {@link IConfig}
38 | *
41 | * Sample Code: 42 | *
43 | * IDatabase db = DbQuery.getDatabase("{database-name}");
44 | * ...
45 | *
46 | *
47 | *
48 | * 49 | * DbQuery is totally open! 50 | *
63 | * Important: This entire javadoc is not read-proof. Some may be up to date, others may not
64 | *
65 | *
66 | * @version 2.0
67 | * @see IConfig
68 | * @see IDatabase
69 | * @author Ricky Tobing
70 | */
71 | public final class DbQuery {
72 |
73 | private static Collectionquery() method will return -1 if there's an error updating and the
72 | * transaction is rollback-ed. Otherwise, it will return the number of records updated
73 | *
74 | * @param entityList IEntityList object
75 | * @param