mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-13 21:01:01 +08:00
Merge pull request #1301 from querydsl/custom-types-querydsl3
Add fix for extending external types
This commit is contained in:
commit
2e9cfb072b
@ -0,0 +1,9 @@
|
||||
package com.mysema.query;
|
||||
|
||||
import com.mysema.query.annotations.QueryEntity;
|
||||
import com.mysema.query.domain.AbstractEntity;
|
||||
|
||||
@QueryEntity
|
||||
public class ExampleEntity2 extends AbstractEntity<ExampleEntity2> {
|
||||
// id inherited
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package com.mysema.query;
|
||||
|
||||
import com.mysema.query.annotations.QueryDelegate;
|
||||
import com.mysema.query.types.expr.NumberExpression;
|
||||
import com.mysema.query.types.path.NumberPath;
|
||||
|
||||
public class IntegerExtensions {
|
||||
|
||||
@QueryDelegate(Integer.class)
|
||||
public static NumberExpression<Integer> difference(NumberPath<Integer> left, NumberExpression<Integer> right) {
|
||||
return right.subtract(left);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package com.mysema.query.apt;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Files;
|
||||
|
||||
public class IntegerExtensionsTest extends AbstractProcessorTest {
|
||||
|
||||
private static final String packagePath = "src/test/apt/com/mysema/query/";
|
||||
|
||||
@Test
|
||||
public void Process() throws IOException {
|
||||
List<String> sources = Arrays.asList(
|
||||
new File(packagePath, "IntegerExtensions.java").getPath(),
|
||||
new File(packagePath, "ExampleEntity2.java").getPath());
|
||||
process(QuerydslAnnotationProcessor.class, sources, "integerExtensions");
|
||||
String qtypeContent = Files.toString(new File("target/integerExtensions/com/mysema/query/QExampleEntity2.java"), Charsets.UTF_8);
|
||||
//The superclass' id property is inherited, but can't be assigned to the custom QInteger
|
||||
assertTrue(qtypeContent.contains("public final ext.java.lang.QInteger id = new ext.java.lang.QInteger(_super.id);"));
|
||||
}
|
||||
|
||||
}
|
||||
@ -652,7 +652,8 @@ public class EntitySerializer implements Serializer {
|
||||
writer.line("// inherited");
|
||||
Supertype superType = model.getSuperType();
|
||||
if (!superType.getEntityType().hasEntityFields()) {
|
||||
writer.publicFinal(queryType, field.getEscapedName(),"_super." + field.getEscapedName());
|
||||
String value = NEW + writer.getRawName(queryType) + "(_super." + field.getEscapedName() + ")";
|
||||
writer.publicFinal(queryType, field.getEscapedName(), value);
|
||||
} else {
|
||||
writer.publicFinal(queryType, field.getEscapedName());
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user