Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Samuel Dudík
PA165 Winery Management System
Commits
c4aa333d
Commit
c4aa333d
authored
Mar 26, 2022
by
Ondřej Pavlica
Browse files
Add javadoc comments
parent
ec49bb56
Changes
3
Hide whitespace changes
Inline
Side-by-side
winery/src/main/java/cz/muni/fi/pa165/winery/persistence/dao/DaoBase.java
View file @
c4aa333d
...
...
@@ -8,9 +8,44 @@ import cz.muni.fi.pa165.winery.persistence.entities.EntityBase;
import
java.util.List
;
public
interface
DaoBase
<
Entity
extends
EntityBase
>
{
/***
* Creates a new entity in the database if it does not exist yet.
* @throws IllegalArgumentException If the entity does already exist or if null was passed into the method.
* @param entity The entity to add.
*/
void
create
(
Entity
entity
);
/***
* Returns an entity with the given ID from the database.
* @param id Primary key.
* @return An entity with the given primary key or null if the entity is not found.
*/
Entity
get
(
int
id
);
/***
* Returns all entities from the database.
* @return A list of all entities.
*/
List
<
Entity
>
getAll
();
/***
* Updates an existing entity in the database according to the supplied data.
* @throws IllegalArgumentException If the entity does not exist or if null was passed into the method.
* @param entity The entity to update.
*/
void
update
(
Entity
entity
);
/***
* Deletes the given entity from the database.
* @throws IllegalArgumentException If the entity does not exist or if null was passed into the method.
* @param entity The entity to delete.
*/
void
delete
(
Entity
entity
);
/***
* Either creates or updates the given entity in the database. This method is slower than its create and delete counterparts.
* @throws IllegalArgumentException If null was passed into the method.
* @param entity The entity to persist into the database.
*/
void
upsert
(
Entity
entity
);
}
winery/src/main/java/cz/muni/fi/pa165/winery/persistence/entities/EntityBase.java
View file @
c4aa333d
...
...
@@ -11,6 +11,10 @@ import javax.validation.constraints.NotNull;
@MappedSuperclass
public
abstract
class
EntityBase
{
/***
* The primary key in DB.
*/
@Id
@NotNull
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
...
...
winery/src/main/java/cz/muni/fi/pa165/winery/persistence/entities/UserRole.java
View file @
c4aa333d
...
...
@@ -17,11 +17,30 @@ import java.util.Objects;
@AllArgsConstructor
@Table
(
name
=
"UserRole"
)
public
class
UserRole
extends
EntityBase
{
/***
* The given user's role type.
*/
@NotNull
@Column
(
nullable
=
false
)
@Enumerated
(
EnumType
.
STRING
)
private
UserRoleType
role
;
/***
* The user to which this role type is assigned.
*/
@ManyToOne
(
fetch
=
FetchType
.
LAZY
,
optional
=
false
)
private
User
user
;
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
!(
o
instanceof
UserRole
))
return
false
;
UserRole
userRole
=
(
UserRole
)
o
;
return
role
==
userRole
.
role
&&
Objects
.
equals
(
user
,
userRole
.
user
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
role
,
user
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment