You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@empire-db.apache.org by exxos <ha...@gmail.com> on 2010/08/15 17:05:33 UTC

Why the connection is given two times in case of UPDATE?

Hello,

Sorry to spam the august's mailling list. ^__^

But, I need a clarification on the implementation for the INSERT and the
UPDATE methods.

Accroding you tutorial, the following steps are needed:

// INSERT
DBRecord rec = new DBRecord();
rec.create(DBRowSet table);
rec.setValue(...)
rec.update(java.sql.Connection conn);

// UPDATE
DBRecord rec = new DBRecord();
rec.read(..., java.sql.Connection conn);
rec.setValue(...)
rec.update(java.sql.Connection conn);

Why in case of the UPDATE we have to give the Connection by two times?

Thank to advise,
Regards.

Re: Why the connection is given two times in case of UPDATE?

Posted by exxos <ha...@gmail.com>.
Thank you very much!

Regards,
exxos.

On Mon, Aug 16, 2010 at 9:07 AM, Rainer Döbele <do...@esteam.de> wrote:

>  This is how to do it:
>
>
>
> // Update a record using a DBCommand object
>
> DBCommand cmd = *db*.createCommand();
>
> cmd.set(*db*.EMPLOYEES.SALARY.to(50000));
>
> cmd.where(*db*.EMPLOYEES.EMPLOYEE_ID.is(123));
>
> *db*.executeSQL(cmd.getUpdate(), conn);
>
>
>
> Regards
>
> Rainer
>
>
>
> *from:* exxos [mailto:hatufr@gmail.com]
> *to:* empire-db-user@incubator.apache.org
> *re:* Re: Why the connection is given two times in case of UPDATE?
>
>
>
> Hi Rainer,
>
> Thank you for your reply.
>
> Could you please just give a short example on how to perform an UPDATE with
> a DBCommand?
>
> Regards,
> exxos.
>
>  On Sun, Aug 15, 2010 at 11:04 PM, Rainer Döbele <do...@esteam.de>
> wrote:
>
> Hi exxos,
>
>
>
> In your update example the call to rec.read() will read the record from the
> database by executing a corresponding SELECT statement.
>
> The UPDATE then only updates the changed fields.
>
>
>
> It is part of our design, that we don’t store connections since they are an
> external resource that might be shared between threads or requests and hence
> a connection must be supplied every time a database action is performed. But
> you may add your own layer (e.g. by deriving a class from DBRecord) to
> implement a connection handling that suits your purpose.
>
>
>
> If you don’t want to read before an update – e.g. if you know that the
> value will change and don’t need the extra logic – then you should use a
> DBCommand to update a record.
>
>
>
> Regards,
>
> Rainer
>
>
>
>
>
> *from:* exxos [mailto:hatufr@gmail.com]
> *to:* empire-db-user@incubator.apache.org
> *re:* Why the connection is given two times in case of UPDATE?
>
>
>
> Hello,
>
>
>
> Sorry to spam the august's mailling list. ^__^
>
>
>
> But, I need a clarification on the implementation for the INSERT and the
> UPDATE methods.
>
>
>
> Accroding you tutorial, the following steps are needed:
>
>
>
> // INSERT
> DBRecord rec = new DBRecord();
> rec.create(DBRowSet table);
> rec.setValue(...)
> rec.update(java.sql.Connection conn);
>
>
>
> // UPDATE
> DBRecord rec = new DBRecord();
> rec.read(..., java.sql.Connection conn);
> rec.setValue(...)
> rec.update(java.sql.Connection conn);
>
>
> Why in case of the UPDATE we have to give the Connection by two times?
>
>
>
> Thank to advise,
>
> Regards.
>
>
>
>
>
>
>

re: Why the connection is given two times in case of UPDATE?

Posted by Rainer Döbele <do...@esteam.de>.
This is how to do it:

 

// Update a record using a DBCommand object

DBCommand cmd = db.createCommand();

cmd.set(db.EMPLOYEES.SALARY.to(50000));

cmd.where(db.EMPLOYEES.EMPLOYEE_ID.is(123));

db.executeSQL(cmd.getUpdate(), conn);

 

Regards

Rainer

 

from: exxos [mailto:hatufr@gmail.com] 
to: empire-db-user@incubator.apache.org
re: Re: Why the connection is given two times in case of UPDATE?

 

Hi Rainer,

Thank you for your reply.

Could you please just give a short example on how to perform an UPDATE with a DBCommand?

Regards,
exxos.



On Sun, Aug 15, 2010 at 11:04 PM, Rainer Döbele <do...@esteam.de> wrote:

Hi exxos,

 

In your update example the call to rec.read() will read the record from the database by executing a corresponding SELECT statement.

The UPDATE then only updates the changed fields.

 

