[Lift] Re: Using TemplatePf for JPA powered templates

2008-12-01 Thread Charles F. Munat

Will do, if I figure it out. But my comment wasn't complaining. I am 
honestly mystified. Am I the only one using trees in Hibernate? Is there 
a tree library in Scala that I'm missing? What the heck does everyone 
else do? It just blows my mind.

Chas.

Viktor Klang wrote:
 
 
 On Mon, Dec 1, 2008 at 5:42 AM, Charles F. Munat [EMAIL PROTECTED] 
 mailto:[EMAIL PROTECTED] wrote:
 
 
 Doing nested sets in your Lift snippet is pretty easy with JPA. I'm
 doing it on one of my Lift sites. One thing to remember, however, is to
 use a transaction. You don't want to do half the update to the tree and
 then have another use start an update before you've finished yours (or
 have half of it fail). Once it gets messed up it's a disaster.
 
 Nested tables are good when you have lots of lookups, particularly
 pulling ancestors or descendants, but not too many updates. Inserts are
 not too bad, but if you have to move whole subtrees, that's a pain.
 
 I'm using one for, among other things, a forum, so messages once posted
 never get moved. Nested sets work great for that.
 
 But, honestly, it is astonishing to me that Java, Scala, and especially
 JPA/Hibernate apparently have no built in features for creating,
 manipulating, and persisting trees (and networks are even less
 supported). These problems were largely solved long ago. Why aren't they
 built in?
 
 
 Charles, I hate to say this, but Hibernate is Open Source, so you can 
 add the support for it. :)
  
 
 
 
 Rails has a cool set of plugins -- acts_as_list, acts_as_tree, and
 acts_as_nested_set -- that make it drop-dead simple to implement trees.
 I was thinking that it would be cool if Lift had something similar but
 maybe as a trait? So my object extends ActsAsNestedSet?
 
 I tried to do this in Hibernate, but it would require the object to
 query for other similar objects. For example, if I had a Node object
 that I was persisting, I'd like to do
 
 class Node extends ActsAsNestedSet
 
 And then define methods such as moveToChildOf(node), moveToFirst,
 moveBack, moveForth, moveToLast, etc. But it appears that you need an
 EntityManager to run a query, and there doesn't seem to be a way to go
 backwards from the Node to the EntityManager (probably because, if I
 understand it correctly, there will only be one copy of a given Node in
 memory but there may be multiple EntityManagers?).
 
 So I put the code in the snippet.
 
 If you come up with any clever solutions, I'd love to hear them.
 
 Chas.
 
 Tim Perrett wrote:
   Hey Derek,
  
   I've been playing around with this nested set stuff today - it's
 pretty
   cool. I nearly have an app working that uses the db for page
 content and
   maps the urls out however you want, it's pretty neat.
  
   I have a slight HQL problem with subquery's but I'll post that
 2mro :-)
  
   Thanks for all your help
  
   Tim
  
   Sent from my iPhone
  
   On 30 Nov 2008, at 23:37, Derek Chen-Becker
 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]
   mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote:
  
   IIRC, JPA has support for batch updates, but I'm not 100%
 positive on
   that. I'll have more time tomorrow to look at this if you'd
 still like
   to discuss it.
  
   Derek
  
   On Sun, Nov 30, 2008 at 12:32 PM, Tim Perrett 
   mailto:[EMAIL PROTECTED]
 mailto:[EMAIL PROTECTED][EMAIL PROTECTED]
 mailto:[EMAIL PROTECTED]
   mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote:
  
  
   Derek,
  
   Those links are *extremely* good - thank you! I've not
 really done
   anything with tree structures before and they are really, really
   usefull.
  
   One thing however, it appears the optimal way of  doing the
 insert
   queries would be with stored procedures, however that im not
 down
   with, and ideally, i want to keep database vendor
 independent (part of
   the point of using JPA) so ideally i want to suck that up
 into the
   application logic. For instance:
  
   --START
   SELECT @myRight := rgt FROM nested_category WHERE name =
   'TELEVISIONS';
  
   UPDATE nested_category SET rgt = rgt + 2 WHERE rgt  @myRight;
   UPDATE nested_category SET lft = lft + 2 WHERE lft  @myRight;
  
   INSERT INTO nested_category(name, lft, rgt) VALUES('GAME
 CONSOLES',
   @myRight + 1, @myRight + 2);
   --END
  
   This makes use of variables, and i could of course do this via 3
   separate queries in JPA, but i wondered if there was a
 neater way to
   construct this type of thing with JPA?
  
   Any advice you guys have is most welcome
 

[Lift] Re: Using TemplatePf for JPA powered templates

2008-12-01 Thread Charles F. Munat

Are you including a link to the parent node or are you just using the 
left and right values to figure out which nodes are children? I always 
include a foreign key to the parent so I can just select the children of 
that parent directly. Then to get all descendants, I use the left and 
right values. Similarly, to get the parent I use the foreign key, to get 
all ancestors, I use the left/right values.

Does this help?

(Sometimes I also include a calculated field called level which 
indicates how far away I am from the root node. It's a simple matter of 
counting the ancestors, but you have to remember to update it on moves. 
The level field is very useful if you want to go, say, two levels deep 
on children, or to parent and grandparent, but not great-grandparent.)

Chas.

Tim Perrett wrote:
 
 
 On Dec 1, 9:21 am, Charles F. Munat [EMAIL PROTECTED] wrote:
 Will do, if I figure it out. But my comment wasn't complaining. I am
 honestly mystified. Am I the only one using trees in Hibernate? Is there
 a tree library in Scala that I'm missing? What the heck does everyone
 else do? It just blows my mind.
 
 I found someone's contribution on Hibernate JIRA for handling sets,
 but it never seems to make it into core or the proper distro; it does
 seem odd its not in there.
 
 Anyway, the HQL problem I mentioned last night... I have the following
 HQL, which is just a slight mod from what was in that mysql article;
 effectivly I want to list all the children of a single leaf:
 
 SELECT node.name, (COUNT(parent.name) - (sub_tree.depth + 1)) AS depth
 FROM Content AS node,
   Content AS parent,
   Content AS sub_parent,
 ( SELECT node.name, (COUNT(parent.name) - 1) AS depth
 FROM Content AS node,
 Content AS parent
 WHERE node.lft BETWEEN parent.lft AND parent.rft
 AND node.name = :leaf
 GROUP BY node.name
 ORDER BY node.lft
 ) AS sub_tree
 WHERE node.lft BETWEEN parent.lft AND parent.rft
 AND node.lft BETWEEN sub_parent.lft AND sub_parent.rft
 AND sub_parent.name = sub_tree.name
 GROUP BY node.name
 HAVING depth = 1
 ORDER BY node.lft
 
 However, it bombs on the sub-query in the SELECT ... FROM ...
 subquery statement im guessing you guys are using get all leaf
 nodes type queries, so what are you doing instead of this?
 
 Cheers
 
 Tim
  

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Using TemplatePf for JPA powered templates

2008-12-01 Thread Tim Perrett

Im not sure I follow? Can you use this diagram to try and explain?:

http://dev.mysql.com/tech-resources/articles/hierarchical-data-4.png

If you wanted to select the direct children of 'electronics', how
would one go about doing that? Is there a simpler way than all that
HQL?

Cheers

Tim

On Dec 1, 10:28 am, Charles F. Munat [EMAIL PROTECTED] wrote:
 Are you including a link to the parent node or are you just using the
 left and right values to figure out which nodes are children? I always
 include a foreign key to the parent so I can just select the children of
 that parent directly. Then to get all descendants, I use the left and
 right values. Similarly, to get the parent I use the foreign key, to get
 all ancestors, I use the left/right values.

 Does this help?

 (Sometimes I also include a calculated field called level which
 indicates how far away I am from the root node. It's a simple matter of
 counting the ancestors, but you have to remember to update it on moves.
 The level field is very useful if you want to go, say, two levels deep
 on children, or to parent and grandparent, but not great-grandparent.)

 Chas.

 Tim Perrett wrote:

  On Dec 1, 9:21 am, Charles F. Munat [EMAIL PROTECTED] wrote:
  Will do, if I figure it out. But my comment wasn't complaining. I am
  honestly mystified. Am I the only one using trees in Hibernate? Is there
  a tree library in Scala that I'm missing? What the heck does everyone
  else do? It just blows my mind.

  I found someone's contribution on Hibernate JIRA for handling sets,
  but it never seems to make it into core or the proper distro; it does
  seem odd its not in there.

  Anyway, the HQL problem I mentioned last night... I have the following
  HQL, which is just a slight mod from what was in that mysql article;
  effectivly I want to list all the children of a single leaf:

  SELECT node.name, (COUNT(parent.name) - (sub_tree.depth + 1)) AS depth
          FROM Content AS node,
            Content AS parent,
            Content AS sub_parent,
                  ( SELECT node.name, (COUNT(parent.name) - 1) AS depth
              FROM Content AS node,
              Content AS parent
              WHERE node.lft BETWEEN parent.lft AND parent.rft
              AND node.name = :leaf
              GROUP BY node.name
              ORDER BY node.lft
              ) AS sub_tree
          WHERE node.lft BETWEEN parent.lft AND parent.rft
          AND node.lft BETWEEN sub_parent.lft AND sub_parent.rft
          AND sub_parent.name = sub_tree.name
          GROUP BY node.name
          HAVING depth = 1
          ORDER BY node.lft

  However, it bombs on the sub-query in the SELECT ... FROM ...
  subquery statement im guessing you guys are using get all leaf
  nodes type queries, so what are you doing instead of this?

  Cheers

  Tim
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Using TemplatePf for JPA powered templates

2008-12-01 Thread David Pollak
Tim,

Please remember that Lift's Snippet processing is recursive.  Thus, you
don't really need to hook into the templating system in order to be able to
using Lift's templates.  For example, if your snippet returned:

spanlift:comet type=Dog/lift:comet type=Cat//span

Lift would then interpret the two comet tags and you'd wind up with two
comet components on the page.

However, I think it's a security risk to allow arbitrary users to be able to
embed lift:xxx/ tags in their content.  This would in effect allow any
user access to any resource that any snippet has access to.

On the caching front, I'd hand-roll my own caching mechanism.  You'll
probably end up caching all (or almost all) the content.  Rather than doing
some goofy stuff in SQL trying to do object graph traversals, just do it in
objects.  You can use immutability and actors to deal with most of the
concurrency issues.

Thanks,

David

On Sat, Nov 29, 2008 at 6:25 PM, Tim Perrett [EMAIL PROTECTED] wrote:


 I've been playing around with this and extending the template loader
 is actually pretty easy. Its much simpler than I thought it would be!

 I have a dilemma however - store the templates (and associated meta
 data) in the database and then have to do a fetch / read on every
 request, or, use the file system and hold (for instance):

 example.html
 and
 example.meta // java properties file format

 The tree structure of the file system is the path of least resistance
 for my particular use case i think, but i guess im after some input /
 advice...? I feel as either way has a couple of hang-ups! The kind of
 meta data is just simple key-value pair stuff, but my plan would be to
 extend Record so that the save() etc became transparent and was
 abstracted away (i.e. don't need to worry about InputStreams etc)

 Appreciate any input / advice people have

 Cheers

 Tim

 On Nov 29, 2:31 pm, Derek Chen-Becker [EMAIL PROTECTED] wrote:
  Looking at findVisibleTemplate in LiftSession (line 512) certainly makes
 it
  appear that the template table defined by addTemplateBefore/After is
  consulted before it checks the filesystem.
 
  Derek
 
  On Fri, Nov 28, 2008 at 10:26 AM, Tim Perrett [EMAIL PROTECTED]
 wrote:
 
   Hey guys,
 
   I want to user lifts LiftRules.addTemplateBefore/After to load
   templates from a database, where my persistence is JPA.
 
   With TemplatePf can I do this? Im also thinking this will be one of
   the nice things about having lift tags, as it will mean i shouldn't
   need to build a custom tagging language or anything (as we already
   have it!). I presume that TemplatePf just tells lift where to get the
   XHTML from then it continues to do the processing on it (process
   snippets etc)?
 
   Cheers
 
   Tim
 



-- 
Lift, the simply functional web framework http://liftweb.net
Collaborative Task Management http://much4.us
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Using TemplatePf for JPA powered templates

2008-12-01 Thread Tim Perrett

Hey David,

Thanks for the response - I have been reflecting on the whole L2 cache
thing today and kind of came to the same conclusion. If the content
has been served, it might as well be cached in its entirety as a HTML
file so it can then be served by the front end web-server (nginx,
apache etc) and i'll just expire the cache on a ad-hoc basis from the
admin application.

As for your concerns over security - I agree, it has grounding, but on
the other hand, my plan was to provide a couple of snippets and
document those, things like:

- list all leaf nodes
- list all nodes
etc, etc

I can also then take advantage of the lift localization mechanism - so
all in all, I think the pro's out weigh the cons. Potentially in the
XML page parser I could add a step which checked for the presence of
un-allowed tags (like comet) via some XML DOM checking. Just a thought
anyways :-)

Cheers

Tim



On Dec 1, 5:11 pm, David Pollak [EMAIL PROTECTED]
wrote:
 Tim,

 Please remember that Lift's Snippet processing is recursive.  Thus, you
 don't really need to hook into the templating system in order to be able to
 using Lift's templates.  For example, if your snippet returned:

 spanlift:comet type=Dog/lift:comet type=Cat//span

 Lift would then interpret the two comet tags and you'd wind up with two
 comet components on the page.

 However, I think it's a security risk to allow arbitrary users to be able to
 embed lift:xxx/ tags in their content.  This would in effect allow any
 user access to any resource that any snippet has access to.

 On the caching front, I'd hand-roll my own caching mechanism.  You'll
 probably end up caching all (or almost all) the content.  Rather than doing
 some goofy stuff in SQL trying to do object graph traversals, just do it in
 objects.  You can use immutability and actors to deal with most of the
 concurrency issues.

 Thanks,

 David

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Using TemplatePf for JPA powered templates

2008-12-01 Thread Charles F. Munat

When I use a nested set, I make it like a combination of nested set and 
a simple tree. So in my database, I have:

idparent_idlftrgtname
--
  1 NULL  1 20Electronics
  21  2  9Televisions
  32  3  4Tube
  42  5  6LCD
  52  7  8Plasma
  61 10 19Portable Electronics
  76 11 14MP3 Players
  87 12 13Flash
  96 15 16CD Players
106 17 182-way Radios

Then I get things the following way:

For MP3 Players (#7):

-- Ancestors
select * from mytable where lft  11 and rgt  14;

-- Ancestors and self
select * from mytable where lft = 11 and rgt = 14;

-- Parent
select * from mytable where id = 6;

-- Siblings and self
select * from mytable where parent_id = 6;

-- Siblings
select * from mytable where parent_id = 6 and id  7;

-- Siblings on the left
select * from mytable where parent_id = 6 and rgt  11;

-- Siblings on the right
select * from mytable where parent_id = 6 and lft  14;

-- Immediate children
select * from mytable where parent_id = 7;

-- Descendants and self
select * from mytable where lft = 11 and rgt = 14;

-- Descendants
select * from mytable where lft  11 and rgt  14;

In JPA/Hibernate, you'd have to modify this slightly. Each node in the 
tree would have a parent: Node attribute and a children: 
java.util.Set[Node] attribute.

So then for example to get immediate children you would do:

from Node n where n.parent.id = :id

(But you could just access them through node.children as well.)

Is this helping at all?

Chas.

Tim Perrett wrote:
 Im not sure I follow? Can you use this diagram to try and explain?:
 
 http://dev.mysql.com/tech-resources/articles/hierarchical-data-4.png
 
 If you wanted to select the direct children of 'electronics', how
 would one go about doing that? Is there a simpler way than all that
 HQL?
 
 Cheers
 
 Tim
 
 On Dec 1, 10:28 am, Charles F. Munat [EMAIL PROTECTED] wrote:
 Are you including a link to the parent node or are you just using the
 left and right values to figure out which nodes are children? I always
 include a foreign key to the parent so I can just select the children of
 that parent directly. Then to get all descendants, I use the left and
 right values. Similarly, to get the parent I use the foreign key, to get
 all ancestors, I use the left/right values.

 Does this help?

 (Sometimes I also include a calculated field called level which
 indicates how far away I am from the root node. It's a simple matter of
 counting the ancestors, but you have to remember to update it on moves.
 The level field is very useful if you want to go, say, two levels deep
 on children, or to parent and grandparent, but not great-grandparent.)

 Chas.

 Tim Perrett wrote:

 On Dec 1, 9:21 am, Charles F. Munat [EMAIL PROTECTED] wrote:
 Will do, if I figure it out. But my comment wasn't complaining. I am
 honestly mystified. Am I the only one using trees in Hibernate? Is there
 a tree library in Scala that I'm missing? What the heck does everyone
 else do? It just blows my mind.
 I found someone's contribution on Hibernate JIRA for handling sets,
 but it never seems to make it into core or the proper distro; it does
 seem odd its not in there.
 Anyway, the HQL problem I mentioned last night... I have the following
 HQL, which is just a slight mod from what was in that mysql article;
 effectivly I want to list all the children of a single leaf:
 SELECT node.name, (COUNT(parent.name) - (sub_tree.depth + 1)) AS depth
 FROM Content AS node,
   Content AS parent,
   Content AS sub_parent,
 ( SELECT node.name, (COUNT(parent.name) - 1) AS depth
 FROM Content AS node,
 Content AS parent
 WHERE node.lft BETWEEN parent.lft AND parent.rft
 AND node.name = :leaf
 GROUP BY node.name
 ORDER BY node.lft
 ) AS sub_tree
 WHERE node.lft BETWEEN parent.lft AND parent.rft
 AND node.lft BETWEEN sub_parent.lft AND sub_parent.rft
 AND sub_parent.name = sub_tree.name
 GROUP BY node.name
 HAVING depth = 1
 ORDER BY node.lft
 However, it bombs on the sub-query in the SELECT ... FROM ...
 subquery statement im guessing you guys are using get all leaf
 nodes type queries, so what are you doing instead of this?
 Cheers
 Tim
  

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Using TemplatePf for JPA powered templates

2008-12-01 Thread Shawn O'Connor

On Sun, Nov 30, 2008 at 6:27 AM, Derek Chen-Becker
[EMAIL PROTECTED] wrote:
 If you're heavily skewed towards reads and not writes (as it seems in the
 case of a CMS), you might want to look at Celko nested sets:

 http://www.intelligententerprise.com/001020/celko.jhtml
 http://dev.mysql.com/tech-resources/articles/hierarchical-data.html

If you're going down this path, you should also read some of Vadim
Tropashko's work on hierarchical SQL approaches.  This blog post of
his offers a good comparison of adjacency relations, nested sets,
materialized paths, and nested intervals via matrix encoding:
 
http://vadimtropashko.wordpress.com/2008/08/09/one-more-nested-intervals-vs-adjacency-list-comparison

Trees in SQL
 http://www.dbazine.com/oracle/or-articles/tropashko4
 http://www.dbazine.com/oracle/or-articles/tropashko5

Nested Intervals Tree Encoding with Continued Fractions
 http://arxiv.org/pdf/cs.DB/0402051

And here's an example circa 2004 Postgres

There are some other options to consider, though.
 1. You might be using a database that implements Recursive SQL
 2. You might consider something like JCR instead
   here's an example of scaffolding for nodes with scalascii art:
   http://dev.day.com/microsling/content/blogs/main/scalajcr2.html
 3. Why doesn't a template/metadata name without hierarchy work in your example?

Shawn

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Using TemplatePf for JPA powered templates

2008-11-30 Thread Tim Perrett

Hey Viktor,

 If you use Hibernate you could simply configure the L2-cache and have
 Hibernate manage it for you. (EHCache or whatever cache-provider you like)
 This means you won't have to manually use the filesystem and can let the
 cache-provider do what it's good at :)

I tried to implement L2 cache before with lift and didnt get very far
- perhaps i'll give it another go.

My other concern is performance - given a table like:

create table tree_items (
  id int(11) unsigned not null auto_increment,
  parent_id int(11) unsigned,
  name varchar(20),
  other_content varchar(255),
  primary key (id)
);

where parent_id defines the tree structure, im a little worried that
the queries would be come fairly bloated? I also did some looking
around to see if there were any examples online of tree structures in
JPA but alas could not find anything usefull - it appears its quite
problematic...?

Cheers

Tim
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Using TemplatePf for JPA powered templates

2008-11-30 Thread Derek Chen-Becker
If you're heavily skewed towards reads and not writes (as it seems in the
case of a CMS), you might want to look at Celko nested sets:

http://www.intelligententerprise.com/001020/celko.jhtml
http://dev.mysql.com/tech-resources/articles/hierarchical-data.html

A little more work on updates than an adjacency model, but a lot more
efficient.

Derek

On Sun, Nov 30, 2008 at 6:29 AM, Viktor Klang [EMAIL PROTECTED]wrote:

 Hi Tim!

 I'm not sure I follow. What do you need the tree-structure for?

 /Vik

 On Sun, Nov 30, 2008 at 1:11 PM, Tim Perrett [EMAIL PROTECTED] wrote:


 Hey Viktor,

  If you use Hibernate you could simply configure the L2-cache and have
  Hibernate manage it for you. (EHCache or whatever cache-provider you
 like)
  This means you won't have to manually use the filesystem and can let the
  cache-provider do what it's good at :)

 I tried to implement L2 cache before with lift and didnt get very far
 - perhaps i'll give it another go.

 My other concern is performance - given a table like:

 create table tree_items (
  id int(11) unsigned not null auto_increment,
  parent_id int(11) unsigned,
  name varchar(20),
  other_content varchar(255),
  primary key (id)
 );

 where parent_id defines the tree structure, im a little worried that
 the queries would be come fairly bloated? I also did some looking
 around to see if there were any examples online of tree structures in
 JPA but alas could not find anything usefull - it appears its quite
 problematic...?

 Cheers

 Tim




 --
 Viktor Klang
 Senior Systems Analyst

 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Using TemplatePf for JPA powered templates

2008-11-30 Thread Tim Perrett
Hey viktor,

I need the tree structure because it's for this publishing engine I'm  
writing. The idea is that you could create a page, and that page can  
have x number of children, and there children cab have children etc etc

Does that make sense? Perhaps there is a more intuitive way to do this?

Cheers

Tim

Sent from my iPhone

On 30 Nov 2008, at 13:29, Viktor Klang [EMAIL PROTECTED] wrote:

 Hi Tim!

 I'm not sure I follow. What do you need the tree-structure for?

 /Vik

 On Sun, Nov 30, 2008 at 1:11 PM, Tim Perrett [EMAIL PROTECTED]  
 wrote:

 Hey Viktor,

  If you use Hibernate you could simply configure the L2-cache and  
 have
  Hibernate manage it for you. (EHCache or whatever cache-provider  
 you like)
  This means you won't have to manually use the filesystem and can  
 let the
  cache-provider do what it's good at :)

 I tried to implement L2 cache before with lift and didnt get very far
 - perhaps i'll give it another go.

 My other concern is performance - given a table like:

 create table tree_items (
  id int(11) unsigned not null auto_increment,
  parent_id int(11) unsigned,
  name varchar(20),
  other_content varchar(255),
  primary key (id)
 );

 where parent_id defines the tree structure, im a little worried that
 the queries would be come fairly bloated? I also did some looking
 around to see if there were any examples online of tree structures in
 JPA but alas could not find anything usefull - it appears its quite
 problematic...?

 Cheers

 Tim




 -- 
 Viktor Klang
 Senior Systems Analyst

 

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Using TemplatePf for JPA powered templates

2008-11-30 Thread Derek Chen-Becker
IIRC, JPA has support for batch updates, but I'm not 100% positive on that.
I'll have more time tomorrow to look at this if you'd still like to discuss
it.

Derek

On Sun, Nov 30, 2008 at 12:32 PM, Tim Perrett [EMAIL PROTECTED] wrote:


 Derek,

 Those links are *extremely* good - thank you! I've not really done
 anything with tree structures before and they are really, really
 usefull.

 One thing however, it appears the optimal way of  doing the insert
 queries would be with stored procedures, however that im not down
 with, and ideally, i want to keep database vendor independent (part of
 the point of using JPA) so ideally i want to suck that up into the
 application logic. For instance:

 --START
 SELECT @myRight := rgt FROM nested_category WHERE name =
 'TELEVISIONS';

 UPDATE nested_category SET rgt = rgt + 2 WHERE rgt  @myRight;
 UPDATE nested_category SET lft = lft + 2 WHERE lft  @myRight;

 INSERT INTO nested_category(name, lft, rgt) VALUES('GAME CONSOLES',
 @myRight + 1, @myRight + 2);
 --END

 This makes use of variables, and i could of course do this via 3
 separate queries in JPA, but i wondered if there was a neater way to
 construct this type of thing with JPA?

 Any advice you guys have is most welcome

 Cheers

 Tim


 On Nov 30, 2:27 pm, Derek Chen-Becker [EMAIL PROTECTED] wrote:
  If you're heavily skewed towards reads and not writes (as it seems in the
  case of a CMS), you might want to look at Celko nested sets:
 
  http://www.intelligententerprise.com/001020/celko.jhtml
  http://dev.mysql.com/tech-resources/articles/hierarchical-data.html
 
  A little more work on updates than an adjacency model, but a lot more
  efficient.
 
  Derek

 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Using TemplatePf for JPA powered templates

