public void create()

in service/src/main/java/org/apache/fineract/cn/provisioner/internal/repository/TenantCassandraRepository.java [102:132]


  public void create(final @Nonnull TenantEntity tenant) {
    final Mapper<TenantEntity> tenantEntityMapper = this.getMappingManager().mapper(TenantEntity.class);
    if (tenantEntityMapper.get(tenant.getIdentifier()) != null) {
      throw ServiceException.conflict("Tenant {0} already exists!", tenant.getIdentifier());
    }
    final Session session = this.getCluster(tenant).connect();
    try {
      session.execute("CREATE KEYSPACE " + tenant.getKeyspaceName() + " WITH REPLICATION = " +
              ReplicationStrategyResolver.replicationStrategy(
                      tenant.getReplicationType(),
                      tenant.getReplicas()));
    }
    catch (final AlreadyExistsException e) {
      throw ServiceException.badRequest("Tenant keyspace {0} already exists!", tenant.getKeyspaceName());
    }

    final String createCommandSourceTable =
            SchemaBuilder.createTable(tenant.getKeyspaceName(), "command_source")
                    .addPartitionKey("source", DataType.text())
                    .addPartitionKey("bucket", DataType.text())
                    .addClusteringColumn("created_on", DataType.timestamp())
                    .addColumn("command", DataType.text())
                    .addColumn("processed", DataType.cboolean())
                    .addColumn("failed", DataType.cboolean())
                    .addColumn("failure_message", DataType.text())
                    .buildInternal();
    session.execute(createCommandSourceTable);
    session.close();

    tenantEntityMapper.save(tenant);
  }