mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-13 21:01:01 +08:00
added convenience constructos QueryMixin and Query types
This commit is contained in:
parent
fc7d96973a
commit
a79331cfaf
@ -28,6 +28,10 @@ public class QueryMixin<T>{
|
||||
this.metadata = Assert.notNull(metadata);
|
||||
}
|
||||
|
||||
public QueryMixin(){
|
||||
this.metadata = new DefaultQueryMetadata();
|
||||
}
|
||||
|
||||
public QueryMixin(T self, QueryMetadata metadata){
|
||||
this.self = Assert.notNull(self);
|
||||
this.metadata = Assert.notNull(metadata);
|
||||
|
||||
@ -29,7 +29,6 @@ import com.mysema.util.JavaWriter;
|
||||
* @author tiwe
|
||||
*
|
||||
*/
|
||||
// simplify
|
||||
@Immutable
|
||||
public class EntitySerializer implements Serializer{
|
||||
|
||||
@ -66,7 +65,7 @@ public class EntitySerializer implements Serializer{
|
||||
writer.suppressWarnings("unchecked");
|
||||
}
|
||||
writer.beginConstructor("PathMetadata<?> metadata");
|
||||
writer.line("super(" + (localName.equals(genericName) ? "" : "(Class)") + localName + ".class, metadata);");
|
||||
writer.line("super(",localName.equals(genericName) ? "" : "(Class)",localName,".class, metadata);");
|
||||
writer.end();
|
||||
}
|
||||
|
||||
@ -76,7 +75,7 @@ public class EntitySerializer implements Serializer{
|
||||
writer.suppressWarnings("unchecked");
|
||||
}
|
||||
writer.beginConstructor("PathMetadata<?> metadata", "PathInits inits");
|
||||
writer.line(thisOrSuper + "(" + (localName.equals(genericName) ? "" : "(Class)") + localName + ".class, metadata, inits);");
|
||||
writer.line(thisOrSuper, "(", localName.equals(genericName) ? "" : "(Class)", localName, ".class, metadata, inits);");
|
||||
writer.end();
|
||||
}
|
||||
|
||||
@ -101,16 +100,9 @@ public class EntitySerializer implements Serializer{
|
||||
if (!localName.equals(genericName)){
|
||||
writer.suppressWarnings("unchecked");
|
||||
}
|
||||
writer.beginConstructor("String variable");
|
||||
writer.append(" "+thisOrSuper+"(");
|
||||
if (!localName.equals(genericName)){
|
||||
writer.append("(Class)");
|
||||
}
|
||||
writer.append(localName + ".class, forVariable(variable)");
|
||||
if (hasEntityFields){
|
||||
writer.append(", INITS");
|
||||
}
|
||||
writer.append(");\n");
|
||||
writer.beginConstructor("String variable");
|
||||
writer.line(thisOrSuper,"(", localName.equals(genericName) ? "" : "(Class)",
|
||||
localName, ".class, forVariable(variable)", hasEntityFields ? ", INITS" : "", ");");
|
||||
writer.end();
|
||||
}
|
||||
|
||||
@ -151,6 +143,8 @@ public class EntitySerializer implements Serializer{
|
||||
}
|
||||
|
||||
protected void initEntityFields(JavaWriter writer, SerializerConfig config, EntityModel model) throws IOException {
|
||||
// TODO : to CodeWriter DSL
|
||||
|
||||
EntityModel superModel = model.getSuperModel();
|
||||
if (superModel != null && superModel.hasEntityFields()){
|
||||
String superQueryType = typeMappings.getPathType(superModel, model, false);
|
||||
@ -160,7 +154,8 @@ public class EntitySerializer implements Serializer{
|
||||
for (PropertyModel field : model.getProperties()){
|
||||
if (field.getType().getCategory() == TypeCategory.ENTITY){
|
||||
String queryType = typeMappings.getPathType(field.getType(), model, false);
|
||||
if (!field.isInherited()){
|
||||
if (!field.isInherited()){
|
||||
// writer.line(
|
||||
writer.append(" this." + field.getEscapedName() + " = ");
|
||||
writer.append("inits.isInitialized(\""+field.getName()+"\") ? ");
|
||||
writer.append("new " + queryType + "(forProperty(\"" + field.getName() + "\")");
|
||||
@ -169,8 +164,7 @@ public class EntitySerializer implements Serializer{
|
||||
}
|
||||
writer.append(") : null;\n");
|
||||
}else if (!config.useEntityAccessors()){
|
||||
writer.append(" this." + field.getEscapedName() + " = ");
|
||||
writer.append("_super." + field.getEscapedName() +";\n");
|
||||
writer.line("this." + field.getEscapedName() + " = ", "_super." + field.getEscapedName() +";");
|
||||
}
|
||||
|
||||
}else if (field.isInherited() && superModel != null && superModel.hasEntityFields()){
|
||||
|
||||
@ -37,7 +37,7 @@ public interface CodeWriter extends Appendable{
|
||||
|
||||
CodeWriter javadoc(String... lines) throws IOException;
|
||||
|
||||
CodeWriter line(String line) throws IOException;
|
||||
CodeWriter line(String... segments) throws IOException;
|
||||
|
||||
CodeWriter lines(String... lines) throws IOException;
|
||||
|
||||
|
||||
@ -121,10 +121,14 @@ public class JavaWriter implements Appendable, CodeWriter{
|
||||
return line(" */");
|
||||
}
|
||||
|
||||
public CodeWriter line(String line) throws IOException{
|
||||
return append(indent + line + "\n");
|
||||
public CodeWriter line(String... segments) throws IOException{
|
||||
append(indent);
|
||||
for (String segment : segments){
|
||||
append(segment);
|
||||
}
|
||||
return append("\n");
|
||||
}
|
||||
|
||||
|
||||
public CodeWriter lines(String... lines) throws IOException{
|
||||
for (String line : lines){
|
||||
line(line);
|
||||
|
||||
@ -27,6 +27,8 @@ import com.mysema.query.types.path.Path;
|
||||
*/
|
||||
public class HQLQueryMixin<T> extends QueryMixin<T> {
|
||||
|
||||
public HQLQueryMixin() {}
|
||||
|
||||
public HQLQueryMixin(QueryMetadata metadata) {
|
||||
super(metadata);
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ import org.hibernate.ScrollableResults;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mysema.query.QueryMetadata;
|
||||
import com.mysema.query.DefaultQueryMetadata;
|
||||
import com.mysema.query.QueryModifiers;
|
||||
import com.mysema.query.SearchResults;
|
||||
import com.mysema.query.hql.HQLQueryBase;
|
||||
@ -44,8 +44,8 @@ public abstract class AbstractHibernateQuery<SubType extends AbstractHibernateQu
|
||||
|
||||
private int timeout = 0;
|
||||
|
||||
public AbstractHibernateQuery(QueryMetadata md, SessionHolder session, HQLTemplates patterns) {
|
||||
super(md, patterns);
|
||||
public AbstractHibernateQuery(SessionHolder session, HQLTemplates patterns) {
|
||||
super(new DefaultQueryMetadata(), patterns);
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ public class HibernateQuery extends AbstractHibernateQuery<HibernateQuery> imple
|
||||
}
|
||||
|
||||
public HibernateQuery(SessionHolder session, HQLTemplates templates) {
|
||||
super(new DefaultQueryMetadata(), session, templates);
|
||||
super(session, templates);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -41,8 +41,8 @@ public abstract class AbstractJDOQLQuery<SubType extends AbstractJDOQLQuery<SubT
|
||||
private final PersistenceManager pm;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public AbstractJDOQLQuery(QueryMetadata md, PersistenceManager pm, JDOQLTemplates templates) {
|
||||
super(new JDOQLQueryMixin<SubType>(new DefaultQueryMetadata()));
|
||||
public AbstractJDOQLQuery(PersistenceManager pm, JDOQLTemplates templates) {
|
||||
super(new JDOQLQueryMixin<SubType>());
|
||||
this.queryMixin.setSelf((SubType) this);
|
||||
this.templates = templates;
|
||||
this.pm = pm;
|
||||
|
||||
@ -20,10 +20,10 @@ import com.mysema.query.DefaultQueryMetadata;
|
||||
public class JDOQLQueryImpl extends AbstractJDOQLQuery<JDOQLQueryImpl> implements JDOQLQuery{
|
||||
|
||||
public JDOQLQueryImpl(PersistenceManager pm, JDOQLTemplates templates) {
|
||||
super(new DefaultQueryMetadata(), pm, templates);
|
||||
super(pm, templates);
|
||||
}
|
||||
|
||||
public JDOQLQueryImpl(PersistenceManager pm) {
|
||||
super(new DefaultQueryMetadata(), pm, JDOQLTemplates.DEFAULT);
|
||||
super(pm, JDOQLTemplates.DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,6 +12,8 @@ import com.mysema.query.types.expr.Expr;
|
||||
*/
|
||||
public class JDOQLQueryMixin<T> extends QueryMixin<T>{
|
||||
|
||||
public JDOQLQueryMixin() { }
|
||||
|
||||
public JDOQLQueryMixin(QueryMetadata metadata) {
|
||||
super(metadata);
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ public abstract class AbstractSQLQuery<SubType extends AbstractSQLQuery<SubType>
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public AbstractSQLQuery(Connection conn, SQLTemplates templates) {
|
||||
super(new QueryMixin<SubType>(new DefaultQueryMetadata()));
|
||||
super(new QueryMixin<SubType>());
|
||||
this.queryMixin.setSelf((SubType) this);
|
||||
this.conn = conn;
|
||||
this.templates = templates;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user