Package org.dbunit.database

Examples of org.dbunit.database.IDatabaseConnection


    * @param inputFile
    * @throws Exception
    */
  public void importDataSet(String inputFile) throws Exception{
   
    IDatabaseConnection conn = null;
   
     try {
      if(inputFile == null || inputFile.equalsIgnoreCase(""))
        throw new Exception("Invalid input file !");
      
       BasicDataSource ds = DatabaseConnectionFactory.getDataSource();
       conn = new DatabaseConnection(ds.getConnection());
      
       //conn = DatabaseConnectionFactory.getConnection();      
       // New feature since dbunit 2.4.7
       FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();      
       IDataSet dataSet = builder.build(new File(inputFile));
  
       DatabaseOperation.INSERT.execute(conn, dataSet);
     
    } catch (Exception e) {
      throw e;
     
    } finally{
        if(conn !=null)
          conn.close();
    }    
  }
View Full Code Here


       
     try
       BasicDataSource ds = DatabaseConnectionFactory.getDataSource();
         
       //ITableFilter filter = new DatabaseSequenceFilter(conn, tables);
       IDatabaseConnection conn = new DatabaseConnection(ds.getConnection());
       ITableFilter filter = new DatabaseSequenceFilter(conn, tables);
     
       //The target dataSet: ie all the tables in the input list
       IDataSet dataSet = new FilteredDataSet(filter, conn.createDataSet());     
     
       DatabaseOperation.DELETE_ALL.execute(conn, dataSet)
    
       conn.close();     
     
    }catch (Exception e) {     
      throw e;         
    }
   }
View Full Code Here

   * @throws Exception
   *
   */
  public List<String> getTableNamesOrdered() throws Exception
   
    IDatabaseConnection conn = null;
   
    try{   
      //to prevent a double loading, because the table list can be loaded in many panels
      if (tableNamesList == null)
      {   
         ArrayList<String> tableListOrdered = new ArrayList<String>();        
        
         BasicDataSource ds = DatabaseConnectionFactory.getDataSource();
         conn = new DatabaseConnection(ds.getConnection());
           
         ITableFilter filter = new DatabaseSequenceFilter(conn);
         
         //The dataSet: ie the list of ALL tables name
         IDataSet dataSet = new FilteredDataSet(filter, conn.createDataSet());
       
         ITableIterator iter = dataSet.iterator();
       
         while(iter.next())
         {
           ITable tab = iter.getTable();
           String tableName = tab.getTableMetaData().getTableName();       
           tableListOrdered.add(tableName);     
         }       
       
         tableNamesList = tableListOrdered;
       
         return tableNamesList;
     
      }else     
         return tableNamesList;
   
    }catch (Exception e) {
     
      if(Log4jManager.IS_LOGGING_CONFIGURED)
        logger.fatal("Error loading tables names ordered, cause: ",e);
     
      throw new Exception("Set a valid target Database and test the connection");
     
    }finally{
       if(conn != null)
        conn.close();
    }
  }
View Full Code Here

  }
 
    //TEST 
    public static List<String> getTableNamesOrderedStatic() throws Exception
   
    IDatabaseConnection conn = null;
   
    try{   
      //to prevent a double loading, because the table list can be loaded in many panels
      if (tableNamesList == null)
      {   
         ArrayList<String> tableListOrdered = new ArrayList<String>()
        
         BasicDataSource ds = DatabaseConnectionFactory.getDataSource();
         conn = new DatabaseConnection(ds.getConnection());
           
         ITableFilter filter = new DatabaseSequenceFilter(conn);
         
         //The dataSet: ie the list of ALL tables name
         IDataSet dataSet = new FilteredDataSet(filter, conn.createDataSet());
       
         ITableIterator iter = dataSet.iterator();
       
         while(iter.next())
         {
           ITable tab = iter.getTable();
           String tableName = tab.getTableMetaData().getTableName();       
           tableListOrdered.add(tableName);     
         }       
       
         tableNamesList = tableListOrdered;
       
         return tableNamesList;
     
      }else     
         return tableNamesList;
   
    }catch (Exception e) {
      throw new Exception("Set a valid target Database and test the connection");
     
    }finally{
       if(conn != null)
        conn.close();
    }
  }
View Full Code Here

     * @param tableName the name of the table
     * @throws Exception
     */
    public boolean isTableEmpty(String tableName) throws Exception
  {   
      IDatabaseConnection conn = null;
     
      try{        
         BasicDataSource ds = DatabaseConnectionFactory.getDataSource();
       conn = new DatabaseConnection(ds.getConnection());
          
         int rowCount = conn.getRowCount(tableName);
         conn.close();
       
         if(rowCount == 0)
           return true;
         else
           return false
     
      }catch (Exception e) {
      throw e;
     
    }finally{
        if(conn != null)
         conn.close();
    }
  }   
View Full Code Here

     * @return
     * @throws Exception
     */
    public boolean testConfigTableDataLoaded(int totalRow, String tableName) throws Exception
 
      IDatabaseConnection conn = null;
     
      try{
        BasicDataSource ds = DatabaseConnectionFactory.getDataSource();
      conn = new DatabaseConnection(ds.getConnection());
       
        int tableRowCount = conn.getRowCount(tableName);
       
        if(tableRowCount == totalRow)
            return true;
         else
            return false
       
        }catch (Exception e) {
          throw e;
   
        }finally{
           if(conn != null)
        conn.close();  
    }
  }
View Full Code Here

    public static void main(String[] args) throws Exception {
        Config config = new Config();
        Class.forName(config.getDbDriver());
        Connection jdbcConnection = DriverManager.getConnection(config.getDbUrl(), config.getDbUser(), config.getDbPass());
        IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);

        // dtd
        FlatDtdDataSet.write(connection.createDataSet(), new FileOutputStream("src_test/it/freshfruits/conf/dbunit/database-schema.dtd"));

        // export dati
        IDataSet fullDataSet = connection.createDataSet();
        FlatXmlDataSet.write(fullDataSet, new FileOutputStream("src_test/it/freshfruits/conf/dbunit/full.xml"));
    }
View Full Code Here

   *
   * @throws Exception
   */
  public void populateTestData() throws Exception {
    FlatXmlDataSet dataSet = new FlatXmlDataSet(testData);
    IDatabaseConnection con = new DatabaseConnection(connection);
    DatabaseOperation.CLEAN_INSERT.execute(con, dataSet);
    con.close();
  }
View Full Code Here

            return;
        // database connection
        Class.forName("com.mysql.jdbc.Driver");
        Connection jdbcConnection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/volunteerdb", "root", "root");
        IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);

        // full database export
        IDataSet fullDataSet = connection.createDataSet();
        FlatXmlDataSet.write(fullDataSet, new FileOutputStream("dataset.xml"));

    }
View Full Code Here

    @Autowired
    private DataSource dataSource;

    @Before
    public void init() throws Exception {
        IDatabaseConnection connection = getConnection();
        try {
             DatabaseOperation.CLEAN_INSERT.execute(connection, getDataSet());
//            createHsqldbTables(getDataSet(), connection.getConnection());

        } finally {
            connection.getConnection().commit();
        }
    }
View Full Code Here

TOP

Related Classes of org.dbunit.database.IDatabaseConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.