2008-11-30 Thread Tim Perrett
Hey Derek,

I've been playing around with this nested set stuff today - it's  
pretty cool. I nearly have an app working that uses the db for page  
content and maps the urls out however you want, it's pretty neat.

I have a slight HQL problem with subquery's but I'll post that 2mro :-)

Thanks for all your help

Tim

Sent from my iPhone

On 30 Nov 2008, at 23:37, Derek Chen-Becker [EMAIL PROTECTED]  
wrote:

 IIRC, JPA has support for batch updates, but I'm not 100% positive  
 on that. I'll have more time tomorrow to look at this if you'd still  
 like to discuss it.

 Derek

 On Sun, Nov 30, 2008 at 12:32 PM, Tim Perrett [EMAIL PROTECTED]  
 wrote:

 Derek,

 Those links are *extremely* good - thank you! I've not really done
 anything with tree structures before and they are really, really
 usefull.

 One thing however, it appears the optimal way of  doing the insert
 queries would be with stored procedures, however that im not down
 with, and ideally, i want to keep database vendor independent (part of
 the point of using JPA) so ideally i want to suck that up into the
 application logic. For instance:

 --START
 SELECT @myRight := rgt FROM nested_category WHERE name =
 'TELEVISIONS';

 UPDATE nested_category SET rgt = rgt + 2 WHERE rgt  @myRight;
 UPDATE nested_category SET lft = lft + 2 WHERE lft  @myRight;

 INSERT INTO nested_category(name, lft, rgt) VALUES('GAME CONSOLES',
 @myRight + 1, @myRight + 2);
 --END

 This makes use of variables, and i could of course do this via 3
 separate queries in JPA, but i wondered if there was a neater way to
 construct this type of thing with JPA?

 Any advice you guys have is most welcome

 Cheers

 Tim


 On Nov 30, 2:27 pm, Derek Chen-Becker [EMAIL PROTECTED] wrote:
  If you're heavily skewed towards reads and not writes (as it seems  
 in the
  case of a CMS), you might want to look at Celko nested sets:
 
  http://www.intelligententerprise.com/001020/celko.jhtml
  http://dev.mysql.com/tech-resources/articles/hierarchical-data.html
 
  A little more work on updates than an adjacency model, but a lot  
 more
  efficient.
 
  Derek




 

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Using TemplatePf for JPA powered templates

2008-11-30 Thread Charles F. Munat

Doing nested sets in your Lift snippet is pretty easy with JPA. I'm 
doing it on one of my Lift sites. One thing to remember, however, is to 
use a transaction. You don't want to do half the update to the tree and 
then have another use start an update before you've finished yours (or 
have half of it fail). Once it gets messed up it's a disaster.

Nested tables are good when you have lots of lookups, particularly 
pulling ancestors or descendants, but not too many updates. Inserts are 
not too bad, but if you have to move whole subtrees, that's a pain.

I'm using one for, among other things, a forum, so messages once posted 
never get moved. Nested sets work great for that.

But, honestly, it is astonishing to me that Java, Scala, and especially 
JPA/Hibernate apparently have no built in features for creating, 
manipulating, and persisting trees (and networks are even less 
supported). These problems were largely solved long ago. Why aren't they 
built in?

Rails has a cool set of plugins -- acts_as_list, acts_as_tree, and 
acts_as_nested_set -- that make it drop-dead simple to implement trees. 
I was thinking that it would be cool if Lift had something similar but 
maybe as a trait? So my object extends ActsAsNestedSet?

I tried to do this in Hibernate, but it would require the object to 
query for other similar objects. For example, if I had a Node object 
that I was persisting, I'd like to do

class Node extends ActsAsNestedSet

And then define methods such as moveToChildOf(node), moveToFirst, 
moveBack, moveForth, moveToLast, etc. But it appears that you need an 
EntityManager to run a query, and there doesn't seem to be a way to go 
backwards from the Node to the EntityManager (probably because, if I 
understand it correctly, there will only be one copy of a given Node in 
memory but there may be multiple EntityManagers?).

So I put the code in the snippet.

If you come up with any clever solutions, I'd love to hear them.

Chas.

