Пример #1
0
 private static DatabaseEngine databaseEngine() {
   String databaseEngine = System.getProperty(DATABASE_ENGINE_SYSTEM_PARAMETER);
   DatabaseEngine engine =
       databaseEngine != null ? DatabaseEngine.valueOf(databaseEngine) : DatabaseEngine.mysql;
   // logger.info("Using database enigine: " + engine);
   return engine;
 }
Пример #2
0
  /**
   * Read entry content starting at offset for given number of bytes.
   *
   * @param hdl Handle - handle to opened file
   * @param offset long - offset into entry content
   * @param count int - number of bytes to be read
   * @param fmt Formatter - protocol-specific entry representation
   * @return byte[] - read content
   */
  public byte[] read(Handle hdl, long offset, int count, AttributeHandler fmt) {

    // check for auth data.
    if (offset == 0) {
      String dbUser = null, dbPassword = null;
      if (dbAuth != null && dbAuth.length() > 0) {
        int pos = dbAuth.indexOf(':');
        if (pos != -1) {
          dbUser = dbAuth.substring(0, pos);
          dbPassword = dbAuth.substring(pos + 1);
        }
        // reset auth string
        dbAuth = null;
      }

      // connect to database
      if (dbUser != null) {
        // establish session with database
        String sessionId = "" + nextSessionId;
        Connection conn = db.connect(dbInst, dbUser, dbPassword);
        if (conn != null) {

          // create subdirectory.
          String client = hdl.userCredential.getUser();
          String group = hdl.userCredential.getGroup();
          Permissions perm = new Permissions(client, group, Permissions.PERM_400);
          Directory session = new SessionDirectory(sessionId, perm, conn);
          parent.add(session);

          content = sessionId + "\n";
          nextSessionId++;
        } else content = "Can't connect to database!\n";
      } else content = "No (valid) authentication data!\n";
    }

    // check bounds.
    byte[] data = content.getBytes();
    int size = data.length;
    if (offset < 0 || offset > size - 1) return null;

    // assemble result.
    int num = (int) Math.min(size - offset, count);
    byte[] res = new byte[num];
    System.arraycopy(data, (int) offset, res, 0, num);
    return res;
  }