querydsl/querydsl-sql
balazs.zsoldos 6e3d404610 Clean out querydsl-sql dependencies
- make querydsl-spatial optional (in my opinion sql-spatial should be a 
   separate module)
 - remove com.vividsolutions:jts dependency: I do not know why it is 
   there. All tests run well and compilation ok if I remove it
 - replace javax.validation to a version that contains OSGi manifest 
   headers
 - replace javax.inject to the servicemix bundle as it contains OSGi 
   headers
 - make javax.inject optional
 - make postgresql dependency optional
 - make postgis dependency optional
 - make oracle dependencies optiona
2014-06-19 12:20:26 +02:00
..
src Merge pull request #805 from querydsl/i630 2014-06-16 18:18:51 +03:00
pom.xml Clean out querydsl-sql dependencies 2014-06-19 12:20:26 +02:00
README.md Format readmes 2014-03-24 10:12:56 +02:00
template.mf Merge branch 'master' into spatial 2014-05-13 22:25:20 +03:00

Querydsl SQL

The SQL module provides integration with the JDBC API.

Maven integration

Add the following dependencies to your Maven project :

<dependency>
  <groupId>com.mysema.querydsl</groupId>
  <artifactId>querydsl-sql</artifactId>
  <version>${querydsl.version}</version>
</dependency>    
        
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.6.1</version>
</dependency>   

Code generation via Maven

This functionality is also available as a Maven plugin. The presented example can be declared like this in the POM :

<plugin>
  <groupId>com.mysema.querydsl</groupId>
  <artifactId>querydsl-maven-plugin</artifactId>
  <version>${querydsl.version}</version>
  <executions>
    <execution>
      <goals>
        <goal>export</goal>
      </goals>
    </execution>            
  </executions>
  <configuration>
    <jdbcDriver>org.apache.derby.jdbc.EmbeddedDriver</jdbcDriver>
    <jdbcUrl>jdbc:derby:target/demoDB;create=true</jdbcUrl>
    <packageName>com.myproject.domain</packageName>
    <targetFolder>${project.basedir}/target/generated-sources/java</targetFolder> 
  </configuration>
  <dependencies>
    <dependency>
      <groupId>org.apache.derby</groupId>
      <artifactId>derby</artifactId>
      <version>${derby.version}</version>
    </dependency>
  </dependencies>
</plugin>  

Use the goal test-export to add the targetFolder as a test compile source root instead of a compile source root.

Querying

Querying with Querydsl SQL is as simple as this :

QCustomer customer = new QCustomer("c");

SQLTemplates dialect = new HSQLDBTemplates(); // SQL-dialect
SQLQuery query = new SQLQuery(connection, dialect); 
List<String> lastNames = query.from(customer)
    .where(customer.firstName.eq("Bob"))
    .list(customer.lastName);

For more information on the Querydsl SQL module visit the reference documentation http://www.querydsl.com/static/querydsl/latest/reference/html/ch02s03.html