use of com.servoy.j2db.persistence.Column in project servoy-client by Servoy.
the class FlattenedSolution method getDataProviderForTable.
/**
* Returns script calculations and aggregates and columns
*/
public IDataProvider getDataProviderForTable(ITable table, String dataProviderID) throws RepositoryException {
if (table == null || dataProviderID == null)
return null;
// check for calculations first because of stored calculations
Map<String, IDataProvider> dps = getAllDataProvidersForTable(table);
IDataProvider dataProvider = null;
if (dps != null) {
dataProvider = dps.get(dataProviderID);
}
if (dataProvider != null)
return dataProvider;
Column column = table.getColumn(Ident.generateNormalizedName(dataProviderID));
if (column != null) {
return column;
}
return null;
}
use of com.servoy.j2db.persistence.Column in project servoy-client by Servoy.
the class FoundSet method js_selectRecord.
/**
* Select the record based on pk data.
* Note that if the foundset has not loaded the record with the pk, selectrecord will fail.
*
* In case of a table with a composite key, the pk sequence must match the alphabetical
* ordering of the pk column names.
*
* @sample %%prefix%%foundset.selectRecord(pkid1,pkid2,pkidn);//pks must be alphabetically set! It is also possible to use an array as parameter.
*
* @param pkid1 primary key
*
* @param pkid2 optional second primary key (in case of composite primary key)
*
* @param pkidn optional nth primary key
*
* @return true if succeeded.
*/
public boolean js_selectRecord(Object[] vargs) {
if (sheet.getTable() == null) {
return false;
}
List<Object> args = new ArrayList<Object>();
if (vargs != null && vargs.length > 0) {
List<Column> cols = sheet.getTable().getRowIdentColumns();
for (int i = 0; i < Math.min(vargs.length, cols.size()); i++) {
Column c = cols.get(i);
args.add(c.getAsRightType(vargs[i]));
}
return selectRecord(args.toArray(), true);
}
return false;
}
use of com.servoy.j2db.persistence.Column in project servoy-client by Servoy.
the class FoundSet method getCalculationValue.
/**
* Found set is using scriptengine to recalculate the specified calculation,check first with containsCalculation before calling
*/
public Object getCalculationValue(IRecordInternal state, String dataProviderID, Object[] vargs, UsedDataProviderTracker usedDataProviderTracker) {
UsedDataProviderTracker current = null;
try {
Object obj;
TableScope tableScope = (TableScope) fsm.getScriptEngine().getTableScope(sheet.getTable());
tableScope.setArguments(vargs);
current = tableScope.setUsedDataProviderTracker(usedDataProviderTracker);
Scriptable previous = tableScope.getPrototype();
try {
// make sure its set correctly
tableScope.setPrototype((Scriptable) state);
obj = tableScope.getCalculationValue(dataProviderID, tableScope);
if (// fix for postgress
obj instanceof Byte) {
obj = Integer.valueOf(((Byte) obj).intValue());
} else {
Column column = sheet.getTable().getColumn(dataProviderID);
if (column != null) {
// TODO: check case with stored calc on column with column converter
if (column.getScale() > 0 && column.getDataProviderType() == IColumnTypes.NUMBER && obj != null) {
// if rounding results in the old value we do not have to save.
try {
obj = Utils.roundNumber(obj, column.getLength(), true);
} catch (Exception e) {
// $NON-NLS-1$
Debug.error("Could not round stored calculation '" + dataProviderID + '\'', e);
}
}
}
}
// TODO: in developer we must check if the return type matches the one specified on a calculation otherwise relations will not work in some cases
} finally {
tableScope.setPrototype(previous);
tableScope.setUsedDataProviderTracker(current);
}
return obj;
} catch (Exception ex) {
// fsm.getApplication().reportJSError(Messages.getString("servoy.error.executingCalculation",new Object[] {dataProviderID,getTable().getName(),ex.getMessage()}),ex) ; //$NON-NLS-1$
fsm.getApplication().reportJSError(ex.getMessage(), ex);
// $NON-NLS-1$
Debug.error("error executing calc: " + dataProviderID, ex);
return null;
}
}
use of com.servoy.j2db.persistence.Column in project servoy-client by Servoy.
the class FoundSet method loadByQuery.
public boolean loadByQuery(IQueryBuilder query) throws ServoyException {
// check if this query is on our base table
if (!Utils.stringSafeEquals(getDataSource(), query.getDataSource())) {
throw new RepositoryException(// $NON-NLS-1$//$NON-NLS-2$
"Cannot load foundset with query based on another table (" + getDataSource() + " != " + query.getDataSource() + ')').setContext(this.toString());
}
// makes a clone
QuerySelect sqlSelect = ((QBSelect) query).build();
if (sqlSelect.getColumns() == null) {
// no columns, add pk
// note that QBSelect.build() already returns a clone
Iterator<Column> pkIt = ((Table) getTable()).getRowIdentColumns().iterator();
if (!pkIt.hasNext()) {
throw new RepositoryException(ServoyException.InternalCodes.PRIMARY_KEY_NOT_FOUND, new Object[] { getTable().getName() }).setContext(this.toString());
}
while (pkIt.hasNext()) {
Column c = pkIt.next();
sqlSelect.addColumn(c.queryColumn(sqlSelect.getTable()));
}
}
Placeholder dynamicPKplaceholder = sqlSelect.getPlaceholder(new TablePlaceholderKey(sqlSelect.getTable(), SQLGenerator.PLACEHOLDER_FOUNDSET_PKS));
if (dynamicPKplaceholder != null && dynamicPKplaceholder.isSet() && dynamicPKplaceholder.getValue() instanceof Object[]) {
// loading from saved query, dynamic pk was replaced by array in serialization, make dynamic again
dynamicPKplaceholder.setValue(new DynamicPkValuesArray(getSQLSheet().getTable().getRowIdentColumns(), SQLGenerator.createPKValuesDataSet(getSQLSheet().getTable().getRowIdentColumns(), (Object[][]) dynamicPKplaceholder.getValue())));
}
if (sqlSelect.getSorts() == null) {
// query does not define sort, use last sorts
fsm.getSQLGenerator().addSorts(sqlSelect, sqlSelect.getTable(), this, sheet.getTable(), lastSortColumns == null ? defaultSort : lastSortColumns, true, false);
} else {
// try to determine the SortColumns from the query-sort
lastSortColumns = determineSortColumns(sqlSelect);
}
return loadByQuery(addFilterconditions(sqlSelect, foundSetFilters));
}
use of com.servoy.j2db.persistence.Column in project servoy-client by Servoy.
the class FoundSetManager method createDataproviderTableFilterdefinition.
public DataproviderTableFilterdefinition createDataproviderTableFilterdefinition(ITable table, String dataprovider, String operator, Object val) throws ServoyException {
if (dataprovider == null || operator == null) {
return null;
}
int op = RelationItem.getValidOperator(operator.trim(), IBaseSQLCondition.ALL_DEFINED_OPERATORS, IBaseSQLCondition.ALL_MODIFIERS);
if (op == -1) {
return null;
}
Object value = val;
if (value instanceof Wrapper) {
value = ((Wrapper) value).unwrap();
}
if (table != null) {
Column column = ((Table) table).getColumn(dataprovider);
if (column == null) {
return null;
}
value = convertFilterValue(table, column, value);
}
return new DataproviderTableFilterdefinition(dataprovider, op, value);
}
Aggregations