Package dev.frostlake

Class DatabaseEngine

java.lang.Object
dev.frostlake.DatabaseEngine

public class DatabaseEngine extends Object
Main Database SQL Engine Provides a complete SQL engine implementing Snowflake DB features
  • Constructor Details

    • DatabaseEngine

      public DatabaseEngine()
    • DatabaseEngine

      public DatabaseEngine(EngineConfig config)
  • Method Details

    • isDurableStatementForTesting

      public boolean isDurableStatementForTesting(String sql)
      The loggability decision, exposed so tests can assert it family by family.
    • checkpoint

      public void checkpoint()
      Write a WAL checkpoint: snapshot the full state durably, append a checkpoint marker (the atomic pivot — recovery keys off the LAST marker, so a crash before it leaves an ignored orphan snapshot), then truncate the log to the marker and drop superseded snapshots. No-op while an explicit transaction is open (its statements aren't committed yet). Safe to call explicitly; also driven by durability.checkpointInterval.
    • execute

      public ExecutionResult execute(String sql)
      Execute a SQL statement or script
    • executeQuery

      public ResultSet executeQuery(String sql)
      Execute a query and return a single result set
    • executeUpdate

      public int executeUpdate(String sql)
      Execute an update statement (INSERT, UPDATE, DELETE)
    • beginTransaction

      public void beginTransaction()
    • commit

      public void commit()
    • rollback

      public void rollback()
    • setSavepoint

      public void setSavepoint(String name)
    • rollbackToSavepoint

      public void rollbackToSavepoint(String name)
    • releaseSavepoint

      public void releaseSavepoint(String name)
    • setAutoCommit

      public void setAutoCommit(boolean autoCommit)
    • isAutoCommit

      public boolean isAutoCommit()
    • useDatabase

      public void useDatabase(String database)
    • useSchema

      public void useSchema(String schema)
    • getCurrentDatabase

      public String getCurrentDatabase()
    • getCurrentSchema

      public String getCurrentSchema()
    • showDatabases

      public ResultSet showDatabases()
    • showSchemas

      public ResultSet showSchemas()
    • showTables

      public ResultSet showTables()
    • showColumns

      public ResultSet showColumns(String tableName)
    • showViews

      public ResultSet showViews()
    • showProcedures

      public ResultSet showProcedures()
    • showFunctions

      public ResultSet showFunctions()
    • checkpointStateTo

      public void checkpointStateTo(Path dir) throws IOException
      Write this engine's complete state — every database with its schemas, tables and rows, views, sequences (at their current positions), functions, procedures, streams with pending records, tasks, stages, roles and policies — to dir, from which restoreStateFrom(Path) can rebuild an equivalent engine. Holds the engine monitor, so it is mutually exclusive with statements running on direct connections. Works regardless of persistence.enabled.
      Throws:
      IOException
    • restoreStateFrom

      public void restoreStateFrom(Path dir) throws IOException, ClassNotFoundException
      Rebuild this engine's state from a checkpointStateTo(Path) snapshot. Intended for a freshly constructed engine (the template-clone pattern: migrate once, checkpoint, boot many); restored functions and procedures recompile lazily from their stored source on first use.
      Throws:
      IOException
      ClassNotFoundException
    • cloneInstance

      public DatabaseEngine cloneInstance() throws IOException, ClassNotFoundException
      A new, fully independent engine carrying a copy of this engine's complete state — databases, schemas, tables with rows, views, sequences at their current positions, functions, procedures, streams with pending records, tasks, stages, roles and policies. Writes to either engine are invisible to the other. The copy happens entirely in memory (no filesystem involvement); use checkpointStateTo(Path) / restoreStateFrom(Path) instead when the clone must cross a process boundary — a serialized checkpoint is the only form of this engine that can.
      Throws:
      IOException
      ClassNotFoundException
    • getConfig

      public EngineConfig getConfig()
      This engine's effective configuration (read-only introspection, e.g. by embedders and tests).
    • bindJsonIndent

      public void bindJsonIndent()
      Bind the session's JSON_INDENT so displayed variants use its width for this statement. The HTTP wire binds it again while it renders a statement's rows, which happens after the statement's own scope has closed; the caller clears it with VariantJsonFormat.clearSessionScope().
    • getQueryResultCache

      public QueryResultCache getQueryResultCache()
      The query-result cache backing RESULT_SCAN and LAST_QUERY_ID.
    • getCatalog

      public Catalog getCatalog()
    • getS3PathResolver

      public S3PathResolver getS3PathResolver()
      Resolver for s3:// (and S3-backed @stage) references to local files — see S3PathResolver.
    • getExecutor

      public QueryExecutor getExecutor()
    • getStorageEngine

      public StorageEngine getStorageEngine()
    • getFunctionRegistry

      public FunctionRegistry getFunctionRegistry()
    • getTransactionManager

      public TransactionManager getTransactionManager()
    • getSystemViews

      public SystemViews getSystemViews()
    • startTaskScheduler

      public void startTaskScheduler()
    • stopTaskScheduler

      public void stopTaskScheduler()
    • getStreamManager

      public StreamManager getStreamManager()
    • getTaskScheduler

      public TaskScheduler getTaskScheduler()
    • getSecurityManager

      public SecurityManager getSecurityManager()
    • getSessionContext

      public SessionContext getSessionContext()
    • setCurrentUser

      public void setCurrentUser(String username)
    • setCurrentRole

      public void setCurrentRole(String roleName)
    • getCurrentUser

      public String getCurrentUser()
    • getCurrentRole

      public String getCurrentRole()
    • shutdown

      public void shutdown()
      Shutdown the engine and release resources