Search in sources :

Example 1 with Table

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

the class WebCellAdapter method isDBDataprovider.

private boolean isDBDataprovider() {
    if (isDBDataproviderObj == null) {
        isDBDataproviderObj = Boolean.FALSE;
        ITable table = view.getDataAdapterList().getFormController().getTable();
        if (table instanceof Table) {
            Table tableObj = (Table) table;
            Iterator<Column> columns = tableObj.getColumns().iterator();
            while (columns.hasNext()) {
                Column col = columns.next();
                ColumnInfo ci = col.getColumnInfo();
                if (ci != null && ci.isExcluded()) {
                    continue;
                }
                if (col.getDataProviderID() == dataprovider) {
                    isDBDataproviderObj = Boolean.TRUE;
                    break;
                }
            }
            Iterator<TableNode> tableNodes = view.getDataAdapterList().getApplication().getFlattenedSolution().getTableNodes(table);
            while (tableNodes.hasNext()) {
                TableNode tableNode = tableNodes.next();
                if (tableNode != null) {
                    Iterator<IPersist> it2 = tableNode.getAllObjects();
                    while (it2.hasNext()) {
                        IPersist persist = it2.next();
                        if (persist instanceof IDataProvider && (((IDataProvider) persist).getDataProviderID() == dataprovider)) {
                            isDBDataproviderObj = Boolean.FALSE;
                        }
                    }
                }
            }
        }
    }
    return isDBDataproviderObj.booleanValue();
}
Also used : ITable(com.servoy.j2db.persistence.ITable) Table(com.servoy.j2db.persistence.Table) Column(com.servoy.j2db.persistence.Column) IPersist(com.servoy.j2db.persistence.IPersist) TableNode(com.servoy.j2db.persistence.TableNode) ColumnInfo(com.servoy.j2db.persistence.ColumnInfo) ITable(com.servoy.j2db.persistence.ITable) IDataProvider(com.servoy.j2db.persistence.IDataProvider)

Example 2 with Table

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

the class FlattenedSolution method getValuelistSortRelation.

/**
 * Get the internal relation that can be used to sort on this value list using the display values.
 * @param valueList
 * @param callingTable
 * @param dataProviderID
 * @param foundSetManager
 * @return
 * @throws RepositoryException
 */
