Re: OOP/OOD Philosophy
- From: "frebe" <fredrik_bertilsson@xxxxxxxxxxx>
- Date: 11 Jul 2005 05:25:26 -0700
> 1) Show current system time.
In java you do System.currentTimeInMillis(). You don't need the
database to do that. If you really want to do it in the database, write
a own stored procedure. The implementation might differ in different
databases, but the application is only calling the stored procedure and
don't know about the implementation.
> to_char(SYSDATE, 'DD-Mon-YYYY HH24:MI')
Why do you convert the date to a string? Your application should
receive the date as a date object.
> 2. How do you calculate a duration or difference between two dates?
I do this in my java code. And if I really needed to do that, create a
stored procedure.
> Some have a datediff function others don't ...
Almost all databases gives you the possibility to create your own
functions.
> One query for one DB and another dialect for others. Ugly duplication
> which cannot be resolved by relying on the standardness of SQL.
Some examples please....
> mySQL has auto_increment, Oracle has create sequence ... with NEXTVAL,
> others have IDENTITY()
Now you are talkning about DDL statements. Your application, normally
only calls DML statements. If you really had to create sequences on the
fly, you could easily create different drivers (strategy pattern maybe)
for different vendors.
>> The syntax for createing a sequence may be
>> different for different vendors, but the applications does not have to
>> care about that. It just put null in that field and the RDBMS creates a
>> sequence number.
> No that isn't correct.
It works for Oracle, Postgres and MySQL (didn't have time to test more
vendors). For which vendors does it not work this way?
> There is a serious race condition here. After the max(id) and before
> the insert you have a critical section.
> To resolve this you must have table locking, which not all databases
> can do.
Just because not all databases support a standard, or is full-featured
does not mean that you can't be switchable between vendors that are
full-featured. Which databases does not support table locking (probably
MySQL, but I am not sure)?
> Or it requires you to prohibit concurrent access (somehow?)
The RDBMS should solve the concurrency issue in this case. That is what
transactions and locking are supposed to do.
Fredrik Bertilsson
http://butler.sourceforge.net
.
- Follow-Ups:
- Re: OOP/OOD Philosophy
- From: Alvin Ryder
- Re: OOP/OOD Philosophy
- References:
- Re: OOP/OOD Philosophy
- From: frebe
- Re: OOP/OOD Philosophy
- From: Robert C . Martin
- Re: OOP/OOD Philosophy
- From: frebe
- Re: OOP/OOD Philosophy
- From: Michael Feathers
- Re: OOP/OOD Philosophy
- From: frebe
- Re: OOP/OOD Philosophy
- From: Phlip
- Re: OOP/OOD Philosophy
- From: Michael Feathers
- Re: OOP/OOD Philosophy
- From: frebe
- Re: OOP/OOD Philosophy
- From: Phlip
- Re: OOP/OOD Philosophy
- From: frebe
- Re: OOP/OOD Philosophy
- From: Phlip
- Re: OOP/OOD Philosophy
- From: frebe
- Re: OOP/OOD Philosophy
- From: Alvin Ryder
- Re: OOP/OOD Philosophy
- From: frebe
- Re: OOP/OOD Philosophy
- From: Alvin Ryder
- Re: OOP/OOD Philosophy
- From: frebe
- Re: OOP/OOD Philosophy
- From: Alvin Ryder
- Re: OOP/OOD Philosophy
- Prev by Date: Re: Design versus invention
- Next by Date: Test first as specification
- Previous by thread: Re: OOP/OOD Philosophy
- Next by thread: Re: OOP/OOD Philosophy
- Index(es):
Relevant Pages
|