/* * disk_update_instance_using_mobj - updates an object that had previously * been reserved with the acutal contents. * return: NO_ERROR if successful, error code otherwise * classop(in): class object * classobj(in): class memory object * obj(in): object memory. * oid(in): oid of the destination */ int disk_update_instance_using_mobj (MOP classop, MOBJ classobj, MOBJ obj, OID * oid) { int error = NO_ERROR; HFID *hfid; bool has_indexes = false; volatile int newsize = 0; bool oldflag; TF_STATUS tf_status = TF_SUCCESS; Diskrec->length = 0; /* * tf_mem_to_disk() is used to get an estimate of the disk space requirements * for the object. When dealing with collections the estimate returned is * not always a good one, hence we need to enclose this block in a loop * increasing the space by increments of DB_PAGESIZE until we hit the correct * space requirement. */ while ((tf_status = tf_mem_to_disk (classop, classobj, obj, Diskrec, &has_indexes)) == TF_OUT_OF_SPACE) { /* make the record larger */ if (newsize) { newsize += DB_PAGESIZE; } else { newsize = -Diskrec->length + DB_PAGESIZE; } free_recdes (Diskrec); Diskrec = alloc_recdes (newsize); if (Diskrec == NULL) { error = er_errid (); break; } } if (tf_status != TF_SUCCESS) { error = ER_LDR_CANT_TRANSFORM; er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0); } if (error == NO_ERROR && Diskrec != NULL) { hfid = get_class_heap (classop, (SM_CLASS *) classop->object); if (hfid == NULL) { error = er_errid (); } else if (heap_update (NULL, hfid, oid, Diskrec, &oldflag, NULL) != oid) { error = er_errid (); } else { if (oldflag) { fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_UPDATE_WARNING)); } else if (has_indexes) { error = update_indexes (WS_OID (classop), oid, Diskrec); } } } return (error); }
/* * disk_insert_instance_using_mobj - inserts a new object in the database * given a memory object and class object * return: NO_ERROR if successful, error code otherwise * classop(in): class object * classobj(in): class memory object * obj(in): object memory. * oid(out): oid of the destination */ int disk_insert_instance_using_mobj (MOP classop, MOBJ classobj, MOBJ obj, OID * oid) { int error = NO_ERROR; HFID *hfid; volatile int newsize = 0; bool has_indexes; TF_STATUS tf_status = TF_SUCCESS; Diskrec->length = 0; /* * tf_mem_to_disk() is used to get an estimate of the disk space requirements * for the object. When dealing with collections the estimate returned is * not always a good one, hence we need to enclose this block in a loop * increasing the space by increments of DB_PAGESIZE until we hit the correct * space requirement. */ while ((tf_status = tf_mem_to_disk (classop, classobj, obj, Diskrec, &has_indexes)) == TF_OUT_OF_SPACE) { /* make the record larger */ if (newsize) { newsize += DB_PAGESIZE; } else { newsize = -Diskrec->length + DB_PAGESIZE; } free_recdes (Diskrec); Diskrec = alloc_recdes (newsize); if (Diskrec == NULL) { assert (er_errid () != NO_ERROR); error = er_errid (); break; } } if (tf_status != TF_SUCCESS) { error = ER_LDR_CANT_TRANSFORM; er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0); } if (error == NO_ERROR && Diskrec != NULL) { hfid = get_class_heap (classop, (SM_CLASS *) classop->object); if (hfid == NULL) { assert (er_errid () != NO_ERROR); error = er_errid (); } else { HEAP_OPERATION_CONTEXT context; /* set up context */ heap_create_insert_context (&context, hfid, WS_OID (classop), Diskrec, NULL); /* oid is set here as a side effect */ if (heap_insert_logical (NULL, &context) != NO_ERROR) { assert (er_errid () != NO_ERROR); error = er_errid (); } else if (has_indexes) { COPY_OID (oid, &context.res_oid); error = update_indexes (WS_OID (classop), oid, Diskrec); } else { COPY_OID (oid, &context.res_oid); } } } return (error); }