'Back-End'에 해당되는 글 135건

donaricano-btn

DataAccessLayer_2


1. NamedParameterJdbcTemplate

- SQL의 파라미터에 플레이스홀더(?마크)를 사용하지 않을 때 사용

- 파라미터의 순서를 맞출 필요가 없다

1_1 메소드 체인 사용 


- : 뒤의 문자열이 파라미터의 이름

- 개발자가 자유롭게 이름을 정할 수 있다

- MapSqlParameterSource를 이용함으로서 파라미터의 순서가 어긋날 위험성을 줄인다

1_2. 메소드 체인 사용 안함

 


2. 배치업데이트, 프로시저 콜

2_1.  배치 업데이트

- 많은 양의 레코드를 한번에 갱신하기 위한 것

1) batchUpdate()

A. jdbcTemplate

 

B. NamedParameterJdbcTemplate

 

- 두번째 인자가 배열이다

2_2. 프로시저 콜

- 데이터베이스에 준비된 스토어드 프로시저를 호출 할때 사용

Ex)

프로시저 이름 : CALC_PET_PRICE

IN 파라미터 : IN_PET_ID

OUT 파라미터 : OUT_PRICE

1) HSQLDB 데이터 베이스

 

2) ORACLE, SQL 서버..

 


3. 범용 데이터 엑세스 예외

- 스프링 JDBC에서만 사용되는 것이 아니라 스프링이 제동하는 데이터 엑세스 기능 전체에서 이용

- 독자적인 예외를 범용적 예외로 변환 함으로써 예외를 핸들링하는 클래스가 데이터 엑세스 기술에 의존하지 않아도 됨

- 스프링이 오류의 원인을 판단해 범용데이터로 변환하브로 SQLException을 분석할 필요 없다

3_1. 적용

1) Template 

- JdbcTemplate, NamedParameterJdbcTemplate을 사용하면 SQLException은 자동으로 적용된다

2) @Repository

- DAO클래스에 @Repository 애노테이션을 설정하고 Bean 정의파일에 아래 설정을 하면 적용됨

 


4. 데이터 소스

- 데이터 소스: 데이터 소스와의 접속 오브젝트인 Connection 오브젝트의 팩토리 이다

- Connection 오브젝트의 생애 주기는 데이터 소스에 맡겨져 있고, 일반 어플리케이션에서 커넥션 풀에 의해Connection 오브젝트를 돌려쓰는 구조로됨

4_1. 데이터 소스의 이용

1) dataSource 정의

 

2) 인젝션

 

or

 

4_2. 스프링이 제공하는 데이터 소스

    - 두 클래스 모두 테스트 용도로 만들어 졌으며 커넥션 풀을 지원하지 않는다

- 실제 현장에서 사용 안함

1) SingleConnectionDataSource

- 하나의 커넥션 오브젝트를 닫지 않고 다시 사용한다

- 테스트 케이스에서 커밋, 롤백하고 싶을 때 도움이 된다

2) DriverManagerDataSource

- 커넥션을 요청할 때 마다 커넥션 오브젝트를 생성해서 돌려준다

 

 

4_3. 서드파티가 제공하는 데이터 소스

- 대표적인 제품으로 DBCP(아파치) c3p0가 있다

1) DBCP

- 커넥션 수 지정가능 

 


4_4. 애플리케이션 서버가 제공하는 데이터 소스

- 보통 애플리케이션 서버 제품은 데이터 소스의 오브젝트 생성/관리 기능이 있

- 네이밍 서비스 이용

- JNDI를 이용하여 데이터 소스 오브젝트를 가져옴


4_1. JNDI를 이용하여 소스를 얻는 방법

1) JndiObjectFactoryBean

- 데이터 소스 JNDI 이름 : jdbc/MyDataSource

 

 

2) jee  스키마를 사용

- JndiObjectFactoryBean 보다 권장

 

3) @Resource 

  - 원래 스프링 독자적인 것이 아니지만 용도가 변경됨(@Autowired + @Qualifier)

 

 

'Back-End > SpringFrame_1' 카테고리의 다른 글

[Spring] BusinessLayer_2  (0) 2016.08.07
[Spring]BusinessLayer_1  (0) 2016.08.01
[Spring] DataAccessLayer_1  (0) 2016.07.25
[Spring] AOP_2  (0) 2016.07.20
[Spring] DI_2  (0) 2016.07.17
블로그 이미지

리딩리드

,

[Java] Static_2

Back-End/Java_1 2016. 7. 26. 18:22
donaricano-btn

Static_2

- The static keyword in java is used for memory management mainly

- It makes your program memory efficient


1) Static variable

- The static variable can be used to refer the common property of all objects 

- The static variable gets memory only once in class area at the time of class loading


1_1. Understanding problem without static variable


- Suppose there are 500 students in my college

- All instance data members will get memory each time when object is created

- If we make it static, college field will get memory only once


1_2. Example

 

1_3. Program Counter

1) Without static variable

 

- Since instance variable gets the memory at the time of object creation, each object will have the copy of the instance variable

- If it is incremented, it won't reflect to other objects

2) static variable

 

2) Static method

- A static method belongs to the class rather than object of class

- A static method can be invoked without the need for creating an instance of a class

- static method can access static data member and can change the value of it


2_1. Example

1) change

 

2) Calculate

 


3) Restriction

- The static method can not use non static data member or call non-static method directly

- this and super cannot be used in static context

 


 4) Why java main method is static?

Object is not required to call static method

- If it were non-static method, jvm create object first then call main() that will lead the problem of extra memory allocation


5) Java static block

- Is used to initialize the static data member

- It it executed before main method at the time of classloading

 


6) Can we execute a program without main() method?

- One of the way is static block but not in JDK 1.7

 

'Back-End > Java_1' 카테고리의 다른 글

[Java] Input by Scanner  (0) 2016.08.18
[Java] This keyword - to refer current class instance variable  (0) 2016.08.05
[Java] Constructor_2  (0) 2016.07.26
[Java] Method Overloading  (0) 2016.07.25
[Java] Object and Class  (0) 2016.06.27
블로그 이미지

리딩리드

,
donaricano-btn

Constructor_2

- Constructor is a special type of method that is used to initialize the object

- Constructor is invoked at the time of object creation


1. Rule

1) Constructor name must be same as its class name

2) Constructor must have no explicit return type


2. Type of constructor

1) Default constructor

2) Parameterized constructor


3. Default Constructor

3_1. Example


- If there is no constructor in a class, compiler automatically creates a default constructor


3_2. What is the purpose of default constructor?

- Default constructor provides the default values to the object like 0, null, etc

 


4. Parameterized Constructor

4_1. Why use parameterized constructor?

- Parameterized constructor is used to provide different values to the distinct objects

 


5. Copy Constructor

- There are many ways to copy the values of one object into another in java

1) By constructor

2) By assigning the values of one object into another

3) By clone() method of Object class


5_1. Example

 

'Back-End > Java_1' 카테고리의 다른 글

[Java] This keyword - to refer current class instance variable  (0) 2016.08.05
[Java] Static_2  (0) 2016.07.26
[Java] Method Overloading  (0) 2016.07.25
[Java] Object and Class  (0) 2016.06.27
[Java] Java OOPs Concepts  (0) 2016.06.27
블로그 이미지

리딩리드

,
donaricano-btn

DataAccessLayer_1

- 비즈니스 로직데이터베이스 접속같은 SQL발행분리하는것이다


1. DAO Pattern

- 데이터 베이스접속과 SQL 발행 같은 데이터 액세스 처리를 DAO라고 불리는 오브젝트로 분리

- 데이터 엑세스에 특화된 처리를 비즈니스 로직에 숨긴다. 

- 데이터 엑세스 방식이 변경되어도 DAO만 변경하면됨


2. 자바의 데이터 엑세스 기술과 스프링의 기능

1) 대표적인 데이터 엑세스 기술

- JDBC, Hibernate, MyBatis(iBatis), JPA, S2DAO ...

- 스프링은 기존의 다섯가지 데이터 엑세스 기술을 더욱 사용하기 쉽게한다


2) 스프링 기능을 이용하여 얻는 장점

- 데이터 엑세스 처리를 간결하게 기술할 수 있다

- 스프링이 제공하는 범용적이고 체계적인 데이터 엑세스 예외를 이용할 수 있다

- 스프링의 트랜젝션 기능을 이용할 수 있다



3. 스프링 JDBC

- 소스코드가 심플해 진다

- SQLException의 원인을 특정하는 처리도 필요없다


3_1. Template 클래스의 소스 단순화

1) JdbcTemplate class

- 메소드의 종류가 풍부

- 스프링 버전 1.0 부터 제공

2) NamedParameterJdbcTemplate

- SQL 파라미터에 임의의 이름을 붙여 SQL을 발행할 수 있다

- 스프링 버전 2.0 부터 제공

3) SimpleJdbcTemplate

- JdbcTemplate + NamedParameterJdbcTemplate

- 3.1 부터는 권장되지 않는다


3_2. 템플릿 클래스의 Bean 등록

1) Bean등록


2) 인젝션

 


3_3. SELECT문 - 도메인으로 변환하지 않을때

- 레코드의 수를 조회할 때 한 레코드안의 특정 컬럼 처럼 단순값을 가져올때


1) queryForInt, queryForLong

- 수치형 값을 가져올때

 

2) queryForObject

- 취득 결과가 문자열이나 날짜형일 때

 

 

3) queryForMap

- 레코드의 값을 가져옴

 

4) queryForList

- 여러 레코드의 Map 데이터를 가져옴

 

3_4. SELECT 문 - 도메인으로 변환할 때

1) queryForObject
- 한 레코드의 도메인을 가져옴

A. 익명의 클래스 사용

 

B. 익명의 클래스 사용 안함

 

2) query

- 여러 레코드의 오브젝트 가져옴

 

3) BeanPropertyRowMapper

- RowMapper 구현 클래스, 도메인을 자동으로 생성

- 내부에서 리플렉션을 사용 하므로 성능이 나쁘다

 

4) ResultSetExtractor

- 조인한 테이블의 여러 레코드를 가져오고 싶을 때

- 소스 코드가 복잡해진다

 


3_5. INSERT/UPDATE/DELETE 

1) update

- insert/update/delete 모두 update()로 사용가능

 

 

 


'Back-End > SpringFrame_1' 카테고리의 다른 글

[Spring]BusinessLayer_1  (0) 2016.08.01
[Spring] DataAccessLayer_2  (0) 2016.07.31
[Spring] AOP_2  (0) 2016.07.20
[Spring] DI_2  (0) 2016.07.17
[Spring] DI_1  (0) 2016.07.16
블로그 이미지

리딩리드

,