private static void ProcessGetResult(Request request)
    {
      Object[] requestData = request.getMethodParameters();
      string id = requestData[0].ToString();
      int startLine = Convert.ToInt32(requestData[1]);
      int numberOfLines = Convert.ToInt32(requestData[2]);
      QueryResult queryResult;
      ResultStorage resultStorage = ResultStorage.Instance;
      QueryDataset queryDataset = resultStorage.GetQueryResult(id, startLine, numberOfLines);
      queryResult = new QueryResult(Convert.ToInt32(id), "Resulting rows being posted.");

      IRootServerCallback iRootServerCallback = request.getRootServerCallback();

      iRootServerCallback.PutDataset(queryResult, id, queryDataset);
    
    }
 void dispatchRequest(Request request)
 {
   switch (request.getRequestType())
   { 
     case RequestType.EXECUTE_QUERY:
       ProcessExecQuery(request);
       break;
     case RequestType.GET_RESULT:
       ProcessGetResult(request);
       break;
     case RequestType.RELEASE:
       ProcessRelease(request);
       break;
     default:
       break;
   }
     
 }
    public void SelectRow(Statement queryObj, IRootServerCallback callback)
    {
      SelectRows selectRows = (SelectRows)queryObj;
      List<TernaryAssociative<string, string, string>> whereList = new List<TernaryAssociative<string, string, string>>();
      List<KeyValuePair<string, string>> orderByColumns = new List<KeyValuePair<string, string>>();

      m_Request = new Request();
      m_Parameters = new Object[8];
      m_Parameters[0] = GetDatabaseName(m_token);
      m_Parameters[1] = selectRows.GetTableName();
      if(selectRows.GetSelectRowTableColList().GetSelectRowColumnType() == SelectRowColumnType.ALL_COLUMNS)
      {
        m_Parameters[2] = new List<string>();
        m_Parameters[3] = "";
      }
      else if (selectRows.GetSelectRowTableColList().GetSelectRowColumnType() == SelectRowColumnType.SPECIFIC_COLUMNS)
      {
        m_Parameters[2] = selectRows.GetSelectRowTableColList().GetTableColumnList().GetList();
        m_Parameters[3] = "";
      }
      else if (selectRows.GetSelectRowTableColList().GetSelectRowColumnType() == SelectRowColumnType.COUNT_ROWS)
      {
        m_Parameters[2] = new List<string>();
        if(selectRows.GetSelectRowTableColList().GetCountRows().GetCountAllRowsFlag() == true)
          m_Parameters[3] = "*";
        else
          m_Parameters[3] = selectRows.GetSelectRowTableColList().GetCountRows().GetColumnName();
      }
      if (selectRows.GetWhereListFlag() == true)
      {
        List<WhereEntry> whereEntries = selectRows.GetWhereList().GetSubWhereList().GetWhereEntryList();
        foreach (WhereEntry whereEntry in whereEntries)
        {
          TernaryAssociative<string, string, string> item = new TernaryAssociative<string, string, string>();
          item.First = whereEntry.GetColumnName();
          item.Second = whereEntry.GetComparisonOperatorType().ToString();

          if (whereEntry.GetColumnValue().GetColumnValueType() == ColValueType.STRING)
          {
            item.Third = whereEntry.GetColumnValue().GetStringColumnValue();
          }
          else if (whereEntry.GetColumnValue().GetColumnValueType() == ColValueType.INTEGER)
          {
            item.Third = whereEntry.GetColumnValue().GetIntColumnValue().ToString();
          }
          else if (whereEntry.GetColumnValue().GetColumnValueType() == ColValueType.DOUBLE)
          {
            item.Third = whereEntry.GetColumnValue().GetDoubleColumnValue().ToString();
          }
          whereList.Add(item);    
        }
      }
      m_Parameters[4] = whereList;
      if (selectRows.GetOrderByFlag() == true)
      {
        List<OrderByEntry> orderByEntries = selectRows.GetOrderByList().GetSubOrderBylist().GetOrderByEntryList();
        foreach (OrderByEntry orderByEntry in orderByEntries)
        {
          KeyValuePair<string, string> item = new KeyValuePair<string, string>(orderByEntry.GetColumnName(),orderByEntry.GetOrderByType());
          orderByColumns.Add(item);
        }
      }
      m_Parameters[5] = orderByColumns;
      if (selectRows.GetLimitRangeFlag() == true)
      {
        m_Parameters[6] = selectRows.GetLimitRange().GetStartIndex();
        m_Parameters[7] = selectRows.GetLimitRange().GetCount();
      }
      else
      {
        m_Parameters[6] = -1;
        m_Parameters[7] = -1;
      }
      
      m_Request.SetCallingMethod("SelectRow");
      m_Request.SetRequestType(RequestType.EXECUTE_QUERY);
      m_Request.SetRootServerCallback(callback);
      m_Request.SetMethodParameters(m_Parameters);
      
    }
    public void InsertRow(Statement queryObj, IRootServerCallback callback)
    {
      
      InsertRow insertObj = (InsertRow)queryObj;
      List<string> ColumnList = new List<string>();
      ArrayList ColumnValueList = new ArrayList();
  
      foreach (ColumnValue val in insertObj.GetValueList())
      {
        if (val.GetColumnValueType() == ColValueType.STRING)
        {
          ColumnValueList.Add(val.GetStringColumnValue());
        }
        else if (val.GetColumnValueType() == ColValueType.INTEGER)
        {
          ColumnValueList.Add(val.GetIntColumnValue());
        }
        else if (val.GetColumnValueType() == ColValueType.DOUBLE)
        {
          ColumnValueList.Add(val.GetDoubleColumnValue());
        }
      }
      
      m_Request = new Request();
      m_Parameters = new Object[4];
      m_Parameters[0] = GetDatabaseName(m_token);
      m_Parameters[1] = insertObj.GetTableName();
      m_Parameters[2] = insertObj.GetList();
      m_Parameters[3] = ColumnValueList;

      m_Request.SetCallingMethod("InsertRow");
      m_Request.SetRequestType(RequestType.EXECUTE_QUERY);
      m_Request.SetRootServerCallback(callback);
      m_Request.SetMethodParameters(m_Parameters);

    }
    public void RenameColumn(Statement queryObj, IRootServerCallback callback)
    {
      m_Request = new Request();
      m_Parameters = new Object[4];
      m_Parameters[0] = GetDatabaseName(m_token);
      m_Parameters[1] = ((RenameColumn)queryObj).GetTableName();
      m_Parameters[2] = ((RenameColumn)queryObj).GetOldColumnName();
      m_Parameters[3] = ((RenameColumn)queryObj).GetNewColumnName();

      m_Request.SetCallingMethod("RenameColumn");
      m_Request.SetRequestType(RequestType.EXECUTE_QUERY);
      m_Request.SetRootServerCallback(callback);
      m_Request.SetMethodParameters(m_Parameters);

    }
    public void EmptyTable(Statement queryObj, IRootServerCallback callback)
    {
      m_Request = new Request();
      m_Parameters = new Object[2];
      m_Parameters[0] = GetDatabaseName(m_token);
      m_Parameters[1] = ((EmptyTable)queryObj).GetTableName();

      m_Request.SetCallingMethod("EmptyTable");
      m_Request.SetRequestType(RequestType.EXECUTE_QUERY);
      m_Request.SetRootServerCallback(callback);
      m_Request.SetMethodParameters(m_Parameters);
    }
 public void DeleteDb(Statement queryObj,IRootServerCallback callback)
 {
   m_Request = new Request();
   m_Parameters = new Object[1];
   m_Parameters[0] = ((DeleteDB)queryObj).GetDatabaseName();
   
   m_Request.SetCallingMethod("DeleteDatabase");
   m_Request.SetRequestType(RequestType.EXECUTE_QUERY);
   m_Request.SetRootServerCallback(callback);
   m_Request.SetMethodParameters(m_Parameters);
 }
    public void ModifyTable(Statement queryObj,IRootServerCallback callback)
    {
        m_Request = new Request();
               
        ModifyTab obj = (ModifyTab)queryObj;

        if (obj.GetTyp() == "ADD")
        {
          AddColumn columnData = obj.GetAddColumnData();
          m_Parameters = new Object[5];
          m_Parameters[0] = GetDatabaseName(m_token);
          m_Parameters[1] = columnData.GetTableName();
               
          if (columnData.GetColumnData().GetUniqueKey() == null)
            m_Parameters[2] = false;
          else
            m_Parameters[2] = true;
          
          m_Parameters[3] = columnData.GetColumnData().GetColumnName();

          if (columnData.GetColumnData().GetVarType() == "VARCHAR")
            m_Parameters[4] = "VARCHAR" + "(" + columnData.GetColumnData().GetVarRange() + ")";
          else
            m_Parameters[4] = columnData.GetColumnData().GetVarType();
          m_Request.SetCallingMethod("AddColumn");
        }
        else
        {
          DeleteColumn columnData = obj.GetDelcolumnData();
          m_Parameters = new Object[3];
          m_Parameters[0] = GetDatabaseName(m_token);
          m_Parameters[1] = columnData.GetTableName();
          m_Parameters[2] = columnData.GetColumnData();
          m_Request.SetCallingMethod("DeleteColumn");
        }

        m_Request.SetRequestType(RequestType.EXECUTE_QUERY);
        m_Request.SetRootServerCallback(callback);
        m_Request.SetMethodParameters(m_Parameters);
    }
