Search in sources :

Example 1 with IServer

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

the class FlattenedSolution method combineServerProxies.

private void combineServerProxies(ConcurrentMap<String, IServer> orgs, ConcurrentMap<String, IServer> additional) throws RemoteException {
    Iterator<IServer> it = additional.values().iterator();
    while (it.hasNext()) {
        IServer addObject = it.next();
        IServer orgObject = orgs.get(addObject.getName());
        if (addObject instanceof ServerProxy) {
            ServerProxy add = (ServerProxy) addObject;
            if (orgObject == null) {
                orgs.put(add.getName(), add);
            } else if (orgObject instanceof ServerProxy) {
                ServerProxy org = (ServerProxy) orgObject;
                org.combineTables(add);
            }
        }
    }
}
Also used : IServer(com.servoy.j2db.persistence.IServer) ServerProxy(com.servoy.j2db.persistence.ServerProxy)

Example 2 with IServer

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

the class Messages method deleteKey.

public static boolean deleteKey(String key, String i18nDatasource, String clientId, Properties settings, IDataServer dataServer, IRepository repository, IFoundSetManagerInternal fm) {
    String[] names = getServerTableNames(i18nDatasource, settings);
    String serverName = names[0];
    String tableName = names[1];
    if (serverName != null && tableName != null) {
        try {
            IServer server = repository.getServer(serverName);
            if (server == null) {
                return false;
            }
            Table table = (Table) server.getTable(tableName);
            if (table == null) {
                return false;
            }
            QueryTable messagesTable = new QueryTable(table.getSQLName(), table.getDataSource(), table.getCatalog(), table.getSchema());
            // $NON-NLS-1$
            QueryColumn msgKey = new QueryColumn(messagesTable, -1, "message_key", Types.VARCHAR, 150, 0, null, 0);
            QueryDelete delete = new QueryDelete(messagesTable);
            delete.addCondition(new CompareCondition(IBaseSQLCondition.EQUALS_OPERATOR, msgKey, key));
            ISQLStatement sqlStatement = new SQLStatement(ISQLActionTypes.DELETE_ACTION, serverName, tableName, null, null, delete, fm != null ? fm.getTableFilterParams(serverName, delete) : null);
            dataServer.performUpdates(clientId, new ISQLStatement[] { sqlStatement });
        } catch (Exception e) {
            return false;
        }
    }
    return true;
}
Also used : IServer(com.servoy.j2db.persistence.IServer) ISQLStatement(com.servoy.j2db.dataprocessing.ISQLStatement) QueryTable(com.servoy.j2db.query.QueryTable) Table(com.servoy.j2db.persistence.Table) QueryDelete(com.servoy.j2db.query.QueryDelete) QueryColumn(com.servoy.j2db.query.QueryColumn) CompareCondition(com.servoy.j2db.query.CompareCondition) ISQLStatement(com.servoy.j2db.dataprocessing.ISQLStatement) SQLStatement(com.servoy.j2db.dataprocessing.SQLStatement) QueryTable(com.servoy.j2db.query.QueryTable) ServoyException(com.servoy.j2db.util.ServoyException) MissingResourceException(java.util.MissingResourceException) RemoteException(java.rmi.RemoteException)

Example 3 with IServer

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

the class Messages method loadMessagesFromDatabaseRepositoryInternal.

/**
 * CURRENTLY FOR INTERNAL USE ONLY, DO NOT CALL.
 *
 * @exclude
 */
