Search in sources :

Example 61 with RepositoryException

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

the class ViewFoundSet method getTable.

@Override
public ITable getTable() {
    if (table == null) {
        try {
            table = manager.getTable(getDataSource());
            if (table == null) {
                table = new Table(IServer.VIEW_SERVER, DataSourceUtils.getViewDataSourceName(getDataSource()), true, ITable.VIEW, null, null);
                ((Table) table).setDataSource(getDataSource());
                for (IQuerySelectValue col : select.getColumns()) {
                    Column newCol = null;
                    QueryColumn qCol = col.getColumn();
                    if (qCol != null && qCol.getTable() != null) {
                        ITable colTable = manager.getTable(qCol.getTable().getDataSource());
                        if (colTable != null) {
                            Column column = colTable.getColumn(qCol.getName());
                            if (column != null) {
                                String colname = getColunmName(col, qCol);
                                newCol = table.createNewColumn(DummyValidator.INSTANCE, colname, column.getType(), column.getLength(), column.getScale(), column.getAllowNull());
                                if (column.getColumnInfo() != null) {
                                    DatabaseUtils.createNewColumnInfo(manager.getApplication().getFlattenedSolution().getPersistFactory().getNewElementID(null), newCol, false);
                                    newCol.getColumnInfo().copyFrom(column.getColumnInfo());
                                }
                            }
                        }
                    }
                    if (newCol == null) {
                        // existing database column not found, create column on the fly
                        BaseColumnType columnType = col.getColumnType();
                        if (columnType == null) {
                            columnType = ColumnType.getColumnType(IColumnTypes.TEXT);
                        }
                        String colname = getColunmName(col, qCol);
                        table.createNewColumn(DummyValidator.INSTANCE, colname, columnType.getSqlType(), columnType.getLength(), columnType.getScale(), true);
                    }
                }
            }
        } catch (RepositoryException e) {
            Debug.error(e);
        }
    }
    return table;
}
Also used : BaseQueryTable(com.servoy.base.query.BaseQueryTable) ITable(com.servoy.j2db.persistence.ITable) Table(com.servoy.j2db.persistence.Table) DerivedTable(com.servoy.j2db.query.DerivedTable) QueryColumn(com.servoy.j2db.query.QueryColumn) IColumn(com.servoy.j2db.persistence.IColumn) IBaseColumn(com.servoy.base.persistence.IBaseColumn) Column(com.servoy.j2db.persistence.Column) QueryColumn(com.servoy.j2db.query.QueryColumn) ITable(com.servoy.j2db.persistence.ITable) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IQuerySelectValue(com.servoy.j2db.query.IQuerySelectValue) BaseColumnType(com.servoy.base.query.BaseColumnType)

Example 62 with RepositoryException

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

the class JSDataSource method getTable.

/**
 * Get the table of a datasource.
 *
 * @return JSTable table
 */
@JSFunction
public JSTable getTable() {
    try {
        ITable table = application.getFoundSetManager().getTable(datasource);
        IServer server = application.getSolution().getServer(table.getServerName());
        if (server != null) {
            return new JSTable(table, server);
        }
    } catch (RepositoryException e) {
        Debug.log(e);
    }
    return null;
}
Also used : IServer(com.servoy.j2db.persistence.IServer) JSTable(com.servoy.j2db.dataprocessing.JSTable) ITable(com.servoy.j2db.persistence.ITable) RepositoryException(com.servoy.j2db.persistence.RepositoryException) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 63 with RepositoryException

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

the class QBJoin method createColumn.

@Override
protected QBColumn createColumn(String name) throws RepositoryException {
    ITableReference foreignTableReference = join.getForeignTableReference();
    if (foreignTableReference instanceof TableExpression) {
        Table joinTable = getRoot().getTable(foreignTableReference.getTable().getDataSource());
        if (joinTable == null) {
            throw new RepositoryException("Cannot find column '" + name + "' in data source '" + foreignTableReference.getTable().getDataSource() + "'");
        }
        Column col = joinTable.getColumn(name);
        if (col == null) {
            throw new RepositoryException("Cannot find column '" + name + "' in data source '" + foreignTableReference.getTable().getDataSource() + "'");
        }
        return new QBColumn(getRoot(), this, new QueryColumn(getQueryTable(), col.getID(), col.getSQLName(), col.getType(), col.getLength(), col.getScale(), col.getNativeTypename(), col.getFlags(), false));
    } else if (foreignTableReference instanceof DerivedTable) {
        QuerySelect query = ((DerivedTable) foreignTableReference).getQuery();
        for (IQuerySelectValue qcol : query.getColumns()) {
            if (name.equals(qcol.getAliasOrName()) || (qcol.getColumn() != null && name.equals(generateNormalizedNonReservedOSName(qcol.getColumn().getName())))) {
                return new QBColumn(getRoot(), this, new QueryColumn(foreignTableReference.getTable(), generateNormalizedNonReservedOSName(name)));
            }
        }
    }
    throw new RepositoryException("Cannot find column '" + name + "' in source '" + foreignTableReference + "'");
}
Also used : DerivedTable(com.servoy.j2db.query.DerivedTable) BaseQueryTable(com.servoy.base.query.BaseQueryTable) Table(com.servoy.j2db.persistence.Table) DerivedTable(com.servoy.j2db.query.DerivedTable) QueryColumn(com.servoy.j2db.query.QueryColumn) Column(com.servoy.j2db.persistence.Column) ITableReference(com.servoy.j2db.query.ITableReference) QueryColumn(com.servoy.j2db.query.QueryColumn) RepositoryException(com.servoy.j2db.persistence.RepositoryException) TableExpression(com.servoy.j2db.query.TableExpression) QuerySelect(com.servoy.j2db.query.QuerySelect) IQuerySelectValue(com.servoy.j2db.query.IQuerySelectValue)

