{"id":15297025,"url":"https://github.com/timotheejeannin/provigen","last_synced_at":"2025-04-09T11:11:36.163Z","repository":{"id":4096246,"uuid":"5204396","full_name":"TimotheeJeannin/ProviGen","owner":"TimotheeJeannin","description":"Easily make a ContentProvider from an annotated ContractClass.","archived":false,"fork":false,"pushed_at":"2021-11-17T16:36:29.000Z","size":9819,"stargazers_count":243,"open_issues_count":15,"forks_count":26,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-04-09T11:11:25.878Z","etag":null,"topics":["android","contentobserver","contentprovider","contentresolver","sqliteopenhelper"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TimotheeJeannin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-07-27T12:42:28.000Z","updated_at":"2023-09-08T16:34:30.000Z","dependencies_parsed_at":"2022-08-17T20:40:13.198Z","dependency_job_id":null,"html_url":"https://github.com/TimotheeJeannin/ProviGen","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimotheeJeannin%2FProviGen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimotheeJeannin%2FProviGen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimotheeJeannin%2FProviGen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimotheeJeannin%2FProviGen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TimotheeJeannin","download_url":"https://codeload.github.com/TimotheeJeannin/ProviGen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248027411,"owners_count":21035594,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","contentobserver","contentprovider","contentresolver","sqliteopenhelper"],"created_at":"2024-09-30T19:14:34.363Z","updated_at":"2025-04-09T11:11:36.140Z","avatar_url":"https://github.com/TimotheeJeannin.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ProviGen [![Build Status](https://travis-ci.org/TimotheeJeannin/ProviGen.png?branch=master)](https://travis-ci.org/TimotheeJeannin/ProviGen) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.provigen/ProviGen-lib/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.provigen/ProviGen-lib/)\n\nEasily make a [ContentProvider] from a [ContractClass].    \n\n## Setup\n\n* Follow the [installation guide](https://github.com/TimotheeJeannin/ProviGen/wiki/Installation-Guide).\n\n* Annotate your ContractClass.\n\n```java\npublic interface MyContract extends ProviGenBaseContract {\n\n\t@Column(Type.INTEGER)\n\tpublic static final String MY_INT_COLUMN = \"int\";\n\n\t@Column(Type.TEXT)\n\tpublic static final String MY_STRING_COLUMN = \"string\";\n\n\t@ContentUri\n\tpublic static final Uri CONTENT_URI = Uri.parse(\"content://com.myapp/table_name\");\n}\n```\n\n* Extend the ProviGenProvider.\n\n```java\npublic class MyContentProvider extends ProviGenProvider {\n\n    private static Class[] contracts = new Class[]{MyContract.class};\n\n    @Override\n    public SQLiteOpenHelper openHelper(Context context) {\n        return new ProviGenOpenHelper(getContext(), \"dbName\", null, 1, contracts);\n    }\n\n    @Override\n    public Class[] contractClasses() {\n        return contracts;\n    }\n}\n```\n\n* Add your provider in your manifest.\n\n```xml\n\u003cprovider\n    android:name=\"com.myapp.MyContentProvider\"\n    android:authorities=\"com.myapp\" \u003e\n\u003c/provider\u003e\n```\n\n* You're done.\n\n## Usage\n\nYou can make the usual insert, update, delete and query using a [ContentResolver].    \nFor example querying a single row boils down to:\n```java\ngetContentResolver().query(\t\n\tUri.withAppendedPath(MyContract.CONTENT_URI, myId),\n\tnull, \"\", null, \"\");\n```\nor \n```java\ngetContentResolver().query(\n\tMyContract.CONTENT_URI, null, \n\tMyContract._ID + \" = ? \", new String[]{ myId }, \"\");\n```\n\n## Features\n\n### Table creation and contract upgrades\n\nProviGen comes with an implementation of the [SQLiteOpenHelper] called `ProviGenOpenHelper`.\nThis default implementation will\n\n* automatically create the needed tables on the first application launch\n* automatically add missing columns every time the database version increases\n\n### Notifications and observers\n\nProviGen fully supports the uri notification mechanism.   \nYou can safely use it with [CursorLoader]s and [ContentObserver]s.\n\n### Custom SQLiteOpenHelper\n\nYou can provide your own implementation of the [SQLiteOpenHelper] for initial population, complex contract upgrades\nor anything else database related you want to achieve.\n\n```java\npublic class MyContentProvider extends ProviGenProvider {\n\n    @Override\n    public Class[] contractClasses() {\n        return new Class[]{MyContract.class};\n    }\n\n    @Override\n    public SQLiteOpenHelper openHelper(Context context) {\n    \n        return new SQLiteOpenHelper(getContext(), \"databaseName\", null, 1) {\n        \n            @Override\n            public void onCreate(SQLiteDatabase database) {\n                // Automatically creates table and needed columns.\n                new TableBuilder(MyContract.class).createTable(database);\n\n                // Do initial population here.\n            }\n\n            @Override\n            public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {\n                // Automatically adds new columns.\n                TableUpdater.addMissingColumns(database, MyContract.class);\n\n                // Anything else related to database upgrade should be done here.\n            }\n        };\n    }\n}\n```\n\n### Data constraint\n\nYou can apply a `UNIQUE` or a `NOT_NULL` constraint to a column using the appropriate `TableBuilder` methods.\n\n```java\nnew TableBuilder(MyContract.class)\n        .addConstraint(MyContract.MY_INT, Constraint.UNIQUE, OnConflict.ABORT)\n        .addConstraint(MyContract.MY_STRING, Constraint.NOT_NULL, OnConflict.IGNORE)\n        .createTable(database);\n```\n\n## License\n\nThis content is released under the MIT License.\n\n[SQLiteOpenHelper]: https://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html\n\n[ContentObserver]: https://developer.android.com/reference/android/database/ContentObserver.html\n\n[CursorLoader]: http://developer.android.com/reference/android/content/CursorLoader.html\n\n[ContentProvider]: https://developer.android.com/reference/android/content/ContentProvider.html\n\n[ContractClass]: http://developer.android.com/guide/topics/providers/content-provider-basics.html#ContractClasses\n\n[ContentResolver]: https://developer.android.com/reference/android/content/ContentResolver.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimotheejeannin%2Fprovigen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimotheejeannin%2Fprovigen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimotheejeannin%2Fprovigen/lists"}