DevFaqJavaModelTransactionLock

What is the transaction lock and when should I use it?

Note: This FAQ item applies only to NetBeans 4.x and 5.x. The Java parsing infrastructure in NetBeans 6 has been replaced with a new API.

It is a lock that allows code to either access/analyze structural elements of java sources, or modify them. If you access the model, you need to acquire the transaction lock - it guarantees that no modifications will be made to the model by other code/threads while your code is in it. If you're seeing InvalidObjectException</tt>s, you're probably accessing model objects outside of the transaction lock.

Here is how it is typically used for write access:

        JavaModel.getJavaRepository().beginTrans(true); // true = write transaction
        boolean rollback = true;
        try {
            //do something
            // ....
            // if everything succeeded
            // set rollback to false
            rollback = false;
        } finally {
            JavaModel.getJavaRepository().endTrans(rollback);
        }

Here is how it is typically used for read access:

        JavaModel.getJavaRepository().beginTrans(false); // false = read transaction
        try {
            //do something
        } finally {
            JavaModel.getJavaRepository().endTrans();
        }
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo