@@ -0,0 +1,1984 @@
+package org.intermine.task;%0A%0A/*%0A * Copyright (C) 2002-2004 FlyMine%0A *%0A * This code may be freely distributed and modified under the%0A * terms of the GNU Lesser General Public Licence.  This should%0A * be distributed with the code.  See the LICENSE file for more%0A * information or http://www.gnu.org/copyleft/lesser.html.%0A *%0A */%0A%0Aimport org.apache.tools.ant.BuildException;%0Aimport org.apache.tools.ant.Task;%0A%0Aimport org.intermine.sql.Database;%0Aimport org.intermine.sql.DatabaseFactory;%0Aimport org.intermine.util.DatabaseUtil;%0A%0A/**%0A * Task to grant permissions on all tables in a database to a given user.%0A *%0A * @author Andrew Varley%0A * @author Richard Smith%0A */%0A%0Apublic class GrantTask extends Task%0A%7B%0A%0A    protected String database;%0A    protected String user;%0A    protected String perm;%0A%0A%0A    /**%0A     * Set the database alias%0A     * @param database the database alias%0A     */%0A    public void setDatabase(String database) %7B%0A        this.database = database;%0A    %7D%0A%0A    /**%0A     * Set user to grant permissions to%0A     * @param user a username%0A     */%0A    public void setUser(String user) %7B%0A        this.user = user;%0A    %7D%0A%0A    /**%0A     * The permission to grant: SELECT, INSERT, UPDATE, DELETE, RULE,%0A     * REFERENCES, TRIGGER, ALL%0A     * @param perm the permission to set%0A     */%0A    public void setPerm(String perm) %7B%0A        this.perm = perm;%0A    %7D%0A%0A    /**%0A     * @see Task#execute%0A     */%0A    public void execute() throws BuildException %7B%0A        if (database == null) %7B%0A            throw new BuildException(%22database attribute is not set%22);%0A        %7D%0A        if (user == null) %7B%0A            throw new BuildException(%22user attribute is not set%22);%0A        %7D%0A        if (perm == null) %7B%0A            throw new BuildException(%22perm attribute is not set%22);%0A        %7D%0A%0A        try %7B%0A            Database db = DatabaseFactory.getDatabase(database);%0A            DatabaseUtil.grant(db, user, perm);%0A        %7D catch (Exception e) %7B%0A            throw new BuildException(e);%0A        %7D%0A    %7D%0A%7D%0A

task to grant permissions on all tables of a given database