Created
April 15, 2018 19:25
-
-
Save lankydan/85780b17f207d143de04f0b5ec091910 to your computer and use it in GitHub Desktop.
Datastax driver - application with repository example usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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