Class DataBase

java.lang.Object
ecmwf.common.database.DataGet
ecmwf.common.database.DataBase
All Implemented Interfaces:
MBeanService, Closeable, AutoCloseable
Direct Known Subclasses:
ECpdsBase

public class DataBase extends DataGet implements MBeanService, Closeable
The Class DataBase.
  • Field Details

    • MODE_EXTERNAL

      public static final int MODE_EXTERNAL
      The Constant MODE_EXTERNAL.
      See Also:
    • MODE_INTERNAL

      public static final int MODE_INTERNAL
      The Constant MODE_INTERNAL.
      See Also:
    • MODE_SERVER

      public static final int MODE_SERVER
      The Constant MODE_SERVER.
      See Also:
  • Constructor Details

    • DataBase

      public DataBase()
  • Method Details

    • initialize

      public void initialize(String brokerProxy, String driverClassName, String level, String protocol, String subProtocol, String alias, String user, String password, String dbms, String serverUrl, String repository, String validation, boolean logDatabaseEvents, boolean debugSqlRequests) throws SQLException, IllegalAccessException, InstantiationException, ClassNotFoundException, DataBaseException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException
      Initialise.
      Parameters:
      brokerProxy - the broker proxy
      driverClassName - the driver
      level - the level
      protocol - the protocol
      subProtocol - the sub protocol
      alias - the alias
      user - the user
      password - the password
      dbms - the dbms
      serverUrl - the server
      repository - the repository
      validation - the validation
      logDatabaseEvents - the log events
      debugSqlRequests - the debug sql
      Throws:
      SQLException - the SQL exception
      IllegalAccessException - the illegal access exception
      InstantiationException - the instantiation exception
      ClassNotFoundException - the class not found exception
      DataBaseException - the data base exception
      IllegalArgumentException - the illegal argument exception
      InvocationTargetException - the invocation target exception
      NoSuchMethodException - the no such method exception
      SecurityException - the security exception
    • formatDate

      public static final String formatDate(long date)
      Format date.
      Parameters:
      date - the date
      Returns:
      the string
    • formatTime

      public static final String formatTime(long time)
      Format time.
      Parameters:
      time - the time
      Returns:
      the string
    • reloadRepository

      public void reloadRepository()
      Reload repository.
    • close

      public void close()
      Close.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • get

      protected <T extends DataBaseObject> T get(T object) throws DataBaseException
      Gets the.
      Throws:
      DataBaseException
    • getAll

      protected <T extends DataBaseObject> ecmwf.common.database.DBIterator<T> getAll(Class<T> target)
      Gets the all.
    • escapeSql

      protected static String escapeSql(String value)
      Escape SQL values to avoid SQL injections.
      Parameters:
      value - the value
      Returns:
      the escaped value
    • logSqlRequest

      protected void logSqlRequest(String sql, long start, long stop, int numberOfRows)
      Log sql request.
      Parameters:
      sql - the sql
      start - the start
      stop - the stop
      numberOfRows - the number of rows
    • logSqlRequest

      protected void logSqlRequest(String name, long count)
      Log sql request.
    • executeSelect

      protected ecmwf.common.database.DBResultSet executeSelect(String originalSql) throws SQLException
      Execute select.
      Parameters:
      originalSql - the original sql
      Returns:
      the DB result set
      Throws:
      SQLException - the SQL exception
    • select

      public byte[] select(String sql) throws SQLException, IOException
      Select.
      Parameters:
      sql - the sql
      Returns:
      the byte[]
      Throws:
      SQLException - the SQL exception
      IOException - Signals that an I/O exception has occurred.
    • update

      public String update(String sql) throws SQLException
      Update.
      Parameters:
      sql - the sql
      Returns:
      the string
      Throws:
      SQLException - the SQL exception
    • executeSelect

      protected ecmwf.common.database.DBResultSet executeSelect(String menu, String name) throws SQLException, IOException
      Execute select.
      Parameters:
      menu - the menu
      name - the name
      Returns:
      the DB result set
      Throws:
      SQLException - the SQL exception
      IOException - Signals that an I/O exception has occurred.
    • executeSelect

      protected ecmwf.common.database.DBResultSet executeSelect(String menu, String name, String[] values) throws SQLException, IOException
      Execute select.
      Parameters:
      menu - the menu
      name - the name
      values - the values
      Returns:
      the DB result set
      Throws:
      SQLException - the SQL exception
      IOException - Signals that an I/O exception has occurred.
    • executeQuery

      protected <T extends DataBaseObject> ecmwf.common.database.DBIterator<T> executeQuery(String menu, String name, Class<T> resultClass) throws SQLException, IOException
      Execute query.
      Type Parameters:
      T - the generic type
      Parameters:
      menu - the menu
      name - the name
      resultClass - the result class
      Returns:
      the DB iterator
      Throws:
      SQLException - the SQL exception
      IOException - Signals that an I/O exception has occurred.
    • executeQuery

      protected <T extends DataBaseObject> ecmwf.common.database.DBIterator<T> executeQuery(String menu, String name, Class<T> resultClass, String[] values) throws SQLException, IOException
      Execute query.
      Type Parameters:
      T - the generic type
      Parameters:
      menu - the menu
      name - the name
      resultClass - the result class
      values - the values
      Returns:
      the DB iterator
      Throws:
      SQLException - the SQL exception
      IOException - Signals that an I/O exception has occurred.
    • executeCountAsInt

      protected int executeCountAsInt(String menu, String name) throws SQLException, IOException
      Execute count as int.
      Parameters:
      menu - the menu
      name - the name
      Returns:
      the int
      Throws:
      SQLException - the SQL exception
      IOException - Signals that an I/O exception has occurred.
    • executeCountAsInt

      protected int executeCountAsInt(String menu, String name, String[] values) throws SQLException, IOException
      Execute count as int.
      Parameters:
      menu - the menu
      name - the name
      values - the values
      Returns:
      the int
      Throws:
      SQLException - the SQL exception
      IOException - Signals that an I/O exception has occurred.
    • executeCountAsLong

      protected long executeCountAsLong(String menu, String name) throws SQLException, IOException
      Execute count as long.
      Parameters:
      menu - the menu
      name - the name
      Returns:
      the long
      Throws:
      SQLException - the SQL exception
      IOException - Signals that an I/O exception has occurred.
    • executeCountAsLong

      protected long executeCountAsLong(String menu, String name, String[] values) throws SQLException, IOException
      Execute count as long.
      Parameters:
      menu - the menu
      name - the name
      values - the values
      Returns:
      the long
      Throws:
      SQLException - the SQL exception
      IOException - Signals that an I/O exception has occurred.
    • executeUpdate

      protected int executeUpdate(String menu, String name) throws SQLException, IOException
      Execute update.
      Parameters:
      menu - the menu
      name - the name
      Returns:
      the int
      Throws:
      SQLException - the SQL exception
      IOException - Signals that an I/O exception has occurred.
    • executeUpdate

      protected int executeUpdate(String menu, String name, String[] values) throws SQLException, IOException
      Execute update.
      Parameters:
      menu - the menu
      name - the name
      values - the values
      Returns:
      the int
      Throws:
      SQLException - the SQL exception
      IOException - Signals that an I/O exception has occurred.
    • getAttribute

      public Object getAttribute(String attributeName) throws AttributeNotFoundException, MBeanException
      Gets the attribute. Gets the attribute.
      Specified by:
      getAttribute in interface MBeanService
      Parameters:
      attributeName - the attribute name
      Returns:
      the attribute
      Throws:
      AttributeNotFoundException - the attribute not found exception
      MBeanException - the MBean exception
    • setAttribute

      public boolean setAttribute(String name, Object value) throws InvalidAttributeValueException, MBeanException
      Sets the attribute. Sets the attribute.
      Specified by:
      setAttribute in interface MBeanService
      Parameters:
      name - the name
      value - the value
      Returns:
      true, if successful
      Throws:
      InvalidAttributeValueException - the invalid attribute value exception
      MBeanException - the MBean exception
    • getMBeanInfo

      public MBeanInfo getMBeanInfo()
      Gets the MBean info. Gets the MBean info.
      Specified by:
      getMBeanInfo in interface MBeanService
      Returns:
      the MBean info
    • getMode

      public int getMode()
      Gets the mode.
      Returns:
      the mode
    • getTime

      public static long getTime() throws ParseException
      Gets the time.
      Returns:
      the time
      Throws:
      ParseException - the parse exception
    • getTime

      public static long getTime(Date date, Time time) throws ParseException
      Gets the time.
      Parameters:
      date - the date
      time - the time
      Returns:
      the time
      Throws:
      ParseException - the parse exception
    • invoke

      public Object invoke(String operationName, Object[] params, String[] signature) throws NoSuchMethodException, MBeanException
      Invoke. Invoke.
      Specified by:
      invoke in interface MBeanService
      Parameters:
      operationName - the operation name
      params - the params
      signature - the signature
      Returns:
      the object
      Throws:
      NoSuchMethodException - the no such method exception
      MBeanException - the MBean exception
    • newActivity

      public Activity newActivity(ECUser ecuser, String plugin, String host, String agent, String action, String comment, boolean error)
      New activity.
      Parameters:
      ecuser - the ecuser
      plugin - the plugin
      host - the host
      agent - the agent
      action - the action
      comment - the comment
      error - the error
      Returns:
      the activity
    • newEvent

      public Event newEvent(Activity activity, String action, String comment, boolean error)
      New event.
      Parameters:
      activity - the activity
      action - the action
      comment - the comment
      error - the error
      Returns:
      the event
    • insert

      public void insert(DataBaseObject object, boolean createPk) throws DataBaseException
      Insert.
      Parameters:
      object - the object
      createPk - the create pk
      Throws:
      DataBaseException - the data base exception
    • insert

      public void insert(DataBaseObject object, boolean createPk, boolean checkDuplicate) throws DataBaseException
      Insert.
      Parameters:
      object - the object
      createPk - the create pk
      checkDuplicate - the check duplicate
      Throws:
      DataBaseException - the data base exception
    • update

      public void update(DataBaseObject object) throws DataBaseException
      Update a DataBase Object.
      Parameters:
      object - the object
      Throws:
      DataBaseException - the data base exception
    • tryUpdate

      public boolean tryUpdate(DataBaseObject object)
      Try to update a DataBase Object. In case of problem it will fail silently.
      Parameters:
      object - the object
      Returns:
      true, if successful
    • tryInsert

      public boolean tryInsert(DataBaseObject object, boolean createPk)
      Try to insert a DataBase Object. In case of problem it will fail silently.
      Parameters:
      object - the object
      createPk - the create pk
      Returns:
      true, if successful
    • store

      public void store(DataBaseObject object) throws DataBaseException
      Store.
      Parameters:
      object - the object
      Throws:
      DataBaseException - the data base exception
    • remove

      public void remove(DataBaseObject object) throws DataBaseException
      Removes the.
      Parameters:
      object - the object
      Throws:
      DataBaseException - the data base exception
    • remove

      public void remove(DataBaseObject[] objects) throws DataBaseException
      Removes the.
      Parameters:
      objects - the objects
      Throws:
      DataBaseException - the data base exception
    • clearCache

      public void clearCache()
      Clear cache.
    • clearCache

      public <T extends DataBaseObject> void clearCache(Class<T> clazz, List<Object> primaryKeys)
      Clear cache for the specified entities and primary keys.
      Type Parameters:
      T - the generic type
      Parameters:
      clazz - the clazz
      primaryKeys - the primary keys
    • clearCache

      public void clearCache(String tableName, String columnName, List<Object> primaryKeys)
      Clear cache for the specified entities and primary keys.
      Parameters:
      tableName - the table name
      columnName - the column name
      primaryKeys - the primary keys
    • getPrimaryKeyValues

      public Object[] getPrimaryKeyValues(DataBaseObject object) throws DataBaseException
      Gets the primary key values.
      Parameters:
      object - the object
      Returns:
      the primary key values
      Throws:
      DataBaseException - the data base exception
    • getScriptFileImpl

      public DataBase.ScriptFileImpl getScriptFileImpl(String repository)
      Gets the script file impl.
      Parameters:
      repository - the repository
      Returns:
      the script file impl