int JNITopend::reportDRConflict(int32_t partitionId, int64_t remoteSequenceNumber, int64_t remoteUniqueId, string tableName, Table* input, Table* output) { if (input != NULL && output != NULL) { // prepare tablename jstring tableNameString = m_jniEnv->NewStringUTF(tableName.c_str()); // prepare input buffer size_t serializeSize = input->getAccurateSizeToSerialize(false); char* backingCharArray = new char[serializeSize]; ReferenceSerializeOutput conflictSerializeOutput(backingCharArray, serializeSize); input->serializeToWithoutTotalSize(conflictSerializeOutput); jobject inputBuffer = m_jniEnv->NewDirectByteBuffer( static_cast<void*>(backingCharArray), static_cast<int32_t>(serializeSize)); if (inputBuffer == NULL) { m_jniEnv->ExceptionDescribe(); throw std::exception(); } // prepare output buffer size_t outputSerializeSize = output->getColumnHeaderSizeToSerialize(false) + sizeof(int32_t) + // tuple count placeholder output->schema()->getMaxSerializedTupleSize(); char* outputBackingCharArray = new char[outputSerializeSize]; ReferenceSerializeOutput outputSerializeOutput(outputBackingCharArray, outputSerializeSize); // NOTE passed-in output table should have only schema and no tuples output->serializeToWithoutTotalSize(outputSerializeOutput); jobject outputBuffer = m_jniEnv->NewDirectByteBuffer( static_cast<void*>(outputBackingCharArray), static_cast<int32_t>(outputSerializeSize)); if (outputBuffer == NULL) { m_jniEnv->ExceptionDescribe(); throw std::exception(); } int32_t retval = m_jniEnv->CallStaticIntMethod( m_partitionDRGatewayClass, m_reportDRConflictMID, partitionId, remoteSequenceNumber, remoteUniqueId, tableNameString, inputBuffer, outputBuffer); ReferenceSerializeInputBE filledOutputSerializeInput(outputBackingCharArray, outputSerializeSize); output->loadTuplesFrom(filledOutputSerializeInput); m_jniEnv->DeleteLocalRef(tableNameString); m_jniEnv->DeleteLocalRef(inputBuffer); m_jniEnv->DeleteLocalRef(outputBuffer); return retval; } // -1 indicates error in parameters provided, for now return -1; }
static char* serializeTable(JNIEnv* jniEngine, Table* table, jobject* buffer) { size_t serializeSize = table->getAccurateSizeToSerialize(false); char* backingCharArray = new char[serializeSize]; ReferenceSerializeOutput conflictSerializeOutput(backingCharArray, serializeSize); table->serializeToWithoutTotalSize(conflictSerializeOutput); *buffer = jniEngine->NewDirectByteBuffer(static_cast<void*>(backingCharArray), static_cast<int32_t>(serializeSize)); if (*buffer == NULL) { jniEngine->ExceptionDescribe(); throw std::exception(); } return backingCharArray; }