Search in sources :

Example 1 with QuerySet

use of com.servoy.j2db.persistence.QuerySet in project servoy-client by Servoy.

the class ProfileDataServer method performQuery.

@Override
public IDataSet performQuery(String client_id, String server_name, String transaction_id, ISQLSelect sqlSelect, ColumnType[] resultTypes, ArrayList<TableFilter> filters, boolean distinctInMemory, int startRow, int rowsToRetrieve, int type, ITrackingSQLStatement trackingInfo) throws ServoyException, RemoteException {
    long startTime = System.currentTimeMillis();
    try {
        return super.performQuery(client_id, server_name, transaction_id, sqlSelect, resultTypes, filters, distinctInMemory, startRow, rowsToRetrieve, type, trackingInfo);
    } finally {
        QuerySet set = getSQLQuerySet(server_name, sqlSelect, filters, startRow, rowsToRetrieve, false, false);
        informListeners("Query[" + PerformanceTiming.getTypeString(type) + ']', server_name, set.getSelect().getSql(), transaction_id, startTime, set.getSelect().getParameters());
    }
}
Also used : QuerySet(com.servoy.j2db.persistence.QuerySet)

Example 2 with QuerySet

use of com.servoy.j2db.persistence.QuerySet in project servoy-client by Servoy.

the class ProfileDataServer method performUpdates.

/**
 * @param clientId
 * @param statements
 * @return
 * @throws ServoyException
 * @throws RemoteException
 * @see com.servoy.j2db.dataprocessing.IDataServer#performUpdates(java.lang.String, com.servoy.j2db.dataprocessing.ISQLStatement[])
 */
@Override
public Object[] performUpdates(String clientId, ISQLStatement[] statements) throws ServoyException, RemoteException {
    long startTime = System.currentTimeMillis();
    try {
        return super.performUpdates(clientId, statements);
    } finally {
        for (ISQLStatement statement : statements) {
            QuerySet set = getSQLQuerySet(statement.getServerName(), statement.getUpdate(), null, -1, -1, false, false);
            informListeners("Update", statement.getServerName() + '.' + statement.getTableName(), set.getUpdate().getSql(), statement.getTransactionID(), startTime, set.getUpdate().getParameters());
        }
    }
}
Also used : ISQLStatement(com.servoy.j2db.dataprocessing.ISQLStatement) QuerySet(com.servoy.j2db.persistence.QuerySet)

Example 3 with QuerySet

use of com.servoy.j2db.persistence.QuerySet in project servoy-client by Servoy.

the class TestNGClient method createDataServer.

