java.lang.Object
edu.internet2.middleware.grouperInstaller.util.GiDbUtils

public class GiDbUtils extends Object
the instance can be reused, it doesnt store state except the connection user/pass etc
  • Constructor Details

    • GiDbUtils

      public GiDbUtils(String url, String user, String pass)
      construct
      Parameters:
      url -
      user -
      pass -
  • Method Details

    • registerDriverOnce

      public void registerDriverOnce(String appDir)
      Parameters:
      appDir - where we can find drivers
    • isPostgres

      public boolean isPostgres()
      see if the config file seems to be postgres
      Returns:
      see if postgres
    • isPostgres

      public static boolean isPostgres(String connectionUrl)
      see if the config file seems to be postgres
      Parameters:
      connectionUrl -
      Returns:
      see if postgres
    • isOracle

      public boolean isOracle()
      see if the config file seems to be oracle
      Returns:
      see if oracle
    • isOracle

      public static boolean isOracle(String connectionUrl)
      see if the config file seems to be oracle
      Parameters:
      connectionUrl -
      Returns:
      see if oracle
    • isMysql

      public boolean isMysql()
      see if the config file seems to be mysql
      Returns:
      see if mysql
    • isMysql

      public static boolean isMysql(String connectionUrl)
      see if the config file seems to be mysql
      Parameters:
      connectionUrl -
      Returns:
      see if mysql
    • convertUrlToDriverClassIfNeeded

      public static String convertUrlToDriverClassIfNeeded(String connectionUrl, String driverClassName)
      if there is no driver class specified, then try to derive it from the URL
      Parameters:
      connectionUrl -
      driverClassName -
      Returns:
      the driver class
    • connection

      public Connection connection()
      get a connection to the oracle DB
      Returns:
      a connection
    • listSelect

      public <T> List<T> listSelect(Class<T> rowType, String query, List<GiDbUtils.DbType> returnColTypes)
      run a query and get rows back
      Type Parameters:
      T - generic type
      Parameters:
      rowType - type of each row returned, e.g. String.class or Object[]
      query -
      returnColTypes -
      Returns:
      the list of objects
    • select

      public <T> T select(Class<T> colType, String query)
      select a value from the db
      Type Parameters:
      T -
      Parameters:
      colType -
      query -
      Returns:
      the data
    • listSelect

      public <T> List<T> listSelect(Class<T> rowType, String query, List<GiDbUtils.DbType> returnColTypes, List<Object> args)
      run a query and get rows back
      Type Parameters:
      T - generic type
      Parameters:
      rowType - type of each row returned, e.g. String.class or Object[]
      query -
      returnColTypes -
      args - preparedstatement arguments
      Returns:
      the list of objects
    • rollbackQuietly

      public void rollbackQuietly(Connection connection)
      rollback quiently
      Parameters:
      connection -
    • executeUpdate

      public int executeUpdate(String query, Object arg)
      execute a query (insert/update/delete/etc)
      Parameters:
      query - query to execute
      arg - preparedstatement argument
      Returns:
      either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
    • executeUpdate

      public int executeUpdate(String query)
      execute a query (insert/update/delete/etc)
      Parameters:
      query - query to execute
      Returns:
      either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
    • executeUpdate

      public int executeUpdate(String query, List<Object> args)
      execute a query (insert/update/delete/etc)
      Parameters:
      query - query to execute
      args - preparedstatement arguments
      Returns:
      either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
    • checkConnection

      public Exception checkConnection()
      check connection to the db
      Returns:
      exception if there is one
    • checkConnectionQuery

      public String checkConnectionQuery()
      check connection to the db
      Returns:
      the query to check connection with
    • executeUpdate

      public int executeUpdate(String query, List<Object> args, boolean commit)
      execute a query (insert/update/delete/etc)
      Parameters:
      query - query to execute
      args - preparedstatement arguments
      commit - if we should commit
      Returns:
      either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing