How could I simplify this
public interface Dao<K, S extends Key<K>> {
void update(S item);
void insert(S item);
void delete(K key);
S select(K key);
List<S> selectAll();
}
public interface Dao<K, T, S extends Key<K, T>> {
void update(S item);
void insert(S item);
void delete(K key1, T key2);
S select(K key1, T key2);
List<S> selectAll();
}
public interface Dao<K, T, I S extends Key<K, T, I>> {
void update(S item);
void insert(S item);
void delete(K key1, T key2, I key3);
S select(K key1, T key2, I key3);
List<S> selectAll();
}
49 Replies
⌛
This post has been reserved for your question.
Hey @userexit! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
Please format your code to make it more readable. For java, it should look like this:
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
P
This is not valid syntax
or actually why do you have all these 3 classes?
Is the first one not enough?
you could create a
void delete(List<? extends K> keys);
if you want a method for deleting multiple keys
and
I have a Stations table in my db that has a primary key that consists of 1 column whereas in Stops table the primary key is consisted of multiple columns
In the first one, there's no need to override the methods
in the 2., why do you want a delete method with multiple keys when you can pass a list (or at least a vararg)
why ?
Because the methods are already present in the super interface
so the child interface inherits them
So why override it?
because my primary key for the Stops table is consisted of multiple columns, 2 in this case, both integers, so then I can do:
String query = "DELETE FROM STOPS WHERE first_id = ? AND second_id = ?"
...
its a class
ah ok I overlooked that
StationsDto represents a station (data transfer object)
StationsDao connects to the database and does CRUD
In that case, make a class for the primary key
or a record
and
and then I can use the version
`
and if I have another table that needs for example 4 columns as pk i just make a new record everytime ?
@dan1st | Daniel
sounds like a good solution to me
yes
yeah
btw you can also use records for your DTOs if you want to
but can you override equals and hashcode
in a record ?
yes
but it gives you a good equals/hashCode with all components by default
So in most cases, you don't have to override it
well the only problem is how do I setup the interface now to accept StopsKey, StopsDto
or should I make StopsPK extends Key of some sort ?
wouldn't that need to be the DTO?
but like what do I put in something<T>
Why?
just do
<T,S>
unless Key
has something important
and if it's an interface, records can implement interfacesno it s just a record itself lol
?
if u do
Is there any reason to not just use
Dao<T,S>
?Dao<T, S>
ur not making sure that T is a key of some sort to S
if u do
ah
Dao<T, S extends something<T>>
ur making sure S extends Key<T>
yeah you can make an interface for that
empty interface >
?
either empty or with a
K getKey()
method
your choice
that's if you want all your DTOs to have a getKey method in commonyou meant this ?
What's
Key
?empty interface
in the end i just made a StationsPK
to keep a main program structure
I thought about
but what you did looks ok as well
can i return its parent
?
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
?
nvm was a dumb question of the moment
it was 9 am for me
So you no longer have that question?
yeah
no longer
Is that late (i.e. before going to bed) or early (after waking up)? xd
(yes that message is sarcastic)
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.