Commit c4aa333d authored by Ondřej Pavlica's avatar Ondřej Pavlica
Browse files

Add javadoc comments

parent ec49bb56
......@@ -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);
}
......@@ -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)
......
......@@ -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);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment