Skip to content

Commit

Permalink
Fix for issue #43.
Browse files Browse the repository at this point in the history
  • Loading branch information
BoD committed Nov 12, 2016
1 parent d402886 commit 3025cb5
Show file tree
Hide file tree
Showing 16 changed files with 1,720 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Android ContentProvider Generator Changelog
===========================================

v1.11.0 (2016-11-12)
------
- Beans generation (if new `generateBeans` boolean parameter in config is true) - fix for issue #43.

v1.10.0 (2016-10-30)
------
- Fix for issue #91.
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ It takes a set of entity (a.k.a "table") definitions as the input, and generates
- one `ContentValues` class per entity
- one `Selection` class per entity
- one `Model` interface per entity
- one `Bean` class per entity (optionally)


How to use
Expand All @@ -34,7 +35,8 @@ These are self-explanatory so here is an example:
"databaseVersion": 1,
"enableForeignKeys": true,
"useAnnotations": true,
"useSupportLibrary": true
"useSupportLibrary": true,
"generateBeans": true
}
```

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

### Run the tool

`java -jar android_contentprovider_generator-1.10.0-bundle.jar -i <input folder> -o <output folder>`
`java -jar android_contentprovider_generator-1.11.0-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 @@ -243,7 +245,7 @@ You need maven to build this tool.

`mvn package`

This will produce `android_contentprovider_generator-1.10.0-bundle.jar` in the `target` folder.
This will produce `android_contentprovider_generator-1.11.0-bundle.jar` in the `target` folder.


Similar tools
Expand Down
3 changes: 2 additions & 1 deletion etc/sample/_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"databaseVersion": 1,
"enableForeignKeys": true,
"useAnnotations": true,
"useSupportLibrary": true
"useSupportLibrary": true,
"generateBeans": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/*
* This source is part of the
* _____ ___ ____
* __ / / _ \/ _ | / __/___ _______ _
* / // / , _/ __ |/ _/_/ _ \/ __/ _ `/
* \___/_/|_/_/ |_/_/ (_)___/_/ \_, /
* /___/
* repository.
*
* Copyright (C) 2012-2015 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/>.
*/
package org.jraf.androidcontentprovidergenerator.sample.provider.company;

// @formatter:off
import org.jraf.androidcontentprovidergenerator.sample.provider.base.BaseModel;

import java.util.Date;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

/**
* A commercial business.
*/
@SuppressWarnings({"WeakerAccess", "unused", "ConstantConditions"})
public class CompanyBean implements CompanyModel {
private long mId;
private String mName;
private String mAddress;
private long mSerialNumberId;

/**
* Primary key.
*/
@Override
public long getId() {
return mId;
}

/**
* Primary key.
*/
public void setId(long id) {
mId = id;
}

/**
* The commercial name of this company.
* Cannot be {@code null}.
*/
@NonNull
@Override
public String getName() {
return mName;
}

/**
* The commercial name of this company.
* Must not be {@code null}.
*/
public void setName(@NonNull String name) {
if (name == null) throw new IllegalArgumentException("name must not be null");
mName = name;
}

/**
* The full address of this company.
* Can be {@code null}.
*/
@Nullable
@Override
public String getAddress() {
return mAddress;
}

/**
* The full address of this company.
* Can be {@code null}.
*/
public void setAddress(@Nullable String address) {
mAddress = address;
}

/**
* The serial number of this company.
*/
@Override
public long getSerialNumberId() {
return mSerialNumberId;
}

/**
* The serial number of this company.
*/
public void setSerialNumberId(long serialNumberId) {
mSerialNumberId = serialNumberId;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CompanyBean bean = (CompanyBean) o;
return mId == bean.mId;
}

@Override
public int hashCode() {
return (int) (mId ^ (mId >>> 32));
}

/**
* Instantiate a new CompanyBean with specified values.
*/
@NonNull
public static CompanyBean newInstance(long id, @NonNull String name, @Nullable String address, long serialNumberId) {
if (name == null) throw new IllegalArgumentException("name must not be null");
CompanyBean res = new CompanyBean();
res.mId = id;
res.mName = name;
res.mAddress = address;
res.mSerialNumberId = serialNumberId;
return res;
}

/**
* Instantiate a new CompanyBean with all the values copied from the given model.
*/
@NonNull
public static CompanyBean copy(@NonNull CompanyModel from) {
CompanyBean res = new CompanyBean();
res.mId = from.getId();
res.mName = from.getName();
res.mAddress = from.getAddress();
res.mSerialNumberId = from.getSerialNumberId();
return res;
}

public static class Builder {
private CompanyBean mRes = new CompanyBean();

/**
* Primary key.
*/
public Builder id(long id) {
mRes.mId = id;
return this;
}

/**
* The commercial name of this company.
* Must not be {@code null}.
*/
public Builder name(@NonNull String name) {
if (name == null) throw new IllegalArgumentException("name must not be null");
mRes.mName = name;
return this;
}

/**
* The full address of this company.
* Can be {@code null}.
*/
public Builder address(@Nullable String address) {
mRes.mAddress = address;
return this;
}

/**
* The serial number of this company.
*/
public Builder serialNumberId(long serialNumberId) {
mRes.mSerialNumberId = serialNumberId;
return this;
}

/**
* Get a new CompanyBean built with the given values.
*/
public CompanyBean build() {
if (mRes.mName == null) throw new IllegalArgumentException("name must not be null");
return mRes;
}
}

public static Builder newBuilder() {
return new Builder();
}
}
Loading

0 comments on commit 3025cb5

Please sign in to comment.