Merge branch 'master' into i723

Conflicts:
	querydsl-root/pom.xml
This commit is contained in:
Timo Westkämper 2014-05-05 21:39:32 +03:00
commit c2d2166644
15 changed files with 159 additions and 170 deletions

View File

@ -4,7 +4,27 @@ jdk:
- oraclejdk8
services:
- mongodb
addons:
postgresql: "9.3"
install:
- sh -c 'cd querydsl-root && mvn -B -q install -Dmaven.javadoc.skip=true -DskipTests=true'
before_script:
- mysql -e "create database querydsl;" -u root
- mysql -e "create database querydsl2;" -u root
- mysql -e "create user 'querydsl'@'localhost' identified by 'querydsl';" -u root
- mysql -e "grant all privileges on querydsl.* to 'querydsl'@'localhost';" -u root
- mysql -e "grant all privileges on querydsl2.* to 'querydsl'@'localhost';" -u root
- psql -c 'create database querydsl;' -U postgres
- psql -c 'create database querydsl2;' -U postgres
- psql -c "create user querydsl with password 'querydsl';" -U postgres
- psql -c 'grant all privileges on database querydsl to querydsl;' -U postgres
- psql -c 'grant all privileges on database querydsl2 to querydsl;' -U postgres
- psql -c 'create extension postgis;' -U postgres
- echo 'yes' | sudo add-apt-repository ppa:cubrid/cubrid
- sudo apt-get update
- sudo apt-get install cubrid
- sudo apt-get install cubrid-demodb
- /etc/profile.d/cubrid.sh
- hostname | sed 's/^/127.0.0.1 /g' | cat - /etc/hosts > /tmp/etchoststemp && sudo mv /tmp/etchoststemp /etc/hosts --force
script:
- sh -c 'cd querydsl-root && mvn -B test'
- sh -c 'cd querydsl-root && mvn -B test -Pall,travis'

View File

@ -4,6 +4,8 @@ Querydsl is a framework which enables the construction of type-safe SQL-like que
Instead of writing queries as inline strings or externalizing them into XML files they are constructed via a fluent API.
[![Build Status](https://travis-ci.org/querydsl/querydsl.svg?branch=master)](https://travis-ci.org/querydsl/querydsl)
**Getting started**
Use these tutorials to get started

View File

@ -29,6 +29,8 @@ import junit.framework.Assert;
public abstract class AbstractProcessorTest {
private final JavaCompiler compiler = new SimpleCompiler();
protected static List<String> getFiles(String path) {
List<String> classes = new ArrayList<String>();
for (File file : new File(path).listFiles()) {
@ -51,7 +53,6 @@ public abstract class AbstractProcessorTest {
}
protected void compile(Class<? extends AbstractProcessor> processorClass, List<String> classes, String target) throws IOException {
JavaCompiler compiler = new SimpleCompiler();
List<String> options = new ArrayList<String>(classes.size() + 3);
options.add("-s");
options.add("target/" + target);

View File

@ -13,28 +13,8 @@
*/
package com.mysema.query.mongodb;
import static java.util.Arrays.asList;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import com.mysema.query.mongodb.domain.*;
import org.bson.types.ObjectId;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mongodb.morphia.Datastore;
import org.mongodb.morphia.Morphia;
import java.util.*;
import com.google.common.collect.Lists;
import com.mongodb.Mongo;
@ -42,10 +22,7 @@ import com.mongodb.MongoException;
import com.mongodb.ReadPreference;
import com.mysema.query.NonUniqueResultException;
import com.mysema.query.SearchResults;
import com.mysema.query.mongodb.domain.QAddress;
import com.mysema.query.mongodb.domain.QItem;
import com.mysema.query.mongodb.domain.QMapEntity;
import com.mysema.query.mongodb.domain.QUser;
import com.mysema.query.mongodb.domain.*;
import com.mysema.query.mongodb.domain.User.Gender;
import com.mysema.query.mongodb.morphia.MorphiaQuery;
import com.mysema.query.types.EntityPath;
@ -53,6 +30,16 @@ import com.mysema.query.types.OrderSpecifier;
import com.mysema.query.types.Predicate;
import com.mysema.query.types.path.StringPath;
import com.mysema.testutil.ExternalDB;
import org.bson.types.ObjectId;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mongodb.morphia.Datastore;
import org.mongodb.morphia.Morphia;
import static java.util.Arrays.asList;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.*;
@Category(ExternalDB.class)
public class MongodbQueryTest {
@ -208,12 +195,14 @@ public class MongodbQueryTest {
@Test
public void Dates() {
Date start = new Date();
long current = System.currentTimeMillis();
int dayInMillis = 24 * 60 * 60 * 1000;
Date start = new Date(current);
ds.delete(ds.createQuery(Dates.class));
Dates d = new Dates();
d.setDate(new Date());
d.setDate(new Date(current + dayInMillis));
ds.save(d);
Date end = new Date();
Date end = new Date(current + 2 * dayInMillis);
assertEquals(d, query(dates).where(dates.date.between(start, end)).singleResult());
assertEquals(0, query(dates).where(dates.date.between(new Date(0), start)).count());

View File

@ -0,0 +1,46 @@
package com.mysema.query.mongodb.domain;
import com.mysema.query.annotations.QuerySupertype;
import org.bson.types.ObjectId;
import org.mongodb.morphia.annotations.Id;
@QuerySupertype
public abstract class AbstractEntity {
private @Id ObjectId id;
public ObjectId getId() {
return id;
}
public void setId(ObjectId id) {
this.id = id;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AbstractEntity other = (AbstractEntity) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
}

View File

@ -1,26 +1,14 @@
package com.mysema.query.mongodb.domain;
import org.bson.types.ObjectId;
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;
import java.util.Date;
@Entity
public class Dates {
import org.mongodb.morphia.annotations.Entity;
private @Id ObjectId id;
@Entity
public class Dates extends AbstractEntity {
private Date date;
public ObjectId getId() {
return id;
}
public void setId(ObjectId id) {
this.id = id;
}
public Date getDate() {
return date;
}
@ -28,4 +16,5 @@ public class Dates {
public void setDate(Date date) {
this.date = date;
}
}

View File

@ -13,27 +13,15 @@
*/
package com.mysema.query.mongodb.domain;
import org.bson.types.ObjectId;
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;
import org.mongodb.morphia.annotations.Property;
@Entity
public class DummyEntity {
private @Id ObjectId id;
public class DummyEntity extends AbstractEntity {
@Property("prop")
private String property;
public ObjectId getId() {
return id;
}
public void setId(ObjectId id) {
this.id = id;
}
public String getProperty() {
return property;
}

View File

@ -13,14 +13,10 @@
*/
package com.mysema.query.mongodb.domain;
import org.bson.types.ObjectId;
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;
@Entity
public class GeoEntity {
private @Id ObjectId id;
public class GeoEntity extends AbstractEntity {
private Double[] location;
@ -30,14 +26,6 @@ public class GeoEntity {
public GeoEntity() {}
public ObjectId getId() {
return id;
}
public void setId(ObjectId id) {
this.id = id;
}
public Double[] getLocation() {
return location;
}

View File

@ -17,23 +17,12 @@ import java.util.List;
import org.bson.types.ObjectId;
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;
@Entity
public class Item {
private @Id ObjectId id;
public class Item extends AbstractEntity {
private List<ObjectId> ctds;
public ObjectId getId() {
return id;
}
public void setId(ObjectId id) {
this.id = id;
}
public List<ObjectId> getCtds() {
return ctds;
}
@ -41,6 +30,5 @@ public class Item {
public void setCtds(List<ObjectId> ctds) {
this.ctds = ctds;
}
}

View File

@ -3,27 +3,15 @@ package com.mysema.query.mongodb.domain;
import java.util.HashMap;
import java.util.Map;
import org.bson.types.ObjectId;
import org.mongodb.morphia.annotations.Embedded;
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;
@Entity
public class MapEntity {
public class MapEntity extends AbstractEntity {
private @Id ObjectId id;
@Embedded
private Map<String, String> properties = new HashMap<String, String>();
public ObjectId getId() {
return id;
}
public void setId(ObjectId id) {
this.id = id;
}
public Map<String, String> getProperties() {
return properties;
}

View File

@ -17,19 +17,15 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.bson.types.ObjectId;
import org.mongodb.morphia.annotations.Embedded;
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;
import org.mongodb.morphia.annotations.Reference;
@Entity
public class User {
public class User extends AbstractEntity {
public enum Gender { MALE, FEMALE }
private @Id ObjectId id;
private String firstName;
private String lastName;
@ -74,18 +70,10 @@ public class User {
@Override
public String toString() {
return "TestUser [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName
return "TestUser [id=" + getId() + ", firstName=" + firstName + ", lastName=" + lastName
+ "]";
}
public ObjectId getId() {
return id;
}
public void setId(ObjectId id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
@ -177,31 +165,4 @@ public class User {
this.enemy = enemy;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
User other = (User) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
}

View File

@ -481,7 +481,31 @@
</plugins>
</build>
</profile>
<profile>
<id>travis</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludedGroups>com.mysema.testutil.DummyInterface</excludedGroups>
<excludes>
<exclude>**/*$*</exclude>
<exclude>**/ExportOracleTest.java</exclude>
<exclude>**/OracleSuiteTest.java</exclude>
<exclude>**/OracleWithQuotingTest.java</exclude>
<exclude>**/MSSQLSuiteTest.java</exclude>
<exclude>**/TeradataSuiteTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<reporting>

View File

@ -16,11 +16,9 @@ package com.mysema.query.sql.codegen;
import javax.tools.JavaCompiler;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@ -49,6 +47,10 @@ public class MetaDataExporterTest {
private boolean schemaToPackage = false;
private DatabaseMetaData metadata;
private JavaCompiler compiler = new SimpleCompiler();
@BeforeClass
public static void setUpClass() throws ClassNotFoundException, SQLException{
Class.forName("org.h2.Driver");
@ -126,6 +128,7 @@ public class MetaDataExporterTest {
@Before
public void setUp() throws ClassNotFoundException, SQLException {
statement = connection.createStatement();
metadata = connection.getMetaData();
}
@After
@ -139,7 +142,6 @@ public class MetaDataExporterTest {
private String beanPackageName = null;
@Test
public void NormalSettings_Repetition() throws SQLException {
test("Q", "", "", "", defaultNaming, "target/1", false, false, false);
@ -156,20 +158,21 @@ public class MetaDataExporterTest {
@Test
public void Multiple() throws SQLException {
// TODO : refactor this to use new JUnit constructs
List<String> emptyString = Collections.singletonList("");
boolean[] trueAndFalse = new boolean[]{true, false};
int counter = 0;
for (String namePrefix : Arrays.asList("", "Q", "Query")) {
for (String nameSuffix : Arrays.asList("", "Type")) {
for (String beanPrefix : Arrays.asList("", "Bean")) {
for (String beanSuffix : Arrays.asList("", "Bean")) {
for (NamingStrategy ns : Arrays.asList(defaultNaming, originalNaming)) {
for (boolean withBeans : trueAndFalse) {
for (boolean withInnerClasses : trueAndFalse) {
for (boolean schemaToPackage : trueAndFalse) {
for (boolean exportColumns : trueAndFalse) {
for (String beanPackage : Arrays.asList("test2", null)) {
for (Serializer beanSerializer : BEAN_SERIALIZERS) {
for (boolean withOriginalPositioning : trueAndFalse) {
for (NamingStrategy ns : Arrays.asList(defaultNaming, originalNaming)) {
for (String namePrefix : Arrays.asList("", "Q", "Query")) {
for (String nameSuffix : Arrays.asList("", "Type")) {
for (String beanPrefix : withBeans ? Arrays.asList("", "Bean") : emptyString) {
for (String beanSuffix : withBeans ? Arrays.asList("", "Bean") : emptyString) {
for (String beanPackage : withBeans ? Arrays.asList("test2", null) : emptyString) {
for (Serializer beanSerializer : BEAN_SERIALIZERS) {
counter++;
this.beanPackageName = beanPackage;
this.schemaToPackage = schemaToPackage;
@ -190,7 +193,7 @@ public class MetaDataExporterTest {
exporter.setNamingStrategy(new DefaultNamingStrategy());
exporter.setBeanSerializer(new BeanSerializer());
exporter.setBeanPackageName("test2");
exporter.export(connection.getMetaData());
exporter.export(metadata);
assertTrue(new File("target/7/test/QDateTest.java").exists());
assertTrue(new File("target/7/test2/DateTest.java").exists());
@ -202,7 +205,7 @@ public class MetaDataExporterTest {
exporter.setSchemaPattern("PUBLIC");
exporter.setPackageName("test");
exporter.setTargetFolder(new File("target/8"));
exporter.export(connection.getMetaData());
exporter.export(metadata);
assertTrue(new File("target/8/test/QDateTest.java").exists());
}
@ -214,7 +217,7 @@ public class MetaDataExporterTest {
exporter.setTableNamePattern("RESERVED,UNDERSCORE,BEANGEN1");
exporter.setPackageName("test");
exporter.setTargetFolder(new File("target/82"));
exporter.export(connection.getMetaData());
exporter.export(metadata);
assertTrue(new File("target/82/test/QBeangen1.java").exists());
assertTrue(new File("target/82/test/QReserved.java").exists());
@ -230,7 +233,7 @@ public class MetaDataExporterTest {
exporter.setNamePrefix("");
exporter.setNameSuffix("Type");
exporter.setTargetFolder(new File("target/9"));
exporter.export(connection.getMetaData());
exporter.export(metadata);
assertTrue(new File("target/9/test/DateTestType.java").exists());
}
@ -244,7 +247,7 @@ public class MetaDataExporterTest {
exporter.setNameSuffix("Type");
exporter.setTargetFolder(new File("target/10"));
exporter.setExportForeignKeys(false);
exporter.export(connection.getMetaData());
exporter.export(metadata);
assertTrue(new File("target/10/test/DateTestType.java").exists());
}
@ -258,7 +261,7 @@ public class MetaDataExporterTest {
exporter.setBeanPrefix("Bean");
exporter.setBeanSerializer(new BeanSerializer());
exporter.setTargetFolder(new File("target/a"));
exporter.export(connection.getMetaData());
exporter.export(metadata);
assertTrue(new File("target/a/test/DateTest.java").exists());
assertTrue(new File("target/a/test/BeanDateTest.java").exists());
@ -273,7 +276,7 @@ public class MetaDataExporterTest {
exporter.setBeanSuffix("Bean");
exporter.setBeanSerializer(new BeanSerializer());
exporter.setTargetFolder(new File("target/b"));
exporter.export(connection.getMetaData());
exporter.export(metadata);
assertTrue(new File("target/b/test/DateTest.java").exists());
assertTrue(new File("target/b/test/DateTestBean.java").exists());
@ -312,9 +315,8 @@ public class MetaDataExporterTest {
if (withOrdinalPositioning) {
exporter.setColumnComparatorClass(OrdinalPositionComparator.class);
}
exporter.export(connection.getMetaData());
exporter.export(metadata);
JavaCompiler compiler = new SimpleCompiler();
Set<String> classes = exporter.getClasses();
int compilationResult = compiler.run(null, System.out, System.err,
classes.toArray(new String[classes.size()]));

View File

@ -13,6 +13,9 @@
*/
package com.mysema.query;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mysema.query.QueryFlag.Position;
import com.mysema.query.sql.SQLSubQuery;
import com.mysema.query.sql.dml.DefaultMapper;
@ -34,10 +37,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import java.sql.ResultSet;
import java.sql.SQLException;
import static com.mysema.query.Constants.survey;
import static com.mysema.query.Constants.survey2;
import static com.mysema.query.Target.*;
@ -84,6 +83,10 @@ public class InsertBase extends AbstractBaseTest {
assertEquals(Integer.valueOf(2), result.get(2, Integer.class));
DateTime dateTime = result.get(dateTimeProperty);
if (target == CUBRID) {
// XXX Cubrid adds random milliseconds for some reason
dateTime = dateTime.withMillisOfSecond(0);
}
assertEquals(localDate.toDateTimeAtStartOfDay(), dateTime);
}

View File

@ -13,13 +13,10 @@
*/
package com.mysema.query.sql;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import java.util.TimeZone;
import com.mysema.query.BooleanBuilder;
import com.mysema.query.QueryMetadata;
@ -36,6 +33,8 @@ import com.mysema.query.types.expr.Wildcard;
import com.mysema.query.types.path.NumberPath;
import com.mysema.query.types.path.PathBuilder;
import com.mysema.query.types.path.StringPath;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class SQLSerializerTest {
@ -289,7 +288,8 @@ public class SQLSerializerTest {
SQLSerializer serializer = new SQLSerializer(Configuration.DEFAULT);
serializer.setUseLiterals(true);
Expression<?> expr = SQLExpressions.datediff(DatePart.year, employee.datefield, new java.sql.Date(0));
int offset = TimeZone.getDefault().getRawOffset();
Expression<?> expr = SQLExpressions.datediff(DatePart.year, employee.datefield, new java.sql.Date(-offset));
serializer.handle(expr);
assertEquals("datediff('year',EMPLOYEE.DATEFIELD,(date '1970-01-01'))", serializer.toString());
}