cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r733790 - in /cayenne/main/trunk/framework: cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/ cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/...
Date Mon, 12 Jan 2009 15:35:13 GMT
Author: aadamchik
Date: Mon Jan 12 07:34:46 2009
New Revision: 733790

URL: http://svn.apache.org/viewvc?rev=733790&view=rev
Log:
CAY-1164 Implement EJBQL query support in the Modeler

a working implementation of EJBQL editor submitted by Olga Tkachova.
- page size is disabled until it will become supported by the backend
- some visual glitches still exist

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EjbqlBuilder.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryMainTab.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryPropertiesPanel.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlTabbedView.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/QueryLoader.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/EJBQLQuery.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/MapLoaderLoadTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/EJBQLQueryTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeController.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeDialog.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeModel.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EditorView.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateScriptsTab.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectPropertiesPanel.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ProjectUtil.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/resources/org/apache/cayenne/modeler/cayennemodeler-strings.properties

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EjbqlBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EjbqlBuilder.java?rev=733790&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EjbqlBuilder.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EjbqlBuilder.java Mon Jan 12 07:34:46 2009
@@ -0,0 +1,35 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.map;
+
+import org.apache.cayenne.query.EJBQLQuery;
+import org.apache.cayenne.query.Query;
+
+
+public class EjbqlBuilder extends QueryLoader{
+
+    @Override
+    Query getQuery() {
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+        query.setName(name);    
+        query.initWithProperties(properties);
+        return query;
+    }
+
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java?rev=733790&r1=733789&r2=733790&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java Mon Jan 12 07:34:46 2009
@@ -100,7 +100,8 @@
     // Query-related
     public static final String QUERY_TAG = "query";
 
-    public static final String QUERY_SQL_TAG = "sql";
+    public static final String QUERY_SQL_TAG = "sql";    
+    public static final String QUERY_EJBQL_TAG = "ejbql";
     public static final String QUERY_QUALIFIER_TAG = "qualifier";
     public static final String QUERY_ORDERING_TAG = "ordering";
     public static final String QUERY_PREFETCH_TAG = "prefetch";
@@ -151,6 +152,7 @@
     private Procedure procedure;
     private QueryLoader queryBuilder;
     private String sqlKey;
+    private String ejbqlKey;    
     private String descending;
     private String ignoreCase;
 
@@ -283,6 +285,15 @@
             void execute(Attributes attributes) throws SAXException {
                 processStartProcedure(attributes);
             }
+        });        
+       
+        startTagOpMap.put(QUERY_EJBQL_TAG, new StartClosure() {
+
+            @Override
+            void execute(Attributes attributes) throws SAXException {
+                charactersBuffer = new StringBuilder();
+                processStartEjbqlQuery(attributes);
+            }
         });
 
         startTagOpMap.put(QUERY_TAG, new StartClosure() {
@@ -518,6 +529,16 @@
                 processEndQuerySQL();
             }
         });
