Esempio n. 1
0
        //Fire up Fastore, create a host, connect to a session.
        protected override void InternalStart(ServerProcess process)
        {
            base.InternalStart(process);

            var addresses = GetAddresses();

            //Connect to the Fastore Service
            _db        = Alphora.Fastore.Client.Client.Connect(addresses);
            _generator = new Alphora.Fastore.Client.Generator(_db);

            _tables = new FastoreTables();
        }
        //TODO: FastoreTable? This function is used internally to make sure tables exist
        //In the case of Fastore, this means reading the tableVar, deciding what the columns will look like, and creating them.
        protected FastoreTable EnsureFastoreTable(Schema.TableVar tableVar)
        {
            if (!tableVar.IsSessionObject && !tableVar.IsATObject)
            {
                tableVar.Scope = (Schema.TableVarScope)Enum.Parse(typeof(Schema.TableVarScope), MetaData.GetTag(tableVar.MetaData, "Storage.Scope", "Database"), false);
            }

            FastoreTables tables = GetTables(tableVar.Scope);

            lock (tables)
            {
                int index = tables.IndexOf(tableVar);
                if (index < 0)
                {
                    index = tables.Add(new FastoreTable(ServerProcess.ValueManager, tableVar, this.Device));
                }
                return(tables[index]);
            }
        }
 //Execute is what actually returns a value? Plan is executed which return a scan.
 protected override object InternalExecute(Program program, PlanNode planNode)
 {
     if (planNode is BaseTableVarNode)
     {
         FastoreCursor scan = new FastoreCursor(program, _db, (BaseTableVarNode)planNode);
         try
         {
             scan.Open();
             return(scan);
         }
         catch
         {
             scan.Dispose();
             throw;
         }
     }
     else if (planNode is OrderNode)
     {
         OrderNode orderNode = (OrderNode)planNode;
         if (orderNode.Order.Columns.Count == 1)
         {
             FastoreCursor scan = new FastoreCursor(program, _db, (BaseTableVarNode)planNode.Nodes[0]);
             try
             {
                 scan.Key        = orderNode.PhysicalOrder;
                 scan.Direction  = orderNode.ScanDirection;
                 scan.Node.Order = orderNode.Order;
                 scan.Open();
                 return(scan);
             }
             catch
             {
                 scan.Dispose();
                 throw;
             }
         }
         else
         {
             FastoreStackedCursor scan = new FastoreStackedCursor(program, _db, orderNode.Order, orderNode.PhysicalOrder, (BaseTableVarNode)planNode.Nodes[0]);
             try
             {
                 scan.Open();
                 return(scan);
             }
             catch
             {
                 scan.Dispose();
                 throw;
             }
         }
     }
     else if (planNode is CreateTableVarBaseNode)
     {
         EnsureFastoreTable(((CreateTableVarBaseNode)planNode).GetTableVar());
         return(null);
     }
     else if (planNode is AlterTableNode)
     {
         // TODO: Memory device alter table support
         return(null);
     }
     else if (planNode is DropTableNode)
     {
         Schema.TableVar tableVar = ((DropTableNode)planNode).Table;
         FastoreTables   tables   = GetTables(tableVar.Scope);
         lock (tables)
         {
             int tableIndex = tables.IndexOf(tableVar);
             if (tableIndex >= 0)
             {
                 FastoreTable nativeTable = tables[tableIndex];
                 nativeTable.Drop(program.ValueManager);
                 tables.RemoveAt(tableIndex);
             }
         }
         return(null);
     }
     else
     {
         throw new DeviceException(DeviceException.Codes.InvalidExecuteRequest, Device.Name, planNode.ToString());
     }
 }