Initializing DataSourceInfo

From: Borut Bolčin (cayenn..mail.si)
Date: Thu Feb 17 2005 - 04:41:37 EST

  • Next message: Jrgen Saar: "Re: Modeller Question"

    Hello,

    I am having trouble initializing DataSourceInfo programaticaly. At
    application startup I want to drop tables, create them and then do so
    the usual staff. How can I obtain an initialized DataSourceInfo from
    DomainNode driver file?

    private DataContext ctxt;

    this.ctxt = createContext();

       private void createTables() {
          try {
             DbAdapter mySqlDbAdapter = new MySQLAdapter();
            
             MapLoader mapLoader = new MapLoader();
             InputStream is =
    this.getClass().getClassLoader().getResourceAsStream("MyDataMap.map.xml");

             DataMap dataMap = mapLoader.loadDataMap(new InputSource(is));
            
             DbGenerator mySqlDbGenerator = new DbGenerator(mySqlDbAdapter,
    dataMap);
                   
    // instead of this (don't want to be hardcoded)
    // DataSourceInfo *dataSourceInfo *= new DataSourceInfo();
    //
    dataSourceInfo.setAdapterClassName("org.objectstyle.cayenne.dba.JdbcAdapter");
    // dataSourceInfo.setDataSourceUrl(connection);
    // dataSourceInfo.setJdbcDriver("com.mysql.jdbc.Driver");
    // dataSourceInfo.setPassword(password);
    // dataSourceInfo.setUserName(username);

    // *where do I get already initialized dataSourceInfo need by
    **mySqlDbGenerator.runGenerator*?
           
             logger.info("DSI getDataSourceUrl(): " +
    dataSourceInfo.getDataSourceUrl());
             logger.info("DSI getJdbcDriver() : " +
    dataSourceInfo.getJdbcDriver());
             logger.info("DSI getPassword() : " +
    dataSourceInfo.getPassword());
             logger.info("DSI getUserName() : " +
    dataSourceInfo.getUserName());
            
             mySqlDbGenerator.setShouldCreatePKSupport(false);
             mySqlDbGenerator.setShouldDropTables(true);
             mySqlDbGenerator.runGenerator(*dataSourceInfo*);
          } catch (DataMapException e) {
             logger.fatal("Error in NewsDataMap.", e);
          } catch (Exception e) {
             logger.fatal("Error running generator.", e);
          }
       }

    Thanks!
    -Borut



    This archive was generated by hypermail 2.0.0 : Thu Feb 17 2005 - 04:41:53 EST