cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Evgeny Ryabitskiy (JIRA)" <j...@apache.org>
Subject [jira] Commented: (CAY-1287) SQLTemplate for not-mapping (DataRow) queries
Date Fri, 02 Oct 2009 10:25:23 GMT

    [ https://issues.apache.org/jira/browse/CAY-1287?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12761521#action_12761521
] 

Evgeny Ryabitskiy commented on CAY-1287:
----------------------------------------

Ah yeah... I found way to run SQLTemplate from runtime without objectMapping! wow... It was
not easy... really...

But I don't see why we need a DomainMap? We could pass DataNode  and it should be enough...
maybe we can create constructor like:
SQLTemplate(DataNode dataNode, String defaultTemplate) 
and few more things... why we need queryWithParameters...

Now to run code SQLTemplate I should write follow code:

String sql = "SELECT * FROM PersonTable WHERE Name = #bind($Name)";
Configuration config = Configuration.getSharedConfiguration();
DataDomain domain = config.getDomain();
DataMap anyDataMap = (DataMap) domain.getNode("MyNode").getDataMaps().iterator().next();
SQLTemplate query = new SQLTemplate(anyDataMap , sql);
Map parameters = new HashMap();
parameters.put("Name", "Eugene");
SQLTemplate newQuery = query.queryWithParameters(parameters);
List rowList = ctx.performQuery(newQuery);

It's huge and contains lot's of redundant operations... And it's hard to find this solution!
We should add it to user guide....
We can do some Improvement to white this code:

String sql = "SELECT * FROM PersonTable WHERE Name = #bind($Name)";
Configuration config = Configuration.getSharedConfiguration();
DataDomain domain = config.getDomain();
Map parameters = new HashMap();
parameters.put("Name", "Eugene");
//here is new constructor: SQLTemplate(DataNode dataNode, String defaultTemplate, Map parameters)
SQLTemplate query = new SQLTemplate(domain.getNode("MyNode"), sql, parameters);  
List rowList = ctx.performQuery(newQuery);
	
It's more intuitive thing and doesn't requires redundant things!

Or I have alternative solution to make this code executable:

String sql = "SELECT * FROM PersonTable WHERE Name = #bind($Name)";
Configuration config = Configuration.getSharedConfiguration();
DataDomain domain = config.getDomain();
Map parameters = new HashMap();
parameters.put("Name", "Eugene");
//here is new constructor: SQLTemplate(DataNode dataNode, String defaultTemplate)
SQLTemplate query = new SQLTemplate(domain.getNode("MyNode"), sql, parameters);  
// pass parameters while performQuery to every query (not only while performing NamedQuery)
List rowList = ctx.performQuery(newQuery, parameters);

Also more comfortable thing... 

> SQLTemplate for not-mapping (DataRow) queries
> ---------------------------------------------
>
>                 Key: CAY-1287
>                 URL: https://issues.apache.org/jira/browse/CAY-1287
>             Project: Cayenne
>          Issue Type: New Feature
>          Components: Cayenne Core Library
>    Affects Versions: 2.0 branch
>            Reporter: Evgeny Ryabitskiy
>             Fix For: 3.0
>
>
> I wish to use nice SQLTemplate scripting engine for my simple not-mapping (DataRow) runtime-formed
queries.
> But now I should pass a DataObject to SQLTemplate constructor.
> The question is: "For what?"
> To do mapping???
> If my query is like: "SELECT max(id) as MAX_ID from Table1" it has no sense!
> I want to add constructor like: SQLTemplate(String defaultTemplate, Map parameter)
> and teach DataContext to perform such queries well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message