mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-27 21:01:15 +08:00
This commit is contained in:
parent
145dc99cd4
commit
d984801c81
@ -56,7 +56,7 @@ class ScalaBeanSerializer extends Serializer {
|
||||
|
||||
// properties
|
||||
for (property <- model.getProperties()){
|
||||
property.getAnnotations.foreach( {writer.annotation(_);} )
|
||||
property.getAnnotations.foreach( {writer.annotation(_);} )
|
||||
if (javaBeanSupport){
|
||||
//writer.annotation(classOf[BeanProperty]);
|
||||
writer.line("@BeanProperty");
|
||||
@ -73,9 +73,9 @@ class ScalaBeanSerializer extends Serializer {
|
||||
imports.add(annotation.annotationType.getName);
|
||||
}
|
||||
for (property <- model.getProperties){
|
||||
for (annotation <- property.getAnnotations){
|
||||
imports.add(annotation.annotationType.getName);
|
||||
}
|
||||
for (annotation <- property.getAnnotations){
|
||||
imports.add(annotation.annotationType.getName);
|
||||
}
|
||||
}
|
||||
imports;
|
||||
}
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
package com.mysema.query.scala.sql
|
||||
|
||||
import com.mysema.query.codegen.{Serializer, EntityType, SerializerConfig}
|
||||
import com.mysema.codegen.CodeWriter
|
||||
import com.mysema.query
|
||||
|
||||
import java.util._
|
||||
import java.io.IOException
|
||||
|
||||
import scala.reflect.BeanProperty
|
||||
import scala.collection.JavaConversions._
|
||||
|
||||
class ScalaMetaDataSerializer extends Serializer {
|
||||
|
||||
val javadocSuffix = " is a Querydsl query type";
|
||||
|
||||
@throws(classOf[IOException])
|
||||
def serialize(model: EntityType, serializerConfig: SerializerConfig, writer: CodeWriter) {
|
||||
val simpleName: String = model.getSimpleName;
|
||||
|
||||
// package
|
||||
if (!model.getPackageName.isEmpty()){
|
||||
writer.packageDecl(model.getPackageName);
|
||||
}
|
||||
|
||||
// imports
|
||||
var importedClasses: Set[String] = getAnnotationTypes(model);
|
||||
if (model.hasLists()){
|
||||
importedClasses.add(classOf[List[_]].getName);
|
||||
}
|
||||
if (model.hasMaps()){
|
||||
importedClasses.add(classOf[Map[_,_]].getName);
|
||||
}
|
||||
|
||||
importedClasses.foreach( { writer.importClasses(_)} )
|
||||
|
||||
// javadoc
|
||||
writer.javadoc(simpleName + javadocSuffix);
|
||||
|
||||
// header
|
||||
for (annotation <- model.getAnnotations){
|
||||
writer.annotation(annotation);
|
||||
}
|
||||
writer.beginClass(model);
|
||||
|
||||
// properties
|
||||
for (property <- model.getProperties()){
|
||||
writer.publicField(property.getType(), property.getEscapedName);
|
||||
}
|
||||
|
||||
// TODO : primary key
|
||||
|
||||
// TODO : foreign keys
|
||||
|
||||
// TODO : inverse foreign keys
|
||||
|
||||
writer.end();
|
||||
}
|
||||
|
||||
def getAnnotationTypes(model: EntityType): Set[String] = {
|
||||
var imports = new HashSet[String]();
|
||||
for (annotation <- model.getAnnotations){
|
||||
imports.add(annotation.annotationType.getName);
|
||||
}
|
||||
imports;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
package com.mysema.query.scala.sql
|
||||
|
||||
import org.apache.commons.lang.StringUtils
|
||||
import com.mysema.codegen._;
|
||||
import com.mysema.codegen.model._;
|
||||
import com.mysema.query.codegen._;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.junit._
|
||||
import org.junit.Assert._
|
||||
|
||||
import scala.collection.JavaConversions._
|
||||
|
||||
class ScalaMetaDataSerializerTest {
|
||||
|
||||
var entityType: EntityType = null;
|
||||
|
||||
var writer = new StringWriter();
|
||||
|
||||
@Before
|
||||
def setUp(){
|
||||
// type
|
||||
var typeModel = new SimpleType(TypeCategory.ENTITY, "com.mysema.query.DomainClass", "com.mysema.query", "DomainClass", false,false);
|
||||
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])
|
||||
.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)));
|
||||
})
|
||||
}
|
||||
|
||||
@Test
|
||||
@throws(classOf[java.io.IOException])
|
||||
def Print(){
|
||||
var serializer = new ScalaMetaDataSerializer();
|
||||
serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new ScalaWriter(writer));
|
||||
var str = writer.toString();
|
||||
System.err.println(str);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user