├── .gitignore ├── .settings └── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── build.txt ├── changes.txt ├── pom.xml ├── troilus-core-java7 ├── pom.xml └── src │ └── main │ └── java │ └── net │ └── oneandone │ └── troilus │ ├── AbstractQuery.java │ ├── BatchMutationQuery.java │ ├── BeanMapper.java │ ├── ColumnName.java │ ├── ConstraintException.java │ ├── Context.java │ ├── Count.java │ ├── CounterBatchMutationQuery.java │ ├── CounterMutationQuery.java │ ├── CounterMutationQueryData.java │ ├── DBSession.java │ ├── DataTypes.java │ ├── DeleteQuery.java │ ├── DeleteQueryDataImpl.java │ ├── ExecutionSpec.java │ ├── Field.java │ ├── IfConditionException.java │ ├── Immutables.java │ ├── InsertQuery.java │ ├── InterceptorRegistry.java │ ├── Java7DaoImpl.java │ ├── ListReadQuery.java │ ├── ListenableFutures.java │ ├── MetadataCatalog.java │ ├── MutationQuery.java │ ├── Optionals.java │ ├── PropertiesSource.java │ ├── ProtocolErrorException.java │ ├── ReadQueryDataImpl.java │ ├── RecordImpl.java │ ├── RecordListImpl.java │ ├── Result.java │ ├── ResultAdapter.java │ ├── ResultListPublisher.java │ ├── ResultListSubscription.java │ ├── SingleEntryResultListAdapter.java │ ├── SingleReadQuery.java │ ├── Tablename.java │ ├── TooManyResultsException.java │ ├── UDTValueMapper.java │ ├── UpdateQuery.java │ ├── WriteQuery.java │ ├── WriteQueryDataImpl.java │ ├── WriteWithCounterQuery.java │ ├── interceptor │ ├── ConstraintsInterceptor.java │ ├── DeleteQueryData.java │ ├── QueryInterceptor.java │ └── SingleReadQueryData.java │ └── java7 │ ├── BatchMutation.java │ ├── Batchable.java │ ├── BatchableWithTime.java │ ├── CounterMutation.java │ ├── Dao.java │ ├── Deletion.java │ ├── FetchingIterable.java │ ├── FetchingIterator.java │ ├── Insertion.java │ ├── ListRead.java │ ├── ListReadWithColumns.java │ ├── ListReadWithUnit.java │ ├── Mutation.java │ ├── Query.java │ ├── Record.java │ ├── ResultList.java │ ├── SingleRead.java │ ├── SingleReadWithColumns.java │ ├── SingleReadWithUnit.java │ ├── Update.java │ ├── UpdateWithUnit.java │ ├── UpdateWithUnitAndCounter.java │ ├── WithCounter.java │ ├── Write.java │ ├── WriteWithCounter.java │ └── interceptor │ ├── CascadeOnDeleteInterceptor.java │ ├── CascadeOnWriteInterceptor.java │ ├── DeleteQueryRequestInterceptor.java │ ├── ReadQueryData.java │ ├── ReadQueryRequestInterceptor.java │ ├── ReadQueryResponseInterceptor.java │ ├── ResultListAdapter.java │ ├── WriteQueryData.java │ └── WriteQueryRequestInterceptor.java └── troilus-core ├── .gitignore ├── .toDelete ├── pom.xml └── src ├── main └── java │ └── net │ └── oneandone │ └── troilus │ ├── AbstractQueryAdapter.java │ ├── BatchMutation.java │ ├── BatchMutationQueryAdapter.java │ ├── Batchable.java │ ├── BatchableWithTime.java │ ├── CompletableFutures.java │ ├── CounterBatchMutationQueryAdapter.java │ ├── CounterMutation.java │ ├── CounterMutationQueryAdapter.java │ ├── Dao.java │ ├── DaoImpl.java │ ├── DeleteQueryAdapter.java │ ├── Deletion.java │ ├── FetchingIterable.java │ ├── FetchingIterator.java │ ├── InsertQueryAdapter.java │ ├── Insertion.java │ ├── ListRead.java │ ├── ListReadQueryAdapter.java │ ├── ListReadWithColumns.java │ ├── ListReadWithUnit.java │ ├── Mutation.java │ ├── Mutations.java │ ├── Query.java │ ├── Record.java │ ├── RecordAdapter.java │ ├── RecordMappingPublisher.java │ ├── ResultList.java │ ├── SingleRead.java │ ├── SingleReadQueryAdapter.java │ ├── SingleReadWithColumns.java │ ├── SingleReadWithUnit.java │ ├── Update.java │ ├── UpdateQueryAdapter.java │ ├── UpdateWithUnit.java │ ├── UpdateWithUnitAndCounter.java │ ├── WithCounter.java │ ├── Write.java │ ├── WriteWithCounter.java │ ├── WriteWithCounterQueryAdapter.java │ └── interceptor │ ├── CascadeOnDeleteInterceptor.java │ ├── CascadeOnWriteInterceptor.java │ ├── DeleteQueryRequestInterceptor.java │ ├── ReadQueryData.java │ ├── ReadQueryRequestInterceptor.java │ ├── ReadQueryResponseInterceptor.java │ ├── RecordListAdapter.java │ ├── WriteQueryData.java │ └── WriteQueryRequestInterceptor.java └── test ├── java └── net │ └── oneandone │ └── troilus │ ├── BeanMapperReadTest.java │ ├── BeanMapperWriteTest.java │ ├── CassandraDB.java │ ├── CompilerCheck.java │ ├── SimpleResultList.java │ ├── UserType.java │ ├── api │ ├── BatchingWithMultiSessionTest.java │ ├── CollectionsTest.java │ ├── ColumnsApiTest.java │ ├── ExpliciteKeyspacenameTest.java │ ├── FeesTable.java │ ├── HistoryTable.java │ ├── HistoryTableTest.java │ ├── IdsTable.java │ ├── InterceptorTest.java │ ├── LoginsTable.java │ ├── NativeTest.java │ ├── PaginationInvites.java │ ├── PaginationTest.java │ ├── PartialReadTest.java │ ├── PlusLoginsTable.java │ ├── ReadWithConditionTest.java │ ├── SessionReplacedTest.java │ ├── UserDefinedFunctionsTest.java │ ├── UserType.java │ ├── UsersTable.java │ ├── UsersTableFields.java │ └── WideRowTest.java │ ├── async │ └── AsyncTest.java │ ├── cascade │ ├── CascadingTest.java │ ├── DaoManager.java │ ├── KeyByAccountColumns.java │ └── KeyByEmailColumns.java │ ├── example │ ├── Address.java │ ├── AddressType.java │ ├── ClassifierEnum.java │ ├── Functions.java │ ├── Hotel.java │ ├── HotelSubscriber.java │ ├── HotelTableFields.java │ ├── HotelTest.java │ ├── HotelsTable.java │ └── RoomsTable.java │ ├── persistence │ ├── EntityInheritanceMappingTest.java │ ├── EntityMappingTest.java │ ├── JPAEntityMappingTest.java │ ├── JPAUser.java │ ├── MinimalUser.java │ └── User.java │ ├── reactive │ ├── MySubscriber.java │ ├── PublisherFetchingTest.java │ ├── PublisherTckTest.java │ └── ReactiveTest.java │ ├── referentialintegrity │ ├── DeviceTable.java │ ├── DeviceTest.java │ ├── Immutables.java │ ├── PhonenumbersConstraints.java │ └── PhonenumbersTable.java │ └── userdefinieddatatypes │ ├── Addr.java │ ├── AddrType.java │ ├── Addressline.java │ ├── AddresslineType.java │ ├── Classifier.java │ ├── ClassifierType.java │ ├── CustomersTable.java │ ├── Score.java │ ├── ScoreType.java │ ├── UDTValueMappingCollectionTests.java │ └── UserDefinedDataTypesTest.java └── resources ├── cassandra.yaml ├── com └── unitedinternet │ └── troilus │ └── example │ ├── addr.ddl │ ├── address.ddl │ ├── addressline.ddl │ ├── classifier.ddl │ ├── customers.ddl │ ├── device.ddl │ ├── fees.ddl │ ├── functions.ddl │ ├── history.ddl │ ├── hotels.ddl │ ├── ids.ddl │ ├── invites.ddl │ ├── key_by_accountid.ddl │ ├── key_by_email.ddl │ ├── logins.ddl │ ├── phone_numbers.ddl │ ├── plus_logins.ddl │ ├── rooms.ddl │ ├── score.ddl │ └── users.ddl └── logback-test.xml /.gitignore: -------------------------------------------------------------------------------- 1 | /.project 2 | /troilus-service-example/target 3 | /troilus-service-example/tomcat.9080 4 | /troilus-service-example/.classpath 5 | /troilus-service-example/.project 6 | /troilus-service-example/.settings 7 | /troilus-core-minimal/.classpath 8 | /troilus-core-minimal/.project 9 | /troilus-core-minimal/target 10 | /troilus-core-minimal/.settings 11 | /troilus-core-java7/.settings 12 | /troilus-core-java7/target 13 | /troilus-core-java7/.classpath 14 | /troilus-core-java7/.project 15 | /target 16 | /troilus-core/test-output 17 | /troilus-core/src/test/java/net/oneandone/troilus/DeleteMe.java 18 | /troilus-service-example/test-output 19 | /troilus-service-example/tomcat.0 20 | /troilus-service-example/bin 21 | -------------------------------------------------------------------------------- /.settings/.gitignore: -------------------------------------------------------------------------------- 1 | /org.eclipse.core.resources.prefs 2 | /org.eclipse.m2e.core.prefs 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | # - oraclejdk7 5 | -------------------------------------------------------------------------------- /build.txt: -------------------------------------------------------------------------------- 1 | 2 | VERIFY 3 | # mvn -P foss-parent-verification clean verify -Denforcer.fail=false -Dcheckstyle.skip=true -Dpmd.skip=true -Djacoco.skip=true -Dcpd.skip=true -Dmaven.test.skip=true 4 | mvn -P foss-parent-verification clean verify -Denforcer.fail=false -Dcheckstyle.skip=true -Dpmd.skip=true -Djacoco.skip=true -Dcpd.skip=true 5 | 6 | PREPARE 7 | mvn release:prepare -DpushChanges=false 8 | 9 | RELEASE 10 | mvn release:perform -DpushChanges=false -DlocalCheckout=true -Darguments="-Denforcer.fail=false -Dcheckstyle.skip=true -Dpmd.skip=true -Djacoco.skip=true -Dlicense.skip=true -Dcpd.skip=true -Dmaven.test.skip=true" 11 | // -Dadditionalparam=-Xdoclint:none 12 | 13 | STAGING REPO 14 | https://oss.sonatype.org/#stagingRepositories 15 | 16 | TAGGING 17 | https://github.com/1and1/Troilus/releases 18 | -------------------------------------------------------------------------------- /changes.txt: -------------------------------------------------------------------------------- 1 | 0.19 2 | * Update Guava to 30.0-jre 3 | 4 | 0.18 5 | * Fixed the putMapValue(...) method(s) in Write API to successfully add/update User Defined Type's into a datatype of map 6 | * Introduced a new Deletion API to remove a map value (ie: Deletion.removeMapValue(...)) 7 | 8 | 0.17 9 | * Pagination Support - ListRead.withPagingState(), ListReadQuery.toStatementAsync() 10 | * Inheritance of @Field mappings for entities in BeanMapper 11 | * Upgrade from Cassandra Datastax 2.2.0-rc2 driver to 3.0.0-rc1 driver 12 | * Upgrade tests from Cassandra 2.x to Cassandra 3.0.0 (see pom.xml dependency and CassandraDB.java) 13 | * LocalDateTime Support - Record.java interfaces and implementations 14 | * bugfix: WriteQueryDataImpl.java toUpdateStatementAsync() no longer maps primary keys into Update SET 15 | * bugfix: RecordImpl.PropertySourceAdapter rewrote read() and read(String name, Class clazz1, Class clazz2) to work with UDTValue collections. 16 | * New test cases: PaginationTest.java, EntityInheritanceMappingTest.java, UDTValueMappingCollectionTests.java 17 | 18 | 0.16 19 | * DaoImpl constructor supports keyspacename paramter instead dot-composed keyspace and tablename string 20 | 21 | 0.15 22 | * bugfix: Prepared statement can no longer be executed by other sessions than the session which prepared the statement. This could result in invalid prepared sessions 23 | 24 | 0.14 25 | * bugfix: removing invalid cached prepared statements: internal prepared statement cache will be invalidated, if a host goes up or an internal driver error occurs 26 | 27 | 0.12 28 | * reactive-streams dependency set to 1.0.0.RC5 -------------------------------------------------------------------------------- /troilus-core-java7/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | net.oneandone.troilus 7 | troilus-parent 8 | 0.19-SNAPSHOT 9 | 10 | troilus-core-java7 11 | jar 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | org.apache.maven.plugins 21 | maven-compiler-plugin 22 | 3.1 23 | 24 | 1.7 25 | 1.7 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/ConstraintException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | 20 | 21 | 22 | /** 23 | * Exception thrown when a constraint is violated 24 | */ 25 | public class ConstraintException extends RuntimeException { 26 | 27 | private static final long serialVersionUID = 4270476820995364200L; 28 | 29 | /** 30 | * @param message the message to report 31 | */ 32 | public ConstraintException(String message) { 33 | super(message); 34 | } 35 | } -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/Count.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | import com.datastax.driver.core.ExecutionInfo; 19 | 20 | import com.datastax.driver.core.ResultSet; 21 | import com.google.common.collect.ImmutableList; 22 | 23 | 24 | 25 | /** 26 | * The count result 27 | */ 28 | public abstract class Count implements Result { 29 | 30 | /** 31 | * @return the count value 32 | */ 33 | public abstract long getCount(); 34 | 35 | /** 36 | * @param rs the result set 37 | * @return the associated count result 38 | */ 39 | static Count newCountResult(ResultSet rs) { 40 | return new CountResultImpl(rs); 41 | } 42 | 43 | 44 | private static final class CountResultImpl extends Count { 45 | private final ResultSet rs; 46 | private final long count; 47 | 48 | 49 | private CountResultImpl(ResultSet rs) { 50 | this.rs = rs; 51 | this.count = rs.one().getLong("count"); 52 | } 53 | 54 | @Override 55 | public ExecutionInfo getExecutionInfo() { 56 | return rs.getExecutionInfo(); 57 | } 58 | 59 | @Override 60 | public ImmutableList getAllExecutionInfo() { 61 | return ImmutableList.copyOf(rs.getAllExecutionInfo()); 62 | } 63 | 64 | @Override 65 | public boolean wasApplied() { 66 | return rs.wasApplied(); 67 | } 68 | 69 | @Override 70 | public long getCount() { 71 | return count; 72 | } 73 | } 74 | } 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/CounterBatchMutationQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | 20 | import net.oneandone.troilus.java7.CounterMutation; 21 | 22 | import com.datastax.driver.core.BatchStatement.Type; 23 | import com.datastax.driver.core.Statement; 24 | import com.google.common.base.Function; 25 | import com.google.common.collect.ImmutableList; 26 | import com.google.common.util.concurrent.ListenableFuture; 27 | 28 | 29 | 30 | /** 31 | * Counter batch mutation query 32 | * 33 | */ 34 | class CounterBatchMutationQuery extends MutationQuery implements CounterMutation { 35 | private final ImmutableList batchables; 36 | 37 | /** 38 | * @param ctx the context to use 39 | * @param batchables the statements to be performed within the batch 40 | */ 41 | CounterBatchMutationQuery(Context ctx, ImmutableList batchables) { 42 | super(ctx); 43 | this.batchables = batchables; 44 | } 45 | 46 | 47 | //////////////////// 48 | // factory methods 49 | 50 | @Override 51 | protected CounterBatchMutationQuery newQuery(Context newContext) { 52 | return new CounterBatchMutationQuery(newContext, batchables); 53 | } 54 | 55 | private CounterBatchMutationQuery newQuery(ImmutableList batchables) { 56 | return new CounterBatchMutationQuery(getContext(), batchables); 57 | } 58 | 59 | // 60 | //////////////////// 61 | 62 | 63 | @Override 64 | public CounterBatchMutationQuery combinedWith(CounterMutation other) { 65 | return newQuery(Immutables.join(batchables, other)); 66 | } 67 | 68 | @Override 69 | public ListenableFuture getStatementAsync(final DBSession dbSession) { 70 | 71 | Function> statementFetcher = new Function>() { 72 | public ListenableFuture apply(CounterMutation batchable) { 73 | return batchable.getStatementAsync(dbSession); 74 | }; 75 | }; 76 | return mergeToBatch(Type.COUNTER, batchables.iterator(), statementFetcher); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/CounterMutationQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | import com.google.common.util.concurrent.MoreExecutors; 19 | import net.oneandone.troilus.java7.CounterMutation; 20 | 21 | import com.datastax.driver.core.ResultSet; 22 | import com.datastax.driver.core.Statement; 23 | import com.google.common.base.Function; 24 | import com.google.common.collect.ImmutableList; 25 | import com.google.common.util.concurrent.Futures; 26 | import com.google.common.util.concurrent.ListenableFuture; 27 | 28 | 29 | /** 30 | * Counter mutation query implementation 31 | * 32 | */ 33 | class CounterMutationQuery extends AbstractQuery implements CounterMutation { 34 | 35 | private final CounterMutationQueryData data; 36 | 37 | /** 38 | * @param ctx the context 39 | * @param data the query data 40 | */ 41 | CounterMutationQuery(Context ctx, CounterMutationQueryData data) { 42 | super(ctx); 43 | this.data = data; 44 | } 45 | 46 | @Override 47 | protected CounterMutationQuery newQuery(Context newContext) { 48 | return new CounterMutationQuery(newContext, data); 49 | } 50 | 51 | 52 | @Override 53 | public CounterBatchMutationQuery combinedWith(CounterMutation other) { 54 | return new CounterBatchMutationQuery(getContext(), ImmutableList.of(this, other)); 55 | } 56 | 57 | @Override 58 | public Result execute() { 59 | return ListenableFutures.getUninterruptibly(executeAsync()); 60 | } 61 | 62 | @Override 63 | public ListenableFuture executeAsync() { 64 | ListenableFuture future = performAsync(getDefaultDbSession(), getStatementAsync(getDefaultDbSession())); 65 | 66 | Function mapEntity = new Function() { 67 | @Override 68 | public Result apply(ResultSet resultSet) { 69 | return newResult(resultSet); 70 | } 71 | }; 72 | 73 | return Futures.transform(future, mapEntity, MoreExecutors.directExecutor()); 74 | } 75 | 76 | 77 | @Override 78 | public ListenableFuture getStatementAsync(DBSession dbSession) { 79 | return data.toStatementAsync(getExecutionSpec(), dbSession, data.getTablename()); 80 | } 81 | } 82 | 83 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/DataTypes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | import com.datastax.driver.core.DataType; 19 | 20 | 21 | 22 | 23 | 24 | 25 | class DataTypes { 26 | 27 | public static boolean isTextDataType(DataType dataType) { 28 | return dataType.equals(DataType.text()) || 29 | dataType.equals(DataType.ascii()) || 30 | dataType.equals(DataType.varchar()); 31 | } 32 | } -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/ExecutionSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | import com.datastax.driver.core.ConsistencyLevel; 20 | import com.datastax.driver.core.policies.RetryPolicy; 21 | 22 | 23 | 24 | 25 | public interface ExecutionSpec { 26 | 27 | ExecutionSpec withConsistency(ConsistencyLevel consistencyLevel); 28 | 29 | ExecutionSpec withSerialConsistency(ConsistencyLevel consistencyLevel); 30 | 31 | ExecutionSpec withTtl(int ttlSec); 32 | 33 | ExecutionSpec withWritetime(long microsSinceEpoch); 34 | 35 | ExecutionSpec withTracking(); 36 | 37 | ExecutionSpec withoutTracking(); 38 | 39 | ExecutionSpec withRetryPolicy(RetryPolicy policy); 40 | 41 | ConsistencyLevel getConsistencyLevel(); 42 | 43 | ConsistencyLevel getSerialConsistencyLevel(); 44 | 45 | Integer getTtl(); 46 | 47 | Long getWritetime(); 48 | 49 | Boolean getEnableTracing(); 50 | 51 | RetryPolicy getRetryPolicy(); 52 | } -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/Field.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 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 | /** 25 | * Annotation that allows to specify the name of the CQL field to which the Java field should be mapped. 26 | * 27 | */ 28 | @Target(ElementType.FIELD) 29 | @Retention(RetentionPolicy.RUNTIME) 30 | public @interface Field { 31 | 32 | /** 33 | * @return the CQL field 34 | */ 35 | String name(); 36 | } 37 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/IfConditionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | 20 | 21 | 22 | /** 23 | * Exception thrown when a if condition is violated 24 | */ 25 | public class IfConditionException extends RuntimeException { 26 | 27 | private static final long serialVersionUID = -4815247201091574807L; 28 | 29 | private transient final Result result; 30 | 31 | /** 32 | * @param message the message to report 33 | * @param result the result 34 | */ 35 | public IfConditionException(Result result, String message) { 36 | super(message); 37 | this.result = result; 38 | } 39 | 40 | /** 41 | * @return the result 42 | */ 43 | public Result getResult() { 44 | return result; 45 | } 46 | } -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/InsertQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | import net.oneandone.troilus.java7.Insertion; 19 | import net.oneandone.troilus.java7.Batchable; 20 | import net.oneandone.troilus.java7.interceptor.WriteQueryData; 21 | 22 | 23 | 24 | 25 | 26 | 27 | /** 28 | * insert query implementation 29 | */ 30 | class InsertQuery extends WriteQuery implements Insertion { 31 | 32 | 33 | /** 34 | * @param ctx the context 35 | * @param data the data 36 | */ 37 | InsertQuery(Context ctx, WriteQueryData data) { 38 | super(ctx, data); 39 | } 40 | 41 | 42 | //////////////////// 43 | // factory methods 44 | 45 | @Override 46 | protected InsertQuery newQuery(Context newContext) { 47 | return new InsertQuery(newContext, getData()); 48 | } 49 | 50 | private InsertQuery newQuery(WriteQueryData data) { 51 | return new InsertQuery(getContext(), data); 52 | } 53 | 54 | // 55 | //////////////////// 56 | 57 | 58 | @Override 59 | public BatchMutationQuery combinedWith(Batchable other) { 60 | return new BatchMutationQuery(getContext(), this, other); 61 | } 62 | 63 | @Override 64 | public InsertQuery withTtl(int ttlSec) { 65 | return newQuery(getContext().withTtl(ttlSec)); 66 | } 67 | 68 | @Override 69 | public InsertQuery ifNotExists() { 70 | return newQuery(getData().ifNotExists(true)); 71 | } 72 | } -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/PropertiesSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | import com.google.common.base.Optional; 19 | 20 | 21 | 22 | /** 23 | * Properties source 24 | */ 25 | interface PropertiesSource { 26 | 27 | /** 28 | * @param name the property name 29 | * @param clazz the property type 30 | * @return the property value 31 | */ 32 | Optional read(String name, Class clazz); 33 | 34 | /** 35 | * @param name the property source 36 | * @param clazz1 the property type of element 1 (e.g. key type of map) 37 | * @param clazz2 the property type of element 2 (e.g. value type of map) 38 | * @return the property value 39 | */ 40 | Optional read(String name, Class clazz1, Class clazz2); 41 | } -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/ProtocolErrorException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | 20 | /** 21 | * Exception thrown when a protocol-level error occurs 22 | * 23 | */ 24 | public class ProtocolErrorException extends RuntimeException { 25 | 26 | private static final long serialVersionUID = 4270476820995364200L; 27 | 28 | /** 29 | * @param message the message to report 30 | */ 31 | public ProtocolErrorException(String message) { 32 | super(message); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/Result.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | import com.datastax.driver.core.ExecutionInfo; 20 | import com.google.common.collect.ImmutableList; 21 | 22 | 23 | /** 24 | * The query result 25 | */ 26 | public interface Result { 27 | 28 | /** 29 | * @return the execution info for the last query made for this ResultSet 30 | */ 31 | ExecutionInfo getExecutionInfo(); 32 | 33 | /** 34 | * @return a list of the execution info for all the queries made for this ResultSet 35 | */ 36 | ImmutableList getAllExecutionInfo(); 37 | 38 | /** 39 | * @return if the query was a conditional update, whether it was applied. true for other types of queries. 40 | */ 41 | boolean wasApplied(); 42 | } 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/ResultAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | import com.datastax.driver.core.ExecutionInfo; 20 | import com.google.common.collect.ImmutableList; 21 | 22 | 23 | /** 24 | * query result adapter 25 | */ 26 | abstract class ResultAdapter implements Result { 27 | 28 | private final Result result; 29 | 30 | /** 31 | * @param result the underlying result 32 | */ 33 | ResultAdapter(Result result) { 34 | this.result = result; 35 | } 36 | 37 | @Override 38 | public ExecutionInfo getExecutionInfo() { 39 | return result.getExecutionInfo(); 40 | } 41 | 42 | @Override 43 | public ImmutableList getAllExecutionInfo() { 44 | return result.getAllExecutionInfo(); 45 | } 46 | 47 | @Override 48 | public boolean wasApplied() { 49 | return result.wasApplied(); 50 | } 51 | } 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/Tablename.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | import com.datastax.driver.core.Session; 19 | import com.google.common.base.Objects; 20 | 21 | 22 | 23 | /** 24 | * Tablename 25 | */ 26 | public class Tablename { 27 | 28 | private String keyspacename; 29 | private String tablename; 30 | 31 | 32 | /** 33 | * @param session the session 34 | * @param tablename the tablename 35 | * @return hte tablename object 36 | */ 37 | static Tablename newTablename(Session session, String tablename) { 38 | String keyspacename = session.getLoggedKeyspace(); 39 | 40 | if (keyspacename == null) { 41 | throw new IllegalStateException("no keyspace assigned"); 42 | } 43 | 44 | return newTablename(keyspacename, tablename); 45 | } 46 | 47 | 48 | /** 49 | * @param tablename the tablename 50 | * @param keyspacename the keyspacename 51 | * @return hte tablename object 52 | */ 53 | static Tablename newTablename(String keyspacename, String tablename) { 54 | return new Tablename(keyspacename, tablename); 55 | } 56 | 57 | private Tablename(String keyspacename, String tablename) { 58 | this.keyspacename = keyspacename; 59 | this.tablename = tablename; 60 | } 61 | 62 | 63 | /** 64 | * @return the keyspaceanme or null 65 | */ 66 | String getKeyspacename() { 67 | return keyspacename; 68 | } 69 | 70 | /** 71 | * @return the tablename 72 | */ 73 | public String getTablename() { 74 | return tablename; 75 | } 76 | 77 | @Override 78 | public boolean equals(Object other) { 79 | return (other instanceof Tablename) && 80 | Objects.equal(((Tablename) other).keyspacename, this.keyspacename) && 81 | Objects.equal(((Tablename) other).tablename, this.tablename); 82 | } 83 | 84 | @Override 85 | public int hashCode() { 86 | return toString().hashCode(); 87 | } 88 | 89 | @Override 90 | public String toString() { 91 | return (keyspacename == null) ? tablename : keyspacename + "." + tablename; 92 | } 93 | } -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/TooManyResultsException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | 20 | 21 | /** 22 | * Exception thrown when a more results (rows) are returned than expected 23 | */ 24 | public class TooManyResultsException extends RuntimeException { 25 | 26 | private static final long serialVersionUID = 4270476820995364200L; 27 | 28 | private transient final Result result; 29 | 30 | /** 31 | * @param message the message to report 32 | * @param result the result 33 | */ 34 | public TooManyResultsException(Result result, String message) { 35 | super(message); 36 | this.result = result; 37 | } 38 | 39 | /** 40 | * @return the result 41 | */ 42 | public Result getResult() { 43 | return result; 44 | } 45 | } -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/interceptor/DeleteQueryData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.interceptor; 17 | 18 | 19 | 20 | import java.util.List; 21 | 22 | import net.oneandone.troilus.Tablename; 23 | 24 | import com.datastax.driver.core.querybuilder.Clause; 25 | import com.google.common.collect.ImmutableList; 26 | import com.google.common.collect.ImmutableMap; 27 | 28 | 29 | 30 | 31 | 32 | /** 33 | * Delete query data 34 | */ 35 | public interface DeleteQueryData { 36 | 37 | /** 38 | * @return the tablename 39 | */ 40 | Tablename getTablename(); 41 | 42 | /** 43 | * @param key the key 44 | * @return the new delete query data 45 | */ 46 | DeleteQueryData key(ImmutableMap key); 47 | 48 | /** 49 | * returns map of values to remove from column family 50 | * @return 51 | */ 52 | ImmutableMap> getMapValuesToRemove(); 53 | 54 | /** 55 | * this method's purpose is to populate the list of map 56 | * values to remove 57 | * 58 | * @param removedMapValues 59 | * @return 60 | */ 61 | DeleteQueryData mapValuesToRemove(ImmutableMap> removedMapValues); 62 | /** 63 | * @param whereConditions the where conditions 64 | * @return the new delete query data 65 | */ 66 | DeleteQueryData whereConditions(ImmutableList whereConditions); 67 | 68 | /** 69 | * @param onlyIfConditions the onlyIf conditions 70 | * @return the new delete query data 71 | */ 72 | DeleteQueryData onlyIfConditions(ImmutableList onlyIfConditions); 73 | 74 | /** 75 | * @param IfExists the ifNotExits conditions 76 | * @return the new delete query data 77 | */ 78 | DeleteQueryData ifExists(Boolean IfExists); 79 | 80 | /** 81 | * @return the key 82 | */ 83 | ImmutableMap getKey(); 84 | 85 | /** 86 | * @return the where conditions 87 | */ 88 | ImmutableList getWhereConditions(); 89 | 90 | /** 91 | * @return the onlyIf conditions 92 | */ 93 | ImmutableList getOnlyIfConditions(); 94 | 95 | /** 96 | * @return the ifExists flag 97 | */ 98 | Boolean getIfExists(); 99 | } -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/interceptor/QueryInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.interceptor; 17 | 18 | 19 | 20 | 21 | /** 22 | * QueryInterceptor marker interface 23 | */ 24 | public interface QueryInterceptor { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/interceptor/SingleReadQueryData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.interceptor; 17 | 18 | import com.google.common.collect.ImmutableMap; 19 | 20 | 21 | 22 | 23 | /** 24 | * The reqd query data 25 | * 26 | */ 27 | public interface SingleReadQueryData { 28 | 29 | /** 30 | * @param key the key 31 | * @return the new read query data 32 | */ 33 | SingleReadQueryData key(ImmutableMap key); 34 | 35 | /** 36 | * @param columnsToFetchs the columns to fetch 37 | * @return the new read query data 38 | */ 39 | SingleReadQueryData columnsToFetch(ImmutableMap columnsToFetchs); 40 | 41 | /** 42 | * @return the key 43 | */ 44 | ImmutableMap getKey(); 45 | 46 | /** 47 | * @return the columns to fetch 48 | */ 49 | ImmutableMap getColumnsToFetch(); 50 | } -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/BatchMutation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | import net.oneandone.troilus.Result; 19 | 20 | 21 | /** 22 | * BatchMutation 23 | */ 24 | public interface BatchMutation extends Batchable { 25 | 26 | /** 27 | * @return a cloned query instance with write ahead log 28 | */ 29 | Mutation withWriteAheadLog(); 30 | 31 | /** 32 | * @return a cloned query instance without write ahead log 33 | */ 34 | Mutation withoutWriteAheadLog(); 35 | } -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/Batchable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | import net.oneandone.troilus.Result; 19 | 20 | 21 | 22 | /** 23 | * Batchable Mutation query 24 | * 25 | * @param the query type 26 | */ 27 | public interface Batchable> extends Mutation { 28 | 29 | 30 | /** 31 | * @param other the other query to combine with. If other is null, this query will be returned 32 | * @return a cloned query instance with the modified behavior 33 | */ 34 | BatchMutation combinedWith(Batchable other); 35 | } 36 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/BatchableWithTime.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | 19 | 20 | /** 21 | * Batchable mutation query (insert or update) 22 | * @param the query type 23 | */ 24 | public interface BatchableWithTime> extends Batchable { 25 | 26 | /** 27 | * @param ttlSec the time-to-live in sec to set 28 | * @return a cloned query instance with the modified behavior 29 | */ 30 | BatchableWithTime withTtl(int ttlSec); 31 | 32 | /** 33 | * @param microsSinceEpoch the writetime in since epoch to set 34 | * @return a cloned query instance with the modified behavior 35 | */ 36 | BatchableWithTime withWritetime(long microsSinceEpoch); 37 | } 38 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/CounterMutation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | import net.oneandone.troilus.Result; 19 | 20 | 21 | /** 22 | * counter mutation 23 | */ 24 | public interface CounterMutation extends Mutation { 25 | 26 | /** 27 | * @param ttlSec the time-to-live to set 28 | * @return a cloned query instance with the modified behavior 29 | */ 30 | CounterMutation withTtl(int ttlSec); 31 | 32 | /** 33 | * @param microsSinceEpoch the writetime in since epoch to set 34 | * @return a cloned query instance with the modified behavior 35 | */ 36 | CounterMutation withWritetime(long microsSinceEpoch); 37 | 38 | /** 39 | * @param other the other query to combine with 40 | * @return a cloned query instance with the modified behavior 41 | */ 42 | CounterMutation combinedWith(CounterMutation other); 43 | } 44 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/Deletion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | import java.util.Map; 19 | 20 | import net.oneandone.troilus.ColumnName; 21 | import net.oneandone.troilus.Result; 22 | 23 | import com.datastax.driver.core.querybuilder.Clause; 24 | 25 | 26 | /** 27 | * delete query 28 | */ 29 | public interface Deletion extends Batchable { 30 | 31 | /** 32 | * @param conditions the conditions 33 | * @return a cloned query instance with lwt (only-if) 34 | */ 35 | Mutation onlyIf(Clause... conditions); 36 | 37 | /** 38 | * @return a cloned query instance with lwt (if-exits) 39 | */ 40 | Mutation ifExists(); 41 | 42 | /** 43 | * this method will remove a provided map entry for a column 44 | * of type "map" in repository 45 | * 46 | * @param columnName 47 | * @param mapKey 48 | * @return 49 | */ 50 | Deletion removeMapValue(String columnName, Object mapKey); 51 | 52 | /** 53 | * this method allows the caller to provide a ColumnName object 54 | * and a mapKey to remove a map entry 55 | * 56 | */ 57 | Deletion removeMapValue(ColumnName> column, Object mapKey); 58 | } -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/FetchingIterable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | 19 | /** 20 | * Iterable which supports fetching methods 21 | * 22 | * @param the type 23 | */ 24 | public interface FetchingIterable extends Iterable { 25 | 26 | @Override 27 | public FetchingIterator iterator(); 28 | } 29 | 30 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/FetchingIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | import java.util.Iterator; 19 | 20 | import com.datastax.driver.core.ResultSet; 21 | import com.google.common.util.concurrent.ListenableFuture; 22 | 23 | 24 | 25 | /** 26 | * Iterator which supports fetching methods 27 | * 28 | * @param the element type 29 | */ 30 | public interface FetchingIterator extends Iterator { 31 | 32 | /** 33 | * @return The number of rows that can be retrieved from this result set without blocking to fetch. 34 | */ 35 | int getAvailableWithoutFetching(); 36 | 37 | /** 38 | * @return whether all results have been fetched. 39 | */ 40 | boolean isFullyFetched(); 41 | 42 | /** 43 | * @return a future on the completion of fetching the next page of results. 44 | * If the result set is already fully retrieved (isFullyFetched() == true), 45 | * then the returned future will return immediately but not particular error 46 | * will be thrown (you should thus call isFullyFetched() to know if calling this method can be of any use). 47 | */ 48 | ListenableFuture fetchMoreResultsAsync(); 49 | } 50 | 51 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/Insertion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | 19 | 20 | 21 | 22 | /** 23 | * Insertion query 24 | */ 25 | public interface Insertion extends BatchableWithTime { 26 | 27 | /** 28 | * @return a cloned query instance with lwt (if-not-exits) 29 | */ 30 | BatchableWithTime ifNotExists(); 31 | } -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/ListRead.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | import com.datastax.driver.core.PagingState; 19 | 20 | 21 | 22 | /** 23 | * List read query 24 | * 25 | * @param the result type 26 | */ 27 | public interface ListRead extends SingleRead { 28 | 29 | 30 | /** 31 | * @param limit the max num of records to read 32 | * @return a cloned query instance with deactivated tracking 33 | */ 34 | ListRead withLimit(int limit); 35 | 36 | /** 37 | * @param fetchSize the fetch size 38 | * @return a cloned query instance with deactivated tracking 39 | */ 40 | ListRead withFetchSize(int fetchSize); 41 | 42 | /** 43 | * @return a cloned query instance with distinct 44 | */ 45 | ListRead withDistinct(); 46 | 47 | /** 48 | * @return a cloned query instance which allows filtering 49 | */ 50 | ListRead withAllowFiltering(); 51 | 52 | /** 53 | * @return a cloned query instance which allows paging 54 | */ 55 | ListRead withPagingState(PagingState pagingState); 56 | } -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/ListReadWithColumns.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | import net.oneandone.troilus.ColumnName; 19 | 20 | 21 | /** 22 | * column-ware list read 23 | * 24 | * @param the result type 25 | */ 26 | public interface ListReadWithColumns extends ListRead { 27 | 28 | /** 29 | * @param name the column name to read 30 | * @return a cloned query instance with the modified behavior 31 | */ 32 | ListReadWithColumns column(String name); 33 | 34 | /** 35 | * @param name the column name incl. meta data to read 36 | * @return a cloned query instance with the modified behavior 37 | */ 38 | ListReadWithColumns columnWithMetadata(String name); 39 | 40 | /** 41 | * @param names the column names to read 42 | * @return a cloned query instance with the modified behavior 43 | */ 44 | ListReadWithColumns columns(String... names); 45 | 46 | /** 47 | * @param name the column name to read 48 | * @return a cloned query instance with the modified behavior 49 | */ 50 | ListReadWithColumns column(ColumnName name); 51 | 52 | /** 53 | * @param name the column name incl. meta data to read 54 | * @return a cloned query instance with the modified behavior 55 | */ 56 | ListReadWithColumns columnWithMetadata(ColumnName name); 57 | 58 | /** 59 | * @param names the column names to read 60 | * @return a cloned query instance with the modified behavior 61 | */ 62 | ListReadWithColumns columns(ColumnName... names); 63 | } -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/ListReadWithUnit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | import net.oneandone.troilus.Count; 19 | 20 | 21 | /** 22 | * list read query 23 | * 24 | * @param the result type 25 | */ 26 | public interface ListReadWithUnit extends ListReadWithColumns { 27 | 28 | /** 29 | * @return a cloned query instance which reads all columns 30 | */ 31 | ListRead all(); 32 | 33 | /** 34 | * @return a cloned query instance which returns the count 35 | */ 36 | ListRead count(); 37 | 38 | /** 39 | * @param objectClass the entity type 40 | * @param the entity type 41 | * @return a cloned query instance with the modified behavior 42 | */ 43 | ListRead, E> asEntity(Class objectClass); 44 | } -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/Mutation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | import net.oneandone.troilus.DBSession; 19 | 20 | import com.datastax.driver.core.ConsistencyLevel; 21 | import com.datastax.driver.core.Statement; 22 | import com.datastax.driver.core.policies.RetryPolicy; 23 | import com.google.common.util.concurrent.ListenableFuture; 24 | 25 | 26 | 27 | 28 | /** 29 | * Mutation query 30 | * 31 | * @param the response type 32 | * @param the query type 33 | */ 34 | public interface Mutation extends Query { 35 | 36 | /** 37 | * @param consistencyLevel the consistency level to use 38 | * @return a cloned query instance with the modified behavior 39 | */ 40 | Q withConsistency(ConsistencyLevel consistencyLevel); 41 | 42 | /** 43 | * @param consistencyLevel the consistency level to use 44 | * @return a cloned query instance with the modified behavior 45 | */ 46 | Q withSerialConsistency(ConsistencyLevel consistencyLevel); 47 | 48 | /** 49 | * @return a cloned query instance with activated tracking 50 | */ 51 | Q withTracking(); 52 | 53 | /** 54 | * @return a cloned query instance with deactivated tracking 55 | */ 56 | Q withoutTracking(); 57 | 58 | /** 59 | * @param policy the retry policy 60 | * @return a cloned query instance with the modified behavior 61 | */ 62 | Q withRetryPolicy(RetryPolicy policy); 63 | 64 | /** 65 | * @return the statement future 66 | */ 67 | ListenableFuture getStatementAsync(DBSession dbSession); 68 | } 69 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/Query.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | import com.google.common.util.concurrent.ListenableFuture; 19 | 20 | 21 | 22 | /** 23 | * The Query 24 | * @param the result type 25 | */ 26 | public interface Query { 27 | 28 | /** 29 | * performs the query in an async way 30 | * @return the result future 31 | */ 32 | ListenableFuture executeAsync(); 33 | 34 | /** 35 | * performs the query in a sync way 36 | * @return the result 37 | */ 38 | T execute(); 39 | } 40 | 41 | 42 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/ResultList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | 19 | import net.oneandone.troilus.Result; 20 | 21 | 22 | 23 | /** 24 | * The entity list 25 | * @param the element type 26 | */ 27 | public interface ResultList extends Result, FetchingIterable { 28 | 29 | 30 | } 31 | 32 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/SingleRead.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | 19 | import org.reactivestreams.Publisher; 20 | 21 | import com.datastax.driver.core.ConsistencyLevel; 22 | 23 | 24 | /** 25 | * Single read query 26 | * 27 | * @param the result type 28 | */ 29 | public interface SingleRead extends Query { 30 | 31 | /** 32 | * @return the publisher 33 | */ 34 | Publisher executeRx(); 35 | 36 | /** 37 | * @return a cloned Dao instance with activated tracking 38 | */ 39 | SingleRead withTracking(); 40 | 41 | /** 42 | * @return a cloned query instance with deactivated tracking 43 | */ 44 | SingleRead withoutTracking(); 45 | 46 | 47 | /** 48 | * @param consistencyLevel the consistency level to use 49 | * @return a cloned query instance with the modified behavior 50 | */ 51 | SingleRead withConsistency(ConsistencyLevel consistencyLevel); 52 | } 53 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/SingleReadWithColumns.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | 19 | import net.oneandone.troilus.ColumnName; 20 | 21 | 22 | 23 | /** 24 | * Single column-aware read query 25 | * 26 | * @param the result type 27 | */ 28 | public interface SingleReadWithColumns extends SingleRead { 29 | 30 | /** 31 | * @param name the column name to read 32 | * @return a cloned query instance with the modified behavior 33 | */ 34 | SingleReadWithColumns column(String name); 35 | 36 | /** 37 | * @param name the column name incl. meta data to read 38 | * @return a cloned query instance with the modified behavior 39 | */ 40 | SingleReadWithColumns columnWithMetadata(String name); 41 | 42 | /** 43 | * @param names the column names to read 44 | * @return a cloned query instance with the modified behavior 45 | */ 46 | SingleReadWithColumns columns(String... names); 47 | 48 | /** 49 | * @param name the column name to read 50 | * @return a cloned query instance with the modified behavior 51 | */ 52 | SingleReadWithColumns column(ColumnName name); 53 | 54 | /** 55 | * @param name the column name incl. meta data to read 56 | * @return a cloned query instance with the modified behavior 57 | */ 58 | SingleReadWithColumns columnWithMetadata(ColumnName name); 59 | 60 | /** 61 | * @param names the column names to read 62 | * @return a cloned query instance with the modified behavior 63 | */ 64 | SingleReadWithColumns columns(ColumnName... names); 65 | } 66 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/SingleReadWithUnit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | 19 | /** 20 | * Single read query 21 | * 22 | * @param the result type 23 | */ 24 | public interface SingleReadWithUnit extends SingleReadWithColumns { 25 | 26 | /** 27 | * @return a cloned query instance which reads all columns 28 | */ 29 | SingleRead all(); 30 | 31 | /** 32 | * @param objectClass the entity type 33 | * @param the entity type 34 | * @return a cloned query instance with the modified behavior 35 | */ 36 | SingleRead asEntity(Class objectClass); 37 | } 38 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/Update.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | import com.datastax.driver.core.querybuilder.Clause; 19 | 20 | 21 | /** 22 | * Update query 23 | * @param the query type 24 | */ 25 | public interface Update> extends BatchableWithTime { 26 | 27 | /** 28 | * @param conditions the conditions 29 | * @return a cloned query instance with lwt (only-if) 30 | */ 31 | BatchableWithTime onlyIf(Clause... conditions); 32 | } 33 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/UpdateWithUnitAndCounter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | 19 | 20 | /** 21 | * values and counter aware update query 22 | */ 23 | public interface UpdateWithUnitAndCounter extends UpdateWithUnit, WithCounter { 24 | 25 | } -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/WithCounter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | 19 | 20 | /** 21 | * Counter-aware write query 22 | */ 23 | public interface WithCounter { 24 | 25 | /** 26 | * @param name the name of the value to decrement 27 | * @return a cloned query instance with the modified behavior 28 | */ 29 | CounterMutation decr(String name); 30 | 31 | /** 32 | * @param name the name of the value to decrement 33 | * @param value the value 34 | * @return a cloned query instance with the modified behavior 35 | */ 36 | CounterMutation decr(String name, long value); 37 | 38 | /** 39 | * @param name the name of the value to increment 40 | * @return a cloned query instance with the modified behavior 41 | */ 42 | CounterMutation incr(String name); 43 | 44 | /** 45 | * @param name the name of the value to increment 46 | * @param value the value 47 | * @return a cloned query instance with the modified behavior 48 | */ 49 | CounterMutation incr(String name, long value); 50 | } -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/Write.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | 19 | 20 | 21 | /** 22 | * write query 23 | */ 24 | public interface Write extends UpdateWithUnit { 25 | 26 | /** 27 | * @return a cloned query instance with lwt (if-not-exits) 28 | */ 29 | BatchableWithTime ifNotExists(); 30 | } 31 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/WriteWithCounter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7; 17 | 18 | 19 | 20 | /** 21 | * write with counter 22 | */ 23 | public interface WriteWithCounter extends Write, WithCounter { 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/interceptor/CascadeOnDeleteInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7.interceptor; 17 | 18 | 19 | import com.google.common.collect.ImmutableSet; 20 | 21 | import com.google.common.util.concurrent.ListenableFuture; 22 | 23 | import net.oneandone.troilus.interceptor.DeleteQueryData; 24 | import net.oneandone.troilus.interceptor.QueryInterceptor; 25 | import net.oneandone.troilus.java7.Batchable; 26 | 27 | 28 | 29 | /** 30 | * Interceptor which adds cascading statements to the delete statement by using the cql batch command with write ahead. 31 | * Please consider that the interceptor will fail, if a non-batchable delete operation e.g. ifExist(...) 32 | * is performed 33 | */ 34 | public interface CascadeOnDeleteInterceptor extends QueryInterceptor { 35 | 36 | /** 37 | * @param queryData the delete query data 38 | * @return the additional, cascading statements to execute 39 | */ 40 | ListenableFuture>> onDeleteAsync(DeleteQueryData queryData); 41 | } 42 | 43 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/interceptor/CascadeOnWriteInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7.interceptor; 17 | 18 | 19 | import net.oneandone.troilus.interceptor.QueryInterceptor; 20 | import net.oneandone.troilus.java7.Batchable; 21 | 22 | import com.google.common.collect.ImmutableSet; 23 | import com.google.common.util.concurrent.ListenableFuture; 24 | 25 | 26 | 27 | /** 28 | * Interceptor which adds cascading statements to the write statement by using the cql batch command with write ahead. 29 | * Please consider that the interceptor will fail, if a non-batchable write operation e.g. ifNotExist(...), onlyIf(...) 30 | * is performed 31 | */ 32 | public interface CascadeOnWriteInterceptor extends QueryInterceptor { 33 | 34 | /** 35 | * @param queryData the write query data 36 | * @return the additional, cascading statements to execute 37 | */ 38 | ListenableFuture>> onWriteAsync(WriteQueryData queryData); 39 | } 40 | 41 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/interceptor/DeleteQueryRequestInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7.interceptor; 17 | 18 | import com.google.common.util.concurrent.ListenableFuture; 19 | 20 | import net.oneandone.troilus.interceptor.DeleteQueryData; 21 | import net.oneandone.troilus.interceptor.QueryInterceptor; 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | /** 34 | * Interceptor which will be executed before performing a delete query 35 | */ 36 | public interface DeleteQueryRequestInterceptor extends QueryInterceptor { 37 | 38 | /** 39 | * @param queryData the request data 40 | * @return the (modified) request data 41 | */ 42 | ListenableFuture onDeleteRequestAsync(DeleteQueryData queryData); 43 | } 44 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/interceptor/ReadQueryRequestInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7.interceptor; 17 | 18 | 19 | 20 | import com.google.common.util.concurrent.ListenableFuture; 21 | 22 | import net.oneandone.troilus.interceptor.QueryInterceptor; 23 | 24 | 25 | 26 | 27 | 28 | /** 29 | * Interceptor which will be executed before performing a list read query 30 | */ 31 | public interface ReadQueryRequestInterceptor extends QueryInterceptor { 32 | 33 | /** 34 | * @param queryData the request data 35 | * @return the (modified) request data 36 | */ 37 | ListenableFuture onReadRequestAsync(ReadQueryData queryData); 38 | } 39 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/interceptor/ReadQueryResponseInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7.interceptor; 17 | 18 | 19 | import com.google.common.util.concurrent.ListenableFuture; 20 | 21 | import net.oneandone.troilus.interceptor.QueryInterceptor; 22 | import net.oneandone.troilus.java7.Record; 23 | import net.oneandone.troilus.java7.ResultList; 24 | 25 | 26 | 27 | 28 | 29 | /** 30 | * Interceptor which will be executed after performing a list read query 31 | */ 32 | public interface ReadQueryResponseInterceptor extends QueryInterceptor { 33 | 34 | /** 35 | * @param queryData the request data 36 | * @param recordList the requested record list 37 | * @return the (modified) requested record list 38 | */ 39 | ListenableFuture> onReadResponseAsync(ReadQueryData queryData, ResultList recordList); 40 | } 41 | -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/interceptor/ResultListAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7.interceptor; 17 | 18 | import net.oneandone.troilus.java7.FetchingIterator; 19 | import net.oneandone.troilus.java7.ResultList; 20 | 21 | import com.datastax.driver.core.ExecutionInfo; 22 | import com.google.common.collect.ImmutableList; 23 | 24 | 25 | 26 | public class ResultListAdapter implements ResultList { 27 | private final ResultList recordList; 28 | 29 | public ResultListAdapter(ResultList recordList) { 30 | this.recordList = recordList; 31 | } 32 | 33 | @Override 34 | public ExecutionInfo getExecutionInfo() { 35 | return recordList.getExecutionInfo(); 36 | } 37 | 38 | @Override 39 | public ImmutableList getAllExecutionInfo() { 40 | return recordList.getAllExecutionInfo(); 41 | } 42 | 43 | @Override 44 | public boolean wasApplied() { 45 | return recordList.wasApplied(); 46 | } 47 | 48 | @Override 49 | public FetchingIterator iterator() { 50 | return recordList.iterator(); 51 | } 52 | } -------------------------------------------------------------------------------- /troilus-core-java7/src/main/java/net/oneandone/troilus/java7/interceptor/WriteQueryRequestInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.java7.interceptor; 17 | 18 | import com.google.common.util.concurrent.ListenableFuture; 19 | 20 | import net.oneandone.troilus.interceptor.QueryInterceptor; 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | /** 31 | * Interceptor which will be executed before performing a write (update, insert) query 32 | */ 33 | public interface WriteQueryRequestInterceptor extends QueryInterceptor { 34 | 35 | /** 36 | * @param data the request data 37 | * @return the (modified) request data 38 | */ 39 | ListenableFuture onWriteRequestAsync(WriteQueryData data); 40 | } 41 | -------------------------------------------------------------------------------- /troilus-core/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | /target 14 | /.classpath 15 | /.settings 16 | /.project 17 | -------------------------------------------------------------------------------- /troilus-core/.toDelete: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1and1/Troilus/25433d0032bd5008e662b2b6eab34e55cdf00aeb/troilus-core/.toDelete -------------------------------------------------------------------------------- /troilus-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | net.oneandone.troilus 7 | troilus-parent 8 | 0.19-SNAPSHOT 9 | 10 | troilus-core 11 | jar 12 | 13 | 14 | 15 | net.oneandone.troilus 16 | troilus-core-java7 17 | 0.19-SNAPSHOT 18 | 19 | 20 | 21 | 22 | org.eclipse.persistence 23 | javax.persistence 24 | 2.1.0 25 | test 26 | 27 | 28 | 29 | junit 30 | junit 31 | 4.12 32 | test 33 | 34 | 35 | 36 | org.mockito 37 | mockito-core 38 | 2.0.3-beta 39 | test 40 | 41 | 42 | 43 | org.reactivestreams 44 | reactive-streams-tck 45 | ${reactivestreams.version} 46 | test 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | org.apache.maven.plugins 55 | maven-compiler-plugin 56 | 3.1 57 | 58 | 1.8 59 | 1.8 60 | 61 | 62 | 63 | 64 | 65 | 66 | maven-surefire-plugin 67 | 68 | 69 | org.apache.maven.surefire 70 | surefire-junit47 71 | ${surefire.version} 72 | 73 | 74 | org.apache.maven.surefire 75 | surefire-testng 76 | ${surefire.version} 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/AbstractQueryAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | 20 | 21 | import java.time.Duration; 22 | 23 | import java.util.concurrent.CompletableFuture; 24 | 25 | 26 | import com.datastax.driver.core.Statement; 27 | 28 | import net.oneandone.troilus.AbstractQuery; 29 | import net.oneandone.troilus.Context; 30 | import net.oneandone.troilus.Result; 31 | 32 | 33 | 34 | abstract class AbstractQueryAdapter extends AbstractQuery { 35 | 36 | private final net.oneandone.troilus.java7.Mutation query; 37 | 38 | 39 | public AbstractQueryAdapter(Context ctx, net.oneandone.troilus.java7.Mutation query) { 40 | super(ctx); 41 | this.query = query; 42 | } 43 | 44 | public Q withTtl(Duration ttl) { 45 | return super.withTtl((int) ttl.getSeconds()); 46 | } 47 | 48 | public Result execute() { 49 | return CompletableFutures.getUninterruptibly(executeAsync()); 50 | } 51 | 52 | public CompletableFuture executeAsync() { 53 | return CompletableFutures.toCompletableFuture(query.executeAsync()); 54 | } 55 | 56 | public CompletableFuture getStatementAsync(DBSession dbSession) { 57 | return CompletableFutures.toCompletableFuture(query.getStatementAsync(dbSession)); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/BatchMutation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | 20 | 21 | 22 | /** 23 | * BatchMutation 24 | */ 25 | public interface BatchMutation extends Batchable { 26 | 27 | /** 28 | * @return a cloned query instance with write ahead log 29 | */ 30 | Mutation withWriteAheadLog(); 31 | 32 | /** 33 | * @return a cloned query instance without write ahead log 34 | */ 35 | Mutation withoutWriteAheadLog(); 36 | } 37 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/BatchMutationQueryAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | 20 | import net.oneandone.troilus.BatchMutationQuery; 21 | import net.oneandone.troilus.Context; 22 | 23 | 24 | 25 | /** 26 | * Java8 adapter of a BatchMutationQuery 27 | */ 28 | class BatchMutationQueryAdapter extends AbstractQueryAdapter implements BatchMutation { 29 | 30 | private final BatchMutationQuery query; 31 | 32 | 33 | /** 34 | * @param ctx the context 35 | * @param query the underyling query 36 | */ 37 | BatchMutationQueryAdapter(Context ctx, BatchMutationQuery query) { 38 | super(ctx, query); 39 | this.query = query; 40 | } 41 | 42 | 43 | //////////////////// 44 | // factory methods 45 | 46 | @Override 47 | protected BatchMutationQueryAdapter newQuery(Context newContext) { 48 | return new BatchMutationQueryAdapter(newContext, query.newQuery(newContext)); 49 | } 50 | 51 | private BatchMutationQueryAdapter newQuery(BatchMutationQuery query) { 52 | return new BatchMutationQueryAdapter(getContext(), query.newQuery(getContext())); 53 | } 54 | 55 | // 56 | //////////////////// 57 | 58 | 59 | @Override 60 | public BatchMutation withWriteAheadLog() { 61 | return newQuery(query.withWriteAheadLog()); 62 | } 63 | 64 | @Override 65 | public BatchMutation withoutWriteAheadLog() { 66 | return newQuery(query.withoutWriteAheadLog()); 67 | } 68 | 69 | public BatchMutation combinedWith(Batchable other) { 70 | return newQuery(query.combinedWith(Mutations.toJava7Mutation(other))); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/Batchable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | 20 | 21 | /** 22 | * Batchable Mutation query 23 | * 24 | * @param the query type 25 | */ 26 | public interface Batchable> extends Mutation { 27 | 28 | /** 29 | * @param other the other query to combine with 30 | * @return a cloned query instance with the modified behavior 31 | */ 32 | BatchMutation combinedWith(Batchable other); 33 | } -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/BatchableWithTime.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | import java.time.Duration; 19 | 20 | 21 | 22 | 23 | /** 24 | * Btachable mutation query (insert or update) 25 | * 26 | * @param the query type 27 | */ 28 | public interface BatchableWithTime> extends Batchable { 29 | 30 | /** 31 | * @param ttl the time-to-live set 32 | * @return a cloned query instance with the modified behavior 33 | */ 34 | BatchableWithTime withTtl(Duration ttl); 35 | 36 | /** 37 | * @param microsSinceEpoch the writetime in since epoch to set 38 | * @return a cloned query instance with the modified behavior 39 | */ 40 | BatchableWithTime withWritetime(long microsSinceEpoch); 41 | } -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/CounterBatchMutationQueryAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | import net.oneandone.troilus.Context; 20 | import net.oneandone.troilus.CounterBatchMutationQuery; 21 | 22 | 23 | 24 | 25 | /** 26 | * Java8 adapter of a CounterBatchMutationQuery 27 | */ 28 | class CounterBatchMutationQueryAdapter extends AbstractQueryAdapter implements CounterMutation { 29 | 30 | private final CounterBatchMutationQuery query; 31 | 32 | 33 | /** 34 | * @param ctx the context 35 | * @param query the underlying query 36 | */ 37 | CounterBatchMutationQueryAdapter(Context ctx, CounterBatchMutationQuery query) { 38 | super(ctx, query); 39 | this.query = query; 40 | } 41 | 42 | 43 | //////////////////// 44 | // factory methods 45 | 46 | @Override 47 | protected CounterMutation newQuery(Context newContext) { 48 | return new CounterBatchMutationQueryAdapter(newContext, query.newQuery(newContext)); 49 | } 50 | 51 | private CounterMutation newQuery(CounterBatchMutationQuery query) { 52 | return new CounterBatchMutationQueryAdapter(getContext(), query.newQuery(getContext())); 53 | } 54 | 55 | // 56 | //////////////////// 57 | 58 | 59 | @Override 60 | public CounterMutation combinedWith(CounterMutation other) { 61 | return newQuery(query.combinedWith(CounterMutationQueryAdapter.toJava7CounterMutation(other))); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/CounterMutation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | import java.time.Duration; 19 | 20 | 21 | 22 | /** 23 | * counter mutation 24 | */ 25 | public interface CounterMutation extends Mutation { 26 | 27 | /** 28 | * @param ttl the time-to-live set 29 | * @return a cloned query instance with the modified behavior 30 | */ 31 | CounterMutation withTtl(Duration ttl); 32 | 33 | /** 34 | * @param microsSinceEpoch the writetime in since epoch to set 35 | * @return a cloned query instance with the modified behavior 36 | */ 37 | CounterMutation withWritetime(long microsSinceEpoch); 38 | 39 | /** 40 | * @param other the other query to combine with 41 | * @return a cloned query instance with the modified behavior 42 | */ 43 | CounterMutation combinedWith(CounterMutation other); 44 | } 45 | 46 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/DeleteQueryAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | 20 | 21 | import java.util.Map; 22 | 23 | import com.datastax.driver.core.querybuilder.Clause; 24 | 25 | 26 | 27 | 28 | 29 | /** 30 | * Java8 adapter of a DeleteQuery 31 | */ 32 | class DeleteQueryAdapter extends AbstractQueryAdapter implements Deletion { 33 | 34 | private final DeleteQuery query; 35 | 36 | 37 | /** 38 | * @param ctx the context 39 | * @param query the query 40 | */ 41 | DeleteQueryAdapter(Context ctx, DeleteQuery query) { 42 | super(ctx, query); 43 | this.query = query; 44 | } 45 | 46 | 47 | //////////////////// 48 | // factory methods 49 | 50 | @Override 51 | protected Deletion newQuery(Context newContext) { 52 | return new DeleteQueryAdapter(newContext, query.newQuery(newContext)); 53 | } 54 | 55 | private Deletion newQuery(DeleteQuery query) { 56 | return new DeleteQueryAdapter(getContext(), query.newQuery(getContext())); 57 | } 58 | 59 | // 60 | //////////////////// 61 | 62 | 63 | @Override 64 | public BatchMutation combinedWith(Batchable other) { 65 | return new BatchMutationQueryAdapter(getContext(), query.combinedWith(Mutations.toJava7Mutation(other))); 66 | } 67 | 68 | @Override 69 | public Deletion onlyIf(Clause... onlyIfConditions) { 70 | return newQuery(query.onlyIf(onlyIfConditions)); 71 | } 72 | 73 | @Override 74 | public Deletion ifExists() { 75 | return newQuery(query.ifExists()); 76 | } 77 | 78 | @Override 79 | public Deletion removeMapValue(String columnName, Object mapKey) { 80 | return newQuery(query.removeMapValue(columnName, mapKey)); 81 | } 82 | 83 | 84 | @Override 85 | public Deletion removeMapValue(ColumnName> column, 86 | Object mapKey) { 87 | return removeMapValue(column.getName(), mapKey); 88 | } 89 | } -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/Deletion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | import java.util.Map; 20 | 21 | import com.datastax.driver.core.querybuilder.Clause; 22 | 23 | 24 | 25 | /** 26 | * delete query 27 | */ 28 | public interface Deletion extends Batchable { 29 | 30 | /** 31 | * @param conditions the conditions 32 | * @return a cloned query instance with lwt (only-if) 33 | */ 34 | Mutation onlyIf(Clause... conditions); 35 | 36 | /** 37 | * @return a cloned query instance with lwt (if-exits) 38 | */ 39 | Mutation ifExists(); 40 | 41 | /** 42 | * this method will remove a provided map entry for a column 43 | * of type "map" in repository 44 | * 45 | * @param columnName 46 | * @param mapKey 47 | * @return 48 | */ 49 | Deletion removeMapValue(String columnName, Object mapKey); 50 | 51 | /** 52 | * this method allows the caller to provide a ColumnName object 53 | * and a mapKey to remove a map entry 54 | * 55 | */ 56 | Deletion removeMapValue(ColumnName> column, Object mapKey); 57 | } -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/FetchingIterable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | /** 20 | * Iterable which supports fetching methods 21 | * 22 | * @param the type 23 | */ 24 | public interface FetchingIterable extends Iterable { 25 | 26 | @Override 27 | public FetchingIterator iterator(); 28 | } 29 | 30 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/FetchingIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | import java.util.Iterator; 19 | import java.util.concurrent.CompletableFuture; 20 | 21 | import com.datastax.driver.core.ResultSet; 22 | 23 | 24 | 25 | /** 26 | * Iterator which supports fetching methods 27 | * 28 | * @param the element type 29 | */ 30 | public interface FetchingIterator extends Iterator { 31 | 32 | /** 33 | * @return The number of rows that can be retrieved from this result set without blocking to fetch. 34 | */ 35 | int getAvailableWithoutFetching(); 36 | 37 | 38 | /** 39 | * @return whether all results have been fetched. 40 | */ 41 | boolean isFullyFetched(); 42 | 43 | /** 44 | * @return a future on the completion of fetching the next page of results. 45 | * If the result set is already fully retrieved (isFullyFetched() == true), 46 | * then the returned future will return immediately but not particular error 47 | * will be thrown (you should thus call isFullyFetched() to know if calling this method can be of any use). 48 | */ 49 | CompletableFuture fetchMoreResultsAsync(); 50 | } 51 | 52 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/InsertQueryAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | import java.time.Duration; 20 | 21 | import net.oneandone.troilus.Context; 22 | import net.oneandone.troilus.InsertQuery; 23 | 24 | 25 | 26 | /** 27 | * Java8 adapter of a InsertQuery 28 | */ 29 | class InsertQueryAdapter extends AbstractQueryAdapter implements Insertion { 30 | 31 | private final InsertQuery query; 32 | 33 | /** 34 | * @param ctx the context 35 | * @param query the query 36 | */ 37 | InsertQueryAdapter(Context ctx, InsertQuery query) { 38 | super(ctx, query); 39 | this.query = query; 40 | } 41 | 42 | 43 | //////////////////// 44 | // factory methods 45 | 46 | @Override 47 | protected InsertQueryAdapter newQuery(Context newContext) { 48 | return new InsertQueryAdapter(newContext, query.newQuery(newContext)); 49 | } 50 | 51 | private InsertQueryAdapter newQuery(InsertQuery query) { 52 | return new InsertQueryAdapter(getContext(), query.newQuery(getContext())); 53 | } 54 | 55 | // 56 | //////////////////// 57 | 58 | 59 | @Override 60 | public BatchMutation combinedWith(Batchable other) { 61 | return new BatchMutationQueryAdapter(getContext(), query.combinedWith(Mutations.toJava7Mutation(other))); 62 | } 63 | 64 | @Override 65 | public InsertQueryAdapter withTtl(Duration ttl) { 66 | return newQuery(getContext().withTtl((int) ttl.getSeconds())); 67 | } 68 | 69 | @Override 70 | public BatchableWithTime ifNotExists() { 71 | return newQuery(query.ifNotExists()); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/Insertion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | 20 | 21 | /** 22 | * insertion query 23 | */ 24 | public interface Insertion extends BatchableWithTime { 25 | 26 | /** 27 | * @return a cloned query instance with lwt (if-not-exits) 28 | */ 29 | BatchableWithTime ifNotExists(); 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/ListRead.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | import com.datastax.driver.core.PagingState; 19 | 20 | 21 | 22 | 23 | /** 24 | * List read query 25 | * 26 | * @param the result type 27 | */ 28 | public interface ListRead extends SingleRead { 29 | 30 | 31 | /** 32 | * @param limit the max number of records to read 33 | * @return a cloned query instance with deactivated tracking 34 | */ 35 | ListRead withLimit(int limit); 36 | 37 | /** 38 | * @param fetchSize the fetch size 39 | * @return a cloned query instance with deactivated tracking 40 | */ 41 | ListRead withFetchSize(int fetchSize); 42 | 43 | /** 44 | * @return a cloned query instance with distinct 45 | */ 46 | ListRead withDistinct(); 47 | 48 | /** 49 | * @return a cloned query instance which allows filtering 50 | */ 51 | ListRead withAllowFiltering(); 52 | 53 | /** 54 | * 55 | * @param pagingState paging state to set on driver Statement, or null, if none 56 | * @return a cloned query instance with paging state set 57 | */ 58 | ListRead withPagingState(PagingState pagingState); 59 | } -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/ListReadWithColumns.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | /** 20 | * column-ware list read 21 | * 22 | * @param the result type 23 | */ 24 | public interface ListReadWithColumns extends ListRead { 25 | 26 | /** 27 | * @param name the column name to read 28 | * @return a cloned query instance with the modified behavior 29 | */ 30 | ListReadWithColumns column(String name); 31 | 32 | /** 33 | * @param name the column name incl. meta data to read 34 | * @return a cloned query instance with the modified behavior 35 | */ 36 | ListReadWithColumns columnWithMetadata(String name); 37 | 38 | /** 39 | * @param names the column names to read 40 | * @return a cloned query instance with the modified behavior 41 | */ 42 | ListReadWithColumns columns(String... names); 43 | 44 | /** 45 | * @param name the column name to read 46 | * @return a cloned query instance with the modified behavior 47 | */ 48 | ListReadWithColumns column(ColumnName name); 49 | 50 | /** 51 | * @param name the column name incl. meta data to read 52 | * @return a cloned query instance with the modified behavior 53 | */ 54 | ListReadWithColumns columnWithMetadata(ColumnName name); 55 | 56 | /** 57 | * @param names the column names to read 58 | * @return a cloned query instance with the modified behavior 59 | */ 60 | ListReadWithColumns columns(ColumnName... names); 61 | } -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/ListReadWithUnit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | 20 | 21 | /** 22 | * list read query 23 | * 24 | * @param the result type 25 | */ 26 | public interface ListReadWithUnit extends ListReadWithColumns { 27 | 28 | /** 29 | * @return a cloned query instance which reads all columns 30 | */ 31 | ListRead all(); 32 | 33 | /** 34 | * @return a cloned query instance which returns the count 35 | */ 36 | ListRead count(); 37 | 38 | /** 39 | * @param objectClass the entity type 40 | * @param the type 41 | * @return a cloned query instance with the modified behavior 42 | */ 43 | ListRead, E> asEntity(Class objectClass); 44 | } -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/Mutation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | import java.util.concurrent.CompletableFuture; 19 | 20 | 21 | import com.datastax.driver.core.ConsistencyLevel; 22 | import com.datastax.driver.core.Statement; 23 | import com.datastax.driver.core.policies.RetryPolicy; 24 | 25 | 26 | /** 27 | * Mutation query 28 | * 29 | * @param the response type 30 | * @param the query type 31 | */ 32 | public interface Mutation extends Query { 33 | 34 | /** 35 | * @param consistencyLevel the consistency level to use 36 | * @return a cloned query instance with the modified behavior 37 | */ 38 | Q withConsistency(ConsistencyLevel consistencyLevel); 39 | 40 | /** 41 | * @param consistencyLevel the consistency level to use 42 | * @return a cloned query instance with the modified behavior 43 | */ 44 | Q withSerialConsistency(ConsistencyLevel consistencyLevel); 45 | 46 | 47 | /** 48 | * @return a cloned query instance with activated tracking 49 | */ 50 | Q withTracking(); 51 | 52 | /** 53 | * @return a cloned query instance with deactivated tracking 54 | */ 55 | Q withoutTracking(); 56 | 57 | /** 58 | * @param policy the retry policy 59 | * @return a cloned query instance with the modified behavior 60 | */ 61 | Q withRetryPolicy(RetryPolicy policy); 62 | 63 | /** 64 | * @return the statement future 65 | */ 66 | CompletableFuture getStatementAsync(DBSession dbSession); 67 | } 68 | 69 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/Query.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | import java.util.concurrent.CompletableFuture; 19 | 20 | 21 | 22 | /** 23 | * The Query 24 | * @param the result type 25 | */ 26 | public interface Query { 27 | 28 | /** 29 | * performs the query in an async way 30 | * @return the result future 31 | */ 32 | CompletableFuture executeAsync(); 33 | 34 | /** 35 | * performs the query in a sync way 36 | * @return the result 37 | */ 38 | T execute(); 39 | } 40 | 41 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/RecordMappingPublisher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | import org.reactivestreams.Publisher; 19 | import org.reactivestreams.Subscriber; 20 | import org.reactivestreams.Subscription; 21 | 22 | 23 | 24 | /** 25 | * RecordMappingPublisher 26 | */ 27 | class RecordMappingPublisher implements Publisher { 28 | private final Publisher publisher; 29 | 30 | /** 31 | * @param publisher the publisher to map 32 | */ 33 | public RecordMappingPublisher(Publisher publisher) { 34 | this.publisher = publisher; 35 | } 36 | 37 | 38 | @Override 39 | public void subscribe(Subscriber subcriber) { 40 | publisher.subscribe(new RecordMappingSubscriber(subcriber)); 41 | } 42 | 43 | 44 | private static class RecordMappingSubscriber implements Subscriber { 45 | 46 | private final Subscriber subcriber; 47 | 48 | public RecordMappingSubscriber(Subscriber subcriber) { 49 | this.subcriber = subcriber; 50 | } 51 | 52 | @Override 53 | public void onSubscribe(Subscription subscription) { 54 | subcriber.onSubscribe(subscription); 55 | } 56 | 57 | @Override 58 | public void onComplete() { 59 | subcriber.onComplete(); 60 | } 61 | 62 | @Override 63 | public void onError(Throwable t) { 64 | subcriber.onError(t); 65 | } 66 | 67 | @Override 68 | public void onNext(net.oneandone.troilus.java7.Record record) { 69 | subcriber.onNext(RecordAdapter.convertFromJava7(record)); 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/ResultList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | import net.oneandone.troilus.Result; 20 | 21 | 22 | 23 | /** 24 | * The entity list 25 | * @param the element type 26 | */ 27 | public interface ResultList extends Result, FetchingIterable { 28 | 29 | 30 | } 31 | 32 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/SingleRead.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | import org.reactivestreams.Publisher; 20 | 21 | import com.datastax.driver.core.ConsistencyLevel; 22 | 23 | 24 | 25 | 26 | /** 27 | * Single read query 28 | * 29 | * @param the result type 30 | */ 31 | public interface SingleRead extends Query { 32 | 33 | /** 34 | * @return the publisher 35 | */ 36 | Publisher executeRx(); 37 | 38 | /** 39 | * @return a cloned query instance with deactivated tracking 40 | */ 41 | SingleRead withTracking(); 42 | 43 | /** 44 | * @return a cloned query instance with deactivated tracking 45 | */ 46 | SingleRead withoutTracking(); 47 | 48 | /** 49 | * @param consistencyLevel the consistency level to use 50 | * @return a cloned query instance with the modified behavior 51 | */ 52 | SingleRead withConsistency(ConsistencyLevel consistencyLevel); 53 | } -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/SingleReadWithColumns.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | 20 | 21 | /** 22 | * Single column-aware read query 23 | * 24 | * @param the result type 25 | */ 26 | public interface SingleReadWithColumns extends SingleRead { 27 | /** 28 | * @param name the column name to read 29 | * @return a cloned query instance with the modified behavior 30 | */ 31 | SingleReadWithColumns column(String name); 32 | 33 | /** 34 | * @param name the column name incl. meta data to read 35 | * @return a cloned query instance with the modified behavior 36 | */ 37 | SingleReadWithColumns columnWithMetadata(String name); 38 | 39 | /** 40 | * @param names the column names to read 41 | * @return a cloned query instance with the modified behavior 42 | */ 43 | SingleReadWithColumns columns(String... names); 44 | 45 | /** 46 | * @param name the column name to read 47 | * @return a cloned query instance with the modified behavior 48 | */ 49 | SingleReadWithColumns column(ColumnName name); 50 | 51 | /** 52 | * @param name the column name incl. meta data to read 53 | * @return a cloned query instance with the modified behavior 54 | */ 55 | SingleReadWithColumns columnWithMetadata(ColumnName name); 56 | 57 | /** 58 | * @param names the column names to read 59 | * @return a cloned query instance with the modified behavior 60 | */ 61 | SingleReadWithColumns columns(ColumnName... names); 62 | } 63 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/SingleReadWithUnit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | import java.util.Optional; 19 | 20 | 21 | 22 | 23 | /** 24 | * Single read query 25 | * 26 | * @param the result type 27 | */ 28 | public interface SingleReadWithUnit extends SingleReadWithColumns { 29 | 30 | /** 31 | * @return a cloned query instance which reads all columns 32 | */ 33 | SingleRead all(); 34 | 35 | /** 36 | * @param objectClass the entity type 37 | * @param the type 38 | * @return a cloned query instance with the modified behavior 39 | */ 40 | SingleRead, E> asEntity(Class objectClass); 41 | } 42 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/Update.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | import com.datastax.driver.core.querybuilder.Clause; 20 | 21 | 22 | 23 | 24 | 25 | /** 26 | * update query 27 | * @param the query type 28 | */ 29 | public interface Update> extends BatchableWithTime { 30 | 31 | /** 32 | * @param conditions the conditions 33 | * @return a cloned query instance with lwt (only-if) 34 | */ 35 | BatchableWithTime onlyIf(Clause... conditions); 36 | } 37 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/UpdateWithUnitAndCounter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | /** 20 | * values and counter aware update query 21 | */ 22 | public interface UpdateWithUnitAndCounter extends UpdateWithUnit, WithCounter { 23 | 24 | } -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/WithCounter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | 20 | 21 | /** 22 | * Counter-aware write query 23 | */ 24 | public interface WithCounter { 25 | 26 | /** 27 | * @param name the name of the value to decrement 28 | * @return a cloned query instance with the modified behavior 29 | */ 30 | CounterMutation decr(String name); 31 | 32 | /** 33 | * @param name the name of the value to decrement 34 | * @param value the value 35 | * @return a cloned query instance with the modified behavior 36 | */ 37 | CounterMutation decr(String name, long value); 38 | 39 | /** 40 | * @param name the name of the value to increment 41 | * @return a cloned query instance with the modified behavior 42 | */ 43 | CounterMutation incr(String name); 44 | 45 | /** 46 | * @param name the name of the value to increment 47 | * @param value the value 48 | * @return a cloned query instance with the modified behavior 49 | */ 50 | CounterMutation incr(String name, long value); 51 | } 52 | 53 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/Write.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | 20 | 21 | /** 22 | * write query 23 | */ 24 | public interface Write extends UpdateWithUnit { 25 | 26 | /** 27 | * @return a cloned query instance with lwt (if-not-exits) 28 | */ 29 | BatchableWithTime ifNotExists(); 30 | } 31 | 32 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/WriteWithCounter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | 20 | /** 21 | * write with counter 22 | */ 23 | public interface WriteWithCounter extends Write, WithCounter { 24 | 25 | } -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/interceptor/CascadeOnDeleteInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.interceptor; 17 | 18 | import java.util.concurrent.CompletableFuture; 19 | 20 | 21 | 22 | 23 | 24 | 25 | import com.google.common.collect.ImmutableSet; 26 | 27 | import net.oneandone.troilus.Batchable; 28 | import net.oneandone.troilus.interceptor.DeleteQueryData; 29 | 30 | 31 | 32 | /** 33 | * Interceptor which adds cascading statements to the delete statement by using the cql batch command with write ahead. 34 | * Please consider that the interceptor will fail, if a non-batchable delete operation e.g. ifExist(...) 35 | * is performed 36 | */ 37 | public interface CascadeOnDeleteInterceptor extends QueryInterceptor { 38 | 39 | /** 40 | * @param queryData the delete query data 41 | * @return the additional, cascading statements to execute 42 | */ 43 | CompletableFuture>> onDelete(DeleteQueryData queryData); 44 | } -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/interceptor/CascadeOnWriteInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.interceptor; 17 | 18 | import java.util.concurrent.CompletableFuture; 19 | 20 | 21 | 22 | import net.oneandone.troilus.Batchable; 23 | 24 | import com.google.common.collect.ImmutableSet; 25 | 26 | 27 | 28 | /** 29 | * Interceptor which adds cascading statements to the write statement by using the cql batch command with write ahead. 30 | * Please consider that the interceptor will fail, if a non-batchable write operation e.g. ifNotExist(...), onlyIf(...) 31 | * is performed 32 | */ 33 | public interface CascadeOnWriteInterceptor extends QueryInterceptor { 34 | 35 | /** 36 | * @param queryData the write query data 37 | * @return the additional, cascading statements to execute 38 | */ 39 | CompletableFuture>> onWrite(WriteQueryData queryData); 40 | } 41 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/interceptor/DeleteQueryRequestInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.interceptor; 17 | 18 | import java.util.concurrent.CompletableFuture; 19 | 20 | import net.oneandone.troilus.interceptor.DeleteQueryData; 21 | import net.oneandone.troilus.interceptor.QueryInterceptor; 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | /** 34 | * Interceptor which will be executed before performing a delete query 35 | */ 36 | public interface DeleteQueryRequestInterceptor extends QueryInterceptor { 37 | 38 | /** 39 | * @param queryData the request data 40 | * @return the (modified) request data 41 | */ 42 | CompletableFuture onDeleteRequestAsync(DeleteQueryData queryData); 43 | } 44 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/interceptor/ReadQueryRequestInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.interceptor; 17 | 18 | import java.util.concurrent.CompletableFuture; 19 | 20 | import net.oneandone.troilus.interceptor.QueryInterceptor; 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | /** 29 | * Interceptor which will be executed before performing a list read query 30 | */ 31 | public interface ReadQueryRequestInterceptor extends QueryInterceptor { 32 | 33 | 34 | /** 35 | * @param queryData the request data 36 | * @return the (modified) request data 37 | */ 38 | CompletableFuture onReadRequestAsync(ReadQueryData queryData); 39 | } 40 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/interceptor/ReadQueryResponseInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.interceptor; 17 | 18 | import java.util.concurrent.CompletableFuture; 19 | 20 | import net.oneandone.troilus.interceptor.QueryInterceptor; 21 | import net.oneandone.troilus.Record; 22 | import net.oneandone.troilus.ResultList; 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | /** 31 | * Interceptor which will be executed after performing a list read query 32 | */ 33 | public interface ReadQueryResponseInterceptor extends QueryInterceptor { 34 | 35 | /** 36 | * @param queryData the request data 37 | * @param recordList the response 38 | * @return the (modified) response 39 | */ 40 | CompletableFuture> onReadResponseAsync(ReadQueryData queryData, ResultList recordList); 41 | } 42 | -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/interceptor/RecordListAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.interceptor; 17 | 18 | 19 | 20 | 21 | import net.oneandone.troilus.FetchingIterator; 22 | 23 | import net.oneandone.troilus.ResultList; 24 | 25 | import com.datastax.driver.core.ExecutionInfo; 26 | import com.google.common.collect.ImmutableList; 27 | 28 | 29 | 30 | public class RecordListAdapter implements ResultList { 31 | private final ResultList list; 32 | 33 | public RecordListAdapter(ResultList list) { 34 | this.list = list; 35 | } 36 | 37 | @Override 38 | public ExecutionInfo getExecutionInfo() { 39 | return list.getExecutionInfo(); 40 | } 41 | 42 | @Override 43 | public ImmutableList getAllExecutionInfo() { 44 | return list.getAllExecutionInfo(); 45 | } 46 | 47 | @Override 48 | public boolean wasApplied() { 49 | return list.wasApplied(); 50 | } 51 | 52 | @Override 53 | public FetchingIterator iterator() { 54 | return list.iterator(); 55 | } 56 | } -------------------------------------------------------------------------------- /troilus-core/src/main/java/net/oneandone/troilus/interceptor/WriteQueryRequestInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.interceptor; 17 | 18 | import java.util.concurrent.CompletableFuture; 19 | 20 | import net.oneandone.troilus.interceptor.QueryInterceptor; 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | /** 29 | * Interceptor which will be executed before performing a write (update, or insert) query 30 | */ 31 | public interface WriteQueryRequestInterceptor extends QueryInterceptor { 32 | 33 | /** 34 | * @param queryData the data to write 35 | * @return the (modified) data to write 36 | */ 37 | CompletableFuture onWriteRequestAsync(WriteQueryData queryData); 38 | } 39 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/CompilerCheck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | import java.time.Duration; 19 | 20 | import com.datastax.driver.core.querybuilder.Clause; 21 | 22 | import net.oneandone.troilus.Dao; 23 | import net.oneandone.troilus.DaoImpl; 24 | 25 | 26 | 27 | 28 | 29 | @SuppressWarnings("unused") 30 | public class CompilerCheck { 31 | 32 | private final Dao dao = new DaoImpl(null, null); 33 | 34 | 35 | // by uncommenting a method a compile error (per method) occurs 36 | 37 | /* 38 | private void checkDeleteWithOnlyIfIsNotBatchable() { 39 | Deletion deletion = dao.deleteWhere((Clause) null); 40 | Batchable batchable = deletion.onlyIf(null); 41 | } 42 | 43 | private void checkDeleteDoesNotSupportTTL() { 44 | Deletion deletion = dao.deleteWhere((Clause) null); 45 | deletion.withTtl(Duration.ofSeconds(1)); 46 | } 47 | 48 | private void checkDeleteDoesNotSupportWritetime() { 49 | Deletion deletion = dao.deleteWhere((Clause) null); 50 | deletion.withWritetime(3234324); 51 | } 52 | 53 | private void checkDeleteWithOnlyIfDoesNotSupportCombinWith() { 54 | dao.deleteWhere((Clause) null) 55 | .onlyIf((Clause) null) 56 | .combinedWith(null); 57 | } 58 | 59 | private void checkWriteEntityDoesNotSupportValueMethod() { 60 | dao.writeEntity(null) 61 | .value("name", "value"); 62 | } 63 | 64 | private void checkWriteEntityDoesNotSupportOnlyIf() { 65 | dao.writeEntity(null) 66 | .onlyIf((Clause) null); 67 | } 68 | 69 | private void checkWriteEntityWithIfNotExistsIsNotBatchable() { 70 | Mutation batchable = dao.writeEntity(null) 71 | .ifNotExits(); 72 | } 73 | 74 | private void checkWriteEntityWithIfDoesNotSupportCombinWith() { 75 | dao.writeEntity(null) 76 | .ifNotExits() 77 | .combinedWith(null); 78 | } 79 | 80 | private void checkWriteWithKeyWithIfNotExistsIsNotBatchable() { 81 | Batchable batchable = dao.writeWithKey("keyName", "keyValue") 82 | .ifNotExits(); 83 | } 84 | 85 | private void checkWriteWithKeyWithIfDoesNotSupportCombinWith() { 86 | dao.writeWithKey("keyName", "keyValue") 87 | .ifNotExits() 88 | .combinedWith(null); 89 | } 90 | 91 | */ 92 | } 93 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/UserType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus; 17 | 18 | 19 | 20 | 21 | public enum UserType { 22 | GOLD, SILVER, METAL 23 | } 24 | 25 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/api/BatchingWithMultiSessionTest.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1and1/Troilus/25433d0032bd5008e662b2b6eab34e55cdf00aeb/troilus-core/src/test/java/net/oneandone/troilus/api/BatchingWithMultiSessionTest.java -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/api/ColumnsApiTest.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1and1/Troilus/25433d0032bd5008e662b2b6eab34e55cdf00aeb/troilus-core/src/test/java/net/oneandone/troilus/api/ColumnsApiTest.java -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/api/ExpliciteKeyspacenameTest.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1and1/Troilus/25433d0032bd5008e662b2b6eab34e55cdf00aeb/troilus-core/src/test/java/net/oneandone/troilus/api/ExpliciteKeyspacenameTest.java -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/api/FeesTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.api; 17 | 18 | 19 | 20 | public interface FeesTable { 21 | 22 | public static final String TABLE = "fees"; 23 | 24 | public static final String CUSTOMER_ID = "customer_id"; 25 | public static final String YEAR = "year"; 26 | public static final String AMOUNT = "amount"; 27 | 28 | public static final String DDL = "com/unitedinternet/troilus/example/fees.ddl"; 29 | } 30 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/api/HistoryTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.api; 17 | 18 | import net.oneandone.troilus.ColumnName; 19 | 20 | 21 | 22 | public interface HistoryTable { 23 | 24 | public static final String TABLE = "history"; 25 | 26 | public static final ColumnName SENDER_EMAIL = ColumnName.defineString("sender_email"); 27 | public static final ColumnName RECEIVER_EMAIL = ColumnName.defineString("receiver_email"); 28 | 29 | public static final String DDL = "com/unitedinternet/troilus/example/history.ddl"; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/api/HistoryTableTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.api; 17 | 18 | 19 | 20 | import java.io.IOException; 21 | 22 | import net.oneandone.troilus.Dao; 23 | import net.oneandone.troilus.DaoImpl; 24 | import net.oneandone.troilus.CassandraDB; 25 | 26 | import org.junit.AfterClass; 27 | import org.junit.Before; 28 | import org.junit.BeforeClass; 29 | import org.junit.Test; 30 | 31 | import com.datastax.driver.core.ConsistencyLevel; 32 | 33 | 34 | 35 | public class HistoryTableTest { 36 | 37 | private static CassandraDB cassandra; 38 | 39 | 40 | @BeforeClass 41 | public static void beforeClass() throws IOException { 42 | cassandra = CassandraDB.newInstance(); 43 | } 44 | 45 | @AfterClass 46 | public static void afterClass() throws IOException { 47 | cassandra.close(); 48 | } 49 | 50 | 51 | @Before 52 | public void before() throws IOException { 53 | cassandra.tryExecuteCqlFile(HistoryTable.DDL); 54 | } 55 | 56 | 57 | @Test 58 | public void testHistoryTable() throws Exception { 59 | Dao history = new DaoImpl(cassandra.getSession(), HistoryTable.TABLE) 60 | .withConsistency(ConsistencyLevel.ONE); 61 | 62 | // insert 63 | history.writeWithKey(HistoryTable.SENDER_EMAIL, "sender@example.org", HistoryTable.RECEIVER_EMAIL, "receiver@example.org") 64 | .execute(); 65 | } 66 | } 67 | 68 | 69 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/api/IdsTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.api; 17 | 18 | 19 | 20 | import com.google.common.collect.ImmutableSet; 21 | 22 | 23 | 24 | public interface IdsTable { 25 | 26 | public static final String TABLE = "ids"; 27 | 28 | public static final String ID = "id"; 29 | public static final String IDS = "ids"; 30 | 31 | public static final ImmutableSet ALL = ImmutableSet.of(ID, IDS); 32 | 33 | public static final String DDL = "com/unitedinternet/troilus/example/ids.ddl"; 34 | } 35 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/api/LoginsTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.api; 17 | 18 | 19 | 20 | 21 | public interface LoginsTable { 22 | 23 | public static final String TABLE = "logins"; 24 | 25 | public static final String USER_ID = "user_id"; 26 | public static final String LOGINS = "logins"; 27 | 28 | public static final String DDL = "com/unitedinternet/troilus/example/logins.ddl"; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/api/NativeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.api; 17 | 18 | 19 | 20 | 21 | import java.io.IOException; 22 | 23 | import net.oneandone.troilus.CassandraDB; 24 | 25 | import org.junit.AfterClass; 26 | import org.junit.Assert; 27 | import org.junit.Before; 28 | import org.junit.BeforeClass; 29 | import org.junit.Test; 30 | 31 | import com.datastax.driver.core.ResultSet; 32 | import com.datastax.driver.core.Row; 33 | import com.datastax.driver.core.Session; 34 | 35 | 36 | public class NativeTest { 37 | 38 | 39 | private static CassandraDB cassandra; 40 | 41 | 42 | @BeforeClass 43 | public static void beforeClass() throws IOException { 44 | cassandra = CassandraDB.newInstance(); 45 | } 46 | 47 | @AfterClass 48 | public static void afterClass() throws IOException { 49 | cassandra.close(); 50 | } 51 | 52 | 53 | @Before 54 | public void before() throws IOException { 55 | cassandra.tryExecuteCqlFile(UsersTable.DDL); 56 | cassandra.tryExecuteCqlFile(LoginsTable.DDL); 57 | cassandra.tryExecuteCqlFile(PlusLoginsTable.DDL); 58 | } 59 | 60 | 61 | @Test 62 | public void testSimpleTable() throws Exception { 63 | 64 | Session session = cassandra.getSession(); 65 | 66 | session.execute("insert into " + UsersTable.TABLE + " (user_id, is_customer) VALUES('93434434', true)"); 67 | 68 | ResultSet rs = session.execute("select is_customer from " + UsersTable.TABLE + " where user_id = '93434434'"); 69 | Row row = rs.one(); 70 | Assert.assertTrue(row.getBool("is_customer")); 71 | } 72 | } 73 | 74 | 75 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/api/PaginationInvites.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package net.oneandone.troilus.api; 5 | 6 | /** 7 | * @author Jason Westra 8 | * 9 | */ 10 | public interface PaginationInvites { 11 | 12 | public static final String DDL = "com/unitedinternet/troilus/example/invites.ddl"; 13 | 14 | public static final String TABLE_NAME = "invites_by_group"; 15 | 16 | public static final String INVITE_DATE = "invite_date"; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/api/PlusLoginsTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.api; 17 | 18 | 19 | 20 | public interface PlusLoginsTable { 21 | 22 | public static final String TABLE = "plus_logins"; 23 | 24 | public static final String USER_ID = "user_id"; 25 | public static final String LOGINS = "logins"; 26 | 27 | public static final String DDL = "com/unitedinternet/troilus/example/plus_logins.ddl"; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/api/UserDefinedFunctionsTest.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1and1/Troilus/25433d0032bd5008e662b2b6eab34e55cdf00aeb/troilus-core/src/test/java/net/oneandone/troilus/api/UserDefinedFunctionsTest.java -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/api/UserType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.api; 17 | 18 | 19 | 20 | 21 | public enum UserType { 22 | GOLD, SILVER, METAL 23 | } 24 | 25 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/api/UsersTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.api; 17 | 18 | 19 | public interface UsersTable { 20 | 21 | public static final String TABLE = "users"; 22 | 23 | public static final String USER_ID = "user_id"; 24 | public static final String USER_TYPE = "user_type"; 25 | public static final String NAME = "name"; 26 | public static final String IS_CUSTOMER = "is_customer"; 27 | public static final String PICTURE = "picture"; 28 | public static final String ADDRESSES = "addresses"; 29 | public static final String MODIFIED = "modified"; 30 | public static final String PHONE_NUMBERS = "phone_numbers"; 31 | public static final String ROLES = "roles"; 32 | 33 | public static final String DDL = "com/unitedinternet/troilus/example/users.ddl"; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/api/UsersTableFields.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.api; 17 | 18 | import java.util.List; 19 | import java.util.Map; 20 | import java.util.Set; 21 | 22 | import net.oneandone.troilus.ColumnName; 23 | 24 | 25 | 26 | public final class UsersTableFields { 27 | 28 | public static final ColumnName USER_ID = ColumnName.defineString("user_id"); 29 | public static final ColumnName USER_TYPE = ColumnName.define("user_type", UserType.class); 30 | public static final ColumnName NAME = ColumnName.defineString("name"); 31 | public static final ColumnName IS_CUSTOMER = ColumnName.defineBool("is_customer"); 32 | public static final ColumnName PICTURE = ColumnName.defineBytes("picture"); 33 | public static final ColumnName> ADDRESSES = ColumnName.defineList("addresses", String.class); 34 | public static final ColumnName MODIFIED = ColumnName.defineLong("modified"); 35 | public static final ColumnName> PHONE_NUMBERS = ColumnName.defineSet("phone_numbers", String.class); 36 | public static final ColumnName> ROLES = ColumnName.defineMap("roles", String.class, String.class); 37 | } 38 | 39 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/api/WideRowTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.api; 17 | 18 | 19 | 20 | import java.io.IOException; 21 | 22 | import java.util.Map; 23 | import java.util.Optional; 24 | 25 | import net.oneandone.troilus.CassandraDB; 26 | import net.oneandone.troilus.Dao; 27 | import net.oneandone.troilus.DaoImpl; 28 | import net.oneandone.troilus.Record; 29 | 30 | import org.junit.AfterClass; 31 | import org.junit.Assert; 32 | import org.junit.Before; 33 | import org.junit.BeforeClass; 34 | import org.junit.Test; 35 | 36 | import com.datastax.driver.core.ConsistencyLevel; 37 | import com.google.common.collect.ImmutableMap; 38 | 39 | 40 | public class WideRowTest { 41 | 42 | private static CassandraDB cassandra; 43 | 44 | 45 | @BeforeClass 46 | public static void beforeClass() throws IOException { 47 | cassandra = CassandraDB.newInstance(); 48 | } 49 | 50 | @AfterClass 51 | public static void afterClass() throws IOException { 52 | cassandra.close(); 53 | } 54 | 55 | 56 | @Before 57 | public void before() throws IOException { 58 | cassandra.tryExecuteCqlFile(IdsTable.DDL); 59 | } 60 | 61 | 62 | 63 | @Test 64 | public void testIdsTable() throws Exception { 65 | Dao userDao = new DaoImpl(cassandra.getSession(), IdsTable.TABLE) 66 | .withConsistency(ConsistencyLevel.ONE); 67 | 68 | // insert 69 | userDao.writeWithKey(IdsTable.ID, "GLOBAL") 70 | .value(IdsTable.IDS, ImmutableMap.of("ID_433433", 23, "ID_33434443", 556)) 71 | .execute(); 72 | 73 | 74 | // update 75 | // TODO 76 | 77 | // read single 78 | Optional optionalRecord = userDao.readWithKey(IdsTable.ID, "GLOBAL") 79 | .column(IdsTable.IDS) 80 | .execute(); 81 | Assert.assertTrue(optionalRecord.isPresent()); 82 | 83 | Map keys = (Map) optionalRecord.get().getMap(IdsTable.IDS, String.class, Integer.class); 84 | Assert.assertEquals(23, (int) keys.get("ID_433433")); 85 | Assert.assertEquals(556,(int) keys.get("ID_33434443")); 86 | } 87 | } 88 | 89 | 90 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/cascade/DaoManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.cascade; 17 | 18 | import com.datastax.driver.core.Session; 19 | 20 | import net.oneandone.troilus.Dao; 21 | import net.oneandone.troilus.DaoImpl; 22 | 23 | 24 | public class DaoManager { 25 | 26 | private final Dao keyByAccountDao; 27 | private final Dao keyByEmailDao; 28 | 29 | 30 | public DaoManager(Session session) { 31 | Dao keyByAccountDao = new DaoImpl(session, KeyByAccountColumns.TABLE); 32 | this.keyByEmailDao = new DaoImpl(session, KeyByEmailColumns.TABLE); 33 | 34 | this.keyByAccountDao = keyByAccountDao.withInterceptor(new KeyByAccountColumns.CascadeToByEmailDao(keyByAccountDao, keyByEmailDao)); 35 | } 36 | 37 | 38 | public Dao getKeyByAccountDao() { 39 | return keyByAccountDao; 40 | } 41 | 42 | public Dao getKeyByEmailDao() { 43 | return keyByEmailDao; 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/cascade/KeyByEmailColumns.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.cascade; 17 | 18 | 19 | import net.oneandone.troilus.ColumnName; 20 | 21 | 22 | 23 | public interface KeyByEmailColumns { 24 | 25 | public static final String TABLE = "key_by_email"; 26 | 27 | public static final ColumnName EMAIL = ColumnName.defineString("email"); 28 | public static final ColumnName CREATED = ColumnName.defineLong("created"); 29 | public static final ColumnName KEY = ColumnName.defineBytes("key"); 30 | public static final ColumnName ACCOUNT_ID = ColumnName.defineString("account_id"); 31 | 32 | public static final String DDL = "com/unitedinternet/troilus/example/key_by_email.ddl"; 33 | } 34 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/example/Address.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.example; 17 | 18 | import net.oneandone.troilus.Field; 19 | 20 | 21 | public class Address { 22 | 23 | @Field(name = "street") 24 | private String street; 25 | 26 | @Field(name = "city") 27 | private String city; 28 | 29 | @Field(name = "post_code") 30 | private String postCode; 31 | 32 | 33 | @SuppressWarnings("unused") 34 | private Address() { } 35 | 36 | 37 | public Address(String street, String city, String postCode) { 38 | this.street = street; 39 | this.city = city; 40 | this.postCode = postCode; 41 | } 42 | 43 | 44 | public String getStreet() { 45 | return street; 46 | } 47 | 48 | 49 | public String getCity() { 50 | return city; 51 | } 52 | 53 | 54 | public String getPostCode() { 55 | return postCode; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/example/AddressType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.example; 17 | 18 | 19 | 20 | public interface AddressType { 21 | 22 | public static final String STREET = "street"; 23 | public static final String CITY = "city"; 24 | public static final String POST_CODE = "post_code"; 25 | 26 | 27 | public static final String DDL = "com/unitedinternet/troilus/example/address.ddl"; 28 | } 29 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/example/ClassifierEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.example; 17 | 18 | 19 | 20 | 21 | public enum ClassifierEnum { 22 | 23 | ONE, TWO, THREE, FOUR, FIVE 24 | } 25 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/example/Functions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.example; 17 | 18 | 19 | 20 | 21 | public interface Functions { 22 | 23 | public static final String DDL = "com/unitedinternet/troilus/example/functions.ddl"; 24 | } 25 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/example/Hotel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.example; 17 | 18 | import java.util.Optional; 19 | 20 | import net.oneandone.troilus.Field; 21 | 22 | import com.google.common.collect.ImmutableSet; 23 | 24 | 25 | 26 | public class Hotel { 27 | 28 | @Field(name = "id") 29 | private String id = null; 30 | 31 | @Field(name = "name") 32 | private String name = null; 33 | 34 | @Field(name = "room_ids") 35 | private ImmutableSet roomIds = ImmutableSet.of(); 36 | 37 | @Field(name = "classification") 38 | private Optional classification = Optional.empty(); 39 | 40 | @Field(name = "description") 41 | private Optional description = Optional.empty(); 42 | 43 | @Field(name = "address") 44 | private Address address = null; 45 | 46 | @Field(name = "phone") 47 | private Optional phone = Optional.empty(); 48 | 49 | 50 | 51 | @SuppressWarnings("unused") 52 | private Hotel() { } 53 | 54 | public Hotel(String id, 55 | String name, 56 | ImmutableSet roomIds, 57 | Optional classification, 58 | Optional description, 59 | Address address, 60 | Optional phone) { 61 | this.id = id; 62 | this.name = name; 63 | this.roomIds = roomIds; 64 | this.classification = classification; 65 | this.description = description; 66 | this.address = address; 67 | this.phone = phone; 68 | } 69 | 70 | public String getId() { 71 | return id; 72 | } 73 | 74 | public String getName() { 75 | return name; 76 | } 77 | 78 | public ImmutableSet getRoomIds() { 79 | return roomIds; 80 | } 81 | 82 | public Optional getClassification() { 83 | return classification; 84 | } 85 | 86 | public Optional getDescription() { 87 | return description; 88 | } 89 | 90 | public Address getAddress() { 91 | return address; 92 | } 93 | 94 | public Optional getPhone() { 95 | return phone; 96 | } 97 | } -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/example/HotelSubscriber.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.example; 17 | 18 | 19 | 20 | import java.util.List; 21 | import java.util.concurrent.atomic.AtomicBoolean; 22 | import java.util.concurrent.atomic.AtomicReference; 23 | 24 | 25 | import org.reactivestreams.Subscriber; 26 | import org.reactivestreams.Subscription; 27 | 28 | import com.google.common.collect.ImmutableList; 29 | import com.google.common.collect.Lists; 30 | 31 | 32 | public class HotelSubscriber implements Subscriber { 33 | private final List elements = Lists.newArrayList(); 34 | private final AtomicBoolean isCompleted = new AtomicBoolean(); 35 | private final AtomicReference errorRef = new AtomicReference<>(); 36 | 37 | private final AtomicReference subscriptionRef = new AtomicReference<>(); 38 | 39 | @Override 40 | public void onSubscribe(Subscription subscription) { 41 | this.subscriptionRef.set(subscription); 42 | subscription.request(2); 43 | } 44 | 45 | @Override 46 | public void onComplete() { 47 | synchronized (this) { 48 | isCompleted.set(true); 49 | notifyAll(); 50 | } 51 | } 52 | 53 | 54 | @Override 55 | public void onError(Throwable t) { 56 | synchronized (this) { 57 | errorRef.set(t); 58 | notifyAll(); 59 | } 60 | } 61 | 62 | @Override 63 | public void onNext(Hotel element) { 64 | synchronized (this) { 65 | elements.add(element); 66 | } 67 | 68 | subscriptionRef.get().request(1); 69 | } 70 | 71 | 72 | public ImmutableList getAll() { 73 | 74 | synchronized (this) { 75 | if (!isCompleted.get()) { 76 | try { 77 | wait(); 78 | } catch (InterruptedException ignore) { } 79 | } 80 | 81 | return ImmutableList.copyOf(elements); 82 | } 83 | } 84 | } 85 | 86 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/example/HotelTableFields.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.example; 17 | 18 | 19 | import java.util.Set; 20 | 21 | import net.oneandone.troilus.ColumnName; 22 | 23 | 24 | 25 | public final class HotelTableFields { 26 | public static final ColumnName ID = ColumnName.defineString("id"); 27 | public static final ColumnName NAME = ColumnName.defineString("name"); 28 | public static final ColumnName> ROOM_IDS = ColumnName.defineSet("room_ids", String.class); 29 | public static final ColumnName
ADDRESS = ColumnName.define("address", Address.class); 30 | public static final ColumnName DESCRIPTION = ColumnName.defineString("description"); 31 | public static final ColumnName CLASSIFICATION = ColumnName.define("classification", ClassifierEnum.class); 32 | } 33 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/example/HotelTest.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1and1/Troilus/25433d0032bd5008e662b2b6eab34e55cdf00aeb/troilus-core/src/test/java/net/oneandone/troilus/example/HotelTest.java -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/example/HotelsTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.example; 17 | 18 | 19 | import net.oneandone.troilus.interceptor.ConstraintsInterceptor; 20 | 21 | 22 | 23 | public interface HotelsTable { 24 | 25 | public static final String TABLE = "hotels"; 26 | 27 | public static final String ID = "id"; 28 | public static final String NAME = "name"; 29 | public static final String ROOM_IDS = "room_ids"; 30 | public static final String DESCRIPTION = "description"; 31 | public static final String CLASSIFICATION = "classification"; 32 | public static final String PHONE = "phone"; 33 | 34 | 35 | public static final String DDL = "com/unitedinternet/troilus/example/hotels.ddl"; 36 | 37 | public static ConstraintsInterceptor CONSTRAINTS = ConstraintsInterceptor.newConstraints() 38 | .withNotNullColumn(NAME); 39 | } 40 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/example/RoomsTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.example; 17 | 18 | 19 | 20 | public interface RoomsTable { 21 | 22 | public static final String TABLE = "rooms"; 23 | 24 | public static final String ID = "room_id"; 25 | public static final String HOTEL_ID = "hotel_id"; 26 | public static final String NUMBER_OF_BEDS = "number_of_beds"; 27 | 28 | 29 | public static final String DDL = "com/unitedinternet/troilus/example/rooms.ddl"; 30 | } 31 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/persistence/JPAUser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.persistence; 17 | 18 | 19 | import java.nio.ByteBuffer; 20 | import java.util.Optional; 21 | 22 | 23 | 24 | 25 | 26 | import javax.persistence.Column; 27 | 28 | 29 | import com.google.common.collect.ImmutableList; 30 | import com.google.common.collect.ImmutableSet; 31 | 32 | public class JPAUser { 33 | 34 | @Column(name = "user_id") 35 | private String userId; 36 | 37 | @Column(name = "name") 38 | private String name; 39 | 40 | @Column(name = "is_customer") 41 | private Optional isCustomer; 42 | 43 | @Column(name = "picture") 44 | private Optional picture; 45 | 46 | @Column(name = "modified") 47 | private Long modified; 48 | 49 | @Column(name = "phone_numbers") 50 | private ImmutableSet phoneNumbers; 51 | 52 | @Column(name = "addresses") 53 | private ImmutableList addresses; 54 | 55 | 56 | public JPAUser() { 57 | 58 | } 59 | 60 | 61 | 62 | public JPAUser(String userId, String name, boolean isCustomer, ByteBuffer picture, long modified, ImmutableSet phoneNumbers, ImmutableList addresses) { 63 | this.userId = userId; 64 | this.name = name; 65 | this.isCustomer = Optional.of(isCustomer); 66 | this.picture = Optional.of(picture); 67 | this.modified = modified; 68 | this.phoneNumbers = phoneNumbers; 69 | this.addresses = addresses; 70 | } 71 | 72 | 73 | public String getUserId() { 74 | return userId; 75 | } 76 | 77 | 78 | public String getName() { 79 | return name; 80 | } 81 | 82 | 83 | public Optional isCustomer() { 84 | return isCustomer; 85 | } 86 | 87 | public ByteBuffer getPicture() { 88 | return picture.get(); 89 | } 90 | 91 | public void setPicture(Optional data) { 92 | this.picture = data; 93 | } 94 | 95 | public Optional getModified() { 96 | return Optional.ofNullable(modified); 97 | } 98 | 99 | public Optional> getPhoneNumbers() { 100 | return Optional.ofNullable(phoneNumbers); 101 | } 102 | 103 | public ImmutableList getAddresses() { 104 | return addresses; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/reactive/MySubscriber.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.reactive; 17 | 18 | 19 | 20 | import java.util.List; 21 | import java.util.concurrent.atomic.AtomicBoolean; 22 | import java.util.concurrent.atomic.AtomicReference; 23 | 24 | import net.oneandone.troilus.Record; 25 | 26 | import org.reactivestreams.Subscriber; 27 | import org.reactivestreams.Subscription; 28 | 29 | import com.google.common.collect.ImmutableList; 30 | import com.google.common.collect.Lists; 31 | 32 | 33 | public class MySubscriber implements Subscriber { 34 | private final List elements = Lists.newArrayList(); 35 | private final AtomicBoolean isCompleted = new AtomicBoolean(); 36 | private final AtomicReference errorRef = new AtomicReference<>(); 37 | 38 | private final AtomicReference subscriptionRef = new AtomicReference<>(); 39 | 40 | @Override 41 | public void onSubscribe(Subscription subscription) { 42 | this.subscriptionRef.set(subscription); 43 | subscription.request(2); 44 | } 45 | 46 | @Override 47 | public void onComplete() { 48 | synchronized (this) { 49 | isCompleted.set(true); 50 | notifyAll(); 51 | } 52 | } 53 | 54 | 55 | @Override 56 | public void onError(Throwable t) { 57 | synchronized (this) { 58 | errorRef.set(t); 59 | notifyAll(); 60 | } 61 | } 62 | 63 | @Override 64 | public void onNext(Record element) { 65 | synchronized (this) { 66 | elements.add(element); 67 | } 68 | 69 | subscriptionRef.get().request(1); 70 | } 71 | 72 | 73 | public ImmutableList getAll() { 74 | 75 | synchronized (this) { 76 | if (!isCompleted.get()) { 77 | try { 78 | wait(); 79 | } catch (InterruptedException ignore) { } 80 | } 81 | 82 | return ImmutableList.copyOf(elements); 83 | } 84 | } 85 | } 86 | 87 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/reactive/PublisherFetchingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.reactive; 17 | 18 | 19 | import net.oneandone.troilus.Record; 20 | import net.oneandone.troilus.SimpleResultList; 21 | 22 | import org.junit.Assert; 23 | import org.junit.Test; 24 | import org.reactivestreams.Publisher; 25 | 26 | 27 | public class PublisherFetchingTest { 28 | 29 | 30 | @Test 31 | public void testReactiveStreams() throws Exception { 32 | 33 | MySubscriber subscriber = new MySubscriber(); 34 | 35 | int num = 400; 36 | 37 | Publisher publisher = SimpleResultList.newResultListPublisher(num, 20); 38 | publisher.subscribe(subscriber); 39 | 40 | Assert.assertEquals(num, subscriber.getAll().size()); 41 | } 42 | } 43 | 44 | 45 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/reactive/PublisherTckTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.reactive; 17 | 18 | 19 | import net.oneandone.troilus.Record; 20 | import net.oneandone.troilus.SimpleResultList; 21 | 22 | import org.reactivestreams.Publisher; 23 | import org.reactivestreams.tck.PublisherVerification; 24 | import org.reactivestreams.tck.TestEnvironment; 25 | import org.testng.annotations.Test; 26 | 27 | 28 | 29 | @Test 30 | public class PublisherTckTest extends PublisherVerification { 31 | 32 | 33 | public PublisherTckTest() { 34 | super(new TestEnvironment(2000), 250); 35 | } 36 | 37 | @Override 38 | public long maxElementsFromPublisher() { 39 | return 100l; 40 | } 41 | 42 | 43 | @Override 44 | public Publisher createFailedPublisher() { 45 | return null; 46 | } 47 | 48 | @Override 49 | public Publisher createPublisher(long elements) { 50 | return SimpleResultList.newResultListPublisher(elements); 51 | } 52 | } -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/referentialintegrity/DeviceTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.referentialintegrity; 17 | 18 | 19 | 20 | 21 | public interface DeviceTable { 22 | 23 | public static final String TABLE = "device"; 24 | 25 | public static final String ID = "device_id"; 26 | public static final String TYPE = "type"; 27 | public static final String PHONENUMBERS = "phone_numbers"; 28 | 29 | public static final String DDL = "com/unitedinternet/troilus/example/device.ddl"; 30 | } 31 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/referentialintegrity/PhonenumbersTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.referentialintegrity; 17 | 18 | 19 | 20 | public interface PhonenumbersTable { 21 | 22 | public static final String TABLE = "phone_numbers"; 23 | 24 | public static final String NUMBER = "number"; 25 | public static final String DEVICE_ID = "device_id"; 26 | public static final String ACTIVE = "active"; 27 | 28 | public static final String DDL = "com/unitedinternet/troilus/example/phone_numbers.ddl"; 29 | } 30 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/userdefinieddatatypes/Addr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.userdefinieddatatypes; 17 | 18 | 19 | import net.oneandone.troilus.Field; 20 | 21 | import com.google.common.collect.ImmutableList; 22 | import com.google.common.collect.ImmutableMap; 23 | 24 | public class Addr { 25 | 26 | @Field(name = "lines") 27 | private ImmutableList lines; 28 | 29 | @Field(name = "zip_code") 30 | private Integer zipCode; 31 | 32 | @Field(name = "aliases") 33 | private ImmutableMap aliases; 34 | 35 | 36 | @SuppressWarnings("unused") 37 | private Addr() { } 38 | 39 | 40 | public Addr(ImmutableList lines, Integer zipCode, ImmutableMap aliases) { 41 | this.lines = lines; 42 | this.zipCode = zipCode; 43 | this.aliases = aliases; 44 | } 45 | 46 | 47 | public ImmutableList getLines() { 48 | return lines; 49 | } 50 | 51 | 52 | public Integer getZipCode() { 53 | return zipCode; 54 | } 55 | 56 | 57 | public ImmutableMap getAliases() { 58 | return aliases; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/userdefinieddatatypes/AddrType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.userdefinieddatatypes; 17 | 18 | 19 | 20 | public interface AddrType { 21 | 22 | public static final String ADDRESS_LINES = "lines"; 23 | public static final String ZIP_CODE = "zip_code"; 24 | 25 | 26 | public static final String DDL = "com/unitedinternet/troilus/example/addr.ddl"; 27 | } 28 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/userdefinieddatatypes/Addressline.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.userdefinieddatatypes; 17 | 18 | 19 | import net.oneandone.troilus.Field; 20 | 21 | 22 | public class Addressline { 23 | 24 | @Field(name = "line") 25 | private String line; 26 | 27 | @SuppressWarnings("unused") 28 | private Addressline() { } 29 | 30 | 31 | public Addressline(String line) { 32 | this.line = line; 33 | } 34 | 35 | 36 | public String getLine() { 37 | return line; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/userdefinieddatatypes/AddresslineType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.userdefinieddatatypes; 17 | 18 | 19 | 20 | 21 | public interface AddresslineType { 22 | 23 | public static final String ADDRESS_LINE = "line"; 24 | 25 | 26 | public static final String DDL = "com/unitedinternet/troilus/example/addressline.ddl"; 27 | } 28 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/userdefinieddatatypes/Classifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.userdefinieddatatypes; 17 | 18 | 19 | import net.oneandone.troilus.Field; 20 | 21 | 22 | public class Classifier { 23 | 24 | @Field(name = "type") 25 | private String type; 26 | 27 | 28 | @SuppressWarnings("unused") 29 | private Classifier() { } 30 | 31 | public Classifier(String type) { 32 | this.type = type; 33 | } 34 | 35 | public String getType() { 36 | return type; 37 | } 38 | 39 | @Override 40 | public int hashCode() { 41 | return type.hashCode(); 42 | } 43 | 44 | @Override 45 | public boolean equals(Object other) { 46 | if (other instanceof Classifier) { 47 | return ((Classifier) other).type.equals(type); 48 | } 49 | 50 | return false; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/userdefinieddatatypes/ClassifierType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.userdefinieddatatypes; 17 | 18 | 19 | 20 | 21 | public interface ClassifierType { 22 | 23 | public static final String TYPE = "type"; 24 | 25 | public static final String DDL = "com/unitedinternet/troilus/example/classifier.ddl"; 26 | } 27 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/userdefinieddatatypes/CustomersTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.userdefinieddatatypes; 17 | 18 | 19 | 20 | 21 | public interface CustomersTable { 22 | 23 | public static final String TABLE = "customers"; 24 | 25 | public static final String ID = "id"; 26 | public static final String NAME = "name"; 27 | public static final String CURRENT_ADDRESS = "current_address"; 28 | public static final String OLD_ADDRESSES = "old_addresses"; 29 | public static final String PHONE_NUMBERS = "phone_numbers"; 30 | public static final String CLASSIFICATION = "classification"; 31 | public static final String CLASSIFICATION2 = "classification2"; 32 | public static final String ROLES = "roles"; 33 | 34 | 35 | 36 | public static final String DDL = "com/unitedinternet/troilus/example/customers.ddl"; 37 | } 38 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/userdefinieddatatypes/Score.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.userdefinieddatatypes; 17 | 18 | 19 | import net.oneandone.troilus.Field; 20 | 21 | 22 | public class Score { 23 | 24 | @Field(name = "score") 25 | private Integer score; 26 | 27 | 28 | @SuppressWarnings("unused") 29 | private Score() { } 30 | 31 | public Score(Integer score) { 32 | this.score = score; 33 | } 34 | 35 | public Integer getScore() { 36 | return score; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /troilus-core/src/test/java/net/oneandone/troilus/userdefinieddatatypes/ScoreType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1&1 Internet AG, https://github.com/1and1/ 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 net.oneandone.troilus.userdefinieddatatypes; 17 | 18 | 19 | 20 | 21 | public interface ScoreType { 22 | 23 | public static final String TYPE = "score"; 24 | 25 | public static final String DDL = "com/unitedinternet/troilus/example/score.ddl"; 26 | } 27 | -------------------------------------------------------------------------------- /troilus-core/src/test/resources/com/unitedinternet/troilus/example/addr.ddl: -------------------------------------------------------------------------------- 1 | CREATE TYPE addr ( 2 | lines list>, 3 | aliases map>, 4 | zip_code int 5 | ) -------------------------------------------------------------------------------- /troilus-core/src/test/resources/com/unitedinternet/troilus/example/address.ddl: -------------------------------------------------------------------------------- 1 | CREATE TYPE address ( 2 | street text, 3 | city text, 4 | post_code text 5 | ) -------------------------------------------------------------------------------- /troilus-core/src/test/resources/com/unitedinternet/troilus/example/addressline.ddl: -------------------------------------------------------------------------------- 1 | CREATE TYPE addressline ( 2 | line text 3 | ) -------------------------------------------------------------------------------- /troilus-core/src/test/resources/com/unitedinternet/troilus/example/classifier.ddl: -------------------------------------------------------------------------------- 1 | 2 | 3 | CREATE TYPE classifier ( 4 | type text 5 | ) -------------------------------------------------------------------------------- /troilus-core/src/test/resources/com/unitedinternet/troilus/example/customers.ddl: -------------------------------------------------------------------------------- 1 | 2 | DROP TABLE customers; 3 | 4 | CREATE TABLE customers ( 5 | id text, 6 | name text, 7 | is_customer boolean, 8 | picture blob, 9 | phone_numbers set, 10 | current_address frozen, 11 | old_addresses set>, 12 | classification map, frozen>, 13 | classification2 map>, 14 | roles map, 15 | PRIMARY KEY (id) 16 | ); -------------------------------------------------------------------------------- /troilus-core/src/test/resources/com/unitedinternet/troilus/example/device.ddl: -------------------------------------------------------------------------------- 1 | 2 | DROP TABLE device; 3 | 4 | CREATE TABLE device ( 5 | device_id text, 6 | type int, 7 | phone_numbers set, 8 | PRIMARY KEY (device_id) 9 | ); -------------------------------------------------------------------------------- /troilus-core/src/test/resources/com/unitedinternet/troilus/example/fees.ddl: -------------------------------------------------------------------------------- 1 | 2 | DROP TABLE fees; 3 | 4 | CREATE TABLE fees ( 5 | customer_id text, 6 | year int, 7 | amount int, 8 | PRIMARY KEY ((customer_id), year) 9 | ) -------------------------------------------------------------------------------- /troilus-core/src/test/resources/com/unitedinternet/troilus/example/functions.ddl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CREATE OR REPLACE FUNCTION phonenumber(phoneNum text) 5 | RETURNS NULL ON NULL INPUT 6 | RETURNS text LANGUAGE javascript AS '"phoneNum";'; 7 | -------------------------------------------------------------------------------- /troilus-core/src/test/resources/com/unitedinternet/troilus/example/history.ddl: -------------------------------------------------------------------------------- 1 | 2 | DROP TABLE history; 3 | 4 | CREATE TABLE history ( 5 | sender_email text, 6 | receiver_email text, 7 | PRIMARY KEY (sender_email, receiver_email) 8 | ) 9 | -------------------------------------------------------------------------------- /troilus-core/src/test/resources/com/unitedinternet/troilus/example/hotels.ddl: -------------------------------------------------------------------------------- 1 | 2 | DROP TABLE hotels; 3 | 4 | CREATE TABLE hotels ( 5 | id text, 6 | name text, 7 | description text, 8 | classification text, 9 | room_ids set, 10 | address frozen
, 11 | phone text, 12 | PRIMARY KEY (id) 13 | ); -------------------------------------------------------------------------------- /troilus-core/src/test/resources/com/unitedinternet/troilus/example/ids.ddl: -------------------------------------------------------------------------------- 1 | 2 | 3 | DROP TABLE ids; 4 | 5 | CREATE TABLE ids ( 6 | id text, 7 | ids map, 8 | PRIMARY KEY (id) 9 | ); 10 | 11 | -------------------------------------------------------------------------------- /troilus-core/src/test/resources/com/unitedinternet/troilus/example/invites.ddl: -------------------------------------------------------------------------------- 1 | DROP TABLE invites_by_group; 2 | 3 | CREATE TABLE invites_by_group ( 4 | group_id text, 5 | invite_date timestamp, 6 | email_address text, 7 | PRIMARY KEY (group_id, invite_date, email_address) 8 | ) 9 | WITH CLUSTERING ORDER BY (invite_date ASC); -------------------------------------------------------------------------------- /troilus-core/src/test/resources/com/unitedinternet/troilus/example/key_by_accountid.ddl: -------------------------------------------------------------------------------- 1 | 2 | DROP TABLE key_by_accountid; 3 | 4 | CREATE TABLE key_by_accountid ( 5 | account_id text, 6 | key blob, 7 | email_idx set>>, 8 | PRIMARY KEY (account_id) 9 | ); -------------------------------------------------------------------------------- /troilus-core/src/test/resources/com/unitedinternet/troilus/example/key_by_email.ddl: -------------------------------------------------------------------------------- 1 | 2 | DROP TABLE key_by_email; 3 | 4 | CREATE TABLE key_by_email ( 5 | email text, 6 | created bigint, 7 | key blob, 8 | account_id text, 9 | PRIMARY KEY ((email, created)) 10 | ); -------------------------------------------------------------------------------- /troilus-core/src/test/resources/com/unitedinternet/troilus/example/logins.ddl: -------------------------------------------------------------------------------- 1 | 2 | DROP TABLE logins; 3 | 4 | 5 | CREATE TABLE logins ( 6 | user_id text, 7 | logins counter, 8 | PRIMARY KEY (user_id) 9 | ); -------------------------------------------------------------------------------- /troilus-core/src/test/resources/com/unitedinternet/troilus/example/phone_numbers.ddl: -------------------------------------------------------------------------------- 1 | 2 | DROP TABLE phone_numbers; 3 | 4 | CREATE TABLE phone_numbers ( 5 | number text, 6 | device_id text, 7 | active boolean, 8 | PRIMARY KEY (number) 9 | ); -------------------------------------------------------------------------------- /troilus-core/src/test/resources/com/unitedinternet/troilus/example/plus_logins.ddl: -------------------------------------------------------------------------------- 1 | 2 | 3 | DROP TABLE plus_logins; 4 | 5 | CREATE TABLE plus_logins ( 6 | user_id text, 7 | logins counter, 8 | PRIMARY KEY (user_id) 9 | ); -------------------------------------------------------------------------------- /troilus-core/src/test/resources/com/unitedinternet/troilus/example/rooms.ddl: -------------------------------------------------------------------------------- 1 | 2 | DROP TABLE rooms; 3 | 4 | CREATE TABLE rooms ( 5 | room_id text, 6 | hotel_id text, 7 | number_of_beds int, 8 | PRIMARY KEY (room_id) 9 | ); -------------------------------------------------------------------------------- /troilus-core/src/test/resources/com/unitedinternet/troilus/example/score.ddl: -------------------------------------------------------------------------------- 1 | 2 | CREATE TYPE score ( 3 | score int 4 | ) -------------------------------------------------------------------------------- /troilus-core/src/test/resources/com/unitedinternet/troilus/example/users.ddl: -------------------------------------------------------------------------------- 1 | 2 | 3 | DROP table users; 4 | 5 | CREATE TABLE users ( 6 | user_id text, 7 | user_type text, 8 | name text, 9 | is_customer boolean, 10 | picture blob, 11 | sec_id blob, 12 | modified bigint, 13 | phone_numbers set, 14 | addresses list, 15 | roles map, 16 | PRIMARY KEY (user_id) 17 | ); -------------------------------------------------------------------------------- /troilus-core/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | --------------------------------------------------------------------------------