author | František Kučera <franta-hg@frantovo.cz> |
Sat, 23 Apr 2022 23:51:13 +0200 | |
branch | v_0 |
changeset 60 | 1b20c1e03065 |
parent 59 | 4fce579bed22 |
permissions | -rw-r--r-- |
29
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
1 |
/** |
30
3f18cb7a6963
license of protocol, reader and writer: GNU LGPLv3+ or GNU GPLv2+
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
2 |
* Relational pipes (library) |
29
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
3 |
* Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info) |
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
4 |
* |
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
30
3f18cb7a6963
license of protocol, reader and writer: GNU LGPLv3+ or GNU GPLv2+
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
6 |
* it under the terms of the: |
3f18cb7a6963
license of protocol, reader and writer: GNU LGPLv3+ or GNU GPLv2+
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
7 |
* - GNU Lesser General Public License as published by the Free Software Foundation; |
41
744b61559eb2
fix license version: GNU LGPLv3 or GPLv2
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
8 |
* version 3 of the License or (at your option) |
30
3f18cb7a6963
license of protocol, reader and writer: GNU LGPLv3+ or GNU GPLv2+
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
9 |
* - GNU General Public License as published by the Free Software Foundation; |
41
744b61559eb2
fix license version: GNU LGPLv3 or GPLv2
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
10 |
* version 2 of the License. |
29
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
11 |
* |
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
12 |
* This program is distributed in the hope that it will be useful, |
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
15 |
* GNU General Public License for more details. |
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
16 |
* |
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License |
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
18 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
19 |
*/ |
7
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
#pragma once |
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
|
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
#include <string> |
59
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
23 |
#include <cstring> |
7
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
#include <iostream> |
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
#include <vector> |
59
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
26 |
#include <stdexcept> |
7
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
|
23
d505eaedc35e
remove format.h and use constants.h from lib-protocol
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
28 |
#include <relpipe/protocol/constants.h> |
d505eaedc35e
remove format.h and use constants.h from lib-protocol
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
29 |
|
20
bef6648e79b1
relpipe-lib-writer: move public header files to: include/relpipe/writer/
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
30 |
#include "../include/relpipe/writer/typedefs.h" |
bef6648e79b1
relpipe-lib-writer: move public header files to: include/relpipe/writer/
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
31 |
#include "../include/relpipe/writer/RelationalWriter.h" |
bef6648e79b1
relpipe-lib-writer: move public header files to: include/relpipe/writer/
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
32 |
#include "../include/relpipe/writer/TypeId.h" |
27
a64afb2d24c9
use AttributeMetadata instead of std::pair for relation header
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
33 |
#include "../include/relpipe/writer/AttributeMetadata.h" |
9
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
34 |
#include "DataTypeWriterBase.h" |
10
40ab091e5dfa
move *DataTypeWriter.h to separate directory
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
35 |
#include "types/BooleanDataTypeWriter.h" |
40ab091e5dfa
move *DataTypeWriter.h to separate directory
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
36 |
#include "types/IntegerDataTypeWriter.h" |
40ab091e5dfa
move *DataTypeWriter.h to separate directory
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
37 |
#include "types/StringDataTypeWriter.h" |
7
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
|
8
03750aff8619
writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
39 |
namespace relpipe { |
03750aff8619
writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
40 |
namespace writer { |
7
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
|
23
d505eaedc35e
remove format.h and use constants.h from lib-protocol
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
42 |
using namespace relpipe::protocol; |
d505eaedc35e
remove format.h and use constants.h from lib-protocol
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
43 |
|
9
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
44 |
class StreamRelationalWriter : public RelationalWriter { |
7
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
private: |
9
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
46 |
std::ostream &output; |
10
40ab091e5dfa
move *DataTypeWriter.h to separate directory
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
47 |
types::BooleanDataTypeWriter booleanWriter; |
40ab091e5dfa
move *DataTypeWriter.h to separate directory
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
48 |
types::IntegerDataTypeWriter integerWriter; |
40ab091e5dfa
move *DataTypeWriter.h to separate directory
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
49 |
types::StringDataTypeWriter stringWriter; |
25
135ef93a4ac2
imports, namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
23
diff
changeset
|
50 |
std::vector<DataTypeWriterBase*> writers = {&booleanWriter, &integerWriter, &stringWriter}; |
60
1b20c1e03065
BufferingMode: set default mode from the constructor
František Kučera <franta-hg@frantovo.cz>
parents:
59
diff
changeset
|
51 |
BufferingMode bufferingMode; |
1b20c1e03065
BufferingMode: set default mode from the constructor
František Kučera <franta-hg@frantovo.cz>
parents:
59
diff
changeset
|
52 |
BufferingMode bufferingModeEnvDefault; |
15
8fd6c4d44071
use more TypeId enum
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
53 |
|
12
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
54 |
/** |
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
55 |
* count of columns in the current table |
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
56 |
*/ |
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
57 |
integer_t columnCount; |
16
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
58 |
/** |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
59 |
* number of column (0 = first) that will be written; after writing, the number is increased and prepared for next one |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
60 |
*/ |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
61 |
integer_t currentColumn; |
15
8fd6c4d44071
use more TypeId enum
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
62 |
|
12
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
63 |
/** |
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
64 |
* types of columns in the current table |
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
65 |
*/ |
25
135ef93a4ac2
imports, namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
23
diff
changeset
|
66 |
std::vector<TypeId> columnTypes; |
9
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
67 |
|
15
8fd6c4d44071
use more TypeId enum
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
68 |
void writeString(const string_t &stringValue, const TypeId typeId) { |
58
25c1ff79297c
flush the output after each attribute; TODO: configurable BufferingMode
František Kučera <franta-hg@frantovo.cz>
parents:
52
diff
changeset
|
69 |
// TODO: cache writers at given positions |
9
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
70 |
for (DataTypeWriterBase* writer : writers) if (writer->supports(typeId)) return writer->writeString(output, stringValue); |
16
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
71 |
throw RelpipeWriterException(L"Unsupported data type: " + static_cast<integer_t> (typeId)); |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
72 |
} |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
73 |
|
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
74 |
void writeRaw(const void* value, const type_info& typeInfo, const TypeId typeId) { |
58
25c1ff79297c
flush the output after each attribute; TODO: configurable BufferingMode
František Kučera <franta-hg@frantovo.cz>
parents:
52
diff
changeset
|
75 |
// TODO: cache writers at given positions |
16
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
76 |
for (DataTypeWriterBase* writer : writers) if (writer->supports(typeId)) return writer->writeRaw(output, value, typeInfo); |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
77 |
throw RelpipeWriterException(L"Unsupported data type: " + static_cast<integer_t> (typeId)); |
9
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
78 |
} |
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
79 |
|
59
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
80 |
BufferingMode decodeBufferingMode(std::string modeName) { |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
81 |
if (modeName == "AUTO") return BufferingMode::AUTO; |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
82 |
else if (modeName == "ENVIRONMENT") return BufferingMode::ENVIRONMENT; |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
83 |
else if (modeName == "RELATION") return BufferingMode::RELATION; |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
84 |
else if (modeName == "RECORD") return BufferingMode::RECORD; |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
85 |
else if (modeName == "ATTRIBUTE") return BufferingMode::ATTRIBUTE; |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
86 |
else throw std::invalid_argument("Invalid value of BufferingMode."); |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
87 |
} |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
88 |
|
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
89 |
void updateBufferingMode() { |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
90 |
if (bufferingMode == BufferingMode::ENVIRONMENT) { |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
91 |
bufferingMode = bufferingModeEnvDefault; |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
92 |
try { |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
93 |
char* modeName = getenv("RELPIPE_WRITER_BUFFERING_MODE"); |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
94 |
if (modeName && strlen(modeName)) bufferingMode = decodeBufferingMode(modeName); |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
95 |
} catch (...) { |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
96 |
throw RelpipeWriterException(L"Invalid value of the RELPIPE_WRITER_BUFFERING_MODE environmental variable."); |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
97 |
} |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
98 |
if (bufferingMode == BufferingMode::ENVIRONMENT) throw RelpipeWriterException(L"RELPIPE_WRITER_BUFFERING_MODE must not be set to ENVIRONMENT (infinite recursion)"); |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
99 |
} |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
100 |
} |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
101 |
|
7
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
102 |
public: |
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
103 |
|
9
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
104 |
StreamRelationalWriter(std::ostream &output) : |
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
105 |
output(output) { |
60
1b20c1e03065
BufferingMode: set default mode from the constructor
František Kučera <franta-hg@frantovo.cz>
parents:
59
diff
changeset
|
106 |
setBufferingMode(BufferingMode::ENVIRONMENT, BufferingMode::AUTO); |
9
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
107 |
} |
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
108 |
|
15
8fd6c4d44071
use more TypeId enum
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
109 |
TypeId toTypeId(const string_t typeCode) override { |
8
03750aff8619
writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
110 |
for (DataTypeWriterBase* writer : writers) if (writer->supports(typeCode)) return writer->getTypeId(); |
03750aff8619
writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
111 |
throw RelpipeWriterException(L"Unsupported data type: " + typeCode); |
7
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
112 |
} |
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
113 |
|
27
a64afb2d24c9
use AttributeMetadata instead of std::pair for relation header
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
114 |
void startRelation(string_t name, std::vector<AttributeMetadata> attributes, boolean_t writeHeader) override { |
12
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
115 |
string_t tableName = name; |
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
116 |
columnCount = attributes.size(); |
16
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
117 |
currentColumn = 0; |
12
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
118 |
|
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
119 |
// Write table name and column count: |
47
77fbaccdeea4
support „writeHeader = false“ to allow appending records to an existing relation
František Kučera <franta-hg@frantovo.cz>
parents:
41
diff
changeset
|
120 |
if (writeHeader) { |
77fbaccdeea4
support „writeHeader = false“ to allow appending records to an existing relation
František Kučera <franta-hg@frantovo.cz>
parents:
41
diff
changeset
|
121 |
integerWriter.writeValue(output, DATA_PART_START); |
77fbaccdeea4
support „writeHeader = false“ to allow appending records to an existing relation
František Kučera <franta-hg@frantovo.cz>
parents:
41
diff
changeset
|
122 |
stringWriter.writeValue(output, tableName); |
77fbaccdeea4
support „writeHeader = false“ to allow appending records to an existing relation
František Kučera <franta-hg@frantovo.cz>
parents:
41
diff
changeset
|
123 |
integerWriter.writeValue(output, columnCount); |
77fbaccdeea4
support „writeHeader = false“ to allow appending records to an existing relation
František Kučera <franta-hg@frantovo.cz>
parents:
41
diff
changeset
|
124 |
} |
12
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
125 |
|
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
126 |
columnTypes.clear(); |
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
127 |
columnTypes.resize(columnCount); |
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
128 |
|
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
129 |
// Write column names: |
47
77fbaccdeea4
support „writeHeader = false“ to allow appending records to an existing relation
František Kučera <franta-hg@frantovo.cz>
parents:
41
diff
changeset
|
130 |
if (writeHeader) { |
77fbaccdeea4
support „writeHeader = false“ to allow appending records to an existing relation
František Kučera <franta-hg@frantovo.cz>
parents:
41
diff
changeset
|
131 |
for (size_t c = 0; c < columnCount; c++) { |
77fbaccdeea4
support „writeHeader = false“ to allow appending records to an existing relation
František Kučera <franta-hg@frantovo.cz>
parents:
41
diff
changeset
|
132 |
wstring columnName = attributes[c].attributeName; |
77fbaccdeea4
support „writeHeader = false“ to allow appending records to an existing relation
František Kučera <franta-hg@frantovo.cz>
parents:
41
diff
changeset
|
133 |
stringWriter.writeValue(output, columnName); |
77fbaccdeea4
support „writeHeader = false“ to allow appending records to an existing relation
František Kučera <franta-hg@frantovo.cz>
parents:
41
diff
changeset
|
134 |
} |
12
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
135 |
} |
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
136 |
|
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
137 |
// Write column types: |
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
138 |
for (size_t c = 0; c < columnCount; c++) { |
27
a64afb2d24c9
use AttributeMetadata instead of std::pair for relation header
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
139 |
TypeId typeId = attributes[c].typeId; |
47
77fbaccdeea4
support „writeHeader = false“ to allow appending records to an existing relation
František Kučera <franta-hg@frantovo.cz>
parents:
41
diff
changeset
|
140 |
if (writeHeader) integerWriter.writeValue(output, static_cast<integer_t> (typeId)); |
12
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
141 |
columnTypes[c] = typeId; |
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
142 |
} |
640e88aedf8f
code for table generation ported from the prototype: RelationalGenerator.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
143 |
|
59
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
144 |
if (bufferingMode >= BufferingMode::RELATION && bufferingMode <= BufferingMode::ATTRIBUTE) output.flush(); |
9
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
145 |
} |
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
146 |
|
17
f2cccaa9dd38
replace writeRecord() with sequence of writeAttribute()
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
147 |
void writeAttribute(const string_t& value) override { |
f2cccaa9dd38
replace writeRecord() with sequence of writeAttribute()
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
148 |
if (currentColumn == 0) integerWriter.writeValue(output, DATA_PART_ROW); |
59
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
149 |
|
52
785fc49b0a55
just TODO comment: performance optimization
František Kučera <franta-hg@frantovo.cz>
parents:
47
diff
changeset
|
150 |
// TODO: select writer for each attribute just once in startRelation() instead of looking it each time here |
17
f2cccaa9dd38
replace writeRecord() with sequence of writeAttribute()
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
151 |
writeString(value, columnTypes[currentColumn]); |
59
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
152 |
|
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
153 |
bool endOfRedord = ++currentColumn == columnCount; |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
154 |
if (endOfRedord) currentColumn = 0; |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
155 |
|
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
156 |
if (bufferingMode == BufferingMode::ATTRIBUTE || (endOfRedord && bufferingMode == BufferingMode::RECORD)) output.flush(); |
7
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
157 |
} |
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
158 |
|
16
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
159 |
void writeAttribute(const void* value, const std::type_info& type) override { |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
160 |
if (currentColumn == 0) integerWriter.writeValue(output, DATA_PART_ROW); |
59
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
161 |
|
52
785fc49b0a55
just TODO comment: performance optimization
František Kučera <franta-hg@frantovo.cz>
parents:
47
diff
changeset
|
162 |
// TODO: select writer for each attribute just once in startRelation() instead of looking it each time here |
16
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
163 |
writeRaw(value, type, columnTypes[currentColumn]); |
59
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
164 |
|
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
165 |
bool endOfRedord = ++currentColumn == columnCount; |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
166 |
if (endOfRedord) currentColumn = 0; |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
167 |
|
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
168 |
if (bufferingMode == BufferingMode::ATTRIBUTE || (endOfRedord && bufferingMode == BufferingMode::RECORD)) output.flush(); |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
169 |
} |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
170 |
|
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
171 |
void setBufferingMode(BufferingMode mode, BufferingMode envDefault) override { |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
172 |
bufferingMode = mode; |
4fce579bed22
BufferingMode: configurable modes that control when flush() is called
František Kučera <franta-hg@frantovo.cz>
parents:
58
diff
changeset
|
173 |
bufferingModeEnvDefault = envDefault; |
60
1b20c1e03065
BufferingMode: set default mode from the constructor
František Kučera <franta-hg@frantovo.cz>
parents:
59
diff
changeset
|
174 |
updateBufferingMode(); |
16
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
175 |
} |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
176 |
|
7
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
177 |
}; |
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
178 |
|
8
03750aff8619
writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
179 |
} |
7
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
180 |
} |