mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
Merge branch 'master' into issue_1561
This commit is contained in:
commit
d9e896278f
@ -0,0 +1,22 @@
|
||||
package com.querydsl.apt.domain;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Properties4Test extends AbstractTest {
|
||||
|
||||
@MappedSuperclass
|
||||
public abstract static class Naming {
|
||||
|
||||
public abstract boolean is8FRecord();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertEquals("8FRecord", QProperties4Test_Naming.naming._8FRecord.getMetadata().getName());
|
||||
}
|
||||
}
|
||||
@ -51,8 +51,7 @@ public final class Property implements Comparable<Property> {
|
||||
|
||||
public Property(EntityType declaringType, String name, Type type, List<String> inits,
|
||||
boolean inherited) {
|
||||
this(declaringType, name, JavaSyntaxUtils.isReserved(name) ? (name + "$") : name, type,
|
||||
inits, inherited);
|
||||
this(declaringType, name, escapeName(name), type, inits, inherited);
|
||||
}
|
||||
|
||||
public Property(EntityType declaringType, String name, String escapedName, Type type,
|
||||
@ -65,6 +64,15 @@ public final class Property implements Comparable<Property> {
|
||||
this.inherited = inherited;
|
||||
}
|
||||
|
||||
private static String escapeName(String name) {
|
||||
if (JavaSyntaxUtils.isReserved(name)) {
|
||||
name = name + "$";
|
||||
} else if (!Character.isJavaIdentifierStart(name.charAt(0))) {
|
||||
name = "_" + name;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public void addAnnotation(Annotation annotation) {
|
||||
annotations.put(annotation.annotationType(), annotation);
|
||||
}
|
||||
|
||||
@ -162,10 +162,10 @@ public abstract class AbstractJDOQuery<T, Q extends AbstractJDOQuery<T, Q>> exte
|
||||
}
|
||||
|
||||
protected void logQuery(String queryString, Map<Object, String> parameters) {
|
||||
String normalizedQuery = queryString.replace('\n', ' ');
|
||||
MDC.put(MDC_QUERY, normalizedQuery);
|
||||
MDC.put(MDC_PARAMETERS, String.valueOf(parameters));
|
||||
if (logger.isDebugEnabled()) {
|
||||
String normalizedQuery = queryString.replace('\n', ' ');
|
||||
MDC.put(MDC_QUERY, normalizedQuery);
|
||||
MDC.put(MDC_PARAMETERS, String.valueOf(parameters));
|
||||
logger.debug(normalizedQuery);
|
||||
}
|
||||
}
|
||||
|
||||
@ -198,10 +198,10 @@ public abstract class AbstractHibernateQuery<T, Q extends AbstractHibernateQuery
|
||||
}
|
||||
|
||||
protected void logQuery(String queryString, Map<Object, String> parameters) {
|
||||
String normalizedQuery = queryString.replace('\n', ' ');
|
||||
MDC.put(MDC_QUERY, normalizedQuery);
|
||||
MDC.put(MDC_PARAMETERS, String.valueOf(parameters));
|
||||
if (logger.isDebugEnabled()) {
|
||||
String normalizedQuery = queryString.replace('\n', ' ');
|
||||
MDC.put(MDC_QUERY, normalizedQuery);
|
||||
MDC.put(MDC_PARAMETERS, String.valueOf(parameters));
|
||||
logger.debug(normalizedQuery);
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,10 +192,10 @@ public abstract class AbstractHibernateSQLQuery<T, Q extends AbstractHibernateSQ
|
||||
}
|
||||
|
||||
protected void logQuery(String queryString, Map<Object, String> parameters) {
|
||||
String normalizedQuery = queryString.replace('\n', ' ');
|
||||
MDC.put(MDC_QUERY, normalizedQuery);
|
||||
MDC.put(MDC_PARAMETERS, String.valueOf(parameters));
|
||||
if (logger.isDebugEnabled()) {
|
||||
String normalizedQuery = queryString.replace('\n', ' ');
|
||||
MDC.put(MDC_QUERY, normalizedQuery);
|
||||
MDC.put(MDC_PARAMETERS, String.valueOf(parameters));
|
||||
logger.debug(normalizedQuery);
|
||||
}
|
||||
}
|
||||
|
||||
@ -226,10 +226,10 @@ public abstract class AbstractJPAQuery<T, Q extends AbstractJPAQuery<T, Q>> exte
|
||||
}
|
||||
|
||||
protected void logQuery(String queryString, Map<Object, String> parameters) {
|
||||
String normalizedQuery = queryString.replace('\n', ' ');
|
||||
MDC.put(MDC_QUERY, normalizedQuery);
|
||||
MDC.put(MDC_PARAMETERS, String.valueOf(parameters));
|
||||
if (logger.isDebugEnabled()) {
|
||||
String normalizedQuery = queryString.replace('\n', ' ');
|
||||
MDC.put(MDC_QUERY, normalizedQuery);
|
||||
MDC.put(MDC_PARAMETERS, String.valueOf(parameters));
|
||||
logger.debug(normalizedQuery);
|
||||
}
|
||||
}
|
||||
|
||||
@ -273,10 +273,10 @@ public abstract class AbstractJPASQLQuery<T, Q extends AbstractJPASQLQuery<T, Q>
|
||||
}
|
||||
|
||||
protected void logQuery(String queryString, Map<Object, String> parameters) {
|
||||
String normalizedQuery = queryString.replace('\n', ' ');
|
||||
MDC.put(MDC_QUERY, normalizedQuery);
|
||||
MDC.put(MDC_PARAMETERS, String.valueOf(parameters));
|
||||
if (logger.isDebugEnabled()) {
|
||||
String normalizedQuery = queryString.replace('\n', ' ');
|
||||
MDC.put(MDC_QUERY, normalizedQuery);
|
||||
MDC.put(MDC_PARAMETERS, String.valueOf(parameters));
|
||||
logger.debug(normalizedQuery);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1098,6 +1098,13 @@ public abstract class AbstractJPATest {
|
||||
assertEquals(0L, query().from(show).where(show.acts.containsValue("C")).fetchCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Map_Contains() {
|
||||
QShow show = QShow.show;
|
||||
assertEquals(1L, query().from(show).where(show.acts.contains("a", "A")).fetchCount());
|
||||
assertEquals(0L, query().from(show).where(show.acts.contains("X", "X")).fetchCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void Map_Join() {
|
||||
|
||||
@ -219,9 +219,16 @@ public class LuceneSerializer {
|
||||
Constant<Collection<?>> collConstant = (Constant<Collection<?>>) operation.getArg(1);
|
||||
Collection<?> values = collConstant.getConstant();
|
||||
BooleanQuery bq = new BooleanQuery();
|
||||
for (Object value : values) {
|
||||
String[] str = convert(path, value);
|
||||
bq.add(eq(field, str, ignoreCase), Occur.SHOULD);
|
||||
if (Number.class.isAssignableFrom(path.getType())) {
|
||||
for (Object value : values) {
|
||||
TermQuery eq = new TermQuery(new Term(field, convertNumber((Number) value)));
|
||||
bq.add(eq, Occur.SHOULD);
|
||||
}
|
||||
} else {
|
||||
for (Object value : values) {
|
||||
String[] str = convert(path, value);
|
||||
bq.add(eq(field, str, ignoreCase), Occur.SHOULD);
|
||||
}
|
||||
}
|
||||
return bq;
|
||||
}
|
||||
|
||||
@ -179,6 +179,16 @@ public class LuceneQueryTest {
|
||||
assertEquals(3, query.distinct().fetchCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void In() {
|
||||
assertEquals(2, query.where(title.in("Jurassic Park", "Nummisuutarit")).fetchCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void In2() {
|
||||
assertEquals(3, query.where(year.in(1990, 1864)).fetchCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void List_Sorted_By_Year_Ascending() {
|
||||
query.where(year.between(1800, 2000));
|
||||
|
||||
@ -222,9 +222,16 @@ public class LuceneSerializer {
|
||||
Constant<Collection<?>> expectedConstant = (Constant<Collection<?>>) operation.getArg(1);
|
||||
Collection<?> values = expectedConstant.getConstant();
|
||||
BooleanQuery bq = new BooleanQuery();
|
||||
for (Object value : values) {
|
||||
String[] str = convert(path, value);
|
||||
bq.add(eq(field, str, ignoreCase), Occur.SHOULD);
|
||||
if (Number.class.isAssignableFrom(path.getType())) {
|
||||
for (Object value : values) {
|
||||
TermQuery eq = new TermQuery(new Term(field, convertNumber((Number) value)));
|
||||
bq.add(eq, Occur.SHOULD);
|
||||
}
|
||||
} else {
|
||||
for (Object value : values) {
|
||||
String[] str = convert(path, value);
|
||||
bq.add(eq(field, str, ignoreCase), Occur.SHOULD);
|
||||
}
|
||||
}
|
||||
return bq;
|
||||
}
|
||||
|
||||
@ -177,6 +177,16 @@ public class LuceneQueryTest {
|
||||
assertEquals(3, query.distinct().fetchCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void In() {
|
||||
assertEquals(2, query.where(title.in("Jurassic Park", "Nummisuutarit")).fetchCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void In2() {
|
||||
assertEquals(3, query.where(year.in(1990, 1864)).fetchCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void List_Sorted_By_Year_Ascending() {
|
||||
query.where(year.between(1800, 2000));
|
||||
|
||||
@ -269,9 +269,16 @@ public class LuceneSerializer {
|
||||
.getArg(1);
|
||||
Collection<?> values = expectedConstant.getConstant();
|
||||
BooleanQuery bq = new BooleanQuery();
|
||||
for (Object value : values) {
|
||||
String[] str = convert(path, value);
|
||||
bq.add(eq(field, str, ignoreCase), Occur.SHOULD);
|
||||
if (Number.class.isAssignableFrom(path.getType())) {
|
||||
for (Object value : values) {
|
||||
TermQuery eq = new TermQuery(new Term(field, convertNumber((Number) value)));
|
||||
bq.add(eq, Occur.SHOULD);
|
||||
}
|
||||
} else {
|
||||
for (Object value : values) {
|
||||
String[] str = convert(path, value);
|
||||
bq.add(eq(field, str, ignoreCase), Occur.SHOULD);
|
||||
}
|
||||
}
|
||||
return bq;
|
||||
}
|
||||
|
||||
@ -253,6 +253,16 @@ public class LuceneQueryTest {
|
||||
assertEquals(3, query.distinct().fetchCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void In() {
|
||||
assertEquals(2, query.where(title.in("Jurassic Park", "Nummisuutarit")).fetchCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void In2() {
|
||||
assertEquals(3, query.where(year.in(1990, 1864)).fetchCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void List_Sorted_By_Year_Ascending() {
|
||||
query.where(year.between(1800, 2000));
|
||||
|
||||
@ -330,13 +330,16 @@ public abstract class MongodbSerializer implements Visitor<Object, Void> {
|
||||
public String visit(Path<?> expr, Void context) {
|
||||
PathMetadata metadata = expr.getMetadata();
|
||||
if (metadata.getParent() != null) {
|
||||
Path<?> parent = metadata.getParent();
|
||||
if (parent.getMetadata().getPathType() == PathType.DELEGATE) {
|
||||
parent = parent.getMetadata().getParent();
|
||||
}
|
||||
if (metadata.getPathType() == PathType.COLLECTION_ANY) {
|
||||
return visit(metadata.getParent(), context);
|
||||
} else if (metadata.getParent().getMetadata().getPathType() != PathType.VARIABLE
|
||||
&& metadata.getParent().getMetadata().getPathType() != PathType.DELEGATE) {
|
||||
return visit(parent, context);
|
||||
} else if (parent.getMetadata().getPathType() != PathType.VARIABLE) {
|
||||
String rv = getKeyForPath(expr, metadata);
|
||||
String parent = visit(metadata.getParent(), context);
|
||||
return rv != null ? parent + "." + rv : parent;
|
||||
String parentStr = visit(parent, context);
|
||||
return rv != null ? parentStr + "." + rv : parentStr;
|
||||
}
|
||||
}
|
||||
return getKeyForPath(expr, metadata);
|
||||
|
||||
@ -30,6 +30,7 @@ import com.mongodb.DBObject;
|
||||
import com.querydsl.core.types.Expression;
|
||||
import com.querydsl.core.types.OrderSpecifier;
|
||||
import com.querydsl.core.types.dsl.*;
|
||||
import com.querydsl.mongodb.domain.QAddress;
|
||||
import com.querydsl.mongodb.domain.QDummyEntity;
|
||||
import com.querydsl.mongodb.domain.QPerson;
|
||||
import com.querydsl.mongodb.domain.QUser;
|
||||
@ -263,6 +264,15 @@ public class MongodbSerializerTest {
|
||||
assertQuery(person.addressId.eq(id), dbo("addressId",id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Path() {
|
||||
QUser user = QUser.user;
|
||||
assertEquals("firstName", serializer.visit(user.firstName, null));
|
||||
assertEquals("firstName", serializer.visit(user.as(QUser.class).firstName, null));
|
||||
assertEquals("mainAddress.street", serializer.visit(user.mainAddress().street, null));
|
||||
assertEquals("mainAddress.street", serializer.visit(user.mainAddress().as(QAddress.class).street, null));
|
||||
}
|
||||
|
||||
|
||||
private List<OrderSpecifier<?>> sortList(OrderSpecifier<?> ... order) {
|
||||
return Arrays.asList(order);
|
||||
|
||||
@ -110,4 +110,10 @@ public class DefaultNamingStrategyTest {
|
||||
assertEquals("a_b", namingStrategy.getPropertyName("a b", entityModel));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ValidName() {
|
||||
assertEquals("8FRecord", namingStrategy.normalizeColumnName("8FRecord"));
|
||||
assertEquals("_8FRecord", namingStrategy.getPropertyName("8FRecord", entityModel));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -609,10 +609,10 @@ public abstract class AbstractSQLQuery<T, Q extends AbstractSQLQuery<T, Q>> exte
|
||||
}
|
||||
|
||||
protected void logQuery(String queryString, Collection<Object> parameters) {
|
||||
String normalizedQuery = queryString.replace('\n', ' ');
|
||||
MDC.put(MDC_QUERY, normalizedQuery);
|
||||
MDC.put(MDC_PARAMETERS, String.valueOf(parameters));
|
||||
if (logger.isDebugEnabled()) {
|
||||
String normalizedQuery = queryString.replace('\n', ' ');
|
||||
MDC.put(MDC_QUERY, normalizedQuery);
|
||||
MDC.put(MDC_PARAMETERS, String.valueOf(parameters));
|
||||
logger.debug(normalizedQuery);
|
||||
}
|
||||
}
|
||||
|
||||
@ -203,10 +203,10 @@ public abstract class AbstractSQLClause<C extends AbstractSQLClause<C>> implemen
|
||||
}
|
||||
|
||||
protected void logQuery(Logger logger, String queryString, Collection<Object> parameters) {
|
||||
String normalizedQuery = queryString.replace('\n', ' ');
|
||||
MDC.put(QueryBase.MDC_QUERY, normalizedQuery);
|
||||
MDC.put(QueryBase.MDC_PARAMETERS, String.valueOf(parameters));
|
||||
if (logger.isDebugEnabled()) {
|
||||
String normalizedQuery = queryString.replace('\n', ' ');
|
||||
MDC.put(QueryBase.MDC_QUERY, normalizedQuery);
|
||||
MDC.put(QueryBase.MDC_PARAMETERS, String.valueOf(parameters));
|
||||
logger.debug(normalizedQuery);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user