public List <PersistSchema> GetList(Session session, string schema) { try { using (var txRef = core.Transactions.Begin(session)) { PersistSchema schemaMeta = VirtualPathToMeta(txRef.Transaction, schema, LockOperation.Read); if (schemaMeta == null || schemaMeta.Exists == false) { throw new LeafSQLSchemaDoesNotExistException(schema); } var list = new List <PersistSchema>(); var filePath = Path.Combine(schemaMeta.DiskPath, Constants.SchemaCatalogFile); var namespaceCatalog = core.IO.GetJson <PersistSchemaCatalog>(txRef.Transaction, filePath, LockOperation.Read); foreach (var item in namespaceCatalog.Collection) { list.Add(item); } txRef.Commit(); return(list); } } catch (Exception ex) { core.Log.Write(String.Format("Failed to get namespace list for session {0}.", session.ProcessId), ex); throw; } }
public List <PersistSchema> GetChildrenMeta(Transaction transaction, PersistSchema node, LockOperation intendedOperation) { List <PersistSchema> metaList = new List <PersistSchema>(); string namespaceCatalogDiskPath = Path.Combine(node.DiskPath, Constants.SchemaCatalogFile); if (core.IO.FileExists(transaction, namespaceCatalogDiskPath, intendedOperation)) { var namespaceCatalog = core.IO.GetJson <PersistSchemaCatalog>(transaction, namespaceCatalogDiskPath, intendedOperation); foreach (var catalogItem in namespaceCatalog.Collection) { metaList.Add(new PersistSchema() { DiskPath = node.DiskPath + "\\" + catalogItem.Name, Exists = true, Id = catalogItem.Id, Name = catalogItem.Name, VirtualPath = node.VirtualPath + ":" + catalogItem.Name }); } } return(metaList); }
public PersistSchema VirtualPathToMeta(Transaction transaction, string schemaPath, LockOperation intendedOperation) { try { schemaPath = schemaPath.Trim(new char[] { ':' }).Trim(); if (schemaPath == string.Empty) { return(RootSchemaMeta); } else { var segments = schemaPath.Split(':'); string schemaName = segments[segments.Count() - 1]; string namespaceDiskPath = Path.Combine(core.Settings.DataRootPath, String.Join("\\", segments)); string parentSchemaDiskPath = Directory.GetParent(namespaceDiskPath).FullName; string parentCatalogDiskPath = Path.Combine(parentSchemaDiskPath, Constants.SchemaCatalogFile); if (core.IO.FileExists(transaction, parentCatalogDiskPath, intendedOperation) == false) { throw new LeafSQLInvalidSchemaException(string.Format("The schema [{0}] does not exist.", schemaPath)); } var parentCatalog = core.IO.GetJson <PersistSchemaCatalog>(transaction, Path.Combine(parentSchemaDiskPath, Constants.SchemaCatalogFile), intendedOperation); var namespaceMeta = parentCatalog.GetByName(schemaName); if (namespaceMeta != null) { namespaceMeta.Name = schemaName; namespaceMeta.DiskPath = namespaceDiskPath; namespaceMeta.VirtualPath = schemaPath; namespaceMeta.Exists = true; } else { namespaceMeta = new PersistSchema() { Name = schemaName, DiskPath = core.Settings.DataRootPath + "\\" + schemaPath.Replace(':', '\\'), VirtualPath = schemaPath, Exists = false }; } transaction.LockDirectory(intendedOperation, namespaceMeta.DiskPath); return(namespaceMeta); } } catch (Exception ex) { core.Log.Write("Failed to translate virtual path to namespace meta.", ex); throw; } }
public PersistSchema GetParentMeta(Transaction transaction, PersistSchema child, LockOperation intendedOperation) { try { if (child == RootSchemaMeta) { return(null); } var segments = child.VirtualPath.Split(':').ToList(); segments.RemoveAt(segments.Count - 1); string parentNs = string.Join(":", segments); return(VirtualPathToMeta(transaction, parentNs, intendedOperation)); } catch (Exception ex) { core.Log.Write("Failed to get parent namespace meta.", ex); throw; } }