Examples of MySqlConnection


Examples of com.alibaba.otter.canal.parse.inbound.mysql.MysqlConnection

public class TableMetaCacheTest {

    @Test
    public void testSimple() {

        MysqlConnection connection = new MysqlConnection(new InetSocketAddress("127.0.0.1", 3306), "xxxxx", "xxxxx");
        try {
            connection.connect();
        } catch (IOException e) {
            Assert.fail(e.getMessage());
        }

        TableMetaCache cache = new TableMetaCache(connection);
View Full Code Here

Examples of com.ubx1.pdpscanner.server.database.MySQLConnection

    /*
     * Login validation
     */
    Validator.validateLogin(username, password);

    MySQLConnection conn = new MySQLConnection();
    conn.connect();

    username = "'" + username + "'";

    ResultSet rs = conn.SQLSelect("SELECT * FROM users WHERE username = "
        + username + " LIMIT 1");

    if (rs.next()) {

      String passwordHash = rs.getString("password");

      if (BCrypt.checkpw(password, passwordHash)) {

        String id = String.valueOf(rs.getInt("id"));
        String name = rs.getString("name");
        String email = rs.getString("email");
        String cell = rs.getString("cell");
        if (rs.wasNull())
          cell = null;
        String creationDate = rs.getDate("creation_date").toString();

        conn.disconnect();

        HttpSession userSession = getThreadLocalRequest().getSession();

        userSession.setAttribute("id", id);
        userSession.setAttribute("name", name);
        userSession.setAttribute("email", email);
        userSession.setAttribute("cell", cell);
        userSession.setAttribute("creationDate", creationDate);

        System.out.println("User session created.");

        return null;
      } else {

        conn.disconnect();

        throw new BadLoginException(username, password,
            "Incorrect password");
      }
    }
    // Username does not exist
    else {

      conn.disconnect();

      throw new BadLoginException(username, password,
          "Incorrect username");
    }
  }
View Full Code Here

Examples of com.ubx1.pdpscanner.server.database.MySQLConnection

     * Signup validation
     */
    Validator.validateSignUp(name, email, username, password, password,
        cell);

    MySQLConnection conn = new MySQLConnection();
    conn.connect();

    ResultSet rs = conn.SQLSelect("SELECT * FROM users");

    // Check username unicity
    while (rs.next()) {

      String s = rs.getString("username");

      if (s.equals(username)) {

        throw new BadUsernameException(username,
            "Username already exists");
      }
    }

    String passwordHash = BCrypt.hashpw(password, BCrypt.gensalt());

    // Prepare insert sql statement
    name = "'" + name + "'";
    email = "'" + email + "'";
    username = "'" + username + "'";
    passwordHash = "'" + passwordHash + "'";

    if (!cell.isEmpty())
      cell = "'" + cell + "'";
    else
      cell = "NULL";

    creationDate = "'" + creationDate + "'";

    // Insert new user
    conn.SQLUpdate("INSERT INTO users (name,email,username,password,cell,creation_date)"
        + " VALUES ("
        + name
        + ","
        + email
        + ","
        + username
        + ","
        + passwordHash + "," + cell + "," + creationDate + ")");

    conn.disconnect();

    return null;
  }
View Full Code Here

Examples of com.ubx1.pdpscanner.server.database.MySQLConnection

    } else {

      throw new InvalidSessionException();
    }

    MySQLConnection conn = new MySQLConnection();
    conn.connect();

    ResultSet rs = conn.SQLSelect("SELECT password FROM users WHERE id="
        + userId);

    if (rs.next()) {

      String dbPasswordHash = rs.getString("password");

      conn.disconnect();

      if (BCrypt.checkpw(password, dbPasswordHash)) {

        return null;
      } else {

        throw new BadPasswordException(password, "Incorrect password");
      }
    } else {

      conn.disconnect();

      throw new Exception("Could not find user with ID " + userId);
    }
  }
View Full Code Here

Examples of com.ubx1.pdpscanner.server.database.MySQLConnection

    } else {

      throw new InvalidSessionException();
    }

    MySQLConnection conn = new MySQLConnection();
    conn.connect();

    newPassword = "'" + BCrypt.hashpw(newPassword, BCrypt.gensalt()) + "'";

    conn.SQLUpdate("UPDATE users SET password=" + newPassword
        + " WHERE id=" + userId);

    conn.disconnect();

    return null;
  }
View Full Code Here

Examples of com.ubx1.pdpscanner.server.database.MySQLConnection

   *         Project object
   */
  @Override
  public Project[] fetchProjects() throws Exception {

    MySQLConnection conn = new MySQLConnection();
    conn.connect();

    ResultSet rs1 = conn
        .SQLSelect("SELECT * FROM projects JOIN users_in_projects ON projects.id = users_in_projects.project "
            + "JOIN users ON "
            + "users_in_projects.user = users.id "
            + "WHERE users_in_projects.project = projects.id"
            + " AND users_in_projects.role = "
            + UserRole.OWNER.code());

    ArrayList<Project> projectsList = new ArrayList<>();

    while (rs1.next()) {

      Project p = new Project(rs1.getInt("id"),
          rs1.getString("users.name"),
          rs1.getString("projects.name"), rs1.getString("repos_url"),
          rs1.getString("repos_user"),
          rs1.getString("repos_password"), rs1.getDate(
              "creation_date").toString()
              + " " + rs1.getTime("creation_date").toString());

      // Get project's loc stat for all versions
      ResultSet rs2 = conn
          .SQLSelect("SELECT * FROM versions JOIN general_stats "
              + "ON versions.project = " + rs1.getInt("id")
              + " AND general_stats.version = versions.id "
              + "ORDER BY versions.version");

      while (rs2.next()) {
        int nloc = rs2.getInt("nloc");
        if (!rs2.wasNull())
          p.addNloc(nloc);
        else
          p.addNloc(-1);
      }

      projectsList.add(p);
    }

    conn.disconnect();

    return projectsList.toArray(new Project[0]);
  }
View Full Code Here

Examples of com.ubx1.pdpscanner.server.database.MySQLConnection

      }

      try {
        checkProjectRepository(svnUrl, svnUser, svnPassword);

        MySQLConnection conn = new MySQLConnection();
        conn.connect();

        ResultSet rs = conn.SQLSelect("SELECT * FROM projects");

        // Check project name unicity
        while (rs.next()) {

          String s = rs.getString("name");

          if (s.equals(name)) {

            throw new BadProjectNameException(name,
                "Project name already exists");
          }
        }

        // Prepare insert sql statement
        name = "'" + name + "'";
        svnUrl = "'" + svnUrl + "'";

        if (!svnUser.isEmpty())
          svnUser = "'" + svnUser + "'";
        else
          svnUser = "NULL";

        if (!svnPassword.isEmpty()) {
          svnPassword = "'"
              + BCrypt.hashpw(svnPassword, BCrypt.gensalt())
              + "'";
        } else
          svnPassword = "NULL";

        creationDate = "'" + creationDate + "'";

        int projectId = conn
            .SQLUpdate("INSERT INTO projects (name,repos_url,repos_user,repos_password,creation_date)"
                + " VALUES ("
                + name
                + ","
                + svnUrl
                + ","
                + svnUser
                + ","
                + svnPassword
                + ","
                + creationDate + ")");

        conn.SQLUpdate("INSERT INTO users_in_projects (user,project,role)"
            + " VALUES ("
            + ownerId
            + ","
            + projectId
            + ","
            + UserRole.OWNER.code() + ")");

        conn.disconnect();
      } catch (SVNException e) {

        throw new RepositoryException(svnUrl, svnUser, svnPassword,
            "Project repository couldn't be reached (svn info)");
      }
View Full Code Here

Examples of com.ubx1.pdpscanner.server.database.MySQLConnection

   *            the id of the project to delete
   * @return a null String object
   */
  public String deleteProject(int id) throws Exception {

    MySQLConnection conn = new MySQLConnection();
    conn.connect();

    // First delete the associated stats
    conn.SQLUpdate("DELETE FROM general_stats "
        + "USING versions,general_stats " + "WHERE versions.project = "
        + id + " AND general_stats.version = versions.id");

    conn.SQLUpdate("DELETE FROM test_stats " + "USING versions,test_stats "
        + "WHERE versions.project = " + id
        + " AND test_stats.version = versions.id");

    conn.SQLUpdate("DELETE FROM findbugs_stats "
        + "USING versions,findbugs_stats "
        + "WHERE versions.project = " + id
        + " AND findbugs_stats.version = versions.id");

    // Then delete the project's users
    conn.SQLUpdate("DELETE FROM users_in_projects "
        + "WHERE users_in_projects.project = " + id);

    // Then delete the project's versions
    conn.SQLUpdate("DELETE FROM versions WHERE project = " + id);

    // Finally delete the project itself
    conn.SQLUpdate("DELETE FROM projects WHERE id = " + id);

    conn.disconnect();

    return null;
  }
View Full Code Here

