cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r399853 - in /incubator/cayenne/jpa/trunk: cayenne-jpa-annotations-example/ cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/ cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/entity/ c...
Date Thu, 04 May 2006 20:37:24 GMT
Author: aadamchik
Date: Thu May  4 13:37:21 2006
New Revision: 399853

URL: http://svn.apache.org/viewcvs?rev=399853&view=rev
Log:
an example can setup a derby schema now...
still missing property accessors enhancers

Added:
    incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/DerbySetupHelper.java
    incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/resources/derby.properties
Modified:
    incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/pom.xml
    incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/Main.java
    incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/entity/Department.java
    incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/entity/Queries.java
    incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/resources/META-INF/persistence.xml
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/JpaSQLTemplate.java
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/JpaSelectQuery.java
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/QueryHints.java
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor.java
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaManagedClass.java
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaPropertyDescriptor.java

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/pom.xml
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/pom.xml?rev=399853&r1=399852&r2=399853&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/pom.xml (original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/pom.xml Thu May  4 13:37:21
2006
@@ -1,58 +1,50 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-	<modelVersion>4.0.0</modelVersion>
-	<groupId>org.apache.cayenne</groupId>
-	<artifactId>cayenne-jpa-annotations-example</artifactId>
-	<packaging>jar</packaging>
-	<version>3.0-incubating-SNAPSHOT</version>
-	<name>An example application using JPA annotations.</name>
-	<url>http://incubator.apache.org/cayenne</url>
-	<dependencies>
-		<dependency>
-			<groupId>junit</groupId>
-			<artifactId>junit</artifactId>
-			<version>3.8.1</version>
-			<scope>test</scope>
-		</dependency>
-		
-		<dependency>
-			<groupId>org.apache.geronimo.specs</groupId>
-			<artifactId>geronimo-jpa_3.0_spec</artifactId>
-			<version>1.0-SNAPSHOT</version>
-		</dependency>
-		
-		<dependency>
-			<groupId>org.apache.cayenne</groupId>
-			<artifactId>cayenne-jpa</artifactId>
-			<version>3.0-incubating-SNAPSHOT</version>
-			<scope>runtime</scope>
-		</dependency>
-		
-		<dependency>
-			<groupId>postgresql</groupId>
-			<artifactId>postgresql</artifactId>
-			<version>8.0-312.jdbc3</version>
-			<scope>runtime</scope>
-		</dependency>
-		
-		<dependency>
-			<groupId>cglib</groupId>
-			<artifactId>cglib-nodep</artifactId>
-			<version>2.1_3</version>
-			<scope>runtime</scope>
-		</dependency>
-	</dependencies>
-	
-	<build>
-		<plugins>
-			<plugin>
-				<artifactId>maven-compiler-plugin</artifactId>
-				<configuration>
-					<source>1.5</source>
-					<target>1.5</target>
-				</configuration>
-			</plugin>
-		</plugins>
-	</build>
-</project>
+<?xml version="1.0"?><project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.cayenne</groupId>
+  <artifactId>cayenne-jpa-annotations-example</artifactId>
+  <name>An example application using JPA annotations.</name>
+  <version>3.0-incubating-SNAPSHOT</version>
+  <url>http://incubator.apache.org/cayenne</url>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.geronimo.specs</groupId>
+      <artifactId>geronimo-jpa_3.0_spec</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cayenne</groupId>
+      <artifactId>cayenne-jpa</artifactId>
+      <version>3.0-incubating-SNAPSHOT</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>cglib</groupId>
+      <artifactId>cglib-nodep</artifactId>
+      <version>2.1_3</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.derby</groupId>
+      <artifactId>derby</artifactId>
+      <version>10.1.2.1</version>
+		<scope>runtime</scope>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file

Added: incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/DerbySetupHelper.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/DerbySetupHelper.java?rev=399853&view=auto
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/DerbySetupHelper.java
(added)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/DerbySetupHelper.java
Thu May  4 13:37:21 2006
@@ -0,0 +1,106 @@
+/*
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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.jpa.example;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import javax.persistence.PersistenceException;
+
+import org.apache.cayenne.jpa.example.entity.Department;
+import org.objectstyle.cayenne.access.DataContext;
+import org.objectstyle.cayenne.access.DataNode;
+import org.objectstyle.cayenne.access.DbGenerator;
+import org.objectstyle.cayenne.map.DataMap;
+
+/**
+ * A helper class that creates a new test Derby database. Uses Cayenne API to bootstrap
+ * the DB, but the schema check query is actaully mapped with annotations.
+ * 
+ * @author Andrus Adamchik
+ */
+class DerbySetupHelper {
+
+    static final String DERBY_SYSTEM_PROPERTY = "derby.system.home";
+
+    private DataContext context;
+
+    void setupDatabase() {
+        if (context == null) {
+            context = DataContext.createDataContext();
+        }
+        if (checkDBSetupNeeded()) {
+            setupDemoSchema();
+        }
+    }
+
+    void prepareDerby() throws PersistenceException {
+        InputStream in = Thread
+                .currentThread()
+                .getContextClassLoader()
+                .getResourceAsStream("derby.properties");
+
+        if (in != null) {
+            Properties props = new Properties();
+
+            try {
+                props.load(in);
+            }
+            catch (IOException e) {
+                throw new PersistenceException("Error reading properties", e);
+            }
+
+            System.getProperties().putAll(props);
+        }
+
+        // setup Derby home to be Java TMP directory if not set explicitly
+
+        if (System.getProperty(DERBY_SYSTEM_PROPERTY) == null) {
+            System.setProperty(DERBY_SYSTEM_PROPERTY, System
+                    .getProperty("java.io.tmpdir"));
+        }
+
+    }
+
+    /**
+     * Runs a test query to see if a schema is initialized.
+     */
+    private boolean checkDBSetupNeeded() {
+        try {
+            context.performNonSelectingQuery("SchemaCheck");
+            return false;
+        }
+        catch (Throwable th) {
+            return true;
+        }
+    }
+
+    private void setupDemoSchema() {
+        DataMap map = context
+                .getEntityResolver()
+                .lookupObjEntity(Department.class)
+                .getDataMap();
+        DataNode node = context.getParentDataDomain().lookupDataNode(map);
+        DbGenerator generator = new DbGenerator(node.getAdapter(), map);
+        try {
+            generator.runGenerator(node.getDataSource());
+        }
+        catch (Exception e) {
+            throw new PersistenceException("Error generating DB schema", e);
+        }
+    }
+}

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/Main.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/Main.java?rev=399853&r1=399852&r2=399853&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/Main.java
(original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/Main.java
Thu May  4 13:37:21 2006
@@ -48,9 +48,20 @@
     }
 
     Main() {
+
+        DerbySetupHelper schemaHelper = new DerbySetupHelper();
+
+        // setup Derby properties first
+        schemaHelper.prepareDerby();
+
+        // create JPA EntityManager
         this.entityManager = Persistence
                 .createEntityManagerFactory("HRPersistenceUnit")
                 .createEntityManager(PersistenceContextType.EXTENDED);
+
+        // now that the mapping is loaded, create test DB
+        schemaHelper.setupDatabase();
+
         this.logger = LogFactory.getLog("3t-client-demo");
     }
 

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/entity/Department.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/entity/Department.java?rev=399853&r1=399852&r2=399853&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/entity/Department.java
(original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/entity/Department.java
Thu May  4 13:37:21 2006
@@ -38,10 +38,10 @@
     protected String name;
     protected String description;
 
-    @OneToMany
+    @OneToMany(mappedBy = "department")
     protected List<Person> employees;
 
-    @OneToMany
+    @OneToMany(mappedBy = "department")
     protected List<Project> projects;
 
     public String getDescription() {

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/entity/Queries.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/entity/Queries.java?rev=399853&r1=399852&r2=399853&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/entity/Queries.java
(original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/java/org/apache/cayenne/jpa/example/entity/Queries.java
Thu May  4 13:37:21 2006
@@ -22,6 +22,10 @@
 import org.apache.cayenne.jpa.bridge.QueryHints;
 
 @NamedQueries(value = {
+        @NamedQuery(name = "SchemaCheck", query = "select count(1) from department", hints
= {
+                @QueryHint(name = QueryHints.QUERY_TYPE_HINT, value = QueryHints.SQL_TEMPLATE_QUERY),
+                @QueryHint(name = QueryHints.DATA_ROWS_HINT, value = "true")
+        }),
         @NamedQuery(name = "CreateData", query = "insert into department (department_id,
name, description) "
                 + "values (1, 'IT', 'Information Technology Department')", hints = {
             @QueryHint(name = QueryHints.QUERY_TYPE_HINT, value = QueryHints.SQL_TEMPLATE_QUERY)

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/resources/META-INF/persistence.xml?rev=399853&r1=399852&r2=399853&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/resources/META-INF/persistence.xml
(original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/resources/META-INF/persistence.xml
Thu May  4 13:37:21 2006
@@ -14,10 +14,15 @@
 		<class>org.apache.cayenne.jpa.example.entity.Queries</class>
 		
 		<properties>
-			<property name="CayenneDataSource.ds1.jdbc.driver" value="org.postgresql.Driver"/>
-			<property name="CayenneDataSource.ds1.jdbc.url" value="jdbc:postgresql://localhost:5432/hr"/>
+			<property name="CayenneDataSource.ds1.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
+			<property name="CayenneDataSource.ds1.jdbc.url" value="jdbc:derby:cayenne/cayenne-jpa-annotations-db;create=true"/>
+		
+		<!-- uncomment this to use login id and password for DB connection. -->
+		<!--
 			<property name="CayenneDataSource.ds1.jdbc.username" value="andrus"/>
 			<property name="CayenneDataSource.ds1.jdbc.password" value="andrus"/>
+		-->
+		
 			<property name="CayenneDataSource.ds1.jdbc.minConnections" value="1"/>
 			<property name="CayenneDataSource.ds1.jdbc.maxConnections" value="2"/>
 		</properties>

Added: incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/resources/derby.properties
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/resources/derby.properties?rev=399853&view=auto
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/resources/derby.properties
(added)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa-annotations-example/src/main/resources/derby.properties
Thu May  4 13:37:21 2006
@@ -0,0 +1 @@
+#derby.system.home = /fullpath/to/desired/derby/location
\ No newline at end of file

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java?rev=399853&r1=399852&r2=399853&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java
(original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java
Thu May  4 13:37:21 2006
@@ -17,7 +17,6 @@
 
 import java.beans.PropertyDescriptor;
 import java.lang.reflect.Field;
-import java.sql.Types;
 
 import javax.persistence.TemporalType;
 
@@ -36,14 +35,12 @@
 import org.apache.cayenne.jpa.map.JpaNamedQuery;
 import org.apache.cayenne.jpa.map.JpaOneToMany;
 import org.apache.cayenne.jpa.map.JpaOneToOne;
-import org.apache.cayenne.jpa.map.JpaPropertyDescriptor;
 import org.apache.cayenne.jpa.map.JpaQueryHint;
 import org.apache.cayenne.jpa.map.JpaRelationship;
 import org.apache.cayenne.jpa.map.JpaTable;
 import org.apache.cayenne.util.BaseTreeVisitor;
 import org.apache.cayenne.util.HierarchicalTreeVisitor;
 import org.apache.cayenne.util.TraversalUtil;
-import org.objectstyle.cayenne.dba.TypesMapping;
 import org.objectstyle.cayenne.map.DataMap;
 import org.objectstyle.cayenne.map.DbAttribute;
 import org.objectstyle.cayenne.map.DbEntity;
@@ -182,31 +179,14 @@
             JpaColumn jpaColumn = (JpaColumn) path.getObject();
             JpaBasic jpaBasic = (JpaBasic) path.getObjectParent();
 
-            ObjAttribute cayenneObjAttribute = (ObjAttribute) targetPath.getObject();
-
             DbAttribute dbAttribute = new DbAttribute(jpaColumn.getName());
 
-            // per JPA spec only date types are mapped explicitly...
-            int type;
             TemporalType ttype = jpaBasic.getParent().getTemporal();
-            if (ttype != null) {
-
-                if (TemporalType.TIMESTAMP == ttype) {
-                    type = Types.TIMESTAMP;
-                }
-                else if (TemporalType.DATE == ttype) {
-                    type = Types.DATE;
-                }
-                else {
-                    type = Types.TIME;
-                }
-            }
-            else {
-                type = TypesMapping.getSqlTypeByJava(cayenneObjAttribute.getJavaClass());
-            }
-            dbAttribute.setType(type);
 
+            dbAttribute.setType(jpaBasic.getParent().getPropertyDescriptor().getJdbcType(
+                    ttype));
             dbAttribute.setMandatory(!jpaColumn.isNullable());
+            dbAttribute.setMaxLength(jpaColumn.getLength());
 
             // TODO, andrus, 4/28/2006 - note that Cayenne DbAttribute's precision is
             // really scale (and precision is not defined at all). Fix this in
@@ -242,25 +222,10 @@
 
             JpaId jpaId = (JpaId) path.firstInstanceOf(JpaId.class);
 
-            // per JPA spec only date types are mapped explicitly...
-            int type;
-            if (jpaId.getTemporal() != null) {
-                if (TemporalType.TIMESTAMP == jpaId.getTemporal()) {
-                    type = Types.TIMESTAMP;
-                }
-                else if (TemporalType.DATE == jpaId.getTemporal()) {
-                    type = Types.DATE;
-                }
-                else {
-                    type = Types.TIME;
-                }
-            }
-            else {
-                JpaPropertyDescriptor property = jpaId.getPropertyDescriptor();
-                type = TypesMapping.getSqlTypeByJava(property.getType());
-            }
-            dbAttribute.setType(type);
+            dbAttribute.setType(jpaId.getPropertyDescriptor().getJdbcType(
+                    jpaId.getTemporal()));
 
+            dbAttribute.setMaxLength(jpaColumn.getLength());
             dbAttribute.setMandatory(true);
             dbAttribute.setPrimaryKey(true);
 
@@ -308,27 +273,10 @@
 
             // TODO: andrus, 5/2/2006 - infer this from Jpa relationship
             src.setMandatory(false);
+            
             src.setMaxLength(jpaTargetId.getColumn().getLength());
-
-            // per JPA spec only date types are mapped explicitly...
-            int type;
-            if (jpaTargetId.getTemporal() != null) {
-                if (TemporalType.TIMESTAMP == jpaTargetId.getTemporal()) {
-                    type = Types.TIMESTAMP;
-                }
-                else if (TemporalType.DATE == jpaTargetId.getTemporal()) {
-                    type = Types.DATE;
-                }
-                else {
-                    type = Types.TIME;
-                }
-            }
-            else {
-                JpaPropertyDescriptor property = jpaTargetId.getPropertyDescriptor();
-                type = TypesMapping.getSqlTypeByJava(property.getType());
-            }
-
-            src.setType(type);
+            src.setType(jpaTargetId.getPropertyDescriptor().getJdbcType(
+                    jpaTargetId.getTemporal()));
 
             DbEntity srcEntity = dataMap.getDbEntity(jpaJoin.getTable());
             srcEntity.addAttribute(src);

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/JpaSQLTemplate.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/JpaSQLTemplate.java?rev=399853&r1=399852&r2=399853&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/JpaSQLTemplate.java
(original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/JpaSQLTemplate.java
Thu May  4 13:37:21 2006
@@ -17,6 +17,7 @@
 
 import java.util.Collections;
 
+import org.apache.cayenne.jpa.map.JpaQueryHint;
 import org.objectstyle.cayenne.CayenneRuntimeException;
 import org.objectstyle.cayenne.map.EntityResolver;
 import org.objectstyle.cayenne.query.Query;
@@ -46,6 +47,12 @@
         }
         else {
             throw new CayenneRuntimeException("Unknown query root. Name: " + getName());
+        }
+
+        // metadata hints
+        JpaQueryHint dataRowsHint = jpaQuery.getHint(QueryHints.DATA_ROWS_HINT);
+        if (dataRowsHint != null) {
+            query.setFetchingDataRows("true".equalsIgnoreCase(dataRowsHint.getValue()));
         }
 
         return query.queryWithParameters(parameters != null

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/JpaSelectQuery.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/JpaSelectQuery.java?rev=399853&r1=399852&r2=399853&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/JpaSelectQuery.java
(original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/JpaSelectQuery.java
Thu May  4 13:37:21 2006
@@ -47,6 +47,15 @@
                     + getName());
         }
 
+        // metadata hints
+
+        JpaQueryHint dataRowsHint = jpaQuery.getHint(QueryHints.DATA_ROWS_HINT);
+        if (dataRowsHint != null) {
+            query.setFetchingDataRows("true".equalsIgnoreCase(dataRowsHint.getValue()));
+        }
+
+        // other hints
+
         JpaQueryHint qualifierHint = jpaQuery.getHint(QueryHints.QUALIFIER_HINT);
         if (qualifierHint != null) {
             query.setQualifier(Expression.fromString(qualifierHint.getValue()));

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/QueryHints.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/QueryHints.java?rev=399853&r1=399852&r2=399853&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/QueryHints.java
(original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/QueryHints.java
Thu May  4 13:37:21 2006
@@ -27,4 +27,5 @@
     public static final String SQL_TEMPLATE_QUERY = "org.apache.cayenne.jpa.bridge.JpaSQLTemplate";
 
     public static final String QUALIFIER_HINT = "cayenne.query.qualifier";
+    public static final String DATA_ROWS_HINT = "cayenne.query.fetchesDataRows";
 }

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor.java?rev=399853&r1=399852&r2=399853&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor.java
(original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor.java
Thu May  4 13:37:21 2006
@@ -29,6 +29,7 @@
 import org.apache.cayenne.jpa.map.JpaEntityMap;
 import org.apache.cayenne.jpa.map.JpaId;
 import org.apache.cayenne.jpa.map.JpaJoinColumn;
+import org.apache.cayenne.jpa.map.JpaManagedAttribute;
 import org.apache.cayenne.jpa.map.JpaManyToMany;
 import org.apache.cayenne.jpa.map.JpaManyToOne;
 import org.apache.cayenne.jpa.map.JpaMappedSuperclass;
@@ -152,6 +153,9 @@
             if (property.isDefaultNonRelationalType()) {
 
                 JpaAttribute attribute = new JpaAttribute();
+
+                attribute.setPropertyDescriptor(property);
+
                 attribute.setBasic(new JpaBasic());
                 attribute.setName(property.getName());
                 entity.getAttributes().add(attribute);
@@ -204,15 +208,26 @@
         public boolean onStartNode(ProjectPath path) {
             JpaColumn column = (JpaColumn) path.getObject();
 
+            JpaManagedAttribute parent = (JpaManagedAttribute) path
+                    .firstInstanceOf(JpaManagedAttribute.class);
+
             if (column.getName() == null) {
-                JpaAttribute attribute = (JpaAttribute) path
-                        .firstInstanceOf(JpaAttribute.class);
-                column.setName(attribute.getName());
+                column.setName(parent.getName());
             }
 
             if (column.getTable() == null) {
                 JpaEntity entity = (JpaEntity) path.firstInstanceOf(JpaEntity.class);
                 column.setTable(entity.getTable().getName());
+            }
+
+            if (parent.getPropertyDescriptor().isStringType()) {
+                if (column.getLength() < 0) {
+                    column.setLength(255);
+                }
+            }
+            else {
+                // length for non-string types should be ignored...
+                column.setLength(-1);
             }
 
             return true;

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaManagedClass.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaManagedClass.java?rev=399853&r1=399852&r2=399853&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaManagedClass.java
(original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaManagedClass.java
Thu May  4 13:37:21 2006
@@ -15,7 +15,6 @@
  */
 package org.apache.cayenne.jpa.map;
 
-
 public abstract class JpaManagedClass {
 
     protected JpaClassDescriptor classDescriptor;

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaPropertyDescriptor.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaPropertyDescriptor.java?rev=399853&r1=399852&r2=399853&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaPropertyDescriptor.java
(original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaPropertyDescriptor.java
Thu May  4 13:37:21 2006
@@ -21,10 +21,14 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
+import java.sql.Types;
 import java.util.Collection;
 import java.util.regex.Matcher;
 
+import javax.persistence.TemporalType;
+
 import org.apache.cayenne.jpa.JpaProviderException;
+import org.objectstyle.cayenne.dba.TypesMapping;
 
 /**
  * A descriptor of a class property that may or may not be persistent.
@@ -100,6 +104,31 @@
         }
 
         return Void.TYPE.equals(targetEntityType) ? null : targetEntityType;
+    }
+
+    public int getJdbcType(TemporalType temporalHint) {
+        // per JPA spec only date types are mapped explicitly... everything else is guess
+        // per JDBC default...
+        
+        if (temporalHint != null) {
+
+            if (TemporalType.TIMESTAMP == temporalHint) {
+                return Types.TIMESTAMP;
+            }
+            else if (TemporalType.DATE == temporalHint) {
+                return Types.DATE;
+            }
+            else {
+                return Types.TIME;
+            }
+        }
+        else {
+            return TypesMapping.getSqlTypeByJava(type);
+        }
+    }
+
+    public boolean isStringType() {
+        return String.class.isAssignableFrom(type);
     }
 
     /**



Mime
View raw message