fixed scala tests

This commit is contained in:
Timo Westkämper 2011-05-17 11:22:43 +00:00
parent f9cccbee78
commit be5dfbfd0f
5 changed files with 64 additions and 31 deletions

View File

@ -46,15 +46,20 @@ class JPAQueryTest {
}
@Test
def Various {
// list
def List {
query from (person) where (person.firstName $like "Rob%") list (person)
// unique result
query from (person) where (person.firstName $like "Rob%") unique (person)
// long where
query from (person) where (person.firstName $like "Rob%", person.lastName $like "An%") list (person)
}
@Test
def Unique_Result {
query from (person) where (person.firstName $like "Rob%") unique (person)
}
@Test
def Long_Where {
query from (person) where (person.firstName $like "Rob%", person.lastName $like "An%") list (person)
}
@Test
def Complex {
query from person where ((person.firstName $like "An%") $and (person.lastName $isNotNull)) list person

View File

@ -124,8 +124,9 @@ class JDBCIntegrationTest {
val s = new Survey()
s.name = "XXX"
val count = insert(survey) populate(s) execute()
assertTrue(count > 0)
val id = insert(survey) populate(s) executeWithKey(survey.id)
val sNew = query from survey where (survey.id === id) uniqueResult (survey)
assertEquals(s.name, sNew.name)
}
@Test
@ -139,6 +140,9 @@ class JDBCIntegrationTest {
val count = update(survey) populate(s) execute()
assertTrue(count > 0)
val sNew = query from survey where (survey.id === id) uniqueResult (survey)
assertEquals(s.name, sNew.name)
}
@Test

View File

@ -23,7 +23,7 @@ class QSurvey(cl: Class[_ <: Survey], md: PathMetadata[_]) extends RelationalPat
val name = createString("NAME")
val sysIdx54: PrimaryKey[Survey] = createPrimaryKey(id, name);
val sysIdx54: PrimaryKey[Survey] = createPrimaryKey(id);
}

View File

@ -6,6 +6,7 @@
package com.mysema.query.sql.dml;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -15,11 +16,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.apache.commons.collections15.BeanMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -351,18 +350,31 @@ public class SQLInsertClause extends AbstractSQLClause implements InsertClause<S
@SuppressWarnings("unchecked")
public SQLInsertClause populate(Object bean) {
try {
BeanMap map = new BeanMap(bean);
for (Map.Entry entry : map.entrySet()){
String property = entry.getKey().toString();
if (!property.equals("class")){
Field field = entity.getClass().getDeclaredField(property);
Class<?> beanClass = bean.getClass();
for (Field beanField : beanClass.getDeclaredFields()) {
if (!Modifier.isStatic(beanField.getModifiers())) {
Field field = entity.getClass().getDeclaredField(beanField.getName());
field.setAccessible(true);
Path path = (Path<?>) field.get(entity);
if (entry.getValue() != null) {
set(path, entry.getValue());
}
beanField.setAccessible(true);
Object propertyValue = beanField.get(bean);
if (propertyValue != null) {
set(path, propertyValue);
}
}
}
// BeanMap map = new BeanMap(bean);
// for (Map.Entry entry : map.entrySet()){
// String property = entry.getKey().toString();
// if (!property.equals("class")){
// Field field = entity.getClass().getDeclaredField(property);
// field.setAccessible(true);
// Path path = (Path<?>) field.get(entity);
// if (entry.getValue() != null) {
// set(path, entry.getValue());
// }
// }
// }
return this;
} catch (SecurityException e) {
throw new QueryException(e);

View File

@ -6,6 +6,7 @@
package com.mysema.query.sql.dml;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
@ -13,9 +14,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections15.BeanMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -228,18 +227,31 @@ public class SQLUpdateClause extends AbstractSQLClause implements UpdateClause<
Collection<? extends Path<?>> primaryKeyColumns = entity.getPrimaryKey() != null
? entity.getPrimaryKey().getLocalColumns()
: Collections.<Path<?>>emptyList();
BeanMap map = new BeanMap(bean);
for (Map.Entry entry : map.entrySet()){
String property = entry.getKey().toString();
if (!property.equals("class")){
Field field = entity.getClass().getDeclaredField(property);
Class<?> beanClass = bean.getClass();
for (Field beanField : beanClass.getDeclaredFields()) {
if (!Modifier.isStatic(beanField.getModifiers())) {
Field field = entity.getClass().getDeclaredField(beanField.getName());
field.setAccessible(true);
Path path = (Path<?>) field.get(entity);
if (!primaryKeyColumns.contains(path)){
set(path, entry.getValue());
}
}
}
if (!primaryKeyColumns.contains(path)) {
beanField.setAccessible(true);
Object propertyValue = beanField.get(bean);
set(path, propertyValue);
}
}
}
// BeanMap map = new BeanMap(bean);
// for (Map.Entry entry : map.entrySet()){
// String property = entry.getKey().toString();
// if (!property.equals("class")){
// Field field = entity.getClass().getDeclaredField(property);
// field.setAccessible(true);
// Path path = (Path<?>) field.get(entity);
// if (!primaryKeyColumns.contains(path)){
// set(path, entry.getValue());
// }
// }
// }
return this;
} catch (SecurityException e) {
throw new QueryException(e);