/**
  * 删除一条记录
  *
  * @param
  */
 public void deleteMessage(String key) {
   try {
     db.delete(db.getConnection(), MESSAGE_DB, RECEIVE_TIME + "=?", new String[] {key});
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     if (db.getConnection().isOpen()) {
       db.closeConnection(db.getConnection());
     }
   }
 }
 /**
  * 添加一条消息
  *
  * @param msg
  */
 public void addOneMessage(ReceiveMessage msg) {
   try {
     ContentValues cv = new ContentValues();
     cv.put(MESSAGE_TEXT, msg.message);
     cv.put(MESSAGE_STATE, msg.state);
     cv.put(RECEIVE_TIME, msg.time);
     db.save(db.getConnection(), MESSAGE_DB, cv);
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     if (db.getConnection().isOpen()) {
       db.closeConnection(db.getConnection());
     }
   }
 }
Пример #3
0
  static void shutdown() {
    if (baseDB != null) {
      baseDB.shutdown();
    }

    baseDB = null;
  }
 /**
  * 修改,更新一条记录
  *
  * @param groupid
  */
 public void updateMessage(ReceiveMessage msg) {
   try {
     ContentValues values = new ContentValues();
     values.put(MESSAGE_TEXT, msg.message);
     values.put(MESSAGE_STATE, msg.state);
     values.put(RECEIVE_TIME, msg.time);
     db.update(
         db.getConnection(), MESSAGE_DB, values, RECEIVE_TIME + "=?", new String[] {msg.time});
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     if (db.getConnection().isOpen()) {
       db.closeConnection(db.getConnection());
     }
   }
 }
Пример #5
0
  static boolean sessionExists(
      final String sessionName, final boolean bMustBeLive, final boolean bMustBeFinal) {
    if (!baseDB.sessionExists(sessionName)) {
      return false;
    }

    if (!bMustBeLive && !bMustBeFinal) {
      return true;
    }

    try {
      ReplaySessionInfo sessionInfo = getSessionInfo(sessionName);

      if (bMustBeLive && !sessionInfo.bIsLive) {
        return false;
      }

      if (bMustBeFinal && sessionInfo.bIsLive) {
        return false;
      }
    } catch (Exception e) {
      return false;
    }

    return true;
  }
Пример #6
0
 static List<ReplaySessionInfo> getRecentSessions(
     final String appName,
     final int version,
     final int changelist,
     final String userName,
     final int limit) {
   return baseDB.getRecentSessions(appName, version, changelist, userName, limit);
 }
Пример #7
0
 static List<ReplaySessionInfo> discoverSessions(
     final String appName,
     final int version,
     final int changelist,
     final String userString,
     final String metaString,
     final int limit) {
   return baseDB.discoverSessions(appName, version, changelist, userString, metaString, limit);
 }
 /** 批量添加 */
 public void saveMessageList(Vector<ReceiveMessage> list) {
   try {
     for (int i = 0; i < list.size(); i++) {
       ReceiveMessage msg = list.elementAt(i);
       ContentValues cv = new ContentValues();
       cv.put(MESSAGE_TEXT, msg.message);
       cv.put(MESSAGE_STATE, msg.state);
       cv.put(RECEIVE_TIME, msg.time);
       db.save(db.getConnection(), MESSAGE_DB, cv);
     }
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     if (db.getConnection().isOpen()) {
       db.closeConnection(db.getConnection());
     }
   }
 }
Пример #9
0
 static void writeSessionStream(
     final String sessionName,
     final String name,
     final String metaTime1,
     final String metaTime2,
     final InputStream inStream)
     throws ReplayException {
   baseDB.writeSessionStream(sessionName, name, metaTime1, metaTime2, inStream);
 }
Пример #10
0
 static void writeEventData(
     final String sessionName,
     final String eventGroup,
     final int eventTime1,
     final int eventTime2,
     final String eventMeta,
     byte[] eventData)
     throws ReplayException {
   baseDB.writeEventData(sessionName, eventGroup, eventTime1, eventTime2, eventMeta, eventData);
 }
Пример #11
0
 static String createViewer(final String sessionName, final String userName)
     throws ReplayException {
   try {
     final String viewerName = java.util.UUID.randomUUID().toString();
     baseDB.createViewer(sessionName, viewerName, userName);
     return viewerName;
   } catch (ReplayException e) {
     throw new ReplayException(
         "CreateViewer. Failed to create viewer. SessionPath: " + sessionName);
   }
 }
Пример #12
0
 static void refreshSession(
     final String sessionName,
     final boolean bIsLive,
     final boolean bIsIncomplete,
     final int NumChunks,
     final int DemoTimeInMS,
     final int SizeInBytes)
     throws ReplayException {
   baseDB.refreshSession(
       sessionName, bIsLive, bIsIncomplete, NumChunks, DemoTimeInMS, SizeInBytes);
 }
  /**
   * 获取所有分组列表
   *
   * @return
   */
  public Vector<ReceiveMessage> getMessageList() {
    messagelist.removeAllElements();
    try {
      String[] cols = new String[] {MESSAGE_TEXT, MESSAGE_STATE, RECEIVE_TIME};
      if (db.isTableExits(db.getConnection(), MESSAGE_DB)) {

      } else {
        initMessageTable();
      }
      System.out.println("table  name" + MESSAGE_DB);
      Cursor cursor = db.getConnection().query(MESSAGE_DB, cols, null, null, null, null, null);
      while (cursor.moveToNext()) {
        ReceiveMessage msg = new ReceiveMessage();
        msg.message = cursor.getString(cursor.getColumnIndex(MESSAGE_TEXT));
        msg.state = Integer.parseInt(cursor.getString(cursor.getColumnIndex(MESSAGE_STATE)));
        msg.time = cursor.getString(cursor.getColumnIndex(RECEIVE_TIME));
        messagelist.add(msg);
      }

      cursor.close();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (db.getConnection().isOpen()) {
        db.closeConnection(db.getConnection());
      }
    }
    return this.messagelist;
  }
 /** 初始新建表 */
 public void initMessageTable() {
   String createSQL =
       "CREATE TABLE IF NOT EXISTS "
           + MESSAGE_DB
           + " ("
           + MESSAGE_STATE
           + " VARCHAR,"
           + MESSAGE_TEXT
           + " VARCHAR,"
           + RECEIVE_TIME
           + " VARCHAR"
           + ")";
   try {
     db.creatTable(db.getConnection(), createSQL);
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     if (db.getConnection().isOpen()) {
       db.closeConnection(db.getConnection());
     }
   }
 }
Пример #15
0
  @Override
  public void runSQL(String template) throws IOException, SQLException {
    if (template.startsWith(ALTER_COLUMN_NAME) || template.startsWith(ALTER_COLUMN_TYPE)) {

      String sql = buildSQL(template);

      String[] alterSqls = StringUtil.split(sql, CharPool.SEMICOLON);

      for (String alterSql : alterSqls) {
        if (!alterSql.startsWith("-- ")) {
          runSQL(alterSql);
        }
      }
    } else {
      super.runSQL(template);
    }
  }
Пример #16
0
  static String createSession(
      final String appName,
      final int version,
      final int changelist,
      final String friendlyName,
      final List<String> userNames,
      final String metaString)
      throws ReplayException {
    final UUID sessionId = java.util.UUID.randomUUID();
    final String sessionName = sessionId.toString();

    try {
      baseDB.createSession(
          appName, version, changelist, sessionName, friendlyName, userNames, metaString);
      return sessionName;
    } catch (ReplayException e) {
      throw new ReplayException(
          "CreateSession. Failed to create session directory. SessionPath: " + sessionName);
    }
  }
  public MessageTableManager(Context context, String time) {
    db = new BaseDB(context);
    time = time.replaceAll("-", "_"); // 数据库名不用有特殊符号和中文,因此先做替换操作
    MESSAGE_DB = MESSAGE_DB + "_" + time.substring(0, 10); // 将日期截取做为表名,如2011_06_10
    isNewInstall = true;
    try {
      if (db.isTableExits(db.getConnection(), MESSAGE_DB)) {
        Cursor cursor =
            db.getConnection()
                .query(
                    MESSAGE_DB,
                    new String[] {MESSAGE_STATE, MESSAGE_TEXT, RECEIVE_TIME},
                    null,
                    null,
                    null,
                    null,
                    null);
        if (cursor != null) {
          while (cursor.moveToNext()) {
            isNewInstall = false;
          }
        }
        cursor.close();
        db.closeConnection(db.getConnection());
      }
      if (isNewInstall) {

        initMessageTable();
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (db.getConnection().isOpen()) {
        db.closeConnection(db.getConnection());
      }
    }
  }
Пример #18
0
 static BaseDB.StreamMetadata getStreamMetadata(final String sessionName, final String name)
     throws ReplayException {
   return baseDB.getStreamMetadata(sessionName, name);
 }
Пример #19
0
 static void longCleanup() {
   baseDB.longCleanup();
 }
Пример #20
0
 static void quickCleanup() {
   baseDB.quickCleanup();
 }
Пример #21
0
 static int printLog(final PrintWriter writer, final Level level, final String subFilter) {
   return baseDB.printLog(writer, level, subFilter);
 }
Пример #22
0
 static void log(final Level level, final String str) {
   baseDB.log(level, str);
 }
Пример #23
0
 static void refreshViewer(final String sessionName, final String viewerName)
     throws ReplayException {
   baseDB.refreshViewer(sessionName, viewerName);
 }
Пример #24
0
 static List<BaseDB.EventInfo> enumerateEvents(final String sessionName, final String eventGroup)
     throws ReplayException {
   return baseDB.enumerateEvents(sessionName, eventGroup);
 }
Пример #25
0
 static int getNumSessions(final String appName, final int version, final int changelist) {
   return baseDB.getNumSessions(appName, version, changelist);
 }
Пример #26
0
 static byte[] readEventData(final String eventId) throws ReplayException {
   return baseDB.readEventData(eventId);
 }
Пример #27
0
 static void deleteViewer(final String sessionName, final String viewerName)
     throws ReplayException {
   baseDB.deleteViewer(sessionName, viewerName);
 }
Пример #28
0
 static ReplaySessionInfo getSessionInfo(final String sessionName) throws ReplayException {
   return baseDB.getSessionInfo(sessionName);
 }
Пример #29
0
 static long readSessionStream(
     final String sessionName, final String name, final OutputStream outStream)
     throws ReplayException {
   return baseDB.readSessionStream(sessionName, name, outStream);
 }
Пример #30
0
 static boolean sessionStreamExists(final String sessionName, final String name) {
   return baseDB.sessionStreamExists(sessionName, name);
 }