Skip to content

Commit d2152cf

Browse files
committed
work on support for NdbRecord-backed ValueObjects which contain
TEXT or BLOB columns.
1 parent afe6882 commit d2152cf

13 files changed

+161
-59
lines changed

Adapter/impl/ndb/NdbOperation.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ function buildValueObject(op) {
567567

568568
if(VOC) {
569569
/* Turn the buffer into a Value Object */
570-
op.result.value = new VOC(op.buffers.row);
570+
op.result.value = new VOC(op.buffers.row, op.blobs);
571571

572572
/* TODO: Apply type converters here, rather than in Column Handler??? */
573573

@@ -732,11 +732,11 @@ function buildOperationResult(transactionHandler, op, op_ndb_error, execMode) {
732732
}
733733

734734
if(op.result.success && op.opcode === opcodes.OP_READ) {
735-
if(op.tableHandler.numberOfLobColumns) {
736-
readResultRow(op); // Objects with BLOBs get plain JS Objects
737-
} else {
735+
// if(op.tableHandler.numberOfLobColumns) {
736+
// readResultRow(op); // Objects with BLOBs get plain JS Objects
737+
// } else {
738738
buildValueObject(op); // Objects without BLOBS get ValueObjects
739-
}
739+
// }
740740
}
741741
}
742742
if(udebug.is_detail()) udebug.log("buildOperationResult finished:", op.result);

Adapter/impl/ndb/include/ColumnHandler.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@ using v8::Handle;
2626
using v8::Value;
2727
using v8::Object;
2828

29+
class BlobWriteHandler;
30+
2931
class ColumnHandler {
3032
public:
3133
ColumnHandler();
3234
~ColumnHandler();
3335
void init(const NdbDictionary::Column *, size_t, Handle<Value>);
34-
Handle<Value> read(char *) const;
36+
Handle<Value> read(char *, Handle<Object>) const;
3537
Handle<Value> write(Handle<Value>, char *) const;
38+
BlobWriteHandler * createBlobWriteHandle(Handle<Value>, int fieldNo) const;
3639

3740
public:
3841
const NdbDictionary::Column *column;
@@ -43,6 +46,7 @@ class ColumnHandler {
4346
Persistent<Object> converterReader;
4447
Persistent<Object> converterWriter;
4548
bool hasConverterReader, hasConverterWriter;
49+
bool isLob, isText;
4650
};
4751

4852

Adapter/impl/ndb/include/ColumnProxy.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,22 @@ class ColumnProxy {
2727
ColumnProxy();
2828
~ColumnProxy();
2929
void setHandler(const ColumnHandler *);
30+
void setBlobBuffer(Handle<Value>);
31+
bool valueIsNull();
32+
BlobWriteHandler * createBlobWriteHandle(int);
3033

3134
Handle<Value> get(char *);
3235
void set(Handle<Value>);
3336
Handle<Value> write(char *);
34-
bool isNull; // value has been set to null
37+
38+
protected:
39+
void Dispose();
3540

3641
private:
3742
const ColumnHandler *handler;
3843
Persistent<Value> jsValue;
44+
Persistent<Object> blobBuffer;
45+
bool isNull; // value has been set to null
3946
bool isLoaded; // value has been read from buffer
4047
bool isDirty; // value should be rewritten in buffer
4148
};
@@ -49,4 +56,10 @@ inline void ColumnProxy::setHandler(const ColumnHandler *h) {
4956
handler = h;
5057
}
5158

59+
inline bool ColumnProxy::valueIsNull() {
60+
return isNull;
61+
}
5262

63+
inline void ColumnProxy::setBlobBuffer(Handle<Value> buffer) {
64+
blobBuffer = Persistent<Object>(buffer->ToObject());
65+
}

Adapter/impl/ndb/include/KeyOperation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class KeyOperation {
5555
void setRowMask(uint32_t);
5656

5757
// Prepare operation
58+
void setBlobHandler(BlobHandler *);
5859
bool isBlobReadOperation();
5960
const NdbOperation *prepare(NdbTransaction *);
6061

Adapter/impl/ndb/include/NdbRecordObject.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020

2121
#include "Record.h"
2222
#include "ColumnProxy.h"
23+
#include "KeyOperation.h"
2324

2425
class NdbRecordObject {
2526
public:
26-
NdbRecordObject(const Record *, ColumnHandlerSet *, Handle<Value>);
27+
NdbRecordObject(const Record *, ColumnHandlerSet *, Handle<Value>, Handle<Value>);
2728
~NdbRecordObject();
2829

2930
Handle<Value> getField(int);
@@ -35,6 +36,7 @@ class NdbRecordObject {
3536
char * getBuffer() const;
3637
uint32_t getMaskValue() const;
3738
unsigned short getWriteCount() const;
39+
void createBlobWriteHandles(KeyOperation &);
3840

3941
private:
4042
const Record * record;

Adapter/impl/ndb/include/NdbTypeEncoders.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
#include <node.h>
2222
#include <NdbApi.hpp>
2323

24-
typedef v8::Handle<v8::Value> EncoderReader(const NdbDictionary::Column *,
25-
char *, size_t);
24+
using namespace v8;
2625

27-
typedef v8::Handle<v8::Value> EncoderWriter(const NdbDictionary::Column *,
28-
v8::Handle<v8::Value>,
29-
char *, size_t);
26+
typedef Handle<Value> EncoderReader(const NdbDictionary::Column *,
27+
char *, size_t);
28+
29+
typedef Handle<Value> EncoderWriter(const NdbDictionary::Column *,
30+
Handle<Value>, char *, size_t);
3031

3132
typedef struct {
3233
EncoderReader * read;
@@ -36,4 +37,5 @@ typedef struct {
3637

3738
const NdbTypeEncoder * getEncoderForColumn(const NdbDictionary::Column *);
3839

39-
40+
Handle<Object> getBufferForText(const NdbDictionary::Column *, Handle<String>);
41+
Handle<String> getTextFromBuffer(const NdbDictionary::Column *, Handle<Object>);

Adapter/impl/ndb/src/ColumnHandler.cpp

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
*/
2020

2121
#include "adapter_global.h"
22-
2322
#include "ColumnHandler.h"
23+
#include "BlobHandler.h"
2424

2525
using namespace v8;
2626

@@ -40,7 +40,8 @@ Keys keys;
4040
ColumnHandler::ColumnHandler() :
4141
column(0), offset(0),
4242
converterClass(), converterReader(), converterWriter(),
43-
hasConverterReader(false), hasConverterWriter(false)
43+
hasConverterReader(false), hasConverterWriter(false),
44+
isLob(false), isText(false)
4445
{
4546
}
4647

@@ -60,6 +61,16 @@ void ColumnHandler::init(const NdbDictionary::Column *_column,
6061
offset = _offset;
6162
Local<Object> t;
6263

64+
switch(column->getType()) {
65+
case NDB_TYPE_TEXT:
66+
isText = true; // fall through to also set isLob
67+
case NDB_TYPE_BLOB:
68+
isLob = true;
69+
break;
70+
default:
71+
break;
72+
}
73+
6374
if(typeConverter->IsObject()) {
6475
converterClass = Persistent<Object>::New(typeConverter->ToObject());
6576

@@ -82,9 +93,20 @@ void ColumnHandler::init(const NdbDictionary::Column *_column,
8293
}
8394

8495

85-
Handle<Value> ColumnHandler::read(char * buffer) const {
96+
Handle<Value> ColumnHandler::read(char * rowBuffer, Handle<Object> blobBuffer) const {
8697
HandleScope scope;
87-
Handle<Value> val = encoder->read(column, buffer, offset);
98+
Handle<Value> val;
99+
100+
if(isText) {
101+
DEBUG_PRINT("text read");
102+
val = getTextFromBuffer(column, blobBuffer);
103+
} else if(isLob) {
104+
DEBUG_PRINT("blob read");
105+
val = Handle<Value>(blobBuffer);
106+
} else {
107+
val = encoder->read(column, rowBuffer, offset);
108+
}
109+
88110
if(hasConverterReader) {
89111
TryCatch tc;
90112
Handle<Value> arguments[1];
@@ -114,3 +136,18 @@ Handle<Value> ColumnHandler::write(Handle<Value> val, char *buffer) const {
114136
return scope.Close(writeStatus);
115137
}
116138

139+
140+
BlobWriteHandler * ColumnHandler::createBlobWriteHandle(Handle<Value> val,
141+
int fieldNo) const {
142+
HandleScope scope;
143+
BlobWriteHandler * b = 0;
144+
Handle<Object> obj = val->ToObject();
145+
if(isLob) {
146+
if(isText && val->IsString()) {
147+
obj = getBufferForText(column, val->ToString());
148+
}
149+
b = new BlobWriteHandler(column->getColumnNo(), fieldNo, obj);
150+
}
151+
return b;
152+
}
153+

Adapter/impl/ndb/src/ColumnProxy.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,28 @@
2525
using namespace v8;
2626

2727
ColumnProxy::~ColumnProxy() {
28-
if(! jsValue.IsEmpty())
29-
jsValue.Dispose();
28+
Dispose();
29+
}
30+
31+
/* Drop our claim on the old value */
32+
void ColumnProxy::Dispose() {
33+
if(! jsValue.IsEmpty()) jsValue.Dispose();
34+
if(! blobBuffer.IsEmpty()) blobBuffer.Dispose();
3035
}
3136

3237
Handle<Value> ColumnProxy::get(char *buffer) {
3338
HandleScope scope;
34-
Handle<Value> val;
3539

36-
if(! isLoaded) {
37-
val = handler->read(buffer);
40+
if(! isLoaded) {
41+
Handle<Value> val = handler->read(buffer, blobBuffer);
3842
jsValue = Persistent<Value>::New(val);
3943
isLoaded = true;
4044
}
4145
return scope.Close(jsValue);
4246
}
4347

44-
4548
void ColumnProxy::set(Handle<Value> newValue) {
46-
HandleScope scope;
47-
48-
/* Drop our claim on the old value */
49-
if(! jsValue.IsEmpty()) jsValue.Dispose();
50-
49+
Dispose();
5150
isNull = (newValue->IsNull());
5251
isLoaded = isDirty = true;
5352
jsValue = Persistent<Value>::New(newValue);
@@ -59,11 +58,19 @@ Handle<Value> ColumnProxy::write(char *buffer) {
5958
HandleScope scope;
6059
Handle<Value> rval;
6160

62-
if(isDirty || (jsValue->IsObject() && jsValue->ToObject()->IsDirty())) {
61+
if(isDirty) {
6362
rval = handler->write(jsValue, buffer);
6463
}
6564
isDirty = false;
6665
DEBUG_PRINT("write %s", handler->column->getName());
6766
return scope.Close(rval);
6867
}
6968

69+
70+
BlobWriteHandler * ColumnProxy::createBlobWriteHandle(int i) {
71+
BlobWriteHandler * b = 0;
72+
if(isDirty && ! isNull) {
73+
b = handler->createBlobWriteHandle(blobBuffer, i);
74+
}
75+
return b;
76+
}

Adapter/impl/ndb/src/DBOperationHelper.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,9 @@ void createBlobReadHandles(Handle<Object> blobsArray, const Record * rowRecord,
120120
for(int i = 0 ; i < ncol ; i++) {
121121
const NdbDictionary::Column * col = rowRecord->getColumn(i);
122122
if((col->getType() == NdbDictionary::Column::Blob) ||
123-
(col->getType() == NdbDictionary::Column::Text)) {
124-
BlobHandler * next = op.blobHandler;
125-
op.blobHandler = new BlobReadHandler(i, col->getColumnNo());
126-
op.blobHandler->setNext(next);
123+
(col->getType() == NdbDictionary::Column::Text))
124+
{
125+
op.setBlobHandler(new BlobReadHandler(i, col->getColumnNo()));
127126
}
128127
}
129128
}
@@ -139,9 +138,7 @@ void createBlobWriteHandles(Handle<Object> blobsArray, const Record * rowRecord,
139138
const NdbDictionary::Column * col = rowRecord->getColumn(i);
140139
assert( (col->getType() == NdbDictionary::Column::Blob) ||
141140
(col->getType() == NdbDictionary::Column::Text));
142-
BlobHandler * next = op.blobHandler;
143-
op.blobHandler = new BlobWriteHandler(i, col->getColumnNo(), blobValue);
144-
op.blobHandler->setNext(next);
141+
op.setBlobHandler(new BlobWriteHandler(i, col->getColumnNo(), blobValue));
145142
}
146143
}
147144
}

Adapter/impl/ndb/src/KeyOperation.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,7 @@ const NdbOperation * KeyOperation::prepare(NdbTransaction *tx) {
103103
}
104104
}
105105

106-
106+
void KeyOperation::setBlobHandler(BlobHandler *b) {
107+
b->setNext(blobHandler);
108+
blobHandler = b;
109+
}

0 commit comments

Comments
 (0)