0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
HypertableConnection.php
Go to the documentation of this file.
1 <?
29 {
30  // Sends a query to the Hypertable server
31  public static function query($hql) {
33  return self::$_client->hql_query(self::$_namespace, $hql);
34  }
35 
36  // Inserts a cell into the Database
37  public static function insert($table, $row, $column, $value, $timestamp=0) {
39  if (!$timestamp)
40  $hql="INSERT INTO $table VALUES ('$row', '$column', '$value')";
41  else
42  $hql="INSERT INTO $table VALUES ('$timestamp', '$row', '$column', ".
43  "'$value')";
44  return self::$_client->hql_query(self::$_namespace, $hql);
45  }
46 
47  // Deletes a cell from the Database
48  public static function delete($table, $row, $column, $timestamp=0) {
50  if ($timestamp==0)
51  $hql="DELETE \"$column\" FROM $table WHERE ROW = \"$row\"";
52  else
53  $hql="DELETE \"$column\" FROM $table WHERE ROW = \"$row\" ".
54  "VERSION $timestamp";
55  return self::$_client->hql_query(self::$_namespace, $hql);
56  }
57 
58  // hypertable timestamps are stored in nanoseconds, but HQL needs
59  // a timestamp like '2001-10-20 12:34:01:23984'
60  public static function format_timestamp_ns($ts) {
61  $epoch=(int)($ts/1000000000);
62  $rem=$ts%1000000000;
63  date_default_timezone_set('UTC');
64  return sprintf("%s:%u", date("Y-m-d H:i:s", $epoch), $rem);
65  }
66 
67  // create and insert a unique value
68  public static function create_cell_unique($table, $row, $cf) {
70 
71  $k=new Hypertable_ThriftGen_Key();
72  $k->row=$row;
73  $k->column_family=$cf;
74  return self::$_client->create_cell_unique(self::$_namespace,
75  $table, $k, '');
76  }
77 
78  // Close the namespace to avoid leaks in the ThriftBroker
79  public static function close() {
80  if (self::$_namespace) {
81  self::$_client->close_namespace(self::$_namespace);
82  self::$_namespace=null;
83  }
84  }
85 
86  // Creates a new connection and returns the Namespace object.
87  // The connection and the namespace are cached.
88  protected static function initialize() {
89  $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
90  $options = $bootstrap->getOptions();
91  if (!self::$_client) {
92  $host=$options['hypertable']['thriftclient']['hostname'];
93  $port=$options['hypertable']['thriftclient']['port'];
94  self::$_client=new Hypertable_ThriftClient($host, $port);
95  }
96  if (!self::$_namespace) {
97  $ns=$options['hypertable']['namespace'];
98  self::$_namespace=self::$_client->open_namespace($ns);
99  }
100  }
101 
102  protected static $_client; // Hypertable database connection
103  protected static $_namespace; // Hypertable Namespace object
104 }
105 
106 ?>
void initialize(const String &name)
Public initialization function - creates a singleton instance of LogWriter.
Definition: Logger.cc:45
static insert($table, $row, $column, $value, $timestamp=0)
Copyright (C) 2007-2015 Hypertable, Inc.
static create_cell_unique($table, $row, $cf)