2.0-RC pushed to maven

113 views
Skip to first unread message

John Patterson

unread,
Nov 9, 2012, 12:14:07 AM11/9/12
to twig-p...@googlegroups.com
Just pushed 2.0-rc to the twig maven repo and the downloads page:


Major change: it is now compulsory to register persistent classes before using them - an Exception will be thrown that helps you find which classes are not.

This should only be done once so a good place to do it might be your data manager class or ObjectDatastore subclass in a static initialiser.

public class MyObjectDatastore extends StandardObjectDatastore
{
static
{
ObjectDatastoreFactory.register(Business.class);
ObjectDatastoreFactory.register(Customer.class);
ObjectDatastoreFactory.register(Account.class);
}
}

This means that you will never get kind names in the datastore like com_example_project_Foo anymore.

Also, the new batching feature is pretty useful



And the @Version annotation is super cool!  It automatically keeps a "version" property on your entity (not needed in your model class) which is checked and incremented every time an instance is updated.


John

Sydney

unread,
Nov 9, 2012, 4:09:54 AM11/9/12
to twig-p...@googlegroups.com
"This means that you will never get kind names in the datastore like com_example_project_Foo anymore."

Is it a problem if you already have in the datastore existing entities of kind com_example_project_Foo?

Miroslav Genov

unread,
Nov 9, 2012, 4:12:00 AM11/9/12
to twig-p...@googlegroups.com
I think so, so you probably have to run map-reduce job to clone entities in another entity group and also if you have Parent->Child relationship with that entity to fix keys that are referencing it.
--
Regards,
  Miroslav Genov

John Patterson

unread,
Nov 9, 2012, 5:52:32 AM11/9/12
to twig-p...@googlegroups.com

On 9/11/2012, at 4:09 PM, Sydney wrote:

> "This means that you will never get kind names in the datastore like com_example_project_Foo anymore."
>
> Is it a problem if you already have in the datastore existing entities of kind com_example_project_Foo?


No, just declare the name explicitly using:

@Entity(kind="com_blah..")

Werner Mahalek

unread,
Nov 12, 2012, 7:56:49 AM11/12/12
to twig-p...@googlegroups.com
Hello,

I have a question regarding the new annotation @Version. Is it possible to access the value of the version "property" from "inside" of the annotated entity? Something like:
@Version
class A {
  public long getVersion() {
    ...
  }
}

Thanks!
Werner

John Patterson

unread,
Nov 12, 2012, 8:07:37 AM11/12/12
to twig-p...@googlegroups.com
I haven't actually tried it but I think it should work to have a field in your entity class called "version" (this name can be changed in the annotation e.g. @Version("number")).  So I think the answer is yes.  Let me know if it works!

Werner Mahalek

unread,
Nov 19, 2012, 4:47:24 PM11/19/12
to twig-p...@googlegroups.com
Hello John,

thank you for answering so fast and please excuse me for taking so long to get back (I was away).

I wrote a short test:
@Entity(kind = "TestEntity")
@Version
public class TestEntity {
    private long version;
    
    public long getVersion() {
        return this.version;
    }
}

public class TestObjectDatastore extends AnnotationObjectDatastore {
    static {
        ObjectDatastoreFactory.register(TestEntity.class);
    }
    
    public TestObjectDatastore() {
        super(false);
    }
}

public class TestService {
    public void execute() {
        long version;
        ObjectDatastore datastore = new TestObjectDatastore();
        
        TestEntity testEntity = datastore.load(datastore.store(new TestEntity()));
        version = testEntity.getVersion();       // version = 0; Datastore Viewer: version = 1
        version = datastore.version(testEntity); // version = 1; Datastore Viewer: version = 1
        
        datastore.update(testEntity);
        version = testEntity.getVersion();       // version = 0; Datastore Viewer: version = 2
        version = datastore.version(testEntity); // version = 1; Datastore Viewer: version = 2 
    }
}

