Beispiel #1
0
 public static byte[] Eval_val_or(
     Xop_ctx ctx,
     byte[] src,
     Xot_invk caller,
     Xot_invk self,
     int self_args_len,
     int i,
     byte[] or) {
   if (i >= self_args_len) return or;
   Bry_bfr bfr = Bry_bfr_.New();
   Arg_nde_tkn nde = self.Args_get_by_idx(i);
   nde.Val_tkn().Tmpl_evaluate(ctx, src, caller, bfr);
   return bfr.To_bry_and_clear_and_trim();
 }
Beispiel #2
0
 public static byte[] Eval_arg_or(
     Xop_ctx ctx,
     byte[] src,
     Xot_invk caller,
     Xot_invk self,
     int self_args_len,
     int i,
     byte[] or) {
   if (i >= self_args_len) return or;
   Arg_nde_tkn nde = self.Args_get_by_idx(i);
   Bry_bfr bfr = Bry_bfr_.New();
   Eval_arg_or(bfr, ctx, src, caller, self, nde, or);
   return bfr.To_bry_and_clear_and_trim();
 }
public class Xoh_page_bfr {
  private byte toc_mode;
  private Bry_bfr head_bfr;
  private final Bry_bfr body_bfr = Bry_bfr_.New();

  public void Init(Bry_bfr head_bfr) {
    this.toc_mode = Xoh_toc_data.Toc_mode__none;
    this.head_bfr = head_bfr;
    body_bfr.Clear();
  }

  public Bry_bfr Split_by_toc(byte toc_mode) {
    this.toc_mode = toc_mode;
    return body_bfr;
  }

  public void Commit(Xoa_page pg) {
    boolean toc_mode_enabled = true,
        toc_mode_is_pgbnr = false; // default to Xoh_toc_data_.Toc_mode__basic
    switch (toc_mode) {
      case Xoh_toc_data.Toc_mode__none:
        toc_mode_enabled = false;
        break;
      case Xoh_toc_data.Toc_mode__pgbnr:
        toc_mode_is_pgbnr = true;
        break;
    }

    // set flags
    pg.Html_data().Toc_mgr().Exists_y_();
    pg.Html_data().Head_mgr().Itm__pgbnr().Enabled_(toc_mode_is_pgbnr);

    // build bfr by add bfr_0, toc, body_bfr
    if (toc_mode_enabled) {
      pg.Html_data()
          .Toc_mgr()
          .To_html(head_bfr, gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Basic, toc_mode_is_pgbnr);
      head_bfr.Add_bfr_and_clear(body_bfr);
    }
  }
}
public class Split_wkr__rndm implements Split_wkr {
  private final Split_rslt_wkr__rndm rslt_wkr = new Split_rslt_wkr__rndm();
  private final Bry_bfr tmp_bfr = Bry_bfr_.New();
  private final Db_attach_mgr attach_mgr = new Db_attach_mgr();
  private Rndm_bldr_wkr bldr;
  private int cur_ns_id = -1;

  public void Split__init(Split_ctx ctx, Xow_wiki wiki, Db_conn wkr_conn) {
    this.bldr = Rndm_addon.Get(wiki).Mgr().New_bldr();
    ctx.Rslt_mgr().Reg_wkr(rslt_wkr);
  }

  public void Split__term(Split_ctx ctx) {
    bldr.Exec_qry_end();
  }

  public void Split__trg__1st__new(Split_ctx ctx, Db_conn trg_conn) {
    Rndm_qry_tbl mgr_tbl = new Rndm_qry_tbl(trg_conn);
    mgr_tbl.Create_tbl();
  }

  public void Split__trg__nth__new(Split_ctx ctx, Db_conn trg_conn) {
    if (cur_ns_id != ctx.Trg_ns()) {
      if (cur_ns_id != -1) bldr.Exec_qry_end();
      cur_ns_id = ctx.Trg_ns();
      bldr.Exec_qry_bgn(Rndm_qry_itm.New_by_ns(ctx.Wiki(), cur_ns_id));
    }
    bldr.Exec_rng_bgn();
    bldr.Conn().Txn_bgn("rndm");
  }

  public void Split__trg__nth__rls(Split_ctx ctx, Db_conn trg_conn) {
    // make rndm_rng and add
    Rndm_rng_itm rng_itm = bldr.Exec_rng_end_or_null();
    if (rng_itm == null) return;
    Rndm_rng_tbl rng_tbl = new Rndm_rng_tbl(trg_conn);
    rng_tbl.Create_tbl();
    Db_stmt rng_stmt = rng_tbl.Insert_stmt();
    rng_tbl.Insert(
        rng_stmt, rng_itm.Mgr_idx(), rng_itm.Rng_idx(), rng_itm.Seq_bgn(), rng_itm.Seq_end());
    rng_stmt.Rls();
    bldr.Conn().Txn_end();

    // make rndm_seq and bulk copy
    Rndm_seq_tbl seq_tbl = new Rndm_seq_tbl(trg_conn);
    seq_tbl.Create_tbl();
    Split_tbl_.Bld_insert_by_select(tmp_bfr, seq_tbl.Tbl_name(), seq_tbl.Flds());
    tmp_bfr.Add_str_u8_fmt(
        "WHERE {0} = {1} AND {2} = {3}",
        seq_tbl.Fld__qry_idx(), bldr.Qry_idx(), seq_tbl.Fld__rng_idx(), bldr.Rng_idx());
    attach_mgr.Conn_main_(trg_conn).Conn_links_(new Db_attach_itm("src_db", bldr.Conn()));
    attach_mgr.Exec_sql(tmp_bfr.To_str_and_clear());
    //			bldr.Conn().Txn_bgn("rndm");
  }

  public void Split__exec(Split_ctx ctx, Split_rslt_mgr rslt_mgr, Xowd_page_itm page, int page_id) {
    if (page.Ns_id() == gplx.xowa.wikis.nss.Xow_ns_.Tid__main && !page.Redirected()) {
      bldr.Exec_seq_itm(page.Id());
      rslt_wkr.On__nth__itm(
          Rndm_seq_tbl.Db_row_size_fixed, bldr.Qry_idx(), bldr.Rng_idx(), bldr.Seq_in_qry());
    }
  }

  public void Split__pages_loaded(
      Split_ctx ctx, int ns_id, int score_bgn, int score_end) {} // rndm_wkr has no caching
}