Search in sources :

Example 6 with ColumnInfo

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

the class DatabaseUtils method updateColumnInfo.

public static void updateColumnInfo(int element_id, Column c, ColumnInfoDef cid) {
    ColumnInfo ci = new ColumnInfo(element_id, true);
    ci.setAutoEnterType(cid.autoEnterType);
    ci.setAutoEnterSubType(cid.autoEnterSubType);
    ci.setSequenceStepSize(cid.sequenceStepSize);
    ci.setPreSequenceChars(cid.preSequenceChars);
    ci.setPostSequenceChars(cid.postSequenceChars);
    ci.setDefaultValue(cid.defaultValue);
    ci.setLookupValue(cid.lookupValue);
    ci.setDatabaseSequenceName(cid.databaseSequenceName);
    ci.setTitleText(cid.titleText);
    ci.setDescription(cid.description);
    ci.setForeignType(cid.foreignType);
    ci.setConverterName(cid.converterName);
    ci.setConverterProperties(cid.converterProperties);
    ci.setValidatorProperties(cid.validatorProperties);
    ci.setValidatorName(cid.validatorName);
    ci.setDefaultFormat(cid.defaultFormat);
    ci.setElementTemplateProperties(cid.elementTemplateProperties);
    ci.setDataProviderID(cid.dataProviderID);
    ci.setContainsMetaData(cid.containsMetaData);
    ci.setConfiguredColumnType(cid.columnType);
    ci.setCompatibleColumnTypes(cid.compatibleColumnTypes);
    ci.setFlags(cid.flags);
    ci.setSortIgnorecase(cid.sortIgnorecase);
    ci.setSortingNullprecedence(cid.sortingNullprecedence);
    c.setDatabasePK((cid.flags & IBaseColumn.PK_COLUMN) != 0);
    c.setColumnInfo(ci);
}
Also used : ColumnInfo(com.servoy.j2db.persistence.ColumnInfo)

Example 7 with ColumnInfo

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

the class DatabaseUtils method createNewColumnInfo.

public static void createNewColumnInfo(int element_id, Column c, boolean createMissingServoySequence) {
    ColumnInfo ci = new ColumnInfo(element_id, false);
    if (createMissingServoySequence && c.getRowIdentType() != IBaseColumn.NORMAL_COLUMN && c.getSequenceType() == ColumnInfo.NO_SEQUENCE_SELECTED && (Column.mapToDefaultType(c.getConfiguredColumnType().getSqlType()) == IColumnTypes.INTEGER || Column.mapToDefaultType(c.getConfiguredColumnType().getSqlType()) == IColumnTypes.NUMBER)) {
        ci.setAutoEnterType(ColumnInfo.SEQUENCE_AUTO_ENTER);
        ci.setAutoEnterSubType(ColumnInfo.SERVOY_SEQUENCE);
        ci.setSequenceStepSize(1);
    }
    if (c.isUUID() && c.isDatabasePK())
        c.setSequenceType(ColumnInfo.UUID_GENERATOR);
    // when column has no columninfo and no flags it will return Column.PK_COLUMN for db pk column.
    ci.setFlags(c.getFlags());
    c.setColumnInfo(ci);
}
Also used : ColumnInfo(com.servoy.j2db.persistence.ColumnInfo)

Example 8 with ColumnInfo

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

the class DataProviderEditor method fillDataProviderList.

protected void fillDataProviderList() {
    try {
        ITable table = null;
        if (definedTable == null) {
            FormManager fm = (FormManager) application.getFormManager();
            FormController fc = fm.getCurrentMainShowingFormController();
            if (fc != null) {
                Form form = fc.getForm();
                table = application.getFlattenedSolution().getTable(form.getDataSource());
            }
        } else {
            if (!showRelatedOptionsOnly)
                table = definedTable;
        }
        DefaultListModel model = (DefaultListModel) list.getModel();
        model.removeAllElements();
        if (showNoneOption)
            model.addElement("-none-");
        if (!showColumnsOnly)
            model.addElement("*columns");
        Object o = relationsComboBox.getSelectedItem();
        if (o != null) {
            if (o instanceof String) {
            // table = form.getTable();
            } else {
                table = application.getFlattenedSolution().getTable(((Relation) o).getForeignDataSource());
            }
            if (table != null) {
                Iterator<Column> it = table.getColumnsSortedByName();
                while (it.hasNext()) {
                    IColumn c = it.next();
                    ColumnInfo ci = c.getColumnInfo();
                    if (ci != null && ci.isExcluded()) {
                        continue;
                    }
                    if (hideMediaColumns) {
                        // use dataprovider type as defined by column converter
                        ComponentFormat componentFormat = ComponentFormat.getComponentFormat(null, c, application);
                        if (componentFormat.dpType == IColumnTypes.MEDIA) {
                            continue;
                        }
                    }
                    model.addElement(c);
                }
            }
        }
        FlattenedSolution s = application.getFlattenedSolution();
        if (table != null && !showColumnsOnly) {
            Iterator it = s.getScriptCalculations(table, true);
            if (it.hasNext()) {
                model.addElement("*calculations");
            }
            while (it.hasNext()) {
                ScriptCalculation sc = (ScriptCalculation) it.next();
                for (int i = 0; i < model.size(); i++) {
                    Object obj = model.elementAt(i);
                    if (obj instanceof IDataProvider) {
                        IDataProvider dp = (IDataProvider) obj;
                        if (dp.getDataProviderID().equals(sc.getDataProviderID())) {
                            // remove the column from the list if use by
                            model.remove(i);
                            // stored calc
                            break;
                        }
                    }
                }
                model.addElement(sc);
            }
            Iterator it2 = s.getScriptVariables(true);
            if (it2.hasNext()) {
                model.addElement("*globals");
            }
            while (it2.hasNext()) {
                model.addElement(it2.next());
            }
            Iterator it3 = s.getAggregateVariables(table, true);
            if (it3.hasNext()) {
                model.addElement("*aggregates");
            }
            while (it3.hasNext()) {
                model.addElement(it3.next());
            }
        }
        if (table != null && showColumnsOnly && showSortableOnly) {
            Iterator it3 = s.getAggregateVariables(table, true);
            while (it3.hasNext()) {
                model.addElement(it3.next());
            }
        }
        if (showGlobalsOption && showColumnsOnly) {
            Iterator it2 = s.getScriptVariables(true);
            if (it2.hasNext()) {
                model.addElement("*globals");
            }
            while (it2.hasNext()) {
                model.addElement(it2.next());
            }
        }
    } catch (Exception ex) {
        Debug.error(ex);
    }
}
Also used : FormController(com.servoy.j2db.FormController) Form(com.servoy.j2db.persistence.Form) DefaultListModel(javax.swing.DefaultListModel) ColumnInfo(com.servoy.j2db.persistence.ColumnInfo) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IDataProvider(com.servoy.j2db.persistence.IDataProvider) ScriptCalculation(com.servoy.j2db.persistence.ScriptCalculation) Relation(com.servoy.j2db.persistence.Relation) FormManager(com.servoy.j2db.FormManager) IColumn(com.servoy.j2db.persistence.IColumn) Column(com.servoy.j2db.persistence.Column) IColumn(com.servoy.j2db.persistence.IColumn) Iterator(java.util.Iterator) ITable(com.servoy.j2db.persistence.ITable) ComponentFormat(com.servoy.j2db.component.ComponentFormat)

Example 9 with ColumnInfo

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

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

the class SQLGenerator method makeQueryColumns.

private static ArrayList<IQuerySelectValue> makeQueryColumns(Iterator<Column> it, QueryTable queryTable, QueryInsert insert) {
    ArrayList<IQuerySelectValue> queryColumns = new ArrayList<IQuerySelectValue>();
    List<QueryColumn> insertColumns = new ArrayList<QueryColumn>();
    while (it.hasNext()) {
        Column column = it.next();
        ColumnInfo ci = column.getColumnInfo();
        if (ci != null && ci.isExcluded()) {
            continue;
        }
        QueryColumn queryColumn = column.queryColumn(queryTable);
        if (isBlobColumn(column)) {
            String alias = column.getDataProviderID().substring(0, Math.min(Column.MAX_SQL_OBJECT_NAME_LENGTH - (IDataServer.BLOB_MARKER_COLUMN_ALIAS.length() + 1), column.getDataProviderID().length())) + '_' + IDataServer.BLOB_MARKER_COLUMN_ALIAS;
            // make sure the alias is unique (2 media columns starting with the same name may clash here)
            char c = 'a';
            for (int i = 0; i < queryColumns.size(); i++) {
                IQuerySelectValue sv = queryColumns.get(i);
                if (alias.equals(sv.getAlias())) {
                    // alias not unique, replace first char to make it unique
                    alias = (c++) + alias.substring(1);
                    // search again
                    i = 0;
                }
            }
            queryColumns.add(new QueryColumnValue(Integer.valueOf(1), alias, true));
        } else {
            queryColumns.add(queryColumn);
        }
        if (insert != null && (ci == null || !ci.isDBManaged())) {
            insertColumns.add(queryColumn);
        }
    }
    if (insert != null) {
        insert.setColumnValues(insertColumns.toArray(new QueryColumn[insertColumns.size()]), new Placeholder(new TablePlaceholderKey(queryTable, PLACEHOLDER_INSERT_KEY)));
    }
    return queryColumns;
}
Also used : Placeholder(com.servoy.j2db.query.Placeholder) TablePlaceholderKey(com.servoy.j2db.query.TablePlaceholderKey) ArrayList(java.util.ArrayList) SafeArrayList(com.servoy.j2db.util.SafeArrayList) ColumnInfo(com.servoy.j2db.persistence.ColumnInfo) QueryColumnValue(com.servoy.j2db.query.QueryColumnValue) QueryColumn(com.servoy.j2db.query.QueryColumn) BaseQueryColumn(com.servoy.base.query.BaseQueryColumn) IColumn(com.servoy.j2db.persistence.IColumn) Column(com.servoy.j2db.persistence.Column) QueryColumn(com.servoy.j2db.query.QueryColumn) BaseQueryColumn(com.servoy.base.query.BaseQueryColumn) IQuerySelectValue(com.servoy.j2db.query.IQuerySelectValue)

Aggregations

ColumnInfo (com.servoy.j2db.persistence.ColumnInfo)21 Column (com.servoy.j2db.persistence.Column)14 RepositoryException (com.servoy.j2db.persistence.RepositoryException)9 IBaseColumn (com.servoy.base.persistence.IBaseColumn)8 IColumn (com.servoy.j2db.persistence.IColumn)8 IOException (java.io.IOException)6 ITable (com.servoy.j2db.persistence.ITable)5 QueryColumn (com.servoy.j2db.query.QueryColumn)5 IDataProvider (com.servoy.j2db.persistence.IDataProvider)4 Table (com.servoy.j2db.persistence.Table)4 ServoyException (com.servoy.j2db.util.ServoyException)4 ArrayList (java.util.ArrayList)4 IServer (com.servoy.j2db.persistence.IServer)3 Placeholder (com.servoy.j2db.query.Placeholder)3 QuerySelect (com.servoy.j2db.query.QuerySelect)3 QueryTable (com.servoy.j2db.query.QueryTable)3 TablePlaceholderKey (com.servoy.j2db.query.TablePlaceholderKey)3 SafeArrayList (com.servoy.j2db.util.SafeArrayList)3 RemoteException (java.rmi.RemoteException)3 BaseQueryColumn (com.servoy.base.query.BaseQueryColumn)2