Skip to content

Commit 3025cb5

Browse files
committed
Fix for issue #43.
1 parent d402886 commit 3025cb5

File tree

16 files changed

+1720
-13
lines changed

16 files changed

+1720
-13
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Android ContentProvider Generator Changelog
22
===========================================
33

4+
v1.11.0 (2016-11-12)
5+
------
6+
- Beans generation (if new `generateBeans` boolean parameter in config is true) - fix for issue #43.
7+
48
v1.10.0 (2016-10-30)
59
------
610
- Fix for issue #91.

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ It takes a set of entity (a.k.a "table") definitions as the input, and generates
1111
- one `ContentValues` class per entity
1212
- one `Selection` class per entity
1313
- one `Model` interface per entity
14+
- one `Bean` class per entity (optionally)
1415

1516

1617
How to use
@@ -34,7 +35,8 @@ These are self-explanatory so here is an example:
3435
"databaseVersion": 1,
3536
"enableForeignKeys": true,
3637
"useAnnotations": true,
37-
"useSupportLibrary": true
38+
"useSupportLibrary": true,
39+
"generateBeans": true
3840
}
3941
```
4042

@@ -128,7 +130,7 @@ https://github.com/BoD/android-contentprovider-generator/releases/latest
128130

129131
### Run the tool
130132

131-
`java -jar android_contentprovider_generator-1.10.0-bundle.jar -i <input folder> -o <output folder>`
133+
`java -jar android_contentprovider_generator-1.11.0-bundle.jar -i <input folder> -o <output folder>`
132134
- Input folder: where to find `_config.json` and your entity json files
133135
- Output folder: where the resulting files will be generated
134136

@@ -243,7 +245,7 @@ You need maven to build this tool.
243245

244246
`mvn package`
245247

246-
This will produce `android_contentprovider_generator-1.10.0-bundle.jar` in the `target` folder.
248+
This will produce `android_contentprovider_generator-1.11.0-bundle.jar` in the `target` folder.
247249

248250

249251
Similar tools

etc/sample/_config.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"databaseVersion": 1,
1111
"enableForeignKeys": true,
1212
"useAnnotations": true,
13-
"useSupportLibrary": true
13+
"useSupportLibrary": true,
14+
"generateBeans": true
1415
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
/*
2+
* This source is part of the
3+
* _____ ___ ____
4+
* __ / / _ \/ _ | / __/___ _______ _
5+
* / // / , _/ __ |/ _/_/ _ \/ __/ _ `/
6+
* \___/_/|_/_/ |_/_/ (_)___/_/ \_, /
7+
* /___/
8+
* repository.
9+
*
10+
* Copyright (C) 2012-2015 Benoit 'BoD' Lubek ([email protected])
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU General Public License as published by
14+
* the Free Software Foundation, either version 3 of the License, or
15+
* (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*/
25+
package org.jraf.androidcontentprovidergenerator.sample.provider.company;
26+
27+
// @formatter:off
28+
import org.jraf.androidcontentprovidergenerator.sample.provider.base.BaseModel;
29+
30+
import java.util.Date;
31+
32+
import android.support.annotation.NonNull;
33+
import android.support.annotation.Nullable;
34+
35+
/**
36+
* A commercial business.
37+
*/
38+
@SuppressWarnings({"WeakerAccess", "unused", "ConstantConditions"})
39+
public class CompanyBean implements CompanyModel {
40+
private long mId;
41+
private String mName;
42+
private String mAddress;
43+
private long mSerialNumberId;
44+
45+
/**
46+
* Primary key.
47+
*/
48+
@Override
49+
public long getId() {
50+
return mId;
51+
}
52+
53+
/**
54+
* Primary key.
55+
*/
56+
public void setId(long id) {
57+
mId = id;
58+
}
59+
60+
/**
61+
* The commercial name of this company.
62+
* Cannot be {@code null}.
63+
*/
64+
@NonNull
65+
@Override
66+
public String getName() {
67+
return mName;
68+
}
69+
70+
/**
71+
* The commercial name of this company.
72+
* Must not be {@code null}.
73+
*/
74+
public void setName(@NonNull String name) {
75+
if (name == null) throw new IllegalArgumentException("name must not be null");
76+
mName = name;
77+
}
78+
79+
/**
80+
* The full address of this company.
81+
* Can be {@code null}.
82+
*/
83+
@Nullable
84+
@Override
85+
public String getAddress() {
86+
return mAddress;
87+
}
88+
89+
/**
90+
* The full address of this company.
91+
* Can be {@code null}.
92+
*/
93+
public void setAddress(@Nullable String address) {
94+
mAddress = address;
95+
}
96+
97+
/**
98+
* The serial number of this company.
99+
*/
100+
@Override
101+
public long getSerialNumberId() {
102+
return mSerialNumberId;
103+
}
104+
105+
/**
106+
* The serial number of this company.
107+
*/
108+
public void setSerialNumberId(long serialNumberId) {
109+
mSerialNumberId = serialNumberId;
110+
}
111+
112+
@Override
113+
public boolean equals(Object o) {
114+
if (this == o) return true;
115+
if (o == null || getClass() != o.getClass()) return false;
116+
CompanyBean bean = (CompanyBean) o;
117+
return mId == bean.mId;
118+
}
119+
120+
@Override
121+
public int hashCode() {
122+
return (int) (mId ^ (mId >>> 32));
123+
}
124+
125+
/**
126+
* Instantiate a new CompanyBean with specified values.
127+
*/
128+
@NonNull
129+
public static CompanyBean newInstance(long id, @NonNull String name, @Nullable String address, long serialNumberId) {
130+
if (name == null) throw new IllegalArgumentException("name must not be null");
131+
CompanyBean res = new CompanyBean();
132+
res.mId = id;
133+
res.mName = name;
134+
res.mAddress = address;
135+
res.mSerialNumberId = serialNumberId;
136+
return res;
137+
}
138+
139+
/**
140+
* Instantiate a new CompanyBean with all the values copied from the given model.
141+
*/
142+
@NonNull
143+
public static CompanyBean copy(@NonNull CompanyModel from) {
144+
CompanyBean res = new CompanyBean();
145+
res.mId = from.getId();
146+
res.mName = from.getName();
147+
res.mAddress = from.getAddress();
148+
res.mSerialNumberId = from.getSerialNumberId();
149+
return res;
150+
}
151+
152+
public static class Builder {
153+
private CompanyBean mRes = new CompanyBean();
154+
155+
/**
156+
* Primary key.
157+
*/
158+
public Builder id(long id) {
159+
mRes.mId = id;
160+
return this;
161+
}
162+
163+
/**
164+
* The commercial name of this company.
165+
* Must not be {@code null}.
166+
*/
167+
public Builder name(@NonNull String name) {
168+
if (name == null) throw new IllegalArgumentException("name must not be null");
169+
mRes.mName = name;
170+
return this;
171+
}
172+
173+
/**
174+
* The full address of this company.
175+
* Can be {@code null}.
176+
*/
177+
public Builder address(@Nullable String address) {
178+
mRes.mAddress = address;
179+
return this;
180+
}
181+
182+
/**
183+
* The serial number of this company.
184+
*/
185+
public Builder serialNumberId(long serialNumberId) {
186+
mRes.mSerialNumberId = serialNumberId;
187+
return this;
188+
}
189+
190+
/**
191+
* Get a new CompanyBean built with the given values.
192+
*/
193+
public CompanyBean build() {
194+
if (mRes.mName == null) throw new IllegalArgumentException("name must not be null");
195+
return mRes;
196+
}
197+
}
198+
199+
public static Builder newBuilder() {
200+
return new Builder();
201+
}
202+
}

0 commit comments

Comments
 (0)