It is part of our design, that we don't store connections since they are an external resource that might be shared between threads or requests and hence a connection must be supplied every time a database action is performed. But you may add your own layer (e.g. by deriving a class from DBRecord) to implement a connection handling that suits your purpose.

 

If you don't want to read before an update - e.g. if you know that the value will change and don't need the extra logic - then you should use a DBCommand to update a record. 

 

Regards,

Rainer

 

 

from: exxos [mailto:hatufr@gmail.com] 
to: empire-db-user@incubator.apache.org
re: Why the connection is given two times in case of UPDATE?

 

Hello,

 

Sorry to spam the august's mailling list. ^__^

 

But, I need a clarification on the implementation for the INSERT and the UPDATE methods.

 

Accroding you tutorial, the following steps are needed:

 

// INSERT
DBRecord rec = new DBRecord();
rec.create(DBRowSet table);
rec.setValue(...)
rec.update(java.sql.Connection conn);

 

// UPDATE
DBRecord rec = new DBRecord();
rec.read(..., java.sql.Connection conn);
rec.setValue(...)
rec.update(java.sql.Connection conn);


Why in case of the UPDATE we have to give the Connection by two times?

 

Thank to advise,

Regards.

 

 

 


Re: Why the connection is given two times in case of UPDATE?

Posted by exxos <ha...@gmail.com>.
Hi Rainer,

Thank you for your reply.

Could you please just give a short example on how to perform an UPDATE with
a DBCommand?

Regards,
exxos.


On Sun, Aug 15, 2010 at 11:04 PM, Rainer Döbele <do...@esteam.de> wrote:

>  Hi exxos,
>
>
>
> In your update example the call to rec.read() will read the record from the
> database by executing a corresponding SELECT statement.
>
> The UPDATE then only updates the changed fields.
>
>
>
> It is part of our design, that we don’t store connections since they are an
> external resource that might be shared between threads or requests and hence
> a connection must be supplied every time a database action is performed. But
> you may add your own layer (e.g. by deriving a class from DBRecord) to
> implement a connection handling that suits your purpose.
>
>
>
> If you don’t want to read before an update – e.g. if you know that the
> value will change and don’t need the extra logic – then you should use a
> DBCommand to update a record.
>
>
>
> Regards,
>
> Rainer
>
>
>
>
>
> *from:* exxos [mailto:hatufr@gmail.com]
> *to:* empire-db-user@incubator.apache.org
> *re:* Why the connection is given two times in case of UPDATE?
>
>
>
> Hello,
>
>
>
> Sorry to spam the august's mailling list. ^__^
>
>
>
> But, I need a clarification on the implementation for the INSERT and the
> UPDATE methods.
>
>
>
> Accroding you tutorial, the following steps are needed:
>
>
>
> // INSERT
> DBRecord rec = new DBRecord();
> rec.create(DBRowSet table);
> rec.setValue(...)
> rec.update(java.sql.Connection conn);
>
>
>
> // UPDATE
> DBRecord rec = new DBRecord();
> rec.read(..., java.sql.Connection conn);
> rec.setValue(...)
> rec.update(java.sql.Connection conn);
>
>
> Why in case of the UPDATE we have to give the Connection by two times?
>
>
>
> Thank to advise,
>
> Regards.
>
>
>
>
>

re: Why the connection is given two times in case of UPDATE?

Posted by Rainer Döbele <do...@esteam.de>.
Hi exxos,

 

In your update example the call to rec.read() will read the record from the database by executing a corresponding SELECT statement.

The UPDATE then only updates the changed fields.

 

It is part of our design, that we don't store connections since they are an external resource that might be shared between threads or requests and hence a connection must be supplied every time a database action is performed. But you may add your own layer (e.g. by deriving a class from DBRecord) to implement a connection handling that suits your purpose.

 

If you don't want to read before an update - e.g. if you know that the value will change and don't need the extra logic - then you should use a DBCommand to update a record. 

 

Regards,

Rainer

 

 

from: exxos [mailto:hatufr@gmail.com] 
to: empire-db-user@incubator.apache.org
re: Why the connection is given two times in case of UPDATE?

 

Hello,

 

Sorry to spam the august's mailling list. ^__^

 

But, I need a clarification on the implementation for the INSERT and the UPDATE methods.

 

Accroding you tutorial, the following steps are needed:

 

// INSERT
DBRecord rec = new DBRecord();
rec.create(DBRowSet table);
rec.setValue(...)
rec.update(java.sql.Connection conn);

 

// UPDATE
DBRecord rec = new DBRecord();
rec.read(..., java.sql.Connection conn);
rec.setValue(...)
rec.update(java.sql.Connection conn);


Why in case of the UPDATE we have to give the Connection by two times?

 

Thank to advise,

Regards.