public void SetUp() { MysqlDataSource mySQLDataSource = new MysqlDataSource(); mySQLDataSource.User = SupportDatabaseService.DBUSER; mySQLDataSource.Password = SupportDatabaseService.DBPWD; mySQLDataSource.URL = "jdbc:mysql://localhost/test"; string envName = "java:comp/env/jdbc/MySQLDB"; SupportInitialContextFactory.AddContextEntry(envName, mySQLDataSource); ConfigurationDBRef config = new ConfigurationDBRef(); Properties properties = new Properties(); properties.Put("java.naming.factory.initial", typeof(SupportInitialContextFactory).Name); config.SetDataSourceConnection(envName, properties); databaseDSConnFactory = new DatabaseDSConnFactory((ConfigurationDBRef.DataSourceConnection)config.ConnectionFactoryDesc, config.ConnectionSettings); }
protected override void SetUp() { base.SetUp(); MysqlDataSource dataSource = new MysqlDataSource(); dataSource.setUser("mysql"); dataSource.setDatabaseName("test"); dataSource.setServerName("localhost"); IDbConnection connection = dataSource.getConnection(); try { PreparedStatement dropStatement = connection.prepareStatement("DROP TABLE IF EXISTS " + DEFAULT_PREFERENCE_TABLE); try { dropStatement.Execute(); } finally { dropStatement.Close(); } IDbCommand createStatement = connection.prepareStatement("CREATE TABLE " + DEFAULT_PREFERENCE_TABLE + " (" + DEFAULT_USER_ID_COLUMN + " VARCHAR(4) NOT NULL, " + DEFAULT_ITEM_ID_COLUMN + " VARCHAR(4) NOT NULL, " + DEFAULT_PREFERENCE_COLUMN + " FLOAT NOT NULL, " + "PRIMARY KEY (" + DEFAULT_USER_ID_COLUMN + ", " + DEFAULT_ITEM_ID_COLUMN + "), " + "INDEX (" + DEFAULT_USER_ID_COLUMN + "), " + "INDEX (" + DEFAULT_ITEM_ID_COLUMN + ") )"); try { createStatement.execute(); } finally { createStatement.close(); } IDbCommand insertStatement = connection.prepareStatement("INSERT INTO " + DEFAULT_PREFERENCE_TABLE + " VALUES (?, ?, ?)"); try { String[] users = new String[]{"A123", "A123", "A123", "B234", "B234", "C345", "C345", "C345", "C345", "D456"}; String[] itemIDs = new String[]{"456", "789", "654", "123", "234", "789", "654", "123", "234", "456"}; double[] preferences = new double[]{0.1, 0.6, 0.7, 0.5, 1.0, 0.6, 0.7, 1.0, 0.5, 0.1}; for (int i = 0; i < users.Length; i++) { insertStatement.setString(1, users[i]); insertStatement.setString(2, itemIDs[i]); insertStatement.setDouble(3, preferences[i]); insertStatement.execute(); } } finally { insertStatement.close(); } } finally { connection.close(); } model = new MySQLJDBCDataModel(dataSource); }
protected override void SetUp() { base.SetUp(); MysqlDataSource dataSource = new MysqlDataSource(); dataSource.setUser("mysql"); dataSource.setDatabaseName("test"); dataSource.setServerName("localhost"); IDbConnection connection = dataSource.getConnection(); try { PreparedStatement dropStatement = connection.prepareStatement("DROP TABLE IF EXISTS " + DEFAULT_PREFERENCE_TABLE); try { dropStatement.Execute(); } finally { dropStatement.Close(); } IDbCommand createStatement = connection.prepareStatement("CREATE TABLE " + DEFAULT_PREFERENCE_TABLE + " (" + DEFAULT_USER_ID_COLUMN + " VARCHAR(4) NOT NULL, " + DEFAULT_ITEM_ID_COLUMN + " VARCHAR(4) NOT NULL, " + DEFAULT_PREFERENCE_COLUMN + " FLOAT NOT NULL, " + "PRIMARY KEY (" + DEFAULT_USER_ID_COLUMN + ", " + DEFAULT_ITEM_ID_COLUMN + "), " + "INDEX (" + DEFAULT_USER_ID_COLUMN + "), " + "INDEX (" + DEFAULT_ITEM_ID_COLUMN + ") )"); try { createStatement.execute(); } finally { createStatement.close(); } IDbCommand insertStatement = connection.prepareStatement("INSERT INTO " + DEFAULT_PREFERENCE_TABLE + " VALUES (?, ?, ?)"); try { String[] users = new String[] { "A123", "A123", "A123", "B234", "B234", "C345", "C345", "C345", "C345", "D456" }; String[] itemIDs = new String[] { "456", "789", "654", "123", "234", "789", "654", "123", "234", "456" }; double[] preferences = new double[] { 0.1, 0.6, 0.7, 0.5, 1.0, 0.6, 0.7, 1.0, 0.5, 0.1 }; for (int i = 0; i < users.Length; i++) { insertStatement.setString(1, users[i]); insertStatement.setString(2, itemIDs[i]); insertStatement.setDouble(3, preferences[i]); insertStatement.execute(); } } finally { insertStatement.close(); } } finally { connection.close(); } model = new MySQLJDBCDataModel(dataSource); }