22 Haziran 2017 Perşembe

Gateway

Giriş
Spring Integration projesinin bir parçası. Açıklaması şöyle
Any bidirectional, or request-reply, adapter is known as a Gateway.
Açıklaması şöyle
Whereas the JMS Channel Adapters are intended for unidirectional Messaging (send-only or receive-only), Spring Integration also provides inbound and outbound JMS Gateways for request/reply operations.


5 Haziran 2017 Pazartesi

SpringContext @ApplicationScope Anotasyonu - Bean'in Yaşamı Servlet'e Bağlıdır

Giriş
Web uygulamalarında kullanılır. Açıklaması şöyle
singleton (Default) Scopes a single bean definition to a single object instance per Spring IoC container.
prototype Scopes a single bean definition to any number of object instances.
request Scopes a single bean definition to the lifecycle of a single HTTP request; that is, each HTTP request has its own instance of a bean created off the back of a single bean definition. Only valid in the context of a web-aware Spring ApplicationContext.
session Scopes a single bean definition to the lifecycle of an HTTP Session. Only valid in the context of a web-aware Spring ApplicationContext.
globalSession Scopes a single bean definition to the lifecycle of a global HTTP Session. Typically only valid when used in a Portlet context. Only valid in the context of a web-aware Spring ApplicationContext.
application Scopes a single bean definition to the lifecycle of a ServletContext. Only valid in the context of a web-aware Spring ApplicationContext.
websocket Scopes a single bean definition to the lifecycle of a WebSocket. Only valid in the context of a web-aware Spring ApplicationContext.
@Scope Anotasyonu yazısına bakabilirsiniz.

Örnek
Şöyle yaparız.
@ApplicationScope
@Component
public class App {
    // ...
}

SqlSessionTemplate Sınıfı

Giriş
Şu satırı dahil ederiz
import org.mybatis.spring.SqlSessionTemplate;
Bu sınıf MyBatis projesine ait.

application.properties
Şöyle yaparız
spring.datasource.url=jdbc:mysql://localhost:3306/airportdb
spring.datasource.username=username
spring.datasource.password=passoword
spring.datasource.driver-class-name =com.mysql.jdbc.Driver

mybatis.configuration.map-underscore-to-camel-case = true
mybatis.configuration.defaultStatementTimeout = 10
DataMapper Örüntüsü
MyBatis "Patterns of Enterprise Application Architecture" kitabındaki DataMapper örüntüsünü kullanılır.

constructor
Şöyle yaparız.
@Autowired
private SqlSessionTemplate sqlSession;
delete metodu
Şöyle yaparız.
public Object delete(String queryId, Object params){
  return sqlSession.delete(queryId, params);
}
insert metodu
Şöyle yaparız.
public Object insert(String queryId, Object params){
  return sqlSession.insert(queryId, params);
}
update metodu
Şöyle yaparız.
public Object update(String queryId, Object params){
  return sqlSession.update(queryId, params);
}

selectList metodu
Şöyle yaparız.
@SuppressWarnings("rawtypes")
public List selectList(String queryId){
  return sqlSession.selectList(queryId);
}

@SuppressWarnings("rawtypes")
public List selectList(String queryId, Object params){
  return sqlSession.selectList(queryId,params);
}
selectOne metodu
Şöyle yaparız.
public Object selectOne(String queryId){
  return sqlSession.selectOne(queryId);
}

public Object selectOne(String queryId, Object params){
  return sqlSession.selectOne(queryId, params);
}