Exemple #9
0
 /*
  * GetResult(id,startline,numberOfLines) receives a request asking for data
  * in a table stored on the root server. 
  * @param id is the identifier for the table on root server.
  * @param startLine is the first data entry that the client wants.
  * @param numberOfLines is the total number of data entries the client wants.
  * @param token is the authentication token.
  * @returns the result of operation and info related to the result.
  */
 public QueryResult GetResult(string id, int startLine, int numberOfLines, string token)
 {
   QueryResult queryResult;
   DateTime dateTime;
   DependencyInjection di = DependencyInjection.GetInstance();
   IAuthValidate iAuthValidate = (IAuthValidate)di.CreateObject("validate",new object[]
                                                                 { null,
                                                                   m_AuthSeverUrl
                                                                   });
   if (!iAuthValidate.Validate(token, out dateTime))
   {
     queryResult = new QueryResult(-1, "Could not authenticate user.");
     return queryResult;
   }
   Request request = new Request();
   request.SetRequestType(RequestType.GET_RESULT);
   request.setTableServerObject(m_ITableServer);
   Object[] requestData = new Object[3];
   requestData[0] = id;
   requestData[1] = startLine;
   requestData[2] = numberOfLines;
   request.SetMethodParameters(requestData);
   request.SetRootServerCallback(OperationContext.Current.GetCallbackChannel<IRootServerCallback>());
   
   m_RequestQueue.enQueueRequest(request);
   
   queryResult = new QueryResult(Convert.ToInt32(id), "Query result request received.");
   return queryResult;
 }
 private void CreateDb(Statement queryObj, IRootServerCallback callback)
 {
   try
   {
     m_Request = new Request();
     m_Parameters = new Object[1];
   m_Parameters[0] = ((CreateDB)queryObj).GetDatabaseName(); 
   
   m_Request.SetCallingMethod("CreateDatabase");
   m_Request.SetRequestType(RequestType.EXECUTE_QUERY);
   m_Request.SetRootServerCallback(callback);
   m_Request.SetMethodParameters(m_Parameters);
   }
   catch (Exception ex)
   {
     Console.WriteLine("createdb: " + ex.Message);
   }
 }
    private static void ProcessExecQuery(Request request)
    {
      ITableServer tableServerObject = request.getTableServerObject();
      Type created = tableServerObject.GetType();

      Object resultObject = created.InvokeMember(request.getCallingMethod(),
                                                  System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.InvokeMethod,
                                                  null,
                                                  tableServerObject,
                                                  request.getMethodParameters()
                                                  );
      TableResponse tableResponse = (TableResponse)resultObject;
      IRootServerCallback iRootServerCallback = request.getRootServerCallback();
      string id = tableResponse.GetId;
      QueryResult queryResult;

      queryResult = new QueryResult(Convert.ToInt32(id), tableResponse.GetMessage);
      iRootServerCallback.PutQueryInfo(queryResult, id, 0);
    }
 private static void ProcessRelease(Request request)
 { }
