Cassandra services
A Cassandra service is a type of service that can be used to execute CQL statements against a Cassandra database.
Creating a Cassandra service
To create a Cassandra service, follow the steps below:
- Launch the Cassandra service wizard by right-clicking on the target package's
code
directory (or any of the directories underneath it) where you'd like to store the Cassandra service, and then select New > Cassandra Service. -
In the wizard, specify the following details:
- Location - where the Cassandra service will reside; its default value will be the folder where you started the wizard from
- Name - the name of the Cassandra service
- Connection Name - the name of the database that the service will connect to while developing the service, and by default when executing it
- Query Type - the type of Cassandra statement the service will perform
- Keyspace - the keyspace that the service will use by default
-
Click Finish.
Launch the wizard using keyboard shortcuts only
In Martini, you can open the Cassandra service wizard by pressing (or in Martini Online)
and typing cql
in the dialog's search box. After that, press and the wizard will appear.
Editing Cassandra services
After creating the Cassandra service, the service will automatically open, and you will be shown the Cassandra service editor.
Here's a breakdown of its primary components:
-
Connection Name drop-down
The name of the database connection Martini will connect to when being executed. By clicking on the drop-down list, you will be able to choose the database you want to execute queries against. Only registered and started database connections will be selectable. You can change the database connection at runtime by setting the
$martiniConnectionPool
input property to the name of another database connection. -
Cassandra Service Type drop-down
The specific type of operation that the service will execute. Currently, these are the supported types:
Type Description Select Single Used to get the first row of the result set from a SELECT
statement.Select Multi Returns an input cursor representing the result set rows from a SELECT
statement.Insert Used to insert one row into a table. Insert Batch Used to insert multiple rows into a table. These types of services return an output cursor. Update Used to update a single row. Update Batch Used to update multiple rows in a table. These types of services return an output cursor. Delete Used to delete a single row. Delete Batch Used to delete multiple rows from a table. These types of services return an output cursor. -
Keyspace drop-down
The default keyspace to be used by this Cassandra service at runtime.
-
Show System checkbox
This is to choose whether to show Cassandra system keyspaces in the Database Tree.
-
Database tree
Displays the target database's keyspaces, tables, columns, and their types. You can use this to navigate around the database.
-
CQL Statement text area
The CQL statement based on the Service Type selected. You can edit the service's CQL directly using this component. You can also press whilst editing to bring up the content-assist menu.
Format your CQL query
You can format your query by right clicking on the statement text area and selecting Format, or by using the shortcut .
Testing and previewing CQL queries
If you aren't sure exactly what CQL you need, you can use the Database perspective in Martini Desktop to test your queries. Alternatively, you can right click on a Cassandra service in the Navigator, and choose Export > CQL Query.
Inputs and outputs
Like regular services, Cassandra services have inputs and outputs, too. As the CQL statement changes, the Cassandra service's inputs and outputs will change as well.
If the CQL statement is incorrect or the output model could not be generated, then a warning will appear underneath the CQL editor. When you hover your mouse pointer over the warning, a tooltip will show up which will provide you with more information on what is wrong with the statement.
Gloop Cassandra services also have special input properties you can set:
Property | Type | Applicable Operations | Description |
---|---|---|---|
$martiniConnectionPool |
Input | All operations | The database connection name. If this isn't specified, the default database configured in the editor will be used. |
$keyspace |
Input | All operations | The keyspace name. If this isn't specified, the default keyspace configured in the editor will be used. |
$consistencyLevel |
Input | All operations | The consistency level to be used for this service. If this isn't specified, the default consistency level configured in the database will be used. |
$serialConsistencyLevel |
Input | All operations | The serial consistency level to be used for this service. If this isn't specified, the default consistency level configured in the database will be used. |
$idempotent |
Input | All operations | The idempotence to be used for this service. If this isn't specified, the default consistency level configured in the database will be used. |
Parameterized queries
Parameterized CQL queries are also supported in Gloop. Parameters allow for flexible
CQL commands - arguments don't need to be hard-coded in the CQL statement. You can specify their values by setting
the parameters' name with a :
character prefix, as shown below:
1 2 3 4 5 6 |
|
As you modify the CQL and add bound parameters, the Input/Output view will change as shown below:
Create models from a table
If you want to have a Data model that represents a Cassandra table, you can right click on a table in the Database tree, then select Export to Data Model.
You can also use Martini to help write the CQL statements for you. Right click on the table or columns you would like to include in the statement and choose the type of CQL statement you would like to execute from the appearing context menu. The items in the context menu will depend on the selected value for the Type dropdown. In the example below, Select was used for Type, hence selectable statements are SELECT statements only.
WHERE clause limitations
Cassandra has limitations with the WHERE
clause. Martini will only add supported columns
to the WHERE
clause.
Generate statements by dragging and dropping table or column nodes to the editor
You can drag and drop tables or columns displayed on the Database node in the Navigator view to the editor. Doing this will prompt Martini to generate a CQL statement based on the selected statement type and provided tables or columns.