Tim Perrett wrote:
 Hey Derek,
 
 I've been playing around with this nested set stuff today - it's pretty 
 cool. I nearly have an app working that uses the db for page content and 
 maps the urls out however you want, it's pretty neat.
 
 I have a slight HQL problem with subquery's but I'll post that 2mro :-)
 
 Thanks for all your help
 
 Tim
 
 Sent from my iPhone
 
 On 30 Nov 2008, at 23:37, Derek Chen-Becker [EMAIL PROTECTED] 
 mailto:[EMAIL PROTECTED] wrote:
 
 IIRC, JPA has support for batch updates, but I'm not 100% positive on 
 that. I'll have more time tomorrow to look at this if you'd still like 
 to discuss it.

 Derek

 On Sun, Nov 30, 2008 at 12:32 PM, Tim Perrett  
 mailto:[EMAIL PROTECTED][EMAIL PROTECTED] 
 mailto:[EMAIL PROTECTED] wrote:


 Derek,

 Those links are *extremely* good - thank you! I've not really done
 anything with tree structures before and they are really, really
 usefull.

 One thing however, it appears the optimal way of  doing the insert
 queries would be with stored procedures, however that im not down
 with, and ideally, i want to keep database vendor independent (part of
 the point of using JPA) so ideally i want to suck that up into the
 application logic. For instance:

 --START
 SELECT @myRight := rgt FROM nested_category WHERE name =
 'TELEVISIONS';

 UPDATE nested_category SET rgt = rgt + 2 WHERE rgt  @myRight;
 UPDATE nested_category SET lft = lft + 2 WHERE lft  @myRight;

 INSERT INTO nested_category(name, lft, rgt) VALUES('GAME CONSOLES',
 @myRight + 1, @myRight + 2);
 --END

 This makes use of variables, and i could of course do this via 3
 separate queries in JPA, but i wondered if there was a neater way to
 construct this type of thing with JPA?

 Any advice you guys have is most welcome

 Cheers

 Tim


 On Nov 30, 2:27 pm, Derek Chen-Becker [EMAIL PROTECTED]
 mailto:[EMAIL PROTECTED] wrote:
  If you're heavily skewed towards reads and not writes (as it
 seems in the
  case of a CMS), you might want to look at Celko nested sets:
 
 
 
 http://www.intelligententerprise.com/001020/celko.jhtmlhttp://www.intelligententerprise.com/001020/celko.jhtml
 
 
 http://dev.mysql.com/tech-resources/articles/hierarchical-data.htmlhttp://dev.mysql.com/tech-resources/articles/hierarchical-data.html
 
  A little more work on updates than an adjacency model, but a lot
 more
  efficient.
 
  Derek





 
  

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Using TemplatePf for JPA powered templates

2008-11-30 Thread Viktor Klang
On Mon, Dec 1, 2008 at 5:42 AM, Charles F. Munat [EMAIL PROTECTED] wrote:


 Doing nested sets in your Lift snippet is pretty easy with JPA. I'm
 doing it on one of my Lift sites. One thing to remember, however, is to
 use a transaction. You don't want to do half the update to the tree and
 then have another use start an update before you've finished yours (or
 have half of it fail). Once it gets messed up it's a disaster.

 Nested tables are good when you have lots of lookups, particularly
 pulling ancestors or descendants, but not too many updates. Inserts are
 not too bad, but if you have to move whole subtrees, that's a pain.

 I'm using one for, among other things, a forum, so messages once posted
 never get moved. Nested sets work great for that.

 But, honestly, it is astonishing to me that Java, Scala, and especially
 JPA/Hibernate apparently have no built in features for creating,
 manipulating, and persisting trees (and networks are even less
 supported). These problems were largely solved long ago. Why aren't they
 built in?


Charles, I hate to say this, but Hibernate is Open Source, so you can add
the support for it. :)




 Rails has a cool set of plugins -- acts_as_list, acts_as_tree, and
 acts_as_nested_set -- that make it drop-dead simple to implement trees.
 I was thinking that it would be cool if Lift had something similar but
 maybe as a trait? So my object extends ActsAsNestedSet?

 I tried to do this in Hibernate, but it would require the object to
 query for other similar objects. For example, if I had a Node object
 that I was persisting, I'd like to do

 class Node extends ActsAsNestedSet

 And then define methods such as moveToChildOf(node), moveToFirst,
 moveBack, moveForth, moveToLast, etc. But it appears that you need an
 EntityManager to run a query, and there doesn't seem to be a way to go
 backwards from the Node to the EntityManager (probably because, if I
 understand it correctly, there will only be one copy of a given Node in
 memory but there may be multiple EntityManagers?).

 So I put the code in the snippet.

 If you come up with any clever solutions, I'd love to hear them.

 Chas.

 Tim Perrett wrote:
  Hey Derek,
 
  I've been playing around with this nested set stuff today - it's pretty
  cool. I nearly have an app working that uses the db for page content and
  maps the urls out however you want, it's pretty neat.
 
  I have a slight HQL problem with subquery's but I'll post that 2mro :-)
 
  Thanks for all your help
 
  Tim
 
  Sent from my iPhone
 
  On 30 Nov 2008, at 23:37, Derek Chen-Becker [EMAIL PROTECTED]
  mailto:[EMAIL PROTECTED] wrote:
 
  IIRC, JPA has support for batch updates, but I'm not 100% positive on
  that. I'll have more time tomorrow to look at this if you'd still like
  to discuss it.
 
  Derek
 
  On Sun, Nov 30, 2008 at 12:32 PM, Tim Perrett 
  mailto:[EMAIL PROTECTED][EMAIL PROTECTED]
  mailto:[EMAIL PROTECTED] wrote:
 
 
  Derek,
 
  Those links are *extremely* good - thank you! I've not really done
  anything with tree structures before and they are really, really
  usefull.
 
  One thing however, it appears the optimal way of  doing the insert
  queries would be with stored procedures, however that im not down
  with, and ideally, i want to keep database vendor independent (part
 of
  the point of using JPA) so ideally i want to suck that up into the
  application logic. For instance:
 
  --START
  SELECT @myRight := rgt FROM nested_category WHERE name =
  'TELEVISIONS';
 
  UPDATE nested_category SET rgt = rgt + 2 WHERE rgt  @myRight;
  UPDATE nested_category SET lft = lft + 2 WHERE lft  @myRight;
 
  INSERT INTO nested_category(name, lft, rgt) VALUES('GAME CONSOLES',
  @myRight + 1, @myRight + 2);
  --END
 
  This makes use of variables, and i could of course do this via 3
  separate queries in JPA, but i wondered if there was a neater way to
  construct this type of thing with JPA?
 
  Any advice you guys have is most welcome
 
  Cheers
 
  Tim
 
 
  On Nov 30, 2:27 pm, Derek Chen-Becker [EMAIL PROTECTED]
  mailto:[EMAIL PROTECTED] wrote:
   If you're heavily skewed towards reads and not writes (as it
  seems in the
   case of a CMS), you might want to look at Celko nested sets:
  
  
  http://www.intelligententerprise.com/001020/celko.jhtml
 http://www.intelligententerprise.com/001020/celko.jhtml
  
  
 http://dev.mysql.com/tech-resources/articles/hierarchical-data.html
 http://dev.mysql.com/tech-resources/articles/hierarchical-data.html
  
   A little more work on updates than an adjacency model, but a lot
  more
   efficient.
  
   Derek
 
 
 
 
 
 
  

 



