Search in sources :

Example 1 with TablePlaceholderKey

use of com.servoy.j2db.query.TablePlaceholderKey in project servoy-client by Servoy.

the class QBSelect method createOperand.

IQuerySelectValue createOperand(Object value, BaseColumnType columnType, int flags) {
    if (value instanceof QBColumn) {
        return ((QBColumn) value).getQuerySelectValue();
    }
    Object val = value;
    if (value instanceof QBParameter) {
        TablePlaceholderKey key = ((QBParameter) value).getPlaceholderKey();
        Placeholder placeholder = null;
        if (query != null) {
            placeholder = query.getPlaceholder(key);
        }
        val = placeholder == null ? new Placeholder(key) : placeholder;
    } else if (columnType == null) {
        if (value instanceof Date && !(value instanceof Timestamp) && !(value instanceof Time)) {
            // make sure a date is a timestamp
            val = new Timestamp(((Date) value).getTime());
        }
    } else if (!(value instanceof IQuerySelectValue)) {
        // convert the value (especially UUID) to the type of the column
        val = getAsRightType(value, columnType, flags);
    }
    if (val instanceof IQuerySelectValue) {
        return (IQuerySelectValue) val;
    }
    return new QueryColumnValue(val, null);
}
Also used : Placeholder(com.servoy.j2db.query.Placeholder) TablePlaceholderKey(com.servoy.j2db.query.TablePlaceholderKey) QueryColumnValue(com.servoy.j2db.query.QueryColumnValue) Time(java.sql.Time) Timestamp(java.sql.Timestamp) Date(java.util.Date) IQuerySelectValue(com.servoy.j2db.query.IQuerySelectValue)

Example 2 with TablePlaceholderKey

use of com.servoy.j2db.query.TablePlaceholderKey in project servoy-client by Servoy.

the class FoundSet method copyCurrentRecordFoundSet.

public // used for printing current record
IFoundSetInternal copyCurrentRecordFoundSet() throws // used for printing current record
ServoyException {
    try {
        FoundSet fs = (FoundSet) clone();
        // no need for clone, just made one
        QuerySelect fs_sqlSelect = fs.pksAndRecords.getQuerySelectForReading();
        SQLSheet.SQLDescription select_desc = sheet.getSQLDescription(SQLSheet.SELECT);
        if (select_desc != null) {
            QuerySelect select = (QuerySelect) select_desc.getSQLQuery();
            fs_sqlSelect.setCondition(SQLGenerator.CONDITION_SEARCH, select.getConditionClone(SQLGenerator.CONDITION_SEARCH));
            // Leave CONDITION_RELATION and CONDITION_FILTER as is in fs (when it is a related fs)
            fs_sqlSelect.clearJoins();
            fs_sqlSelect.clearSorts();
            // clear, 1 row needs no sort etc.
            fs_sqlSelect.clearCondition(SQLGenerator.CONDITION_OMIT);
            // make sure the references to the tables from the copies are correct
            fs_sqlSelect.relinkTable(select.getTable(), fs_sqlSelect.getTable());
            // reset the creation! because we just changed the sqlSelect
            fs.creationSqlSelect = AbstractBaseQuery.deepClone(fs_sqlSelect);
            fs.lastSortColumns = null;
            if (fs.rowManager != null)
                fs.rowManager.register(fs);
            fs.aggregateCache = new HashMap<String, Object>(6);
            fs.pksAndRecords.setPksAndQuery(new BufferedDataSet(), 0, fs_sqlSelect);
        }
        int selRow = getSelectedIndex();
        if (selRow >= 0) {
            IRecordInternal selRec = getRecord(selRow);
            if (selRec != null) {
                Row row = selRec.getRawData();
                if (row != null && row.existInDB()) {
                    Object[] pk = row.getPK();
                    if (!fs_sqlSelect.setPlaceholderValue(new TablePlaceholderKey(fs_sqlSelect.getTable(), SQLGenerator.PLACEHOLDER_PRIMARY_KEY), pk)) {
                        Debug.error(new RuntimeException(// $NON-NLS-1$
                        "Could not set placeholder " + new TablePlaceholderKey(fs_sqlSelect.getTable(), SQLGenerator.PLACEHOLDER_PRIMARY_KEY) + " in query " + fs_sqlSelect + // $NON-NLS-1$ //$NON-NLS-2$
                        "-- continuing"));
                    }
                    fs.pksAndRecords.getPks().setRow(0, pk);
                    fs.setSelectedIndex(0);
                } else {
                    fs.newRecord(row, 0, true, false);
                }
            }
        }
        return fs;
    } catch (CloneNotSupportedException e) {
        throw new RuntimeException(e);
    }
}
Also used : TablePlaceholderKey(com.servoy.j2db.query.TablePlaceholderKey) IJSFoundSet(com.servoy.base.scripting.api.IJSFoundSet) QuerySelect(com.servoy.j2db.query.QuerySelect)

Example 3 with TablePlaceholderKey

use of com.servoy.j2db.query.TablePlaceholderKey in project servoy-client by Servoy.

the class SQLGenerator method makeQueryColumns.

private static ArrayList<IQuerySelectValue> makeQueryColumns(Iterator<Column> it, QueryTable queryTable, QueryInsert insert) {
    ArrayList<IQuerySelectValue> queryColumns = new ArrayList<IQuerySelectValue>();
    List<QueryColumn> insertColumns = new ArrayList<QueryColumn>();
    while (it.hasNext()) {
        Column column = it.next();
        ColumnInfo ci = column.getColumnInfo();
        if (ci != null && ci.isExcluded()) {
            continue;
        }
        QueryColumn queryColumn = column.queryColumn(queryTable);
        if (isBlobColumn(column)) {
            String alias = column.getDataProviderID().substring(0, Math.min(Column.MAX_SQL_OBJECT_NAME_LENGTH - (IDataServer.BLOB_MARKER_COLUMN_ALIAS.length() + 1), column.getDataProviderID().length())) + '_' + IDataServer.BLOB_MARKER_COLUMN_ALIAS;
            // make sure the alias is unique (2 media columns starting with the same name may clash here)
            char c = 'a';
            for (int i = 0; i < queryColumns.size(); i++) {
                IQuerySelectValue sv = queryColumns.get(i);
                if (alias.equals(sv.getAlias())) {
                    // alias not unique, replace first char to make it unique
                    alias = (c++) + alias.substring(1);
                    // search again
                    i = 0;
                }
            }
            queryColumns.add(new QueryColumnValue(Integer.valueOf(1), alias, true));
        } else {
            queryColumns.add(queryColumn);
        }
        if (insert != null && (ci == null || !ci.isDBManaged())) {
            insertColumns.add(queryColumn);
        }
    }
    if (insert != null) {
        insert.setColumnValues(insertColumns.toArray(new QueryColumn[insertColumns.size()]), new Placeholder(new TablePlaceholderKey(queryTable, PLACEHOLDER_INSERT_KEY)));
    }
    return queryColumns;
}
Also used : Placeholder(com.servoy.j2db.query.Placeholder) TablePlaceholderKey(com.servoy.j2db.query.TablePlaceholderKey) ArrayList(java.util.ArrayList) SafeArrayList(com.servoy.j2db.util.SafeArrayList) ColumnInfo(com.servoy.j2db.persistence.ColumnInfo) QueryColumnValue(com.servoy.j2db.query.QueryColumnValue) QueryColumn(com.servoy.j2db.query.QueryColumn) BaseQueryColumn(com.servoy.base.query.BaseQueryColumn) IColumn(com.servoy.j2db.persistence.IColumn) Column(com.servoy.j2db.persistence.Column) QueryColumn(com.servoy.j2db.query.QueryColumn) BaseQueryColumn(com.servoy.base.query.BaseQueryColumn) IQuerySelectValue(com.servoy.j2db.query.IQuerySelectValue)

Example 4 with TablePlaceholderKey

use of com.servoy.j2db.query.TablePlaceholderKey in project servoy-client by Servoy.

the class SQLGenerator method createDynamicPKSetConditionForFoundset.

