コード例 #1
0
 /**
  * ************************************* COPIES
  * SECTION********************************************************************
  */
 public void createBorrower(Borrower bor) throws Exception {
   ConnectionUtil c = new ConnectionUtil();
   Connection conn = c.createConnection();
   try {
     if (bor == null
         || bor.getBorrowerName() == null
         || bor.getBorrowerName().length() == 0
         || bor.getBorrowerName().length() > 45
         || bor.getBorrowerAddress() == null
         || bor.getBorrowerAddress().length() == 0
         || bor.getBorrowerAddress().length() > 45
         || bor.getBorrowerPhone() == null
         || bor.getBorrowerPhone().length() == 0
         || bor.getBorrowerPhone().length() > 45) {
       throw new Exception("Borrower Name, Address, Phone cannot be empty or more than 45 Chars");
     } else {
       BorrowerDAO bdao = new BorrowerDAO(conn);
       bdao.create(bor);
       conn.commit();
     }
   } catch (Exception e) {
     e.printStackTrace();
     conn.rollback();
   } finally {
     conn.close();
   }
 }
コード例 #2
0
 /** *************************************************************************************** */
 public void UpdateBorrower(Borrower bor) throws Exception {
   ConnectionUtil c = new ConnectionUtil();
   Connection conn = c.createConnection();
   try {
     if (bor == null
         || bor.getCardNo() == 0
         || bor.getBorrowerName() == null
         || bor.getBorrowerName().length() == 0
         || bor.getBorrowerName().length() > 45
         || bor.getBorrowerAddress() == null
         || bor.getBorrowerAddress().length() == 0
         || bor.getBorrowerAddress().length() > 45
         || bor.getBorrowerPhone() == null
         || bor.getBorrowerPhone().length() == 0
         || bor.getBorrowerPhone().length() > 45) {
       throw new Exception("The Borrower cannot be null or CardNo can not be 0 ");
     } else {
       BorrowerDAO bordao = new BorrowerDAO(conn);
       bordao.update(bor);
       conn.commit();
     }
   } catch (Exception e) {
     e.printStackTrace();
     conn.rollback();
   } finally {
     conn.close();
   }
 }
コード例 #3
0
 /** ******************************************************************************************* */
 public void DeletePublisher(Publisher publisher) throws Exception {
   ConnectionUtil c = new ConnectionUtil();
   Connection conn = c.createConnection();
   try {
     if (publisher == null
         || publisher.getPublisherName() == null
         || publisher.getPublisherName().length() == 0
         || publisher.getPublisherName().length() > 45
         || publisher.getPublisherAddress() == null
         || publisher.getPublisherAddress().length() == 0
         || publisher.getPublisherAddress().length() > 45
         || publisher.getPublisherPhone() == null
         || publisher.getPublisherPhone().length() == 0
         || publisher.getPublisherPhone().length() > 45) {
       throw new Exception("The Publisher cannot be null");
     } else {
       PublisherDAO pdao = new PublisherDAO(conn);
       pdao.delete(publisher);
       conn.commit();
     }
   } catch (Exception e) {
     e.printStackTrace();
     conn.rollback();
   } finally {
     conn.close();
   }
 }
コード例 #4
0
 public List<Genre> ListGenres() throws Exception {
   ConnectionUtil c = new ConnectionUtil();
   Connection conn = c.createConnection();
   try {
     GenreDAO gdao = new GenreDAO(conn);
     List<Genre> genres = gdao.readAll();
     conn.commit();
     return genres;
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   } finally {
     conn.close();
   }
 }
コード例 #5
0
 public List<Author> ListAuthors() throws Exception {
   ConnectionUtil c = new ConnectionUtil();
   Connection conn = c.createConnection();
   try {
     AuthorDAO adao = new AuthorDAO(conn);
     List<Author> authors = adao.readAll();
     conn.commit();
     return authors;
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   } finally {
     conn.close();
   }
 }
コード例 #6
0
 public List<LibBranch> ListBranches() throws Exception {
   ConnectionUtil c = new ConnectionUtil();
   Connection conn = c.createConnection();
   try {
     LibBranchDAO lib = new LibBranchDAO(conn);
     List<LibBranch> branches = lib.readAll();
     conn.commit();
     return branches;
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   } finally {
     conn.close();
   }
 }
コード例 #7
0
ファイル: JdbcConnection.java プロジェクト: scooter/scooter
  /**
   * Create a connection based on specific database connection context.
   *
   * @return Connection
   */
  protected Connection createConnection() {
    JdbcConnectionContext jdcc = (JdbcConnectionContext) getDatabaseConnectionContext();
    Connection connection = null;
    if (jdcc.useConnectionPool()) {
      connection = ConnectionUtil.createPooledConnection(jdcc);
    } else {
      connection = ConnectionUtil.createConnection(jdcc);
    }

    if (connection == null)
      throw new CreateConnectionFailureException(
          "JdbcConnection:createConnection() failure for " + getConnectionName() + ".");

    return connection;
  }
