MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / onTrigger

Method onTrigger

extensions/sqlite/PutSQL.cpp:83–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83void PutSQL::onTrigger(const std::shared_ptr<core::ProcessContext> &context,
84 const std::shared_ptr<core::ProcessSession> &session) {
85 auto flow_file = session->get();
86
87 if (!flow_file) {
88 return;
89 }
90
91 uint64_t batch_processed = 1;
92
93 try {
94 // Use an existing context, if one is available
95 std::shared_ptr<minifi::sqlite::SQLiteConnection> db;
96
97 if (conn_q_.try_dequeue(db)) {
98 logger_->log_debug("Using available SQLite connection");
99 }
100
101 if (!db) {
102 logger_->log_info("Creating new SQLite connection");
103 if (db_url_.substr(0, 9) == "sqlite://") {
104 db = std::make_shared<minifi::sqlite::SQLiteConnection>(db_url_.substr(9));
105 } else {
106 std::stringstream err_msg;
107 err_msg << "Connection URL '" << db_url_ << "' is unsupported";
108 logger_->log_error(err_msg.str().c_str());
109 throw std::runtime_error("Connection Error");
110 }
111 }
112
113 do {
114 auto sql = std::make_shared<std::string>();
115
116 if (sql_.empty()) {
117 // SQL is not defined as a property, so get SQL from the file content
118 SQLReadCallback cb(sql);
119 session->read(flow_file, &cb);
120 } else {
121 // SQL is defined as a property, so get the property dynamically w/ EL support
122 context->getProperty(SQLStatement, *sql, flow_file);
123 }
124
125 auto stmt = db->prepare(*sql);
126 for (uint64_t i = 1; i < UINT64_MAX; i++) {
127 std::string val;
128 std::stringstream val_key;
129 val_key << "sql.args." << i << ".value";
130
131 if (!flow_file->getAttribute(val_key.str(), val)) {
132 break;
133 }
134
135 stmt.bind_text(i, val);
136 }
137
138 stmt.step();
139
140 if (!stmt.is_ok()) {

Callers

nothing calls this directly

Calls 15

log_debugMethod · 0.80
log_infoMethod · 0.80
log_errorMethod · 0.80
c_strMethod · 0.80
prepareMethod · 0.80
bind_textMethod · 0.80
stepMethod · 0.80
is_okMethod · 0.80
errormsgMethod · 0.80
getMethod · 0.45
emptyMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected