Permalink
Browse files

Add UUID time based (version 1) support

	modified:   columnfamily_action.php
	modified:   helper/ColumnFamilyHelper.php
	modified:   views/columnfamily_browse_data_row.php
	modified:   views/columnfamily_insert_edit_row.php
  • Loading branch information...
1 parent d6d63a6 commit 5bc192a7a96d8e770a98a8705c981f5954368183 @kovalenko kovalenko committed Mar 2, 2013
View
@@ -12,6 +12,7 @@
use phpcassa\Connection\ConnectionPool;
use phpcassa\ColumnFamily;
use phpcassa\SuperColumnFamily;
+ use phpcassa\UUID;
use cassandra\IndexType;
$included_header = false;
@@ -527,11 +528,18 @@
$cf_def = ColumnFamilyHelper::getCFInKeyspace($keyspace_name,$columnfamily_name);
$is_super_cf = $cf_def->column_type == 'Super';
+ switch ($cf_def->comparator_type) {
+ case 'org.apache.cassandra.db.marshal.TimeUUIDType':
+ $autopack_names = false;
+ break;
+ default:
+ $autopack_names = true;
+ }
if ($is_super_cf) {
- $column_family = new SuperColumnFamily($pool, $columnfamily_name);
+ $column_family = new SuperColumnFamily($pool, $columnfamily_name, $autopack_names);
}
else {
- $column_family = new ColumnFamily($pool, $columnfamily_name);
+ $column_family = new ColumnFamily($pool, $columnfamily_name, $autopack_names);
}
$no_column = 1;
@@ -548,6 +556,12 @@
while (isset($_POST['column_name_'.$no_scf.'_'.$no_column]) && isset($_POST['column_value_'.$no_scf.'_'.$no_column])) {
$column_name = $_POST['column_name_'.$no_scf.'_'.$no_column];
+ switch ($cf_def->comparator_type) {
+ case 'org.apache.cassandra.db.marshal.TimeUUIDType':
+ $uuid = UUID::import($column_name);
+ $column_name = $uuid->bytes;
+ break;
+ }
$column_value = $_POST['column_value_'.$no_scf.'_'.$no_column];
if ($_POST['column_name_'.$no_scf.'_'.$no_column] != '' && $_POST['column_value_'.$no_scf.'_'.$no_column] != '') {
@@ -714,7 +728,7 @@
else {
$column_family = new ColumnFamily($pool, $columnfamily_name);
}
-
+
// Increment counter
if (isset($_GET['increment'])) {
$row_key = $_GET['row_key'];
@@ -793,6 +807,7 @@
$vw_row_vars['keyspace_name'] = $keyspace_name;
$vw_row_vars['columnfamily_name'] = $columnfamily_name;
+ $vw_row_vars['comparator_type'] = $cf_def->comparator_type;
$vw_row_vars['show_actions_link'] = true;
@@ -868,6 +883,7 @@
$is_super_cf = $cf_def->column_type == 'Super';
$vw_vars['is_super_cf'] = $cf_def->column_type == 'Super';
+ $vw_vars['comparator_type'] = $cf_def->comparator_type;
$vw_vars['key'] = $key;
$vw_vars['super_key'] = $super_key;
@@ -96,6 +96,25 @@ public static function displayCFRow($row_key,$keyspace_name,$columnfamily_name,$
return getHTML('columnfamily_row.php',$vw_vars);
}
}
+ public static function displayCFTimeUUIDTypeRow($row_key,$keyspace_name,$columnfamily_name,$row,$scf_key = null,$is_counter_column = false) {
+ $vw_vars['scf_key'] = $scf_key;
+ $uuid_row = array();
+ foreach ($row as $c=>&$v) {
+ $uuid_row[(string)unserialize($c)] = $v;
+ } unset($row, $v);
+ $vw_vars['row'] = $uuid_row;
+ $vw_vars['keyspace_name'] = $keyspace_name;
+ $vw_vars['columnfamily_name'] = $columnfamily_name;
+ $vw_vars['row_key'] = $row_key;
+
+ // If it's a column family of counter
+ if ($is_counter_column) {
+ return getHTML('columnfamily_row_counter.php',$vw_vars);
+ }
+ else {
+ return getHTML('columnfamily_row.php',$vw_vars);
+ }
+ }
/*
Display a row out of a super column family
@@ -115,6 +134,15 @@ public static function displaySCFRow($row_key,$keyspace_name,$columnfamily_name,
return $output;
}
+ public static function displaySCFTimeUUIDTypeRow($row_key,$keyspace_name,$columnfamily_name,$row,$is_counter_column = false) {
+ $output = '';
+
+ foreach ($row as $key => $value) {
+ $output .= ColumnFamilyHelper::displayCFTimeUUIDTypeRow($row_key,$keyspace_name,$columnfamily_name,$value,$key,$is_counter_column);
+ }
+
+ return $output;
+ }
/*
Used by usort() method. Assists in sorts column families by name
@@ -2,11 +2,21 @@
<td><?php echo htmlentities($key,ENT_COMPAT,'UTF-8'); ?></td>
<td>
<?php
- if ($is_super_cf):
- echo ColumnFamilyHelper::displaySCFRow($key,$keyspace_name,$columnfamily_name,$value,$is_counter_column);
- else:
- echo ColumnFamilyHelper::displayCFRow($key,$keyspace_name,$columnfamily_name,$value,null,$is_counter_column);
- endif;
+ switch ($comparator_type) {
+ case 'org.apache.cassandra.db.marshal.TimeUUIDType':
+ if ($is_super_cf):
+ echo ColumnFamilyHelper::displaySCFTimeUUIDTypeRow($key,$keyspace_name,$columnfamily_name,$value,$is_counter_column);
+ else:
+ echo ColumnFamilyHelper::displayCFTimeUUIDTypeRow($key,$keyspace_name,$columnfamily_name,$value,null,$is_counter_column);
+ endif;
+ break;
+ default:
+ if ($is_super_cf):
+ echo ColumnFamilyHelper::displaySCFRow($key,$keyspace_name,$columnfamily_name,$value,$is_counter_column);
+ else:
+ echo ColumnFamilyHelper::displayCFRow($key,$keyspace_name,$columnfamily_name,$value,null,$is_counter_column);
+ endif;
+ }
?>
</td>
<?php if ($show_actions_link): ?>
@@ -59,20 +59,37 @@ function addSuperColumnWithColumn() {
<?php endif; ?>
<?php
if ($mode == 'edit'):
- if ($is_super_cf):
- foreach ($output as $super_key => $data):
- echo 'addSuperColumn(', json_encode($super_key), ');';
-
- foreach ($data as $name => $value):
- echo 'addColumn(', json_encode($name), ',', json_encode($value), ',num_super_columns);';
- endforeach;
- endforeach;
- else:
- echo 'num_super_columns++;';
- foreach ($output as $name => $value):
- echo 'addColumn(', json_encode($name), ',', json_encode($value), ',num_super_columns);';
- endforeach;
- endif;
+ switch ($comparator_type):
+ case 'org.apache.cassandra.db.marshal.TimeUUIDType' :
+ if ($is_super_cf):
+ foreach ($output as $super_key => $data):
+ echo 'addSuperColumn(', json_encode($super_key), ');';
+ foreach ($data as $name => $value):
+ echo 'addColumn(', json_encode((string)unserialize($name)), ',', json_encode($value), ',num_super_columns);';
+ endforeach;
+ endforeach;
+ else:
+ echo 'num_super_columns++;';
+ foreach ($output as $name => $value):
+ echo 'addColumn(', json_encode((string)unserialize($name)), ',', json_encode($value), ',num_super_columns);';
+ endforeach;
+ endif;
+ break;
+ default:
+ if ($is_super_cf):
+ foreach ($output as $super_key => $data):
+ echo 'addSuperColumn(', json_encode($super_key), ');';
+ foreach ($data as $name => $value):
+ echo 'addColumn(', json_encode($name), ',', json_encode($value), ',num_super_columns);';
+ endforeach;
+ endforeach;
+ else:
+ echo 'num_super_columns++;';
+ foreach ($output as $name => $value):
+ echo 'addColumn(', json_encode($name), ',', json_encode($value), ',num_super_columns);';
+ endforeach;
+ endif;
+ endswitch;
endif;
?>
});

0 comments on commit 5bc192a

Please sign in to comment.