public class TableContext extends Object
api.getTableContext()
. So if that variable goes out of scope the database is lost. Hence for reusing put it into api.global
for example.
def tableContext = api.getTableContext()
def fields1 = ["ID":DataType.LONG,
"Name":DataType.STRING,
"Value":DataType.STRING]
def fields2 = ["Name":DataType.STRING,
"Multiplier":DataType.NUMBER]
def values1 = [
["ID":1, "Name":"A", "Value":"1"],
["ID":2, "Name":"B", "Value":"2"],
["ID":3, "Name":"C", "Value":"3"]
]
def values2 = [
["Name":"A", "Multiplier":0.5],
["Name":"B", "Multiplier":2],
["Name":"C", "Multiplier":5]
]
tableContext.createTable("Table1", fields1, null)
tableContext.loadRows("Table1",values1)
tableContext.createTable("Table2", fields2, null)
tableContext.loadRows("Table2",values2)
api.trace("Tables",null,tableContext.printTablesDefinitions("%"))
api.trace("Tables 1 Count",null,tableContext.count("Table1"))
api.trace("Tables 2 Count",null,tableContext.count("Table2"))
return tableContext.executeQuery("SELECT t1.Name, Value, Multiplier FROM Table1 t1 JOIN Table2 t2 ON (t1.Name = t2.Name)").toResultMatrix()
Modifier and Type | Field and Description |
---|---|
protected Connection |
conn |
protected PersistedObjectService |
objService |
protected DMSchemaService |
schemaService |
Modifier | Constructor and Description |
---|---|
|
TableContext(FormulaEngineContext context) |
protected |
TableContext(PersistedObjectService objService,
String dbName) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
int |
count(String tableName)
Get the row count of a in-memory table
|
void |
createTable(String tableName,
Map<String,DataType> fields,
List<String> indexFields)
Creates a new in-memory table - eventually dropping an already existing table with same name - based on the passed field list
No data is loaded yet.
|
void |
createTable(String tableName,
Object input)
Creates a new in-memory table - eventually dropping an already existing table with same name
|
void |
createTableFromCustomerExtension(String tableName,
String cxName,
Collection<String> fields)
Creates a new in-memory table - eventually dropping an already existing table with same name - based on the customer master extension meta data.
|
void |
createTableFromCustomerMaster(String tableName,
Collection<String> fields)
Creates a new in-memory table - eventually dropping an already existing table with same name - based on the customer master meta data.
|
void |
createTableFromLookupTable(String tableName,
Long lookupTableId,
Collection<String> fields)
Creates a new in-memory table - eventually dropping an already existing table with same name - based on a lookup table/ pricing parameter table
|
void |
createTableFromProductExtension(String tableName,
String pxName,
Collection<String> fields)
Creates a new in-memory table - eventually dropping an already existing table with same name - based on the product master extension meta data.
|
void |
createTableFromProductMaster(String tableName,
Collection<String> fields)
Creates a new in-memory table - eventually dropping an already existing table with same name - based on the product master meta data.
|
void |
createTableFromQuery(String tableName,
DatamartContext.Query query)
Creates a new in-memory table - eventually dropping an already existing table with same name - based on the query definition fields.
|
void |
createTableFromQueryResult(String tableName,
DatamartQueryResultImpl queryResult)
Creates a new in-memory table - eventually dropping an already existing table with same name - based on the query result fields.
|
int |
createTableFromSearch(String tableName,
Search search,
String entityName) |
void |
dropTable(String tableName)
Drops an existing in-memory table.
|
Matrix2D |
executeQuery(Query query) |
Matrix2D |
executeQuery(String queryString) |
int |
executeUpdate(String sql)
Execute non-select queries like UPDATE,INSERT, etc
|
protected DataContext |
getDataContext() |
Schema |
getDefaultSchema() |
Table |
getTable(String tableName) |
List<Table> |
getTables() |
int |
getTotalRows()
Returns the total row count over all used in-memory tables.
|
int |
loadRows(String tableName,
AbstractProducer.ResultIterator stream)
Load data into an existing in-memory table.
|
void |
loadRows(String tableName,
List<Map<String,Object>> rowsAsListOfMaps)
Load data into an existing in-memory table.
|
int |
loadRows(String tableName,
StreamResults results) |
Query |
newQuery(String tableName) |
Query |
newQuery(Table table) |
protected Query |
parseQuery(String queryString) |
String |
printTablesDefinitions(String tablePattern)
Returns a debug string that contains the complete schema definition for the temporary in-memory database.
|
Matrix2D |
select(String selectSql)
Deprecated.
|
String |
toDBDataType(DataType dataType)
Converts a Price f(x) datatype into a in-memory database datatype.
|
protected final PersistedObjectService objService
protected final DMSchemaService schemaService
protected final Connection conn
public TableContext(FormulaEngineContext context) throws SQLException
SQLException
protected TableContext(PersistedObjectService objService, String dbName) throws SQLException
SQLException
public void close()
public int getTotalRows()
public void dropTable(String tableName) throws SQLException
tableName
- The in-memory table name to dropSQLException
public void createTable(String tableName, Object input) throws SQLException
tableName
- The in-memory table nameinput
- Accepts two types: String and DatamartQueryResultImpl
. If a string is passed it needs to be a valid SELECT sql clause based on an already existing in-memory database.
Basically a "CREATE TABLE x AS SELECT ..."
command is called. In case of DatamartQueryResultImpl
the method behaves as createTableFromQueryResultSQLException
public void createTableFromQueryResult(String tableName, DatamartQueryResultImpl queryResult) throws SQLException
tableName
- The in-memory table namequeryResult
- The result set of a datamart querySQLException
public void createTableFromQuery(String tableName, DatamartContext.Query query)
tableName
- The in-memory table namequery
- public void createTableFromProductMaster(String tableName, Collection<String> fields) throws SQLException
tableName
- The in-memory table namefields
- The fields to pick form the product master, or null for all fieldsSQLException
public void createTableFromCustomerMaster(String tableName, Collection<String> fields) throws SQLException
tableName
- The in-memory table namefields
- The fields to pick form the customer master, or null for all fieldsSQLException
public void createTableFromProductExtension(String tableName, String pxName, Collection<String> fields) throws SQLException
tableName
- The in-memory table namepxName
- The extension namefields
- The fields to pick form the product master extension, or null for all fieldsSQLException
public void createTableFromCustomerExtension(String tableName, String cxName, Collection<String> fields) throws SQLException
tableName
- The in-memory table namecxName
- The extension namefields
- The fields to pick form the customer master extension, or null for all fieldsSQLException
public void createTableFromLookupTable(String tableName, Long lookupTableId, Collection<String> fields) throws SQLException
tableName
- The in-memory table namelookupTableId
- The id of the lookup tablefields
- The fields to pick form the customer master extension, or null for all fieldsSQLException
public void createTable(String tableName, Map<String,DataType> fields, List<String> indexFields) throws SQLException
tableName
- The in-memory table namefields
- Mandatory. Map of fieldName => DataType of the table. Supported DataType constants are: STRING, NUMBER, DATE, BOOLEAN, DATETIME, LONGindexFields
- Optional, can be null. List of fieldNames for which an index should be createdSQLException
public int createTableFromSearch(String tableName, Search search, String entityName) throws SQLException
SQLException
@Deprecated public Matrix2D select(String selectSql) throws SQLException
selectSql
- SQLException
public int count(String tableName)
tableName
- The in-memory tablepublic int executeUpdate(String sql) throws SQLException
sql
- A valid SQL statementSQLException
public String printTablesDefinitions(String tablePattern) throws SQLException
tablePattern
- a table name pattern; must match the table name as it is stored in the database. You can use wildcards like %SQLException
public String toDBDataType(DataType dataType)
dataType
- protected DataContext getDataContext()
public final Schema getDefaultSchema()
public List<Table> getTables()
public Table getTable(String tableName)
public Query newQuery(Table table) throws SQLException
SQLException
public Query newQuery(String tableName) throws SQLException
SQLException
protected Query parseQuery(String queryString)
public Matrix2D executeQuery(String queryString) throws SQLException
SQLException
public Matrix2D executeQuery(Query query) throws SQLException
SQLException
public int loadRows(String tableName, AbstractProducer.ResultIterator stream) throws SQLException
api.stream
like:
def pxResults = api.stream("PX", null, Filter.equal("name", "MySamplePX"))
tableContext.loadRows("PX_T1", pxResults)
tableName
- The target in-memory tablestream
- The result of an api.stream callSQLException
public int loadRows(String tableName, StreamResults results) throws SQLException
SQLException
public void loadRows(String tableName, List<Map<String,Object>> rowsAsListOfMaps) throws SQLException
api.find
def pxResults = api.find("PX", null, Filter.equal("name", "MySamplePX"))
tableContext.loadRows("PX_T1", pxResults)
tableName
- The target in-memory tablerowsAsListOfMaps
- The result of an api.find call or any custom list with map elementsSQLException
Copyright © 2019. All rights reserved.