191 lines
7.5 KiB
C++
191 lines
7.5 KiB
C++
//
|
|
// storagenodedbaccess.h
|
|
//
|
|
// Created by Frank Vernon on 3/20/14.
|
|
// Copyright (c) 2014 IOnU. All rights reserved.
|
|
// Copyright (c) 2016, Sequence Logic, Inc. All rights reserved.
|
|
//
|
|
|
|
#ifndef STORAGENODEDBACCESS
|
|
#define STORAGENODEDBACCESS
|
|
|
|
#include <iostream>
|
|
#include <mutex>
|
|
|
|
#include "../../libeye/eyeutils.h"
|
|
#include "../../libeye/eyedb.h"
|
|
|
|
#include "storagenode.h"
|
|
|
|
#ifdef WIN32
|
|
#ifdef SL_CPPCORE_DLLEXPORT
|
|
#define SL_CPPCORE_EXPORT __declspec(dllexport)
|
|
#else
|
|
#define SL_CPPCORE_EXPORT __declspec(dllimport)
|
|
#endif
|
|
#else
|
|
#define SL_CPPCORE_EXPORT
|
|
#endif
|
|
|
|
#define SGDB_PERM_STATUS "permStatus"
|
|
|
|
namespace sequencelogic {
|
|
|
|
class StorageNodeDBAccess: public EyeDB {
|
|
public:
|
|
SL_CPPCORE_EXPORT
|
|
StorageNodeDBAccess();
|
|
|
|
/**
|
|
Initialize the database. This will create an empy databse with the correct schema if necessary.
|
|
In the event the DB schema has changed this routine is responsible for migrating the data as necessary.
|
|
@param dbFilePath - path the database file
|
|
@returns bool - success/fail
|
|
*/
|
|
SL_CPPCORE_EXPORT
|
|
bool initDB(const std::string & dbFilePath);
|
|
|
|
/**
|
|
@brief Find one or more nodes based on a sparse description
|
|
@details
|
|
Node mount, path hash, and path are the selection criteria; uses
|
|
wildcard for any of those respective arguments if not specified.
|
|
For the path in the query node, asterisk characters can be used as a
|
|
substring wildcard.
|
|
@param node - A sparsely configured node descriping the node(s) you want.
|
|
@returns Vector of StorageNodePtr. May be empty
|
|
*/
|
|
SL_CPPCORE_EXPORT
|
|
StorageNodeVector getNodes(const StorageNode & node);
|
|
|
|
SL_CPPCORE_EXPORT
|
|
StorageNodeVector getNodesInDirectory(const StorageNode & node);
|
|
|
|
/*
|
|
@brief Node path is the only selection criterion; uses a wildcard
|
|
for path if none specified
|
|
@details
|
|
For the path in the query node, asterisk characters can be used as a
|
|
substring wildcard.
|
|
*/
|
|
SL_CPPCORE_EXPORT
|
|
StorageNodeVector getNodesByPath(const StorageNode & node);
|
|
|
|
/**
|
|
Retrun all nodes for a given path on a given mount and signature; uses a wildcard
|
|
for mount, path, and signature if none specified
|
|
@param node - A sparsely configured node descriping the node(s) you want.
|
|
@returns Vector of StorageNodePtr. May be empty
|
|
*/
|
|
StorageNodeVector getNodesByPathForMountAndSignature(const StorageNode & node);
|
|
|
|
/*
|
|
@brief Node status and mount are the selection criteria; uses a wildcard
|
|
for mount if none specified
|
|
*/
|
|
SL_CPPCORE_EXPORT
|
|
StorageNodeVector getNodesByStatus(const StorageNode & node);
|
|
|
|
/**
|
|
@brief Node URN is the only selection criterion
|
|
*/
|
|
SL_CPPCORE_EXPORT
|
|
StorageNodeVector getNodesByUniformResourceName(const StorageNode & node);
|
|
|
|
/**
|
|
List children based on a sparse description.
|
|
@param parent - A sparsely configured node descriping the parent of children you want. Parent URN is required, metadata_status and permission_status are optional.
|
|
@param offset - 0 = first node, positive values offset from first node, negative values offset from last node.
|
|
@param limit - 0 = all nodes, positive values define limit from the begining of the ordered set, negative values define limit from the end of the ordered set
|
|
@param sort = metadata property key you wish to use to sort the results before they are returned. Defaults to utime.
|
|
@param sortDescending = order of sort, defaults to ascending
|
|
@returns StorageNodePtr or null_ptr on failure
|
|
*/
|
|
SL_CPPCORE_EXPORT
|
|
StorageNodePtr listChildren(const StorageNode & parent,
|
|
int32_t offset = 0,
|
|
int32_t limit = 0,
|
|
const std::string & sort = "metadata_utime",
|
|
bool sortAscending = true);
|
|
|
|
/**
|
|
List children based on a sparse description.
|
|
@param parent - A sparsely configured node descriping the parent of children you want. Parent URN is required, metadata_status and permission_status are optional.
|
|
@param startingNode = The node defining the starting point (offset) for the limit.
|
|
@param limit - 0 = all nodes, positive values define limit from the begining of the ordered set, negative values define limit from the end of the ordered set
|
|
@param sort = metadata property key you wish to use to sort the results before they are returned. Defaults to utime.
|
|
@param sortDescending = order of sort, defaults to ascending
|
|
@returns StorageNodePtr or null_ptr on failure
|
|
*/
|
|
SL_CPPCORE_EXPORT
|
|
StorageNodePtr listChildren(const StorageNode & parent,
|
|
const StorageNode & startingNode,
|
|
int32_t limit = 0,
|
|
const std::string & sort = "metadata_utime",
|
|
bool sortAscending = true);
|
|
|
|
/**
|
|
Count of children based on a sparse description.
|
|
@param parent - A sparsely configured node descriping the parent of children you want. Parent URN is required, metadata_status and permission_status are optional.
|
|
@returns StorageNodePtr or null_ptr on failure
|
|
*/
|
|
int32_t countChildren(const StorageNode & parent);
|
|
|
|
/**
|
|
Insert or update a node
|
|
@param node - A fully qualified node.
|
|
@returns boolean - true on success, false on failure
|
|
*/
|
|
SL_CPPCORE_EXPORT
|
|
bool putNode(const StorageNode & node);
|
|
|
|
/**
|
|
@brief Remove one or more nodes based on a sparse description
|
|
@details
|
|
The document urn is the primary selection criterion. If not supplied, uses
|
|
the combination of mount, path hash, and path as the selection criteria.
|
|
If not using document urn, uses wildcard for the other selection criteria
|
|
if not specified. For the path in the given query node, asterisk characters
|
|
can be used as a substring wildcard.
|
|
Never removes the host system file indicated by path, only removes the db
|
|
row.
|
|
@param node - A sparsely configured node descriping the node(s) you want.
|
|
@returns true if the query executed succesfully, regardless of whether
|
|
rows were removed; false otherwise
|
|
*/
|
|
SL_CPPCORE_EXPORT
|
|
bool deleteNodes(const StorageNode & node);
|
|
|
|
/**
|
|
Get size of table
|
|
@returns number of rows
|
|
*/
|
|
SL_CPPCORE_EXPORT
|
|
int32_t rowCount();
|
|
|
|
/**
|
|
Get initialization state
|
|
@returns true/false
|
|
*/
|
|
bool isInitialized() {
|
|
std::lock_guard<std::mutex> lock(_protectInit);
|
|
return _tableInitialized;
|
|
}
|
|
|
|
protected:
|
|
bool _tableInitialized;
|
|
mutable std::mutex _protectInit;
|
|
|
|
std::string getTableHash();
|
|
bool setTableHash(const std::string & tableHash);
|
|
|
|
std::string makeSQLWildcardIfNecessary(const std::string & string);
|
|
std::string replaceFilesystemWildcard(const std::string & string);
|
|
|
|
bool replaceNode(const StorageNode & node);
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|