google-code-export / twig-persist

Automatically exported from code.google.com/p/twig-persist
1 stars 1 forks source link

make it easier/functional to delete entities by Key #47

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This is a followup to
http://groups.google.com/group/twig-persist/browse_thread/thread/c3e1...

For me,
datastore.getService().delete(key);
doesn't seem to have any effect. Reading the entity again in a null
variable sets it with data.

datastore.delete(entity);
works as expected.

Here's a test case, wrote blindly as twig2 doesn't compile for me
right now

        public void deleteKeyTest() {
                ObjectDatastore od = new AnnotationObjectDatastore();

                Restaurant restaurant = new Restaurant();
                restaurant.name = "test";
                Key restaurantKey = od.store(restaurant);

                Restaurant restaurant2;
                restaurant2 = od.load(restaurantKey);
                assertTrue("stored entity exists",
                                restaurant.name.equals(restaurant2.name));
                od.getService().delete(restaurantKey);
                restaurant2 = null;
                restaurant2 = od.load(restaurantKey);
                assertTrue("deleted entity exists", null == restaurant2);
        }

Please provide any additional information below.
In addition, would it be possible for twig to offer a "native" delete(Key key) 
implementation?

Even if behind all it does is getService().delete(key), having this
means twig offers full CRUD support. It would also have a unit test on
it, guaranteeing delete works on each release. 

Perhaps a delete() fluent command would be best for all the options.
 Similar to load()

od.delete().key(key).now() 

Original issue reported on code.google.com by marius.a...@gmail.com on 9 Nov 2010 at 7:44

GoogleCodeExporter commented 9 years ago

Original comment by jdpatterson on 10 Nov 2010 at 4:00