"데이터 접근 객체"의 두 판 사이의 차이

(새 문서: ==개요== ;data access object; DAO *데이터베이스에 대한 추상화된 인터페이스를 제공하는 객체 *어떤 DB를 사용하든 일정한 조작방법을 제...)
 
잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
(사용자 2명의 중간 판 60개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
==개요==
;data access object; DAO
;data access object (DAO)
;데이터 접근 객체, 데이터 액세스 객체
*데이터<ref>주로 DB</ref> 입출력을 [[추상화]]
*[[데이터베이스]]에 대한 추상화된 인터페이스를 제공하는 [[객체]]
*[[데이터베이스]]에 대한 추상화된 인터페이스를 제공하는 [[객체]]
*데이터저장장치<ref>데이터베이스 또는 파일시스템</ref>에 대한 공통적인 인터페이스를 제공하는 객체
*어떤 DB를 사용하든 일정한 조작방법을 제공함
*어떤 DB를 사용하든 일정한 조작방법을 제공함
*[[비즈니스 로직]]과 데이터베이스 입출력 구현을 분리하는 [[디자인 패턴]]
*[[데이터접근계층]]<ref>[[J2EE 패턴]]에서는 [[통합 티어]]</ref>을 구성하는 객체 중 하나
*흔히 DB테이블 1개당 하나의 클래스 작성. [[CRUD]] 메소드 제공
==구현==
*데이터 요청시: DB커넥션 클래스(싱글턴 패턴 응용)로부터 getConnection<ref>커넥션 재사용함으로써 커넥션 비용 감소</ref>
*생성시 데이터소스를<ref name='ds'>어떤 DB에 접속해야 하는지에 대한 정보</ref>입력받는 경우도 있음
:[[인스턴스 생성]]시: 실제 커넥션을 맺는 것은 아니고, 데이터소스<ref name='ds' />만 저장
*(선택적) DAOFactory.getXxxDAO();로 생성([[팩토리 패턴]]에서 생성)<ref>http://www.oracle.com/technetwork/java/dataaccessobject-138824.html</ref>
==그림 예시==
;패턴 구조<ref>[[클래스 다이어그램]]</ref>
http://www.oracle.com/ocom/groups/public/@otn/documents/digitalasset/146804.jpg
;객체간 상호작용<ref>[[시퀀스 다이어그램]]</ref>
http://www.oracle.com/ocom/groups/public/@otn/documents/digitalasset/145996.jpg
==구현 예시 1 ==
<syntaxhighlight lang='java'>
public class Person {
  ... (생략)
}
</syntaxhighlight>
<syntaxhighlight lang='java'>
public class PersonDao {
  protected DataSource dataSource = null;
  public PersonDao(DataSource dataSource){
    this.dataSource = dataSource;
  }
  public Person readPerson(long personId){
    Connection connection = this.dataSource.getConnection();
    Person person = ... (생략)
    return person;
  }
}
</syntaxhighlight>
<syntaxhighlight lang='java'>
Person person = personDao.readPerson(123);
</syntaxhighlight>
==구현 예시 2 ==
<syntaxhighlight lang='PHP'>
class Employee {
  protected $id; 
  protected $name; 
  protected $birth; 
  function __contruct($row) {
    $this->id = $row['id'];
    $this->name = $row['name'];
    $this->birth = $row['birth'];
  }
}
</syntaxhighlight>
<syntaxhighlight lang='PHP'>
class EmployeeDao {
  protected $dataSource = null;
  function __construct(DataSource $dataSource) {
    $this->dataSource = $dataSource;
  }
  function readEmployee($employeeId) {
    $connection = $this->dataSource->getConnection();
    $row= $connection->query_row("SELECT * FROM employee WHERE id=?", $employeeId);
    return new Employee($row);
  }
}
</syntaxhighlight>


==같이 보기==
==같이 보기==
*[[DAOFactory]]
*[[DAO 메소드]]
*[[CRUD]]
*[[데이터접근계층 DAL]]
*[[데이터전달객체 DTO]]
*[[리파지토리 패턴]]
*[[객체]]
*[[객체]]
*[[추상화]]
*[[디자인 패턴]]
*[[J2EE 패턴]]
*[[JDBC]]
*[[안드로이드 ContentResolver]]
==주석==
<references/>


==참고 자료==
==참고==
*http://en.wikipedia.org/wiki/Data_access_object
*http://en.wikipedia.org/wiki/Data_access_object
*http://www.oracle.com/technetwork/java/dataaccessobject-138824.html


[[분류: 객체지향]]
[[분류: 객체]]

2022년 12월 16일 (금) 09:30 기준 최신판

1 개요[ | ]

data access object (DAO)
데이터 접근 객체, 데이터 액세스 객체

2 구현[ | ]

  • 데이터 요청시: DB커넥션 클래스(싱글턴 패턴 응용)로부터 getConnection[4]
  • 생성시 데이터소스를[5]입력받는 경우도 있음
인스턴스 생성시: 실제 커넥션을 맺는 것은 아니고, 데이터소스[5]만 저장

3 그림 예시[ | ]

패턴 구조[7]

 

객체간 상호작용[8]

 

4 구현 예시 1[ | ]

public class Person {
  ... (생략)
}
public class PersonDao {
  protected DataSource dataSource = null;

  public PersonDao(DataSource dataSource){
    this.dataSource = dataSource;
  }

  public Person readPerson(long personId){
    Connection connection = this.dataSource.getConnection();
    Person person = ... (생략)
    return person;
  }
}
Person person = personDao.readPerson(123);

5 구현 예시 2[ | ]

class Employee {
  protected $id;  
  protected $name;  
  protected $birth;  
  function __contruct($row) {
    $this->id = $row['id'];
    $this->name = $row['name'];
    $this->birth = $row['birth'];
  }
}
class EmployeeDao {
  protected $dataSource = null;

  function __construct(DataSource $dataSource) {
    $this->dataSource = $dataSource;
  }
  function readEmployee($employeeId) {
    $connection = $this->dataSource->getConnection();
    $row= $connection->query_row("SELECT * FROM employee WHERE id=?", $employeeId);
    return new Employee($row);
  }
}

6 같이 보기[ | ]

7 주석[ | ]

  1. 주로 DB
  2. 데이터베이스 또는 파일시스템
  3. J2EE 패턴에서는 통합 티어
  4. 커넥션 재사용함으로써 커넥션 비용 감소
  5. 5.0 5.1 어떤 DB에 접속해야 하는지에 대한 정보
  6. http://www.oracle.com/technetwork/java/dataaccessobject-138824.html
  7. 클래스 다이어그램
  8. 시퀀스 다이어그램

8 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}