Interface BasicDatabase

    • Method Detail

      • drop

        void drop()
      • newDocument

        MutableDocument newDocument​(String typeName)
        Creates a new document of type typeName. The type must be defined beforehand in the schema. The returned document only lives in memory until the method MutableDocument.save() is executed.
        Parameters:
        typeName - Type name defined in the schema
        Returns:
        The new document as a MutableDocument object.
      • newVertex

        MutableVertex newVertex​(String typeName)
        Creates a new vertex of type typeName. The type must be defined beforehand in the schema. The returned vertex only lives in memory until the method MutableVertex.save() is executed.
        Parameters:
        typeName - Type name defined in the schema
        Returns:
        The new vertex as a MutableVertex object.
      • isTransactionActive

        boolean isTransactionActive()
        Returns true if there is a transaction active. A transaction is active if it is in the following states: `{BEGUN, COMMIT_1ST_PHASE, COMMIT_2ND_PHASE}`.
      • transaction

        void transaction​(BasicDatabase.TransactionScope txBlock)
        Executes a lambda in the transaction scope. If there is an active transaction, then the current transaction is temporarily parked and a new sub-transaction is begun. In case an exception is thrown inside the lambda method, the transaction is rolled back.
        Parameters:
        txBlock - Transaction lambda to execute
      • transaction

        boolean transaction​(BasicDatabase.TransactionScope txBlock,
                            boolean joinCurrentTx)
        Executes a lambda in the transaction scope. If there is an active transaction, then the current transaction is temporarily parked and a new sub-transaction is begun. In case an exception is thrown inside the lambda method, the transaction is rolled back. If joinCurrentTx is true, otherwise the current active transaction is joined.
        Parameters:
        txBlock - Transaction lambda to execute
        joinCurrentTx - if active joins the current transaction, otherwise always create a new one
        Returns:
        true if a new transaction has been created or false if an existent transaction has been joined
      • transaction

        boolean transaction​(BasicDatabase.TransactionScope txBlock,
                            boolean joinCurrentTx,
                            int retries)
        Executes a lambda in the transaction scope. If there is an active transaction, then the current transaction is temporarily parked and a new sub-transaction is begun. In case an exception is thrown inside the lambda method, the transaction is rolled back. If joinCurrentTx is true, otherwise the current active transaction is joined. The difference with the method transaction(TransactionScope) is that in case the NeedRetryException exception is thrown, the transaction is re-executed for a number of retries.
        Parameters:
        txBlock - Transaction lambda to execute
        joinCurrentTx - if active joins the current transaction, otherwise always create a new one
        retries - number of retries in case the NeedRetryException exception is thrown
        Returns:
        true if a new transaction has been created or false if an existent transaction has been joined
      • transaction

        boolean transaction​(BasicDatabase.TransactionScope txBlock,
                            boolean joinCurrentTx,
                            int attempts,
                            OkCallback ok,
                            ErrorCallback error)
        Executes a lambda in the transaction scope. If there is an active transaction, then the current transaction is parked and a new sub-transaction is begun if joinCurrentTx is true, otherwise the current active transaction is joined. The difference with the method transaction(TransactionScope) is that in case the NeedRetryException exception is thrown, the transaction is re-executed for a number of retries.
        Parameters:
        txBlock - Transaction lambda to execute
        joinCurrentTx - if active joins the current transaction, otherwise always create a new one
        attempts - number of attempts in case the NeedRetryException exception is thrown
        ok - callback invoked if the transaction completes the commit
        error - callback invoked if the transaction cannot complete the commit, after the rollback
        Returns:
        true if a new transaction has been created or false if an existent transaction has been joined
      • begin

        void begin()
        Begins a new transaction. If a transaction is already begun, the current transaction is parked and a new sub-transaction is begun. The new sub-transaction does not access to the content of the previous transaction. Sub transactions are totally isolated.
      • begin

        void begin​(Database.TRANSACTION_ISOLATION_LEVEL isolationLevel)
        Begins a new transaction specifying the isolation level. If a transaction is already begun, the current transaction is parked and a new sub-transaction is begun. The new sub-transaction does not access to the content of the previous transaction. Sub transactions are totally isolated.
        Parameters:
        isolationLevel - Isolation level between the following: READ_COMMITTED, REPEATABLE_READ, SERIALIZABLE
      • commit

        void commit()
        Commits the current transaction. If it was a sub-transaction, then the previous in the stack becomes active again.
      • rollback

        void rollback()
        Rolls back the current transaction. If it was a sub-transaction, then the previous in the stack becomes active again.
      • lookupByRID

        Record lookupByRID​(RID rid,
                           boolean loadContent)
        Looks up for a record by its @RID (record id). If #loadContent is true, the content is immediately loaded, otherwise the content will be loaded at the first attempt to access to its content.
        Parameters:
        rid -
        loadContent - true to load the record content immediately, otherwise the content will be loaded at the first attempt to access to its content
        Returns:
        The record found
        Throws:
        RecordNotFoundException - If the record is not found
      • existsRecord

        boolean existsRecord​(RID rid)
        Checks if the record exists.
        Parameters:
        rid - – @RID record id
        Returns:
        true if the record exists, otherwise false
      • deleteRecord

        void deleteRecord​(Record record)
        Deletes a record. The actual deletion will be effective only at transaction commit time. This operation is not allowed in databases open in read-only mode.
        Parameters:
        record - The record to delete
      • command

        ResultSet command​(String language,
                          String query,
                          ContextConfiguration configuration,
                          Object... args)
        Executes a command by specifying the language and an optional variable array of arguments.
        Parameters:
        language - The language to use between the supported ones ("sql", "gremlin", "cypher", "graphql", "mongo", etc.)
        query - The command to be interpreted in the specified language as a string
        configuration - Configuration to use. When executed from a server, the server configuration is used. If null, an empty configuration will be used
        args - Arguments to pass to the command as a map of name/values.
        Returns:
        The ResultSet object containing the result of the operation if succeeded, otherwise a runtime exception is thrown
      • command

        ResultSet command​(String language,
                          String query,
                          Object... args)
        Executes a command by specifying the language and an optional variable array of arguments.
        Parameters:
        language - The language to use between the supported ones ("sql", "gremlin", "cypher", "graphql", "mongo", etc.)
        query - The command to be interpreted in the specified language as a string
        args - (optional) Arguments to pass to the command as a variable length array
        Returns:
        The ResultSet object containing the result of the operation if succeeded, otherwise a runtime exception is thrown
      • query

        ResultSet query​(String language,
                        String query,
                        Object... args)
        Executes a query as an idempotent (read only) command by specifying the language and an optional variable array of arguments.
        Parameters:
        language - The language to use between the supported ones ("sql", "gremlin", "cypher", "graphql", "mongo", etc.)
        query - The command to be interpreted in the specified language as a string
        args - (optional) Arguments to pass to the command as a variable length array
        Returns:
        The ResultSet object containing the result of the operation if succeeded, otherwise a runtime exception is thrown
      • countType

        long countType​(String typeName,
                       boolean polymorphic)
        Returns the number of record contained in all the buckets defined by a type. This operation is expensive because it scans all the entire buckets.
        Parameters:
        typeName - The name of the type
        polymorphic - true if the records of all the subtypes must be included, otherwise only the records strictly contained in the #typeName will be scanned
        Returns:
        The number of records found
      • countBucket

        long countBucket​(String bucketName)
        Returns the number of record contained in a bucket. This operation is expensive because it scans the entire bucket.
        Parameters:
        bucketName - The name of the bucket
        Returns:
        The number of records found
      • getStats

        Map<String,​Object> getStats()
        Returns statistics for the current database instance as a map.