Skip to content

Commit

Permalink
Merge branch 'ysobj-bugfix-return-object-as-maps-value'
Browse files Browse the repository at this point in the history
  • Loading branch information
takezoe committed Nov 4, 2018
2 parents b011efe + 6a99621 commit 0f303cb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/miragesql/miragesql/SqlManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.miragesql.miragesql.type.IntegerValueType;
import com.miragesql.miragesql.type.LongPrimitiveValueType;
import com.miragesql.miragesql.type.LongValueType;
import com.miragesql.miragesql.type.ObjectValueType;
import com.miragesql.miragesql.type.ShortPrimitiveValueType;
import com.miragesql.miragesql.type.ShortValueType;
import com.miragesql.miragesql.type.SqlDateValueType;
Expand Down Expand Up @@ -96,6 +97,7 @@ public SqlManagerImpl(){
addValueType(new EnumStringValueType());
addValueType(new EnumOrdinalValueType());
addValueType(new EnumOneBasedOrdinalValueType());
addValueType(new ObjectValueType());
// addValueType(new com.miragesql.miragesql.type.DefaultValueType());

setDialect(dialect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public MapBeanDescImpl(Map<String, Object> map){
/**{@inheritDoc}*/
public PropertyDesc getPropertyDesc(String name) {
if(this.map == null){
return new MapPropertyDescImpl(name, "");
return new MapPropertyDescImpl(name, new Object());
}
return this.propertyMap.get(name);
}
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/com/miragesql/miragesql/type/ObjectValueType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.miragesql.miragesql.type;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ObjectValueType extends AbstractValueType<Object> {

public ObjectValueType() {
super(Object.class);
}

public Object get(Class<? extends Object> type, ResultSet rs, int columnIndex) throws SQLException {
return rs.getObject(columnIndex);
}

public Object get(Class<? extends Object> type, ResultSet rs, String columnName) throws SQLException {
return rs.getObject(columnName);
}

public void set(Class<? extends Object> type, PreparedStatement stmt, Object value, int index) throws SQLException {
if (value == null) {
setNull(type, stmt, index);
} else {
stmt.setObject(index, value);
}
}

public Object get(Class<? extends Object> type, CallableStatement cs, int index) throws SQLException {
return cs.getObject(index);
}

public Object get(Class<? extends Object> type, CallableStatement cs, String parameterName) throws SQLException {
return cs.getObject(parameterName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public void testGetSingleResultByMap() throws Exception {

assertEquals("Mirage in Action", map.get("bookName"));
assertEquals("Naoki Takezoe", map.get("author"));
assertEquals("20", map.get("price"));
assertEquals(Integer.class, map.get("price").getClass());
assertEquals(20, map.get("price"));
}

public void testSelectIn() throws Exception {
Expand Down

0 comments on commit 0f303cb

Please sign in to comment.