How to import/export app engine data

cloudCMS has XML based data exchange API which you can use to import/export data into app engine.

XML Structure for data import

The XML structure for importing data into app engine is very easy to generate and use. It can be used to update existing entities or add new entities to the system.
Following is example of demo Entity called "AddressBook" showing all possible data types supported by import tool.

<?xml version="1.0" encoding="UTF-8"?>
<entity kind="AddressBook">
<row>
       <property id="personName" type="string">
         <value>test User</value>
       </property>
       <property id="dob" type="date">
         <value>1980-05-27</value>
       </property>
       <property id="isFamily" type="boolean">
         <value>true</value>
        </property>
        <property id="comment" type="text">
         <value>Some comment here</value>
        </property>

         <property id="age" type="long">
         <value>29</value>
        </property>

         <property id="lastModified" type="timestamp">
         <value>2009-07-15 18:10:30</value>
        </property>

         <property id="website" type="link">
         <value>http://example.com</value>
        </property>

         <property id="height" type="double">
         <value>5.9</value>
        </property>

</row>
<!-- next row property and so on-->
<row>

</row>
</entity>


Import with update action

If you provide "id" attribute for a row, the import tool will update the row with given id.

<?xml version="1.0" encoding="UTF-8"?>
<entity kind="AddressBook">
<row id="1001"> 
<!-- property tags -->
</row>

In above example, import tool will update the row where id is 1001.

Entity group

To create a entity group use "parent" and "parentId" attributes.
<?xml version="1.0" encoding="UTF-8"?>
<entity kind="Phone" parent="AddressBook">
<row parentId="1001"> 
         <property id="home" type="string">
         <value>555-222-2222</value>
        </property>
        <property id="mobile" type="string">
         <value>555-222-3333</value>
        </property>
</row>

The "AddressBook" is parent of "Phone" entity and new Phone row's parent is row with id 1001 of AddressBook.


Export data

To export any entity or any data use cloudCMS's data exchange format which can be used to import data back into the cloudCMS system.

For example, following code will export all data from "test_GuestBook" Entity of demo GuestBook application.

<?xml version="1.0" encoding="UTF-8"?>
<entity kind="test_GuestBook">
  <@listEntity kind="test_GuestBook"  limit=100 offset=0 ; row,index,size >
  <row>
       <property id="guestname" type="string">
         <value>${row.guestname?xml}</value>
        </property>
       <property id="message" type="string">
         <value>${row.message?xml}</value>
        </property>
        <property id="dateAdded" type="date">
         <value>${row.dateAdded?datetime?string("yyyy-MM-dd")}</value>
        </property>
  </row>
</@listEntity>
</entity>

Click here to see exported XML.

Export Any Entity


Following is the example of generic entity exporter,
<?xml version="1.0" encoding="UTF-8"?>
<entity kind="GuestBook">
  <@listEntity kind="test_GuestBook"
  limit=100 offset=0 ; row,index,size >
  <#if index == 0><!-- Total rows : ${size} --></#if>
  <row>
      <#assign keys=row.value?keys>
      <#list keys as propname> 
       <property id="${propname}" type="${row.type[propname]}">
         <#assign val=row.value[propname]!'null'>
         <#if val?is_date>
         <value>${val?datetime?string("yyyy-MM-dd")}</value>
         </#if>
        <#if val?is_number>
         <value>${val?c}</value>
         </#if>
        <#if val?is_boolean>
         <value>${val?string}</value>
         </#if>
        <#if val?is_string>
         <value>${val?xml}</value>
         </#if>
         <#if val?is_sequence>
         <value>[<#list val as val_v>${val_v?xml}<#if val_v_has_next>,</#if></#list>]</value>
         </#if>
        </property>
      </#list>
  </row>
</@listEntity>
</entity>


blog comments powered by Disqus

Last Modified : Jul 27, 2009 10:14:29 AM