-
Notifications
You must be signed in to change notification settings - Fork 0
Persistence of shares implemented(not yet a full version) #219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One additional comment, how do we decide which storage implementation is used between the memory and postgres one?
@Inject | ||
ShareRepository shareRepository; | ||
|
||
@Inject | ||
public JdbcStorageManager(){ | ||
this.shareRepository = new ShareRepository(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use constructor based injection, also have a look at:
https://agile-lab-dev.github.io/whitefox/docs/development_guidelines
List<Share> shares = shareRepository.listAll().stream() | ||
.map(ShareMapper::shareDaoToShare) | ||
.collect(Collectors.toList()); | ||
var totalSize = shares.size(); | ||
if (offset > totalSize) { | ||
throw new InvalidPageTokenException( | ||
String.format("Invalid Next Page Token: token %s is larger than totalSize", offset)); | ||
} else { | ||
return new ResultAndTotalSize<>( | ||
shares.stream().skip(offset).limit(maxResultSize).collect(Collectors.toList()), | ||
totalSize); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This eagerly fetches all shares, it might get very slow when a lot of shares are created.
Have a look at: https://quarkus.io/guides/hibernate-orm-panache#paging
import java.util.Optional; | ||
@Entity | ||
@Table(name = "share") | ||
public class ShareDao { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can/want you can use Lombok to auto-generate some boilerplate
This is just the wip for a general structure for jdbc persistence, if this is alright I'll model all the entities that are required for persistence then make a big PR