コード例 #8
0
 public List<Borrower> ListBorrower() throws Exception {
   ConnectionUtil c = new ConnectionUtil();
   Connection conn = c.createConnection();
   try {
     BorrowerDAO bdao = new BorrowerDAO(conn);
     List<Borrower> bor = bdao.readAll();
     conn.commit();
     return bor;
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   } finally {
     conn.close();
   }
 }
コード例 #9
0
 public List<Publisher> ListPublisher() throws Exception {
   ConnectionUtil c = new ConnectionUtil();
   Connection conn = c.createConnection();
   try {
     PublisherDAO pdao = new PublisherDAO(conn);
     List<Publisher> publishers = pdao.readAll();
     conn.commit();
     return publishers;
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   } finally {
     conn.close();
   }
 }
コード例 #10
0
 public List<BookLoans> ListBookLoans() throws Exception {
   ConnectionUtil c = new ConnectionUtil();
   Connection conn = c.createConnection();
   try {
     BookLoansDAO bldao = new BookLoansDAO(conn);
     List<BookLoans> bookloanslist = bldao.readAll();
     conn.commit();
     return bookloanslist;
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   } finally {
     conn.close();
   }
 }
コード例 #11
0
ファイル: ClientImpl.java プロジェクト: rramdas/voltdb
  /**
   * Create a new client without any initial connections. Also provide a hint indicating the
   * expected serialized size of most outgoing procedure invocations. This helps size initial
   * allocations for serializing network writes
   *
   * @param expectedOutgoingMessageSize Expected size of procedure invocations in bytes
   * @param maxArenaSizes Maximum size arenas in the memory pool should grow to
   * @param heavyweight Whether to use multiple or a single thread
   */
  ClientImpl(ClientConfig config) {
    m_distributer =
        new Distributer(
            config.m_heavyweight,
            config.m_procedureCallTimeoutNanos,
            config.m_connectionResponseTimeoutMS,
            config.m_useClientAffinity,
            config.m_subject);
    m_distributer.addClientStatusListener(new CSL());
    String username = config.m_username;
    if (config.m_subject != null) {
      username = config.m_subject.getPrincipals().iterator().next().getName();
    }
    m_username = username;

    if (config.m_cleartext) {
      m_passwordHash = ConnectionUtil.getHashedPassword(config.m_password);
    } else {
      m_passwordHash = Encoder.hexDecode(config.m_password);
    }
    if (config.m_listener != null) {
      m_distributer.addClientStatusListener(config.m_listener);
    }
    assert (config.m_maxOutstandingTxns > 0);
    m_blessedThreadIds.addAll(m_distributer.getThreadIds());
    if (config.m_autoTune) {
      m_distributer.m_rateLimiter.enableAutoTuning(config.m_autoTuneTargetInternalLatency);
    } else {
      m_distributer.m_rateLimiter.setLimits(
          config.m_maxTransactionsPerSecond, config.m_maxOutstandingTxns);
    }
  }
コード例 #12
0
 /** *************************************************************************************** */
 public void DeleteBorrower(Borrower bor) throws Exception {
   ConnectionUtil c = new ConnectionUtil();
   Connection conn = c.createConnection();
   try {
     if (bor == null) {
       throw new Exception("The Borrower cannot be null");
     } else {
       BorrowerDAO bordao = new BorrowerDAO(conn);
       bordao.delete(bor);
       conn.commit();
     }
   } catch (Exception e) {
     e.printStackTrace();
     conn.rollback();
   } finally {
     conn.close();
   }
 }
コード例 #13
0
  /** *************************************************************************************** */
  public Genre ListOneGenre(int genre_id) throws Exception {

    ConnectionUtil c = new ConnectionUtil();
    Connection conn = c.createConnection();

    try {

      GenreDAO gdao = new GenreDAO(conn);
      Genre genre = gdao.readOne(genre_id);
      return genre;

    } catch (Exception e) {
      // TODO: handle exception
      e.printStackTrace();
      return null;
    } finally {
      conn.close();
    }
  }
コード例 #14
0
  /** *************************************************************************************** */
  public LibBranch ListOneBranche(int branchId) throws Exception {

    ConnectionUtil c = new ConnectionUtil();
    Connection conn = c.createConnection();

    try {

      LibBranchDAO lib = new LibBranchDAO(conn);
      LibBranch branch = lib.readOne(branchId);
      return branch;

    } catch (Exception e) {
      // TODO: handle exception
      e.printStackTrace();
      return null;
    } finally {
      conn.close();
    }
  }
