Reads a hunt object from the database.
345136
def ReadHuntObject(self, hunt_id):
    """"""
    try:
      return self._DeepCopy(self.hunts[hunt_id])
    except KeyError:
      raise db.UnknownHuntError(hunt_id)
294341
private <T> T read_(Class<T> clazz, Object id) {
		Map<String, Object> objects = objects(clazz);
		return (T) objects.get(id.toString());
	}
1165715
public Object readObject(DatabaseReadable pReadable) throws SQLException {
        return readObject(pReadable.getId(), pReadable.getClass(), 
                          pReadable.getMapping());
    }
555425
def ReadHuntClientResourcesStats(self, hunt_id, cursor=None):
    """"""
    hunt_id_int = db_utils.HuntIDToInt(hunt_id)

    query = """
      SELECT
        COUNT(*),
        SUM(user_cpu_time_used_micros),
        SUM((user_cpu_time_used_micros) * (user_cpu_time_used_micros)),
        SUM(system_cpu_time_used_micros),
        SUM((system_cpu_time_used_micros) * (system_cpu_time_used_micros)),
        SUM(network_bytes_sent),
        SUM(network_bytes_sent * network_bytes_sent),
    """

    scaled_bins = [
        int(1000000 * b) for b in rdf_stats.ClientResourcesStats.CPU_STATS_BINS
    ]

    query += self._BinsToQuery(scaled_bins, "(user_cpu_time_used_micros)")
    query += ","
    query += self._BinsToQuery(scaled_bins, "(system_cpu_time_used_micros)")
    query += ","
    query += self._BinsToQuery(
        rdf_stats.ClientResourcesStats.NETWORK_STATS_BINS, "network_bytes_sent")

    query += " FROM flows "
    query += "FORCE INDEX(flows_by_hunt) "
    query += "WHERE parent_hunt_id = %s AND parent_flow_id IS NULL"

    cursor.execute(query, [hunt_id_int])

    response = cursor.fetchone()
    (count, user_sum, user_sq_sum, system_sum, system_sq_sum, network_sum,
     network_sq_sum) = response[:7]

    stats = rdf_stats.ClientResourcesStats(
        user_cpu_stats=rdf_stats.RunningStats(
            num=count,
            sum=db_utils.MicrosToSeconds(int(user_sum or 0)),
            sum_sq=int(user_sq_sum or 0) / 1e12,
        ),
        system_cpu_stats=rdf_stats.RunningStats(
            num=count,
            sum=db_utils.MicrosToSeconds(int(system_sum or 0)),
            sum_sq=int(system_sq_sum or 0) / 1e12,
        ),
        network_bytes_sent_stats=rdf_stats.RunningStats(
            num=count,
            sum=float(network_sum or 0),
            sum_sq=float(network_sq_sum or 0),
        ),
    )

    offset = 7
    stats.user_cpu_stats.histogram = rdf_stats.StatsHistogram()
    for b_num, b_max_value in zip(
        response[offset:], rdf_stats.ClientResourcesStats.CPU_STATS_BINS):
      stats.user_cpu_stats.histogram.bins.append(
          rdf_stats.StatsHistogramBin(range_max_value=b_max_value, num=b_num))

    offset += len(rdf_stats.ClientResourcesStats.CPU_STATS_BINS)
    stats.system_cpu_stats.histogram = rdf_stats.StatsHistogram()
    for b_num, b_max_value in zip(
        response[offset:], rdf_stats.ClientResourcesStats.CPU_STATS_BINS):
      stats.system_cpu_stats.histogram.bins.append(
          rdf_stats.StatsHistogramBin(range_max_value=b_max_value, num=b_num))

    offset += len(rdf_stats.ClientResourcesStats.CPU_STATS_BINS)
    stats.network_bytes_sent_stats.histogram = rdf_stats.StatsHistogram()
    for b_num, b_max_value in zip(
        response[offset:], rdf_stats.ClientResourcesStats.NETWORK_STATS_BINS):
      stats.network_bytes_sent_stats.histogram.bins.append(
          rdf_stats.StatsHistogramBin(range_max_value=b_max_value, num=b_num))

    query = """
      SELECT
        client_id, flow_id, user_cpu_time_used_micros,
        system_cpu_time_used_micros, network_bytes_sent
      FROM flows
      FORCE INDEX(flows_by_hunt)
      WHERE parent_hunt_id = %s AND parent_flow_id IS NULL AND
            (user_cpu_time_used_micros > 0 OR
             system_cpu_time_used_micros > 0 OR
             network_bytes_sent > 0)
      ORDER BY (user_cpu_time_used_micros + system_cpu_time_used_micros) DESC
      LIMIT 10
    """

    cursor.execute(query, [hunt_id_int])

    for cid, fid, ucpu, scpu, nbs in cursor.fetchall():
      client_id = db_utils.IntToClientID(cid)
      flow_id = db_utils.IntToFlowID(fid)
      stats.worst_performers.append(
          rdf_client_stats.ClientResources(
              client_id=client_id,
              session_id=rdfvalue.RDFURN(client_id).Add(flow_id),
              cpu_usage=rdf_client_stats.CpuSeconds(
                  user_cpu_time=db_utils.MicrosToSeconds(ucpu),
                  system_cpu_time=db_utils.MicrosToSeconds(scpu),
              ),
              network_bytes_sent=nbs))

    return stats
1350201
public Object read(Object key) throws SQLException {
        if (key instanceof Integer) {
            return base.getObject((Integer) key);
        } else {
            return base.getObject((String) key);
        }
    }
982571
def _read_objects(cls, soup, game):
        
        players = Players()
        players.game = Players.Game()
        # game data
        players.game.venue = soup.game['venue']
        players.game.date = soup.game['date']
        # players & team data
        for team in soup.find_all('team'):
            team_object = cls._get_team(team)
            if team['type'] == Game.TEAM_TYPE_HOME:
                # team data(home)
                players.home_team = team_object
            elif team['type'] == Game.TEAM_TYPE_AWAY:
                # team data(away)
                players.away_team = team_object
            # player data
            players.rosters.update(
                    {player['id']: cls.Player(player, game.retro_game_id) for player in team.find_all('player')}
            )
            # coach data
            players.coaches.update(
                    {coach['id']: cls.Coach(coach, game.retro_game_id, team_object) for coach in team.find_all('coach')}
            )
        # umpire data
        umpires = soup.find('umpires')
        players.umpires.update(
                {umpire['id']: cls.Umpire(umpire, game.retro_game_id) for umpire in umpires.find_all('umpire')}
        )
        return players
767667
public void read(@WillClose InputStream in) throws IOException, PropertyDatabaseFormatException {
        BufferedReader reader = null;

        try {
            reader = new BufferedReader(Util.getReader(in));
            String line;
            while ((line = reader.readLine()) != null) {
                line = line.trim();
                if ("".equals(line)) {
                    continue;
                }
                int bar = line.indexOf('|');
                if (bar < 0) {
                    throw new PropertyDatabaseFormatException("Invalid property database: missing separator");
                }
                KeyType key = parseKey(line.substring(0, bar));
                ValueType property = decodeProperty(line.substring(bar + 1));

                setProperty(key, property);
            }
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException e) {
                // Ignore
            }
        }
    }
1129530
def ReadHuntCounters(self, hunt_id, cursor=None):
    """"""
    hunt_id_int = db_utils.HuntIDToInt(hunt_id)

    query = ("SELECT flow_state, COUNT(*) "
             "FROM flows "
             "FORCE INDEX(flows_by_hunt) "
             "WHERE parent_hunt_id = %s AND parent_flow_id IS NULL "
             "GROUP BY flow_state")

    cursor.execute(query, [hunt_id_int])
    counts_by_state = dict(cursor.fetchall())

    num_successful_clients = counts_by_state.get(
        int(rdf_flow_objects.Flow.FlowState.FINISHED), 0)
    num_failed_clients = counts_by_state.get(
        int(rdf_flow_objects.Flow.FlowState.ERROR), 0)
    num_crashed_clients = counts_by_state.get(
        int(rdf_flow_objects.Flow.FlowState.CRASHED), 0)
    num_clients = sum(counts_by_state.values())

    query = """
    SELECT * FROM

      (
      SELECT COUNT(client_id)
      FROM flows
      FORCE INDEX(flows_by_hunt)
      WHERE parent_hunt_id = %s AND parent_flow_id IS NULL AND
            num_replies_sent > 0) counters,

      (
      SELECT SUM(user_cpu_time_used_micros + system_cpu_time_used_micros),
             SUM(network_bytes_sent),
             SUM(num_replies_sent)
      FROM flows
      FORCE INDEX(flows_by_hunt)
      WHERE parent_hunt_id = %s AND parent_flow_id IS NULL) resources
    """

    cursor.execute(query, [hunt_id_int, hunt_id_int])
    (
        num_clients_with_results,
        total_cpu_seconds,
        total_network_bytes_sent,
        num_results,
    ) = cursor.fetchone()

    return db.HuntCounters(
        num_clients=num_clients,
        num_successful_clients=num_successful_clients,
        num_failed_clients=num_failed_clients,
        num_clients_with_results=num_clients_with_results,
        num_crashed_clients=num_crashed_clients,
        num_results=int(num_results or 0),
        total_cpu_seconds=db_utils.MicrosToSeconds(int(total_cpu_seconds or 0)),
        total_network_bytes_sent=int(total_network_bytes_sent or 0))
650437
async def read(cls, id: int):
        """"""
        data = await cls._handler.read(id=id)
        return cls(data)
11247
def ProcessHuntFlowLog(flow_obj, log_msg):
  """"""

  if not hunt.IsLegacyHunt(flow_obj.parent_hunt_id):
    return

  hunt_urn = rdfvalue.RDFURN("hunts").Add(flow_obj.parent_hunt_id)
  flow_urn = hunt_urn.Add(flow_obj.flow_id)
  log_entry = rdf_flows.FlowLog(
      client_id=flow_obj.client_id,
      urn=flow_urn,
      flow_name=flow_obj.flow_class_name,
      log_message=log_msg)
  with data_store.DB.GetMutationPool() as pool:
    grr_collections.LogCollection.StaticAdd(
        hunt_urn.Add("Logs"), log_entry, mutation_pool=pool)
1086550
@Override
	public ServerResponse readObject(ZooPC pc) {
		long oid = pc.jdoZooGetOid();
		FilePos oie = oidIndex.findOid(oid);
		if (oie == null) {
			return new ServerResponse(RESULT.OBJECT_NOT_FOUND,
					"ERROR OID not found: " + Util.oidToString(oid));
//			throw DBLogger.newObjectNotFoundException(
//					"ERROR OID not found: " + Util.oidToString(oid));
		}
		
		try {
	        final DataDeSerializer dds = ddsPool.get();
            dds.readObject(pc, oie.getPage(), oie.getOffs());
	        ddsPool.offer(dds);
		} catch (RuntimeException e) {
			if (DBLogger.isUser(e)) {
				throw e;
			}
			throw DBLogger.newFatal("ERROR reading object: " + Util.oidToString(oid), e);
		}
		return new ServerResponse(RESULT.SUCCESS);
	}
648281
def fetch_all_objects_from_db(self,
                                  cls: Type[T],
                                  table: str,
                                  fieldlist: Sequence[str],
                                  construct_with_pk: bool,
                                  *args) -> List[T]:
        """"""
        return self.fetch_all_objects_from_db_where(
            cls, table, fieldlist, construct_with_pk, None, *args)
728755
def CountHuntFlows(self,
                     hunt_id,
                     filter_condition=db.HuntFlowsCondition.UNSET):
    """"""

    return len(
        self.ReadHuntFlows(
            hunt_id, 0, sys.maxsize, filter_condition=filter_condition))
51289
def _HuntObjectFromRow(self, row):
    """"""
    (
        create_time,
        last_update_time,
        creator,
        duration_micros,
        client_rate,
        client_limit,
        hunt_state,
        hunt_state_comment,
        init_start_time,
        last_start_time,
        num_clients_at_start_time,
        description,
        body,
    ) = row
    hunt_obj = rdf_hunt_objects.Hunt.FromSerializedString(body)
    hunt_obj.duration = rdfvalue.Duration.FromMicroseconds(duration_micros)
    hunt_obj.create_time = mysql_utils.TimestampToRDFDatetime(create_time)
    hunt_obj.last_update_time = mysql_utils.TimestampToRDFDatetime(
        last_update_time)

    # Checks below are needed for hunts that were written to the database before
    # respective fields became part of F1 schema.
    if creator is not None:
      hunt_obj.creator = creator

    if client_rate is not None:
      hunt_obj.client_rate = client_rate

    if client_limit is not None:
      hunt_obj.client_limit = client_limit

    if hunt_state is not None:
      hunt_obj.hunt_state = hunt_state

    if hunt_state_comment is not None:
      hunt_obj.hunt_state_comment = hunt_state_comment

    if init_start_time is not None:
      hunt_obj.init_start_time = mysql_utils.TimestampToRDFDatetime(
          init_start_time)

    if last_start_time is not None:
      hunt_obj.last_start_time = mysql_utils.TimestampToRDFDatetime(
          last_start_time)

    if num_clients_at_start_time is not None:
      hunt_obj.num_clients_at_start_time = num_clients_at_start_time

    if description is not None:
      hunt_obj.description = description

    return hunt_obj
642265
@Override
	public CloseableIterator<ZooPC> readAllObjects(long schemaId, boolean loadFromCache) {
		SchemaIndexEntry se = schemaIndex.getSchema(schemaId);
		if (se == null) {
			throw DBLogger.newUser("Schema not found for class: " + schemaId);
		}
		
		return new ObjectPosIterator(se.getObjectIndexIterator(), cache, objectReader, 
		        loadFromCache);
	}
881230
public ZooPC readObject(int page, int offs, boolean skipIfCached) {
        long clsOid = in.startReading(page, offs);
        long ts = in.getHeaderTimestamp();

        //Read first object:
        long oid = in.readLong();

        //check cache
        ZooPC pc = cache.findCoByOID(oid);
        if (skipIfCached && pc != null) {
            if (pc.jdoZooIsDeleted() || !pc.jdoZooIsStateHollow()) {
                //isDeleted() are filtered out later.
                return pc;
            }
        }

        ZooClassDef clsDef = cache.getSchema(clsOid);
        ObjectReader or = in;
        boolean isEvolved = false;
        if (clsDef.getNextVersion() != null) {
            isEvolved = true;
            GenericObject go = GenericObject.newInstance(clsDef, oid, false, cache);
            readGOPrivate(go, clsDef);
            clsDef = go.ensureLatestVersion();
            in = go.toStream();
            if (oid != in.readLong()) {
                throw new IllegalStateException();
            }
        }
        
        
        ZooPC pObj = getInstance(clsDef, oid, pc);
        pObj.jdoZooSetTimestamp(ts);

        readObjPrivate(pObj, clsDef);
        in = or;
        if (isEvolved) {
            //force object to be stored again
            //TODO is this necessary?
            pObj.jdoZooMarkDirty();
        }
        return pObj;
    }
1151404
async def read(self):
        """"""
        try:
            data = await self._stream_reader.readuntil(self.SEPARATOR)
        except asyncio.IncompleteReadError:
            self.connection_lost()
        else:
            query = self.decoder(data)
            if self.debug:
                access_logger.info("get query: {}".format(
                    query
                ), extra=self._extra)
            return query