nutzam/nutz — Issue #171: dao set,list,map对于String类型的支持
Author: enzozhong
Created: 2012-02-29 23:45:20+00:00
State: open

public class Wire {

@Id
private Long wireId;
@Column
private Map map;
}

Dao dao = new NutIoc( new JsonLoader( "dao.json" ) ).get( Dao.class, "dao" );
dao.create( Wire.class, true );
Map map = new HashMap();
map.put( 1, "string" );

Wire wire = new Wire();
wire.setMap( map );

System.out.println( wire );
wire = dao.insert( wire );
wire = dao.fetch( wire.getClass(), wire.getWireId() );
System.out.println( wire );

2012-03-01 00:41:00 WARN [main] !!You are using default SystemLog! Don't use it in Production environment!!
2012-03-01 00:41:00 DEBUG [main] Loaded 8 bean define from path=[dao.json]
2012-03-01 00:41:00 DEBUG [main] Get 'dao'
2012-03-01 00:41:00 DEBUG [main]	>> Load definition
2012-03-01 00:41:00 DEBUG [main] Loading define for name=dao
2012-03-01 00:41:00 DEBUG [main]	>> Make...'dao'
2012-03-01 00:41:00 DEBUG [main] class org.nutz.dao.impl.NutDao , no config to enable AOP.
2012-03-01 00:41:00 DEBUG [main] Save object 'dao' to [app]
2012-03-01 00:41:00 DEBUG [main] Get 'dataSource'
2012-03-01 00:41:00 DEBUG [main]	>> Load definition
2012-03-01 00:41:00 DEBUG [main] Loading define for name=dataSource
2012-03-01 00:41:00 DEBUG [main] Scan Resource by org.nutz.resource.impl.LocalResourceScan@dc6180
2012-03-01 00:41:00 DEBUG [main] Scan resources in JarFile( /D:/App/lib/Nutz/nutz-1.b.42-jdk6.jar ) by regex( ^.+[.]class$ ) base on src ( org/nutz/castor/castor/ )
2012-03-01 00:41:00 DEBUG [main] Found 79 resources in JarFile( /D:/App/lib/Nutz/nutz-1.b.42-jdk6.jar ) by regex( ^.+[.]class$ ) base on src ( org/nutz/castor/castor/ )
2012-03-01 00:41:00 DEBUG [main] Using 78 castor for Castors
2012-03-01 00:41:00 DEBUG [main]	>> Make...'dataSource'
2012-03-01 00:41:00 DEBUG [main] class com.mchange.v2.c3p0.ComboPooledDataSource , no config to enable AOP.
2012-03-01 00:41:00 DEBUG [main] Save object 'dataSource' to [app]
三月 01, 2012 12:41:00 上午 com.mchange.v2.log.MLog
信息: MLog clients using java 1.4+ standard logging.
三月 01, 2012 12:41:00 上午 com.mchange.v2.c3p0.C3P0Registry banner
信息: Initializing c3p0-0.9.1 [built 16-January-2007 14:46:42; debug? true; trace: 10]
2012-03-01 00:41:01 DEBUG [main] Get 'dataSource'
2012-03-01 00:41:01 INFO [main] Init file-pool by: ~/.nutz/tmp/dao/ [2000]
2012-03-01 00:41:01 DEBUG [main] file-pool.home: 'C:\Users\EnzoZhong\.nutz\tmp\dao'
2012-03-01 00:41:01 INFO [main] file-pool.cursor: 0
三月 01, 2012 12:41:01 上午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
信息: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1bwm5fm8l1kgl5cttz46up|1404e39, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1bwm5fm8l1kgl5cttz46up|1404e39, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://127.0.0.1:3306/enzozhong?characterEncoding=utf8, lastAcquisitionFailureDefaultUser -> null, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
2012-03-01 00:41:01 DEBUG [main] take field 'map(java.util.Map)'(e.z.tuan.dao.system.Wire) as VARCHAR(50)
2012-03-01 00:41:01 DEBUG [main] DROP TABLE d2s_dao_wire
2012-03-01 00:41:01 DEBUG [main] CREATE TABLE d2s_dao_wire(
wireId BIGINT(64) NOT NULL AUTO_INCREMENT,
map VARCHAR(50),
PRIMARY KEY (wireId)
) ENGINE=InnoDB CHARSET=utf8
Wire{wireId=null, map={1=string}}
2012-03-01 00:41:01 DEBUG [main] INSERT INTO d2s_dao_wire(map) VALUES(?)
| 1 |
|----------------------|
| {
"1" :"string"
} |
For example:> "INSERT INTO d2s_dao_wire(map) VALUES('{1=string}') "
2012-03-01 00:41:01 DEBUG [main] SELECT MAX(wireId) AS wireId FROM d2s_dao_wire
2012-03-01 00:41:01 DEBUG [main] SELECT * FROM d2s_dao_wire WHERE wireId=?
| 1 |
|---|
| 1 |
For example:> "SELECT * FROM d2s_dao_wire WHERE wireId=1"
2012-03-01 00:41:01 INFO [main] Fail to set value by field
org.nutz.castor.FailToCastObjectException: Fail to cast from to for {{1=string}} because:
JsonException:!Json syntax error nearby [row:0,col:9 char '￿'], reason: 'Unexpected End'
Exception in thread "main" org.nutz.dao.DaoException: java.lang.RuntimeException: Fail to set '{1=string}'[ null ] to field e.z.tuan.dao.system.Wire.'map' because [org.nutz.json.JsonException: !Json syntax error nearby [row:0,col:9 char '￿'], reason: 'Unexpected End']: !Json syntax error nearby [row:0,col:9 char '￿'], reason: 'Unexpected End'
at org.nutz.castor.Castors.cast(Castors.java:299	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:74)
)
at org.nutz.castor.Castors.castTo(Castors.java:349	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:178)
)
at org.nutz.dao.impl.NutDao.fetch(NutDao.java:429)
at org.nutz.lang.inject.InjectByField.inject(InjectByField.java:24)
at NewMain.main(NewMain.java:34)
at org.nutz.dao.impl.entity.field.AbstractEntityField.setValue(AbstractEntityField.java:53)
at org.nutz.dao.impl.entity.field.NutMappingField.injectValue(NutMappingField.java:62)
at org.nutz.dao.impl.entity.NutEntity.getObject(Caused by: java.lang.RuntimeException: Fail to set '{1=string}'[ null ] to field e.z.tuan.dao.system.Wire.'map' because [org.nutz.json.JsonException: !Json syntax error nearby [row:0,col:9 char '￿'], reason: 'Unexpected End']: !Json syntax error nearby [row:0,col:9 char '￿'], reason: 'Unexpected End'
NutEntity.java:196)
at org.nutz.dao.impl.sql.pojo.PojoFetchEntityCallback.invoke(PojoFetchEntityCallback.java:14)
at org.nutz.lang.Lang.makeThrow(Lang.java:84)
at org.nutz.dao.impl.jdbc.NutPojo.onAfter(NutPojo.java:108)
at org.nutz.lang.inject.InjectByField.inject(InjectByField.java:30)
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:102)
at org.nutz.dao.impl.entity.field.AbstractEntityField.setValue(AbstractEntityField.java:53)
at org.nutz.dao.impl.DaoSupport$2.invoke(DaoSupport.java:186)
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:63	at org.nutz.dao.impl.entity.field.NutMappingField.injectValue(NutMappingField.java:62)
)
at org.nutz.dao.impl.entity.NutEntity.getObject(NutEntity.java:196)
at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:178)
at org.nutz.dao.impl.NutDao.fetch(NutDao.java:429)
at org.nutz.dao.impl.sql.pojo.PojoFetchEntityCallback.invoke(PojoFetchEntityCallback.java:14)
at NewMain.main(NewMain.java:34)
at org.nutz.dao.impl.jdbc.NutPojo.onAfter(NutPojo.java:108)
Caused by: org.nutz.json.JsonException: !Json syntax error nearby [row:0,col:9 char '￿'], reason: 'Unexpected End'
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:102)
at org.nutz.json.JsonCompile.unexpectedEnd(JsonCompile.java:411)
at org.nutz.dao.impl.DaoSupport$2.invoke(DaoSupport.java:186)
at org.nutz.json.JsonCompile.nextChar(JsonCompile.java:352)
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:63)
at org.nutz.json.JsonCompile.parseMapItem(	... 3 more
JsonCompile.java:294)
at org.nutz.json.JsonCompile.parseMap(JsonCompile.java:263)
at org.nutz.json.JsonCompile.parseFromHere(JsonCompile.java:63)
at org.nutz.json.JsonCompile.parse(JsonCompile.java:52)
at org.nutz.json.Json.fromJson(Json.java:64)
at org.nutz.castor.castor.String2Map.cast(String2Map.java:15)
at org.nutz.castor.castor.String2Map.cast(String2Map.java:10)
at org.nutz.castor.Castors.cast(Castors.java:293)
... 13 more

好郁闷噢，1.b.38到现在1.b42都还没有fix