-- 
Viktor Klang
Senior Systems Analyst

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to 

[Lift] Re: Using TemplatePf for JPA powered templates

2008-11-29 Thread Tim Perrett

I've been playing around with this and extending the template loader
is actually pretty easy. Its much simpler than I thought it would be!

I have a dilemma however - store the templates (and associated meta
data) in the database and then have to do a fetch / read on every
request, or, use the file system and hold (for instance):

example.html
and
example.meta // java properties file format

The tree structure of the file system is the path of least resistance
for my particular use case i think, but i guess im after some input /
advice...? I feel as either way has a couple of hang-ups! The kind of
meta data is just simple key-value pair stuff, but my plan would be to
extend Record so that the save() etc became transparent and was
abstracted away (i.e. don't need to worry about InputStreams etc)

Appreciate any input / advice people have

Cheers

Tim

On Nov 29, 2:31 pm, Derek Chen-Becker [EMAIL PROTECTED] wrote:
 Looking at findVisibleTemplate in LiftSession (line 512) certainly makes it
 appear that the template table defined by addTemplateBefore/After is
 consulted before it checks the filesystem.

 Derek

 On Fri, Nov 28, 2008 at 10:26 AM, Tim Perrett [EMAIL PROTECTED] wrote:

  Hey guys,

  I want to user lifts LiftRules.addTemplateBefore/After to load
  templates from a database, where my persistence is JPA.

  With TemplatePf can I do this? Im also thinking this will be one of
  the nice things about having lift tags, as it will mean i shouldn't
  need to build a custom tagging language or anything (as we already
  have it!). I presume that TemplatePf just tells lift where to get the
  XHTML from then it continues to do the processing on it (process
  snippets etc)?

  Cheers

  Tim
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Using TemplatePf for JPA powered templates

2008-11-29 Thread Viktor Klang
If you use Hibernate you could simply configure the L2-cache and have
Hibernate manage it for you. (EHCache or whatever cache-provider you like)
This means you won't have to manually use the filesystem and can let the
cache-provider do what it's good at :)

Cheers,
Viktor

On Sun, Nov 30, 2008 at 3:25 AM, Tim Perrett [EMAIL PROTECTED] wrote:


 I've been playing around with this and extending the template loader
 is actually pretty easy. Its much simpler than I thought it would be!

 I have a dilemma however - store the templates (and associated meta
 data) in the database and then have to do a fetch / read on every
 request, or, use the file system and hold (for instance):

 example.html
 and
 example.meta // java properties file format

 The tree structure of the file system is the path of least resistance
 for my particular use case i think, but i guess im after some input /
 advice...? I feel as either way has a couple of hang-ups! The kind of
 meta data is just simple key-value pair stuff, but my plan would be to
 extend Record so that the save() etc became transparent and was
 abstracted away (i.e. don't need to worry about InputStreams etc)

 Appreciate any input / advice people have

 Cheers

 Tim

 On Nov 29, 2:31 pm, Derek Chen-Becker [EMAIL PROTECTED] wrote:
  Looking at findVisibleTemplate in LiftSession (line 512) certainly makes
 it
  appear that the template table defined by addTemplateBefore/After is
  consulted before it checks the filesystem.
 
  Derek
 
  On Fri, Nov 28, 2008 at 10:26 AM, Tim Perrett [EMAIL PROTECTED]
 wrote:
 
   Hey guys,
 
   I want to user lifts LiftRules.addTemplateBefore/After to load
   templates from a database, where my persistence is JPA.
 
   With TemplatePf can I do this? Im also thinking this will be one of
   the nice things about having lift tags, as it will mean i shouldn't
   need to build a custom tagging language or anything (as we already
   have it!). I presume that TemplatePf just tells lift where to get the
   XHTML from then it continues to do the processing on it (process
   snippets etc)?
 
   Cheers
 
   Tim
 



-- 
Viktor Klang
Senior Systems Analyst

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---