This commit is contained in:
Timo Westkämper 2010-09-19 18:41:25 +00:00
parent d984801c81
commit c43e2c1a40
7 changed files with 71 additions and 15 deletions

View File

@ -29,6 +29,14 @@
<version>${scala.version}</version>
<scope>provided</scope>
</dependency>
<!-- provided -->
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-sql</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<!-- test -->
<dependency>
@ -38,12 +46,7 @@
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-sql</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>

View File

@ -3,9 +3,9 @@
* All rights reserved.
*
*/
package com.mysema.query.scala
package com.mysema.query.scala.sql
import com.mysema.query.codegen.{Serializer, EntityType, SerializerConfig}
import com.mysema.query.codegen._
import com.mysema.codegen.CodeWriter
import com.mysema.query

View File

@ -1,7 +1,8 @@
package com.mysema.query.scala.sql
import com.mysema.query.codegen.{Serializer, EntityType, SerializerConfig}
import com.mysema.query.codegen._
import com.mysema.codegen.CodeWriter
import com.mysema.codegen.model.TypeCategory._
import com.mysema.query
import java.util._
@ -12,6 +13,8 @@ import scala.collection.JavaConversions._
class ScalaMetaDataSerializer extends Serializer {
val typeMappings = new TypeMappings();
val javadocSuffix = " is a Querydsl query type";
@throws(classOf[IOException])
@ -24,6 +27,9 @@ class ScalaMetaDataSerializer extends Serializer {
}
// imports
writer.importPackages("com.mysema.query.sql");
writer.importPackages("com.mysema.query.types.path");
var importedClasses: Set[String] = getAnnotationTypes(model);
if (model.hasLists()){
importedClasses.add(classOf[List[_]].getName);
@ -41,14 +47,34 @@ class ScalaMetaDataSerializer extends Serializer {
for (annotation <- model.getAnnotations){
writer.annotation(annotation);
}
writer.beginClass(model);
val queryType = typeMappings.getPathType(model, model, true);
writer.beginClass(queryType);
// properties
for (property <- model.getProperties()){
writer.publicField(property.getType(), property.getEscapedName);
val methodName: String = property.getType.getCategory match {
case COMPARABLE => "createComparable";
case BOOLEAN => "createBoolean";
case DATE => "createDate";
case DATETIME => "createDateTime";
case ENUM => "createEnum";
case NUMERIC => "createNumber";
case STRING => "createString";
case SIMPLE => "createSimple";
case TIME => "createTime";
}
var ptype = typeMappings.getPathType(property.getType, model, false);
var value: String = null;
if (property.getType.getCategory == BOOLEAN || property.getType.getCategory == STRING){
value = methodName + "(\"" + property.getName + "\")";
}else{
value = methodName + "(\"" + property.getName + "\", classOf[" + writer.getRawName(property.getType) + "])";
}
writer.publicFinal(ptype, property.getEscapedName, value);
}
// TODO : primary key
// TODO : primary keys
// TODO : foreign keys

View File

@ -1,9 +1,13 @@
package com.mysema.query.scala
package com.mysema.query.scala.sql
import com.mysema.query.sql._
import com.mysema.query.types.path._
import java.util.{Arrays, Collections}
object QUser {
def as(path: String) = new QUser(path);
}
@Table("USER")
class QUser(path: String) extends RelationalPathBase[QUser](classOf[QUser], path){
val id = createNumber("ID", classOf[Integer]);
@ -14,6 +18,10 @@ class QUser(path: String) extends RelationalPathBase[QUser](classOf[QUser], path
val superiorIdKey: ForeignKey[QUser] = createForeignKey(superiorId,"ID");
}
object QDepartment {
def as(path: String) = new QDepartment(path);
}
@Table("DEPARTMENT")
class QDepartment(path: String) extends RelationalPathBase[QDepartment](classOf[QDepartment], path){
val id = createNumber("ID", classOf[Integer]);
@ -22,6 +30,10 @@ class QDepartment(path: String) extends RelationalPathBase[QDepartment](classOf[
val companyKey: ForeignKey[QCompany] = createForeignKey(company, "ID");
}
object QCompany {
def as(path: String) = new QCompany(path);
}
@Table("COMPANY")
class QCompany(path: String) extends RelationalPathBase[QCompany](classOf[QCompany], path){
val id = createNumber("ID", classOf[Integer]);
@ -34,6 +46,10 @@ class QCompany(path: String) extends RelationalPathBase[QCompany](classOf[QCompa
// val books = oneToMany(Book.category) // allows navigating between associations transparently
//}
object QCategory {
def as(path: String) = new QCategory(path);
}
@Table("CATEGORY")
class QCategory(path: String) extends RelationalPathBase[QCategory](classOf[QCategory], path){
val id = createNumber("ID", classOf[Integer]);
@ -48,6 +64,10 @@ class QCategory(path: String) extends RelationalPathBase[QCategory](classOf[QCat
// val category = manyToOne(Book.category)
//}
object QBook {
def as(path: String) = new QBook(path);
}
@Table("BOOK")
class QBook(path: String) extends RelationalPathBase[QBook](classOf[QBook], path){
val id = createNumber("ID",classOf[Integer]);

View File

@ -1,4 +1,4 @@
package com.mysema.query.scala
package com.mysema.query.scala.sql
import com.mysema.query.sql._
import org.junit.Test
@ -6,6 +6,13 @@ import org.junit.Assert._
class QuerySyntaxTest {
@Test
def Path_Creation(){
var c1 = new QCategory("c");
var c2 = QCategory as "c";
assertEquals(c1, c2);
}
@Test
def Query_Syntax(){
// select()

View File

@ -25,7 +25,7 @@ class ScalaMetaDataSerializerTest {
entityType = new EntityType("Q", typeModel);
// properties
List(classOf[Boolean], classOf[Comparable[_]], classOf[Integer], classOf[java.util.Date], classOf[java.sql.Date], classOf[java.sql.Time])
List(classOf[java.lang.Boolean], classOf[Comparable[_]], classOf[Integer], classOf[java.util.Date], classOf[java.sql.Date], classOf[java.sql.Time])
.foreach(cl => {
var classType = new ClassType(TypeCategory.get(cl.getName), cl);
entityType.addProperty(new Property(entityType, StringUtils.uncapitalize(cl.getSimpleName), classType, new Array[String](0)));