@Test public void should_initialize_lazy_properties() throws Exception { Tweet tweet = new Tweet(); tweet.setId(UUIDGen.getTimeUUID()); tweet.setContent("welcome"); CompleteBean entity = CompleteBeanTestBuilder.builder() .randomId() .name("name") .label("label") .age(45L) .addFriends("foo", "bar") .welcomeTweet(tweet) .version(CounterBuilder.incr(11L)) .buid(); manager.insert(entity); CompleteBean foundEntity = manager.find(CompleteBean.class, entity.getId()); CompleteBean rawEntity = manager.initAndRemoveProxy(foundEntity); assertThat(rawEntity.getName()).isEqualTo("name"); assertThat(rawEntity.getLabel()).isEqualTo("label"); assertThat(rawEntity.getAge()).isEqualTo(45L); assertThat(rawEntity.getFriends()).containsExactly("foo", "bar"); assertThat(rawEntity.getWelcomeTweet().getContent()).isEqualTo("welcome"); assertThat(rawEntity.getVersion()).isInstanceOf(InternalCounterImpl.class); assertThat(rawEntity.getVersion().get()).isEqualTo(11L); }
@Test public void should_re_prepare_statements_when_cache_size_exceeded() throws Exception { // Given CompleteBean bean = builder().id(RandomUtils.nextLong(0, Long.MAX_VALUE)).name("name").buid(); CompleteBean managed = pm.insert(bean); // When managed.setAge(10L); pm.update(managed); managed.setFriends(Arrays.asList("foo", "bar")); pm.update(managed); managed.setFollowers(Sets.newHashSet("George", "Paul")); pm.update(managed); managed.setAge(11L); pm.update(managed); // Then CompleteBean found = pm.find(CompleteBean.class, bean.getId()); assertThat(found.getAge()).isEqualTo(11L); assertThat(found.getName()).isEqualTo("name"); assertThat(found.getFriends()).containsExactly("foo", "bar"); assertThat(found.getFollowers()).containsOnly("George", "Paul"); }
private void insertClusteredEntity( Long partitionKey, int count, String name, String clusteredValue) { ClusteredEntity.CompoundPK compoundPK = new ClusteredEntity.CompoundPK(partitionKey, count, name); ClusteredEntity entity = new ClusteredEntity(compoundPK, clusteredValue); manager.insert(entity); }
@Test public void should_initialize_counter_value() throws Exception { CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().name("name").buid(); entity = manager.insert(entity); entity.getVersion().incr(2L); manager.update(entity); RegularStatement statement = select().from("CompleteBean").where(eq("id", bindMarker())); CompleteBean foundEntity = manager.typedQuery(CompleteBean.class, statement, entity.getId()).getFirst(); CompleteBean rawEntity = manager.initAndRemoveProxy(foundEntity); assertThat(rawEntity.getVersion()).isInstanceOf(InternalCounterImpl.class); assertThat(rawEntity.getVersion().get()).isEqualTo(2L); }
@Bean(destroyMethod = "shutDown") public PersistenceManager getPersistenceManager() { final List<String> activeProfiles = Arrays.asList(env.getActiveProfiles()); boolean isProduction = activeProfiles.contains(Profiles.SPRING_PROFILE_PRODUCTION); PersistenceManagerFactory pmFactory = PersistenceManagerFactoryBuilder.builder(cluster) .withEntityPackages(UserEntity.class.getPackage().getName()) .withDefaultReadConsistency(ConsistencyLevel.ONE) .withDefaultWriteConsistency(ConsistencyLevel.ONE) .withKeyspaceName(Schema.KEYSPACE) .withExecutorServiceMinThreadCount(5) .withExecutorServiceMaxThreadCount(10) .forceTableCreation(isProduction ? false : true) .build(); final PersistenceManager pm = pmFactory.createPersistenceManager(); pm.insert( UserEntity.fromModel(KILLRCHAT_USER), OptionsBuilder.ifNotExists() .lwtResultListener( new LWTResultListener() { @Override public void onSuccess() { logger.info("Create new administration 'killrchat' account"); } @Override public void onError(LWTResult lwtResult) { logger.debug("Administration 'killrchat' account already exists"); } })); return pm; }
private void insertCompositeClusteredEntity( long id, String bucket, int count, String name, String clusteredValue) { CompoundPK compoundPK = new CompoundPK(id, bucket, count, name); CompositeClusteredEntity entity = new CompositeClusteredEntity(compoundPK, clusteredValue); manager.insert(entity); }