static SetCondition createDynamicPKSetConditionForFoundset(FoundSet foundSet, BaseQueryTable queryTable, IDataSet pks) {
    Table table = (Table) foundSet.getTable();
    List<Column> rowIdentColumns = table.getRowIdentColumns();
    QueryColumn[] pkQueryColumns = new QueryColumn[rowIdentColumns.size()];
    // getPrimaryKeys from table
    for (int i = 0; i < rowIdentColumns.size(); i++) {
        Column column = rowIdentColumns.get(i);
        pkQueryColumns[i] = column.queryColumn(queryTable);
    }
    // Dynamic PK condition, the special placeholder will be updated when the foundset pk set changes
    Placeholder placeHolder = new Placeholder(new TablePlaceholderKey(queryTable, SQLGenerator.PLACEHOLDER_FOUNDSET_PKS));
    placeHolder.setValue(new DynamicPkValuesArray(rowIdentColumns, pks.clone()));
    return new SetCondition(IBaseSQLCondition.EQUALS_OPERATOR, pkQueryColumns, placeHolder, true);
}
Also used : Placeholder(com.servoy.j2db.query.Placeholder) BaseQueryTable(com.servoy.base.query.BaseQueryTable) QueryTable(com.servoy.j2db.query.QueryTable) ITable(com.servoy.j2db.persistence.ITable) Table(com.servoy.j2db.persistence.Table) TablePlaceholderKey(com.servoy.j2db.query.TablePlaceholderKey) QueryColumn(com.servoy.j2db.query.QueryColumn) BaseQueryColumn(com.servoy.base.query.BaseQueryColumn) IColumn(com.servoy.j2db.persistence.IColumn) Column(com.servoy.j2db.persistence.Column) QueryColumn(com.servoy.j2db.query.QueryColumn) BaseQueryColumn(com.servoy.base.query.BaseQueryColumn) SetCondition(com.servoy.j2db.query.SetCondition)

Example 5 with TablePlaceholderKey

use of com.servoy.j2db.query.TablePlaceholderKey in project servoy-client by Servoy.

the class SQLGenerator method isDynamicPKSetCondition.

static boolean isDynamicPKSetCondition(ISQLCondition condition) {
    if (condition instanceof SetCondition) {
        Object values = ((SetCondition) condition).getValues();
        if (!(values instanceof Placeholder)) {
            return false;
        }
        IPlaceholderKey key = ((Placeholder) values).getKey();
        if (!(key instanceof TablePlaceholderKey)) {
            return false;
        }
        if (!SQLGenerator.PLACEHOLDER_FOUNDSET_PKS.equals(((TablePlaceholderKey) key).getName())) {
            return false;
        }
        return true;
    }
    return false;
}
Also used : Placeholder(com.servoy.j2db.query.Placeholder) TablePlaceholderKey(com.servoy.j2db.query.TablePlaceholderKey) SetCondition(com.servoy.j2db.query.SetCondition) IPlaceholderKey(com.servoy.j2db.query.IPlaceholderKey)

Aggregations

TablePlaceholderKey (com.servoy.j2db.query.TablePlaceholderKey)16 QuerySelect (com.servoy.j2db.query.QuerySelect)9 Placeholder (com.servoy.j2db.query.Placeholder)8 ArrayList (java.util.ArrayList)8 RepositoryException (com.servoy.j2db.persistence.RepositoryException)7 SafeArrayList (com.servoy.j2db.util.SafeArrayList)7 Column (com.servoy.j2db.persistence.Column)6 QueryColumn (com.servoy.j2db.query.QueryColumn)6 RemoteException (java.rmi.RemoteException)5 BaseQueryTable (com.servoy.base.query.BaseQueryTable)4 IColumn (com.servoy.j2db.persistence.IColumn)4 IQuerySelectValue (com.servoy.j2db.query.IQuerySelectValue)4 QueryTable (com.servoy.j2db.query.QueryTable)4 BaseQueryColumn (com.servoy.base.query.BaseQueryColumn)3 ColumnInfo (com.servoy.j2db.persistence.ColumnInfo)3 ITable (com.servoy.j2db.persistence.ITable)3 Table (com.servoy.j2db.persistence.Table)3 ISQLTableJoin (com.servoy.j2db.query.ISQLTableJoin)2 QueryColumnValue (com.servoy.j2db.query.QueryColumnValue)2 QueryInsert (com.servoy.j2db.query.QueryInsert)2