public static void loadMessagesFromDatabaseRepositoryInternal(String i18nDatasource, String clientId, Properties settings, IDataServer dataServer, IRepository repository, Properties properties, Properties localeProperties, Locale language, int loadingType, String searchKey, String searchText, String columnNameFilter, String[] columnValueFilter, IFoundSetManagerInternal fm) {
    noConnection = false;
    String[] names = getServerTableNames(i18nDatasource, settings);
    String serverName = names[0];
    String tableName = names[1];
    if (serverName == null || tableName == null || "".equals(serverName) || "".equals(tableName)) {
        noConnection = true;
        return;
    }
    try {
        // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
        Debug.trace("Loading messages from DB: Server: " + serverName + " Table: " + tableName + " Language: " + language);
        IServer server = repository.getServer(serverName);
        if (server == null) {
            noConnection = true;
            return;
        }
        Table table = (Table) server.getTable(tableName);
        if (table == null) {
            noConnection = true;
            return;
        }
        Column filterColumn = null;
        if (columnNameFilter != null) {
            // check if column exists
            filterColumn = table.getColumn(columnNameFilter);
            if (filterColumn == null) {
                return;
            }
        }
        String[] iColumnValueFilter = columnValueFilter;
        boolean isColumnValueFilterChanged = false;
        if (filterColumn == null && fm != null) {
            QueryTable messagesTable = new QueryTable(table.getSQLName(), table.getDataSource(), table.getCatalog(), table.getSchema());
            QuerySelect sql = new QuerySelect(messagesTable);
            ArrayList<TableFilter> tableFilters = fm.getTableFilterParams(serverName, sql);
            if (tableFilters != null) {
                for (TableFilter tableFilter : tableFilters) {
                    TableFilterdefinition tableFilterdefinition = tableFilter.getTableFilterdefinition();
                    if (tableFilterdefinition instanceof DataproviderTableFilterdefinition) {
                        DataproviderTableFilterdefinition dpTtableFilterdefinition = (DataproviderTableFilterdefinition) tableFilterdefinition;
                        Object value = dpTtableFilterdefinition.getValue();
                        if (value instanceof Object[]) {
                            filterColumn = table.getColumn(dpTtableFilterdefinition.getDataprovider());
                            iColumnValueFilter = new String[((Object[]) value).length];
                            for (int i = 0; i < ((Object[]) value).length; i++) {
                                iColumnValueFilter[i] = ((Object[]) value)[i] != null ? ((Object[]) value)[i].toString() : null;
                            }
                            isColumnValueFilterChanged = true;
                            break;
                        }
                    }
                }
            }
        }
        if (!isColumnValueFilterChanged) {
            loadMessagesFromDatabaseRepositorySinglefilter(server, table, clientId, dataServer, properties, localeProperties, language, loadingType, searchKey, searchText, filterColumn, null, fm);
        }
        if (iColumnValueFilter != null) {
            for (int i = iColumnValueFilter.length - 1; i >= 0; i--) {
                loadMessagesFromDatabaseRepositorySinglefilter(server, table, clientId, dataServer, properties, localeProperties, language, loadingType, searchKey, searchText, filterColumn, iColumnValueFilter[i], fm);
            }
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        Debug.error("Couldn't get the default messages");
        Debug.error(e);
        invalidConnection = true;
    }
}
Also used : IServer(com.servoy.j2db.persistence.IServer) QueryTable(com.servoy.j2db.query.QueryTable) Table(com.servoy.j2db.persistence.Table) DataproviderTableFilterdefinition(com.servoy.j2db.dataprocessing.DataproviderTableFilterdefinition) QuerySelect(com.servoy.j2db.query.QuerySelect) DataproviderTableFilterdefinition(com.servoy.j2db.dataprocessing.DataproviderTableFilterdefinition) TableFilterdefinition(com.servoy.j2db.dataprocessing.TableFilterdefinition) QueryTable(com.servoy.j2db.query.QueryTable) ServoyException(com.servoy.j2db.util.ServoyException) MissingResourceException(java.util.MissingResourceException) RemoteException(java.rmi.RemoteException) QueryColumn(com.servoy.j2db.query.QueryColumn) Column(com.servoy.j2db.persistence.Column) TableFilter(com.servoy.j2db.dataprocessing.TableFilter)

Example 4 with IServer

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

the class FoundSetManager method getSortOptions.

@Override
public SortOptions getSortOptions(IColumn column) {
    boolean ignoreCase = false;
    SortingNullprecedence sortingNullprecedence = SortingNullprecedence.databaseDefault;
    if (column != null) {
        try {
            // First defined at server level
            IServer server = application.getSolution().getServer(column.getTable().getServerName());
            if (server != null) {
                ignoreCase = server.getSettings().isSortIgnorecase();
                sortingNullprecedence = server.getSettings().getSortingNullprecedence();
            }
        } catch (RepositoryException | RemoteException e) {
            Debug.error("Exception getting server settings", e);
        }
        ColumnInfo columnInfo = column.getColumnInfo();
        if (columnInfo != null) {
            // Can be overridden at column level
            if (columnInfo.getSortIgnorecase() != null) {
                ignoreCase = columnInfo.getSortIgnorecase().booleanValue();
            }
            if (columnInfo.getSortingNullprecedence() != null && columnInfo.getSortingNullprecedence() != SortingNullprecedence.databaseDefault) {
                sortingNullprecedence = columnInfo.getSortingNullprecedence();
            }
        }
    }
    return SortOptions.NONE.withIgnoreCase(ignoreCase).withNullprecedence(sortingNullprecedence);
}
Also used : IServer(com.servoy.j2db.persistence.IServer) SortingNullprecedence(com.servoy.j2db.persistence.SortingNullprecedence) ColumnInfo(com.servoy.j2db.persistence.ColumnInfo) RepositoryException(com.servoy.j2db.persistence.RepositoryException) RemoteException(java.rmi.RemoteException)

Example 5 with IServer

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

the class SQLSheet method processCopyValues.

void processCopyValues(IRecordInternal s) {
    SQLDescription desc = getSQLDescription(SELECT);
    if (desc == null) {
        return;
    }
    List<?> list = desc.getDataProviderIDsDilivery();
    for (int i = 0; i < list.size(); i++) {
        try {
            String id = (String) list.get(i);
            Column c = table.getColumn(id);
            if (c != null) {
                ColumnInfo ci = c.getColumnInfo();
                if (ci != null && ci.getAutoEnterType() == ColumnInfo.LOOKUP_VALUE_AUTO_ENTER) {
                    String lookupDataProviderID = ci.getLookupValue();
                    Object obj = s.getValue(lookupDataProviderID);
                    if (ScopesUtils.isVariableScope(lookupDataProviderID) && !s.has(lookupDataProviderID)) {
                        ScriptMethod globalScriptMethod = application.getFlattenedSolution().getScriptMethod(null, lookupDataProviderID);
                        if (globalScriptMethod != null) {
                            try {
                                IServer server = application.getSolution().getServer(table.getServerName());
                                obj = application.getScriptEngine().getScopesScope().executeGlobalFunction(globalScriptMethod.getScopeName(), globalScriptMethod.getName(), new Object[] { new JSColumn(c, server, table) }, false, false);
                            } catch (Exception e) {
                                Debug.error(e);
                            }
                        }
                    }
                    // Protect to writing null to null-protected columns. An exception gets written in the log.
                    if (!((obj == null) && !c.getAllowNull()))
                        s.setValue(id, obj, false);
                }
            }
        } catch (Exception ex) {
            Debug.error(ex);
        }
    }
}
Also used : IServer(com.servoy.j2db.persistence.IServer) IBaseColumn(com.servoy.base.persistence.IBaseColumn) Column(com.servoy.j2db.persistence.Column) ColumnInfo(com.servoy.j2db.persistence.ColumnInfo) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) ServoyException(com.servoy.j2db.util.ServoyException) IOException(java.io.IOException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Aggregations

IServer (com.servoy.j2db.persistence.IServer)19 RepositoryException (com.servoy.j2db.persistence.RepositoryException)14 RemoteException (java.rmi.RemoteException)12 ServoyException (com.servoy.j2db.util.ServoyException)10 ITable (com.servoy.j2db.persistence.ITable)7 Table (com.servoy.j2db.persistence.Table)7 ApplicationException (com.servoy.j2db.ApplicationException)6 Column (com.servoy.j2db.persistence.Column)5 QueryTable (com.servoy.j2db.query.QueryTable)5 QueryColumn (com.servoy.j2db.query.QueryColumn)4 SQLException (java.sql.SQLException)4 IBaseColumn (com.servoy.base.persistence.IBaseColumn)3 ColumnInfo (com.servoy.j2db.persistence.ColumnInfo)3 ArrayList (java.util.ArrayList)3 BaseQueryTable (com.servoy.base.query.BaseQueryTable)2 BufferedDataSet (com.servoy.j2db.dataprocessing.BufferedDataSet)2 Relation (com.servoy.j2db.persistence.Relation)2 Solution (com.servoy.j2db.persistence.Solution)2 CompareCondition (com.servoy.j2db.query.CompareCondition)2 QueryDelete (com.servoy.j2db.query.QueryDelete)2