开发者

GQL query for <missing>

开发者 https://www.devze.com 2023-01-14 20:22 出处:网络
When you change data models on the app engine to add new properties those entries without a certain prope开发者_StackOverflow社区rty are listed with the value <missing> in the online data viewer

When you change data models on the app engine to add new properties those entries without a certain prope开发者_StackOverflow社区rty are listed with the value <missing> in the online data viewer.

What I'm wondering is how can I write a query to find those entries?


There is no direct way to query for older entities with missing attribute, but you can design data model upfront to support this. Add a version attribute to each model class. Version should have a default value, which is increased every time model class is changed and deployed. This way you will be able to query entities by version number.


There's no way to query the datastore for entities that don't have a given property. You need to iterate over all the entities and check each one - possibly by using the mapreduce API.


Or you could create a script to stick null in there for all current items that don't have that property using the low level datastore API, so then you can query on null.

I had this issue and that's how I solved it. The rough code would look like:

DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        Query query = new Query("JDOObjectType");
        List<Entity> results = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(9999));

        for (Entity lObject : results) {
            Object lProperty = lObject.getProperty("YOUR_PROPERTY");
            if (lProperty == null) {
                lObject.setProperty("YOUR_PROPERTY", null);
                datastore.put(lProperty);
            }
        }

    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号