├── .gitignore ├── CHANGELOG.md ├── COPYING ├── README.md ├── acpg-gradle-plugin ├── build.gradle └── src │ └── main │ ├── groovy │ └── org │ │ └── jraf │ │ └── acpg │ │ └── gradleplugin │ │ ├── AcpgPlugin.groovy │ │ ├── AcpgPluginExtension.groovy │ │ └── GenerateContentProviderTask.groovy │ └── resources │ └── META-INF │ └── gradle-plugins │ └── org.jraf.acpg.gradleplugin.properties ├── acpg-lib ├── build.gradle └── src │ └── main │ ├── java │ └── org │ │ └── jraf │ │ └── acpg │ │ └── lib │ │ ├── Generator.java │ │ ├── GeneratorException.java │ │ ├── config │ │ ├── Config.java │ │ └── ConfigParser.java │ │ └── model │ │ ├── Constraint.java │ │ ├── Entity.java │ │ ├── EnumValue.java │ │ ├── Field.java │ │ ├── ForeignKey.java │ │ ├── Model.java │ │ ├── SortOrder.java │ │ └── parser │ │ ├── JsonConstraint.java │ │ ├── JsonEntity.java │ │ ├── JsonEnumValue.java │ │ ├── JsonEnumValueDeserializer.java │ │ ├── JsonField.java │ │ ├── JsonForeignKey.java │ │ └── ModelParser.java │ └── resources │ ├── log4j2.xml │ └── org │ └── jraf │ └── acpg │ └── lib │ ├── abstractcontentvalues.ftl │ ├── abstractcursor.ftl │ ├── abstractselection.ftl │ ├── basecontentprovider.ftl │ ├── basemodel.ftl │ ├── basesqliteopenhelpercallbacks.ftl │ ├── bean.ftl │ ├── columns.ftl │ ├── contentprovider.ftl │ ├── contentvalues.ftl │ ├── cursor.ftl │ ├── enum.ftl │ ├── manifest.ftl │ ├── model.ftl │ ├── selection.ftl │ └── sqliteopenhelper.ftl ├── build.gradle ├── cli ├── build.gradle └── src │ └── main │ ├── java │ └── org │ │ └── jraf │ │ └── acpg │ │ └── cli │ │ ├── Arguments.java │ │ └── Cli.java │ └── resources │ └── log4j2.xml ├── etc ├── generate-contentprovider.sh ├── generate-schema-graph.sh ├── sample-generated-code │ └── org │ │ └── jraf │ │ └── androidcontentprovidergenerator │ │ └── sample │ │ └── provider │ │ ├── SampleProvider.java │ │ ├── SampleSQLiteOpenHelper.java │ │ ├── base │ │ ├── AbstractContentValues.java │ │ ├── AbstractCursor.java │ │ ├── AbstractSelection.java │ │ ├── BaseContentProvider.java │ │ ├── BaseModel.java │ │ └── BaseSQLiteOpenHelperCallbacks.java │ │ ├── company │ │ ├── CompanyBean.java │ │ ├── CompanyColumns.java │ │ ├── CompanyContentValues.java │ │ ├── CompanyCursor.java │ │ ├── CompanyModel.java │ │ └── CompanySelection.java │ │ ├── manual │ │ ├── ManualBean.java │ │ ├── ManualColumns.java │ │ ├── ManualContentValues.java │ │ ├── ManualCursor.java │ │ ├── ManualModel.java │ │ └── ManualSelection.java │ │ ├── person │ │ ├── Gender.java │ │ ├── PersonBean.java │ │ ├── PersonColumns.java │ │ ├── PersonContentValues.java │ │ ├── PersonCursor.java │ │ ├── PersonModel.java │ │ └── PersonSelection.java │ │ ├── personteam │ │ ├── PersonTeamBean.java │ │ ├── PersonTeamColumns.java │ │ ├── PersonTeamContentValues.java │ │ ├── PersonTeamCursor.java │ │ ├── PersonTeamModel.java │ │ └── PersonTeamSelection.java │ │ ├── product │ │ ├── ProductBean.java │ │ ├── ProductColumns.java │ │ ├── ProductContentValues.java │ │ ├── ProductCursor.java │ │ ├── ProductModel.java │ │ └── ProductSelection.java │ │ ├── serialnumber │ │ ├── SerialNumberBean.java │ │ ├── SerialNumberColumns.java │ │ ├── SerialNumberContentValues.java │ │ ├── SerialNumberCursor.java │ │ ├── SerialNumberModel.java │ │ └── SerialNumberSelection.java │ │ └── team │ │ ├── TeamBean.java │ │ ├── TeamColumns.java │ │ ├── TeamContentValues.java │ │ ├── TeamCursor.java │ │ ├── TeamModel.java │ │ └── TeamSelection.java ├── sample-schema.png └── sample-schema.svg ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.properties ├── sample-app ├── build.gradle ├── etc │ └── acpg │ │ ├── _config.json │ │ ├── company.json │ │ ├── header.txt │ │ ├── manual.json │ │ ├── person.json │ │ ├── person_team.json │ │ ├── product.json │ │ ├── serial_number.json │ │ └── team.json └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── org │ │ └── jraf │ │ └── androidcontentprovidergenerator │ │ └── sample │ │ ├── app │ │ └── SampleActivity.java │ │ └── provider │ │ └── SampleSQLiteOpenHelperCallbacks.java │ └── res │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── layout │ └── main.xml │ └── values │ └── strings.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .idea 3 | .DS_Store 4 | *.iml 5 | .gradle 6 | build 7 | out 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Android ContentProvider Generator Changelog 2 | =========================================== 3 | 4 | v1.13.1 (2017-04-16) 5 | ------ 6 | - `XyzSelection.addRaw()` now returns `this` to allow chaining. 7 | 8 | v1.13.0 (2017-02-20) 9 | ------ 10 | - `XyzSelection.getCursorLoader()` now returns loaders of wrapped cursors. 11 | - New `XyzContentValues.notify(boolean)` method to enable/disable notifications. 12 | - New `debugLogsFieldName` attribute to enable/disable debug logging in the generated code. 13 | 14 | v1.12.0 (2017-02-06) 15 | ------ 16 | This is a somewhat big update in the way the tool is used, and there are also a few syntax differences. 17 | 18 | - New **Gradle plugin**, and this is now the preferred way to generate the code. 19 | - The config `syntaxVersion` for this release is **4**. This means you **must** update your `_config.json` file. 20 | - Syntax updates: 21 | - `projectPackageId` is renamed to `packageName` to avoid confusion and match the term used here: https://developer.android.com/studio/build/application-id.html. 22 | - `sqliteOpenHelperCallbacksClassName` is now optional. If omitted, `BaseSQLiteOpenHelperCallbacks` is used in the generated code. If present, it must reference an existing class in your project (it will not be generated), that extends `BaseSQLiteOpenHelperCallbacks`. 23 | - `sqliteOpenHelperClassName`, `enableForeignKeys`, `useAnnotations`, `useSupportLibrary` and `generateBeans` are now optional and will assume default values if omitted. 24 | - The CLI tool still exists but its name has changed (now `acpg-cli-.jar`). 25 | - Other internal changes that as a user, you needn't care about: 26 | - Use of Gradle instead of Maven. 27 | - Module separation (lib, cli, gradle-plugin). 28 | - Use of Jackson to parse the json files. 29 | - Use of Log4J to output logs. 30 | 31 | v1.11.0 (2016-11-12) 32 | ------ 33 | - Beans generation (if new `generateBeans` boolean parameter in config is true) - fix for issue #43. 34 | 35 | v1.10.0 (2016-10-30) 36 | ------ 37 | - Fix for issue #91. 38 | - Fix for issue #102. 39 | - Fix for issue #762. 40 | - Fix for issue #57. 41 | - Fixed or suppressed lots of warnings from the generated code. 42 | - New `useSupportLibrary` boolean parameter in config, to choose which implementation of `CursorLoader` to use. 43 | - Minor log cleanup. 44 | 45 | v1.9.3 (2015-07-18) 46 | ------ 47 | - Updated content provider template to support ${applicationId} variable that is supported in the 48 | new manifest merger build tool (thanks almilli!). 49 | - Fixed invalid json in sample and readme (thanks mdupierreux!). 50 | - Added methods that take a Context in addition to the ones that take a ContentResolver. 51 | - New `orderByXXX` methods in Selection classes (thanks yargray!). 52 | 53 | v1.9.2 (2015-03-05) 54 | ------ 55 | - Fix for issue #77. 56 | 57 | v1.9.1 (2015-02-21) 58 | ------ 59 | - Fix for issue #73. 60 | 61 | v1.9.0 (2015-02-15) 62 | ------ 63 | - The config `syntaxVersion` for this release is **3**. This means you **must** update your `_config.json` file. 64 | - Generation of new "Model" interfaces (one per entity) 65 | - New `useAnnotations` boolean parameter in config, to generate annotations from the `support-annotations` library (issue #38) 66 | - A few optimizations in the generated code 67 | - Column names are no longer automatically made lower case, to help using the tool with an existing db (issue #52) 68 | - New `contains`, `startsWith`, `endsWitdh` methods on Selection objects (issue #55) 69 | - The `CREATE_TABLE and CREATE_INDEX` constants are now public to make upgrades easier (issue #59) 70 | - The "id" (single column primary key) can now be specified to be an arbitrary column, instead of automatically being generated as "_id" (issue #56) 71 | - Ability to specify a LIMIT and HAVING clause in queries, via a query parameter (issues #62 and #70) 72 | - Better handling of default values (issue #67) 73 | - Ability to call `notify`, `groupBy`, `limit` and `having` on Selection objects. 74 | -------------------------------------------------------------------------------- /acpg-gradle-plugin/build.gradle: -------------------------------------------------------------------------------- 1 | description = 'gradle-plugin (Android ContentProvider Generator Gradle Plugin)' 2 | 3 | apply plugin: 'groovy' 4 | apply plugin: 'maven-publish' 5 | 6 | javadoc.failOnError = false 7 | 8 | task sourcesJar(type: Jar, dependsOn: classes) { 9 | classifier = 'sources' 10 | from sourceSets.main.allSource 11 | } 12 | 13 | task javadocJar(type: Jar, dependsOn: javadoc) { 14 | classifier = 'javadoc' 15 | from javadoc.destinationDir 16 | } 17 | 18 | artifacts { 19 | archives sourcesJar 20 | archives javadocJar 21 | } 22 | 23 | dependencies { 24 | compile gradleApi() 25 | compile localGroovy() 26 | compile project(':acpg-lib') 27 | compile 'com.android.tools.build:gradle:2.2.0' 28 | } 29 | 30 | // Use "./gradlew install" to deploy the artifacts to your local maven repository -------------------------------------------------------------------------------- /acpg-gradle-plugin/src/main/groovy/org/jraf/acpg/gradleplugin/AcpgPlugin.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | 26 | package org.jraf.acpg.gradleplugin 27 | 28 | import com.android.builder.core.DefaultManifestParser 29 | import org.gradle.api.Plugin 30 | import org.gradle.api.Project 31 | import org.gradle.api.ProjectConfigurationException 32 | 33 | class AcpgPlugin implements Plugin { 34 | @Override 35 | void apply(Project project) { 36 | ensurePluginDependencies(project) 37 | 38 | def acpgExtension = project.extensions.create('acpg', AcpgPluginExtension, project) 39 | 40 | project.afterEvaluate { 41 | // Get the packageName from the manifest 42 | def manifestParser = new DefaultManifestParser(project.android.sourceSets.main.manifest.srcFile) 43 | def packageName = manifestParser.getPackage() 44 | 45 | project.android[variants(project)].all { variant -> 46 | File sourceFolder = project.file("${project.buildDir}/generated/source/acpg/${variant.dirName}") 47 | acpgExtension.packageName packageName 48 | def javaGenerationTask = project.tasks.create(name: "acpgGenerate${variant.name.capitalize()}ContentProvider", type: GenerateContentProviderTask) { 49 | entitiesDir acpgExtension.entitiesDir 50 | outputDir sourceFolder 51 | config acpgExtension.config 52 | } 53 | variant.registerJavaGeneratingTask(javaGenerationTask, sourceFolder) 54 | } 55 | } 56 | } 57 | 58 | private static void ensurePluginDependencies(Project project) { 59 | if (!isApplication(project) && !isLibrary(project)) { 60 | throw new ProjectConfigurationException("The 'com.android.application' or 'com.android.library' plugin is required.", null) 61 | } 62 | } 63 | 64 | private static String variants(Project project) { 65 | if (isApplication(project)) { 66 | return 'applicationVariants' 67 | } else if (isLibrary(project)) { 68 | return 'libraryVariants' 69 | } 70 | throw new ProjectConfigurationException("The 'com.android.application' or 'com.android.library' plugin is required.", null) 71 | } 72 | 73 | private static boolean isLibrary(Project project) { 74 | project.plugins.hasPlugin('com.android.library') || project.plugins.hasPlugin('android-library') 75 | } 76 | 77 | private static boolean isApplication(Project project) { 78 | project.plugins.hasPlugin('com.android.application') || project.plugins.hasPlugin('android') 79 | } 80 | } 81 | 82 | -------------------------------------------------------------------------------- /acpg-gradle-plugin/src/main/groovy/org/jraf/acpg/gradleplugin/AcpgPluginExtension.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | 26 | package org.jraf.acpg.gradleplugin 27 | 28 | import org.gradle.api.Project 29 | import org.jraf.acpg.lib.config.Config 30 | 31 | class AcpgPluginExtension { 32 | private final Project project 33 | final Config config = new Config() 34 | 35 | AcpgPluginExtension(Project project) { 36 | this.project = project 37 | config.syntaxVersion = 4 38 | } 39 | 40 | def entitiesDir = project.parent.file('etc/acpg') 41 | 42 | def syntaxVersion(int syntaxVersion) { 43 | config.syntaxVersion = syntaxVersion 44 | } 45 | 46 | def packageName(String packageName) { 47 | config.packageName = packageName 48 | } 49 | 50 | def authority(String authority) { 51 | config.authority = authority 52 | } 53 | 54 | def providerJavaPackage(String providerJavaPackage) { 55 | config.providerJavaPackage = providerJavaPackage 56 | } 57 | 58 | def providerClassName(String providerClassName) { 59 | config.providerClassName = providerClassName 60 | } 61 | 62 | def sqliteOpenHelperClassName(String sqliteOpenHelperClassName) { 63 | config.sqliteOpenHelperClassName = sqliteOpenHelperClassName 64 | } 65 | 66 | def sqliteOpenHelperCallbacksClassName(String sqliteOpenHelperCallbacksClassName) { 67 | config.sqliteOpenHelperCallbacksClassName = sqliteOpenHelperCallbacksClassName 68 | } 69 | 70 | def databaseFileName(String databaseFileName) { 71 | config.databaseFileName = databaseFileName 72 | } 73 | 74 | def databaseVersion(int databaseVersion) { 75 | config.databaseVersion = databaseVersion 76 | } 77 | 78 | def enableForeignKeys(boolean enableForeignKeys) { 79 | config.enableForeignKeys = enableForeignKeys 80 | } 81 | 82 | def useAnnotations(boolean useAnnotations) { 83 | config.useAnnotations = useAnnotations 84 | } 85 | 86 | def useSupportLibrary(boolean useSupportLibrary) { 87 | config.useSupportLibrary = useSupportLibrary 88 | } 89 | 90 | def generateBeans(boolean generateBeans) { 91 | config.generateBeans = generateBeans 92 | } 93 | 94 | def debugLogsFieldName(String debugLogsFieldName) { 95 | config.debugLogsFieldName = debugLogsFieldName 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /acpg-gradle-plugin/src/main/groovy/org/jraf/acpg/gradleplugin/GenerateContentProviderTask.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | 26 | package org.jraf.acpg.gradleplugin 27 | 28 | import org.gradle.api.DefaultTask 29 | import org.gradle.api.GradleException 30 | import org.gradle.api.tasks.Input 31 | import org.gradle.api.tasks.InputDirectory 32 | import org.gradle.api.tasks.OutputDirectory 33 | import org.gradle.api.tasks.TaskAction 34 | import org.jraf.acpg.lib.Generator 35 | import org.jraf.acpg.lib.GeneratorException 36 | import org.jraf.acpg.lib.config.Config 37 | 38 | class GenerateContentProviderTask extends DefaultTask { 39 | @OutputDirectory 40 | File outputDir 41 | 42 | @InputDirectory 43 | File entitiesDir 44 | 45 | @Input 46 | Config config 47 | 48 | @TaskAction 49 | void generate() { 50 | try { 51 | new Generator(config, entitiesDir, outputDir).generate() 52 | } catch (GeneratorException e) { 53 | throw new GradleException("Problem while generating the ContentProvider: $e.message", e) 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /acpg-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.jraf.acpg.gradleplugin.properties: -------------------------------------------------------------------------------- 1 | implementation-class=org.jraf.acpg.gradleplugin.AcpgPlugin -------------------------------------------------------------------------------- /acpg-lib/build.gradle: -------------------------------------------------------------------------------- 1 | description = 'lib (Android ContentProvider Generator Library)' 2 | 3 | apply plugin: 'java' 4 | apply plugin: 'maven-publish' 5 | 6 | sourceCompatibility = 1.7 7 | targetCompatibility = 1.7 8 | 9 | javadoc.failOnError = false 10 | 11 | task sourcesJar(type: Jar, dependsOn: classes) { 12 | classifier = 'sources' 13 | from sourceSets.main.allSource 14 | } 15 | 16 | task javadocJar(type: Jar, dependsOn: javadoc) { 17 | classifier = 'javadoc' 18 | from javadoc.destinationDir 19 | } 20 | 21 | artifacts { 22 | archives sourcesJar 23 | archives javadocJar 24 | } 25 | 26 | dependencies { 27 | compile 'com.fasterxml.jackson.core:jackson-databind:2.8.6' 28 | compile 'commons-io:commons-io:2.4' 29 | compile 'commons-lang:commons-lang:2.6' 30 | compile 'org.freemarker:freemarker:2.3.20' 31 | compile 'org.apache.logging.log4j:log4j-api:2.8' 32 | compile 'org.apache.logging.log4j:log4j-core:2.8' 33 | } 34 | 35 | // Use "./gradlew install" to deploy the artifacts to your local maven repository -------------------------------------------------------------------------------- /acpg-lib/src/main/java/org/jraf/acpg/lib/GeneratorException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.acpg.lib; 26 | 27 | public class GeneratorException extends Exception { 28 | public GeneratorException(String message) { 29 | super(message); 30 | } 31 | 32 | public GeneratorException(String message, Throwable cause) { 33 | super(message, cause); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /acpg-lib/src/main/java/org/jraf/acpg/lib/config/Config.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.acpg.lib.config; 26 | 27 | import java.io.Serializable; 28 | 29 | public class Config implements Serializable, Cloneable { 30 | public Integer syntaxVersion; 31 | public String packageName; 32 | public String authority; 33 | public String providerJavaPackage; 34 | public String providerClassName; 35 | public String sqliteOpenHelperClassName; 36 | public String sqliteOpenHelperCallbacksClassName; 37 | public String databaseFileName; 38 | public Integer databaseVersion; 39 | public Boolean enableForeignKeys; 40 | public Boolean useAnnotations; 41 | public Boolean useSupportLibrary; 42 | public Boolean generateBeans; 43 | public String debugLogsFieldName; 44 | 45 | @Override 46 | public Object clone() throws CloneNotSupportedException { 47 | return super.clone(); 48 | } 49 | 50 | @Override 51 | public boolean equals(Object o) { 52 | if (this == o) return true; 53 | if (o == null || getClass() != o.getClass()) return false; 54 | 55 | Config config = (Config) o; 56 | 57 | if (syntaxVersion != null ? !syntaxVersion.equals(config.syntaxVersion) : config.syntaxVersion != null) return false; 58 | if (packageName != null ? !packageName.equals(config.packageName) : config.packageName != null) return false; 59 | if (authority != null ? !authority.equals(config.authority) : config.authority != null) return false; 60 | if (providerJavaPackage != null ? !providerJavaPackage.equals(config.providerJavaPackage) : config.providerJavaPackage != null) return false; 61 | if (providerClassName != null ? !providerClassName.equals(config.providerClassName) : config.providerClassName != null) return false; 62 | if (sqliteOpenHelperClassName != null ? !sqliteOpenHelperClassName.equals(config.sqliteOpenHelperClassName) : config.sqliteOpenHelperClassName != null) 63 | return false; 64 | if (sqliteOpenHelperCallbacksClassName != null ? !sqliteOpenHelperCallbacksClassName.equals(config.sqliteOpenHelperCallbacksClassName) : 65 | config.sqliteOpenHelperCallbacksClassName != null) return false; 66 | if (databaseFileName != null ? !databaseFileName.equals(config.databaseFileName) : config.databaseFileName != null) return false; 67 | if (databaseVersion != null ? !databaseVersion.equals(config.databaseVersion) : config.databaseVersion != null) return false; 68 | if (enableForeignKeys != null ? !enableForeignKeys.equals(config.enableForeignKeys) : config.enableForeignKeys != null) return false; 69 | if (useAnnotations != null ? !useAnnotations.equals(config.useAnnotations) : config.useAnnotations != null) return false; 70 | if (useSupportLibrary != null ? !useSupportLibrary.equals(config.useSupportLibrary) : config.useSupportLibrary != null) return false; 71 | if (generateBeans != null ? !generateBeans.equals(config.generateBeans) : config.generateBeans != null) return false; 72 | return debugLogsFieldName != null ? debugLogsFieldName.equals(config.debugLogsFieldName) : config.debugLogsFieldName == null; 73 | } 74 | 75 | @Override 76 | public int hashCode() { 77 | int result = syntaxVersion != null ? syntaxVersion.hashCode() : 0; 78 | result = 31 * result + (packageName != null ? packageName.hashCode() : 0); 79 | result = 31 * result + (authority != null ? authority.hashCode() : 0); 80 | result = 31 * result + (providerJavaPackage != null ? providerJavaPackage.hashCode() : 0); 81 | result = 31 * result + (providerClassName != null ? providerClassName.hashCode() : 0); 82 | result = 31 * result + (sqliteOpenHelperClassName != null ? sqliteOpenHelperClassName.hashCode() : 0); 83 | result = 31 * result + (sqliteOpenHelperCallbacksClassName != null ? sqliteOpenHelperCallbacksClassName.hashCode() : 0); 84 | result = 31 * result + (databaseFileName != null ? databaseFileName.hashCode() : 0); 85 | result = 31 * result + (databaseVersion != null ? databaseVersion.hashCode() : 0); 86 | result = 31 * result + (enableForeignKeys != null ? enableForeignKeys.hashCode() : 0); 87 | result = 31 * result + (useAnnotations != null ? useAnnotations.hashCode() : 0); 88 | result = 31 * result + (useSupportLibrary != null ? useSupportLibrary.hashCode() : 0); 89 | result = 31 * result + (generateBeans != null ? generateBeans.hashCode() : 0); 90 | result = 31 * result + (debugLogsFieldName != null ? debugLogsFieldName.hashCode() : 0); 91 | return result; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /acpg-lib/src/main/java/org/jraf/acpg/lib/config/ConfigParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.acpg.lib.config; 26 | 27 | import java.io.File; 28 | 29 | import org.apache.logging.log4j.LogManager; 30 | import org.apache.logging.log4j.Logger; 31 | 32 | import com.fasterxml.jackson.databind.ObjectMapper; 33 | 34 | import org.jraf.acpg.lib.GeneratorException; 35 | 36 | public class ConfigParser { 37 | private static final Logger LOG = LogManager.getLogger(ConfigParser.class); 38 | private static final int SYNTAX_VERSION = 4; 39 | 40 | public Config parseConfig(File configFile) throws GeneratorException { 41 | if (!configFile.exists()) throw new GeneratorException("Could not find a config file at this location: '" + configFile.getAbsolutePath() + "'."); 42 | ObjectMapper objectMapper = new ObjectMapper(); 43 | Config config; 44 | try { 45 | config = objectMapper.readValue(configFile, Config.class); 46 | } catch (Exception e) { 47 | throw new GeneratorException("Error while parsing _config.json file", e); 48 | } 49 | return config; 50 | } 51 | 52 | public void validateConfig(Config config) throws GeneratorException { 53 | // Ensure the input files are compatible with this version of the tool 54 | if (config.syntaxVersion == null || config.syntaxVersion != SYNTAX_VERSION) { 55 | throw new GeneratorException( 56 | "Invalid 'syntaxVersion' value in configuration: found '" + config.syntaxVersion + "' but expected '" + SYNTAX_VERSION + "'."); 57 | } 58 | 59 | // Ensure mandatory fields are present 60 | ensureNotNull(config.packageName, "packageName"); 61 | ensureNotNull(config.providerJavaPackage, "providerJavaPackage"); 62 | ensureNotNull(config.providerClassName, "providerClassName"); 63 | ensureNotNull(config.databaseFileName, "databaseFileName"); 64 | ensureNotNull(config.databaseVersion, "databaseVersion"); 65 | 66 | // Default values 67 | if (config.authority == null) { 68 | String defaultValue = config.packageName; 69 | LOG.info("'authority' not set in configuration: assuming '" + defaultValue + "'."); 70 | config.authority = defaultValue; 71 | } 72 | if (config.sqliteOpenHelperClassName == null) { 73 | String defaultValue = config.providerClassName + "SQLiteOpenHelper"; 74 | LOG.info("'sqliteOpenHelperClassName' not set in configuration: assuming '" + defaultValue + "'."); 75 | config.sqliteOpenHelperClassName = defaultValue; 76 | } 77 | if (config.sqliteOpenHelperCallbacksClassName == null) { 78 | LOG.info("'sqliteOpenHelperCallbacksClassName' not set in configuration: will use default BaseSQLiteOpenHelperCallbacks."); 79 | } 80 | if (config.enableForeignKeys == null) { 81 | LOG.info("'enableForeignKeys' not set in configuration: assuming false."); 82 | config.enableForeignKeys = true; 83 | } 84 | if (config.useAnnotations == null) { 85 | LOG.info("'useAnnotations' not set in configuration: assuming false."); 86 | config.useAnnotations = false; 87 | } 88 | if (config.useSupportLibrary == null) { 89 | LOG.info("'useSupportLibrary' not set in configuration: assuming false."); 90 | config.useSupportLibrary = false; 91 | } 92 | if (config.generateBeans == null) { 93 | LOG.info("'generateBeans' not set in configuration: assuming true."); 94 | config.generateBeans = true; 95 | } 96 | if (config.debugLogsFieldName == null) { 97 | LOG.info("'debugLogsFieldName' not set in configuration: assuming 'DEBUG'."); 98 | config.debugLogsFieldName = "DEBUG"; 99 | } 100 | } 101 | 102 | private void ensureNotNull(Object value, String fieldName) throws GeneratorException { 103 | if (value == null) throw new GeneratorException("Mandatory property '" + fieldName + "' not set in configuration."); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /acpg-lib/src/main/java/org/jraf/acpg/lib/model/Constraint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.acpg.lib.model; 26 | 27 | public class Constraint { 28 | private final String mName; 29 | private final String mDefinition; 30 | 31 | public Constraint(String name, String definition) { 32 | mName = name; 33 | mDefinition = definition; 34 | } 35 | 36 | public String getName() { 37 | return mName; 38 | } 39 | 40 | public String getDefinition() { 41 | return mDefinition; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "Constraint [mName=" + mName + ", mDefinition=" + mDefinition + "]"; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /acpg-lib/src/main/java/org/jraf/acpg/lib/model/EnumValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.acpg.lib.model; 26 | 27 | public class EnumValue { 28 | private final String mName; 29 | private final String mDocumentation; 30 | 31 | public EnumValue(String name, String documentation) { 32 | mName = name; 33 | mDocumentation = documentation; 34 | } 35 | 36 | public String getName() { 37 | return mName; 38 | } 39 | 40 | public String getDocumentation() { 41 | return mDocumentation; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /acpg-lib/src/main/java/org/jraf/acpg/lib/model/ForeignKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.acpg.lib.model; 26 | 27 | public class ForeignKey { 28 | private final String mEntityName; 29 | private final Field.OnDeleteAction mOnDeleteAction; 30 | 31 | public ForeignKey(String entityName, Field.OnDeleteAction onDeleteAction) { 32 | mEntityName = entityName; 33 | mOnDeleteAction = onDeleteAction; 34 | } 35 | 36 | public String getEntityName() { 37 | return mEntityName; 38 | } 39 | 40 | public Entity getEntity() { 41 | return Entity.getByName(mEntityName); 42 | } 43 | 44 | public Field getField() { 45 | return getEntity().getFieldByName("_id"); 46 | } 47 | 48 | public Field.OnDeleteAction getOnDeleteAction() { 49 | return mOnDeleteAction; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "ForeignKey [mEntityName=" + mEntityName + ", mOnDeleteAction=" + mOnDeleteAction + "]"; 55 | } 56 | } -------------------------------------------------------------------------------- /acpg-lib/src/main/java/org/jraf/acpg/lib/model/Model.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.acpg.lib.model; 26 | 27 | import java.util.ArrayList; 28 | import java.util.Collections; 29 | import java.util.List; 30 | 31 | import org.apache.logging.log4j.LogManager; 32 | import org.apache.logging.log4j.Logger; 33 | 34 | import org.jraf.acpg.lib.GeneratorException; 35 | 36 | public class Model { 37 | private static final Logger LOG = LogManager.getLogger(Model.class); 38 | 39 | private final List mEntities = new ArrayList(); 40 | private String mHeader; 41 | 42 | public void addEntity(Entity entity) { 43 | mEntities.add(entity); 44 | } 45 | 46 | public List getEntities() { 47 | return Collections.unmodifiableList(mEntities); 48 | } 49 | 50 | public void setHeader(String header) { 51 | mHeader = header; 52 | } 53 | 54 | public String getHeader() { 55 | return mHeader; 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return mEntities.toString(); 61 | } 62 | 63 | public void flagAmbiguousFields() throws GeneratorException { 64 | for (Entity entity : mEntities) { 65 | entity.flagAmbiguousFields(); 66 | } 67 | 68 | for (Entity entity : mEntities) { 69 | for (Field field : entity.getFields()) { 70 | if (field.getIsAmbiguous()) { 71 | LOG.info("Note: in the table '" + entity.getNameLowerCase() + "', the column '" + field.getName() + "' will be named '" 72 | + field.getPrefixedName() + "' to avoid ambiguities when joining."); 73 | } 74 | } 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /acpg-lib/src/main/java/org/jraf/acpg/lib/model/SortOrder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.acpg.lib.model; 26 | 27 | public class SortOrder { 28 | private final Field mField; 29 | private final boolean mDescending; 30 | 31 | public SortOrder(Field field, boolean descending) { 32 | mField = field; 33 | mDescending = descending; 34 | } 35 | 36 | public Field getField() { 37 | return mField; 38 | } 39 | 40 | public boolean isDescending() { 41 | return mDescending; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /acpg-lib/src/main/java/org/jraf/acpg/lib/model/parser/JsonConstraint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | 26 | package org.jraf.acpg.lib.model.parser; 27 | 28 | public class JsonConstraint { 29 | public String name; 30 | public String definition; 31 | } 32 | -------------------------------------------------------------------------------- /acpg-lib/src/main/java/org/jraf/acpg/lib/model/parser/JsonEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | 26 | package org.jraf.acpg.lib.model.parser; 27 | 28 | import java.util.List; 29 | 30 | public class JsonEntity { 31 | public String documentation; 32 | public List fields; 33 | public List constraints; 34 | public String defaultOrder; 35 | public List idField; 36 | } 37 | -------------------------------------------------------------------------------- /acpg-lib/src/main/java/org/jraf/acpg/lib/model/parser/JsonEnumValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | 26 | package org.jraf.acpg.lib.model.parser; 27 | 28 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 29 | 30 | @JsonDeserialize(using = JsonEnumValueDeserializer.class) 31 | public class JsonEnumValue { 32 | public String name; 33 | public String documentation; 34 | } 35 | -------------------------------------------------------------------------------- /acpg-lib/src/main/java/org/jraf/acpg/lib/model/parser/JsonEnumValueDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | 26 | package org.jraf.acpg.lib.model.parser; 27 | 28 | import java.io.IOException; 29 | import java.util.Map; 30 | 31 | import com.fasterxml.jackson.core.JsonParser; 32 | import com.fasterxml.jackson.databind.DeserializationContext; 33 | import com.fasterxml.jackson.databind.JsonNode; 34 | import com.fasterxml.jackson.databind.deser.std.StdDeserializer; 35 | 36 | public class JsonEnumValueDeserializer extends StdDeserializer { 37 | public JsonEnumValueDeserializer() { 38 | this(null); 39 | } 40 | 41 | public JsonEnumValueDeserializer(Class vc) { 42 | super(vc); 43 | } 44 | 45 | @Override 46 | public JsonEnumValue deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException { 47 | JsonNode node = jsonParser.getCodec().readTree(jsonParser); 48 | JsonEnumValue res = new JsonEnumValue(); 49 | if (node.isObject()) { 50 | Map.Entry entry = node.fields().next(); 51 | res.name = entry.getKey(); 52 | res.documentation = entry.getValue().asText(); 53 | } else { 54 | res.name = node.asText(); 55 | } 56 | return res; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /acpg-lib/src/main/java/org/jraf/acpg/lib/model/parser/JsonField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | 26 | package org.jraf.acpg.lib.model.parser; 27 | 28 | import java.util.List; 29 | 30 | public class JsonField { 31 | public String documentation; 32 | public String name; 33 | public String type; 34 | public Boolean nullable; 35 | public Boolean index; 36 | public JsonForeignKey foreignKey; 37 | public String defaultValue; 38 | public String enumName; 39 | public List enumValues; 40 | } 41 | -------------------------------------------------------------------------------- /acpg-lib/src/main/java/org/jraf/acpg/lib/model/parser/JsonForeignKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | 26 | package org.jraf.acpg.lib.model.parser; 27 | 28 | public class JsonForeignKey { 29 | public String table; 30 | public String onDelete; 31 | } 32 | -------------------------------------------------------------------------------- /acpg-lib/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /acpg-lib/src/main/resources/org/jraf/acpg/lib/abstractcontentvalues.ftl: -------------------------------------------------------------------------------- 1 | <#if header??> 2 | ${header} 3 | 4 | package ${config.providerJavaPackage}.base; 5 | 6 | // @formatter:off 7 | import android.content.Context; 8 | import android.content.ContentResolver; 9 | import android.content.ContentValues; 10 | import android.net.Uri; 11 | 12 | @SuppressWarnings("unused") 13 | public abstract class AbstractContentValues> { 14 | protected final ContentValues mContentValues = new ContentValues(); 15 | private Boolean mNotify; 16 | 17 | /** 18 | * Returns the {@code uri} argument to pass to the {@code ContentResolver} methods. 19 | */ 20 | protected abstract Uri baseUri(); 21 | 22 | /** 23 | * Returns the {@code uri} argument to pass to the {@code ContentResolver} methods. 24 | */ 25 | public Uri uri() { 26 | Uri uri = baseUri(); 27 | if (mNotify != null) uri = BaseContentProvider.notify(uri, mNotify); 28 | return uri; 29 | } 30 | 31 | @SuppressWarnings("unchecked") 32 | public T notify(boolean notify) { 33 | mNotify = notify; 34 | return (T) this; 35 | } 36 | 37 | /** 38 | * Returns the {@code ContentValues} wrapped by this object. 39 | */ 40 | public ContentValues values() { 41 | return mContentValues; 42 | } 43 | 44 | /** 45 | * Inserts a row into a table using the values stored by this object. 46 | * 47 | * @param contentResolver The content resolver to use. 48 | */ 49 | public Uri insert(ContentResolver contentResolver) { 50 | return contentResolver.insert(uri(), values()); 51 | } 52 | 53 | /** 54 | * Inserts a row into a table using the values stored by this object. 55 | * 56 | * @param context The context to use. 57 | */ 58 | public Uri insert(Context context) { 59 | return context.getContentResolver().insert(uri(), values()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /acpg-lib/src/main/resources/org/jraf/acpg/lib/abstractcursor.ftl: -------------------------------------------------------------------------------- 1 | <#if header??> 2 | ${header} 3 | 4 | package ${config.providerJavaPackage}.base; 5 | 6 | // @formatter:off 7 | import java.util.Date; 8 | import java.util.HashMap; 9 | 10 | import android.database.Cursor; 11 | import android.database.CursorWrapper; 12 | import android.provider.BaseColumns; 13 | 14 | @SuppressWarnings({"WeakerAccess", "unused"}) 15 | public abstract class AbstractCursor extends CursorWrapper { 16 | private final HashMap mColumnIndexes; 17 | 18 | public AbstractCursor(Cursor cursor) { 19 | super(cursor); 20 | mColumnIndexes = new HashMap<>(cursor.getColumnCount() * 4 / 3, .75f); 21 | } 22 | 23 | public abstract long getId(); 24 | 25 | protected int getCachedColumnIndexOrThrow(String colName) { 26 | Integer index = mColumnIndexes.get(colName); 27 | if (index == null) { 28 | index = getColumnIndexOrThrow(colName); 29 | mColumnIndexes.put(colName, index); 30 | } 31 | return index; 32 | } 33 | 34 | public String getStringOrNull(String colName) { 35 | int index = getCachedColumnIndexOrThrow(colName); 36 | if (isNull(index)) return null; 37 | return getString(index); 38 | } 39 | 40 | public Integer getIntegerOrNull(String colName) { 41 | int index = getCachedColumnIndexOrThrow(colName); 42 | if (isNull(index)) return null; 43 | return getInt(index); 44 | } 45 | 46 | public Long getLongOrNull(String colName) { 47 | int index = getCachedColumnIndexOrThrow(colName); 48 | if (isNull(index)) return null; 49 | return getLong(index); 50 | } 51 | 52 | public Float getFloatOrNull(String colName) { 53 | int index = getCachedColumnIndexOrThrow(colName); 54 | if (isNull(index)) return null; 55 | return getFloat(index); 56 | } 57 | 58 | public Double getDoubleOrNull(String colName) { 59 | int index = getCachedColumnIndexOrThrow(colName); 60 | if (isNull(index)) return null; 61 | return getDouble(index); 62 | } 63 | 64 | public Boolean getBooleanOrNull(String colName) { 65 | int index = getCachedColumnIndexOrThrow(colName); 66 | if (isNull(index)) return null; 67 | return getInt(index) != 0; 68 | } 69 | 70 | public Date getDateOrNull(String colName) { 71 | int index = getCachedColumnIndexOrThrow(colName); 72 | if (isNull(index)) return null; 73 | return new Date(getLong(index)); 74 | } 75 | 76 | public byte[] getBlobOrNull(String colName) { 77 | int index = getCachedColumnIndexOrThrow(colName); 78 | if (isNull(index)) return null; 79 | return getBlob(index); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /acpg-lib/src/main/resources/org/jraf/acpg/lib/basemodel.ftl: -------------------------------------------------------------------------------- 1 | <#if header??> 2 | ${header} 3 | 4 | package ${config.providerJavaPackage}.base; 5 | 6 | // @formatter:off 7 | public interface BaseModel { 8 | } 9 | -------------------------------------------------------------------------------- /acpg-lib/src/main/resources/org/jraf/acpg/lib/basesqliteopenhelpercallbacks.ftl: -------------------------------------------------------------------------------- 1 | <#if header??> 2 | ${header} 3 | 4 | package ${config.providerJavaPackage}.base; 5 | 6 | // @formatter:off 7 | import android.content.Context; 8 | import android.database.sqlite.SQLiteDatabase; 9 | 10 | import android.util.Log; 11 | 12 | import ${config.packageName}.BuildConfig; 13 | 14 | /** 15 | * Override this class to implement your custom database opening, creation or upgrade. 16 | */ 17 | public class BaseSQLiteOpenHelperCallbacks { 18 | private static final String TAG = BaseSQLiteOpenHelperCallbacks.class.getSimpleName(); 19 | 20 | /** 21 | * Called when the database has been opened. 22 | * @see android.database.sqlite.SQLiteOpenHelper#onOpen(SQLiteDatabase) onOpen 23 | */ 24 | public void onOpen(Context context, SQLiteDatabase db) { 25 | if (BuildConfig.${config.debugLogsFieldName}) Log.d(TAG, "onOpen"); 26 | } 27 | 28 | /** 29 | * Called before the database tables are created. 30 | * @see android.database.sqlite.SQLiteOpenHelper#onCreate(SQLiteDatabase) onCreate 31 | */ 32 | public void onPreCreate(Context context, SQLiteDatabase db) { 33 | if (BuildConfig.${config.debugLogsFieldName}) Log.d(TAG, "onPreCreate"); 34 | } 35 | 36 | /** 37 | * Called after the database tables have been created. 38 | * @see android.database.sqlite.SQLiteOpenHelper#onCreate(SQLiteDatabase) onCreate 39 | */ 40 | public void onPostCreate(Context context, SQLiteDatabase db) { 41 | if (BuildConfig.${config.debugLogsFieldName}) Log.d(TAG, "onPostCreate"); 42 | } 43 | 44 | /** 45 | * Called when the database needs to be upgraded. 46 | * @see android.database.sqlite.SQLiteOpenHelper#onUpgrade(Context, SQLiteDatabase, int, int) onUpgrade 47 | */ 48 | public void onUpgrade(final Context context, final SQLiteDatabase db, final int oldVersion, final int newVersion) { 49 | if (BuildConfig.${config.debugLogsFieldName}) Log.d(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /acpg-lib/src/main/resources/org/jraf/acpg/lib/columns.ftl: -------------------------------------------------------------------------------- 1 | <#if header??> 2 | ${header} 3 | 4 | package ${config.providerJavaPackage}.${entity.packageName}; 5 | 6 | // @formatter:off 7 | import android.net.Uri; 8 | import android.provider.BaseColumns; 9 | 10 | import ${config.providerJavaPackage}.${config.providerClassName}; 11 | import ${config.providerJavaPackage}.base.AbstractSelection; 12 | <#list model.entities as entity> 13 | import ${config.providerJavaPackage}.${entity.packageName}.${entity.nameCamelCase}Columns; 14 | 15 | 16 | /** 17 | <#if entity.documentation??> 18 | * ${entity.documentation} 19 | <#else> 20 | * Columns for the {@code ${entity.nameLowerCase}} table. 21 | 22 | */ 23 | @SuppressWarnings("unused") 24 | public class ${entity.nameCamelCase}Columns implements BaseColumns { 25 | public static final String TABLE_NAME = "${entity.nameLowerCase}"; 26 | public static final Uri CONTENT_URI = Uri.parse(${config.providerClassName}.CONTENT_URI_BASE + "/" + TABLE_NAME); 27 | 28 | <#list entity.fields as field> 29 | <#if field.documentation??> 30 | /** 31 | * ${field.documentation} 32 | */ 33 | 34 | <#if field.isId> 35 | <#if field.nameLowerCase == "_id"> 36 | public static final String _ID = BaseColumns._ID; 37 | <#else> 38 | public static final String _ID = "${field.nameOrPrefixed}"; 39 | 40 | public static final String ${field.nameUpperCase} = "${field.nameOrPrefixed}"; 41 | 42 | <#else> 43 | public static final String ${field.nameUpperCase} = "${field.nameOrPrefixed}"; 44 | 45 | 46 | 47 | 48 | public static final String DEFAULT_ORDER = <#if !entity.sortOrders?has_content>null<#else><#list entity.sortOrders as sortOrder>TABLE_NAME + "." + ${sortOrder.field.nameUpperCase}<#if sortOrder.isDescending()> + AbstractSelection.DESC<#if sortOrder_has_next> + "," 49 | + ; 50 | 51 | public static final String[] ALL_COLUMNS = new String[] { 52 | <#list entity.fields as field> 53 | <#if field.isId> 54 | _ID<#if field_has_next>, 55 | <#else> 56 | ${field.nameUpperCase}<#if field_has_next>, 57 | 58 | 59 | }; 60 | 61 | public static boolean hasColumns(String[] projection) { 62 | if (projection == null) return true; 63 | for (String c : projection) { 64 | <#list entity.fields as field> 65 | <#if field.nameLowerCase != "_id"> 66 | if (c.equals(${field.nameUpperCase}) || c.contains("." + ${field.nameUpperCase})) return true; 67 | 68 | 69 | } 70 | return false; 71 | } 72 | 73 | <#list entity.fields as field> 74 | <#if field.foreignKey??> 75 | public static final String PREFIX_${field.foreignKey.entity.nameUpperCase} = TABLE_NAME + "__" + ${field.foreignKey.entity.nameCamelCase}Columns.TABLE_NAME; 76 | 77 | 78 | } 79 | -------------------------------------------------------------------------------- /acpg-lib/src/main/resources/org/jraf/acpg/lib/contentvalues.ftl: -------------------------------------------------------------------------------- 1 | <#if header??> 2 | ${header} 3 | 4 | package ${config.providerJavaPackage}.${entity.packageName}; 5 | 6 | // @formatter:off 7 | import java.util.Date; 8 | 9 | import android.content.Context; 10 | import android.content.ContentResolver; 11 | import android.net.Uri; 12 | <#if config.useAnnotations> 13 | import android.support.annotation.NonNull; 14 | import android.support.annotation.Nullable; 15 | 16 | 17 | import ${config.providerJavaPackage}.base.AbstractContentValues; 18 | 19 | /** 20 | * Content values wrapper for the {@code ${entity.nameLowerCase}} table. 21 | */ 22 | @SuppressWarnings({"ConstantConditions", "unused"}) 23 | public class ${entity.nameCamelCase}ContentValues extends AbstractContentValues<${entity.nameCamelCase}ContentValues> { 24 | @Override 25 | protected Uri baseUri() { 26 | return ${entity.nameCamelCase}Columns.CONTENT_URI; 27 | } 28 | 29 | /** 30 | * Update row(s) using the values stored by this object and the given selection. 31 | * 32 | * @param contentResolver The content resolver to use. 33 | * @param where The selection to use (can be {@code null}). 34 | */ 35 | public int update(ContentResolver contentResolver, <#if config.useAnnotations>@Nullable ${entity.nameCamelCase}Selection where) { 36 | return contentResolver.update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args()); 37 | } 38 | 39 | /** 40 | * Update row(s) using the values stored by this object and the given selection. 41 | * 42 | * @param context The context to use. 43 | * @param where The selection to use (can be {@code null}). 44 | */ 45 | public int update(Context context, <#if config.useAnnotations>@Nullable ${entity.nameCamelCase}Selection where) { 46 | return context.getContentResolver().update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args()); 47 | } 48 | <#list entity.fields as field> 49 | <#if field.nameLowerCase != "_id"> 50 | 51 | <#if field.documentation??> 52 | /** 53 | * ${field.documentation} 54 | */ 55 | 56 | <#if config.useAnnotations && !field.isNullable && !field.type.hasNotNullableJavaType()> 57 | public ${entity.nameCamelCase}ContentValues put${field.nameCamelCase}(@NonNull ${field.javaTypeSimpleName} value) { 58 | <#elseif config.useAnnotations && field.isNullable> 59 | public ${entity.nameCamelCase}ContentValues put${field.nameCamelCase}(@Nullable ${field.javaTypeSimpleName} value) { 60 | <#else> 61 | public ${entity.nameCamelCase}ContentValues put${field.nameCamelCase}(${field.javaTypeSimpleName} value) { 62 | 63 | <#if !field.isNullable && !field.type.hasNotNullableJavaType()> 64 | if (value == null) throw new IllegalArgumentException("${field.nameCamelCaseLowerCase} must not be null"); 65 | 66 | <#switch field.type.name()> 67 | <#case "DATE"> 68 | mContentValues.put(${entity.nameCamelCase}Columns.${field.nameUpperCase}, <#if field.isNullable>value == null ? null : value.getTime()); 69 | <#break> 70 | <#case "ENUM"> 71 | mContentValues.put(${entity.nameCamelCase}Columns.${field.nameUpperCase}, <#if field.isNullable>value == null ? null : value.ordinal()); 72 | <#break> 73 | <#default> 74 | mContentValues.put(${entity.nameCamelCase}Columns.${field.nameUpperCase}, value); 75 | 76 | return this; 77 | } 78 | 79 | <#if field.isNullable> 80 | public ${entity.nameCamelCase}ContentValues put${field.nameCamelCase}Null() { 81 | mContentValues.putNull(${entity.nameCamelCase}Columns.${field.nameUpperCase}); 82 | return this; 83 | } 84 | 85 | <#switch field.type.name()> 86 | <#case "DATE"> 87 | 88 | public ${entity.nameCamelCase}ContentValues put${field.nameCamelCase}(<#if field.isNullable><#if config.useAnnotations>@Nullable Long<#else>long value) { 89 | mContentValues.put(${entity.nameCamelCase}Columns.${field.nameUpperCase}, value); 90 | return this; 91 | } 92 | <#break> 93 | 94 | 95 | 96 | } 97 | -------------------------------------------------------------------------------- /acpg-lib/src/main/resources/org/jraf/acpg/lib/cursor.ftl: -------------------------------------------------------------------------------- 1 | <#if header??> 2 | ${header} 3 | 4 | package ${config.providerJavaPackage}.${entity.packageName}; 5 | 6 | // @formatter:off 7 | import java.util.Date; 8 | 9 | import android.database.Cursor; 10 | <#if config.useAnnotations> 11 | import android.support.annotation.NonNull; 12 | import android.support.annotation.Nullable; 13 | 14 | 15 | import ${config.providerJavaPackage}.base.AbstractCursor; 16 | <#list entity.joinedEntities as joinedEntity> 17 | import ${config.providerJavaPackage}.${joinedEntity.packageName}.*; 18 | 19 | 20 | /** 21 | * Cursor wrapper for the {@code ${entity.nameLowerCase}} table. 22 | */ 23 | @SuppressWarnings({"WeakerAccess", "unused", "UnnecessaryLocalVariable"}) 24 | public class ${entity.nameCamelCase}Cursor extends AbstractCursor implements ${entity.nameCamelCase}Model { 25 | public ${entity.nameCamelCase}Cursor(Cursor cursor) { 26 | super(cursor); 27 | } 28 | <#list entity.getFieldsIncludingJoins() as field> 29 | <#if field.isId && field.nameLowerCase != '_id'> 30 | 31 | @Override 32 | public long getId() { 33 | return getLongOrNull(${field.entity.nameCamelCase}Columns._ID); 34 | } 35 | 36 | 37 | /** 38 | <#if field.documentation??> 39 | * ${field.documentation} 40 | <#else> 41 | * Get the {@code ${field.nameLowerCase}} value. 42 | 43 | <#if field.isNullable> 44 | * Can be {@code null}. 45 | <#else> 46 | <#if !field.type.hasNotNullableJavaType()> 47 | * Cannot be {@code null}. 48 | 49 | 50 | */ 51 | <#if config.useAnnotations> 52 | <#if field.isNullable> 53 | @Nullable 54 | <#else> 55 | <#if !field.type.hasNotNullableJavaType()> 56 | @NonNull 57 | 58 | 59 | 60 | <#if !field.isForeign> 61 | @Override 62 | 63 | public ${field.javaTypeSimpleName} get<#if field.isForeign>${field.path}${field.nameCamelCase}() { 64 | <#switch field.type.name()> 65 | <#case "STRING"> 66 | String res = getStringOrNull(${field.entity.nameCamelCase}Columns.${field.nameUpperCase}); 67 | <#break> 68 | <#case "INTEGER"> 69 | Integer res = getIntegerOrNull(${field.entity.nameCamelCase}Columns.${field.nameUpperCase}); 70 | <#break> 71 | <#case "LONG"> 72 | Long res = getLongOrNull(${field.entity.nameCamelCase}Columns.${field.nameUpperCase}); 73 | <#break> 74 | <#case "FLOAT"> 75 | Float res = getFloatOrNull(${field.entity.nameCamelCase}Columns.${field.nameUpperCase}); 76 | <#break> 77 | <#case "DOUBLE"> 78 | Double res = getDoubleOrNull(${field.entity.nameCamelCase}Columns.${field.nameUpperCase}); 79 | <#break> 80 | <#case "BOOLEAN"> 81 | Boolean res = getBooleanOrNull(${field.entity.nameCamelCase}Columns.${field.nameUpperCase}); 82 | <#break> 83 | <#case "DATE"> 84 | Date res = getDateOrNull(${field.entity.nameCamelCase}Columns.${field.nameUpperCase}); 85 | <#break> 86 | <#case "BYTE_ARRAY"> 87 | byte[] res = getBlobOrNull(${field.entity.nameCamelCase}Columns.${field.nameUpperCase}); 88 | <#break> 89 | <#case "ENUM"> 90 | Integer intValue = getIntegerOrNull(${field.entity.nameCamelCase}Columns.${field.nameUpperCase}); 91 | <#if field.isNullable> 92 | if (intValue == null) return null; 93 | <#else> 94 | if (intValue == null) 95 | throw new NullPointerException("The value of '${field.nameLowerCase}' in the database was null, which is not allowed according to the model definition"); 96 | 97 | return ${field.javaTypeSimpleName}.values()[intValue]; 98 | <#break> 99 | 100 | <#if field.type.name() != "ENUM"> 101 | <#if !field.isNullable> 102 | if (res == null) 103 | throw new NullPointerException("The value of '${field.nameLowerCase}' in the database was null, which is not allowed according to the model definition"); 104 | 105 | return res; 106 | 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /acpg-lib/src/main/resources/org/jraf/acpg/lib/enum.ftl: -------------------------------------------------------------------------------- 1 | <#if header??> 2 | ${header} 3 | 4 | package ${config.providerJavaPackage}.${entity.packageName}; 5 | 6 | // @formatter:off 7 | /** 8 | * Possible values for the {@code ${field.nameLowerCase}} column of the {@code ${entity.nameLowerCase}} table. 9 | */ 10 | public enum ${field.enumName} { 11 | <#list field.enumValues as enumValue> 12 | /** 13 | * ${enumValue.documentation!""} 14 | */ 15 | ${enumValue.name}, 16 | 17 | 18 | } -------------------------------------------------------------------------------- /acpg-lib/src/main/resources/org/jraf/acpg/lib/manifest.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | -------------------------------------------------------------------------------- /acpg-lib/src/main/resources/org/jraf/acpg/lib/model.ftl: -------------------------------------------------------------------------------- 1 | <#if header??> 2 | ${header} 3 | 4 | package ${config.providerJavaPackage}.${entity.packageName}; 5 | 6 | // @formatter:off 7 | import ${config.providerJavaPackage}.base.BaseModel; 8 | 9 | import java.util.Date; 10 | <#if config.useAnnotations> 11 | 12 | import android.support.annotation.NonNull; 13 | import android.support.annotation.Nullable; 14 | 15 | 16 | /** 17 | <#if entity.documentation??> 18 | * ${entity.documentation} 19 | <#else> 20 | * Data model for the {@code ${entity.nameLowerCase}} table. 21 | 22 | */ 23 | @SuppressWarnings({"WeakerAccess", "unused"}) 24 | public interface ${entity.nameCamelCase}Model extends BaseModel { 25 | <#list entity.getFields() as field> 26 | 27 | /** 28 | <#if field.documentation??> 29 | * ${field.documentation} 30 | <#else> 31 | * Get the {@code ${field.nameLowerCase}} value. 32 | 33 | <#if field.isNullable> 34 | * Can be {@code null}. 35 | <#else> 36 | <#if !field.type.hasNotNullableJavaType()> 37 | * Cannot be {@code null}. 38 | 39 | 40 | */ 41 | <#if config.useAnnotations> 42 | <#if field.isNullable> 43 | @Nullable 44 | <#else> 45 | <#if !field.type.hasNotNullableJavaType()> 46 | @NonNull 47 | 48 | 49 | 50 | ${field.javaTypeSimpleName} get${field.nameCamelCase}(); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | } 5 | 6 | dependencies { 7 | classpath 'com.android.tools.build:gradle:2.4.0-alpha6' 8 | } 9 | } 10 | 11 | allprojects { 12 | apply plugin: 'maven' 13 | 14 | group = 'org.jraf' 15 | version = '1.13.1' 16 | 17 | repositories { 18 | mavenLocal() 19 | jcenter() 20 | } 21 | } 22 | 23 | task wrapper(type: Wrapper) { 24 | gradleVersion = '3.5' 25 | distributionType = Wrapper.DistributionType.ALL 26 | } -------------------------------------------------------------------------------- /cli/build.gradle: -------------------------------------------------------------------------------- 1 | description = 'cli (Android ContentProvider Generator Command Line Interface)' 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4' 9 | } 10 | } 11 | 12 | apply plugin: 'java' 13 | apply plugin: 'application' 14 | apply plugin: 'com.github.johnrengelman.shadow' 15 | 16 | sourceCompatibility = 1.7 17 | targetCompatibility = 1.7 18 | 19 | mainClassName = "org.jraf.acpg.cli.Cli" 20 | 21 | dependencies { 22 | compile project(':acpg-lib') 23 | compile 'commons-lang:commons-lang:2.6' 24 | compile 'com.beust:jcommander:1.32' 25 | compile 'org.apache.logging.log4j:log4j-api:2.8' 26 | compile 'org.apache.logging.log4j:log4j-core:2.8' 27 | } 28 | 29 | shadowJar { 30 | baseName = 'acpg-cli' 31 | classifier = null 32 | version = project.version 33 | } 34 | 35 | // Use "./gradlew shadowJar" to create the jar including dependencies -------------------------------------------------------------------------------- /cli/src/main/java/org/jraf/acpg/cli/Arguments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2015 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.acpg.cli; 26 | 27 | import java.io.File; 28 | 29 | import com.beust.jcommander.Parameter; 30 | import com.beust.jcommander.Parameters; 31 | 32 | @Parameters(separators = " =") 33 | public class Arguments { 34 | @Parameter(names = { "-h", "--help" }, description = "Display this help and exit") 35 | public boolean help; 36 | 37 | @Parameter(names = { "-i", "--input" }, description = "Input folder, where to find _config.json and your entity json files") 38 | public File inputDir = new File("."); 39 | 40 | @Parameter(names = { "-o", "--output" }, description = "Output folder, where the resulting files will be generated") 41 | public File outputDir = new File("generated"); 42 | } 43 | -------------------------------------------------------------------------------- /cli/src/main/java/org/jraf/acpg/cli/Cli.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2014 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.acpg.cli; 26 | 27 | import org.apache.logging.log4j.LogManager; 28 | import org.apache.logging.log4j.Logger; 29 | 30 | import com.beust.jcommander.JCommander; 31 | 32 | import org.jraf.acpg.lib.Generator; 33 | import org.jraf.acpg.lib.GeneratorException; 34 | import org.jraf.acpg.lib.config.Config; 35 | 36 | public class Cli { 37 | private static final Logger LOG = LogManager.getLogger(Cli.class); 38 | 39 | private void go(String[] args) { 40 | Arguments arguments = new Arguments(); 41 | JCommander jCommander = new JCommander(arguments, args); 42 | jCommander.setProgramName("GenerateAndroidProvider"); 43 | 44 | if (arguments.help) { 45 | jCommander.usage(); 46 | return; 47 | } 48 | 49 | Config config = null; 50 | try { 51 | config = Generator.parseConfig(arguments.inputDir); 52 | } catch (GeneratorException e) { 53 | LOG.error("Problem while parsing the _config.json file.", e); 54 | } 55 | 56 | try { 57 | new Generator(config, arguments.inputDir, arguments.outputDir).generate(); 58 | } catch (GeneratorException e) { 59 | LOG.error("Problem while generating the ContentProvider.", e); 60 | } 61 | } 62 | 63 | public static void main(String[] args) throws Exception { 64 | new Cli().go(args); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /cli/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /etc/generate-contentprovider.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | java -jar ../cli/build/libs/acpg-cli-*.jar -i ../sample-app/etc/acpg -o sample-generated-code -------------------------------------------------------------------------------- /etc/generate-schema-graph.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ./sc.sh -server=sqlite -database=/Users/bod//Tmp/sample.2015-02-21-12_00_59.db -c=graph -o=/Users/bod/gitrepo/android-contentprovider-generator/etc/sample/sample-schema.png -infolevel=standard -portablenames -password= -outputformat png 3 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/base/AbstractContentValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.base; 26 | 27 | // @formatter:off 28 | import android.content.Context; 29 | import android.content.ContentResolver; 30 | import android.content.ContentValues; 31 | import android.net.Uri; 32 | 33 | @SuppressWarnings("unused") 34 | public abstract class AbstractContentValues> { 35 | protected final ContentValues mContentValues = new ContentValues(); 36 | private Boolean mNotify; 37 | 38 | /** 39 | * Returns the {@code uri} argument to pass to the {@code ContentResolver} methods. 40 | */ 41 | protected abstract Uri baseUri(); 42 | 43 | /** 44 | * Returns the {@code uri} argument to pass to the {@code ContentResolver} methods. 45 | */ 46 | public Uri uri() { 47 | Uri uri = baseUri(); 48 | if (mNotify != null) uri = BaseContentProvider.notify(uri, mNotify); 49 | return uri; 50 | } 51 | 52 | @SuppressWarnings("unchecked") 53 | public T notify(boolean notify) { 54 | mNotify = notify; 55 | return (T) this; 56 | } 57 | 58 | /** 59 | * Returns the {@code ContentValues} wrapped by this object. 60 | */ 61 | public ContentValues values() { 62 | return mContentValues; 63 | } 64 | 65 | /** 66 | * Inserts a row into a table using the values stored by this object. 67 | * 68 | * @param contentResolver The content resolver to use. 69 | */ 70 | public Uri insert(ContentResolver contentResolver) { 71 | return contentResolver.insert(uri(), values()); 72 | } 73 | 74 | /** 75 | * Inserts a row into a table using the values stored by this object. 76 | * 77 | * @param context The context to use. 78 | */ 79 | public Uri insert(Context context) { 80 | return context.getContentResolver().insert(uri(), values()); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/base/AbstractCursor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.base; 26 | 27 | // @formatter:off 28 | import java.util.Date; 29 | import java.util.HashMap; 30 | 31 | import android.database.Cursor; 32 | import android.database.CursorWrapper; 33 | import android.provider.BaseColumns; 34 | 35 | @SuppressWarnings({"WeakerAccess", "unused"}) 36 | public abstract class AbstractCursor extends CursorWrapper { 37 | private final HashMap mColumnIndexes; 38 | 39 | public AbstractCursor(Cursor cursor) { 40 | super(cursor); 41 | mColumnIndexes = new HashMap<>(cursor.getColumnCount() * 4 / 3, .75f); 42 | } 43 | 44 | public abstract long getId(); 45 | 46 | protected int getCachedColumnIndexOrThrow(String colName) { 47 | Integer index = mColumnIndexes.get(colName); 48 | if (index == null) { 49 | index = getColumnIndexOrThrow(colName); 50 | mColumnIndexes.put(colName, index); 51 | } 52 | return index; 53 | } 54 | 55 | public String getStringOrNull(String colName) { 56 | int index = getCachedColumnIndexOrThrow(colName); 57 | if (isNull(index)) return null; 58 | return getString(index); 59 | } 60 | 61 | public Integer getIntegerOrNull(String colName) { 62 | int index = getCachedColumnIndexOrThrow(colName); 63 | if (isNull(index)) return null; 64 | return getInt(index); 65 | } 66 | 67 | public Long getLongOrNull(String colName) { 68 | int index = getCachedColumnIndexOrThrow(colName); 69 | if (isNull(index)) return null; 70 | return getLong(index); 71 | } 72 | 73 | public Float getFloatOrNull(String colName) { 74 | int index = getCachedColumnIndexOrThrow(colName); 75 | if (isNull(index)) return null; 76 | return getFloat(index); 77 | } 78 | 79 | public Double getDoubleOrNull(String colName) { 80 | int index = getCachedColumnIndexOrThrow(colName); 81 | if (isNull(index)) return null; 82 | return getDouble(index); 83 | } 84 | 85 | public Boolean getBooleanOrNull(String colName) { 86 | int index = getCachedColumnIndexOrThrow(colName); 87 | if (isNull(index)) return null; 88 | return getInt(index) != 0; 89 | } 90 | 91 | public Date getDateOrNull(String colName) { 92 | int index = getCachedColumnIndexOrThrow(colName); 93 | if (isNull(index)) return null; 94 | return new Date(getLong(index)); 95 | } 96 | 97 | public byte[] getBlobOrNull(String colName) { 98 | int index = getCachedColumnIndexOrThrow(colName); 99 | if (isNull(index)) return null; 100 | return getBlob(index); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/base/BaseModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.base; 26 | 27 | // @formatter:off 28 | public interface BaseModel { 29 | } 30 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/base/BaseSQLiteOpenHelperCallbacks.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.base; 26 | 27 | // @formatter:off 28 | import android.content.Context; 29 | import android.database.sqlite.SQLiteDatabase; 30 | 31 | import android.util.Log; 32 | 33 | import org.jraf.androidcontentprovidergenerator.sample.BuildConfig; 34 | 35 | /** 36 | * Override this class to implement your custom database opening, creation or upgrade. 37 | */ 38 | public class BaseSQLiteOpenHelperCallbacks { 39 | private static final String TAG = BaseSQLiteOpenHelperCallbacks.class.getSimpleName(); 40 | 41 | /** 42 | * Called when the database has been opened. 43 | * @see android.database.sqlite.SQLiteOpenHelper#onOpen(SQLiteDatabase) onOpen 44 | */ 45 | public void onOpen(Context context, SQLiteDatabase db) { 46 | if (BuildConfig.LOG_DEBUG_PROVIDER) Log.d(TAG, "onOpen"); 47 | } 48 | 49 | /** 50 | * Called before the database tables are created. 51 | * @see android.database.sqlite.SQLiteOpenHelper#onCreate(SQLiteDatabase) onCreate 52 | */ 53 | public void onPreCreate(Context context, SQLiteDatabase db) { 54 | if (BuildConfig.LOG_DEBUG_PROVIDER) Log.d(TAG, "onPreCreate"); 55 | } 56 | 57 | /** 58 | * Called after the database tables have been created. 59 | * @see android.database.sqlite.SQLiteOpenHelper#onCreate(SQLiteDatabase) onCreate 60 | */ 61 | public void onPostCreate(Context context, SQLiteDatabase db) { 62 | if (BuildConfig.LOG_DEBUG_PROVIDER) Log.d(TAG, "onPostCreate"); 63 | } 64 | 65 | /** 66 | * Called when the database needs to be upgraded. 67 | * @see android.database.sqlite.SQLiteOpenHelper#onUpgrade(Context, SQLiteDatabase, int, int) onUpgrade 68 | */ 69 | public void onUpgrade(final Context context, final SQLiteDatabase db, final int oldVersion, final int newVersion) { 70 | if (BuildConfig.LOG_DEBUG_PROVIDER) Log.d(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/company/CompanyColumns.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.company; 26 | 27 | // @formatter:off 28 | import android.net.Uri; 29 | import android.provider.BaseColumns; 30 | 31 | import org.jraf.androidcontentprovidergenerator.sample.provider.SampleProvider; 32 | import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractSelection; 33 | import org.jraf.androidcontentprovidergenerator.sample.provider.company.CompanyColumns; 34 | import org.jraf.androidcontentprovidergenerator.sample.provider.manual.ManualColumns; 35 | import org.jraf.androidcontentprovidergenerator.sample.provider.person.PersonColumns; 36 | import org.jraf.androidcontentprovidergenerator.sample.provider.personteam.PersonTeamColumns; 37 | import org.jraf.androidcontentprovidergenerator.sample.provider.product.ProductColumns; 38 | import org.jraf.androidcontentprovidergenerator.sample.provider.serialnumber.SerialNumberColumns; 39 | import org.jraf.androidcontentprovidergenerator.sample.provider.team.TeamColumns; 40 | 41 | /** 42 | * A commercial business. 43 | */ 44 | @SuppressWarnings("unused") 45 | public class CompanyColumns implements BaseColumns { 46 | public static final String TABLE_NAME = "company"; 47 | public static final Uri CONTENT_URI = Uri.parse(SampleProvider.CONTENT_URI_BASE + "/" + TABLE_NAME); 48 | 49 | /** 50 | * Primary key. 51 | */ 52 | public static final String _ID = BaseColumns._ID; 53 | 54 | /** 55 | * The commercial name of this company. 56 | */ 57 | public static final String NAME = "company__name"; 58 | 59 | /** 60 | * The full address of this company. 61 | */ 62 | public static final String ADDRESS = "address"; 63 | 64 | /** 65 | * The serial number of this company. 66 | */ 67 | public static final String SERIAL_NUMBER_ID = "company__serial_number_id"; 68 | 69 | 70 | public static final String DEFAULT_ORDER = TABLE_NAME + "." + NAME; 71 | 72 | public static final String[] ALL_COLUMNS = new String[] { 73 | _ID, 74 | NAME, 75 | ADDRESS, 76 | SERIAL_NUMBER_ID 77 | }; 78 | 79 | public static boolean hasColumns(String[] projection) { 80 | if (projection == null) return true; 81 | for (String c : projection) { 82 | if (c.equals(NAME) || c.contains("." + NAME)) return true; 83 | if (c.equals(ADDRESS) || c.contains("." + ADDRESS)) return true; 84 | if (c.equals(SERIAL_NUMBER_ID) || c.contains("." + SERIAL_NUMBER_ID)) return true; 85 | } 86 | return false; 87 | } 88 | 89 | public static final String PREFIX_SERIAL_NUMBER = TABLE_NAME + "__" + SerialNumberColumns.TABLE_NAME; 90 | } 91 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/company/CompanyContentValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.company; 26 | 27 | // @formatter:off 28 | import java.util.Date; 29 | 30 | import android.content.Context; 31 | import android.content.ContentResolver; 32 | import android.net.Uri; 33 | import android.support.annotation.NonNull; 34 | import android.support.annotation.Nullable; 35 | 36 | import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractContentValues; 37 | 38 | /** 39 | * Content values wrapper for the {@code company} table. 40 | */ 41 | @SuppressWarnings({"ConstantConditions", "unused"}) 42 | public class CompanyContentValues extends AbstractContentValues { 43 | @Override 44 | protected Uri baseUri() { 45 | return CompanyColumns.CONTENT_URI; 46 | } 47 | 48 | /** 49 | * Update row(s) using the values stored by this object and the given selection. 50 | * 51 | * @param contentResolver The content resolver to use. 52 | * @param where The selection to use (can be {@code null}). 53 | */ 54 | public int update(ContentResolver contentResolver, @Nullable CompanySelection where) { 55 | return contentResolver.update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args()); 56 | } 57 | 58 | /** 59 | * Update row(s) using the values stored by this object and the given selection. 60 | * 61 | * @param context The context to use. 62 | * @param where The selection to use (can be {@code null}). 63 | */ 64 | public int update(Context context, @Nullable CompanySelection where) { 65 | return context.getContentResolver().update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args()); 66 | } 67 | 68 | /** 69 | * The commercial name of this company. 70 | */ 71 | public CompanyContentValues putName(@NonNull String value) { 72 | if (value == null) throw new IllegalArgumentException("name must not be null"); 73 | mContentValues.put(CompanyColumns.NAME, value); 74 | return this; 75 | } 76 | 77 | 78 | /** 79 | * The full address of this company. 80 | */ 81 | public CompanyContentValues putAddress(@Nullable String value) { 82 | mContentValues.put(CompanyColumns.ADDRESS, value); 83 | return this; 84 | } 85 | 86 | public CompanyContentValues putAddressNull() { 87 | mContentValues.putNull(CompanyColumns.ADDRESS); 88 | return this; 89 | } 90 | 91 | /** 92 | * The serial number of this company. 93 | */ 94 | public CompanyContentValues putSerialNumberId(long value) { 95 | mContentValues.put(CompanyColumns.SERIAL_NUMBER_ID, value); 96 | return this; 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/company/CompanyCursor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.company; 26 | 27 | // @formatter:off 28 | import java.util.Date; 29 | 30 | import android.database.Cursor; 31 | import android.support.annotation.NonNull; 32 | import android.support.annotation.Nullable; 33 | 34 | import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractCursor; 35 | import org.jraf.androidcontentprovidergenerator.sample.provider.serialnumber.*; 36 | 37 | /** 38 | * Cursor wrapper for the {@code company} table. 39 | */ 40 | @SuppressWarnings({"WeakerAccess", "unused", "UnnecessaryLocalVariable"}) 41 | public class CompanyCursor extends AbstractCursor implements CompanyModel { 42 | public CompanyCursor(Cursor cursor) { 43 | super(cursor); 44 | } 45 | 46 | /** 47 | * Primary key. 48 | */ 49 | @Override 50 | public long getId() { 51 | Long res = getLongOrNull(CompanyColumns._ID); 52 | if (res == null) 53 | throw new NullPointerException("The value of '_id' in the database was null, which is not allowed according to the model definition"); 54 | return res; 55 | } 56 | 57 | /** 58 | * The commercial name of this company. 59 | * Cannot be {@code null}. 60 | */ 61 | @NonNull 62 | @Override 63 | public String getName() { 64 | String res = getStringOrNull(CompanyColumns.NAME); 65 | if (res == null) 66 | throw new NullPointerException("The value of 'name' in the database was null, which is not allowed according to the model definition"); 67 | return res; 68 | } 69 | 70 | /** 71 | * The full address of this company. 72 | * Can be {@code null}. 73 | */ 74 | @Nullable 75 | @Override 76 | public String getAddress() { 77 | String res = getStringOrNull(CompanyColumns.ADDRESS); 78 | return res; 79 | } 80 | 81 | /** 82 | * The serial number of this company. 83 | */ 84 | @Override 85 | public long getSerialNumberId() { 86 | Long res = getLongOrNull(CompanyColumns.SERIAL_NUMBER_ID); 87 | if (res == null) 88 | throw new NullPointerException("The value of 'serial_number_id' in the database was null, which is not allowed according to the model definition"); 89 | return res; 90 | } 91 | 92 | /** 93 | * Unique id, first part. 94 | * Cannot be {@code null}. 95 | */ 96 | @NonNull 97 | public String getSerialNumberPart0() { 98 | String res = getStringOrNull(SerialNumberColumns.PART0); 99 | if (res == null) 100 | throw new NullPointerException("The value of 'part0' in the database was null, which is not allowed according to the model definition"); 101 | return res; 102 | } 103 | 104 | /** 105 | * Unique id, second part. 106 | * Cannot be {@code null}. 107 | */ 108 | @NonNull 109 | public String getSerialNumberPart1() { 110 | String res = getStringOrNull(SerialNumberColumns.PART1); 111 | if (res == null) 112 | throw new NullPointerException("The value of 'part1' in the database was null, which is not allowed according to the model definition"); 113 | return res; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/company/CompanyModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 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"}) 39 | public interface CompanyModel extends BaseModel { 40 | 41 | /** 42 | * Primary key. 43 | */ 44 | long getId(); 45 | 46 | /** 47 | * The commercial name of this company. 48 | * Cannot be {@code null}. 49 | */ 50 | @NonNull 51 | String getName(); 52 | 53 | /** 54 | * The full address of this company. 55 | * Can be {@code null}. 56 | */ 57 | @Nullable 58 | String getAddress(); 59 | 60 | /** 61 | * The serial number of this company. 62 | */ 63 | long getSerialNumberId(); 64 | } 65 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/manual/ManualBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.manual; 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 manual related to a product. 37 | */ 38 | @SuppressWarnings({"WeakerAccess", "unused", "ConstantConditions"}) 39 | public class ManualBean implements ManualModel { 40 | private long mId; 41 | private String mTitle; 42 | private String mIsbn; 43 | 44 | /** 45 | * Primary key. 46 | */ 47 | @Override 48 | public long getId() { 49 | return mId; 50 | } 51 | 52 | /** 53 | * Primary key. 54 | */ 55 | public void setId(long id) { 56 | mId = id; 57 | } 58 | 59 | /** 60 | * Get the {@code title} value. 61 | * Cannot be {@code null}. 62 | */ 63 | @NonNull 64 | @Override 65 | public String getTitle() { 66 | return mTitle; 67 | } 68 | 69 | /** 70 | * Set the {@code title} value. 71 | * Must not be {@code null}. 72 | */ 73 | public void setTitle(@NonNull String title) { 74 | if (title == null) throw new IllegalArgumentException("title must not be null"); 75 | mTitle = title; 76 | } 77 | 78 | /** 79 | * Get the {@code isbn} value. 80 | * Cannot be {@code null}. 81 | */ 82 | @NonNull 83 | @Override 84 | public String getIsbn() { 85 | return mIsbn; 86 | } 87 | 88 | /** 89 | * Set the {@code isbn} value. 90 | * Must not be {@code null}. 91 | */ 92 | public void setIsbn(@NonNull String isbn) { 93 | if (isbn == null) throw new IllegalArgumentException("isbn must not be null"); 94 | mIsbn = isbn; 95 | } 96 | 97 | @Override 98 | public boolean equals(Object o) { 99 | if (this == o) return true; 100 | if (o == null || getClass() != o.getClass()) return false; 101 | ManualBean bean = (ManualBean) o; 102 | return mId == bean.mId; 103 | } 104 | 105 | @Override 106 | public int hashCode() { 107 | return (int) (mId ^ (mId >>> 32)); 108 | } 109 | 110 | /** 111 | * Instantiate a new ManualBean with specified values. 112 | */ 113 | @NonNull 114 | public static ManualBean newInstance(long id, @NonNull String title, @NonNull String isbn) { 115 | if (title == null) throw new IllegalArgumentException("title must not be null"); 116 | if (isbn == null) throw new IllegalArgumentException("isbn must not be null"); 117 | ManualBean res = new ManualBean(); 118 | res.mId = id; 119 | res.mTitle = title; 120 | res.mIsbn = isbn; 121 | return res; 122 | } 123 | 124 | /** 125 | * Instantiate a new ManualBean with all the values copied from the given model. 126 | */ 127 | @NonNull 128 | public static ManualBean copy(@NonNull ManualModel from) { 129 | ManualBean res = new ManualBean(); 130 | res.mId = from.getId(); 131 | res.mTitle = from.getTitle(); 132 | res.mIsbn = from.getIsbn(); 133 | return res; 134 | } 135 | 136 | public static class Builder { 137 | private ManualBean mRes = new ManualBean(); 138 | 139 | /** 140 | * Primary key. 141 | */ 142 | public Builder id(long id) { 143 | mRes.mId = id; 144 | return this; 145 | } 146 | 147 | /** 148 | * Set the {@code title} value. 149 | * Must not be {@code null}. 150 | */ 151 | public Builder title(@NonNull String title) { 152 | if (title == null) throw new IllegalArgumentException("title must not be null"); 153 | mRes.mTitle = title; 154 | return this; 155 | } 156 | 157 | /** 158 | * Set the {@code isbn} value. 159 | * Must not be {@code null}. 160 | */ 161 | public Builder isbn(@NonNull String isbn) { 162 | if (isbn == null) throw new IllegalArgumentException("isbn must not be null"); 163 | mRes.mIsbn = isbn; 164 | return this; 165 | } 166 | 167 | /** 168 | * Get a new ManualBean built with the given values. 169 | */ 170 | public ManualBean build() { 171 | if (mRes.mTitle == null) throw new IllegalArgumentException("title must not be null"); 172 | if (mRes.mIsbn == null) throw new IllegalArgumentException("isbn must not be null"); 173 | return mRes; 174 | } 175 | } 176 | 177 | public static Builder newBuilder() { 178 | return new Builder(); 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/manual/ManualColumns.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.manual; 26 | 27 | // @formatter:off 28 | import android.net.Uri; 29 | import android.provider.BaseColumns; 30 | 31 | import org.jraf.androidcontentprovidergenerator.sample.provider.SampleProvider; 32 | import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractSelection; 33 | import org.jraf.androidcontentprovidergenerator.sample.provider.company.CompanyColumns; 34 | import org.jraf.androidcontentprovidergenerator.sample.provider.manual.ManualColumns; 35 | import org.jraf.androidcontentprovidergenerator.sample.provider.person.PersonColumns; 36 | import org.jraf.androidcontentprovidergenerator.sample.provider.personteam.PersonTeamColumns; 37 | import org.jraf.androidcontentprovidergenerator.sample.provider.product.ProductColumns; 38 | import org.jraf.androidcontentprovidergenerator.sample.provider.serialnumber.SerialNumberColumns; 39 | import org.jraf.androidcontentprovidergenerator.sample.provider.team.TeamColumns; 40 | 41 | /** 42 | * A manual related to a product. 43 | */ 44 | @SuppressWarnings("unused") 45 | public class ManualColumns implements BaseColumns { 46 | public static final String TABLE_NAME = "manual"; 47 | public static final Uri CONTENT_URI = Uri.parse(SampleProvider.CONTENT_URI_BASE + "/" + TABLE_NAME); 48 | 49 | /** 50 | * Primary key. 51 | */ 52 | public static final String _ID = BaseColumns._ID; 53 | 54 | public static final String TITLE = "title"; 55 | 56 | public static final String ISBN = "isbn"; 57 | 58 | 59 | public static final String DEFAULT_ORDER = null; 60 | 61 | public static final String[] ALL_COLUMNS = new String[] { 62 | _ID, 63 | TITLE, 64 | ISBN 65 | }; 66 | 67 | public static boolean hasColumns(String[] projection) { 68 | if (projection == null) return true; 69 | for (String c : projection) { 70 | if (c.equals(TITLE) || c.contains("." + TITLE)) return true; 71 | if (c.equals(ISBN) || c.contains("." + ISBN)) return true; 72 | } 73 | return false; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/manual/ManualContentValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.manual; 26 | 27 | // @formatter:off 28 | import java.util.Date; 29 | 30 | import android.content.Context; 31 | import android.content.ContentResolver; 32 | import android.net.Uri; 33 | import android.support.annotation.NonNull; 34 | import android.support.annotation.Nullable; 35 | 36 | import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractContentValues; 37 | 38 | /** 39 | * Content values wrapper for the {@code manual} table. 40 | */ 41 | @SuppressWarnings({"ConstantConditions", "unused"}) 42 | public class ManualContentValues extends AbstractContentValues { 43 | @Override 44 | protected Uri baseUri() { 45 | return ManualColumns.CONTENT_URI; 46 | } 47 | 48 | /** 49 | * Update row(s) using the values stored by this object and the given selection. 50 | * 51 | * @param contentResolver The content resolver to use. 52 | * @param where The selection to use (can be {@code null}). 53 | */ 54 | public int update(ContentResolver contentResolver, @Nullable ManualSelection where) { 55 | return contentResolver.update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args()); 56 | } 57 | 58 | /** 59 | * Update row(s) using the values stored by this object and the given selection. 60 | * 61 | * @param context The context to use. 62 | * @param where The selection to use (can be {@code null}). 63 | */ 64 | public int update(Context context, @Nullable ManualSelection where) { 65 | return context.getContentResolver().update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args()); 66 | } 67 | 68 | public ManualContentValues putTitle(@NonNull String value) { 69 | if (value == null) throw new IllegalArgumentException("title must not be null"); 70 | mContentValues.put(ManualColumns.TITLE, value); 71 | return this; 72 | } 73 | 74 | 75 | public ManualContentValues putIsbn(@NonNull String value) { 76 | if (value == null) throw new IllegalArgumentException("isbn must not be null"); 77 | mContentValues.put(ManualColumns.ISBN, value); 78 | return this; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/manual/ManualCursor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.manual; 26 | 27 | // @formatter:off 28 | import java.util.Date; 29 | 30 | import android.database.Cursor; 31 | import android.support.annotation.NonNull; 32 | import android.support.annotation.Nullable; 33 | 34 | import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractCursor; 35 | 36 | /** 37 | * Cursor wrapper for the {@code manual} table. 38 | */ 39 | @SuppressWarnings({"WeakerAccess", "unused", "UnnecessaryLocalVariable"}) 40 | public class ManualCursor extends AbstractCursor implements ManualModel { 41 | public ManualCursor(Cursor cursor) { 42 | super(cursor); 43 | } 44 | 45 | /** 46 | * Primary key. 47 | */ 48 | @Override 49 | public long getId() { 50 | Long res = getLongOrNull(ManualColumns._ID); 51 | if (res == null) 52 | throw new NullPointerException("The value of '_id' in the database was null, which is not allowed according to the model definition"); 53 | return res; 54 | } 55 | 56 | /** 57 | * Get the {@code title} value. 58 | * Cannot be {@code null}. 59 | */ 60 | @NonNull 61 | @Override 62 | public String getTitle() { 63 | String res = getStringOrNull(ManualColumns.TITLE); 64 | if (res == null) 65 | throw new NullPointerException("The value of 'title' in the database was null, which is not allowed according to the model definition"); 66 | return res; 67 | } 68 | 69 | /** 70 | * Get the {@code isbn} value. 71 | * Cannot be {@code null}. 72 | */ 73 | @NonNull 74 | @Override 75 | public String getIsbn() { 76 | String res = getStringOrNull(ManualColumns.ISBN); 77 | if (res == null) 78 | throw new NullPointerException("The value of 'isbn' in the database was null, which is not allowed according to the model definition"); 79 | return res; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/manual/ManualModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.manual; 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 manual related to a product. 37 | */ 38 | @SuppressWarnings({"WeakerAccess", "unused"}) 39 | public interface ManualModel extends BaseModel { 40 | 41 | /** 42 | * Primary key. 43 | */ 44 | long getId(); 45 | 46 | /** 47 | * Get the {@code title} value. 48 | * Cannot be {@code null}. 49 | */ 50 | @NonNull 51 | String getTitle(); 52 | 53 | /** 54 | * Get the {@code isbn} value. 55 | * Cannot be {@code null}. 56 | */ 57 | @NonNull 58 | String getIsbn(); 59 | } 60 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/person/Gender.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.person; 26 | 27 | // @formatter:off 28 | /** 29 | * Possible values for the {@code gender} column of the {@code person} table. 30 | */ 31 | public enum Gender { 32 | /** 33 | * 34 | */ 35 | MALE, 36 | 37 | /** 38 | * 39 | */ 40 | FEMALE, 41 | 42 | /** 43 | * Value to use when neither male nor female 44 | */ 45 | OTHER, 46 | 47 | } -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/person/PersonColumns.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.person; 26 | 27 | // @formatter:off 28 | import android.net.Uri; 29 | import android.provider.BaseColumns; 30 | 31 | import org.jraf.androidcontentprovidergenerator.sample.provider.SampleProvider; 32 | import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractSelection; 33 | import org.jraf.androidcontentprovidergenerator.sample.provider.company.CompanyColumns; 34 | import org.jraf.androidcontentprovidergenerator.sample.provider.manual.ManualColumns; 35 | import org.jraf.androidcontentprovidergenerator.sample.provider.person.PersonColumns; 36 | import org.jraf.androidcontentprovidergenerator.sample.provider.personteam.PersonTeamColumns; 37 | import org.jraf.androidcontentprovidergenerator.sample.provider.product.ProductColumns; 38 | import org.jraf.androidcontentprovidergenerator.sample.provider.serialnumber.SerialNumberColumns; 39 | import org.jraf.androidcontentprovidergenerator.sample.provider.team.TeamColumns; 40 | 41 | /** 42 | * A human being which is part of a team. 43 | */ 44 | @SuppressWarnings("unused") 45 | public class PersonColumns implements BaseColumns { 46 | public static final String TABLE_NAME = "person"; 47 | public static final Uri CONTENT_URI = Uri.parse(SampleProvider.CONTENT_URI_BASE + "/" + TABLE_NAME); 48 | 49 | /** 50 | * Primary key. 51 | */ 52 | public static final String _ID = BaseColumns._ID; 53 | 54 | /** 55 | * First name of this person. For instance, John. 56 | */ 57 | public static final String FIRST_NAME = "first_name"; 58 | 59 | /** 60 | * Last name (a.k.a. Given name) of this person. For instance, Smith. 61 | */ 62 | public static final String LAST_NAME = "last_name"; 63 | 64 | public static final String AGE = "age"; 65 | 66 | public static final String BIRTH_DATE = "birth_date"; 67 | 68 | /** 69 | * If {@code true}, this person has blue eyes. Otherwise, this person doesn't have blue eyes. 70 | */ 71 | public static final String HAS_BLUE_EYES = "has_blue_eyes"; 72 | 73 | public static final String HEIGHT = "height"; 74 | 75 | public static final String GENDER = "gender"; 76 | 77 | public static final String COUNTRY_CODE = "person__country_code"; 78 | 79 | 80 | public static final String DEFAULT_ORDER = TABLE_NAME + "." + FIRST_NAME + "," 81 | + TABLE_NAME + "." + LAST_NAME + "," 82 | + TABLE_NAME + "." + AGE + AbstractSelection.DESC; 83 | 84 | public static final String[] ALL_COLUMNS = new String[] { 85 | _ID, 86 | FIRST_NAME, 87 | LAST_NAME, 88 | AGE, 89 | BIRTH_DATE, 90 | HAS_BLUE_EYES, 91 | HEIGHT, 92 | GENDER, 93 | COUNTRY_CODE 94 | }; 95 | 96 | public static boolean hasColumns(String[] projection) { 97 | if (projection == null) return true; 98 | for (String c : projection) { 99 | if (c.equals(FIRST_NAME) || c.contains("." + FIRST_NAME)) return true; 100 | if (c.equals(LAST_NAME) || c.contains("." + LAST_NAME)) return true; 101 | if (c.equals(AGE) || c.contains("." + AGE)) return true; 102 | if (c.equals(BIRTH_DATE) || c.contains("." + BIRTH_DATE)) return true; 103 | if (c.equals(HAS_BLUE_EYES) || c.contains("." + HAS_BLUE_EYES)) return true; 104 | if (c.equals(HEIGHT) || c.contains("." + HEIGHT)) return true; 105 | if (c.equals(GENDER) || c.contains("." + GENDER)) return true; 106 | if (c.equals(COUNTRY_CODE) || c.contains("." + COUNTRY_CODE)) return true; 107 | } 108 | return false; 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/person/PersonContentValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.person; 26 | 27 | // @formatter:off 28 | import java.util.Date; 29 | 30 | import android.content.Context; 31 | import android.content.ContentResolver; 32 | import android.net.Uri; 33 | import android.support.annotation.NonNull; 34 | import android.support.annotation.Nullable; 35 | 36 | import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractContentValues; 37 | 38 | /** 39 | * Content values wrapper for the {@code person} table. 40 | */ 41 | @SuppressWarnings({"ConstantConditions", "unused"}) 42 | public class PersonContentValues extends AbstractContentValues { 43 | @Override 44 | protected Uri baseUri() { 45 | return PersonColumns.CONTENT_URI; 46 | } 47 | 48 | /** 49 | * Update row(s) using the values stored by this object and the given selection. 50 | * 51 | * @param contentResolver The content resolver to use. 52 | * @param where The selection to use (can be {@code null}). 53 | */ 54 | public int update(ContentResolver contentResolver, @Nullable PersonSelection where) { 55 | return contentResolver.update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args()); 56 | } 57 | 58 | /** 59 | * Update row(s) using the values stored by this object and the given selection. 60 | * 61 | * @param context The context to use. 62 | * @param where The selection to use (can be {@code null}). 63 | */ 64 | public int update(Context context, @Nullable PersonSelection where) { 65 | return context.getContentResolver().update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args()); 66 | } 67 | 68 | /** 69 | * First name of this person. For instance, John. 70 | */ 71 | public PersonContentValues putFirstName(@NonNull String value) { 72 | if (value == null) throw new IllegalArgumentException("firstName must not be null"); 73 | mContentValues.put(PersonColumns.FIRST_NAME, value); 74 | return this; 75 | } 76 | 77 | 78 | /** 79 | * Last name (a.k.a. Given name) of this person. For instance, Smith. 80 | */ 81 | public PersonContentValues putLastName(@NonNull String value) { 82 | if (value == null) throw new IllegalArgumentException("lastName must not be null"); 83 | mContentValues.put(PersonColumns.LAST_NAME, value); 84 | return this; 85 | } 86 | 87 | 88 | public PersonContentValues putAge(int value) { 89 | mContentValues.put(PersonColumns.AGE, value); 90 | return this; 91 | } 92 | 93 | 94 | public PersonContentValues putBirthDate(@Nullable Date value) { 95 | mContentValues.put(PersonColumns.BIRTH_DATE, value == null ? null : value.getTime()); 96 | return this; 97 | } 98 | 99 | public PersonContentValues putBirthDateNull() { 100 | mContentValues.putNull(PersonColumns.BIRTH_DATE); 101 | return this; 102 | } 103 | 104 | public PersonContentValues putBirthDate(@Nullable Long value) { 105 | mContentValues.put(PersonColumns.BIRTH_DATE, value); 106 | return this; 107 | } 108 | 109 | /** 110 | * If {@code true}, this person has blue eyes. Otherwise, this person doesn't have blue eyes. 111 | */ 112 | public PersonContentValues putHasBlueEyes(boolean value) { 113 | mContentValues.put(PersonColumns.HAS_BLUE_EYES, value); 114 | return this; 115 | } 116 | 117 | 118 | public PersonContentValues putHeight(@Nullable Float value) { 119 | mContentValues.put(PersonColumns.HEIGHT, value); 120 | return this; 121 | } 122 | 123 | public PersonContentValues putHeightNull() { 124 | mContentValues.putNull(PersonColumns.HEIGHT); 125 | return this; 126 | } 127 | 128 | public PersonContentValues putGender(@NonNull Gender value) { 129 | if (value == null) throw new IllegalArgumentException("gender must not be null"); 130 | mContentValues.put(PersonColumns.GENDER, value.ordinal()); 131 | return this; 132 | } 133 | 134 | 135 | public PersonContentValues putCountryCode(@NonNull String value) { 136 | if (value == null) throw new IllegalArgumentException("countryCode must not be null"); 137 | mContentValues.put(PersonColumns.COUNTRY_CODE, value); 138 | return this; 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/person/PersonCursor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.person; 26 | 27 | // @formatter:off 28 | import java.util.Date; 29 | 30 | import android.database.Cursor; 31 | import android.support.annotation.NonNull; 32 | import android.support.annotation.Nullable; 33 | 34 | import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractCursor; 35 | 36 | /** 37 | * Cursor wrapper for the {@code person} table. 38 | */ 39 | @SuppressWarnings({"WeakerAccess", "unused", "UnnecessaryLocalVariable"}) 40 | public class PersonCursor extends AbstractCursor implements PersonModel { 41 | public PersonCursor(Cursor cursor) { 42 | super(cursor); 43 | } 44 | 45 | /** 46 | * Primary key. 47 | */ 48 | @Override 49 | public long getId() { 50 | Long res = getLongOrNull(PersonColumns._ID); 51 | if (res == null) 52 | throw new NullPointerException("The value of '_id' in the database was null, which is not allowed according to the model definition"); 53 | return res; 54 | } 55 | 56 | /** 57 | * First name of this person. For instance, John. 58 | * Cannot be {@code null}. 59 | */ 60 | @NonNull 61 | @Override 62 | public String getFirstName() { 63 | String res = getStringOrNull(PersonColumns.FIRST_NAME); 64 | if (res == null) 65 | throw new NullPointerException("The value of 'first_name' in the database was null, which is not allowed according to the model definition"); 66 | return res; 67 | } 68 | 69 | /** 70 | * Last name (a.k.a. Given name) of this person. For instance, Smith. 71 | * Cannot be {@code null}. 72 | */ 73 | @NonNull 74 | @Override 75 | public String getLastName() { 76 | String res = getStringOrNull(PersonColumns.LAST_NAME); 77 | if (res == null) 78 | throw new NullPointerException("The value of 'last_name' in the database was null, which is not allowed according to the model definition"); 79 | return res; 80 | } 81 | 82 | /** 83 | * Get the {@code age} value. 84 | */ 85 | @Override 86 | public int getAge() { 87 | Integer res = getIntegerOrNull(PersonColumns.AGE); 88 | if (res == null) 89 | throw new NullPointerException("The value of 'age' in the database was null, which is not allowed according to the model definition"); 90 | return res; 91 | } 92 | 93 | /** 94 | * Get the {@code birth_date} value. 95 | * Can be {@code null}. 96 | */ 97 | @Nullable 98 | @Override 99 | public Date getBirthDate() { 100 | Date res = getDateOrNull(PersonColumns.BIRTH_DATE); 101 | return res; 102 | } 103 | 104 | /** 105 | * If {@code true}, this person has blue eyes. Otherwise, this person doesn't have blue eyes. 106 | */ 107 | @Override 108 | public boolean getHasBlueEyes() { 109 | Boolean res = getBooleanOrNull(PersonColumns.HAS_BLUE_EYES); 110 | if (res == null) 111 | throw new NullPointerException("The value of 'has_blue_eyes' in the database was null, which is not allowed according to the model definition"); 112 | return res; 113 | } 114 | 115 | /** 116 | * Get the {@code height} value. 117 | * Can be {@code null}. 118 | */ 119 | @Nullable 120 | @Override 121 | public Float getHeight() { 122 | Float res = getFloatOrNull(PersonColumns.HEIGHT); 123 | return res; 124 | } 125 | 126 | /** 127 | * Get the {@code gender} value. 128 | * Cannot be {@code null}. 129 | */ 130 | @NonNull 131 | @Override 132 | public Gender getGender() { 133 | Integer intValue = getIntegerOrNull(PersonColumns.GENDER); 134 | if (intValue == null) 135 | throw new NullPointerException("The value of 'gender' in the database was null, which is not allowed according to the model definition"); 136 | return Gender.values()[intValue]; 137 | } 138 | 139 | /** 140 | * Get the {@code country_code} value. 141 | * Cannot be {@code null}. 142 | */ 143 | @NonNull 144 | @Override 145 | public String getCountryCode() { 146 | String res = getStringOrNull(PersonColumns.COUNTRY_CODE); 147 | if (res == null) 148 | throw new NullPointerException("The value of 'country_code' in the database was null, which is not allowed according to the model definition"); 149 | return res; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/person/PersonModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.person; 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 human being which is part of a team. 37 | */ 38 | @SuppressWarnings({"WeakerAccess", "unused"}) 39 | public interface PersonModel extends BaseModel { 40 | 41 | /** 42 | * Primary key. 43 | */ 44 | long getId(); 45 | 46 | /** 47 | * First name of this person. For instance, John. 48 | * Cannot be {@code null}. 49 | */ 50 | @NonNull 51 | String getFirstName(); 52 | 53 | /** 54 | * Last name (a.k.a. Given name) of this person. For instance, Smith. 55 | * Cannot be {@code null}. 56 | */ 57 | @NonNull 58 | String getLastName(); 59 | 60 | /** 61 | * Get the {@code age} value. 62 | */ 63 | int getAge(); 64 | 65 | /** 66 | * Get the {@code birth_date} value. 67 | * Can be {@code null}. 68 | */ 69 | @Nullable 70 | Date getBirthDate(); 71 | 72 | /** 73 | * If {@code true}, this person has blue eyes. Otherwise, this person doesn't have blue eyes. 74 | */ 75 | boolean getHasBlueEyes(); 76 | 77 | /** 78 | * Get the {@code height} value. 79 | * Can be {@code null}. 80 | */ 81 | @Nullable 82 | Float getHeight(); 83 | 84 | /** 85 | * Get the {@code gender} value. 86 | * Cannot be {@code null}. 87 | */ 88 | @NonNull 89 | Gender getGender(); 90 | 91 | /** 92 | * Get the {@code country_code} value. 93 | * Cannot be {@code null}. 94 | */ 95 | @NonNull 96 | String getCountryCode(); 97 | } 98 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/personteam/PersonTeamBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.personteam; 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 | * Entity joining people and teams. A team contains several people, and a person can belong to several teams. 37 | */ 38 | @SuppressWarnings({"WeakerAccess", "unused", "ConstantConditions"}) 39 | public class PersonTeamBean implements PersonTeamModel { 40 | private long mId; 41 | private long mPersonId; 42 | private long mTeamId; 43 | 44 | /** 45 | * Primary key. 46 | */ 47 | @Override 48 | public long getId() { 49 | return mId; 50 | } 51 | 52 | /** 53 | * Primary key. 54 | */ 55 | public void setId(long id) { 56 | mId = id; 57 | } 58 | 59 | /** 60 | * Get the {@code person_id} value. 61 | */ 62 | @Override 63 | public long getPersonId() { 64 | return mPersonId; 65 | } 66 | 67 | /** 68 | * Set the {@code person_id} value. 69 | */ 70 | public void setPersonId(long personId) { 71 | mPersonId = personId; 72 | } 73 | 74 | /** 75 | * Get the {@code team_id} value. 76 | */ 77 | @Override 78 | public long getTeamId() { 79 | return mTeamId; 80 | } 81 | 82 | /** 83 | * Set the {@code team_id} value. 84 | */ 85 | public void setTeamId(long teamId) { 86 | mTeamId = teamId; 87 | } 88 | 89 | @Override 90 | public boolean equals(Object o) { 91 | if (this == o) return true; 92 | if (o == null || getClass() != o.getClass()) return false; 93 | PersonTeamBean bean = (PersonTeamBean) o; 94 | return mId == bean.mId; 95 | } 96 | 97 | @Override 98 | public int hashCode() { 99 | return (int) (mId ^ (mId >>> 32)); 100 | } 101 | 102 | /** 103 | * Instantiate a new PersonTeamBean with specified values. 104 | */ 105 | @NonNull 106 | public static PersonTeamBean newInstance(long id, long personId, long teamId) { 107 | PersonTeamBean res = new PersonTeamBean(); 108 | res.mId = id; 109 | res.mPersonId = personId; 110 | res.mTeamId = teamId; 111 | return res; 112 | } 113 | 114 | /** 115 | * Instantiate a new PersonTeamBean with all the values copied from the given model. 116 | */ 117 | @NonNull 118 | public static PersonTeamBean copy(@NonNull PersonTeamModel from) { 119 | PersonTeamBean res = new PersonTeamBean(); 120 | res.mId = from.getId(); 121 | res.mPersonId = from.getPersonId(); 122 | res.mTeamId = from.getTeamId(); 123 | return res; 124 | } 125 | 126 | public static class Builder { 127 | private PersonTeamBean mRes = new PersonTeamBean(); 128 | 129 | /** 130 | * Primary key. 131 | */ 132 | public Builder id(long id) { 133 | mRes.mId = id; 134 | return this; 135 | } 136 | 137 | /** 138 | * Set the {@code person_id} value. 139 | */ 140 | public Builder personId(long personId) { 141 | mRes.mPersonId = personId; 142 | return this; 143 | } 144 | 145 | /** 146 | * Set the {@code team_id} value. 147 | */ 148 | public Builder teamId(long teamId) { 149 | mRes.mTeamId = teamId; 150 | return this; 151 | } 152 | 153 | /** 154 | * Get a new PersonTeamBean built with the given values. 155 | */ 156 | public PersonTeamBean build() { 157 | return mRes; 158 | } 159 | } 160 | 161 | public static Builder newBuilder() { 162 | return new Builder(); 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/personteam/PersonTeamColumns.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.personteam; 26 | 27 | // @formatter:off 28 | import android.net.Uri; 29 | import android.provider.BaseColumns; 30 | 31 | import org.jraf.androidcontentprovidergenerator.sample.provider.SampleProvider; 32 | import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractSelection; 33 | import org.jraf.androidcontentprovidergenerator.sample.provider.company.CompanyColumns; 34 | import org.jraf.androidcontentprovidergenerator.sample.provider.manual.ManualColumns; 35 | import org.jraf.androidcontentprovidergenerator.sample.provider.person.PersonColumns; 36 | import org.jraf.androidcontentprovidergenerator.sample.provider.personteam.PersonTeamColumns; 37 | import org.jraf.androidcontentprovidergenerator.sample.provider.product.ProductColumns; 38 | import org.jraf.androidcontentprovidergenerator.sample.provider.serialnumber.SerialNumberColumns; 39 | import org.jraf.androidcontentprovidergenerator.sample.provider.team.TeamColumns; 40 | 41 | /** 42 | * Entity joining people and teams. A team contains several people, and a person can belong to several teams. 43 | */ 44 | @SuppressWarnings("unused") 45 | public class PersonTeamColumns implements BaseColumns { 46 | public static final String TABLE_NAME = "person_team"; 47 | public static final Uri CONTENT_URI = Uri.parse(SampleProvider.CONTENT_URI_BASE + "/" + TABLE_NAME); 48 | 49 | /** 50 | * Primary key. 51 | */ 52 | public static final String _ID = BaseColumns._ID; 53 | 54 | public static final String PERSON_ID = "person_id"; 55 | 56 | public static final String TEAM_ID = "team_id"; 57 | 58 | 59 | public static final String DEFAULT_ORDER = null; 60 | 61 | public static final String[] ALL_COLUMNS = new String[] { 62 | _ID, 63 | PERSON_ID, 64 | TEAM_ID 65 | }; 66 | 67 | public static boolean hasColumns(String[] projection) { 68 | if (projection == null) return true; 69 | for (String c : projection) { 70 | if (c.equals(PERSON_ID) || c.contains("." + PERSON_ID)) return true; 71 | if (c.equals(TEAM_ID) || c.contains("." + TEAM_ID)) return true; 72 | } 73 | return false; 74 | } 75 | 76 | public static final String PREFIX_PERSON = TABLE_NAME + "__" + PersonColumns.TABLE_NAME; 77 | public static final String PREFIX_TEAM = TABLE_NAME + "__" + TeamColumns.TABLE_NAME; 78 | } 79 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/personteam/PersonTeamContentValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.personteam; 26 | 27 | // @formatter:off 28 | import java.util.Date; 29 | 30 | import android.content.Context; 31 | import android.content.ContentResolver; 32 | import android.net.Uri; 33 | import android.support.annotation.NonNull; 34 | import android.support.annotation.Nullable; 35 | 36 | import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractContentValues; 37 | 38 | /** 39 | * Content values wrapper for the {@code person_team} table. 40 | */ 41 | @SuppressWarnings({"ConstantConditions", "unused"}) 42 | public class PersonTeamContentValues extends AbstractContentValues { 43 | @Override 44 | protected Uri baseUri() { 45 | return PersonTeamColumns.CONTENT_URI; 46 | } 47 | 48 | /** 49 | * Update row(s) using the values stored by this object and the given selection. 50 | * 51 | * @param contentResolver The content resolver to use. 52 | * @param where The selection to use (can be {@code null}). 53 | */ 54 | public int update(ContentResolver contentResolver, @Nullable PersonTeamSelection where) { 55 | return contentResolver.update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args()); 56 | } 57 | 58 | /** 59 | * Update row(s) using the values stored by this object and the given selection. 60 | * 61 | * @param context The context to use. 62 | * @param where The selection to use (can be {@code null}). 63 | */ 64 | public int update(Context context, @Nullable PersonTeamSelection where) { 65 | return context.getContentResolver().update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args()); 66 | } 67 | 68 | public PersonTeamContentValues putPersonId(long value) { 69 | mContentValues.put(PersonTeamColumns.PERSON_ID, value); 70 | return this; 71 | } 72 | 73 | 74 | public PersonTeamContentValues putTeamId(long value) { 75 | mContentValues.put(PersonTeamColumns.TEAM_ID, value); 76 | return this; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/personteam/PersonTeamModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.personteam; 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 | * Entity joining people and teams. A team contains several people, and a person can belong to several teams. 37 | */ 38 | @SuppressWarnings({"WeakerAccess", "unused"}) 39 | public interface PersonTeamModel extends BaseModel { 40 | 41 | /** 42 | * Primary key. 43 | */ 44 | long getId(); 45 | 46 | /** 47 | * Get the {@code person_id} value. 48 | */ 49 | long getPersonId(); 50 | 51 | /** 52 | * Get the {@code team_id} value. 53 | */ 54 | long getTeamId(); 55 | } 56 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/product/ProductBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.product; 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 product that the company sells. 37 | */ 38 | @SuppressWarnings({"WeakerAccess", "unused", "ConstantConditions"}) 39 | public class ProductBean implements ProductModel { 40 | private long mProductId; 41 | private String mName; 42 | private Long mManualId; 43 | 44 | /** 45 | * Get the {@code product_id} value. 46 | */ 47 | @Override 48 | public long getProductId() { 49 | return mProductId; 50 | } 51 | 52 | /** 53 | * Set the {@code product_id} value. 54 | */ 55 | public void setProductId(long productId) { 56 | mProductId = productId; 57 | } 58 | 59 | /** 60 | * Get the {@code name} value. 61 | * Cannot be {@code null}. 62 | */ 63 | @NonNull 64 | @Override 65 | public String getName() { 66 | return mName; 67 | } 68 | 69 | /** 70 | * Set the {@code name} value. 71 | * Must not be {@code null}. 72 | */ 73 | public void setName(@NonNull String name) { 74 | if (name == null) throw new IllegalArgumentException("name must not be null"); 75 | mName = name; 76 | } 77 | 78 | /** 79 | * Optional manual id. 80 | * Can be {@code null}. 81 | */ 82 | @Nullable 83 | @Override 84 | public Long getManualId() { 85 | return mManualId; 86 | } 87 | 88 | /** 89 | * Optional manual id. 90 | * Can be {@code null}. 91 | */ 92 | public void setManualId(@Nullable Long manualId) { 93 | mManualId = manualId; 94 | } 95 | 96 | @Override 97 | public boolean equals(Object o) { 98 | if (this == o) return true; 99 | if (o == null || getClass() != o.getClass()) return false; 100 | ProductBean bean = (ProductBean) o; 101 | return mProductId == bean.mProductId; 102 | } 103 | 104 | @Override 105 | public int hashCode() { 106 | return (int) (mProductId ^ (mProductId >>> 32)); 107 | } 108 | 109 | /** 110 | * Instantiate a new ProductBean with specified values. 111 | */ 112 | @NonNull 113 | public static ProductBean newInstance(long productId, @NonNull String name, @Nullable Long manualId) { 114 | if (name == null) throw new IllegalArgumentException("name must not be null"); 115 | ProductBean res = new ProductBean(); 116 | res.mProductId = productId; 117 | res.mName = name; 118 | res.mManualId = manualId; 119 | return res; 120 | } 121 | 122 | /** 123 | * Instantiate a new ProductBean with all the values copied from the given model. 124 | */ 125 | @NonNull 126 | public static ProductBean copy(@NonNull ProductModel from) { 127 | ProductBean res = new ProductBean(); 128 | res.mProductId = from.getProductId(); 129 | res.mName = from.getName(); 130 | res.mManualId = from.getManualId(); 131 | return res; 132 | } 133 | 134 | public static class Builder { 135 | private ProductBean mRes = new ProductBean(); 136 | 137 | /** 138 | * Set the {@code product_id} value. 139 | */ 140 | public Builder productId(long productId) { 141 | mRes.mProductId = productId; 142 | return this; 143 | } 144 | 145 | /** 146 | * Set the {@code name} value. 147 | * Must not be {@code null}. 148 | */ 149 | public Builder name(@NonNull String name) { 150 | if (name == null) throw new IllegalArgumentException("name must not be null"); 151 | mRes.mName = name; 152 | return this; 153 | } 154 | 155 | /** 156 | * Optional manual id. 157 | * Can be {@code null}. 158 | */ 159 | public Builder manualId(@Nullable Long manualId) { 160 | mRes.mManualId = manualId; 161 | return this; 162 | } 163 | 164 | /** 165 | * Get a new ProductBean built with the given values. 166 | */ 167 | public ProductBean build() { 168 | if (mRes.mName == null) throw new IllegalArgumentException("name must not be null"); 169 | return mRes; 170 | } 171 | } 172 | 173 | public static Builder newBuilder() { 174 | return new Builder(); 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/product/ProductColumns.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.product; 26 | 27 | // @formatter:off 28 | import android.net.Uri; 29 | import android.provider.BaseColumns; 30 | 31 | import org.jraf.androidcontentprovidergenerator.sample.provider.SampleProvider; 32 | import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractSelection; 33 | import org.jraf.androidcontentprovidergenerator.sample.provider.company.CompanyColumns; 34 | import org.jraf.androidcontentprovidergenerator.sample.provider.manual.ManualColumns; 35 | import org.jraf.androidcontentprovidergenerator.sample.provider.person.PersonColumns; 36 | import org.jraf.androidcontentprovidergenerator.sample.provider.personteam.PersonTeamColumns; 37 | import org.jraf.androidcontentprovidergenerator.sample.provider.product.ProductColumns; 38 | import org.jraf.androidcontentprovidergenerator.sample.provider.serialnumber.SerialNumberColumns; 39 | import org.jraf.androidcontentprovidergenerator.sample.provider.team.TeamColumns; 40 | 41 | /** 42 | * A product that the company sells. 43 | */ 44 | @SuppressWarnings("unused") 45 | public class ProductColumns implements BaseColumns { 46 | public static final String TABLE_NAME = "product"; 47 | public static final Uri CONTENT_URI = Uri.parse(SampleProvider.CONTENT_URI_BASE + "/" + TABLE_NAME); 48 | 49 | public static final String _ID = "product_id"; 50 | 51 | public static final String PRODUCT_ID = "product_id"; 52 | 53 | public static final String NAME = "name"; 54 | 55 | /** 56 | * Optional manual id. 57 | */ 58 | public static final String MANUAL_ID = "manual_id"; 59 | 60 | 61 | public static final String DEFAULT_ORDER = null; 62 | 63 | public static final String[] ALL_COLUMNS = new String[] { 64 | _ID, 65 | NAME, 66 | MANUAL_ID 67 | }; 68 | 69 | public static boolean hasColumns(String[] projection) { 70 | if (projection == null) return true; 71 | for (String c : projection) { 72 | if (c.equals(PRODUCT_ID) || c.contains("." + PRODUCT_ID)) return true; 73 | if (c.equals(NAME) || c.contains("." + NAME)) return true; 74 | if (c.equals(MANUAL_ID) || c.contains("." + MANUAL_ID)) return true; 75 | } 76 | return false; 77 | } 78 | 79 | public static final String PREFIX_MANUAL = TABLE_NAME + "__" + ManualColumns.TABLE_NAME; 80 | } 81 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/product/ProductContentValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.product; 26 | 27 | // @formatter:off 28 | import java.util.Date; 29 | 30 | import android.content.Context; 31 | import android.content.ContentResolver; 32 | import android.net.Uri; 33 | import android.support.annotation.NonNull; 34 | import android.support.annotation.Nullable; 35 | 36 | import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractContentValues; 37 | 38 | /** 39 | * Content values wrapper for the {@code product} table. 40 | */ 41 | @SuppressWarnings({"ConstantConditions", "unused"}) 42 | public class ProductContentValues extends AbstractContentValues { 43 | @Override 44 | protected Uri baseUri() { 45 | return ProductColumns.CONTENT_URI; 46 | } 47 | 48 | /** 49 | * Update row(s) using the values stored by this object and the given selection. 50 | * 51 | * @param contentResolver The content resolver to use. 52 | * @param where The selection to use (can be {@code null}). 53 | */ 54 | public int update(ContentResolver contentResolver, @Nullable ProductSelection where) { 55 | return contentResolver.update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args()); 56 | } 57 | 58 | /** 59 | * Update row(s) using the values stored by this object and the given selection. 60 | * 61 | * @param context The context to use. 62 | * @param where The selection to use (can be {@code null}). 63 | */ 64 | public int update(Context context, @Nullable ProductSelection where) { 65 | return context.getContentResolver().update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args()); 66 | } 67 | 68 | public ProductContentValues putProductId(long value) { 69 | mContentValues.put(ProductColumns.PRODUCT_ID, value); 70 | return this; 71 | } 72 | 73 | 74 | public ProductContentValues putName(@NonNull String value) { 75 | if (value == null) throw new IllegalArgumentException("name must not be null"); 76 | mContentValues.put(ProductColumns.NAME, value); 77 | return this; 78 | } 79 | 80 | 81 | /** 82 | * Optional manual id. 83 | */ 84 | public ProductContentValues putManualId(@Nullable Long value) { 85 | mContentValues.put(ProductColumns.MANUAL_ID, value); 86 | return this; 87 | } 88 | 89 | public ProductContentValues putManualIdNull() { 90 | mContentValues.putNull(ProductColumns.MANUAL_ID); 91 | return this; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/product/ProductCursor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.product; 26 | 27 | // @formatter:off 28 | import java.util.Date; 29 | 30 | import android.database.Cursor; 31 | import android.support.annotation.NonNull; 32 | import android.support.annotation.Nullable; 33 | 34 | import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractCursor; 35 | import org.jraf.androidcontentprovidergenerator.sample.provider.manual.*; 36 | 37 | /** 38 | * Cursor wrapper for the {@code product} table. 39 | */ 40 | @SuppressWarnings({"WeakerAccess", "unused", "UnnecessaryLocalVariable"}) 41 | public class ProductCursor extends AbstractCursor implements ProductModel { 42 | public ProductCursor(Cursor cursor) { 43 | super(cursor); 44 | } 45 | 46 | @Override 47 | public long getId() { 48 | return getLongOrNull(ProductColumns._ID); 49 | } 50 | 51 | /** 52 | * Get the {@code product_id} value. 53 | */ 54 | @Override 55 | public long getProductId() { 56 | Long res = getLongOrNull(ProductColumns.PRODUCT_ID); 57 | if (res == null) 58 | throw new NullPointerException("The value of 'product_id' in the database was null, which is not allowed according to the model definition"); 59 | return res; 60 | } 61 | 62 | /** 63 | * Get the {@code name} value. 64 | * Cannot be {@code null}. 65 | */ 66 | @NonNull 67 | @Override 68 | public String getName() { 69 | String res = getStringOrNull(ProductColumns.NAME); 70 | if (res == null) 71 | throw new NullPointerException("The value of 'name' in the database was null, which is not allowed according to the model definition"); 72 | return res; 73 | } 74 | 75 | /** 76 | * Optional manual id. 77 | * Can be {@code null}. 78 | */ 79 | @Nullable 80 | @Override 81 | public Long getManualId() { 82 | Long res = getLongOrNull(ProductColumns.MANUAL_ID); 83 | return res; 84 | } 85 | 86 | /** 87 | * Get the {@code title} value. 88 | * Can be {@code null}. 89 | */ 90 | @Nullable 91 | public String getManualTitle() { 92 | String res = getStringOrNull(ManualColumns.TITLE); 93 | return res; 94 | } 95 | 96 | /** 97 | * Get the {@code isbn} value. 98 | * Can be {@code null}. 99 | */ 100 | @Nullable 101 | public String getManualIsbn() { 102 | String res = getStringOrNull(ManualColumns.ISBN); 103 | return res; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/product/ProductModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.product; 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 product that the company sells. 37 | */ 38 | @SuppressWarnings({"WeakerAccess", "unused"}) 39 | public interface ProductModel extends BaseModel { 40 | 41 | /** 42 | * Get the {@code product_id} value. 43 | */ 44 | long getProductId(); 45 | 46 | /** 47 | * Get the {@code name} value. 48 | * Cannot be {@code null}. 49 | */ 50 | @NonNull 51 | String getName(); 52 | 53 | /** 54 | * Optional manual id. 55 | * Can be {@code null}. 56 | */ 57 | @Nullable 58 | Long getManualId(); 59 | } 60 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/serialnumber/SerialNumberBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.serialnumber; 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 serial number. 37 | */ 38 | @SuppressWarnings({"WeakerAccess", "unused", "ConstantConditions"}) 39 | public class SerialNumberBean implements SerialNumberModel { 40 | private long mId; 41 | private String mPart0; 42 | private String mPart1; 43 | 44 | /** 45 | * Primary key. 46 | */ 47 | @Override 48 | public long getId() { 49 | return mId; 50 | } 51 | 52 | /** 53 | * Primary key. 54 | */ 55 | public void setId(long id) { 56 | mId = id; 57 | } 58 | 59 | /** 60 | * Unique id, first part. 61 | * Cannot be {@code null}. 62 | */ 63 | @NonNull 64 | @Override 65 | public String getPart0() { 66 | return mPart0; 67 | } 68 | 69 | /** 70 | * Unique id, first part. 71 | * Must not be {@code null}. 72 | */ 73 | public void setPart0(@NonNull String part0) { 74 | if (part0 == null) throw new IllegalArgumentException("part0 must not be null"); 75 | mPart0 = part0; 76 | } 77 | 78 | /** 79 | * Unique id, second part. 80 | * Cannot be {@code null}. 81 | */ 82 | @NonNull 83 | @Override 84 | public String getPart1() { 85 | return mPart1; 86 | } 87 | 88 | /** 89 | * Unique id, second part. 90 | * Must not be {@code null}. 91 | */ 92 | public void setPart1(@NonNull String part1) { 93 | if (part1 == null) throw new IllegalArgumentException("part1 must not be null"); 94 | mPart1 = part1; 95 | } 96 | 97 | @Override 98 | public boolean equals(Object o) { 99 | if (this == o) return true; 100 | if (o == null || getClass() != o.getClass()) return false; 101 | SerialNumberBean bean = (SerialNumberBean) o; 102 | return mId == bean.mId; 103 | } 104 | 105 | @Override 106 | public int hashCode() { 107 | return (int) (mId ^ (mId >>> 32)); 108 | } 109 | 110 | /** 111 | * Instantiate a new SerialNumberBean with specified values. 112 | */ 113 | @NonNull 114 | public static SerialNumberBean newInstance(long id, @NonNull String part0, @NonNull String part1) { 115 | if (part0 == null) throw new IllegalArgumentException("part0 must not be null"); 116 | if (part1 == null) throw new IllegalArgumentException("part1 must not be null"); 117 | SerialNumberBean res = new SerialNumberBean(); 118 | res.mId = id; 119 | res.mPart0 = part0; 120 | res.mPart1 = part1; 121 | return res; 122 | } 123 | 124 | /** 125 | * Instantiate a new SerialNumberBean with all the values copied from the given model. 126 | */ 127 | @NonNull 128 | public static SerialNumberBean copy(@NonNull SerialNumberModel from) { 129 | SerialNumberBean res = new SerialNumberBean(); 130 | res.mId = from.getId(); 131 | res.mPart0 = from.getPart0(); 132 | res.mPart1 = from.getPart1(); 133 | return res; 134 | } 135 | 136 | public static class Builder { 137 | private SerialNumberBean mRes = new SerialNumberBean(); 138 | 139 | /** 140 | * Primary key. 141 | */ 142 | public Builder id(long id) { 143 | mRes.mId = id; 144 | return this; 145 | } 146 | 147 | /** 148 | * Unique id, first part. 149 | * Must not be {@code null}. 150 | */ 151 | public Builder part0(@NonNull String part0) { 152 | if (part0 == null) throw new IllegalArgumentException("part0 must not be null"); 153 | mRes.mPart0 = part0; 154 | return this; 155 | } 156 | 157 | /** 158 | * Unique id, second part. 159 | * Must not be {@code null}. 160 | */ 161 | public Builder part1(@NonNull String part1) { 162 | if (part1 == null) throw new IllegalArgumentException("part1 must not be null"); 163 | mRes.mPart1 = part1; 164 | return this; 165 | } 166 | 167 | /** 168 | * Get a new SerialNumberBean built with the given values. 169 | */ 170 | public SerialNumberBean build() { 171 | if (mRes.mPart0 == null) throw new IllegalArgumentException("part0 must not be null"); 172 | if (mRes.mPart1 == null) throw new IllegalArgumentException("part1 must not be null"); 173 | return mRes; 174 | } 175 | } 176 | 177 | public static Builder newBuilder() { 178 | return new Builder(); 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/serialnumber/SerialNumberColumns.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.serialnumber; 26 | 27 | // @formatter:off 28 | import android.net.Uri; 29 | import android.provider.BaseColumns; 30 | 31 | import org.jraf.androidcontentprovidergenerator.sample.provider.SampleProvider; 32 | import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractSelection; 33 | import org.jraf.androidcontentprovidergenerator.sample.provider.company.CompanyColumns; 34 | import org.jraf.androidcontentprovidergenerator.sample.provider.manual.ManualColumns; 35 | import org.jraf.androidcontentprovidergenerator.sample.provider.person.PersonColumns; 36 | import org.jraf.androidcontentprovidergenerator.sample.provider.personteam.PersonTeamColumns; 37 | import org.jraf.androidcontentprovidergenerator.sample.provider.product.ProductColumns; 38 | import org.jraf.androidcontentprovidergenerator.sample.provider.serialnumber.SerialNumberColumns; 39 | import org.jraf.androidcontentprovidergenerator.sample.provider.team.TeamColumns; 40 | 41 | /** 42 | * A serial number. 43 | */ 44 | @SuppressWarnings("unused") 45 | public class SerialNumberColumns implements BaseColumns { 46 | public static final String TABLE_NAME = "serial_number"; 47 | public static final Uri CONTENT_URI = Uri.parse(SampleProvider.CONTENT_URI_BASE + "/" + TABLE_NAME); 48 | 49 | /** 50 | * Primary key. 51 | */ 52 | public static final String _ID = BaseColumns._ID; 53 | 54 | /** 55 | * Unique id, first part. 56 | */ 57 | public static final String PART0 = "serial_number__part0"; 58 | 59 | /** 60 | * Unique id, second part. 61 | */ 62 | public static final String PART1 = "serial_number__part1"; 63 | 64 | 65 | public static final String DEFAULT_ORDER = null; 66 | 67 | public static final String[] ALL_COLUMNS = new String[] { 68 | _ID, 69 | PART0, 70 | PART1 71 | }; 72 | 73 | public static boolean hasColumns(String[] projection) { 74 | if (projection == null) return true; 75 | for (String c : projection) { 76 | if (c.equals(PART0) || c.contains("." + PART0)) return true; 77 | if (c.equals(PART1) || c.contains("." + PART1)) return true; 78 | } 79 | return false; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/serialnumber/SerialNumberContentValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.serialnumber; 26 | 27 | // @formatter:off 28 | import java.util.Date; 29 | 30 | import android.content.Context; 31 | import android.content.ContentResolver; 32 | import android.net.Uri; 33 | import android.support.annotation.NonNull; 34 | import android.support.annotation.Nullable; 35 | 36 | import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractContentValues; 37 | 38 | /** 39 | * Content values wrapper for the {@code serial_number} table. 40 | */ 41 | @SuppressWarnings({"ConstantConditions", "unused"}) 42 | public class SerialNumberContentValues extends AbstractContentValues { 43 | @Override 44 | protected Uri baseUri() { 45 | return SerialNumberColumns.CONTENT_URI; 46 | } 47 | 48 | /** 49 | * Update row(s) using the values stored by this object and the given selection. 50 | * 51 | * @param contentResolver The content resolver to use. 52 | * @param where The selection to use (can be {@code null}). 53 | */ 54 | public int update(ContentResolver contentResolver, @Nullable SerialNumberSelection where) { 55 | return contentResolver.update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args()); 56 | } 57 | 58 | /** 59 | * Update row(s) using the values stored by this object and the given selection. 60 | * 61 | * @param context The context to use. 62 | * @param where The selection to use (can be {@code null}). 63 | */ 64 | public int update(Context context, @Nullable SerialNumberSelection where) { 65 | return context.getContentResolver().update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args()); 66 | } 67 | 68 | /** 69 | * Unique id, first part. 70 | */ 71 | public SerialNumberContentValues putPart0(@NonNull String value) { 72 | if (value == null) throw new IllegalArgumentException("part0 must not be null"); 73 | mContentValues.put(SerialNumberColumns.PART0, value); 74 | return this; 75 | } 76 | 77 | 78 | /** 79 | * Unique id, second part. 80 | */ 81 | public SerialNumberContentValues putPart1(@NonNull String value) { 82 | if (value == null) throw new IllegalArgumentException("part1 must not be null"); 83 | mContentValues.put(SerialNumberColumns.PART1, value); 84 | return this; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/serialnumber/SerialNumberCursor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.serialnumber; 26 | 27 | // @formatter:off 28 | import java.util.Date; 29 | 30 | import android.database.Cursor; 31 | import android.support.annotation.NonNull; 32 | import android.support.annotation.Nullable; 33 | 34 | import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractCursor; 35 | 36 | /** 37 | * Cursor wrapper for the {@code serial_number} table. 38 | */ 39 | @SuppressWarnings({"WeakerAccess", "unused", "UnnecessaryLocalVariable"}) 40 | public class SerialNumberCursor extends AbstractCursor implements SerialNumberModel { 41 | public SerialNumberCursor(Cursor cursor) { 42 | super(cursor); 43 | } 44 | 45 | /** 46 | * Primary key. 47 | */ 48 | @Override 49 | public long getId() { 50 | Long res = getLongOrNull(SerialNumberColumns._ID); 51 | if (res == null) 52 | throw new NullPointerException("The value of '_id' in the database was null, which is not allowed according to the model definition"); 53 | return res; 54 | } 55 | 56 | /** 57 | * Unique id, first part. 58 | * Cannot be {@code null}. 59 | */ 60 | @NonNull 61 | @Override 62 | public String getPart0() { 63 | String res = getStringOrNull(SerialNumberColumns.PART0); 64 | if (res == null) 65 | throw new NullPointerException("The value of 'part0' in the database was null, which is not allowed according to the model definition"); 66 | return res; 67 | } 68 | 69 | /** 70 | * Unique id, second part. 71 | * Cannot be {@code null}. 72 | */ 73 | @NonNull 74 | @Override 75 | public String getPart1() { 76 | String res = getStringOrNull(SerialNumberColumns.PART1); 77 | if (res == null) 78 | throw new NullPointerException("The value of 'part1' in the database was null, which is not allowed according to the model definition"); 79 | return res; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/serialnumber/SerialNumberModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.serialnumber; 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 serial number. 37 | */ 38 | @SuppressWarnings({"WeakerAccess", "unused"}) 39 | public interface SerialNumberModel extends BaseModel { 40 | 41 | /** 42 | * Primary key. 43 | */ 44 | long getId(); 45 | 46 | /** 47 | * Unique id, first part. 48 | * Cannot be {@code null}. 49 | */ 50 | @NonNull 51 | String getPart0(); 52 | 53 | /** 54 | * Unique id, second part. 55 | * Cannot be {@code null}. 56 | */ 57 | @NonNull 58 | String getPart1(); 59 | } 60 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/team/TeamColumns.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.team; 26 | 27 | // @formatter:off 28 | import android.net.Uri; 29 | import android.provider.BaseColumns; 30 | 31 | import org.jraf.androidcontentprovidergenerator.sample.provider.SampleProvider; 32 | import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractSelection; 33 | import org.jraf.androidcontentprovidergenerator.sample.provider.company.CompanyColumns; 34 | import org.jraf.androidcontentprovidergenerator.sample.provider.manual.ManualColumns; 35 | import org.jraf.androidcontentprovidergenerator.sample.provider.person.PersonColumns; 36 | import org.jraf.androidcontentprovidergenerator.sample.provider.personteam.PersonTeamColumns; 37 | import org.jraf.androidcontentprovidergenerator.sample.provider.product.ProductColumns; 38 | import org.jraf.androidcontentprovidergenerator.sample.provider.serialnumber.SerialNumberColumns; 39 | import org.jraf.androidcontentprovidergenerator.sample.provider.team.TeamColumns; 40 | 41 | /** 42 | * A group of people who work together. 43 | */ 44 | @SuppressWarnings("unused") 45 | public class TeamColumns implements BaseColumns { 46 | public static final String TABLE_NAME = "team"; 47 | public static final Uri CONTENT_URI = Uri.parse(SampleProvider.CONTENT_URI_BASE + "/" + TABLE_NAME); 48 | 49 | /** 50 | * Primary key. 51 | */ 52 | public static final String _ID = BaseColumns._ID; 53 | 54 | public static final String COMPANY_ID = "company_id"; 55 | 56 | public static final String NAME = "team__name"; 57 | 58 | /** 59 | * 2 letter country code where this team operates. 60 | */ 61 | public static final String COUNTRY_CODE = "team__country_code"; 62 | 63 | /** 64 | * The serial number of this team. 65 | */ 66 | public static final String SERIAL_NUMBER_ID = "team__serial_number_id"; 67 | 68 | 69 | public static final String DEFAULT_ORDER = null; 70 | 71 | public static final String[] ALL_COLUMNS = new String[] { 72 | _ID, 73 | COMPANY_ID, 74 | NAME, 75 | COUNTRY_CODE, 76 | SERIAL_NUMBER_ID 77 | }; 78 | 79 | public static boolean hasColumns(String[] projection) { 80 | if (projection == null) return true; 81 | for (String c : projection) { 82 | if (c.equals(COMPANY_ID) || c.contains("." + COMPANY_ID)) return true; 83 | if (c.equals(NAME) || c.contains("." + NAME)) return true; 84 | if (c.equals(COUNTRY_CODE) || c.contains("." + COUNTRY_CODE)) return true; 85 | if (c.equals(SERIAL_NUMBER_ID) || c.contains("." + SERIAL_NUMBER_ID)) return true; 86 | } 87 | return false; 88 | } 89 | 90 | public static final String PREFIX_COMPANY = TABLE_NAME + "__" + CompanyColumns.TABLE_NAME; 91 | public static final String PREFIX_SERIAL_NUMBER = TABLE_NAME + "__" + SerialNumberColumns.TABLE_NAME; 92 | } 93 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/team/TeamContentValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.team; 26 | 27 | // @formatter:off 28 | import java.util.Date; 29 | 30 | import android.content.Context; 31 | import android.content.ContentResolver; 32 | import android.net.Uri; 33 | import android.support.annotation.NonNull; 34 | import android.support.annotation.Nullable; 35 | 36 | import org.jraf.androidcontentprovidergenerator.sample.provider.base.AbstractContentValues; 37 | 38 | /** 39 | * Content values wrapper for the {@code team} table. 40 | */ 41 | @SuppressWarnings({"ConstantConditions", "unused"}) 42 | public class TeamContentValues extends AbstractContentValues { 43 | @Override 44 | protected Uri baseUri() { 45 | return TeamColumns.CONTENT_URI; 46 | } 47 | 48 | /** 49 | * Update row(s) using the values stored by this object and the given selection. 50 | * 51 | * @param contentResolver The content resolver to use. 52 | * @param where The selection to use (can be {@code null}). 53 | */ 54 | public int update(ContentResolver contentResolver, @Nullable TeamSelection where) { 55 | return contentResolver.update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args()); 56 | } 57 | 58 | /** 59 | * Update row(s) using the values stored by this object and the given selection. 60 | * 61 | * @param context The context to use. 62 | * @param where The selection to use (can be {@code null}). 63 | */ 64 | public int update(Context context, @Nullable TeamSelection where) { 65 | return context.getContentResolver().update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args()); 66 | } 67 | 68 | public TeamContentValues putCompanyId(long value) { 69 | mContentValues.put(TeamColumns.COMPANY_ID, value); 70 | return this; 71 | } 72 | 73 | 74 | public TeamContentValues putName(@NonNull String value) { 75 | if (value == null) throw new IllegalArgumentException("name must not be null"); 76 | mContentValues.put(TeamColumns.NAME, value); 77 | return this; 78 | } 79 | 80 | 81 | /** 82 | * 2 letter country code where this team operates. 83 | */ 84 | public TeamContentValues putCountryCode(@NonNull String value) { 85 | if (value == null) throw new IllegalArgumentException("countryCode must not be null"); 86 | mContentValues.put(TeamColumns.COUNTRY_CODE, value); 87 | return this; 88 | } 89 | 90 | 91 | /** 92 | * The serial number of this team. 93 | */ 94 | public TeamContentValues putSerialNumberId(long value) { 95 | mContentValues.put(TeamColumns.SERIAL_NUMBER_ID, value); 96 | return this; 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /etc/sample-generated-code/org/jraf/androidcontentprovidergenerator/sample/provider/team/TeamModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | package org.jraf.androidcontentprovidergenerator.sample.provider.team; 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 group of people who work together. 37 | */ 38 | @SuppressWarnings({"WeakerAccess", "unused"}) 39 | public interface TeamModel extends BaseModel { 40 | 41 | /** 42 | * Primary key. 43 | */ 44 | long getId(); 45 | 46 | /** 47 | * Get the {@code company_id} value. 48 | */ 49 | long getCompanyId(); 50 | 51 | /** 52 | * Get the {@code name} value. 53 | * Cannot be {@code null}. 54 | */ 55 | @NonNull 56 | String getName(); 57 | 58 | /** 59 | * 2 letter country code where this team operates. 60 | * Cannot be {@code null}. 61 | */ 62 | @NonNull 63 | String getCountryCode(); 64 | 65 | /** 66 | * The serial number of this team. 67 | */ 68 | long getSerialNumberId(); 69 | } 70 | -------------------------------------------------------------------------------- /etc/sample-schema.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoD/android-contentprovider-generator/d8189567b8e23db435556ec23a21bb13b5b3b5dd/etc/sample-schema.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoD/android-contentprovider-generator/d8189567b8e23db435556ec23a21bb13b5b3b5dd/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Apr 16 16:48:24 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /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 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 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 Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /local.properties: -------------------------------------------------------------------------------- 1 | ## This file is automatically generated by Android Studio. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must *NOT* be checked into Version Control Systems, 5 | # as it contains information specific to your local configuration. 6 | # 7 | # Location of the SDK. This is only used by Gradle. 8 | # For customization when using a Version Control System, please read the 9 | # header note. 10 | #Sat Oct 17 22:13:22 CEST 2015 11 | sdk.dir=/Users/bod/Dev/android-sdk-macosx 12 | -------------------------------------------------------------------------------- /sample-app/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenLocal() 4 | jcenter() 5 | } 6 | 7 | dependencies { 8 | classpath "org.jraf:acpg-gradle-plugin:${project.version}" 9 | } 10 | } 11 | 12 | apply plugin: 'com.android.application' 13 | apply plugin: 'org.jraf.acpg.gradleplugin' 14 | 15 | android { 16 | compileSdkVersion 25 17 | buildToolsVersion '25.0.0' 18 | 19 | defaultConfig { 20 | applicationId 'org.jraf.androidcontentprovidergenerator.sample' 21 | minSdkVersion 9 22 | targetSdkVersion 25 23 | versionCode 1 24 | versionName '1.0' 25 | 26 | buildConfigField 'boolean', 'LOG_DEBUG_PROVIDER', "true" 27 | } 28 | } 29 | 30 | acpg { 31 | entitiesDir file('etc/acpg') 32 | providerJavaPackage 'org.jraf.androidcontentprovidergenerator.sample.provider' 33 | authority '${applicationId}.provider' 34 | providerClassName 'SampleProvider' 35 | databaseFileName 'sample.db' 36 | databaseVersion 1 37 | sqliteOpenHelperCallbacksClassName 'SampleSQLiteOpenHelperCallbacks' 38 | enableForeignKeys true 39 | useAnnotations true 40 | useSupportLibrary true 41 | debugLogsFieldName 'LOG_DEBUG_PROVIDER' 42 | } 43 | 44 | dependencies { 45 | compile 'com.android.support:support-compat:25.0.0' 46 | compile 'com.android.support:support-core-utils:25.0.0' 47 | compile 'com.android.support:appcompat-v7:25.0.0' 48 | } 49 | -------------------------------------------------------------------------------- /sample-app/etc/acpg/_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "syntaxVersion": "4", 3 | "packageName": "org.jraf.androidcontentprovidergenerator.sample", 4 | "providerJavaPackage": "org.jraf.androidcontentprovidergenerator.sample.provider", 5 | "authority": "org.jraf.androidcontentprovidergenerator.sample.provider", 6 | "providerClassName": "SampleProvider", 7 | "databaseFileName": "sample.db", 8 | "databaseVersion": 1, 9 | "sqliteOpenHelperClassName": "SampleSQLiteOpenHelper", 10 | "sqliteOpenHelperCallbacksClassName": "SampleSQLiteOpenHelperCallbacks", 11 | "enableForeignKeys": true, 12 | "useAnnotations": true, 13 | "useSupportLibrary": true, 14 | "generateBeans": true, 15 | "debugLogsFieldName": "LOG_DEBUG_PROVIDER" 16 | } 17 | -------------------------------------------------------------------------------- /sample-app/etc/acpg/company.json: -------------------------------------------------------------------------------- 1 | { 2 | "documentation": "A commercial business.", 3 | "fields": [ 4 | { 5 | "documentation": "The commercial name of this company.", 6 | "name": "name", 7 | "type": "String", 8 | "nullable": false, 9 | "index": true 10 | }, 11 | { 12 | "documentation": "The full address of this company.", 13 | "name": "address", 14 | "type": "String", 15 | "nullable": true 16 | }, 17 | { 18 | "documentation": "The serial number of this company.", 19 | "name": "serial_number_id", 20 | "type": "Long", 21 | "nullable": false, 22 | "foreignKey": { 23 | "table": "serial_number", 24 | "onDelete": "CASCADE" 25 | } 26 | } 27 | ], 28 | 29 | "defaultOrder": "name" 30 | } 31 | -------------------------------------------------------------------------------- /sample-app/etc/acpg/header.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ -------------------------------------------------------------------------------- /sample-app/etc/acpg/manual.json: -------------------------------------------------------------------------------- 1 | { 2 | "documentation": "A manual related to a product.", 3 | "fields": [ 4 | { 5 | "name": "title", 6 | "type": "String", 7 | "nullable": false 8 | }, 9 | { 10 | "name": "isbn", 11 | "type": "String", 12 | "nullable": false 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /sample-app/etc/acpg/person.json: -------------------------------------------------------------------------------- 1 | { 2 | "documentation": "A human being which is part of a team.", 3 | "fields": [ 4 | { 5 | "documentation": "First name of this person. For instance, John.", 6 | "name": "first_name", 7 | "type": "String", 8 | "nullable": false 9 | }, 10 | { 11 | "documentation": "Last name (a.k.a. Given name) of this person. For instance, Smith.", 12 | "name": "last_name", 13 | "type": "String", 14 | "nullable": false, 15 | "index": true 16 | }, 17 | { 18 | "name": "age", 19 | "type": "Integer", 20 | "nullable": false 21 | }, 22 | { 23 | "name": "birth_date", 24 | "type": "Date", 25 | "nullable": true 26 | }, 27 | { 28 | "documentation": "If {@code true}, this person has blue eyes. Otherwise, this person doesn't have blue eyes.", 29 | "name": "has_blue_eyes", 30 | "type": "Boolean", 31 | "nullable": false, 32 | "defaultValue": "0" 33 | }, 34 | { 35 | "name": "height", 36 | "type": "Float", 37 | "nullable": true 38 | }, 39 | { 40 | "name": "gender", 41 | "type": "enum", 42 | "enumName": "Gender", 43 | "enumValues": [ 44 | "MALE", 45 | "FEMALE", 46 | {"OTHER": "Value to use when neither male nor female"} 47 | ], 48 | "nullable": false 49 | }, 50 | { 51 | "name": "country_code", 52 | "type": "String", 53 | "nullable": false 54 | } 55 | ], 56 | 57 | "constraints": [ 58 | { 59 | "name": "unique_name", 60 | "definition": "UNIQUE (first_name, last_name) ON CONFLICT REPLACE" 61 | } 62 | ], 63 | 64 | "defaultOrder": "first_name, last_name, age DESC" 65 | } 66 | -------------------------------------------------------------------------------- /sample-app/etc/acpg/person_team.json: -------------------------------------------------------------------------------- 1 | { 2 | "documentation": "Entity joining people and teams. A team contains several people, and a person can belong to several teams.", 3 | "fields": [ 4 | { 5 | "name": "person_id", 6 | "type": "Long", 7 | "nullable": false, 8 | "foreignKey": { 9 | "table": "person", 10 | "onDelete": "RESTRICT" 11 | } 12 | }, 13 | { 14 | "name": "team_id", 15 | "type": "Long", 16 | "nullable": false, 17 | "foreignKey": { 18 | "table": "team", 19 | "onDelete": "RESTRICT" 20 | } 21 | } 22 | ], 23 | "constraints": [ 24 | { 25 | "name": "unique_person_team", 26 | "definition": "UNIQUE (person_id, team_id) ON CONFLICT REPLACE" 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /sample-app/etc/acpg/product.json: -------------------------------------------------------------------------------- 1 | { 2 | "documentation": "A product that the company sells.", 3 | "fields": [ 4 | { 5 | "name": "product_id", 6 | "type": "Long", 7 | "nullable": false, 8 | "index": true 9 | }, 10 | { 11 | "name": "name", 12 | "type": "String", 13 | "nullable": false 14 | }, 15 | { 16 | "documentation": "Optional manual id.", 17 | "name": "manual_id", 18 | "type": "Long", 19 | "nullable": true, 20 | "foreignKey": { 21 | "table": "manual", 22 | "onDelete": "SET NULL" 23 | } 24 | } 25 | ], 26 | "idField": ["product_id"] 27 | } 28 | -------------------------------------------------------------------------------- /sample-app/etc/acpg/serial_number.json: -------------------------------------------------------------------------------- 1 | { 2 | "documentation": "A serial number.", 3 | "fields": [ 4 | { 5 | "documentation": "Unique id, first part.", 6 | "name": "part0", 7 | "type": "String", 8 | "nullable": false 9 | }, 10 | { 11 | "documentation": "Unique id, second part.", 12 | "name": "part1", 13 | "type": "String", 14 | "nullable": false 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /sample-app/etc/acpg/team.json: -------------------------------------------------------------------------------- 1 | { 2 | "documentation": "A group of people who work together.", 3 | "fields": [ 4 | { 5 | "name": "company_id", 6 | "type": "Long", 7 | "nullable": false, 8 | "foreignKey": { 9 | "table": "company", 10 | "onDelete": "CASCADE" 11 | } 12 | }, 13 | { 14 | "name": "name", 15 | "type": "String", 16 | "nullable": false 17 | }, 18 | { 19 | "documentation": "2 letter country code where this team operates.", 20 | "name": "country_code", 21 | "type": "String", 22 | "nullable": false 23 | }, 24 | { 25 | "documentation": "The serial number of this team.", 26 | "name": "serial_number_id", 27 | "type": "Long", 28 | "nullable": false, 29 | "foreignKey": { 30 | "table": "serial_number", 31 | "onDelete": "CASCADE" 32 | } 33 | } 34 | ], 35 | 36 | "constraints": [ 37 | { 38 | "name": "unique_name", 39 | "definition": "UNIQUE (team__name) ON CONFLICT REPLACE" 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /sample-app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 9 | 10 | 14 | 15 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /sample-app/src/main/java/org/jraf/androidcontentprovidergenerator/sample/provider/SampleSQLiteOpenHelperCallbacks.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source is part of the 3 | * _____ ___ ____ 4 | * __ / / _ \/ _ | / __/___ _______ _ 5 | * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/ 6 | * \___/_/|_/_/ |_/_/ (_)___/_/ \_, / 7 | * /___/ 8 | * repository. 9 | * 10 | * Copyright (C) 2012-2017 Benoit 'BoD' Lubek (BoD@JRAF.org) 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 . 24 | */ 25 | 26 | package org.jraf.androidcontentprovidergenerator.sample.provider; 27 | 28 | import android.content.Context; 29 | import android.database.sqlite.SQLiteDatabase; 30 | 31 | import org.jraf.androidcontentprovidergenerator.sample.provider.base.BaseSQLiteOpenHelperCallbacks; 32 | 33 | /** 34 | * Allows the app to be called when opening/creating/upgrading the db. 35 | */ 36 | public class SampleSQLiteOpenHelperCallbacks extends BaseSQLiteOpenHelperCallbacks { 37 | @Override 38 | public void onOpen(Context context, SQLiteDatabase db) { 39 | super.onOpen(context, db); 40 | } 41 | 42 | @Override 43 | public void onPreCreate(Context context, SQLiteDatabase db) { 44 | super.onPreCreate(context, db); 45 | } 46 | 47 | @Override 48 | public void onPostCreate(Context context, SQLiteDatabase db) { 49 | super.onPostCreate(context, db); 50 | } 51 | 52 | @Override 53 | public void onUpgrade(Context context, SQLiteDatabase db, int oldVersion, int newVersion) { 54 | super.onUpgrade(context, db, oldVersion, newVersion); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /sample-app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoD/android-contentprovider-generator/d8189567b8e23db435556ec23a21bb13b5b3b5dd/sample-app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample-app/src/main/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 |