Search in sources :

Example 16 with IColumn

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

the class FoundSetManager method getConvertedTypeForColumn.

@Override
public int getConvertedTypeForColumn(IColumn column, boolean mapToDefaultType) {
    int type = mapToDefaultType ? column.getDataProviderType() : (column instanceof Column ? ((Column) column).getType() : column.getDataProviderType());
    ColumnInfo ci = column.getColumnInfo();
    if (ci != null && ci.getConverterName() != null && ci.getConverterName().trim().length() != 0) {
        IColumnConverter columnConverter = ((FoundSetManager) application.getFoundSetManager()).getColumnConverterManager().getConverter(ci.getConverterName());
        if (columnConverter instanceof ITypedColumnConverter) {
            try {
                int convType = ((ITypedColumnConverter) columnConverter).getToObjectType(ComponentFactory.<String>parseJSonProperties(ci.getConverterProperties()));
                if (convType != Integer.MAX_VALUE) {
                    type = Column.mapToDefaultType(convType);
                }
            } catch (IOException e) {
                Debug.error("Exception loading properties for converter " + columnConverter.getName() + ", properties: " + ci.getConverterProperties(), e);
            }
        }
    }
    return type;
}
Also used : Column(com.servoy.j2db.persistence.Column) IColumn(com.servoy.j2db.persistence.IColumn) IBaseColumn(com.servoy.base.persistence.IBaseColumn) ColumnInfo(com.servoy.j2db.persistence.ColumnInfo) IOException(java.io.IOException)

Example 17 with IColumn

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

the class FoundSetManager method getSortColumn.

