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;
}
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;
}
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;
}
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;
}
Aggregations