Exemple #13
0
    /*
     * @param token is the authentication token
     * @returns the DB structure.
     */
    public Dictionary<string, List<string>> GetDBInfo(string token)
    {
      DateTime dateTime;
      DependencyInjection di = DependencyInjection.GetInstance();
      IAuthValidate iAuthValidate = (IAuthValidate)di.CreateObject("validate", new object[]
                                                                    { null,
                                                                      m_AuthSeverUrl
                                                                      });
      if (!iAuthValidate.Validate(token, out dateTime))
      {
        throw new Exception("Not authenticated");
      }
      Request request = new Request();
      request.SetRequestType(RequestType.DB_QUERY);
      request.setTableServerObject(m_ITableServer);
      request.SetRootServerCallback(OperationContext.Current.GetCallbackChannel<IRootServerCallback>());

      m_RequestQueue.enQueueRequest(request);
      return new Dictionary<string, List<string>>(); 
    }
    public void DeleteRows(Statement queryObj, IRootServerCallback callback)
    {
      DeleteRows deleteRows = (DeleteRows)queryObj;
      List<TernaryAssociative<string, string, string>> whereList = new List<TernaryAssociative<string, string, string>>();
      
      m_Request = new Request();
      m_Parameters = new Object[3];
      m_Parameters[0] = GetDatabaseName(m_token);
      m_Parameters[1] = deleteRows.GetTableName();

      if (deleteRows.GetWhereListFlag() == true)
      {
        List<WhereEntry> whereEntries = deleteRows.GetWhereList().GetSubWhereList().GetWhereEntryList();
        foreach (WhereEntry whereEntry in whereEntries)
        {
          TernaryAssociative<string, string, string> item = new TernaryAssociative<string, string, string>();
          item.First = whereEntry.GetColumnName();
          item.Second = whereEntry.GetComparisonOperatorType().ToString();

          if (whereEntry.GetColumnValue().GetColumnValueType() == ColValueType.STRING)
          {
            item.Third = whereEntry.GetColumnValue().GetStringColumnValue();
          }
          else if (whereEntry.GetColumnValue().GetColumnValueType() == ColValueType.INTEGER)
          {
            item.Third = whereEntry.GetColumnValue().GetIntColumnValue().ToString();
          }
          else if (whereEntry.GetColumnValue().GetColumnValueType() == ColValueType.DOUBLE)
          {
            item.Third = whereEntry.GetColumnValue().GetDoubleColumnValue().ToString();
          }
          whereList.Add(item);
        }
      }
      m_Parameters[2] = whereList;
      
      m_Request.SetCallingMethod("DeleteRow");
      m_Request.SetRequestType(RequestType.EXECUTE_QUERY);
      m_Request.SetRootServerCallback(callback);
      m_Request.SetMethodParameters(m_Parameters);
    }
    private void CreateTable(Statement queryObj, IRootServerCallback callback)
    {
      List<TableColumn> columnList = new List<TableColumn>();
      Dictionary<string, bool> columnData = new Dictionary<string, bool>();
      List<bool> uniqueKey = new List<bool>();
      List<string> columnName = new List<string>();
      List<string> columnType = new List<string>();
      string tableName = ((CreateTable)queryObj).GetTableName();
      columnList = ((CreateTable)queryObj).GetList();
      foreach(TableColumn column in columnList)
      {
        if((column.GetUniqueKey() == "PRIMARY KEY" ||(column.GetUniqueKey() == "primary key") || (column.GetUniqueKey() =="INDEX") || (column.GetUniqueKey() =="index")))
        {
          columnData.Add(column.GetColumnName(), true);
        }
        else
        {
          columnData.Add(column.GetColumnName(), false);
        }
        if (column.GetVarType() == "VARCHAR")
        {
          string range = column.GetVarRange();
          columnType.Add("VARCHAR(" + range + ")");
        }
        else
        {
          columnType.Add(column.GetVarType());
        }
      }
      
      m_Request = new Request();
      m_Parameters = new Object[5];
      m_Parameters[0] = GetDatabaseName(m_token);
      m_Parameters[1] = tableName;
      m_Parameters[2] = uniqueKey;
      m_Parameters[3] = columnName;
      m_Parameters[4] = columnType;

      m_Request.SetCallingMethod("CreateTable");
      m_Request.SetRequestType(RequestType.EXECUTE_QUERY);
      m_Request.SetRootServerCallback(callback);
      m_Request.SetMethodParameters(m_Parameters);

    }
 public void SelectDb(Statement queryObj, IRootServerCallback callback)
 {
   SelectDB selectdb = (SelectDB)queryObj;
   
   m_Request = new Request();
   m_Parameters = new Object[1];
   m_Parameters[0] = selectdb.GetDatabaseName();
   
   m_Request.SetCallingMethod("SelectDatabase");
   m_Request.SetRequestType(RequestType.EXECUTE_QUERY);
   m_Request.SetRootServerCallback(callback);
   m_Request.SetMethodParameters(m_Parameters);
   
 }
Exemple #17
0
 public void enQueueRequest(Request request)
 {
   m_RequestQueue.enQ(request);    
 }