public Relation getValuelistSortRelation(ValueList valueList, Table callingTable, String dataProviderID, IFoundSetManagerInternal foundSetManager) throws RepositoryException {
    if (callingTable == null || valueList == null) {
        return null;
    }
    String destDataSource;
    Relation[] relationSequence;
    String relationPrefix;
    switch(valueList.getDatabaseValuesType()) {
        case IValueListConstants.TABLE_VALUES:
            // create an internal relation
            relationSequence = null;
            // $NON-NLS-1$
            relationPrefix = "";
            destDataSource = valueList.getDataSource();
            break;
        case IValueListConstants.RELATED_VALUES:
            // replace the last relation in the sequence with an internal relation
            relationSequence = getRelationSequence(valueList.getRelationName());
            if (relationSequence == null) {
                return null;
            }
            if (relationSequence.length > 1) {
                for (Relation r : relationSequence) {
                    if (r.getJoinType() != INNER_JOIN) {
                        // outer join on the intermediate tables causes extra results that influence the sorting result
                        return null;
                    }
                }
            }
            StringBuilder sb = new StringBuilder();
            for (Relation r : relationSequence) {
                sb.append('-').append(r.getName());
            }
            relationPrefix = sb.toString();
            destDataSource = relationSequence[relationSequence.length - 1].getForeignDataSource();
            break;
        default:
            return null;
    }
    if (destDataSource == null || !DataSourceUtils.isSameServer(callingTable.getDataSource(), destDataSource)) {
        // do not create a cross-server relation
        return null;
    }
    Table destTable = (Table) foundSetManager.getTable(destDataSource);
    if (destTable == null) {
        return null;
    }
    String relationName = // $NON-NLS-1$
    Relation.INTERNAL_PREFIX + "VL-" + callingTable.getDataSource() + '-' + dataProviderID + relationPrefix + '-' + valueList.getName() + '-';
    synchronized (this) {
        Column callingColumn = callingTable.getColumn(dataProviderID);
        if (callingColumn == null) {
            return null;
        }
        Relation relation = getRelation(relationName);
        if (relation == null) {
            // create in internal relation
            String dp;
            int returnValues = valueList.getReturnDataProviders();
            if ((returnValues & 1) != 0) {
                dp = valueList.getDataProviderID1();
            } else if ((returnValues & 2) != 0) {
                dp = valueList.getDataProviderID2();
            } else if ((returnValues & 4) != 0) {
                dp = valueList.getDataProviderID3();
            } else {
                return null;
            }
            Column destColumn = destTable.getColumn(dp);
            if (destColumn == null) {
                return null;
            }
            // create internal value list relation
            QueryTable callingQTable = new QueryTable(callingTable.getSQLName(), callingTable.getDataSource(), callingTable.getCatalog(), callingTable.getSchema());
            QueryTable destQTable = new QueryTable(destTable.getSQLName(), destTable.getDataSource(), destTable.getCatalog(), destTable.getSchema());
            List<ISQLTableJoin> joins = new ArrayList<ISQLTableJoin>();
            ISQLTableJoin lastJoin = null;
            if (relationSequence == null) {
                // table values
                joins.add(lastJoin = new QueryJoin(relationName, callingQTable, destQTable, new AndCondition(), LEFT_OUTER_JOIN, false));
                if (// apply name as filter on column valuelist_name
                valueList.getUseTableFilter()) {
                    lastJoin.getCondition().addCondition(new CompareCondition(IBaseSQLCondition.EQUALS_OPERATOR, new QueryColumn(destQTable, DBValueList.NAME_COLUMN), valueList.getName()));
                }
            } else {
                // related values
                QueryTable primaryQTable = callingQTable;
                for (int i = 0; i < relationSequence.length; i++) {
                    Relation r = relationSequence[i];
                    QueryTable foreignQTable;
                    if (i == relationSequence.length - 1) {
                        // last one
                        foreignQTable = destQTable;
                    } else {
                        ITable relForeignTable = getTable(r.getForeignDataSource());
                        if (relForeignTable == null) {
                            return null;
                        }
                        foreignQTable = new QueryTable(relForeignTable.getSQLName(), relForeignTable.getDataSource(), relForeignTable.getCatalog(), relForeignTable.getSchema());
                    }
                    lastJoin = SQLGenerator.createJoin(this, r, primaryQTable, foreignQTable, false, new IGlobalValueEntry() {

                        public Object setDataProviderValue(String dpid, Object value) {
                            return null;
                        }

                        public Object getDataProviderValue(String dpid) {
                            // A value will be added when the relation is used, see SQLGenerator.createJoin
                            return new Placeholder(new ObjectPlaceholderKey<int[]>(null, dpid));
                        }

                        public boolean containsDataProvider(String dpid) {
                            return false;
                        }
                    });
                    joins.add(lastJoin);
                    primaryQTable = foreignQTable;
                }
            }
            // add condition for return dp id
            lastJoin.getCondition().addCondition(new CompareCondition(IBaseSQLCondition.EQUALS_OPERATOR, destColumn.queryColumn(destQTable), callingColumn.queryColumn(callingQTable)));
            relation = getSolutionCopy().createNewRelation(new ScriptNameValidator(this), relationName, callingTable.getDataSource(), destDataSource, LEFT_OUTER_JOIN);
            ISQLTableJoin join;
            if (joins.size() == 1) {
                join = lastJoin;
            } else {
                // combine joins
                join = new QueryCompositeJoin(relationName, joins);
            }
            relation.setRuntimeProperty(Relation.RELATION_JOIN, join);
        }
        return relation;
    }
}
Also used : Placeholder(com.servoy.j2db.query.Placeholder) Table(com.servoy.j2db.persistence.Table) QueryTable(com.servoy.j2db.query.QueryTable) ITable(com.servoy.j2db.persistence.ITable) ArrayList(java.util.ArrayList) QueryJoin(com.servoy.j2db.query.QueryJoin) QueryTable(com.servoy.j2db.query.QueryTable) AndCondition(com.servoy.j2db.query.AndCondition) Relation(com.servoy.j2db.persistence.Relation) IGlobalValueEntry(com.servoy.j2db.dataprocessing.IGlobalValueEntry) QueryCompositeJoin(com.servoy.j2db.query.QueryCompositeJoin) QueryColumn(com.servoy.j2db.query.QueryColumn) Column(com.servoy.j2db.persistence.Column) IColumn(com.servoy.j2db.persistence.IColumn) ISQLTableJoin(com.servoy.j2db.query.ISQLTableJoin) QueryColumn(com.servoy.j2db.query.QueryColumn) CompareCondition(com.servoy.j2db.query.CompareCondition) ITable(com.servoy.j2db.persistence.ITable) JSONObject(org.json.JSONObject) IRootObject(com.servoy.j2db.persistence.IRootObject) ScriptNameValidator(com.servoy.j2db.persistence.ScriptNameValidator)

