<?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.7 Container Creation and Deletion</h1>
<h2 id="overview">Overview</h2>
<p>This chapter describes how to create/delete GridDB containers.</p>
<p><br/></p>
<h2 id="collection-and-timeseries-container">Collection and Timeseries Container</h2>
<p>There are 2 container types, a <strong>timeseries container</strong> and a <strong>collection</strong>.</p>
<ul>
<li>Timeseries container
<ul>
<li>A container that specializes for data whcih is consisted of the pair of time and value, such as sensor data.</li>
<li>The TIMESTAMP data can be specified in a row key.</li>
<li>It is possible to acquire the data in a specified period of time or to aggregate the data.</li>
<li>Value can be linearly interpolated when register or retreive the data.</li>
</ul></li>
<li>Collection
<ul>
<li>Collection is a general purpose container.</li>
<li>Collection does not have any functions related to timeseries data, however it can be used with any data type in a key and it can be used in the same way as the other key-value database.</li>
</ul></li>
</ul>
<p>Here are some programming samples to create or delete each type of containers.</p>
<p><br/></p>
<h2 id="how-to-create-a-collection">How to create a Collection</h2>
<p>Collection can be created as follows.</p>
<strong>List.1 Creating a Collection</strong>(WeatherStationLogic.java)
<pre class="prettyprint linenums:33">
// Create Collection
Collection&lt;String, WeatherStation&gt; weatherStationCol =
        store.putCollection("weather_station", WeatherStation.class);
return weatherStationCol;
</pre>
<ul>
<li>L.34-35: Use <code>GridStore.putCollection(String, Class)</code> method to create a Collection.<br />
A container name should be specified to <code>String</code>, and <code>WeatherStation</code> class which can be created in chapter <a href="5-1-6_container-schema.php">Schema definition</a> should be set to <code>Class</code>.<br />
A created Collection will obtained as an instance of <code>com.toshiba.mwcloud.gs.Collection</code> class.</li>
</ul>
<p><br/></p>
<strong>List.2 Releasing a Collection</strong>(CollectionCreate.java)
<pre class="prettyprint linenums:181">
} finally {
    // Close Connection
    weatherStationCol.close();
}
</pre>
<ul>
<li>L.183: Use <code>Collection.close()</code> method to release associated resources by closing the created Collection.</li>
</ul>
<p><br></p>

<h2 id="how-to-create-a-timeseries-container">How to create a Timeseries Container</h2>
<p>Timeseries Container can be created as follows.</p>
<strong>List.3 Creating a Timeseries Container</strong>(InstrumentLogLogic.java)
<pre class="prettyprint linenums:135">
for (int i = 0; i &lt; WeatherStationLogic.JP_PREFECTURE; i++) {
    // Create TimeSeries Container
    TimeSeries&lt;InstrumentLog&gt; ts =
            store.putTimeSeries("weather_station_" + (i + 1), InstrumentLog.class);

    (snip)
}
</pre>
<ul>
<li>L.137-138: Use <code>GridStore.putTimeSeries(String, Class)</code> method to create a Timeseries Container.<br />
A Timeseries container name should be specified to <code>String</code>, and <code>InstrumentLog</code> class which can be created in chapter <a href="5-1-6_container-schema.php">Schema definition</a> should be set to <code>Class</code>.<br />
A created Timeseries Container will obtained as an instance of <code>com.toshiba.mwcloud.gs.TimeSeries</code> class.</li>
</ul>
<br/> <strong>List.4 Releasing a Timeseries Container</strong>(InstrumentLogLogic.java)
<pre class="prettyprint linenums:55">
// Close TimeSeries Container
ts.close();
</pre>
<ul>
<li>L.56: In the same manner as Collection, use <code>Collection.close()</code> method to release associated resources by closing the created Timeseries Container.</li>
</ul>
<p><br/></p>
<h2 id="how-to-delete-a-container">How to delete a Container</h2>
<strong>List.5 Deleting Collection</strong>(WeatherStationLogic.java)
<pre class="prettyprint linenums:45">
public void dropCollection(GridStore store) throws GSException {
    // Drop Collection
    store.dropCollection("weather_station");
}
</pre>
<ul>
<li>L.47: Use <code>GridStore.dropCollection(String)</code> method to delete a Collection.</li>
</ul>
<p><br/></p>
<strong>List.6 Deleting Timeseries Container</strong>(SampleTimeSeries.java)
<pre class="prettyprint linenums:67">
public void dropTimeSeries(GridStore store, String name) throws GSException {
    // Drop TimeSeries Container
    store.dropTimeSeries(name);
}
</pre>
<ul>
<li>L.69: Use <code>GridStore.dropTimeSeries(String)</code> method to delete a Timeseries Container.</li>
</ul>
<hr />
<p>This chapter provided how to create or delete 2 types of Container, a <strong>Collection</strong> and a <strong>Timeseries Container</strong>.<br />
Container can be easily created or deleted by simply preparing a container name and a class that represents the rows.</p>
<p>Here we describe only the static method of preparing a class that represents a row in advance, but there is a way to dynamically create a Container without providing a class.<br />
Please refer to <a href="5-1-22_metainfo.php">Meta-information</a> for more details.</p>
<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/container-create-drop.zip">container-create-drop.zip</a></p>
</div>
</div>
</div>
</div>
</div>
<!-- / main -->

<?php get_footer(); ?>
