How to use different stores in different webapps

0 views
Skip to first unread message

Andrea Russo

unread,
Mar 19, 2009, 8:53:36 AM3/19/09
to webl...@googlegroups.com
Hi,

I'm trying to write my first web application using weblocks slowly
trying to break the ice with this magical framework.

I'm really a common lisp newbie, so sorry if my questions are too lame
:-)

Trying to learn from the examples, I'm often bitten from strange
problems regarding the persistence layer.

In particular, I loaded the simple-blog demo, the weblocks-elephant-demo
and an home made webapp which uses also the elephant persistence layer.

When I run these webapps isolated, all works like a charm, but when
starting them together it seems that they end up using the same
persistence store, instead of using the stores defined in their own
package.

I'm using weblocks-stable with sbcl 1.0.26.1 from clbuild with cffi and
uffi installed through asdf-install to make the elephant layer works.

So, my question is: how can I use multiple elephant storage in my
weblocks applications?

Any help would be much appreciated.

TIA,
Andrea.

--
Reclama i tuoi diritti digitali, elimina il DRM. Approfondisci su
http://www.no1984.org
Reclaim your digital rights, eliminate DRM. Learn more at
http://www.defectivebydesign.org/what_is_drm

Vyacheslav Akhmechet

unread,
Mar 19, 2009, 9:26:57 AM3/19/09
to webl...@googlegroups.com
If you set up *my-store* you can access it from all running
applications. The sample apps you're talking about probably fail
because they were copy pasted, so they use the same store name. If you
want different applications to use different stores, simply use
different store names (e.g. *my-store1*, *my-store2*, etc.) and you'll
be fine.

Ian Eslick

unread,
Mar 19, 2009, 9:53:21 AM3/19/09
to webl...@googlegroups.com
Another possible problem is that many of the Elephant operators (get-
instances-by-name) are independent of Weblocks and rely on a common
global variable, *store-controller*. To make things more fun,
weblocks also uses a default store reference *default-store* The
first store opened becomes *store-controller* and any subsequent
operations go there. If you want to have multiple controllers for
multiple applications, you have to be explicit about using your
weblocks store for the weblocks API functions, and the Elephant store
if you are using Elephant's native functions.

However, after you wrap up store accesses in webapp specific
functions, then you shouldn't have to think about this much. This
macro might be helpful.

(defmacro with-ele-store ((wl-store) &body body)
`(let ((*default-store* wl-store)
(*store-controller* (elephant-controller ,wl-store)))
(declare (special *store-controller* *default-store*))
,@body))

(defun get-person (name)
(with-ele-store (*webapp-store1*)
(get-instance-by-value 'person 'name name)))


Ian

Vyacheslav Akhmechet

unread,
Mar 19, 2009, 10:41:15 AM3/19/09
to webl...@googlegroups.com
On Thu, Mar 19, 2009 at 9:53 AM, Ian Eslick <esl...@media.mit.edu> wrote:
> To make things more fun, weblocks also uses a default store
> reference *default-store*
I think this was removed when support for multiple applications was
added (at least it's removed in my branch, perhaps it was added back
at some point).

Ian Eslick

unread,
Mar 19, 2009, 11:07:55 AM3/19/09
to webl...@googlegroups.com
I'm still doing most of my work on an old image and haven't spent much
time yet porting to the latest weblocks-dev so my knowledge may be out
of date. The Elephant *store-controller* assumption is still baked
in, however.

Ian

Andrea Russo

unread,
Mar 20, 2009, 6:32:11 AM3/20/09
to webl...@googlegroups.com
Ian Eslick <esl...@media.mit.edu> writes:

> However, after you wrap up store accesses in webapp specific
> functions, then you shouldn't have to think about this much. This
> macro might be helpful.

[...]

>
> Ian

Thank you very much for these suggestions. Changing name of the store
variables didn't worked out, so I'll try with your approach.

Thanks again,

Andrea Russo

unread,
Mar 20, 2009, 10:07:18 AM3/20/09
to webl...@googlegroups.com
Vyacheslav Akhmechet <coff...@gmail.com>
writes:

I've tried that but it seems that, at least with the elephant store,
different webapps ends up using the same store.

Many thanks for your help,

Stephen Compall

unread,
Apr 7, 2009, 3:46:15 PM4/7/09
to webl...@googlegroups.com
Andrea Russo <rastandy-CuI0ZD...@public.gmane.org> writes:
> Thank you very much for these suggestions. Changing name of the store
> variables didn't worked out, so I'll try with your approach.

It is easiest to do this with an :around-method on
handle-client-request. Search the group for my past messages on this
(with regard to CLSQL).

--
Sorry but you say Nibiru is a Hoax? Doesnt Exist? So maybe The
Sumerian people doesnt exist also! --Anonymous by way of SkI

Antoine Tremblay

unread,
Apr 7, 2009, 4:50:48 PM4/7/09
to webl...@googlegroups.com
I searched for the post you mentioned found it as :

http://groups.google.com/group/weblocks/msg/91bc34d5cf198f0c

Just so that others don't have to search too much :)

Stephen Compall

unread,
Apr 8, 2009, 11:07:07 PM4/8/09
to webl...@googlegroups.com
Antoine Tremblay <hexa00-Re5JQEe...@public.gmane.org> writes:
> I searched for the post you mentioned found it as :
>
> http://groups.google.com/group/weblocks/msg/91bc34d5cf198f0c
>
> Just so that others don't have to search too much :)

Unfortunately, this post lies at the same level as that post, so if/when
it comes up again, whoever asks will have to search again, or someone
will make a post like the one to which I reply...

It would not behoove us to document the ability to create around-methods
for this purpose in the HCR docstring; this is implicit in CLOS. It is
a mere matter of mentally adding this CLOS feature with that knowledge
of the (documented) Weblocks API.

Leslie P. Polzer

unread,
Apr 9, 2009, 2:51:04 AM4/9/09
to webl...@googlegroups.com
On Wed, Apr 08, 2009 at 10:07:07PM -0500, Stephen Compall wrote:

> It would not behoove us to document the ability to create around-methods
> for this purpose in the HCR docstring; this is implicit in CLOS. It is
> a mere matter of mentally adding this CLOS feature with that knowledge
> of the (documented) Weblocks API.

I usually hint at that possibility in docstrings by writing
"Create an :AROUND method for METHOD in order to ..."

Andrea Russo

unread,
Apr 9, 2009, 12:13:46 PM4/9/09
to webl...@googlegroups.com
Stephen Compall <s...@member.fsf.org> writes:

> It is easiest to do this with an :around-method on
> handle-client-request. Search the group for my past messages on this
> (with regard to CLSQL).

This works great, thanks.

Stephen Compall

unread,
Apr 24, 2009, 5:43:51 AM4/24/09
to webl...@googlegroups.com
d11705372f3a, just added to dev, is of interest for this. Essentially,
in the file

(in-package a)
(defwebapp app-a)
(defstore *store-a*)

(in-package b)
(defwebapp app-b)
(defstore *store-b*)

When an app-a request is running, *default-store*=*store-a*, and similar
for app-b requests with *store-b*. More details in `*default-store*'
docstring and new defwebapp :default-store initarg.

Reply all
Reply to author
Forward
0 new messages