Search in sources :

Example 16 with RepositoryException

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

the class DataAdapterList method valueChanged.

/*
	 * _____________________________________________________________ JavaScriptModificationListner
	 */
/**
 * listen for global var changes via own listener and state vars(mainly columns) via state listener if via javascript any var is changed it will be noted
 * here,and dispatched to refresh the displays
 */
public void valueChanged(ModificationEvent e) {
    if (destroyed) {
        Debug.error("Destroyed DataAdapterList " + formController + " was still attached to the record: " + e.getRecord() + ", removing it if possible, currentRecord: " + currentRecord, new RuntimeException());
        if (e.getRecord() != null)
            e.getRecord().removeModificationListener(this);
        else if (currentRecord != null)
            currentRecord.removeModificationListener(this);
        return;
    }
    if (formController != null && formController.isDestroyed()) {
        Debug.error("Destroying DataAdapterList of a destroyed " + formController, new RuntimeException());
        destroy();
        return;
    }
    FormScope formScope = getFormScope();
    if (visible && (currentRecord != null || (formScope != null && formScope.has(e.getName(), formScope)))) {
        for (IDataAdapter da : dataAdapters.values()) {
            // dataAdapter should call state.getValue if name from event is same as its dataProviderID
            da.valueChanged(e);
        }
        // check if a related adapter depends on he global
        if (e != null && e.getName() != null) {
            for (IDisplayRelatedData drd : relatedDataAdapters) {
                boolean depends = false;
                String[] allRelationNames = drd.getAllRelationNames();
                for (int a = 0; !depends && allRelationNames != null && a < allRelationNames.length; a++) {
                    Relation[] relations = application.getFlattenedSolution().getRelationSequence(allRelationNames[a]);
                    for (int r = 0; !depends && relations != null && r < relations.length; r++) {
                        try {
                            IDataProvider[] primaryDataProviders = relations[r].getPrimaryDataProviders(application.getFlattenedSolution());
                            for (int p = 0; !depends && primaryDataProviders != null && p < primaryDataProviders.length; p++) {
                                depends = e.getName().equals(primaryDataProviders[p].getDataProviderID());
                            }
                        } catch (RepositoryException ex) {
                            Debug.log(ex);
                        }
                    }
                }
                if (depends) {
                    // related adapter depends on the modified global
                    if (drd instanceof IDisplayDependencyData)
                        ((IDisplayDependencyData) drd).dependencyChanged(currentRecord);
                    else
                        drd.setRecord(currentRecord, true);
                }
            }
        }
        // inform servoy aware beans
        for (IServoyAwareBean drd : servoyAwareBeans) {
            if (drd instanceof IModificationListener) {
                try {
                    ((IModificationListener) drd).valueChanged(e);
                } catch (RuntimeException ex) {
                    // never make the app break on faulty beans
                    Debug.error(ex);
                }
            }
        }
    }
}
Also used : RepositoryException(com.servoy.j2db.persistence.RepositoryException) IDataProvider(com.servoy.j2db.persistence.IDataProvider) FormScope(com.servoy.j2db.scripting.FormScope) Relation(com.servoy.j2db.persistence.Relation) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean)

Example 17 with RepositoryException

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

the class I18NMessagesTable method createMessagesTable.

public static ITable createMessagesTable(IServerInternal server, String tablename, int primaryKeySequenceType) throws RepositoryException, SQLException {
    // Create the table in the repository.
    IValidateName validator = DummyValidator.INSTANCE;
    ITable table = server.createNewTable(validator, tablename);
    if (primaryKeySequenceType == ColumnInfo.UUID_GENERATOR) {
        Column column = table.createNewColumn(validator, "message_id", IColumnTypes.TEXT, 36);
        column.setDatabasePK(true);
        column.setSequenceType(primaryKeySequenceType);
        column.setFlag(IBaseColumn.UUID_COLUMN, true);
    } else {
        Column column = table.createNewColumn(validator, "message_id", Types.INTEGER, 0, 0, false, true);
        column.setSequenceType(primaryKeySequenceType);
    }
    table.createNewColumn(validator, "message_key", Types.VARCHAR, 150, 0, false);
    Column messageLanguage = table.createNewColumn(validator, "message_language", Types.VARCHAR, 150, 0, true);
    table.createNewColumn(validator, "message_value", Types.VARCHAR, 2000, 0, true);
    server.syncTableObjWithDB(table, false, false);
    try {
        server.createIndex(table, table.getName() + "_m_l", new Column[] { messageLanguage }, false);
    } catch (Exception e) {
        Debug.error("Failed to create an index on the messages table", e);
    }
    return table;
}
Also used : IBaseColumn(com.servoy.base.persistence.IBaseColumn) Column(com.servoy.j2db.persistence.Column) ITable(com.servoy.j2db.persistence.ITable) IValidateName(com.servoy.j2db.persistence.IValidateName) SQLException(java.sql.SQLException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Example 18 with RepositoryException

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

the class ViewFoundSet method loadAllRecordsImpl.

private void loadAllRecordsImpl() throws ServoyException {
    String serverName = DataSourceUtils.getDataSourceServerName(select.getTable().getDataSource());
    String transaction_id = manager.getTransactionID(serverName);
    try {
        IDataSet ds = manager.getApplication().getDataServer().performQuery(manager.getApplication().getClientID(), serverName, transaction_id, select, null, manager.getTableFilterParams(serverName, select), select.isUnique(), 0, currentChunkSize, IDataServer.FOUNDSET_LOAD_QUERY);
        refresh = false;
        ArrayList<IQuerySelectValue> cols = select.getColumns();
        int currentSize = records.size();
        List<ViewRecord> old = records;
        records = new ArrayList<>(ds.getRowCount());
        pkByDatasourceCache.clear();
        String[] colNames = columnNames.values().toArray(new String[columnNames.size()]);
        try (FireCollector fireCollector = getFireCollector()) {
            for (int i = 0; i < ds.getRowCount(); i++) {
                Object[] rowData = ds.getRow(i);
                if (i < currentSize) {
                    ViewRecord current = old.get(i);
                    records.add(current);
                    current.updateValues(colNames, rowData);
                } else {
                    records.add(new ViewRecord(colNames, rowData, this));
                }
            }
        }
        hasMore = ds.hadMoreRows();
        fireDifference(currentSize, records.size());
    } catch (RemoteException e) {
        throw new RepositoryException(e);
    }
}
Also used : FireCollector.getFireCollector(com.servoy.j2db.dataprocessing.FireCollector.getFireCollector) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IConstantsObject(com.servoy.j2db.scripting.IConstantsObject) RemoteException(java.rmi.RemoteException) IQuerySelectValue(com.servoy.j2db.query.IQuerySelectValue)

Example 19 with RepositoryException

use of com.servoy.j2db.persistence.RepositoryException 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)

