Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [dali-dev] JPA contex model refresh

Title: JPA contex model refresh
Milen,

for reasonably predictable JUnit testing, you will need to configure your test JpaProject
to use a synchronous updater. The default JpaProject uses an asynchronous updater
that synchronizes the context model with the resource model (your Java source) in a
background job whenever changes occur (e.g. adding a Java source file). When you
construct your JpaProject you will need some code like this:

    jpaProject.setUpdater(new SynchronousJpaProjectUpdater(jpaProject));

This will keep you context model in synch with your resource model synchronously.
So, when you change a resource the context model should be in synch upon return
from the method.

I hope this is what you need. :-)

Brian

Manov, Milen wrote:

Hello colleagues,

 I am writing a junit test in which I create an IFile with content looking something like this

String content = "package " + packageName + ";\n\n"
                                        + "import javax.persistence.*;\n\n"
                                        + "@Entity \n"
                                        + "public class " + entityShortName + " {\n"
                                        + "     @Id \n"                                
                                        + "     private int id;\n"
                                        + "     public int getId() {\n"
                                        + "             return id;\n"
                                        + "     }\n"
                                        + "     public void setId(int id) {\n"
                                        + "             this.id = id;\n"
                                        + "     }\n"
                                        + "}"; //$NON-NLS-1$

Then I try to acquire the PersistenType using

for (Iterator<JpaStructureNode> i = jpaFile.rootStructureNodes(); i.hasNext(); ) {
                        JpaStructureNode node = i.next();
                        if(node instanceof JavaPersistentType){
                                JavaPersistentType entity = (JavaPersistentType) node;
                                return entity;
                        }
                }

On some occasions the returned result is null.

My question is - is there a way to make sure that the context jpa model is refreshed, or if I can get the JavaPersistentType in some other way, that will ensure I will receive constant results.

Thanks in advance,
Milen


_______________________________________________ dali-dev mailing list dali-dev@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/dali-dev


Back to the top