Skip to content

Commit

Permalink
Add ConstraintNameAware and ConstraintsAware
Browse files Browse the repository at this point in the history
  • Loading branch information
mfvanek committed Nov 15, 2024
1 parent 9182714 commit 89d971d
Show file tree
Hide file tree
Showing 35 changed files with 126 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public enum Diagnostic implements CheckTypeAware {
}

/**
* Gets the place where the diagnostic should be executed.
* Retrieves the place where the diagnostic should be executed.
*
* @return {@code ExecutionTopology}
*/
Expand All @@ -117,7 +117,7 @@ public ExecutionTopology getExecutionTopology() {
}

/**
* Gets the associated sql query file name.
* Retrieves the associated sql query file name.
*
* @return sql query file name
*/
Expand All @@ -127,7 +127,7 @@ public String getSqlQueryFileName() {
}

/**
* Gets the lambda which executes the associated sql query.
* Retrieves the lambda which executes the associated sql query.
*
* @return {@code QueryExecutor}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public interface DiagnosticAware {

/**
* Gets the diagnostic - a rule related to the check.
* Retrieves the diagnostic - a rule related to the check.
*
* @return diagnostic
* @see Diagnostic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public interface RawTypeAware<T extends DbObject> {

/**
* Gets original java type.
* Retrieves original java type.
*
* @return java type representing database object
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public interface StatisticsAware {
boolean resetStatistics();

/**
* Gets time at which database statistics were last reset.
* Retrieves the time at which database statistics were last reset.
*
* @return {@code Optional} of null or time at which database statistics were last reset.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public interface StatisticsMaintenanceOnHost extends StatisticsAware, HostAware
boolean resetStatistics();

/**
* Gets time at which database statistics were last reset on current host.
* Retrieves the time at which database statistics were last reset on current host.
*
* @return {@code Optional} of null or time at which database statistics were last reset.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private ConnectionCredentials(@Nonnull final Collection<String> connectionUrls,
}

/**
* Gets a set of connection strings for accessing all hosts in the database cluster.
* Retrieves a set of connection strings for accessing all hosts in the database cluster.
*
* @return connection urls
*/
Expand All @@ -54,7 +54,7 @@ public Collection<String> getConnectionUrls() {
}

/**
* Gets the name of the user to connect to the database.
* Retrieves the name of the user to connect to the database.
*
* @return the name of the user
*/
Expand All @@ -64,7 +64,7 @@ public String getUserName() {
}

/**
* Gets the user's password for connecting to the database.
* Retrieves the user's password for connecting to the database.
*
* @return the user's password
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
public interface HighAvailabilityPgConnection {

/**
* Gets connection to a primary host in the cluster.
* Retrieves connection to a primary host in the cluster.
*
* @return {@code PgConnection} to a primary host in the cluster
*/
@Nonnull
PgConnection getConnectionToPrimary();

/**
* Gets connections to all hosts in the cluster (including a connection to a primary host).
* Retrieves connections to all hosts in the cluster (including a connection to a primary host).
*
* @return {@code Set} of connections to all hosts in target cluster
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public interface HostAware {

/**
* Gets information about host in the cluster.
* Retrieves information about host in the cluster.
*
* @return {@code PgHost}
* @see PgHost
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public interface PgConnection extends HostAware {

/**
* Gets a standard {@code DataSource} object to access the database.
* Retrieves a standard {@code DataSource} object to access the database.
*
* @return {@code DataSource}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@
public interface PgHost {

/**
* Gets a valid connection string to this host.
* Retrieves a valid connection string to this host.
*
* @return connection url to the host
*/
@Nonnull
String getPgUrl();

/**
* Gets the name of this host.
* Retrieves the name of this host.
*
* @return host name
*/
@Nonnull
String getName();

/**
* Gets the port of this host.
* Retrieves the port of this host.
*
* @return port
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
public interface BloatAware {

/**
* Gets bloat amount in bytes.
* Retrieves bloat amount in bytes.
*
* @return bloat amount
*/
long getBloatSizeInBytes();

/**
* Gets bloat percentage (in the range from 0 to 100 inclusive).
* Retrieves bloat percentage (in the range from 0 to 100 inclusive).
*
* @return bloat percentage
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
public interface DbObject {

/**
* Gets database object name.
* Retrieves database object name.
*
* @return database object name
*/
@Nonnull
String getName();

/**
* Gets database object type.
* Retrieves database object type.
*
* @return database object type
* @since 0.13.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public interface ColumnNameAware extends TableNameAware {

/**
* Gets column name in the table.
* Retrieves column name in the table.
*
* @return column name
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public boolean isNotNull() {
}

/**
* Gets raw type of serial column.
* Retrieves raw type of serial column.
*
* @return type of serial column
*/
Expand All @@ -97,7 +97,7 @@ public SerialType getSerialType() {
}

