Skip to content

Commit

Permalink
Fix: Cassandra Queries
Browse files Browse the repository at this point in the history
  • Loading branch information
ChakshuGautam committed Jul 2, 2021
2 parents d3004a2 + bcd6e35 commit 5bbb11e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/uci/dao/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import reactor.core.publisher.SignalType;

import java.time.LocalDate;
import java.time.LocalDateTime;
Expand All @@ -16,7 +17,6 @@
* @author chakshu
*/
@Slf4j
@ConfigurationProperties("dao-application.properties")
@SpringBootApplication(scanBasePackages = "com.uci.dao")
public class Application implements CommandLineRunner {

Expand All @@ -37,9 +37,9 @@ public void run(String... args) throws Exception {
xMessageRepository.insert(new XMessageDAO(new Long(1213134), "HHBJ24", "hkkh", "efef", "grdgrdg", LocalDateTime.now(),
"HHBJ", "hkkh", "efef", "grdgrdg", "HHBJ", "hkkh", "efef")).log().subscribe();
LocalDateTime yesterday = LocalDateTime.now().minusDays(1L);
xMessageRepository.findAllByUserIdAndTimestampAfter("HHBJ", yesterday).subscribe(xMessageDAO -> {
log.info("XMessage List Item :>> " + counter + " " + xMessageDAO.getMessageId() + " " + xMessageDAO.getTimestamp());
counter += 1;
});
xMessageRepository.findAllByUserIdAndTimestampAfter("HHBJ", yesterday).subscribe(xMessageDAO -> {
log.info("XMessage List Item :>> " + counter + " " + xMessageDAO.getMessageId() + " " + xMessageDAO.getTimestamp());
counter += 1;
});
}
}
13 changes: 10 additions & 3 deletions src/main/java/com/uci/dao/models/XMessageDAO.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
package com.uci.dao.models;

import lombok.*;
import org.springframework.data.cassandra.core.cql.Ordering;
import org.springframework.data.cassandra.core.cql.PrimaryKeyType;
import org.springframework.data.cassandra.core.mapping.Column;
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn;
import org.springframework.data.cassandra.core.mapping.Table;

import java.time.LocalDateTime;

import static org.springframework.data.cassandra.core.cql.PrimaryKeyType.CLUSTERED;
import static org.springframework.data.cassandra.core.cql.PrimaryKeyType.PARTITIONED;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Table("XMessage")
public class XMessageDAO {
@PrimaryKey
private Long id;
@Column
private Long id;

@PrimaryKeyColumn(type = PrimaryKeyType.PARTITIONED)
private String userId;
@Column
private String fromId;
@Column
private String channel;
@Column
private String provider;
@Column
@PrimaryKeyColumn(type = CLUSTERED, ordering = Ordering.DESCENDING)
private LocalDateTime timestamp;
@Column
private String messageState;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/uci/dao/repository/XMessageRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public interface XMessageRepository extends ReactiveCassandraRepository<XMessage

Flux<XMessageDAO> findFirstByAppOrderByTimestampDesc(String appName);

@AllowFiltering
Flux<List<XMessageDAO>> findAllByUserId(String userID);

Flux<XMessageDAO> findByMessageId(String messageID);
Expand All @@ -27,6 +28,7 @@ public interface XMessageRepository extends ReactiveCassandraRepository<XMessage

Flux<XMessageDAO> findFirstByCauseIdAndMessageStateOrderByTimestampDesc(String causeId, String messageState);

@AllowFiltering
Flux<List<XMessageDAO>> findAllByUserIdOrderByTimestampDesc(String userID);

@AllowFiltering
Expand Down

0 comments on commit 5bbb11e

Please sign in to comment.