home | non-tech | cs | ee | about
Abstract New

Setting up datastore-indexes.xml in App Engine – Java

Database Indexes are data structures that help speed up data retrieval. Similar to indexes in books, they help you find the reference quickly. They also suffer from the same disadvantage - they take up space.
App Engine has built-in indexes that can handle simple queries. Indexes for complex queries need to be generated and stored in a file called datastore-indexes.xml.
Creating the datastore-indexes.xml
Add a file named datastore-indexes.xml on to the web-inf directory. This is where App Engine indexes will be stored. Include the following in the xml file
<?xml version="1.0" encoding="UTF-8"?>
<datastore-indexes  autoGenerate="true">
</datastore-indexes> 
Setting autoGenerate = “true”
The App Engine development server makes life easier for us by determining index configurations for queries run in the development server. Every time the application issues a successful query to the datastore in the development environment you will see the datastore-indexes-auto.xml being updated with the index configuration corresponding to these queries. Simple queries will not be reflected in the datastore-indexes.xml file since App Engine has built-in indexes that can handle such queries.
The datastore-indexes-auto.xml file is rewritten every time you start a new session. Once you test your application and generate all the corresponding indexes copy the contents of the datastore-indexes-auto.xml to datastore-indexes.xml.
Sample Query in JDOQL for a table with columns - firstname, lastname and Salary
SELECT * FROM yourdatatable 
WHERE firstname == ‘John’ && lastname == ‘Doe’ &&  Salary < 1000
The corresponding configuration generated in datastore-index-auto.xml
<datastore-index kind=" yourdatatable " ancestor="false" source="auto">
        <property name="firstname" direction="asc"/>
        <property name="lastname" direction="asc"/>
        <property name="Salary" direction="asc"/>
 </datastore-index>
Once you deploy your application onto App Engine you can view the stored index configurations on the admin console by clicking on Indexes under Datastore.

4 comments:

Anonymous said...

Thx

Anonymous said...

"Simple queries will not be reflected in the datastore-indexes.xml"

What is the meaning of Simple Queries

Gideon Bar said...

I create the datastore-indexes.xml:









Now I get an error deploying the project:

An internal error occurred during: "Deploying server MFF_Site7.47 to Google".
XML error validating C:\Users\Gideon\Desktop\dev3\workspace\server MFF_Site7.47\war\WEB-INF\datastore-indexes.xml against C:\Users\Gideon\Desktop\dev3\eclipse\plugins\com.google.appengine.eclipse.sdkbundle_1.8.2\appengine-java-sdk-1.8.2\docs\datastore-indexes.xsd

author said...

Do you have an xmlns tag in the XML. If so try removing that and test.

Post a Comment

© 2014 - 2015 abstract new. All rights reserved.