mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-30 21:08:30 +08:00
#849734 : improved any() path initialization
This commit is contained in:
parent
a1378b75bd
commit
d33e0729bb
@ -0,0 +1,63 @@
|
||||
package com.mysema.query.domain;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class AnyUsageTest {
|
||||
|
||||
@Entity
|
||||
public class DealerGroup implements Serializable {
|
||||
private static final long serialVersionUID = 8001287260658920066L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
public Long id;
|
||||
|
||||
@OneToMany(mappedBy = "dealerGroup")
|
||||
public Set<Dealer> dealers;
|
||||
|
||||
}
|
||||
|
||||
@Entity
|
||||
public class Dealer implements Serializable {
|
||||
private static final long serialVersionUID = -6832045219902674887L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
public Long id;
|
||||
|
||||
@ManyToOne
|
||||
public DealerGroup dealerGroup;
|
||||
|
||||
@ManyToOne
|
||||
public Company company;
|
||||
|
||||
}
|
||||
|
||||
@Entity
|
||||
public class Company {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
public Long id;
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
QAnyUsageTest_Dealer dealer = QAnyUsageTest_DealerGroup.dealerGroup.dealers.any();
|
||||
assertNotNull(dealer);
|
||||
assertNotNull(dealer.company);
|
||||
}
|
||||
|
||||
}
|
||||
@ -32,6 +32,8 @@ public abstract class CollectionPathBase<C extends Collection<E>, E, Q extends S
|
||||
@Nullable
|
||||
private transient volatile Constructor<?> constructor;
|
||||
|
||||
private volatile boolean usePathInits = false;
|
||||
|
||||
public abstract Q any();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -39,15 +41,34 @@ public abstract class CollectionPathBase<C extends Collection<E>, E, Q extends S
|
||||
try{
|
||||
if (constructor == null) {
|
||||
if (Constants.isTyped(queryType)){
|
||||
constructor = queryType.getConstructor(Class.class, PathMetadata.class);
|
||||
try {
|
||||
constructor = queryType.getConstructor(Class.class, PathMetadata.class, PathInits.class);
|
||||
usePathInits = true;
|
||||
} catch (NoSuchMethodException e) {
|
||||
constructor = queryType.getConstructor(Class.class, PathMetadata.class);
|
||||
}
|
||||
}else{
|
||||
constructor = queryType.getConstructor(PathMetadata.class);
|
||||
try {
|
||||
constructor = queryType.getConstructor(PathMetadata.class, PathInits.class);
|
||||
usePathInits = true;
|
||||
} catch (NoSuchMethodException e) {
|
||||
constructor = queryType.getConstructor(PathMetadata.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Constants.isTyped(queryType)){
|
||||
return (Q)constructor.newInstance(getElementType(), pm);
|
||||
if (usePathInits) {
|
||||
return (Q)constructor.newInstance(getElementType(), pm, PathInits.DIRECT);
|
||||
} else {
|
||||
return (Q)constructor.newInstance(getElementType(), pm);
|
||||
}
|
||||
|
||||
}else{
|
||||
return (Q)constructor.newInstance(pm);
|
||||
if (usePathInits) {
|
||||
return (Q)constructor.newInstance(pm, PathInits.DIRECT);
|
||||
} else {
|
||||
return (Q)constructor.newInstance(pm);
|
||||
}
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new ExpressionException(e);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user