<?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.21 Multi-Get</h1>

<h2 id="what-is-multi-get">What is Multi-Get</h2>
<p>Note: The concept of Multi-Get is described in our <a href="/en/docs/GridDB_TechnicalReference.pdf">GridDB_TechnicalReference (Section 4.7.2) </a></p>
<h2 id="create-the-acquisition-conditions">Create the acquisition conditions</h2>
<strong>List.1 Create the acquisition conditions</strong>(MultiGet.java)
<pre class="prettyprint linenums:x">
private static Map&lt;String, RowKeyPredicate&lt;?&gt;&gt; createMultiGetCondition(
				Collection&lt;String, WeatherStation&gt; weatherStationCol)
				throws GSException, ParseException {
		SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm", Locale.US);

		// Create search condition of WeatherStation
		RowKeyPredicate&lt;String&gt; wsRowKeys = RowKeyPredicate.create(String.class);

		// Create multiget condition
		Map&lt;String, RowKeyPredicate&lt;?&gt;&gt; containerPredicateMap = new HashMap&lt;&gt;();
		for (int i = 0; i &lt; 2; i++) {
				// Get WeatherStation
				WeatherStation weatherStation = weatherStationCol.get(String.valueOf(i + 1));
				wsRowKeys.add(weatherStation.id);

				// Create search condition of InstrumentLog
				RowKeyPredicate&lt;Date&gt; logRowKeys = RowKeyPredicate.create(Date.class);
				// Set TimeSeries Rows Timestamp
				logRowKeys.setStart(format.parse("2016/07/02 6:00"));
				logRowKeys.setFinish(format.parse("2016/07/02 12:00"));
				// Add ContainerName and RowKeyPredicate
				String logContainerName = "weather_station_" + weatherStation.id;

				// Put multiget condition
				containerPredicateMap.put(logContainerName, logRowKeys);
		}
		// Put multiget condition
		String wsContainerName = "weather_station";
		containerPredicateMap.put(wsContainerName, wsRowKeys);
		return containerPredicateMap;
}
</pre>
<h2 id="multi-get-execution">Multi-Get execution</h2>
<strong>List.2 Multi-Get execution</strong>(MultiGet.java)
<pre class="prettyprint linenums:x">
// Create Connection
store = gridLogic.createGridStore();

// Get Collection
Collection&lt;String, WeatherStation&gt; weatherStationCol =
		store.getCollection("weather_station", WeatherStation.class);

// Create MultiGet parameters
Map&lt;String, RowKeyPredicate&lt;?&gt;&gt; containerPredicateMap =
		careteMultiGetCondition(weatherStationCol);

// Get by multiget
Map&lt;String, List&lt;Row&gt;&gt; multiGetResults = store.multiGet(containerPredicateMap);
</pre>
<h2 id="result-of-multi-get-execution">Result of Multi-Get execution</h2>
<strong>List.3 Obtain of Multi-Get results</strong>(MultiGet.java)
<pre class="prettyprint linenums:x">
// Retrieve results
for (Entry&lt;String, List&lt;Row&gt;&gt; multiGetResult : multiGetResults.entrySet()) {
// Container Name
String containerName = multiGetResult.getKey();
System.out.println(containerName + " ################");

if ("weather_station".equals(containerName)) {
		// Retrieve WeatherStation Rows
		retieveWeatherStationRows(multiGetResult);
} else {
		// Retrieve InstrumentLog Rows
		retrieveInstrumentLogRows(multiGetResult);
}
}
</pre>
<strong>List.4 Result of Multi-Get execution</strong>
<pre class="prettyprint linenums:x">
weather_station_2 ################
Timestamp                       WeatherStation ID       Temperature      Live Image
Sat Jul 02 06:00:00 JST 2016    weather_station_2       70.0            None
Sat Jul 02 09:00:00 JST 2016    weather_station_2       75.0            None
Sat Jul 02 12:00:00 JST 2016    weather_station_2       80.0            None
weather_station ################
ID      Name                    Longitude               Latitude        Camera
1       Hokkaido-Sapporo        43.06417                141.34694       true
2       Aomori-Aomori           40.82444                140.74          true
weather_station_1 ################
Timestamp                       WeatherStation ID       Temperature      Live Image
Sat Jul 02 06:00:00 JST 2016    weather_station_1       70.0            None
Sat Jul 02 09:00:00 JST 2016    weather_station_1       75.0            None
Sat Jul 02 12:00:00 JST 2016    weather_station_1       90.0            None
</pre>
<h2 id="source-code">Source Code</h2>
<p>Complete source code used in this sample can be downloaded from the following.</p>
<p>Download:<a href="img/multi-get.zip">multi-get.zip</a></p>
<p><br/></p>
</div>
</div>
</div>
</div>
</div>
<!-- / main -->

<?php get_footer(); ?>
