greatfooty wrote:
> 
> Thanks Patrick a solution like that would be ideal and very clean but for
> these apps the hosting provider is restricting access to just one mysql
> database (without a big hike in rates). I'm no mysql guru but fairly sure
> in mysql "database" equates to "schema". 
> 
Ok, I see.
As far as I know it is not possible to define values of @Table annotations
in runtime (from configuration). Sculptor could generate them with different
names at build time, but they must be located in the concrete entity not in
the re-generated subclass, so that is not an option (when using gap
classes).

It is possible to define hibernate mapping in hbm xml files, and sculptor
can generate that, but it doesn't feel attractive.


greatfooty wrote:
> 
> Thats why i'd originally thought to try having common tables shared by the
> webapps (with each table including a differentiating column eg. context)
> .. until i realised that would need a swag of customisation after sculptor
> generation etc etc
> 

Do you really need a lot of customization for that solution? findById, save,
delete should be ok without change. Maybe you need something to verify that
apps doesn't see/modify each others data. Can be solved with an interceptor.

findAll need a small adjustment. I would replace the findAll access object,
as described in 
http://fornax.itemis.de/confluence/display/fornax/7.+Developer%27s+Guide+%28CSC%29#7.Developer%27sGuide%28CSC%29-GenericAccessObjects
Dev Guide .

sculptor-generator.properties:
framework.accessimpl.FindAllAccessImpl=org.mypkg.accessimpl.MyFindAllAccessImpl

MyFindAllAccessImpl would be something like this:

public class MyFindAllAccessImpl<T> extends JpaHibFindAllAccessImpl<T> {

    public MyFindAllAccessImpl(Class<T> persistentClass) {
        super(persistentClass);
    }

    @Override
    protected List<T> executeQuery(String queryStr) {
        String appId = ServiceContextStore.get().getApplicationId();
        String where = " where e.context = '" + appId + "' ";

        String modifiedQueryStr;
        if (queryStr.contains("order by")) {
            modifiedQueryStr = queryStr.replace("order by", where + "order
by");
        } else {
            modifiedQueryStr = queryStr + where;
        }

        return super.executeQuery(modifiedQueryStr);
    }

}


Note how I use ServiceContext to pass the context parameter.

By the way, context attribute can be set automatically in entities using
@PrePersist method, so that the clients doesn't have to care about it.


greatfooty wrote:
> 
> Note though I still may be able to negotiate having multiple mysql dbs
> (its unlikely but worth another try) - so when you say customise the
> datasource do you mean in such a way that it would have appropriate
> generated generically into the datasource (somehow based on the webapp
> context) - or are you meaning a solution that involves inclusion of a
> hand-coded datasource into each webapp?
> 
I'm not sure exactly which way is best, but I'm sure that it can be solved.
Let me know if you get approval for that solution and need help customizing
the datasource. 

-- 
View this message in context: 
http://old.nabble.com/-Sculptor--Injecting-tablenames-from-web-tier--tp27195699s17564p27201974.html
Sent from the Fornax-Platform mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
Fornax-developer mailing list
Fornax-developer@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fornax-developer

Reply via email to