+        
+       ////////////////////////////////////////// 
+        endTagOpMap.put(QUERY_EJBQL_TAG, new EndClosure() {
+
+            @Override
+            void execute() throws SAXException {
+                processEndEjbqlQuery();
+            }
+        });
+        
         endTagOpMap.put(QUERY_QUALIFIER_TAG, new EndClosure() {
 
             @Override
@@ -873,6 +894,12 @@
     private void processStartQuerySQL(Attributes atts) {
         this.sqlKey = convertClassNameFromV1_2(atts.getValue("", "adapter-class"));
     }
+    
+    ///////////////////////////////
+    private void processStartEjbqlQuery(Attributes atts) throws SAXException {
+        this.ejbqlKey = convertClassNameFromV1_2(atts.getValue("", "adapter-class"));
+    }
+    
 
     private void processStartObjEntity(Attributes atts) {
         objEntity = new ObjEntity(atts.getValue("", "name"));
@@ -1061,6 +1088,8 @@
         dataMap.addProcedure(procedure);
     }
 
+  
+    
     private void processStartProcedureParameter(Attributes attributes)
             throws SAXException {
 
@@ -1196,6 +1225,13 @@
         queryBuilder = null;
     }
 
+    ///////////////////////////////////////////////
+
+    private void processEndEjbqlQuery() throws SAXException {
+        queryBuilder.setEjbql(charactersBuffer.toString());
+        ejbqlKey = null;
+    }
+    
     private void processEndQuerySQL() {
         queryBuilder.addSql(charactersBuffer.toString(), sqlKey);
         sqlKey = null;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/QueryLoader.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/QueryLoader.java?rev=733790&r1=733789&r2=733790&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/QueryLoader.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/QueryLoader.java Mon Jan 12 07:34:46 2009
@@ -41,6 +41,7 @@
     protected String name;
     protected Map<String, String> properties;
     protected String sql;
+    protected String ejbql;
     protected Map<String, String> adapterSql;
     protected Expression qualifier;
     protected List<Ordering> orderings;
@@ -105,6 +106,11 @@
         this.rootName = rootName;
     }
 
+    void setEjbql(String ejbql) {        
+            this.ejbql = ejbql;
+    }
+
+    
     /**
      * Adds raw sql. If adapterClass parameter is not null, sets the SQL string to be
      * adapter-specific. Otherwise it is used as a default SQL string.

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/EJBQLQuery.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/EJBQLQuery.java?rev=733790&r1=733789&r2=733790&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/EJBQLQuery.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/EJBQLQuery.java Mon Jan 12 07:34:46 2009
@@ -28,13 +28,15 @@
 import org.apache.cayenne.ejbql.EJBQLParserFactory;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.util.XMLEncoder;
+import org.apache.cayenne.util.XMLSerializable;
 
 /**
  * An EJBQL query representation in Cayenne.
  * 
  * @since 3.0
  */
-public class EJBQLQuery implements Query {
+public class EJBQLQuery implements Query, XMLSerializable {
 
     protected String name;
     protected String ejbqlStatement;
@@ -48,6 +50,18 @@
         this.ejbqlStatement = ejbqlStatement;
     }
 
+    public EJBQLQuery() {
+    }
+    
+    public void initWithProperties(Map<String, ?> properties) {
+
+        // must init defaults even if properties are empty
+        if (properties == null) {
+            properties = Collections.EMPTY_MAP;
+        }
+        metadata.initWithProperties(properties);
+    }
+
     public QueryMetadata getMetaData(EntityResolver resolver) {
         metadata.resolve(resolver, this);
         return metadata;
@@ -78,11 +92,7 @@
     public void setCacheStrategy(QueryCacheStrategy strategy) {
         metadata.setCacheStrategy(strategy);
     }
-    
-
-
-
-
+  
     public void route(QueryRouter router, EntityResolver resolver, Query substitutedQuery) {
         DataMap map = getMetaData(resolver).getDataMap();
 
@@ -208,4 +218,32 @@
     public void setFetchOffset(int fetchOffset) {
         metadata.setFetchOffset(fetchOffset);
     }
+
+    public void encodeAsXML(XMLEncoder encoder) {
+        encoder.print("<query name=\"");
+        encoder.print(getName());
+        encoder.print("\" factory=\"");
+        encoder.print("org.apache.cayenne.map.EjbqlBuilder");
+
+        encoder.println("\">");
+
+        encoder.indent(1);
+        
+        metadata.encodeAsXML(encoder);
+       
+        if (ejbqlStatement != null) {
+            encoder.print("<ejbql><![CDATA[");
+            encoder.print(ejbqlStatement);
+            encoder.println("]]></ejbql>");
+        }
+        
+        encoder.indent(-1);
+        encoder.println("</query>");        
+    }
+
+    public void setEjbqlStatement(String text) {
+        this.ejbqlStatement = text;
+    }
+    
+ 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/MapLoaderLoadTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/MapLoaderLoadTest.java?rev=733790&r1=733789&r2=733790&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/MapLoaderLoadTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/MapLoaderLoadTest.java Mon Jan 12 07:34:46 2009
@@ -29,6 +29,7 @@
 
 import org.apache.art.Artist;
 import org.apache.art.Gallery;
+import org.apache.cayenne.query.EJBQLQuery;
 import org.apache.cayenne.query.Ordering;
 import org.apache.cayenne.query.SQLTemplate;
 import org.apache.cayenne.query.SelectQuery;
@@ -159,7 +160,12 @@
         SQLTemplate nonSelectingQuery = (SQLTemplate) map.getQuery("NonSelectingQuery");
         assertNotNull(nonSelectingQuery);
         assertEquals("NonSelectingQuery", nonSelectingQuery.getName());
-        
         assertEquals(SQLTemplate.UPPERCASE_COLUMN_NAMES, nonSelectingQuery.getColumnNamesCapitalization());
+        
+        EJBQLQuery ejbqlQueryTest = (EJBQLQuery) map.getQuery("EjbqlQueryTest");      
+        assertNotNull(ejbqlQueryTest);
+        assertEquals("EjbqlQueryTest", ejbqlQueryTest.getName());
+        assertNotNull(ejbqlQueryTest.getEjbqlStatement());        
+        assertEquals("SHARED_CACHE", ejbqlQueryTest.getCacheStrategy().toString());       
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/EJBQLQueryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/EJBQLQueryTest.java?rev=733790&r1=733789&r2=733790&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/EJBQLQueryTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/EJBQLQueryTest.java Mon Jan 12 07:34:46 2009
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.cayenne.query;
 
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.util.List;
 import java.util.Map;
 
@@ -27,6 +29,7 @@
 import org.apache.cayenne.ejbql.EJBQLCompiledExpression;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.util.XMLEncoder;
 
 public class EJBQLQueryTest extends CayenneCase {
 
@@ -166,4 +169,34 @@
         assertTrue(md.isResolvingInherited());
         assertEquals(QueryCacheStrategy.NO_CACHE, md.getCacheStrategy());
     }
+    
+    public void testEncodeAsXML() {
+        
+        String ejbql = "select a FROM Artist a";
+        String name = "Test";
+        
+        StringWriter w = new StringWriter();
+        XMLEncoder e = new XMLEncoder(new PrintWriter(w));
+        
+        StringBuffer s = new StringBuffer("<query name=\"");
+        s.append(name);
+        s.append("\" factory=\"");
+        s.append("org.apache.cayenne.map.EjbqlBuilder");
+        s.append("\">");
+        s.append("\n");
+      
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+        
+        if (query.getEjbqlStatement() != null) {
+            s.append("<ejbql><![CDATA[");
+            s.append(query.getEjbqlStatement());
+            s.append("]]></ejbql>");
+        }
+        s.append("\n");
+        s.append("</query>");     
+        s.append("\n");
+        query.setName(name);
+        query.encodeAsXML(e);       
+        assertTrue(w.getBuffer().toString().equals(s.toString()));
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml?rev=733790&r1=733789&r2=733790&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml Mon Jan 12 07:34:46 2009
@@ -632,6 +632,11 @@
 		<property name="cayenne.SQLTemplate.columnNameCapitalization" value="upper"/>
 		<sql><![CDATA[select * from ARTIST]]></sql>
 	</query>
+	<query name="EjbqlQueryTest" factory="org.apache.cayenne.map.EjbqlBuilder">	
+		<property name="cayenne.GenericSelectQuery.cacheStrategy" value="SHARED_CACHE"/>		
+		<property name="cayenne.GenericSelectQuery.fetchingDataRows" value="true"/>
+		<ejbql><![CDATA[select * from ejbql]]></ejbql>
+	</query>
 	<entity-listener class="org.apache.art.EntityListenerDataMap">
 		<pre-persist method-name="prePersistDataMap1"/>
 		<pre-persist method-name="prePersistDataMap2"/>

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeController.java?rev=733790&r1=733789&r2=733790&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeController.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeController.java Mon Jan 12 07:34:46 2009
@@ -27,6 +27,7 @@
 import org.apache.cayenne.modeler.event.QueryDisplayEvent;
 import org.apache.cayenne.project.NamedObjectFactory;
 import org.apache.cayenne.query.AbstractQuery;
+import org.apache.cayenne.query.EJBQLQuery;
 import org.apache.cayenne.query.Query;
 import org.scopemvc.controller.basic.BasicController;
 import org.scopemvc.core.Control;
@@ -42,7 +43,8 @@
     public static final String CREATE_CONTROL = "cayenne.modeler.queryType.create.button";
     public static final String OBJECT_QUERY_CONTROL = "cayenne.modeler.queryType.selectQuery.radio";
     public static final String SQL_QUERY_CONTROL = "cayenne.modeler.queryType.sqlQuery.radio";
-    public static final String PROCEDURE_QUERY_CONTROL = "cayenne.modeler.queryType.procedureQuery.radio";
+    public static final String PROCEDURE_QUERY_CONTROL = "cayenne.modeler.queryType.procedureQuery.radio";    
+    public static final String EJBQL_QUERY_CONTROL = "cayenne.modeler.queryType.ejbqlQuery.radio";
 
     protected ProjectController mediator;
     protected DataMap dataMap;
@@ -72,6 +74,9 @@
         else if (control.matchesID(PROCEDURE_QUERY_CONTROL)) {
             // do nothing... need to match control
         }
+         else if (control.matchesID(EJBQL_QUERY_CONTROL)) {
+            // do nothing... need to match control            
+        }
     }
 
     /**
@@ -89,7 +94,8 @@
      */
     public void createQuery() {
         QueryTypeModel model = (QueryTypeModel) getModel();
-        AbstractQuery query = model.getSelectedQuery();
+        
+        Query query = model.getSelectedQuery();
         if (query == null) {
             // wha?
             return;
@@ -97,7 +103,11 @@
 
         // update query...
         String queryName = NamedObjectFactory.createName(Query.class, dataMap);
-        query.setName(queryName);
+        if(query instanceof EJBQLQuery) {
+            ((EJBQLQuery)query).setName(queryName);
+        } else {
+            ((AbstractQuery)query).setName(queryName);
+        }
         dataMap.addQuery(query);
 
         // notify listeners

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeDialog.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeDialog.java?rev=733790&r1=733789&r2=733790&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeDialog.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeDialog.java Mon Jan 12 07:34:46 2009
@@ -40,47 +40,55 @@
  * 
  */
 public class QueryTypeDialog extends SPanel {
-
-    public QueryTypeDialog() {
+    
+     public QueryTypeDialog() {
         initView();
     }
 
     private void initView() {
         // create widgets
-        ButtonGroup buttonGroup = new ButtonGroup();
-        SRadioButton objectSelect = new SRadioButton(
+     ButtonGroup buttonGroup = new ButtonGroup();
+       
+     SRadioButton objectSelect = new SRadioButton(
                 QueryTypeController.OBJECT_QUERY_CONTROL,
                 QueryTypeModel.OBJECT_SELECT_QUERY_SELECTOR);
+        
+      SRadioButton sqlSelect = new SRadioButton(
+      QueryTypeController.SQL_QUERY_CONTROL,
+      QueryTypeModel.RAW_SQL_QUERY_SELECTOR);
+        
+      SRadioButton procedureSelect = new SRadioButton(
+      QueryTypeController.PROCEDURE_QUERY_CONTROL,
+      QueryTypeModel.PROCEDURE_QUERY_SELECTOR);
+        
+      SRadioButton ejbqlSelect = new SRadioButton(
+              QueryTypeController.EJBQL_QUERY_CONTROL,
+              QueryTypeModel.EJBQL_QUERY_SELECTOR);
+      
         buttonGroup.add(objectSelect);
-
-        SRadioButton sqlSelect = new SRadioButton(
-                QueryTypeController.SQL_QUERY_CONTROL,
-                QueryTypeModel.RAW_SQL_QUERY_SELECTOR);
         buttonGroup.add(sqlSelect);
-
-        SRadioButton procedureSelect = new SRadioButton(
-                QueryTypeController.PROCEDURE_QUERY_CONTROL,
-                QueryTypeModel.PROCEDURE_QUERY_SELECTOR);
         buttonGroup.add(procedureSelect);
-
+        buttonGroup.add(ejbqlSelect);
+       
         SButton saveButton = new SButton(new SAction(QueryTypeController.CREATE_CONTROL));
         saveButton.setEnabled(true);
 
         SButton cancelButton = new SButton(
                 new SAction(QueryTypeController.CANCEL_CONTROL));
         cancelButton.setEnabled(true);
-
+ 
         // assemble
         CellConstraints cc = new CellConstraints();
         FormLayout layout = new FormLayout(
                 "left:max(180dlu;pref)",
-                "p, 3dlu, p, 3dlu, p, 3dlu");
+                "p, 4dlu, p, 4dlu, p, 4dlu, p, 4dlu");
         PanelBuilder builder = new PanelBuilder(layout);
         builder.setDefaultDialogBorder();
 
         builder.add(objectSelect, cc.xy(1, 1));
         builder.add(sqlSelect, cc.xy(1, 3));
         builder.add(procedureSelect, cc.xy(1, 5));
+        builder.add(ejbqlSelect, cc.xy(1, 7));
 
         setLayout(new BorderLayout());
         add(builder.getPanel(), BorderLayout.CENTER);
@@ -94,3 +102,5 @@
         setTitle("Select New Query Type");
     }
 }
+
+

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeModel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeModel.java?rev=733790&r1=733789&r2=733790&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeModel.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeModel.java Mon Jan 12 07:34:46 2009
@@ -22,7 +22,9 @@
 
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.query.AbstractQuery;
+import org.apache.cayenne.query.EJBQLQuery;
 import org.apache.cayenne.query.ProcedureQuery;
+import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.SQLTemplate;
 import org.apache.cayenne.query.SelectQuery;
 import org.scopemvc.core.Selector;
@@ -37,13 +39,16 @@
             .fromString("rawSQLQuery");
     public static final Selector PROCEDURE_QUERY_SELECTOR = Selector
             .fromString("procedureQuery");
-
+    public static final Selector EJBQL_QUERY_SELECTOR = Selector
+    .fromString("ejbqlQuery");
+ 
     // query prototypes...
     protected AbstractQuery objectSelectQuery;
     protected AbstractQuery rawSQLQuery;
     protected AbstractQuery procedureQuery;
+    protected EJBQLQuery ejbqlQuery;
 
-    protected AbstractQuery selectedQuery;
+    protected Query selectedQuery;
 
     public QueryTypeModel(DataMap root) {
         // create query prototypes:
@@ -54,12 +59,13 @@
         rawSQLQuery.setRoot(root);
         rawSQLQuery.setFetchingDataRows(true);
         this.rawSQLQuery = rawSQLQuery;
-
+        
+        ejbqlQuery = new EJBQLQuery();
         // by default use object query...
         selectedQuery = objectSelectQuery;
     }
 
-    public AbstractQuery getSelectedQuery() {
+    public Query getSelectedQuery() {
         return selectedQuery;
     }
 
@@ -105,4 +111,17 @@
             selectedQuery = procedureQuery;
         }
     }
+    
+    public boolean isEjbqlQuery() {
+        return selectedQuery == ejbqlQuery;
+    }
+
+    public void setEjbqlQuery(boolean flag) {
+        if (!flag && isEjbqlQuery()) {
+            selectedQuery = null;
+        }
+        else if (flag && !isEjbqlQuery()) {
+            selectedQuery = ejbqlQuery;
+        }
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EditorView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EditorView.java?rev=733790&r1=733789&r2=733790&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EditorView.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EditorView.java Mon Jan 12 07:34:46 2009
@@ -50,6 +50,7 @@
 import org.apache.cayenne.modeler.event.QueryDisplayListener;
 import org.apache.cayenne.modeler.pref.ComponentGeometry;
 import org.apache.cayenne.pref.Domain;
+import org.apache.cayenne.query.EJBQLQuery;
 import org.apache.cayenne.query.ProcedureQuery;
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.SQLTemplate;
@@ -74,13 +75,13 @@
     private static final String SELECT_QUERY_VIEW = "SelectQueryView";
     private static final String SQL_TEMPLATE_VIEW = "SQLTemplateView";
     private static final String PROCEDURE_QUERY_VIEW = "ProcedureQueryView";
+    private static final String EJBQL_QUERY_VIEW = "EjbqlQueryView";
 
     protected ProjectController eventController;
     protected JSplitPane splitPane;
     protected Container detailPanel;
     protected CardLayout detailLayout;
-    private ProjectTreeView treePanel;
-    
+    private ProjectTreeView treePanel;    
     
     public ProjectTreeView getProjectTreeView() {
         return treePanel;
@@ -142,6 +143,9 @@
 
         Component procedureQueryView = new ProcedureQueryView(eventController);
         detailPanel.add(new JScrollPane(procedureQueryView), PROCEDURE_QUERY_VIEW);
+       
+        Component ejbqlQueryView = new EjbqlTabbedView(eventController);
+        detailPanel.add(new JScrollPane(ejbqlQueryView), EJBQL_QUERY_VIEW);
 
         objDetailView = new ObjEntityTabbedView(eventController);
         detailPanel.add(objDetailView, OBJ_VIEW);
@@ -230,6 +234,9 @@
         else if (query instanceof ProcedureQuery) {
             detailLayout.show(detailPanel, PROCEDURE_QUERY_VIEW);
         }
+        else if (query instanceof EJBQLQuery) {
+            detailLayout.show(detailPanel, EJBQL_QUERY_VIEW);
+        }
         else {
             detailLayout.show(detailPanel, EMPTY_VIEW);
         }

Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryMainTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryMainTab.java?rev=733790&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryMainTab.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryMainTab.java Mon Jan 12 07:34:46 2009
@@ -0,0 +1,136 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.modeler.editor;
+
+import java.awt.BorderLayout;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.event.QueryEvent;
+import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.util.ProjectUtil;
+import org.apache.cayenne.modeler.util.TextAdapter;
+import org.apache.cayenne.query.EJBQLQuery;
+import org.apache.cayenne.query.Query;
+import org.apache.cayenne.util.Util;
+import org.apache.cayenne.validation.ValidationException;
+import com.jgoodies.forms.builder.PanelBuilder;
+import com.jgoodies.forms.layout.CellConstraints;
+import com.jgoodies.forms.layout.FormLayout;
+
+
+public class EjbqlQueryMainTab extends JPanel{
+
+    protected ProjectController mediator;
+    protected TextAdapter name;
+    protected EjbqlQueryPropertiesPanel properties;
+    protected TextAdapter qualifier;
+
+    public EjbqlQueryMainTab(ProjectController mediator) {
+        this.mediator = mediator;
+        initView();  
+    }
+
+    private void initView() {
+        // create widgets
+        name = new TextAdapter(new JTextField()) {
+
+            protected void updateModel(String text) {
+                setQueryName(text);
+            }
+        };
+
+        properties = new EjbqlQueryPropertiesPanel(mediator);
+        // assemble
+        CellConstraints cc = new CellConstraints();
+        FormLayout layout = new FormLayout(
+                "right:max(80dlu;pref), 3dlu, fill:max(200dlu;pref)",
+                "p, 3dlu, p");
+        PanelBuilder builder = new PanelBuilder(layout);
+        builder.setDefaultDialogBorder();
+        builder.addSeparator("EJBQL Query Settings", cc.xywh(1, 1, 3, 1));
+        builder.addLabel("Query Name:", cc.xy(1, 3));
+        builder.add(name.getComponent(), cc.xy(3, 3));
+
+        this.setLayout(new BorderLayout());
+        this.add(builder.getPanel(), BorderLayout.NORTH);
+        this.add(properties, BorderLayout.CENTER);
+    }
+
+    /**
+     * Updates the view from the current model state. Invoked when a currently displayed
+     * query is changed.
+     */
+    void initFromModel() {
+        Query query = mediator.getCurrentQuery();
+
+        if (!(query instanceof EJBQLQuery)) {
+            setVisible(false);
+            return;
+        }
+
+        EJBQLQuery ejbqlQuery = (EJBQLQuery) query;
+        name.setText(ejbqlQuery.getName());        
+        properties.initFromModel(ejbqlQuery);
+        setVisible(true);
+    }
+
+    protected EJBQLQuery getQuery() {
+        Query query = mediator.getCurrentQuery();
+        return (query instanceof EJBQLQuery) ? (EJBQLQuery) query : null;
+    }
+
+    /**
+     * Initializes Query name from string.
+     */
+    void setQueryName(String newName) {
+        if (newName != null && newName.trim().length() == 0) {
+            newName = null;
+        }
+
+        EJBQLQuery query = getQuery();
+
+        if (query == null) {
+            return;
+        }
+
+        if (Util.nullSafeEquals(newName, query.getName())) {
+            return;
+        }
+
+        if (newName == null) {
+            throw new ValidationException("Query name is required.");
+        }
+
+        DataMap map = mediator.getCurrentDataMap();
+
+        if (map.getQuery(newName) == null) {
+            // completely new name, set new name for entity
+            QueryEvent e = new QueryEvent(this, query, query.getName());
+            ProjectUtil.setQueryName(map, query, newName);
+            mediator.fireQueryEvent(e);
+        }
+        else {
+            // there is a query with the same name
+            throw new ValidationException("There is another query named '"
+                    + newName
+                    + "'. Use a different name.");
+        }
+    }
+}

Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryPropertiesPanel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryPropertiesPanel.java?rev=733790&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryPropertiesPanel.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryPropertiesPanel.java Mon Jan 12 07:34:46 2009
@@ -0,0 +1,94 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.modeler.editor;
+
+import java.awt.BorderLayout;
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.text.JTextComponent;
+import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.query.EJBQLQuery;
+import org.apache.cayenne.query.Query;
+import org.apache.cayenne.query.QueryCacheStrategy;
+
+import com.jgoodies.forms.builder.PanelBuilder;
+import com.jgoodies.forms.layout.CellConstraints;
+import com.jgoodies.forms.layout.FormLayout;
+
+
+public class EjbqlQueryPropertiesPanel extends SelectPropertiesPanel {
+
+
+    public EjbqlQueryPropertiesPanel(ProjectController mediator) {
+        super(mediator);
+    }
+
+    protected void initController() {
+        super.initController();
+    }
+
+    protected PanelBuilder createPanelBuilder() {
+        CellConstraints cc = new CellConstraints();
+        FormLayout layout = new FormLayout(
+                "right:max(80dlu;pref), 3dlu, left:max(10dlu;pref), "
+                        + "3dlu, left:max(37dlu;pref), 3dlu, fill:max(147dlu;pref)",
+                "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p");
+
+        PanelBuilder builder = new PanelBuilder(layout);
+        builder.setDefaultDialogBorder();
+        builder.addSeparator("Select Properties", cc.xywh(1, 1, 7, 1));
+        builder.addLabel("Result Caching:", cc.xy(1, 3));
+        builder.add(cacheStrategy, cc.xywh(3, 3, 5, 1));
+        builder.addLabel("Fetch Offset, Rows:", cc.xy(1, 7));
+        builder.add(fetchOffset.getComponent(), cc.xywh(3, 7, 3, 1));
+        builder.addLabel("Fetch Limit, Rows:", cc.xy(1, 9));
+        builder.add(fetchLimit.getComponent(), cc.xywh(3, 9, 3, 1));
+        builder.addLabel("Page Size:", cc.xy(1, 11));
+        builder.add(pageSize.getComponent(), cc.xywh(3, 11, 3, 1));
+        return builder;
+    }
+
+    protected void initView() {
+        super.initView();
+        this.setLayout(new BorderLayout());
+        this.add(createPanelBuilder().getPanel(), BorderLayout.CENTER);
+    }
+
+    /**
+     * Updates the view from the current model state. Invoked when a currently displayed
+     * query is changed.
+     */
+    public void initFromModel(Query query) {
+        EJBQLQuery ejbqlQuery = (EJBQLQuery) query;
+     
+        DefaultComboBoxModel cacheModel = new DefaultComboBoxModel(CACHE_POLICIES);
+
+        QueryCacheStrategy selectedStrategy = ejbqlQuery.getCacheStrategy();
+        
+        cacheModel.setSelectedItem(selectedStrategy != null
+                ? selectedStrategy
+                : QueryCacheStrategy.getDefaultStrategy());
+        cacheStrategy.setModel(cacheModel);
+
+        fetchOffset.setText(String.valueOf(ejbqlQuery.getFetchOffset()));
+        fetchLimit.setText(String.valueOf(ejbqlQuery.getFetchLimit()));
+ //       pageSize.setText(String.valueOf(ejbqlQuery.getPageSize()));
+        JTextComponent ps = pageSize.getComponent();
+        ps.setEditable(false);
+    }
+}

Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java?rev=733790&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java Mon Jan 12 07:34:46 2009
@@ -0,0 +1,180 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.modeler.editor;
+
+import java.awt.BorderLayout;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+
+import org.apache.cayenne.map.event.QueryEvent;
+import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.util.CayenneWidgetFactory;
+import org.apache.cayenne.query.EJBQLQuery;
+import org.apache.cayenne.query.Query;
+import org.apache.cayenne.util.Util;
+import org.syntax.jedit.JEditTextArea;
+import org.syntax.jedit.KeywordMap;
+import org.syntax.jedit.tokenmarker.PLSQLTokenMarker;
+import org.syntax.jedit.tokenmarker.SQLTokenMarker;
+import org.syntax.jedit.tokenmarker.Token;
+import org.syntax.jedit.tokenmarker.TokenMarker;
+
+import com.jgoodies.forms.builder.PanelBuilder;
+import com.jgoodies.forms.layout.CellConstraints;
+import com.jgoodies.forms.layout.FormLayout;
+
+
+public class EjbqlQueryScriptsTab extends JPanel implements DocumentListener{
+
+    protected ProjectController mediator;
+    
+    static final TokenMarker SQL_TEMPLATE_MARKER;
+    static {
+        KeywordMap map = PLSQLTokenMarker.getKeywordMap();
+        
+        //adding more keywords
+        map.add("FIRST", Token.KEYWORD1);
+        map.add("LIMIT", Token.KEYWORD1);
+        map.add("OFFSET", Token.KEYWORD1);
+        map.add("TOP", Token.KEYWORD1);
+        
+        //adding velocity template highlighing
+        map.add("#bind", Token.KEYWORD2);
+        map.add("#bindEqual", Token.KEYWORD2);
+        map.add("#bindNotEqual", Token.KEYWORD2);
+        map.add("#bindObjectEqual", Token.KEYWORD2);
+        map.add("#bindObjectNotEqual", Token.KEYWORD2);
+        map.add("#chain", Token.KEYWORD2);
+        map.add("#chunk", Token.KEYWORD2);
+        map.add("#end", Token.KEYWORD2);
+        map.add("#result", Token.KEYWORD2);
+        
+        SQL_TEMPLATE_MARKER = new SQLTokenMarker(map);
+    }
+    
+    /**
+     * JEdit text component for highlighing SQL syntax (see CAY-892)
+     */
+    protected JEditTextArea scriptArea;
+ 
+    private boolean updateDisabled;
+    
+    public EjbqlQueryScriptsTab(ProjectController mediator) {
+        this.mediator = mediator;
+        initView();
+    }
+    
+    void displayScript() {
+        EJBQLQuery query = getQuery();
+        updateDisabled = true;
+        scriptArea.setText(query.getEjbqlStatement());
+        updateDisabled = false;
+     }
+
+    private void initView() {
+ 
+        scriptArea = CayenneWidgetFactory.createJEditTextArea();     
+        scriptArea.setTokenMarker(SQL_TEMPLATE_MARKER);  
+        scriptArea.getDocument().addDocumentListener(this);
+        CellConstraints cc = new CellConstraints();
+        
+        FormLayout formLayout = new FormLayout(
+                "fill:0dlu:grow", 
+                "fill:0dlu:grow");
+
+        formLayout.maximumLayoutSize(scriptArea);
+        PanelBuilder builder = new PanelBuilder(formLayout);
+      
+        builder.add(new JScrollPane(scriptArea), cc.xy(1,1));
+        
+        setLayout(new BorderLayout());
+        add(builder.getPanel(), BorderLayout.CENTER); 
+    }
+
+
+    public void initFromModel() {
+        Query query = mediator.getCurrentQuery();
+
+        if (!(query instanceof EJBQLQuery)) {
+            setVisible(false);
+            return;
+        }
+        
+        scriptArea.setEnabled(true);      
+        displayScript();
+        setVisible(true);    
+   
+    }
+    
+    EJBQLQuery getQuery() {
+        Query query = mediator.getCurrentQuery();
+        return (query instanceof EJBQLQuery) ? (EJBQLQuery) query : null;
+    }
+    
+    void setEJBQL(DocumentEvent e) {
+        Document doc = e.getDocument();
+     
+        try {
+            setEJBQL(doc.getText(0, doc.getLength()));
+        }
+        catch (BadLocationException e1) {
+            e1.printStackTrace();
+        }
+    }
+    
+    void setEJBQL(String text) {
+        EJBQLQuery query = getQuery();
+        if (query == null) {
+            return;
+        }
+
+        if (text != null) {
+            text = text.trim();
+            if (text.length() == 0) {
+                text = null;
+            }
+        }
+
+        // Compare the value before modifying the query - text area
+        // will call "verify" even if no changes have occured....
+        if (!Util.nullSafeEquals(text, query.getEjbqlStatement())) {
+             query.setEjbqlStatement(text);
+             mediator.fireQueryEvent(new QueryEvent(this, query));
+        }
+        
+    }
+ 
+    public void insertUpdate(DocumentEvent e) {
+        changedUpdate(e);
+    }
+
+    public void removeUpdate(DocumentEvent e) {
+        changedUpdate(e);
+    }
+    
+    public void changedUpdate(DocumentEvent e) {
+        if (!updateDisabled) {
+            setEJBQL(e);
+        }
+    }
+}

Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlTabbedView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlTabbedView.java?rev=733790&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlTabbedView.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlTabbedView.java Mon Jan 12 07:34:46 2009
@@ -0,0 +1,99 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.modeler.editor;
+
+import javax.swing.JScrollPane;
+import javax.swing.JTabbedPane;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.event.QueryDisplayEvent;
+import org.apache.cayenne.modeler.event.QueryDisplayListener;
+import org.apache.cayenne.query.EJBQLQuery;
+
+
+
+public class EjbqlTabbedView extends JTabbedPane {
+
+    protected ProjectController mediator;
+    protected EjbqlQueryMainTab mainTab;
+    protected EjbqlQueryScriptsTab scriptsTab;
+    protected int lastSelectionIndex;
+
+    public EjbqlTabbedView(ProjectController mediator) {
+        this.mediator = mediator;
+        initView();
+        initController();
+    }
+
+    private void initView() {
+        setTabPlacement(JTabbedPane.TOP);
+        
+        this.mainTab = new EjbqlQueryMainTab(mediator);
+        addTab("General", new JScrollPane(mainTab));
+
+        this.scriptsTab = new EjbqlQueryScriptsTab(mediator);
+        addTab("EJBQL Scripts", scriptsTab);
+    }
+
+    private void initController() {
+        mediator.addQueryDisplayListener(new QueryDisplayListener() {
+
+            public void currentQueryChanged(QueryDisplayEvent e) {
+                initFromModel();
+            }
+        });
+
+        this.addChangeListener(new ChangeListener() {
+
+            public void stateChanged(ChangeEvent e) {
+                lastSelectionIndex = getSelectedIndex();
+                updateTabs();
+            }
+        });
+    }
+
+    void initFromModel() {
+        if (!(mediator.getCurrentQuery() instanceof EJBQLQuery)) {
+            setVisible(false);
+            return;
+        }
+
+        // tab did not change - force update
+        if (getSelectedIndex() == lastSelectionIndex) {
+            updateTabs();
+        }
+        // change tab, this will update newly displayed tab...
+        else {
+            setSelectedIndex(lastSelectionIndex);
+        }
+
+        setVisible(true);
+    }
+
+    void updateTabs() {
+        switch (lastSelectionIndex) {
+            case 0:
+                mainTab.initFromModel();
+                break;
+            case 1:
+                scriptsTab.initFromModel();
+                break;
+        }
+    }}

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateScriptsTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateScriptsTab.java?rev=733790&r1=733789&r2=733790&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateScriptsTab.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateScriptsTab.java Mon Jan 12 07:34:46 2009
@@ -70,7 +70,7 @@
     /**
      * JEdit marker for SQL Template
      */
-    private static final TokenMarker SQL_TEMPLATE_MARKER;
+    static final TokenMarker SQL_TEMPLATE_MARKER;
     static {
         KeywordMap map = PLSQLTokenMarker.getKeywordMap();
         
@@ -123,7 +123,7 @@
 
             public void valueChanged(ListSelectionEvent e) {
                 if (!e.getValueIsAdjusting()) {
-                    displayScript();
+                    displayScript();                    
                 }
             }
         };
@@ -154,6 +154,7 @@
                 scripts,
                 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                 JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), cc.xy(1, 2));
+        
         builder.add(new JScrollPane(scriptArea), cc.xy(3, 2));
 
         setLayout(new BorderLayout());
@@ -173,7 +174,7 @@
         scripts.setSelectedIndex(0);
         displayScript();
         scripts.addListSelectionListener(scriptRefreshHandler);
-
+        
         scriptArea.setEnabled(true);
         setVisible(true);
     }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectPropertiesPanel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectPropertiesPanel.java?rev=733790&r1=733789&r2=733790&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectPropertiesPanel.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectPropertiesPanel.java Mon Jan 12 07:34:46 2009
@@ -59,7 +59,7 @@
     private static final String LOCAL_CACHE_LABEL = "Local Cache (per ObjectContext)";
     private static final String SHARED_CACHE_LABEL = "Shared Cache";
 
-    private static final Object[] CACHE_POLICIES = new Object[] {
+    protected static final Object[] CACHE_POLICIES = new Object[] {
             QueryCacheStrategy.NO_CACHE, QueryCacheStrategy.LOCAL_CACHE,
             QueryCacheStrategy.SHARED_CACHE
     };
@@ -199,7 +199,6 @@
         super.setEnabled(flag);
 
         // propagate to children
-
         Container mainPanel = (Container) getComponent(0);
         Component[] children = mainPanel.getComponents();
         for (Component child : children) {

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ProjectUtil.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ProjectUtil.java?rev=733790&r1=733789&r2=733790&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ProjectUtil.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ProjectUtil.java Mon Jan 12 07:34:46 2009
@@ -43,6 +43,8 @@
 import org.apache.cayenne.map.ProcedureParameter;
 import org.apache.cayenne.map.Relationship;
 import org.apache.cayenne.query.AbstractQuery;
+import org.apache.cayenne.query.EJBQLQuery;
+import org.apache.cayenne.query.Query;
 import org.apache.cayenne.util.Util;
 
 /**
@@ -134,7 +136,7 @@
         }
     }
 
-    public static void setQueryName(DataMap map, AbstractQuery query, String newName) {
+    public static void setQueryName(DataMap map, Query query, String newName) {
 
         String oldName = query.getName();
 
@@ -143,7 +145,12 @@
             return;
         }
 
-        query.setName(newName);
+        if(query instanceof AbstractQuery){
+            ((AbstractQuery)query).setName(newName);
+        }
+        if(query instanceof EJBQLQuery){
+            ((EJBQLQuery)query).setName(newName);
+        }
         map.removeQuery(oldName);
         map.addQuery(query);
 

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/resources/org/apache/cayenne/modeler/cayennemodeler-strings.properties
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/resources/org/apache/cayenne/modeler/cayennemodeler-strings.properties?rev=733790&r1=733789&r2=733790&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/resources/org/apache/cayenne/modeler/cayennemodeler-strings.properties (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/resources/org/apache/cayenne/modeler/cayennemodeler-strings.properties Mon Jan 12 07:34:46 2009
@@ -126,6 +126,9 @@
 cayenne.modeler.queryType.procedureQuery.radio = Stored Procedure Query
 cayenne.modeler.queryType.procedureQuery.radio.ShortDescription = Stored Procedure Query
 
+cayenne.modeler.queryType.ejbqlQuery.radio = EJBQL Query
+cayenne.modeler.queryType.ejbqlQuery.radio.ShortDescription = EJBQL Query
+
 // DataMap DefaultsPreferences Dialog
 cayenne.modeler.datamap.defaultprefs.update.button = Update
 cayenne.modeler.datamap.defaultprefs.update.button.ShortDescription = Update



Mime
View raw message