1 /*
2  Copyright (c) 2013, Oracle and/or its affiliates. All rights
3  reserved.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License, version 2.0,
7  as published by the Free Software Foundation.
8 
9  This program is also distributed with certain software (including
10  but not limited to OpenSSL) that is licensed under separate terms,
11  as designated in a particular file or component or in included license
12  documentation.  The authors of MySQL hereby grant you an additional
13  permission to link the program and your derivative works with the
14  separately licensed software that they have included with MySQL.
15 
16  This program is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  GNU General Public License, version 2.0, for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24  02110-1301  USA
25 */
26 
27 #include "Record.h"
28 #include "ColumnProxy.h"
29 #include "KeyOperation.h"
30 
31 class NdbRecordObject {
32 public:
33   NdbRecordObject(const Record *, ColumnHandlerSet *, Handle<Value>, Handle<Value>);
34   ~NdbRecordObject();
35 
36   Handle<Value> getField(int);
37   void setField(int nField, Handle<Value> value);
38   Handle<Value> prepare();
39   void resetMask();
40 
41   const Record * getRecord() const;
42   char * getBuffer() const;
43   uint32_t getMaskValue() const;
44   unsigned short getWriteCount() const;
45   int createBlobWriteHandles(KeyOperation &);
46 
47 private:
48   const Record * record;
49   char * buffer;
50   ColumnHandlerSet * handlers;
51   Persistent<Value> persistentBufferHandle;
52   const unsigned int ncol;
53   ColumnProxy * const proxy;
54   union {
55     uint8_t row_mask[4];
56     uint32_t maskvalue;
57   } u;
58   unsigned short nWrites;
59 
60   void maskIn(unsigned int nField);
61   bool isMaskedIn(unsigned int nField);
62 };
63 
64 
maskIn(unsigned int nField)65 inline void NdbRecordObject::maskIn(unsigned int nField) {
66   assert(nField < ncol);
67   u.row_mask[nField >> 3] |= (1 << (nField & 7));
68 }
69 
70 
isMaskedIn(unsigned int nField)71 inline bool NdbRecordObject::isMaskedIn(unsigned int nField) {
72   assert(nField < ncol);
73   return (u.row_mask[nField >> 3] & (1<<(nField & 7)));
74 }
75 
76 
setField(int nField,Handle<Value> value)77 inline void NdbRecordObject::setField(int nField, Handle<Value> value) {
78   nWrites++;
79   maskIn(nField);
80   proxy[nField].set(value);
81 }
82 
83 
getRecord()84 inline const Record * NdbRecordObject::getRecord() const {
85   return record;
86 }
87 
88 
getBuffer()89 inline char * NdbRecordObject::getBuffer() const {
90   return buffer;
91 }
92 
93 
getMaskValue()94 inline uint32_t NdbRecordObject::getMaskValue() const {
95   return u.maskvalue;
96 }
97 
98 
resetMask()99 inline void NdbRecordObject::resetMask() {
100   u.maskvalue = 0;
101 }
102 
getWriteCount()103 inline unsigned short NdbRecordObject::getWriteCount() const {
104   return nWrites;
105 }
106 
107