Spring Data Flashcards

1
Q

What built-in class does Spring provide that implements Pageable?

A

PageRequest

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Spring Data

What is the signature for a “derived query method”?

A

[Subject Keyword][(Optional Description]By[Predicate]

[Subject Keyword] could be:

1. Find
2. Exists
3. Count
4. Delete

[Optional Description] could be:

1. First<number>
2. Distinct

[Predicate] is composed of:

1. Class Property
2. Logical keywords
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What annotation can be used on the main configuration class to scan for domain objects defined outside of its directory or sub-directories?

A

@EntityScan(basePackages=String[])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Spring Data?

A

Spring Data is a framework for building data access applications

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a repository?

A

A repository is a data access object. It’s used to interface with a database

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a datasource/connection string?

A

A datasource is all the information an application needs to connect to a database

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can you make a repository method implement a native query?

A

Annotate the query method with @Query

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What annotation on the main configuration class can be used to scan for repositories outside of its package?

A

@EnableMongoRepositories(basePackages=String[])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the 2 steps to implement custom repositories?

A
  1. Define a custom interface and implementation
  2. Define a normal repository interface that extends both a Spring repository and the custom interface
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the relationship between @EnableAutoConfiguration and @Document?

A

@Document will be scanned for by the configuration class that is annotated with @EnableAutoConfiguration (@SpringBootApplication)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the difference between Page and Slice?

A

A Page knows about the total number of elements and pages available. It does so by the infrastructure triggering a count query to calculate the overall number. As this might be expensive (depending on the store used), you can instead return a Slice. A Slice knows only about whether a next Slice is available, which might be sufficient when walking through a larger result set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Do “query derived methods” support the use of parameters that are mapped to @DBRef fields in the domain class?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Can a “derived query method” be used to update a document?

A

Yes. For example:

@Update("{ '$set' : { 'password' : ?1 } }")
void findAndSetPasswordByEmail(String email, String password);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

True or False

“Derived query methods” annotated with @Update must return either void or a numeric type

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the difference between @DBRef and @DocumentReference?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

True or False

@Document
public class Account {

  @Id
  private ObjectId id;
  private Float total;
}

@Document
public class Person {

  @Id
  private ObjectId id;
  @Indexed
  private Integer ssn;
  @DBRef
  private List<Account> accounts;
}

The mapping framework does not handle cascading saves. If you change an Account object that is referenced by a Person object, you must save the Account object separately. Calling save on the Person object does not automatically save the Account objects in the accounts property

A

True

17
Q

What is the n + 1 problem?

A

The n + 1 problem is a data retrieval problem. It occurs when a query returns a list of resources (n), and for each resource, an additional query (1) is made. DTO projections, caching, etc. can help avoid n + 1 problems