コード例 #15
0
  /** *************************************************************************************** */
  public Book ListOneBook(int bookId) throws Exception {

    ConnectionUtil c = new ConnectionUtil();
    Connection conn = c.createConnection();

    try {

      BookDAO bdao = new BookDAO(conn);
      Book book = bdao.readOne(bookId);
      return book;

    } catch (Exception e) {
      // TODO: handle exception
      e.printStackTrace();
      return null;
    } finally {
      conn.close();
    }
  }
コード例 #16
0
  /** *************************************************************************************** */
  public Borrower ListOneBorrower(int cardNo) throws Exception {

    ConnectionUtil c = new ConnectionUtil();
    Connection conn = c.createConnection();

    try {

      BorrowerDAO bdao = new BorrowerDAO(conn);
      Borrower bor = bdao.readOne(cardNo);
      return bor;

    } catch (Exception e) {
      // TODO: handle exception
      e.printStackTrace();
      return null;
    } finally {
      conn.close();
    }
  }
コード例 #17
0
  /** *************************************************************************************** */
  public BookLoans ListOneBookLoan(int bookId, int branchId, int cardNo) throws Exception {

    ConnectionUtil c = new ConnectionUtil();
    Connection conn = c.createConnection();

    try {

      BookLoansDAO bldao = new BookLoansDAO(conn);
      BookLoans bookloans = bldao.readOne(bookId, branchId, cardNo);
      return bookloans;

    } catch (Exception e) {
      // TODO: handle exception
      e.printStackTrace();
      return null;
    } finally {
      conn.close();
    }
  }
コード例 #18
0
  /** *************************************************************************************** */
  public Publisher ListOnePublisher(int PublisherId) throws Exception {

    ConnectionUtil c = new ConnectionUtil();
    Connection conn = c.createConnection();

    try {

      PublisherDAO pdao = new PublisherDAO(conn);
      Publisher publisher = pdao.readOne(PublisherId);
      return publisher;

    } catch (Exception e) {
      // TODO: handle exception
      e.printStackTrace();
      return null;
    } finally {
      conn.close();
    }
  }
コード例 #19
0
  /** *************************************************************************************** */
  public Author ListOneAuthor(int authorId) throws Exception {

    ConnectionUtil c = new ConnectionUtil();
    Connection conn = c.createConnection();

    try {

      AuthorDAO adao = new AuthorDAO(conn);
      Author author = adao.readOne(authorId);
      return author;

    } catch (Exception e) {
      // TODO: handle exception
      e.printStackTrace();
      return null;
    } finally {
      conn.close();
    }
  }
コード例 #20
0
 /** ******************************************************************************************* */
 public void DeleteGenre(Genre genre) throws Exception {
   ConnectionUtil c = new ConnectionUtil();
   Connection conn = c.createConnection();
   try {
     if (genre == null
         || genre.getGenreName().length() == 0
         || genre.getGenreName().length() > 45) {
       throw new Exception("The Genre cannot be null");
     } else {
       GenreDAO gdao = new GenreDAO(conn);
       gdao.delete(genre);
       conn.commit();
     }
   } catch (Exception e) {
     e.printStackTrace();
     conn.rollback();
   } finally {
     conn.close();
   }
 }
コード例 #21
0
 /** ******************************************************************************************* */
 public void DeleteBook(Book book) throws Exception {
   ConnectionUtil c = new ConnectionUtil();
   Connection conn = c.createConnection();
   try {
     if (book == null
         || book.getTitle() == null
         || book.getTitle().length() == 0
         || book.getTitle().length() > 45) {
       throw new Exception("The Book cannot be null");
     } else {
       BookDAO bdao = new BookDAO(conn);
       bdao.delete(book);
       conn.commit();
     }
   } catch (Exception e) {
     e.printStackTrace();
     conn.rollback();
   } finally {
     conn.close();
   }
 }
コード例 #22
0
 /** *************************************************************************************** */
 public void DeleteBookLoans(BookLoans bookloan) throws Exception {
   ConnectionUtil c = new ConnectionUtil();
   Connection conn = c.createConnection();
   try {
     if (bookloan == null
         || bookloan.getDateOut() == null
         || bookloan.getDueDate() == null
         || bookloan.getDateOut().after(bookloan.getDueDate())) {
       throw new Exception("The Borrower cannot be null");
     } else {
       BookLoansDAO bookLdao = new BookLoansDAO(conn);
       bookLdao.delete(bookloan);
       conn.commit();
     }
   } catch (Exception e) {
     e.printStackTrace();
     conn.rollback();
   } finally {
     conn.close();
   }
 }
コード例 #23
0
 /** *************************************************************************************** */
 public void DeleteAuthor(Author author) throws Exception {
   ConnectionUtil c = new ConnectionUtil();
   Connection conn = c.createConnection();
   try {
     if (author == null
         || author.getAuthorName() == null
         || author.getAuthorName().length() == 0
         || author.getAuthorName().length() > 45) {
       throw new Exception("The Author cannot be null");
     } else {
       AuthorDAO adao = new AuthorDAO(conn);
       adao.delete(author);
       conn.commit();
     }
   } catch (Exception e) {
     e.printStackTrace();
     conn.rollback();
   } finally {
     conn.close();
   }
 }
コード例 #24
0
 /** *************************************************************************************** */
 public void UpdateBookloans(BookLoans bookloans) throws Exception {
   ConnectionUtil c = new ConnectionUtil();
   Connection conn = c.createConnection();
   try {
     if (bookloans == null
         || bookloans.getCardNo() == 0
         || bookloans.getBookId() == 0
         || bookloans.getBranchId() == 0
         || bookloans.getDateOut() == null
         || bookloans.getDueDate() == null
         || bookloans.getDateOut().after(bookloans.getDueDate())) {
       throw new Exception("The Borrower cannot be null or CardNo can not be 0 ");
     } else {
       BookLoansDAO bookldao = new BookLoansDAO(conn);
       bookldao.update(bookloans);
       conn.commit();
     }
   } catch (Exception e) {
     e.printStackTrace();
     conn.rollback();
   } finally {
     conn.close();
   }
 }
コード例 #25
0
 /** *************************************************************************************** */
 public void DeleteLibBranch(LibBranch branch) throws Exception {
   ConnectionUtil c = new ConnectionUtil();
   Connection conn = c.createConnection();
   try {
     if (branch == null
         || branch.getLibraryBranchName() == null
         || branch.getLibraryBranchName().length() == 0
         || branch.getLibraryBranchName().length() > 45
         || branch.getLibraryBranchAddress() == null
         || branch.getLibraryBranchAddress().length() == 0
         || branch.getLibraryBranchAddress().length() > 45) {
       throw new Exception("The Book cannot be null");
     } else {
       LibBranchDAO lib = new LibBranchDAO(conn);
       lib.delete(branch);
       conn.commit();
     }
   } catch (Exception e) {
     e.printStackTrace();
     conn.rollback();
   } finally {
     conn.close();
   }
 }
コード例 #26
0
ファイル: ClientImpl.java プロジェクト: rramdas/voltdb
  public void createConnectionWithHashedCredentials(
      String host, int port, String program, byte[] hashedPassword) throws IOException {
    if (m_isShutdown) {
      throw new IOException("Client instance is shutdown");
    }
    final String subProgram = (program == null) ? "" : program;
    final byte[] subPassword =
        (hashedPassword == null) ? ConnectionUtil.getHashedPassword("") : hashedPassword;

    if (!verifyCredentialsAreAlwaysTheSame(subProgram, subPassword)) {
      throw new IOException(
          "New connection authorization credentials do not match previous credentials for client.");
    }

    m_distributer.createConnectionWithHashedCredentials(host, subProgram, subPassword, port);
  }
コード例 #27
0
 public boolean saveNotification(Notification notification) throws SQLException {
   Connection conn = ConnectionUtil.getConnection();
   Statement stmt = null;
   try {
     stmt = conn.createStatement();
     String sql =
         "INSERT INTO communication_hub.notifications(notification_subject,notification_to,notification_from,messageBody,receiver_guid,receiver_tenant_guid,sender_guid,sender_tenant_guid,received_date,forwardDate,forwardEmail,forward,messagetype)"
             + "VALUES('"
             + notification.getSubject()
             + "','"
             + notification.getTo()
             + "','"
             + notification.getFrom()
             + "','"
             + notification.getMessageBody()
             + "','"
             + notification.getReceiverGUID()
             + "','"
             + notification.getReceiverTenantGuid()
             + "','"
             + notification.getSenderGUID()
             + "','"
             + notification.getSenderTenantGUID()
             + "','"
             + DateUtil.getShortDate(notification.getReceivedDate())
             + "','"
             + DateUtil.getShortDate(notification.getForwardDate())
             + "','"
             + notification.getForwardEmail()
             + "',"
             + notification.getForward()
             + ","
             + notification.getMessageType()
             + ")";
     System.out.println("Sql:" + sql);
     int rows = stmt.executeUpdate(sql);
     System.out.println("saved " + rows);
   } catch (Exception ex) {
     ex.printStackTrace();
     return false;
   } finally {
     if (stmt != null) stmt.close();
     if (conn != null) conn.close();
   }
   return true;
 }