Skip to content

Commit

Permalink
refactor: update database
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
  • Loading branch information
otaviojava committed Mar 2, 2024
1 parent 386125b commit c1646f8
Show file tree
Hide file tree
Showing 24 changed files with 73 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* It is the state of column queries, with a condition and a value, as a {@link Column},
* where both combined define a predicate.
*
* @see ColumnManager#select(ColumnQuery)
* @see DatabaseManager#select(ColumnQuery)
* @see Condition
*/
public final class ColumnCondition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* A unit that has the columnFamily and condition to delete from conditions.
* This instance will be used on:
* <p>{@link ColumnManager#delete(ColumnDeleteQuery)}</p>
* <p>{@link DatabaseManager#delete(ColumnDeleteQuery)}</p>
*/
public interface ColumnDeleteQuery {

Expand Down Expand Up @@ -260,7 +260,7 @@ interface ColumnDeleteNotCondition extends ColumnDeleteNameCondition {
/**
* The last step to the build of {@link ColumnDeleteQuery}.
* It either can return a new {@link ColumnDeleteQuery} instance or execute a query with
* {@link ColumnManager}
* {@link DatabaseManager}
*/
interface ColumnDeleteQueryBuild {

Expand All @@ -272,12 +272,12 @@ interface ColumnDeleteQueryBuild {
ColumnDeleteQuery build();

/**
* executes the {@link ColumnManager#delete(ColumnDeleteQuery)}
* executes the {@link DatabaseManager#delete(ColumnDeleteQuery)}
*
* @param manager the entity manager
* @throws NullPointerException when manager is null
*/
void delete(ColumnManager manager);
void delete(DatabaseManager manager);

}

Expand Down Expand Up @@ -369,13 +369,13 @@ interface ColumnDeleteQueryBuilder {
ColumnDeleteQuery build();

/**
* executes the {@link ColumnManager#delete(ColumnDeleteQuery)}
* executes the {@link DatabaseManager#delete(ColumnDeleteQuery)}
*
* @param manager the entity manager
* @throws NullPointerException when manager is null
* @throws IllegalStateException It returns a state exception when an element is not valid or not fill-up,
* such as the {@link ColumnDeleteQueryBuilder#from(String)} method was not called.
*/
void delete(ColumnManager manager);
void delete(DatabaseManager manager);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public final class ColumnPreparedStatement {

private final Duration duration;

private final ColumnManager manager;
private final DatabaseManager manager;

private ColumnPreparedStatement(ColumnEntity entity,
ColumnQuery columnQuery,
Expand All @@ -60,7 +60,7 @@ private ColumnPreparedStatement(ColumnEntity entity,
String query,
List<String> paramsLeft,
Duration duration,
ColumnManager manager) {
DatabaseManager manager) {
this.entity = entity;
this.columnQuery = columnQuery;
this.columnDeleteQuery = columnDeleteQuery;
Expand Down Expand Up @@ -149,7 +149,7 @@ static ColumnPreparedStatement select(
ColumnQuery columnQuery,
Params params,
String query,
ColumnManager manager) {
DatabaseManager manager) {
return new ColumnPreparedStatement(null, columnQuery,
null, PreparedStatementType.SELECT, params, query,
params.getParametersNames(), null, manager);
Expand All @@ -159,7 +159,7 @@ static ColumnPreparedStatement select(
static ColumnPreparedStatement delete(ColumnDeleteQuery columnDeleteQuery,
Params params,
String query,
ColumnManager manager) {
DatabaseManager manager) {

return new ColumnPreparedStatement(null, null,
columnDeleteQuery, PreparedStatementType.DELETE, params, query,
Expand All @@ -171,7 +171,7 @@ static ColumnPreparedStatement insert(ColumnEntity entity,
Params params,
String query,
Duration duration,
ColumnManager manager) {
DatabaseManager manager) {
return new ColumnPreparedStatement(entity, null,
null, PreparedStatementType.INSERT, params, query,
params.getParametersNames(), duration, manager);
Expand All @@ -181,7 +181,7 @@ static ColumnPreparedStatement insert(ColumnEntity entity,
static ColumnPreparedStatement update(ColumnEntity entity,
Params params,
String query,
ColumnManager manager) {
DatabaseManager manager) {
return new ColumnPreparedStatement(entity, null,
null, PreparedStatementType.UPDATE, params, query,
params.getParametersNames(), null, manager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/**
* Class that contains information to do a select to {@link ColumnEntity}
*
* @see ColumnManager#select(ColumnQuery)
* @see DatabaseManager#select(ColumnQuery)
* @see ColumnCondition
* @see Sort
*/
Expand Down Expand Up @@ -265,7 +265,7 @@ interface ColumnOrder {
/**
* The last step to the build of {@link ColumnQuery}.
* It either can return a new {@link ColumnQuery} instance or execute a query with
* {@link ColumnManager}
* {@link DatabaseManager}
*/
interface ColumnQueryBuild {

Expand All @@ -277,22 +277,22 @@ interface ColumnQueryBuild {
ColumnQuery build();

/**
* Executes {@link ColumnManager#select(ColumnQuery)}
* Executes {@link DatabaseManager#select(ColumnQuery)}
*
* @param manager the entity manager
* @return the result of {@link ColumnManager#select(ColumnQuery)}
* @return the result of {@link DatabaseManager#select(ColumnQuery)}
* @throws NullPointerException when manager is null
*/
Stream<ColumnEntity> getResult(ColumnManager manager);
Stream<ColumnEntity> getResult(DatabaseManager manager);

/**
* Executes {@link ColumnManager#singleResult(ColumnQuery)}
* Executes {@link DatabaseManager#singleResult(ColumnQuery)}
*
* @param manager the entity manager
* @return the result of {@link ColumnManager#singleResult(ColumnQuery)}
* @return the result of {@link DatabaseManager#singleResult(ColumnQuery)}
* @throws NullPointerException when manager is null
*/
Optional<ColumnEntity> getSingleResult(ColumnManager manager);
Optional<ColumnEntity> getSingleResult(DatabaseManager manager);

}

Expand Down Expand Up @@ -599,25 +599,25 @@ interface ColumnQueryBuilder {
ColumnQuery build();

/**
* Executes {@link ColumnManager#select(ColumnQuery)}
* Executes {@link DatabaseManager#select(ColumnQuery)}
*
* @param manager the entity manager
* @return the result of {@link ColumnManager#select(ColumnQuery)}
* @return the result of {@link DatabaseManager#select(ColumnQuery)}
* @throws NullPointerException when manager is null
* @throws IllegalStateException It returns a state exception when an element is not valid or not fill-up,
* such as the {@link ColumnQueryBuilder#from(String)} method was not called.
*/
Stream<ColumnEntity> getResult(ColumnManager manager);
Stream<ColumnEntity> getResult(DatabaseManager manager);

/**
* Executes {@link ColumnManager#singleResult(ColumnQuery)}
* Executes {@link DatabaseManager#singleResult(ColumnQuery)}
*
* @param manager the entity manager
* @return the result of {@link ColumnManager#singleResult(ColumnQuery)}
* @return the result of {@link DatabaseManager#singleResult(ColumnQuery)}
* @throws NullPointerException when manager is null
* @throws IllegalStateException It returns a state exception when an element is not valid or not fill-up,
* such as the {@link ColumnQueryBuilder#from(String)} method was not called.
*/
Optional<ColumnEntity> getSingleResult(ColumnManager manager);
Optional<ColumnEntity> getSingleResult(DatabaseManager manager);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.stream.Stream;

/**
* A query parser to column database type, this class will convert a String to an operation in {@link ColumnManager}.
* A query parser to column database type, this class will convert a String to an operation in {@link DatabaseManager}.
*/
public final class ColumnQueryParser {

Expand All @@ -43,7 +43,7 @@ public final class ColumnQueryParser {
* @throws IllegalArgumentException when the query has value parameters
* @throws QueryException when there is error in the syntax
*/
public Stream<ColumnEntity> query(String query, ColumnManager manager, ColumnObserverParser observer) {
public Stream<ColumnEntity> query(String query, DatabaseManager manager, ColumnObserverParser observer) {
validation(query, manager, observer);
String command = query.substring(0, 6);
return switch (command) {
Expand All @@ -68,7 +68,7 @@ public Stream<ColumnEntity> query(String query, ColumnManager manager, ColumnObs
* @throws IllegalArgumentException when the query has value parameters
* @throws QueryException when there is error in the syntax
*/
public ColumnPreparedStatement prepare(String query, ColumnManager manager, ColumnObserverParser observer) {
public ColumnPreparedStatement prepare(String query, DatabaseManager manager, ColumnObserverParser observer) {
validation(query, manager, observer);
String command = query.substring(0, 6);

Expand All @@ -83,7 +83,7 @@ public ColumnPreparedStatement prepare(String query, ColumnManager manager, Colu
}


private void validation(String query, ColumnManager manager, ColumnObserverParser observer) {
private void validation(String query, DatabaseManager manager, ColumnObserverParser observer) {
Objects.requireNonNull(query, "query is required");
Objects.requireNonNull(manager, "manager is required");
Objects.requireNonNull(observer, "manager is observer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,35 @@
* It is a function that reads from {@link Settings} and then creates a manager factory instance.
* It should return a {@link NullPointerException} when the {@link Settings} parameter is null.
*
* @see ColumnManagerFactory
* @see ColumnManager
* @see DatabaseManagerFactory
* @see DatabaseManager
*/
public interface ColumnConfiguration extends Function<Settings, ColumnManagerFactory> {
public interface DatabaseConfiguration extends Function<Settings, DatabaseManagerFactory> {


/**
* creates and returns a {@link ColumnConfiguration} instance from {@link ServiceLoader}
* creates and returns a {@link DatabaseConfiguration} instance from {@link ServiceLoader}
*
* @param <T> the configuration type
* @return {@link ColumnConfiguration} instance
* @return {@link DatabaseConfiguration} instance
*/
static <T extends ColumnConfiguration> T getConfiguration() {
return (T) ServiceLoader.load(ColumnConfiguration.class)
static <T extends DatabaseConfiguration> T getConfiguration() {
return (T) ServiceLoader.load(DatabaseConfiguration.class)
.stream()
.map(ServiceLoader.Provider::get)
.findFirst().orElseThrow(() -> new CommunicationException("No ColumnConfiguration implementation found!"));
}

/**
* creates and returns a {@link ColumnConfiguration} instance from {@link ServiceLoader}
* creates and returns a {@link DatabaseConfiguration} instance from {@link ServiceLoader}
* for a particular provider implementation.
*
* @param <T> the configuration type
* @param type the particular provider
* @return {@link ColumnConfiguration} instance
* @return {@link DatabaseConfiguration} instance
*/
static <T extends ColumnConfiguration> T getConfiguration(Class<T> type) {
return (T) ServiceLoader.load(ColumnConfiguration.class)
static <T extends DatabaseConfiguration> T getConfiguration(Class<T> type) {
return (T) ServiceLoader.load(DatabaseConfiguration.class)
.stream()
.map(ServiceLoader.Provider::get)
.filter(type::isInstance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
*
* @see ColumnEntity
*/
public interface ColumnManager extends AutoCloseable {
public interface DatabaseManager extends AutoCloseable {

/**
* Returns the database's name of this {@link ColumnManager}
* Returns the database's name of this {@link DatabaseManager}
*
* @return the database's name
*/
Expand All @@ -59,7 +59,7 @@ public interface ColumnManager extends AutoCloseable {

/**
* Updates a Column family entities, by default it's just run for each saving using
* {@link ColumnManager#update(ColumnEntity)}, each NoSQL vendor might
* {@link DatabaseManager#update(ColumnEntity)}, each NoSQL vendor might
* replace to a more appropriate one.
*
* @param entities column family to be saved
Expand All @@ -81,7 +81,7 @@ public interface ColumnManager extends AutoCloseable {

/**
* Saves a Column family entities, by default it's just run for each saving using
* {@link ColumnManager#insert(ColumnEntity)}, each NoSQL vendor might
* {@link DatabaseManager#insert(ColumnEntity)}, each NoSQL vendor might
* replace to a more appropriate one.
*
* @param entities column family to be saved
Expand All @@ -92,7 +92,7 @@ public interface ColumnManager extends AutoCloseable {

/**
* Saves a Column family entity with time to live, by default it's just run for each saving using
* {@link ColumnManager#insert(ColumnEntity, Duration)},
* {@link DatabaseManager#insert(ColumnEntity, Duration)},
* each NoSQL vendor might replace to a more appropriate one.
*
* @param entities column family to be saved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
* The manager factory instance creates a manager instance from the database name.
* It should return a {@link NullPointerException} when the {@link String} parameter is null.
*
* @see ColumnManager
* @see DatabaseManager
*/
public interface ColumnManagerFactory extends Function<String, ColumnManager>, AutoCloseable {
public interface DatabaseManagerFactory extends Function<String, DatabaseManager>, AutoCloseable {


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ public ColumnQuery build() {
}

@Override
public Stream<ColumnEntity> getResult(ColumnManager manager) {
public Stream<ColumnEntity> getResult(DatabaseManager manager) {
Objects.requireNonNull(manager, "manager is required");
return manager.select(build());
}

@Override
public Optional<ColumnEntity> getSingleResult(ColumnManager manager) {
public Optional<ColumnEntity> getSingleResult(DatabaseManager manager) {
Objects.requireNonNull(manager, "manager is required");
return manager.singleResult(build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public ColumnDeleteQuery build() {
}

@Override
public void delete(ColumnManager manager) {
public void delete(DatabaseManager manager) {
Objects.requireNonNull(manager, "manager is required");
manager.delete(build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ public ColumnQuery build() {
}

@Override
public Stream<ColumnEntity> getResult(ColumnManager manager) {
public Stream<ColumnEntity> getResult(DatabaseManager manager) {
requireNonNull(manager, "manager is required");
return manager.select(this.build());
}

@Override
public Optional<ColumnEntity> getSingleResult(ColumnManager manager) {
public Optional<ColumnEntity> getSingleResult(DatabaseManager manager) {
requireNonNull(manager, "manager is required");
return manager.singleResult(this.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public ColumnDeleteQuery build() {
}

@Override
public void delete(ColumnManager manager) {
public void delete(DatabaseManager manager) {
requireNonNull(manager, "manager is required");
manager.delete(this.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public final class DeleteQueryParser implements BiFunction<DeleteQuery, ColumnOb



Stream<ColumnEntity> query(String query, ColumnManager manager, ColumnObserverParser observer) {
Stream<ColumnEntity> query(String query, DatabaseManager manager, ColumnObserverParser observer) {

ColumnDeleteQuery deleteQuery = getQuery(query, observer);
manager.delete(deleteQuery);
return Stream.empty();
}


ColumnPreparedStatement prepare(String query, ColumnManager manager,
ColumnPreparedStatement prepare(String query, DatabaseManager manager,
ColumnObserverParser observer) {
Params params = Params.newParams();
ColumnDeleteQuery columnDeleteQuery = getQuery(query, params, observer);
Expand Down
Loading

0 comments on commit c1646f8

Please sign in to comment.