## org.h2.tools
Class MultiDimension

    java.lang.Object
      org.h2.tools.MultiDimension

    public class MultiDimension

extends java.lang.Object

A tool to help an application execute multi-dimensional range queries. The algorithm used is database independent, the only requirement is that the engine supports a range index (for example b-tree).

Method Summary
`int` `deinterleave(long scalar, int dimensions, int dim)` Gets one of the original multi-dimensional values from a scalar value.
`java.lang.String` `generatePreparedQuery(java.lang.String table, java.lang.String scalarColumn, java.lang.String[] columns)` Generates an optimized multi-dimensional range query.
`java.lang.String` `generateQuery(java.lang.String table, java.lang.String scalarColumn, java.lang.String[] columns, int[] min, int[] max)` Generates an optimized multi-dimensional range query.
`static MultiDimension` `getInstance()` Get the singleton.
`java.sql.ResultSet` `getResult(java.sql.PreparedStatement prep, int[] min, int[] max)` Executes a prepared query that was generated using generatePreparedQuery.
`long` `interleave(int[] values)` Convert the multi-dimensional value into a one-dimensional (scalar) value.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### getInstance

    public static MultiDimension getInstance()

  Get the singleton.

  Returns:
    the singleton

### interleave

    public long interleave(int[] values)

  Convert the multi-dimensional value into a one-dimensional (scalar) value. This is done by interleaving the bits of the values. Each values must be bigger or equal to 0. The maximum value is dependent on the number of dimensions. For two keys, it is 32 bit, for 3: 21 bit, 4: 16 bit, 5: 12 bit, 6: 10 bit, 7: 9 bit, 8: 8 bit.

  Parameters:
    `values` - the multi-dimensional value
  Returns:
    the scalar value

### deinterleave

    public int deinterleave(long scalar,
                            int dimensions,
                            int dim)

  Gets one of the original multi-dimensional values from a scalar value.

  Parameters:
    `scalar` - the scalar value
    `dimensions` - the number of dimensions
    `dim` - the dimension of the returned value (starting from 0)
  Returns:
    the value

### generatePreparedQuery

    public java.lang.String generatePreparedQuery(java.lang.String table,
                                                  java.lang.String scalarColumn,
                                                  java.lang.String[] columns)

  Generates an optimized multi-dimensional range query. The query contains parameters. It can only be used with the H2 database.

  Parameters:
    `table` - the table name
    `columns` - the list of columns
    `scalarColumn` - the column name of the computed scalar column
  Returns:
    the query

### getResult

    public java.sql.ResultSet getResult(java.sql.PreparedStatement prep,
                                        int[] min,
                                        int[] max)
                                 throws java.sql.SQLException

  Executes a prepared query that was generated using generatePreparedQuery.

  Parameters:
    `prep` - the prepared statement
    `min` - the lower values
    `max` - the upper values
  Returns:
    the result set
  Throws:
    `java.sql.SQLException`

### generateQuery

    public java.lang.String generateQuery(java.lang.String table,
                                          java.lang.String scalarColumn,
                                          java.lang.String[] columns,
                                          int[] min,
                                          int[] max)

  Generates an optimized multi-dimensional range query. This query is database independent, however the performance is not as good as when using generatePreparedQuery

  Parameters:
    `table` - the table name
    `columns` - the list of columns
    `min` - the lower values
    `max` - the upper values
    `scalarColumn` - the column name of the computed scalar column
  Returns:
    the query