<?php require_once( dirname(dirname(dirname( __FILE__ ))) . '/wp-load.php' ); ?>
<!-- START of header -->
<?php get_header(); ?>
<!-- END of header -->

<!-- warapper -->

<div class="docs-content">
<!-- START of page navigation -->
<?php get_template_part( 'docs_navigation' ); ?>
<!-- END of page navigation -->
<!-- START of pusher -->
<div class="docs-content-body">
<div id="content" class="docs-content-body__inner">

<h1 class="title">5.1.11 Collection Modification</h1>
<h2 id="overview">Overview</h2>
<p>This section describes modifying the schema and the index of a GridDB collection.</p>
<p><br/></p>
<h2 id="schema-modification">Schema Modification</h2>
<p>You can modify the schema by adding or deleting columns in a container after the container has been created.<br>
This example demonstrates how to modify a newly created class with a new column in addition to <code>WeatherStation</code> class.<br>
In addition, there is a way to modify the schema without creating a new class. Please refer to <a href="5-1-22_metainfo.php">Meta-information</a> for more details.</p>
<strong> List.1 Modified Class</strong> (AnotherWeatherStation.java)
<pre class="prettyprint linenums">
package sample.row;

import com.toshiba.mwcloud.gs.RowKey;

public class AnotherWeatherStation {
    / **
    * ID of WeatherStation
    * /
    @RowKey
    public String id;

    / **
    * Name of WeatherStation
    * /
    public String name;

    / **
    * Installation Latitude
    * /
    public double latitude;

    / **
    * Installation Longitude
    * /
    public double longitude;

    / **
    * Camera exists or not
    * /
    public boolean hasCamera;

    / **
    * Added field to WeatherStation
    * /
    public String description;
}
</pre>
<ul>
<li>L.35: The newly added column.</li>
</ul>
<p>In the case creating a new collection, the <code>GridStore.putCollection(String, Class)</code> method is used, and the case modifying schema of column, the method with parameters of modification options <code>GridStore.putCollection(String, Class, boolean)</code> is used.
</p>
<strong> List.2 putCollection Method </strong>
<pre class="prettyprint">
&lt; K, R &gt; Collection &lt; K, R &gt; putCollection (java.lang.String name,
                                    java.lang.Class &lt; R &gt; rowType,
                                    boolean modifiable)
                                    throws GSException
</pre>
<p>You can modify a schema of an existing collection with setting the modifiable parameter to true.<br>
However there are several conditions in order to modify. Please refer to <a href="../GridDB_API_Reference.html">GridDB API Reference</a> for more information.</p>
<strong>List.3 Modifying the collection to be added a new column</strong> (CollectionModify.java)
<pre class="prettyprint linenums:28">
// Modify ano ther schema Collection
Collection <String, AnotherWeatherStation> ano therWeatherStationCol =
        store.putCollection("weather_station", AnotherWeatherStation.class, <span style="font-weight: bold">true </ span>);
</pre>
<ul>
<li>L.29-30: Set the <code>modifiable</code> paramater to true.</li>
</ul>
<p><br/></p>
<h2 id="add-an-index">Add an Index</h2>
<p>You can set an Index to column in GridDB identically with general RDB.</p>
<strong> List.4 Adding an Index</strong> (CollectionIndex.java)
<pre class="prettyprint linenums:33">
// Create Index
weatherStationCol.createIndex("id");
weatherStationCol.createIndex("name", IndexType.TREE);
</pre>
<ul>
<li>L.34: Add an index with specifying a column name id of the measuring instrument ID with <code>Container.createIndex(String)</code> method.</li>
<li>L.35: Add ab index specifying a column name of the measuring instrument name with <code>Container.createIndex(String, IndexType)</code> method and set <code>IndexType.TREE</code> to the index type.</li>
</ul>
<p>Types of indexes are as follows:</p>
<p><strong> Table.1 Index types </strong></p>
<div class="griddb">

</div>
<table>
<thead>
<tr class="header">
<th style="text-align: left;">Index type</th>
<th style="text-align: left;">Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">HASH</td>
<td style="text-align: left;">High speed retrieval, but not suitable for the operation of reading Row sequentially and impossible to set in the TimeSeries container.</td>
</tr>
<tr class="even">
<td style="text-align: left;">TREE</td>
<td style="text-align: left;">It is suitable for a retrival specifying that whether the value is larger or smaller than a retrieval vulue to a retrieval range.</td>
</tr>
</tbody>
</table>

<p>There are index types which can not be specified owing to the container type or the column type. Please refer to <a href="../GridDB_API_Reference.html">GridDB API Reference</a> and <a href="../GridDB_TechnicalReference.pdf">GridDB Technical Reference</a> for more information.</p>
<p><br/></p>
<h2 id="delete-an-index">Delete an Index</h2>
<p>Index set in the column can be deleted.</p>
<strong> List.5 Delete an Index</strong> (CollectionIndex.java)
<pre class="prettyprint linenums:37">
// Drop Index
weatherStationCol.dropIndex("id");
weatherStationCol.dropIndex("name");
</pre>
<ul>
<li>L.38-39: Delete an Index with the <code>Container.dropIndex (String)</code> method specifying column name set to the index.</li>
</ul>
<p><br/></p>
<h2 id="complete-source-code">Complete source code</h2>
<p>Complete source code used in this sample can be downloaded from the following.</p>
<p>Download: <a href="img/collection-modify.zip">collection_modify.zip</a></p>

</div>
</div>
</div>
</div>
</div>

<!-- / main -->

<?php get_footer(); ?>
