Esempio n. 1
0
        private static void _DropIndexData(SqlConnection conn, string bingo_schema,
                                           BingoIndexID id, bool throw_if_not_exists)
        {
            BingoIndexData data = _extractIndexData(conn, bingo_schema, id, throw_if_not_exists);

            if (data != null)
            {
                data.DropTables(conn);
                data.DropTriggers(conn);
            }

            BingoSqlUtils.ExecNonQueryNoThrow(conn, "DELETE FROM {0} WHERE obj_id = '{1}'",
                                              _contextTable(bingo_schema), id.table_id);

            for (int i = index_data_list.Count - 1; i >= 0; i--)
            {
                BingoIndexDataRefs refs = (BingoIndexDataRefs)index_data_list[i];
                if (refs.index_data.id.Equals(id))
                {
                    index_data_list.RemoveAt(i);
                    BingoLog.logMessage("Sessions for table {0} have been released", id.InformationName(conn));
                }
            }
            if (data != null)
            {
                BingoLog.logMessage("Bingo index for table {0} has been dropped", id.InformationName(conn));
            }
        }
Esempio n. 2
0
        private static BingoIndexData GetIndexDataById(SqlConnection conn, string bingo_schema,
                                                       BingoIndexID id, int spid)
        {
            lock (index_data_list_lock)
            {
                foreach (BingoIndexDataRefs index_data_refs in index_data_list)
                {
                    if (index_data_refs.index_data.id.Equals(id))
                    {
                        if (!index_data_refs.session_ids.Contains(spid))
                        {
                            BingoLog.logMessage("Existing BingoIndexData added for spid={0} table={1}",
                                                spid, id.FullTableName(conn));
                            index_data_refs.session_ids.Add(spid);
                        }
                        return(index_data_refs.index_data);
                    }
                }

                BingoLog.logMessage("Extracting new BingoIndexData for spid={0} table={1}",
                                    spid, id.FullTableName(conn));

                BingoIndexData data = _extractIndexData(conn, bingo_schema, id, true);
                _AddIndexDataToList(spid, data);

                return(data);
            }
        }
Esempio n. 3
0
        private static void _AddIndexDataToList(int spid, BingoIndexData data)
        {
            BingoIndexDataRefs new_refs = new BingoIndexDataRefs();

            new_refs.index_data  = data;
            new_refs.session_ids = new List <int>();
            new_refs.session_ids.Add(spid);

            index_data_list.Add(new_refs);
        }
Esempio n. 4
0
        private static BingoIndexData _extractIndexData(SqlConnection conn, string bingo_schema,
                                                        BingoIndexID id, bool throw_if_not_exists)
        {
            BingoIndexData data = null;

            using (SqlCommand cmd = new SqlCommand(String.Format(
                                                       "SELECT id_column, data_column, type FROM {0} WHERE obj_id = '{1}'",
                                                       _contextTable(bingo_schema), id.table_id), conn))
            {
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    if (!reader.Read())
                    {
                        if (throw_if_not_exists)
                        {
                            throw new Exception("Cannot find Bingo index for table with id=" + id.table_id);
                        }
                        else
                        {
                            return(null);
                        }
                    }

                    string id_column   = Convert.ToString(reader[0]);
                    string data_column = Convert.ToString(reader[1]);
                    string type        = Convert.ToString(reader[2]);

                    if (type.ToLower().Equals("molecule"))
                    {
                        data = new MangoIndexData(id, id_column, data_column, bingo_schema);
                    }
                    if (type.ToLower().Equals("reaction"))
                    {
                        data = new RingoIndexData(id, id_column, data_column, bingo_schema);
                    }

                    if (data == null)
                    {
                        throw new Exception("unknown type: " + type);
                    }
                }
            }

            data.keep_cache =
                (BingoConfig.getInt(conn, bingo_schema, "KEEP_CACHE", id.table_id) != 0);

            return(data);
        }