As you can see in the comments in TestService I couldn't get the version of the entity from "inside" of it. What's even more curious is that the second call of datastore.version(testEntity) returned "1" again (instead of "2"). Am I doing something wrong?

Thanks again.
Werner

John Patterson

unread,
Nov 19, 2012, 8:51:20 PM11/19/12
to twig-p...@googlegroups.com
Ah yes good point, the version field is not yet updated with the new version number which is causing this problem.

Actually, I designed this feature without expecting to have a "version" field.  

So it looks like the actual field value (which is incorrectly not updated) is somehow interfering with the number from the datastore.  I'll look into it because this would be very handy for sending the version to a client (e.g. GWT).

I use a hacked version of GWT-RPC to send the version and Key of any persistent instance to the client in the encoded data.  It seems to be working well so I will soon make that publicly available.

Also note that the @Entity("TestEntity") is not strictly required now.  This simple name of the class will be used by default when you register the class.  This will still work if the class is refactored to a new package (better than before when the package name was included) but would need to be explicitly added if you rename the class or have two classes with the same simple name.

John Patterson

unread,
Nov 19, 2012, 10:09:38 PM11/19/12
to twig-p...@googlegroups.com
Ok, I've fixed the problem (more than one!) and checked in an updated test case:


This check-in actually contains a lot of other fixes and improvements all clumped into a single commit because I use git locally and have not been using hg-git during recent checkins.

Werner Mahalek

unread,
Nov 20, 2012, 1:04:10 AM11/20/12
to twig-p...@googlegroups.com
Wow, great! Thank you very much!

Werner

Rémi BOURGAREL

unread,
Nov 28, 2012, 4:52:35 PM11/28/12
to twig-p...@googlegroups.com
John,

I had a few problems trying to run Twig, so I'd like to share here my experience.

Twig need Guava, but it's guava 10 (guava 10+ will raise an exception like Illegal access to a method). You can find it here : http://code.google.com/p/guava-libraries/wiki/Release10

Also the error message when a class is not registred is "Unregistred type class"

I looked for a solution about it (the documentation for v2 doesn't mention it) until I finally decide to get the code from the repo, change branch (where is the v2 branch on the google code site ?) and explore the test source code.

Anyway  it seems like a good job here, congrats !

John Patterson

unread,
Nov 28, 2012, 11:09:53 PM11/28/12
to twig-p...@googlegroups.com

On 29/11/2012, at 4:52 AM, Rémi BOURGAREL wrote:

> John,
>
> I had a few problems trying to run Twig, so I'd like to share here my experience.

Cheers. I need to update the docs
>
> Twig need Guava, but it's guava 10 (guava 10+ will raise an exception like Illegal access to a method). You can find it here : http://code.google.com/p/guava-libraries/wiki/Release10

Yes I have also run into this where I want some features from the latest guava. The latest guava uses a Cache builder instead or CacheMaker or something.

> Also the error message when a class is not registred is "Unregistred type class"

Ah ok, it should print out the class name?

You will need to call ObjectDatastoreFactory.register(MyClass.class) before using it.

>
> I looked for a solution about it (the documentation for v2 doesn't mention it) until I finally decide to get the code from the repo, change branch (where is the v2 branch on the google code site ?) and explore the test source code.
>
> Anyway it seems like a good job here, congrats !

Cheers!

Rémi BOURGAREL

unread,
Nov 30, 2012, 11:04:26 AM11/30/12
to twig-p...@googlegroups.com
Yes it's printing the class name. 
I was just pointing out that there is no documentation about this error message, I googled "Unregistred type class" + twig and nothing popped (even source code). 
Is there any way to read the source code without hg ? I can't find it on the google code website.

Rémi

John Patterson

unread,
Nov 30, 2012, 11:10:21 AM11/30/12
to twig-p...@googlegroups.com
Yeah its all here 


The trick is to select Branch v2.0 from the drop down.  Its not a very clear UI.

Also, you can download the source jar from the downloads page or use m2eclipse which will download it for you and set it up so you can step into the code.
Reply all
Reply to author
Forward
0 new messages