List of usage examples for java.sql SQLException getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
public List<ServerWideStatsRecord> getWeeklyUniqueLogins() { String mysql = "select STR_TO_DATE(concat(date_format(LOGIN_DATE, '%x-%v'), ' Monday'),'%x-%v %W') as week_start," + " count(distinct user_id) as unique_users" + " from " + getExternalDbNameAsPrefix() + "SST_USERSTATS" + " group by 1"; String oracle = "select next_day(LOGIN_DATE - 7, 2) as week_start," + " count(distinct user_id) as unique_users" + " from " + getExternalDbNameAsPrefix() + "SST_USERSTATS" + " group by next_day(LOGIN_DATE - 7, 2)"; List result = sqlService.dbRead(getSqlForVendor(mysql, oracle), null, new SqlReader() { public Object readSqlResultRecord(ResultSet result) { ServerWideStatsRecord info = new ServerWideStatsRecordImpl(); try { info.add(result.getDate(1)); info.add(result.getLong(2)); } catch (SQLException e) { log.error("getWeeklyUniqueLogins() exception: " + e.getClass() + ": " + e.getMessage()); return null; }/*from ww w . j a v a2 s. co m*/ return info; } }); // remove the last entry, as it might not be a complete period result.remove(result.size() - 1); return result; }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
public List<ServerWideStatsRecord> getHourlyUsagePattern() { String mysql = "select date(SESSION_START) as session_date, " + "hour(session_start) as hour_start, " + "count(distinct SESSION_USER) as unique_users " + "from SAKAI_SESSION " + "where SESSION_START > DATE_SUB(CURDATE(), INTERVAL 30 DAY) " + "group by 1, 2"; String oracle = "select trunc(SESSION_START, 'DDD') as session_date," + " to_number(to_char(session_start, 'HH24')) as hour_start," + " count(distinct SESSION_USER) as unique_users" + " from SAKAI_SESSION" + " where SESSION_START > (SYSDATE - 30)" + " group by trunc(SESSION_START, 'DDD'), to_number(to_char(session_start, 'HH24'))"; // This query uses only the main Sakai database, so do not specify the connection as it might be external List result = sqlService.dbRead(getSqlForVendor(mysql, oracle), null, new SqlReader() { public Object readSqlResultRecord(ResultSet result) { ServerWideStatsRecord info = new ServerWideStatsRecordImpl(); try { info.add(result.getDate(1)); info.add(result.getInt(2)); info.add(result.getLong(3)); } catch (SQLException e) { log.error("getHourlyUsagePattern() exception: " + e.getClass() + ": " + e.getMessage()); return null; }/*from w w w . ja v a2 s .c o m*/ return info; } }); return result; }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
public List<ServerWideStatsRecord> getMonthlyTotalLogins() { String mysql = "select STR_TO_DATE(date_format(ACTIVITY_DATE, '%Y-%m-01'),'%Y-%m-%d') as period," + " sum(ACTIVITY_COUNT) as user_logins" + " from " + getExternalDbNameAsPrefix() + "SST_SERVERSTATS" + " where EVENT_ID='user.login'" + " group by 1"; String oracle = ("select TO_DATE(TO_CHAR(ACTIVITY_DATE, 'YYYY-MM-\"01\"'), 'YYYY-MM-DD') as period," + " sum(ACTIVITY_COUNT) as user_logins" + " from " + getExternalDbNameAsPrefix() + "SST_SERVERSTATS" + " where EVENT_ID='user.login'" + " group by TO_DATE(TO_CHAR(ACTIVITY_DATE, 'YYYY-MM-\"01\"'), 'YYYY-MM-DD')"); List result = sqlService.dbRead(getSqlForVendor(mysql, oracle), null, new SqlReader() { public Object readSqlResultRecord(ResultSet result) { ServerWideStatsRecord info = new ServerWideStatsRecordImpl(); try { info.add(result.getDate(1)); info.add(result.getLong(2)); } catch (SQLException e) { log.error("getMonthlyTotalLogins() exception: " + e.getClass() + ": " + e.getMessage()); return null; }/*from w ww. j av a2 s .com*/ return info; } }); // remove the last entry, as it might not be a complete period result.remove(result.size() - 1); return result; }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
public List<ServerWideStatsRecord> getMonthlyUniqueLogins() { String mysql = "select STR_TO_DATE(date_format(LOGIN_DATE, '%Y-%m-01'),'%Y-%m-%d') as period," + " count(distinct user_id) as unique_users" + " from " + getExternalDbNameAsPrefix() + "SST_USERSTATS" + " group by 1"; String oracle = "select TO_DATE(TO_CHAR(LOGIN_DATE, 'YYYY-MM-\"01\"'),'YYYY-MM-DD') as period," + " count(distinct user_id) as unique_users" + " from " + getExternalDbNameAsPrefix() + "SST_USERSTATS" + " group by TO_DATE(TO_CHAR(LOGIN_DATE, 'YYYY-MM-\"01\"'),'YYYY-MM-DD')"; List result = sqlService.dbRead(getSqlForVendor(mysql, oracle), null, new SqlReader() { public Object readSqlResultRecord(ResultSet result) { ServerWideStatsRecord info = new ServerWideStatsRecordImpl(); try { info.add(result.getDate(1)); info.add(result.getLong(2)); } catch (SQLException e) { log.error("getMonthlyUniqueLogins() exception: " + e.getClass() + ": " + e.getMessage()); return null; }//from www . j ava 2s. c o m return info; } }); // remove the last entry, as it might not be a complete period result.remove(result.size() - 1); return result; }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
public List<ServerWideStatsRecord> getTop20Activities() { String mysql = "SELECT event_id, " + "sum(if(event_date > DATE_SUB(CURDATE(), INTERVAL 7 DAY),1,0))/7 as last7, " + "sum(if(event_date > DATE_SUB(CURDATE(), INTERVAL 30 DAY),1,0))/30 as last30, " + "sum(if(event_date > DATE_SUB(CURDATE(), INTERVAL 365 DAY),1,0))/365 as last365 " + "FROM " + getExternalDbNameAsPrefix() + "SST_EVENTS " + "where event_id not in ('content.read', 'user.login', 'user.logout', 'pres.begin', 'pres.end', " + "'realm.upd', 'realm.add', 'realm.del', 'realm.upd.own', 'site.add', 'site.del', 'user.add', 'user.del') " + "and event_date > DATE_SUB(CURDATE(), INTERVAL 365 DAY) " + "group by 1 " + "order by 2 desc, 3 desc, 4 desc " + "LIMIT 20"; String oracle = "select * from" + " (SELECT event_id," + " sum(decode(sign(event_date - (SYSDATE - 7)), 1, 1, 0)) / 7 as last7," + " sum(decode(sign(event_date - (SYSDATE - 30)), 1, 1, 0)) / 30 as last30," + " sum(decode(sign(event_date - (SYSDATE - 365)), 1, 1, 0)) / 365 as last365" + " FROM " + getExternalDbNameAsPrefix() + "SST_EVENTS" + " where event_id not in ('content.read', 'user.login', 'user.logout', 'pres.begin', 'pres.end', 'realm.upd', 'realm.add', 'realm.del', 'realm.upd.own', 'site.add', 'site.del', 'user.add', 'user.del')" + " and event_date > (SYSDATE - 365)" + " group by event_id" + " order by last7 desc, last30 desc, last365 desc)" + " where rownum <= 20"; List result = sqlService.dbRead(getSqlForVendor(mysql, oracle), null, new SqlReader() { public Object readSqlResultRecord(ResultSet result) { ServerWideStatsRecord info = new ServerWideStatsRecordImpl(); try { info.add(result.getString(1)); info.add(result.getDouble(2)); info.add(result.getDouble(3)); info.add(result.getDouble(4)); } catch (SQLException e) { log.error("getTop20Activities() exception: " + e.getClass() + ": " + e.getMessage()); return null; }//from w w w .j a v a2 s . c om return info; } }); return result; }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
public List<ServerWideStatsRecord> getWeeklyRegularUsers() { String mysql = "select s.week_start, sum(if(s.user_logins >= 5,1,0)) as five_plus, " + "sum(if(s.user_logins = 4,1,0)) as four, " + "sum(if(s.user_logins = 3,1,0)) as three, " + "sum(if(s.user_logins = 2,1,0)) as twice, " + "sum(if(s.user_logins = 1,1,0)) as once " + "from (select " + "STR_TO_DATE(concat(date_format(login_date, '%x-%v'), ' Monday'),'%x-%v %W') as week_start, " + "user_id, login_count as user_logins " + "from " + getExternalDbNameAsPrefix() + "SST_USERSTATS group by 1, 2) as s " + "group by 1"; String oracle = "select s.week_start," + " sum(decode(sign(s.user_logins - 4), 1, 1, 0)) as five_plus," + " sum(decode(s.user_logins, 4, 1, 0)) as four, " + " sum(decode(s.user_logins, 3, 1, 0)) as three, " + " sum(decode(s.user_logins, 2, 1, 0)) as twice, " + " sum(decode(s.user_logins, 1, 1, 0)) as once" + " from (select next_day(LOGIN_DATE - 7, 2) as week_start," + " user_id, login_count as user_logins" + " from " + getExternalDbNameAsPrefix() + "SST_USERSTATS" + " group by next_day(LOGIN_DATE - 7, 2), user_id, login_count) s" + " group by s.week_start"; List result = sqlService.dbRead(getSqlForVendor(mysql, oracle), null, new SqlReader() { public Object readSqlResultRecord(ResultSet result) { ServerWideStatsRecord info = new ServerWideStatsRecordImpl(); try { info.add(result.getDate(1)); info.add(result.getLong(2)); info.add(result.getLong(3)); info.add(result.getLong(4)); info.add(result.getLong(5)); info.add(result.getLong(6)); } catch (SQLException e) { log.error("getWeeklyRegularUsers() exception: " + e.getClass() + ": " + e.getMessage()); return null; }/*from ww w . j a v a 2s . c o m*/ return info; } }); // remove the last entry, as it might not be a complete period result.remove(result.size() - 1); return result; }
From source file:org.apache.hadoop.hive.metastore.txn.TestTxnHandler.java
@Test @Ignore/*w w w .j a v a2 s . c o m*/ public void deadlockDetected() throws Exception { LOG.debug("Starting deadlock test"); Connection conn = txnHandler.getDbConn(Connection.TRANSACTION_SERIALIZABLE); Statement stmt = conn.createStatement(); long now = txnHandler.getDbTime(conn); stmt.executeUpdate("insert into TXNS (txn_id, txn_state, txn_started, txn_last_heartbeat, " + "txn_user, txn_host) values (1, 'o', " + now + ", " + now + ", 'shagy', " + "'scooby.com')"); stmt.executeUpdate("insert into HIVE_LOCKS (hl_lock_ext_id, hl_lock_int_id, hl_txnid, " + "hl_db, hl_table, hl_partition, hl_lock_state, hl_lock_type, hl_last_heartbeat, " + "hl_user, hl_host) values (1, 1, 1, 'mydb', 'mytable', 'mypartition', '" + txnHandler.LOCK_WAITING + "', '" + txnHandler.LOCK_EXCLUSIVE + "', " + now + ", 'fred', " + "'scooby.com')"); conn.commit(); txnHandler.closeDbConn(conn); final AtomicBoolean sawDeadlock = new AtomicBoolean(); final Connection conn1 = txnHandler.getDbConn(Connection.TRANSACTION_SERIALIZABLE); final Connection conn2 = txnHandler.getDbConn(Connection.TRANSACTION_SERIALIZABLE); try { for (int i = 0; i < 5; i++) { Thread t1 = new Thread() { @Override public void run() { try { try { updateTxns(conn1); updateLocks(conn1); Thread.sleep(1000); conn1.commit(); LOG.debug("no exception, no deadlock"); } catch (SQLException e) { try { txnHandler.checkRetryable(conn1, e, "thread t1"); LOG.debug("Got an exception, but not a deadlock, SQLState is " + e.getSQLState() + " class of exception is " + e.getClass().getName() + " msg is <" + e.getMessage() + ">"); } catch (TxnHandler.RetryException de) { LOG.debug("Forced a deadlock, SQLState is " + e.getSQLState() + " class of " + "exception is " + e.getClass().getName() + " msg is <" + e.getMessage() + ">"); sawDeadlock.set(true); } } conn1.rollback(); } catch (Exception e) { throw new RuntimeException(e); } } }; Thread t2 = new Thread() { @Override public void run() { try { try { updateLocks(conn2); updateTxns(conn2); Thread.sleep(1000); conn2.commit(); LOG.debug("no exception, no deadlock"); } catch (SQLException e) { try { txnHandler.checkRetryable(conn2, e, "thread t2"); LOG.debug("Got an exception, but not a deadlock, SQLState is " + e.getSQLState() + " class of exception is " + e.getClass().getName() + " msg is <" + e.getMessage() + ">"); } catch (TxnHandler.RetryException de) { LOG.debug("Forced a deadlock, SQLState is " + e.getSQLState() + " class of " + "exception is " + e.getClass().getName() + " msg is <" + e.getMessage() + ">"); sawDeadlock.set(true); } } conn2.rollback(); } catch (Exception e) { throw new RuntimeException(e); } } }; t1.start(); t2.start(); t1.join(); t2.join(); if (sawDeadlock.get()) break; } assertTrue(sawDeadlock.get()); } finally { conn1.rollback(); txnHandler.closeDbConn(conn1); conn2.rollback(); txnHandler.closeDbConn(conn2); } }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
public List<ServerWideStatsRecord> getNewUserStats(String period) { String mysqlPeriod = ""; if (period.equals("daily")) { mysqlPeriod = "date(ACTIVITY_DATE) as event_period"; } else if (period.equals("weekly")) { mysqlPeriod = "STR_TO_DATE(date_format(ACTIVITY_DATE, '%x-%v Monday'),'%x-%v %W') as event_period"; } else {//from www . ja v a 2 s . c o m // monthly mysqlPeriod = "STR_TO_DATE(date_format(ACTIVITY_DATE, '%Y-%m-01'),'%Y-%m-%d') as event_period"; } String mysql = "select " + mysqlPeriod + ", " + " ACTIVITY_COUNT as new_user" + " FROM " + getExternalDbNameAsPrefix() + "SST_SERVERSTATS" + " where EVENT_ID='user.add'"; if (period.equals("daily")) { mysql = mysql + " and ACTIVITY_DATE > DATE_SUB(CURDATE(), INTERVAL 90 DAY) "; } mysql = mysql + " group by 1"; String oraclePeriod = ""; if (period.equals("daily")) { oraclePeriod = "trunc(ACTIVITY_DATE, 'DDD')"; } else if (period.equals("weekly")) { oraclePeriod = "next_day(ACTIVITY_DATE - 7, 2)"; } else { // monthly oraclePeriod = "TO_DATE(TO_CHAR(ACTIVITY_DATE, 'YYYY-MM-\"01\"'),'YYYY-MM-DD')"; } String oracle = "select " + oraclePeriod + " as event_period, " + " sum(ACTIVITY_COUNT) as new_user" + " FROM " + getExternalDbNameAsPrefix() + "SST_SERVERSTATS" + " where EVENT_ID='user.add'"; if (period.equals("daily")) { oracle = oracle + " AND ACTIVITY_DATE > (SYSDATE - 90) "; } oracle = oracle + " group by " + oraclePeriod; List result = sqlService.dbRead(getSqlForVendor(mysql, oracle), null, new SqlReader() { public Object readSqlResultRecord(ResultSet result) { ServerWideStatsRecord info = new ServerWideStatsRecordImpl(); try { info.add(result.getDate(1)); info.add(result.getLong(2)); } catch (SQLException e) { log.error("getNewUserStats() exception: " + e.getClass() + ": " + e.getMessage()); return null; } return info; } }); // remove the last entry, as it might not be a complete period if (result.size() > 0) { result.remove(result.size() - 1); } return result; }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
public List<ServerWideStatsRecord> getSiteCreatedDeletedStats(String period) { String mysqlPeriod = ""; if (period.equals("daily")) { mysqlPeriod = "date(ACTIVITY_DATE) as event_period"; } else if (period.equals("weekly")) { mysqlPeriod = "STR_TO_DATE(date_format(ACTIVITY_DATE, '%x-%v Monday'),'%x-%v %W') as event_period"; } else {//from w w w . j a v a 2 s. c om // monthly mysqlPeriod = "STR_TO_DATE(date_format(ACTIVITY_DATE, '%Y-%m-01'),'%Y-%m-%d') as event_period"; } String mysql = "select " + mysqlPeriod + ", " + "sum(if(EVENT_ID = 'site.add',activity_count,0)) as site_created, " + "sum(if(EVENT_ID = 'site.del',activity_count,0)) as site_deleted " + "FROM " + getExternalDbNameAsPrefix() + "SST_SERVERSTATS "; if (period.equals("daily")) { mysql = mysql + "where ACTIVITY_DATE > DATE_SUB(CURDATE(), INTERVAL 90 DAY) "; } mysql = mysql + "group by 1"; String oraclePeriod = ""; if (period.equals("daily")) { oraclePeriod = "trunc(ACTIVITY_DATE, 'DDD')"; } else if (period.equals("weekly")) { oraclePeriod = "next_day(ACTIVITY_DATE - 7, 2)"; } else { // monthly oraclePeriod = "TO_DATE(TO_CHAR(ACTIVITY_DATE, 'YYYY-MM-\"01\"'),'YYYY-MM-DD')"; } String oracle = "select " + oraclePeriod + " as event_period, " + "sum(decode(EVENT_ID, 'site.add',activity_count,0)) as site_created, " + "sum(decode(EVENT_ID, 'site.del',activity_count,0)) as site_deleted " + "FROM " + getExternalDbNameAsPrefix() + "SST_SERVERSTATS "; if (period.equals("daily")) { oracle = oracle + "where ACTIVITY_DATE > (SYSDATE - 90) "; } oracle = oracle + "group by " + oraclePeriod; List result = sqlService.dbRead(getSqlForVendor(mysql, oracle), null, new SqlReader() { public Object readSqlResultRecord(ResultSet result) { ServerWideStatsRecord info = new ServerWideStatsRecordImpl(); try { info.add(result.getDate(1)); info.add(result.getLong(2)); info.add(result.getLong(3)); } catch (SQLException e) { log.error("getSiteCreatedDeletedStats() exception: " + e.getClass() + ": " + e.getMessage()); return null; } return info; } }); // remove the last entry, as it might not be a complete period if (result.size() > 0) { result.remove(result.size() - 1); } return result; }
From source file:shnakkydoodle.measuring.provider.MetricsProviderSQLServer.java
/** * Delete metric sla alarm status's/*w ww. j a va 2s. c om*/ * * @param metricSlaId */ public void deleteMetricSlaAlarmStatus(Integer metricSlaId) { Connection conn = null; CallableStatement stmt = null; try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); conn = DriverManager.getConnection(this.host + ";user=" + this.username + ";password=" + this.password); // Delete metric sla exclusion time stmt = conn.prepareCall("uspMetricSlaAlarmStatus_Delete(?)"); stmt.setInt(1, metricSlaId); stmt.execute(); } catch (SQLException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ClassNotFoundException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } finally { DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(conn); } }