Skip to content

Instantly share code, notes, and snippets.

@lankydan
Created April 15, 2018 19:25
Show Gist options
  • Save lankydan/85780b17f207d143de04f0b5ec091910 to your computer and use it in GitHub Desktop.
Save lankydan/85780b17f207d143de04f0b5ec091910 to your computer and use it in GitHub Desktop.
Datastax driver - application with repository example usage
@SpringBootApplication
public class Application implements CommandLineRunner {
@Autowired
private PersonRepository personRepository;
public static void main(String args[]) {
SpringApplication.run(Application.class);
}
@Override
public void run(String... args) {
final Person bob = new Person("UK", "Bob", "Bobbington", UUID.randomUUID(), 50, "Software Developer", 50000);
final Person john = new Person("UK", "John", "Doe", UUID.randomUUID(), 30, "Doctor", 100000);
personRepository.save(bob);
personRepository.save(john);
System.out.println("Find all");
personRepository.findAll().forEach(System.out::println);
System.out.println("Find one record");
System.out.println(personRepository.find(john.getCountry(), john.getFirstName(), john.getLastName(), john.getId()));
System.out.println("Find all by country");
personRepository.findAllByCountry("UK").forEach(System.out::println);
john.setProfession("Unemployed");
john.setSalary(0);
personRepository.save(john);
System.out.println("Demonstrating updating a record");
System.out.println(personRepository.find(john.getCountry(), john.getFirstName(), john.getLastName(), john.getId()));
personRepository.delete(john.getCountry(), john.getFirstName(), john.getLastName(), john.getId());
System.out.println("Demonstrating deleting a record");
System.out.println(personRepository.find(john.getCountry(), john.getFirstName(), john.getLastName(), john.getId()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment