Recent

Author Topic: And what about the object layer?  (Read 3508 times)

greyspammer

  • New member
  • *
  • Posts: 6
And what about the object layer?
« on: July 04, 2013, 10:54:27 am »
Greetings!

I'm a newbie experimenting with Lazarus and its database capabilities. I have a question which I could not find an answer for elsewhere. Hopefully, you can help me.

I already got a simple prototype of a small DB application working using ZeosLib and the standard Lazarus components and I am impressed with how little time that took (much quicker than a similar mockup with Java!).

But I do not see any obvious way to squeeze the object layer (model) into my application. The data-aware GUI components link directly to the database management components. And the object representation of the DB record seems to be left out of the loop.

Under Java, for instance, I would create my model as class hierarchy and then use a persistence layer like Hibernate to map that to a relational database like PostgreSQL. During my search for a similar persistence layer for Lazarus, I found tiOPF. But the website states that there is no persistence layer for neither MySQL nor PostgreSQL (which I would very much like to use because they're kind of a de-facto standard with lots of 3rd party tools and bindings for almost any language - which would keep my options open).

I guess I could instead use Firebird which seems to be supported by tiOPF (even though I have no experience with it) but before I jump into that abyss, I'd like to ask:

- Am I on the right track? Maybe I have not understood the concept behind Lazarus DB development (who is to say it has to work like it does in Java?) and there is a much easier way to get my DB data linked to an FreePascal object.

- Is there perhaps another O/R mapper that works with PostgreSQL or is better suited for other reasons?

I am using Lazarus 1.0.10 on Ubuntu Linux and would very much like to maintain platform independence, so any pure Windows and/or i386 solutions are pretty much out of the question, if that's relevant.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8222
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: And what about the object layer?
« Reply #1 on: July 04, 2013, 11:06:02 am »
Quote
- Am I on the right track? Maybe I have not understood the concept behind Lazarus DB development (who is to say it has to work like it does in Java?) and there is a much easier way to get my DB data linked to an FreePascal object.
Depends, some people prefer RAD dataset approach like what you have just figured out, some (including me) prefer persistence layer. Both are actually quite easy to change backend, so that's not problem in any of them. The problem of dataset approach is that you might need to play with SQL manually, but from the RAD perspective, it's easy to see the result right away at design time, thus reducing compile cycle. The problem with OPF/ORM is that you'll code much more, but no need to touch SQL most of the time and you can even change the backend to something that's not based on SQL. Just pick up what you prefer.
Quote
Is there perhaps another O/R mapper that works with PostgreSQL or is better suited for other reasons?
Other than tiOPF, if you're willing to use Greyhound (which can use either ZEOS or SQLdb as backend), you can use my ghORM unit. It's not complete yet though and still needs testing for the relationship feature, and I use convention over configuration principle in order to make it easier to use. There are other persistence frameworks for Object Pascal out there but I have no list, just google.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: And what about the object layer?
« Reply #2 on: July 04, 2013, 12:20:50 pm »
IIRC, tiOPF does support mysql nowadays. Probably postgresql as well as it supports the FPC sqldb layer - which supports mysql, postgresql, firebird, Oracle, mssql etc.

I do have the feeling the tiOPF website is out of date.

Perhaps try asking on the tiopf mailing lists if you need more details.

@Graeme: where are you? ;)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

greyspammer

  • New member
  • *
  • Posts: 6
Re: And what about the object layer?
« Reply #3 on: July 05, 2013, 05:47:39 pm »
Yes, it seems the tiOPF website is a bit out of date. There appears to be support for both MySQL and PostgreSQL.

I tried to get started by reading http://tiopf.sourceforge.net/Doc/PersistingObjectsAndRelationships/SimpleCollection/, yet I keep running into troubles. Firstly, it's focussed on Delphi, so I cannot apply it 1:1 to Lazarus.

Secondly, at one point, the author suddenly uses a TPerson.Save method that was never properly introduced. I simply exported it (like the earlier TPersonList.Read) but nothing happens to my DB when I call it (even when I switch to CSV database for testing purposes).

Thirdly, I installed the tiOPF packages like described here: http://wiki.lazarus.freepascal.org/tiOPF. But when I try to drop any TtiPerAwareXXXX component on the form, all I get are two access violation messages (one for creation and one for destruction of the component).

Fourthly, the mailing list link at the project's website leads to a dead end: https://lists.sourceforge.net/lists/listinfo/tiopf-talk.

Is this software really mature and under active development? Or is just me being incredibly stupid?

I think I'll try to take a look at Greyhound before trying to untangle that ball of yarn. Given the ease of the dataset approach, I was hoping for a similarly easy O/R solution. You know, write a BOM, drop a component that links the BOM to the DB and maybe another one that links BOM and GUI and be done with it. Seems it's not that easy at all.
« Last Edit: July 05, 2013, 05:49:53 pm by greyspammer »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: And what about the object layer?
« Reply #4 on: July 05, 2013, 05:54:06 pm »
Well, it's under active development.

There's an NNTP server at opensoft.homeip.net (tiopf.support). People seem to get quite some support there.


One of the developers who maintains the FPC port, Graeme Geldenhuys, is on this forum as well.
I'm assuming you've seen the wiki page as well:
http://wiki.lazarus.freepascal.org/tiOPF
... shame the NNTP info doesn't seem to be there...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

ojn

  • New Member
  • *
  • Posts: 24
Re: And what about the object layer?
« Reply #5 on: July 05, 2013, 06:53:07 pm »
I think I'll try to take a look at Greyhound before trying to untangle that ball of yarn. Given the ease of the dataset approach, I was hoping for a similarly easy O/R solution. You know, write a BOM, drop a component that links the BOM to the DB and maybe another one that links BOM and GUI and be done with it. Seems it's not that easy at all.

Hello:

A few days ago, in a Delphi forum thread, someone mentioned a persistence framework called InstantObjects. On it's SourceForge page, it says: "InstantObjects for Delphi/Kylix/FPC".

You can check the InstantObjects web pages at: http://sourceforge.net/projects/instantobjects/?source=navbar and http://www.instantobjects.org/. You can also view a comparison of tiOPF and InstantObjects at http://tiopf.sourceforge.net/tiOFPvsInstantObjects.shtml.

The gist of this comparison seemed to be that InstantObjects offered more ease of use but that tiOPF offered much more control. However, on the Delphi forum thread, Graeme  said he was surprised to hear someone mention InstantObjects and asked if it was still being actively developed. And the SourceForge page shows that there have not been any updates to InstantObjects for 7 years, so I would be very leery of starting any development based on InstantObjects. But it may offer you the ease of use that you're looking for.

(Note that I don't have any experience using any of these ORM persistence frameworks. I'm just looking at them myself, which is why I've been following this thread with interest. Thank you for asking your question about persistence frameworks.)

Regards,
Jerry

 

TinyPortal © 2005-2018