Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add batch with db transaction #4

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Shusshu
Copy link
Contributor

@Shusshu Shusshu commented Mar 27, 2013

Ability for the ProviGenProvider to execute a bunch of insert/delete/update within a database transaction

@Shusshu
Copy link
Contributor Author

Shusshu commented Mar 27, 2013

Oups I just saw my commit changed the whole file... this is not normal...

I only added 1 method at the end :
@OverRide
public ContentProviderResult[] applyBatch(ArrayList operations) throws OperationApplicationException {

@TimotheeJeannin
Copy link
Owner

Hi @Shusshu,

Thank you for this pull request.

Can you clarify what the db.yieldIfContendedSafely(); is for ?

Can you make your commit not change the whole file ?

Adding javadoc and matching current code style would appreciated too. :)

Tim

@Shusshu
Copy link
Contributor Author

Shusshu commented Mar 29, 2013

Hello,

I don't get it I apply your code formatter but it just doesn't change anything, actually I didn't even change the formatting so I have no idea why the whole file is marked as changed

About db.yieldIfContendedSafely() it is supposed to be able to let other threads use the db during that transaction

…ure-batch

Conflicts:
	ProviGen/src/com/tjeannin/provigen/ProviGenProvider.java
@Shusshu
Copy link
Contributor Author

Shusshu commented Apr 18, 2013

updated to have a nice diff

@Shusshu
Copy link
Contributor Author

Shusshu commented Feb 28, 2014

Any plan to include this soon?

@TimotheeJeannin
Copy link
Owner

Hi @Shusshu,

The idea behind ProviGen is:

Annotate a ContractClass and ProviGen will provide a ContentProvider for that contract.

There is already a default implementation of the applyBatch method:

public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
        throws OperationApplicationException {
    final int numOperations = operations.size();
    final ContentProviderResult[] results = new ContentProviderResult[numOperations];
    for (int i = 0; i < numOperations; i++) {
        results[i] = operations.get(i).apply(this, results, i);
    }
    return results;
}

Using transactions is a great way to improve performance of the executed ContentProviderOperations, and I agree overriding the applyBatch method is the right way to go if the application heavily uses ContentProviderOperations. But I feel like it's more the developer's responsibility to override the applyBatch method than ProviGen's responsibility.

It's a bit as if ProviGen was : A library to generate a ContentProvider from a ContractClass and also it will override the applyBatch method to use transactions ... it sounds a bit weird ...

See issue #28, I would like to discuss the overall organisation of ProviGen regarding more advances features like transactions.

@Shusshu
Copy link
Contributor Author

Shusshu commented Mar 3, 2014

Yes you make a good point there :)
I'll read the other issues

@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
SQLiteDatabase db = openHelper.getWritableDatabase();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In ProviGen 2.0.0
SQLiteDatabase db = openHelper(getContext()).getWritableDatabase();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants