public static void dropAndRecreateViewForTable(String schema, String name,
			MonetDBTable monetDBTable) throws SQLException
	{
		Connection conn = CopyToolConnectionManager.getInstance().getMonetDbConnection();
		
		// disable autocommit to work in a single transaction
		boolean oldAutoCommit = conn.getAutoCommit();
		conn.setAutoCommit(false);
		
		// make sure the referenced table exists 
		if (monetDBTableExists(monetDBTable))
		{
			String fullName = schema + "." + name;
			
			LOG.info("Drop and recreate or create the view '" + fullName + "' for table '"
				+ monetDBTable.getToTableSql() + "' on MonetDB server...");
			
			// drop current table/view
			// we do this in a loop (of max 10) to ensure it really is dropped
			// due to a possible bug in MonetDB whereby a view can exist multiple times
			for(int i=0; i < 10 && tableOrViewExists(schema, name); i++)
			{				
				boolean isTable = isTable(schema, name);
				
				// display warning when table/view should have been dropped already
				if (i > 0)
				{
					if (isTable)
						LOG.warn(String.format("Table %s still exists despite previous DROP. This should not be possible!", fullName));
					else
						LOG.warn(String.format("View %s still exists despite previous DROP. This should not be possible!", fullName));
				}
				
				try (Statement stmt = conn.createStatement()) 
				{
					if (isTable)
					{
						LOG.info(String.format("Dropping existing table '%s'...", fullName));
						stmt.execute("DROP TABLE " + fullName + ";");
						LOG.info("Table dropped");
					}
					else
					{
						LOG.info(String.format("Dropping existing view '%s'...", fullName));
						stmt.execute("DROP VIEW " + fullName + ";");
						LOG.info("View dropped");
					}
				} catch (SQLException e) {
					if (isTable)
						LOG.error(String.format("Unable to drop table '%s'", fullName));
					else
						LOG.error(String.format("Unable to drop view '%s'", fullName));
					
					throw e;
				}
			}
			
			// create new view
			try (Statement q = conn.createStatement())
			{
				q.execute(String.format(
					"CREATE VIEW %s AS SELECT * FROM %s",
					fullName,
					monetDBTable.getToTableSql()
				));
			} catch (SQLException e) {
				LOG.error(String.format(
					"Unable to create view %s for table %s",
					fullName,
					monetDBTable.getToTableSql()
				));				
				
				throw e;
			}
			
			// commit transaction
			conn.commit();
			LOG.info("View '" + fullName + "' created");
		}
		else
		{
			LOG.info("View not created because the MonetDB table '" + monetDBTable.getToTableSql()
				+ "' does not exist");
		}
		
		// restore previous autocommit mode
		conn.setAutoCommit(oldAutoCommit);
	}