Home Help Center

create proxy and database

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.

Comments

  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    I'm not sure I understand the question. Is this related to Ice? When you open and close database connections is part of your server code, isn't it?

    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 :) I suggest to read the various examples in the Ice documentation in detail.
  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    If I understand correctly, your snippet represents an Ice client that calls an Ice server to insert some data (100 rows) in a database.

    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
  • Bernard, you've solved the riddle ;-).
    Sorry, the code snippet was a little bit confusing. I will try the batched one ways.
Sign In or Register to comment.