private void createEntry()

in library/src/main/java/org/apache/fineract/cn/anubis/repository/TenantAuthorizationDataRepository.java [198:259]


  private void createEntry(final @Nonnull Session tenantSession,
                           final @Nonnull String timestamp,
                           final @Nonnull BigInteger identityManagerPublicKeyModulus,
                           final @Nonnull BigInteger identityManagerPublicKeyExponent,
                           final @Nonnull BigInteger applicationPrivateKeyModulus,
                           final @Nonnull BigInteger applicationPrivateKeyExponent,
                           final @Nonnull BigInteger applicationPublicKeyModulus,
                           final @Nonnull BigInteger applicationPublicKeyExponent)
  {

    final ResultSet timestampCount =
        tenantSession.execute("SELECT count(*) FROM " + this.tableName + " WHERE " + TIMESTAMP_COLUMN + " = '" + timestamp + "'");
    final Long value = timestampCount.one().get(0, Long.class);
    if (value == 0L) {
      //There will only be one entry in this table per version.
      final BoundStatement tenantCreationStatement =
          tenantSession.prepare("INSERT INTO " + tableName + " ("
                  + TIMESTAMP_COLUMN + ", "
                  + VALID_COLUMN + ", "
                  + IDENTITY_MANAGER_PUBLIC_KEY_MOD_COLUMN + ", "
                  + IDENTITY_MANAGER_PUBLIC_KEY_EXP_COLUMN + ", "
                  + APPLICATION_PRIVATE_KEY_MOD_COLUMN + ", "
                  + APPLICATION_PRIVATE_KEY_EXP_COLUMN + ", "
                  + APPLICATION_PUBLIC_KEY_MOD_COLUMN + ", "
                  + APPLICATION_PUBLIC_KEY_EXP_COLUMN + ")"
                  + "VALUES (?, ?, ?, ?, ?, ?, ?, ?)").bind();
      completeBoundStatement(tenantCreationStatement,
              timestamp,
              true,
              identityManagerPublicKeyModulus,
              identityManagerPublicKeyExponent,
              applicationPrivateKeyModulus,
              applicationPrivateKeyExponent,
              applicationPublicKeyModulus,
              applicationPublicKeyExponent);

      tenantSession.execute(tenantCreationStatement);
    } else {
      //TODO: Make sure existing entry hasn't been invalidated, or just don't allow an update.
      final BoundStatement tenantUpdateStatement =
          tenantSession.prepare("UPDATE " + tableName + " SET "
                  + VALID_COLUMN + " = ?, "
                  + IDENTITY_MANAGER_PUBLIC_KEY_MOD_COLUMN + " = ?, "
                  + IDENTITY_MANAGER_PUBLIC_KEY_EXP_COLUMN + " = ?, "
                  + APPLICATION_PRIVATE_KEY_MOD_COLUMN + " = ?, "
                  + APPLICATION_PRIVATE_KEY_EXP_COLUMN + " = ?, "
                  + APPLICATION_PUBLIC_KEY_MOD_COLUMN + " = ?, "
                  + APPLICATION_PUBLIC_KEY_EXP_COLUMN + " = ? "
                  + "WHERE " + TIMESTAMP_COLUMN + " = ?").bind();
      completeBoundStatement(tenantUpdateStatement,
              timestamp,
              true,
              identityManagerPublicKeyModulus,
              identityManagerPublicKeyExponent,
              applicationPrivateKeyModulus,
              applicationPrivateKeyExponent,
              applicationPublicKeyModulus,
              applicationPublicKeyExponent);

      tenantSession.execute(tenantUpdateStatement);
    }
  }