⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractrowmappertest.java

📁 spring+acegi编写的网上书城
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package net.livebookstore.dao.jdbc;

import static org.junit.Assert.*;

import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.*;
import java.util.Calendar;
import java.util.Map;

import javax.persistence.*;

import org.junit.Test;

public class AbstractRowMapperTest {

    private static final DomainObject DOMAIN_OBJECT;

    static {
        DOMAIN_OBJECT = new DomainObject();
        DOMAIN_OBJECT.setId(new Integer(1024));
        DOMAIN_OBJECT.setUsername("reg_user");
        DOMAIN_OBJECT.setPassword("test*12345");
        DOMAIN_OBJECT.setGender(true);
        DOMAIN_OBJECT.setBonus(1982.0214f);
        DOMAIN_OBJECT.setPub(new java.util.Date());
    }

    @Test
    public void mapRow() throws SQLException {
        DomainObjectRowMapper mapper = new DomainObjectRowMapper();
        assertEquals("T_Domain", mapper.getTable());
        ResultSetImpl rs = new ResultSetImpl(DOMAIN_OBJECT);
        DomainObject domain = (DomainObject)mapper.mapRow(rs, 1);
        assertEquals(DOMAIN_OBJECT.getUsername(), domain.getUsername());
        assertEquals(DOMAIN_OBJECT.getPassword(), domain.getPassword());
        assertTrue(domain.getGender());
        assertEquals(DOMAIN_OBJECT.getBonus(), domain.getBonus(), 0.00001f);
        assertEquals(DOMAIN_OBJECT.getId(), domain.getId());
    }

}

@Table(name="T_Domain")
class DomainObject {

    private Integer id;
    private String username;
    private String password;
    private boolean gender;
    private float bonus;
    private java.util.Date pub;

    @Id
    public Integer getId() { return id; }
    protected void setId(Integer id) { this.id = id; }

    @Column(name="username")
    public String getUsername() { return username; }
    public void setUsername(String username) { this.username = username; }

    @Column(name="password")
    public String getPassword() { return password; }
    public void setPassword(String password) { this.password = password; }

    @Column(name="gender")
    public boolean getGender() { return gender; }
    public void setGender(boolean gender) { this.gender = gender; }

    @Column(name="bonus")
    public float getBonus() { return bonus; }
    public void setBonus(float bonus) { this.bonus = bonus; }

    @Column(name="publish")
    public java.util.Date getPub() { return pub; }
    public void setPub(java.util.Date pub) { this.pub = pub; }

    @Transient
    public String getDisplayName() { return "Guest"; }
}

class DomainObjectRowMapper extends DomainRowMapper<DomainObject> {

    public DomainObjectRowMapper() {
        super(DomainObject.class);
    }

}

class ResultSetImpl extends ResultSetAdapter {

    private DomainObject row;

    public ResultSetImpl(DomainObject row) {
        this.row = row;
    }

    @Override
    public boolean getBoolean(String columnName) throws SQLException {
        if(columnName.equals("gender"))
            return row.getGender();
        throw new SQLException("Not found");
    }

    @Override
    public Timestamp getTimestamp(String columnName) throws SQLException {
        if(columnName.equals("publish"))
            return new Timestamp(row.getPub().getTime());
        throw new SQLException("Not found");
    }

    @Override
    public float getFloat(String columnName) throws SQLException {
        if(columnName.equals("bonus"))
            return row.getBonus();
        throw new SQLException("Not found");
    }

    @Override
    public int getInt(String columnName) throws SQLException {
        if(columnName.equals("id"))
            return row.getId().intValue();
        throw new SQLException("Not found");
    }

    @Override
    public String getString(String columnName) throws SQLException {
        if(columnName.equals("username"))
            return row.getUsername();
        if(columnName.equals("password"))
            return row.getPassword();
        throw new SQLException("Not found");
    }

}

class ResultSetAdapter implements ResultSet {

    public boolean absolute(int row) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public void afterLast() throws SQLException {
        throw new UnsupportedOperationException();
    }

    public void beforeFirst() throws SQLException {
        throw new UnsupportedOperationException();
    }

    public void cancelRowUpdates() throws SQLException {
        throw new UnsupportedOperationException();
    }

    public void clearWarnings() throws SQLException {
        throw new UnsupportedOperationException();
    }

    public void close() throws SQLException {
        throw new UnsupportedOperationException();
    }

    public void deleteRow() throws SQLException {
        throw new UnsupportedOperationException();
    }

    public int findColumn(String columnName) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public boolean first() throws SQLException {
        throw new UnsupportedOperationException();
    }

    public Array getArray(int i) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public Array getArray(String colName) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public InputStream getAsciiStream(int columnIndex) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public InputStream getAsciiStream(String columnName) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public BigDecimal getBigDecimal(String columnName) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public InputStream getBinaryStream(int columnIndex) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public InputStream getBinaryStream(String columnName) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public Blob getBlob(int i) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public Blob getBlob(String colName) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public boolean getBoolean(int columnIndex) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public boolean getBoolean(String columnName) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public byte getByte(int columnIndex) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public byte getByte(String columnName) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public byte[] getBytes(int columnIndex) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public byte[] getBytes(String columnName) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public Reader getCharacterStream(int columnIndex) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public Reader getCharacterStream(String columnName) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public Clob getClob(int i) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public Clob getClob(String colName) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public int getConcurrency() throws SQLException {
        throw new UnsupportedOperationException();
    }

    public String getCursorName() throws SQLException {
        throw new UnsupportedOperationException();
    }

    public Date getDate(int columnIndex, Calendar cal) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public Date getDate(int columnIndex) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public Date getDate(String columnName, Calendar cal) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public Date getDate(String columnName) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public double getDouble(int columnIndex) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public double getDouble(String columnName) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public int getFetchDirection() throws SQLException {
        throw new UnsupportedOperationException();
    }

    public int getFetchSize() throws SQLException {
        throw new UnsupportedOperationException();
    }

    public float getFloat(int columnIndex) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public float getFloat(String columnName) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public int getInt(int columnIndex) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public int getInt(String columnName) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public long getLong(int columnIndex) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public long getLong(String columnName) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public ResultSetMetaData getMetaData() throws SQLException {
        throw new UnsupportedOperationException();
    }

    public Object getObject(int i, Map<String, Class<?>> map) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public Object getObject(int columnIndex) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public Object getObject(String colName, Map<String, Class<?>> map) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public Object getObject(String columnName) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public Ref getRef(int i) throws SQLException {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -