get method
Get a node by node name from the storage backend.
@param path the fully qualified node name @return the requested node @throws StorageException if node is not found or an error in the storage API happens
Implementation
@override
Future<Node> get(String path) async {
checkPath(path);
getSanity(path);
String sqlStatement =
'SELECT path, owner, name, visibility, children, tombstone,last_modified '
'FROM storage_node WHERE path = ?';
Node res;
int lastModified;
try {
ResultSet resultSet = _requestResult(sqlStatement, [path]);
if (resultSet.isEmpty) {
throw StorageException('Node "$path" does not exist on sqlite backend');
} else {
String owner = (resultSet.first['owner'] ?? '<UNSET>') as String;
if ('true' == resultSet.first['tombstone'].toLowerCase()) {
res = await NodeImpl.fromPath(
resultSet.first['path'] as String, owner,
isTombstone: true);
res.visibility = VisibilityExtension.valueOf(
resultSet.first['visibility']! as String) ??
Visibility.red;
return res;
}
res = await NodeImpl.fromPath(resultSet.first['path'] as String, owner);
res.owner = owner;
res.visibility = VisibilityExtension.valueOf(
resultSet.first['visibility'] as String) ??
Visibility.red;
String children = resultSet.first['children'] as String;
if (!('' == children)) {
for (String childName in children.split(',')) {
await res.addChild(NodeImpl.createSkeleton(
(path != ':' ? path + ':' : ':') + childName,
owner,
controller));
}
}
lastModified = int.parse(resultSet.first['last_modified']);
}
} on Exception catch (exception, s) {
if (!(exception is StorageException || exception is SqliteException)) {
rethrow;
}
throw StorageException(
'Could not retrieve node "$path"', null, exception, s);
}
sqlStatement = ('SELECT path, key, value, type, locale, last_modified '
'FROM node_value WHERE path = ?');
ResultSet resultSetValues = _requestResult(sqlStatement, [path]);
String key;
try {
for (Row valueRow in resultSetValues) {
key = valueRow['key'] as String;
NodeValue value = NodeValueImpl(
key,
valueRow['value'] as String,
valueRow['type'] as String?,
'',
int.parse(valueRow['last_modified'] as String));
String sqlStatementTranslations =
'SELECT path, key, identifier, locale, translation '
'FROM translation WHERE (path = ? AND key = ?)';
ResultSet resultSetTranslations =
_requestResult(sqlStatementTranslations, [path, key]);
try {
for (Row translationRow in resultSetTranslations) {
String identifier = translationRow['identifier'] as String;
if ('VALUE' == identifier) {
value.setValue(translationRow['translation'] as String,
Locale.parse(translationRow['locale'] as String));
} else {
if ('DESCRIPTION' == identifier) {
value.setDescription(translationRow['translation'] as String,
Locale.parse(translationRow['locale'] as String));
}
}
}
} on SqliteException catch (e, st) {
throw StorageException(
'Could not retrieve description for node "' +
path +
'" and key "' +
key +
'"',
null,
e,
st);
}
// GwM: Unclear what this is!
await res.addValue(value);
}
} on SqliteException catch (e, st) {
throw StorageException(
'Could not retrieve values for node "' + path + '"', null, e, st);
}
// Has to be add the end because else the modification above will change it
res.lastModified = lastModified;
return res;
}