Package org.h2.engine

Class DbObject

java.lang.Object
org.h2.engine.DbObject
All Implemented Interfaces:
HasSQL
Direct Known Subclasses:
Comment, Right, RightOwner, Schema, SchemaObject, Setting

public abstract class DbObject extends Object implements HasSQL
A database object such as a table, an index, or a user.
  • Field Details

    • TABLE_OR_VIEW

      public static final int TABLE_OR_VIEW
      The object is of the type table or view.
      See Also:
    • INDEX

      public static final int INDEX
      This object is an index.
      See Also:
    • USER

      public static final int USER
      This object is a user.
      See Also:
    • SEQUENCE

      public static final int SEQUENCE
      This object is a sequence.
      See Also:
    • TRIGGER

      public static final int TRIGGER
      This object is a trigger.
      See Also:
    • CONSTRAINT

      public static final int CONSTRAINT
      This object is a constraint (check constraint, unique constraint, or referential constraint).
      See Also:
    • SETTING

      public static final int SETTING
      This object is a setting.
      See Also:
    • ROLE

      public static final int ROLE
      This object is a role.
      See Also:
    • FUNCTION_ALIAS

      public static final int FUNCTION_ALIAS
      This object is an alias for a Java function.
      See Also:
    • SCHEMA

      public static final int SCHEMA
      This object is a schema.
      See Also:
    • CONSTANT

      public static final int CONSTANT
      This object is a constant.
      See Also:
    • DOMAIN

      public static final int DOMAIN
      This object is a domain.
      See Also:
    • COMMENT

      public static final int COMMENT
      This object is a comment.
      See Also:
    • AGGREGATE

      public static final int AGGREGATE
      This object is a user-defined aggregate function.
      See Also:
    • SYNONYM

      public static final int SYNONYM
      This object is a synonym.
      See Also:
    • database

      protected Database database
      The database.
    • trace

      protected Trace trace
      The trace module.
    • comment

      protected String comment
      The comment (if set).
    • id

      private int id
    • objectName

      private String objectName
    • modificationId

      private long modificationId
    • temporary

      private boolean temporary
  • Constructor Details

    • DbObject

      protected DbObject(Database db, int objectId, String name, int traceModuleId)
      Initialize some attributes of this object.
      Parameters:
      db - the database
      objectId - the object id
      name - the name
      traceModuleId - the trace module id
  • Method Details

    • setModified

      public final void setModified()
      Tell the object that is was modified.
    • getModificationId

      public final long getModificationId()
    • setObjectName

      protected final void setObjectName(String name)
    • getSQL

      public String getSQL(int sqlFlags)
      Description copied from interface: HasSQL
      Get the SQL statement of this expression. This may not always be the original SQL statement, specially after optimization.
      Specified by:
      getSQL in interface HasSQL
      Parameters:
      sqlFlags - formatting flags
      Returns:
      the SQL statement
    • getSQL

      public StringBuilder getSQL(StringBuilder builder, int sqlFlags)
      Description copied from interface: HasSQL
      Appends the SQL statement of this object to the specified builder.
      Specified by:
      getSQL in interface HasSQL
      Parameters:
      builder - string builder
      sqlFlags - formatting flags
      Returns:
      the specified string builder
    • getChildren

      public ArrayList<DbObject> getChildren()
      Get the list of dependent children (for tables, this includes indexes and so on).
      Returns:
      the list of children, or null
    • getDatabase

      public final Database getDatabase()
      Get the database.
      Returns:
      the database
    • getId

      public final int getId()
      Get the unique object id.
      Returns:
      the object id
    • getName

      public final String getName()
      Get the name.
      Returns:
      the name
    • invalidate

      protected void invalidate()
      Set the main attributes to null to make sure the object is no longer used.
    • isValid

      public final boolean isValid()
    • getCreateSQLForCopy

      public abstract String getCreateSQLForCopy(Table table, String quotedName)
      Build a SQL statement to re-create the object, or to create a copy of the object with a different name or referencing a different table
      Parameters:
      table - the new table
      quotedName - the quoted name
      Returns:
      the SQL statement
    • getCreateSQLForMeta

      public String getCreateSQLForMeta()
      Construct the CREATE ... SQL statement for this object for meta table.
      Returns:
      the SQL statement
    • getCreateSQL

      public abstract String getCreateSQL()
      Construct the CREATE ... SQL statement for this object.
      Returns:
      the SQL statement
    • getDropSQL

      public String getDropSQL()
      Construct a DROP ... SQL statement for this object.
      Returns:
      the SQL statement
    • getType

      public abstract int getType()
      Get the object type.
      Returns:
      the object type
    • removeChildrenAndResources

      public abstract void removeChildrenAndResources(SessionLocal session)
      Delete all dependent children objects and resources of this object.
      Parameters:
      session - the session
    • checkRename

      public void checkRename()
      Check if renaming is allowed. Does nothing when allowed.
    • rename

      public void rename(String newName)
      Rename the object.
      Parameters:
      newName - the new name
    • isTemporary

      public boolean isTemporary()
      Check if this object is temporary (for example, a temporary table).
      Returns:
      true if is temporary
    • setTemporary

      public void setTemporary(boolean temporary)
      Tell this object that it is temporary or not.
      Parameters:
      temporary - the new value
    • setComment

      public void setComment(String comment)
      Change the comment of this object.
      Parameters:
      comment - the new comment, or null for no comment
    • getComment

      public String getComment()
      Get the current comment of this object.
      Returns:
      the comment, or null if not set
    • toString

      public String toString()
      Overrides:
      toString in class Object