Example 20 with RepositoryException

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

the class PartNode method getAggregatesFromRenderer.

private void getAggregatesFromRenderer(final List<AggregateVariable> aggregates, final Form f, DataRenderer a_renderer) throws RepositoryException {
    Map<IPersist, IDisplay> allFields = a_renderer.getFieldComponents();
    Iterator<IDisplay> it = allFields.values().iterator();
    while (it.hasNext()) {
        IDisplay display = it.next();
        if (display instanceof IDisplayData) {
            String dataProviderID = ((IDisplayData) display).getDataProviderID();
            if (dataProviderID != null) {
                IDataProvider dp = application.getFlattenedSolution().getDataproviderLookup(application.getFoundSetManager(), f).getDataProvider(dataProviderID);
                if (dp instanceof AggregateVariable) {
                    if (!aggregates.contains(dp))
                        aggregates.add((AggregateVariable) dp);
                }
            } else if (display instanceof IDisplayTagText) {
                String tagText = ((IDisplayTagText) display).getTagText();
                Text.processTags(tagText, new ITagResolver() {

                    public String getStringValue(String name) {
                        try {
                            IDataProvider dp = application.getFlattenedSolution().getDataproviderLookup(application.getFoundSetManager(), f).getDataProvider(name);
                            if (dp instanceof AggregateVariable) {
                                if (!aggregates.contains(dp))
                                    aggregates.add((AggregateVariable) dp);
                            }
                        } catch (Exception e) {
                            Debug.error(e);
                        }
                        return null;
                    }
                });
            }
        }
    }
}
Also used : IPersist(com.servoy.j2db.persistence.IPersist) ITagResolver(com.servoy.base.util.ITagResolver) IDisplay(com.servoy.j2db.dataprocessing.IDisplay) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) IDataProvider(com.servoy.j2db.persistence.IDataProvider) AggregateVariable(com.servoy.j2db.persistence.AggregateVariable) IDisplayTagText(com.servoy.j2db.ui.IDisplayTagText) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Aggregations

RepositoryException (com.servoy.j2db.persistence.RepositoryException)116 RemoteException (java.rmi.RemoteException)45 QuerySelect (com.servoy.j2db.query.QuerySelect)25 ITable (com.servoy.j2db.persistence.ITable)22 JSFunction (org.mozilla.javascript.annotations.JSFunction)22 ServoyException (com.servoy.j2db.util.ServoyException)21 Column (com.servoy.j2db.persistence.Column)19 ArrayList (java.util.ArrayList)19 BaseQueryTable (com.servoy.base.query.BaseQueryTable)16 Table (com.servoy.j2db.persistence.Table)16 QueryTable (com.servoy.j2db.query.QueryTable)16 FlattenedSolution (com.servoy.j2db.FlattenedSolution)14 Point (java.awt.Point)14 IDataProvider (com.servoy.j2db.persistence.IDataProvider)13 QueryColumn (com.servoy.j2db.query.QueryColumn)13 IColumn (com.servoy.j2db.persistence.IColumn)12 ApplicationException (com.servoy.j2db.ApplicationException)11 ScriptNameValidator (com.servoy.j2db.persistence.ScriptNameValidator)10 SafeArrayList (com.servoy.j2db.util.SafeArrayList)10 FoundSetManager (com.servoy.j2db.dataprocessing.FoundSetManager)8