public SortColumn getSortColumn(ITable table, String dataProviderID, boolean logIfCannotBeResolved) throws RepositoryException {
    if (table == null || dataProviderID == null)
        return null;
    Table lastTable = (Table) table;
    List<Relation> relations = new ArrayList<Relation>();
    // $NON-NLS-1$
    String[] split = dataProviderID.split("\\.");
    for (int i = 0; i < split.length - 1; i++) {
        Relation r = application.getFlattenedSolution().getRelation(split[i]);
        String reason = null;
        if (r == null) {
            reason = "relation '" + split[i] + "' not found";
        } else if (!Relation.isValid(r, application.getFlattenedSolution()) || !r.isUsableInSort()) {
            if (!Relation.isValid(r, application.getFlattenedSolution()))
                reason = "relation '" + split[i] + "' not valid";
            else if (r.isMultiServer())
                reason = "relation '" + split[i] + "' is cross server, sorting is not supported";
            else if (r.isGlobal())
                reason = "relation '" + split[i] + "' is global, sorting is not supported";
            else
                reason = "relation '" + split[i] + "' is outer join with or null modifier, sorting is not supported";
        } else if (!lastTable.equals(getTable(r.getPrimaryDataSource()))) {
            reason = "table '" + lastTable.getName() + "' does not match with relation '" + split[i] + "'primary table";
        }
        if (reason != null) {
            if (logIfCannotBeResolved)
                Debug.log("Cannot sort on dataprovider " + dataProviderID + ", " + reason, new Exception(split[i]));
            return null;
        }
        relations.add(r);
        lastTable = (Table) getTable(r.getForeignDataSource());
    }
    String colName = split[split.length - 1];
    IColumn c = lastTable.getColumn(colName);
    if (c == null) {
        // check for aggregate
        c = AbstractBase.selectByName(application.getFlattenedSolution().getAggregateVariables(lastTable, false), colName);
    }
    if (c != null) {
        return new SortColumn(c, relations.size() == 0 ? null : relations.toArray(new Relation[relations.size()]));
    }
    return null;
}
Also used : Relation(com.servoy.j2db.persistence.Relation) BaseQueryTable(com.servoy.base.query.BaseQueryTable) Table(com.servoy.j2db.persistence.Table) QueryTable(com.servoy.j2db.query.QueryTable) ITable(com.servoy.j2db.persistence.ITable) IColumn(com.servoy.j2db.persistence.IColumn) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ServoyException(com.servoy.j2db.util.ServoyException) JavaScriptException(org.mozilla.javascript.JavaScriptException) IOException(java.io.IOException) MarshallException(org.jabsorb.serializer.MarshallException) ApplicationException(com.servoy.j2db.ApplicationException) RemoteException(java.rmi.RemoteException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Example 18 with IColumn

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

the class ComponentFormat method getComponentFormat.

public static ComponentFormat getComponentFormat(String format, IDataProvider dataProvider, IServiceProvider application, boolean autoFillMaxLength) {
    int dpType = IColumnTypes.TEXT;
    String formatProperty = format;
    if (dataProvider != null) {
        dpType = dataProvider.getDataProviderType();
        IColumn column = null;
        if (dataProvider instanceof ColumnWrapper) {
            column = ((ColumnWrapper) dataProvider).getColumn();
        } else if (dataProvider instanceof Column) {
            column = (Column) dataProvider;
        } else if (dataProvider instanceof ScriptCalculation) {
            // When it is a stored calculation, the name of the calc is the name of he column
            ScriptCalculation calc = (ScriptCalculation) dataProvider;
            try {
                ITable table = calc.getTable();
                if (table != null) {
                    column = table.getColumn(calc.getName());
                }
            } catch (RepositoryException e) {
                Debug.error(e);
            }
        }
        if (column instanceof AggregateVariable) {
            Column columnToAggregate = null;
            try {
                ITable table = column.getTable();
                if (table != null) {
                    columnToAggregate = table.getColumn(((AggregateVariable) column).getDataProviderIDToAggregate());
                }
            } catch (RepositoryException e) {
                Debug.error(e);
            }
            // Use aggregated column when they are of the same type (so not count(textcolumn))
            if (columnToAggregate != null && column.getDataProviderType() == columnToAggregate.getDataProviderType()) {
                column = columnToAggregate;
            }
        }
        if (column instanceof Column) {
            ColumnInfo ci = ((Column) column).getColumnInfo();
            if (ci != null) {
                if (formatProperty == null || formatProperty.length() == 0) {
                    if (ci.getDefaultFormat() != null && ci.getDefaultFormat().length() > 0) {
                        formatProperty = ci.getDefaultFormat();
                    }
                }
                dpType = application.getFoundSetManager().getConvertedTypeForColumn(column, true);
            }
        }
    }
    ComponentFormat componentFormat = ComponentFormat.getComponentFormat(formatProperty, dpType, application);
    if (autoFillMaxLength && dataProvider != null && dataProvider.getLength() > 0 && componentFormat.parsedFormat != null && componentFormat.parsedFormat.getMaxLength() == null && (dpType == IColumnTypes.TEXT || dpType == IColumnTypes.MEDIA)) {
        componentFormat.parsedFormat.updateMaxLength(Integer.valueOf(dataProvider.getLength()));
    }
    return componentFormat;
}
Also used : ScriptCalculation(com.servoy.j2db.persistence.ScriptCalculation) IColumn(com.servoy.j2db.persistence.IColumn) IColumn(com.servoy.j2db.persistence.IColumn) Column(com.servoy.j2db.persistence.Column) ColumnWrapper(com.servoy.j2db.persistence.ColumnWrapper) ColumnInfo(com.servoy.j2db.persistence.ColumnInfo) ITable(com.servoy.j2db.persistence.ITable) RepositoryException(com.servoy.j2db.persistence.RepositoryException) AggregateVariable(com.servoy.j2db.persistence.AggregateVariable)

Example 19 with IColumn

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

the class FoundSetManager method getRelationWhereArgs.

/**
 * Get relation where-args, not using column converters
 * @param state
 * @param relation
 * @param testForCalcs
 * @return
 * @throws RepositoryException
 */
public Object[] getRelationWhereArgs(IRecordInternal state, Relation relation, boolean testForCalcs) throws RepositoryException {
    boolean isNull = true;
    IDataProvider[] args = relation.getPrimaryDataProviders(application.getFlattenedSolution());
    Column[] columns = relation.getForeignColumns(application.getFlattenedSolution());
    Object[] array = new Object[args.length];
    for (int i = 0; i < args.length; i++) {
        Object value = null;
        if (args[i] instanceof LiteralDataprovider) {
            value = ((LiteralDataprovider) args[i]).getValue();
        } else if (args[i] instanceof EnumDataProvider) {
            value = getScopesScopeProvider().getDataProviderValue(args[i].getDataProviderID());
        } else {
            String dataProviderID = args[i].getDataProviderID();
            if (testForCalcs && state.getRawData().containsCalculation(dataProviderID) && state.getRawData().mustRecalculate(dataProviderID, true)) {
                // else this can just cascade through..
                return null;
            }
            // unconverted (todb value)
            value = state.getValue(dataProviderID, false);
        }
        if (value != Scriptable.NOT_FOUND) {
            array[i] = columns[i].getAsRightType(value);
        }
        if (array[i] != null) {
            isNull = false;
        } else {
            // Because null columns can't have a relation.
            if (args[i] instanceof IColumn) {
                return null;
            }
            if (isNull) {
                isNull = !(args[i] instanceof ScriptVariable);
            }
        }
    }
    // optimize for null keys (multiple all null!) but not empty pk (db ident)
    if (isNull)
        return null;
    return array;
}
Also used : IDataProvider(com.servoy.j2db.persistence.IDataProvider) LiteralDataprovider(com.servoy.j2db.persistence.LiteralDataprovider) Column(com.servoy.j2db.persistence.Column) IColumn(com.servoy.j2db.persistence.IColumn) IBaseColumn(com.servoy.base.persistence.IBaseColumn) IColumn(com.servoy.j2db.persistence.IColumn) EnumDataProvider(com.servoy.j2db.persistence.EnumDataProvider) ScriptVariable(com.servoy.j2db.persistence.ScriptVariable) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject)

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