'개발 > iOS' 카테고리의 다른 글
[iOS] UITableView Cell 변경 animation (0) | 2011.04.29 |
---|---|
[IOS] KEYBOARD 화면 이동 (0) | 2010.12.13 |
[XCODE] Breakpoint가 안먹을 때 (0) | 2010.11.28 |
[XCODE] 메모리 관리 규칙 (0) | 2010.11.16 |
[XCODE] Redefine NSLog (0) | 2010.11.16 |
[iOS] UITableView Cell 변경 animation (0) | 2011.04.29 |
---|---|
[IOS] KEYBOARD 화면 이동 (0) | 2010.12.13 |
[XCODE] Breakpoint가 안먹을 때 (0) | 2010.11.28 |
[XCODE] 메모리 관리 규칙 (0) | 2010.11.16 |
[XCODE] Redefine NSLog (0) | 2010.11.16 |
[IOS] KEYBOARD 화면 이동 (0) | 2010.12.13 |
---|---|
[IOS] image size (0) | 2010.11.28 |
[XCODE] 메모리 관리 규칙 (0) | 2010.11.16 |
[XCODE] Redefine NSLog (0) | 2010.11.16 |
[XCODE] DEBUGING 팁 (0) | 2010.11.16 |
[Mac] MobileBackups 비 활성화 (0) | 2012.09.22 |
---|---|
[Mac] Clearing Finder’s ‘Open With’ Menu in Mac OS X Mountain Lion (0) | 2012.09.17 |
[Mac] USB에 이미지 장치(iphone 등) 연결시 자동 실행 방지 (0) | 2011.12.12 |
[Mac] 한글 키보드 변경 (0) | 2011.11.24 |
[Mac] itunes 한글 깨질때 (0) | 2010.11.02 |
규칙1]
- alloc, copy, new 를 포함하는 메서드는 retain된 객체를 리턴한다.
이 리턴되는 객처는 retain되어 있기 때문에 반드시 release를 호출해야 한다.
규칙2]
- 자신이 retain 호출했다면 반드시 release를호출해야 한다.
규칙3]
- 클래스메서드가 객체를 생성해 줄 때는 autorelease 객체를 리턴한다.
그렇기 때문에 별도의 release를 호출하지 않아도 오토릴리즈 풀이 자동으로 release를 호출한다.
하지만, 이 객체에 대한 retain을 호출했다면 같은 횟수만큼 release를 호출해야 한다.
예)
NSString *pStr = [NSString stringWithString:@"Test"];
규칙4]
- 배열, 딕셔너리 등의 자료구조 클래스는 추가된 객체를 retain하고, 항목을 제거할 때 release를 한다.
NSArray, NSDictionary, NSSet등의 자료구조 클래스는 항목으로 추가되는 객체에 retain을 한 번 호출한다.
그리고 객체가 포함 객체에서 제거될 때 release를 호출한다. 그렇기 때문에 별도의 retain을 해 줄 필요는 없다.
규칙5]
- retain 속성을 갖는 접근자의 경우(@property (retain) ... ) 객체가 설정될 때 자동으로 retain 된다.
예)
myImage = [[UIImage alloc] init]; // myImage retain '1'
self.userImage = myImage; // myImage retain '2'
[myImage release]; // myImage retain '1'
...
self.userImage = myImage2; // myImage retain '0'
규칙 6]
- 메서드가 리턴하는 객체는 autorelease을 하고 리턴하도록 한다.
예)
- (NSString *) findTopPlayer{
NSString *ret = [[top objectAtIndex:0] copy];
[ret autorelease];
return ret;
}
규칙7]
- IBOutlet으로 연결되는 객체는 retain 되어 있다. 따라서, 반드시 release를 호출해야 한다.
예)
IBOutlet UIButton *button;
....
- (void) dealloc{
[button release];
[super dealloc];
}
[IOS] image size (0) | 2010.11.28 |
---|---|
[XCODE] Breakpoint가 안먹을 때 (0) | 2010.11.28 |
[XCODE] Redefine NSLog (0) | 2010.11.16 |
[XCODE] DEBUGING 팁 (0) | 2010.11.16 |
[IOS] Core Data에서 SQLite 사용하기 (0) | 2010.11.01 |
x#ifdef DEBUG #define NSLog(fmt, ...) NSLog((@"%s[Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); #else #define NSLog(...) #endif
[IOS] image size (0) | 2010.11.28 |
---|---|
[XCODE] Breakpoint가 안먹을 때 (0) | 2010.11.28 |
[XCODE] 메모리 관리 규칙 (0) | 2010.11.16 |
[XCODE] DEBUGING 팁 (0) | 2010.11.16 |
[IOS] Core Data에서 SQLite 사용하기 (0) | 2010.11.01 |
NSZombieEnabled=YESCFZombieLevel=16
[IOS] image size (0) | 2010.11.28 |
---|---|
[XCODE] Breakpoint가 안먹을 때 (0) | 2010.11.28 |
[XCODE] 메모리 관리 규칙 (0) | 2010.11.16 |
[XCODE] Redefine NSLog (0) | 2010.11.16 |
[IOS] Core Data에서 SQLite 사용하기 (0) | 2010.11.01 |
[LINUX] Subversion설치 (0) | 2011.02.07 |
---|---|
[LINUX] CentOS 5.5에 CMake 설치 (0) | 2010.12.20 |
[LINUX] FIND AND REPLACE with SED (0) | 2010.12.13 |
[LINUX] HDD 복사 (0) | 2010.10.28 |
[LINUX] TIME SYNC (0) | 2010.10.28 |
vi /Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse.ini
showsplash org.eclipse.platform
--launcher.XXMaxPermSize 512m
-vmargs
-Xms40m
-Xmx512m
-XX:MaxPermSize=512m
-Xms40m
-Xmx512m
[WAS] Occurs when an exception is thrown in the contextInitialized method of a ServletContextListener (0) | 2011.09.27 |
---|---|
[JAVA] Spring Framework Annotation-based Controller Interceptor Configuration (0) | 2011.09.07 |
[JAVA] DWR (0) | 2010.11.23 |
12.5. iBATIS SQL Maps
The iBATIS support in the Spring Framework much resembles the JDBC / Hibernate support in that it supports the same template style programming and just as with JDBC or Hibernate, the iBATIS support works with Spring's exception hierarchy and let's you enjoy the all IoC features Spring has.
Transaction management can be handled through Spring's standard facilities. There are no special transaction strategies for iBATIS, as there is no special transactional resource involved other than a JDBCConnection. Hence, Spring's standard JDBC DataSourceTransactionManager orJtaTransactionManager are perfectly sufficient.
Note |
|
Spring does actually support both iBatis 1.x and 2.x. However, only support for iBatis 2.x is actually shipped with the core Spring distribution. The iBatis 1.x support classes were moved to the Spring Modules project as of Spring 2.0, and you are directed there for documentation. |
12.5.1. Setting up the SqlMapClient
If we want to map the previous Account class with iBATIS 2.x we need to create the following SQL map'Account.xml':
<sqlMap namespace="Account">
<resultMap id="result" class="examples.Account">
<result property="name" column="NAME" columnIndex="1"/>
<result property="email" column="EMAIL" columnIndex="2"/>
</resultMap>
<select id="getAccountByEmail" resultMap="result">
select ACCOUNT.NAME, ACCOUNT.EMAIL
from ACCOUNT
where ACCOUNT.EMAIL = #value#
</select>
<insert id="insertAccount">
insert into ACCOUNT (NAME, EMAIL) values (#name#, #email#)
</insert>
</sqlMap>
The configuration file for iBATIS 2 looks like this:
<sqlMapConfig>
<sqlMap resource="example/Account.xml"/>
</sqlMapConfig>
Remember that iBATIS loads resources from the class path, so be sure to add the 'Account.xml' file to the class path.
We can use the SqlMapClientFactoryBean in the Spring container. Note that with iBATIS SQL Maps 2.x, the JDBC DataSource is usually specified on the SqlMapClientFactoryBean, which enables lazy loading.
<beans>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="WEB-INF/sqlmap-config.xml"/>
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
12.5.2. Using SqlMapClientTemplate and SqlMapClientDaoSupport
The SqlMapClientDaoSupport class offers a supporting class similar to the SqlMapDaoSupport. We extend it to implement our DAO:
public class SqlMapAccountDao extends SqlMapClientDaoSupport implements AccountDao {
public Account getAccount(String email) throws DataAccessException {
return (Account) getSqlMapClientTemplate().queryForObject("getAccountByEmail", email);
}
public void insertAccount(Account account) throws DataAccessException {
getSqlMapClientTemplate().update("insertAccount", account);
}
}
In the DAO, we use the pre-configured SqlMapClientTemplate to execute the queries, after setting up the SqlMapAccountDao in the application context and wiring it with our SqlMapClient instance:
<beans>
<bean id="accountDao" class="example.SqlMapAccountDao">
<property name="sqlMapClient" ref="sqlMapClient"/>
</bean>
</beans>
Note that a SqlMapTemplate instance could also be created manually, passing in the SqlMapClient as constructor argument. The SqlMapClientDaoSupport base class simply pre-initializes aSqlMapClientTemplate instance for us.
The SqlMapClientTemplate also offers a generic execute method, taking a customSqlMapClientCallback implementation as argument. This can, for example, be used for batching:
public class SqlMapAccountDao extends SqlMapClientDaoSupport implements AccountDao {
public void insertAccount(Account account) throws DataAccessException {
getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
executor.startBatch();
executor.update("insertAccount", account);
executor.update("insertAddress", account.getAddress());
executor.executeBatch();
}
});
}
}
In general, any combination of operations offered by the native SqlMapExecutor API can be used in such a callback. Any SQLException thrown will automatically get converted to Spring's genericDataAccessException hierarchy.
12.5.3. Implementing DAOs based on plain iBATIS API
DAOs can also be written against plain iBATIS API, without any Spring dependencies, directly using an injected SqlMapClient. A corresponding DAO implementation looks like as follows:
public class SqlMapAccountDao implements AccountDao {
private SqlMapClient sqlMapClient;
public void setSqlMapClient(SqlMapClient sqlMapClient) {
this.sqlMapClient = sqlMapClient;
}
public Account getAccount(String email) {
try {
return (Account) this.sqlMapClient.queryForObject("getAccountByEmail", email);
}
catch (SQLException ex) {
throw new MyDaoException(ex);
}
}
public void insertAccount(Account account) throws DataAccessException {
try {
this.sqlMapClient.update("insertAccount", account);
}
catch (SQLException ex) {
throw new MyDaoException(ex);
}
}
}
In such a scenario, the SQLException thrown by the iBATIS API needs to be handled in a custom fashion: usually, wrapping it in your own application-specific DAO exception. Wiring in the application context would still look like before, due to the fact that the plain iBATIS-based DAO still follows the Dependency Injection pattern:
<beans>
<bean id="accountDao" class="example.SqlMapAccountDao">
<property name="sqlMapClient" ref="sqlMapClient"/>
</bean>
</beans>
[기타] How To Enable “Click To Play” For Plug-ins And Flash In Google Chrome (0) | 2012.01.09 |
---|---|
[기타] VMWare SCSI warning message 해결 방법 (0) | 2011.11.23 |
[기타] HTTP1.0-1.1 Protocol Massage & Header 구성요소 (0) | 2011.11.18 |
[기타] DNS cache 삭제 (0) | 2011.08.28 |
[LIB] gSoap (0) | 2011.01.27 |