Commit b156b14b authored by Vincent Pelletier's avatar Vincent Pelletier

ZSQLCatalog.SQLCatalog: Factorise access to sql_getitem_by_{uid,path}.

parent 7f2b9d84
...@@ -1796,17 +1796,7 @@ class Catalog(Folder, ...@@ -1796,17 +1796,7 @@ class Catalog(Folder,
security.declarePrivate('getUidForPath') security.declarePrivate('getUidForPath')
def getUidForPath(self, path): def getUidForPath(self, path):
""" Looks up into catalog table to convert path into uid """ """ Looks up into catalog table to convert path into uid """
#try: return self.getUidDictForPathList([path]).get(path)
if path is None:
return None
# Get the appropriate SQL Method
method = getattr(self, self.sql_getitem_by_path)
search_result = method(path = path, uid_only=1)
# If not empty, return first record
if len(search_result) > 0:
return long(search_result[0].uid)
else:
return None
security.declarePrivate('getUidDictForPathList') security.declarePrivate('getUidDictForPathList')
def getUidDictForPathList(self, path_list): def getUidDictForPathList(self, path_list):
...@@ -1860,40 +1850,16 @@ class Catalog(Folder, ...@@ -1860,40 +1850,16 @@ class Catalog(Folder,
security.declarePrivate('getPathForUid') security.declarePrivate('getPathForUid')
def getPathForUid(self, uid): def getPathForUid(self, uid):
""" Looks up into catalog table to convert uid into path """ """ Looks up into catalog table to convert uid into path """
try: return self.getPathDictForUidList([uid]).get(uid)
if uid is None:
return None
try:
int(uid)
except ValueError:
return None
# Get the appropriate SQL Method
method = getattr(self, self.sql_getitem_by_uid)
search_result = method(uid = uid)
# If not empty return first record
if len(search_result) > 0:
return search_result[0].path
else:
return None
except ConflictError:
raise
except:
# This is a real LOG message
# which is required in order to be able to import .zexp files
LOG('SQLCatalog', WARNING, "could not find path from uid %s" % (uid,))
return None
security.declarePrivate('getMetadataForUid') security.declarePrivate('getMetadataForUid')
def getMetadataForUid(self, uid): def getMetadataForUid(self, uid):
""" Accesses a single record for a given uid """ """ Accesses a single record for a given uid """
if uid is None:
return None
# Get the appropriate SQL Method
method = getattr(self, self.sql_getitem_by_uid)
brain = method(uid = uid)[0]
result = {} result = {}
for k in brain.__record_schema__.keys(): path = self.getPathForUid(uid)
result[k] = getattr(brain,k) if uid is not None:
result['path'] = path
result['uid'] = uid
return result return result
security.declarePrivate('getIndexDataForUid') security.declarePrivate('getIndexDataForUid')
...@@ -1904,22 +1870,12 @@ class Catalog(Folder, ...@@ -1904,22 +1870,12 @@ class Catalog(Folder,
security.declarePrivate('getMetadataForPath') security.declarePrivate('getMetadataForPath')
def getMetadataForPath(self, path): def getMetadataForPath(self, path):
""" Accesses a single record for a given path """ """ Accesses a single record for a given path """
try:
# Get the appropriate SQL Method
method = getattr(self, self.sql_getitem_by_path)
brain = method(path = path)[0]
result = {} result = {}
for k in brain.__record_schema__.keys(): uid = self.getUidForPath(path)
result[k] = getattr(brain,k) if uid is not None:
result['path'] = path
result['uid'] = uid
return result return result
except ConflictError:
raise
except:
# This is a real LOG message
# which is required in order to be able to import .zexp files
LOG('SQLCatalog', WARNING,
"could not find metadata from path %s" % (path,))
return None
security.declarePrivate('getIndexDataForPath') security.declarePrivate('getIndexDataForPath')
def getIndexDataForPath(self, path): def getIndexDataForPath(self, path):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment