create proxy and database

in Help Center
Hello,
In the following code snippet I create proxies to insert data in a database. The call TestPrx::checkedCast(base) invokes the constructor, that initializes my database-object with the primary key.
for(int i = 1; i <= 100; i++)
{
QString primaryKey = QString("name%1").stripWhiteSpace().arg(i);
Ice::ObjectPrx base = ic->stringToProxy((string) primaryKey + ":default -p 10000");
TestPrx proxy = TestPrx::checkedCast(base);
...
proxy->connectToDB(user, pwd, db);
//call set functions
...
proxy->insertInDB();
proxy->disconnectFromDB();
}
At the moment for every single object a database connection is opened, the object is inserted in the db and the connection is closed. Is there any possibility to open the database connection at the beginning and insert all the data within this connection?
Thank you for your hint.
In the following code snippet I create proxies to insert data in a database. The call TestPrx::checkedCast(base) invokes the constructor, that initializes my database-object with the primary key.
for(int i = 1; i <= 100; i++)
{
QString primaryKey = QString("name%1").stripWhiteSpace().arg(i);
Ice::ObjectPrx base = ic->stringToProxy((string) primaryKey + ":default -p 10000");
TestPrx proxy = TestPrx::checkedCast(base);
...
proxy->connectToDB(user, pwd, db);
//call set functions
...
proxy->insertInDB();
proxy->disconnectFromDB();
}
At the moment for every single object a database connection is opened, the object is inserted in the db and the connection is closed. Is there any possibility to open the database connection at the beginning and insert all the data within this connection?
Thank you for your hint.
0
Comments
As for the code below, I don't understand why you have so many Ice objects. Also, what is "insertInDB()" doing? It doesn't have any arguments, so what does it insert?
Sorry, but I'm a bit confused by the design below
Your server would be more scalable and easier to use if the database connections were not exposed to the clients. If possible (from a permission/security point of view), I would recommend to create a pool of connections in the server: each time a request arrives, the servant picks a connection from this pool.
You should also avoid lots of small "set" remote calls, since remote calls are not as fast as local calls. You could use batched one ways, but combining all your sets into insert parameters would be simpler.
You could end up with something as simple as:
TestPrx proxy = databaseProxy->insert(primaryKey, c1, c2, c3, c4);
Cheers,
Bernard
Sorry, the code snippet was a little bit confusing. I will try the batched one ways.