날짜별 글 목록: 2008년 4월 21일

MVC(Model-View-Controller) 패턴


MVC 패턴에 대한 내용입니다.
아래 내용은 http://en.wikipedia.org/wiki/Model-view-controller 에서 정의한 내용입니다.

Model
The domain-specific representation of the information on which the application operates. Domain logic adds meaning to raw data (e.g., calculating if today is the user’s birthday, or the totals, taxes, and shipping charges for shopping cart items).
Many applications use a persistent storage mechanism (such as a database ) to store data. MVC does not specifically mention the data access layer because it is understood to be underneath or encapsulated by the Model.
View
Renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes.
Controller
Processes and responds to events, typically user actions, and may invoke changes on the model.

예제코드

Model.java

import java.util.*;

public class Model {
    private int x;
    private int y;
    private ArrayList<Model> arrList = new ArrayList<Model>();
   
    public Model(int i, int j) {
        this.x = i;
        this.y = j;
    }
   
    public void setModel(int x) {
        for(int i=0; i < x; i++) {   
            arrList.add(new Model(i, i+1));
        }
    }
   
    public ArrayList<Model> getArrayList() {
        return this.arrList;
    }
   
    public int getX(){
        return this.x;
    }
   
    public int getY(){
        return this.y;
    }
}

View.java

import java.util.*;

public class View {
    private static Controller con = null;
   
    // x, y 축 보기
    public static void viewList() {       
        ArrayList<Model> arrayList = View.con.getModelList();
        for(int i = 0; i < arrayList.size(); i++ ) {
            System.out.println(arrayList.get(i).getX() + “, ” + arrayList.get(i).getY());
        }
    }
   
    // x축 보기
    public static void viewLine(){
        ArrayList<Model> arrayList = View.con.getModelList(20);
       
        for(int i = 0; i < arrayList.size(); i++ ) {
            System.out.println(arrayList.get(i).getX());
        }
    }
   
    public static void main(String[] args) {
        // TODO Auto-generated method stub
       
        con = new Controller();
        viewList();
        viewLine();   
    }
}

Controller.java

import java.util.*;

public class Controller {
    private Model model= null;
   
    public Controller() {
        this.model = new Model(1,1);
    }
   
    public ArrayList<Model> getModelList() {
        model.setModel(10);
        return model.getArrayList();
    }
   
    public ArrayList<Model> getModelList(int count) {
        model.setModel(count);
        return model.getArrayList();
    }   
}

자바에서 사용하는 다양한 JDBC Driver들

자바를 사용해서 연결할 수 있는 다양한 데이터베이스의 JDBC 드라이버 설정 내용입니다.

DB2

Vendor Site http://www.ibm.com/db2/
Driver Name com.ibm.db2.jcc.DB2Driver
Sample URL jdbc:db2://127.0.0.1:50000/dbname

Derby

(since Cayenne 1.2)

Vendor Site http://db.apache.org/derby/
Embedded
Driver Name org.apache.derby.jdbc.EmbeddedDriver
Sample URL jdbc:derby:path-to-hsql-db-files;create=true
Remote Server
Driver Name org.apache.derby.jdbc.ClientDriver
Sample URL jdbc:derby://127.0.0.1/testdb

FireBird (Interbase)

Vendor Site http://www.firebirdsql.org/
Driver Name org.firebirdsql.jdbc.FBDriver
Sample URL jdbc:firebirdsql:127.0.0.1/10007:/path-to-dbname.fdb
Notes FirebirdAdapter hasn’t been well-tested for some time. Looking for volunteer FireBird users to help us.

FrontBase

(since Cayenne 1.2)

Vendor Site http://www.frontbase.com/
Driver Name jdbc.FrontBase.FBJDriver
Sample URL jdbc:FrontBase://127.0.0.1/dbname

HSQLDB

Vendor Site http://hsqldb.org/
Driver Name org.hsqldb.jdbcDriver
Embedded
Sample URL jdbc:hsqldb:file:/path-to-hsql-db-files
Remote Server
Sample URL jdbc:hsqldb:hsql://127.0.0.1

MySQL

Vendor Site http://www.mysql.com/
Driver Name com.mysql.jdbc.Driver
Sample URL jdbc:mysql://127.0.0.1/dbname

OpenBase

Vendor Site http://www.openbase.com/
Driver Name com.openbase.jdbc.ObDriver
Sample URL jdbc:openbase://127.0.0.1/dbname

Oracle (10i)

Vendor Site http://oracle.com/
Driver Name oracle.jdbc.driver.OracleDriver
Sample URL jdbc:oracle:thin:@//127.0.0.1:1521/dbname

Oracle (8, 8i, 9i)

Vendor Site http://oracle.com/
Driver Name oracle.jdbc.driver.OracleDriver
Sample URL jdbc:oracle:thin:@127.0.0.1:1521:dbname

PostgreSQL (7.4, 8.*)

Vendor Site http://www.postgresql.org/
Driver Name org.postgresql.Driver
Sample URL jdbc:postgresql://127.0.0.1:5432/dbname

SQLServer

Microsoft Driver – SQL Server 2005
Vendor Site http://www.microsoft.com/sql/default.asp
Driver Name com.microsoft.sqlserver.jdbc.SQLServerDriver
Sample URL jdbc:sqlserver://127.0.0.1;databaseName=dbname
Microsoft Driver – SQL Server prior to 2005
Vendor Site http://www.microsoft.com/sql/default.asp
Driver Name com.microsoft.jdbc.sqlserver.SQLServerDriver
Sample URL jdbc:microsoft:sqlserver://127.0.0.1;databaseName=dbname;SelectMethod=cursor
jTDS Driver
Vendor Site http://jtds.sourceforge.net/
Driver Name net.sourceforge.jtds.jdbc.Driver
Sample URL jdbc:jtds:sqlserver://127.0.0.1:5000/dbname

Sybase

Sybase Driver
Vendor Site http://www.sybase.com/
Driver Name com.sybase.jdbc3.jdbc.SybDriver
Sample URL jdbc:sybase:Tds:127.0.0.1:5000/dbname
jTDS Driver
Vendor Site http://jtds.sourceforge.net/
Driver Name net.sourceforge.jtds.jdbc.Driver
Sample URL jdbc:jtds:sybase://127.0.0.1:5000/dbname;useLOBs=false;TDS=4.2

* Reference
https://cayenne.apache.org/docs/3.0/database-support.html