Skip to content

Commit

Permalink
Fix for mybatis#39. Objects with no properties should be considered new.
Browse files Browse the repository at this point in the history
  • Loading branch information
emacarron committed Dec 23, 2015
1 parent c550979 commit d455b3e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.Set;

/**
Expand Down Expand Up @@ -985,13 +986,15 @@ private List<ResultMapping> getResultMappingsForRowKey(ResultMap resultMap) {
}

private void createRowKeyForMappedProperties(ResultMap resultMap, ResultSetWrapper rsw, CacheKey cacheKey, List<ResultMapping> resultMappings, String columnPrefix) throws SQLException {
boolean hasSimpleProperties = false;
for (ResultMapping resultMapping : resultMappings) {
if (resultMapping.getNestedResultMapId() != null && resultMapping.getResultSet() == null) {
// Issue #392
final ResultMap nestedResultMap = configuration.getResultMap(resultMapping.getNestedResultMapId());
createRowKeyForMappedProperties(nestedResultMap, rsw, cacheKey, nestedResultMap.getConstructorResultMappings(),
prependPrefix(resultMapping.getColumnPrefix(), columnPrefix));
} else if (resultMapping.getNestedQueryId() == null) {
hasSimpleProperties = true;
final String column = prependPrefix(resultMapping.getColumn(), columnPrefix);
final TypeHandler<?> th = resultMapping.getTypeHandler();
List<String> mappedColumnNames = rsw.getMappedColumnNames(resultMap, columnPrefix);
Expand All @@ -1005,6 +1008,9 @@ private void createRowKeyForMappedProperties(ResultMap resultMap, ResultSetWrapp
}
}
}
if (!hasSimpleProperties && cacheKey.getUpdateCount() == 1) {
cacheKey.update(new Random()); // issue #39
}
}

private void createRowKeyForUnmappedProperties(ResultMap resultMap, ResultSetWrapper rsw, CacheKey cacheKey, String columnPrefix) throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2012 the original author or authors.
/**
* Copyright 2009-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2012 the original author or authors.
/**
* Copyright 2009-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2012 the original author or authors.
/**
* Copyright 2009-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -151,7 +151,6 @@ public void testGetPersonOrderedByItem() {
}
}

@Ignore
@Test //reopen issue 39? (not a bug?)
public void testGetPersonItemPairs(){
SqlSession sqlSession = sqlSessionFactory.openSession();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2012 the original author or authors.
/**
* Copyright 2009-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright 2009-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ibatis.submitted.nestedresulthandler;

/**
* Created by eyal on 12/9/2015.
*/
public class PersonItemPair {
private Person person;
private Item item;

public String toString(){
return new StringBuilder()
.append("PersonItemPair(")
.append(person)
.append(", ")
.append(item)
.append(" )")
.toString();
}

public Person getPerson() {
return person;
}

public void setPerson(Person person) {
this.person = person;
}

public Item getItem() {
return item;
}

public void setItem(Item item) {
this.item = item;
}
}

0 comments on commit d455b3e

Please sign in to comment.