Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package uk.ac.ebi.lnetdb.core;
- import uk.ac.ebi.lnetdb.db.accessors.Fatty_acid_speciesTableAccessor;
- import uk.ac.ebi.lnetdb.utilities.readers.FattyAcidConstraints;
- import java.io.InputStream;
- import java.sql.Connection;
- import java.sql.Driver;
- import java.sql.SQLException;
- import java.util.HashMap;
- import java.util.Properties;
- /**
- * Created by IntelliJ IDEA.
- * User: jfoster
- * Date: 20-Apr-2011
- * Time: 16:45:15
- * To change this template use File | Settings | File Templates.
- */
- public class PopulateFATable {
- public static void main(String[] args) {
- try{
- Driver driver = (Driver)Class.forName("com.mysql.jdbc.Driver").newInstance();
- Properties props = new Properties();
- //props.put("user", "xxxx");
- //props.put("password", "xxxx");
- props.put("user", "xxx");
- props.put("password", "xxxx");
- //Connection con = driver.connect("jdbc:mysql://mysql-lnet.ebi.ac.uk:4265/lnetdb", props);
- try{
- Connection con = driver.connect("jdbc:mysql://localhost:3306/lnetdb", props);
- con.setAutoCommit(false);
- StaticConnectionManager.setConnection(con);
- InputStream facis = PopulateFATable.class.getClassLoader().getResourceAsStream("fattyAcidConstraints.txt");
- FattyAcidConstraints fac = new FattyAcidConstraints(facis);
- HashMap<String, Integer> facHM = fac.getiFattyAcidConstaints();
- Integer maxCarbons = facHM.get("maxCarbons");
- Integer minCarbons = facHM.get("minCarbons");
- Integer maxDoubleBonds = facHM.get("maxDoubleBonds");
- Integer minDoubleBonds = facHM.get("minDoubleBonds");
- Long fasPKCount = 0l;
- //iterate FA results
- for (Object o : facHM.keySet()) {
- Fatty_acid_speciesTableAccessor fasta = new Fatty_acid_speciesTableAccessor();
- fasta.setCarbons(o.getCarbons());
- fasta.setDouble_bonds(o.getDoubleBonds());
- fasta.setName(o.getName());
- fasta.setValidated(false);
- fasta.setFatty_acid_species_id(fasPKCount);
- fasPKCount++;
- fasta.persist(con);
- }
- con.commit();
- }catch (SQLException e){
- e.printStackTrace();
- }
- }catch(Exception e1){
- e1.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment