-
Notifications
You must be signed in to change notification settings - Fork 251
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
Implement selective update for HostAgentBean and add unit tests #1770
base: master
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.
lgtm
public void updateChanged(String hostId, HostAgentBean oldBean, HostAgentBean newBean) | ||
throws SQLException { | ||
SetClause setClause = | ||
oldBean == null ? newBean.genSetClause() : newBean.genChangedSetClause(oldBean); | ||
String clause = String.format(UPDATE_HOST_BY_ID, setClause.getClause()); | ||
setClause.addValue(id); | ||
setClause.addValue(hostId); |
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.
passing the hostId
as a parameter while it's already contained in both beans is a bit weird, but I guess it can serve as outlining how special that field is ?
I can't tell if I like it or hate it, so I'm ok with status quo.
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.
Looks like a good optimization
This pull request includes several changes to the
deploy-service
module, focusing on updating theHostAgentBean
class and related components to support partial updates. The most important changes include adding a new method to generate a set clause for changed fields, modifying theHostAgentDAO
andDBHostAgentDAOImpl
classes to use this new method, and updating thePingHandler
class to utilize these changes. Additionally, a new test class forHostAgentBean
has been added.Enhancements to
HostAgentBean
:deploy-service/common/src/main/java/com/pinterest/deployservice/bean/HostAgentBean.java
: AddedtoBuilder = true
to the@Builder
annotation and introduced thegenChangedSetClause
method to generate a set clause for only the changed fields. Also added theaddChangedColumn
helper method. [1] [2]Updates to DAO classes:
deploy-service/common/src/main/java/com/pinterest/deployservice/dao/HostAgentDAO.java
: Added theupdateChanged
method to update only the non-null changed fields of aHostAgentBean
.deploy-service/common/src/main/java/com/pinterest/deployservice/db/DBHostAgentDAOImpl.java
: Modified theupdate
method to use the newgenChangedSetClause
method and renamed it toupdateChanged
to reflect the new functionality.Changes to
PingHandler
:deploy-service/common/src/main/java/com/pinterest/deployservice/handler/PingHandler.java
: Removed unused DAO fields and updated theupdateHostStatus
method to use the newupdateChanged
method inHostAgentDAO
. [1] [2] [3] [4] [5] [6]New test class:
deploy-service/common/src/test/java/com/pinterest/deployservice/bean/HostAgentBeanTest.java
: Added a new test class to verify the functionality of thegenChangedSetClause
method.These changes improve the efficiency of updates to
HostAgentBean
by ensuring that only the modified fields are updated in the database.