-/* $Id: zebraapi.c,v 1.94 2003-03-25 19:56:01 adam Exp $
+/* $Id: zebraapi.c,v 1.102 2003-05-20 21:39:57 adam Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
Index Data Aps
assert (res);
- yaz_log (LOG_DEBUG, "zebra_register_open rw = %d useshadow=%d p=%p",
+ yaz_log (LOG_LOG, "zebra_register_open rw = %d useshadow=%d p=%p",
rw, useshadow, reg);
-
+
reg->dh = data1_createx (DATA1_FLAG_XML);
if (!reg->dh)
return 0;
zebraRankInstall (reg, rank1_class);
zebraRankInstall (reg, rankzv_class);
+ zebraRankInstall (reg, rankliv_class);
recordCompression = res_get_def (res, "recordCompression", "none");
if (!strcmp (recordCompression, "none"))
static void zebra_register_close (ZebraService zs, struct zebra_register *reg)
{
ASSERTZS;
- yaz_log(LOG_DEBUG, "zebra_register_close p=%p", reg);
+ yaz_log(LOG_LOG, "zebra_register_close p=%p", reg);
reg->stop_flag = 0;
zebra_chdir (zs);
if (reg->records)
return 0;
}
-void zebra_search_rpn (ZebraHandle zh, ODR decode, ODR stream,
+void zebra_search_RPN (ZebraHandle zh,
Z_RPNQuery *query, const char *setname, int *hits)
{
ASSERTZH;
if (zebra_begin_read (zh))
return;
- resultSetAddRPN (zh, decode, stream, query,
+
+ zebra_livcode_transform(zh, query);
+
+ resultSetAddRPN (zh, query,
zh->num_basenames, zh->basenames, setname);
zebra_end_read (zh);
return 0;
}
-void zebra_admin_create (ZebraHandle zh, const char *database)
+void zebra_create_database (ZebraHandle zh, const char *database)
{
ZebraService zs;
ASSERTZH;
if (zebra_select_database (zh, database))
return;
- zebra_begin_trans (zh, 1);
+ if (zebra_begin_trans (zh, 1))
+ return;
zs = zh->service;
/* announce database */
int zebra_begin_trans (ZebraHandle zh, int rw)
{
+ yaz_log(LOG_LOG, "zebra_begin_trans rw=%d trans=%d", rw, zh->trans_no);
+ if (!zh->res)
+ {
+ zh->errCode = 2;
+ zh->errString = "zebra_begin_trans: no database selected";
+ return -1;
+ }
ASSERTZHRES;
assert (zh->res);
if (rw)
if (zh->trans_no != 1)
{
zh->errCode = 2;
- zh->errString = "write trans not allowed within read trans";
+ zh->errString = "zebra_begin_trans: write trans not allowed within read trans";
return -1;
}
+ if (zh->reg)
+ zebra_register_close (zh->service, zh->reg);
+
zh->trans_w_no = zh->trans_no;
zh->errCode=0;
- yaz_log (LOG_LOG, "zebra_begin_trans");
-
zh->records_inserted = 0;
zh->records_updated = 0;
zh->records_deleted = 0;
zh->reg = zebra_register_open (zh->service, zh->reg_name,
1, rval ? 1 : 0, zh->res,
zh->path_reg);
-
- zh->reg->seqno = seqno;
+ if (zh->reg)
+ zh->reg->seqno = seqno;
+ else
+ {
+ zebra_set_state (zh, 'o', seqno);
+
+ zebra_unlock (zh->lock_shadow);
+ zebra_unlock (zh->lock_normal);
+
+ zh->trans_no--;
+ zh->trans_w_no = 0;
+
+ zh->errCode = 2;
+ zh->errString = "zebra_begin_trans: cannot open register";
+ yaz_log(LOG_FATAL, zh->errString);
+ return -1;
+ }
}
else
{
zh->res, zh->path_reg);
if (!zh->reg)
{
+ zebra_unlock (zh->lock_normal);
+ zebra_unlock (zh->lock_shadow);
+ zh->trans_no--;
zh->errCode = 109;
return -1;
}
return 0;
}
-void zebra_end_trans (ZebraHandle zh) {
- ZebraTransactionStatus dummy;
- zebra_end_transaction(zh, &dummy);
+int zebra_end_trans (ZebraHandle zh)
+{
+ ZebraTransactionStatus dummy;
+ return zebra_end_transaction(zh, &dummy);
}
-void zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status)
+int zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status)
{
char val;
int seqno;
status->utime = 0;
status->stime = 0;
+ if (!zh->res || !zh->reg)
+ {
+ zh->errCode = 2;
+ zh->errString = "zebra_end_trans: no open transaction";
+ return -1;
+ }
if (zh->trans_no != zh->trans_w_no)
{
zh->trans_no--;
if (zh->trans_no != 0)
- return;
+ return 0;
/* release read lock */
zebra_flush_reg (zh);
+ resultSetInvalidate (zh);
+
zebra_register_close (zh->service, zh->reg);
zh->reg = 0;
status->utime = (long) (zh->tms2.tms_utime - zh->tms1.tms_utime);
status->stime = (long) (zh->tms2.tms_stime - zh->tms1.tms_stime);
#endif
+ return 0;
}
void zebra_repository_update (ZebraHandle zh)
int zebra_clean (ZebraHandle zh)
{
- zebra_commit_ex(zh, 1);
+ return zebra_commit_ex(zh, 1);
}
int zebra_commit (ZebraHandle zh)
{
- zebra_commit_ex(zh, 0);
+ return zebra_commit_ex(zh, 0);
}
int zebra_init (ZebraHandle zh)
int zebra_record_insert (ZebraHandle zh, const char *buf, int len)
{
int sysno = 0;
- int olderr;
ASSERTZH;
zh->errCode=0;
- zebra_begin_trans (zh, 1);
- if (zh->errCode)
- return 0; /* bad sysno */
+ if (zebra_begin_trans (zh, 1))
+ return 0;
extract_rec_in_mem (zh, "grs.sgml",
buf, len,
"Default", /* database */
1 /* store_keys */,
1 /* store_data */,
0 /* match criteria */);
- olderr=zh->errCode;
- zebra_end_trans (zh);
- if (olderr)
- zh->errCode=olderr;
+ if (zebra_end_trans (zh))
+ return 0;
return sysno;
}
}
const char *zebra_get_resource(ZebraHandle zh,
- const char *name, const char *defaultvalue)
+ const char *name, const char *defaultvalue)
{
ASSERTZH;
zh->errCode=0;
const char *recordType,
int sysno, const char *match, const char *fname,
const char *buf, int buf_size,
- int force_update) // This one is ignored
+ int force_update) /* This one is ignored */
{
int res;
zebra_begin_trans(zh, 1);
res=bufferExtractRecord (zh, buf, buf_size, rGroup,
- 0, // delete_flag
- 0, // test_mode,
+ 0, /* delete_flag */
+ 0, /* test_mode */
recordType,
&sysno,
match, fname,
force_update,
- 0); // allow_update
+ 0); /* allow_update */
zebra_end_trans(zh);
if (res < 0) return (res);
return sysno;
zebra_begin_trans(zh, 1);
res=bufferExtractRecord (zh, buf, buf_size, rGroup,
- 0, // delete_flag
- 0, // test_mode,
+ 0, /* delete_flag */
+ 0, /* test_mode */
recordType,
&sysno,
match, fname,
force_update,
- 1); // allow_update
+ 1); /* allow_update */
zebra_end_trans(zh);
return sysno;
}
zebra_begin_trans(zh, 1);
res=bufferExtractRecord (zh, buf, buf_size, rGroup,
- 1, // delete_flag
- 0, // test_mode,
+ 1, /* delete_flag */
+ 0, /* test_mode */
recordType,
&sysno,
match,fname,
force_update,
- 1); // allow_update
+ 1); /* allow_update */
zebra_end_trans(zh);
return sysno;
}
is not mandatory. (it's repeatable now, also in zebraapi.c)
*/
-void zebra_search_RPN (ZebraHandle zh, ODR decode, ODR stream,
- Z_RPNQuery *query, const char *setname, int *hits)
-{
- zh->hits = 0;
- *hits = 0;
-
- if (zebra_begin_read (zh))
- return;
- resultSetAddRPN (zh, decode, stream, query,
- zh->num_basenames, zh->basenames, setname);
-
- zebra_end_read (zh);
-
- *hits = zh->hits;
-}
-
-int zebra_search_PQF (ZebraHandle zh,
- ODR odr_input, ODR odr_output,
- const char *pqf_query,
+int zebra_search_PQF (ZebraHandle zh, const char *pqf_query,
const char *setname)
-
{
- int hits;
+ int hits = 0;
Z_RPNQuery *query;
- query = p_query_rpn (odr_input, PROTO_Z3950, pqf_query);
+ ODR odr = odr_createmem(ODR_ENCODE);
- if (!query) {
- logf (LOG_WARN, "bad query %s\n", pqf_query);
- odr_reset (odr_input);
- return(0);
- }
- zebra_search_RPN (zh, odr_input, odr_output, query, setname, &hits);
+ query = p_query_rpn (odr, PROTO_Z3950, pqf_query);
- odr_reset (odr_input);
- odr_reset (odr_output);
+ if (!query)
+ yaz_log (LOG_WARN, "bad query %s\n", pqf_query);
+ else
+ zebra_search_RPN (zh, query, setname, &hits);
- return(hits);
+ odr_destroy(odr);
+
+ return hits;
}
/* ---------------------------------------------------------------------------