Skip to content

Commit 43b5fce

Browse files
committed
update samples for 0.8
1 parent 386e77d commit 43b5fce

19 files changed

+629
-757
lines changed

sample/BlobData.php

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,49 @@
11
<?php
22
include('griddb_php_client.php');
33

4-
$factory = StoreFactory::get_default();
4+
$factory = StoreFactory::getInstance();
55

66
$containerName = "SamplePHP_BlobData";
77

88
try {
99
// Get GridStore object
10-
$gridstore = $factory->get_store(array("notificationAddress" => $argv[1],
11-
"notificationPort" => $argv[2],
10+
$gridstore = $factory->getStore(["host" => $argv[1],
11+
"port" => (int)$argv[2],
1212
"clusterName" => $argv[3],
13-
"user" => $argv[4],
14-
"password" => $argv[5]
15-
));
16-
17-
// When operations such as container creation and acquisition are performed, it is connected to the cluster.
18-
$gridstore->get_container("containerName");
19-
echo("Connect to Cluster\n");
13+
"username" => $argv[4],
14+
"password" => $argv[5]]);
2015

2116
// Create a collection container
22-
$col = $gridstore->put_container(
23-
$containerName,
24-
array(array("id" => GS_TYPE_INTEGER),
25-
array("blob" => GS_TYPE_BLOB)),
26-
GS_CONTAINER_COLLECTION
27-
);
17+
$conInfo = new ContainerInfo(["name" => $containerName,
18+
"columnInfoArray" => [["id", Type::INTEGER],
19+
["blob", Type::BLOB]],
20+
"type" => ContainerType::COLLECTION,
21+
"rowKey" => true]);
22+
23+
$col = $gridstore->putContainer($conInfo);
2824
echo("Create Collection name=$containerName\n");
2925

3026
// Register string data
31-
// (1)Read string data file
32-
$blobString = file_get_contents('BlobData.php');
33-
34-
// (2)Create and set row data
35-
$row = $col->create_row(); //Create row for refer
36-
$row->set_field_by_integer(0, 0);
37-
$row->set_field_by_blob(1, $blobString);
38-
39-
// (3)Put row
40-
$col->put_row($row);
27+
// (1)Get contents of a file into a string
28+
$filename = "sample/BlobData.php";
29+
$handle = fopen($filename, "rb");
30+
$blobString = fread($handle, filesize($filename));
31+
fclose($handle);
32+
33+
//(2)Register a row
34+
$col->put([0, $blobString]);
4135
echo("Put Row (Blob)\n");
4236

4337
// Get string data file from row
44-
// (1)Create an empty Row object
45-
$row1 = $col->create_row();
46-
47-
// (2)Specify row key and get row
48-
$col->get_row_by_integer(0, false, $row1);
49-
$blob = $row1->get_field_as_blob(1);
50-
echo("Get Row (Blob string data=$blob");
38+
$row = $col->get(0);
39+
echo("Get Row (Blob content: \n$row[1]\nBlob size = ".strlen($row[1]).")\n");
5140
echo("success!\n");
5241
} catch (GSException $e) {
53-
echo($e->what()."\n");
54-
echo($e->get_code()."\n");
42+
for ($i= 0; $i < $e->getErrorStackSize(); $i++) {
43+
echo("\n[$i]\n");
44+
echo($e->getErrorCode($i)."\n");
45+
echo($e->getLocation($i)."\n");
46+
echo($e->getErrorMessage($i)."\n");
47+
}
5548
}
5649
?>

sample/Connect.php

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,41 @@
11
<?php
22
include('griddb_php_client.php');
33

4-
$factory = StoreFactory::get_default();
4+
$factory = StoreFactory::getInstance();
55

66
try {
77
// (1)Get GridStore object
88
// Multicast method
9-
$gridstore = $factory->get_store(array("notificationAddress" => $argv[1],
10-
"notificationPort" => $argv[2],
9+
$gridstore = $factory->getStore(["host" => $argv[1],
10+
"port" => (int)$argv[2],
1111
"clusterName" => $argv[3],
12-
"user" => $argv[4],
13-
"password" => $argv[5]
14-
));
12+
"username" => $argv[4],
13+
"password" => $argv[5]]);
1514

1615
// Fixed list method
17-
//$gridstore = $factory->get_store(array("notificationMember" => $argv[1],
18-
// "clusterName" => $argv[2],
19-
// "user" => $argv[3],
20-
// "password" => $argv[4]
21-
// ));
16+
// $gridstore = $factory->getStore(array("notificationMember" => $argv[1],
17+
// "clusterName" => $argv[2],
18+
// "username" => $argv[3],
19+
// "password" => $argv[4]
20+
// ));
2221

2322
// Provider method
24-
//$gridstore = $factory->get_store(array("notificationProvider" => $argv[1],
25-
// "clusterName" => $argv[2],
26-
// "user" => $argv[3],
27-
// "password" => $argv[4]
28-
// ));
23+
// $gridstore = $factory->getStore(array("notificationProvider" => $argv[1],
24+
// "clusterName" => $argv[2],
25+
// "username" => $argv[3],
26+
// "password" => $argv[4]
27+
// ));
2928

3029
// (2)When operations such as container creation and acquisition are performed, it is connected to the cluster.
31-
$gridstore->get_container("containerName");
30+
$gridstore->getContainer("containerName");
3231
echo("Connect to Cluster\n");
3332
echo("success!\n");
3433
} catch (GSException $e) {
35-
echo($e->what()."\n");
36-
echo($e->get_code()."\n");
34+
for ($i= 0; $i < $e->getErrorStackSize(); $i++) {
35+
echo("\n[$i]\n");
36+
echo($e->getErrorCode($i)."\n");
37+
echo($e->getLocation($i)."\n");
38+
echo($e->getErrorMessage($i)."\n");
39+
}
3740
}
38-
?>
41+
?>

sample/ContainerNames.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
<?php
22
include('griddb_php_client.php');
33

4-
$factory = StoreFactory::get_default();
4+
$factory = StoreFactory::getInstance();
55

66
try {
77
// Get GridStore object
8-
$gridstore = $factory->get_store(array("notificationAddress" => $argv[1],
9-
"notificationPort" => $argv[2],
8+
$gridstore = $factory->getStore(["host" => $argv[1],
9+
"port" => (int)$argv[2],
1010
"clusterName" => $argv[3],
11-
"user" => $argv[4],
12-
"password" => $argv[5]
13-
));
11+
"username" => $argv[4],
12+
"password" => $argv[5]]);
1413

15-
// When operations such as container creation and acquisition are performed, it is connected to the cluster.
16-
$gridstore->get_container("containerName");
17-
echo("Connect to Cluster\n");
18-
19-
// Get a list of container names
14+
// Get an array of container names
2015
// (1)Get partition controller and number of partitions
21-
$pc = $gridstore->get_partition_controller();
22-
$pcCount = $pc->get_partition_count();
16+
$pc = $gridstore->partitionController;
17+
$pcCount = $pc->partitionCount;
2318

24-
// (2)Loop by the number of partitions to get a list of container names
19+
//(2)Loop by the number of partitions to get an array of container names
2520
for ($i = 0; $i < $pcCount; $i++) {
26-
$nameList = $pc->get_partition_container_names($i, 0);
27-
$nameCount = sizeof($nameList);
21+
$arrayContainerNames = $pc->getContainerNames($i, 0);
22+
$nameCount = sizeof($arrayContainerNames);
2823
for ($j = 0; $j < $nameCount; $j++) {
29-
echo("$nameList[$j]\n");
24+
echo("$arrayContainerNames[$j]\n");
3025
}
3126
}
27+
echo("success!\n");
3228
} catch (GSException $e) {
33-
echo($e->what()."\n");
34-
echo($e->get_code()."\n");
29+
for ($i= 0; $i < $e->getErrorStackSize(); $i++) {
30+
echo("\n[$i]\n");
31+
echo($e->getErrorCode($i)."\n");
32+
echo($e->getLocation($i)."\n");
33+
echo($e->getErrorMessage($i)."\n");
34+
}
3535
}
3636
?>

sample/CreateCollection.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
<?php
22
include('griddb_php_client.php');
33

4-
$factory = StoreFactory::get_default();
4+
$factory = StoreFactory::getInstance();
55

66
$containerName = "SamplePHP_collection1";
77

88
try {
99
// Get GridStore object
10-
$gridstore = $factory->get_store(array("notificationAddress" => $argv[1],
11-
"notificationPort" => $argv[2],
10+
$gridstore = $factory->getStore(["host" => $argv[1],
11+
"port" => (int)$argv[2],
1212
"clusterName" => $argv[3],
13-
"user" => $argv[4],
14-
"password" => $argv[5]
15-
));
16-
17-
// When operations such as container creation and acquisition are performed, it is connected to the cluster.
18-
$gridstore->get_container("containerName");
19-
echo("Connect to Cluster\n");
13+
"username" => $argv[4],
14+
"password" => $argv[5]]);
2015

2116
// Create a collection container
22-
$col = $gridstore->put_container(
23-
$containerName,
24-
array(array("id" => GS_TYPE_INTEGER),
25-
array("productName" => GS_TYPE_STRING),
26-
array("count" => GS_TYPE_INTEGER)),
27-
GS_CONTAINER_COLLECTION
28-
);
29-
echo("Create Collection name=$containerName\n");
17+
$conInfo = new ContainerInfo(["name" => $containerName,
18+
"columnInfoArray" => [["id", Type::INTEGER],
19+
["productName", Type::STRING],
20+
["count", Type::INTEGER]],
21+
"type" => ContainerType::COLLECTION,
22+
"rowKey" => true]);
23+
24+
$col = $gridstore->putContainer($conInfo);
25+
echo("Create Collection name = $containerName\n");
3026
echo("success!\n");
3127
} catch (GSException $e) {
32-
echo($e->what()."\n");
33-
echo($e->get_code()."\n");
28+
for ($i= 0; $i < $e->getErrorStackSize(); $i++) {
29+
echo("\n[$i]\n");
30+
echo($e->getErrorCode($i)."\n");
31+
echo($e->getLocation($i)."\n");
32+
echo($e->getErrorMessage($i)."\n");
33+
}
3434
}
3535
?>

sample/CreateIndex.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
<?php
22
include('griddb_php_client.php');
33

4-
$factory = StoreFactory::get_default();
4+
$factory = StoreFactory::getInstance();
55

66
$containerName = "SamplePHP_Index";
77

88
try {
99
// Get GridStore object
10-
$gridstore = $factory->get_store(array("notificationAddress" => $argv[1],
11-
"notificationPort" => $argv[2],
10+
$gridstore = $factory->getStore(["host" => $argv[1],
11+
"port" => (int)$argv[2],
1212
"clusterName" => $argv[3],
13-
"user" => $argv[4],
14-
"password" => $argv[5]
15-
));
16-
17-
// When operations such as container creation and acquisition are performed, it is connected to the cluster.
18-
$gridstore->get_container("containerName");
19-
echo("Connect to Cluster\n");
13+
"username" => $argv[4],
14+
"password" => $argv[5]]);
2015

2116
// Create a collection container
22-
$col = $gridstore->put_container(
23-
$containerName,
24-
array(array("id" => GS_TYPE_INTEGER),
25-
array("productName" => GS_TYPE_STRING),
26-
array("count" => GS_TYPE_INTEGER)),
27-
GS_CONTAINER_COLLECTION
28-
);
17+
$conInfo = new ContainerInfo(["name" => $containerName,
18+
"columnInfoArray" => [["id", Type::INTEGER],
19+
["productName", Type::STRING],
20+
["count", Type::INTEGER]],
21+
"type" => ContainerType::COLLECTION,
22+
"rowKey" => true]);
23+
24+
$gridstore->putContainer($conInfo);
2925
echo("Create Collection name=$containerName\n");
3026

3127
// Get the container
32-
$container = $gridstore->get_container($containerName);
33-
if ($container == null) {
28+
$col = $gridstore->getContainer($containerName);
29+
if ($col == null) {
3430
echo("ERROR Container not found. name=$containerName\n");
3531
}
3632

3733
// Create an index
38-
$container->create_index("count", GS_INDEX_FLAG_HASH);
34+
$col->createIndex("count", IndexType::HASH, "hash_index");
3935
echo("Create Index\n");
4036
echo("success!\n");
4137
} catch (GSException $e) {
42-
echo($e->what()."\n");
43-
echo($e->get_code()."\n");
38+
for ($i= 0; $i < $e->getErrorStackSize(); $i++) {
39+
echo("\n[$i]\n");
40+
echo($e->getErrorCode($i)."\n");
41+
echo($e->getLocation($i)."\n");
42+
echo($e->getErrorMessage($i)."\n");
43+
}
4444
}
4545
?>

sample/CreateTimeSeries.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
<?php
22
include('griddb_php_client.php');
33

4-
$factory = StoreFactory::get_default();
4+
$factory = StoreFactory::getInstance();
55

66
$containerName = "SamplePHP_timeseries1";
77

88
try {
99
// Get GridStore object
10-
$gridstore = $factory->get_store(array("notificationAddress" => $argv[1],
11-
"notificationPort" => $argv[2],
10+
$gridstore = $factory->getStore(["host" => $argv[1],
11+
"port" => (int)$argv[2],
1212
"clusterName" => $argv[3],
13-
"user" => $argv[4],
14-
"password" => $argv[5]
15-
));
13+
"username" => $argv[4],
14+
"password" => $argv[5]]);
1615

17-
// When operations such as container creation and acquisition are performed, it is connected to the cluster.
18-
$gridstore->get_container("containerName");
19-
echo("Connect to Cluster\n");
16+
// Create a time series container
17+
$conInfo = new ContainerInfo(["name" => $containerName,
18+
"columnInfoArray" => [["date", Type::TIMESTAMP],
19+
["value", Type::DOUBLE]],
20+
"type" => ContainerType::TIME_SERIES]);
2021

21-
// Create a timeseries container
22-
$col = $gridstore->put_container(
23-
$containerName,
24-
array(array("date" => GS_TYPE_TIMESTAMP),
25-
array("value" => GS_TYPE_DOUBLE)),
26-
GS_CONTAINER_TIME_SERIES
27-
);
28-
echo("Create Timeseries name=$containerName\n");
22+
$ts = $gridstore->putContainer($conInfo);
23+
echo("Create Collection name = $containerName\n");
2924
echo("success!\n");
3025
} catch (GSException $e) {
31-
echo($e->what()."\n");
32-
echo($e->get_code()."\n");
26+
for ($i= 0; $i < $e->getErrorStackSize(); $i++) {
27+
echo("\n[$i]\n");
28+
echo($e->getErrorCode($i)."\n");
29+
echo($e->getLocation($i)."\n");
30+
echo($e->getErrorMessage($i)."\n");
31+
}
3332
}
3433
?>

0 commit comments

Comments
 (0)