Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/main/java/org/hoverla/bibernate/action/EntityAction.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package org.hoverla.bibernate.action;

/**
* Interface for actions relating to insert/update/delete of an entity instance.
* Represents an action to be executed on an entity.
*/
public interface EntityAction {

/**
* Executes the action.
*/
void execute();

/**
* Gets the priority of the action. Actions with higher priority values will be executed first.
*
* @return the priority of the action
*/
int priority();
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
package org.hoverla.bibernate.action;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
/**
* Represents the priority of an entity action.
*/
@RequiredArgsConstructor
public enum EntityActionPriority {
INSERT(1), UPDATE(2), DELETE(3);

/**
* Represents an entity insertion action with a priority of 1.
*/
INSERT(1),

/**
* Represents an entity update action with a priority of 2.
*/
UPDATE(2),

/**
* Represents an entity deletion action with a priority of 3.
*/
DELETE(3);

/**
* The priority of the entity action.
*/
private final int priority;

/**
* Gets the priority value of this entity action.
*
* @return the priority value of this entity action
*/
public int getPriority() {
return priority;
}
}
14 changes: 14 additions & 0 deletions src/main/java/org/hoverla/bibernate/action/EntityDeleteAction.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
package org.hoverla.bibernate.action;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hoverla.bibernate.session.EntityPersister;


@Slf4j
@RequiredArgsConstructor
public class EntityDeleteAction implements EntityAction {

private final Object entity;
private final EntityPersister persister;

/**
* Deletes the entity using the entity persister.
*/
@Override
public void execute() {
log.debug("Executing EntityDeleteAction for entity: {}", entity);
persister.delete(entity);
log.debug("EntityDeleteAction completed for entity: {}", entity);
}

/**
* Gets the priority of the entity deletion action.
*
* @return the priority of the entity deletion action
*/
@Override
public int priority() {
return EntityActionPriority.DELETE.getPriority();
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/hoverla/bibernate/action/EntityInsertAction.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
package org.hoverla.bibernate.action;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hoverla.bibernate.session.EntityPersister;

@Slf4j
@RequiredArgsConstructor
public class EntityInsertAction implements EntityAction {

private final Object entity;
private final EntityPersister persister;

/**
* Inserts the entity using the entity persister.
*/
@Override
public void execute() {
log.debug("Executing EntityInsertAction for entity: {}", entity);
persister.insert(entity);
log.debug("EntityInsertAction completed for entity: {}", entity);
}

/**
* Gets the priority of the entity insertion action.
*
* @return the priority of the entity insertion action
*/
@Override
public int priority() {
return EntityActionPriority.INSERT.getPriority();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
package org.hoverla.bibernate.action;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hoverla.bibernate.session.EntityPersister;

@Slf4j
@RequiredArgsConstructor
public class EntityUpdateAction implements EntityAction {

private final Object entity;
private final EntityPersister persister;

/**
* Updates the entity using the entity persister.
*/
@Override
public void execute() {
log.debug("Executing EntityUpdateAction for entity: {}", entity);
persister.update(entity);
log.debug("EntityUpdateAction completed for entity: {}", entity);
}

/**
* Gets the priority of the entity update action.
*
* @return the priority of the entity update action
*/
@Override
public int priority() {
return EntityActionPriority.UPDATE.getPriority();
}
}
}
5 changes: 3 additions & 2 deletions src/main/java/org/hoverla/bibernate/annotation/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*
* @return column name
*/
String name();

String name() default "";
boolean unique() default false;
boolean nullable() default true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.hoverla.bibernate.annotation.relations;

public @interface JoinColumn {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.hoverla.bibernate.annotation.relations;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface ManyToMany {
String mappedBy() default "";
Class<?> targetEntity();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.hoverla.bibernate.annotation.relations;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface ManyToOne {
String mappedBy() default "";
Class<?> targetEntity();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.hoverla.bibernate.annotation.relations;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface OneToMany {
Class<?> targetEntity();
String mappedBy();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.hoverla.bibernate.annotation.relations;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
* Defines a one-to-one mapping between two entities.
*
* <p>
* This annotation is used to specify a one-to-one association
* between two entities in a JPA application. It can be
* applied to a field or a getter method.
* </p>
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface OneToOne {

/**
* The name of the inverse side of the relationship.
*
* <p>
* This element specifies the name of the field or property in the target entity that owns the relationship. This
* attribute is only used when the target entity is the owning side of the relationship.
* </p>
* @return the name of the inverse side of the relationship.
*/
String mappedBy() default "";

/**
* The target entity of the association.
* <p>
* This element specifies the entity class that is the target of the association. It is required unless the
* association is unidirectional.
* </p>
*
* @return the target entity of the association.
*/
Class<?> targetEntity();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,70 @@
* Configuration API used to configure datasource as to create SessionFactory
*/
public interface Configuration {

/**
* Gets the JDBC URL for the data source.
*
* @return the JDBC URL
*/
String getUrl();

/**
* Gets the username for the data source.
*
* @return the username
*/
String getUsername();

/**
* Gets the password for the data source.
*
* @return the password
*/
String getPassword();

/**
* Gets the JDBC driver class for the data source.
*
* @return the JDBC driver class
*/
String getDriver();

/**
* Gets the maximum number of connections to be maintained in the connection pool.
*
* @return the maximum number of connections
*/
Integer getPoolSize();

/**
* Gets the type of connection pool provider to use.
*
* @return the connection pool provider type
*/
ConnPoolProviderType getPoolProvider();

/**
* Gets the package name containing the entity classes.
*
* @return the entity package name
*/
String getEntitiesPackage();

/**
* Builds a new session factory using the provided configuration settings.
*
* @return a new session factory
*/
SessionFactory buildSessionFactory();

/**
* Returns a boolean indicating whether automatic DDL creation is enabled.
*
* @return true if automatic DDL creation is enabled, false otherwise
*/
boolean isAutoDdlCreation();

/**
* Validates the correctness of configuration object.
* Since configuration is used to initialize datasource, all properties should be non-null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@ public class DefaultConfiguration implements Configuration {
private String username;
private String password;
private String driver;
private String entityPackageToScan;
private String entitiesPackage;
private boolean autoDdlCreation;

/**
* The maximum number of connections to be maintained in the connection pool.
* The default value is 10.
*/
@Builder.Default
private Integer poolSize = 10;

/**
* The type of connection pool provider to use.
* The default value is HikariCP.
*/
@Builder.Default
private ConnPoolProviderType poolProvider = ConnPoolProviderType.HIKARI;

Expand Down
Loading