On 3.10.2012 10:10, Lukas Eder wrote:
Hello Jouni,
Feature proposal 1:
[...]
Generated XXXRecord.store() returns
1 if the record was inserted to the database.
2 if the record was updated in the database.
0 if storing was not necessary.
I'm not sure this is a good idea. 1 isn't a code indicating that a
record was stored, it means that "one" record was affected by the
underlying SQL statement, just as you may get 1 from int count =
stmt.executeUpdate("INSERT INTO ..");
There are some parts of the API that involve updating records, which
already return values greater than 1 to indicate that 2 records were
updated, for instance.
What would you need this information for? Maybe there is another way
to know this.
I have record manipulation on one layer and storing is done on other
layer. Storing part can do different type of logging depending on the
operation (=insert, update, nothing).
I understand that the change might be questionable if the meaning of the
return value is currently "number of rows changed".
Is it possible to have a function that returns the type of last executed
operation in db.
E.g.
Author a = ...
a.store()
Operation op = a.getLastOpetion();
if ( op == Operation.INSERT )
...
or
Author a = ...
a.store()
Operation op = factory.getLastOpetion();
if ( op == Operation.INSERT )
...
oreven better
factory.getNumberOfInsertedRows()
factory.getNumberOfUpdatedRows()
Feature proposal 3:
Proposed functionality:
To add a function XXXRecord.setChanged(Field field, boolean isChanged) which
sets the value true or false. This is needed e.g. when records are copied
field by field to new (e.g. extended class) records. Ofcourse reflection
can be used to reset isChanged, but it is not very efficient way of doing
it.
That API suggestion feels like internals are allowed to leak to the
public API. Why would you need this?
I made a piece of code that parses records from query resulting multiple
different types of records. Suppose you have SQL:
select * from author left join book on author.id=book.author_id left
join language on book.language_id=language.id
Resulting rows might look something like this:
Author1, Book1, Language1
Author1, Book2, Language1
Author1, Book3, null
Author2, Book4, Language2
Author3, null, null
Where AuthorX means all column values belonging to AuthorX, that is:
select * from Author where id = id of AuthorX.
My simple result parser creates Author, Book and Language records from
Result<Record>. This involves copying record fields and without setting
isChanged=false afterwards these newly created Author, Book and Language
records have all fields dirty although they are just fetched from db. I
made a temporary resetting solution using reflection, but I would like
to replace it with better / faster solution.
Cheers,
Jouni