Example 3 with Table

use of com.servoy.j2db.persistence.Table 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 4 with Table

use of com.servoy.j2db.persistence.Table 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 5 with Table

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

the class QBJoins method getOrAddRelation.

private QBJoin getOrAddRelation(IRelation relation, String relationName, String alias) {
    if (relation == null || !parent.getDataSource().equals(relation.getPrimaryDataSource())) {
        if (relation == null) {
            Debug.log("relation '" + relationName + "' not found");
        } else {
            Debug.log("relation '" + relationName + "' does not match parent data source: " + parent.getDataSource() + '/' + relation.getPrimaryDataSource());
        }
        return null;
    }
    String name = alias == null ? relationName : alias;
    QBJoin join = getJoin(name);
    if (join == null) {
        try {
            Table foreignTable = root.getTable(relation.getForeignDataSource());
            if (foreignTable == null) {
                Debug.log("foreign table for relation '" + relationName + "' not found");
                return null;
            }
            join = addJoin(SQLGenerator.createJoin(root.getDataProviderHandler(), relation, parent.getQueryTable(), new QueryTable(foreignTable.getSQLName(), foreignTable.getDataSource(), foreignTable.getCatalog(), foreignTable.getSchema(), alias), true, root.getGlobalScopeProvider()), relation.getForeignDataSource(), name);
        } catch (RepositoryException e) {
            Debug.error("could not load relation '" + relationName + "'", e);
        }
    }
    return join;
}
Also used : DerivedTable(com.servoy.j2db.query.DerivedTable) QueryTable(com.servoy.j2db.query.QueryTable) Table(com.servoy.j2db.persistence.Table) RepositoryException(com.servoy.j2db.persistence.RepositoryException) QueryTable(com.servoy.j2db.query.QueryTable)

Aggregations

Table (com.servoy.j2db.persistence.Table)43 ITable (com.servoy.j2db.persistence.ITable)27 QueryTable (com.servoy.j2db.query.QueryTable)26 RepositoryException (com.servoy.j2db.persistence.RepositoryException)23 BaseQueryTable (com.servoy.base.query.BaseQueryTable)22 Column (com.servoy.j2db.persistence.Column)21 ServoyException (com.servoy.j2db.util.ServoyException)17 QueryColumn (com.servoy.j2db.query.QueryColumn)16 QuerySelect (com.servoy.j2db.query.QuerySelect)16 ArrayList (java.util.ArrayList)16 RemoteException (java.rmi.RemoteException)14 ApplicationException (com.servoy.j2db.ApplicationException)13 IColumn (com.servoy.j2db.persistence.IColumn)10 IBaseColumn (com.servoy.base.persistence.IBaseColumn)9 IServer (com.servoy.j2db.persistence.IServer)7 Relation (com.servoy.j2db.persistence.Relation)7 HashMap (java.util.HashMap)7 SortColumn (com.servoy.j2db.dataprocessing.SortColumn)6 SafeArrayList (com.servoy.j2db.util.SafeArrayList)6 ColumnInfo (com.servoy.j2db.persistence.ColumnInfo)5