Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #54 from Manuri/0.991.0-release
Browse files Browse the repository at this point in the history
Sync with 0.991.0 version
  • Loading branch information
wggihan authored Apr 24, 2019
2 parents a203dbd + 744c2e3 commit c6e93fd
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 58 deletions.
4 changes: 2 additions & 2 deletions component/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</dependency>
<dependency>
<groupId>org.ballerinalang</groupId>
<artifactId>ballerina-runtime</artifactId>
<artifactId>ballerina-runtime-api</artifactId>
</dependency>
<dependency>
<groupId>org.ballerinalang</groupId>
Expand All @@ -72,7 +72,7 @@
</dependency>
<dependency>
<groupId>org.ballerinalang</groupId>
<artifactId>ballerina-runtime</artifactId>
<artifactId>ballerina-runtime-api</artifactId>
<type>zip</type>
<classifier>ballerina-binary-repo</classifier>
</dependency>
Expand Down
3 changes: 1 addition & 2 deletions component/src/main/ballerina/cassandra/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ if (returned is ()) {
var selectRet = conn->select("select id, name, salary from testballerina.person where salary = ? ALLOW FILTERING",
Person, pSalary);
if (selectRet is table) {
table dt = selectRet;
if (selectRet is table<Person>) {
// Processing logic
} else {
io:println("Select data from person table failed: " + selectRet.reason());
Expand Down
10 changes: 5 additions & 5 deletions component/src/main/ballerina/cassandra/endpoint.bal
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public type Client client object {
# + queryString - Query to be executed
# + recordType - The Type result should be mapped to
# + return - `table` representing the result of the select action or `error` if an error occurs
public remote extern function select(string queryString, typedesc recordType, Param... parameters)
returns (table<record {}>|error);
public remote function select(string queryString, typedesc recordType, Param... parameters)
returns (table<record {}>|error) = external;

# Execute update query on cassandra datasource.

# + queryString - Query to be executed
# + return - `nil` or `error` if an error occurs
public remote extern function update(string queryString, Param... parameters) returns (error?);
public remote function update(string queryString, Param... parameters) returns (error?) = external;

# Stops the registered service.
public function stop() {
Expand All @@ -47,6 +47,6 @@ public type Client client object {
# An internal function used by clients to shutdown the connection pool.
#
# + cassandraClient - Client object that encapsulates the connection/connection pool
extern function close(Client cassandraClient);
function close(Client cassandraClient) = external;

extern function initClient(Client cassandraClient, ClientEndpointConfig clientEndpointConfig);
function initClient(Client cassandraClient, ClientEndpointConfig clientEndpointConfig) = external;
53 changes: 23 additions & 30 deletions component/src/main/ballerina/cassandra/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@
// under the License.

# The Datatype of the parameter.
public type Type "INT"|"BIGINT"|"VARINT"|"FLOAT"|"DOUBLE"|"TEXT"|"BOOLEAN"|"LIST";
public type Type TYPE_INT | TYPE_BIGINT | TYPE_VARINT | TYPE_FLOAT | TYPE_DOUBLE | TYPE_TEXT | TYPE_BOOLEAN | TYPE_LIST;

# A 32-bit signed integer.
public final Type TYPE_INT = "INT";
public const TYPE_INT = "INT";

# A 64-bit signed long.
public final Type TYPE_BIGINT = "BIGINT";
public const TYPE_BIGINT = "BIGINT";

# Arbitrary precision integer.
public final Type TYPE_VARINT = "VARINT";
public const TYPE_VARINT = "VARINT";

# A 32-bit IEEE-754 floating point.
public final Type TYPE_FLOAT = "FLOAT";
public const TYPE_FLOAT = "FLOAT";

# A 64-bit IEEE-754 floating point.
public final Type TYPE_DOUBLE = "DOUBLE";
public const TYPE_DOUBLE = "DOUBLE";

# UTF-8 encoded string.
public final Type TYPE_TEXT = "TEXT";
public const TYPE_TEXT = "TEXT";

# Boolean value either True or false.
public final Type TYPE_BOOLEAN = "BOOLEAN";
public const TYPE_BOOLEAN = "BOOLEAN";

# A collection of one or more ordered elements.
public final Type TYPE_LIST = "LIST";
public const TYPE_LIST = "LIST";

# Represents complex parameter passed to `select` or `update` operation.

Expand All @@ -60,14 +60,13 @@ public type Param string|int|boolean|float|Parameter;
# + username - Username for the database connection
# + password - Password for the database connection
# + options - Properties for the connection configuration
public type ClientEndpointConfig record {
public type ClientEndpointConfig record {|
string host;
int port;
string username;
string password;
ConnectionProperties options = {};
!...;
};
|};

# ConnectionProperties type represents the properties which are used to configure Cassandra connection.
#
Expand All @@ -89,7 +88,7 @@ public type ClientEndpointConfig record {
# + socketOptionsConfig - Options to configure low-level socket options for the connections kept to the Cassandra
# hosts
# + protocolOptionsConfig - Options of the Cassandra native binary protocol
public type ConnectionProperties record {
public type ConnectionProperties record {|
string clusterName = "";
string loadBalancingPolicy = "";
string reconnectionPolicy = "";
Expand All @@ -108,8 +107,7 @@ public type ConnectionProperties record {
PoolingOptionsConfig poolingOptionsConfig = {};
SocketOptionsConfig socketOptionsConfig = {};
ProtocolOptionsConfig protocolOptionsConfig = {};
!...;
};
|};

# Options of the Cassandra native binary protocol.
#
Expand All @@ -118,16 +116,15 @@ public type ConnectionProperties record {
# + maxSchemaAgreementWaitSeconds - The maximum time to wait for schema agreement before returning from a DDL query
# + initialProtocolVersion - Version of the native protocol supported by the driver
# + compression - Compression supported by the Cassandra binary protocol
public type ProtocolOptionsConfig record {
public type ProtocolOptionsConfig record {|
boolean sslEnabled = false;
boolean noCompact = false;

int maxSchemaAgreementWaitSeconds = -1;

string initialProtocolVersion = "";
string compression = "";
!...;
};
|};

# Options related to defaults for individual queries.
#
Expand Down Expand Up @@ -158,7 +155,7 @@ public type ProtocolOptionsConfig record {
# refresh requests
# + refreshSchemaIntervalMillis - Determines the default window size in milliseconds used to debounce schema refresh
# requests
public type QueryOptionsConfig record {
public type QueryOptionsConfig record {|
string consistencyLevel = "";
string serialConsistencyLevel = "";

Expand All @@ -174,8 +171,7 @@ public type QueryOptionsConfig record {
int refreshNodeListIntervalMillis = -1;
int refreshNodeIntervalMillis = -1;
int refreshSchemaIntervalMillis = -1;
!...;
};
|};


# Options related to connection pooling.
Expand All @@ -193,7 +189,7 @@ public type QueryOptionsConfig record {
# + coreConnectionsPerHostRemote - The core number of connections per remote host
# + maxConnectionsPerHostRemote - The maximum number of connections per remote host
# + newConnectionThresholdRemote - The threshold that triggers the creation of a new connection to a remote host
public type PoolingOptionsConfig record {
public type PoolingOptionsConfig record {|
int maxRequestsPerConnectionLocal = -1;
int maxRequestsPerConnectionRemote = -1;
int idleTimeoutSeconds = -1;
Expand All @@ -206,8 +202,7 @@ public type PoolingOptionsConfig record {
int coreConnectionsPerHostRemote = -1;
int maxConnectionsPerHostRemote = -1;
int newConnectionThresholdRemote = -1;
!...;
};
|};

# Options to configure low-level socket options for the connections kept to the Cassandra hosts.
#
Expand All @@ -216,16 +211,14 @@ public type PoolingOptionsConfig record {
# + soLinger - The linger-on-close timeout
# + receiveBufferSize - A hint to the size of the underlying buffers for incoming network I/O
# + sendBufferSize - A hint to the size of the underlying buffers for outgoing network I/O
public type SocketOptionsConfig record {
public type SocketOptionsConfig record {|
int connectTimeoutMillis = -1;
int readTimeoutMillis = -1;
int soLinger = -1;
int receiveBufferSize = -1;
int sendBufferSize = -1;
!...;
};
|};

public type DatabaseErrorData record {
public type DatabaseErrorData record {|
string message;
!...;
};
|};
16 changes: 8 additions & 8 deletions component/src/test/resources/samples/cassandra-actions-test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ function testKeySpaceCreation() {
password: "cassandra",
options: {}
});
_ = conn->update("CREATE KEYSPACE dummyks WITH replication = {'class':'SimpleStrategy', 'replication_factor'
checkpanic conn->update("CREATE KEYSPACE dummyks WITH replication = {'class':'SimpleStrategy', 'replication_factor'
:1}");
conn.stop();
}

function testDuplicateKeySpaceCreation() returns (any) {
function testDuplicateKeySpaceCreation() returns error? {
c:Client conn = new({
host: "localhost",
port: 9142,
username: "cassandra",
password: "cassandra",
options: {}
});
_ = conn->update("CREATE KEYSPACE duplicatekstest WITH replication = {'class':'SimpleStrategy',
checkpanic conn->update("CREATE KEYSPACE duplicatekstest WITH replication = {'class':'SimpleStrategy',
'replication_factor':1}");

var result = conn->update("CREATE KEYSPACE duplicatekstest WITH replication = {'class':'SimpleStrategy',
Expand All @@ -46,7 +46,7 @@ function testTableCreation() {
password: "cassandra",
options: {}
});
_ = conn->update("CREATE TABLE peopleinfoks.student(id int PRIMARY KEY,name text, age int)");
checkpanic conn->update("CREATE TABLE peopleinfoks.student(id int PRIMARY KEY,name text, age int)");
conn.stop();
}

Expand All @@ -65,7 +65,7 @@ function testInsert() {
c:Parameter pIncome = { cqlType: c:TYPE_DOUBLE, value: 1000.5 };
c:Parameter pMarried = { cqlType: c:TYPE_BOOLEAN, value: true };

_ = conn->update("INSERT INTO peopleinfoks.person(id, name, salary, income, married) values (?,?,?,?,?)",
checkpanic conn->update("INSERT INTO peopleinfoks.person(id, name, salary, income, married) values (?,?,?,?,?)",
pID, pName, pSalary, pIncome, pMarried);
conn.stop();
}
Expand All @@ -81,7 +81,7 @@ function testInsertRawParams() {

c:Parameter pIncome = { cqlType: c:TYPE_DOUBLE, value: 1001.5 };

_ = conn->update("INSERT INTO peopleinfoks.person(id, name, salary, income, married) values (?,?,?,?,?)",
checkpanic conn->update("INSERT INTO peopleinfoks.person(id, name, salary, income, married) values (?,?,?,?,?)",
10, "Tommy", 101.5, pIncome, false);
conn.stop();
}
Expand Down Expand Up @@ -155,7 +155,7 @@ function testSelect() returns (int, string, float) {
return (id, name, salary);
}

function testSelectNonExistentColumn() returns (any) {
function testSelectNonExistentColumn() returns any | error {
c:Client conn = new({
host: "localhost",
port: 9142,
Expand All @@ -179,7 +179,7 @@ function testInsertWithNilParams() {
options: {}
});

_ = conn->update("INSERT INTO peopleinfoks.person(id, name, salary, income, married)
checkpanic conn->update("INSERT INTO peopleinfoks.person(id, name, salary, income, married)
values (10,'Jim',101.5,1001.5,false)");
conn.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function testConnectionInitWithLBPolicy() {
password: "cassandra",
options: { loadBalancingPolicy: "DCAwareRoundRobinPolicy" }
});
_ = conn->update("CREATE KEYSPACE lbtestkeyspace WITH replication = {'class': 'SimpleStrategy',
checkpanic conn->update("CREATE KEYSPACE lbtestkeyspace WITH replication = {'class': 'SimpleStrategy',
'replication_factor' :1}");
conn.stop();
}
Expand All @@ -37,7 +37,7 @@ function testConnectionInitWithRetryPolicy() {
options: { retryPolicy: "DefaultRetryPolicy" }
});

_ = conn->update("CREATE KEYSPACE retrytestkeyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor':
checkpanic conn->update("CREATE KEYSPACE retrytestkeyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor':
1}");
conn.stop();
}
Expand All @@ -62,7 +62,7 @@ function testConnectionInitWithReconnectionPolicy() {
options: { reconnectionPolicy: "ConstantReconnectionPolicy", constantReconnectionPolicyDelay: 500 }
});

_ = conn->update("CREATE KEYSPACE reconnectiontestkeyspace WITH replication = {'class': 'SimpleStrategy',
checkpanic conn->update("CREATE KEYSPACE reconnectiontestkeyspace WITH replication = {'class': 'SimpleStrategy',
'replication_factor': 1}");
conn.stop();
}
Expand Down Expand Up @@ -113,7 +113,7 @@ function testConnectionInitWithPoolingOptions() {
coreConnectionsPerHostLocal: 2, maxConnectionsPerHostLocal: 2, newConnectionThresholdLocal: 100,
coreConnectionsPerHostRemote: 1, maxConnectionsPerHostRemote: 8,
newConnectionThresholdRemote: 100 } } });
_ = conn->update("CREATE KEYSPACE poolingoptionstestkeyspace WITH replication = {'class': 'SimpleStrategy',
checkpanic conn->update("CREATE KEYSPACE poolingoptionstestkeyspace WITH replication = {'class': 'SimpleStrategy',
'replication_factor': 1}");
conn.stop();

Expand All @@ -129,7 +129,7 @@ function testConnectionInitWithSocketOptions() {
options: { socketOptionsConfig: {
connectTimeoutMillis: 5000, readTimeoutMillis: 12000, soLinger: 0 } }
});
_ = conn->update("CREATE KEYSPACE socketoptionstestkeyspace WITH replication = {'class': 'SimpleStrategy',
checkpanic conn->update("CREATE KEYSPACE socketoptionstestkeyspace WITH replication = {'class': 'SimpleStrategy',
'replication_factor': 1}");
conn.stop();
}
Expand All @@ -146,7 +146,7 @@ function testConnectionInitWithQueryOptions() {
maxPendingRefreshNodeRequests: 20, maxPendingRefreshSchemaRequests: 20, refreshNodeListIntervalMillis: 1000,
refreshNodeIntervalMillis: 1000, refreshSchemaIntervalMillis: 1000 } }
});
_ = conn->update("CREATE KEYSPACE queryoptionstestkeyspace WITH replication = {'class': 'SimpleStrategy',
checkpanic conn->update("CREATE KEYSPACE queryoptionstestkeyspace WITH replication = {'class': 'SimpleStrategy',
'replication_factor': 1}");
conn.stop();
}
Expand All @@ -162,7 +162,7 @@ function testConnectionInitWithProtocolOptions() {
initialProtocolVersion: "V4" } }
});

_ = conn->update("CREATE KEYSPACE protocoloptionstestkeyspace WITH replication = {'class': 'SimpleStrategy',
checkpanic conn->update("CREATE KEYSPACE protocoloptionstestkeyspace WITH replication = {'class': 'SimpleStrategy',
'replication_factor' :1}");
conn.stop();
}
Expand All @@ -177,7 +177,7 @@ function testConnectionInitWithAdditionalConnectionParams() {
false, withoutJMXReporting: false, allowRemoteDCsForLocalConsistencyLevel: false }
});

_ = conn->update("CREATE KEYSPACE conparamtestkeyspace WITH replication = {'class': 'SimpleStrategy',
checkpanic conn->update("CREATE KEYSPACE conparamtestkeyspace WITH replication = {'class': 'SimpleStrategy',
'replication_factor': 1}");
conn.stop();
}
Expand Down
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
</dependency>
<dependency>
<groupId>org.ballerinalang</groupId>
<artifactId>ballerina-runtime</artifactId>
<artifactId>ballerina-runtime-api</artifactId>
<version>${ballerina.version}</version>
<exclusions>
<exclusion>
Expand Down Expand Up @@ -185,7 +185,7 @@
</dependency>
<dependency>
<groupId>org.ballerinalang</groupId>
<artifactId>ballerina-runtime</artifactId>
<artifactId>ballerina-runtime-api</artifactId>
<version>${ballerina.version}</version>
<type>zip</type>
<classifier>ballerina-binary-repo</classifier>
Expand Down Expand Up @@ -244,6 +244,7 @@
<configuration>
<source>${wso2.maven.compiler.source}</source>
<target>${wso2.maven.compiler.target}</target>
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -329,7 +330,7 @@

<properties>
<project.scm.id>my-scm-server</project.scm.id>
<ballerina.version>0.990.3</ballerina.version>
<ballerina.version>0.991.0</ballerina.version>
<cassandra.version>3.6.0</cassandra.version>
<com.google.guava.version>19.0</com.google.guava.version>
<io.dropwizard.metrics.version>3.1.2</io.dropwizard.metrics.version>
Expand Down

0 comments on commit c6e93fd

Please sign in to comment.