net.freechoice.model.orm.Map_Profile.java Source code

Java tutorial

Introduction

Here is the source code for net.freechoice.model.orm.Map_Profile.java

Source

/*******************************************************************************
 * Copyright (c) 2013 BowenCai.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     BowenCai - initial API and implementation
 ******************************************************************************/
package net.freechoice.model.orm;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import net.freechoice.model.FC_Profile;

import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;

/**
 * 
 * @author BowenCai
 *
 */
public class Map_Profile implements IMapper<FC_Profile> {

    KeyHolder keyHolder = new GeneratedKeyHolder();

    @Override
    public FC_Profile mapRow(final ResultSet rs, int arg1) throws SQLException {

        FC_Profile prof = new FC_Profile();
        prof.id = rs.getInt(1);
        prof.id_user_ = rs.getInt(2);
        prof.date_register = rs.getDate(3);
        prof.site_personal = rs.getString(4);
        prof.name_first = rs.getString(5);
        prof.name_last = rs.getString(6);
        prof.contact_public = rs.getString(7);
        prof.gender = rs.getBoolean(8);
        prof.date_birth = rs.getDate(9);
        return prof;
    }

    @Override
    public PreparedStatementCreator createUpdate(final FC_Profile entity) {

        return new PreparedStatementCreator() {

            @Override
            public PreparedStatement createPreparedStatement(Connection con) throws SQLException {

                PreparedStatement ps = con.prepareStatement(
                        "update  FC_Transaction" + " set  id_user_ = ? " + ",      site_personal = ? "
                                + ",     name_first = ? " + ",     name_last = ? " + ",     contact_public = ? "
                                + ",     gender = ? " + ",     date_birth = ? " + " where id = ?");
                ps.setInt(1, entity.id_user_);
                ps.setString(2, entity.site_personal);
                ps.setString(3, entity.name_first);
                ps.setString(4, entity.name_last);
                ps.setString(5, entity.contact_public);
                ps.setBoolean(6, entity.gender);
                ps.setDate(7, entity.date_birth);
                ps.setInt(8, entity.id);
                return ps;
            }
        };
    }

    @Override
    public PreparedStatementCreator createInsert(final FC_Profile prof) {

        return new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
                PreparedStatement ps = con.prepareStatement("insert into FC_Profile(" + " id_user_, "
                        + " site_personal," + " name_first, name_last," + " contact_public, "
                        + " gender, date_birth)" + " values( " + prof.id_user_ + ", ?, ?, ?, ?, ?, ?)", RET_ID);
                ps.setString(1, prof.site_personal);
                ps.setString(2, prof.name_first);
                ps.setString(3, prof.name_last);
                ps.setString(4, prof.contact_public);
                ps.setBoolean(5, prof.gender);
                ps.setDate(6, prof.date_birth);
                return ps;
            }
        };
    }

}