// Path: lib/src/main/java/com/google/capillary/NoSuchKeyException.java
// public final class NoSuchKeyException extends CapillaryException {
// 
//   /**
//    * Creates a new {@link NoSuchKeyException} object.
//    *
//    * @param msg the exception message.
//    */
//   public NoSuchKeyException(String msg) {
//     super(msg);
//   }
// }


import com.google.capillary.NoSuchKeyException;
import com.google.capillary.demo.common.AddOrUpdatePublicKeyRequest;
import com.google.capillary.demo.common.AddOrUpdateUserRequest;
import com.google.capillary.demo.common.KeyAlgorithm;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

  private final String databasePath;

  /**
   * Initializes a new {@link DemoDb}.
   */
  DemoDb(String databasePath) {
    this.databasePath = databasePath;
  }

  /**
   * Inserts or updates the given recipient Capillary public key in the SQLite database.
   */
  void addOrUpdatePublicKey(AddOrUpdatePublicKeyRequest request) throws SQLException {
    try (
        Connection connection = DriverManager.getConnection(databasePath);
        PreparedStatement statement = connection.prepareStatement(CMD_PUT_PUBLIC_KEY)
    ) {
      statement.setString(1, request.getUserId());
      statement.setInt(2, request.getAlgorithmValue());
      statement.setInt(3, request.getIsAuth() ? 1 : 0);
      statement.setBytes(4, request.getKeyBytes().toByteArray());
      statement.executeUpdate();
    }
  }

  /**
   * Returns the Capillary public key of the given user and key parameters.
   */
  byte[] getKeyBytes(String userId, KeyAlgorithm algorithm, boolean isAuth)
// Path: lib/src/main/java/com/google/capillary/NoSuchKeyException.java
// public final class NoSuchKeyException extends CapillaryException {
// 
//   /**
//    * Creates a new {@link NoSuchKeyException} object.
//    *
//    * @param msg the exception message.
//    */
//   public NoSuchKeyException(String msg) {
//     super(msg);
//   }
// }


// Path: demo/server/src/main/java/com/google/capillary/demo/server/DemoDb.java
import com.google.capillary.NoSuchKeyException;
import com.google.capillary.demo.common.AddOrUpdatePublicKeyRequest;
import com.google.capillary.demo.common.AddOrUpdateUserRequest;
import com.google.capillary.demo.common.KeyAlgorithm;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


  private final String databasePath;

  /**
   * Initializes a new {@link DemoDb}.
   */
  DemoDb(String databasePath) {
    this.databasePath = databasePath;
  }

  /**
   * Inserts or updates the given recipient Capillary public key in the SQLite database.
   */
  void addOrUpdatePublicKey(AddOrUpdatePublicKeyRequest request) throws SQLException {
    try (
        Connection connection = DriverManager.getConnection(databasePath);
        PreparedStatement statement = connection.prepareStatement(CMD_PUT_PUBLIC_KEY)
    ) {
      statement.setString(1, request.getUserId());
      statement.setInt(2, request.getAlgorithmValue());
      statement.setInt(3, request.getIsAuth() ? 1 : 0);
      statement.setBytes(4, request.getKeyBytes().toByteArray());
      statement.executeUpdate();
    }
  }

  /**
   * Returns the Capillary public key of the given user and key parameters.
   */
  byte[] getKeyBytes(String userId, KeyAlgorithm algorithm, boolean isAuth)
      throws SQLException, NoSuchKeyException {