/ Update the current document from the collection. */ /
| 781 | /* Update the current document from the collection. */ |
| 782 | /***********************************************************************/ |
| 783 | int JMgoConn::DocUpdate(PGLOBAL g, PTDB tdbp) |
| 784 | { |
| 785 | int j = 0, rc = RC_OK; |
| 786 | bool error; |
| 787 | PCOL colp; |
| 788 | jstring jkey; |
| 789 | jobject val, upd, updlist = env->CallObjectMethod(job, mkdocid); |
| 790 | |
| 791 | // Make the list of changes to do |
| 792 | for (colp = tdbp->GetSetCols(); colp; colp = colp->GetNext()) { |
| 793 | jkey = env->NewStringUTF(colp->GetJpath(g, false)); |
| 794 | val = MakeObject(g, colp, error); |
| 795 | |
| 796 | if (error) |
| 797 | return RC_FX; |
| 798 | else if (Stringify(colp)) |
| 799 | switch (*colp->GetCharValue()) { |
| 800 | case '{': j = 1; break; |
| 801 | case '[': j = 2; break; |
| 802 | default: break; |
| 803 | } // endswitch |
| 804 | |
| 805 | if (env->CallBooleanMethod(job, docaddid, updlist, jkey, val, j)) |
| 806 | return RC_OK; |
| 807 | |
| 808 | env->DeleteLocalRef(jkey); |
| 809 | } // endfor colp |
| 810 | |
| 811 | // Make the update parameter |
| 812 | upd = env->CallObjectMethod(job, mkdocid); |
| 813 | jkey = env->NewStringUTF("$set"); |
| 814 | |
| 815 | if (env->CallBooleanMethod(job, docaddid, upd, jkey, updlist, 0)) |
| 816 | return RC_OK; |
| 817 | |
| 818 | env->DeleteLocalRef(jkey); |
| 819 | |
| 820 | jlong ar = env->CallLongMethod(job, updateid, upd); |
| 821 | |
| 822 | if (trace(1)) |
| 823 | htrc("DocUpdate: ar = %ld\n", ar); |
| 824 | |
| 825 | if (Check((int)ar)) { |
| 826 | snprintf(g->Message, sizeof(g->Message), "CollUpdate: %s", Msg); |
| 827 | rc = RC_FX; |
| 828 | } // endif ar |
| 829 | |
| 830 | return rc; |
| 831 | } // end of DocUpdate |
| 832 | |
| 833 | /***********************************************************************/ |
| 834 | /* Remove all or only the current document from the collection. */ |