[Lift] Re: Newbie Question design pattern for ORM in Lift

2009-08-29 Thread David Pollak
On Thu, Aug 27, 2009 at 10:26 AM, rstradling wrote:

>
> With a parser combinator I wrote to parse .sql and it outputs scala
> orm files.


Care to share?  That'd be a pretty darned useful utility!


> Please note it is very specific to my needs (i.e. only
> works with certain grammars (INSERTS) but that particular grammar is
> all I needed to process at the time) but is written in a way that
> could be extended to the full grammar (at least that was my
> intent :)..


So... the problem is that objects in Scala are not subclassible.  What does
this mean?  For example:

trait Foo {
  object bar extends AnyRef
}

trait MyFoo extends Foo {
  override object bar {
def cantDoIt = "sigh"
  }
}

Back in the Scala 2.5 days, there was some talk about allowing this to
happen, but it never did.  So, unfortunately, I can't think of a way for
your sql generator to create a superclass that could be subclassed and have
the effect that you want.

Sorry/


>
>
>
> On Aug 27, 1:09 pm, Naftoli Gugenheim  wrote:
> > How do you auto-generate them?
> >
> > On Thu, Aug 27, 2009 at 1:03 PM, rstradling 
> wrote:
> >
> > > I am using Lift 1.0 with the Mapper ORM module from Lift. I am a
> > > newbie to Scala and Lift.  I have auto-generated my ORM classes from
> > > a .sql file.  Given that these classes are auto-generated I would
> > > prefer not to edit them directly and provide additional functionality
> > > via inheritance.
> >
> > > Say I have the following...
> > > class StatGenerated extends LongKeyedMapper[StatGenerated] with IdPK {
> > >   def getSingleton = StatGenerated
> > >   object errors extends MappedLong(this)
> > >   object hits extends MappedLong(this)
> > >   object AB extends MappedLong(this)
> > > }
> >
> > > object StatGenerated extends StatGenerated with LongKeyedMetaMapper
> > > [StatGenerated] {
> > >   override def fieldOrder = List(errors, hits)
> > > }
> >
> > > class Statistics extends StatGenerated {
> > >   def GetBattingAverage(id : Long) : float = {
> > >val stat = Stat.findByKey(id)
> > >stat.hits/stat.AB
> > >   }
> > > }
> >
> > > Now what I would like to do is work with the Statistics class as my
> > > ORM object...
> > > But I believe everything that is ORM related is actually of type
> > > StatGenerated rather than Statistics.  i.e. findByKey will return me a
> > > StatGenerated rather than a Statistics class.  Is there any clever way
> > > around this that I am missing without either modifying the generated
> > > class or duplicating code?
>
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Newbie Question design pattern for ORM in Lift

2009-08-28 Thread Bjarte Stien Karlsen

That looks very cool from a first glance.

mvh
Bjarte

On Fri, Aug 28, 2009 at 5:04 AM, rstradling wrote:
>
> git clone git://github.com/rstradling/DDLtoLiftORM.git  is the
> location of the git code.
>
> http://github.com/rstradling/DDLtoLiftORM is the web address
>
> I hope this is helpful to others.
>
> On Aug 27, 3:13 pm, rstradling  wrote:
>> Thanks for the answers everyone.  What David hit upon about wanting
>> objects to be subclassible is the conclusion I came to that would
>> work..if it existed.  I was hoping there was a way. :(.  Well, I guess
>> Naftoli has provided a possible solution but seems more involved than
>> I have the experience for.
>>
>> I will resort to putting the stuff on the generated classes and let
>> merge tools do the rest.
>>
>> Regarding sharing the codeI should be more specific in that it
>> parses ddl.  To be honest, I hope you all are not hoping for
>> muchbut I will get it up on github and when I do will reply to
>> this thread with the location.
>>
>> On Aug 27, 1:35 pm, David Pollak 
>> wrote:
>>
>> > On Thu, Aug 27, 2009 at 10:26 AM, rstradling 
>> > wrote:
>>
>> > > With a parser combinator I wrote to parse .sql and it outputs scala
>> > > orm files.
>>
>> > Care to share?  That'd be a pretty darned useful utility!
>>
>> > > Please note it is very specific to my needs (i.e. only
>> > > works with certain grammars (INSERTS) but that particular grammar is
>> > > all I needed to process at the time) but is written in a way that
>> > > could be extended to the full grammar (at least that was my
>> > > intent :)..
>>
>> > So... the problem is that objects in Scala are not subclassible.  What does
>> > this mean?  For example:
>>
>> > trait Foo {
>> >   object bar extends AnyRef
>>
>> > }
>>
>> > trait MyFoo extends Foo {
>> >   override object bar {
>> >     def cantDoIt = "sigh"
>> >   }
>>
>> > }
>>
>> > Back in the Scala 2.5 days, there was some talk about allowing this to
>> > happen, but it never did.  So, unfortunately, I can't think of a way for
>> > your sql generator to create a superclass that could be subclassed and have
>> > the effect that you want.
>>
>> > Sorry/
>>
>> > > On Aug 27, 1:09 pm, Naftoli Gugenheim  wrote:
>> > > > How do you auto-generate them?
>>
>> > > > On Thu, Aug 27, 2009 at 1:03 PM, rstradling 
>> > > wrote:
>>
>> > > > > I am using Lift 1.0 with the Mapper ORM module from Lift. I am a
>> > > > > newbie to Scala and Lift.  I have auto-generated my ORM classes from
>> > > > > a .sql file.  Given that these classes are auto-generated I would
>> > > > > prefer not to edit them directly and provide additional functionality
>> > > > > via inheritance.
>>
>> > > > > Say I have the following...
>> > > > > class StatGenerated extends LongKeyedMapper[StatGenerated] with IdPK 
>> > > > > {
>> > > > >   def getSingleton = StatGenerated
>> > > > >   object errors extends MappedLong(this)
>> > > > >   object hits extends MappedLong(this)
>> > > > >   object AB extends MappedLong(this)
>> > > > > }
>>
>> > > > > object StatGenerated extends StatGenerated with LongKeyedMetaMapper
>> > > > > [StatGenerated] {
>> > > > >   override def fieldOrder = List(errors, hits)
>> > > > > }
>>
>> > > > > class Statistics extends StatGenerated {
>> > > > >   def GetBattingAverage(id : Long) : float = {
>> > > > >                val stat = Stat.findByKey(id)
>> > > > >                stat.hits/stat.AB
>> > > > >   }
>> > > > > }
>>
>> > > > > Now what I would like to do is work with the Statistics class as my
>> > > > > ORM object...
>> > > > > But I believe everything that is ORM related is actually of type
>> > > > > StatGenerated rather than Statistics.  i.e. findByKey will return me 
>> > > > > a
>> > > > > StatGenerated rather than a Statistics class.  Is there any clever 
>> > > > > way
>> > > > > around this that I am missing without either modifying the generated
>> > > > > class or duplicating code?
>>
>> > --
>> > Lift, the simply functional web frameworkhttp://liftweb.net
>> > Beginning Scalahttp://www.apress.com/book/view/1430219890
>> > Follow me:http://twitter.com/dpp
>> > Git some:http://github.com/dpp
>
> >
>



-- 
Bjarte Stien Karlsen
Ronatoppen 6a, 4638 Kristiansand
95219547
MSN: m...@ibjarte.com

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Newbie Question design pattern for ORM in Lift

2009-08-27 Thread rstradling

git clone git://github.com/rstradling/DDLtoLiftORM.git  is the
location of the git code.

http://github.com/rstradling/DDLtoLiftORM is the web address

I hope this is helpful to others.

On Aug 27, 3:13 pm, rstradling  wrote:
> Thanks for the answers everyone.  What David hit upon about wanting
> objects to be subclassible is the conclusion I came to that would
> work..if it existed.  I was hoping there was a way. :(.  Well, I guess
> Naftoli has provided a possible solution but seems more involved than
> I have the experience for.
>
> I will resort to putting the stuff on the generated classes and let
> merge tools do the rest.
>
> Regarding sharing the codeI should be more specific in that it
> parses ddl.  To be honest, I hope you all are not hoping for
> muchbut I will get it up on github and when I do will reply to
> this thread with the location.
>
> On Aug 27, 1:35 pm, David Pollak 
> wrote:
>
> > On Thu, Aug 27, 2009 at 10:26 AM, rstradling wrote:
>
> > > With a parser combinator I wrote to parse .sql and it outputs scala
> > > orm files.
>
> > Care to share?  That'd be a pretty darned useful utility!
>
> > > Please note it is very specific to my needs (i.e. only
> > > works with certain grammars (INSERTS) but that particular grammar is
> > > all I needed to process at the time) but is written in a way that
> > > could be extended to the full grammar (at least that was my
> > > intent :)..
>
> > So... the problem is that objects in Scala are not subclassible.  What does
> > this mean?  For example:
>
> > trait Foo {
> >   object bar extends AnyRef
>
> > }
>
> > trait MyFoo extends Foo {
> >   override object bar {
> >     def cantDoIt = "sigh"
> >   }
>
> > }
>
> > Back in the Scala 2.5 days, there was some talk about allowing this to
> > happen, but it never did.  So, unfortunately, I can't think of a way for
> > your sql generator to create a superclass that could be subclassed and have
> > the effect that you want.
>
> > Sorry/
>
> > > On Aug 27, 1:09 pm, Naftoli Gugenheim  wrote:
> > > > How do you auto-generate them?
>
> > > > On Thu, Aug 27, 2009 at 1:03 PM, rstradling 
> > > wrote:
>
> > > > > I am using Lift 1.0 with the Mapper ORM module from Lift. I am a
> > > > > newbie to Scala and Lift.  I have auto-generated my ORM classes from
> > > > > a .sql file.  Given that these classes are auto-generated I would
> > > > > prefer not to edit them directly and provide additional functionality
> > > > > via inheritance.
>
> > > > > Say I have the following...
> > > > > class StatGenerated extends LongKeyedMapper[StatGenerated] with IdPK {
> > > > >   def getSingleton = StatGenerated
> > > > >   object errors extends MappedLong(this)
> > > > >   object hits extends MappedLong(this)
> > > > >   object AB extends MappedLong(this)
> > > > > }
>
> > > > > object StatGenerated extends StatGenerated with LongKeyedMetaMapper
> > > > > [StatGenerated] {
> > > > >   override def fieldOrder = List(errors, hits)
> > > > > }
>
> > > > > class Statistics extends StatGenerated {
> > > > >   def GetBattingAverage(id : Long) : float = {
> > > > >                val stat = Stat.findByKey(id)
> > > > >                stat.hits/stat.AB
> > > > >   }
> > > > > }
>
> > > > > Now what I would like to do is work with the Statistics class as my
> > > > > ORM object...
> > > > > But I believe everything that is ORM related is actually of type
> > > > > StatGenerated rather than Statistics.  i.e. findByKey will return me a
> > > > > StatGenerated rather than a Statistics class.  Is there any clever way
> > > > > around this that I am missing without either modifying the generated
> > > > > class or duplicating code?
>
> > --
> > Lift, the simply functional web frameworkhttp://liftweb.net
> > Beginning Scalahttp://www.apress.com/book/view/1430219890
> > Follow me:http://twitter.com/dpp
> > Git some:http://github.com/dpp

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Newbie Question design pattern for ORM in Lift

2009-08-27 Thread Naftoli Gugenheim
How do you auto-generate them?

On Thu, Aug 27, 2009 at 1:03 PM, rstradling  wrote:

>
> I am using Lift 1.0 with the Mapper ORM module from Lift. I am a
> newbie to Scala and Lift.  I have auto-generated my ORM classes from
> a .sql file.  Given that these classes are auto-generated I would
> prefer not to edit them directly and provide additional functionality
> via inheritance.
>
> Say I have the following...
> class StatGenerated extends LongKeyedMapper[StatGenerated] with IdPK {
>   def getSingleton = StatGenerated
>   object errors extends MappedLong(this)
>   object hits extends MappedLong(this)
>   object AB extends MappedLong(this)
> }
>
> object StatGenerated extends StatGenerated with LongKeyedMetaMapper
> [StatGenerated] {
>   override def fieldOrder = List(errors, hits)
> }
>
> class Statistics extends StatGenerated {
>   def GetBattingAverage(id : Long) : float = {
>val stat = Stat.findByKey(id)
>stat.hits/stat.AB
>   }
> }
>
>
> Now what I would like to do is work with the Statistics class as my
> ORM object...
> But I believe everything that is ORM related is actually of type
> StatGenerated rather than Statistics.  i.e. findByKey will return me a
> StatGenerated rather than a Statistics class.  Is there any clever way
> around this that I am missing without either modifying the generated
> class or duplicating code?
>
>
>
>
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Newbie Question design pattern for ORM in Lift

2009-08-27 Thread Naftoli Gugenheim
You could try making StatGenerated a trait and either extending
LongKeyedMapper or using a self type, and experiment with the fields as
objects in the trait or just defs that you override either with the object
(the actual field), or with an implementation that points to the
field.Subclassing
Mappers seems to get very tricky, because of the self types and its
ramifications.

On Thu, Aug 27, 2009 at 1:26 PM, rstradling  wrote:

>
> With a parser combinator I wrote to parse .sql and it outputs scala
> orm files.  Please note it is very specific to my needs (i.e. only
> works with certain grammars (INSERTS) but that particular grammar is
> all I needed to process at the time) but is written in a way that
> could be extended to the full grammar (at least that was my
> intent :)..
>
>
> On Aug 27, 1:09 pm, Naftoli Gugenheim  wrote:
> > How do you auto-generate them?
> >
> > On Thu, Aug 27, 2009 at 1:03 PM, rstradling 
> wrote:
> >
> > > I am using Lift 1.0 with the Mapper ORM module from Lift. I am a
> > > newbie to Scala and Lift.  I have auto-generated my ORM classes from
> > > a .sql file.  Given that these classes are auto-generated I would
> > > prefer not to edit them directly and provide additional functionality
> > > via inheritance.
> >
> > > Say I have the following...
> > > class StatGenerated extends LongKeyedMapper[StatGenerated] with IdPK {
> > >   def getSingleton = StatGenerated
> > >   object errors extends MappedLong(this)
> > >   object hits extends MappedLong(this)
> > >   object AB extends MappedLong(this)
> > > }
> >
> > > object StatGenerated extends StatGenerated with LongKeyedMetaMapper
> > > [StatGenerated] {
> > >   override def fieldOrder = List(errors, hits)
> > > }
> >
> > > class Statistics extends StatGenerated {
> > >   def GetBattingAverage(id : Long) : float = {
> > >val stat = Stat.findByKey(id)
> > >stat.hits/stat.AB
> > >   }
> > > }
> >
> > > Now what I would like to do is work with the Statistics class as my
> > > ORM object...
> > > But I believe everything that is ORM related is actually of type
> > > StatGenerated rather than Statistics.  i.e. findByKey will return me a
> > > StatGenerated rather than a Statistics class.  Is there any clever way
> > > around this that I am missing without either modifying the generated
> > > class or duplicating code?
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Newbie Question design pattern for ORM in Lift

2009-08-27 Thread rstradling

Thanks for the answers everyone.  What David hit upon about wanting
objects to be subclassible is the conclusion I came to that would
work..if it existed.  I was hoping there was a way. :(.  Well, I guess
Naftoli has provided a possible solution but seems more involved than
I have the experience for.

I will resort to putting the stuff on the generated classes and let
merge tools do the rest.

Regarding sharing the codeI should be more specific in that it
parses ddl.  To be honest, I hope you all are not hoping for
muchbut I will get it up on github and when I do will reply to
this thread with the location.


On Aug 27, 1:35 pm, David Pollak 
wrote:
> On Thu, Aug 27, 2009 at 10:26 AM, rstradling wrote:
>
>
>
> > With a parser combinator I wrote to parse .sql and it outputs scala
> > orm files.
>
> Care to share?  That'd be a pretty darned useful utility!
>
> > Please note it is very specific to my needs (i.e. only
> > works with certain grammars (INSERTS) but that particular grammar is
> > all I needed to process at the time) but is written in a way that
> > could be extended to the full grammar (at least that was my
> > intent :)..
>
> So... the problem is that objects in Scala are not subclassible.  What does
> this mean?  For example:
>
> trait Foo {
>   object bar extends AnyRef
>
> }
>
> trait MyFoo extends Foo {
>   override object bar {
>     def cantDoIt = "sigh"
>   }
>
> }
>
> Back in the Scala 2.5 days, there was some talk about allowing this to
> happen, but it never did.  So, unfortunately, I can't think of a way for
> your sql generator to create a superclass that could be subclassed and have
> the effect that you want.
>
> Sorry/
>
>
>
>
>
> > On Aug 27, 1:09 pm, Naftoli Gugenheim  wrote:
> > > How do you auto-generate them?
>
> > > On Thu, Aug 27, 2009 at 1:03 PM, rstradling 
> > wrote:
>
> > > > I am using Lift 1.0 with the Mapper ORM module from Lift. I am a
> > > > newbie to Scala and Lift.  I have auto-generated my ORM classes from
> > > > a .sql file.  Given that these classes are auto-generated I would
> > > > prefer not to edit them directly and provide additional functionality
> > > > via inheritance.
>
> > > > Say I have the following...
> > > > class StatGenerated extends LongKeyedMapper[StatGenerated] with IdPK {
> > > >   def getSingleton = StatGenerated
> > > >   object errors extends MappedLong(this)
> > > >   object hits extends MappedLong(this)
> > > >   object AB extends MappedLong(this)
> > > > }
>
> > > > object StatGenerated extends StatGenerated with LongKeyedMetaMapper
> > > > [StatGenerated] {
> > > >   override def fieldOrder = List(errors, hits)
> > > > }
>
> > > > class Statistics extends StatGenerated {
> > > >   def GetBattingAverage(id : Long) : float = {
> > > >                val stat = Stat.findByKey(id)
> > > >                stat.hits/stat.AB
> > > >   }
> > > > }
>
> > > > Now what I would like to do is work with the Statistics class as my
> > > > ORM object...
> > > > But I believe everything that is ORM related is actually of type
> > > > StatGenerated rather than Statistics.  i.e. findByKey will return me a
> > > > StatGenerated rather than a Statistics class.  Is there any clever way
> > > > around this that I am missing without either modifying the generated
> > > > class or duplicating code?
>
> --
> Lift, the simply functional web frameworkhttp://liftweb.net
> Beginning Scalahttp://www.apress.com/book/view/1430219890
> Follow me:http://twitter.com/dpp
> Git some:http://github.com/dpp

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Newbie Question design pattern for ORM in Lift

2009-08-27 Thread rstradling

With a parser combinator I wrote to parse .sql and it outputs scala
orm files.  Please note it is very specific to my needs (i.e. only
works with certain grammars (INSERTS) but that particular grammar is
all I needed to process at the time) but is written in a way that
could be extended to the full grammar (at least that was my
intent :)..


On Aug 27, 1:09 pm, Naftoli Gugenheim  wrote:
> How do you auto-generate them?
>
> On Thu, Aug 27, 2009 at 1:03 PM, rstradling  wrote:
>
> > I am using Lift 1.0 with the Mapper ORM module from Lift. I am a
> > newbie to Scala and Lift.  I have auto-generated my ORM classes from
> > a .sql file.  Given that these classes are auto-generated I would
> > prefer not to edit them directly and provide additional functionality
> > via inheritance.
>
> > Say I have the following...
> > class StatGenerated extends LongKeyedMapper[StatGenerated] with IdPK {
> >   def getSingleton = StatGenerated
> >   object errors extends MappedLong(this)
> >   object hits extends MappedLong(this)
> >   object AB extends MappedLong(this)
> > }
>
> > object StatGenerated extends StatGenerated with LongKeyedMetaMapper
> > [StatGenerated] {
> >   override def fieldOrder = List(errors, hits)
> > }
>
> > class Statistics extends StatGenerated {
> >   def GetBattingAverage(id : Long) : float = {
> >                val stat = Stat.findByKey(id)
> >                stat.hits/stat.AB
> >   }
> > }
>
> > Now what I would like to do is work with the Statistics class as my
> > ORM object...
> > But I believe everything that is ORM related is actually of type
> > StatGenerated rather than Statistics.  i.e. findByKey will return me a
> > StatGenerated rather than a Statistics class.  Is there any clever way
> > around this that I am missing without either modifying the generated
> > class or duplicating code?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---