dboo::odb::commit
template<class T>
void commit(T* object, const object_name& name); 1)
template<class T>
void commit(T* object); 2)
template<class T>
void commit(const std::unique_ptr<T>& object); 3)
template<class T>
void commit(const ref<T>& object); 4)
template<class FwdIterator>
void commit(FwdIterator first, FwdIterator last); 5)
template<class T>
void commit(std::vector<T*> objects); 6)
template<class T>
void commit(const std::vector<std::unique_ptr<T>>& objects); 7)
void commit(const internalized_instance& object); 8)
void commit(const std::vector<internalized_instance>& objects); 9)
commit(object [, name]) 1,2)
commit(<array of objects>) 6)
Saves objects in the database.
- 1
Commits the specified object and name it as specified
- 2
Commits the specified object
- 3
Commits the object pointed to by the unique_ptr
- 4
Commits the specified object
- 5
Commits all specified objects
- 6
Commits all objects in the vector
- 7
Commits all objects pointed to by the unique_ptr
- 8
Commits an internalized_instance (ie not native runtime object)
- 9
Commits all internalized_instance in vector
Parameters
- object
A pointer or unique_ptr to an object
- objects
A vector or array of pointers/unique_ptr to objects
- first
Beginning of sequence (Forward iterator)
- last
End of sequence (Forward iterator)
- name
A unique identifying name given to an object.
Notes
The submitted objects will be traversed to find other referenced objects. All objects that are either indicated as being updated (by calls to the updated() functions) or objects that are previously unknown to the database will be committed to the server. Internalized_instance objects will not be traversed.
Object names can be overwritten by calling commit with another object with an existing name.
Return value
(none)
Exceptions
- exception_concurrent_update
An object in the transaction fails concurrency check. I.e. it has already been updated or is being updated by another database client.
- exception_database_limits_exceeded
The transaction does not fit within the database’s limit
Example
#include <dboo/rfx.h>
#include <dboo/odb.h>
class A {
public:
inline static dboo::cls<A> cls{"A"};
static void dboo_class_init(dboo::cls<A>& c) {
c.member(&A::var1, "var1");
}
private:
int var1;
};
class B {
public:
B() = default;
B(A* a) : a{a} {}
virtual ~B() = default;
inline static dboo::cls<B> cls{"B"};
static void dboo_class_init(dboo::cls<B>& c) {
c.member(&A::a, "a");
}
private:
A* a;
};
int main() {
dboo::odb db;
db.connect("localhost", 8823,
"my_database",
"usr132",
"password");
auto a = new A();
auto b = new A();
auto c = new A();
auto d = new A();
auto e = new A();
auto objA = new B(d);
auto objB = new B(e);
db.commit(a, "AnObject"); // commits a with a name
db.commit(b); // commits b
db.commit({c, d}); // commits c and d
db.commit(objA); // commits objA but not d as
// it has already been committed
db.commit(objB); // commits objB and e
return 0;
}
const dboo = require('dboo');
const config = require('config');
dboo.argv(process.argv);
dbConfig = config.get('dbConfig');
class UserId {
userId = "";
screenName = "";
constructor(userid = "", screenName = "") {
this.userId = userid;
this.screenName = screenName;
}
};
dboo.class(UserId,
[{"userId": dboo.string},
{"screenName": dboo.string},
]
);
class User {
userId = null;
address = "";
constructor(userid = null, address = "") {
this.userId = userid;
this.screenName = screenName;
}
};
dboo.class(User,
[{"userId": UserId}, // referencing a UserId object
{"address": dboo.string},
]
);
dboo.init(); // Class declarations must come before init!
const db = new dboo.odb();
db.connect(dbConfig.host, Number(dbConfig.port),
dbConfig.dbName, dbConfig.webUserName,
dbConfig.webUserPwd);
let a = new UserId();
let b = new UserId();
let c = new UserId();
let d = new UserId();
let e = new UserId();
let usrA = new User(d, "address1");
let usrB = new User(e, "address2");
db.commit(a, "user_a"); // commits a with a name
db.commit(b); // commits b
db.commit([c,d]); // commits c and d
db.commit(usrA); // commits usrA but not UserId d as
// it has already been committed
db.commit(usrB); // commits usrB and UserId e