5 changed files with 86 additions and 0 deletions
@ -0,0 +1,23 @@ |
|||||||
|
package org.leolo.nrdatad.db; |
||||||
|
|
||||||
|
import org.leolo.nrdatad.model.Tiploc; |
||||||
|
|
||||||
|
import java.sql.SQLException; |
||||||
|
import java.util.Collection; |
||||||
|
|
||||||
|
public abstract class TiplocDao extends BaseDao{ |
||||||
|
|
||||||
|
public TiplocDao(DatabaseManager manager) { |
||||||
|
super(manager); |
||||||
|
} |
||||||
|
|
||||||
|
public abstract void insert(Tiploc tiploc) throws SQLException; |
||||||
|
|
||||||
|
public void insertAll(Collection<Tiploc> tiplocs) throws SQLException{ |
||||||
|
for(Tiploc tiploc: tiplocs){ |
||||||
|
insert(tiploc); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public abstract void truncateTable() throws SQLException; |
||||||
|
} |
||||||
@ -0,0 +1,49 @@ |
|||||||
|
package org.leolo.nrdatad.db.mariadb; |
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
import org.leolo.nrdatad.db.DatabaseManager; |
||||||
|
import org.leolo.nrdatad.db.TiplocDao; |
||||||
|
import org.leolo.nrdatad.model.Tiploc; |
||||||
|
|
||||||
|
import java.sql.Connection; |
||||||
|
import java.sql.PreparedStatement; |
||||||
|
import java.sql.SQLException; |
||||||
|
import java.sql.Statement; |
||||||
|
|
||||||
|
public class TiplocDaoImpl extends TiplocDao { |
||||||
|
|
||||||
|
private Logger log = LogManager.getLogger(); |
||||||
|
|
||||||
|
public TiplocDaoImpl(DatabaseManager manager) { |
||||||
|
super(manager); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void insert(Tiploc tiploc) throws SQLException { |
||||||
|
try( |
||||||
|
Connection conn = getConnection(); |
||||||
|
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO tiploc (tiploc_code, nalco, stanox, crs_code, description, tps_description) VALUES (?,?,?,?,?,?)") |
||||||
|
){ |
||||||
|
setString(pstmt, 1, tiploc.getTiplocCode()); |
||||||
|
setString(pstmt, 2, tiploc.getNalco()); |
||||||
|
setString(pstmt, 3, tiploc.getStanox()); |
||||||
|
setString(pstmt, 4, tiploc.getCrsCode()); |
||||||
|
setString(pstmt, 5, tiploc.getDescription()); |
||||||
|
setString(pstmt, 6, tiploc.getTpsDescription()); |
||||||
|
pstmt.executeUpdate(); |
||||||
|
conn.commit(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void truncateTable() throws SQLException{ |
||||||
|
try( |
||||||
|
Connection conn = getConnection(); |
||||||
|
Statement stmt = conn.createStatement() |
||||||
|
){ |
||||||
|
log.atInfo().log("Truncating table tiploc"); |
||||||
|
stmt.executeQuery("TRUNCATE TABLE tiploc"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue