Search in sources :

Example 11 with IColumn

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

the class MetaDataUtils method canBeMarkedAsMetaData.

public static boolean canBeMarkedAsMetaData(ITable table) {
    for (IColumn column : table.getRowIdentColumns()) {
        if (column.getColumnInfo() == null || !column.getColumnInfo().hasFlag(IBaseColumn.UUID_COLUMN)) {
            return false;
        }
    }
    IColumn column = table.getColumn(METADATA_MODIFICATION_COLUMN);
    if (column == null || column.getDataProviderType() != IColumnTypes.DATETIME)
        return false;
    column = table.getColumn(METADATA_DELETION_COLUMN);
    if (column == null || column.getDataProviderType() != IColumnTypes.DATETIME)
        return false;
    return true;
}
Also used : IColumn(com.servoy.j2db.persistence.IColumn)

Example 12 with IColumn

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

the class DatabaseUtils method deserializeInMemoryTable.

public static void deserializeInMemoryTable(IPersistFactory persistFactory, ITable t, ServoyJSONObject property) throws RepositoryException, JSONException {
    int existingColumnInfo = 0;
    TableDef tableInfo = deserializeTableInfo(property);
    // if (!t.getName().equals(tableInfo.name))
    // {
    // throw new RepositoryException("Table name does not match dbi file name for " + t.getName());
    // }
    List<IColumn> changedColumns = null;
    if (tableInfo.columnInfoDefSet.size() > 0) {
        changedColumns = new ArrayList<IColumn>(tableInfo.columnInfoDefSet.size());
        for (ColumnInfoDef cid : tableInfo.columnInfoDefSet) {
            String cname = cid.name;
            Column c = t.getColumn(cname);
            if (c == null) {
                c = t.createNewColumn(DummyValidator.INSTANCE, cid.name, cid.columnType.getSqlType(), cid.columnType.getLength(), cid.columnType.getScale(), cid.allowNull);
                existingColumnInfo++;
                updateColumnInfo(persistFactory.getNewElementID(null), c, cid);
                changedColumns.add(c);
            }
        }
    }
    Iterator<Column> columns = t.getColumns().iterator();
    while (columns.hasNext()) {
        Column c = columns.next();
        if (c.getColumnInfo() == null) {
            // only create servoy sequences when this was a new table and there is only 1 pk column
            // was missing - create automatic sequences if missing
            createNewColumnInfo(persistFactory.getNewElementID(null), c, existingColumnInfo == 0 && t.getPKColumnTypeRowIdentCount() == 1);
        }
    }
    // if (t.getRowIdentColumnsCount() == 0)
    // {
    // t.setHiddenInDeveloperBecauseNoPk(true);
    // s.setTableMarkedAsHiddenInDeveloper(t.getName(), true);
    // }
    // else s.setTableMarkedAsHiddenInDeveloper(t.getName(), tableInfo.hiddenInDeveloper);
    t.setMarkedAsMetaData(Boolean.TRUE.equals(tableInfo.isMetaData));
    // let table editors and so on now that a columns are loaded
    t.fireIColumnsChanged(changedColumns);
}
Also used : IColumn(com.servoy.j2db.persistence.IColumn) IBaseColumn(com.servoy.base.persistence.IBaseColumn) IColumn(com.servoy.j2db.persistence.IColumn) Column(com.servoy.j2db.persistence.Column) TableDef(com.servoy.j2db.util.xmlxport.TableDef) ColumnInfoDef(com.servoy.j2db.util.xmlxport.ColumnInfoDef)

Example 13 with IColumn

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

the class SortModel method getValueAt.

public Object getValueAt(int row, int col) {
    SortColumn v = rows.get(row);
    switch(col) {
        case -1:
            return v;
        // return new Boolean(v.getInUse());
        case 0:
            String title = null;
            IColumn c = v.getColumn();
            if (c instanceof Column) {
                title = ((Column) c).getTitle();
            }
            return (title == null ? v.getName() : title);
        case 1:
            return new Integer(v.getSortOrder());
        default:
            return null;
    }
}
Also used : IColumn(com.servoy.j2db.persistence.IColumn) IColumn(com.servoy.j2db.persistence.IColumn) SortColumn(com.servoy.j2db.dataprocessing.SortColumn) Column(com.servoy.j2db.persistence.Column) SortColumn(com.servoy.j2db.dataprocessing.SortColumn)

Example 14 with IColumn

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

the class DataproviderTypeSabloValue method dataProviderOrRecordChanged.

@Override
public void dataProviderOrRecordChanged(final IRecordInternal record, final String dataProvider, final boolean isFormDP, final boolean isGlobalDP, boolean fireChangeEvent) {
    // TODO can type or fieldFormat change, for example in scripting the format is reset (but type shouldn't really change)
    IDataProviderLookup dpLookup = new FormAndTableDataProviderLookup(servoyDataConverterContext.getApplication().getFlattenedSolution(), servoyDataConverterContext.getForm().getForm(), record != null ? record.getParentFoundSet().getTable() : null);
    Collection<PropertyDescription> properties = webObjectContext.getProperties(TypesRegistry.getType(FormatPropertyType.TYPE_NAME));
    FormatTypeSabloValue formatSabloValue = null;
    for (PropertyDescription formatPd : properties) {
        // see whether format if "for" this property (dataprovider)
        Object formatConfig = formatPd.getConfig();
        if (formatConfig instanceof String[] && Arrays.asList((String[]) formatConfig).indexOf(dpPD.getName()) != -1) {
            INGApplication application = servoyDataConverterContext.getApplication();
            formatSabloValue = (FormatTypeSabloValue) webObjectContext.getProperty(formatPd.getName());
            if (formatSabloValue != null) {
                if (formatSabloValue.getFormatDesignValue() != null) {
                    fieldFormat = ComponentFormat.getComponentFormat(formatSabloValue.getFormatDesignValue(), dataProviderID, dpLookup, application);
                }
                break;
            }
        }
    }
    if (fieldFormat != null) {
        typeOfDP = NGUtils.getDataProviderPropertyDescription(fieldFormat.uiType, getDataProviderConfig().hasParseHtml(), fieldFormat.parsedFormat.useLocalDateTime());
        if (record instanceof FindState) {
            ((FindState) record).setFormat(dataProviderID, fieldFormat.parsedFormat);
        }
    } else {
        // see type of dataprovider; this is done only once - first time we get a new record
        typeOfDP = NGUtils.getDataProviderPropertyDescription(dataProviderID, servoyDataConverterContext.getApplication(), servoyDataConverterContext.getForm().getForm(), record != null ? record.getParentFoundSet().getTable() : null, getDataProviderConfig().hasParseHtml(), formatSabloValue != null ? formatSabloValue.getComponentFormat().parsedFormat.useLocalDateTime() : false);
    }
    if (dpPD.hasTag(TAG_TYPE_NAME)) {
        IPropertyType<?> specType = TypesRegistry.getType((String) dpPD.getTag(TAG_TYPE_NAME));
        if (specType != null && (typeOfDP == null || !specType.getClass().isAssignableFrom(typeOfDP.getClass()))) {
            typeOfDP = new PropertyDescriptionBuilder().withName("Spec type hint").withType(specType).build();
        }
    }
    String dpID = dataProviderID;
    IDataProvider dp = null;
    if (dpLookup != null) {
        try {
            dp = dpLookup.getDataProvider(dataProviderID);
            if (dp != null) {
                dpID = dp.getDataProviderID();
            }
        } catch (RepositoryException e) {
            Debug.error(e);
        }
    }
    if (globalRelationName != null) {
        try {
            IFoundSetInternal newRelatedFoundset = servoyDataConverterContext.getApplication().getFoundSetManager().getGlobalRelatedFoundSet(globalRelationName);
            if (newRelatedFoundset != globalRelatedFoundset) {
                if (globalRelatedFoundsetListener == null) {
                    globalRelatedFoundsetListener = new IFoundSetEventListener() {

                        @Override
                        public void foundSetChanged(FoundSetEvent e) {
                            if (e.getType() == FoundSetEvent.CONTENTS_CHANGED) {
                                dataProviderOrRecordChanged(DataproviderTypeSabloValue.this.dataAdapterList.getRecord(), null, false, false, true);
                            }
                        }
                    };
                } else if (globalRelatedFoundset != null) {
                    globalRelatedFoundset.removeFoundSetEventListener(globalRelatedFoundsetListener);
                }
                globalRelatedFoundset = newRelatedFoundset;
                globalRelatedFoundset.addFoundSetEventListener(globalRelatedFoundsetListener);
            }
        } catch (Exception ex) {
            Debug.error(ex);
        }
    }
    if (relatedFoundsetSelectionListener != null) {
        try {
            ArrayList<IFoundSetInternal> newRelatedFoundsets = getRelatedFoundsets(record, relationName);
            boolean equals = testByReference(newRelatedFoundsets, this.relatedFoundsets);
            if (!equals) {
                IDataProvider column = dp;
                if (column instanceof ColumnWrapper) {
                    column = ((ColumnWrapper) column).getColumn();
                }
                boolean isAggregate = (column instanceof IColumn) ? ((IColumn) column).isAggregate() : false;
                if (isAggregate && relatedFoundsets.size() > 0) {
                    relatedFoundsets.get(relatedFoundsets.size() - 1).removeAggregateModificationListener(relatedRecordModificationListener);
                }
                for (IFoundSetInternal relatedFoundset : relatedFoundsets) {
                    ((ISwingFoundSet) relatedFoundset).getSelectionModel().removeListSelectionListener(relatedFoundsetSelectionListener);
                }
                relatedFoundsets = newRelatedFoundsets;
                for (IFoundSetInternal relatedFoundset : relatedFoundsets) {
                    ((ISwingFoundSet) relatedFoundset).getSelectionModel().addListSelectionListener(relatedFoundsetSelectionListener);
                }
                if (isAggregate && relatedFoundsets.size() > 0) {
                    relatedFoundsets.get(relatedFoundsets.size() - 1).addAggregateModificationListener(relatedRecordModificationListener);
                }
            }
        } catch (Exception ex) {
            Debug.error(ex);
        }
    }
    if (relatedRecordModificationListener != null) {
        try {
            ArrayList<IRecordInternal> newRelatedRecords = getRelatedRecords(record, relationName);
            boolean equals = testByReference(newRelatedRecords, this.relatedRecords);
            if (!equals) {
                for (IRecordInternal relatedRecord : relatedRecords) {
                    relatedRecord.removeModificationListener(relatedRecordModificationListener);
                }
                relatedRecords = newRelatedRecords;
                for (IRecordInternal relatedRecord : relatedRecords) {
                    relatedRecord.addModificationListener(relatedRecordModificationListener);
                }
            }
        } catch (Exception ex) {
            Debug.error(ex);
        }
    }
    Object v = com.servoy.j2db.dataprocessing.DataAdapterList.getValueObject(record, servoyDataConverterContext.getForm().getFormScope(), dpID);
    if (v == Scriptable.NOT_FOUND)
        v = null;
    if (fieldFormat != null && !findMode) {
        // if it has an UI converter, transform it from the record/scope value into the UI value
        v = ComponentFormat.applyUIConverterToObject(v, dataProviderID, servoyDataConverterContext.getApplication().getFoundSetManager(), fieldFormat);
    }
    v = replaceTagsIfNeeded(v);
    boolean changed = ((v != uiValue) && (v == null || !v.equals(uiValue)));
    uiValue = v;
    if (changed) {
        jsonValue = null;
    }
    if (// if it is a foundset related DAL then always call valuechanged (the value can be of a previous row)
    fireChangeEvent && (changed || dataAdapterList instanceof FoundsetDataAdapterList)) {
        changeMonitor.valueChanged();
    }
}
Also used : IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) PropertyDescriptionBuilder(org.sablo.specification.PropertyDescriptionBuilder) IDataProvider(com.servoy.j2db.persistence.IDataProvider) INGApplication(com.servoy.j2db.server.ngclient.INGApplication) FindState(com.servoy.j2db.dataprocessing.FindState) FormAndTableDataProviderLookup(com.servoy.j2db.FormAndTableDataProviderLookup) FoundsetDataAdapterList(com.servoy.j2db.server.ngclient.property.FoundsetDataAdapterList) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) ColumnWrapper(com.servoy.j2db.persistence.ColumnWrapper) RepositoryException(com.servoy.j2db.persistence.RepositoryException) FoundSetEvent(com.servoy.j2db.dataprocessing.FoundSetEvent) JSONException(org.json.JSONException) ParseException(java.text.ParseException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) PropertyDescription(org.sablo.specification.PropertyDescription) IColumn(com.servoy.j2db.persistence.IColumn) IDataProviderLookup(com.servoy.j2db.persistence.IDataProviderLookup) IFoundSetEventListener(com.servoy.j2db.dataprocessing.IFoundSetEventListener)

Example 15 with IColumn

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

the class FoundSet method findColumnWrapperForColumn.

private ColumnWrapper findColumnWrapperForColumn(QuerySelect sqlSelect, QueryColumn qcolumn) throws RepositoryException {
    List<Relation> relationSequence = findQueryRelationSequence(sqlSelect, qcolumn.getTable());
    if (relationSequence == null) {
        return null;
    }
    // found the relations, match the column (by sqlName)
    ITable table = fsm.getTable(qcolumn.getTable().getDataSource());
    if (table != null) {
        IColumn column = table.getColumnBySqlname(qcolumn.getName());
        if (column != null) {
            return new ColumnWrapper(column, relationSequence.toArray(new Relation[relationSequence.size()]));
        }
    }
    return null;
}
Also used : Relation(com.servoy.j2db.persistence.Relation) IColumn(com.servoy.j2db.persistence.IColumn) ColumnWrapper(com.servoy.j2db.persistence.ColumnWrapper) ITable(com.servoy.j2db.persistence.ITable)

Aggregations

IColumn (com.servoy.j2db.persistence.IColumn)19 Column (com.servoy.j2db.persistence.Column)10 ITable (com.servoy.j2db.persistence.ITable)7 ColumnWrapper (com.servoy.j2db.persistence.ColumnWrapper)6 IDataProvider (com.servoy.j2db.persistence.IDataProvider)6 Relation (com.servoy.j2db.persistence.Relation)6 RepositoryException (com.servoy.j2db.persistence.RepositoryException)6 BaseQueryTable (com.servoy.base.query.BaseQueryTable)5 ColumnInfo (com.servoy.j2db.persistence.ColumnInfo)5 QueryTable (com.servoy.j2db.query.QueryTable)5 AggregateVariable (com.servoy.j2db.persistence.AggregateVariable)4 QueryColumn (com.servoy.j2db.query.QueryColumn)4 IBaseColumn (com.servoy.base.persistence.IBaseColumn)3 ScriptCalculation (com.servoy.j2db.persistence.ScriptCalculation)3 Table (com.servoy.j2db.persistence.Table)3 IQuerySelectValue (com.servoy.j2db.query.IQuerySelectValue)3 IQuerySort (com.servoy.j2db.query.IQuerySort)3 QuerySort (com.servoy.j2db.query.QuerySort)3 SafeArrayList (com.servoy.j2db.util.SafeArrayList)3 ArrayList (java.util.ArrayList)3