├── driver-core
├── CHANGELOG.rst
├── Upgrade_guide_to_2.0.rst
├── Upgrade_guide_to_2.1.rst
└── src
│ ├── test
│ ├── resources
│ │ ├── META-INF
│ │ │ └── services
│ │ │ │ └── org.testng.ITestNGListener
│ │ ├── client.keystore
│ │ ├── server.keystore
│ │ ├── client.truststore
│ │ ├── server.truststore
│ │ └── log4j.properties
│ └── java
│ │ └── com
│ │ └── datastax
│ │ └── driver
│ │ └── core
│ │ ├── M3PTokenVnodeIntegrationTest.java
│ │ ├── RPTokenVnodeIntegrationTest.java
│ │ ├── OPPTokenVnodeIntegrationTest.java
│ │ ├── M3PTokenIntegrationTest.java
│ │ ├── RPTokenIntegrationTest.java
│ │ ├── OPPTokenIntegrationTest.java
│ │ ├── SimpleStatementTest.java
│ │ ├── MockClocks.java
│ │ ├── SimpleJSONParserTest.java
│ │ ├── Assertions.java
│ │ ├── SessionAssert.java
│ │ ├── TableMetadataTest.java
│ │ ├── utils
│ │ └── CassandraVersion.java
│ │ ├── policies
│ │ ├── DelegatingSpeculativeExecutionPolicy.java
│ │ └── CloseableLoadBalancingPolicyTest.java
│ │ ├── schemabuilder
│ │ └── CreateIndexTest.java
│ │ ├── ClusterDelegateTest.java
│ │ ├── StreamIdGeneratorTest.java
│ │ ├── VersionNumberTest.java
│ │ ├── AsyncQueryTest.java
│ │ └── DataTypeAssert.java
│ └── main
│ ├── resources
│ └── com
│ │ └── datastax
│ │ └── driver
│ │ └── core
│ │ └── Driver.properties
│ └── java
│ └── com
│ └── datastax
│ └── driver
│ └── core
│ ├── SchemaElement.java
│ ├── exceptions
│ ├── package-info.java
│ ├── PagingStateException.java
│ ├── InvalidTypeException.java
│ ├── SyntaxError.java
│ ├── QueryValidationException.java
│ ├── TruncateException.java
│ ├── UnsupportedFeatureException.java
│ ├── QueryExecutionException.java
│ ├── InvalidQueryException.java
│ ├── InvalidConfigurationInQueryException.java
│ ├── UnauthorizedException.java
│ ├── TraceRetrievalException.java
│ ├── DriverInternalError.java
│ ├── DriverException.java
│ ├── AuthenticationException.java
│ ├── BootstrappingException.java
│ ├── OverloadedException.java
│ └── UnpreparedException.java
│ ├── policies
│ ├── package-info.java
│ ├── ChainableLoadBalancingPolicy.java
│ ├── CloseableAddressTranslater.java
│ ├── CloseableLoadBalancingPolicy.java
│ ├── IdentityTranslater.java
│ ├── NoSpeculativeExecutionPolicy.java
│ └── ConstantReconnectionPolicy.java
│ ├── querybuilder
│ ├── package-info.java
│ ├── Ordering.java
│ ├── BindMarker.java
│ ├── Truncate.java
│ └── Using.java
│ ├── schemabuilder
│ ├── package-info.java
│ ├── StatementStart.java
│ ├── NativeColumnType.java
│ └── ColumnType.java
│ ├── package-info.java
│ ├── GettableData.java
│ ├── BusyConnectionException.java
│ ├── SettableData.java
│ ├── ProtocolV1Authenticator.java
│ ├── OperationTimedOutException.java
│ ├── ServerSideTimestampGenerator.java
│ ├── TransportException.java
│ ├── TimestampGenerator.java
│ ├── Clock.java
│ ├── ConnectionException.java
│ ├── ExceptionCatchingRunnable.java
│ ├── MetricsOptions.java
│ ├── UnsupportedProtocolVersionException.java
│ ├── ClusterNameMismatchException.java
│ ├── utils
│ └── MoreFutures.java
│ ├── AbstractTimestampGenerator.java
│ ├── HostDistance.java
│ ├── AtomicMonotonicTimestampGenerator.java
│ ├── PreparedId.java
│ ├── MD5Digest.java
│ ├── ThreadLocalMonotonicTimestampGenerator.java
│ ├── AuthProvider.java
│ ├── WriteType.java
│ └── ExceptionCode.java
├── .travis.yml
├── README.md
├── my-docs
└── 需要理清的基本概念.java
├── src
├── main
│ └── config
│ │ └── ide
│ │ ├── intellij-code-style.jar
│ │ └── eclipse.importorder
└── license
│ └── header.txt
├── .gitignore
├── faq
└── README.md
├── features
├── object_mapper
│ └── README.md
├── README.md
└── shaded_jar
│ └── README.md
├── driver-examples
├── stress
│ ├── README.md
│ ├── src
│ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── datastax
│ │ │ └── driver
│ │ │ └── stress
│ │ │ └── Consumer.java
│ └── bin
│ │ ├── stress
│ │ └── build
└── osgi
│ ├── src
│ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── datastax
│ │ │ └── driver
│ │ │ └── osgi
│ │ │ ├── api
│ │ │ ├── MailboxException.java
│ │ │ ├── MailboxService.java
│ │ │ └── MailboxMessage.java
│ │ │ └── impl
│ │ │ └── Activator.java
│ └── test
│ │ ├── resources
│ │ └── log4j.properties
│ │ └── java
│ │ └── com
│ │ └── datastax
│ │ └── driver
│ │ └── osgi
│ │ ├── VersionProvider.java
│ │ └── CCMBridgeListener.java
│ └── README.md
├── driver-mapping
└── src
│ ├── test
│ ├── java
│ │ └── com
│ │ │ └── datastax
│ │ │ └── driver
│ │ │ └── core
│ │ │ └── CoreHooks.java
│ └── resources
│ │ └── log4j.properties
│ └── main
│ └── java
│ └── com
│ └── datastax
│ └── driver
│ └── mapping
│ ├── annotations
│ ├── FrozenKey.java
│ ├── FrozenValue.java
│ ├── Accessor.java
│ ├── Param.java
│ ├── Transient.java
│ ├── ClusteringColumn.java
│ ├── PartitionKey.java
│ ├── Enumerated.java
│ ├── Query.java
│ ├── UDT.java
│ ├── Computed.java
│ ├── QueryParameters.java
│ ├── Column.java
│ ├── Field.java
│ └── Frozen.java
│ ├── EnumType.java
│ ├── ReflectionUtils.java
│ ├── AccessorReflectionMapper.java
│ └── AccessorMapper.java
├── my-test
└── src
│ └── main
│ └── java
│ └── my
│ └── test
│ ├── cql3
│ ├── ddl
│ │ ├── AggregateTest.java
│ │ ├── MaterializedViewTest.java
│ │ ├── RoleOrUserTest.java
│ │ ├── FunctionTest.java
│ │ └── TriggerTest.java
│ ├── PermissionTest.java
│ ├── ConstantsTest.java
│ ├── Test.java
│ └── MetaDataTest.java
│ ├── transport
│ └── MessageTest.java
│ └── auth
│ └── AuthenticationTest.java
├── clirr-ignores.xml
├── docs.yaml
└── testing
└── README.md
/driver-core/CHANGELOG.rst:
--------------------------------------------------------------------------------
1 | The changelog has moved `here <../changelog/>`_.
2 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk:
3 | - openjdk6
4 | - oraclejdk7
5 | - oraclejdk8
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codefollower/Cassandra-Java-Driver-Research/HEAD/README.md
--------------------------------------------------------------------------------
/driver-core/Upgrade_guide_to_2.0.rst:
--------------------------------------------------------------------------------
1 | The upgrade guide has moved `here <../upgrade_guide/>`_.
2 |
--------------------------------------------------------------------------------
/driver-core/Upgrade_guide_to_2.1.rst:
--------------------------------------------------------------------------------
1 | The upgrade guide has moved `here <../upgrade_guide/>`_.
2 |
--------------------------------------------------------------------------------
/driver-core/src/test/resources/META-INF/services/org.testng.ITestNGListener:
--------------------------------------------------------------------------------
1 | com.datastax.driver.core.TestListener
2 |
--------------------------------------------------------------------------------
/my-docs/需要理清的基本概念.java:
--------------------------------------------------------------------------------
1 | com.datastax.driver.core.Cluster
2 | 相当于java.sql.DriverManager
3 |
4 | com.datastax.driver.core.Session
5 | 相当于java.sql.Connection
6 |
--------------------------------------------------------------------------------
/src/main/config/ide/intellij-code-style.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codefollower/Cassandra-Java-Driver-Research/HEAD/src/main/config/ide/intellij-code-style.jar
--------------------------------------------------------------------------------
/driver-core/src/test/resources/client.keystore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codefollower/Cassandra-Java-Driver-Research/HEAD/driver-core/src/test/resources/client.keystore
--------------------------------------------------------------------------------
/driver-core/src/test/resources/server.keystore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codefollower/Cassandra-Java-Driver-Research/HEAD/driver-core/src/test/resources/server.keystore
--------------------------------------------------------------------------------
/driver-core/src/test/resources/client.truststore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codefollower/Cassandra-Java-Driver-Research/HEAD/driver-core/src/test/resources/client.truststore
--------------------------------------------------------------------------------
/driver-core/src/test/resources/server.truststore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codefollower/Cassandra-Java-Driver-Research/HEAD/driver-core/src/test/resources/server.truststore
--------------------------------------------------------------------------------
/src/main/config/ide/eclipse.importorder:
--------------------------------------------------------------------------------
1 | #Organize Import Order
2 | #Sun Oct 19 21:16:33 CEST 2014
3 | 5=\#com.datastax.driver.core
4 | 4=com.datastax.driver.core
5 | 3=\#
6 | 2=
7 | 1=\#java
8 | 0=java
9 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | cobertura-history/
3 | testing/
4 | .settings
5 | .classpath
6 | .project
7 | doc
8 | docs
9 | notes
10 | .DS_Store
11 |
12 | /.idea
13 | *.iml
14 |
15 | /driver-core/dependency-reduced-pom.xml
16 |
--------------------------------------------------------------------------------
/faq/README.md:
--------------------------------------------------------------------------------
1 | ## Frequently Asked Questions
2 |
3 | ### How do I implement paging?
4 |
5 | When using [native protocol](../features/native_protocol/) version 2 or
6 | higher, the driver automatically pages large result sets under the hood.
7 | You can also save the paging state to resume iteration later. See [this
8 | page](../features/paging/) for more information.
9 |
10 | Native protocol v1 does not support paging, but you can emulate it in
11 | CQL with `LIMIT` and the `token()` function. See
12 | [this conversation](https://groups.google.com/a/lists.datastax.com/d/msg/java-driver-user/U2KzAHruWO4/6vDmUVDDkOwJ) on the mailing list.
13 |
--------------------------------------------------------------------------------
/features/object_mapper/README.md:
--------------------------------------------------------------------------------
1 | # Object Mapper
2 |
3 | Version 2.1 of the driver introduces a simple object mapper, which
4 | avoids most of the boilerplate when converting your domain classes to
5 | and from query results. It handles basic CRUD operations in Cassandra tables
6 | containing UDTs, collections and all native CQL types.
7 |
8 | The mapper is published as a separate Maven artifact:
9 |
10 | ```xml
11 |
12 | com.datastax.cassandra
13 | cassandra-driver-mapping
14 | 2.1.7
15 |
16 | ```
17 |
18 | This documentation is organized in subsections describing mapper features.
19 |
--------------------------------------------------------------------------------
/src/license/header.txt:
--------------------------------------------------------------------------------
1 | Copyright (C) ${project.inceptionYear}-${currentYear} DataStax Inc.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 |
--------------------------------------------------------------------------------
/driver-core/src/main/resources/com/datastax/driver/core/Driver.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2012-2015 DataStax Inc.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | driver.version=${project.version}
--------------------------------------------------------------------------------
/features/README.md:
--------------------------------------------------------------------------------
1 | ## Features
2 |
3 | This part of the documentation is organized into sub-sections covering
4 | specific topics.
5 |
6 | If you're reading this from the [generated HTML documentation on
7 | github.io](http://datastax.github.io/java-driver/), use the "Read More"
8 | menu on the right hand side. If you're [browsing the source files on
9 | github.com](https://github.com/datastax/java-driver/tree/2.1/features),
10 | simply navigate to each sub-directory.
11 |
12 | This is a work in progress: new sections will be added to cover existing
13 | features or document new ones.
14 |
15 | You can also find more help in the legacy
16 | [user documentation](http://docs.datastax.com/en/developer/java-driver/2.1/java-driver/whatsNew2.html)
17 | on the DataStax website.
18 |
--------------------------------------------------------------------------------
/driver-examples/stress/README.md:
--------------------------------------------------------------------------------
1 | # Stress application
2 |
3 | A simple example application that uses the java driver to stress test
4 | Cassandra. This also somewhat stress test the java driver as a result.
5 |
6 | Please note that this simple example is far from being a complete stress
7 | application. In particular it currently supports a very limited number of
8 | stress scenario.
9 |
10 | ## Usage
11 |
12 | You will need to build the stress application fist:
13 |
14 | ./bin/build
15 |
16 | After which you can run it using for instance:
17 |
18 | ./bin/stress insert_prepared
19 |
20 | Of course, you will need to have at least one Cassandra node running (on
21 | 127.0.0.1 by default) for this to work. Please refer to:
22 |
23 | ./bin/stress -h
24 |
25 | for more details on the options available.
26 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/SchemaElement.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | enum SchemaElement {
19 | KEYSPACE, TABLE, TYPE
20 | }
21 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/exceptions/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /**
17 | * Exceptions thrown by the DataStax Java driver for Cassandra.
18 | */
19 | package com.datastax.driver.core.exceptions;
20 |
--------------------------------------------------------------------------------
/driver-examples/stress/src/main/java/com/datastax/driver/stress/Consumer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.stress;
17 |
18 | public interface Consumer {
19 |
20 | public void start();
21 | public void join();
22 | }
23 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/policies/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /**
17 | * Policies that allow to control some of the behavior of the DataStax Java driver for Cassandra.
18 | */
19 | package com.datastax.driver.core.policies;
20 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/querybuilder/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /**
17 | * A CQL3 query builder.
18 | *
19 | * The main entry for this package is the {@code QueryBuilder} class.
20 | */
21 | package com.datastax.driver.core.querybuilder;
22 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/schemabuilder/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /**
17 | * A CQL3 schema builder.
18 | *
19 | * The main entry for this package is the {@code SchemaBuilder} class.
20 | */
21 | package com.datastax.driver.core.schemabuilder;
22 |
--------------------------------------------------------------------------------
/driver-examples/stress/bin/stress:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | SCRIPT_DIR=$( cd "$( dirname "$0" )" && pwd )
4 | CURRENT_DIR=$( pwd )
5 |
6 | # Use $JAVA_HOME if set
7 | if [ -n "$JAVA_HOME" ]; then
8 | JAVA="$JAVA_HOME/bin/java"
9 | else
10 | JAVA=java
11 | fi
12 |
13 | if [ "x$STRESS_JAR" = "x" ]; then
14 |
15 | STRESS_JAR="$SCRIPT_DIR/../target/cassandra-driver-examples-stress-*-jar-with-dependencies.jar"
16 |
17 | if [ ! -f $STRESS_JAR ]; then
18 | # Trash the version file in case there was some crap in it
19 | RELATIVE_SCRIPT_DIR=`dirname $0`
20 | echo "Stress application does not seem to be build, try $RELATIVE_SCRIPT_DIR/build first" 1>&2
21 | exit 1
22 | fi
23 | else
24 | if [ ! -f $STRESS_JAR ]; then
25 | echo "Cannot find file $STRESS_JAR" 1>&2
26 | exit 1
27 | fi
28 | fi
29 |
30 | "$JAVA" -Dlog4j.configuration="$SCRIPT_DIR/../conf/log4j.properties" -jar $STRESS_JAR $@
31 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /**
17 | * The main package for the DataStax Java driver for Cassandra.
18 | *
19 | * The main entry for this package is the {@link com.datastax.driver.core.Cluster} class.
20 | */
21 | package com.datastax.driver.core;
22 |
--------------------------------------------------------------------------------
/driver-examples/stress/bin/build:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | SCRIPT_DIR=$( cd "$( dirname "$0" )" && pwd )
4 | CURRENT_DIR=$( pwd )
5 |
6 | LOG_FILE="$CURRENT_DIR/stress_build.log"
7 | [ -f $LOG_FILE ] && rm $LOG_FILE
8 |
9 | echo "Building java driver ..."
10 | echo "-- Driver build --\n" > $LOG_FILE
11 |
12 | cd $SCRIPT_DIR/../../..
13 | mvn clean install -Dmaven.test.skip=true >> $LOG_FILE 2>&1
14 | EXIT_CODE=$?
15 | if [ $EXIT_CODE -ne 0 ];
16 | then
17 | echo "Error building driver. See $LOG_FILE for details." 1>&2
18 | cd $CURRENT_DIR
19 | exit $EXIT_CODE
20 | fi
21 |
22 | echo "Building stress application ..."
23 | echo "\n-- Stress build --\n" >> $LOG_FILE
24 |
25 | cd $SCRIPT_DIR/..
26 | mvn package assembly:single >> $LOG_FILE 2>&1
27 | EXIT_CODE=$?
28 | if [ $EXIT_CODE -ne 0 ];
29 | then
30 | echo "Error building stress application. See $LOG_FILE for details." 1>&2
31 | cd $CURRENT_DIR
32 | exit $EXIT_CODE
33 | fi
34 |
35 | cd $CURRENT_DIR
36 | rm $LOG_FILE
37 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/GettableData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | /**
19 | * Collection of (typed) CQL values that can be retrieved either by index (starting a 0) or by name.
20 | */
21 | public interface GettableData extends GettableByIndexData, GettableByNameData {
22 | }
23 |
--------------------------------------------------------------------------------
/driver-examples/osgi/src/main/java/com/datastax/driver/osgi/api/MailboxException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.osgi.api;
17 |
18 | public class MailboxException extends Exception {
19 |
20 | public MailboxException(Throwable cause) {
21 | super("Failure interacting with Mailbox", cause);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/BusyConnectionException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | class BusyConnectionException extends Exception
19 | {
20 | private static final long serialVersionUID = 0;
21 |
22 | public BusyConnectionException() {
23 | super();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/schemabuilder/StatementStart.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.schemabuilder;
17 |
18 | /**
19 | * The start of a statement, that another class will append to, to build the final statement.
20 | */
21 | interface StatementStart {
22 | String buildInternal();
23 | }
24 |
--------------------------------------------------------------------------------
/driver-examples/osgi/README.md:
--------------------------------------------------------------------------------
1 | # OSGi Example
2 |
3 | A simple example application that demonstrates using the Java Driver in
4 | an OSGi service.
5 |
6 | MailboxService is an activated service that uses Cassandra to
7 | persist a Mailbox by email address.
8 |
9 | ## Usage
10 |
11 | To build the bundle and run tests execute the following maven task::
12 |
13 | mvn integration-test -P short
14 |
15 | The short profile needs to be activated since the tests run under
16 | this group.
17 |
18 | After which the bundle jar will be present in the target/ directory.
19 |
20 | The project includes an integration test that verifies the service can
21 | be activated and used in an OSGi container. It also verifies that
22 | driver-core can be used in an OSGi container in the following
23 | configurations:
24 |
25 | 1. Default (default classifier with all dependencies)
26 | 2. Netty-Shaded (shaded classifier with all depedencies w/o Netty)
27 | 3. Guava 15 (default classifier with Guava 15.0)
28 | 4. Guava 16
29 | 5. Guava 17
30 | 6. Guava 18
31 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/SettableData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 | import java.util.*;
18 |
19 | /**
20 | * Collection of (typed) CQL values that can set either by index (starting a 0) or by name.
21 | */
22 | public interface SettableData> extends SettableByIndexData, SettableByNameData {
23 | }
24 |
--------------------------------------------------------------------------------
/driver-mapping/src/test/java/com/datastax/driver/core/CoreHooks.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import java.util.Collections;
19 |
20 | /**
21 | * Provides access to package-private members of the core module.
22 | */
23 | public class CoreHooks {
24 | public static UserType MOCK_USER_TYPE = new UserType("mockKs", "mockUDT", Collections.emptyList());
25 | }
26 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/ProtocolV1Authenticator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import java.util.Map;
19 |
20 | // Not an interface because we don't want to expose it. We only support password authentication
21 | // for the protocol V1 similarly to what the driver 1.x branch do.
22 | abstract class ProtocolV1Authenticator {
23 | abstract Map getCredentials();
24 | }
25 |
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/M3PTokenVnodeIntegrationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | public class M3PTokenVnodeIntegrationTest extends TokenIntegrationTest {
19 | public M3PTokenVnodeIntegrationTest() {
20 | super("", DataType.bigint(), true);
21 | }
22 |
23 | @Override protected Token.Factory tokenFactory() {
24 | return Token.M3PToken.FACTORY;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/RPTokenVnodeIntegrationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | public class RPTokenVnodeIntegrationTest extends TokenIntegrationTest {
19 | public RPTokenVnodeIntegrationTest() {
20 | super("-p RandomPartitioner", DataType.varint(), true);
21 | }
22 |
23 | @Override protected Token.Factory tokenFactory() {
24 | return Token.RPToken.FACTORY;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/OPPTokenVnodeIntegrationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | public class OPPTokenVnodeIntegrationTest extends TokenIntegrationTest {
19 | public OPPTokenVnodeIntegrationTest() {
20 | super("-p ByteOrderedPartitioner", DataType.blob(), true);
21 | }
22 |
23 | @Override protected Token.Factory tokenFactory() {
24 | return Token.OPPToken.FACTORY;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/policies/ChainableLoadBalancingPolicy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.policies;
17 |
18 | /**
19 | * A load balancing policy that wraps another policy.
20 | */
21 | public interface ChainableLoadBalancingPolicy extends LoadBalancingPolicy {
22 | /**
23 | * Returns the child policy.
24 | *
25 | * @return the child policy.
26 | */
27 | LoadBalancingPolicy getChildPolicy();
28 | }
29 |
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/M3PTokenIntegrationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import com.datastax.driver.core.Token.M3PToken;
19 |
20 | public class M3PTokenIntegrationTest extends TokenIntegrationTest {
21 | public M3PTokenIntegrationTest() {
22 | super("", DataType.bigint());
23 | }
24 |
25 | @Override protected Token.Factory tokenFactory() {
26 | return M3PToken.FACTORY;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/exceptions/PagingStateException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.exceptions;
17 |
18 | public class PagingStateException extends DriverException {
19 |
20 | private static final long serialVersionUID = 0;
21 |
22 | public PagingStateException(String msg) {
23 | super(msg);
24 | }
25 |
26 | public PagingStateException(String msg, Throwable cause) {
27 | super(msg, cause);
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/RPTokenIntegrationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import com.datastax.driver.core.Token.RPToken;
19 |
20 | public class RPTokenIntegrationTest extends TokenIntegrationTest {
21 | public RPTokenIntegrationTest() {
22 | super("-p RandomPartitioner", DataType.varint());
23 | }
24 |
25 | @Override protected Token.Factory tokenFactory() {
26 | return RPToken.FACTORY;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/OPPTokenIntegrationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import com.datastax.driver.core.Token.OPPToken;
19 |
20 | public class OPPTokenIntegrationTest extends TokenIntegrationTest {
21 | public OPPTokenIntegrationTest() {
22 | super("-p ByteOrderedPartitioner", DataType.blob());
23 | }
24 |
25 | @Override protected Token.Factory tokenFactory() {
26 | return OPPToken.FACTORY;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/FrozenKey.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.mapping.annotations;
17 |
18 | import java.lang.annotation.*;
19 |
20 | /**
21 | * Shorthand to specify that the key type of a MAP field is frozen.
22 | *
23 | * This is equivalent to {@code @Frozen("map, bar>")}.
24 | *
25 | * @see Frozen
26 | */
27 | @Target(ElementType.FIELD)
28 | @Retention(RetentionPolicy.RUNTIME)
29 | public @interface FrozenKey {
30 | }
31 |
--------------------------------------------------------------------------------
/driver-core/src/test/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2012-2015 DataStax Inc.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | # Set root logger level to DEBUG and its only appender to A1.
18 | log4j.rootLogger=INFO, A1
19 |
20 | # Scassandra's info log is a bit verbose
21 | log4j.logger.org.scassandra=WARN
22 |
23 | # A1 is set to be a ConsoleAppender.
24 | log4j.appender.A1=org.apache.log4j.ConsoleAppender
25 |
26 | # A1 uses PatternLayout.
27 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout
28 | log4j.appender.A1.layout.ConversionPattern=\ %-6r [%t] %-5p %c %x - %m%n
29 |
--------------------------------------------------------------------------------
/driver-mapping/src/test/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2012-2015 DataStax Inc.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | # Set root logger level to DEBUG and its only appender to A1.
18 | log4j.rootLogger=INFO, A1
19 |
20 | # Scassandra's info log is a bit verbose
21 | log4j.logger.org.scassandra=WARN
22 |
23 | # A1 is set to be a ConsoleAppender.
24 | log4j.appender.A1=org.apache.log4j.ConsoleAppender
25 |
26 | # A1 uses PatternLayout.
27 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout
28 | log4j.appender.A1.layout.ConversionPattern=\ %-6r [%t] %-5p %c %x - %m%n
29 |
--------------------------------------------------------------------------------
/driver-examples/osgi/src/test/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2012-2015 DataStax Inc.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | # Set root logger level to DEBUG and its only appender to A1.
18 | log4j.rootLogger=INFO, A1
19 |
20 | # Scassandra's info log is a bit verbose
21 | log4j.logger.org.scassandra=WARN
22 |
23 | # A1 is set to be a ConsoleAppender.
24 | log4j.appender.A1=org.apache.log4j.ConsoleAppender
25 |
26 | # A1 uses PatternLayout.
27 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout
28 | log4j.appender.A1.layout.ConversionPattern=\ %-6r [%t] %-5p %c %x - %m%n
29 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/OperationTimedOutException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import java.net.InetSocketAddress;
19 |
20 | /**
21 | * Thrown on a client-side timeout, i.e. when the client didn't hear back from the server within
22 | * {@link SocketOptions#getReadTimeoutMillis()}.
23 | */
24 | class OperationTimedOutException extends ConnectionException {
25 | public OperationTimedOutException(InetSocketAddress address) {
26 | super(address, "Operation timed out");
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/SimpleStatementTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import java.util.Collections;
19 | import java.util.List;
20 |
21 | import org.testng.annotations.Test;
22 |
23 | public class SimpleStatementTest {
24 | @Test(groups = "unit", expectedExceptions = { IllegalArgumentException.class })
25 | public void should_fail_if_too_many_variables() {
26 | List args = Collections.nCopies(1 << 16, (Object)1);
27 | new SimpleStatement("mock query", args.toArray());
28 | }
29 | }
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/schemabuilder/NativeColumnType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.schemabuilder;
17 |
18 | import com.datastax.driver.core.DataType;
19 |
20 | /**
21 | * Represents a native CQL type in a SchemaBuilder statement.
22 | */
23 | class NativeColumnType implements ColumnType {
24 | private final String asCQLString;
25 |
26 | NativeColumnType(DataType nativeType) {
27 | asCQLString = nativeType.toString();
28 | }
29 |
30 | @Override public String asCQLString() {
31 | return asCQLString;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/driver-mapping/src/main/java/com/datastax/driver/mapping/EnumType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.mapping;
17 |
18 | /**
19 | * The types of way to persist a JAVA Enum.
20 | */
21 | public enum EnumType {
22 | /**
23 | * Persists enumeration values using their ordinal in the Enum declaration.
24 | *
25 | * Note that this relies on the order of the values in source code, and will change
26 | * if values are added/removed before existing ones.
27 | */
28 | ORDINAL,
29 | /** Persists enumeration values using the string they have been declared with. */
30 | STRING
31 | }
32 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/exceptions/InvalidTypeException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.exceptions;
17 |
18 | public class InvalidTypeException extends DriverException {
19 |
20 | private static final long serialVersionUID = 0;
21 |
22 | public InvalidTypeException(String msg) {
23 | super(msg);
24 | }
25 |
26 | public InvalidTypeException(String msg, Throwable cause) {
27 | super(msg, cause);
28 | }
29 |
30 | @Override
31 | public DriverException copy() {
32 | return new InvalidTypeException(getMessage(), this);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/my-test/src/main/java/my/test/cql3/ddl/AggregateTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package my.test.cql3.ddl;
19 |
20 | import my.test.TestBase;
21 |
22 | public class AggregateTest extends TestBase {
23 | String indexName;
24 |
25 | public static void main(String[] args) throws Exception {
26 | new AggregateTest().start();
27 | }
28 |
29 | @Override
30 | public void startInternal() throws Exception {
31 |
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/my-test/src/main/java/my/test/cql3/ddl/MaterializedViewTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package my.test.cql3.ddl;
19 |
20 | import my.test.TestBase;
21 |
22 | public class MaterializedViewTest extends TestBase {
23 | String indexName;
24 |
25 | public static void main(String[] args) throws Exception {
26 | new MaterializedViewTest().start();
27 | }
28 |
29 | @Override
30 | public void startInternal() throws Exception {
31 |
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/exceptions/SyntaxError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.exceptions;
17 |
18 | /**
19 | * Indicates a syntax error in a query.
20 | */
21 | public class SyntaxError extends QueryValidationException {
22 |
23 | private static final long serialVersionUID = 0;
24 |
25 | public SyntaxError(String msg) {
26 | super(msg);
27 | }
28 |
29 | private SyntaxError(String msg, Throwable cause) {
30 | super(msg, cause);
31 | }
32 |
33 | @Override
34 | public DriverException copy() {
35 | return new SyntaxError(getMessage(), this);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/exceptions/QueryValidationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.exceptions;
17 |
18 | /**
19 | * An exception indicating that a query cannot be executed because it is
20 | * syntactically incorrect, invalid, unauthorized or any other reason.
21 | */
22 | @SuppressWarnings("serial")
23 | public abstract class QueryValidationException extends DriverException {
24 |
25 | protected QueryValidationException(String msg) {
26 | super(msg);
27 | }
28 |
29 | protected QueryValidationException(String msg, Throwable cause) {
30 | super(msg, cause);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/schemabuilder/ColumnType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.schemabuilder;
17 |
18 | import com.datastax.driver.core.DataType;
19 |
20 | /**
21 | * Wrapper around UDT and non-UDT types.
22 | *
23 | * The reason for this interface is that the core API doesn't let us build {@link com.datastax.driver.core.DataType}s representing UDTs, we have to obtain
24 | * them from the cluster metadata. Since we want to use SchemaBuilder without a Cluster instance, UDT types will be provided via
25 | * {@link UDTType} instances.
26 | */
27 | interface ColumnType {
28 | String asCQLString();
29 | }
30 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/policies/CloseableAddressTranslater.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.policies;
17 |
18 | import com.datastax.driver.core.Cluster;
19 |
20 | /**
21 | * Extends {@link AddressTranslater} for implementations that need to free some resources
22 | * at {@link Cluster} shutdown.
23 | *
24 | * Note: the only reason {@link #close()} was not added directly to {@code AddressTranslater}
25 | * is backward-compatibility.
26 | */
27 | public interface CloseableAddressTranslater extends AddressTranslater {
28 | /**
29 | * Called at {@link Cluster} shutdown.
30 | */
31 | void close();
32 | }
33 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/exceptions/TruncateException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.exceptions;
17 |
18 | /**
19 | * Error during a truncation operation.
20 | */
21 | public class TruncateException extends QueryExecutionException {
22 |
23 | private static final long serialVersionUID = 0;
24 |
25 | public TruncateException(String msg) {
26 | super(msg);
27 | }
28 |
29 | private TruncateException(String msg, Throwable cause) {
30 | super(msg, cause);
31 | }
32 |
33 | @Override
34 | public DriverException copy() {
35 | return new TruncateException(getMessage(), this);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/FrozenValue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.mapping.annotations;
17 |
18 | import java.lang.annotation.*;
19 |
20 | /**
21 | * Shorthand to specify that the value type of a collection field is frozen.
22 | *
23 | * This is equivalent to any of the following:
24 | *
25 | * {@code @Frozen("list>")}
26 | * {@code @Frozen("set>")}
27 | * {@code @Frozen("map>")}
28 | *
29 | *
30 | * @see Frozen
31 | */
32 | @Target(ElementType.FIELD)
33 | @Retention(RetentionPolicy.RUNTIME)
34 | public @interface FrozenValue {
35 | }
36 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/ServerSideTimestampGenerator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | /**
19 | * A timestamp generator that always returns {@link Long#MIN_VALUE}, in order to let Cassandra
20 | * assign server-side timestamps.
21 | */
22 | public class ServerSideTimestampGenerator implements TimestampGenerator {
23 | /**
24 | * The unique instance of this generator.
25 | */
26 | public static final TimestampGenerator INSTANCE = new ServerSideTimestampGenerator();
27 |
28 | @Override
29 | public long next() {
30 | return Long.MIN_VALUE;
31 | }
32 |
33 | private ServerSideTimestampGenerator() {
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/exceptions/UnsupportedFeatureException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.exceptions;
17 |
18 | import com.datastax.driver.core.ProtocolVersion;
19 |
20 | /**
21 | * Exception thrown when a feature is not supported by the native protocol
22 | * currently in use.
23 | */
24 | public class UnsupportedFeatureException extends DriverException {
25 |
26 | private static final long serialVersionUID = 0;
27 |
28 | public UnsupportedFeatureException(ProtocolVersion currentVersion, String msg) {
29 | super("Unsupported feature with the native protocol " + currentVersion + " (which is currently in use): " + msg);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/exceptions/QueryExecutionException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.exceptions;
17 |
18 | /**
19 | * Exception related to the execution of a query.
20 | *
21 | * This correspond to the exception that Cassandra throw when a (valid) query
22 | * cannot be executed (TimeoutException, UnavailableException, ...).
23 | */
24 | @SuppressWarnings("serial")
25 | public abstract class QueryExecutionException extends DriverException {
26 |
27 | protected QueryExecutionException(String msg) {
28 | super(msg);
29 | }
30 |
31 | protected QueryExecutionException(String msg, Throwable cause) {
32 | super(msg, cause);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/TransportException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import java.net.InetSocketAddress;
19 |
20 | /**
21 | * A connection exception that has to do with the transport itself, i.e. that
22 | * suggests the node is down.
23 | */
24 | class TransportException extends ConnectionException
25 | {
26 | private static final long serialVersionUID = 0;
27 |
28 | public TransportException(InetSocketAddress address, String msg, Throwable cause)
29 | {
30 | super(address, msg, cause);
31 | }
32 |
33 | public TransportException(InetSocketAddress address, String msg)
34 | {
35 | super(address, msg);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/exceptions/InvalidQueryException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.exceptions;
17 |
18 | /**
19 | * Indicates a syntactically correct but invalid query.
20 | */
21 | public class InvalidQueryException extends QueryValidationException {
22 |
23 | private static final long serialVersionUID = 0;
24 |
25 | public InvalidQueryException(String msg) {
26 | super(msg);
27 | }
28 |
29 | private InvalidQueryException(String msg, Throwable cause) {
30 | super(msg, cause);
31 | }
32 |
33 | @Override
34 | public DriverException copy() {
35 | return new InvalidQueryException(getMessage(), this);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/TimestampGenerator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | /**
19 | * Generates client-side, microsecond-precision query timestamps.
20 | *
21 | * Given that Cassandra uses those timestamps to resolve conflicts, implementations should generate
22 | * incrementing timestamps for successive implementations.
23 | */
24 | public interface TimestampGenerator {
25 | /**
26 | * Returns the next timestamp.
27 | *
28 | * @return the next timestamp (in microseconds). If it equals {@link Long#MIN_VALUE}, it won't be
29 | * sent by the driver, letting Cassandra generate a server-side timestamp.
30 | */
31 | long next();
32 | }
33 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/exceptions/InvalidConfigurationInQueryException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.exceptions;
17 |
18 | /**
19 | * A specific invalid query exception that indicates that the query is invalid
20 | * because of some configuration problem.
21 | *
22 | * This is generally throw by query that manipulate the schema (CREATE and
23 | * ALTER) when the required configuration options are invalid.
24 | */
25 | public class InvalidConfigurationInQueryException extends InvalidQueryException {
26 |
27 | private static final long serialVersionUID = 0;
28 |
29 | public InvalidConfigurationInQueryException(String msg) {
30 | super(msg);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/querybuilder/Ordering.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.querybuilder;
17 |
18 | import java.util.List;
19 |
20 | public class Ordering extends Utils.Appendeable {
21 |
22 | private final String name;
23 | private final boolean isDesc;
24 |
25 | Ordering(String name, boolean isDesc) {
26 | this.name = name;
27 | this.isDesc = isDesc;
28 | }
29 |
30 | @Override
31 | void appendTo(StringBuilder sb, List variables) {
32 | Utils.appendName(name, sb);
33 | sb.append(isDesc ? " DESC" : " ASC");
34 | }
35 |
36 | @Override
37 | boolean containsBindMarker() {
38 | return false;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/Accessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.mapping.annotations;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | /**
24 | * An accessor is an interface that defines a set of method to read and write
25 | * from Cassandra.
26 | *
27 | * Each method declaration of an interface with the annotation {@link Accessor} must
28 | * have a {@link Query} annotation that defines the query the method executes.
29 | */
30 | @Target(ElementType.TYPE)
31 | @Retention(RetentionPolicy.RUNTIME)
32 | public @interface Accessor {}
33 |
--------------------------------------------------------------------------------
/driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/Param.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.mapping.annotations;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | /**
24 | * Provides a name for a parameter of a method in an {@link Accessor} interface that
25 | * can be used to reference to that parameter in method {@link Query}.
26 | */
27 | @Target(ElementType.PARAMETER)
28 | @Retention(RetentionPolicy.RUNTIME)
29 | public @interface Param {
30 | /**
31 | * The name for the parameter
32 | *
33 | * @return the name of the parameter.
34 | */
35 | String value();
36 | }
37 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/exceptions/UnauthorizedException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.exceptions;
17 |
18 | /**
19 | * Indicates that a query cannot be performed due to the authorization
20 | * restrictions of the logged user.
21 | */
22 | public class UnauthorizedException extends QueryValidationException {
23 |
24 | private static final long serialVersionUID = 0;
25 |
26 | public UnauthorizedException(String msg) {
27 | super(msg);
28 | }
29 |
30 | private UnauthorizedException(String msg, Throwable cause) {
31 | super(msg, cause);
32 | }
33 |
34 | @Override
35 | public DriverException copy() {
36 | return new UnauthorizedException(getMessage(), this);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/MockClocks.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | class MockClocks {
19 | static class BackInTimeClock implements Clock {
20 | final long arbitraryTimeStamp = 1412610226270L;
21 | int calls;
22 |
23 | @Override
24 | public long currentTime() {
25 | return arbitraryTimeStamp - calls++;
26 | }
27 | }
28 |
29 | static class FixedTimeClock implements Clock {
30 | final long fixedTime;
31 |
32 | public FixedTimeClock(long fixedTime) {
33 | this.fixedTime = fixedTime;
34 | }
35 |
36 | @Override
37 | public long currentTime() {
38 | return fixedTime;
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/exceptions/TraceRetrievalException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.exceptions;
17 |
18 | /**
19 | * Exception thrown if a query trace cannot be retrieved.
20 | *
21 | * @see com.datastax.driver.core.QueryTrace
22 | */
23 | public class TraceRetrievalException extends DriverException {
24 |
25 | private static final long serialVersionUID = 0;
26 |
27 | public TraceRetrievalException(String message) {
28 | super(message);
29 | }
30 |
31 | public TraceRetrievalException(String message, Throwable cause) {
32 | super(message, cause);
33 | }
34 |
35 | @Override
36 | public DriverException copy() {
37 | return new TraceRetrievalException(getMessage(), this);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/Clock.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | /**
19 | * This interface allows us not to have a direct call to {@code System.currentTimeMillis()} for testing purposes
20 | */
21 | interface Clock {
22 | /**
23 | * Returns the current time in milliseconds
24 | *
25 | * @return the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
26 | * @see System#currentTimeMillis()
27 | */
28 | long currentTime();
29 | }
30 |
31 | /**
32 | * Default implementation of a clock that delegate its calls to the system clock.
33 | */
34 | class SystemClock implements Clock {
35 | @Override
36 | public long currentTime() {
37 | return System.currentTimeMillis();
38 | }
39 | }
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/policies/CloseableLoadBalancingPolicy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.policies;
17 |
18 | /**
19 | * A load balancing policy that wants to be notified at cluster shutdown.
20 | *
21 | * The only reason that this is separate from {@link LoadBalancingPolicy} is to avoid breaking binary compatibility at the
22 | * time this was introduced (2.0.7 / 2.1.3). It might be merged with the parent interface in a future major version.
23 | */
24 | public interface CloseableLoadBalancingPolicy extends LoadBalancingPolicy {
25 | /**
26 | * Gets invoked at cluster shutdown.
27 | *
28 | * This gives the policy the opportunity to perform some cleanup, for instance stop threads that it might have started.
29 | */
30 | void close();
31 | }
32 |
--------------------------------------------------------------------------------
/driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/Transient.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.mapping.annotations;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | /**
24 | * Whenever this annotation is added on a field, the field will not be mapped
25 | * to any column (neither during reads nor writes).
26 | *
27 | * Please note that it is thus illegal to have a field that has both the
28 | * {@code Transcient} annotation and one of the {@link Column}, {@link PartitionKey}
29 | * or {@link ClusteringColumn} annotation.
30 | */
31 | @Target(ElementType.FIELD)
32 | @Retention(RetentionPolicy.RUNTIME)
33 | public @interface Transient {
34 | }
35 |
--------------------------------------------------------------------------------
/my-test/src/main/java/my/test/cql3/ddl/RoleOrUserTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package my.test.cql3.ddl;
19 |
20 | import my.test.TestBase;
21 |
22 | public class RoleOrUserTest extends TestBase {
23 | public static void main(String[] args) throws Exception {
24 | new RoleOrUserTest().start();
25 | }
26 |
27 | @Override
28 | public void startInternal() throws Exception {
29 | execute("CREATE USER UserTest WITH PASSWORD 'mypassword' SUPERUSER");
30 | execute("ALTER USER UserTest WITH PASSWORD 'mypassword2' SUPERUSER");
31 | execute("LIST USERS");
32 | execute("DROP USER UserTest");
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/ConnectionException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import java.net.InetSocketAddress;
19 |
20 | class ConnectionException extends Exception {
21 |
22 | private static final long serialVersionUID = 0;
23 |
24 | public final InetSocketAddress address;
25 |
26 | public ConnectionException(InetSocketAddress address, String msg, Throwable cause)
27 | {
28 | super(msg, cause);
29 | this.address = address;
30 | }
31 |
32 | public ConnectionException(InetSocketAddress address, String msg)
33 | {
34 | super(msg);
35 | this.address = address;
36 | }
37 |
38 | @Override
39 | public String getMessage() {
40 | return String.format("[%s] %s", address, super.getMessage());
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/clirr-ignores.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 | 6006
15 | com/datastax/driver/core/ProtocolVersion
16 | NEWEST_SUPPORTED
17 | This was an oversight, this field was never intended to be non final
18 |
19 |
20 |
21 | 8001
22 | com/datastax/driver/core/schemabuilder/ColumnType$NativeColumnType
23 | This class was accidentally exposed, it was meant to be package-private
24 |
25 |
26 |
27 | 1001
28 | com/datastax/driver/core/HostConnectionPool$Phase
29 | False positive: HostConnectionPool is not exposed to clients
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/SimpleJSONParserTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import com.google.common.collect.ImmutableMap;
19 | import com.google.common.collect.ImmutableList;
20 |
21 | import org.testng.annotations.Test;
22 | import static org.testng.Assert.assertEquals;
23 |
24 | public class SimpleJSONParserTest {
25 |
26 | @Test(groups = "unit")
27 | public void SimpleParsingTest() throws Exception {
28 |
29 | assertEquals(ImmutableList.of("1", "2", "3"), SimpleJSONParser.parseStringList("[\"1\",\"2\",\"3\"]"));
30 | assertEquals(ImmutableList.of("foo ' bar \""), SimpleJSONParser.parseStringList("[\"foo ' bar \\\"\"]"));
31 |
32 | assertEquals(ImmutableMap.of("foo", "bar", "bar", "foo"), SimpleJSONParser.parseStringMap("{\"foo\":\"bar\",\"bar\":\"foo\"}"));
33 | }
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/policies/IdentityTranslater.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.policies;
17 |
18 | import java.net.InetSocketAddress;
19 |
20 | /**
21 | * The default {@link AddressTranslater} used by the driver that do no
22 | * translation.
23 | */
24 | public class IdentityTranslater implements AddressTranslater {
25 |
26 | /**
27 | * Translates a Cassandra {@code rpc_address} to another address if necessary.
28 | *
29 | * This method is the identity function, it always return the address passed
30 | * in argument, doing no translation.
31 | *
32 | * @param address the address of a node as returned by Cassandra.
33 | * @return {@code address} unmodified.
34 | */
35 | public InetSocketAddress translate(InetSocketAddress address) {
36 | return address;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/ExceptionCatchingRunnable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import org.slf4j.Logger;
19 | import org.slf4j.LoggerFactory;
20 |
21 | // Simple utility class to make sure we don't let exception slip away and kill
22 | // our executors.
23 | abstract class ExceptionCatchingRunnable implements Runnable {
24 |
25 | private static final Logger logger = LoggerFactory.getLogger(ExceptionCatchingRunnable.class);
26 |
27 | public abstract void runMayThrow() throws Exception;
28 |
29 | @Override
30 | public void run() {
31 | try {
32 | runMayThrow();
33 | } catch (InterruptedException e) {
34 | Thread.currentThread().interrupt();
35 | } catch (Exception e) {
36 | logger.error("Unexpected error while executing task", e);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/exceptions/DriverInternalError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.exceptions;
17 |
18 | /**
19 | * An unexpected error happened internally.
20 | *
21 | * This should never be raise and indicates a bug (either in the driver or in
22 | * Cassandra).
23 | */
24 | public class DriverInternalError extends DriverException {
25 |
26 | private static final long serialVersionUID = 0;
27 |
28 | public DriverInternalError(String message) {
29 | super(message);
30 | }
31 |
32 | public DriverInternalError(Throwable cause) {
33 | super(cause);
34 | }
35 |
36 | public DriverInternalError(String message, Throwable cause) {
37 | super(message, cause);
38 | }
39 |
40 | @Override
41 | public DriverInternalError copy() {
42 | return new DriverInternalError(getMessage(), this);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/ClusteringColumn.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.mapping.annotations;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | /**
24 | * Annotation for fields that map to a CQL clustering column.
25 | *
26 | * If the mapped table has multiple clustering columns, it is mandatory
27 | * to specify the ordinal parameter to avoid ordering ambiguity.
28 | */
29 | @Target(ElementType.FIELD)
30 | @Retention(RetentionPolicy.RUNTIME)
31 | public @interface ClusteringColumn {
32 | /**
33 | * Ordinal to add when several clustering columns are declared within a single
34 | * entity.
35 | *
36 | * @return the ordinal value.
37 | */
38 | int value() default 0;
39 | }
40 |
--------------------------------------------------------------------------------
/driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/PartitionKey.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.mapping.annotations;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | /**
24 | * Annotation for fields that map to a CQL partition key (or one of it's
25 | * component if the partition key is composite).
26 | *
27 | * If the partition key of the mapped table is composite, it is mandatory
28 | * to specify the ordinal parameter to avoid ordering ambiguity.
29 | */
30 | @Target(ElementType.FIELD)
31 | @Retention(RetentionPolicy.RUNTIME)
32 | public @interface PartitionKey {
33 | /**
34 | * Ordinal to add when the partition key has multiple components.
35 | *
36 | * @return the ordinal to use.
37 | */
38 | int value() default 0;
39 | }
40 |
--------------------------------------------------------------------------------
/docs.yaml:
--------------------------------------------------------------------------------
1 | # This is provided on the 2.0 branch for convenience. Use docs.yaml from the
2 | # 2.1 branch to generate the docs for all versions.
3 | title: Java Driver for Apache Cassandra
4 | summary: High performance Java client for Apache Cassandra
5 | homepage: http://datastax.github.io/java-driver/
6 | sections:
7 | - title: Features
8 | prefix: /features
9 | sources:
10 | - type: markdown
11 | files: 'features/**/*.md'
12 | - title: Changelog
13 | prefix: /changelog
14 | sources:
15 | - type: markdown
16 | files: 'changelog/**/*.md'
17 | - title: Upgrading
18 | prefix: /upgrade_guide
19 | sources:
20 | - type: markdown
21 | files: 'upgrade_guide/**/*.md'
22 | - title: FAQ
23 | prefix: /faq
24 | sources:
25 | - type: markdown
26 | files: 'faq/**/*.md'
27 | links:
28 | - title: Code
29 | href: https://github.com/datastax/java-driver/
30 | - title: Docs
31 | href: http://datastax.github.io/java-driver/
32 | - title: Issues
33 | href: https://datastax-oss.atlassian.net/browse/JAVA/
34 | - title: Mailing List
35 | href: https://groups.google.com/a/lists.datastax.com/forum/#!forum/java-driver-user
36 | - title: IRC Channel
37 | href: irc://irc.freenode.net/datastax-drivers
38 | - title: Releases
39 | href: https://github.com/datastax/java-driver/releases
40 |
41 | #versions:
42 | # - name: 2.1.6
43 | # ref: '2.1.6'
44 | # - name: 2.1.5
45 | # ref: '2.1.5'
46 | # - name: 2.0.10.1
47 | # ref: '12f8840'
48 | # - name: 2.0.10
49 | # ref: '3a602f1'
50 |
--------------------------------------------------------------------------------
/driver-mapping/src/main/java/com/datastax/driver/mapping/ReflectionUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.mapping;
17 |
18 | import java.lang.reflect.ParameterizedType;
19 | import java.lang.reflect.Type;
20 |
21 | /**
22 | * Utility methods related to reflection.
23 | */
24 | class ReflectionUtils {
25 |
26 | /**
27 | * Gets a type argument from a parameterized type.
28 | *
29 | * @param pt the parameterized type.
30 | * @param arg the index of the argument to retrieve.
31 | * @param name the name of the element (field or method argument).
32 | * @return the type argument.
33 | */
34 | static Class> getParam(ParameterizedType pt, int arg, String name) {
35 | Type ft = pt.getActualTypeArguments()[arg];
36 | if (!(ft instanceof Class))
37 | throw new IllegalArgumentException(String.format("Cannot map parameter of class %s for %s", pt, name));
38 | return (Class>)ft;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/MetricsOptions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | /**
19 | * {@link Metrics} options.
20 | */
21 | public class MetricsOptions {
22 |
23 | private final boolean jmxEnabled;
24 |
25 | /**
26 | * Creates a new {@code MetricsOptions} object with default values.
27 | */
28 | public MetricsOptions()
29 | {
30 | this(true);
31 | }
32 |
33 | /**
34 | * Creates a new {@code MetricsOptions} object.
35 | *
36 | * @param jmxEnabled whether to enable JMX reporting or not.
37 | */
38 | public MetricsOptions(boolean jmxEnabled)
39 | {
40 | this.jmxEnabled = jmxEnabled;
41 | }
42 |
43 | /**
44 | * Returns whether JMX reporting is enabled (the default).
45 | *
46 | * @return whether JMX reporting is enabled.
47 | */
48 | public boolean isJMXReportingEnabled()
49 | {
50 | return jmxEnabled;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/Enumerated.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.mapping.annotations;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | import com.datastax.driver.mapping.EnumType;
24 |
25 | /**
26 | * Defines that the annotated field (that must be a Java Enum) must be
27 | * persisted as an enumerated type.
28 | *
29 | * The optional {@link EnumType} value defined how the enumeration must be
30 | * persisted.
31 | */
32 | @Target(value = {ElementType.FIELD, ElementType.PARAMETER})
33 | @Retention(RetentionPolicy.RUNTIME)
34 | public @interface Enumerated {
35 | /**
36 | * How the enumeration must be persisted.
37 | *
38 | * @return the {@link EnumType} to use for mapping this enumeration.
39 | */
40 | EnumType value() default EnumType.STRING;
41 | }
42 |
--------------------------------------------------------------------------------
/my-test/src/main/java/my/test/cql3/ddl/FunctionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package my.test.cql3.ddl;
19 |
20 | import my.test.TestBase;
21 |
22 | public class FunctionTest extends TestBase {
23 |
24 | public static void main(String[] args) throws Exception {
25 | new FunctionTest().start();
26 | }
27 |
28 | @Override
29 | public void startInternal() throws Exception {
30 | // 不能在system中建函数
31 | // execute("use system");
32 | // 也不能像这样system.f_sin
33 | cql = "CREATE OR REPLACE FUNCTION f_sin ( input frozen> ) CALLED ON NULL INPUT RETURNS double "
34 | + "LANGUAGE java AS 'return Double.valueOf(Math.sin(input.doubleValue()));'";
35 | execute();
36 |
37 | cql = "DROP FUNCTION IF EXISTS f_sin";
38 | execute();
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/querybuilder/BindMarker.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.querybuilder;
17 |
18 | /**
19 | * A CQL3 bind marker.
20 | *
21 | * This can be either an anonymous bind marker or a named one (but note that
22 | * named ones are only supported starting in Cassandra 2.0.1).
23 | *
24 | * Please note that to create a new bind maker object you should use
25 | * {@link QueryBuilder#bindMarker()} (anonymous marker) or
26 | * {@link QueryBuilder#bindMarker(String)} (named marker).
27 | */
28 | public class BindMarker {
29 | static final BindMarker ANONYMOUS = new BindMarker(null);
30 |
31 | private final String name;
32 |
33 | BindMarker(String name) {
34 | this.name = name;
35 | }
36 |
37 | @Override
38 | public String toString() {
39 | if (name == null)
40 | return "?";
41 |
42 | return Utils.appendName(name, new StringBuilder(name.length() + 1).append(':')).toString();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/Assertions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import com.datastax.driver.core.ColumnMetadata.IndexMetadata;
19 |
20 | /**
21 | * Augment AssertJ with custom assertions for the Java driver.
22 | */
23 | public class Assertions extends org.assertj.core.api.Assertions{
24 | public static ClusterAssert assertThat(Cluster cluster) {
25 | return new ClusterAssert(cluster);
26 | }
27 |
28 | public static SessionAssert assertThat(Session session) {
29 | return new SessionAssert(session);
30 | }
31 |
32 | public static TokenRangeAssert assertThat(TokenRange range) {
33 | return new TokenRangeAssert(range);
34 | }
35 |
36 | public static DataTypeAssert assertThat(DataType type) {
37 | return new DataTypeAssert(type);
38 | }
39 |
40 | public static IndexMetadataAssert assertThat(IndexMetadata indexMetadata) {
41 | return new IndexMetadataAssert(indexMetadata);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/SessionAssert.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import org.assertj.core.api.AbstractAssert;
19 |
20 | import static org.assertj.core.api.Assertions.assertThat;
21 |
22 | public class SessionAssert extends AbstractAssert {
23 |
24 | protected SessionAssert(Session actual) {
25 | // We are cheating a bit by casting, but this is the only implementation anyway
26 | super((SessionManager)actual, SessionAssert.class);
27 | }
28 |
29 | public SessionAssert hasPoolFor(int hostNumber) {
30 | Host host = TestUtils.findHost(actual.cluster, hostNumber);
31 | assertThat(actual.pools.containsKey(host)).isTrue();
32 | return this;
33 | }
34 |
35 | public SessionAssert hasNoPoolFor(int hostNumber) {
36 | Host host = TestUtils.findHost(actual.cluster, hostNumber);
37 | assertThat(actual.pools.containsKey(host)).isFalse();
38 | return this;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/my-test/src/main/java/my/test/transport/MessageTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package my.test.transport;
19 |
20 | import my.test.TestBase;
21 |
22 | import com.datastax.driver.core.BoundStatement;
23 | import com.datastax.driver.core.PreparedStatement;
24 | import com.datastax.driver.core.SimpleStatement;
25 |
26 | public class MessageTest extends TestBase {
27 | public static void main(String[] args) throws Exception {
28 | new MessageTest().start();
29 | }
30 |
31 | @Override
32 | public void startInternal() throws Exception {
33 | SimpleStatement stmt = newSimpleStatement("USE " + KEYSPACE_NAME);
34 | stmt.enableTracing();
35 | PreparedStatement ps = session.prepare(stmt);
36 | BoundStatement boundStatement = new BoundStatement(ps);
37 | session.execute(boundStatement);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/driver-examples/osgi/src/main/java/com/datastax/driver/osgi/api/MailboxService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.osgi.api;
17 |
18 | import java.util.Collection;
19 | import java.util.UUID;
20 |
21 | public interface MailboxService {
22 |
23 | /**
24 | * Retrieve all messages for a given recipient.
25 | * @param recipient User whose mailbox is being read.
26 | * @return All messages in the mailbox.
27 | */
28 | public Collection getMessages(String recipient) throws MailboxException;
29 |
30 | /**
31 | * Stores the given message in the appropriate mailbox.
32 | * @param message Message to send.
33 | * @return UUID generated for the message.
34 | */
35 | public UUID sendMessage(MailboxMessage message) throws MailboxException;
36 |
37 | /**
38 | * Deletes all mail for the given recipient.
39 | * @param recipient User whose mailbox will be cleared.
40 | */
41 | public void clearMailbox(String recipient) throws MailboxException;
42 | }
43 |
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/TableMetadataTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import java.util.Collection;
19 |
20 | import com.google.common.collect.Lists;
21 | import org.testng.annotations.Test;
22 |
23 | import static org.assertj.core.api.Assertions.assertThat;
24 |
25 | public class TableMetadataTest extends CCMBridge.PerClassSingleNodeCluster {
26 | @Override
27 | protected Collection getTableDefinitions() {
28 | return Lists.newArrayList(
29 | "CREATE TABLE single_quote (\n"
30 | + " c1 int PRIMARY KEY\n"
31 | + ") WITH comment = 'comment with single quote '' should work'"
32 | );
33 | }
34 |
35 | @Test(groups = "short")
36 | public void should_escape_single_quote_table_comment() {
37 | TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("single_quote");
38 | assertThat(table.asCQLQuery()).contains("comment with single quote '' should work");
39 | }
40 | }
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/UnsupportedProtocolVersionException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import java.net.InetSocketAddress;
19 |
20 | /**
21 | * Indicates that we've attempted to connect to a 1.2 C* node with version 2 of
22 | * the protocol.
23 | */
24 | class UnsupportedProtocolVersionException extends Exception {
25 |
26 | private static final long serialVersionUID = 0;
27 |
28 | public final InetSocketAddress address;
29 | public final ProtocolVersion unsupportedVersion;
30 | public final ProtocolVersion serverVersion;
31 |
32 | public UnsupportedProtocolVersionException(InetSocketAddress address, ProtocolVersion unsupportedVersion, ProtocolVersion serverVersion)
33 | {
34 | super(String.format("[%s] Host %s does not support protocol version %s but %s", address, address, unsupportedVersion, serverVersion));
35 | this.address = address;
36 | this.unsupportedVersion = unsupportedVersion;
37 | this.serverVersion = serverVersion;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/querybuilder/Truncate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.querybuilder;
17 |
18 | import java.nio.ByteBuffer;
19 | import java.util.List;
20 |
21 | import com.datastax.driver.core.TableMetadata;
22 |
23 | /**
24 | * A built TRUNCATE statement.
25 | */
26 | public class Truncate extends BuiltStatement {
27 |
28 | private final String table;
29 |
30 | Truncate(String keyspace, String table) {
31 | super(keyspace);
32 | this.table = table;
33 | }
34 |
35 | Truncate(TableMetadata table) {
36 | super(table);
37 | this.table = escapeId(table.getName());
38 | }
39 |
40 | @Override
41 | protected StringBuilder buildQueryString(List variables) {
42 | StringBuilder builder = new StringBuilder();
43 |
44 | builder.append("TRUNCATE ");
45 | if (keyspace != null)
46 | Utils.appendName(keyspace, builder).append('.');
47 | Utils.appendName(table, builder);
48 |
49 | return builder;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/Query.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.mapping.annotations;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | /**
24 | * Defines the CQL query that an {@link Accessor} method must implement.
25 | */
26 | @Target(ElementType.METHOD)
27 | @Retention(RetentionPolicy.RUNTIME)
28 | public @interface Query {
29 | /**
30 | * The CQL query to use.
31 | *
32 | * In that query string, the parameter of the annotated method can be referenced using
33 | * name bind markers. For instance, the first parameter can be refered by {@code :arg0},
34 | * the second one by {@code :arg1}, ... Alternatively, if a parameter of the annonated
35 | * method has a {@link Param} annotation, the value of that latter annoation should be
36 | * used instead.
37 | *
38 | * @return the CQL query to use.
39 | */
40 | String value();
41 | }
42 |
--------------------------------------------------------------------------------
/features/shaded_jar/README.md:
--------------------------------------------------------------------------------
1 | ## Using the shaded JAR
2 |
3 | The default driver JAR depends on [Netty](http://netty.io/), which is
4 | used internally for networking.
5 |
6 | This explicit dependency can be a problem if your application already
7 | uses another Netty version. To avoid conflicts, we provide a "shaded"
8 | version of the JAR, which bundles the Netty classes under a different
9 | package name:
10 |
11 | ```xml
12 |
13 | com.datastax.cassandra
14 | cassandra-driver-core
15 | 2.1.7
16 | shaded
17 |
19 |
20 |
21 | io.netty
22 | *
23 |
24 |
25 |
26 | ```
27 |
28 | If you also use the mapper, you need to remove its dependency to the
29 | non-shaded JAR:
30 |
31 | ```xml
32 |
33 | com.datastax.cassandra
34 | cassandra-driver-core
35 | 2.1.7
36 | shaded
37 |
38 |
39 | io.netty
40 | *
41 |
42 |
43 |
44 |
45 | com.datastax.cassandra
46 | cassandra-driver-mapping
47 | 2.1.7
48 |
49 |
50 | com.datastax.cassandra
51 | cassandra-driver-core
52 |
53 |
54 |
55 | ```
56 |
--------------------------------------------------------------------------------
/my-test/src/main/java/my/test/cql3/PermissionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package my.test.cql3;
19 |
20 | import my.test.TestBase;
21 |
22 | public class PermissionTest extends TestBase {
23 | public static void main(String[] args) throws Exception {
24 | new PermissionTest().start();
25 | }
26 |
27 | @Override
28 | public void startInternal() throws Exception {
29 | execute("CREATE TABLE IF NOT EXISTS PermissionTest ( f1 int primary key, f2 int)");
30 | tryExecute("CREATE USER User_PermissionTest WITH PASSWORD 'mypassword' SUPERUSER");
31 | execute("GRANT SELECT PERMISSION ON TABLE " + KEYSPACE_NAME + ".PermissionTest TO User_PermissionTest");
32 | execute("LIST SELECT PERMISSION ON TABLE " + KEYSPACE_NAME + ".PermissionTest OF User_PermissionTest");
33 | execute("REVOKE SELECT PERMISSION ON TABLE " + KEYSPACE_NAME + ".PermissionTest FROM User_PermissionTest");
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/ClusterNameMismatchException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import java.net.InetSocketAddress;
19 |
20 | /**
21 | * Indicates that we've attempted to connect to a node which cluster name doesn't match that of the other nodes known to the driver.
22 | */
23 | class ClusterNameMismatchException extends Exception {
24 |
25 | private static final long serialVersionUID = 0;
26 |
27 | public final InetSocketAddress address;
28 | public final String expectedClusterName;
29 | public final String actualClusterName;
30 |
31 | public ClusterNameMismatchException(InetSocketAddress address, String actualClusterName, String expectedClusterName) {
32 | super(String.format("[%s] Host %s reports cluster name '%s' that doesn't match our cluster name '%s'. This host will be ignored.",
33 | address, address, actualClusterName, expectedClusterName));
34 | this.address = address;
35 | this.expectedClusterName = expectedClusterName;
36 | this.actualClusterName = actualClusterName;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/utils/CassandraVersion.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.utils;
17 |
18 | import java.lang.annotation.Retention;
19 | import java.lang.annotation.RetentionPolicy;
20 |
21 | /**
22 | *
Annotation for a Class or Method that defines a Cassandra Version requirement. If the cassandra verison in used
23 | * does not meet the version requirement, the test is skipped.
24 | *
25 | * @see {@link com.datastax.driver.core.TestListener#beforeInvocation(org.testng.IInvokedMethod, org.testng.ITestResult)} for usage.
26 | */
27 | @Retention(RetentionPolicy.RUNTIME)
28 | public @interface CassandraVersion {
29 | /**
30 | * @return The major version required to execute this test, i.e. "2.0"
31 | */
32 | public double major();
33 |
34 | /**
35 | * @return The minor version required to execute this test, i.e. "0"
36 | */
37 | public int minor() default 0;
38 |
39 | /**
40 | * @return The description returned if this version requirement is not met.
41 | */
42 | public String description() default "Does not meet minimum version requirement.";
43 | }
44 |
--------------------------------------------------------------------------------
/driver-examples/osgi/src/test/java/com/datastax/driver/osgi/VersionProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.osgi;
17 |
18 | import com.jcabi.manifests.Manifests;
19 |
20 | /**
21 | * Attempts to resolve the project version from the Bundle manifest. If not present, will throw RuntimeException
22 | * on initialization. If this happens, try building with 'mvn compile' to generate the Bundle manifest.
23 | *
24 | * In IntelliJ you can have compile run after make by right clicking on 'compile' in the 'Maven Projects' tool window.
25 | */
26 | public class VersionProvider {
27 |
28 | private static String PROJECT_VERSION;
29 | static {
30 | String bundleName = Manifests.read("Bundle-SymbolicName");
31 | if (bundleName.equals("com.datastax.driver.osgi")) {
32 | PROJECT_VERSION = Manifests.read("Bundle-Version").replaceAll("\\.SNAPSHOT", "-SNAPSHOT");
33 | } else {
34 | throw new RuntimeException("Couldn't resolve bundle manifest (try building with mvn compile)");
35 | }
36 | }
37 |
38 | public static String projectVersion() {
39 | return PROJECT_VERSION;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/my-test/src/main/java/my/test/auth/AuthenticationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package my.test.auth;
19 |
20 | import my.test.TestBase;
21 |
22 | public class AuthenticationTest extends TestBase {
23 | public static void main(String[] args) throws Exception {
24 | new AuthenticationTest().start();
25 | }
26 |
27 | @Override
28 | public void startInternal() throws Exception {
29 | testCreateRoleStatement();
30 | execute("LIST USERS");
31 |
32 | testAlterRoleStatement();
33 | testDropRoleStatement();
34 | }
35 |
36 | void testCreateRoleStatement() {
37 | execute("CREATE USER AuthenticationTest WITH PASSWORD 'mypassword' SUPERUSER");
38 | }
39 |
40 | void testAlterRoleStatement() {
41 | execute("ALTER USER AuthenticationTest WITH PASSWORD 'mypassword2' SUPERUSER");
42 | }
43 |
44 | void testDropRoleStatement() {
45 | execute("DROP USER AuthenticationTest");
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/utils/MoreFutures.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.utils;
17 |
18 | import com.google.common.util.concurrent.FutureCallback;
19 | import com.google.common.util.concurrent.Futures;
20 | import com.google.common.util.concurrent.ListenableFuture;
21 |
22 | /**
23 | * Helpers to work with Guava's {@link ListenableFuture}.
24 | */
25 | public class MoreFutures {
26 | /**
27 | * An immediate successful {@code ListenableFuture}.
28 | */
29 | public static final ListenableFuture VOID_SUCCESS = Futures.immediateFuture(null);
30 |
31 | /**
32 | * A {@link FutureCallback} that does nothing on failure.
33 | */
34 | public static abstract class SuccessCallback implements FutureCallback {
35 | @Override
36 | public void onFailure(Throwable t) { /* nothing */ }
37 | }
38 |
39 | /**
40 | * A {@link FutureCallback} that does nothing on success.
41 | */
42 | public static abstract class FailureCallback implements FutureCallback {
43 | @Override
44 | public void onSuccess(V result) { /* nothing */ }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/policies/DelegatingSpeculativeExecutionPolicy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.policies;
17 |
18 | import com.datastax.driver.core.Cluster;
19 | import com.datastax.driver.core.Statement;
20 |
21 | /**
22 | * Base class for tests that want to wrap a policy to add some instrumentation.
23 | *
24 | * NB: this is currently only used in tests, but could be provided as a convenience in the production code.
25 | */
26 | public abstract class DelegatingSpeculativeExecutionPolicy implements SpeculativeExecutionPolicy {
27 | private final SpeculativeExecutionPolicy delegate;
28 |
29 | protected DelegatingSpeculativeExecutionPolicy(SpeculativeExecutionPolicy delegate) {
30 | this.delegate = delegate;
31 | }
32 |
33 | @Override
34 | public void init(Cluster cluster) {
35 | delegate.init(cluster);
36 | }
37 |
38 | @Override
39 | public SpeculativeExecutionPlan newPlan(String loggedKeyspace, Statement statement) {
40 | return delegate.newPlan(loggedKeyspace, statement);
41 | }
42 |
43 | @Override
44 | public void close() {
45 | delegate.close();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/schemabuilder/CreateIndexTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.schemabuilder;
17 |
18 | import org.testng.annotations.Test;
19 |
20 | import static org.assertj.core.api.Assertions.assertThat;
21 |
22 | import static com.datastax.driver.core.schemabuilder.SchemaBuilder.createIndex;
23 |
24 | public class CreateIndexTest {
25 |
26 | @Test(groups = "unit")
27 | public void should_create_index() throws Exception {
28 | //Given //When
29 | SchemaStatement statement = createIndex("myIndex").ifNotExists().onTable("ks", "test").andColumn("col");
30 |
31 | //Then
32 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE INDEX IF NOT EXISTS myIndex ON ks.test(col)");
33 | }
34 |
35 | @Test(groups = "unit")
36 | public void should_create_index_on_keys_of_map_column() throws Exception {
37 | //Given //When
38 | SchemaStatement statement = createIndex("myIndex").ifNotExists().onTable("ks", "test").andKeysOfColumn("col");
39 |
40 | //Then
41 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE INDEX IF NOT EXISTS myIndex ON ks.test(KEYS(col))");
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/UDT.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.mapping.annotations;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | /**
24 | * Defines to which User Defined Type a class must be mapped to.
25 | */
26 | @Target(ElementType.TYPE)
27 | @Retention(RetentionPolicy.RUNTIME)
28 | public @interface UDT {
29 | /**
30 | * The name of the keyspace the type is part of.
31 | *
32 | * @return the name of the keyspace.
33 | */
34 | String keyspace() default "";
35 | /**
36 | * The name of the type.
37 | *
38 | * @return the name of the type.
39 | */
40 | String name();
41 |
42 | /**
43 | * Whether the keyspace name is a case sensitive one.
44 | *
45 | * @return whether the keyspace name is a case sensitive one.
46 | */
47 | boolean caseSensitiveKeyspace() default false;
48 | /**
49 | * Whether the type name is a case sensitive one.
50 | *
51 | * @return whether the type name is a case sensitive one.
52 | */
53 | boolean caseSensitiveType() default false;
54 | }
55 |
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/ClusterDelegateTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import java.util.Collection;
19 |
20 | import com.google.common.collect.Lists;
21 | import org.testng.annotations.Test;
22 |
23 | import static org.assertj.core.api.Assertions.assertThat;
24 |
25 | public class ClusterDelegateTest extends CCMBridge.PerClassSingleNodeCluster {
26 | @Override
27 | protected Collection getTableDefinitions() {
28 | return Lists.newArrayList();
29 | }
30 |
31 | @Test(groups = "short")
32 | public void should_allow_subclass_to_delegate_to_other_instance() {
33 | SimpleDelegatingCluster delegatingCluster = new SimpleDelegatingCluster(cluster);
34 |
35 | ResultSet rs = delegatingCluster.connect().execute("select * from system.local");
36 |
37 | assertThat(rs.all()).hasSize(1);
38 | }
39 |
40 | static class SimpleDelegatingCluster extends DelegatingCluster {
41 |
42 | private final Cluster delegate;
43 |
44 | public SimpleDelegatingCluster(Cluster delegate) {
45 | this.delegate = delegate;
46 | }
47 |
48 | @Override
49 | protected Cluster delegate() {
50 | return delegate;
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/AbstractTimestampGenerator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import org.slf4j.Logger;
19 | import org.slf4j.LoggerFactory;
20 |
21 | /**
22 | * Base implementation for generators based on {@link System#currentTimeMillis()} and a counter to generate
23 | * the sub-millisecond part.
24 | */
25 | abstract class AbstractMonotonicTimestampGenerator implements TimestampGenerator {
26 | private static final Logger logger = LoggerFactory.getLogger(AbstractMonotonicTimestampGenerator.class);
27 |
28 | volatile Clock clock = new SystemClock();
29 |
30 | protected long computeNext(long last) {
31 | long millis = last / 1000;
32 | long counter = last % 1000;
33 |
34 | long now = clock.currentTime();
35 |
36 | // System.currentTimeMillis can go backwards on an NTP resync, hence the ">" below
37 | if (millis >= now) {
38 | if (counter == 999)
39 | logger.warn("Sub-millisecond counter overflowed, some query timestamps will not be distinct");
40 | else
41 | counter += 1;
42 | } else {
43 | millis = now;
44 | counter = 0;
45 | }
46 |
47 | return millis * 1000 + counter;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/HostDistance.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | /**
19 | * The distance to a Cassandra node as assigned by a
20 | * {@link com.datastax.driver.core.policies.LoadBalancingPolicy} (through its {@code
21 | * distance} method).
22 | *
23 | * The distance assigned to an host influences how many connections the driver
24 | * maintains towards this host. If for a given host the assigned {@code HostDistance}
25 | * is {@code LOCAL} or {@code REMOTE}, some connections will be maintained by
26 | * the driver to this host. More active connections will be kept to
27 | * {@code LOCAL} host than to a {@code REMOTE} one (and thus well behaving
28 | * {@code LoadBalancingPolicy} should assign a {@code REMOTE} distance only to
29 | * hosts that are the less often queried).
30 | *
31 | * However, if a host is assigned the distance {@code IGNORED}, no connection
32 | * to that host will maintained active. In other words, {@code IGNORED} should
33 | * be assigned to hosts that should not be used by this driver (because they
34 | * are in a remote data center for instance).
35 | */
36 | public enum HostDistance {
37 | // Note: PoolingOptions rely on the order of the enum.
38 | LOCAL,
39 | REMOTE,
40 | IGNORED
41 | }
42 |
--------------------------------------------------------------------------------
/testing/README.md:
--------------------------------------------------------------------------------
1 | ## Testing Prerequisites
2 |
3 | ### Install CCM
4 |
5 | pip install ccm
6 |
7 | ### Setup CCM Loopbacks (required for OSX)
8 |
9 | # For basic ccm
10 | sudo ifconfig lo0 alias 127.0.0.2 up
11 | sudo ifconfig lo0 alias 127.0.0.3 up
12 |
13 | # Additional loopbacks for java-driver testing
14 | sudo ifconfig lo0 alias 127.0.1.1 up
15 | sudo ifconfig lo0 alias 127.0.1.2 up
16 | sudo ifconfig lo0 alias 127.0.1.3 up
17 | sudo ifconfig lo0 alias 127.0.1.4 up
18 | sudo ifconfig lo0 alias 127.0.1.5 up
19 | sudo ifconfig lo0 alias 127.0.1.6 up
20 |
21 |
22 |
23 | ## Building the Driver
24 |
25 | mvn clean package
26 |
27 |
28 |
29 | ## Testing the Driver
30 |
31 | ### Unit Tests
32 |
33 | Use the following command to run only the unit tests:
34 |
35 | mvn test
36 |
37 | _**Estimated Run Time**: x minutes_
38 |
39 | ### Integration Tests
40 |
41 | The following command runs the full set of unit and integration tests:
42 |
43 | mvn verify
44 |
45 | _**Estimated Run Time**: 4 minutes_
46 |
47 | ### Coverage Report
48 |
49 | The following command runs the full set of integration tests and produces a
50 | coverage report:
51 |
52 | mvn cobertura:cobertura
53 |
54 | Coverage report can be found at:
55 |
56 | driver-core/target/site/cobertura/index.html
57 |
58 | _**Estimated Run Time**: 4 minutes_
59 |
60 |
61 |
62 | ## Test Utility
63 |
64 | `testing/bin/coverage` exists to make testing a bit more straight-forward.
65 |
66 | The main commands are as follows:
67 |
68 | Displays the available parameters:
69 |
70 | testing/bin/coverage --help
71 |
72 | Runs all the integration tests, creates the Cobertura report, and uploads Cobertura
73 | site to a remote machine, if applicable:
74 |
75 | testing/bin/coverage
76 |
77 | Runs a single integration test along with the Cobertura report for that test:
78 |
79 | testing/bin/coverage --test TestClass[#optionalTestMethod]
80 |
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/StreamIdGeneratorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import org.testng.annotations.Test;
19 | import static org.testng.Assert.assertEquals;
20 | import static org.testng.Assert.fail;
21 |
22 | public class StreamIdGeneratorTest {
23 |
24 | @Test(groups = "unit")
25 | public void SimpleGenIdTest() throws Exception {
26 |
27 | StreamIdGenerator generator = StreamIdGenerator.newInstance(ProtocolVersion.V2);
28 |
29 | assertEquals(generator.next(), 0);
30 | assertEquals(generator.next(), 64);
31 | generator.release(0);
32 | assertEquals(generator.next(), 0);
33 | assertEquals(generator.next(), 65);
34 | assertEquals(generator.next(), 1);
35 | generator.release(64);
36 | assertEquals(generator.next(), 64);
37 | assertEquals(generator.next(), 2);
38 |
39 | for (int i = 5; i < 128; i++)
40 | generator.next();
41 |
42 | generator.release(100);
43 | assertEquals(generator.next(), 100);
44 |
45 | try {
46 | generator.next();
47 | fail("No more streamId should be available");
48 | } catch (BusyConnectionException e) {
49 | // Ok, expected
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/AtomicMonotonicTimestampGenerator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import java.util.concurrent.atomic.AtomicLong;
19 |
20 | /**
21 | * A timestamp generator based on {@code System.currentTimeMillis()}, with an incrementing atomic counter
22 | * to generate the sub-millisecond part.
23 | *
24 | * This implementation guarantees incrementing timestamps among all client threads, provided that no more than
25 | * 1000 are requested for a given clock tick (the exact granularity of of {@link System#currentTimeMillis()}
26 | * depends on the operating system).
27 | *
28 | * If that rate is exceeded, a warning is logged and the timestamps don't increment anymore until the next clock
29 | * tick. If you consistently exceed that rate, consider using {@link ThreadLocalMonotonicTimestampGenerator}.
30 | */
31 | public class AtomicMonotonicTimestampGenerator extends AbstractMonotonicTimestampGenerator {
32 | private AtomicLong lastRef = new AtomicLong(0);
33 |
34 | @Override
35 | public long next() {
36 | while (true) {
37 | long last = lastRef.get();
38 | long next = computeNext(last);
39 | if (lastRef.compareAndSet(last, next))
40 | return next;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/policies/NoSpeculativeExecutionPolicy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.policies;
17 |
18 | import com.datastax.driver.core.Cluster;
19 | import com.datastax.driver.core.Host;
20 | import com.datastax.driver.core.Statement;
21 |
22 | /**
23 | * A {@link SpeculativeExecutionPolicy} that never schedules speculative executions.
24 | */
25 | public class NoSpeculativeExecutionPolicy implements SpeculativeExecutionPolicy {
26 |
27 | /** The single instance (this class is stateless). */
28 | public static final NoSpeculativeExecutionPolicy INSTANCE = new NoSpeculativeExecutionPolicy();
29 |
30 | private static final SpeculativeExecutionPlan PLAN = new SpeculativeExecutionPlan() {
31 | @Override
32 | public long nextExecution(Host lastQueried) {
33 | return -1;
34 | }
35 | };
36 |
37 | @Override
38 | public SpeculativeExecutionPlan newPlan(String loggedKeyspace, Statement statement) {
39 | return PLAN;
40 | }
41 |
42 | private NoSpeculativeExecutionPolicy() {
43 | // do nothing
44 | }
45 |
46 | @Override
47 | public void init(Cluster cluster) {
48 | // do nothing
49 | }
50 |
51 | @Override
52 | public void close() {
53 | // do nothing
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/my-test/src/main/java/my/test/cql3/ddl/TriggerTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package my.test.cql3.ddl;
19 |
20 | import my.test.TestBase;
21 |
22 | public class TriggerTest extends TestBase {
23 |
24 | public static void main(String[] args) throws Exception {
25 | new TriggerTest().start();
26 | }
27 |
28 | String triggerName;
29 |
30 | @Override
31 | public void startInternal() throws Exception {
32 | tableName = "TriggerTest";
33 | createTest();
34 | dropTest();
35 | }
36 |
37 | void createTest() throws Exception {
38 | triggerName = tableName + "_mytrigger";
39 | // execute("DROP TABLE IF EXISTS " + tableName);
40 | execute("CREATE TABLE IF NOT EXISTS " + tableName + " (pk int PRIMARY KEY, c text)");
41 | execute("CREATE TRIGGER IF NOT EXISTS " + triggerName + " ON " + tableName
42 | + " USING 'my.test.trigger.MyTrigger'");
43 |
44 | execute("insert into " + tableName + "(pk, c) values(100, 'abc')");
45 | }
46 |
47 | void dropTest() throws Exception {
48 | execute("DROP TRIGGER " + triggerName + " ON " + tableName);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/PreparedId.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | /**
19 | * Identifies a PreparedStatement.
20 | */
21 | public class PreparedId
22 | {
23 | // This class is mostly here to group PreparedStatement data that are need for
24 | // execution but that we don't want to expose publicly (see JAVA-195)
25 | final MD5Digest id;
26 |
27 | //对应com.datastax.driver.core.Responses.Result.Prepared类
28 | //例如,对于这样的sql: SELECT title,album,artist FROM playlists WHERE id = ?
29 | //metadata = [id (uuid)] (对应绑定参数)
30 | //resultMetadata = [title (varchar)][album (varchar)][artist (varchar)] (对应查询结果)
31 |
32 | //对于insert这种sql,只有metadata对应绑定参数,而resultMetadata是[0 columns]
33 | final ColumnDefinitions metadata;
34 | final ColumnDefinitions resultSetMetadata;
35 |
36 | final int[] routingKeyIndexes;
37 | final ProtocolVersion protocolVersion;
38 |
39 | PreparedId(MD5Digest id, ColumnDefinitions metadata, ColumnDefinitions resultSetMetadata, int[] routingKeyIndexes, ProtocolVersion protocolVersion)
40 | {
41 | this.id = id;
42 | this.metadata = metadata;
43 | this.resultSetMetadata = resultSetMetadata;
44 | this.routingKeyIndexes = routingKeyIndexes;
45 | this.protocolVersion = protocolVersion;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/exceptions/DriverException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.exceptions;
17 |
18 | /**
19 | * Top level class for exceptions thrown by the driver.
20 | */
21 | public class DriverException extends RuntimeException {
22 |
23 | private static final long serialVersionUID = 0;
24 |
25 | DriverException() {
26 | super();
27 | }
28 |
29 | public DriverException(String message) {
30 | super(message);
31 | }
32 |
33 | public DriverException(Throwable cause) {
34 | super(cause);
35 | }
36 |
37 | public DriverException(String message, Throwable cause) {
38 | super(message, cause);
39 | }
40 |
41 | /**
42 | * Copy the exception.
43 | *
44 | * This return a new exception, equivalent to the original one, except that
45 | * because a new object is created in the current thread, the top-most
46 | * element in the stacktrace of the exception will refer to the current
47 | * thread (this mainly use for internal use by the driver). The cause of
48 | * the copied exception will be the original exception.
49 | *
50 | * @return a copy/clone of this exception.
51 | */
52 | public DriverException copy() {
53 | return new DriverException(getMessage(), this);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/driver-examples/osgi/src/main/java/com/datastax/driver/osgi/api/MailboxMessage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.osgi.api;
17 |
18 | import java.util.Date;
19 |
20 | public class MailboxMessage {
21 | private String recipient;
22 | private Date date;
23 | private String sender;
24 | private String body;
25 |
26 | public MailboxMessage(String recipient, Date date, String sender, String body) {
27 | this.recipient = recipient;
28 | this.date = date;
29 | this.sender = sender;
30 | this.body = body;
31 | }
32 |
33 | public String getRecipient() {
34 | return recipient;
35 | }
36 |
37 | public Date getDate() {
38 | return date;
39 | }
40 |
41 | public String getSender() {
42 | return sender;
43 | }
44 |
45 | public String getBody() {
46 | return body;
47 | }
48 |
49 | @Override public boolean equals(Object that) {
50 | if(that instanceof MailboxMessage) {
51 | MailboxMessage thatM = (MailboxMessage)that;
52 | return recipient.equals(thatM.getRecipient()) &&
53 | date.equals(thatM.getDate()) &&
54 | sender.equals(thatM.getSender()) &&
55 | body.equals(thatM.getBody());
56 | } else {
57 | return false;
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/driver-examples/osgi/src/test/java/com/datastax/driver/osgi/CCMBridgeListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.osgi;
17 |
18 | import org.testng.ITestContext;
19 | import org.testng.ITestListener;
20 | import org.testng.ITestResult;
21 |
22 | import com.datastax.driver.core.CCMBridge;
23 |
24 | /**
25 | * A listener that fires up a single node CCM instance on test class start and tears it
26 | * down on test class end.
27 | *
28 | * This is needed for tests that use Pax-Exam since it runs some methods in the OSGi container
29 | * which we do not want.
30 | */
31 | public class CCMBridgeListener implements ITestListener {
32 |
33 | private CCMBridge ccm;
34 |
35 | @Override public void onStart(ITestContext context) {
36 | ccm = CCMBridge.builder("test").withNodes(1).build();
37 | }
38 |
39 | @Override public void onFinish(ITestContext context) {
40 | if(ccm != null) {
41 | ccm.remove();
42 | }
43 | }
44 |
45 | @Override public void onTestStart(ITestResult result) {}
46 |
47 | @Override public void onTestSuccess(ITestResult result) {}
48 |
49 | @Override public void onTestFailure(ITestResult result) {}
50 |
51 | @Override public void onTestSkipped(ITestResult result) {}
52 |
53 | @Override public void onTestFailedButWithinSuccessPercentage(ITestResult result) {}
54 | }
55 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/MD5Digest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import java.util.Arrays;
19 |
20 | import com.datastax.driver.core.utils.Bytes;
21 |
22 | /**
23 | * The result of the computation of an MD5 digest.
24 | *
25 | * A MD5 is really just a byte[] but arrays are a no go as map keys. We could
26 | * wrap it in a ByteBuffer but:
27 | * 1. MD5Digest is a more explicit name than ByteBuffer to represent a md5.
28 | * 2. Using our own class allows to use our FastByteComparison for equals.
29 | */
30 | class MD5Digest {
31 |
32 | public final byte[] bytes;
33 |
34 | private MD5Digest(byte[] bytes) {
35 | this.bytes = bytes;
36 | }
37 |
38 | public static MD5Digest wrap(byte[] digest) {
39 | return new MD5Digest(digest);
40 | }
41 |
42 | @Override
43 | public final int hashCode() {
44 | return Arrays.hashCode(bytes);
45 | }
46 |
47 | @Override
48 | public final boolean equals(Object o) {
49 | if(!(o instanceof MD5Digest))
50 | return false;
51 | MD5Digest that = (MD5Digest)o;
52 | // handles nulls properly
53 | return Arrays.equals(this.bytes, that.bytes);
54 | }
55 |
56 | @Override
57 | public String toString() {
58 | return Bytes.toHexString(bytes);
59 | }
60 | }
61 |
62 |
--------------------------------------------------------------------------------
/driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/Computed.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.mapping.annotations;
17 |
18 |
19 | import java.lang.annotation.ElementType;
20 | import com.datastax.driver.mapping.Mapper;
21 | import java.lang.annotation.Retention;
22 | import java.lang.annotation.RetentionPolicy;
23 | import java.lang.annotation.Target;
24 |
25 | /**
26 | * Annotates a "computed" field, which gets filled from a CQL expression in the SELECT query
27 | * used to retrieve an entity.
28 | *
29 | * Note that such fields are only filled by default mapper operations ({@link Mapper#get(Object...)}),
30 | * they will be ignored in accessor queries and save operations.
31 | *
32 | * As opposed to other mapper annotation, this one doesn't handle case sensitivity. If your expression
33 | * contains case-sensitive names, you'll need to quote them explicitly:
34 | *
35 | * {@code @Computed("\"caseSensitiveFunction\"(v)")}
36 | *
37 | */
38 | @Target(ElementType.FIELD)
39 | @Retention(RetentionPolicy.RUNTIME)
40 | public @interface Computed {
41 | /**
42 | * The formula used to compute the field.
43 | *
44 | * This is a CQL expression like you would use directly in a query, for instance
45 | * "writetime(v)".
46 | *
47 | * @return the formula.
48 | */
49 | String value();
50 | }
51 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/ThreadLocalMonotonicTimestampGenerator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 |
19 | /**
20 | * A timestamp generator based on {@code System.currentTimeMillis()}, with an incrementing thread-local counter
21 | * to generate the sub-millisecond part.
22 | *
23 | * This implementation guarantees incrementing timestamps for a given client thread, provided that no more than
24 | * 1000 are requested for a given clock tick (the exact granularity of of {@link System#currentTimeMillis()}
25 | * depends on the operating system).
26 | *
27 | * If that rate is exceeded, a warning is logged and the timestamps don't increment anymore until the next clock
28 | * tick.
29 | */
30 | public class ThreadLocalMonotonicTimestampGenerator extends AbstractMonotonicTimestampGenerator {
31 | // We're deliberately avoiding an anonymous subclass with initialValue(), because this can introduce
32 | // classloader leaks in managed environments like Tomcat
33 | private final ThreadLocal lastRef = new ThreadLocal();
34 |
35 | @Override
36 | public long next() {
37 | Long last = this.lastRef.get();
38 | if (last == null)
39 | last = 0L;
40 |
41 | long next = computeNext(last);
42 |
43 | this.lastRef.set(next);
44 | return next;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/AuthProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import java.net.InetSocketAddress;
19 |
20 | import com.datastax.driver.core.exceptions.AuthenticationException;
21 |
22 | /**
23 | * Provides {@link Authenticator} instances for use when connecting
24 | * to Cassandra nodes.
25 | *
26 | * See {@link PlainTextAuthProvider} for an implementation which uses SASL
27 | * PLAIN mechanism to authenticate using username/password strings
28 | */
29 | public interface AuthProvider {
30 |
31 | /**
32 | * A provider that provides no authentication capability.
33 | *
34 | * This is only useful as a placeholder when no authentication is to be used.
35 | */
36 | public static final AuthProvider NONE = new AuthProvider() {
37 | public Authenticator newAuthenticator(InetSocketAddress host) {
38 | throw new AuthenticationException(host,
39 | String.format("Host %s requires authentication, but no authenticator found in Cluster configuration", host));
40 | }
41 | };
42 |
43 | /**
44 | * The {@code Authenticator} to use when connecting to {@code host}
45 | *
46 | * @param host the Cassandra host to connect to.
47 | * @return The authentication implementation to use.
48 | */
49 | public Authenticator newAuthenticator(InetSocketAddress host) throws AuthenticationException;
50 | }
51 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/querybuilder/Using.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.querybuilder;
17 |
18 | import java.util.List;
19 |
20 | public abstract class Using extends Utils.Appendeable {
21 |
22 | final String optionName;
23 |
24 | private Using(String optionName) {
25 | this.optionName = optionName;
26 | }
27 |
28 | static class WithValue extends Using {
29 | private final long value;
30 |
31 | WithValue(String optionName, long value) {
32 | super(optionName);
33 | this.value = value;
34 | }
35 |
36 | @Override
37 | void appendTo(StringBuilder sb, List variables) {
38 | sb.append(optionName).append(' ').append(value);
39 | }
40 |
41 | @Override
42 | boolean containsBindMarker() {
43 | return false;
44 | }
45 | }
46 |
47 | static class WithMarker extends Using {
48 | private final BindMarker marker;
49 |
50 | WithMarker(String optionName, BindMarker marker) {
51 | super(optionName);
52 | this.marker = marker;
53 | }
54 |
55 | @Override
56 | void appendTo(StringBuilder sb, List variables) {
57 | sb.append(optionName).append(' ').append(marker);
58 | }
59 |
60 | @Override
61 | boolean containsBindMarker() {
62 | return true;
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/VersionNumberTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import org.testng.annotations.Test;
19 | import static org.testng.Assert.assertEquals;
20 |
21 | public class VersionNumberTest {
22 |
23 | @Test(groups = "unit")
24 | public void versionNumberTest() {
25 |
26 | String[] versions = new String[] {
27 | "1.2.0",
28 | "2.0.0",
29 | "2.0.0-beta1",
30 | "2.0.0-beta1-SNAPSHOT",
31 | "2.0.0-beta1-SNAPSHOT+abc01",
32 | "2.0.0.22" // DSE
33 | };
34 |
35 | VersionNumber[] numbers = new VersionNumber[versions.length];
36 | for (int i = 0; i < versions.length; i++)
37 | numbers[i] = VersionNumber.parse(versions[i]);
38 |
39 | for (int i = 0; i < versions.length; i++)
40 | assertEquals(numbers[i].toString(), versions[i]);
41 |
42 | assertEquals(numbers[0].compareTo(numbers[1]), -1);
43 | assertEquals(numbers[1].compareTo(numbers[2]), 1);
44 | assertEquals(numbers[2].compareTo(numbers[3]), -1);
45 | assertEquals(numbers[3].compareTo(numbers[4]), 0);
46 | assertEquals(numbers[1].compareTo(numbers[5]), -1);
47 |
48 | VersionNumber deb = VersionNumber.parse("2.0.0~beta1");
49 | assertEquals(deb, numbers[2]);
50 |
51 | VersionNumber shorter = VersionNumber.parse("2.0");
52 | assertEquals(shorter, numbers[1]);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/WriteType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | /**
19 | * The type of a Cassandra write query.
20 | *
21 | * This information is returned by Cassandra when a write timeout is raised to
22 | * indicate what type of write timed out. This information is useful to decide
23 | * which retry policy to adopt.
24 | */
25 | public enum WriteType
26 | {
27 | /** A write to a single partition key. Such writes are guaranteed to be atomic and isolated. */
28 | SIMPLE,
29 | /**
30 | * A write to a multiple partition key that used the distributed batch log to ensure atomicity
31 | * (atomicity meaning that if any statement in the batch succeeds, all will eventually succeed).
32 | */
33 | BATCH,
34 | /** A write to a multiple partition key that doesn't use the distributed batch log. Atomicity for such writes is not guaranteed */
35 | UNLOGGED_BATCH,
36 | /** A counter write (that can be for one or multiple partition key). Such write should not be replayed to avoid over-counting. */
37 | COUNTER,
38 | /** The initial write to the distributed batch log that Cassandra performs internally before a BATCH write. */
39 | BATCH_LOG,
40 | /**
41 | * A conditional write. If a timeout has this {@code WriteType}, the timeout has happened while doing the compare-and-swap for
42 | * an conditional update. In this case, the update may or may not have been applied.
43 | */
44 | CAS;
45 | }
46 |
--------------------------------------------------------------------------------
/driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/QueryParameters.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.mapping.annotations;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | import com.datastax.driver.core.Configuration;
24 |
25 | /**
26 | * Query parameters to use in the (generated) implementation of a method of an {@link Accessor}
27 | * interface.
28 | *
29 | * All the parameters of this annotation are optional, and when not provided default to whatever
30 | * default the {@code Cluster} instance used underneath are (those set in
31 | * {@link Configuration#getQueryOptions}).
32 | */
33 | @Target(ElementType.METHOD)
34 | @Retention(RetentionPolicy.RUNTIME)
35 | public @interface QueryParameters {
36 | /**
37 | * The consistency level to use for the operation.
38 | *
39 | * @return the consistency level to use for the operation.
40 | */
41 | String consistency() default "";
42 |
43 | /**
44 | * The fetch size to use for paging the result of this operation.
45 | *
46 | * @return the fetch size to use for the operation.
47 | */
48 | int fetchSize() default -1;
49 |
50 | /**
51 | * Whether tracing should be enabled for this operation.
52 | *
53 | * @return whether tracing should be enabled for this operation.
54 | */
55 | boolean tracing() default false;
56 | }
57 |
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/AsyncQueryTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import java.util.Collection;
19 | import java.util.concurrent.TimeUnit;
20 |
21 | import com.google.common.collect.Lists;
22 | import org.testng.annotations.Test;
23 |
24 | import static org.testng.Assert.assertEquals;
25 | import static org.testng.Assert.assertTrue;
26 |
27 | public class AsyncQueryTest extends CCMBridge.PerClassSingleNodeCluster {
28 |
29 | @Override
30 | protected Collection getTableDefinitions() {
31 | return Lists.newArrayList();
32 | }
33 |
34 | /**
35 | * Checks that a cancelled query releases the connection (JAVA-407).
36 | */
37 | @Test(groups = "short")
38 | public void cancelQueryTest() throws InterruptedException {
39 | ResultSetFuture future = session.executeAsync("select release_version from system.local");
40 | future.cancel(true);
41 | assertTrue(future.isCancelled());
42 |
43 | TimeUnit.MILLISECONDS.sleep(100);
44 |
45 | HostConnectionPool pool = getPool(session);
46 | for (Connection connection : pool.connections) {
47 | assertEquals(connection.inFlight.get(), 0);
48 | }
49 | }
50 |
51 | private static HostConnectionPool getPool(Session session) {
52 | Collection pools = ((SessionManager) session).pools.values();
53 | assertEquals(pools.size(), 1);
54 | return pools.iterator().next();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/Column.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.mapping.annotations;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | /**
24 | * Annotation that allows to specify the name of the CQL column to which the
25 | * field should be mapped.
26 | *
27 | * Note that this annotation is generally optional in the sense that any field
28 | * of a class annotated by {@link Table} will be mapped by default to a column
29 | * having the same name than this field unless that field has the
30 | * {@link Transient} annotation. As such, this annotation is mainly useful when
31 | * the name to map the field to is not the same one that the field itself (but
32 | * can be added without it's name parameter for documentation sake).
33 | */
34 | @Target(ElementType.FIELD)
35 | @Retention(RetentionPolicy.RUNTIME)
36 | public @interface Column {
37 | /**
38 | * Name of the column being mapped in Cassandra. By default, the name of the
39 | * field will be used.
40 | *
41 | * @return the name of the mapped column in Cassandra, or {@code ""} to use
42 | * the field name.
43 | */
44 | String name() default "";
45 |
46 | /**
47 | * Whether the column name is a case sensitive one.
48 | *
49 | * @return whether the column name is a case sensitive one.
50 | */
51 | boolean caseSensitive() default false;
52 | }
53 |
--------------------------------------------------------------------------------
/driver-examples/osgi/src/main/java/com/datastax/driver/osgi/impl/Activator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.osgi.impl;
17 |
18 | import java.util.Hashtable;
19 |
20 | import org.osgi.framework.BundleActivator;
21 | import org.osgi.framework.BundleContext;
22 |
23 | import com.datastax.driver.core.Cluster;
24 | import com.datastax.driver.core.Session;
25 | import com.datastax.driver.osgi.api.MailboxService;
26 |
27 | public class Activator implements BundleActivator {
28 |
29 | private Cluster cluster;
30 |
31 | @Override public void start(BundleContext context) throws Exception {
32 | String contactPointsStr = context.getProperty("cassandra.contactpoints");
33 | if(contactPointsStr == null) {
34 | contactPointsStr = "127.0.0.1";
35 | }
36 | String[] contactPoints = contactPointsStr.split(",");
37 |
38 | String keyspace = context.getProperty("cassandra.keyspace");
39 | if(keyspace == null) {
40 | keyspace = "mailbox";
41 | }
42 |
43 | cluster = Cluster.builder().addContactPoints(contactPoints).build();
44 | Session session = cluster.connect();
45 |
46 | MailboxImpl mailbox = new MailboxImpl(session, keyspace);
47 | mailbox.init();
48 |
49 | context.registerService(MailboxService.class.getName(), mailbox, new Hashtable());
50 | }
51 |
52 | @Override public void stop(BundleContext context) throws Exception {
53 | if(cluster != null) {
54 | cluster.close();
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/driver-mapping/src/main/java/com/datastax/driver/mapping/AccessorReflectionMapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.mapping;
17 |
18 | import java.lang.reflect.Proxy;
19 | import java.util.*;
20 |
21 | class AccessorReflectionMapper extends AccessorMapper {
22 |
23 | private static AccessorReflectionFactory factory = new AccessorReflectionFactory();
24 |
25 | private final Class[] proxyClasses;
26 | private final AccessorInvocationHandler handler;
27 |
28 | @SuppressWarnings({"unchecked", "rawtypes"})
29 | private AccessorReflectionMapper(Class daoClass, List methods) {
30 | super(daoClass, methods);
31 | this.proxyClasses = (Class[])new Class[]{ daoClass };
32 | this.handler = new AccessorInvocationHandler(this);
33 | }
34 |
35 | public static Factory factory() {
36 | return factory;
37 | }
38 |
39 | @SuppressWarnings("unchecked")
40 | @Override
41 | public T createProxy() {
42 | try {
43 | return (T) Proxy.newProxyInstance(daoClass.getClassLoader(), proxyClasses, handler);
44 | } catch (Exception e) {
45 | throw new RuntimeException("Cannot create instance for Accessor interface " + daoClass.getName());
46 | }
47 | }
48 |
49 | private static class AccessorReflectionFactory implements Factory {
50 | public AccessorMapper create(Class daoClass, List methods) {
51 | return new AccessorReflectionMapper(daoClass, methods);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/Field.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.mapping.annotations;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | /**
24 | * Annotation that allows to specify the name of the CQL UDT field to which the
25 | * Java field should be mapped.
26 | *
27 | * Note that this annotation is generally optional in the sense that any field
28 | * of a class annotated by {@link UDT} will be mapped by default to a UDT field
29 | * having the same name than this Java field unless that Java field has the
30 | * {@link Transient} annotation. As such, this annotation is mainly useful when
31 | * the name to map the field to is not the same one that the field itself (but
32 | * can be added without it's name parameter for documentation sake).
33 | */
34 | @Target(ElementType.FIELD)
35 | @Retention(RetentionPolicy.RUNTIME)
36 | public @interface Field {
37 | /**
38 | * Name of the column being mapped in Cassandra. By default, the name of the
39 | * field will be used.
40 | *
41 | * @return the name of the mapped column in Cassandra, or {@code ""} to use
42 | * the field name.
43 | */
44 | String name() default "";
45 |
46 | /**
47 | * Whether the column name is a case sensitive one.
48 | *
49 | * @return whether the column name is a case sensitive one.
50 | */
51 | boolean caseSensitive() default false;
52 | }
53 |
--------------------------------------------------------------------------------
/driver-mapping/src/main/java/com/datastax/driver/mapping/AccessorMapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.mapping;
17 |
18 | import java.util.*;
19 |
20 | import com.google.common.util.concurrent.Futures;
21 | import com.google.common.util.concurrent.ListenableFuture;
22 |
23 | import com.datastax.driver.core.*;
24 |
25 | abstract class AccessorMapper {
26 |
27 | public final Class daoClass;
28 | protected final List methods;
29 |
30 | protected AccessorMapper(Class daoClass, List methods) {
31 | this.daoClass = daoClass;
32 | this.methods = methods;
33 | }
34 |
35 | abstract T createProxy();
36 |
37 | public void prepare(MappingManager manager) {
38 | List> statements = new ArrayList>(methods.size());
39 |
40 | for (MethodMapper method : methods)
41 | statements.add(manager.getSession().prepareAsync(method.queryString));
42 |
43 | try {
44 | List preparedStatements = Futures.allAsList(statements).get();
45 | for (int i = 0; i < methods.size(); i++)
46 | methods.get(i).prepare(manager, preparedStatements.get(i));
47 | } catch (Exception e) {
48 | throw new RuntimeException("Error preparing queries for accessor " + daoClass.getSimpleName(), e);
49 | }
50 | }
51 |
52 | interface Factory {
53 | public AccessorMapper create(Class daoClass, List methods);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/my-test/src/main/java/my/test/cql3/ConstantsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package my.test.cql3;
19 |
20 | import my.test.TestBase;
21 |
22 | public class ConstantsTest extends TestBase {
23 |
24 | public static void main(String[] args) throws Exception {
25 | new ConstantsTest().start();
26 | }
27 |
28 | @Override
29 | public void startInternal() throws Exception {
30 | test_Adder_Substracter();
31 | dropTest();
32 | }
33 |
34 | void test_Adder_Substracter() throws Exception {
35 | execute("CREATE TABLE IF NOT EXISTS test_Adder (counter_value counter," + //
36 | "url_name varchar,," + //
37 | "page_name varchar,," + //
38 | "PRIMARY KEY (url_name, page_name))");
39 | execute("UPDATE test_Adder SET counter_value = counter_value + 1 WHERE url_name='datastax.com' AND page_name='home'");
40 |
41 | execute("UPDATE test_Adder SET counter_value = counter_value - 2 WHERE url_name='datastax.com' AND page_name='home'");
42 |
43 | //出错:The negation of -9223372036854775808 overflows supported counter precision (signed 8 bytes integer)
44 | //不允许是Long.MIN_VALUE
45 | tryExecute("UPDATE test_Adder SET counter_value = counter_value - -9223372036854775808 "
46 | + "WHERE url_name='datastax.com' AND page_name='home'");
47 | }
48 |
49 | void dropTest() throws Exception {
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/my-test/src/main/java/my/test/cql3/Test.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package my.test.cql3;
19 |
20 | import java.util.ArrayList;
21 | import java.util.Collections;
22 | import java.util.Comparator;
23 | import java.util.HashMap;
24 | import java.util.List;
25 | import java.util.Map;
26 |
27 | public class Test {
28 |
29 | static class A {
30 |
31 | }
32 |
33 | /**
34 | * @param args
35 | */
36 | public static void main(String[] args) {
37 | // Sort the sstables by hotness (coldest-first). We first build a map because the hotness may change during the sort.
38 | final Map hotnessSnapshot = new HashMap();
39 |
40 | hotnessSnapshot.put("a", 2.0);
41 | hotnessSnapshot.put("b", 3.0);
42 | hotnessSnapshot.put("c", 1.0);
43 |
44 | List sstables = new ArrayList();
45 | sstables.addAll(hotnessSnapshot.keySet());
46 | Collections.sort(sstables, new Comparator() {
47 | public int compare(String o1, String o2) {
48 | int comparison = Double.compare(hotnessSnapshot.get(o1), hotnessSnapshot.get(o2));
49 | if (comparison != 0)
50 | return comparison;
51 |
52 | return 0;
53 | }
54 | });
55 |
56 | System.out.println(sstables);
57 |
58 | System.out.println(sstables.subList(1, sstables.size()));
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/Frozen.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.mapping.annotations;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | import com.datastax.driver.core.DataType;
24 |
25 | /**
26 | * Specifies that the field decorated with this annotation maps to a CQL type that is {@link DataType#isFrozen() frozen},
27 | * or contains frozen subtypes.
28 | *
29 | * This annotation is purely informational at this stage, but will become useful when a schema generation feature is
30 | * added to the mapper.
31 | *
32 | * @see FrozenKey
33 | * @see FrozenValue
34 | */
35 | @Target(ElementType.FIELD)
36 | @Retention(RetentionPolicy.RUNTIME)
37 | public @interface Frozen {
38 |
39 | /**
40 | * Contains the full CQL type of the target column. As a convenience, this can be left out when only the top-level
41 | * type is frozen.
42 | *
43 | * Examples:
44 | *
45 | * // Will map to frozen<user>
46 | * @Frozen
47 | * private User user;
48 | *
49 | * @Frozen("map<text, map<text, frozen<user>>>")
50 | * private Map<String, Map<String, User>> m;
51 | *
52 | *
53 | * Also consider the {@link FrozenKey @FrozenKey} and {@link FrozenValue @FrozenValue} shortcuts for simple collections.
54 | *
55 | * @return the full CQL type of the target column.
56 | */
57 | String value() default "";
58 | }
59 |
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/policies/CloseableLoadBalancingPolicyTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.policies;
17 |
18 | import org.testng.annotations.Test;
19 |
20 | import static org.assertj.core.api.Assertions.assertThat;
21 |
22 | import com.datastax.driver.core.CCMBridge;
23 | import com.datastax.driver.core.Cluster;
24 |
25 | public class CloseableLoadBalancingPolicyTest {
26 | @Test(groups = "short")
27 | public void should_be_invoked_at_shutdown() {
28 | CloseMonitoringPolicy policy = new CloseMonitoringPolicy(Policies.defaultLoadBalancingPolicy());
29 | CCMBridge ccm = null;
30 | Cluster cluster = null;
31 | try {
32 | ccm = CCMBridge.builder("test").withNodes(1).build();
33 | cluster = Cluster.builder()
34 | .addContactPoint(CCMBridge.ipOfNode(1))
35 | .withLoadBalancingPolicy(policy)
36 | .build();
37 | cluster.connect();
38 | } finally {
39 | if (cluster != null)
40 | cluster.close();
41 | if (ccm != null)
42 | ccm.remove();
43 | }
44 | assertThat(policy.wasClosed).isTrue();
45 | }
46 |
47 | static class CloseMonitoringPolicy extends DelegatingLoadBalancingPolicy {
48 |
49 | volatile boolean wasClosed = false;
50 |
51 | public CloseMonitoringPolicy(LoadBalancingPolicy delegate) {
52 | super(delegate);
53 | }
54 |
55 | @Override
56 | public void close() {
57 | wasClosed = true;
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/ExceptionCode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import java.util.HashMap;
19 | import java.util.Map;
20 |
21 | import com.datastax.driver.core.exceptions.DriverInternalError;
22 |
23 | /**
24 | * Exceptions code, as defined by the native protocol.
25 | */
26 | enum ExceptionCode {
27 |
28 | SERVER_ERROR (0x0000),
29 | PROTOCOL_ERROR (0x000A),
30 |
31 | BAD_CREDENTIALS (0x0100),
32 |
33 | // 1xx: problem during request execution
34 | UNAVAILABLE (0x1000),
35 | OVERLOADED (0x1001),
36 | IS_BOOTSTRAPPING(0x1002),
37 | TRUNCATE_ERROR (0x1003),
38 | WRITE_TIMEOUT (0x1100),
39 | READ_TIMEOUT (0x1200),
40 |
41 | // 2xx: problem validating the request
42 | SYNTAX_ERROR (0x2000),
43 | UNAUTHORIZED (0x2100),
44 | INVALID (0x2200),
45 | CONFIG_ERROR (0x2300),
46 | ALREADY_EXISTS (0x2400),
47 | UNPREPARED (0x2500);
48 |
49 | public final int value;
50 | private static final Map valueToCode = new HashMap(ExceptionCode.values().length);
51 | static {
52 | for (ExceptionCode code : ExceptionCode.values())
53 | valueToCode.put(code.value, code);
54 | }
55 |
56 | private ExceptionCode(int value) {
57 | this.value = value;
58 | }
59 |
60 | public static ExceptionCode fromValue(int value) {
61 | ExceptionCode code = valueToCode.get(value);
62 | if (code == null)
63 | throw new DriverInternalError(String.format("Unknown error code %d", value));
64 | return code;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/my-test/src/main/java/my/test/cql3/MetaDataTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package my.test.cql3;
19 |
20 | import my.test.TestBase;
21 |
22 | public class MetaDataTest extends TestBase {
23 | public static void main(String[] args) throws Exception {
24 | new MetaDataTest().start();
25 | }
26 |
27 | @Override
28 | public void startInternal() throws Exception {
29 | cql = "SELECT * FROM system.schema_keyspaces WHERE keyspace_name='mytest'";
30 | //printResultSet();
31 |
32 | cql = "SELECT * FROM system.schema_keyspaces";
33 | printResultSet();
34 |
35 | cql = "SELECT * FROM system.schema_keyspaces WHERE keyspace_name='system'";
36 | //printResultSet();
37 |
38 | cql = "SELECT columnfamily_name FROM system.schema_columnfamilies";
39 | printResultSet();
40 |
41 | cql = "SELECT columnfamily_name,column_name FROM system.schema_columns";
42 | printResultSet();
43 |
44 | // cql = "SELECT columnfamily_name FROM system.schema_columnfamilies WHERE keyspace_name='system'";
45 | // printResultSet();
46 | //
47 | // cql = "SELECT columnfamily_name,column_name FROM system.schema_columns WHERE keyspace_name='system'";
48 | // printResultSet();
49 | //
50 | // cql = "SELECT columnfamily_name,column_name FROM system.schema_columns WHERE keyspace_name='mytest'";
51 | // printResultSet();
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/driver-core/src/test/java/com/datastax/driver/core/DataTypeAssert.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core;
17 |
18 | import com.google.common.reflect.TypeToken;
19 | import org.assertj.core.api.AbstractAssert;
20 |
21 | import static com.datastax.driver.core.Assertions.assertThat;
22 |
23 | public class DataTypeAssert extends AbstractAssert {
24 | public DataTypeAssert(DataType actual) {
25 | super(actual, DataTypeAssert.class);
26 | }
27 |
28 | public DataTypeAssert hasName(DataType.Name name) {
29 | assertThat(actual.name).isEqualTo(name);
30 | return this;
31 | }
32 |
33 | public DataTypeAssert isFrozen() {
34 | assertThat(actual.isFrozen()).isTrue();
35 | return this;
36 | }
37 |
38 | public DataTypeAssert isNotFrozen() {
39 | assertThat(actual.isFrozen()).isFalse();
40 | return this;
41 | }
42 |
43 | public DataTypeAssert canBeDeserializedAs(TypeToken typeToken) {
44 | assertThat(actual.canBeDeserializedAs(typeToken)).isTrue();
45 | return this;
46 | }
47 |
48 | public DataTypeAssert cannotBeDeserializedAs(TypeToken typeToken) {
49 | assertThat(actual.canBeDeserializedAs(typeToken)).isFalse();
50 | return this;
51 | }
52 |
53 | public DataTypeAssert hasTypeArgument(int position, DataType expected) {
54 | assertThat(actual.getTypeArguments().get(position)).isEqualTo(expected);
55 | return this;
56 | }
57 |
58 | public DataTypeAssert hasTypeArguments(DataType... expected) {
59 | assertThat(actual.getTypeArguments()).containsExactly(expected);
60 | return this;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/exceptions/AuthenticationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.exceptions;
17 |
18 | import java.net.InetAddress;
19 | import java.net.InetSocketAddress;
20 |
21 | /**
22 | * Indicates an error during the authentication phase while connecting to a node.
23 | */
24 | public class AuthenticationException extends DriverException {
25 |
26 | private static final long serialVersionUID = 0;
27 |
28 | private final InetSocketAddress address;
29 |
30 | public AuthenticationException(InetSocketAddress address, String message) {
31 | super(String.format("Authentication error on host %s: %s", address, message));
32 | this.address = address;
33 | }
34 |
35 | private AuthenticationException(String message, Throwable cause, InetSocketAddress address)
36 | {
37 | super(message, cause);
38 | this.address = address;
39 | }
40 |
41 | /**
42 | * The host for which the authentication failed.
43 | *
44 | * This is a shortcut for {@code getAddress().getAddress()}.
45 | *
46 | * @return the host for which the authentication failed.
47 | */
48 | public InetAddress getHost() {
49 | return address.getAddress();
50 | }
51 |
52 | /**
53 | * The full address of the host for which the authentication failed.
54 | *
55 | * @return the host for which the authentication failed.
56 | */
57 | public InetSocketAddress getAddress() {
58 | return address;
59 | }
60 |
61 | @Override
62 | public DriverException copy() {
63 | return new AuthenticationException(getMessage(), this, address);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/exceptions/BootstrappingException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.exceptions;
17 |
18 | import java.net.InetSocketAddress;
19 |
20 | /**
21 | * Indicates that the contacted host was bootstrapping.
22 | * This class is mainly intended for internal use;
23 | * client applications are not expected to deal with this exception directly,
24 | * because the driver would transparently retry the same query on another host;
25 | * but such exceptions are likely to appear occasionally in the driver logs.
26 | */
27 | public class BootstrappingException extends DriverInternalError {
28 |
29 | private static final long serialVersionUID = 0;
30 |
31 | private final InetSocketAddress address;
32 |
33 | public BootstrappingException(InetSocketAddress address, String message) {
34 | super(String.format("Queried host (%s) was bootstrapping: %s", address, message));
35 | this.address = address;
36 | }
37 |
38 | /**
39 | * Private constructor used solely when copying exceptions.
40 | */
41 | private BootstrappingException(InetSocketAddress address, String message, BootstrappingException cause) {
42 | super(message, cause);
43 | this.address = address;
44 | }
45 |
46 | /**
47 | * The full address of the host that was bootstrapping.
48 | *
49 | * @return The full address of the host that was bootstrapping.
50 | */
51 | public InetSocketAddress getAddress() {
52 | return address;
53 | }
54 |
55 | @Override
56 | public BootstrappingException copy() {
57 | return new BootstrappingException(address, getMessage(), this);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/policies/ConstantReconnectionPolicy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.policies;
17 |
18 | /**
19 | * A reconnection policy that waits a constant time between each reconnection attempt.
20 | */
21 | public class ConstantReconnectionPolicy implements ReconnectionPolicy {
22 |
23 | private final long delayMs;
24 |
25 | /**
26 | * Creates a reconnection policy that creates with the provided constant wait
27 | * time between reconnection attempts.
28 | *
29 | * @param constantDelayMs the constant delay in milliseconds to use.
30 | */
31 | public ConstantReconnectionPolicy(long constantDelayMs) {
32 | if (constantDelayMs < 0)
33 | throw new IllegalArgumentException(String.format("Invalid negative delay (got %d)", constantDelayMs));
34 |
35 | this.delayMs = constantDelayMs;
36 | }
37 |
38 | /**
39 | * The constant delay used by this reconnection policy.
40 | *
41 | * @return the constant delay used by this reconnection policy.
42 | */
43 | public long getConstantDelayMs() {
44 | return delayMs;
45 | }
46 |
47 | /**
48 | * A new schedule that uses a constant {@code getConstantDelayMs()} delay
49 | * between reconnection attempt.
50 | *
51 | * @return the newly created schedule.
52 | */
53 | @Override
54 | public ReconnectionSchedule newSchedule() {
55 | return new ConstantSchedule();
56 | }
57 |
58 | private class ConstantSchedule implements ReconnectionSchedule {
59 |
60 | @Override
61 | public long nextDelayMs() {
62 | return delayMs;
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/exceptions/OverloadedException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.exceptions;
17 |
18 | import java.net.InetSocketAddress;
19 |
20 | /**
21 | * Indicates that the contacted host reported itself being overloaded.
22 | * This class is mainly intended for internal use;
23 | * client applications are not expected to deal with this exception directly,
24 | * because the driver would transparently retry the same query on another host;
25 | * but such exceptions are likely to appear occasionally in the driver logs.
26 | */
27 | public class OverloadedException extends DriverInternalError {
28 |
29 | private static final long serialVersionUID = 0;
30 |
31 | private final InetSocketAddress address;
32 |
33 | public OverloadedException(InetSocketAddress address, String message) {
34 | super(String.format("Queried host (%s) was overloaded: %s", address, message));
35 | this.address = address;
36 | }
37 |
38 | /**
39 | * Private constructor used solely when copying exceptions.
40 | */
41 | private OverloadedException(InetSocketAddress address, String message, OverloadedException cause) {
42 | super(message, cause);
43 | this.address = address;
44 | }
45 |
46 | /**
47 | * The full address of the host that reported itself being overloaded.
48 | *
49 | * @return The full address of the host that reported itself being overloaded.
50 | */
51 | public InetSocketAddress getAddress() {
52 | return address;
53 | }
54 |
55 | @Override
56 | public OverloadedException copy() {
57 | return new OverloadedException(address, getMessage(), this);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/driver-core/src/main/java/com/datastax/driver/core/exceptions/UnpreparedException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2015 DataStax Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.driver.core.exceptions;
17 |
18 | import java.net.InetSocketAddress;
19 |
20 | /**
21 | * Indicates that the contacted host replied with an UNPREPARED error code.
22 | * This class is mainly intended for internal use;
23 | * client applications are not expected to deal with this exception directly,
24 | * because the driver would transparently prepare the query and execute it again;
25 | * but such exceptions are likely to appear occasionally in the driver logs.
26 | */
27 | public class UnpreparedException extends DriverInternalError {
28 |
29 | private static final long serialVersionUID = 0;
30 |
31 | private final InetSocketAddress address;
32 |
33 | public UnpreparedException(InetSocketAddress address, String message) {
34 | super(String.format("A prepared query was submitted on %s but was not known of that node: %s", address, message));
35 | this.address = address;
36 | }
37 |
38 | /**
39 | * Private constructor used solely when copying exceptions.
40 | */
41 | private UnpreparedException(InetSocketAddress address, String message, UnpreparedException cause) {
42 | super(message, cause);
43 | this.address = address;
44 | }
45 |
46 | /**
47 | * The full address of the host that replied with an UNPREPARED error code.
48 | *
49 | * @return The full address of the host that replied with an UNPREPARED error code.
50 | */
51 | public InetSocketAddress getAddress() {
52 | return address;
53 | }
54 |
55 | @Override
56 | public UnpreparedException copy() {
57 | return new UnpreparedException(address, getMessage(), this);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------