Esempio n. 5
0
      private static IEnumerable<FetchedData> _Fetch (SqlString query, string search_type,
         bool highlighting, object[] ext_options, SqlConnection conn,
         BingoIndexData index_data, string options_str, int? id_next_from)
      {
         int? storage_id_next_from = null;
         if (id_next_from.HasValue)
         {
            // -1 means start of the iterations
            if (id_next_from.Value != -1)
            {
               storage_id_next_from = index_data.getStorageIdById(conn, id_next_from.Value);
               if (!storage_id_next_from.HasValue)
                  throw new Exception(String.Format("Cannot find record with id={0}", id_next_from));
            }
            else
               storage_id_next_from = -1;
         }

         IEnumerable<FetchedData> fetched;
         if (search_type == "SUB" || search_type == "SMARTS")
         {
            MangoFastIndexFetch fetch_sub = new MangoFastIndexFetch((MangoIndexData)index_data);
            fetch_sub.prepareSub(query.Value, options_str, highlighting, search_type == "SMARTS");
            fetch_sub.nextAfterStorageId = storage_id_next_from;
            fetched = fetch_sub.fetch(conn);
         }
         else if (search_type == "EXACT")
         {
            MangoShadowFetch fetch_exact = new MangoShadowFetch((MangoIndexData)index_data);
            fetch_exact.prepareExact(query.Value, options_str);
            fetch_exact.nextAfterStorageId = storage_id_next_from;
            fetched = fetch_exact.fetch(conn);
         }
         else if (search_type == "SIM")
         {
            MangoFastIndexFetch fetch_sim = new MangoFastIndexFetch((MangoIndexData)index_data);
            float min = (float)ext_options[0];
            float max = (float)ext_options[1];

            fetch_sim.prepareSimilarity(query.Value, options_str, min, max);
            fetch_sim.nextAfterStorageId = storage_id_next_from;
            fetched = fetch_sim.fetch(conn);
         }
         else if (search_type == "MASS")
         {
            MangoShadowFetch fetch_mass = new MangoShadowFetch((MangoIndexData)index_data);
            float? min = (float?)ext_options[0];
            float? max = (float?)ext_options[1];

            fetch_mass.prepareMass(min, max);
            fetch_mass.nextAfterStorageId = storage_id_next_from;
            fetched = fetch_mass.fetch(conn);
         }
         else if (search_type == "GROSS")
         {
            MangoShadowFetch fetch_gross = new MangoShadowFetch((MangoIndexData)index_data);
            fetch_gross.prepareGross(query.Value);
            fetch_gross.nextAfterStorageId = storage_id_next_from;
            fetched = fetch_gross.fetch(conn);
         }
         else if (search_type == "RSUB" || search_type == "RSMARTS")
         {
            RingoFastIndexFetch fetch_sub = new RingoFastIndexFetch((RingoIndexData)index_data);
            fetch_sub.prepareSub(query.Value, options_str, highlighting, search_type == "RSMARTS");
            fetch_sub.nextAfterStorageId = storage_id_next_from;
            fetched = fetch_sub.fetch(conn);
         }
         else if (search_type == "REXACT")
         {
            RingoShadowFetch fetch_exact = new RingoShadowFetch((RingoIndexData)index_data);
            fetch_exact.prepareExact(query.Value, options_str);
            fetch_exact.nextAfterStorageId = storage_id_next_from;
            fetched = fetch_exact.fetch(conn);
         }
         else
            throw new Exception("Unknown search type: " + search_type);
         return fetched;
      }
Esempio n. 6
0
      private static bool _AddReactionToIndex (SqlConnection conn, BingoIndexData bingo_data)
      {
         RingoIndexData data = (RingoIndexData)bingo_data;

         int id;
         RingoIndex index = new RingoIndex();
         if (!index.readPrepared(out id))
         {
            string message =
               String.Format("Reaction with ID={0} wasn't added to the index: {1}",
                  id, BingoCore.lib.bingoGetWarning());
            SqlContext.Pipe.Send(message);
            BingoLog.logMessage(message);
            return false;
         }

         byte[] new_data = new byte[index.crf.Length + 4];
         index.crf.CopyTo(new_data, 4);

         MemoryStream stream = new MemoryStream(new_data, 0, 4, true);
         BinaryWriter writer = new BinaryWriter(stream);
         writer.Write(id);

         int storage_id = data.storage.add(new_data, conn);
         data.fingerprints.addFingerprint(conn, index.fingerprint, storage_id);

         data.addToShadowTable(conn, index, id, storage_id);
         return false;
      }
Esempio n. 7
0
      private static bool _AddMoleculeToIndex (SqlConnection conn, BingoIndexData bingo_data)
      {
         MangoIndexData data = (MangoIndexData)bingo_data;

         MangoIndex index = new MangoIndex();
         int id;
         if (!index.readPrepared(out id))
         {
            string message =
               String.Format("Molecule with ID={0} wasn't added to the index: {1}",
                  id, BingoCore.lib.bingoGetWarning());
            SqlContext.Pipe.Send(message);
            BingoLog.logMessage(message);
            return false;
         }
         // 4 bytes for Id, 2 bytes for similarity fingerprints bits counts
         byte[] new_data = new byte[index.cmf.Length + 4 + 2];
         index.cmf.CopyTo(new_data, 6);

         MemoryStream stream = new MemoryStream(new_data, 0, 6, true);
         BinaryWriter writer = new BinaryWriter(stream);
         writer.Write(id);
         writer.Write((short)index.sim_fp_bits_count);

         int storage_id = data.storage.add(new_data, conn);
         data.fingerprints.addFingerprint(conn, index.fingerprint, storage_id);

         data.addToShadowTable(conn, index, id, storage_id);
         return true;
      }
Esempio n. 8
0
 public BingoStorage(BingoIndexData index_data)
 {
     _index_data = index_data;
 }
Esempio n. 9
0
 public BingoStorage (BingoIndexData index_data)
 {
    _index_data = index_data;
 }
Esempio n. 10
0
 public BingoFingerprints (BingoIndexData index_data)
 {
    _index_data = index_data;
    _fp_bytes = -1;
    _chunk_bytes = 8000;
 }
Esempio n. 11
0
 public BingoFingerprints(BingoIndexData index_data)
 {
     _index_data  = index_data;
     _fp_bytes    = -1;
     _chunk_bytes = 8000;
 }
Esempio n. 12
0
      private static void _AddIndexDataToList (int spid, BingoIndexData data)
      {
         BingoIndexDataRefs new_refs = new BingoIndexDataRefs();

         new_refs.index_data = data;
         new_refs.session_ids = new List<int>();
         new_refs.session_ids.Add(spid);

         index_data_list.Add(new_refs);
      }