Examples of com.ubx1.pdpscanner.server.database.MySQLConnection

   * @return the modified Project object, which now contains the stats
   */
  @Override
  public Project fetchStats(Project p) throws Exception {

    MySQLConnection conn = new MySQLConnection();
    conn.connect();

    // Get project's stats for all versions
    ResultSet rs1 = conn
        .SQLSelect("SELECT * FROM versions JOIN general_stats "
            + "ON general_stats.version = versions.id "
            + "WHERE versions.project = " + p.getId()
            + " ORDER BY versions.version");

    ResultSet rs2 = conn
        .SQLSelect("SELECT * FROM versions JOIN test_stats "
            + "ON test_stats.version = versions.id "
            + "WHERE versions.project = " + p.getId()
            + " ORDER BY versions.version");

    ResultSet rs3 = conn
        .SQLSelect("SELECT * FROM versions JOIN findbugs_stats "
            + "ON findbugs_stats.version = versions.id "
            + "WHERE versions.project = " + p.getId()
            + " ORDER BY versions.version");

    // fetchProjects() already fetched the nlocs which now might be from an
    // old version, so clear them then fetch them again
    p.clearNlocs();

    // Get project's general stats
    while (rs1.next()) {

      int nloc = rs1.getInt("nloc");
      if (!rs1.wasNull())
        p.addNloc(nloc);
      else
        p.addNloc(-1);

      int npkg = rs1.getInt("npkg");
      if (!rs1.wasNull())
        p.addNpkg(npkg);
      else
        p.addNpkg(-1);

      int nfile = rs1.getInt("nfile");
      if (!rs1.wasNull())
        p.addNfile(nfile);
      else
        p.addNfile(-1);

      int nfunc = rs1.getInt("nfunc");
      if (!rs1.wasNull())
        p.addNfunc(nfunc);
      else
        p.addNfunc(-1);

      int ncl = rs1.getInt("ncl");
      if (!rs1.wasNull())
        p.addNcl(ncl);
      else
        p.addNcl(-1);

      int ncom = rs1.getInt("ncom");
      if (!rs1.wasNull())
        p.addNcom(ncom);
      else
        p.addNcom(-1);

      int ndupl = rs1.getInt("ndupl");
      if (!rs1.wasNull())
        p.addNdupl(ndupl);
      else
        p.addNdupl(-1);
    }

    // Get project's test stats
    while (rs2.next()) {

      int ncovl = rs2.getInt("ncovl");
      if (!rs2.wasNull())
        p.addNcovl(ncovl);
      else
        p.addNcovl(-1);
    }

    int currentVersion = 0;

    ArrayList<FindbugsBugInstance> bps = null;
    ArrayList<FindbugsBugInstance> ps = null;

    // Get project's Findbugs bug instances
    while (rs3.next()) {

      int version = rs3.getInt("version");

      // We got to the next version
      if (version > currentVersion) {
        currentVersion++;

        if (bps != null) {
          p.addBp(bps);
          p.addP(ps);
        }

        bps = new ArrayList<FindbugsBugInstance>();
        ps = new ArrayList<FindbugsBugInstance>();

        String category = rs3.getString("category");
        // If category is null, Findbugs bug instances are unavailable
        // for this version
        if (rs3.wasNull()) {

          p.addBp(null);
          p.addP(null);
        } else {

          String abbrev = rs3.getString("abbrev");

          String type = rs3.getString("type");

          String file = rs3.getString("file");
          if (rs3.wasNull())
            file = null;

          int line = rs3.getInt("line");
          if (rs3.wasNull())
            line = -1;

          FindbugsBugInstance fb = new FindbugsBugInstance(category,
              abbrev, type, file, line);

          if (category.equals(FindbugsCategory.BAD_PRACTICE
              .toString())) {

            bps.add(fb);
          } else {
            ps.add(fb);
          }
        }
      }
      // We are reading the same version as in the previous loop, ignore
      // anything but Findbugs
      else {
        // Get project's Findbugs bug instances
        String category = rs3.getString("category");

        String abbrev = rs3.getString("abbrev");

        String type = rs3.getString("type");

        String file = rs3.getString("file");
        if (rs3.wasNull())
          file = null;

        int line = rs3.getInt("line");
        if (rs3.wasNull())
          line = -1;

        FindbugsBugInstance fb = new FindbugsBugInstance(category,
            abbrev, type, file, line);

        if (category.equals(FindbugsCategory.BAD_PRACTICE.toString())) {

          bps.add(fb);
        } else {
          ps.add(fb);
        }
      }
    }

    p.addBp(bps);
    p.addP(ps);

    conn.disconnect();

    return p;
  }
View Full Code Here

Examples of database.MySQLConnection

    clocParsingThread.join();
  }

  public void saveResults(int idVersion) throws Exception {

    MySQLConnection conn = new MySQLConnection();
    conn.connect();

    int numLinesOfCode = this.clocParser.getNumLinesOfCode();
    int numFiles = this.clocParser.getNumFiles();
    int numComments = this.clocParser.getNumComments();
    int numPackages = this.jncssParser.getNumPackages();
    int numClasses = this.jncssParser.getNumClasses();
    int numFunctions = this.jncssParser.getNumFunctions();
    int numCodeDuplications = this.pmdParser.getNumCodeDuplications();

    conn.SQLUpdate("insert into general_stats (version , nloc , nfunc , ncl , npkg , ncom , ndupl , nfile) values ("
        + idVersion
        + ","
        + (numLinesOfCode == -1 ? "NULL" : numLinesOfCode)
        + ","
        + (numFunctions == -1 ? "NULL" : numFunctions)
        + ","
        + (numClasses == -1 ? "NULL" : numClasses)
        + ","
        + (numPackages == -1 ? "NULL" : numPackages)
        + ","
        + (numComments == -1 ? "NULL" : numComments)
        + ","
        + (numCodeDuplications == -1 ? "NULL" : numCodeDuplications)
        + "," + (numFiles == -1 ? "NULL" : numFiles) + ")");

    conn.disconnect();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.