Example 64 with RepositoryException

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

the class JSPortal method newButton.

/**
 * Creates a new button on the portal with the given text, place, size and JSMethod as the onClick action.
 *
 * @sample
 * var clickMethod = form.newMethod('function clickMe() { application.output("I was clicked!"); }');
 * var childrenPortal = form.newPortal('pp', 'parent_to_child', 10, 10, 620, 460);
 * childrenPortal.newButton('Click me!', 400, 100, 20, clickMethod);
 *
 * @param text The text to be displayed on the button.
 *
 * @param x The x coordinate of the button. If the portal does not have the "multiLine" property set, then the x coordinates are used only for determining the order of the columns in the grid. If the portal has the "multiLine" property set, then the components are actually displayed at the specified coordinates.
 *
 * @param width The width of the button.
 *
 * @param height The height of the button. In a portal the height of all components is set to the height of the first component, unless the "multiLine" property is set.
 *
 * @param action The JSMethod object that should be executed when the button is clicked.
 *
 * @return A JSButton instance representing the newly created button.
 */
@JSFunction
public JSButton newButton(String text, int x, int width, int height, Object action) {
    try {
        GraphicalComponent gc = getBaseComponent(true).createNewGraphicalComponent(new Point(getX() + x, getY()));
        gc.setSize(new Dimension(width, height));
        gc.setText(text);
        if (action instanceof JSMethod) {
            JSButton button = new JSButton(this, gc, application, true);
            button.setOnAction((JSMethod) action);
            return button;
        } else {
            int id = JSForm.getMethodId(action, gc, application);
            gc.setOnActionMethodID(id);
            return new JSButton(this, gc, application, true);
        }
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) RepositoryException(com.servoy.j2db.persistence.RepositoryException) Point(java.awt.Point) Dimension(java.awt.Dimension) Point(java.awt.Point) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 65 with RepositoryException

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

the class JSPortal method newField.

/**
 * Creates a new field on this form. The type of the field is specified by
 * using one of the JSField constants like JSField.TEXT_FIELD.
 *
 * @sample
 * var childrenPortal = form.newPortal('pp', 'parent_to_my_table', 10, 10, 1180, 780);
 *
 * var vlist = solutionModel.newValueList('options', JSValueList.CUSTOM_VALUES);
 * vlist.customValues = "one\ntwo\nthree\nfour";
 *
 * var cal = childrenPortal.newField('my_table_date', JSField.CALENDAR, 0, 60, 20);
 * var chk = childrenPortal.newField('my_table_options', JSField.CHECKS, 60, 60, 50);
 * chk.valuelist = vlist;
 * var cmb = childrenPortal.newField('my_table_options', JSField.COMBOBOX, 120, 160, 20);
 * cmb.valuelist = vlist;
 * var html = childrenPortal.newField('my_table_html', JSField.HTML_AREA, 180, 60, 50);
 * var img = childrenPortal.newField('my_table_image', JSField.IMAGE_MEDIA, 240, 60, 50);
 * var pwd = childrenPortal.newField('my_table_text', JSField.PASSWORD, 300, 60, 20);
 * var radio = childrenPortal.newField('my_table_options', JSField.RADIOS, 360, 60, 50);
 * radio.valuelist = vlist;
 * var rtf = childrenPortal.newField('my_table_rtf', JSField.RTF_AREA, 420, 60, 50);
 * var tarea = childrenPortal.newField('my_table_text', JSField.TEXT_AREA, 480, 60, 50);
 * var tfield = childrenPortal.newField('my_table_text', JSField.TEXT_FIELD, 540, 60, 20);
 * var tahead = childrenPortal.newField('my_table_text', JSField.TYPE_AHEAD, 600, 60, 20);
 * tahead.valuelist = vlist;
 *
 * @param dataprovider The data provider for this field. Can be either a column name, or an instance of JSVariable.
 *
 * @param displaytype The display type of the field. Use constants from JSField for this parameter.
 *
 * @param x The x coordinate of the field. If the portal does not have the "multiLine" property set, then the x coordinates are used only for determining the order of the columns in the grid. If the portal has the "multiLine" property set, then the components are actually displayed at the specified coordinates.
 *
 * @param width The width of the field.
 *
 * @param height The height of the field. In a portal the height of all components is set to the height of the first component, unless the "multiLine" property is set.
 *
 * @return A JSField instance that corresponds to the newly created field.
 */
@JSFunction
public JSField newField(Object dataprovider, int displaytype, int x, int width, int height) {
    try {
        Field field = getBaseComponent(true).createNewField(new Point(getX() + x, getY()));
        field.setDisplayType(displaytype);
        field.setSize(new Dimension(width, height));
        if (dataprovider instanceof String) {
            field.setDataProviderID((String) dataprovider);
        } else if (dataprovider instanceof JSVariable) {
            field.setDataProviderID(((JSVariable) dataprovider).getName());
        }
        return JSField.createField(this, field, application, true);
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : IBaseSMField(com.servoy.base.solutionmodel.IBaseSMField) Field(com.servoy.j2db.persistence.Field) RepositoryException(com.servoy.j2db.persistence.RepositoryException) Point(java.awt.Point) Dimension(java.awt.Dimension) JSFunction(org.mozilla.javascript.annotations.JSFunction)

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