@Override
protected IDataServer createDataServer() {
    return new IDataServer() {

        private final HashMap<String, IDataSet> dataSetMap = new HashMap<String, IDataSet>();

        @Override
        public void setServerMaintenanceMode(boolean maintenanceMode) throws RemoteException {
        }

        @Override
        public void logMessage(String msg) throws RemoteException {
        }

        @Override
        public boolean isInServerMaintenanceMode() throws RemoteException {
            return false;
        }

        @Override
        public boolean releaseLocks(String client_id, String server_name, String table_name, Set<Object> pkhashkeys) throws RemoteException, RepositoryException {
            return false;
        }

        @Override
        public IDataSet acquireLocks(String client_id, String server_name, String table_name, Set<Object> pkhashkeys, QuerySelect lockSelect, String transaction_id, ArrayList<TableFilter> filters, int chunkSize) throws RemoteException, RepositoryException {
            return null;
        }

        @Override
        public String startTransaction(String clientId, String server_name) throws RepositoryException, RemoteException {
            return null;
        }

        @Override
        public Object[] performUpdates(String clientId, ISQLStatement[] statements) throws ServoyException, RemoteException {
            return statements;
        }

        @Override
        public IDataSet[] performQuery(String client_id, String server_name, String transaction_id, QueryData[] array) throws ServoyException, RemoteException {
            if (array.length > 0) {
                String ds = array[0].getSqlSelect().getTable().getDataSource();
                if ("mem:relatedtest".equals(ds)) {
                    IDataSet set = dataSetMap.get(ds);
                    IDataSet[] returnDataSet = new IDataSet[array.length];
                    for (int i = 0; i < array.length; i++) {
                        returnDataSet[i] = new BufferedDataSet();
                        for (int k = 0; k < set.getRowCount(); k++) {
                            Object[][] value = (Object[][]) ((Placeholder) ((SetCondition) ((QuerySelect) array[i].getSqlSelect()).getConditions().values().iterator().next().getConditions().get(0)).getValues()).getValue();
                            if (set.getRow(k)[1].equals(value[0][0])) {
                                returnDataSet[i].addRow(new Object[] { set.getRow(k)[0], set.getRow(k)[1], set.getRow(k)[2], set.getRow(k)[3] });
                            }
                        }
                    }
                    return returnDataSet;
                }
            }
            return null;
        }

        @Override
        public IDataSet performQuery(String client_id, String server_name, String driverTableName, String transaction_id, String sql, Object[] questiondata, int startRow, int rowsToRetrieve, boolean updateIdleTimestamp) throws ServoyException, RemoteException {
            // don't know the
            return dataSetMap.values().iterator().next();
        // datasource,
        // just return
        // the first
        // dataset
        }

        @Override
        public IDataSet performQuery(String client_id, String server_name, String transaction_id, ISQLSelect sqlSelect, ColumnType[] resultTypes, ArrayList<TableFilter> filters, boolean distinctInMemory, int startRow, int rowsToRetrieve, boolean updateIdleTimestamp) throws ServoyException, RemoteException {
            return dataSetMap.get(sqlSelect.getTable().getDataSource());
        }

        @Override
        public IDataSet performQuery(String client_id, String server_name, String driverTableName, String transaction_id, String sql, Object[] questiondata, int startRow, int rowsToRetrieve, int type) throws ServoyException, RemoteException {
            // don't know the
            return dataSetMap.values().iterator().next();
        // datasource,
        // just return
        // the first
        // dataset
        }

        @Override
        public IDataSet performQuery(String client_id, String server_name, String transaction_id, ISQLSelect sqlSelect, ColumnType[] resultTypes, ArrayList<TableFilter> filters, boolean distinctInMemory, int startRow, int rowsToRetrieve, int type, ITrackingSQLStatement trackingInfo) throws ServoyException, RemoteException {
            return dataSetMap.get(sqlSelect.getTable().getDataSource());
        }

        @Override
        public IDataSet performQuery(String client_id, String server_name, String transaction_id, ISQLSelect sqlSelect, ColumnType[] resultTypes, ArrayList<TableFilter> filters, boolean distinctInMemory, int startRow, int rowsToRetrieve, int type) throws ServoyException, RemoteException {
            IDataSet set = dataSetMap.get(sqlSelect.getTable().getDataSource());
            if (sqlSelect instanceof QuerySelect && ((QuerySelect) sqlSelect).getColumns().size() == 1) {
                // pk select
                int lastRow = Math.min(set.getRowCount(), startRow + rowsToRetrieve);
                BufferedDataSet ds = BufferedDataSetInternal.createBufferedDataSet(null, null, new SafeArrayList<Object[]>(0), lastRow < set.getRowCount());
                for (int i = startRow; i < lastRow; i++) {
                    ds.addRow(new Object[] { set.getRow(i)[0] });
                }
                return ds;
            }
            return set;
        }

        @Override
        public IDataSet performQuery(String client_id, String server_name, String driverTableName, String transaction_id, String sql, Object[] questiondata, int startRow, int rowsToRetrieve) throws ServoyException, RemoteException {
            // don't know the
            return dataSetMap.values().iterator().next();
        // datasource,
        // just return
        // the first
        // dataset
        }

        @Override
        public IDataSet performQuery(String client_id, String server_name, String transaction_id, ISQLSelect sqlSelect, ColumnType[] resultTypes, ArrayList<TableFilter> filters, boolean distinctInMemory, int startRow, int rowsToRetrieve) throws ServoyException, RemoteException {
            return dataSetMap.get(sqlSelect.getTable().getDataSource());
        }

        @Override
        public IDataSet performCustomQuery(String client_id, String server_name, String driverTableName, String transaction_id, ISQLSelect sqlSelect, ArrayList<TableFilter> filters, int startRow, int rowsToRetrieve) throws ServoyException, RemoteException {
            return dataSetMap.get(sqlSelect.getTable().getDataSource());
        }

        @Override
        public boolean notifyDataChange(String client_id, String server_name, String tableName, IDataSet pks, int action, String transaction_id) throws RemoteException {
            return false;
        }

        @Override
        public ITable insertQueryResult(String client_id, String queryServerName, String queryTid, ISQLSelect sqlSelect, ArrayList<TableFilter> filters, boolean distinctInMemory, int startRow, int rowsToRetrieve, int type, String dataSource, String targetServerName, String targetTableName, String targetTid, ColumnType[] columnTypes, String[] pkNames) throws ServoyException, RemoteException {
            return null;
        }

        @Override
        public InsertResult insertDataSet(String client_id, IDataSet set, final String dataSource, String serverName, String tableName, String tid, ColumnType[] columnTypes, String[] pkNames, HashMap<String, ColumnInfoDef> columnInfoDefinitions) throws ServoyException, RemoteException {
            dataSetMap.put(dataSource, set);
            Table table = new Table(serverName, serverName, true, ITable.TABLE, null, null);
            table.setDataSource(dataSource);
            for (int i = 0; i < set.getColumnCount(); i++) {
                Column col = new Column(table, set.getColumnNames()[i], set.getColumnTypes()[i], 50, 50, true);
                table.addColumn(col);
                if (Arrays.binarySearch(pkNames, col.getName()) >= 0) {
                    col.setDatabasePK(true);
                }
            }
            return new InsertResult(table, new Object[0]);
        }

        @Override
        public QuerySet getSQLQuerySet(String serverName, ISQLQuery sqlQuery, ArrayList<TableFilter> filters, int startRow, int rowsToRetrieve, boolean forceQualifyColumns, boolean disableUseArrayForIn) throws RepositoryException, RemoteException {
            QuerySet qs = new QuerySet();
            qs.setSelect(new QueryString("select from test", false));
            return qs;
        }

        @Override
        public Object getNextSequence(String serverName, String tableName, String columnName, int columnInfoID, String columnInfoServer) throws RepositoryException, RemoteException {
            return null;
        }

        @Override
        public Blob getBlob(String clientId, String serverName, ISQLSelect blobSelect, ArrayList<TableFilter> filters, String tid) throws RepositoryException, RemoteException {
            return null;
        }

        @Override
        public boolean endTransactions(String client_id, String[] transaction_id, boolean commit) throws RepositoryException, RemoteException {
            return false;
        }

        @Override
        public void dropTemporaryTable(String client_id, String serverName, String tableName) throws RemoteException, RepositoryException {
        }

        @Override
        public ISQLStatement createSQLStatement(int action, String server_name, String tableName, Object[] pkColumnData, String tid, ISQLUpdate sqlUpdate, ArrayList<TableFilter> filters) throws RemoteException {
            return null;
        }

        @Override
        public ISQLStatement createSQLStatement(int action, String server_name, String tableName, Object[] pkColumnData, String tid, String sql, Object[] questiondata) throws RemoteException, RepositoryException {
            return null;
        }

        @Override
        public void addClientAsTableUser(String client_id, String serverName, String tableName) throws RemoteException, RepositoryException {
        }

        @Override
        public IDataSet[] executeProcedure(String clientId, String server_name, String tid, Procedure procedure, Object[] arguments) throws RepositoryException, RemoteException {
            return null;
        }
    };
}
Also used : Set(java.util.Set) QuerySet(com.servoy.j2db.persistence.QuerySet) IDataSet(com.servoy.j2db.dataprocessing.IDataSet) BufferedDataSet(com.servoy.j2db.dataprocessing.BufferedDataSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SafeArrayList(com.servoy.j2db.util.SafeArrayList) QuerySet(com.servoy.j2db.persistence.QuerySet) QueryString(com.servoy.j2db.persistence.QueryString) SetCondition(com.servoy.j2db.query.SetCondition) BufferedDataSet(com.servoy.j2db.dataprocessing.BufferedDataSet) Column(com.servoy.j2db.persistence.Column) Procedure(com.servoy.j2db.persistence.Procedure) ITable(com.servoy.j2db.persistence.ITable) Table(com.servoy.j2db.persistence.Table) IDataServer(com.servoy.j2db.dataprocessing.IDataServer) QueryString(com.servoy.j2db.persistence.QueryString) QuerySelect(com.servoy.j2db.query.QuerySelect) ISQLUpdate(com.servoy.j2db.query.ISQLUpdate) ITrackingSQLStatement(com.servoy.j2db.dataprocessing.ITrackingSQLStatement) ISQLQuery(com.servoy.j2db.query.ISQLQuery) IDataSet(com.servoy.j2db.dataprocessing.IDataSet) ISQLSelect(com.servoy.j2db.query.ISQLSelect)

Example 4 with QuerySet

use of com.servoy.j2db.persistence.QuerySet in project servoy-client by Servoy.

the class JSDatabaseManager method js_getSQLParameters.

/**
 * Returns the internal SQL parameters, as an array, that are used to define the specified (related)foundset.
 * When the founset is in find mode, the arguments for the find conditions are included in the result.
 *
 * @sample var sqlParameterArray = databaseManager.getSQLParameters(foundset,false)
 *
 * @param foundsetOrQBSelect The JSFoundset or QBSelect to get the sql parameters for.
 * @param includeFilters include the parameters for the filters.
 *
 * @return An Array with the sql parameter values.
 */
public Object[] js_getSQLParameters(Object foundsetOrQBSelect, boolean includeFilters) throws ServoyException {
    checkAuthorized();
    if (foundsetOrQBSelect instanceof IFoundSetInternal && ((IFoundSetInternal) foundsetOrQBSelect).getTable() != null) {
        try {
            // TODO parameters from updates and cleanups
            QuerySet querySet = getQuerySet(((IFoundSetInternal) foundsetOrQBSelect).getCurrentStateQuery(true, false), includeFilters);
            Object[][] qsParams = querySet.getSelect().getParameters();
            if (qsParams == null || qsParams.length == 0) {
                return null;
            }
            return qsParams[0];
        } catch (Exception e) {
            Debug.error(e);
        }
    } else if (foundsetOrQBSelect instanceof QBSelect) {
        try {
            QuerySelect select = ((QBSelect) foundsetOrQBSelect).build();
            if (select.getColumns() == null) {
                // no columns, add pk
                // note that QBSelect.build() already returns a clone
                ITable table = application.getFoundSetManager().getTable(select.getTable().getDataSource());
                Iterator<Column> pkIt = ((Table) table).getRowIdentColumns().iterator();
                if (!pkIt.hasNext()) {
                    throw new RepositoryException(ServoyException.InternalCodes.PRIMARY_KEY_NOT_FOUND, new Object[] { table.getName() });
                }
                while (pkIt.hasNext()) {
                    Column c = pkIt.next();
                    select.addColumn(c.queryColumn(select.getTable()));
                }
            }
            QuerySet querySet = getQuerySet(select, includeFilters);
            Object[][] qsParams = querySet.getSelect().getParameters();
            if (qsParams == null || qsParams.length == 0) {
                return null;
            }
            return qsParams[0];
        } catch (RemoteException e) {
            Debug.error(e);
        }
    }
    return null;
}
Also used : BaseQueryTable(com.servoy.base.query.BaseQueryTable) QueryTable(com.servoy.j2db.query.QueryTable) ITable(com.servoy.j2db.persistence.ITable) Table(com.servoy.j2db.persistence.Table) QuerySet(com.servoy.j2db.persistence.QuerySet) RepositoryException(com.servoy.j2db.persistence.RepositoryException) QuerySelect(com.servoy.j2db.query.QuerySelect) ApplicationException(com.servoy.j2db.ApplicationException) RemoteException(java.rmi.RemoteException) SQLException(java.sql.SQLException) ServoyException(com.servoy.j2db.util.ServoyException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) QBSelect(com.servoy.j2db.querybuilder.impl.QBSelect) QueryColumn(com.servoy.j2db.query.QueryColumn) IBaseColumn(com.servoy.base.persistence.IBaseColumn) Column(com.servoy.j2db.persistence.Column) QBColumn(com.servoy.j2db.querybuilder.impl.QBColumn) Iterator(java.util.Iterator) ITable(com.servoy.j2db.persistence.ITable) NativeObject(org.mozilla.javascript.NativeObject) RemoteException(java.rmi.RemoteException)

Example 5 with QuerySet

use of com.servoy.j2db.persistence.QuerySet in project servoy-client by Servoy.

the class ProfileDataServer method performQuery.

/**
 * @param client_id
 * @param server_name
 * @param transaction_id
 * @param sqlSelect
 * @param filters
 * @param distinctInMemory
 * @param startRow
 * @param rowsToRetrieve
 * @return
 * @throws ServoyException
 * @throws RemoteException
 * @see com.servoy.j2db.dataprocessing.IDataServer#performQuery(java.lang.String, java.lang.String, java.lang.String, com.servoy.j2db.query.ISQLSelect, java.util.ArrayList, boolean, int, int)
 */
@Override
public IDataSet performQuery(String client_id, String server_name, String transaction_id, ISQLSelect sqlSelect, ColumnType[] resultTypes, ArrayList<TableFilter> filters, boolean distinctInMemory, int startRow, int rowsToRetrieve) throws ServoyException, RemoteException {
    long startTime = System.currentTimeMillis();
    try {
        return super.performQuery(client_id, server_name, transaction_id, sqlSelect, resultTypes, filters, distinctInMemory, startRow, rowsToRetrieve);
    } finally {
        QuerySet set = getSQLQuerySet(server_name, sqlSelect, filters, startRow, rowsToRetrieve, false, false);
        informListeners("Query", server_name, set.getSelect().getSql(), transaction_id, startTime, set.getSelect().getParameters());
    }
}
Also used : QuerySet(com.servoy.j2db.persistence.QuerySet)

Aggregations

QuerySet (com.servoy.j2db.persistence.QuerySet)12 RepositoryException (com.servoy.j2db.persistence.RepositoryException)4 QuerySelect (com.servoy.j2db.query.QuerySelect)4 Column (com.servoy.j2db.persistence.Column)3 ITable (com.servoy.j2db.persistence.ITable)3 Table (com.servoy.j2db.persistence.Table)3 RemoteException (java.rmi.RemoteException)3 IBaseColumn (com.servoy.base.persistence.IBaseColumn)2 BaseQueryTable (com.servoy.base.query.BaseQueryTable)2 ApplicationException (com.servoy.j2db.ApplicationException)2 QueryString (com.servoy.j2db.persistence.QueryString)2 QueryColumn (com.servoy.j2db.query.QueryColumn)2 QueryTable (com.servoy.j2db.query.QueryTable)2 QBColumn (com.servoy.j2db.querybuilder.impl.QBColumn)2 QBSelect (com.servoy.j2db.querybuilder.impl.QBSelect)2 ServoyException (com.servoy.j2db.util.ServoyException)2 SQLException (java.sql.SQLException)2 Iterator (java.util.Iterator)2 NativeObject (org.mozilla.javascript.NativeObject)2 BufferedDataSet (com.servoy.j2db.dataprocessing.BufferedDataSet)1