public class Xob_xfer_regy_log_tbl { public static void Create_table(Db_conn p) { gplx.dbs.engines.sqlite.Sqlite_engine_.Tbl_create_and_delete(p, Tbl_name, Tbl_sql); } public static Db_stmt Insert_stmt(Db_conn p) { return Db_stmt_.new_insert_( p, Tbl_name, Fld_lnki_id, Fld_xfer_status, Fld_xfer_bin_tid, Fld_xfer_bin_msg); } public static void Insert(Db_stmt stmt, byte status, int id, byte wkr_tid, String wkr_msg) { stmt.Clear().Val_int(id).Val_byte(status).Val_byte(wkr_tid).Val_str(wkr_msg).Exec_insert(); } private static final String Tbl_sql = String_.Concat_lines_nl( "CREATE TABLE IF NOT EXISTS xfer_regy_log", "( lnki_id integer NOT NULL", ", xfer_status tinyint NOT NULL" // 0=todo; 1=fail; 2=pass; 3=done , ", xfer_bin_tid tinyint NOT NULL", ", xfer_bin_msg varchar(255) NOT NULL", ");"); public static final String Tbl_name = "xfer_regy_log", Fld_lnki_id = "lnki_id", Fld_xfer_status = "xfer_status", Fld_xfer_bin_tid = "xfer_bin_tid", Fld_xfer_bin_msg = "xfer_bin_msg"; }
public void Select_tasks_steps( Xobc_task_step_hash task_step_hash, Xobc_step_map_tbl step_map_tbl, byte[] wiki_abrv, String wiki_date) { task_step_hash.Clear(); Db_rdr rdr = conn.Stmt_sql( String_.Concat_lines_nl_skip_last( "SELECT DISTINCT sm.task_id, sm.step_id", "FROM " + tbl_name + " imps", " JOIN " + step_map_tbl.Tbl_name() + " sm ON sm.step_id = imps.step_id", "WHERE imps.wiki_abrv = ?", "AND imps.wiki_date = ?")) .Crt_bry_as_str(fld_wiki_abrv, wiki_abrv) .Crt_str(fld_wiki_date, wiki_date) .Exec_select__rls_auto(); try { while (rdr.Move_next()) { task_step_hash.Add(rdr.Read_int("task_id"), rdr.Read_int("step_id")); } } finally { rdr.Rls(); } }
private int Load_from_db(List_adp list, int uid_prv) { // prepare for page_tbl String sql = String_.Format( String_.Concat_lines_nl_skip_last // ANSI.Y ( "SELECT mp.xomp_uid", ", pp.page_id", ", pp.page_namespace", ", pp.page_title", ", pp.page_text_db_id", "FROM xomp_page mp", " JOIN <page_db>page pp ON mp.page_id = pp.page_id", "WHERE mp.xomp_uid > {0}", "AND mp.page_status = 0", "LIMIT {1}"), uid_prv, num_pages_per_load); this.attach_mgr.Conn_links_( new Db_attach_itm("page_db", wiki.Data__core_mgr().Db__core().Conn())); sql = attach_mgr.Resolve_sql(sql); // run page_tbl int rv = -1; Xomp_text_db_loader text_db_loader = new Xomp_text_db_loader(wiki); attach_mgr.Attach(); Db_rdr rdr = make_conn.Stmt_sql(sql).Exec_select__rls_auto(); try { while (rdr.Move_next()) { rv = rdr.Read_int("xomp_uid"); int text_db_id = rdr.Read_int("page_text_db_id"); Xomp_page_itm ppg = new Xomp_page_itm(rdr.Read_int("page_id")); ppg.Init_by_page( rdr.Read_int("page_namespace"), rdr.Read_bry_by_str("page_title"), text_db_id); list.Add(ppg); text_db_loader.Add(text_db_id, ppg); } } finally { rdr.Rls(); } attach_mgr.Detach(); text_db_loader.Load(); return rv; }
public static Fsdb_db_mgr new_src_bin_db_mgr(Xow_wiki wiki, String version) { String domain_str = wiki.Domain_str(); Fsdb_db_mgr rv = null; Io_url url = null; if (String_.Eq(version, "v1")) { url = wiki.Fsys_mgr() .File_dir() .OwnerDir() .GenSubDir(domain_str + "-prv"); // v1: EX: /xowa/file/en.wikipedia.org-prv/ rv = new Fsdb_db_mgr__v1(url); } else if (String_.Eq(version, "v2")) { url = wiki.Fsys_mgr().Root_dir().GenSubDir("prv"); // v2: EX: /xowa/wiki/en.wikipedia.org/prv/ rv = Fsdb_db_mgr_.new_detect(wiki, url, url); // note that v2 is prioritized over v1 } else throw Err_.new_wo_type("fsdb.make:unknown fsdb_type", "version", version); if (rv == null) throw Err_.new_wo_type( "fsdb.make:source fsdb not found", "version", version, "url", url.Raw()); return rv; }
private void Download_exec(Xodb_tbl_oimg_xfer_itm fsdb) { Io_stream_rdr src_rdr = src_bin_mgr.Find_as_rdr(Xof_exec_tid.Tid_wiki_page, fsdb); try { if (src_rdr == Io_stream_rdr_.Noop) { // download failed ++exec_fail; usr_dlg.Warn_many( "", "", "failed: ttl=~{0}", String_.Format("[[File:{0}|{1}px]]", fsdb.Orig_ttl(), fsdb.Html_w())); Print_progress(fsdb); } else { // download passed long src_rdr_len = src_rdr.Len(); int lnki_tier_id = fsdb.Lnki_tier_id(); if (src_rdr_len > download_size_max && !Int_.In(lnki_tier_id, download_keep_tier_ids)) { usr_dlg.Warn_many( "", "", "skipped; ttl=~{0} w=~{1} size=~{2} tier=~{3}", fsdb.Orig_ttl(), fsdb.Lnki_w(), src_rdr_len, lnki_tier_id); return; } if (trg_bin_fil == null) // no trg_bin_fil Make_trg_bin_file(Bool_.Y, fsdb, src_rdr_len); else if (trg_bin_fil.Bin_len() + src_rdr_len > trg_bin_db_max) // or trg_bin_fil is out of space Make_trg_bin_file(Bool_.N, fsdb, src_rdr_len); else if (prv_lnki_tier_id != lnki_tier_id) { // or tier has changed if (prv_lnki_tier_id != -1 && !bin_db_mgr.Schema_is_1()) // do not increment dbs for v1 Make_trg_bin_file(Bool_.Y, fsdb, src_rdr_len); prv_lnki_tier_id = lnki_tier_id; } trg_bin_updater.Save_bin(trg_mnt_itm, trg_atr_fil, trg_bin_fil, fsdb, src_rdr, src_rdr_len); } } finally { src_rdr.Rls(); } }
public Xobc_import_step_itm[] Select_by_task_id(int task_id) { List_adp list = List_adp_.New(); Db_rdr rdr = conn.Stmt_sql( Db_sql_.Make_by_fmt( String_.Ary( "SELECT s.*", "FROM import_step s", " JOIN step_map sm ON s.step_id = sm.step_id", "WHERE sm.task_id = {0}"), task_id)) .Exec_select__rls_auto(); try { while (rdr.Move_next()) { list.Add(New_itm(rdr)); } } finally { rdr.Rls(); } return (Xobc_import_step_itm[]) list.To_ary_and_clear(Xobc_import_step_itm.class); }
@Override public void Cmd_bgn(Xob_bldr bldr) { wiki.Init_assert(); this.poll_interval = poll_mgr.Poll_interval(); this.bin_db_mgr = new Xob_bin_db_mgr(ns_ids); // src_bin_mgr if (src_bin_mgr__fsdb_version != null) { this.src_fsdb_wkr = Xof_bin_wkr__fsdb_sql.new_(wiki.File__mnt_mgr()); src_bin_mgr.Wkrs__add(src_fsdb_wkr); src_fsdb_wkr.Mnt_mgr().Ctor_by_load(new_src_bin_db_mgr(wiki, src_bin_mgr__fsdb_version)); src_fsdb_wkr.Mnt_mgr() .Mnts__get_main() .Txn_bgn(); // NOTE: txn on atr speeds up from 50 -> 300; DATE:2015-03-21 if (src_bin_mgr__fsdb_skip_wkrs != null) { src_fsdb_wkr.Skip_mgr_init( src_fsdb_wkr.Mnt_mgr().Mnts__get_main().Cfg_mgr(), src_bin_mgr__fsdb_skip_wkrs); } if (src_bin_mgr__cache_enabled) { usr_dlg.Prog_many("", "", "src_bin_mgr.cache.bgn"); src_fsdb_wkr.Mnt_mgr().Mnts__get_main().Atr_mgr().Db__core().Fil_cache_enabled_y_(); usr_dlg.Prog_many("", "", "src_bin_mgr.cache.end"); } } if (src_bin_mgr__wmf_enabled) { Xof_bin_wkr__http_wmf wmf_wkr = Xof_bin_wkr__http_wmf.new_(wiki); src_bin_mgr.Wkrs__add(wmf_wkr); wmf_wkr.Fail_timeout_( 0); // 1000; NOTE: set Fail_timeout here; DATE:2014-06-21; NOTE: do not put in ctor, or // else will be 1st wkr; DATE:2014-06-28 } // trg_mnt_itm this.trg_bin_db_max = app.Api_root().Bldr().Wiki().Import().File_db_max(); Io_url trg_file_dir_v1 = String_.Eq(trg_bin_mgr__fsdb_version, "v1") ? wiki.Fsys_mgr().File_dir().GenNewNameOnly(wiki.Domain_str() + "-prv") : wiki.Fsys_mgr().File_dir(); // NOTE: convoluted way of setting trg to -prv if // trg_bin_mgr__fsdb_version_v1 is set; otherwise set to // "en.wikipedia.org" which will noop; DATE:2015-12-02 Fsdb_db_mgr trg_db_mgr = Fsdb_db_mgr_.new_detect(wiki, wiki.Fsys_mgr().Root_dir(), trg_file_dir_v1); if (trg_db_mgr == null) trg_db_mgr = Fsdb_db_mgr__v2_bldr.Get_or_make(wiki, Bool_.Y); Fsm_mnt_mgr trg_mnt_mgr = new Fsm_mnt_mgr(); trg_mnt_mgr.Ctor_by_load(trg_db_mgr); trg_mnt_mgr.Mnts__get_insert_idx_( Fsm_mnt_mgr .Mnt_idx_main); // NOTE: do not delete; mnt_mgr default to Mnt_idx_user; DATE:2014-04-25 this.trg_mnt_itm = trg_mnt_mgr.Mnts__get_insert(); Fsm_mnt_mgr.Patch( trg_mnt_itm.Cfg_mgr() .Tbl()); // NOTE: always patch again; fsdb_make may be run separately without lnki_temp; // DATE:2014-04-26 this.trg_atr_fil = trg_mnt_itm.Atr_mgr().Db__core(); this.trg_cfg_mgr = trg_mnt_itm.Cfg_mgr(); bin_db_mgr.Init_by_mnt_mgr(trg_mnt_mgr); trg_atr_fil.Conn().Txn_bgn("bldr__fsdb_make__trg_atr_fil"); if (!trg_atr_fil.Conn() .Eq(trg_cfg_mgr.Tbl().Conn())) // need to create txn for v1; DATE:2015-07-04 trg_cfg_mgr.Tbl().Conn().Txn_bgn("bldr__fsdb_make__trg_cfg_fil"); // bldr_db Xob_db_file bldr_db = Xob_db_file.New__file_make(wiki.Fsys_mgr().Root_dir()); this.bldr_conn = bldr_db.Conn(); this.bldr_cfg_tbl = bldr_db.Tbl__cfg(); // NOTE: cfg and atr is in same db; use it bldr_cfg_tbl.Conn().Txn_bgn("bldr__fsdb_make__bldr_cfg_tbl"); }