MCPcopy Index your code
hub / github.com/TimotheeJeannin/ProviGen

github.com/TimotheeJeannin/ProviGen @2.0.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release 2.0.1 ↗ · + Follow
112 symbols 309 edges 22 files 19 documented · 17%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ProviGen Build Status

Easily make a ContentProvider from a ContractClass.

Setup

public interface MyContract extends ProviGenBaseContract {

    @Column(Type.INTEGER)
    public static final String MY_INT_COLUMN = "int";

    @Column(Type.TEXT)
    public static final String MY_STRING_COLUMN = "string";

    @ContentUri
    public static final Uri CONTENT_URI = Uri.parse("content://com.myapp/table_name");
}
  • Extend the ProviGenProvider.
public class MyContentProvider extends ProviGenProvider {

    private static Class[] contractClasses = new Class[]{MyContract.class};

    @Override
    public SQLiteOpenHelper openHelper(Context context) {
        return new ProviGenOpenHelper(getContext(), "dbName", null, 1, contractClasses);
    }

    @Override
    public Class[] contractClasses() {
            return contractClasses;
    }
}
  • Add your provider in your manifest.
<provider
    android:name="com.myapp.MyContentProvider"
    android:authorities="com.myapp" >
</provider>
  • You're done.

Usage

You can make the usual insert, update, delete and query using a ContentResolver.
For example querying a single row boils down to:

getContentResolver().query( 
    Uri.withAppendedPath(MyContract.CONTENT_URI, myId),
    null, "", null, "");

or

getContentResolver().query(
    MyContract.CONTENT_URI, null, 
    MyContract._ID + " = ? ", new String[]{ myId }, "");

Features

Table creation and contract upgrades

ProviGen comes with an implementation of the SQLiteOpenHelper called ProviGenOpenHelper. This default implementation will

  • automatically create the needed tables on the first application launch
  • automatically add missing columns every time the database version increases

Notifications and observers

ProviGen fully supports the uri notification mechanism.
You can safely use it with CursorLoaders and ContentObservers.

Custom SQLiteOpenHelper

You can provide your own implementation of the SQLiteOpenHelper for initial population, complex contract upgrades or anything else database related you want to achieve.

public class MyContentProvider extends ProviGenProvider {

    @Override
    public Class[] contractClasses() {
        return new Class[]{MyContract.class};
    }

    @Override
    public SQLiteOpenHelper openHelper(Context context) {
        return new SQLiteOpenHelper(getContext(), "databaseName", null, 1) {
            @Override
            public void onCreate(SQLiteDatabase database) {
                // Automatically creates table and needed columns.
                new TableBuilder(MyContract.class).createTable(database);

                // Do initial population here.
            }

            @Override
            public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
                // Automatically adds new columns.
                TableUpdater.addMissingColumns(database, MyContract.class);

                // Anything else related to database upgrade should be done here.
            }
        };
    }
}

Data constraint

You can apply a UNIQUE or a NOT_NULL constraint to a column using the appropriate TableBuilder methods.

new TableBuilder(MyContract.class)
        .addConstraint(MyContract.MY_INT, Constraint.UNIQUE, OnConflict.ABORT)
        .addConstraint(MyContract.MY_STRING, Constraint.NOT_NULL, OnConflict.IGNORE)
        .createTable(database);

License

This content is released under the MIT License.

Extension points exported contracts — how you extend this code

ProviGenBaseContract (Interface)
Base interface for a ProviGenProvider contract.
ProviGen/src/com/tjeannin/provigen/ProviGenBaseContract.java
ContractOne (Interface)
(no doc)
ProviGenTests/src/com/tjeannin/provigen/test/multiple/MultipleContractContentProvider.java
Person (Interface)
(no doc)
ProviGenSample/src/com/tjeannin/provigen/sample/SampleContentProvider.java
ContractTwo (Interface)
(no doc)
ProviGenTests/src/com/tjeannin/provigen/test/multiple/MultipleContractContentProvider.java
ContractOne (Interface)
(no doc)
ProviGenTests/src/com/tjeannin/provigen/test/basis/SimpleContentProvider.java
ContractTwo (Interface)
(no doc)
ProviGenTests/src/com/tjeannin/provigen/test/basis/SimpleContentProvider.java
ContractAbort (Interface)
(no doc)
ProviGenTests/src/com/tjeannin/provigen/test/constraint/OnConflictProvider.java

Core symbols most depended-on inside this repo

insert
called by 36
ProviGen/src/com/tjeannin/provigen/ProviGenProvider.java
getTable
called by 18
ProviGen/src/com/tjeannin/provigen/model/Contract.java
addConstraint
called by 9
ProviGen/src/com/tjeannin/provigen/helper/TableBuilder.java
createTable
called by 8
ProviGen/src/com/tjeannin/provigen/helper/TableBuilder.java
getIdField
called by 7
ProviGen/src/com/tjeannin/provigen/model/Contract.java
query
called by 6
ProviGen/src/com/tjeannin/provigen/ProviGenProvider.java
findMatchingContract
called by 5
ProviGen/src/com/tjeannin/provigen/ProviGenProvider.java
delete
called by 4
ProviGen/src/com/tjeannin/provigen/ProviGenProvider.java

Shape

Method 79
Class 20
Interface 13

Languages

Java100%

Modules by API surface

ProviGenTests/src/com/tjeannin/provigen/test/basis/SimpleContentProviderTest.java12 symbols
ProviGen/src/com/tjeannin/provigen/ProviGenProvider.java11 symbols
ProviGenTests/src/com/tjeannin/provigen/test/constraint/OnConflictProvider.java9 symbols
ProviGenTests/src/com/tjeannin/provigen/test/constraint/OnConflictTest.java8 symbols
ProviGenTests/src/com/tjeannin/provigen/test/constraint/ConstraintsProvider.java8 symbols
ProviGenTests/src/com/tjeannin/provigen/test/ExtendedProviderTestCase.java8 symbols
ProviGenSample/src/com/tjeannin/provigen/sample/MainActivity.java7 symbols
ProviGen/src/com/tjeannin/provigen/model/Contract.java6 symbols
ProviGenTests/src/com/tjeannin/provigen/test/multiple/MultipleContractContentTest.java5 symbols
ProviGenTests/src/com/tjeannin/provigen/test/multiple/MultipleContractContentProvider.java5 symbols
ProviGenTests/src/com/tjeannin/provigen/test/constraint/ConstraintsTest.java5 symbols
ProviGenTests/src/com/tjeannin/provigen/test/basis/SimpleContentProvider.java5 symbols

For agents

$ claude mcp add ProviGen \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page