activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikmela <mikm...@yahoo.com>
Subject Re: how to make activemq switch to JDBCPersistenceAdapter in source code?
Date Thu, 29 Mar 2012 14:57:30 GMT
There are many ways to  do it, but steps are
1. Create a datasource
2. Set it on JDBCPersistenceAdapter object.
3. Set PersistenceAdapter object on the broker instance...

Below code for illustration only...

 protected PersistenceAdapter createJDBCPersistenceAdapter(DataSource ds,
boolean createOnStartup)       {
    	JDBCPersistenceAdapter persistenceAdapter = null;
         ....
    	
    	persistenceAdapter = new JDBCPersistenceAdapter();
    	persistenceAdapter.setDataSource(ds);
    	persistenceAdapter.setCreateTablesOnStartup(createOnStartup);
    	
    	
    	return persistenceAdapter;
    }
    protected void configureJDBC() {
		DataSource ds = createDataSource();

		PersistenceAdapter persistenceAdapter = createJDBCPersistenceAdapter(ds,
false);
		try {
				this.broker.setPersistenceAdapter(persistenceAdapter);
			} catch ( IOException ex ) {
				throw new Exception ( "Failed to set JDBC: " + ex.toString());
			}
	}

    protected DataSource createDataSource(String url, String driverFQN,
String user, String password) 
    {
    	BasicDataSource ds = new BasicDataSource();
    	ds.setUsername(user);
    	ds.setPassword(password);
    	ds.setDriverClassName(driverFQN);//"oracle.jdbc.driver.OracleDriver");
    	ds.setUrl(url);//"jdbc:oracle:thin:@//haha:1521/haha1");
    	ds.setPoolPreparedStatements(true);
    	return ds;
    }



--
View this message in context: http://activemq.2283324.n4.nabble.com/how-to-make-activemq-switch-to-JDBCPersistenceAdapter-in-source-code-tp4501897p4515693.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Mime
View raw message