/**
* Gets name of the associated sequence.
* Retrieves name of the associated sequence.
*
* @return name of the associated sequence
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public String toString() {
}

/**
* Gets {@code SerialType} from PostgreSQL serial column type.
* Retrieves {@code SerialType} from PostgreSQL serial column type.
*
* @param pgColumnType PostgreSQL serial column type; should be non-null.
* @return {@code SerialType}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @since 0.11.0
*/
@Immutable
public class Constraint implements DbObject, TableNameAware {
public class Constraint implements DbObject, TableNameAware, ConstraintNameAware {

private final String tableName;
private final String constraintName;
Expand Down Expand Up @@ -78,17 +78,16 @@ public String getTableName() {
}

/**
* Gets the name of constraint.
*
* @return the name of constraint
* {@inheritDoc}
*/
@Nonnull
@Override
public String getConstraintName() {
return constraintName;
}

/**
* Gets type of constraint.
* Retrieves type of constraint.
*
* @return type of constraint
* @see ConstraintType
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2019-2024. Ivan Vakhrushev and others.
* https://github.com/mfvanek/pg-index-health
*
* This file is a part of "pg-index-health" - a Java library for
* analyzing and maintaining indexes health in PostgreSQL databases.
*
* Licensed under the Apache License 2.0
*/

package io.github.mfvanek.pg.model.constraint;

import javax.annotation.Nonnull;

/**
* Represents an entity that is aware of a database constraint name.
* Classes implementing this interface should provide the name of a specific database constraint.
*
* @author Ivan Vakhrushev
* @since 0.13.3
*/
public interface ConstraintNameAware {

/**
* Retrieves the name of the database constraint associated with this entity.
*
* @return the name of the constraint as a non-null {@link String}.
*/
@Nonnull
String getConstraintName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public enum ConstraintType {
}

/**
* Gets internal PostgreSQL constraint type.
* Retrieves internal PostgreSQL constraint type.
*
* @return pgConType
*/
Expand All @@ -48,7 +48,7 @@ public String getPgConType() {
}

/**
* Gets {@code ConstraintType} from internal PostgreSQL constraint type.
* Retrieves {@code ConstraintType} from internal PostgreSQL constraint type.
*
* @param pgConType internal PostgreSQL constraint type; should be non-null.
* @return {@code ConstraintType}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2019-2024. Ivan Vakhrushev and others.
* https://github.com/mfvanek/pg-index-health
*
* This file is a part of "pg-index-health" - a Java library for
* analyzing and maintaining indexes health in PostgreSQL databases.
*
* Licensed under the Apache License 2.0
*/

package io.github.mfvanek.pg.model.constraint;

import java.util.List;
import javax.annotation.Nonnull;

/**
* Represents an entity that is aware of database constraints.
* Classes implementing this interface should provide access to a list of associated constraints.
*
* @author Ivan Vakhrushev
* @since 0.13.3
*/
public interface ConstraintsAware {

/**
* Retrieves the list of database constraints associated with this entity.
*
* @return a list of {@link Constraint} objects. The list may be empty but will never be {@code null}.
*/
@Nonnull
List<Constraint> getConstraints();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @since 0.13.1
*/
@Immutable
public class DuplicatedForeignKeys implements DbObject, TableNameAware {
public class DuplicatedForeignKeys implements DbObject, TableNameAware, ConstraintsAware {

private final List<ForeignKey> foreignKeys;
private final List<String> foreignKeysNames;
Expand Down Expand Up @@ -72,7 +72,7 @@ public String getTableName() {
}

/**
* Gets duplicated foreign keys.
* Retrieves duplicated foreign keys.
*
* @return list of duplicated foreign keys
* @see ForeignKey
Expand All @@ -82,6 +82,15 @@ public List<ForeignKey> getForeignKeys() {
return foreignKeys;
}

/**
* {@inheritDoc}
*/
@Override
@Nonnull
public List<Constraint> getConstraints() {
return List.copyOf(getForeignKeys());
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private ForeignKey(@Nonnull final String tableName,
}

/**
* Gets columns of foreign key constraint.
* Retrieves columns of foreign key constraint.
*
* @return columns of foreign key constraint
* @see Column
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public final PgObjectType getObjectType() {
}

/**
* Gets procedure/function name.
* Retrieves procedure/function name.
*
* @return returns procedure/function name
*/
Expand All @@ -65,7 +65,7 @@ public String getFunctionName() {
}

/**
* Gets procedure/function arguments.
* Retrieves procedure/function arguments.
*
* @return returns procedure/function arguments or empty string
*/
Expand Down
Loading

0 comments on commit 89d971d

Please sign in to comment.