Class AbstractStatement
java.lang.Object
org.pgcodekeeper.core.database.base.schema.AbstractStatement
- All Implemented Interfaces:
IStatement,IHashable
- Direct Known Subclasses:
ChAbstractStatement,MsAbstractStatement,PgAbstractStatement
Abstract base class for all database statements and objects.
Provides common functionality including naming, ownership, privileges, dependencies,
and metadata management. All changes to hashed fields of extending classes must be
followed by a
resetHash() call.- Author:
- Alexander Levsha
-
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a dependency to this statement.voidaddPrivilege(IPrivilege privilege) Adds a privilege to this statement.voidappendAlterComments(AbstractStatement newObj, SQLScript script) Appends ALTER comment SQL if the comment has changed.voidappendComments(SQLScript script) Appends comment SQL to the script if this statement has comments.voidappendPrivileges(SQLScript script) booleancanDrop()booleanChecks if this statement can be dropped before being recreated.booleanChecks if this statement has non-empty comments.voidRemoves all privileges from this statement.booleancompare(IStatement obj) This method does not account for nested child PgStatements.booleanDeep part ofequals(Object).final IStatementdeepCopy()PerformsIStatement.shallowCopy()on this object and all its children.final booleanCompares this object and all its children with another statement.voidfillChildrenList(List<Collection<? extends AbstractStatement>> l) voidfillDescendantsList(List<Collection<? extends AbstractStatement>> l) Gets the author of this statement.final StringGets the bare name without qualifiers or arguments.final Stream<AbstractStatement>Returns all subelements of current elementGets the comment associated with this statement.final Stream<AbstractStatement>Returns all subtree elementsfinal voidgetDropSQL(SQLScript script) Generates DROP SQL for this statement using settings from the script.voidgetDropSQL(SQLScript script, boolean generateExists) Generates DROP SQL for this statement.Gets the name of the library this statement comes from.Gets the location information for this statement.getName()Gets the name of this statement.getObjectState(boolean isNeedDepcies, SQLScript script, int startSize) Determines the object state based on changes made to the script.getObjectState(SQLScript script, int startSize) Determines the object state based on changes made to the script.getOwner()Returns owner of the objectGets the parent statement that contains this statement.Gets an unmodifiable set of privileges for this statement.Gets the fully qualified name of this statement.Gets the SQL representation of this statement with optional formatting.booleanChecks if this statement has any child statements.final inthashCode()booleanisLib()voidSets the author of this statement.voidsetComment(String comment) voidsetLibName(String libName) Sets the name of the library this statement comes from.voidsetLocation(ObjectLocation location) Sets the location information for this statement.voidvoidsetParent(AbstractStatement parent) Sets the parent statement for this statement.final AbstractStatementCopies all object properties into a new object and leaves all its children empty.toString()Methods inherited from interface org.pgcodekeeper.core.hasher.IHashable
computeHashMethods inherited from interface org.pgcodekeeper.core.database.api.schema.IStatement
appendAlterSQL, appendOwnerSQL, formatSql, getCreationSQL, getDatabase, getQuotedName, getQuoter, getRenameCommand, getStatementType, getTypeName, isOwned, quote, toObjectReference
-
Method Details
-
appendComments
Appends comment SQL to the script if this statement has comments.- Parameters:
script- the SQL script to append comments to
-
appendAlterComments
Appends ALTER comment SQL if the comment has changed.- Parameters:
newObj- the new statement to compare comments withscript- the SQL script to append ALTER comments to
-
appendPrivileges
-
getSQL
Description copied from interface:IStatementGets the SQL representation of this statement with optional formatting.- Specified by:
getSQLin interfaceIStatement- Parameters:
isFormatted- whether to apply formatting to the SQLsettings- the settings to use for SQL generation and formatting- Returns:
- the SQL string representation of this statement
-
getDropSQL
Generates DROP SQL for this statement using settings from the script.- Parameters:
script- the SQL script to append the DROP statement to
-
getDropSQL
Description copied from interface:IStatementGenerates DROP SQL for this statement.- Specified by:
getDropSQLin interfaceIStatement- Parameters:
script- the SQL script to append the DROP statement togenerateExists- whether to include "IF EXISTS" in the DROP statement
-
canDropBeforeCreate
public boolean canDropBeforeCreate()Description copied from interface:IStatementChecks if this statement can be dropped before being recreated. Override in subclasses that support drop-before-create behavior.- Specified by:
canDropBeforeCreatein interfaceIStatement- Returns:
- true if the statement can be dropped before recreation
-
getObjectState
Determines the object state based on changes made to the script.- Parameters:
script- the SQL script to check for changesstartSize- the initial size of the script before changes- Returns:
- the object state indicating the type of change
-
getObjectState
Determines the object state based on changes made to the script.- Parameters:
isNeedDepcies- whether dependencies need to be consideredscript- the SQL script to check for changesstartSize- the initial size of the script before changes- Returns:
- the object state: NOTHING if no changes, ALTER_WITH_DEP if dependencies needed, ALTER otherwise
-
canDrop
public boolean canDrop()- Specified by:
canDropin interfaceIStatement- Returns:
- true if the statement can be dropped
-
getName
Description copied from interface:IStatementGets the name of this statement.- Specified by:
getNamein interfaceIStatement- Returns:
- the statement name
-
getBareName
Description copied from interface:IStatementGets the bare name without qualifiers or arguments.- Specified by:
getBareNamein interfaceIStatement- Returns:
- Always returns just the object's name.
-
getParent
Gets the parent statement that contains this statement.- Specified by:
getParentin interfaceIStatement- Returns:
- the parent statement, or null if this is a top-level statement
-
getLocation
Description copied from interface:IStatementGets the location information for this statement.- Specified by:
getLocationin interfaceIStatement- Returns:
- the location where this statement is defined
-
setLocation
Sets the location information for this statement.- Specified by:
setLocationin interfaceIStatement- Parameters:
location- the location where this statement is defined
-
isLib
public boolean isLib()- Specified by:
isLibin interfaceIStatement- Returns:
- true if this statement is from a library
-
getLibName
Description copied from interface:IStatementGets the name of the library this statement comes from.- Specified by:
getLibNamein interfaceIStatement- Returns:
- the library name, or null if not from a library
-
setLibName
Sets the name of the library this statement comes from.- Specified by:
setLibNamein interfaceIStatement- Parameters:
libName- the library name to set
-
getAuthor
Gets the author of this statement.- Specified by:
getAuthorin interfaceIStatement- Returns:
- the author name, or null if not specified
-
setAuthor
Sets the author of this statement.- Parameters:
author- the author name to set
-
setParent
Sets the parent statement for this statement.- Parameters:
parent- the parent statement to set- Throws:
IllegalStateException- if this statement already has a parent
-
getDependencies
- Specified by:
getDependenciesin interfaceIStatement- Returns:
- all object dependencies
-
addDependency
Description copied from interface:IStatementAdds a dependency to this statement.- Specified by:
addDependencyin interfaceIStatement- Parameters:
dep- the dependency to add
-
getComment
Description copied from interface:IStatementGets the comment associated with this statement.- Specified by:
getCommentin interfaceIStatement- Returns:
- the comment, or null if no comment is set
-
checkComments
public boolean checkComments()Checks if this statement has non-empty comments.- Returns:
- true if the statement has comments
-
setComment
- Specified by:
setCommentin interfaceIStatement
-
getPrivileges
Gets an unmodifiable set of privileges for this statement.- Specified by:
getPrivilegesin interfaceIStatement- Returns:
- unmodifiable set of privileges
-
addPrivilege
Adds a privilege to this statement.- Parameters:
privilege- the privilege to add- Throws:
IllegalArgumentException- if database type is unsupported
-
clearPrivileges
public void clearPrivileges()Description copied from interface:IStatementRemoves all privileges from this statement.- Specified by:
clearPrivilegesin interfaceIStatement
-
getOwner
Description copied from interface:IStatementReturns owner of the object- Specified by:
getOwnerin interfaceIStatement
-
setOwner
- Specified by:
setOwnerin interfaceIStatement
-
getTwin
- Specified by:
getTwinin interfaceIStatement- Returns:
- an element in another db sharing the same name and location
-
getDescendants
Description copied from interface:IStatementReturns all subtree elements- Specified by:
getDescendantsin interfaceIStatement
-
getChildren
Description copied from interface:IStatementReturns all subelements of current element- Specified by:
getChildrenin interfaceIStatement
-
hasChildren
public boolean hasChildren()Checks if this statement has any child statements.- Specified by:
hasChildrenin interfaceIStatement- Returns:
- true if this statement has children, false otherwise
-
fillDescendantsList
-
fillChildrenList
-
getQualifiedName
Description copied from interface:IStatementGets the fully qualified name of this statement.- Specified by:
getQualifiedNamein interfaceIStatement- Returns:
- fully qualified (up to schema) dot-delimited object name. Identifiers are quoted.
-
getSeparator
- Specified by:
getSeparatorin interfaceIStatement
-
hashCode
public final int hashCode()CallsIHashable.computeHash(org.pgcodekeeper.core.hasher.Hasher). Modifies that value with combined hashcode of all parents of this object in the tree to complementparentNamesEquals(AbstractStatement)andequals(Object)
Caches the hashcode value until recalculation is requested viaresetHash(). Always request recalculation when you change the hashed fields.
Do actual hashing inIHashable.computeHash(org.pgcodekeeper.core.hasher.Hasher).
-
equals
Compares this object and all its children with another statement.
-
compare
This method does not account for nested child PgStatements. Shallow version ofequals(Object)- Specified by:
comparein interfaceIStatement
-
compareChildren
Deep part ofequals(Object). Compares all object's child PgStatements for equality. -
deepCopy
Description copied from interface:IStatementPerformsIStatement.shallowCopy()on this object and all its children.- Specified by:
deepCopyin interfaceIStatement- Returns:
- a fully recursive copy of this statement.
-
shallowCopy
Description copied from interface:IStatementCopies all object properties into a new object and leaves all its children empty.- Specified by:
shallowCopyin interfaceIStatement- Returns:
- shallow copy of a DB object.
-
toString
-